コード例 #1
0
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(',', '&#44;', str_replace('+', '&#43;', str_replace('\'', '\\\'', htmlentities($post['datecalled_' . $i]))))), trim(str_replace(',', '&#44;', str_replace('+', '&#43;', 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);
    }
}
コード例 #2
0
 function get_remaining_vacancies($id)
 {
     error_log("The id is " . $id);
     $shift = select_dbShifts($id);
     $peoparr = $shift->get_persons();
     $numofpeople = count($peoparr);
     $vacancies = $shift->get_vacancies() - $numofpeople;
     error_log("The remaining number of vacancies is {$vacancies} ----------------------------------------");
     return $vacancies;
 }
コード例 #3
0
 function report_individual_hours($shifthis, $projecthis, $from, $to)
 {
     $from_date = setFromDate($from);
     $to_date = setToDate($to);
     $groupedreports = [];
     $count = 0;
     $fw = getNormWeek($from_date);
     $tw = getNormWeek($to_date);
     $yearswithweeks = DateRange($fw, $tw);
     foreach ($yearswithweeks as $years => $weeks) {
         foreach ($weeks as $w) {
             $currentweek = getSunWeek($years, $w);
             $weeklyreport = ['Sun' => [[0, 0], [0, 0], [0, 0]], 'Mon' => [[0, 0], [0, 0], [0, 0]], 'Tue' => [[0, 0], [0, 0], [0, 0]], 'Wed' => [[0, 0], [0, 0], [0, 0]], 'Thu' => [[0, 0], [0, 0], [0, 0]], 'Fri' => [[0, 0], [0, 0], [0, 0]], 'Sat' => [[0, 0], [0, 0], [0, 0]]];
             //This consists of [Days] => [shift, project, total] => [hrs, mins] - GIOVI
             $hours_s = 0;
             $minutes_s = 0;
             $hrmin_s = [0, 0];
             $hours_p = 0;
             $minutes_p = 0;
             $hrmin_p = [0, 0];
             if (array_key_exists($this->get_id(), $shifthis)) {
                 $sfthid = explode(',', $shifthis[$this->ID]);
                 foreach ($sfthid as $shift_id) {
                     $s = select_dbShifts($shift_id);
                     if (CheckIfDateIsInWeek($s->get_date(), $currentweek)) {
                         $shift_date = date_create_from_mm_dd_yyyy($s->get_mm_dd_yy());
                         if ($shift_date >= $from_date && $shift_date <= $to_date) {
                             $hrmin_s = ConvertTimeToHrMin($s->duration());
                             $hours_s = $hrmin_s[0];
                             $minutes_s = $hrmin_s[1];
                             $weeklyreport[$s->get_day()][0][0] += $hours_s;
                             //Shift hours
                             $weeklyreport[$s->get_day()][0][1] += $minutes_s;
                             //Shift minutes
                         }
                     }
                 }
             }
             if (array_key_exists($this->get_id(), $projecthis)) {
                 $projhid = explode(',', $projecthis[$this->ID]);
                 foreach ($projhid as $proj_id) {
                     $p = select_dbProjects($proj_id);
                     if (CheckIfDateIsInWeek($p->get_date(), $currentweek)) {
                         $proj_date = date_create_from_mm_dd_yyyy($p->get_mm_dd_yy());
                         if ($proj_date >= $from_date && $proj_date <= $to_date) {
                             $hrmin_p = ConvertTimeToHrMin($p->duration());
                             $hours_p = $hrmin_p[0];
                             $minutes_p = $hrmin_p[1];
                             $weeklyreport[$p->get_dayOfWeek()][1][0] += $hours_p;
                             //Project hours
                             $weeklyreport[$p->get_dayOfWeek()][1][1] += $minutes_p;
                             //Project minutes
                         }
                     }
                 }
             }
             foreach ($weeklyreport as $day => $hrs) {
                 $weeklyreport[$day][2][0] = $weeklyreport[$day][0][0] + $weeklyreport[$day][1][0];
                 $weeklyreport[$day][2][1] = $weeklyreport[$day][0][1] + $weeklyreport[$day][1][1];
             }
             $groupedreports[] = $weeklyreport;
             $count++;
         }
     }
     error_log("------- " . $count . " grouped report(s) recorded-----------");
     error_log("/////EXITING the report_hours function--------------------");
     return $groupedreports;
 }
コード例 #4
0
ファイル: dbShifts.php プロジェクト: billgoad/rmhc-homebase
/**
 * Tries to move a shift to a new start and end time.  New times must
 * not overlap with any other shift on the same date and venue
 * @return false if shift doesn't exist or there's an overlap
 * Otherwise, change the shift in the database and @return true
 */
