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);
 }
 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();
     }
     // Get a list of any missing input the user didn't fill in
     $missingFieldList = $this->checkForMissingInput();
     // If there are missing fields, redirect to the add internship interface
     if (!empty($missingFieldList)) {
         $this->redirectToForm();
     }
     // Check that the student Id looks valid
     $studentId = $_POST['studentId'];
     // Get the term
     // TODO Double check that this is reasonable
     $term = $_POST['term'];
     // Create the student object
     $student = StudentProviderFactory::getProvider()->getStudent($studentId, $term);
     // Get the department ojbect
     $departmentId = preg_replace("/^_/", '', $_POST['department']);
     // Remove leading underscore in department id
     $department = DepartmentFactory::getDepartmentById($departmentId);
     if (!$department instanceof Department) {
         throw new \Exception('Could not load department.');
     }
     // Create and save the agency object
     $agency = new Agency($_POST['agency']);
     DatabaseStorage::save($agency);
     // Get the location
     $location = $_POST['location'];
     if ($location == 'international') {
         $state = null;
         $country = $_POST['country'];
     } else {
         $state = $_POST['state'];
         $country = null;
     }
     // Create a new internship object
     $intern = new Internship($student, $term, $location, $state, $country, $department, $agency);
     // Save it!!
     $intern->save();
     $t = \Intern\WorkflowTransitionFactory::getTransitionByName('Intern\\WorkflowTransition\\CreationTransition');
     $workflow = new \Intern\WorkflowController($intern, $t);
     $workflow->doTransition(null);
     $workflow->doNotification(null);
     // Show a success notice and redirect to the edit page
     \NQ::simple('intern', \Intern\UI\NotifyUI::SUCCESS, "Created internship for {$intern->getFullName()}");
     \NQ::close();
     return \PHPWS_Core::reroute('index.php?module=intern&action=ShowInternship&internship_id=' . $intern->getId());
 }
 public function get()
 {
     $this->loadContact();
     switch ($_GET['cop']) {
         case 'logout':
             unset($_SESSION['Contact_User']);
             \PHPWS_Core::home();
             break;
         case 'edit_property':
             $this->checkPermission();
             $this->loadProperty($this->contact->id);
             $this->editProperty($this->contact->id);
             break;
         case 'view_properties':
             $this->checkPermission();
             $this->title = "Properties list";
             $this->propertiesList($this->contact->id);
             break;
         case 'photo_form':
             $photo = new Photo();
             echo $photo->form();
             exit;
             break;
         case 'activate_property':
             $this->checkPermission();
             $this->loadProperty();
             $this->property->setActive(true);
             $this->property->save();
             \PHPWS_Core::goBack();
             break;
         case 'deactivate_property':
             $this->checkPermission();
             $this->loadProperty();
             $this->property->setActive(false);
             $this->property->save();
             \PHPWS_Core::goBack();
             break;
         case 'edit_contact':
             $this->checkPermission();
             $this->editContact();
             break;
         case 'delete_photo':
             // called via ajax
             $this->checkPermission();
             ob_start();
             $photo = new Photo($_GET['id']);
             $photo->delete();
             echo Photo::getThumbs($photo->pid);
             exit;
             break;
         case 'delete_property':
             $this->checkPermission();
             $this->loadProperty();
             // double security
             if ($this->property->contact_id == $this->contact->id) {
                 $this->property->delete();
             }
             \PHPWS_Core::goBack();
             break;
         case 'make_main':
             $photo = new Photo($_GET['id']);
             $photo->makeMain();
             exit;
             break;
         case 'update':
             $this->checkPermission();
             $this->loadProperty();
             $this->property->update();
             \PHPWS_Core::goBack();
             break;
     }
     $this->display();
 }
Exemple #4
0
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * @version $Id$
 * @author Verdon Vaillancourt <verdonv at gmail dot com>
 */
if (!defined('PHPWS_SOURCE_DIR')) {
    include '../../core/conf/404.html';
    exit;
}
PHPWS_Core::initModClass('whatsnew', 'Whatsnew.php');
$whatsnew = new whatsnew();
if (isset($_REQUEST['aop'])) {
    $whatsnew->adminMenu();
} elseif (isset($_REQUEST['uop'])) {
    $whatsnew->userMenu();
} else {
    PHPWS_Core::home();
}
Exemple #5
0
 public static function popUrlHistory()
 {
     if (!isset($_SESSION['PHPWS_UrlHistory']) || count($_SESSION['PHPWS_UrlHistory']) == 0) {
         PHPWS_Core::home();
     }
     PHPWS_Core::reroute(array_pop($_SESSION['PHPWS_UrlHistory']));
 }
 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');
 }
