Example #1
0
 public function execute()
 {
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     if (!isset($this->term) || is_null($this->term)) {
         throw new InvalidArgumentException('Missing term.');
     }
     $db = new PHPWS_DB('hms_new_application');
     $db->addColumn('banner_id');
     $db->addColumn('username');
     $db->addWhere('term', $this->term);
     $results = $db->select();
     if (empty($results)) {
         return;
     } elseif (PEAR::isError($results)) {
         throw new DatabaseException($results->toString());
     }
     $twentyFiveYearsAgo = strtotime("-25 years");
     foreach ($results as $student) {
         try {
             $sf = StudentFactory::getStudentByBannerId($student['banner_id'], $this->term);
             $dob = $sf->getDOB();
             if (strtotime($dob) > $twentyFiveYearsAgo) {
                 continue;
             }
             $student['dob'] = $dob;
             $student['full_name'] = $sf->getFullName();
             $this->all_rows[] = $student;
         } catch (Exception $e) {
             $student['dob'] = $student['full_name'] = null;
             $this->problems[] = $student['banner_id'];
         }
     }
 }
Example #2
0
/**
 * Uninstall file for PhatForm v2
 *
 * Rewritten to work with phpwebsite 1.0
 * @version $Id$
 */
function phatform_uninstall(&$content)
{
    $db = new PHPWS_DB('mod_phatform_forms');
    $db->addColumn('id');
    $db->addColumn('archiveTableName');
    $db->addWhere('saved', 1);
    $result = $db->select();
    if (!empty($result)) {
        foreach ($result as $form) {
            if (empty($form['archiveTableName'])) {
                $table = 'mod_phatform_form_' . $form['id'];
                if (PHPWS_DB::isTable($table)) {
                    PHPWS_DB::dropTable($table);
                }
            } else {
                $table = $form['archiveTableName'];
                PHPWS_DB::dropTable($table);
            }
        }
        $content[] = dgettext('phatform', 'Removed all dynamic Form Generator tables.');
    }
    PHPWS_DB::dropTable('mod_phatform_forms');
    PHPWS_DB::dropTable('mod_phatform_options');
    PHPWS_DB::dropTable('mod_phatform_textfield');
    PHPWS_DB::dropTable('mod_phatform_textarea');
    PHPWS_DB::dropTable('mod_phatform_dropbox');
    PHPWS_DB::dropTable('mod_phatform_multiselect');
    PHPWS_DB::dropTable('mod_phatform_radiobutton');
    PHPWS_DB::dropTable('mod_phatform_checkbox');
    $content[] = dgettext('phatform', 'All Form Generator static tables removed.');
    return TRUE;
}
 public function execute()
 {
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     $this->reasons = HousingApplication::getCancellationReasons();
     // All students
     $db = new PHPWS_DB('hms_new_application');
     $db->addColumn('cancelled_reason');
     $db->addColumn('id', null, 'ount', true);
     $db->addWhere('term', $this->getTerm());
     $db->addWhere('cancelled', 1);
     $db->addGroupBy('cancelled_reason');
     $this->reasonCounts = $db->select('assoc');
     // Freshmen
     $db = new PHPWS_DB('hms_new_application');
     $db->addColumn('cancelled_reason');
     $db->addColumn('id', null, 'count', true);
     $db->addWhere('term', $this->getTerm());
     $db->addWhere('cancelled', 1);
     $db->addWhere('student_type', TYPE_FRESHMEN);
     $db->addGroupBy('cancelled_reason');
     $this->freshmenReasonCounts = $db->select('assoc');
     // Continuing
     $db = new PHPWS_DB('hms_new_application');
     $db->addColumn('cancelled_reason');
     $db->addColumn('id', null, 'count', true);
     $db->addWhere('term', $this->getTerm());
     $db->addWhere('cancelled', 1);
     $db->addWhere('student_type', TYPE_CONTINUING);
     $db->addGroupBy('cancelled_reason');
     $this->continuingReasonCounts = $db->select('assoc');
 }
