/**
  * Action to show a list of queueable resources.
  */
 public function indexAction()
 {
     $this->view->headTitle($this->_headPrefix . 'Rig Selection');
     /* Whether to enable the permission activation system. */
     $this->view->renderPermActivation = $this->_config->permkey->enable;
     /* Load the permissions of the user. */
     $client = Sahara_Soap::getSchedServerPermissionsClient();
     $perms = $client->getPermissionsForUser(array('userQName' => $this->_auth->getIdentity()));
     if (!isset($perms->permission)) {
         $this->view->noPermissions = true;
         return;
     }
     /* Translate the permissions into a form to display based on user class. */
     $userClasses = array();
     $i = 1;
     foreach ($perms->permission as $perm) {
         /* This is a hack because PHPSoap / Zend SOAP seems to have some quirks
          * parsing WSDLs. It generates a different object structure
          * depending if there is one permission, or multiple permissions. */
         if ($perm->permission == null) {
             if (is_bool($perm)) {
                 continue;
             }
             $p = $perm;
             $perm = $perms;
             $perm->isLocked = $perm->permission->isLocked;
         } else {
             $p = $perm->permission;
         }
         /* Add the user class if it hasn't already been loaded. */
         if (!array_key_exists($p->userClass->userClassName, $userClasses)) {
             $userClasses[$p->userClass->userClassName] = array();
         }
         /* Load up resource information. */
         $resource = array('canBook' => $p->canBook, 'canQueue' => $p->canQueue, 'resourceClass' => $p->resourceClass, 'resource' => $p->resource->resourceName, 'locked' => $perm->isLocked, 'active' => Sahara_DateTimeUtil::isBeforeNow($p->start) && Sahara_DateTimeUtil::isAfterNow($p->expiry), 'id' => 'permission' . $p->permissionID, 'start' => $p->start, 'expiry' => $p->expiry, 'permissionId' => $p->permissionID, 'display' => isset($p->displayName) ? $p->displayName : $p->resource->resourceName);
         array_push($userClasses[$p->userClass->userClassName], $resource);
     }
     /* Sort each of the user class permissions by resource name. */
     foreach ($userClasses as $class => $permList) {
         $buckets = array();
         foreach ($permList as $perm) {
             if (!array_key_exists($perm['resourceClass'], $buckets)) {
                 $buckets[$perm['resourceClass']] = array();
             }
             $bucket =& $buckets[$perm['resourceClass']];
             if (array_key_exists($perm['display'], $bucket)) {
                 $bucket[$perm['display'] . $perm['permissionId']] = $perm;
             } else {
                 $bucket[$perm['display']] = $perm;
             }
         }
         foreach ($buckets as &$bucket) {
             ksort($bucket);
         }
         $userClasses[$class] = array('Rig Types:' => array_key_exists('TYPE', $buckets) ? $buckets['TYPE'] : array(), 'Specific Rigs:' => array_key_exists('RIG', $buckets) ? $buckets['RIG'] : array(), 'Other:' => array_key_exists('CAPABILITY', $buckets) ? $buckets['CAPABILITY'] : array());
     }
     $this->view->userPermissions = $userClasses;
 }
 /**
  * Action to put a rig offline for a time period.
  */
 public function putofflineAction()
 {
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->layout()->disableLayout();
     $name = $this->_getParam('rig');
     $start = $this->_getParam('start');
     $end = $this->_getParam('end');
     $reason = $this->_getParam('reason');
     if (!$name || !$start || !$end || !$reason) {
         echo $this->view->json(array('successful' => false, 'failureCode' => -1, 'failureReason' => 'Required param not supplied.'));
     }
     $tzOff = new DateTimeZone(date_default_timezone_get());
     $tzOff = $tzOff->getOffset(new DateTime());
     $tz = $tzOff > 0 ? '+' : '-';
     $tz .= Sahara_DateTimeUtil::zeroPad(floor(abs($tzOff) / 3600)) . ':' . Sahara_DateTimeUtil::zeroPad(abs($tzOff) % 3600);
     list($date, $time) = explode(' ', trim($start));
     list($day, $mon, $yr) = explode('/', $date);
     list($hr, $min) = explode(':', $time);
     $start = trim($yr) . '-' . trim($mon) . '-' . trim($day) . 'T' . trim($hr) . ':' . trim($min) . ':00' . $tz;
     list($date, $time) = explode(' ', trim($end));
     list($day, $mon, $yr) = explode('/', $date);
     list($hr, $min) = explode(':', $time);
     $end = trim($yr) . '-' . trim($mon) . '-' . trim($day) . 'T' . trim($hr) . ':' . trim($min) . ':00' . $tz;
     echo $this->view->json(Sahara_Soap::getSchedServerRigManagementClient()->putRigOffline(array('requestorQName' => $this->_auth->getIdentity(), 'rig' => array('name' => $name), 'start' => $start, 'end' => $end, 'reason' => $reason)));
 }
 /**
  * View for a booking that is about to start.
  */
 public function waitingAction()
 {
     $this->view->headTitle($this->_headPrefix . 'Reservation');
     $this->view->bid = $this->_request->getParam('bid');
     if (!$this->view->bid) {
         $this->_redirectTo('index', 'queue');
     }
     $booking = Sahara_Soap::getSchedServerBookingsClient()->getBooking(array('userID' => array('userQName' => $this->_auth->getIdentity()), 'bookingID' => array('bookingID' => $this->view->bid)));
     $this->view->displayName = $booking->displayName;
     $this->view->time = Sahara_DateTimeUtil::getTsFromISO8601($booking->startTime) - time();
 }
 /**
  * Returns true if the specified dateTime is after the current
  * time. The dateTime format is 'ISO 8601 and
  * specified in 'http://www.w3.org/TR/xmlschema11-2/#dateTime'.
  *
  * @param String $tm1 first time
  * @param String $tm2 second time
  * @return boolean true if the first time is before the second time
  */
 public static function isAfterNow($tm)
 {
     return Sahara_DateTimeUtil::getTsFromISO8601($tm) > time();
 }