public function execute(CommandContext $context)
 {
     NQ::close();
     header('HTTP/1.1 303 See Other');
     header("Location: {$_SERVER['SCRIPT_NAME']}?module=controlpanel");
     HMS::quit();
 }
예제 #2
0
파일: Command.php 프로젝트: sinkdb/events
 function redirect()
 {
     $path = $this->getURI();
     NQ::close();
     header('HTTP/1.1 303 See Other');
     header("Location: {$path}");
     Events::quit();
 }
 public function execute()
 {
     // Check permissions
     if (!\Current_User::allow('intern', 'create_internship')) {
         \NQ::simple('intern', NotifyUI::ERROR, 'You do not have permission to create new internships.');
         \NQ::close();
         \PHPWS_Core::home();
     }
     $view = new \Intern\AddInternshipView();
     return new \Response($view);
 }
예제 #4
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;
 }
예제 #5
0
 /**
  * Rename the Editable item with ID $id to $newName.
  */
 public function rename($newName)
 {
     /* Permission check */
     if (!Current_User::allow('intern', $this->getEditPermission())) {
         return NQ::simple('intern', INTERN_ERROR, 'You do not have permission to rename this.');
     }
     /* Must be valid name */
     $newName = trim($newName);
     if ($newName == '') {
         return NQ::simple('intern', INTERN_WARNING, 'No name was given. Nothing were changed.');
     }
     /* Check ID */
     if ($this->id == 0) {
         // Editable wasn't loaded correctly
         if (isset($_REQUEST['ajax'])) {
             NQ::simple('intern', INTERN_ERROR, "Error occurred while loading information from database.");
             NQ::close();
             echo true;
             exit;
         }
         NQ::simple('intern', INTERN_ERROR, "Error occurred while loading information from database.");
         return;
     }
     /* Keep old name around for NQ */
     $old = $this->name;
     try {
         /* Save and notify */
         $this->name = $newName;
         $this->save();
         if (isset($_REQUEST['ajax'])) {
             NQ::simple('intern', INTERN_SUCCESS, "<i>{$old}</i> renamed to <i>{$newName}</i>");
             NQ::close();
             echo true;
             exit;
         }
         return NQ::simple('intern', INTERN_SUCCESS, "<i>{$old}</i> renamed to <i>{$newName}</i>");
     } catch (Exception $e) {
         if (isset($_REQUEST['ajax'])) {
             NQ::simple('intern', INTERN_ERROR, $e->getMessage());
             NQ::close();
             echo false;
             exit;
         }
         return NQ::simple('intern', INTERN_ERROR, $e->getMessage());
     }
 }
예제 #6
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;
 }
 public function execute()
 {
     // Make sure an 'internship_id' key is set on the request
     if (!isset($_REQUEST['internship_id'])) {
         \NQ::simple('intern', NotifyUI::ERROR, 'No internship ID was given.');
         \NQ::close();
         \PHPWS_Core::reroute('index.php');
     }
     // Load the Internship
     try {
         $intern = InternshipFactory::getInternshipById($_REQUEST['internship_id']);
     } catch (\Intern\Exception\InternshipNotFoundException $e) {
         \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, 'Could not locate an internship with the given ID.');
         return;
     }
     if ($intern === false) {
         \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, 'Could not locate an internship with the given ID.');
         //TODO redirect to the search interface
         return;
     }
     // Load a fresh copy of the student data from the web service
     try {
         $student = StudentProviderFactory::getProvider()->getStudent($intern->getBannerId(), $intern->getTerm());
     } catch (\Intern\Exception\StudentNotFoundException $e) {
         $studentId = $intern->getBannerId();
         $student = null;
         \NQ::simple('intern', \Intern\UI\NotifyUI::WARNING, "We couldn't find a student with an ID of {$studentId} in Banner. This probably means this person is not an active student.");
     }
     // Load the WorkflowState
     $wfState = $intern->getWorkflowState();
     // Load the agency
     $agency = AgencyFactory::getAgencyById($intern->getAgencyId());
     // Load the documents
     $docs = $intern->getDocuments();
     if ($docs === null) {
         $docs = array();
         // if no docs, setup an empty array
     }
     $view = new InternshipView($intern, $student, $wfState, $agency, $docs);
     return $view->display();
 }