Example #4
0
 /**
  * Report lists rooms in each residence hall that are still available, along with
  * the available beds in the room.  Also, show the number of beds allocated to the
  * lotter for each residence hall.
  *
  */
 public static function reappAvailability()
 {
     $term = Term::getSelectedTerm();
     // Available rooms in each residence hall.
     $db = new PHPWS_DB('hms_bed');
     $db->addJoin('LEFT', 'hms_bed', 'hms_room', 'room_id', 'id');
     $db->addJoin('LEFT', 'hms_room', 'hms_floor', 'floor_id', 'id');
     $db->addJoin('LEFT', 'hms_floor', 'hms_residence_hall', 'residence_hall_id', 'id');
     //$db->addWhere('hms_bed.ra_bed', 0);
     $db->addWhere('hms_room.private', 0);
     $db->addWhere('hms_room.overflow', 0);
     $db->addWhere('hms_room.reserved', 0);
     $db->addWhere('hms_room.offline', 0);
     $db->addWhere('hms_bed.term', $term);
     $db->addColumn('hms_room.room_number');
     $db->addColumn('hms_bed.bed_letter', null, null, True);
     $db->addColumn('hms_residence_hall.hall_name');
     $db->addGroupBy('hms_residence_hall.hall_name');
     $db->addGroupBy('hms_room.room_number');
     $db->addOrder('hms_residence_hall.hall_name');
     $availRooms = $db->select();
     // Allocated beds for lottery.
     $db = new PHPWS_DB('hms_bed');
     $db->addJoin('LEFT', 'hms_bed', 'hms_room', 'room_id', 'id');
     $db->addJoin('LEFT', 'hms_room', 'hms_floor', 'floor_id', 'id');
     $db->addJoin('LEFT', 'hms_floor', 'hms_residence_hall', 'residence_hall_id', 'id');
     $db->addJoin('RIGHT', 'hms_bed', 'hms_lottery_reservation', 'id', 'bed_id');
     $db->addWhere('hms_lottery_reservation.term', $term);
     $db->addColumn('hms_residence_hall.hall_name');
     $db->addColumn('hms_bed.id', null, null, True);
     $db->addGroupBy('hms_residence_hall.hall_name');
     $db->setIndexBy('hall_name');
     $lotteryBeds = $db->select();
     $tpl = new PHPWS_Template('hms');
     $tpl->setFile('admin/reports/reapp_availability.tpl');
     //
     // "The parent row must be parsed after the child rows."
     // Preload currHall with first residence hall name
     $currHall = $availRooms[0]['hall_name'];
     foreach ($availRooms as $row) {
         // Change halls, create new block.
         if ($currHall != $row['hall_name'] || $currHall == null) {
             $tpl->setCurrentBlock('halls');
             // Get allocated beds for the residence hall.
             $lottCount = isset($lotteryBeds[$currHall]['count']) ? $lotteryBeds[$currHall]['count'] : 0;
             $tpl->setData(array('HALL_NAME' => $currHall, 'LOTTERY_BEDS' => $lottCount));
             $tpl->parseCurrentBlock();
             $currHall = $row['hall_name'];
         }
         // Add room to residence hall template block.
         $tpl->setCurrentBlock('rooms');
         $tpl->setData(array('ROOM_NUM' => $row['room_number'], 'BED_COUNT' => $row['count']));
         $tpl->parseCurrentBlock();
     }
     // Get last residence hall. Can't parse parent before child with template class.
     $tpl->setCurrentBlock('halls');
     $tpl->setData(array('HALL_NAME' => $currHall));
     $tpl->parseCurrentBlock();
     return $tpl->get();
 }
Example #5
0
 public function execute()
 {
     PHPWS_Core::initModClass('hms', 'HMS_Util.php');
     $term = $this->term;
     $db = new PHPWS_DB('hms_checkin');
     // Join hall structure
     $db->addJoin('', 'hms_checkin', 'hms_hall_structure', 'bed_id', 'bedid');
     $db->addColumn('hms_checkin.banner_id');
     $db->addColumn('hms_checkin.checkin_date');
     $db->addColumn('hms_hall_structure.hall_name');
     $db->addColumn('hms_hall_structure.room_number');
     $db->addWhere('hms_checkin.term', $term);
     $db->addWhere('hms_checkin.checkout_date', null, 'IS NULL');
     // Sort by hall, then room number
     $db->addOrder(array('hms_hall_structure.hall_name ASC', 'hms_hall_structure.room_number ASC'));
     $results = $db->select();
     if (PHPWS_Error::isError($results)) {
         throw new DatabaseException($results->toString());
     }
     // Post-processing, cleanup, making it pretty
     foreach ($results as $row) {
         // Updates counts
         $this->total++;
         $row['checkin_date'] = HMS_Util::get_short_date_time($row['checkin_date']);
         // Copy the cleaned up row to the member var for data
         $this->data[] = $row;
     }
 }
 public function execute()
 {
     $db = new PHPWS_DB('hms_new_application');
     $db->addColumn('student_type');
     $db->addColumn('id', null, 'count', true);
     $db->addWhere('term', $this->getTerm());
     $db->addWhere('cancelled', 1);
     $db->addGroupBy('student_type');
     $this->typeCounts = $db->select('assoc');
 }
 public static function getAssignmentsByTermStateType($term, $state, $type)
 {
     $db = new PHPWS_DB('hms_learning_community_applications');
     $db->addColumn('hms_learning_community_applications.*');
     $db->addColumn('hms_learning_community_assignment.*');
     $db->addJoin('', 'hms_learning_community_applications', 'hms_learning_community_assignment', 'id', 'application_id');
     $db->addWhere('term', $term);
     $db->addWhere('hms_learning_community_assignment.state', $state);
     $db->addWhere('application_type', $type);
     return $db->getObjects('HMS_RLC_Assignment');
 }
 public function execute()
 {
     PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     $db = new PHPWS_DB('hms_new_application');
     $db->addColumn('hms_new_application.*');
     $db->addWhere('term', $this->term);
     $db->addWhere('cancelled', 0);
     $term = Term::getTermSem($this->term);
     if ($term == TERM_FALL) {
         $db->addJoin('LEFT', 'hms_new_application', 'hms_fall_application', 'id', 'id');
         $db->addColumn('hms_fall_application.*');
     } else {
         if ($term == TERM_SUMMER1 || $term == TERM_SUMMER2) {
             $db->addJoin('LEFT', 'hms_new_application', 'hms_summer_application', 'id', 'id');
             $db->addColumn('hms_summer_application.*');
         }
     }
     $result = $db->select();
     $app = array();
     foreach ($result as $app) {
         $username = $app['username'];
         $bannerId = $app['banner_id'];
         $type = $app['student_type'];
         $cellPhone = $app['cell_phone'];
         $date = date('n/j/Y', $app['created_on']);
         $assignment = HMS_Assignment::getAssignmentByBannerId($bannerId, $this->term);
         if (!is_null($assignment)) {
             $room = $assignment->where_am_i();
         } else {
             $room = '';
         }
         $student = StudentFactory::getStudentByBannerId($bannerId, $this->term);
         $first = $student->getFirstName();
         $middle = $student->getMiddleName();
         $last = $student->getLastName();
         $gender = $student->getPrintableGender();
         $birthday = date("m/d/Y", $student->getDobDateTime()->getTimestamp());
         $address = $student->getAddress(NULL);
         if ($term == TERM_SPRING || $term == TERM_FALL) {
             $lifestyle = $app['lifestyle_option'] == 1 ? 'Single Gender' : 'Co-Ed';
         } else {
             $lifestyle = $app['room_type'] == 1 ? 'Single Room' : 'Double Room';
         }
         if (!is_null($address) && $address !== false) {
             $this->rows[] = array($username, $bannerId, $first, $middle, $last, $gender, $type, $cellPhone, $room, $date, $address->line1, $address->line2, $address->line3, $address->city, $address->state, $address->zip, $birthday, $lifestyle);
         } else {
             $this->rows[] = array($username, $bannerId, $first, $middle, $last, '', $type, $cellPhone, $room, $date, '', '', '', '', '', '', $lifestyle);
         }
     }
 }
