/** * Adds a {@link BSCAHdate} to the table * If the date already exists, the date is deleted and replaced. */ function insert_dbDates(BSCAHdate $d) { connect(); $query = "SELECT * FROM DATE WHERE DATE_ID =\"" . $d->get_id() . "\""; $result = mysql_query($query); if (!$result) { error_log('ERROR on select in insert_dbDates() ' . mysql_error()); die('Invalid query: ' . mysql_error()); } if (mysql_num_rows($result) != 0) { delete_dbDates($d); connect(); } $query = sprintf('INSERT INTO DATE VALUES ("%s", "%s", "%s", "%s")', $d->get_id(), get_shifts_text($d), $d->get_mgr_notes(), $d->get_projects()); $result = mysql_query($query); if (!$result) { echo "unable to insert into DATE: " . $d->get_id() . mysql_error(); mysql_close(); return false; } mysql_close(); $shifts = $d->get_shifts(); foreach ($shifts as $key => $value) { insert_dbShifts($d->get_shift($key)); } return true; }
/** * Adds a RMHDate to the table * If the date already exists, the date is deleted and replaced. */ function insert_dbDates($d) { if (!$d instanceof RMHdate) { die("Invalid argument for dbDates->insert_dbdates function call"); } connect(); $query = "SELECT * FROM dbDates WHERE id =\"" . $d->get_id() . "\""; $result = mysql_query($query); if (mysql_num_rows($result) != 0) { delete_dbDates($d); connect(); } $query = "INSERT INTO dbDates VALUES\n\t\t\t\t(\"" . $d->get_id() . "\",\"" . get_shifts_text($d) . "\",\"" . $d->get_mgr_notes() . "\")"; $result = mysql_query($query); if (!$result) { echo "unable to insert into dbDates: " . $d->get_id() . mysql_error(); mysql_close(); return false; } mysql_close(); $shifts = $d->get_shifts(); foreach ($shifts as $key => $value) { insert_dbShifts($d->get_shift($key)); } return true; }
function test_get_shifts_text() { $newDate = new BSCAHdate("01-01-15", "9-11", "notes", []); $nd = insert_dbDates($newDate); echo 'will test get_shifts_text</br>'; $result = get_shifts_text($newDate); if ($result == null) { echo 'get_shifts_text failed</br>'; } else { echo 'get_shifts_text succeeded</br>'; } $res = delete_dbDates($newDate); if ($res == null) { echo 'Delete failed</br>'; } }