예제 #8
0
 public function execute()
 {
     PHPWS_Core::initModClass('intern', 'Internship.php');
     PHPWS_Core::initModClass('intern', 'Agency.php');
     PHPWS_Core::initModClass('intern', 'Department.php');
     PHPWS_Core::initModClass('intern', 'Faculty.php');
     /**************
      * Sanity Checks
      */
     // Required fields check
     $missing = self::checkRequest();
     if (!is_null($missing) && !empty($missing)) {
         // checkRequest returned some missing fields.
         $url = 'index.php?module=intern&action=edit_internship';
         $url .= '&missing=' . implode('+', $missing);
         // Restore the values in the fields the user already entered
         foreach ($_POST as $key => $val) {
             $url .= "&{$key}={$val}";
         }
         NQ::simple('intern', INTERN_ERROR, 'Please fill in the highlighted fields.');
         NQ::close();
         return PHPWS_Core::reroute($url);
     }
     // Sanity check the Banner ID
     if (!preg_match('/^\\d{9}$/', $_REQUEST['banner'])) {
         $url = 'index.php?module=intern&action=edit_internship&missing=banner';
         // Restore the values in the fields the user already entered
         foreach ($_POST as $key => $val) {
             $url .= "&{$key}={$val}";
         }
         NQ::simple('intern', INTERN_ERROR, "The Banner ID you entered is not valid. No changes were saved. The student's Banner ID should be nine digits only (no letters, spaces, or punctuation).");
         NQ::close();
         return PHPWS_Core::reroute($url);
     }
     // Sanity check student email
     if (isset($_REQUEST['student_email']) && preg_match("/@/", $_REQUEST['student_email'])) {
         $url = 'index.php?module=intern&action=edit_internship&missing=student_email';
         // Restore the values in the fields the user already entered
         foreach ($_POST as $key => $val) {
             $url .= "&{$key}={$val}";
         }
         NQ::simple('intern', INTERN_ERROR, "The student's email address is invalid. No changes were saved. Enter only the username portion of the student's email address. The '@appstate.edu' portion is not necessary.");
         NQ::close();
         return PHPWS_Core::reroute($url);
     }
     // Sanity check student zip
     if (isset($_REQUEST['student_zip']) && $_REQUEST['student_zip'] != "" && (strlen($_REQUEST['student_zip']) != 5 || !is_numeric($_REQUEST['student_zip']))) {
         $url = 'index.php?module=intern&action=edit_internship&missing=student_zip';
         // Restore the values in the fields the user already entered
         foreach ($_POST as $key => $val) {
             $url .= "&{$key}={$val}";
         }
         NQ::simple('intern', INTERN_ERROR, "The student's zip code is invalid. No changes were saved. Zip codes should be 5 digits only (no letters, spaces, or punctuation).");
         NQ::close();
         return PHPWS_Core::reroute($url);
     }
     // Course start date must be before end date
     if (!empty($_REQUEST['start_date']) && !empty($_REQUEST['end_date'])) {
         $start = strtotime($_REQUEST['start_date']);
         $end = strtotime($_REQUEST['end_date']);
         if ($start > $end) {
             $url = 'index.php?module=intern&action=edit_internship&missing=start_date+end_date';
             // Restore the values in the fields the user already entered
             unset($_POST['start_date']);
             unset($_POST['end_date']);
             foreach ($_POST as $key => $val) {
                 $url .= "&{$key}={$val}";
             }
             NQ::simple('intern', INTERN_WARNING, 'The internship start date must be before the end date.');
             NQ::close();
             return PHPWS_Core::reroute($url);
         }
     }
     // Sanity check internship location zip
     if (isset($_REQUEST['loc_zip']) && $_REQUEST['loc_zip'] != "" && (strlen($_REQUEST['loc_zip']) != 5 || !is_numeric($_REQUEST['loc_zip']))) {
         $url = 'index.php?module=intern&action=edit_internship&missing=loc_zip';
         // Restore the values in the fields the user already entered
         foreach ($_POST as $key => $val) {
             $url .= "&{$key}={$val}";
         }
         NQ::simple('intern', INTERN_ERROR, "The internship location's zip code is invalid. No changes were saved. Zip codes should be 5 digits only (no letters, spaces, or punctuation).");
         NQ::close();
         return PHPWS_Core::reroute($url);
     }
     // Sanity check agency zip
     if (isset($_REQUEST['agency_zip']) && $_REQUEST['agency_zip'] != "" && (strlen($_REQUEST['agency_zip']) != 5 || !is_numeric($_REQUEST['agency_zip']))) {
         $url = 'index.php?module=intern&action=edit_internship&missing=agency_zip';
         // Restore the values in the fields the user already entered
         foreach ($_POST as $key => $val) {
             $url .= "&{$key}={$val}";
         }
         NQ::simple('intern', INTERN_ERROR, "The agency's zip code is invalid. No changes were saved. Zip codes should be 5 digits only (no letters, spaces, or punctuation).");
         NQ::close();
         return PHPWS_Core::reroute($url);
     }
     // Sanity check supervisor's zip
     if (isset($_REQUEST['agency_sup_zip']) && $_REQUEST['agency_sup_zip'] != "" && (strlen($_REQUEST['agency_sup_zip']) != 5 || !is_numeric($_REQUEST['agency_sup_zip']))) {
         $url = 'index.php?module=intern&action=edit_internship&missing=agency_sup_zip';
         // Restore the values in the fields the user already entered
         foreach ($_POST as $key => $val) {
             $url .= "&{$key}={$val}";
         }
         NQ::simple('intern', INTERN_ERROR, "The agency supervisor's zip code is invalid. No changes were saved. Zip codes should be 5 digits only (no letters, spaces, or punctuation).");
         NQ::close();
         return PHPWS_Core::reroute($url);
     }
     // Sanity check course number
     if (isset($_REQUEST['course_no']) && $_REQUEST['course_no'] != '' && (strlen($_REQUEST['course_no']) > 20 || !is_numeric($_REQUEST['course_no']))) {
         $url = 'index.php?module=intern&action=edit_internship&missing=course_no';
         // Restore the values in the fields the user already entered
         foreach ($_POST as $key => $val) {
             $url .= "&{$key}={$val}";
         }
         NQ::simple('intern', INTERN_ERROR, "The course number provided is invalid. No changes were saved. Course numbers should be less than 20 digits (no letters, spaces, or punctuation).");
         NQ::close();
         return PHPWS_Core::reroute($url);
     }
     PHPWS_DB::begin();
     // Create/Save agency
     $agency = new Agency();
     if (isset($_REQUEST['agency_id'])) {
         // User is editing internship
         try {
             $agency = new Agency($_REQUEST['agency_id']);
         } catch (Exception $e) {
             // Rollback and re-throw the exception so that admins gets an email
             PHPWS_DB::rollback();
             throw $e;
         }
     }
     $agency->name = $_REQUEST['agency_name'];
     $agency->address = $_REQUEST['agency_address'];
     $agency->city = $_REQUEST['agency_city'];
     $agency->zip = $_REQUEST['agency_zip'];
     $agency->phone = $_REQUEST['agency_phone'];
     if ($_REQUEST['location'] == 'internat') {
         /* Location is INTERNATIONAL. Country is required. Province was typed in. */
         $agency->state = $_REQUEST['agency_state'];
         $agency->province = $_REQUEST['agency_province'];
         $agency->country = $_REQUEST['agency_country'];
         $agency->supervisor_state = $_REQUEST['agency_sup_state'];
         $agency->supervisor_province = $_REQUEST['agency_sup_province'];
         $agency->supervisor_country = $_REQUEST['agency_sup_country'];
     } else {
         /* Location is DOMESTIC. Country is U.S. State was chosen from drop down */
         $agency->state = $_REQUEST['agency_state'] == -1 ? null : $_REQUEST['agency_state'];
         $agency->country = 'United States';
         $agency->supervisor_state = $_REQUEST['agency_sup_state'] == -1 ? null : $_REQUEST['agency_sup_state'];
         $agency->supervisor_country = 'United States';
     }
     $agency->supervisor_first_name = $_REQUEST['agency_sup_first_name'];
     $agency->supervisor_last_name = $_REQUEST['agency_sup_last_name'];
     $agency->supervisor_title = $_REQUEST['agency_sup_title'];
     $agency->supervisor_phone = $_REQUEST['agency_sup_phone'];
     $agency->supervisor_email = $_REQUEST['agency_sup_email'];
     $agency->supervisor_fax = $_REQUEST['agency_sup_fax'];
     $agency->supervisor_address = $_REQUEST['agency_sup_address'];
     $agency->supervisor_city = $_REQUEST['agency_sup_city'];
     $agency->supervisor_zip = $_REQUEST['agency_sup_zip'];
     $agency->address_same_flag = isset($_REQUEST['copy_address']) ? 't' : 'f';
     try {
         $agencyId = $agency->save();
     } catch (Exception $e) {
         // Rollback and re-throw the exception so that admins gets an email
         PHPWS_DB::rollback();
         throw $e;
     }
     /**********************************
      * Create and/or save the Internship
      */
     if (isset($_REQUEST['internship_id']) && $_REQUEST['internship_id'] != '') {
         // User is editing internship
         try {
             PHPWS_Core::initModClass('intern', 'InternshipFactory.php');
             $i = InternshipFactory::getInternshipById($_REQUEST['internship_id']);
         } catch (Exception $e) {
             // Rollback and re-throw the exception so that admins gets an email
             PHPWS_DB::rollback();
             throw $e;
         }
     } else {
         $i = new Internship();
     }
     $i->term = $_REQUEST['term'];
     $i->agency_id = $agencyId;
     $i->faculty_id = $_REQUEST['faculty_id'] > 0 ? $_REQUEST['faculty_id'] : null;
     $i->department_id = $_REQUEST['department'];
     $i->start_date = !empty($_REQUEST['start_date']) ? strtotime($_REQUEST['start_date']) : 0;
     $i->end_date = !empty($_REQUEST['end_date']) ? strtotime($_REQUEST['end_date']) : 0;
     // Credit hours must be an integer (because of database column type),
     // so round the credit hours to nearest int
     if (isset($_REQUEST['credits'])) {
         $i->credits = round($_REQUEST['credits']);
     }
     $avg_hours_week = (int) $_REQUEST['avg_hours_week'];
     $i->avg_hours_week = $avg_hours_week ? $avg_hours_week : null;
     $i->paid = $_REQUEST['payment'] == 'paid';
     $i->stipend = isset($_REQUEST['stipend']) && $i->paid;
     $i->unpaid = $_REQUEST['payment'] == 'unpaid';
     $i->pay_rate = $_REQUEST['pay_rate'];
     // Internship experience type
     if (isset($_REQUEST['experience_type'])) {
         $i->setExperienceType($_REQUEST['experience_type']);
     }
     // Set fields depending on domestic/international
     if ($_REQUEST['location'] == 'domestic') {
         // Set Flags
         $i->domestic = 1;
         $i->international = 0;
         // Set state
         if ($_POST['loc_state'] != '-1') {
             $i->loc_state = strip_tags($_POST['loc_state']);
         } else {
             $i->loc_state = null;
         }
         // Clear province, country
         $i->loc_province = '';
         $i->loc_country = '';
     } else {
         if ($_REQUEST['location'] == 'internat') {
             // Set flags
             $i->domestic = 0;
             $i->international = 1;
             // Set province, country
             $i->loc_province = $_POST['loc_province'];
             $i->loc_country = strip_tags($_POST['loc_country']);
             // Clear state
             $i->loc_state = null;
         }
     }
     // Address, city, zip are always set (no matter domestic or international)
     $i->loc_address = strip_tags($_POST['loc_address']);
     $i->loc_city = strip_tags($_POST['loc_city']);
     $i->loc_zip = strip_tags($_POST['loc_zip']);
     if (isset($_POST['course_subj']) && $_POST['course_subj'] != '-1') {
         $i->course_subj = strip_tags($_POST['course_subj']);
     } else {
         $i->course_subj = null;
     }
     // Course info
     $i->course_no = strip_tags($_POST['course_no']);
     $i->course_sect = strip_tags($_POST['course_sect']);
     $i->course_title = strip_tags($_POST['course_title']);
     // Multipart course
     if (isset($_POST['multipart'])) {
         $i->multi_part = 1;
     } else {
         $i->multi_part = 0;
     }
     if (isset($_POST['multipart']) && isset($_POST['secondary_part'])) {
         $i->secondary_part = 1;
     } else {
         $i->secondary_part = 0;
     }
     // Corequisite Course Info
     if (isset($_POST['corequisite_course_num'])) {
         $i->corequisite_number = $_POST['corequisite_course_num'];
     }
     if (isset($_POST['corequisite_course_sect'])) {
         $i->corequisite_section = $_POST['corequisite_course_sect'];
     }
     // Student Information
     $i->first_name = $_REQUEST['student_first_name'];
     $i->middle_name = $_REQUEST['student_middle_name'];
     $i->last_name = $_REQUEST['student_last_name'];
     $i->setFirstNameMetaphone($_REQUEST['student_first_name']);
     $i->setLastNameMetaphone($_REQUEST['student_last_name']);
     $i->banner = $_REQUEST['banner'];
     $i->phone = $_REQUEST['student_phone'];
     $i->email = $_REQUEST['student_email'];
     $i->level = $_REQUEST['student_level'];
     // Check the level and record the major/program for this level.
     // Be sure to set/clear the other leve's major/program to null
     // in case the user is switching levels.
     if ($i->getLevel() == 'ugrad') {
         $i->ugrad_major = $_REQUEST['ugrad_major'];
         $i->grad_prog = null;
     } else {
         if ($i->getLevel() == 'grad') {
             $i->grad_prog = $_REQUEST['grad_prog'];
             $i->ugrad_major = null;
         }
     }
     $i->gpa = $_REQUEST['student_gpa'];
     $i->campus = $_REQUEST['campus'];
     $i->student_address = $_REQUEST['student_address'];
     $i->student_city = $_REQUEST['student_city'];
     if ($_REQUEST['student_state'] != '-1') {
         $i->student_state = $_REQUEST['student_state'];
     } else {
         $i->student_state = "";
     }
     $i->student_zip = $_REQUEST['student_zip'];
     /*
     $i->emergency_contact_name = $_REQUEST['emergency_contact_name'];
     $i->emergency_contact_relation = $_REQUEST['emergency_contact_relation'];
     $i->emergency_contact_phone = $_REQUEST['emergency_contact_phone'];
     */
     /************
      * OIED Certification
      */
     // If OIED certification has changed, then double check permissions
     $cert = $i->oied_certified == 1 ? true : false;
     $certSubmitted = $_POST['oied_certified_hidden'] == 'true' ? true : false;
     $certChanged = $cert != $certSubmitted;
     if ($certChanged && !Current_User::allow('intern', 'oied_certify')) {
         $url = "index.php?module=intern&action=edit_internship&internship_id={$i->getId()}";
         NQ::simple('intern', INTERN_ERROR, "You do not have permission to change the OIED certification checkbox. No changes were saved.");
         NQ::close();
         return PHPWS_Core::reroute($url);
     }
     // Check if this has changed from non-certified->certified so we can log it later
     if ($i->oied_certified == 0 && $_POST['oied_certified_hidden'] == 'true') {
         // note the change for later
         $oiedCertified = true;
     } else {
         $oiedCertified = false;
     }
     if ($_POST['oied_certified_hidden'] == 'true') {
         $i->oied_certified = 1;
     } else {
         if ($_POST['oied_certified_hidden'] == 'false') {
             $i->oied_certified = 0;
         } else {
             $i->oied_certified = 0;
         }
     }
     // If we don't have a state and this is a new internship,
     // the set an initial state
     if ($i->id == 0 && is_null($i->state)) {
         PHPWS_Core::initModClass('intern', 'WorkflowStateFactory.php');
         $state = WorkflowStateFactory::getState('CreationState');
         $i->setState($state);
         // Set this initial value
     }
     try {
         $i->save();
     } catch (Exception $e) {
         // Rollback and re-throw the exception so that admins gets an email
         PHPWS_DB::rollback();
         throw $e;
     }
     PHPWS_DB::commit();
     /***************************
      * State/Workflow Handling *
      ***************************/
     PHPWS_Core::initModClass('intern', 'WorkflowController.php');
     PHPWS_Core::initModClass('intern', 'WorkflowTransitionFactory.php');
     $t = WorkflowTransitionFactory::getTransitionByName($_POST['workflow_action']);
     $workflow = new WorkflowController($i, $t);
     try {
         $workflow->doTransition(isset($_POST['notes']) ? $_POST['notes'] : null);
     } catch (MissingDataException $e) {
         NQ::simple('intern', INTERN_ERROR, $e->getMessage());
         NQ::close();
         return PHPWS_Core::reroute('index.php?module=intern&action=edit_internship&internship_id=' . $i->id);
     }
     // Create a ChangeHisotry for the OIED certification.
     if ($oiedCertified) {
         $currState = WorkflowStateFactory::getState($i->getStateName());
         $ch = new ChangeHistory($i, Current_User::getUserObj(), time(), $currState, $currState, 'Certified by OIED');
         $ch->save();
     }
     $workflow->doNotification(isset($_POST['notes']) ? $_POST['notes'] : null);
     if (isset($_REQUEST['internship_id'])) {
         // Show message if user edited internship
         NQ::simple('intern', INTERN_SUCCESS, 'Saved internship for ' . $i->getFullName());
         NQ::close();
         return PHPWS_Core::reroute('index.php?module=intern&action=edit_internship&internship_id=' . $i->id);
     } else {
         NQ::simple('intern', INTERN_SUCCESS, 'Added internship for ' . $i->getFullName());
         NQ::close();
         return PHPWS_Core::reroute('index.php?module=intern&action=edit_internship&internship_id=' . $i->id);
     }
 }