Example #9
0
 public function execute()
 {
     $db = new PHPWS_DB('hms_room');
     $db->addColumn('hms_residence_hall.hall_name');
     $db->addColumn('hms_floor.floor_number');
     $db->addColumn('hms_room.room_number');
     $db->addJoin('LEFT', 'hms_room', 'hms_floor', 'floor_id', 'id');
     $db->addJoin('LEFT', 'hms_floor', 'hms_residence_hall', 'residence_hall_id', 'id');
     $db->addWhere('hms_room.term', $this->term);
     $db->addWhere('hms_room.gender_type', COED);
     $results = $db->select();
     $this->totalCoed = sizeof($results);
     $this->rows = $results;
 }
Example #10
0
 public static function getAllowedStates()
 {
     $db = new \PHPWS_DB('intern_state');
     $db->addWhere('active', 1);
     $db->addColumn('abbr');
     $db->addColumn('full_name');
     $db->setIndexBy('abbr');
     $db->addOrder('full_name ASC');
     $states = $db->select('col');
     if (empty($states)) {
         \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, 'The list of allowed US states for internship locations has not been configured. Please use the administrative options to <a href="index.php?module=intern&action=edit_states">add allowed states.</a>');
         \NQ::close();
         PHPWS_Core::goBack();
     }
     return $states;
 }
Example #11
0
 public function loadMembers()
 {
     $db = new PHPWS_DB('users_members');
     $db->addWhere('group_id', $this->getId());
     $db->addColumn('member_id');
     $result = $db->select('col');
     $this->setMembers($result);
 }
Example #12
0
 /**
  * Returns an associative array containing the list of RLCs using their full names, keyed by their id.
  *
  * @param int $term
  * @param string $studentType
  * @param string $hidden
  * @throws DatabaseException
  * @return Array Array of communities
  */
 public static function getRlcList($term, $studentType = NULL, $hidden = NULL)
 {
     $db = new PHPWS_DB('hms_learning_communities');
     $db->addColumn('id');
     $db->addColumn('community_name');
     if (!is_null($studentType) && strlen($studentType) == 1) {
         $db->addWhere('allowed_student_types', "%{$student_type}%", 'ilike');
     }
     if ($hidden === FALSE) {
         $db->addWhere('hide', 0);
     }
     $db->addOrder('community_name ASC');
     $rlcs = $db->select('assoc');
     if (PHPWS_Error::logIfError($rlcs)) {
         throw new DatabaseException($rlcs->toString());
     }
     return $rlcs;
 }
Example #13
0
 public function execute()
 {
     if (!isset($this->term) || is_null($this->term)) {
         throw new InvalidArgumentException('Missing term.');
     }
     /*****
      * Total Beds
      */
     $db = new PHPWS_DB('hms_bed');
     $db->addJoin('', 'hms_bed', 'hms_room', 'room_id', 'id');
     $db->addJoin('', 'hms_room', 'hms_floor', 'floor_id', 'id');
     $db->addJoin('', 'hms_floor', 'hms_residence_hall', 'residence_hall_id', 'id');
     $db->addWhere('hms_bed.term', $this->term);
     $this->totalBedCount = $db->count();
     if (PHPWS_Error::logIfError($this->totalBedCount)) {
         PHPWS_Core::initModClass('hms', 'exception', 'DatabaseException.php');
         throw new DatabaseException($this->totalBedCount->toString());
     }
     /*******
      * Unavailable Beds
      */
     $db = new PHPWS_DB('hms_bed');
     $db->addColumn('hms_residence_hall.hall_name');
     $db->addColumn('hms_bed.*');
     $db->addColumn('hms_room.*');
     $db->addJoin('', 'hms_bed', 'hms_room', 'room_id', 'id');
     $db->addJoin('', 'hms_room', 'hms_floor', 'floor_id', 'id');
     $db->addJoin('', 'hms_floor', 'hms_residence_hall', 'residence_hall_id', 'id');
     $db->addWhere('hms_room.reserved', 1, null, 'OR', 'foo');
     $db->addWhere('hms_room.ra', 1, null, 'OR', 'foo');
     $db->addWhere('hms_room.private', 1, null, 'OR', 'foo');
     $db->addWhere('hms_room.overflow', 1, null, 'OR', 'foo');
     $db->addWhere('hms_room.parlor', 1, null, 'OR', 'foo');
     $db->addWhere('hms_room.offline', 1, null, 'OR', 'foo');
     $db->addWhere('hms_bed.ra_roommate', 1, null, 'OR', 'foo');
     $db->addWhere('hms_bed.international_reserved', 1, null, 'OR', 'foo');
     $db->addWhere('hms_bed.term', $this->term);
     $db->addOrder(array('hms_residence_hall.hall_name', 'hms_room.room_number', 'bed_letter'));
     $this->unavailableBeds = $db->select();
     if (PHPWS_Error::logIfError($this->unavailableBeds)) {
         PHPWS_Core::initModClass('hms', 'exception/DatabaseException.php');
         throw new DatabaseException($this->unavailableBeds->toString());
     }
 }
