示例#1
0
 function CancelRequest()
 {
     global $user;
     if (!$user) {
         return array('success' => false, 'error' => 'Could not cancel the request, you must be logged in to cancel the request.');
     } elseif (!isset($_REQUEST['id'])) {
         return array('success' => false, 'error' => 'Could not cancel the request, no id provided.');
     } else {
         $id = $_REQUEST['id'];
         $materialsRequest = new MaterialsRequest();
         $materialsRequest->id = $id;
         $materialsRequest->createdBy = $user->id;
         if ($materialsRequest->find(true)) {
             //get the correct status to set based on the user's home library
             $homeLibrary = Library::getPatronHomeLibrary();
             $cancelledStatus = new MaterialsRequestStatus();
             $cancelledStatus->isPatronCancel = 1;
             $cancelledStatus->libraryId = $homeLibrary->libraryId;
             $cancelledStatus->find(true);
             $materialsRequest->dateUpdated = time();
             $materialsRequest->status = $cancelledStatus->id;
             if ($materialsRequest->update()) {
                 return array('success' => true);
             } else {
                 return array('success' => false, 'error' => 'Could not cancel the request, error during update.');
             }
         } else {
             return array('success' => false, 'error' => 'Could not cancel the request, could not find a request for the provided id.');
         }
     }
 }