function move_shift($s, $new_start, $new_end)
{
    // first, see if it exists
    $old_s = select_dbShifts($s->get_id());
    if ($old_s == null) {
        return false;
    }
    // now see if it can be moved by looking at all other shifts for the same date and venue
    $new_s = $s->set_start_end_time($new_start, $new_end);
    $current_shifts = selectDateVenue_dbShifts($s->get_date(), $s->get_venue());
    connect();
    for ($i = 0; $i < mysql_num_rows($current_shifts); ++$i) {
        $same_day_shift = mysql_fetch_row($current_shifts);
        if ($old_s->get_id() == $same_day_shift[0]) {
            // skip its own entry
            continue;
        }
        if (timeslots_overlap($same_day_shift[1], $same_day_shift[2], $new_s->get_start_time(), $new_s->get_end_time())) {
            $s = $old_s;
            mysql_close();
            return false;
        }
    }
    mysql_close();
    // we're good to go
    replace_dbDates($old_s, $new_s);
    delete_dbShifts($old_s);
    return true;
}
コード例 #5
0
 $shift = select_dbShifts($shiftid);
 if (!$shift instanceof Shift) {
     echo "<p>Invalid Shift ID Supplied.  Click on \"Calendar\" above to edit shifts.</p>";
 } else {
     if (!process_fill_vacancy($_POST, $shift, $venue) && !process_add_volunteer($_POST, $shift, $venue) && !process_move_shift($_POST, $shift) && !process_change_times($_POST, $shift)) {
         if (process_unfill_shift($_POST, $shift, $venue)) {
             $shift = select_dbShifts($shiftid);
         } else {
             if (process_add_slot($_POST, $shift, $venue)) {
                 $shift = select_dbShifts($shiftid);
             } else {
                 if (process_clear_shift($_POST, $shift, $venue)) {
                     $shift = select_dbShifts($shiftid);
                 } else {
                     if (process_ignore_slot($_POST, $shift, $venue)) {
                         $shift = select_dbShifts($shiftid);
                     }
                 }
             }
         }
         $persons = $shift->get_persons();
         echo "<br><br><table align=\"center\" border=\"1px\"><tr><td align=\"center\" colspan=\"2\"><b>" . get_shift_name_from_id($shiftid) . "</b></td></tr>";
         if ($_SESSION['access_level'] >= 2) {
             echo "<tr><td valign=\"top\"><br>&nbsp;" . do_slot_num($persons, $shift->num_vacancies()) . "</td><td>";
             echo "<form method=\"POST\" style=\"margin-bottom:0;\">\n\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"_submit_add_slot\" value=\"1\"><br>\n\t\t\t\t\t\t\t\t\t\t\t<input type=\"submit\" value=\"Add Slot\" style=\"width: 150px\"\n\t\t\t\t\t\t\t\t\t\t\tname=\"submit\" >\n\t\t\t\t\t\t\t\t\t\t\t</form>";
             echo "<form method=\"POST\" style=\"margin-bottom:0;\">\n\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"_submit_clear_shift\" value=\"1\">\n\t\t\t\t\t\t\t\t\t\t\t<input type=\"submit\" value=\"Clear Entire Shift\" style=\"width: 150px\"\n\t\t\t\t\t\t\t\t\t\t\tname=\"submit\" >\n\t\t\t\t\t\t\t\t\t\t\t</form>";
             echo "<form method=\"POST\" style=\"margin-bottom:0;\">\n\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"_submit_move_shift\" value=\"1\">\n\t\t\t\t\t\t\t\t\t\t\t<input type=\"submit\" value=\"Move Shift\" style=\"width: 150px\"\n\t\t\t\t\t\t\t\t\t\t\tname=\"submit\" >\n\t\t\t\t\t\t\t\t\t\t\t</form>";
             echo "<br></td></tr>";
         }
         echo display_filled_slots($persons);
         echo display_vacant_slots($shift->num_vacancies());
コード例 #6
0
/**
 * selects a date from the table
 * @return BSCAHdate
 */
function select_dbDates($id)
{
    if (strlen($id) != 8) {
        error_log('in select_dbDates,  Invalid argument for date->select_dbDates call = ' . $id);
        die("Invalid argument for date->select_dbDates call =" . $id);
    }
    connect();
    $query = "SELECT * FROM DATE WHERE DATE_ID =\"" . $id . "\"";
    error_log('in select_dbDates query is ' . $query);
    $result = mysql_query($query);
    mysql_close();
    if (!$result) {
        // echo 'Could not select from date: ' . $id;
        error_log('Could not select from DATE: ' . $id);
        return null;
    } else {
        $result_row = mysql_fetch_row($result);
        if ($result_row) {
            $shifts = $result_row[1];
            $shifts = explode("*", $shifts);
            $s = [];
            foreach ($shifts as $i) {
                $temp = select_dbShifts($i);
                if ($temp instanceof Shift) {
                    $s[$temp->get_name()] = $temp;
                }
            }
            $d = new BSCAHdate($result_row[0], $s, "", []);
            error_log($d->get_projects());
            return $d;
        } else {
            error_log("Could not fetch from DATE " . $id);
            return null;
        }
    }
}
コード例 #7
0
ファイル: dbDates.php プロジェクト: billgoad/rmhc-homebase
/**
 * selects a date from the table
 * @return RMHDate
 */
function select_dbDates($id)
{
    if (strlen($id) < 12) {
        die("Invalid argument for dbDates->select_dbDates call =" . $id);
    }
    connect();
    $query = "SELECT * FROM dbDates WHERE id =\"" . $id . "\"";
    $result = mysql_query($query);
    mysql_close();
    if (!$result) {
        echo 'Could not select from dbDates: ' . $id;
        error_log('Could not select from dbDates: ' . $id);
        return null;
    } else {
        $result_row = mysql_fetch_row($result);
        if ($result_row) {
            $shifts = $result_row[1];
            $shifts = explode("*", $shifts);
            $s = array();
            foreach ($shifts as $i) {
                $temp = select_dbShifts($i);
                if ($temp instanceof Shift) {
                    $s[$temp->get_hours()] = $temp;
                }
            }
            $parts = explode(":", $result_row[0]);
            $d = new RMHdate($parts[0], $parts[1], $s, $result_row[2]);
            return $d;
        } else {
            error_log("Could not fetch from dbDates " . $id);
            return null;
        }
    }
}