/** Learners::cascadeDelete($id)
  * @param $id integer record pointer
  * @return true on success false otherwise
  */
 public function cascadeDelete($id)
 {
     foreach ($this->_children as $key => $val) {
         $opts = (array) array();
         $opts['table'] = $val['table'];
         $opts['fields']['deleted'] = time();
         $opts['where'] = 'learnerid=' . $id;
         if (($update = sqlCommit($opts)) === false) {
             throw new man_exception('Could not successfully query the database on line: ' . __LINE__ . ' of file: ' . __FILE__);
         }
     }
     $opts = (array) array();
     $opts['table'] = $this->_name;
     $opts['fields']['deleted'] = time();
     $opts['where'] = 'id=' . $id;
     return sqlCommit($opts);
 }
<?php

// include config with database definition
include '../config.php';
// input parameter is element to delete (suppress errors by adding a @ sign)
$p = @$_REQUEST['p'];
// explode input parameters:
// 0 - $sub_id - subject id
// 1 - $tbl1   - target table index
// 2 - $row1   - target row
// 3 - $col1   - target column
// 4 - $tbl0   - source table index
// 5 - $row0   - source row
// 6 - $col0   - source column
list($sub_id, $tbl1, $row1, $col1, $tbl0, $row0, $col0) = explode('_', $p);
// discard clone id part from the sub_id
$sub_id = substr($sub_id, 0, 2);
// if source table is 0 (element is dragged from "subject" table and dropped to the "timetable") then it should be inserted to the table
if ($tbl0 == 0) {
    sqlQuery("insert into redips_timetable (sub_id, tbl_row, tbl_col) values ('{$sub_id}', {$row1}, {$col1})");
} else {
    sqlQuery("update redips_timetable set tbl_row={$row1}, tbl_col={$col1} where sub_id='{$sub_id}' and tbl_row={$row0} and tbl_col={$col0}");
}
// commit transaction (sqlCommit is function from config.php)
sqlCommit();
// no cache
header('Pragma: no-cache');
// HTTP/1.1
header('Cache-Control: no-cache, must-revalidate');
// date in the past
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
Exemple #3
0
function commitRightsGroup($config)
{
    $data["name"] = $config["name"];
    $data["description"] = $config["desc"];
    if ($config["groupid"]) {
        sqlCommit(array("table" => "rights_groups", "where" => "id=" . $config["groupid"], "fields" => $data));
    } else {
        sqlCreate(array("table" => "rights_groups", "fields" => $data));
    }
}
 /** refuel($test = FALSE)
  * get open and missing refuel data
  * @param BOOL $test is this a request for test platform?
  * @return TRUE on success. FALSE otherwise
  */
 public function refuel($test = FALSE)
 {
     $fleets = $this->_incomefleets;
     $data = (array) array();
     foreach ($fleets as $val) {
         $data[$val['maxid']]['fleet_id'] = $val['maxid'];
         if (array_key_exists('fleets', $val)) {
             $sql = (string) 'SELECT SUM(`fleet_count`) AS `fleet_count`, SUM(`missing_count`) AS `missing_count`, SUM(`open_count`) AS `open_count`, SUM(`total_open_count`) AS `total_open_count` ';
             $sql .= 'FROM `refuels` ';
             $fleetsToLoop = (array) array();
             foreach ($val['fleets'] as $ook) {
                 $fleetsToLoop[] = $ook[0];
             }
             $sql .= 'WHERE `fleet_id` IN(' . implode($fleetsToLoop, ',') . ')';
             $row = sqlQuery($sql);
             if ($row === FALSE) {
                 continue;
             }
             $data[$val['maxid']]['fleet_count'] = $row[0]['fleet_count'];
             $data[$val['maxid']]['missing_count'] = $row[0]['missing_count'];
             $data[$val['maxid']]['open_count'] = $row[0]['open_count'];
             $data[$val['maxid']]['total_open_count'] = $row[0]['total_open_count'];
         } else {
             //: Get fleet count
             $trucks = $this->_apiurl . "report=145&responseFormat=csv&Fleet=" . $val['maxid'] . "&Start%20Date=" . date("Y-m-d") . "&Stop%20Date=" . date("Y-m-d", strtotime("+1 day"));
             if ($test === TRUE) {
                 $trucks = preg_replace('/https\\:\\/\\/login\\.max\\.bwtsgroup\\.com/', 'http://max.mobilize.biz', $trucks);
             }
             $fileParser = new FileParser($trucks);
             $fileParser->setCurlFile("trucks." . $val['maxid'] . ".csv");
             $trucks = $fileParser->parseFile();
             if ($trucks === FALSE) {
                 print "<pre style='font-family:verdana;font-size:13'>";
                 print_r($fileParser->getErrors());
                 print "</pre>";
                 return FALSE;
             }
             if (is_array($trucks) === FALSE) {
                 return FALSE;
             }
             $data[$val['maxid']]['fleet_count'] = count($trucks);
             //: End
             $refuels = $this->_apiurl . "report=175&responseFormat=csv&Fleet=" . $val['maxid'] . "&Start%20Date=" . date("Y-m-d", strtotime('-30 days')) . "&Stop%20Date=" . date("Y-m-01", strtotime("+1 month"));
             if ($test === TRUE) {
                 $refuels = preg_replace('/https\\:\\/\\/login\\.max\\.bwtsgroup\\.com/', 'http://max.mobilize.biz', $refuels);
             }
             print $refuels . PHP_EOL;
             $fileParser = new FileParser($refuels);
             $fileParser->setCurlFile("missingrefuels" . $val['maxid'] . ".csv");
             $missingrefuels = $fileParser->parseFile();
             if ($missingrefuels === FALSE) {
                 print "<pre style='font-family:verdana;font-size:13'>";
                 print_r($fileParser->getErrors());
                 print "</pre>";
                 return FALSE;
             }
             if (is_array($missingrefuels) === FALSE) {
                 return FALSE;
             }
             // print_r($missingrefuels);
             $i = (int) 0;
             //: Missing Refuels
             foreach ($missingrefuels as $key => $value) {
                 //: Checks
                 if ($val['maxid'] == 73) {
                     print_r($value);
                 }
                 if ($value['Odometer'] === '(none)' || $value['Odometer'] === '') {
                     continue;
                 }
                 if (substr($value['Variance'], 0, 1) !== '-') {
                     continue;
                 }
                 //: End
                 if ($value['Variance'] * -1 >= $val['kms_limit']) {
                     $i++;
                 }
             }
             $data[$val['maxid']]['missing_count'] = $i;
             //: End
             //: Open Refuels
             $refuels = $this->_apiurl . "report=174&responseFormat=csv&Fleet=" . $val['maxid'] . "&Start%20Date=" . date("Y-m-d", strtotime('-30 days')) . "&Stop%20Date=" . date("Y-m-01", strtotime("+1 month"));
             if ($test === TRUE) {
                 $refuels = preg_replace('/https\\:\\/\\/login\\.max\\.bwtsgroup\\.com/', 'http://max.mobilize.biz', $refuels);
             }
             print $refuels . PHP_EOL;
             $fileParser = new FileParser($refuels);
             $fileParser->setCurlFile("openrefuels" . $val['maxid'] . ".csv");
             $openrefuels = $fileParser->parseFile();
             if ($openrefuels === FALSE) {
                 print "<pre style='font-family:verdana;font-size:13'>";
                 print_r($fileParser->getErrors());
                 print "</pre>";
                 return FALSE;
             }
             if (is_array($openrefuels) === FALSE) {
                 return FALSE;
             }
             // print_r($openrefuels);
             $cnt = (int) 0;
             foreach ($openrefuels as $key => $value) {
                 //: Convert the refuel time difference into seconds
                 $refuel_time = (int) 0;
                 $split = preg_split('/\\s/', $value['Duration Open (Refuel Time)']);
                 if (array_key_exists(0, $split)) {
                     if (substr($split[0], -1, 1) === 'd') {
                         //: Days
                         $refuel_time += 24 * 60 * 60 * (int) $split[0];
                     } else {
                         //: Hours
                         $refuel_time += 60 * 60 * (int) $split[0];
                     }
                 }
                 if (array_key_exists(1, $split)) {
                     //: Hours
                     $refuel_time += 60 * 60 * (int) $split[0];
                 }
                 // print('refuel time: '.$refuel_time.PHP_EOL);
                 if ($refuel_time >= $val['open_time']) {
                     $cnt++;
                 }
                 //: End
             }
             $data[$val['maxid']]['total_open_count'] = count($openrefuels);
             $data[$val['maxid']]['open_count'] = $cnt;
             //: End
         }
     }
     foreach ($data as $key => $val) {
         $record = sqlPull(array("table" => "refuels", "where" => "fleet_id=" . $key, "customkey" => "fleet_id"));
         if (array_key_exists($key, $record) && $record[$key]) {
             sqlCommit(array("table" => "refuels", "where" => "fleet_id=" . $key, "fields" => $val));
         } else {
             sqlCreate(array("table" => "refuels", "fields" => $val));
         }
         print '|';
     }
 }
    }
    $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA);
    foreach ($t24Budget as $fleet => $data) {
        foreach ($data as $day) {
            // print_r($day);
            $sql = (string) "SELECT * FROM `fleet_scores` WHERE `fleetid`=" . $day["fleetid"] . " AND `date`=" . $day["date"];
            //print($sql);exit;
            if ($result = $mysqli->query($sql)) {
                $record = (array) array();
                while ($obj = $result->fetch_array()) {
                    foreach ($obj as $key => $val) {
                        if (is_int($key) === TRUE) {
                            unset($obj[$key]);
                        }
                    }
                    $record = $obj;
                }
                /* free result set */
                $result->close();
            }
            // print_r($record);
            if (isset($record) && $record) {
                //: Update
                sqlCommit(array("table" => "fleet_scores", "where" => "id=" . $record["id"], "fields" => $day));
            } else {
                sqlCreate(array("table" => "fleet_scores", "fields" => $day));
            }
        }
    }
}
//: End
 public function saveFleetDay($fleetscore)
 {
     // Create or commit records to database {
     $record = sqlPull(array("table" => "fleet_scores", "where" => "date=" . $this->_date, "customkey" => "fleetid"));
     $check = (array) array("income", "contrib", "kms", "budget", "budgetcontrib", "budkms");
     foreach ($fleetscore as $fleetkey => $fleetval) {
         if ($record[$fleetkey]) {
             if ($this->confirmFleetScoreData($record[$fleetkey], $fleetval) === FALSE) {
                 continue;
             }
             //sqlDelete(array("table"=>"fleet_scores", "where"=>"fleetid=".$fleetkey." AND day=".$this->_day));
             //sqlCreate(array("table"=>"fleet_scores", "fields"=>$fleetval));
             sqlCommit(array("table" => "fleet_scores", "where" => "fleetid=" . $fleetkey . " AND date=" . $this->_date, "fields" => $fleetval));
         } else {
             sqlCreate(array("table" => "fleet_scores", "fields" => $fleetval));
         }
     }
     // }
 }
Exemple #7
0
 /** Table::update($where, $data, $options)
 		* @param $where string standar sql where statement
 		* @param $data array array data to be inserted into the database
 		* @param $options array array options to be passed to sqlCreate
 		* @return true|array data on success false otherwise
 		* @example $users = new Users();
 							 $users->update('firstname like "%john%"', array('name'=>'sdf'), array('record'=>true));
 	*/
 public function update($where, array $data, array $options = array())
 {
     foreach ($data as $key => $val) {
         if (!in_array($key, $this->_cols)) {
             unset($data[$key]);
         }
     }
     $opts = (array) array();
     $opts['table'] = $this->_name;
     $opts['fields'] = $data;
     $opts['where'] = $where;
     if (sqlCommit($opts) === false) {
         return false;
     } else {
         if ($options['record']) {
             return sqlPull(array('table' => $this->_name, 'where' => $where));
         }
         return true;
     }
 }