示例#2
0
 function launch()
 {
     global $configArray;
     global $interface;
     global $user;
     //Load status information
     $materialsRequestStatus = new MaterialsRequestStatus();
     $materialsRequestStatus->orderBy('isDefault DESC, isOpen DESC, description ASC');
     if ($user->hasRole('library_material_requests')) {
         $homeLibrary = Library::getPatronHomeLibrary();
         $materialsRequestStatus->libraryId = $homeLibrary->libraryId;
     } else {
         $libraryList[-1] = 'Default';
     }
     $materialsRequestStatus->find();
     $allStatuses = array();
     $availableStatuses = array();
     $defaultStatusesToShow = array();
     while ($materialsRequestStatus->fetch()) {
         $availableStatuses[$materialsRequestStatus->id] = $materialsRequestStatus->description;
         $allStatuses[$materialsRequestStatus->id] = clone $materialsRequestStatus;
         if ($materialsRequestStatus->isOpen == 1 || $materialsRequestStatus->isDefault == 1) {
             $defaultStatusesToShow[] = $materialsRequestStatus->id;
         }
     }
     $interface->assign('availableStatuses', $availableStatuses);
     if (isset($_REQUEST['statusFilter'])) {
         $statusesToShow = $_REQUEST['statusFilter'];
         $_SESSION['materialsRequestStatusFilter'] = $statusesToShow;
     } elseif (isset($_SESSION['materialsRequestStatusFilter'])) {
         $statusesToShow = $_SESSION['materialsRequestStatusFilter'];
     } else {
         $statusesToShow = $defaultStatusesToShow;
     }
     $interface->assign('statusFilter', $statusesToShow);
     //Process status change if needed
     if (isset($_REQUEST['updateStatus']) && isset($_REQUEST['select'])) {
         //Look for which titles should be modified
         $selectedRequests = $_REQUEST['select'];
         $statusToSet = $_REQUEST['newStatus'];
         require_once ROOT_DIR . '/sys/Mailer.php';
         $mail = new VuFindMailer();
         foreach ($selectedRequests as $requestId => $selected) {
             $materialRequest = new MaterialsRequest();
             $materialRequest->id = $requestId;
             if ($materialRequest->find(true)) {
                 $materialRequest->status = $statusToSet;
                 $materialRequest->dateUpdated = time();
                 $materialRequest->update();
                 if ($allStatuses[$statusToSet]->sendEmailToPatron == 1 && $materialRequest->email) {
                     $body = '*****This is an auto-generated email response. Please do not reply.*****';
                     $body .= "\r\n" . $allStatuses[$statusToSet]->emailTemplate;
                     //Replace tags with appropriate values
                     $materialsRequestUser = new User();
                     $materialsRequestUser->id = $materialRequest->createdBy;
                     $materialsRequestUser->find(true);
                     foreach ($materialsRequestUser as $fieldName => $fieldValue) {
                         if (!is_array($fieldValue)) {
                             $body = str_replace('{' . $fieldName . '}', $fieldValue, $body);
                         }
                     }
                     foreach ($materialRequest as $fieldName => $fieldValue) {
                         if (!is_array($fieldValue)) {
                             $body = str_replace('{' . $fieldName . '}', $fieldValue, $body);
                         }
                     }
                     $materialsRequestUser->find(true);
                     $mail->send($materialRequest->email, $configArray['Site']['email'], "Your Materials Request Update", $body, $configArray['Site']['email']);
                 }
             }
         }
     }
     $availableFormats = MaterialsRequest::getFormats();
     $interface->assign('availableFormats', $availableFormats);
     $defaultFormatsToShow = array_keys($availableFormats);
     if (isset($_REQUEST['formatFilter'])) {
         $formatsToShow = $_REQUEST['formatFilter'];
         $_SESSION['materialsRequestFormatFilter'] = $formatsToShow;
     } elseif (isset($_SESSION['materialsRequestFormatFilter'])) {
         $formatsToShow = $_SESSION['materialsRequestFormatFilter'];
     } else {
         $formatsToShow = $defaultFormatsToShow;
     }
     $interface->assign('formatFilter', $formatsToShow);
     //Get a list of all materials requests for the user
     $allRequests = array();
     if ($user) {
         $materialsRequests = new MaterialsRequest();
         $materialsRequests->joinAdd(new Location(), "LEFT");
         $materialsRequests->joinAdd(new MaterialsRequestStatus());
         $materialsRequests->joinAdd(new User(), 'INNER', 'user');
         $materialsRequests->selectAdd();
         $materialsRequests->selectAdd('materials_request.*, description as statusLabel, location.displayName as location, firstname, lastname, ' . $configArray['Catalog']['barcodeProperty'] . ' as barcode');
         if ($user->hasRole('library_material_requests')) {
             //Need to limit to only requests submitted for the user's home location
             $userHomeLibrary = Library::getPatronHomeLibrary();
             $locations = new Location();
             $locations->libraryId = $userHomeLibrary->libraryId;
             $locations->find();
             $locationsForLibrary = array();
             while ($locations->fetch()) {
                 $locationsForLibrary[] = $locations->locationId;
             }
             $materialsRequests->whereAdd('user.homeLocationId IN (' . implode(', ', $locationsForLibrary) . ')');
         }
         if (count($availableStatuses) > count($statusesToShow)) {
             $statusSql = "";
             foreach ($statusesToShow as $status) {
                 if (strlen($statusSql) > 0) {
                     $statusSql .= ",";
                 }
                 $statusSql .= "'" . $materialsRequests->escape($status) . "'";
             }
             $materialsRequests->whereAdd("status in ({$statusSql})");
         }
         if (count($availableFormats) > count($formatsToShow)) {
             //At least one format is disabled
             $formatSql = "";
             foreach ($formatsToShow as $format) {
                 if (strlen($formatSql) > 0) {
                     $formatSql .= ",";
                 }
                 $formatSql .= "'" . $materialsRequests->escape($format) . "'";
             }
             $materialsRequests->whereAdd("format in ({$formatSql})");
         }
         //Add filtering by date as needed
         if (isset($_REQUEST['startDate']) && strlen($_REQUEST['startDate']) > 0) {
             $startDate = strtotime($_REQUEST['startDate']);
             $materialsRequests->whereAdd("dateCreated >= {$startDate}");
             $interface->assign('startDate', $_REQUEST['startDate']);
         }
         if (isset($_REQUEST['endDate']) && strlen($_REQUEST['endDate']) > 0) {
             $endDate = strtotime($_REQUEST['endDate']);
             $materialsRequests->whereAdd("dateCreated <= {$endDate}");
             $interface->assign('endDate', $_REQUEST['endDate']);
         }
         $materialsRequests->find();
         while ($materialsRequests->fetch()) {
             $allRequests[] = clone $materialsRequests;
         }
     } else {
         $interface->assign('error', "You must be logged in to manage requests.");
     }
     $interface->assign('allRequests', $allRequests);
     if (isset($_REQUEST['exportSelected'])) {
         $this->exportToExcel($_REQUEST['select'], $allRequests);
     } else {
         $interface->setTemplate('manageRequests.tpl');
         $interface->setPageTitle('Manage Materials Requests');
         $interface->display('layout.tpl');
     }
 }