예제 #9
0
            \PHPWS_Core::goBack();
        } catch (Exception $e) {
            $message2 = formatException($e);
            echo "The Intern Inventory has experienced a major internal error.  Attempting to email an admin and then exit.";
            $message = "Something terrible has happened, and the exception catch-all threw an exception.\n\nThe first exception was:\n\n{$message}\n\nThe second exception was:\n\n{$message2}";
            mail('*****@*****.**', 'A Major Intern Inventory Error Has Occurred', $message);
            exit;
        }
    }
}
/**
 * Plug content into TopUI. Show notifications. Add Style.
 */
if (isset($content)) {
    if ($content === false) {
        \NQ::close();
        \PHPWS_Core::reroute('index.php?module=intern');
    }
}
// Add top menu bar to theme
\PHPWS_Core::initModClass('intern', 'UI/TopUI.php');
UI\TopUI::plug();
// Get Notifications, add to layout
$nv = new UI\NotifyUI();
$notifications = $nv->display();
\Layout::add($notifications);
// Add content to Layout
\Layout::addStyle('intern', 'style.css');
\Layout::addStyle('intern', 'tango-icons.css');
\Layout::add($content);
function formatException(Exception $e)
 /**
  * @Override FC_Document_Manager::postDocumentUpload().
  *
  * This is a copy and past of the overriden function except
  * that we now create a new InternDocument object
  * and save it to databse.
  */
 public function postDocumentUpload()
 {
     // importPost in File_Common
     $result = $this->document->importPost('file_name');
     if (\PHPWS_Error::isError($result) || !$result) {
         \PHPWS_Error::log($result);
         $vars['timeout'] = '3';
         $vars['refresh'] = 0;
         javascript('close_refresh', $vars);
         return dgettext('filecabinet', 'An error occurred when trying to save your document.');
     } elseif ($result) {
         $result = $this->document->save();
         if (\PHPWS_Error::logIfError($result)) {
             $content = dgettext('filecabinet', '<p>Could not upload file to folder. Please check your directory permissions.</p>');
             $content .= sprintf('<a href="#" onclick="window.close(); return false">%s</a>', dgettext('filecabinet', 'Close this window'));
             Layout::nakedDisplay($content);
             exit;
         }
         //\PHPWS_Core::initModClass('filecabinet', 'File_Assoc.php');
         //\FC_File_Assoc::updateTag(\FC_DOCUMENT, $this->document->id, $this->document->getTag());
         $this->document->moveToFolder();
         // If the document's id is set in the request
         // then we are updating a file. Not need to insert
         // it into database.
         if (!isset($_REQUEST['document_id'])) {
             // Save InternDocument in database.
             $doc = new InternDocument();
             $doc->internship_id = $_REQUEST['internship'];
             $doc->document_fc_id = $this->document->id;
             $result = $doc->save();
         }
         // Choose the proper notification text...
         if (isset($_REQUEST['document_id']) && $_REQUEST['document_id'] && $result) {
             \NQ::simple('intern', \Intern\UI\NotifyUI::SUCCESS, "File saved.");
         } else {
             if ($result) {
                 \NQ::simple('intern', \Intern\UI\NotifyUI::SUCCESS, "File added.");
             } else {
                 if (\PHPWS_Error::logIfError($result)) {
                     \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, $result->toString());
                 }
             }
         }
         \NQ::close();
         if (!isset($_POST['im'])) {
             javascript('close_refresh');
         } else {
             javascript('/filecabinet/refresh_manager', array('document_id' => $this->document->id));
         }
     } else {
         return $this->edit();
     }
 }
