function getAllDispatcherOfficeHours() { $db = DB::getInstance(); $Dispatcher_hours = $db->prep_execute('SELECT * FROM Dispatcher_hours;', array()); // Global list of user & course objects. Prevents unnecessary DB reads. global $users, $courses; // Array of user - course object pair mappings to be returned. $return = array(); // Loop through all Driver - course key mappings foreach ($Dispatcher_hours as $row) { // Read user from DB and add to user array if not found in array if (!isset($users[$row['email']])) { $users[$row['email']] = USER::fromDatabase($row['email']); } // Read course from DB and add to user array if not found in array if (!isset($courses[$row['subj'] . '-' . $row['crse']])) { $courses[$row['subj'] . '-' . $row['crse']] = COURSE::fromDatabase($row['subj'], intval($row['crse'])); } // Add Driver - course object pair to return array $return[] = ['user' => $users[$row['email']], 'course' => $courses[$row['subj'] . '-' . $row['crse']], 'week_day' => $row['week_day'], 'startTime' => $row['start_time'], 'endTime' => $row['end_time']]; } return $return; }
if (isset($_POST['register'])) { $empty = empty($_POST['firstName']) || empty($_POST['lastName']) || empty($_POST['email']) || empty($_POST['password']) || empty($_POST['isDriver']) || empty($_POST['isDispatcher']) || empty($_POST['isfirstTime']); if (isset($_POST['firstName'], $_POST['lastName'], $_POST['email'], $_POST['password'], $_POST['isDriver'], $_POST['isDispatcher'], $_POST['isfirstTime']) && $empty == false) { $firstName = mysql_real_escape_string(stripslashes($_POST['firstName'])); $lastName = mysql_real_escape_string(stripslashes($_POST['lastName'])); $email = mysql_real_escape_string(stripslashes($_POST['email'])); $password = mysql_real_escape_string(stripslashes($_POST['password'])); $isDriver = mysql_real_escape_string(stripslashes($_POST['isDriver'])); $isDispatcher = mysql_real_escape_string(stripslashes($_POST['isDispatcher'])); $isfirstTime = mysql_real_escape_string(stripslashes($_POST['isfirstTime'])); // Transforms strings into boolean values $isDriver = $isDriver === 'true' ? true : false; $isDispatcher = $isDispatcher === 'true' ? true : false; $isfirstTime = $isfirstTime === 'true' ? true : false; // If user in database if (USER::fromDatabase($email) !== null) { echo 1; } else { $user = User::withValues($email, $password, $isDriver, $isDispatcher, $isfirstTime, false, $firstName, $lastName); //var_dump($user); if ($user === null) { //check if error instantiating user (password too short) echo 0; } else { $user->store(); $user->login($password); echo 2; } } } }
public static function getAllDispatchers() { $allDispatchers = array(); $db = DB::getInstance(); $Dispatcher_rows = $db->prep_execute('SELECT email FROM users WHERE isDispatcher = 1;', array()); foreach ($Dispatcher_rows as $row) { $allDispatchers[] = USER::fromDatabase($row['email']); } return $allDispatchers; }