function testSelectProject()
{
    $newProject = new Project(PROJID, "03-12-14", "Main Building", "UnloadDelivery", 10, 13, 15, "", "notes");
    echo 'will test select_dbProject </br>';
    $result = insert_dbProjects($newProject);
    echo 'result is ' . $result;
    if ($result) {
        echo "add_person inserted </br>";
    } else {
        echo "add_person not inserted</br>";
    }
    $p = select_dbProjects(PROJID);
    if ($p == null) {
        echo 'Retrieve failed</br>';
    } else {
        checkEquals($p->get_id(), PROJID);
        checkEquals($p->get_name(), "UnloadDelivery");
    }
    $res = delete_dbProjects($newProject);
    if ($res == null) {
        echo 'Retrieve failed</br>';
    }
}
 $project = select_dbProjects($projectid);
 if (!$project instanceof Project) {
     echo "<p>Invalid Project ID Supplied.  Click on \"Calendar\" above to edit projects.</p>";
 } else {
     if (!process_fill_vacancy($_POST, $project, $venue) && !process_add_volunteer($_POST, $project, $venue) && !process_move_project($_POST, $project) && !process_change_times($_POST, $project)) {
         if (process_unfill_project($_POST, $project, $venue)) {
             $project = select_dbProjects($projectid);
         } else {
             if (process_add_slot($_POST, $project, $venue)) {
                 $project = select_dbProjects($projectid);
             } else {
                 if (process_clear_project($_POST, $project, $venue)) {
                     $project = select_dbProjects($projectid);
                 } else {
                     if (process_ignore_slot($_POST, $project, $venue)) {
                         $project = select_dbProjects($projectid);
                     }
                 }
             }
         }
         $persons = $project->get_persons();
         echo "<br><br><table align=\"center\" border=\"1px\"><tr><td align=\"center\" colspan=\"2\"><b>" . get_project_name_from_id($projectid) . "</b></td></tr>";
         if ($_SESSION['access_level'] >= 2) {
             echo "<tr><td valign=\"top\"><br>&nbsp;" . do_slot_num($persons, $project > num_vacancies()) . "</td><td>";
             echo "<form method=\"POST\" style=\"margin-bottom:0;\">\r\n\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"_submit_add_slot\" value=\"1\"><br>\r\n\t\t\t\t\t\t\t\t\t\t\t<input type=\"submit\" value=\"Add Slot\" style=\"width: 150px\"\r\n\t\t\t\t\t\t\t\t\t\t\tname=\"submit\" >\r\n\t\t\t\t\t\t\t\t\t\t\t</form>";
             echo "<form method=\"POST\" style=\"margin-bottom:0;\">\r\n\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"_submit_clear_project\" value=\"1\">\r\n\t\t\t\t\t\t\t\t\t\t\t<input type=\"submit\" value=\"Clear Entire Project\" style=\"width: 150px\"\r\n\t\t\t\t\t\t\t\t\t\t\tname=\"submit\" >\r\n\t\t\t\t\t\t\t\t\t\t\t</form>";
             echo "<form method=\"POST\" style=\"margin-bottom:0;\">\r\n\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"_submit_move_project\" value=\"1\">\r\n\t\t\t\t\t\t\t\t\t\t\t<input type=\"submit\" value=\"Move Project\" style=\"width: 150px\"\r\n\t\t\t\t\t\t\t\t\t\t\tname=\"submit\" >\r\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($project->num_vacancies());
Ejemplo n.º 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;
 }
function add_A_Person($idProject, $idPerson, $fNamePerson, $lNamePerson)
{
    //connect();
    //Counter to determine whether or not a person is found in the delimited string
    $counter = 0;
    $removedPersonConcatenated = "";
    //Get the current project so that you can get the current people in the project.
    $currentProject = select_dbProjects($idProject);
    $currentPeople = implode("*", $currentProject->get_persons());
    //Use the * delimiter to separate multiple values in a single persons field. (Breaks 1NF)
    $allPeople = explode('*', $currentPeople);
    //Concatenate the Person credentials to make it look like the DB field.
    $concatenatedPerson = "*" . $idPerson . "+" . $fNamePerson . "+" . $lNamePerson . "+";
    $allPeopleConcatenated = $currentPeople . $concatenatedPerson;
    $formattedPerson = str_replace("*", "", $concatenatedPerson);
    //Checks each delimited string to see if it is equal to the current person trying to add/remove themselves
    foreach ($allPeople as $individualPerson) {
        if ($formattedPerson == $individualPerson) {
            $counter = 1;
        } else {
            //Concatenated string without person
            $removedPersonConcatenated = $removedPersonConcatenated . $individualPerson;
        }
    }
    //Checks if the counter came back as 1, in which case the person is already in the DB and needs to be removed.
    if ($counter == 1) {
        remove_Person_To_Person_Column($removedPersonConcatenated, $idProject);
    } else {
        add_Person_From_Person_Column($allPeopleConcatenated, $idProject);
    }
}
Ejemplo n.º 5
0
 function get_remaining_vacancies($id)
 {
     error_log("The id is " . $id);
     $proj = select_dbProjects($id);
     $peoparr = $proj->get_persons();
     $numofpeople = count($peoparr);
     $vacancies = $proj->get_vacancies() - $numofpeople;
     error_log("The remaining number of vacancies is {$vacancies} ----------------------------------------");
     return $vacancies;
 }
/**
 * process_form sanitizes data, concatenates needed data, and enters it all into a database
 */
function process_form($id)
{
    //echo($_POST['first_name']);
    //step one: sanitize data by replacing HTML entities and escaping the ' character
    if (substr($_POST['date'], 0, 2) == 20) {
        $eurodate = explode('-', $_POST['date']);
        $eurodate[0] = substr($eurodate[0], 2, 3);
        $swapdate = [$eurodate[1], $eurodate[2], $eurodate[0]];
        $amerdate = implode('/', $swapdate);
        $mm_dd_yy = $amerdate;
    } else {
        $mm_dd_yy = $_POST['date'];
    }
    error_log("In process form this is " . $mm_dd_yy);
    $address = $_POST['address'];
    //trim(str_replace('\\\'', '\'', htmlentities($_POST['address'])));
    $name = $_POST['name'];
    //trim(htmlentities($_POST['name']));
    $type = $_POST['project_type'];
    $start_time = $_POST['start_time'];
    //ereg_replace("[^0-9]", "", $_POST['start_time']);
    $end_time = $_POST['end_time'];
    //ereg_replace("[^0-9]", "", $_POST['end_time']);
    //$dayOfWeek = trim(htmlentities($_POST['dayOfWeek']));
    $vacancies = $_POST['vacancies'];
    //ereg_replace("[^0-9]", "", $_POST['vacancies']);
    //$persons = trim(htmlentities($_POST['persons']));_log("In process form this is ".$mm_dd_yy);
    $age = $_POST['age'];
    $id = $_POST['old_id'];
    //trim(htmlentities($_POST['old_id']));
    $project_description = $_POST['notes'];
    //trim(htmlentities($_POST['notes']));
    $path = strrev(substr(strrev($_SERVER['SCRIPT_NAME']), strpos(strrev($_SERVER['SCRIPT_NAME']), '/')));
    //step two: try to make the deletion, password change, addition, or change
    if ($_POST['deleteMe'] == "DELETE") {
        $result = select_dbProjects($id);
        if (!$result) {
            echo '<p>Unable to delete. ' . $mm_dd_yy . ' is not in the database. <br>Please report this error to the House Manager.';
        } else {
            //What if they're the last remaining manager account?
            if (strpos($type, 'manager') !== false) {
                //They're a manager, we need to check that they can be deleted
                $managers = getall_type('manager');
                if (!$managers || mysql_num_rows($managers) <= 1) {
                    echo '<p class="error">You cannot remove the last remaining manager from the database.</p>';
                } else {
                    $result = delete_dbProjects($id);
                    echo "<p>You have successfully removed " . mm_dd_yy . " from the database.</p>";
                    if ($id == $_SESSION['_id']) {
                        session_unset();
                        session_destroy();
                    }
                }
            } else {
                $result = delete_dbProjects($id);
                echo "<p>You have successfully removed " . $mm_dd_yy . " from the database.</p>";
                if ($id == $_SESSION['_id']) {
                    session_unset();
                    session_destroy();
                }
            }
        }
    }
    // try to add a new project to the database
    //else {
    if ($_POST['old_id'] == 'new') {
        $id = $mm_dd_yy;
        //check if there's already an entry
        $dup = select_dbProjects($id);
        if ($dup) {
            echo '<p class="error">Unable to add ' . $mm_dd_yy . ' to the database. <br>Another project with the same name is already there.';
        } else {
            $newproject = new Project($mm_dd_yy, $address, $type, $name, $start_time, $end_time, $vacancies, $persons, $age, $project_description);
            $result = insert_dbProjects($newproject);
            $db_date_format = str_replace("/", "-", $mm_dd_yy);
            $update = update_dbDates_projects($db_date_format);
            if (!$update) {
                delete_dbProjects($newproject);
                error_log("Project has not been added");
                echo "<p class='error'>The week of " . $mm_dd_yy . " must be added to the weekly calendar first. Select the Project Calendar tab and then choose Manage Weeks";
            } else {
                if ($_SESSION['access_level'] == 0) {
                    echo "<p>Your application has been successfully submitted.<br>  The House Manager will contact you soon.  Thank you!";
                } else {
                    echo "<p>You have successfully added " . $newproject->get_id() . " to the database.</p>";
                }
            }
        }
    } else {
        $id = $_POST['old_id'];
        $result = delete_dbProjects($id);
        if (!$result) {
            echo '<p class="error">Unable to update ' . $mm_dd_yy . '. <br>Please report this error to the House Manager.';
        } else {
            $newproject = new Project($mm_dd_yy, $address, $name, $start_time, $end_time, $vacancies, $persons, $project_description);
            echo '<p>You have successfully edited <a href="' . $path . 'projectEdit.php?id=' . $id . '"><b>' . $mm_dd_yy . ' </b></a> in the database.</p>';
        }
        add_log_entry('<a href=\\"projectEdit.php?id=' . $id . '\\">' . $mm_dd_yy . ' </a>\'s Project Edit Form has been changed.');
    }
}
        $name = trim(str_replace('\'', '&#39;', htmlentities($_POST['s_name'])));
        include_once 'database/dbProjects.php';
        include_once 'domain/Project.php';
        $allProjects = get_Projects_By_All_Fields($name, $address, $day, $type, $vacancies, $date);
        //$allProjects = search_dbProjects_By_Name($_POST['s_name']);
        if (sizeof($allProjects) > 0) {
            echo '<b>' . '<font size="6">' . 'Select one to add or remove yourself from the project.' . '</font>' . '</b>';
            echo '<p><table> <tr><td>Name</td><td>Date</td><td>Address</td><td>Start Time</td><td>End Time</td><td>Age Requirement</td><td>Volunteers</td></tr>';
            foreach ($allProjects as $temp) {
                echo "<tr><td><a href=projectSearch.php?id=" . $temp->get_id() . ">" . $temp->get_name() . "</td><td>" . $temp->get_date() . "</td><td>" . $temp->get_address() . "</td><td>" . $temp->get_start_time() . "</td><td>" . $temp->get_end_time() . "</td><td>" . $temp->get_age() . "</td><td>" . $temp->get_persons() . "</td></a></tr>";
            }
        }
        echo '</table>';
    }
} else {
    $selectedProj = select_dbProjects($id);
    if ($selectedProj == null) {
        error_log("The ID is invalid." . $id);
        die;
    } else {
        $personToBeAdded = $_SESSION['_id'];
        include_once 'domain/Person.php';
        $self = retrieve_person($personToBeAdded);
        /*} else if($tempAge >= $ageZero){
          error_log('user id is ' . $_SESSION['_id']);
          
          $completePerson = retrieve_person($personToBeAdded);
          add_A_Person($selectedProj->get_id(), $completePerson->get_id(), $completePerson->get_first_name(), $completePerson->get_last_name());
          */
        if ($self == null) {
            error_log('Error with User information');