예제 #11
0
파일: HMS.php 프로젝트: jlbooker/homestead
 public static function quit()
 {
     NQ::close();
     exit;
 }
 public function handleRequest()
 {
     /* Check if it is time to insert more terms into DB */
     if (Term::isTimeToUpdate()) {
         Term::doTermUpdate();
     }
     // Fetch the action from the REQUEST.
     if (!isset($_REQUEST['action'])) {
         $req = "";
     } else {
         $req = $_REQUEST['action'];
     }
     // Show requested page.
     switch ($req) {
         case 'example_form':
             header('Content-type: application/pdf');
             readfile(PHPWS_SOURCE_DIR . 'mod/intern/pdf/Internship_Example.pdf');
             exit;
             break;
         case 'edit_internship':
             PHPWS_Core::initModClass('intern', 'UI/InternshipUI.php');
             $view = new InternshipUI();
             $this->content = $view->display();
             break;
         case 'add_internship':
             PHPWS_Core::initModClass('intern', 'command/SaveInternship.php');
             $ctrl = new SaveInternship();
             $ctrl->execute();
             test('finished execute', 1);
             break;
         case 'search':
             PHPWS_Core::initModClass('intern', 'UI/SearchUI.php');
             $view = new SearchUI();
             $this->content = $view->display();
             break;
         case 'results':
             PHPWS_Core::initModClass('intern', 'UI/ResultsUI.php');
             $view = new ResultsUI();
             $this->content = $view->display();
             break;
         case DEPT_EDIT:
             PHPWS_Core::initModClass('intern', 'UI/DepartmentUI.php');
             PHPWS_Core::initModClass('intern', 'Department.php');
             if (isset($_REQUEST['add'])) {
                 /* Add department with the name in REQUEST */
                 if (isset($_REQUEST['name'])) {
                     Department::add($_REQUEST['name']);
                 } else {
                     NQ::simple('intern', INTERN_ERROR, "Department must have name.");
                 }
             } else {
                 if (isset($_REQUEST['rename'])) {
                     /* Rename dept with ID to new name that was passed in REQUEST */
                     if (isset($_REQUEST['id'])) {
                         $d = new Department($_REQUEST['id']);
                         $d->rename($_REQUEST['rename']);
                     } else {
                         NQ::simple('intern', INTERN_ERROR, "No ID given. Cannot rename department.");
                     }
                 } else {
                     if (isset($_REQUEST['hide'])) {
                         /* Hide/Show department with ID passed in REQUEST. */
                         if (isset($_REQUEST['id'])) {
                             $d = new Department($_REQUEST['id']);
                             $d->hide($_REQUEST['hide'] == 1);
                         } else {
                             NQ::simple('intern', INTERN_ERROR, "No ID given. Cannot hide department.");
                         }
                     } else {
                         if (isset($_REQUEST['del'])) {
                             /* Delete department with same ID passed in REQUEST. */
                             if (isset($_REQUEST['id'])) {
                                 $d = new Department($_REQUEST['id']);
                                 $d->del();
                             } else {
                                 NQ::simple('intern', INTERN_ERROR, "No ID given. Cannot delete department.");
                             }
                         } else {
                             if (isset($_REQUEST['fDel'])) {
                                 /** for now... */
                                 NQ::simple('intern', INTERN_WARNING, 'Sorry, cannot forcefully delete a department.');
                             }
                         }
                     }
                 }
             }
             $view = new DepartmentUI();
             $this->content = $view->display();
             break;
         case GRAD_PROG_EDIT:
             PHPWS_Core::initModClass('intern', 'GradProgram.php');
             PHPWS_Core::initModClass('intern', 'UI/GradProgramUI.php');
             if (isset($_REQUEST['add'])) {
                 /* Add grad program with the name in REQUEST */
                 if (isset($_REQUEST['name'])) {
                     GradProgram::add($_REQUEST['name']);
                 } else {
                     NQ::simple('intern', INTERN_ERROR, "Grad Program must have name.");
                 }
             } else {
                 if (isset($_REQUEST['rename'])) {
                     /* Rename program with ID to new name that was passed in REQUEST */
                     if (isset($_REQUEST['id'])) {
                         $g = new GradProgram($_REQUEST['id']);
                         $g->rename($_REQUEST['rename']);
                     } else {
                         NQ::simple('intern', INTERN_ERROR, "No ID given. Cannot rename graduate program.");
                     }
                 } else {
                     if (isset($_REQUEST['hide'])) {
                         /* Hide/Show program with ID passed in REQUEST. */
                         if (isset($_REQUEST['id'])) {
                             $g = new GradProgram($_REQUEST['id']);
                             $g->hide($_REQUEST['hide'] == 1);
                         } else {
                             NQ::simple('intern', INTERN_ERROR, "No ID given. Cannot hide graduate program.");
                         }
                     } else {
                         if (isset($_REQUEST['del'])) {
                             /* Delete program with same ID passed in REQUEST. */
                             if (isset($_REQUEST['id'])) {
                                 $g = new GradProgram($_REQUEST['id']);
                                 $g->del();
                             } else {
                                 NQ::simple('intern', INTERN_ERROR, "No ID given. Cannot delete graduate program.");
                             }
                         }
                     }
                 }
             }
             $view = new GradProgramUI();
             $this->content = $view->display();
             break;
         case MAJOR_EDIT:
             PHPWS_Core::initModClass('intern', 'UI/MajorUI.php');
             if (isset($_REQUEST['add'])) {
                 /* Add major with the name passed in REQUEST. */
                 if (isset($_REQUEST['name'])) {
                     Major::add($_REQUEST['name']);
                 } else {
                     NQ::simple('intern', INTERN_ERROR, "Major must have name.");
                 }
             } else {
                 if (isset($_REQUEST['rename'])) {
                     /* Rename major with ID to new name that was passed in REQUEST */
                     if (isset($_REQUEST['id'])) {
                         $m = new Major($_REQUEST['id']);
                         $m->rename($_REQUEST['rename']);
                     } else {
                         NQ::simple('intern', INTERN_ERROR, "No ID given. Cannot rename major.");
                     }
                 } else {
                     if (isset($_REQUEST['hide'])) {
                         /* Hide major with ID passed in REQUEST. */
                         if (isset($_REQUEST['id'])) {
                             $m = new Major($_REQUEST['id']);
                             $m->hide($_REQUEST['hide'] == 1);
                         } else {
                             NQ::simple('intern', INTERN_ERROR, "No ID given. Cannot hide major.");
                         }
                     } else {
                         if (isset($_REQUEST['del'])) {
                             /* Delete major with same ID passed in REQUEST. */
                             if (isset($_REQUEST['id'])) {
                                 $m = new Major($_REQUEST['id']);
                                 $m->del();
                             } else {
                                 NQ::simple('intern', INTERN_ERROR, "No ID given. Cannot delete major.");
                             }
                         }
                     }
                 }
             }
             $view = new MajorUI();
             $this->content = $view->display();
             break;
             /**
              * Matt additions!
              */
         /**
          * Matt additions!
          */
         case 'add_state':
             if (!Current_User::allow('intern', 'edit_state')) {
                 disallow();
             }
             PHPWS_Core::initModClass('intern', 'State.php');
             $state = new State($_GET['abbr']);
             $state->setActive(true);
             $state->save();
             exit;
             break;
         case 'remove_state':
             if (!Current_User::allow('intern', 'edit_state')) {
                 disallow();
             }
             PHPWS_Core::initModClass('intern', 'State.php');
             $state = new State($_GET['abbr']);
             $state->setActive(false);
             $state->save();
             exit;
             break;
         case STATE_EDIT:
             if (!Current_User::allow('intern', 'edit_state')) {
                 disallow();
             }
             PHPWS_Core::initModClass('intern', 'UI/StateUI.php');
             $view = new StateUI();
             $this->content = $view->display();
             break;
         case 'edit_admins':
             PHPWS_Core::initModClass('intern', 'UI/AdminUI.php');
             PHPWS_Core::initModClass('intern', 'Admin.php');
             PHPWS_Core::initModClass('intern', 'Department.php');
             if (isset($_REQUEST['add'])) {
                 // Add user in REQUEST to administrator list for the department in REQUEST.
                 Admin::add($_REQUEST['username'], $_REQUEST['department_id']);
             } else {
                 if (isset($_REQUEST['del'])) {
                     // Delete the user in REQUEST from department in REQUEST.
                     Admin::del($_REQUEST['username'], $_REQUEST['department_id']);
                 } else {
                     if (isset($_REQUEST['user_complete'])) {
                         $users = Admin::searchUsers($_REQUEST['term']);
                         echo json_encode($users);
                         exit;
                     }
                 }
             }
             $view = new AdminUI();
             $this->content = $view->display();
             break;
         case 'pdf':
             PHPWS_Core::initModClass('intern', 'InternshipFactory.php');
             PHPWS_Core::initModClass('intern', 'InternshipContractPdfView.php');
             PHPWS_Core::initModClass('intern', 'EmergencyContactFactory.php');
             $i = InternshipFactory::getInternshipById($_REQUEST['id']);
             $emgContacts = EmergencyContactFactory::getContactsForInternship($i);
             $pdfView = new InternshipContractPdfView($i, $emgContacts);
             $pdf = $pdfView->getPdf();
             $pdf->output();
             exit;
         case 'upload_document_form':
             PHPWS_Core::initModClass('intern', 'Intern_Document_Manager.php');
             $docManager = new Intern_Document_Manager();
             echo $docManager->edit();
             exit;
             break;
         case 'post_document_upload':
             PHPWS_Core::initModClass('intern', 'Intern_Document_Manager.php');
             $docManager = new Intern_Document_Manager();
             $docManager->postDocumentUpload();
             break;
         case 'delete_document':
             PHPWS_Core::initModClass('intern', 'Intern_Document.php');
             $doc = new Intern_Document($_REQUEST['doc_id']);
             $doc->delete();
             NQ::simple('intern', INTERN_SUCCESS, 'Document deleted.');
             NQ::close();
             PHPWS_Core::goBack();
             break;
         case 'addEmergencyContact':
             PHPWS_Core::initModClass('intern', 'command/AddEmergencyContact.php');
             $ctrl = new AddEmergencyContact();
             $ctrl->execute();
             break;
         case 'removeEmergencyContact':
             PHPWS_Core::initModClass('intern', 'command/RemoveEmergencyContact.php');
             $ctrl = new RemoveEmergencyContact();
             $ctrl->execute();
             break;
         case 'edit_faculty':
             PHPWS_Core::initModClass('intern', 'FacultyUI.php');
             $facultyUI = new FacultyUI();
             $this->content = $facultyUI->display();
             break;
         case 'getFacultyListForDept':
             PHPWS_Core::initModClass('intern', 'command/GetFacultyListForDept.php');
             $ctrl = new GetFacultyListForDept();
             $ctrl->execute();
             break;
         case 'restFacultyById':
             PHPWS_Core::initModClass('intern', 'command/RestFacultyById.php');
             $ctrl = new RestFacultyById();
             $ctrl->execute();
             break;
         case 'facultyDeptRest':
             PHPWS_Core::initModClass('intern', 'command/FacultyDeptRest.php');
             $ctrl = new FacultyDeptRest();
             $ctrl->execute();
             break;
         default:
             PHPWS_Core::initModClass('intern', 'UI/InternMenu.php');
             $menu = new InternMenu();
             $this->content = $menu->display();
             break;
     }
 }
 public static function display()
 {
     PHPWS_Core::initModClass('intern', 'Internship.php');
     PHPWS_Core::initModClass('intern', 'InternshipFactory.php');
     PHPWS_Core::initModClass('intern', 'Intern_Document.php');
     PHPWS_Core::initModClass('intern', 'Intern_Folder.php');
     PHPWS_Core::initModClass('intern', 'Agency.php');
     PHPWS_Core::initModClass('intern', 'InternshipFormView.php');
     PHPWS_Core::initModClass('intern', 'EditInternshipFormView.php');
     PHPWS_Core::initModClass('intern', 'Term.php');
     PHPWS_Core::initModClass('intern', 'Department.php');
     PHPWS_Core::initModClass('intern', 'Major.php');
     PHPWS_Core::initModClass('intern', 'GradProgram.php');
     PHPWS_Core::initModClass('intern', 'Subject.php');
     $tpl = array();
     if (isset($_REQUEST['internship_id'])) {
         /* Attempting to edit internship */
         try {
             $i = InternshipFactory::getInternshipById($_REQUEST['internship_id']);
         } catch (InternshipNotFoundException $e) {
             NQ::simple('intern', INTERN_ERROR, 'Could not locate an internship with the given ID.');
             return;
         }
         $internshipForm = new EditInternshipFormView('Edit Internship', $i);
         $internshipForm->buildInternshipForm();
         $internshipForm->plugInternship();
         $tpl['TITLE'] = 'Edit Internship';
         $form = $internshipForm->getForm();
         /*** 'Generate Contract' Button ***/
         $tpl['PDF'] = PHPWS_Text::linkAddress('intern', array('action' => 'pdf', 'id' => $i->id));
         /*** Document List ***/
         $docs = $i->getDocuments();
         if (!is_null($docs)) {
             foreach ($docs as $doc) {
                 $tpl['docs'][] = array('DOWNLOAD' => $doc->getDownloadLink('blah'), 'DELETE' => $doc->getDeleteLink());
             }
         }
         $folder = new Intern_Folder(Intern_Document::getFolderId());
         $tpl['UPLOAD_DOC'] = $folder->documentUpload($i->id);
         $wfState = $i->getWorkflowState();
         if (($wfState instanceof SigAuthReadyState || $wfState instanceof SigAuthApprovedState || $wfState instanceof DeanApprovedState || $wfState instanceof RegisteredState) && $docs < 1) {
             NQ::simple('intern', INTERN_WARNING, "No documents have been uploaded yet. Usually a copy of the signed contract document should be uploaded.");
         }
         /******************
          * Change History *
          */
         if (!is_null($i->id)) {
             PHPWS_Core::initModClass('intern', 'ChangeHistoryView.php');
             $historyView = new ChangeHistoryView($i);
             $tpl['CHANGE_LOG'] = $historyView->show();
         }
         // Show a warning if in SigAuthReadyState, is international, and not OIED approved
         if ($i->getWorkflowState() instanceof SigAuthReadyState && $i->isInternational() && !$i->isOiedCertified()) {
             NQ::simple('intern', INTERN_WARNING, 'This internship can not be approved by the Signature Authority bearer until the internship is certified by the Office of International Education and Development.');
         }
         // Show a warning if in DeanApproved state and is distance_ed campus
         if ($i->getWorkflowState() == 'DeanApprovedState' && $i->isDistanceEd()) {
             NQ::simple('intern', INTERN_WARNING, 'This internship must be registered by Distance Education.');
         }
         // Sanity check cource section #
         if ($i->isDistanceEd() && ($i->getCourseSection() < 300 || $i->getCourseSection() > 399)) {
             NQ::simple('intern', INTERN_WARNING, "This is a distance ed internship, so the course section number should be between 300 and 399.");
         }
         // Sanity check distance ed radio
         if (!$i->isDistanceEd() && ($i->getCourseSection() > 300 && $i->getCourseSection() < 400)) {
             NQ::simple('intern', INTERN_WARNING, "The course section number you entered looks like a distance ed course. Be sure to check the Distance Ed option, or double check the section number.");
         }
         PHPWS_Core::initModClass('intern', 'EmergencyContactFormView.php');
         $emgContactDialog = new EmergencyContactFormView($i);
         $tpl['ADD_EMERGENCY_CONTACT'] = '<button type="button" class="btn btn-default btn-sm" id="add-ec-button"><i class="fa fa-plus"></i> Add Contact</button>';
         $tpl['EMERGENCY_CONTACT_DIALOG'] = $emgContactDialog->getHtml();
     } else {
         // Attempting to create a new internship
         // Check permissions
         if (!Current_User::allow('intern', 'create_internship')) {
             NQ::simple('intern', INTERN_ERROR, 'You do not have permission to create new internships.');
             NQ::close();
             PHPWS_Core::home();
         }
         $tpl['TITLE'] = 'Add Internship';
         $internshipForm = new InternshipFormView('Add Internship');
         $internshipForm->buildInternshipForm();
         $tpl['AUTOFOCUS'] = 'autofocus';
         /* Show form with empty fields. */
         $form = $internshipForm->getForm();
         // Show a disabled button in document list if we are adding an internship.
         $tpl['UPLOAD_DOC'] = '<div title="Please save this internship first."><button id="doc-upload-btn" class="btn btn-default btn-sm" title="Please save this internship first." disabled="disabled"><i class="fa fa-upload"></i> Add document</button></div>';
         // Show a disabled emergency contact button
         $tpl['ADD_EMERGENCY_CONTACT'] = '<div title="Please save this internship first."><button class="btn btn-default btn-sm" id="add-ec-button" disabled="disabled" data-toggle="tooltip" title="first tooltip"><i class="fa fa-plus"></i> Add Contact</button></div>';
     }
     /*
      * If 'missing' is set then we have been redirected
      * back to the form because the user didn't type in something and
      * somehow got past the javascript.
      */
     if (isset($_REQUEST['missing'])) {
         $missing = explode(' ', $_REQUEST['missing']);
         //javascriptMod('intern', 'missing');
         /*
          * Set classes on field we are missing.
          */
         foreach ($missing as $m) {
             //$form->addCssClass($m, 'has-error');
             $form->addExtraTag($m, 'data-has-error="true"');
         }
         /* Plug old values back into form fields. */
         $form->plugIn($_GET);
         // If internship is being edited...
         if (isset($_REQUEST['internship_id'])) {
             /* Re-add hidden fields with object ID's */
             $i = InternshipFactory::getInternshipById($_GET['internship_id']);
             $a = $i->getAgency();
             //$f = $i->getFacultySupervisor();
             $form->addHidden('agency_id', $a->id);
             //$form->addHidden('supervisor_id', $f->id);
             $form->addHidden('id', $i->id);
         }
     }
     $form->mergeTemplate($tpl);
     //test($form->getTemplate(),1);
     return PHPWS_Template::process($form->getTemplate(), 'intern', 'add_internship.tpl');
 }
 public function execute()
 {
     /**************
      * Sanity Checks
      */
     // Required fields check
     $missing = self::checkRequest();
     if (!is_null($missing) && !empty($missing)) {
         // checkRequest returned some missing fields.
         $url = 'index.php?module=intern&action=ShowInternship';
         $url .= '&missing=' . implode('+', $missing);
         // Restore the values in the fields the user already entered
         foreach ($_POST as $key => $val) {
             $url .= "&{$key}={$val}";
         }
         \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, 'Please fill in the highlighted fields.');
         \NQ::close();
         return \PHPWS_Core::reroute($url);
     }
     // Sanity check student email
     if (isset($_REQUEST['student_email']) && preg_match("/@/", $_REQUEST['student_email'])) {
         $url = 'index.php?module=intern&action=ShowInternship&missing=student_email';
         // Restore the values in the fields the user already entered
         foreach ($_POST as $key => $val) {
             $url .= "&{$key}={$val}";
         }
         \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "The student's email address is invalid. No changes were saved. Enter only the username portion of the student's email address. The '@appstate.edu' portion is not necessary.");
         \NQ::close();
         return \PHPWS_Core::reroute($url);
     }
     // Sanity check student zip
     if (isset($_REQUEST['student_zip']) && $_REQUEST['student_zip'] != "" && !preg_match('/^[\\d]{5}$|^[\\d]{5}-[\\d]{4}$/', $_REQUEST['student_zip'])) {
         $url = 'index.php?module=intern&action=ShowInternship&missing=student_zip';
         // Restore the values in the fields the user already entered
         foreach ($_POST as $key => $val) {
             $url .= "&{$key}={$val}";
         }
         \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "The student's zip code is invalid. No changes were saved. The zip code should be 5 digits (no letters, spaces, or punctuation), OR use the extended nine digit form (e.g. 28608-1234).");
         \NQ::close();
         return \PHPWS_Core::reroute($url);
     }
     // Course start date must be before end date
     if (!empty($_REQUEST['start_date']) && !empty($_REQUEST['end_date'])) {
         $start = strtotime($_REQUEST['start_date']);
         $end = strtotime($_REQUEST['end_date']);
         if ($start > $end) {
             $url = 'index.php?module=intern&action=ShowInternship&missing=start_date+end_date';
             // Restore the values in the fields the user already entered
             unset($_POST['start_date']);
             unset($_POST['end_date']);
             foreach ($_POST as $key => $val) {
                 $url .= "&{$key}={$val}";
             }
             \NQ::simple('intern', Intern\NotifyUI::WARNING, 'The internship start date must be before the end date.');
             \NQ::close();
             return \PHPWS_Core::reroute($url);
         }
     }
     // Sanity check internship location zip
     if (isset($_REQUEST['loc_zip']) && $_REQUEST['loc_zip'] != "" && !is_numeric($_REQUEST['loc_zip'])) {
         $url = 'index.php?module=intern&action=ShowInternship&missing=loc_zip';
         // Restore the values in the fields the user already entered
         foreach ($_POST as $key => $val) {
             $url .= "&{$key}={$val}";
         }
         \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "The internship location's zip code is invalid. No changes were saved. Zip codes should be 5 digits only (no letters, spaces, or punctuation).");
         \NQ::close();
         return \PHPWS_Core::reroute($url);
     }
     // Sanity check agency zip
     if (isset($_REQUEST['agency_zip']) && $_REQUEST['agency_zip'] != "" && !is_numeric($_REQUEST['agency_zip'])) {
         $url = 'index.php?module=intern&action=ShowInternship&missing=agency_zip';
         // Restore the values in the fields the user already entered
         foreach ($_POST as $key => $val) {
             $url .= "&{$key}={$val}";
         }
         \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "The agency's zip code is invalid. No changes were saved. Zip codes should be 5 digits only (no letters, spaces, or punctuation).");
         \NQ::close();
         return \PHPWS_Core::reroute($url);
     }
     // Sanity check supervisor's zip
     if (isset($_REQUEST['agency_sup_zip']) && $_REQUEST['agency_sup_zip'] != "" && !is_numeric($_REQUEST['agency_sup_zip'])) {
         $url = 'index.php?module=intern&action=ShowInternship&missing=agency_sup_zip';
         // Restore the values in the fields the user already entered
         foreach ($_POST as $key => $val) {
             $url .= "&{$key}={$val}";
         }
         \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "The agency supervisor's zip code is invalid. No changes were saved. Zip codes should be 5 digits only (no letters, spaces, or punctuation).");
         \NQ::close();
         return \PHPWS_Core::reroute($url);
     }
     // Sanity check course number
     if (isset($_REQUEST['course_no']) && $_REQUEST['course_no'] != '' && (strlen($_REQUEST['course_no']) > 20 || !is_numeric($_REQUEST['course_no']))) {
         $url = 'index.php?module=intern&action=ShowInternship&missing=course_no';
         // Restore the values in the fields the user already entered
         foreach ($_POST as $key => $val) {
             $url .= "&{$key}={$val}";
         }
         \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "The course number provided is invalid. No changes were saved. Course numbers should be less than 20 digits (no letters, spaces, or punctuation).");
         \NQ::close();
         return \PHPWS_Core::reroute($url);
     }
     \PHPWS_DB::begin();
     /********************************
      * Load the existing internship *
      */
     try {
         $i = \Intern\InternshipFactory::getInternshipById($_REQUEST['internship_id']);
     } catch (\Exception $e) {
         // Rollback and re-throw the exception so that admins gets an email
         \PHPWS_DB::rollback();
         throw $e;
     }
     // Load the student object
     try {
         $student = StudentProviderFactory::getProvider()->getStudent($i->getBannerId(), $i->getTerm());
     } catch (StudentNotFoundException $e) {
         $student = null;
         \NQ::simple('intern', \Intern\UI\NotifyUI::WARNING, "We couldn't find a matching student in Banner. Your changes were saved, but this student probably needs to contact the Registrar's Office to re-enroll.");
         \NQ::close();
     }
     $i->faculty_id = $_REQUEST['faculty_id'] > 0 ? $_REQUEST['faculty_id'] : null;
     $i->department_id = $_REQUEST['department'];
     $i->start_date = !empty($_REQUEST['start_date']) ? strtotime($_REQUEST['start_date']) : 0;
     $i->end_date = !empty($_REQUEST['end_date']) ? strtotime($_REQUEST['end_date']) : 0;
     $i->credits = $_REQUEST['credits'] != '' ? (int) $_REQUEST['credits'] : null;
     $avg_hours_week = (int) $_REQUEST['avg_hours_week'];
     $i->avg_hours_week = $avg_hours_week ? $avg_hours_week : null;
     $i->paid = $_REQUEST['payment'] == 'paid';
     $i->stipend = isset($_REQUEST['stipend']) && $i->paid;
     $i->pay_rate = $_REQUEST['pay_rate'];
     // Internship experience type
     if (isset($_REQUEST['experience_type'])) {
         $i->setExperienceType($_REQUEST['experience_type']);
     }
     if ($i->isInternational()) {
         // Set province
         $i->loc_province = $_POST['loc_province'];
     }
     // Address, city, zip are always set (no matter domestic or international)
     $i->loc_address = strip_tags($_POST['loc_address']);
     $i->loc_city = strip_tags($_POST['loc_city']);
     $i->loc_zip = strip_tags($_POST['loc_zip']);
     if (isset($_POST['course_subj']) && $_POST['course_subj'] != '-1') {
         $i->course_subj = strip_tags($_POST['course_subj']);
     } else {
         $i->course_subj = null;
     }
     // Course info
     $i->course_no = strip_tags($_POST['course_no']);
     $i->course_sect = strip_tags($_POST['course_sect']);
     $i->course_title = strip_tags($_POST['course_title']);
     // Multipart course
     if (isset($_POST['multipart'])) {
         $i->multi_part = 1;
     } else {
         $i->multi_part = 0;
     }
     if (isset($_POST['multipart']) && isset($_POST['secondary_part'])) {
         $i->secondary_part = 1;
     } else {
         $i->secondary_part = 0;
     }
     // Corequisite Course Info
     if (isset($_POST['corequisite_course_num'])) {
         $i->corequisite_number = $_POST['corequisite_course_num'];
     }
     if (isset($_POST['corequisite_course_sect'])) {
         $i->corequisite_section = $_POST['corequisite_course_sect'];
     }
     // Student Information
     $i->first_name = $_REQUEST['student_first_name'];
     $i->middle_name = $_REQUEST['student_middle_name'];
     $i->last_name = $_REQUEST['student_last_name'];
     $i->setFirstNameMetaphone($_REQUEST['student_first_name']);
     $i->setMiddleNameMetaphone($_REQUEST['student_middle_name']);
     $i->setLastNameMetaphone($_REQUEST['student_last_name']);
     $i->phone = $_REQUEST['student_phone'];
     $i->email = $_REQUEST['student_email'];
     $i->student_address = $_REQUEST['student_address'];
     $i->student_city = $_REQUEST['student_city'];
     if ($_REQUEST['student_state'] != '-1') {
         $i->student_state = $_REQUEST['student_state'];
     } else {
         $i->student_state = "";
     }
     $i->student_zip = $_REQUEST['student_zip'];
     // Student major handling, if more than one major
     // Make sure we have a student object, since it could be null if the Banner lookup failed
     if (isset($student) && $student != null) {
         $majors = $student->getMajors();
     } else {
         $majors = array();
     }
     if (sizeof($majors) > 1) {
         if (!isset($_POST['major_code'])) {
             // Student has multiple majors, but user didn't choose one, so just take the first one
             $i->major_code = $majors[0]->getCode();
             $i->major_description = $majors[0]->getDescription();
         } else {
             // User choose a major, so loop over the set of majors until we find the matching major code
             $code = $_POST['major_code'];
             foreach ($majors as $m) {
                 if ($m->getCode() == $code) {
                     $major = $m;
                     break;
                 }
             }
             $i->major_code = $major->getCode();
             $i->major_description = $major->getDescription();
         }
     } else {
         if (sizeof($majors) == 1) {
             // Student has exactly one major
             $i->major_code = $majors[0]->getCode();
             $i->major_description = $majors[0]->getDescription();
         }
     }
     /************
      * OIED Certification
      */
     // Check if this has changed from non-certified->certified so we can log it later
     if ($i->oied_certified == 0 && $_POST['oied_certified_hidden'] == 'true') {
         // note the change for later
         $oiedCertified = true;
     } else {
         $oiedCertified = false;
     }
     if ($_POST['oied_certified_hidden'] == 'true') {
         $i->oied_certified = 1;
     } else {
         if ($_POST['oied_certified_hidden'] == 'false') {
             $i->oied_certified = 0;
         } else {
             $i->oied_certified = 0;
         }
     }
     // If we don't have a state and this is a new internship,
     // the set an initial state
     if ($i->id == 0 && is_null($i->state)) {
         $state = WorkflowStateFactory::getState('CreationState');
         $i->setState($state);
         // Set this initial value
     }
     try {
         $i->save();
     } catch (\Exception $e) {
         // Rollback and re-throw the exception so that admins gets an email
         \PHPWS_DB::rollback();
         throw $e;
     }
     // Update agency
     try {
         $agency = AgencyFactory::getAgencyById($_REQUEST['agency_id']);
     } catch (\Exception $e) {
         // Rollback and re-throw the exception so that admins gets an email
         \PHPWS_DB::rollback();
         throw $e;
     }
     // Agency Info
     $agency->name = $_REQUEST['agency_name'];
     $agency->address = $_REQUEST['agency_address'];
     $agency->city = $_REQUEST['agency_city'];
     $agency->zip = $_REQUEST['agency_zip'];
     $agency->phone = $_REQUEST['agency_phone'];
     if ($i->isDomestic()) {
         $agency->state = $_REQUEST['agency_state'] == '-1' ? null : $_REQUEST['agency_state'];
     } else {
         $agency->province = $_REQUEST['agency_province'];
         $agency->country = $_REQUEST['agency_country'] == '-1' ? null : $_REQUEST['agency_country'];
     }
     // Agency Supervisor Info
     $agency->supervisor_first_name = $_REQUEST['agency_sup_first_name'];
     $agency->supervisor_last_name = $_REQUEST['agency_sup_last_name'];
     $agency->supervisor_title = $_REQUEST['agency_sup_title'];
     $agency->supervisor_phone = $_REQUEST['agency_sup_phone'];
     $agency->supervisor_email = $_REQUEST['agency_sup_email'];
     $agency->supervisor_fax = $_REQUEST['agency_sup_fax'];
     $agency->supervisor_address = $_REQUEST['agency_sup_address'];
     $agency->supervisor_city = $_REQUEST['agency_sup_city'];
     $agency->supervisor_zip = $_REQUEST['agency_sup_zip'];
     if ($i->isDomestic()) {
         $agency->supervisor_state = $_REQUEST['agency_sup_state'];
     } else {
         $agency->supervisor_province = $_REQUEST['agency_sup_province'];
         $agency->supervisor_country = $_REQUEST['agency_sup_country'] == '-1' ? null : $_REQUEST['agency_sup_country'];
     }
     $agency->address_same_flag = isset($_REQUEST['copy_address']) ? 't' : 'f';
     try {
         DatabaseStorage::save($agency);
     } catch (\Exception $e) {
         // Rollback and re-throw the exception so that admins gets an email
         \PHPWS_DB::rollback();
         throw $e;
     }
     /***************************
      * State/Workflow Handling *
      ***************************/
     $t = \Intern\WorkflowTransitionFactory::getTransitionByName($_POST['workflow_action']);
     $workflow = new \Intern\WorkflowController($i, $t);
     try {
         $workflow->doTransition(isset($_POST['notes']) ? $_POST['notes'] : null);
     } catch (\Intern\Exception\MissingDataException $e) {
         \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, $e->getMessage());
         \NQ::close();
         return \PHPWS_Core::reroute('index.php?module=intern&action=ShowInternship&internship_id=' . $i->id);
     }
     // Create a ChangeHisotry for the OIED certification.
     if ($oiedCertified) {
         $currState = WorkflowStateFactory::getState($i->getStateName());
         $ch = new ChangeHistory($i, \Current_User::getUserObj(), time(), $currState, $currState, 'Certified by OIED');
         $ch->save();
     }
     \PHPWS_DB::commit();
     $workflow->doNotification(isset($_POST['notes']) ? $_POST['notes'] : null);
     //var_dump($_POST['generateContract']);exit;
     // If the user clicked the 'Generate Contract' button, then redirect to the PDF view
     if (isset($_POST['generateContract']) && $_POST['generateContract'] == 'true') {
         //return \PHPWS_Core::reroute('index.php?module=intern&action=pdf&internship_id=' . $i->id);
         echo json_encode($i);
         exit;
     } else {
         // Otherwise, redirect to the internship edit view
         // Show message if user edited internship
         \NQ::simple('intern', \Intern\UI\NotifyUI::SUCCESS, 'Saved internship for ' . $i->getFullName());
         \NQ::close();
         return \PHPWS_Core::reroute('index.php?module=intern&action=ShowInternship&internship_id=' . $i->id);
     }
 }
