/**
  * Executes this pulse. Does the withdrawn search and emails the results.
  */
 public function execute()
 {
     // Reschedule the next run of this process
     $sp = $this->makeClone();
     $sp->execute_at = strtotime("tomorrow");
     $sp->save();
     // Load some classes
     PHPWS_Core::initModClass('hms', 'HMS.php');
     PHPWS_Core::initModClass('hms', 'WithdrawnSearch.php');
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     PHPWS_Core::initModClass('hms', 'UserStatus.php');
     UserStatus::wearMask('HMS System');
     // The search is run over all future terms
     $terms = Term::getFutureTerms();
     $text = "";
     foreach ($terms as $term) {
         $search = new WithdrawnSearch($term);
         $search->doSearch();
         $text .= "\n\n=========== " . Term::toString($term) . " ===========\n\n";
         $text .= $search->getTextView();
     }
     $text = $search->getTextView();
     HMS_Email::sendWithdrawnSearchOutput($text);
     UserStatus::removeMask();
     HMS::quit();
 }
Ejemplo n.º 2
0
 public function execute(CommandContext $context)
 {
     NQ::close();
     header('HTTP/1.1 303 See Other');
     header("Location: {$_SERVER['SCRIPT_NAME']}?module=controlpanel");
     HMS::quit();
 }
Ejemplo n.º 3
0
 public function process()
 {
     $this->context->setDefault('action', 'ShowAdminMaintenanceMenu');
     parent::process();
     $view = new hms\UserView();
     $view->setMain($this->context->getContent());
     $nv = new hms\NotificationView();
     $nv->popNotifications();
     $view->addNotifications($nv->show());
     $view->show();
     $this->saveState();
 }
Ejemplo n.º 4
0
 public function process()
 {
     $this->context->setDefault('action', 'ShowFrontPage');
     parent::process();
     PHPWS_Core::initModClass('hms', 'GuestView.php');
     $view = new hms\GuestView();
     $view->setMain($this->context->getContent());
     $nv = new hms\NotificationView();
     $nv->popNotifications();
     $view->addNotifications($nv->show());
     $view->show();
     $this->saveState();
 }
Ejemplo n.º 5
0
 public function execute(CommandContext $context)
 {
     if (!Current_User::allow('hms', 'reports')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do no have permission to run reports.');
     }
     PHPWS_Core::initModClass('hms', 'ReportFactory.php');
     $reportClass = $context->get('reportClass');
     if (!isset($reportClass) || is_null($reportClass)) {
         throw new InvalidArgumentException('Missing report class name.');
     }
     $reportCtrl = ReportFactory::getcontrollerInstance($reportClass);
     $runNow = $context->get('runNow');
     if (isset($runNow) && $runNow == "true") {
         $time = time();
     } else {
         $timePicker = $context->get('timePicker');
         $timeParts = explode(" ", $timePicker);
         $meridian = $timeParts[1];
         $timeParts = explode(":", $timeParts[0]);
         $hour = $timeParts[0];
         if ($meridian == "PM") {
             $hour += 12;
         }
         $min = $timeParts[1];
         $datePicker = $context->get('datePicker');
         $dateParts = explode("/", $datePicker);
         $month = $dateParts[0];
         $day = $dateParts[1];
         $year = $dateParts[2];
         $time = mktime($hour, $min, 0, $month, $day, $year);
     }
     // Set the exec time
     $reportCtrl->newReport($time);
     // Save the report
     $reportCtrl->saveReport();
     // Grab the report's settings from the context
     $reportCtrl->setParams($context->getParams());
     // Save those params
     $reportCtrl->saveParams();
     HMS::quit();
 }