Exemple #7
0
    /**
     * Controller of user requests. Based on the command request variable
     * defaults to my_page
     */
    public static function userAction()
    {
        $auth = Current_User::getAuthorization();
        $content = $title = null;
        if (isset($_REQUEST['command'])) {
            $command = $_REQUEST['command'];
        } else {
            $command = 'my_page';
        }
        switch ($command) {
            case 'login':
                if (!Current_User::isLogged() && isset($_POST['phpws_username']) && isset($_POST['phpws_password'])) {
                    $result = Current_User::loginUser($_POST['phpws_username'], $_POST['phpws_password']);
                    // here
                    if (!$result) {
                        $title = dgettext('users', 'Login page');
                        $message = dgettext('users', 'Username and password combination not found.');
                        $content = User_Form::loginPage();
                    } elseif (PHPWS_Error::isError($result)) {
                        if (preg_match('/L\\d/', $result->code)) {
                            $title = dgettext('users', 'Sorry');
                            $content = $result->getMessage();
                            $content .= ' ' . sprintf('<a href="mailto:%s">%s</a>', PHPWS_User::getUserSetting('site_contact'), dgettext('users', 'Contact the site administrator'));
                        } else {
                            PHPWS_Error::log($result);
                            $message = dgettext('users', 'A problem occurred when accessing user information. Please try again later.');
                        }
                    } else {
                        Current_User::getLogin();
                        PHPWS_Core::returnToBookmark();
                    }
                } else {
                    PHPWS_Core::errorPage('403');
                }
                break;
                // This is used by auth scripts if they need to return the user to
                // where they left off after redirection to another site for SSO
            // This is used by auth scripts if they need to return the user to
            // where they left off after redirection to another site for SSO
            case 'return_bookmark':
                PHPWS_Core::popUrlHistory();
                break;
                // reset user password
            // reset user password
            case 'rp':
                $user_id = User_Action::checkResetPassword();
                if ($user_id) {
                    $title = dgettext('users', 'Reset my password');
                    $content = User_Form::resetPassword($user_id, $_GET['auth']);
                } else {
                    $title = dgettext('users', 'Sorry');
                    $content = dgettext('users', 'Your password request was not found or timed out. Please apply again.');
                }
                break;
            case 'my_page':
                if ($auth->local_user) {
                    PHPWS_Core::initModClass('users', 'My_Page.php');
                    $my_page = new My_Page();
                    $my_page->main();
                } else {
                    Layout::add(PHPWS_ControlPanel::display(dgettext('users', 'My Page unavailable to remote users.'), 'my_page'));
                }
                break;
            case 'signup_user':
                $title = dgettext('users', 'New Account Sign-up');
                if (Current_User::isLogged()) {
                    $content = dgettext('users', 'You already have an account.');
                    break;
                }
                $user = new PHPWS_User();
                if (PHPWS_User::getUserSetting('new_user_method') == 0) {
                    $content = dgettext('users', 'Sorry, we are not accepting new users at this time.');
                    break;
                }
                $content = User_Form::signup_form($user);
                break;
            case 'submit_new_user':
                $title = dgettext('users', 'New Account Sign-up');
                $user_method = PHPWS_User::getUserSetting('new_user_method');
                if ($user_method == 0) {
                    Current_User::disallow(dgettext('users', 'New user signup not allowed.'));
                    return;
                }
                $user = new PHPWS_User();
                $result = User_Action::postNewUser($user);
                if (is_array($result)) {
                    $content = User_Form::signup_form($user, $result);
                } else {
                    $content = User_Action::successfulSignup($user);
                }
                break;
            case 'logout':
                $auth = Current_User::getAuthorization();
                $auth->logout();
                PHPWS_Core::killAllSessions();
                PHPWS_Core::reroute('index.php?module=users&action=reset');
                break;
            case 'login_page':
                if (Current_User::isLogged()) {
                    PHPWS_Core::home();
                }
                $title = dgettext('users', 'Login Page');
                $content = User_Form::loginPage();
                break;
            case 'confirm_user':
                if (Current_User::isLogged()) {
                    PHPWS_Core::home();
                }
                if (User_Action::confirmUser()) {
                    $title = dgettext('users', 'Welcome!');
                    $content = dgettext('users', 'Your account has been successfully activated. Please log in.');
                } else {
                    $title = dgettext('users', 'Sorry');
                    $content = dgettext('users', 'This authentication does not exist.<br />
 If you did not log in within the time frame specified in your email, please apply for another account.');
                }
                User_Action::cleanUpConfirm();
                break;
            case 'forgot_password':
                if (Current_User::isLogged()) {
                    PHPWS_Core::home();
                }
                $title = dgettext('users', 'Forgot Password');
                $content = User_Form::forgotForm();
                break;
            case 'post_forgot':
                $title = dgettext('users', 'Forgot Password');
                if (ALLOW_CAPTCHA) {
                    PHPWS_Core::initCoreClass('Captcha.php');
                    if (!Captcha::verify()) {
                        $content = dgettext('users', 'Captcha information was incorrect.');
                        $content .= User_Form::forgotForm();
                    } else {
                        if (!User_Action::postForgot($content)) {
                            $content .= User_Form::forgotForm();
                        }
                    }
                } elseif (!User_Action::postForgot($content)) {
                    $content .= User_Form::forgotForm();
                }
                break;
            case 'reset_pw':
                $pw_result = User_Action::finishResetPW();
                switch ($pw_result) {
                    case PHPWS_Error::isError($pw_result):
                        $title = dgettext('users', 'Reset my password');
                        $content = dgettext('users', 'Passwords were not acceptable for the following reason:');
                        $content .= '<br />' . $pw_result->getmessage() . '<br />';
                        $content .= User_Form::resetPassword($_POST['user_id'], $_POST['authhash']);
                        break;
                    case 0:
                        $title = dgettext('users', 'Sorry');
                        $content = dgettext('users', 'A problem occurred when trying to update your password. Please try again later.');
                        break;
                    case 1:
                        PHPWS_Core::home();
                        break;
                }
                break;
            default:
                PHPWS_Core::errorPage('404');
                break;
        }
        if (isset($message)) {
            $tag['MESSAGE'] = $message;
        }
        if (isset($title)) {
            $tag['TITLE'] = $title;
        }
        if (isset($content)) {
            $tag['CONTENT'] = $content;
        }
        if (isset($tag)) {
            $final = PHPWS_Template::process($tag, 'users', 'user_main.tpl');
            Layout::add($final);
        }
    }
Exemple #8
0
 public function get()
 {
     $this->loadContact();
     switch ($_GET['cop']) {
         case 'logout':
             unset($_SESSION['Contact_User']);
             \PHPWS_Core::home();
             break;
         case 'manager_sign_up':
             if (!self::allowNewUserSignup()) {
                 $this->title = 'Sorry';
                 $this->content = '<p>New manager sign ups are not permitted at this time.</p>';
             } else {
                 $this->newManagerSetup();
             }
             break;
         case 'edit_property':
             $this->checkPermission();
             $this->loadProperty($this->contact->id);
             $this->editProperty($this->contact->id);
             break;
         case 'view_properties':
             $this->checkPermission();
             $this->title = "Properties list";
             $this->propertiesList($this->contact->id);
             break;
         case 'photo_form':
             $photo = new Photo();
             echo $photo->form();
             exit;
             break;
         case 'activate_property':
             $this->checkPermission();
             $this->loadProperty();
             $this->property->setActive(true);
             $this->property->save();
             \PHPWS_Core::goBack();
             break;
         case 'deactivate_property':
             $this->checkPermission();
             $this->loadProperty();
             $this->property->setActive(false);
             $this->property->save();
             \PHPWS_Core::goBack();
             break;
         case 'edit_contact':
             $this->checkPermission();
             $this->editContact();
             break;
         case 'delete_photo':
             // called via ajax
             $this->checkPermission();
             ob_start();
             $photo = new Photo($_GET['id']);
             $photo->delete();
             echo Photo::getThumbs($photo->pid);
             exit;
             break;
         case 'delete_property':
             $this->checkPermission();
             $this->loadProperty();
             // double security
             if ($this->property->contact_id == $this->contact->id) {
                 $this->property->delete();
             }
             \PHPWS_Core::goBack();
             break;
         case 'make_main':
             $photo = new Photo($_GET['id']);
             $photo->makeMain();
             exit;
             break;
         case 'update':
             $this->checkPermission();
             $this->loadProperty();
             $this->property->update();
             \PHPWS_Core::goBack();
             break;
         case 'checkUsername':
             $this->checkUsername();
             exit;
         case 'checkEmail':
             $this->checkEmail();
             exit;
     }
     $this->display();
 }
Exemple #9
0
 public function userMenu($action = null)
 {
     $javascript = false;
     if (empty($action)) {
         if (!isset($_REQUEST['uop'])) {
             PHPWS_Core::errorPage('404');
         }
         $action = $_REQUEST['uop'];
     }
     switch ($action) {
         case 'message':
             $this->loadMessage();
             if (empty($this->message)) {
                 PHPWS_Core::home();
             }
             $this->title = dgettext('signup', 'Signup');
             break;
         case 'signup_sheet':
             $this->loadPeep();
             $this->loadForm('user_signup');
             break;
         case 'slot_signup':
             if ($this->postPeep()) {
                 if ($this->saveUnregistered()) {
                     $this->forwardMessage(dgettext('signup', 'You should receive an email allowing you to verify your application.<br />You have one hour to confirm your application.'), dgettext('signup', 'Thank you'));
                     $this->sendMessage();
                 } else {
                     $this->loadForm('user_signup');
                 }
             } else {
                 $this->loadForm('user_signup');
             }
             break;
         case 'confirm':
             $this->confirmPeep();
             $this->purgeOverdue();
             break;
     }
     $tpl['TITLE'] = $this->title;
     $tpl['MESSAGE'] = $this->message;
     $tpl['CONTENT'] = $this->content;
     if ($javascript) {
         Layout::nakedDisplay(PHPWS_Template::process($tpl, 'signup', 'usermain.tpl'));
     } else {
         Layout::add(PHPWS_Template::process($tpl, 'signup', 'usermain.tpl'));
     }
 }