/**
 * Inserts a week into the db
 *
 * @param $w Week the week to insert
 */
function insert_dbWeeks(Week $w)
{
    if (!assert_week_format($w)) {
        error_log("ERROR: Your week object did not start on a Sunday or did not have a length of 7 days");
        return false;
    }
    connect();
    $query = sprintf('SELECT * FROM WEEKS WHERE ID=\'%s\'', $w->get_id());
    $result = mysql_query($query);
    if (mysql_num_rows($result) != 0) {
        delete_dbWeeks($w);
        connect();
    }
    $query = sprintf('INSERT INTO WEEKS VALUES("%s", "%s", "%s", %d)', $w->get_id(), get_dates_text($w->get_dates()), $w->get_status(), $w->get_end());
    $result = mysql_query($query);
    mysql_close();
    if (!$result) {
        echo "<br>unable to insert into week: " . $w->get_id() . get_dates_text($w->get_dates()) . $w->get_status() . $w->get_name() . $w->get_end();
        return false;
    } else {
        foreach ($w->get_dates() as $i) {
            insert_dbDates($i);
        }
    }
    return true;
}
Example #2
0
/**
 * Inserts a week into the db
 * @param $w the week to insert
 */
function insert_dbWeeks($w)
{
    if (!$w instanceof Week) {
        die("Invalid argument for dbWeeks->insert_dbWeeks function call");
    }
    connect();
    $query = "SELECT * FROM dbWeeks WHERE id =\"" . $w->get_id() . "\"";
    $result = mysql_query($query);
    if (mysql_num_rows($result) != 0) {
        delete_dbWeeks($w);
        connect();
    }
    $query = "INSERT INTO dbWeeks VALUES (\"" . $w->get_id() . "\"," . get_dates_text($w->get_dates()) . ",\"" . $w->get_venue() . "\",\"" . $w->get_status() . "\",\"" . $w->get_name() . "\",\"" . $w->get_end() . "\")";
    $result = mysql_query($query);
    mysql_close();
    if (!$result) {
        echo "<br>unable to insert into dbWeeks: " . $w->get_id() . get_dates_text($w->get_dates()) . $w->get_venue() . $w->get_status() . $w->get_name() . $w->get_end();
        return false;
    } else {
        foreach ($w->get_dates() as $i) {
            insert_dbDates($i);
        }
    }
    return true;
}
function testget_dates_test()
{
    $newWeek = new Week("03-30-14", "Bscah", "Active");
    $nd = insert_dbWeeks($newDate);
    $id = "03-30-14";
    echo 'will test get_dates_test</br>';
    $result = get_dates_text($dates);
    if ($result != null) {
        echo 'select_dbDates failed</br>';
    }
    $res = delete_dbWeeks($newWeek);
    if ($res == null) {
        echo 'Delete failed</br>';
    }
}