Ejemplo n.º 6
0
 public function process()
 {
     // Set headers to allow Cross-origin scripting
     $rh = getallheaders();
     header('Allow: GET,HEAD,POST,PUT,DELETE,OPTIONS');
     if (array_key_exists('Origin', $rh)) {
         header('Access-Control-Allow-Origin:' . $rh['Origin']);
     }
     if (array_key_exists('Access-Control-Request-Headers', $rh)) {
         header('Access-Control-Allow-Headers:' . $rh['Access-Control-Request-Headers']);
     }
     header('Access-Control-Allow-Credentials: true');
     try {
         parent::process();
     } catch (PermissionException $e) {
         $error = new JsonError('401 Unauthorized');
         $error->setMessage('You are not authorized to perform this action.  You may need to sign back in.');
         $error->renderStatus();
         $content = $error->encode();
     } catch (Exception $e) {
         $error = new JsonError('500 Internal Server Error');
         $error->setMessage($e->getMessage());
         $error->renderStatus();
         $content = $error->encode();
         // Log the exception
         error_log('Caught API Exception: ' . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . ' Trace: ' . $e->getTraceAsString());
         $message = $this->formatException($e);
         $this->emailError($message);
     }
     $callback = $this->context->get('callback');
     $content = $this->context->getContent();
     // Wrap a jsonp request in it's function callback
     $response = !is_null($callback) ? "{$callback}({$content})" : $content;
     header('Content-Type: application/json; charset=utf-8');
     echo $response;
     // This sets NQ (notifications), which aren't valid for AJAX, so we aren't doing it. Just exit instead.
     //HMS::quit();
     exit;
 }
 public function execute(CommandContext $context)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'deadlines')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to edit deadlines.');
     }
     PHPWS_Core::initModClass('hms', 'exception/MissingDataException.php');
     if (!isset($this->featureId)) {
         $this->featureId = $context->get('featureId');
     }
     $featureId = $this->featureId;
     if (!isset($this->term)) {
         $this->term = $context->get('term');
     }
     $term = $this->term;
     if (!isset($this->name)) {
         $this->name = $context->get('name');
     }
     $name = $this->name;
     PHPWS_Core::initModClass('hms', 'ApplicationFeature.php');
     if (!is_null($featureId)) {
         $feature = ApplicationFeature::getInstanceById($featureId);
     } else {
         if (!is_null($name) && !is_null($term)) {
             $feature = ApplicationFeature::getInstanceByName($name);
             $feature->setTerm($term);
         } else {
             throw new InvalidArgumentException('You must either provide a featureId, or a name and a term.');
         }
     }
     // Checkboxes are weird.
     $enabled = !is_null($context->get('enabled'));
     $feature->setEnabled($enabled);
     if ($enabled) {
         $startDate = strtotime($context->get('start_date'));
         $editDate = strtotime($context->get('edit_date'));
         $endDate = strtotime($context->get('end_date'));
         if ($startDate && $endDate) {
             if ($startDate >= $endDate) {
                 $e = new MissingDataException('Start date must be before the end date.', array('Start date', 'End date'));
                 echo $e->getJSON();
                 HMS::quit();
             }
             if ($editDate && ($editDate <= $startDate || $editDate >= $endDate)) {
                 $e = new MissingDataException('Edit date must be between the start and end dates.', array('Edit date'));
                 echo $e->getJSON();
                 HMS::quit();
             }
         }
         if (!is_null($startDate)) {
             $feature->setStartDate($startDate);
         }
         $registration = $feature->getRegistration();
         if ($registration->requiresEditDate()) {
             $feature->setEditDate($editDate + 86399);
             // Add 23h23m23s so that the end date is actuall 11:59:59pm on the selected day
         } else {
             $feature->setEditDate(0);
         }
         if ($registration->requiresEndDate()) {
             $feature->setEndDate($endDate + 86399);
             // Add 23h23m23s so that the end date is actuall 11:59:59pm on the selected day
         } else {
             $feature->setEndDate(0);
         }
     }
     try {
         $feature->save();
     } catch (MissingDataException $e) {
         echo json_encode($e);
         HMS::quit();
     }
     echo json_encode($feature);
     HMS::quit();
 }
Ejemplo n.º 8
0
 public function goBack()
 {
     $path = $_SERVER['SCRIPT_NAME'] . '?module=hms&hms_goback=true';
     header('HTTP/1.1 303 See Other');
     header("Location: {$path}");
     HMS::quit();
 }
Ejemplo n.º 9
0
 /**
  * Returns a 303 Redirect to this command and then exits.  This
  * should be used after every POST request or destructive GET to
  * prevent accidental damage through a refresh or back/forward
  * operation in the client web browser.
  *
  * Note: Obviously, the implementation of HTTP 303 is browser-
  * specific and cannot be predicted by this script.  Most browsers
  * implement HTTP 303 in such a way that refresh/back/forward won't
  * attempt to re-POST, but some might.  Sucks to be them.
  *
  * Also Note: This DOES EVENTUALLY CALL exit().  After you call
  * this redirect function, you won't be returned control unless an
  * exception is somehow thrown.
  *
  * @see getRequestVars
  * @see getLink
  * @see getURI
  * @see initForm
  */
 public function redirect()
 {
     $path = $this->getURI();
     NQ::close();
     header('HTTP/1.1 303 See Other');
     header("Location: {$path}");
     HMS::quit();
 }