diff --git a/boost/install.sql b/boost/install.sql index 158b8e26..ed981dfe 100644 --- a/boost/install.sql +++ b/boost/install.sql @@ -150,7 +150,7 @@ CREATE TABLE hms_residence_hall ( map_image_id integer DEFAULT 0, room_plan_image_id integer DEFAULT 0, assignment_notifications integer NOT NULL DEFAULT 1, - package_desk integer NOT NULL REFERENCES hms_package_desk(id), + package_desk integer REFERENCES hms_package_desk(id), primary key(id) ); diff --git a/boost/updates/00-05-08.sql b/boost/updates/00-05-08.sql new file mode 100644 index 00000000..8e6f0439 --- /dev/null +++ b/boost/updates/00-05-08.sql @@ -0,0 +1,27 @@ +CREATE TABLE hms_package_desk ( + id integer NOT NULL, + name character varying, + location character varying, + street character varying, + city character varying, + state character varying, + zip character varying, + PRIMARY KEY(id) +); + +CREATE TABLE hms_package ( + id integer NOT NULL, + carrier character varying, + tacking_number character varying, + addressed_to character varying, + addressed_phone character varying, + recipient_banner_id integer NOT NULL, + received_on integer NOT NULL, + received_by character varying, + package_desk integer NOT NULL references hms_package_desk(id), + pickedup_on integer, + released_by character varying, + PRIMARY KEY(id) +); + +ALTER TABLE hms_residence_hall ADD COLUMN package_desk integer REFERENCES hms_package_desk(id); diff --git a/class/HMS_Email.php b/class/HMS_Email.php index ce3e90da..cb7f74ee 100644 --- a/class/HMS_Email.php +++ b/class/HMS_Email.php @@ -329,6 +329,52 @@ public static function sendAssignmentNotice($to, $name, $term, $location, Array } } + $student = StudentFactory::getStudentByUsername($to, $term); + + $poBox = $student->getAddress('AB'); + if($poBox) + { + $tpl['PO_NAME'] = $student->getName(); + $tpl['PO_STREET_ONE'] = $poBox->line1; + if($poBox->line2) + { + $tpl['PO_STREET_TWO'] = $poBox->line2; + } + if($poBox->line3) + { + $tpl['PO_STREET_THREE'] = $poBox->line3; + } + $tpl['PO_CITY'] = $poBox->city; + $tpl['PO_STATE'] = $poBox->state; + $tpl['PO_ZIPCODE'] = $poBox->zip; + } + else + { + $tpl['PO_EMPTY_ADDRESS'] = 'Address for your P.O. Box is not currently available.'; + } + + $assignment = HMS_Assignment::getAssignment($student->getUsername(), $term); + + if($assignment) + { + $bed = $assignment->get_parent(); + $room = $bed->get_parent(); + $floor = $room->get_parent(); + $hall = $floor->get_parent(); + + $packageDesk = PackageDeskFactory::getPackageDeskById($hall->getPackageDeskId()); + + if($packageDesk) + { + $tpl['DESK_NAME'] = $student->getName(); + $tpl['DESK_CO_LABEL'] = 'c/o: '. $packageDesk->name; + $tpl['DESK_STREET'] = $packageDesk->street; + $tpl['DESK_CITY'] = $packageDesk->city; + $tpl['DESK_STATE'] = $packageDesk->state; + $tpl['DESK_ZIPCODE'] = $packageDesk->zip; + } + } + $sem = Term::getTermSem($term); switch($sem){ diff --git a/class/PackageDeskFactory.php b/class/PackageDeskFactory.php index d1976a23..bacc72e8 100644 --- a/class/PackageDeskFactory.php +++ b/class/PackageDeskFactory.php @@ -3,19 +3,19 @@ PHPWS_Core::initModClass('hms','PackageDesk.php'); class PackageDeskFactory { - + public static function getPackageDesks() { $db = new PHPWS_DB('hms_package_desk'); - + $result = $db->select(); - + if (PHPWS_Error::logIfError($result)) { throw new DatabaseException($result->toString()); } - + $desks = array(); - + foreach ($result as $row) { $desk = new RestoredPackageDesk(); $desk->setId($row['id']); @@ -25,30 +25,49 @@ public static function getPackageDesks() $desk->setCity($row['city']); $desk->setState($row['state']); $desk->setZip($row['zip']); - + $desks[] = $desk; } - + return $desks; } - + public static function getPackageDesksAssoc() { $desks = self::getPackageDesks(); - + if (sizeof($desks) == 0) { - test('done!',1); + // var_dump($desks); + // exit; return array(); } - + $results = array(); - + foreach ($desks as $d) { $results[$d->getId()] = $d->getName(); } - + return $results; } -} + /** + * Retrieves the package desk matching the given id from the database. + * @return array containing one PortalRestored object + */ + public static function getPackageDeskById($id) + { + $db = PdoFactory::getPdoInstance(); + $query = 'SELECT * FROM hms_package_desk WHERE id = :deskId'; + $stmt = $db->prepare($query); + $params = array( + 'deskId' => $id + ); + + $stmt->execute($params); + $stmt->setFetchMode(PDO::FETCH_CLASS, 'RestoredPackageDesk'); + + return $stmt->fetch(); + } +} diff --git a/class/ResidenceHallView.php b/class/ResidenceHallView.php index 8828c06a..a5a33d67 100644 --- a/class/ResidenceHallView.php +++ b/class/ResidenceHallView.php @@ -61,12 +61,13 @@ public function show() $form->addCheckBox('assignment_notifications', 1); $form->setMatch('assignment_notifications', $this->hall->assignment_notifications); - // Package Desks - //PHPWS_Core::initModClass('hms', 'PackageDeskFactory.php'); - //$packageDesks = PackageDeskFactory::getPackageDesksAssoc(); - - //$form->addDropBox('package_desk', $packageDesks); - //$form->setMatch('package_desk', $this->hall->getPackageDeskId()); + //Package Desks + + $packageDesks = PackageDeskFactory::getPackageDesksAssoc(); + $packageDesks = array('-1' => 'None') + $packageDesks; + $form->addDropBox('package_desk', $packageDesks); + $form->setMatch('package_desk', $this->hall->getPackageDeskId()); + $form->addCssClass('package_desk', 'form-control'); // Images PHPWS_Core::initModClass('filecabinet', 'Cabinet.php'); diff --git a/class/Student.php b/class/Student.php index 7b8e955e..c186818b 100644 --- a/class/Student.php +++ b/class/Student.php @@ -220,13 +220,17 @@ public function getAddress($type = null) { $pr_address = null; $ps_address = null; + $ab_address = null; foreach ($this->addressList as $address) { if (((string) $address->atyp_code) == ADDRESS_PRMT_RESIDENCE) { $pr_address = $address; } else if (((string) $address->atyp_code) == ADDRESS_PRMT_STUDENT) { $ps_address = $address; + } else if (((string) $address->atyp_code) == ADDRESS_ASU_BOX) { + $ab_address = $address; } + } # Decide which address type to return, based on $type parameter @@ -237,6 +241,8 @@ public function getAddress($type = null) # Since there was no ps address, return the ps address, if it exists } else if (!is_null($ps_address)) { return $ps_address; + } else if (!is_null($ab_address)){ + return $ab_address; } else { # No address found, return false return false; @@ -245,6 +251,8 @@ public function getAddress($type = null) return $pr_address; } else if ($type == ADDRESS_PRMT_STUDENT && !is_null($ps_address)) { return $ps_address; + } else if ($type == ADDRESS_ASU_BOX && !is_null($ab_address)){ + return $ab_address; } else { # Either a bad type was specified (i.e. not null and not PS or PR) # or the specified type was not found diff --git a/class/VerifyAssignmentView.php b/class/VerifyAssignmentView.php index 5739b5f7..f28f52ce 100644 --- a/class/VerifyAssignmentView.php +++ b/class/VerifyAssignmentView.php @@ -73,6 +73,51 @@ public function show() $tpl['RLC'] = 'You have been assigned to the ' . $rlc_list[$rlc_assignment['rlc_id']]; } + $poBox = $this->student->getAddress('AB'); + if($poBox) + { + $tpl['PO_NAME'] = $this->student->getName(); + $tpl['PO_STREET_ONE'] = $poBox->line1; + if($poBox->line2) + { + $tpl['PO_STREET_TWO'] = $poBox->line2; + } + if($poBox->line3) + { + $tpl['PO_STREET_THREE'] = $poBox->line3; + } + $tpl['PO_CITY'] = $poBox->city; + $tpl['PO_STATE'] = $poBox->state; + $tpl['PO_ZIPCODE'] = $poBox->zip; + } + else + { + $tpl['PO_EMPTY_ADDRESS'] = 'Address for your P.O. Box is not currently available.'; + } + + + if($assignment) + { + $bed = $assignment->get_parent(); + $room = $bed->get_parent(); + $floor = $room->get_parent(); + $hall = $floor->get_parent(); + + $packageDesk = PackageDeskFactory::getPackageDeskById($hall->getPackageDeskId()); + + + + if($packageDesk) + { + $tpl['DESK_NAME'] = $this->student->getName(); + $tpl['DESK_CO_LABEL'] = 'c/o: '. $packageDesk->name; + $tpl['DESK_STREET'] = $packageDesk->street; + $tpl['DESK_CITY'] = $packageDesk->city; + $tpl['DESK_STATE'] = $packageDesk->state; + $tpl['DESK_ZIPCODE'] = $packageDesk->zip; + } + } + $tpl['MENU_LINK'] = PHPWS_Text::secureLink('Back to Main Menu', 'hms', array('type'=>'student', 'op'=>'show_main_menu')); Layout::addPageTitle("Verify Assignment"); diff --git a/class/command/EditResidenceHallCommand.php b/class/command/EditResidenceHallCommand.php index e181e73a..792606ca 100644 --- a/class/command/EditResidenceHallCommand.php +++ b/class/command/EditResidenceHallCommand.php @@ -85,7 +85,16 @@ public function execute(CommandContext $context) $hall->meal_plan_required = $context->get('meal_plan_required'); $hall->assignment_notifications = $context->get('assignment_notifications'); - $hall->setPackageDeskId($context->get('package_desk')); + + $packageDeskId = $context->get('package_desk'); + if ($packageDeskId > 0 ) + { + $hall->setPackageDeskId($packageDeskId); + } + else + { + $hall->setPackageDeskId(null); + } } else if ($context->get('tab') == 'images'){ $hall->exterior_image_id = $context->get('exterior_image_id'); diff --git a/class/command/SendAssignmentNotificationCommand.php b/class/command/SendAssignmentNotificationCommand.php index 2a82e5db..b0039e42 100644 --- a/class/command/SendAssignmentNotificationCommand.php +++ b/class/command/SendAssignmentNotificationCommand.php @@ -52,121 +52,129 @@ public function execute(CommandContext $context) throw new DatabaseException($result->toString()); } - foreach($result as $assignment){ - //get the students real name from their asu_username - $student = StudentFactory::getStudentByUsername($assignment->getUsername(), $term); + if($result) + { + foreach($result as $assignment){ + //get the students real name from their asu_username + $student = StudentFactory::getStudentByUsername($assignment->getUsername(), $term); - //get the location of their assignment - PHPWS_Core::initModClass('hms', 'HMS_Bed.php'); - $bed = new HMS_Bed($assignment->getBedId()); - $room = $bed->get_parent(); - $location = $bed->where_am_i() . ' - Bedroom ' . $bed->bedroom_label; + //get the location of their assignment + PHPWS_Core::initModClass('hms', 'HMS_Bed.php'); + $bed = new HMS_Bed($assignment->getBedId()); + $room = $bed->get_parent(); + $location = $bed->where_am_i() . ' - Bedroom ' . $bed->bedroom_label; - // Lookup the floor and hall to make sure the - // assignment notifications flag is true for this hall - $floor = $room->get_parent(); - $hall = $floor->get_parent(); + // Lookup the floor and hall to make sure the + // assignment notifications flag is true for this hall + $floor = $room->get_parent(); + $hall = $floor->get_parent(); - if($hall->assignment_notifications == 0){ - continue; - } + if($hall->assignment_notifications == 0){ + continue; + } - // Get the student type for determining move-in time - $type = $student->getType(); + // Get the student type for determining move-in time + $type = $student->getType(); - // Check for an accepted and confirmed RLC assignment - $rlcAssignment = HMS_RLC_Assignment::getAssignmentByUsername($student->getUsername(), $term); + // Check for an accepted and confirmed RLC assignment + $rlcAssignment = HMS_RLC_Assignment::getAssignmentByUsername($student->getUsername(), $term); - // If there is an assignment, make sure the student "confirmed" the rlc invite - if(!is_null($rlcAssignment)){ - if($rlcAssignment->getStateName() != 'confirmed' && $rlcAssignment->getStateName() != 'selfselect-assigned'){ - $rlcAssignment = null; + // If there is an assignment, make sure the student "confirmed" the rlc invite + if(!is_null($rlcAssignment)){ + if($rlcAssignment->getStateName() != 'confirmed' && $rlcAssignment->getStateName() != 'selfselect-assigned'){ + $rlcAssignment = null; + } } - } - // Make sure this is re-initialized - $moveinTimeId = null; - $rlcSetMoveinTime = false; - - // Determine the move-in time - if(!is_null($rlcAssignment)){ - // If there is a 'confirmed' RLC assignment, use the RLC's move-in times - $rlc = $rlcAssignment->getRlc(); - - if($type == TYPE_CONTINUING){ - $moveinTimeId = $rlc->getContinuingMoveinTime(); - }else if($type == TYPE_TRANSFER){ - $moveinTimeId = $rlc->getTransferMoveinTime(); - }else if($type == TYPE_FRESHMEN){ - $moveinTimeId = $rlc->getFreshmenMoveinTime(); + // Make sure this is re-initialized + $moveinTimeId = null; + $rlcSetMoveinTime = false; + + // Determine the move-in time + if(!is_null($rlcAssignment)){ + // If there is a 'confirmed' RLC assignment, use the RLC's move-in times + $rlc = $rlcAssignment->getRlc(); + + if($type == TYPE_CONTINUING){ + $moveinTimeId = $rlc->getContinuingMoveinTime(); + }else if($type == TYPE_TRANSFER){ + $moveinTimeId = $rlc->getTransferMoveinTime(); + }else if($type == TYPE_FRESHMEN){ + $moveinTimeId = $rlc->getFreshmenMoveinTime(); + } } - } - // If there's a non-null move-in time ID at this point, then we know the RLC must have set it - if(!is_null($moveinTimeId)){ - $rlcSetMoveinTime = true; - } + // If there's a non-null move-in time ID at this point, then we know the RLC must have set it + if(!is_null($moveinTimeId)){ + $rlcSetMoveinTime = true; + } - // If the RLC didn't set a movein time, set it according to the floor - // TODO: Find continuing students by checking the student's application term - // against the term we're wending assignment notices for - if(is_null($moveinTimeId)){ - if($type == TYPE_CONTINUING){ - $moveinTimeId = $assignment->get_rt_movein_time_id(); - }else if($type == TYPE_TRANSFER){ - $moveinTimeId = $assignment->get_t_movein_time_id(); - }else{ - $moveinTimeId = $assignment->get_f_movein_time_id(); + // If the RLC didn't set a movein time, set it according to the floor + // TODO: Find continuing students by checking the student's application term + // against the term we're wending assignment notices for + if(is_null($moveinTimeId)){ + if($type == TYPE_CONTINUING){ + $moveinTimeId = $assignment->get_rt_movein_time_id(); + }else if($type == TYPE_TRANSFER){ + $moveinTimeId = $assignment->get_t_movein_time_id(); + }else{ + $moveinTimeId = $assignment->get_f_movein_time_id(); + } } - } - // Check for missing move-in times - if($moveinTimeId == NULL){ - //test($assignment, 1); // Will only happen if there's no move-in time set for the floor,student type - // Lets only keep a set of the floors - if(!in_array($floor, $missingMovein)){ - $missingMovein[] = $floor; + // Check for missing move-in times + if($moveinTimeId == NULL){ + //test($assignment, 1); // Will only happen if there's no move-in time set for the floor,student type + // Lets only keep a set of the floors + if(!in_array($floor, $missingMovein)){ + $missingMovein[] = $floor; + } + + // Missing move-in time, so skip to the next assignment + continue; } - // Missing move-in time, so skip to the next assignment - continue; - } - - // TODO: Grab all the move-in times and index them in an array by ID so we don't have to query the DB every single time - $movein_time_obj = new HMS_Movein_Time($moveinTimeId); - $movein_time = $movein_time_obj->get_formatted_begin_end(); + // TODO: Grab all the move-in times and index them in an array by ID so we don't have to query the DB every single time + $movein_time_obj = new HMS_Movein_Time($moveinTimeId); + $movein_time = $movein_time_obj->get_formatted_begin_end(); - // Add a bit of text if the move-in time was for an RLC - if($rlcSetMoveinTime){ - $movein_time .= ' (for the ' . $rlc->get_community_name() . ' Residential Learning Community)'; - } + // Add a bit of text if the move-in time was for an RLC + if($rlcSetMoveinTime){ + $movein_time .= ' (for the ' . $rlc->get_community_name() . ' Residential Learning Community)'; + } - //get the list of roommates - $roommates = array(); + //get the list of roommates + $roommates = array(); - $beds = $room->get_beds(); - foreach($beds as $bed){ - $roommate = $bed->get_assignee(); - if($roommate == false || is_null($roommate) || $roommate->getUsername() == $student->getUsername()){ - continue; - } + $beds = $room->get_beds(); + foreach($beds as $bed){ + $roommate = $bed->get_assignee(); + if($roommate == false || is_null($roommate) || $roommate->getUsername() == $student->getUsername()){ + continue; + } - $roommates[] = $roommate->getFullName() . ' ('. $roommate->getUsername() . '@appstate.edu) - Bedroom ' . $bed->bedroom_label; - } + $roommates[] = $roommate->getFullName() . ' ('. $roommate->getUsername() . '@appstate.edu) - Bedroom ' . $bed->bedroom_label; + } - // Send the email - HMS_Email::sendAssignmentNotice($student->getUsername(), $student->getName(), $term, $location, $roommates, $movein_time); + // Send the email + HMS_Email::sendAssignmentNotice($student->getUsername(), $student->getName(), $term, $location, $roommates, $movein_time); - // Mark the student as having received an email - $db->reset(); - $db->addWhere('asu_username', $assignment->getUsername()); - $db->addWhere('term', $term); - $db->addValue('email_sent', 1); - $rslt = $db->update(); + // Mark the student as having received an email + $db->reset(); + $db->addWhere('asu_username', $assignment->getUsername()); + $db->addWhere('term', $term); + $db->addValue('email_sent', 1); + $rslt = $db->update(); - if(PHPWS_Error::logIfError($rslt)){ - throw new DatabaseException($result->toString()); - } + if(PHPWS_Error::logIfError($rslt)){ + throw new DatabaseException($result->toString()); + } + } + } + else + { + NQ::simple('hms', hms\NotificationView::ERROR, "No assignment notifications remaining that need to be sent."); + $context->goBack(); } // Check for floors with missing move-in times. diff --git a/inc/defines.php b/inc/defines.php index 4783b90b..b96b1b40 100644 --- a/inc/defines.php +++ b/inc/defines.php @@ -236,6 +236,7 @@ */ define('ADDRESS_PRMT_STUDENT', 'PS'); // Permanent student address define('ADDRESS_PRMT_RESIDENCE', 'PR'); // permenent student residence +define('ADDRESS_ASU_BOX', 'AB'); // ASU Box address /** * Room Types (used for summer applications) diff --git a/templates/admin/edit_residence_hall.tpl b/templates/admin/edit_residence_hall.tpl index e001e7d1..ce6e9612 100644 --- a/templates/admin/edit_residence_hall.tpl +++ b/templates/admin/edit_residence_hall.tpl @@ -56,7 +56,7 @@ {HALL_NAME}