コード例 #1
0
 /**
  * @Override FC_Document_Manager::postDocumentUpload().
  *
  * This is a copy and past of the overriden function except
  * that we now create a new Intern_Document object
  * and save it to databse.
  */
 public function postDocumentUpload()
 {
     // importPost in File_Common
     $result = $this->document->importPost('file_name');
     if (PEAR::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 Intern_Document in database.
             PHPWS_Core::initModClass('intern', 'Intern_Document.php');
             $doc = new Intern_Document();
             $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_SUCCESS, "File saved.");
         } else {
             if ($result) {
                 NQ::simple('intern', INTERN_SUCCESS, "File added.");
             } else {
                 if (PHPWS_Error::logIfError($result)) {
                     NQ::simple('intern', INTERN_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();
     }
 }
コード例 #2
0
 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');
 }
コード例 #3
0
 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;
     }
 }
コード例 #4
0
 /**
  * Get Document objects associated with this internship.
  */
 public function getDocuments()
 {
     PHPWS_Core::initModClass('intern', 'Intern_Document.php');
     $db = Intern_Document::getDB();
     $db->addWhere('internship_id', $this->id);
     return $db->getObjects('Intern_Document');
 }