/** getMonthIncome::__construct() * Class constructor */ public function __construct() { //: This doesn't need to happen at all if we aren't after the third of the month if (date('d') < 2) { syslog(LOG_INFO, "No need to run, as it is before the third of the month"); exit; } $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA) or die(mysqli_error($link)); $fleetdayobj = new fleetDayHandler(); $end = (int) date('d', strtotime('-4 days')); for ($i = 1; $i <= $end; $i++) { print 'Pulling for day: ' . $i . PHP_EOL; $fleetscore = $fleetdayobj->pullFleetDay($i); $fleetdayobj->saveFleetDay($fleetscore); } }
// Defines and includes { $times = substr_count($_SERVER['PHP_SELF'], "/"); $rootaccess = ""; $i = 1; while ($i < $times) { $rootaccess .= "../"; $i++; } define("BASE", $rootaccess); include_once BASE . "/basefunctions/localdefines.php"; include_once BASE . "/basefunctions/dbcontrols.php"; include_once BASE . "/basefunctions/baseapis/manapi.php"; include_once BASE . "Maxine/api/maxineapi.php"; require_once BASE . "basefunctions/baseapis/fleetDayHandler.php"; $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA) or die(mysqli_error($link)); $fleetdayobj = new fleetDayHandler(); // } /** returnFleetTruckCount() * get all fleets truck count * @return array on success false otherwise */ function returnFleetTruckCount() { require_once BASE . "/basefunctions/baseapis/TableManager.php"; $manager = new TableManager("fleet_truck_count"); $manager->setCustomIndex("fleet_id"); return $manager->selectMultiple(); } $truckcount = returnFleetTruckCount(); // } $count = $conf["fleetcount"];
/** ImportFleetDay * This function imports a single day of Income into the maxinedb.fleet_scores table */ function ImportFleetDay() { $start = microtime(TRUE); //: Preparation $times = substr_count($_SERVER['PHP_SELF'], "/"); $rootaccess = ""; $i = 1; while ($i < $times) { $rootaccess .= "../"; $i++; } set_time_limit(0); defined('BASE') || define("BASE", $rootaccess); include_once BASE . "/basefunctions/localdefines.php"; include_once BASE . "/basefunctions/dbcontrols.php"; include_once BASE . "/basefunctions/baseapis/manapi.php"; include_once BASE . "Maxine/api/maxineapi.php"; require_once BASE . "basefunctions/baseapis/fleetDayHandler.php"; $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA) or die(mysqli_error($link)); $fleetdayobj = new fleetDayHandler(); $startdate = (int) (isset($_POST['conf']) && $_POST['conf'] && (isset($_POST['conf']['date']) && $_POST['conf']['date']) ? strtotime(preg_replace('/\\//', '-', $_POST['conf']['date'])) : strtotime(date('Y-m-01'))); //: End print '<!DOCTYPE html>'; print '<head>'; print '<meta charset="utf-8">'; print '<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">'; print '<title>Dashboards - Barloworld Transport</title>'; print '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />'; print '<link href="favicon.ico" rel="shortcut icon" />'; print '<link rel="stylesheet" href="' . BASE . 'basefunctions/scripts/bootstrap.min.css">'; print '<link href="' . BASE . 'basefunctions/scripts/font-awesome.min.css" rel="stylesheet">'; print '<link rel="stylesheet" href="' . BASE . 'Maxine/displaycase/content/site/css/fonts.css">'; print '<link rel="stylesheet" href="' . BASE . 'Maxine/displaycase/content/site/css/main.css">'; print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/vendor/modernizr-2.6.2.min.js"></script>'; print '<script src="' . BASE . 'basefunctions/scripts/jquery.min.js"></script>'; print '<script src="' . BASE . 'basefunctions/scripts/jquery.ui.touch-punch.min.js"></script>'; print '<!--[if lt IE 9]>'; print '<script src="' . BASE . 'basefunctions/scripts/html5shiv.min.js"></script>'; print '<script src="' . BASE . 'basefunctions/scripts/respond.js"></script>'; print '<![endif]-->'; print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/vendor/jcircle.js"></script>'; print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/vendor/jquery.flot/jquery.flot.js"></script>'; print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/vendor/jquery.flot/jquery.flot.time.js"></script>'; print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/vendor/jquery.flot/jquery.flot.tooltip.js"></script>'; print '</head>' . PHP_EOL; print '<body>'; print '<div id="root"></div>'; print '<div id="page" style="overflow-y:auto;">'; print '<header>'; print '<div class="controlsWrapper">'; print '<a href="#" class="menu"></a>'; print '</div><!-- controlsWrapper -->'; print '</header>'; print '<nav>'; print '<ul>'; print '<li><a href="/?personal">Dashboard</a></li>'; print '<li><a href="/?mydashdetails">Dashboard Builder</a></li>'; print '<li><a href="/?importfleetday">Import Day</a></li>'; print '<li><a href="/?checkfleetscoreupdates">Fleet Scores</a></li>'; print '<li><a href="/?ocddata">OCD Data</a></li>'; print '<li><a href="/?logout">Logout</a></li>'; print '</ul>'; print '</nav>'; //: Page Content print '<div id="blackouts">'; //: Form print '<div class="fleetWrapper" style="height:10%;">'; print '<form method="POST">'; print '<table><tbody><tr>'; print '<td>'; //: Col 1 print '<label for="conf[date]">Date:</label>'; print '<input id="conf[date]" name="conf[date]" value="' . date("d/m/Y", $startdate) . '" readonly style="width: 160px; text-align: center;">'; print '<img src="' . BASE . '/images/calendar.png" style="cursor:pointer" onClick="displayDatePicker(\'conf[date]\', this, \'dmy\', \'\');">'; print '</td>'; print '<td>'; //: Col 2 print '<input type="Submit" value="Import" />'; print '</td>'; print '</tr></tbody></table>'; print '</form>'; print '</div>'; print '<div class="fleetWrapper" style="height:90%;">'; print '<table><tbody><tr><td>'; if (isset($_POST) && $_POST) { print 'Importing for date: ' . date('Y-m-d', $startdate) . '<br />'; $day = date('d', $startdate); $fleetscore = $fleetdayobj->pullFleetDay($day); $fleetdayobj->saveFleetDay($fleetscore); $end = microtime(TRUE); $time = $end - $start; print 'Import completed in :' . $time / 60; } print '</td></tr></tbody></table>'; print '</div>'; //: End print '</div>'; //: End //: End Page print '<script>window.jQuery || document.write("<script src=\\"' . BASE . 'Maxine/displaycase/content/site/js/vendor/jquery-1.9.1.min.js\\"><\\/script>")</script>'; print '<script src="' . BASE . 'basefunctions/scripts/jquery.color.min.js"></script>'; print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/plugins.js"></script>'; print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/styling.js"></script>'; print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/main.js"></script>'; print '<script type="text/javascript" language="javascript" src="' . BASE . '/basefunctions/scripts/manline.js"></script>'; print '</body>' . PHP_EOL; print '</html>'; }
//: Get the Data $times = substr_count($_SERVER['PHP_SELF'], "/"); $rootaccess = ""; $i = 1; while ($i < $times) { $rootaccess .= "../"; $i++; } define("BASE", $rootaccess); include_once BASE . "/basefunctions/localdefines.php"; include_once BASE . "/basefunctions/dbcontrols.php"; include_once BASE . "/basefunctions/baseapis/manapi.php"; include_once BASE . "Maxine/api/maxineapi.php"; require_once BASE . "basefunctions/baseapis/fleetDayHandler.php"; $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA) or die(mysqli_error($link)); $fleetdayobj = new fleetDayHandler(); $fleet = $fleetdayobj->getFleetById(substr($_POST['dashid'], 1)); //: Missing and open refuels $sql = (string) 'SELECT * FROM `refuels` WHERE `fleet_id`=' . (int) $fleet['maxid']; $refuels = sqlQuery($sql); if ($refuels === FALSE) { syslog(LOG_INFO, 'Query for unauthorized refuels returned FALSE.'); } //: End //: Unauthorized Refuels $sql = (string) 'SELECT * FROM `unauthorized_refuels` WHERE `fleet_id`=' . (int) $fleet['maxid']; $unauth = sqlQuery($sql); if ($unauth === FALSE) { syslog(LOG_INFO, 'Query for unauthorized refuels returned FALSE.'); } //: End
// Defines and includes { $times = substr_count($_SERVER['PHP_SELF'], "/"); $rootaccess = ""; $i = 1; while ($i < $times) { $rootaccess .= "../"; $i++; } define("BASE", $rootaccess); include_once BASE . "/basefunctions/localdefines.php"; include_once BASE . "/basefunctions/dbcontrols.php"; include_once BASE . "/basefunctions/baseapis/manapi.php"; include_once BASE . "Maxine/api/maxineapi.php"; require_once BASE . "basefunctions/baseapis/fleetDayHandler.php"; $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA) or die(mysqli_error($link)); $fleetdayobj = new fleetDayHandler(); // } // } if ($conf["maxwidth"]) { $maxwidth = $conf["maxwidth"]; if ($maxwidth < 1000) { $factor = 0.8; } else { if ($maxwidth < 1300) { $factor = 0.9399999999999999; } else { if ($maxwidth > 1600) { $factor = 1.4; } else { $factor = 1; }
* @license GNU GPL * @link http://www.gnu.org/licenses/gpl.html * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ // Defines and includes { $realPath = realpath(dirname(__FILE__)); $maxine = substr($realPath, 0, strrpos($realPath, DIRECTORY_SEPARATOR)); $rootaccess = substr($maxine, 0, strrpos($maxine, DIRECTORY_SEPARATOR) + 1); define("BASE", $rootaccess); include_once BASE . "/basefunctions/localdefines.php"; include_once BASE . "/basefunctions/dbcontrols.php"; include_once BASE . "/basefunctions/baseapis/manapi.php"; include_once BASE . "Maxine/api/maxineapi.php"; require_once BASE . "basefunctions/baseapis/fleetDayHandler.php"; $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA) or die(mysqli_error($link)); $fleetdayobj = new fleetDayHandler(); // } $fleetdayobj->getUnauthorizedRefuels(); # B@r!0W0r!d # /var/www/htdocs/mobilize/vendor/Kaluma/Max/scripts/ortit.php -t 'BWTS Group' -r 'Feighen Oosterbroek' -f '2.T24 - Timber24' -f '2.Freight SA (Own)' -f '2.Freight Africa' -f '2.Freight Subcontractors Consolidated' -f '2.Manline Mega' -f '2.Energy' -f '2.Construction' -f '2.Environmental' -f '2.Commercial' -f '2.Agriculture' -f '2.Mining'
// Defines and includes { $times = substr_count($_SERVER['PHP_SELF'], "/"); $rootaccess = ""; $i = 1; while ($i < $times) { $rootaccess .= "../"; $i++; } define("BASE", $rootaccess); include_once BASE . "/basefunctions/localdefines.php"; include_once BASE . "/basefunctions/dbcontrols.php"; include_once BASE . "/basefunctions/baseapis/manapi.php"; include_once BASE . "Maxine/api/maxineapi.php"; require_once BASE . "basefunctions/baseapis/fleetDayHandler.php"; $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA) or die(mysqli_error($link)); $fleetdayobj = new fleetDayHandler(); // } // } // Sort functions { function cmpBudgets($a, $b) { if ($a["Date"] == $b["Date"]) { return 0; } return $a["Date"] < $b["Date"] ? -1 : 1; } function cmpScores($a, $b) { if ($a["score"] == $b["score"]) { return 0; }
<?php //: Preparation $realPath = realpath(dirname(__FILE__)); $maxine = substr($realPath, 0, strrpos($realPath, DIRECTORY_SEPARATOR)); $rootaccess = substr($maxine, 0, strrpos($maxine, DIRECTORY_SEPARATOR) + 1); defined("BASE") || define("BASE", $rootaccess); include_once BASE . "basefunctions/localdefines.php"; include_once BASE . "basefunctions/dbcontrols.php"; include_once BASE . "basefunctions/baseapis/manapi.php"; include_once BASE . "Maxine/api/maxineapi.php"; require_once BASE . "basefunctions/baseapis/fleetDayHandler.php"; $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA) or die(mysqli_error($link)); //: End //: Content $fleetdayobj = new fleetDayHandler(); function dates_month($month, $year) { $num = cal_days_in_month(CAL_GREGORIAN, $month, $year); $dates_month = array(); for ($i = 1; $i <= $num; $i++) { $mktime = mktime(0, 0, 0, $month, $i, $year); $date = date("d-M-Y", $mktime); $dates_month[$i] = $date; } return $dates_month; } $days = dates_month(date("m"), date("Y")); foreach ($days as $day) { if (date("d", strtotime($day)) > 31) { continue;
* @copyright 2013 onwards Barloworld Transport Solutions * @license GNU GPL * @link http://www.gnu.org/licenses/gpl.html * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ // Defines and includes { $realPath = realpath(dirname(__FILE__)); $maxine = substr($realPath, 0, strrpos($realPath, DIRECTORY_SEPARATOR)); $rootaccess = substr($maxine, 0, strrpos($maxine, DIRECTORY_SEPARATOR) + 1); define("BASE", $rootaccess); include_once BASE . "/basefunctions/localdefines.php"; include_once BASE . "/basefunctions/dbcontrols.php"; include_once BASE . "/basefunctions/baseapis/manapi.php"; include_once BASE . "Maxine/api/maxineapi.php"; require_once BASE . "basefunctions/baseapis/fleetDayHandler.php"; $link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysqli_error($link)); $db_selected = mysql_select_db(DB_SCHEMA, $link); $fleetdayobj = new fleetDayHandler(); // } $fleetdayobj->refuel();
//} //: End //: Preparation $realPath = realpath(dirname(__FILE__)); $maxine = substr($realPath, 0, strrpos($realPath, DIRECTORY_SEPARATOR)); $rootaccess = substr($maxine, 0, strrpos($maxine, DIRECTORY_SEPARATOR) + 1); defined('BASE') || define("BASE", $rootaccess); include_once BASE . "basefunctions/localdefines.php"; include_once BASE . "basefunctions/dbcontrols.php"; include_once BASE . "basefunctions/baseapis/manapi.php"; include_once BASE . "Maxine/api/maxineapi.php"; include_once BASE . "basefunctions/baseapis/fleetDayHandler.php"; $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA) or die(mysqli_error($link)); //: End //: Content $fleetdayobj = new fleetDayHandler(); $today = date("d"); $day = (int) 0; if (array_key_exists(1, $argv)) { $day = (int) $argv[1]; } $customday = (int) 0; if ($day) { $customday = $day; } if ($customday > 0) { $fleetscore = $fleetdayobj->pullFleetDay($customday); $fleetdayobj->saveFleetDay($fleetscore); } else { print "Pulling today.<br>"; $fleetscore = $fleetdayobj->pullFleetDay($today);
<?php $fleetdayobj = new fleetDayHandler(); $budgets = $fleetdayobj->getAllBudgetsInDateRange(date("Y-m-01"), date("Y-m-01", strtotime("+1 month"))); // print_r($budgets);exit; //: Get the days listed $days = (array) array(); foreach ($budgets as $truck_id => $budgetrow) { //print_r($budgetrow); foreach ($budgetrow as $val) { $days[] = $val["date"]; } break; } $t24Budget = (array) array(); foreach ($days as $day) { //: Get the trucks in a fleet on a specific day $date = intval(substr($day, strrpos($day, "-") + 1)); //echo $date; if ($date > 1) { continue; } $trucksinafleet = $fleetdayobj->pullT24FleetData($date); print_r($trucksinafleet); //: End //: Sum the budget amounts per truck foreach ($trucksinafleet as $row) { //: Get the budget for this truck if (array_key_exists($row["truck_id"], $budgets)) { $t24Budget[$row["fleet_id"]][$day] = array(); $t24Budget[$row["fleet_id"]][$day]["fleetid"] = $row["fleet_id"];
} //: End $starttimer = date("U"); // Preparation { $realPath = realpath(dirname(__FILE__)); $maxine = substr($realPath, 0, strrpos($realPath, DIRECTORY_SEPARATOR)); $rootaccess = substr($maxine, 0, strrpos($maxine, DIRECTORY_SEPARATOR) + 1); define("BASE", $rootaccess); include_once BASE . "basefunctions/localdefines.php"; include_once BASE . "basefunctions/dbcontrols.php"; include_once BASE . "basefunctions/baseapis/manapi.php"; include_once BASE . "Maxine/api/maxineapi.php"; require_once BASE . "basefunctions/baseapis/fleetDayHandler.php"; $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA) or die(mysqli_error($link)); // } $fleetdayobj = new fleetDayHandler(); $today = date("d"); $customday = 0; if ($customday > 0) { $fleetscore = $fleetdayobj->pullFleetDayWithContrib($customday); $fleetdayobj->saveFleetDay($fleetscore); print "<pre style='font-family:verdana;font-size:13'>"; print_r($fleetscore); print "</pre>"; } else { print "Pulling today.<br>"; $fleetscore = $fleetdayobj->pullFleetDayWithContrib($today); $fleetdayobj->saveFleetDay($fleetscore); if ($today > 1) { print "Pulling yesterday.<br>"; $fleetscore = $fleetdayobj->pullFleetDayWithContrib($today - 1);
<?php //: Preparation $realPath = realpath(dirname(__FILE__)); $maxine = substr($realPath, 0, strrpos($realPath, DIRECTORY_SEPARATOR)); $rootaccess = substr($maxine, 0, strrpos($maxine, DIRECTORY_SEPARATOR) + 1); define("BASE", $rootaccess); include_once BASE . "basefunctions/localdefines.php"; include_once BASE . "basefunctions/dbcontrols.php"; include_once BASE . "basefunctions/baseapis/manapi.php"; include_once BASE . "Maxine/api/maxineapi.php"; require_once BASE . "basefunctions/baseapis/fleetDayHandler.php"; $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA) or die(mysqli_error($link)); //: End //: Content $fleet = (int) 0; if (array_key_exists(1, $argv)) { $fleet = (int) $argv[1]; } //: Max Fleets $fleetdayobj = new fleetDayHandler(); $fleetdayobj->importBudget($fleet ? $fleet : NULL); //: End\
function importCustomFleetday() { $conf = $_POST["conf"]; $fleetdayobj = new fleetDayHandler(); $fleetscore = $fleetdayobj->pullFleetDay($conf["dayselect"]); $fleetdayobj->saveFleetDay($fleetscore); print "DONE."; goHere("index.php?mode=maxine/index&action=selectcustomfleetday"); }
<?php $starttimer = date("U"); //: Preparation $realPath = realpath(dirname(__FILE__)); $maxine = substr($realPath, 0, strrpos($realPath, DIRECTORY_SEPARATOR)); $rootaccess = substr($maxine, 0, strrpos($maxine, DIRECTORY_SEPARATOR) + 1); define("BASE", $rootaccess); include_once BASE . "basefunctions/localdefines.php"; include_once BASE . "basefunctions/dbcontrols.php"; include_once BASE . "basefunctions/baseapis/manapi.php"; include_once BASE . "Maxine/api/maxineapi.php"; require_once BASE . "basefunctions/baseapis/fleetDayHandler.php"; $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA) or die(mysqli_error($link)); //: End $fleetdayobj = new fleetDayHandler(); $today = date("d"); $customday = 0; if ($customday > 0) { $fleetscore = $fleetdayobj->pullFleetDayT24($customday); $fleetdayobj->saveFleetDay($fleetscore); print "<pre style='font-family:verdana;font-size:13'>"; print_r($fleetscore); print "</pre>"; } else { print "Pulling today." . PHP_EOL; $fleetscore = $fleetdayobj->pullFleetDayT24($today); if ($fleetscore === FALSE) { //: broken print "No data recieved" . PHP_EOL; exit;
/** fleetTruckLinkImporter::__construct() * Class constructor */ public function __construct() { $realPath = realpath(dirname(__FILE__)); $maxine = substr($realPath, 0, strrpos($realPath, DIRECTORY_SEPARATOR)); $rootaccess = substr($maxine, 0, strrpos($maxine, DIRECTORY_SEPARATOR) + 1); defined("BASE") || define("BASE", $rootaccess); include_once BASE . "basefunctions/baseapis/TableManager.php"; include_once BASE . "basefunctions/baseapis/FileParser/FileParser.php"; $manager = new TableManager("fleet_truck_count"); //: Do a test to see if table includes subbie_trucks field $fields = $manager->describeTable(); if (in_array('subbie_count', array_keys($fields)) === FALSE) { $sql = (string) "ALTER TABLE `fleet_truck_count` ADD COLUMN `subbie_count` INT NOT NULL DEFAULT 0;"; if ($manager->runSql($sql) === FALSE) { print "Altering table failed" . PHP_EOL; return FALSE; } } //: End $subbietrucksurl = "https://login.max.bwtsgroup.com/api_request/Report/export?report=153&responseFormat=csv"; // Max $apiurl = "https://login.max.bwtsgroup.com/api_request/Report/export?report=145&responseFormat=csv"; // Max $t24apiurl = "https://t24.max.bwtsgroup.com/api_request/Report/export?report=73&responseFormat=csv"; // T24 // $apiurl = "http://max.mobilize.biz/m4/2/api_request/Report/export?report=141&responseFormat=csv"; // Test //: Get the list of subbie trucks $fileParser = new FileParser($subbietrucksurl); $fileParser->setCurlFile("subbie_trucks.csv"); $data = $fileParser->parseFile(); $subbieTrucks = (array) array(); foreach ($data as $val) { if (array_key_exists("Trucks", $val) === FALSE) { continue; } $trucks = preg_split("/\\,/", $val["Trucks"]); if (is_array($trucks) === FALSE) { continue; } foreach ($trucks as $trucklist) { $subbieTrucks[] = $trucklist; } } //print_r($subbieTrucks); unset($data); //return FALSE; //: End $fleetDayHandler = new fleetDayHandler(); $required_fleets = $fleetDayHandler->getIncomeFleets(); $rows = (array) array(); foreach ($required_fleets as $val) { if (array_key_exists('fleets', $val)) { $count = (int) 0; $subbie_count = (int) 0; foreach ($val['fleets'] as $subfleets) { $manager->setWhere($manager->quoteString('`fleet_id`=?', $subfleets[0])); $record = $manager->selectSingle(); $count += (int) $record['count']; $subbie_count += (int) $record['subbie_count']; } $rows[] = (array) array('fleet_id' => $val['id'], 'count' => isset($count) && $count ? $count : 0, 'subbie_count' => isset($subbie_count) && $subbie_count ? $subbie_count : 0); } else { $url = $apiurl . "&Fleet=" . $val["maxid"] . "&Start%20Date=" . date("Y-m-d") . "&Stop%20Date=" . date('Y-m-d', strtotime('+1 day')); if (array_key_exists('t24', $val)) { $url = $t24apiurl . "&Fleet=" . $val["maxid"] . "&Start%20Date=" . date("Y-m-d") . "&Stop%20Date=" . date('Y-m-d', strtotime('+1 day')); } print_r('url: ' . $url . PHP_EOL); $fileParser = new FileParser($url); $fileParser->setCurlFile("fleet_truck_count_" . $val["id"] . ".csv"); $data = $fileParser->parseFile(); // print_r($data); /*if ($fleetId == 75) { //: confirm a fleet is correct print("<pre>"); print_r($data); print("</pre>"); }*/ $sub_cnt = (int) 0; foreach ($data as $row) { if (in_array($row['Truck'], $subbieTrucks)) { $sub_cnt++; } } //print($sub_cnt.PHP_EOL); $record = (array) array('fleet_id' => $val['id'], 'count' => count($data), 'subbie_count' => $sub_cnt); if (array_key_exists('t24', $val)) { $record['t24'] = (int) 1; } $rows[] = $record; } } //: Loop through and update/insert records foreach ($rows as $row) { $where = (string) $manager->quoteString('`fleet_id`=?', $row['fleet_id']); if (array_key_exists('t24', $row) && $row['t24'] === 1) { $where .= $manager->quoteString(' AND `t24`=?', $row['t24']); } $manager->setWhere($where); $record = $manager->selectSingle(); if ($record) { print_r($record); print_r($row); $nDifference = (double) $row['count'] == 0 ? 100 : ($record['count'] - $row['count']) / $row['count'] * 100; print_r('diff: ' . $nDifference . PHP_EOL); if ($nDifference > 50 || $nDifference < -50) { continue; } $manager->setWhere($manager->quoteString('`id`=?', $record['id'])); $manager->update($row); } else { $manager->insert($row); } } }
/** ocdData.php * @package ocdData * @author Feighen Oosterbroek <*****@*****.**> * @copyright 2013 onwards Barloworld Transport Solutions * @license GNU GPL * @link http://www.gnu.org/licenses/gpl.html * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ function ocdData() { //: Preparation $times = substr_count($_SERVER['PHP_SELF'], "/"); $rootaccess = ""; $i = 1; while ($i < $times) { $rootaccess .= "../"; $i++; } defined('BASE') || define("BASE", $rootaccess); include_once BASE . "/basefunctions/localdefines.php"; include_once BASE . "/basefunctions/dbcontrols.php"; include_once BASE . "/basefunctions/baseapis/manapi.php"; include_once BASE . "Maxine/api/maxineapi.php"; require_once BASE . "basefunctions/baseapis/fleetDayHandler.php"; $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA) or die(mysqli_error($link)); $fleetdayobj = new fleetDayHandler(); $fleetlist = (array) array(); $tmp = $fleetdayobj->getIncomeFleets(); foreach ($tmp as $key => $val) { $sorted[$val['maxid']] = $val["name"]; } asort($sorted, SORT_STRING); foreach ($sorted as $key => $val) { $fleetlist[$key] = $sorted[$key]; } unset($sorted); unset($tmp); $sql = (string) 'SELECT `r`.`fleet_id`, `missing_count`, `open_count`, `total_open_count`, `count`, `litres` FROM `refuels` AS `r` INNER JOIN `unauthorized_refuels` AS `u` ON `r`.`fleet_id`=`u`.`fleet_id`'; if (isset($_POST) && isset($_POST['conf']) && $_POST['conf']) { if (isset($_POST['conf']['fleetid']) && $_POST['conf']['fleetid']) { $data = __sanitizeData(array(0 => $_POST['conf']['fleetid'])); $sql .= ' WHERE `r`.`fleet_id`=' . $data[0]; } } $fleetid = (int) (isset($_POST['conf']) && $_POST['conf'] && (isset($_POST['conf']['fleetid']) && $_POST['conf']['fleetid']) ? $_POST['conf']['fleetid'] : 0); $records = sqlQuery($sql); $data = (array) array(); foreach ($records as $val) { $data[$val['fleet_id']] = $val; } unset($records); //: End print '<!DOCTYPE html>'; print '<head>'; print '<meta charset="utf-8">'; print '<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">'; print '<title>Dashboards - Barloworld Transport</title>'; print '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />'; print '<link href="favicon.ico" rel="shortcut icon" />'; print '<link rel="stylesheet" href="' . BASE . 'basefunctions/scripts/bootstrap.min.css">'; print '<link href="' . BASE . 'basefunctions/scripts/font-awesome.min.css" rel="stylesheet">'; print '<link rel="stylesheet" href="' . BASE . 'Maxine/displaycase/content/site/css/fonts.css">'; print '<link rel="stylesheet" href="' . BASE . 'Maxine/displaycase/content/site/css/main.css">'; print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/vendor/modernizr-2.6.2.min.js"></script>'; print '<script src="' . BASE . 'basefunctions/scripts/jquery.min.js"></script>'; print '<script src="' . BASE . 'basefunctions/scripts/jquery.ui.touch-punch.min.js"></script>'; print '<!--[if lt IE 9]>'; print '<script src="' . BASE . 'basefunctions/scripts/html5shiv.min.js"></script>'; print '<script src="' . BASE . 'basefunctions/scripts/respond.js"></script>'; print '<![endif]-->'; print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/vendor/jcircle.js"></script>'; print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/vendor/jquery.flot/jquery.flot.js"></script>'; print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/vendor/jquery.flot/jquery.flot.time.js"></script>'; print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/vendor/jquery.flot/jquery.flot.tooltip.js"></script>'; print '</head>' . PHP_EOL; print '<body>'; print '<div id="root"></div>'; print '<div id="page" style="overflow-y:auto;">'; print '<header>'; print '<div class="controlsWrapper">'; print '<a href="#" class="menu"></a>'; print '</div><!-- controlsWrapper -->'; print '</header>'; print '<nav>'; print '<ul>'; print '<li><a href="/?personal">Dashboard</a></li>'; print '<li><a href="/?mydashdetails">Dashboard Builder</a></li>'; print '<li><a href="/?importfleetday">Import Day</a></li>'; print '<li><a href="/?checkfleetscoreupdates">Fleet Scores</a></li>'; print '<li><a href="/?ocddata">OCD Data</a></li>'; print '<li><a href="/?logout">Logout</a></li>'; print '</ul>'; print '</nav>'; //: Page Content print '<div id="blackouts">'; //: Form print '<div class="fleetWrapper" style="height:10%;">'; print '<form method="POST">'; print '<table><tbody><tr>'; print '<td>'; //: Col 1 print '<label for="conf[fleetid]">Fleet:</label>'; print '<select id="conf[fleetid]" name="conf[fleetid]" value="' . $fleetid . '">'; print '<option value="0" ' . ($fleetid == 0 ? "selected" : "") . '>All</option>'; foreach ($fleetlist as $fleetkey => $fleetval) { if (!$fleetval) { continue; } print '<option value="' . $fleetkey . '"' . ($fleetid == $fleetkey ? ' selected="selected"' : '') . '>' . $fleetval . '</option>'; } print '</select>'; print '</td>'; print '<td>'; //: Col 2 print '<input type="Submit" value="Search" />'; print '</td>'; print '</tr></tbody></table>'; print '</form>'; print '</div>'; print '<div class="fleetWrapper" style="height:90%;">'; print '<table style="margin-bottom:20px;">'; if ($data) { $cols = (array) array('fleet_id' => 'Fleet', 'missing_count' => 'Missing count', 'total_open_count' => 'Total open', 'open_count' => 'Open above fleet limit', 'count' => 'Unauthorized count', 'litres' => 'Litres'); print '<thead><tr>'; foreach ($cols as $key => $val) { print '<td>' . $val . '</td>'; } print '</tr></thead>'; print '<tbody>'; foreach ($fleetlist as $key => $val) { //: Skip rows that do not have an active fleet if (array_key_exists($key, $data) === FALSE) { continue; } $row = $data[$key]; print '<tr>'; foreach ($cols as $key1 => $val1) { print '<td>'; print $key1 == 'fleet_id' ? $val : $row[$key1]; print '</td>'; } print '</tr>'; } print '</tbody>'; } else { print '<tbody><tr><td>No results to show</td></tr></tbody>'; } print '</table>'; print '</div>'; //: End print '</div>'; //: End //: End Page print '<script>window.jQuery || document.write("<script src=\\"' . BASE . 'Maxine/displaycase/content/site/js/vendor/jquery-1.9.1.min.js\\"><\\/script>")</script>'; print '<script src="' . BASE . 'basefunctions/scripts/jquery.color.min.js"></script>'; print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/plugins.js"></script>'; print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/styling.js"></script>'; print '<script src="' . BASE . 'Maxine/displaycase/content/site/js/main.js"></script>'; print '<script type="text/javascript" language="javascript" src="' . BASE . '/basefunctions/scripts/manline.js"></script>'; print '</body>' . PHP_EOL; print '</html>'; }