/** * * @param string $name * @param bool $instance * @return object|null Object or NULL * @throws Exception */ public static function core($name, $instance = TRUE) { $core_name = ucfirst($name); if (!class_exists($core_name)) { try { $path = APP_DIR . '/core/' . $core_name . '.php'; if (file_exists($path)) { require $path; if ($instance === TRUE) { $exclude_instance = array('View', 'Layout'); if (in_array($core_name, $exclude_instance)) { return NULL; } $instance_name = $core_name == 'Database' ? 'DB' : $core_name; return new $instance_name(); } } else { throw new Exception('Core not found: ' . $core_name); } } catch (Exception $e) { logMessage('error', $e->getMessage(), TRUE); showError($e->getMessage(), 'Error: Loader', 500); } } return NULL; }
private function sendReport($get_parameters, $post_parameters) { if (extension_loaded("curl")) { // create a new cURL resource $ch = curl_init(); $url = INSTALL_REPORT_URL . '?' . http_build_query($get_parameters); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); //curl_setopt($ch, CURLOPT_HTTPGET, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_parameters); // grab URL and pass it to the browser $result = curl_exec($ch); if (!$result) { logMessage(L_ERROR, 'Failed sending install report ' . curl_error($ch)); } else { logMessage(L_INFO, 'Sending install report'); } // close cURL resource, and free up system resources curl_close($ch); } }
function startSQLSession() { global $globalLink; if (!empty($globalLink)) { return $globalLink; } $link = mysql_connect(HOST, USER, PASSWORD); if ($link) { $db_selected = mysql_select_db(DATABASE, $link); if (!$db_selected) { logMessage(__FUNCTION__ . " - IMPOSSIBLE DE SE CONNECTER A LA DATABASE", LOG_LEVEL_ERROR); } } else { logMessage(__FUNCTION__ . " - IMPOSSIBLE DE SE CONNECTER AU SERVEUR SQL : " . mysql_error(), LOG_LEVEL_ERROR); //////////////////////////////////////////////////////////////// sleep(10); $link = mysql_connect(HOST, USER, PASSWORD); if ($link) { $db_selected = mysql_select_db(DATABASE, $link); if (!$db_selected) { logMessage(__FUNCTION__ . " - IMPOSSIBLE DE SE CONNECTER A LA DATABASE", LOG_LEVEL_ERROR); } } //////////////////////////////////////////////////////////////// } $globalLink = $link; return $link; }
public function update() { // validation check if (!is_null($this->desirePercent)) { if ($this->desirePercent > 100.0) { $this->desirePercent = 100.0; } if ($this->desirePercent < 0.0) { $this->desirePercent = 0.0; } $this->desirePercent = round($this->desirePercent); } // now onto the update try { $dbh = getPDOConnection(); $dbh->beginTransaction(); $stmt = $dbh->prepare("UPDATE shiftpreference SET desirePercent = ? " . " WHERE workerid = ? AND jobid = ?"); $stmt->execute(array($this->desirePercent, $this->workerid, $this->jobid)); $dbh->commit(); return $this; } catch (PDOException $pe) { logMessage('ShiftPreference::update()', $pe->getMessage()); throw $pe; } }
public function logWorkerListState($message, $note) { logMessage($message, $note); foreach ($this->workerList as $worker) { $worker->logState($message); } }
public function test($value, $expected, $testName) { if ($value != $expected) { failed("{$testName} - Expected '{$expected}', Got: '{$value}'"); } else { logMessage(" Passed: {$testName} - value '{$value}'"); } }
function executeRCommand($rInstanceScreenName, $command, $markInstanceAsAvailable = 1) { if ($markInstanceAsAvailable == 1) { $command = $command . "mark.as.available();"; } $cmd = 'screen -L -S ' . $rInstanceScreenName . ' -p 0 -X stuff "' . $command . "\n" . '"'; logMessage(" - " . $command); shell_exec($cmd); }
/** * used both internally, and to send any arbitrary mail. * See notes on WorkerViewPage */ public static function send($to, $subject, $body) { try { $headers = 'From: support@consked.com' . "\r\n" . 'Reply-To: support@consked.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $body, $headers); } catch (Exception $ex) { logMessage('FormMail.send(' . $to . ')', $ex->getMessage()); } }
public function addJob(JobSchedule $job, $expoId, $override = FALSE) { if (array_key_exists($job->jobid, $this->jobList)) { return; } // already added if (!$override) { $expo = Expo::selectID($expoId); $preference = $this->jobPreferences[$job->jobid]; if (is_null($preference->desirePercent)) { $job->subWorker($this, $expoId, TRUE); // we may have added it throw new ScheduleImpossibleException("Worker:" . $this->workerid . " cannot work in Job:" . $job->jobid); } $newJobMinutes = $this->jobMinutes + $job->jobMinutes(); if ($newJobMinutes > $this->maxMinutes) { $job->subWorker($this, $expoId, TRUE); // we may have added it throw new ScheduleOverMaxHoursException("Worker:" . $this->workerid . " cannot work in Job:" . $job->jobid . " as will have total minutes above max:" . ($newJobMinutes - $this->maxMinutes)); } if ($newJobMinutes > 60 * $expo->expoHourCeiling) { $job->subWorker($this, $expoId, TRUE); // we may have added it throw new ScheduleOverMaxHoursException("Worker:" . $this->workerid . " cannot work in Job:" . $job->jobid . " as will have total minutes above expo max:" . ($newJobMinutes - 60 * $expo->expoHourCeiling)); } foreach ($this->jobList as $existing) { if ($job->isTimeConflict($existing)) { if ($expo->allowScheduleTimeConflict) { logMessage("WorkerSchedule", "overlapping conflict allowed"); if ($job->isStartTimeConflict($existing)) { $job->subWorker($this, $expoId, TRUE); // we may have added it $sce = new ScheduleConflictException("Worker:" . $this->workerid . " cannot work in Job:" . $job->jobid . " due to identical start time conflict with existing Job:" . $existing->jobid); $sce->conflict = $existing; logMessage("WorkerSchedule", $sce); throw $sce; } } else { $job->subWorker($this, $expoId, TRUE); // we may have added it $sce = new ScheduleConflictException("Worker:" . $this->workerid . " cannot work in Job:" . $job->jobid . " due to conflict with existing Job:" . $existing->jobid); $sce->conflict = $existing; logMessage("WorkerSchedule", $sce); throw $sce; } // allowScheduleTimeConflict } } // $existing } // $override $this->jobList[$job->jobid] = $job; $this->jobMinutes += $job->jobMinutes(); $job->addWorker($this, $expoId, $override); // must be at very end return; }
function addHistory($idMember, $type, $filename = "") { $createdDate = getCurrentDateSQLFormat(); $sqlQuery = "INSERT INTO qcs_history (idMember, createdDate , type , filename) VALUES('" . $idMember . "' , '" . $createdDate . "' , '" . $type . "' , '" . $filename . "'" . ")"; // echo $sqlQuery . "<br/>"; logMessage(__FUNCTION__ . " - " . $sqlQuery, LOG_LEVEL_DEBUG); $sqlLink = startSQLSession(); $result = mysql_query($sqlQuery); closeSQLSession($sqlLink); }
public function assignWorker(WorkerSchedule $worker, $expoId) { if (0 == count($this->jobList)) { return; } // jobs in preference order $myJobList = $worker->sortJobPreference($this->jobList, FALSE); // first get locations in preference order $locations = array(); foreach ($myJobList as $job) { if (!in_array($job->location, $locations)) { $locations[] = $job->location; } } // $job // next reorder jobs ... order by preference group by location! $groupByLocation = array(); foreach ($locations as $location) { foreach ($myJobList as $job) { if (0 == strcmp($job->location, $location)) { $groupByLocation[] = $job; } } // $job } // $location $myJobList = NULL; $locations = NULL; $lockLocation = NULL; logMessage("LocationLock", "assigning workerid:" . $worker->workerid . " count(gbl):" . count($groupByLocation)); foreach ($groupByLocation as $job) { try { logMessage("LocationLock - isnull?", "jobid:" . $job->jobid . " in try "); if (!is_null($lockLocation)) { logMessage("LocationLock - strcmp", "lockLocation:" . $lockLocation . " after is_null " . $job->location); if (0 != strcmp($lockLocation, $job->location)) { logMessage("LocationLock - break", "jobid:" . $job->jobid . " lockLocation:" . $lockLocation . " before break "); break; // leave loop } } logMessage("LocationLock - addwprler", "jobid:" . $job->jobid . " worker:" . $worker->workerid); $job->addWorker($worker, $expoId); // exception leaves $lockLocation NULL logMessage("LocationLock - set lockLocation", "job->location:" . $job->location); $lockLocation = $job->location; } catch (ScheduleException $se) { logMessage("LocationLock failure", $job->jobid . " " . $se->getMessage()); continue; // do not force } } // $job $groupByLocation = NULL; }
function groupInfo($key) { global $debug; $result = rest("get_group_profile", "group={$key}"); if ($result == null) { logMessage('sl', 0, "Error retrieving group profile for {$key}", null, null); return null; } $xml = new SimpleXMLElement($result); return $xml->groupprofile->name . "," . $xml->groupprofile->insignia . "," . $xml->groupprofile->maturepublish . "," . $xml->groupprofile->charter; }
private static function select($sql, $params) { try { $rows = simpleSelect("ShiftAssignmentView", $sql, $params); foreach ($rows as $row) { $row->fixDates(); } return $rows; } catch (PDOException $pe) { logMessage('ShiftAssignmentView::select(' . $sql . ', ' . var_export($params, true) . ')', $pe->getMessage()); } }
function dbConnect() { $dbserver = "localhost"; $dbuser = "******"; $dbpass = "******"; $dbname = "naboor"; $myDB = new mysqli($dbserver, $dbuser, $dbpass, $dbname); if ($myDB->connect_errno > 0) { logMessage("Connection failed on DB " . $dbname); } return $myDB; }
/** * used both internally, and to send any arbitrary mail. * See notes on WorkerViewPage */ public static function send($to, $subject, $body) { try { $headers = 'From: support@consked.com' . "\r\n" . 'Reply-To: support@consked.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); //echo("<pre>to: ");print_r($to);echo("</pre>"); //echo("<pre>subject: ");print_r($subject);echo("</pre>"); //echo("<pre>body: ");print_r($body);echo("</pre>"); //echo("<pre>headers: ");print_r($headers);echo("</pre>"); mail($to, $subject, $body, $headers); } catch (Exception $ex) { logMessage('FormMail.send(' . $to . ')', $ex->getMessage()); } }
public function update() { try { $dbh = getPDOConnection(); $dbh->beginTransaction(); $stmt = $dbh->prepare("UPDATE jobpreference SET job1 = ?, job2 = ?, job3 = ?, job4 = ?, job5 = ?, job6 = ?, job7 = ?, job8 = ?, job9 = ?, job10 = ?, " . "job11 = ?, job12 = ?, job13 = ?, job14 = ?, job15 = ?, job16 = ?, job17 = ?, job18 = ?, job19 = ?, job20 = ? " . "WHERE workerid = ?"); $stmt->execute(array($this->job1, $this->job2, $this->job3, $this->job4, $this->job5, $this->job6, $this->job7, $this->job8, $this->job9, $this->job10, $this->job11, $this->job12, $this->job13, $this->job14, $this->job15, $this->job16, $this->job17, $this->job18, $this->job19, $this->job20, $this->workerid)); $dbh->commit(); return $this; } catch (PDOException $pe) { logMessage('JobPreference::update()', $pe->getMessage()); } }
public function delete() { try { $dbh = getPDOConnection(); $dbh->beginTransaction(); $stmt = $dbh->prepare("DELETE FROM jobtitle WHERE expoid = ? AND jobtitle = ?"); $stmt->execute(array($this->expoid, $this->jobTitle)); $dbh->commit(); return $this; } catch (PDOException $pe) { logMessage('JobTitle::delete()', $pe->getMessage()); } }
private static function tableSchema($table) { $sql = "DESCRIBE {$table}"; try { $dbh = getPDOConnection(); $stmt = $dbh->prepare($sql); $stmt->execute(); return $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $pe) { logMessage("Report::tableSchema({$table})", $pe->getMessage()); return array(); } }
public function update() { try { $dbh = getPDOConnection(); $dbh->beginTransaction(); $stmt = $dbh->prepare("UPDATE timepreference SET shift1 = ?, shift2 = ?, shift3 = ?, shift4 = ?, shift5 = ?, shift6 = ?, shift7 = ?, shift8 = ?, shift9 = ? , shift10 = ?, " . "shift11 = ?, shift12 = ?, shift13 = ?, shift14 = ?, shift15 = ?, shift16 = ?, shift17 = ?, shift18 = ?, shift19 = ?, shift20 = ? " . "WHERE workerid = ?"); $stmt->execute(array($this->shift1, $this->shift2, $this->shift3, $this->shift4, $this->shift5, $this->shift6, $this->shift7, $this->shift8, $this->shift9, $this->shift10, $this->shift11, $this->shift12, $this->shift13, $this->shift14, $this->shift15, $this->shift16, $this->shift17, $this->shift18, $this->shift19, $this->shift20, $this->workerid)); $dbh->commit(); return $this; } catch (PDOException $pe) { logMessage('TimePreference::update()', $pe->getMessage()); } }
public static function insert($date) { try { $dbh = getPDOConnection(); $dbh->beginTransaction(); $stmt = $dbh->prepare("INSERT INTO remindersent (date) VALUES (?)"); $stmt->execute(array($date)); $dbh->commit(); return; } catch (PDOException $pe) { logMessage('ReminderSend::insert(' . $date . ')', $pe->getMessage()); } }
function doUpdate($sql) { global $debugdb; if ($debugdb) { logMessage('db', 3, "SQL - " . $sql); } $conn = getConn(); $result = $conn->query($sql); if (DB::isError($result)) { logMessage('db', 0, "Query Error " . $result->getMessage(), null, null); genPipeError('db'); } return $conn->affectedrows(); }
function call($url, $xmlFormat = true) { logMessage('call ' . $url); $result = file_get_contents($url); if ($result === false) { logMessage('call failed'); } else { if ($xmlFormat) { $xml = new SimpleXMLElement($result); return $xml; } else { return $result; } } }
function checkLoginAndPassword($username, $password) { // echo "password = "******"<br/>"; $password = getMD5($username, $password); // echo "password MD5 = " . $password . "<br/>"; $sqlQuery = "SELECT username FROM qcs_users WHERE username = '******' AND password = '******'"; logMessage(__FUNCTION__ . " - " . $sqlQuery, LOG_LEVEL_DEBUG); $sqlLink = startSQLSession(); $result = mysql_query($sqlQuery, $sqlLink); closeSQLSession($sqlLink); $login = ''; if (mysql_num_rows($result) == 1) { $line = mysql_fetch_assoc($result); $login = $line['username']; } return $login; }
public function assignSchedule($expoId) { if (0 == count($this->jobList) || 0 == count($this->workerList)) { return; } $this->assignAll($expoId); logMessage("AssignAndSubtract->assignSchedule({$expoId})", "assignAll({$expoId})"); $this->removeObvious($expoId); logMessage("AssignAndSubtract->assignSchedule({$expoId})", "removeObvious({$expoId})"); $this->replaceOverMax($expoId); $this->replaceOverMax($expoId); // we call a second time as the lists have changed logMessage("AssignAndSubtract->assignSchedule({$expoId})", "replaceOverMax({$expoId})"); $this->assignUnderEmployed($expoId); logMessage("AssignAndSubtract->assignSchedule({$expoId})", "assignUnderEmployed({$expoId})"); // here we would begin to swap unhappy people until happiness doesn't change return; }
/** * * @static * @param string $file * @return void */ public static function load($file = 'config') { try { $path = APP_DIR . '/config/' . $file . '.php'; if (file_exists($path)) { require $path; if (isset($config) and is_array($config) and !empty($config)) { foreach ($config as $key => $value) { self::set($key, $value, $file); } } else { throw new Exception('Config file not found: ' . $path); } } } catch (Exception $e) { logMessage('error', $e->getMessage(), TRUE); showError($e->getMessage(), 'Error: Config', 500); } }
function installationFailed($what_happened, $description, $what_to_do, $cleanup = false) { global $report, $installer, $app, $db_params, $user; if (isset($report)) { $report->reportInstallationFailed($what_happened . "\n" . $description); } if (!empty($what_happened)) { logMessage(L_USER, $what_happened); } if (!empty($description)) { logMessage(L_USER, $description); } if ($cleanup) { $leftovers = $installer->detectLeftovers(true, $app, $db_params); if (isset($leftovers) && $user->getTrueFalse(null, "Do you want to cleanup?", 'y')) { $installer->detectLeftovers(false, $app, $db_params); } } if (!empty($what_to_do)) { logMessage(L_USER, $what_to_do); } die(1); }
public static function assignAsYouGo(Expo $expo, Worker $worker) { if ($expo->scheduleAssignAsYouGo) { $workerList = NULL; $stationList = NULL; $assignmentList = NULL; try { // needed for all $workerList = WorkerSchedule::selectExpo($expo->expoid); $stationList = JobSchedule::selectExpo($expo->expoid); $assignmentList = ShiftAssignment::selectExpo($expo->expoid); } catch (PDOException $ex) { logMessage("FirstComeFirstServed", "assignAsYouGo(" . $expo->titleString() . ", " . $worker->email . ") - " . $ex->getMessage()); return; } foreach ($workerList as $w) { if ($w->workerid == $worker->workerid) { $worker = $w; break; } } // $w $aas = new FirstComeFirstServed($expo->expoid, $stationList, $workerList, $assignmentList, TRUE); $stationList = NULL; $assignmentList = NULL; $workerList = NULL; $d1 = new DateTime(); logMessage("FirstComeFirstServed", "**** assignSchedule(" . $expoId . ") ****", $d1->format('H:i'), "\n"); $aas->assignWorker($worker, $expoId); $d2 = new DateTime(); logMessage("FirstComeFirstServed", "****assignSchedule(" . $expoId . ") ****", $d2->format('H:i'), " elapsed: ", $d2->getTimestamp() - $d1->getTimestamp(), "\n"); // $aas->logJobListState("FirstComeFirstServed", "jobs after assignment"); // $aas->logWorkerListState("FirstComeFirstServed", "workers after assignment"); AbstractScheduler::commitSchedule($expo->expoid, TRUE, $aas->getSchedule()); } return; }
function getGridStatus() { $url = "http://www.secondlife.com/status"; if (!@($web = file($url))) { logMessage('sl', 0, 'Error looking up grid status', null, null); return "Unknown"; } if (!$web) { logMessage('sl', 0, 'Error looking up grid status', null, null); return "Unknown"; } $data = implode("", $web); $findme = 'Open'; preg_match_all("/<h3>([^`]*?)<\\/h3>/", $data, $matches); $result = $matches[0][0]; //Force a fake "SL Grid is closed result for testing //$result = "Second life is offline"; $pos = strpos($result, $findme); if ($pos == FALSE) { return "Closed"; } else { return "Open"; } }
function getErrorMessage($name) { $clientName = $_FILES[$name]['name']; if (UPLOAD_ERR_OK == $_FILES[$name]['error']) { return "Your file, {$clientName}, uploaded correctly."; } else { if (UPLOAD_ERR_INI_SIZE == $_FILES[$name]['error'] || UPLOAD_ERR_FORM_SIZE == $_FILES[$name]['error']) { return "Your file, {$clientName}, is too big for the server to handle."; } else { if (UPLOAD_ERR_NO_FILE == $_FILES[$name]['error']) { return "Please specify a file to upload."; } } } // else $error = ""; if (UPLOAD_ERR_PARTIAL == $_FILES[$name]['error']) { $error = "The uploaded file was only partially uploaded."; } else { if (UPLOAD_ERR_NO_TMP_DIR == $_FILES[$name]['error']) { $error = "Missing a temporary folder."; } else { if (UPLOAD_ERR_CANT_WRITE == $_FILES[$name]['error']) { $error = "ailed to write file to disk."; } else { if (UPLOAD_ERR_EXTENSION == $_FILES[$name]['error']) { $error = "A PHP extension stopped the file upload."; } else { $error = "error unknown, code:" . $_FILES[$name]['error']; } } } } logMessage("FileUpload.php - getErrorMessage({$name})", "error:{$error}"); return "Your file did not upload correctly, please try again."; }
function logError($message) { logMessage("ERROR", $message); }