fixed date trans bugs and added live search
This commit is contained in:
@@ -22,45 +22,48 @@ for($i = 0; $i < 2; $i++) {
|
||||
|
||||
natsort($worklists);
|
||||
|
||||
$checkedLists = $_GET['worklist'];
|
||||
|
||||
$monthTrans = ['jan' => 'Jan', 'feb' => 'Feb', 'mrt' => 'Mar', 'apr' => 'Apr', 'mei' => 'May', 'jul' => 'Jul', 'aug' => 'Aug', 'sep' => 'Sep',
|
||||
'okt' => 'Oct', 'nov' => 'Nov', 'dec' => 'Dec'];
|
||||
|
||||
$all_names = [];
|
||||
$totalShifted = 0;
|
||||
$total = 0;
|
||||
$checkedLists = [];
|
||||
|
||||
foreach ($checkedLists as $site) {
|
||||
$site = 'https://old.wina.be/worklists/' . $site;
|
||||
$data = file_get_contents($site);
|
||||
if (isset($_GET['worklist'])) {
|
||||
$checkedLists = $_GET['worklist'];
|
||||
|
||||
preg_match_all('/<div id="(data_shift.*?<table.*?>.*?<\/table>)/s', $data, $shiften);
|
||||
$shiften = $shiften[1];
|
||||
$monthTrans = ['jan' => 'Jan', 'feb' => 'Feb', 'mrt' => 'Mar', 'apr' => 'Apr', 'mei' => 'May', 'jun' => 'Jun', 'jul' => 'Jul', 'aug' => 'Aug', 'sep' => 'Sep',
|
||||
'okt' => 'Oct', 'nov' => 'Nov', 'dec' => 'Dec'];
|
||||
|
||||
foreach ($shiften as $shift) {
|
||||
preg_match_all('/data_shift.*?Start<\/td>.*?>.*?(\d.*?)<\/td>/s', $shift, $start);
|
||||
preg_match_all('/data_shift.*?Einde<\/td>.*?>.*?(\d.*?)<\/td>/s', $shift, $einde);
|
||||
$start = explode(' ', $start[1][0]);
|
||||
$start[1] = $monthTrans[$start[1]];
|
||||
$start = DateTime::createFromFormat('j M Y - G:i', implode(' ', $start));
|
||||
$einde = explode(' ', $einde[1][0]);
|
||||
$einde[1] = $monthTrans[$einde[1]];
|
||||
$einde = DateTime::createFromFormat('j M Y - G:i', implode(' ', $einde));
|
||||
foreach ($checkedLists as $site) {
|
||||
$site = 'https://old.wina.be/worklists/' . $site;
|
||||
$data = file_get_contents($site);
|
||||
|
||||
$diff = ($einde->getTimestamp() - $start->getTimestamp()) / 3600;
|
||||
preg_match_all('/<div id="(data_shift.*?<table.*?>.*?<\/table>)/s', $data, $shiften);
|
||||
$shiften = $shiften[1];
|
||||
|
||||
preg_match_all('/data_shift.*?Invulling.*?<td.*?>(.*?)<\/td>/s', $shift, $blockNames);
|
||||
if (count($blockNames[1]) !== 0) {
|
||||
preg_match_all('/<span.*?>(.*?)<\/span>/s', $blockNames[1][0], $names);
|
||||
foreach ($shiften as $shift) {
|
||||
preg_match_all('/data_shift.*?Start<\/td>.*?>.*?(\d.*?)<\/td>/s', $shift, $start);
|
||||
preg_match_all('/data_shift.*?Einde<\/td>.*?>.*?(\d.*?)<\/td>/s', $shift, $einde);
|
||||
$start = explode(' ', $start[1][0]);
|
||||
$start[1] = $monthTrans[$start[1]];
|
||||
$start = DateTime::createFromFormat('j M Y - G:i', implode(' ', $start));
|
||||
$einde = explode(' ', $einde[1][0]);
|
||||
$einde[1] = $monthTrans[$einde[1]];
|
||||
$einde = DateTime::createFromFormat('j M Y - G:i', implode(' ', $einde));
|
||||
|
||||
foreach ($names[1] as $name) {
|
||||
if (!array_key_exists($name, $all_names)) {
|
||||
$all_names[$name] = $diff;
|
||||
} else {
|
||||
$all_names[$name] += $diff;
|
||||
$diff = ($einde->getTimestamp() - $start->getTimestamp()) / 3600;
|
||||
|
||||
preg_match_all('/data_shift.*?Invulling.*?<td.*?>(.*?)<\/td>/s', $shift, $blockNames);
|
||||
if (count($blockNames[1]) !== 0) {
|
||||
preg_match_all('/<span.*?>(.*?)<\/span>/s', $blockNames[1][0], $names);
|
||||
|
||||
foreach ($names[1] as $name) {
|
||||
if (!array_key_exists($name, $all_names)) {
|
||||
$all_names[$name] = $diff;
|
||||
} else {
|
||||
$all_names[$name] += $diff;
|
||||
}
|
||||
$totalShifted += $diff;
|
||||
}
|
||||
$totalShifted += $diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,9 +76,9 @@ $avg = $totalShifted / count($all_names);
|
||||
<!doctype html>
|
||||
<html lang="nl">
|
||||
<head>
|
||||
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>Wina shift counter</title>
|
||||
<meta name="author" content="Arthur Bols">
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
|
||||
@@ -90,7 +93,7 @@ $avg = $totalShifted / count($all_names);
|
||||
<div class="text-center">
|
||||
<h1>Wina shift counter</h1>
|
||||
<form class="mb-2" method="get">
|
||||
<select name="worklist[]" class="selectpicker" data-style="btn-primary" multiple>
|
||||
<select name="worklist[]" class="selectpicker" data-style="btn-primary" data-live-search="true" multiple>
|
||||
<?php
|
||||
foreach($worklists as $key => $list) {
|
||||
echo "<option " . (in_array($key, $checkedLists) ? "selected " : '') . "value='$key'>" . $list . "</option>";
|
||||
|
Reference in New Issue
Block a user