Example #14
0
 public static function getAllowedStates()
 {
     $db = new PHPWS_DB('intern_state');
     $db->addWhere('active', 1);
     $db->addColumn('abbr');
     $db->addColumn('full_name');
     $db->setIndexBy('abbr');
     // get backwards because we flip it
     $db->addOrder('full_name desc');
     $states = $db->select('col');
     if (empty($states)) {
         NQ::simple('intern', INTERN_ERROR, 'The list of allowed US states for internship locations has not been configured. Please use the administrative options to <a href="index.php?module=intern&action=edit_states">add allowed states.</a>');
         NQ::close();
         PHPWS_Core::goBack();
     }
     $states[-1] = 'Select a state';
     $states = array_reverse($states, true);
     return $states;
 }
Example #15
0
 function getOwnerUsername()
 {
     $db = new PHPWS_DB('users');
     $db->addWhere('id', $this->getOwnerId());
     $db->addColumn('username');
     $result = $db->select('col');
     if (PHPWS_Error::logIfError($result)) {
         return dgettext('wiki', 'N/A');
     }
     return $result[0];
 }
 public function doPairing(&$applications, &$pairs)
 {
     $db = new PHPWS_DB('hms_roommate');
     $db->addWhere('term', $this->term);
     $db->addWhere('confirmed', 1);
     $db->addColumn('requestor');
     $db->addColumn('requestee');
     $roommates = $db->select();
     if (PHPWS_Error::logIfError($roommates)) {
         throw new DatabaseException($roommates->toString());
     }
     foreach ($roommates as $pair) {
         if (!isset($applications[$pair['requestor']]) || !isset($applications[$pair['requestee']])) {
             // Not to be assigned anyway.
             if (isset($applications[$pair['requestor']])) {
                 echo "Weird: {$pair['requestee']} not in the list but {$pair['requestor']} is. Skipping.\n";
                 unset($applications[$pair['requestor']]);
             }
             if (isset($applications[$pair['requestee']])) {
                 echo "Weird: {$pair['requestor']} not in the list but {$pair['requestee']} is. Skipping.\n";
                 unset($applications[$pair['requestee']]);
             }
             continue;
         }
         $requestor = $applications[$pair['requestor']];
         $requestee = $applications[$pair['requestee']];
         if (!$this->pairAllowed($requestor, $requestee)) {
             echo "Weird: {$pair['requestor']} and {$pair['requestee']} are confirmed roommates but different gender.  Skipping.\n";
             unset($applications[$pair['requestor']]);
             unset($applications[$pair['requestee']]);
             continue;
         }
         $newPair = $this->createPairing($requestor, $requestee);
         if (!is_null($newPair)) {
             $pairs[] = $newPair;
         }
         unset($applications[$pair['requestor']]);
         unset($applications[$pair['requestee']]);
     }
 }
Example #17
0
 public function authenticate()
 {
     if (empty($this->password)) {
         return false;
     }
     $db = new PHPWS_DB('user_authorization');
     if (!Current_User::allowUsername($this->user->username)) {
         return false;
     }
     $password_hash = md5($this->user->username . $this->password);
     $db->addColumn('username');
     $db->addWhere('username', strtolower($this->user->username));
     $db->addWhere('password', $password_hash);
     $result = $db->select('one');
     return !PHPWS_Error::logIfError($result) && (bool) $result;
 }
