public static function display()
 {
     /* Check if user can add/edit/hide/delete grad programs. */
     if (!Current_User::allow('intern', 'edit_grad_prog') && !Current_User::allow('intern', 'delete_grad_prog')) {
         NQ::simple('intern', INTERN_WARNING, 'You do not have permission to edit graduate programs.');
         return false;
     }
     $tpl['PAGER'] = self::doPager();
     javascript('/jquery/');
     javascriptMod('intern', 'editMajor', array('EDIT_ACTION' => GradProgram::getEditAction()));
     /* Form for adding new grad program */
     $form = new PHPWS_Form('add_prog');
     $form->addText('name');
     $form->setLabel('name', 'Graduate Program Title');
     $form->addSubmit('submit', 'Add Graduate Program');
     $form->setAction('index.php?module=intern&action=edit_grad');
     $form->addHidden('add', TRUE);
     $form->mergeTemplate($tpl);
     return PHPWS_Template::process($form->getTemplate(), 'intern', 'edit_grad.tpl');
 }
 /**
  * Builds the body of the internship form.
  */
 public function buildInternshipForm()
 {
     javascript('jquery');
     javascript('jquery_ui');
     javascriptMod('intern', 'spinner');
     javascriptMod('intern', 'formGoodies');
     // Form Submission setup
     $this->form->setAction('index.php?module=intern&action=add_internship');
     $this->form->addSubmit('submit', 'Save');
     /*********************
      * Workflow / Status *
      */
     PHPWS_Core::initModClass('intern', 'WorkflowStateFactory.php');
     PHPWS_Core::initModClass('intern', 'WorkflowTransitionView.php');
     // Check the Internship's state, and set a default state if it's a new internship
     $workflowState = $this->intern->getWorkflowState();
     if (is_null($workflowState)) {
         $state = WorkflowStateFactory::getState('CreationState');
         $this->intern->setState($state);
         // Set this initial value
     }
     // Workflow Transitions View, adds fields to the form by reference
     $transView = new WorkflowTransitionView($this->intern, $this->form);
     $transView->show();
     /*****************
      * OIED Approval *
      */
     $this->form->addCheck('oied_certified');
     $this->form->setLabel('oied_certified', 'Certified by Office of International Education and Development');
     // If the user is not allowed to do OIED certification, disable the checkbox
     if (!Current_User::allow('intern', 'oied_certify') || $this->intern->isDomestic()) {
         $this->form->setExtra('oied_certified', 'disabled');
     }
     // Hidden field that shadows the real field, to ensure a value is always submitted,
     // because disabled fields are not submitted
     $this->form->addHidden('oied_certified_hidden');
     /******************
      * Student fields *
      */
     $this->form->addText('student_first_name');
     $this->form->setLabel('student_first_name', 'First Name');
     $this->form->addCssClass('student_first_name', 'form-control');
     $this->form->addText('student_middle_name');
     $this->form->setLabel('student_middle_name', 'Middle Name/Initial');
     $this->form->addCssClass('student_middle_name', 'form-control');
     $this->form->addText('student_last_name');
     $this->form->setLabel('student_last_name', 'Last Name');
     $this->form->addCssClass('student_last_name', 'form-control');
     $this->form->addText('banner');
     $this->form->setLabel('banner', 'Banner ID');
     // Digits only
     $this->form->addCssClass('banner', 'form-control');
     $this->form->addText('student_phone');
     $this->form->setLabel('student_phone', 'Phone');
     $this->form->addCssClass('student_phone', 'form-control');
     $this->form->addText('student_email');
     $this->form->setLabel('student_email', 'ASU Email');
     $this->form->addCssClass('student_email', 'form-control');
     /* Student Address */
     $this->form->addText('student_address');
     $this->form->setLabel('student_address', 'Address');
     $this->form->addCssClass('student_address', 'form-control');
     $this->form->addText('student_city');
     $this->form->setLabel('student_city', 'City');
     $this->form->addCssClass('student_city', 'form-control');
     $this->form->addDropBox('student_state', State::$UNITED_STATES);
     $this->form->setLabel('student_state', 'State');
     $this->form->addCssClass('student_state', 'form-control');
     $this->form->addText('student_zip');
     $this->form->setLabel('student_zip', 'Zip Code');
     $this->form->addCssClass('student_zip', 'form-control');
     // GPA
     $this->form->addText('student_gpa');
     $this->form->setLabel('student_gpa', 'GPA');
     $this->form->addCssClass('student_gpa', 'form-control');
     // Campus
     $this->form->addRadioAssoc('campus', array('main_campus' => 'Main Campus', 'distance_ed' => 'Distance Ed'));
     $this->form->setMatch('campus', 'main_campus');
     // Student level
     $levels = array('-1' => 'Choose level', 'ugrad' => 'Undergraduate', 'grad' => 'Graduate');
     $this->form->addDropBox('student_level', $levels);
     $this->form->setLabel('student_level', 'Level');
     $this->form->addCssClass('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');
     $this->form->addDropBox('student_major', $levels);
     $this->form->setLabel('student_major', 'Major / Program');
     $this->form->addCssClass('student_major', 'form-control');
     /*****************************
      * Undergrad Major Drop Down *
      */
     if (isset($this->intern)) {
         $majors = Major::getMajorsAssoc($this->intern->ugrad_major);
     } else {
         $majors = Major::getMajorsAssoc();
     }
     $this->form->addSelect('ugrad_major', $majors);
     $this->form->setLabel('ugrad_major', 'Undergraduate Majors & Certificate Programs');
     $this->form->addCssClass('ugrad_major', 'form-control');
     /****************************
      * Graduate Major Drop Down *
      */
     if (isset($this->intern)) {
         $progs = GradProgram::getGradProgsAssoc($this->intern->grad_prog);
     } else {
         $progs = GradProgram::getGradProgsAssoc();
     }
     $this->form->addSelect('grad_prog', $progs);
     $this->form->setLabel('grad_prog', 'Graduate Majors & Certificate Programs');
     $this->form->addCssClass('grad_prog', 'form-control');
     /************************
      * Department Drop Down *
      */
     if (Current_User::isDeity()) {
         if (!is_null($this->intern)) {
             $depts = Department::getDepartmentsAssoc($this->intern->department_id);
         } else {
             $depts = Department::getDepartmentsAssoc();
         }
     } else {
         if (!is_null($this->intern)) {
             $depts = Department::getDepartmentsAssocForUsername(Current_User::getUsername(), $this->intern->department_id);
         } else {
             $depts = Department::getDepartmentsAssocForUsername(Current_User::getUsername());
         }
     }
     $this->form->addSelect('department', $depts);
     $this->form->setLabel('department', 'Department');
     $this->form->addCssClass('department', '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);
         $this->form->setMatch('department', $keys[1]);
     }
     /********************
      * Faculty Member Dropdown
      *
      * The options for this drop down are provided through AJAX on page-load and
      * when the user changes the department dropdown above.
      */
     $this->form->addSelect('faculty', array(-1 => 'Select Faculty Advisor'));
     $this->form->setExtra('faculty', 'disabled');
     $this->form->setLabel('faculty', 'Faculty Advisor / Instructor of Record');
     $this->form->addCssClass('faculty', 'form-control');
     // Hidden field for selected faculty member
     $this->form->addHidden('faculty_id');
     /***************
      * Agency info *
      */
     $this->form->addText('agency_name');
     $this->form->setLabel('agency_name', 'Agency Name');
     $this->form->addCssClass('agency_name', 'form-control');
     $this->form->addCheck('copy_address_agency');
     $this->form->setLabel('copy_address_agency', "Agency's address is same as Internship's");
     $this->form->addText('agency_address');
     $this->form->setLabel('agency_address', 'Address');
     $this->form->addCssClass('agency_address', 'form-control');
     $this->form->addText('agency_city');
     $this->form->setLabel('agency_city', 'City');
     $this->form->addCssClass('agency_city', 'form-control');
     $this->form->addSelect('agency_state', State::$UNITED_STATES);
     $this->form->setLabel('agency_state', 'State');
     $this->form->addCssClass('agency_state', 'form-control');
     $this->form->addText('agency_zip');
     $this->form->setLabel('agency_zip', 'Zip Code');
     $this->form->addCssClass('agency_zip', 'form-control');
     $this->form->addText('agency_province');
     $this->form->setLabel('agency_province', 'Province/Territory');
     $this->form->addCssClass('agency_province', 'form-control');
     $this->form->addText('agency_country');
     $this->form->setLabel('agency_country', 'Country');
     $this->form->addCssClass('agency_country', 'form-control');
     $this->form->addText('agency_phone');
     $this->form->setLabel('agency_phone', 'Phone');
     $this->form->addCssClass('agency_phone', 'form-control');
     /***
      * Agency supervisor info
      */
     $this->form->addText('agency_sup_first_name');
     $this->form->setLabel('agency_sup_first_name', 'First Name');
     $this->form->addCssClass('agency_sup_first_name', 'form-control');
     $this->form->addText('agency_sup_last_name');
     $this->form->setLabel('agency_sup_last_name', 'Last Name');
     $this->form->addCssClass('agency_sup_last_name', 'form-control');
     $this->form->addText('agency_sup_title');
     $this->form->setLabel('agency_sup_title', 'Title');
     $this->form->addCssClass('agency_sup_title', 'form-control');
     $this->form->addText('agency_sup_phone');
     $this->form->setLabel('agency_sup_phone', 'Phone');
     $this->form->addCssClass('agency_sup_phone', 'form-control');
     $this->form->addText('agency_sup_email');
     $this->form->setLabel('agency_sup_email', 'Email');
     $this->form->addCssClass('agency_sup_email', 'form-control');
     $this->form->addCheck('copy_address');
     $this->form->setLabel('copy_address', "Supervisor's address is same as agency's");
     $this->form->addText('agency_sup_address');
     $this->form->setLabel('agency_sup_address', 'Address');
     $this->form->addCssClass('agency_sup_address', 'form-control');
     $this->form->addText('agency_sup_city');
     $this->form->setLabel('agency_sup_city', 'City');
     $this->form->addCssClass('agency_sup_city', 'form-control');
     $this->form->addSelect('agency_sup_state', State::$UNITED_STATES);
     $this->form->setLabel('agency_sup_state', 'State');
     $this->form->addCssClass('agency_sup_state', 'form-control');
     $this->form->addText('agency_sup_zip');
     $this->form->setLabel('agency_sup_zip', 'Zip Code');
     $this->form->addCssClass('agency_sup_zip', 'form-control');
     $this->form->addText('agency_sup_province');
     $this->form->setLabel('agency_sup_province', 'Province');
     $this->form->addCssClass('agency_sup_province', 'form-control');
     $this->form->addText('agency_sup_country');
     $this->form->setLabel('agency_sup_country', 'Country');
     $this->form->addCssClass('agency_sup_country', 'form-control');
     $this->form->addText('agency_sup_fax');
     $this->form->setLabel('agency_sup_fax', 'Fax');
     $this->form->addCssClass('agency_sup_fax', 'form-control');
     /**********************
      * Internship details *
      */
     /***********************
      * Internship location *
      */
     $loc = array('domestic' => 'Domestic', 'internat' => 'International');
     $this->form->addRadioAssoc('location', $loc);
     //$this->form->setMatch('location', 'domestic'); // Default to domestic
     //$this->form->setRequired('location');
     // Domestic fields
     $this->form->addText('loc_address');
     $this->form->setLabel('loc_address', 'Address');
     $this->form->addCssClass('loc_address', 'form-control');
     $this->form->addText('loc_city');
     $this->form->setLabel('loc_city', 'City');
     $this->form->addCssClass('loc_city', 'form-control');
     $this->form->addSelect('loc_state', State::getAllowedStates());
     $this->form->setLabel('loc_state', 'State');
     $this->form->addCssClass('loc_state', 'form-control');
     $this->form->addText('loc_zip');
     $this->form->setLabel('loc_zip', 'Zip');
     $this->form->addCssClass('loc_zip', 'form-control');
     // Itn'l location fields
     $this->form->addText('loc_province');
     $this->form->setLabel('loc_province', 'Province/Territory');
     $this->form->addCssClass('loc_province', 'form-control');
     $this->form->addText('loc_country');
     $this->form->setLabel('loc_country', 'Country');
     $this->form->addCssClass('loc_country', 'form-control');
     /*************
      * Term Info *
      */
     $terms = Term::getFutureTermsAssoc();
     $terms[-1] = 'Select Term';
     $this->form->addSelect('term', $terms);
     $this->form->setLabel('term', 'Select Term');
     $this->form->addCssClass('term', 'form-control');
     $this->form->addText('start_date');
     $this->form->setLabel('start_date', 'Start Date');
     $this->form->addCssClass('start_date', 'form-control');
     $this->form->addText('end_date');
     $this->form->setLabel('end_date', 'End Date');
     $this->form->addCssClass('end_date', 'form-control');
     $this->form->addText('credits');
     $this->form->setLabel('credits', 'Credit Hours');
     $this->form->addCssClass('credits', 'form-control');
     $this->form->addText('avg_hours_week');
     $this->form->setLabel('avg_hours_week', 'Average Hours per Week');
     $this->form->addCssClass('avg_hours_week', 'form-control');
     $this->form->addCheck('multipart');
     $this->form->setLabel('multipart', 'This internship is part of a multi-part experience.');
     $this->form->addCheck('secondary_part');
     $this->form->setLabel('secondary_part', 'This is a secondary part (enrollment complete through primary part).');
     /***************
      * Course Info *
      */
     $subjects = Subject::getSubjects();
     $this->form->addSelect('course_subj', $subjects);
     $this->form->setLabel('course_subj', 'Subject');
     $this->form->addCssClass('course_subj', 'form-control');
     $this->form->addText('course_no');
     $this->form->setLabel('course_no', 'Number');
     $this->form->addCssClass('course_no', 'form-control');
     $this->form->addText('course_sect');
     $this->form->setLabel('course_sect', 'Section');
     $this->form->addCssClass('course_sect', 'form-control');
     $this->form->addText('course_title');
     $this->form->setLabel('course_title', 'Title');
     $this->form->setMaxSize('course_title', 28);
     // Limit to 28 chars, per Banner
     $this->form->addCssClass('course_title', 'form-control');
     // Corequisite
     if (!is_null($this->intern)) {
         $dept = $this->intern->getDepartment();
         if ($dept->hasCorequisite()) {
             $this->form->addText('corequisite_course_num');
             $this->form->addCssClass('corequisite_course_num', 'form-control');
             $this->form->addText('corequisite_course_sect');
             $this->form->addCssClass('corequisite_course_sect', 'form-control');
         }
     }
     /************
      * Pay Info *
      */
     $pay = array('unpaid' => 'Unpaid', 'paid' => 'Paid');
     $this->form->addRadioAssoc('payment', $pay);
     $this->form->setMatch('payment', 'unpaid');
     // Default to unpaid
     $this->form->addCheck('stipend');
     $this->form->setLabel('stipend', 'Stipend');
     $this->form->addText('pay_rate');
     $this->form->setLabel('pay_rate', 'Pay Rate');
     $this->form->addCssClass('pay_rate', 'form-control');
     /*******************
      * Internship Type *
      */
     $this->form->addRadioAssoc('experience_type', Internship::getTypesAssoc());
     $this->form->setMatch('experience_type', 'internship');
     /*********
      * Notes *
      */
     $this->form->addTextArea('notes');
     $this->form->setLabel('notes', 'Notes');
     $this->form->addCssClass('notes', 'form-control');
 }
 /**
  * Add a program to DB if it does not already exist.
  */
 public static function add($name)
 {
     $name = trim($name);
     if ($name == '') {
         return NQ::simple('intern', INTERN_ERROR, 'No name given for new graduate program. No graduate program added.');
     }
     /* Search DB for program with matching name. */
     $db = self::getDb();
     $db->addWhere('name', $name);
     if ($db->select('count') > 0) {
         NQ::simple('intern', INTERN_WARNING, "The graduate program <i>{$name}</i> already exists.");
         return;
     }
     /* Program does not exist...keep going */
     $prog = new GradProgram();
     $prog->name = $name;
     try {
         $prog->save();
     } catch (Exception $e) {
         NQ::simple('intern', INTERN_ERROR, "Error adding graduate program <i>{$name}</i>.<br/>" . $e->getMessage());
         return;
     }
     /* Program was successfully added. */
     NQ::simple('intern', INTERN_SUCCESS, "<i>{$name}</i> added as graduate program.");
 }
 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', '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 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;
     }
 }