예제 #15
0
 public static function display()
 {
     PHPWS_Core::initModClass('intern', 'Term.php');
     PHPWS_Core::initModClass('intern', 'Department.php');
     PHPWS_Core::initModClass('intern', 'Major.php');
     PHPWS_Core::initModClass('intern', 'GradProgram.php');
     PHPWS_Core::initModClass('intern', 'Internship.php');
     PHPWS_Core::initModClass('intern', 'Agency.php');
     PHPWS_Core::initModClass('intern', 'Subject.php');
     PHPWS_Core::initModClass('intern', 'WorkflowStateFactory.php');
     // Set up search fields
     $form = new PHPWS_Form();
     $form->setMethod('get');
     $form->addHidden('module', 'intern');
     $form->addHidden('action', 'results');
     $form->useRowRepeat();
     $form->addText('name');
     $form->setLabel('name', "Name or Banner ID");
     $terms = Term::getTermsAssoc();
     //$thisTerm = Term::timeToTerm(time());
     $form->addSelect('term_select', $terms);
     $form->setLabel('term_select', 'Term');
     $form->setClass('term_select', 'form-control');
     //$form->setMatch('term_select', $thisTerm);
     // Deity can search for any department. Other users are restricted.
     if (Current_User::isDeity()) {
         $depts = Department::getDepartmentsAssoc();
     } else {
         $depts = Department::getDepartmentsAssocForUsername(Current_User::getUsername());
     }
     $form->addSelect('dept', $depts);
     $form->setLabel('dept', 'Department');
     //$form->setClass('', 'form-control');
     $form->setClass('dept', 'form-control');
     // If the user only has one department, select it for them
     // sizeof($depts) == 2 because of the 'Select Deparmtnet' option
     if (sizeof($depts) == 2) {
         $keys = array_keys($depts);
         $form->setMatch('dept', $keys[1]);
     }
     // Student level radio button
     javascript('jquery');
     javascriptMod('intern', 'majorSelector', array('form_id' => $form->id));
     $levels = array('-1' => 'Any Level', 'ugrad' => 'Undergraduate', 'grad' => 'Graduate');
     $form->addSelect('student_level', $levels);
     $form->setLabel('student_level', 'Level');
     $form->setClass('student_level', 'form-control');
     // Student Major dummy box (gets replaced by dropdowns below using JS when student_level is selected)
     $levels = array('-1' => 'Choose student level first');
     $form->addDropBox('student_major', $levels);
     $form->setLabel('student_major', 'Major / Program');
     $form->addCssClass('student_major', 'form-control');
     // Undergrad major drop down
     if (isset($s)) {
         $majors = Major::getMajorsAssoc($s->ugrad_major);
     } else {
         $majors = Major::getMajorsAssoc();
     }
     $form->addSelect('ugrad_major', $majors);
     $form->setLabel('ugrad_major', 'Undergraduate Majors &amp; Certificate Programs');
     $form->setClass('ugrad_major', 'form-control');
     // Graduate major drop down
     if (isset($s)) {
         $progs = GradProgram::getGradProgsAssoc($s->grad_prog);
     } else {
         $progs = GradProgram::getGradProgsAssoc();
     }
     $form->addSelect('grad_prog', $progs);
     $form->setLabel('grad_prog', 'Graduate Majors &amp; Certificate Programs');
     $form->setClass('grad_prog', 'form-control');
     // Campus
     $campuses = array('main_campus' => 'Main Campus', 'distance_ed' => 'Distance Ed');
     $form->addRadioAssoc('campus', $campuses);
     /***************
      * Course Info *
      ***************/
     $subjects = Subject::getSubjects();
     $form->addSelect('course_subj', $subjects);
     $form->setLabel('course_subj', 'Subject');
     $form->setClass('course_subj', 'form-control');
     $form->addText('course_no');
     $form->setLabel('course_no', 'Course Number');
     $form->setSize('course_no', 6);
     $form->setMaxSize('course_no', 4);
     $form->setClass('course_no', 'form-control');
     $form->addText('course_sect');
     $form->setLabel('course_sect', 'Section');
     $form->setSize('course_sect', 6);
     $form->setMaxSize('course_sect', 4);
     $form->setClass('course_sect', 'form-control');
     // Internship types.
     $types = Internship::getTypesAssoc();
     $form->addRadioAssoc('type', $types);
     // Location
     $loc = array('domestic' => 'Domestic', 'internat' => 'International');
     $form->addRadioAssoc('loc', $loc);
     /* State search */
     $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 state';
     $states = array_reverse($states, true);
     $form->addSelect('state', $states);
     $form->setLabel('state', 'State');
     $form->setClass('state', 'form-control');
     /* Province search */
     $form->addText('prov');
     $form->setLabel('prov', 'Province/Territory');
     $form->setClass('prov', 'form-control');
     // Workflow states
     $workflowStates = WorkflowStateFactory::getStatesAssoc();
     unset($workflowStates['CreationState']);
     // Remove this state, since it's not valid (internal only state for initial creation)
     $form->addCheckAssoc('workflow_state', $workflowStates);
     unset($_REQUEST['module']);
     unset($_REQUEST['action']);
     unset($_REQUEST['submit']);
     //test($_REQUEST,1);
     $form->plugIn($_REQUEST);
     $form->addSubmit('submit', 'Search');
     // Javascript...
     javascript('jquery');
     javascriptMod('intern', 'resetSearch');
     return PHPWS_Template::process($form->getTemplate(), 'intern', 'search.tpl');
 }
 public function execute(CommandContext $context)
 {
     // Check permissions
     if (!Current_User::allow('hms', 'checkin')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to checkin students.');
     }
     // Grab data from JSON source
     $bannerId = filter_input(INPUT_POST, 'bannerId', FILTER_VALIDATE_INT);
     $checkinId = filter_input(INPUT_POST, 'checkinId', FILTER_VALIDATE_INT);
     if (empty($bannerId)) {
         throw new InvalidArgumentException('Missing banner id.');
     }
     if (empty($checkinId)) {
         throw new InvalidArgumentException('Missing checkin id.');
     }
     // Check for key code
     //$keyCode = filter_input(INPUT_POST, 'keyCode',FILTER_SANITIZE_SPECIAL_CHARS);
     $keyCode = filter_input(INPUT_POST, 'keyCode', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/[^\\W]/')));
     $keyReturned = filter_input(INPUT_POST, 'keyReturned', FILTER_VALIDATE_BOOLEAN);
     if (!isset($keyReturned) || !isset($keyCode)) {
         throw new InvalidArgumentException('Missing key return information.');
     }
     if ($keyReturned == "1" && empty($keyCode)) {
         throw new InvalidArgumentException('Missing key code.');
     }
     $properCheckout = filter_input(INPUT_POST, 'properCheckout', FILTER_VALIDATE_BOOLEAN);
     $term = Term::getCurrentTerm();
     $this->term = $term;
     // Lookup the student
     $student = StudentFactory::getStudentByBannerId($bannerId, $term);
     // Get the existing check-in
     $checkin = CheckinFactory::getCheckinById($checkinId);
     // Make sure we found a check-in
     if (is_null($checkin)) {
         /*
         NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, we couldn't find a corresponding check-in for this check-out.");
         $errorCmd = CommandFactory::getCommand('ShowCheckoutForm');
         $errorCmd->setBannerId($bannerId);
         $errorCmd->setHallId($hallId);
         $errorCmd->redirect();
         */
         throw new Exception('Could not find a corresponding checkin.');
     }
     // Create the bed
     $bed = BedFactory::getBedByPersistentId($checkin->getBedPersistentId(), $term);
     // Get the room
     $room = $bed->get_parent();
     /*****
      * Add new damages
      */
     $newDamages = filter_input(INPUT_POST, 'newDamage', FILTER_SANITIZE_SPECIAL_CHARS, FILTER_REQUIRE_ARRAY);
     if (!empty($newDamages)) {
         foreach ($newDamages as $dmg) {
             $this->addDamage($dmg, $room);
         }
     }
     /******
      * Complete the Checkout
      */
     // Set checkout date and user
     $checkin->setCheckoutDate(time());
     $checkin->setCheckoutBy(Current_User::getUsername());
     // Set the checkout code code, if any
     $checkin->setCheckoutKeyCode($keyCode);
     // Improper checkout handling
     if ($properCheckout == "1") {
         $checkin->setImproperCheckout(false);
     } else {
         $checkin->setImproperCheckout(true);
         $improperNote = filter_input(INPUT_POST, 'improperNote', FILTER_SANITIZE_SPECIAL_CHARS);
         // Add damage for improper checkout
         // TODO: Find a better way to handle the magic number for dmg type
         $dmg = array('damage_type' => 105, 'side' => 'both', 'note' => $improperNote, 'residents' => array(array('studentId' => $student->getBannerId(), 'selected' => true)));
         $this->addDamage($dmg, $room);
         // Add the improper checkout note
         $checkin->setImproperCheckoutNote($improperNote);
     }
     if ($keyReturned == "1") {
         $checkin->setKeyNotReturned(false);
     } else {
         $checkin->setKeyNotReturned(true);
         // Add a damage record for key not returned
         // TODO: Find a better way to handle the magic number for dmg type
         $dmg = array('damage_type' => 79, 'side' => 'both', 'note' => 'Key not returned.', 'residents' => array(array('studentId' => $student->getBannerId(), 'selected' => true)));
         $this->addDamage($dmg, $room);
     }
     // Save the check-in
     $checkin->save();
     // Add this to the activity log
     HMS_Activity_Log::log_activity($student->getUsername(), ACTIVITY_CHECK_OUT, UserStatus::getUsername(), $bed->where_am_i());
     // Generate the RIC
     PHPWS_Core::initModClass('hms', 'InfoCard.php');
     PHPWS_Core::initModClass('hms', 'InfoCardPdfView.php');
     $infoCard = new InfoCard($checkin);
     /*
      * Info card removed per #869
     $infoCardView = new InfoCardPdfView();
     $infoCardView->addInfoCard($infoCard);
     */
     // Send confirmation Email with the RIC form to the student
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     HMS_Email::sendCheckoutConfirmation($student, $infoCard);
     /***** Room Change Request Handling *******/
     // Check if this checkout was part of a room change request
     PHPWS_Core::initModClass('hms', 'RoomChangeRequestFactory.php');
     PHPWS_Core::initModClass('hms', 'RoomChangeParticipantFactory.php');
     $request = RoomChangeRequestFactory::getRequestPendingCheckout($student, $term);
     if (!is_null($request)) {
         $participant = RoomChangeParticipantFactory::getParticipantByRequestStudent($request, $student);
         // Transition to StudentApproved state
         $participant->transitionTo(new ParticipantStateCheckedOut($participant, time(), null, UserStatus::getUsername()));
         // If all the participants are in CheckedOut state, then this room change is complete, so transition it
         if ($request->allParticipantsInState('CheckedOut')) {
             $request->transitionTo(new RoomChangeStateComplete($request, time(), null, UserStatus::getUsername()));
         }
     }
     // Cleanup and redirect
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Checkout successful.');
     NQ::close();
     exit;
 }
예제 #17
0
 /**
  * Redirect to the add internship interface and highlight any missing fields
  */
 private function redirectToForm()
 {
     \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "Please complete the highlighted fields.");
     \NQ::close();
     return \PHPWS_Core::reroute('index.php?module=intern&action=ShowAddInternship');
 }