Example #18
0
 public function init()
 {
     PHPWS_Core::initCoreClass('Module.php');
     $db = new PHPWS_DB('users_my_page_mods');
     $db->addColumn('mod_title');
     $result = $db->select('col');
     if (PHPWS_Error::isError($result)) {
         return $result;
     }
     if ($result) {
         foreach ($result as $mod_title) {
             $this->modules[$mod_title] = new PHPWS_Module($mod_title);
         }
     } else {
         return FALSE;
     }
     return TRUE;
 }
 /**
  * Returns an array of HMS_Residence_Hall objects for the given term.
  *
  * @param integer $term
  * @throws InvalidArgumentException
  * @throws DatabaseException
  * @return multitype:HMS_Residence_Hall
  */
 public static function getHallsForTerm($term)
 {
     if (!isset($term)) {
         throw new InvalidArgumentException('Missing term.');
     }
     $halls = array();
     $db = new PHPWS_DB('hms_residence_hall');
     $db->addColumn('id');
     $db->addOrder('hall_name', 'DESC');
     $db->addWhere('term', $term);
     $results = $db->select();
     if (PHPWS_Error::logIfError($results)) {
         throw new DatabaseException($result->toString());
     }
     //TODO this is terribly inefficient
     foreach ($results as $result) {
         $halls[] = new HMS_Residence_Hall($result['id']);
     }
     return $halls;
 }
 public function execute()
 {
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     $db = new PHPWS_DB('hms_assignment');
     $db->addColumn('hms_assignment.banner_id');
     $db->addColumn('hms_assignment.reason');
     $db->addColumn('hms_residence_hall.hall_name');
     $db->addColumn('hms_room.room_number');
     $db->addColumn('hms_new_application.cell_phone');
     $db->addWhere('hms_assignment.term', $this->term);
     $db->addJoin('LEFT OUTER', 'hms_assignment', 'hms_bed', 'bed_id', 'id');
     $db->addJoin('LEFT OUTER', 'hms_bed', 'hms_room', 'room_id', 'id');
     $db->addJoin('LEFT OUTER', 'hms_room', 'hms_floor', 'floor_id', 'id');
     $db->addJoin('LEFT OUTER', 'hms_floor', 'hms_residence_hall', 'residence_hall_id', 'id');
     $db->addJoin('LEFT OUTER', 'hms_assignment', 'hms_new_application', 'banner_id', 'banner_id AND hms_assignment.term = hms_new_application.term');
     $results = $db->select();
     if (PHPWS_Error::logIfError($results)) {
         return $results;
     }
     foreach ($results as $row) {
         try {
             $student = StudentFactory::getStudentByBannerId($row['banner_id'], $this->term);
             $bannerId = $student->getBannerId();
             $username = $student->getUsername();
             $first = $student->getFirstName();
             $middle = $student->getMiddleName();
             $last = $student->getLastName();
             $type = $student->getType();
             $appTerm = $student->getApplicationTerm();
             $cellPhone = $row['cell_phone'];
             $assignmentType = $row['reason'];
             $gender = HMS_Util::formatGender($student->getGender());
             $dob = $student->getDob();
             $room = $row['hall_name'] . ' ' . $row['room_number'];
             $address = $student->getAddress(NULL);
             if (!$address || !isset($address) || is_null($address)) {
                 $line1 = "";
                 $line2 = "";
                 $line3 = "";
                 $city = "";
                 $state = "";
                 $zip = "";
             } else {
                 $line1 = $address->line1;
                 $line2 = $address->line2;
                 $line3 = $address->line3;
                 $city = $address->city;
                 $state = $address->state;
                 $zip = $address->zip;
             }
         } catch (StudentNotFoundException $e) {
             $bannerId = $row['banner_id'];
             $username = '';
             $first = '';
             $middle = '';
             $last = '';
             $gender = '';
             $dob = '';
             $type = '';
             $cellPhone = '';
             $line1 = '';
             $line2 = '';
             $line3 = '';
             $city = '';
             $state = '';
             $zip = '';
             $appTerm = '';
             $assignmentType = '';
             $room = '';
         }
         $this->rows[] = array($username, $bannerId, $first, $middle, $last, $gender, $dob, $type, $appTerm, $cellPhone, $assignmentType, $room, $line1, $line2, $line3, $city, $state, $zip);
     }
 }
Example #21
0
 public function getPhotos()
 {
     $db = new \PHPWS_DB('prop_photo');
     $db->addColumn('path');
     $db->addColumn('title');
     $db->addWhere('pid', $this->id);
     $db->addOrder('main_pic desc');
     $photos = $db->select();
     if (empty($photos)) {
         return null;
     }
     return $photos;
 }
Example #22
0
 public static function searchUsers($string)
 {
     $db = new \PHPWS_DB('users');
     $db->addWhere('username', "%{$string}%", 'ILIKE');
     $db->addColumn('username');
     return $db->select('col');
 }
Example #23
0
 public function setUsername($username)
 {
     if (empty($username)) {
         throw new \Exception('User name may not be blank');
     }
     if (strlen($username) < 3) {
         throw new \Exception('User name must be more than 3 characters');
     }
     if (preg_match('/\\W]/', $username)) {
         throw new \Exception('User name may contain alphanumeric characters only');
     }
     // check for duplicate user names
     $db = new \PHPWS_DB('prop_contacts');
     $db->addWhere('username', $username);
     $db->addColumn('id');
     $result = $db->select('one');
     if (\PHPWS_Error::isError($result)) {
         \PHPWS_Error::log($result);
         throw new \Exception('A database error occurred. Contact the site administrator');
     }
     // if an id is found (user name in use) and this is a new user OR the result id
     // is not equal to the current contact id, then throw a duplicate warning
     if ($result && (!$this->id || $this->id != $result)) {
         throw new \Exception('This user name is already in use, please choose another');
     }
     $this->username = $username;
 }
Example #24
0
 public function isInstalled($title = null)
 {
     static $module_list = array();
     if (isset($this->_error) && $this->_error->code == PHPWS_NO_MOD_FOUND) {
         return false;
     }
     if (empty($title)) {
         if (isset($this->title)) {
             $title =& $this->title;
         } else {
             return null;
         }
     }
     if ($title == 'core') {
         return true;
     }
     if (!empty($module_list) && isset($module_list[$title])) {
         return $module_list[$title];
     }
     $db = new PHPWS_DB('modules');
     $db->addWhere('title', $title);
     $db->addColumn('title');
     $result = $db->select('one');
     if (PHPWS_Error::isError($result)) {
         PHPWS_Error::log($result);
         return false;
     } else {
         if (isset($result)) {
             $module_list[$title] = true;
             return true;
         } else {
             $module_list[$title] = false;
             return false;
         }
     }
 }
