function testdbMonthsModule()
 {
     //creates an empty dbMonths table
     //$this->assertTrue(create_dbMonths());
     // create a month to add to the table
     $m1 = new Month("13-10-foodbank", "unpublished");
     // test the insert function
     $this->assertTrue(insert_dbMonths($m1));
     // test the retrieve function
     $this->assertEqual(retrieve_dbMonths($m1->get_id())->get_id(), "13-10-foodbank");
     $this->assertEqual(retrieve_dbMonths($m1->get_id())->get_status(), "unpublished");
     $this->assertEqual(retrieve_dbMonths($m1->get_id())->get_group(), "foodbank");
     $this->assertEqual(retrieve_dbMonths($m1->get_id())->get_end_of_month_timestamp(), mktime(0, 0, 0, 10, 31, 2013));
     // testing generation of a new calendar month from the master schedule
     $this->assertTrue(newMonth("13-10-foodbank"));
     // test the update function
     $m1->set_status("published");
     $this->assertTrue(update_dbMonths($m1));
     $this->assertEqual(retrieve_dbMonths($m1->get_id())->get_status(), "published");
     // tests the delete function
     $this->assertTrue(delete_dbMonths($m1));
     echo "\ntestdbMonths complete\n";
 }
function newMonth($id)
{
    $days = array(1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat");
    $fpdays = array(1 => "Mon", 2 => "Wed930", 3 => "Wed1100", 4 => "Thu", 5 => "Fri", 6 => "Sat");
    if (substr($id, 6) == "foodpantry") {
        $thisdays = $fpdays;
    } else {
        $thisdays = $days;
    }
    // We switched new months to default to published, because otherwise they won't be available for viewing.
    // We're unsure if this was the right move to make.
    $new_month = new Month($id, "unpublished");
    $new_crews = $new_month->get_crews();
    $dom = 1;
    // day of the month, 1, 2, ..., 31
    $week_no = 1;
    // master schedule week number
    $firstdow = $dow = date("N", mktime(0, 0, 0, substr($id, 3, 2), "01", substr($id, 0, 2)));
    // day of week, 1 = Monday
    if (substr($id, 6) == "foodpantry" && $firstdow == 3) {
        $firstdow = $dow = 2;
    }
    $newbies = array();
    foreach ($new_crews as $new_crew) {
        if ($dom == sizeof($new_crews) && substr($id, 6) == "foodpantry" && $dow == 2) {
            break;
        }
        $id1 = substr($id, 6) . $thisdays[$dow] . $week_no;
        $schedule_entry = retrieve_dbMasterSchedule($id1);
        if ($schedule_entry && $schedule_entry->get_slots() > 0) {
            if ($dom < 10) {
                $dd = "-0" . $dom;
            } else {
                $dd = "-" . $dom;
            }
            $person_ids = $schedule_entry->get_persons();
            $crew_names = array();
            foreach ($person_ids as $person_id) {
                if ($person_id == "") {
                    continue;
                }
                $p = retrieve_person($person_id);
                if ($p) {
                    $crew_names[] = $person_id . "+" . $p->get_first_name() . "+" . $p->get_last_name() . "+(" . implode(' ', $p->get_role()) . ")";
                } else {
                    $crew_names[] = $person_id . "+++";
                }
            }
            $newbie = new Crew(substr($id, 0, 5) . $dd, substr($id, 6), $schedule_entry->get_slots(), $crew_names, "", "");
            $new_month->set_crew($dom, $newbie->get_id());
            $newbies[] = $newbie;
        }
        if ($dow == 7) {
            $dow = 1;
        } else {
            $dow++;
        }
        if ($dow == $firstdow) {
            $week_no++;
        }
        $dom++;
    }
    update_dbMonths($new_month);
    foreach ($newbies as $newbie) {
        update_dbCrews($newbie);
    }
    return $new_month;
}