예제 #18
0
 public function display()
 {
     javascript('jquery');
     \Layout::addPageTitle('Search Results');
     // Initalize variables
     $dept = null;
     $term = null;
     $name = null;
     $ugradMajor = null;
     $gradProg = null;
     $level = null;
     $campus = null;
     $type = null;
     $loc = null;
     $state = null;
     $country = null;
     $workflowState = null;
     $courseSubject = null;
     $courseNum = null;
     $courseSect = null;
     /**
      * Check if any search fields are set.
      * This is a pretty nasty block of code...
      */
     if (isset($_REQUEST['dept'])) {
         $dept = $_REQUEST['dept'];
     }
     if (isset($_REQUEST['term_select'])) {
         $term = $_REQUEST['term_select'];
     }
     if (isset($_REQUEST['name'])) {
         $name = $_REQUEST['name'];
     }
     if (isset($_REQUEST['undergrad_major'])) {
         $ugradMajor = $_REQUEST['undergrad_major'];
     }
     if (isset($_REQUEST['graduate_major'])) {
         $gradProg = $_REQUEST['graduate_major'];
     }
     if (isset($_REQUEST['student_level']) && $_REQUEST['student_level'] != '-1') {
         $level = $_REQUEST['student_level'];
     }
     if (isset($_REQUEST['type'])) {
         $type = $_REQUEST['type'];
     }
     if (isset($_REQUEST['campus'])) {
         $campus = $_REQUEST['campus'];
     }
     if (isset($_REQUEST['location'])) {
         $loc = $_REQUEST['location'];
     }
     if (isset($_REQUEST['state'])) {
         $state = $_REQUEST['state'];
     }
     if (isset($_REQUEST['country'])) {
         $country = $_REQUEST['country'];
     }
     if (isset($_REQUEST['workflow_state'])) {
         $workflowState = $_REQUEST['workflow_state'];
     }
     if (isset($_REQUEST['course_subj'])) {
         $courseSubject = $_REQUEST['course_subj'];
     }
     if (isset($_REQUEST['course_no'])) {
         $courseNum = $_REQUEST['course_no'];
     }
     if (isset($_REQUEST['course_sect'])) {
         $courseSect = $_REQUEST['course_sect'];
     }
     /* Get Pager */
     $pager = self::getPager($name, $dept, $term, $ugradMajor, $gradProg, $level, $type, $campus, $loc, $state, $country, $workflowState, $courseSubject, $courseNum, $courseSect);
     $pagerContent = $pager->get();
     // If there were no results, send the user back to the search interface
     if ($pager->total_rows == 0) {
         \NQ::simple('intern', NotifyUI::WARNING, "There were no internships that matched your search criteria. If you're looking for a specific student double check the student's name, id number, or email address. Otherwise, try selecting less search criteria and then search again.");
         \NQ::close();
         // Rebuild the URL
         $url = 'index.php?module=intern&action=search&';
         unset($_REQUEST['action']);
         unset($_REQUEST['module']);
         $url .= http_build_query($_REQUEST);
         return \PHPWS_Core::reroute($url);
     }
     return $pagerContent;
 }
 public function handleRequest()
 {
     /* Check if it is time to insert more terms into DB */
     if (Term::isTimeToUpdate()) {
         Term::doTermUpdate();
     }
     // Fetch the action from the REQUEST.
     if (!isset($_REQUEST['action'])) {
         $req = "";
     } else {
         $req = $_REQUEST['action'];
     }
     // Show requested page.
     switch ($req) {
         case 'example_form':
             header('Content-type: application/pdf');
             readfile(\PHPWS_SOURCE_DIR . 'mod/intern/pdf/Internship_Example.pdf');
             exit;
             break;
         case 'ShowInternship':
             $ctrl = new Command\ShowInternship();
             $this->content = $ctrl->execute();
             break;
         case 'ShowAddInternship':
             $ctrl = new Command\ShowAddInternship();
             $this->content = $ctrl->execute()->getView()->render();
             break;
         case 'AddInternship':
             $ctrl = new Command\AddInternship();
             $ctrl->execute();
             break;
         case 'SaveInternship':
             $ctrl = new Command\SaveInternship();
             $ctrl->execute();
             break;
         case 'search':
             $view = new UI\SearchUI();
             $this->content = $view->display();
             break;
         case 'results':
             $view = new UI\ResultsUI();
             $this->content = $view->display();
             break;
         case 'showEditDept':
             $view = new UI\DepartmentUI();
             $this->content = $view->display();
             break;
         case 'edit_dept':
             if (isset($_REQUEST['add'])) {
                 /* Add department with the name in REQUEST */
                 if (isset($_REQUEST['name'])) {
                     Department::add($_REQUEST['name']);
                 } else {
                     \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "Department must have name.");
                 }
             } else {
                 if (isset($_REQUEST['rename'])) {
                     /* Rename dept with ID to new name that was passed in REQUEST */
                     if (isset($_REQUEST['id'])) {
                         $d = new Department($_REQUEST['id']);
                         $d->rename($_REQUEST['rename']);
                     } else {
                         \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "No ID given. Cannot rename department.");
                     }
                 } else {
                     if (isset($_REQUEST['hide'])) {
                         /* Hide/Show department with ID passed in REQUEST. */
                         if (isset($_REQUEST['id'])) {
                             $d = new Department($_REQUEST['id']);
                             $d->hide($_REQUEST['hide'] == 1);
                         } else {
                             \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "No ID given. Cannot hide department.");
                         }
                     } else {
                         if (isset($_REQUEST['del'])) {
                             /* Delete department with same ID passed in REQUEST. */
                             if (isset($_REQUEST['id'])) {
                                 $d = new Department($_REQUEST['id']);
                                 $d->del();
                             } else {
                                 \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "No ID given. Cannot delete department.");
                             }
                         }
                     }
                 }
             }
             \PHPWS_Core::reroute('index.php?module=intern&action=showEditDept');
             break;
         case 'showEditGradProgs':
             $view = new UI\GradProgramUI();
             $this->content = $view->display();
             break;
         case 'edit_grad':
             //TODO Separate these into their own controllers
             if (isset($_REQUEST['add'])) {
                 /* Add grad program with the name in REQUEST */
                 if (isset($_REQUEST['name'])) {
                     GradProgram::add($_REQUEST['name']);
                 } else {
                     \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "Grad Program must have name.");
                 }
             } else {
                 if (isset($_REQUEST['rename'])) {
                     /* Rename program with ID to new name that was passed in REQUEST */
                     if (isset($_REQUEST['id'])) {
                         $g = new GradProgram($_REQUEST['id']);
                         $g->rename($_REQUEST['rename']);
                     } else {
                         \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "No ID given. Cannot rename graduate program.");
                     }
                 } else {
                     if (isset($_REQUEST['hide'])) {
                         /* Hide/Show program with ID passed in REQUEST. */
                         if (isset($_REQUEST['id'])) {
                             $g = new GradProgram($_REQUEST['id']);
                             $g->hide($_REQUEST['hide'] == 1);
                         } else {
                             \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "No ID given. Cannot hide graduate program.");
                         }
                     } else {
                         if (isset($_REQUEST['del'])) {
                             /* Delete program with same ID passed in REQUEST. */
                             if (isset($_REQUEST['id'])) {
                                 $g = new GradProgram($_REQUEST['id']);
                                 $g->del();
                             } else {
                                 \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "No ID given. Cannot delete graduate program.");
                             }
                         }
                     }
                 }
             }
             \PHPWS_Core::reroute('index.php?module=intern&action=showEditGradProgs');
             break;
         case 'showEditMajors':
             $view = new UI\MajorUI();
             $this->content = $view->display();
             break;
         case 'edit_major':
             // TODO: Break these into their own commands
             if (isset($_REQUEST['add'])) {
                 /* Add major with the name passed in REQUEST. */
                 if (isset($_REQUEST['name'])) {
                     Major::add($_REQUEST['name']);
                 } else {
                     \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "Major must have name.");
                 }
             } else {
                 if (isset($_REQUEST['rename'])) {
                     /* Rename major with ID to new name that was passed in REQUEST */
                     if (isset($_REQUEST['id'])) {
                         $m = new Major($_REQUEST['id']);
                         $m->rename($_REQUEST['rename']);
                     } else {
                         \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "No ID given. Cannot rename major.");
                     }
                 } else {
                     if (isset($_REQUEST['hide'])) {
                         /* Hide major with ID passed in REQUEST. */
                         if (isset($_REQUEST['id'])) {
                             $m = new Major($_REQUEST['id']);
                             $m->hide($_REQUEST['hide'] == 1);
                         } else {
                             \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "No ID given. Cannot hide major.");
                         }
                     } else {
                         if (isset($_REQUEST['del'])) {
                             /* Delete major with same ID passed in REQUEST. */
                             if (isset($_REQUEST['id'])) {
                                 $m = new Major($_REQUEST['id']);
                                 $m->del();
                             } else {
                                 \NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, "No ID given. Cannot delete major.");
                             }
                         }
                     }
                 }
             }
             \PHPWS_Core::reroute('index.php?module=intern&action=showEditMajors');
             break;
             /**
              * Matt additions!
              */
         /**
          * Matt additions!
          */
         case 'add_state':
             if (!Current_User::allow('intern', 'edit_state')) {
                 disallow();
             }
             $state = new State($_GET['abbr']);
             $state->setActive(true);
             $state->save();
             exit;
             break;
         case 'remove_state':
             if (!Current_User::allow('intern', 'edit_state')) {
                 disallow();
             }
             $state = new State($_GET['abbr']);
             $state->setActive(false);
             $state->save();
             exit;
             break;
         case 'edit_states':
             if (!Current_User::allow('intern', 'edit_state')) {
                 disallow();
             }
             $view = new StateUI();
             $this->content = $view->display();
             break;
         case 'showEditAdmins':
             $view = new UI\AdminUI();
             $this->content = $view->display();
             break;
         case 'edit_admins':
             if (isset($_REQUEST['add'])) {
                 // Add user in REQUEST to administrator list for the department in REQUEST.
                 Admin::add($_REQUEST['username'], $_REQUEST['department_id']);
             } else {
                 if (isset($_REQUEST['del'])) {
                     // Delete the user in REQUEST from department in REQUEST.
                     Admin::del($_REQUEST['username'], $_REQUEST['department_id']);
                 } else {
                     if (isset($_REQUEST['user_complete'])) {
                         $users = Admin::searchUsers($_REQUEST['term']);
                         echo json_encode($users);
                         exit;
                     }
                 }
             }
             $view = new UI\AdminUI();
             $this->content = $view->display();
             break;
         case 'pdf':
             $i = InternshipFactory::getInternshipById($_REQUEST['internship_id']);
             $emgContacts = EmergencyContactFactory::getContactsForInternship($i);
             $pdfView = new InternshipContractPdfView($i, $emgContacts);
             $pdf = $pdfView->getPdf();
             $pdf->output();
             exit;
         case 'upload_document_form':
             $docManager = new DocumentManager();
             echo $docManager->edit();
             exit;
             break;
         case 'post_document_upload':
             $docManager = new DocumentManager();
             $docManager->postDocumentUpload();
             break;
         case 'delete_document':
             $doc = new InternDocument($_REQUEST['doc_id']);
             $doc->delete();
             \NQ::simple('intern', \Intern\UI\NotifyUI::SUCCESS, 'Document deleted.');
             \NQ::close();
             \PHPWS_Core::goBack();
             break;
         case 'addEmergencyContact':
             $ctrl = new Command\AddEmergencyContact();
             $ctrl->execute();
             break;
         case 'removeEmergencyContact':
             $ctrl = new Command\RemoveEmergencyContact();
             $ctrl->execute();
             break;
         case 'edit_faculty':
             $facultyUI = new UI\FacultyUI();
             $this->content = $facultyUI->display();
             break;
         case 'getFacultyListForDept':
             $ctrl = new Command\GetFacultyListForDept();
             $ctrl->execute();
             break;
         case 'restFacultyById':
             $ctrl = new Command\RestFacultyById();
             $ctrl->execute();
             break;
         case 'facultyDeptRest':
             $ctrl = new Command\FacultyDeptRest();
             $ctrl->execute();
             break;
         case 'GetSearchSuggestions':
             $ctrl = new Command\GetSearchSuggestions();
             $ctrl->execute();
             break;
         case 'GetAvailableStates':
             $ctrl = new Command\GetAvailableStates();
             $ctrl->execute();
             break;
         case 'GetAvailableCountries':
             $ctrl = new Command\GetAvailableCountries();
             $ctrl->execute();
             break;
         case 'GetDepartments':
             $ctrl = new Command\GetDepartments();
             $ctrl->execute();
             break;
         case 'GetAvailableTerms':
             $ctrl = new Command\GetAvailableTerms();
             $ctrl->execute();
             break;
         default:
             $menu = new UI\InternMenu();
             $this->content = $menu->display();
             break;
     }
 }