Example #25
0
 /**
  * Returns the Report object identified by the given id.
  * 
  * @param integer $reportId
  * @return Report
  * @throws DatabaseExecption
  * @throws InvalidArgumentException
  */
 public static function getReportById($reportId)
 {
     // Get the class of the requested report
     $db = new PHPWS_DB('hms_report');
     $db->addColumn('report');
     $db->addWhere('id', $reportId);
     $result = $db->select('one');
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseExecption($result->toString());
     }
     if (is_null($result)) {
         throw new InvalidArgumentException('The given report ID does not exist.');
     }
     self::loadReportClass($result);
     $report = new $result($reportId);
     return $report;
 }
 private function getAssignmentsByHall($hallId)
 {
     $db = new PHPWS_DB('hms_assignment');
     $db->addColumn('hms_assignment.banner_id');
     // Limit to just the requested hall id
     $db->addWhere('hms_residence_hall.id', $hallId);
     // Join the assignment all the way up to the hall
     $db->addJoin('LEFT OUTER', 'hms_assignment', 'hms_bed', 'bed_id', 'id');
     $db->addJoin('LEFT OUTER', 'hms_bed', 'hms_room', 'room_id', 'id');
     $db->addJoin('LEFT OUTER', 'hms_room', 'hms_floor', 'floor_id', 'id');
     $db->addJoin('LEFT OUTER', 'hms_floor', 'hms_residence_hall', 'residence_hall_id', 'id');
     // Don't report on anything that's not online
     $db->addWhere('hms_room.offline', 0);
     $db->addWhere('hms_floor.is_online', 1);
     $db->addWhere('hms_residence_hall.is_online', 1);
     $assignments = $db->select();
     if (PHPWS_Error::logIfError($assignments)) {
         throw new DatabaseException($assignments->toString());
     }
     return $assignments;
 }
Example #27
0
/**
 * @version $Id$
 * @author Matthew McNaney <mcnaney at gmail dot com>
 */
