public function __construct() { $this->dbConnection = Connection::getConnection(); date_default_timezone_set("Africa/Cairo"); // set time zone to local time }
public static function log($action, $details, $userID, $module) { //$module = isset($module) ? $module : $_SESSION['module_number']; try { $query = in_array($details, [3, 4, 5, 6, 7, 8, 9, 10]) ? "(SELECT name FROM templates WHERE templateID = {$details})" : ":details"; $stmt = Connection::getConnection()->prepare("INSERT INTO log " . " (module, action, details, userID, ip_address) " . " VALUES (:module, :action, " . $query . ", :userID, :ip)"); $stmt->bindValue(":module", isset($module) ? $module : $_SESSION['module_number'], PDO::PARAM_INT); $stmt->bindParam(":action", $action, PDO::PARAM_STR); if (!in_array($details, [3, 4, 5, 6, 7, 8, 9, 10])) { $stmt->bindParam(":details", $details, PDO::PARAM_STR); } $stmt->bindValue(":userID", isset($userID) ? $userID : (isset($_SESSION['user']) ? $_SESSION['user']->getID() : NULL), PDO::PARAM_INT); $stmt->bindParam(":ip", $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR); //exit($stmt->queryString); $stmt->execute(); } catch (\PDOException $e) { // send mail to admin exit($e); } }
public static function getUser($userID) { try { $sql = "SELECT `userID`, `name`, `emailAddress` AS email, `username`, `celNumber` AS cell, `position` " . "FROM user " . "WHERE userID = :userID OR emailAddress = :email"; $query = Connection::getConnection()->prepare($sql); $query->bindValue(":userID", $userID, PDO::PARAM_INT); $query->bindValue(":email", $userID, PDO::PARAM_STR); if ($query->execute() && ($user = $query->fetch(PDO::FETCH_OBJ))) { // implicit declaration of $user return ["success" => true, "user" => $user]; } return ["success" => false, "exception" => "Internal error occurred. Could not fetch user."]; } catch (\PDOException $e) { return ["success" => false, "exception" => $e]; } }