function testdbShiftsModule() { $s1 = new Shift("08-02-25:1-5", "house", 3, array(), array(), "", ""); $this->assertTrue(insert_dbShifts($s1)); $this->assertTrue(delete_dbShifts($s1)); $s2 = new Shift("08-02-25:9-1", "house", 3, array(), array(), "", ""); $this->assertTrue(insert_dbShifts($s2)); $s2 = new Shift("08-02-25:9-1", "house", 2, array(), array(), "", ""); $this->assertTrue(update_dbShifts($s2)); $shifts[] = $s2; $this->assertTrue(delete_dbShifts($s2)); echo "testdbShifts complete"; }
function process_edit_scl($post) { $id = $post['_shiftid']; $shift = select_dbShifts($id); $venue = substr($id, 9); $venue = substr($venue, strlen($venue) - 3); $scl = select_dbSCL($id); $persons_old = $scl->get_persons(); $vacancies = $shift->num_vacancies(); $new_acceptances = 0; for ($i = 0; $i < count($persons_old); ++$i) { $p_new = [$persons_old[$i][0], $persons_old[$i][1], $persons_old[$i][2], $persons_old[$i][3], $persons_old[$i][4], trim(str_replace(',', ',', str_replace('+', '+', str_replace('\'', '\\\'', htmlentities($post['datecalled_' . $i]))))), trim(str_replace(',', ',', str_replace('+', '+', str_replace('\'', '\\\'', htmlentities($post['notes_' . $i]))))), $post['accepted_' . $i]]; $persons_new[] = $p_new; if ($post['accepted_' . $i] == "Yes" && $persons_old[$i][7] != "Yes") { ++$new_acceptances; $accepted_people[] = $i; } } if ($new_acceptances > $vacancies) { for ($j = 0; $j < count($accepted_people); ++$j) { if ($j == 0) { $s = $persons_new[$accepted_people[$j]][1] . " " . $persons_new[$accepted_people[$j]][2]; } else { if ($j == count($accepted_people) - 1) { $s = $s . " and " . $persons_new[$accepted_people[$j]][1] . " " . $persons_new[$accepted_people[$j]][2]; } else { $s = $s . ", " . $persons_new[$accepted_people[$j]][1] . " " . $persons_new[$accepted_people[$j]][2]; } } $persons_new[$accepted_people[$j]][7] = "?"; } if ($vacancies == 1) { echo "You assigned <b>" . $s . "</b> to this shift, but there is only " . $vacancies . " open slot.<br>\n\t\t\t\t\tPlease assign volunteers again.</p>"; } else { echo "You assigned <b>" . $s . "</b> to this shift, but there are only " . $vacancies . " open slots.<br>\n\t\t\t\t\tPlease assign volunteers again.</p>"; } update_sub_call_list($scl, $persons_new, $vacancies, "open"); return $id; } else { $p = $shift->get_persons(); for ($j = 0; $j < count($accepted_people); ++$j) { $s = $persons_new[$accepted_people[$j]][0] . "+" . $persons_new[$accepted_people[$j]][1] . "+" . $persons_new[$accepted_people[$j]][2]; $p[] = $s; --$vacancies; $shift->ignore_vacancy(); } $shift->assign_persons($p); update_dbShifts($shift); for ($j = 0; $j < count($accepted_people); ++$j) { add_log_entry('<a href=\\"personEdit.php?id=' . $_SESSION['_id'] . '\\">' . $_SESSION['f_name'] . ' ' . $_SESSION['l_name'] . '</a> assigned <a href=\\"personEdit.php?id=' . $persons_new[$accepted_people[$j]][0] . '\\">' . $persons_new[$accepted_people[$j]][1] . ' ' . $persons_new[$accepted_people[$j]][2] . '</a> to the shift: <a href=\\"editShift.php?shift=' . $shift->get_id() . '&venue=' . $venue . '\\">' . get_shift_name_from_id($shift->get_id()) . '</a>.'); } //print_r($shift); if ($vacancies == 0) { $status = "closed"; } else { $status = "open"; } update_sub_call_list($scl, $persons_new, $vacancies, $status); } }
function remove_from_future_shifts($id) { $today = date('y-m-d'); connect(); $query = "select * from dbShifts where substring(id,1,8) >= '" . $today . "' AND persons LIKE '%" . $id . "%' "; $result = mysql_query($query); mysql_close(); while ($result_row = mysql_fetch_assoc($result)) { $persons_array = explode('*', $result_row['persons']); // individual persons for ($i = 0; $i < count($persons_array); $i++) { $p = explode('+', $persons_array[$i]); // id, first_name, last_name if ($p[0] == $id) { array_splice($persons_array, $i, 1); // remove person from array $result_row['vacancies']++; $result_row['persons'] = implode('*', $persons_array); $s = make_a_shift($result_row); update_dbShifts($s); break; } } } }