function checkin_update(&$content, $current_version)
{
    switch (1) {
        case version_compare($current_version, '1.0.1', '<'):
            $content[] = '<pre>';
            $db = new PHPWS_DB('checkin_staff');
            if (PHPWS_Error::logIfError($db->addTableColumn('view_order', 'smallint not null default 0'))) {
                $content[] = 'Unable to create checkin_staff.view_order column.</pre>';
                return false;
            } else {
                $content[] = 'Created checkin_staff.view_order column.';
            }
            $db->addColumn('id');
            $staff_list = $db->select('col');
            if (!empty($staff_list)) {
                $count = 1;
                foreach ($staff_list as $staff_id) {
                    $db->reset();
                    $db->addWhere('id', $staff_id);
                    $db->addValue('view_order', $count);
                    PHPWS_Error::logIfError($db->update());
                    $count++;
                }
            }
            checkinUpdateFiles(array('templates/visitors.tpl', 'templates/waiting.tpl', 'templates/queue.tpl', 'templates/settings.tpl'), $content);
            $content[] = '1.0.1 changes
------------------
+ Fixed bug with pulling current staff member
+ Added refresh link to waiting and assignment page
+ Fixed report
</pre>';
        case version_compare($current_version, '1.0.2', '<'):
            $content[] = '<pre>';
            checkinUpdateFiles(array('templates/visitors.tpl', 'templates/waiting.tpl', 'templates/style.css'), $content);
            $content[] = '1.0.2 changes
--------------------
+ Fixed translation typo.
+ Added "Send back" condition</pre>';
        case version_compare($current_version, '1.0.3', '<'):
            $content[] = '<pre>';
            checkinUpdateFiles(array('templates/report.tpl'), $content);
            $content[] = '1.0.3 changes
--------------------
+ Removed error message from report if no reasons created
+ Added the time of arrival to the report
+ Changed report date entry interface
+ Upper cased names.
</pre>';
        case version_compare($current_version, '1.0.4', '<'):
            $content[] = '<pre>1.0.4 changes
---------------------
+ Fixed waiting time setting</pre>';
        case version_compare($current_version, '1.1.0', '<'):
            $content[] = '<pre>1.1.0 changes
---------------------
+ Added code to prevent refreshed duplicates
+ Fixed possible error in admin view
+ Added monthly and student reports
+ Added report for number of times a visitor has visited within 30 days.
+ PHP 5 Strict changes</pre>';
        case version_compare($current_version, '1.1.1', '<'):
            $content[] = '<pre>1.1.1 changes
---------------------
+ Reports limited to admins</pre>';
        case version_compare($current_version, '1.2', '<'):
            $db = new PHPWS_DB('checkin_staff');
            $db->addTableColumn('active', 'smallint not null default 1');
            $content[] = '<pre>1.2 changes
--------------
+ Fixed blue button on admin menu
+ Staff can now be deactivated so they appear on reports but do not receive visitors</pre>';
        case version_compare($current_version, '1.3', '<'):
            $db = new PHPWS_DB('checkin_visitor');
            $db->addTableColumn('email', 'varchar(255) NULL');
            $content[] = '<pre>1.3 changes
---------------
+ Option to collect visitor email addresses.</pre>';
        case version_compare($current_version, '1.4.0', '<'):
            $content[] = '<pre>1.4.0 changes
---------------
+ May now report by visitor name.</pre>';
        case version_compare($current_version, '1.5.0', '<'):
            $content[] = '<pre>';
            // Make changes to checkin_visitor table
            $db = new PHPWS_DB('checkin_visitor');
            if (PHPWS_Error::logIfError($db->addTableColumn('gender', 'varchar(20) default NULL'))) {
                $content[] = 'Unable to create checkin_visitor.gender column.</pre>';
                return false;
            } else {
                $content[] = 'Created checkin_visitor.gender column.';
            }
            if (PHPWS_Error::logIfError($db->addTableColumn('birthdate', 'varchar(20) default NULL'))) {
                $content[] = 'Unable to create checkin_visitor.birthdate column.</pre>';
                return false;
            } else {
                $content[] = 'Created checkin_visitor.birthdate column.';
            }
            // Make changes to checkin_staff table
            $db = new PHPWS_DB('checkin_staff');
            if (PHPWS_Error::logIfError($db->addTableColumn('birthdate_filter_end', 'varchar(20) default NULL', 'f_regexp'))) {
                $content[] = 'Unable to create checkin_staff.birthdate_filter_end column.</pre>';
                return false;
            } else {
                $content[] = 'Created checkin_staff.birthdate_filter_end column.';
            }
            if (PHPWS_Error::logIfError($db->addTableColumn('birthdate_filter_start', 'varchar(20) default NULL', 'f_regexp'))) {
                $content[] = 'Unable to create checkin_staff.birthdate_filter_start column.</pre>';
                return false;
            } else {
                $content[] = 'Created checkin_staff.birthdate_filter_start column.';
            }
            if (PHPWS_Error::logIfError($db->addTableColumn('gender_filter', 'varchar(20) default NULL', 'f_regexp'))) {
                $content[] = 'Unable to create checkin_staff.gender_filter column.</pre>';
                return false;
            } else {
                $content[] = 'Created checkin_staff.gender_filter column.';
            }
            if (PHPWS_Error::logIfError($db->query('ALTER TABLE checkin_staff CHANGE filter lname_filter varchar(255) default NULL'))) {
                $content[] = 'Unable to rename checkin_staff.filter column.</pre>';
                return false;
            } else {
                $content[] = 'Renamed checkin_staff.filter to checkin_staff.lname_filter.';
            }
            if (PHPWS_Error::logIfError($db->query('ALTER TABLE checkin_staff CHANGE f_regexp lname_regexp varchar(255) default NULL'))) {
                $content[] = 'Unable to rename checkin_staff.f_regexp column.</pre>';
                return false;
            } else {
                $content[] = 'Renamed checkin_staff.f_regexp to checkin_staff.lname_regexp.';
            }
            $content[] = '1.5.0 changes
---------------
+ Fixed the "print view" for daily reports.
+ Option to collect visitor gender.
+ Option to collect visitor birthdate.
+ Added staff filters for gender and birthdate.
+ Staff can now have more than one filter.</pre>';
        case version_compare($current_version, '1.5.1', '<'):
            $content[] = '<pre>1.5.1 changes
----------------
+ Fixed some bugs and notices</pre>';
    }
    return true;
}
 public function execute()
 {
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
     if (!isset($this->term) || is_null($this->term)) {
         throw new InvalidArgumentException('Missing term.');
     }
     // Get all of the residence halls for this term
     $halls = ResidenceHallFactory::getHallsForTerm($this->term);
     foreach ($halls as $hall) {
         $hallName = $hall->hall_name;
         $maxOccupancy = $hall->get_number_of_online_nonoverflow_beds();
         $currOccupancy = $hall->get_number_of_assignees();
         $this->totalCurrOccupancy += $currOccupancy;
         $males = 0;
         $females = 0;
         $coed = 0;
         // Get all the assignments for this hall, joined up to the
         // room level so we can determine gender, and joined up to the
         // hall level so we can limit by hall
         $db = new PHPWS_DB('hms_assignment');
         $db->addColumn('hms_assignment.*');
         $db->addColumn('hms_room.gender_type');
         $db->addJoin('LEFT', 'hms_assignment', 'hms_bed', 'bed_id', 'id');
         $db->addJoin('LEFT', 'hms_bed', 'hms_room', 'room_id', 'id');
         $db->addJoin('LEFT', 'hms_room', 'hms_floor', 'floor_id', 'id');
         $db->addJoin('LEFT', 'hms_floor', 'hms_residence_hall', 'residence_hall_id', 'id');
         $db->addWhere('hms_assignment.term', $this->term);
         $db->addWhere('hms_residence_hall.id', $hall->id);
         $results = $db->select();
         if (empty($results)) {
             continue;
         } elseif (PEAR::isError($results)) {
             throw new DatabaseException($results->toString());
         }
         // foreach assignment, tally up the genders
         foreach ($results as $assign) {
             if ($assign['gender_type'] == MALE) {
                 $males++;
                 $this->totalMales++;
             } else {
                 if ($assign['gender_type'] == FEMALE) {
                     $females++;
                     $this->totalFemales++;
                 } else {
                     if ($assign['gender_type'] == COED) {
                         $coed++;
                         $this->totalCoed++;
                     }
                 }
             }
         }
         if ($males == 0) {
             $malePercent = 0;
         } else {
             $malePercent = round($males / $currOccupancy * 100, 1);
         }
         if ($females == 0) {
             $femalePercent = 0;
         } else {
             $femalePercent = round($females / $currOccupancy * 100, 1);
         }
         if ($coed == 0) {
             $coedPercent = 0;
         } else {
             $coedPercent = round($coed / $currOccupancy * 100, 1);
         }
         $this->rows[] = array('hallName' => $hallName, 'maxOccupancy' => $maxOccupancy, 'currOccupancy' => $currOccupancy, 'males' => $males, 'malePercent' => $malePercent, 'females' => $females, 'femalePercent' => $femalePercent, 'coed' => $coed, 'coedPercent' => $coedPercent);
     }
     $this->totalMalePercent = round($this->totalMales / $this->totalCurrOccupancy * 100, 1);
     $this->totalFemalePercent = round($this->totalFemales / $this->totalCurrOccupancy * 100, 1);
     $this->totalCoedPercent = round($this->totalCoed / $this->totalCurrOccupancy * 100, 1);
 }
