function testdbMasterScheduleModule() { //creates MasterScheduleEntries to insert to database $entry1 = new MasterScheduleEntry("house", "Wed", "odd", "1-5", 2, "", "I do not know what Lin means"); $entry2 = new MasterScheduleEntry("house", "Tue", "even", "1-5", 3, "", "Yay kitchen shift!"); $entry3 = new MasterScheduleEntry("house", "Wed", "even", "1-5", 2, "", ""); $entry4 = new MasterScheduleEntry("house", "Fri", "odd", "1-5", 4, "", "Best job ever."); //tests the insert function $this->assertTrue(insert_dbMasterSchedule($entry1)); $this->assertTrue(insert_dbMasterSchedule($entry2)); $this->assertTrue(insert_dbMasterSchedule($entry3)); $this->assertTrue(insert_dbMasterSchedule($entry4)); //tests the retrieve function $this->assertEqual(retrieve_dbMasterSchedule($entry2->get_id())->get_day(), $entry2->get_day()); $this->assertEqual(retrieve_dbMasterSchedule($entry2->get_id())->get_hours(), $entry2->get_hours()); $this->assertEqual(retrieve_dbMasterSchedule($entry2->get_id())->get_venue(), $entry2->get_venue()); $this->assertEqual(retrieve_dbMasterSchedule($entry2->get_id())->get_week_no(), $entry2->get_week_no()); $this->assertEqual(retrieve_dbMasterSchedule($entry2->get_id())->get_slots(), $entry2->get_slots()); $this->assertEqual(retrieve_dbMasterSchedule($entry2->get_id())->get_id(), $entry2->get_id()); //tests the update function $entry3->set_notes("This is a new note"); $this->assertTrue(update_dbMasterSchedule($entry3)); $this->assertEqual(retrieve_dbMasterSchedule($entry3->get_id())->get_notes(), "This is a new note"); //tests the delete function $this->assertTrue(delete_dbMasterSchedule($entry1->get_id())); $this->assertTrue(delete_dbMasterSchedule($entry2->get_id())); $this->assertTrue(delete_dbMasterSchedule($entry3->get_id())); $this->assertTrue(delete_dbMasterSchedule($entry4->get_id())); echo "testdbMasterSchedule complete"; }
function test_update_dbMasterSchedule() { $new_MasterScheduleEntry = new MasterScheduleEntry("monthly", "Wed", "odd", 14, 17, 2, "joe2071234567,sue2079876543", "This is a super fun shift.", "Afternoon Shift"); // not sure what the id looks like echo 'will test update_dbMasterSchedule </br>'; $new_MasterScheduleEntry = new MasterScheduleEntry("monthly", "Wed", "odd", 14, 17, 2, "joe2071234567,sue2079876543", "This is a super fun shift.", "Afternoon Shift"); // not sure what the id looks like echo 'will test update_dbMasterSchedule </br>'; error_log('testing update'); $result = insert_dbMasterSchedule($new_MasterScheduleEntry); echo 'result is ' . $result; if ($result) { echo "insert_dbMasterSchedule succeeded </br>"; } else { echo "insert_dbMasterSchedule failed</br>"; } // removed one person $updated_MasterScheduleEntry = new MasterScheduleEntry("monthly", "Wed", "odd", "14", "17", 2, "sue2079876543", "This is a super fun shift.", "Afternoon Shift"); // not sure what the id looks lik $mse = update_dbMasterSchedule($updated_MasterScheduleEntry); if ($mse == false) { echo 'update failed</br>'; } else { echo 'update succeeded'; } $res = delete_dbMasterSchedule($new_MasterScheduleEntry->get_MS_ID()); if ($res == null) { echo 'delete failed</br>'; } }
function update_dbMasterSchedule($entry) { connect(); if (!$entry instanceof MasterScheduleEntry) { echo "Invalid argument for update_dbMasterSchedule function call"; return false; } if (delete_dbMasterSchedule($entry->get_id())) { return insert_dbMasterSchedule($entry); } else { echo mysql_error() . " - Unable to update dbMasterSchedule: " . $entry->get_id() . "\n"; return false; } mysql_close(); return true; }
function insert_dbMasterSchedule(MasterScheduleEntry $entry) { connect(); $result = mysql_query("SELECT * FROM MASTERSCHEDULE WHERE MS_ID = '" . $entry->get_MS_ID() . "'"); if (!$result) { error_log('ERROR on select in insert_dbMasterSchedule() ' . mysql_error()); die('Invalid query: ' . mysql_error()); } if (mysql_num_rows($result) != 0) { delete_dbMasterSchedule($entry->get_MS_ID()); connect(); } $query = "INSERT INTO MASTERSCHEDULE VALUES ('" . $entry->get_MS_ID() . "','" . $entry->get_Schedule_type() . "','" . $entry->get_day() . "','" . $entry->get_start_time() . "','" . $entry->get_end_time() . "','" . $entry->get_slots() . "','" . $entry->get_notes() . "','" . $entry->get_Shifts() . "');"; //TODO: Log in a separate file //error_log("in insert into master schedule, query is " . $query); $result = mysql_query($query); if (!$result) { error_log('ERROR on select in insert_dbMasterSchedule() ' . mysql_error() . " - Unable to insert in MASTERSCHEDULE: " . $entry->get_MS_ID()); mysql_close(); return false; } mysql_close(); return true; }
function process_remove_shift($post, $shift, $day, $time, $frequency) { if (!array_key_exists('_submit_remove_shift', $post)) { return false; } $id = $frequency . $day . $time; if (delete_dbMasterSchedule($id)) { echo "<br>Deleted " . ucfirst($frequency) . " shift for " . $shift[2] . " (" . do_name($time) . ")<br><br>"; $returnpoint = "viewSchedule.php?frequency=" . $frequency; echo "<table align=\"center\"><tr><td align=\"center\" width=\"442\">\r\n\t\t\t\t<br><a href=\"" . $returnpoint . "\">\r\n\t\t\t\tBack to Master Schedule</a></td></tr></table>"; add_log_entry('<a href=\\"personEdit.php?id=' . $_SESSION['_id'] . '\\">' . $_SESSION['f_name'] . ' ' . $_SESSION['l_name'] . '</a> deleted a new master schedule shift: <a href=\\"editMasterSchedule.php?' . "day=" . $day . "&shift=" . $shift . "&frequency=" . $frequency . '\\">' . $frequency . " " . $day . " " . $shift . '</a>.'); return true; } return false; }
function process_remove_shift($post, $msentry, $group, $day, $time, $venue) { if (!array_key_exists('_submit_remove_shift', $post)) { return false; } if ($msentry->get_id()) { if (delete_dbMasterSchedule($msentry->get_id())) { // the next 3 lines are a 1-time cleanup for the database and should be removed if (substr($msentry->get_id(), 4) == "Sat:9-5:bangor") { delete_dbMasterSchedule(substr($msentry->get_id(), 0, 4) . "Sat:9-9:bangor"); delete_dbMasterSchedule("1st:Sat:10-1:bangor"); } echo "<br>Removed a master schedule shift <br><br>"; $returnpoint = "viewSchedule.php?venue=" . $venue; echo "<table align=\"center\"><tr><td align=\"center\" width=\"442\">\n\t\t\t\t\t\t\t\t\t<a href=\"" . $returnpoint . "\">\n\t\t\t\t\t\t\t\t\tBack to Master Schedule</a></td></tr></table>"; add_log_entry('<a href=\\"personEdit.php?id=' . $_SESSION['_id'] . '\\">' . $_SESSION['f_name'] . ' ' . $_SESSION['l_name'] . '</a> deleted a new master schedule shift: <a href=\\"editMasterSchedule.php?group=' . $group . "&day=" . $day . "&shift=" . $time . "&venue=" . $venue . '\\">' . $group . ":" . $day . ":" . $time . ":" . $venue . '</a>.'); return true; } } return false; }
function process_remove_crew($post, $group, $day, $week_no) { if (!array_key_exists('_submit_remove_crew', $post)) { return false; } $id = $group . $day . $week_no; if (delete_dbMasterSchedule($id)) { echo "<br>Removed entire crew for " . do_group_name($group) . ", " . do_week_name($week_no) . " " . do_day_name($day) . "<br><br>"; $returnpoint = "viewSchedule.php?group=" . $group; echo "<table align=\"center\"><tr><td align=\"center\" width=\"442\">\n\t\t\t\t<br><a href=\"" . $returnpoint . "\">\n\t\t\t\tBack to Master Schedule</a></td></tr></table>"; return true; } return false; }