Example #29
0
 public function nextBox()
 {
     $DB = new PHPWS_DB('layout_box');
     $DB->addWhere('theme', $this->theme);
     $DB->addWhere('theme_var', $this->theme_var);
     $DB->addColumn('box_order', 'max');
     $max = $DB->select('one');
     if (isset($max)) {
         return $max + 1;
     } else {
         return 1;
     }
 }
Example #30
0
 public function execute()
 {
     PHPWS_Core::initModClass('hms', 'HMS_Util.php');
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'SpringApplication.php');
     PHPWS_Core::initModClass('hms', 'SummerApplication.php');
     PHPWS_Core::initModClass('hms', 'FallApplication.php');
     PHPWS_Core::initModClass('hms', 'HMS_Roommate.php');
     $term = $this->term;
     $sem = Term::getTermSem($term);
     // List of student 'application terms' which we'll consider as 'Freshmen' for term we're looking at
     // E.g. Students with an applicationt erm in Summer 1, Summer 2, and Fall all count as Freshmen for Fall.
     $applicationTerms = array();
     $db = new PHPWS_DB('hms_new_application');
     $db->addColumn('hms_new_application.banner_id');
     $db->addColumn('hms_new_application.username');
     $db->addColumn('hms_new_application.term');
     $db->addColumn('hms_new_application.gender');
     $db->addColumn('hms_new_application.application_term');
     $db->addColumn('hms_new_application.student_type');
     $db->addColumn('hms_new_application.cell_phone');
     $db->addColumn('hms_new_application.meal_plan');
     $db->addColumn('hms_new_application.physical_disability');
     $db->addColumn('hms_new_application.psych_disability');
     $db->addColumn('hms_new_application.medical_need');
     $db->addColumn('hms_new_application.gender_need');
     $db->addColumn('hms_new_application.international');
     $db->addColumn('hms_new_application.created_on');
     // Join for additional application data based on semester
     switch ($sem) {
         case TERM_SUMMER1:
         case TERM_SUMMER2:
             $db->addJoin('', 'hms_new_application', 'hms_summer_application', 'id', 'id');
             $db->addColumn('hms_summer_application.*');
             $applicationTerms[] = $term;
             $db->addWhere('application_type', 'summer');
             break;
         case TERM_FALL:
             $db->addJoin('', 'hms_new_application', 'hms_fall_application', 'id', 'id');
             $db->addColumn('hms_fall_application.*');
             // Add the summer 1 and summe 2 application terms
             $summer2 = Term::getPrevTerm($term);
             $summer1 = Term::getPrevTerm($summer2);
             $applicationTerms[] = $summer1;
             $applicationTerms[] = $summer2;
             $applicationTerms[] = $term;
             $db->addWhere('application_type', 'fall');
             break;
         case TERM_SPRING:
             $db->addJoin('', 'hms_new_application', 'hms_spring_application', 'id', 'id');
             $db->addColumn('hms_spring_application.*');
             $applicationTerms[] = $term;
             $db->addWhere('application_type', 'spring');
             break;
         default:
             // error
             throw new InvalidArgumentException('Invalid term specified.');
     }
     // Join for un-assigned students
     $db->addJoin('LEFT OUTER', 'hms_new_application', 'hms_assignment', 'banner_id', 'banner_id AND hms_new_application.term = hms_assignment.term');
     $db->addWhere('hms_assignment.banner_id', 'NULL');
     $db->addWhere('hms_new_application.term', $term);
     $db->addWhere('hms_new_application.student_type', 'F');
     // Don't show students who have cancelled applications
     $db->addWhere('hms_new_application.cancelled', 0);
     // Limit by application term
     foreach ($applicationTerms as $t) {
         $db->addWhere('application_term', $t, '=', 'OR', 'app_term_group');
     }
     // Sort by gender, then application date (earliest to latest)
     $db->addOrder(array('gender ASC', 'created_on ASC'));
     $results = $db->select();
     if (PHPWS_Error::isError($results)) {
         throw new DatabaseException($results->toString());
     }
     // Post-processing, cleanup, making it pretty
     foreach ($results as $row) {
         // Updates counts
         $this->total++;
         if ($row['gender'] == MALE) {
             $this->male++;
         } else {
             if ($row['gender'] == FEMALE) {
                 $this->female++;
             }
         }
         $row['application_term'] = Term::toString($row['application_term']);
         $row['gender'] = HMS_Util::formatGender($row['gender']);
         $row['created_on'] = HMS_Util::get_short_date_time($row['created_on']);
         $row['meal_plan'] = HMS_Util::formatMealOption($row['meal_plan']);
         $row['lifestyle_option'] = HMS_Util::formatLifestyle($row['lifestyle_option']);
         $row['room_condition'] = HMS_Util::formatRoomCondition($row['room_condition']);
         $row['preferred_bedtime'] = HMS_Util::formatBedtime($row['preferred_bedtime']);
         // Roommates
         $roommie = HMS_Roommate::get_confirmed_roommate($row['username'], $this->term);
         if (!is_null($roommie)) {
             $row['roommate'] = $roommie->getUsername();
             $row['roommate_banner_id'] = $roommie->getBannerId();
         }
         // Copy the cleaned up row to the member var for data
         $this->data[] = $row;
     }
 }