Exemplo n.º 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.');
         }
     }
 }
Exemplo n.º 2
0
 function launch()
 {
     global $configArray;
     global $interface;
     global $user;
     $showOpen = true;
     if (isset($_REQUEST['requestsToShow']) && $_REQUEST['requestsToShow'] == 'allRequests') {
         $showOpen = false;
     }
     $interface->assign('showOpen', $showOpen);
     $defaultStatus = new MaterialsRequestStatus();
     $defaultStatus->isDefault = 1;
     $defaultStatus->libraryId = Library::getPatronHomeLibrary()->libraryId;
     $defaultStatus->find(true);
     $interface->assign('defaultStatus', $defaultStatus->id);
     //Get a list of all materials requests for the user
     $allRequests = array();
     if ($user) {
         $materialsRequests = new MaterialsRequest();
         $materialsRequests->createdBy = $user->id;
         $materialsRequests->orderBy('title, dateCreated');
         $statusQuery = new MaterialsRequestStatus();
         if ($showOpen) {
             $homeLibrary = Library::getPatronHomeLibrary();
             $statusQuery->libraryId = $homeLibrary->libraryId;
             $statusQuery->isOpen = 1;
         }
         $materialsRequests->joinAdd($statusQuery);
         $materialsRequests->selectAdd();
         $materialsRequests->selectAdd('materials_request.*, description as statusLabel');
         $materialsRequests->find();
         while ($materialsRequests->fetch()) {
             $allRequests[] = clone $materialsRequests;
         }
     } else {
         header('Location: ' . $configArray['Site']['path'] . '/MyResearch/Home?followupModule=MaterialsRequest&followupAction=MyRequests');
         //$interface->assign('error', "You must be logged in to view your requests.");
     }
     $interface->assign('allRequests', $allRequests);
     $interface->assign('sidebar', 'MyAccount/account-sidebar.tpl');
     $interface->setTemplate('myMaterialRequests.tpl');
     $interface->setPageTitle('My Materials Requests');
     $interface->display('layout.tpl');
 }
Exemplo n.º 3
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;
     }
     $materialsRequestStatus->find();
     $availableStatuses = array();
     $defaultStatusesToShow = array();
     while ($materialsRequestStatus->fetch()) {
         $availableStatuses[$materialsRequestStatus->id] = $materialsRequestStatus->description;
         if ($materialsRequestStatus->isOpen == 1 || $materialsRequestStatus->isDefault == 1) {
             $defaultStatusesToShow[] = $materialsRequestStatus->id;
         }
     }
     $interface->assign('availableStatuses', $availableStatuses);
     if (isset($_REQUEST['statusFilter'])) {
         $statusesToShow = $_REQUEST['statusFilter'];
     } else {
         $statusesToShow = $defaultStatusesToShow;
     }
     $interface->assign('statusFilter', $statusesToShow);
     //Get a list of users that have requests open
     $materialsRequest = new MaterialsRequest();
     $materialsRequest->joinAdd(new User());
     $materialsRequest->joinAdd(new MaterialsRequestStatus());
     $materialsRequest->selectAdd();
     $materialsRequest->selectAdd('COUNT(materials_request.id) as numRequests');
     $materialsRequest->selectAdd('user.id as userId, status, description, user.firstName, user.lastName, user.cat_username, user.cat_password');
     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;
         }
         $materialsRequest->whereAdd('user.homeLocationId IN (' . implode(', ', $locationsForLibrary) . ')');
     }
     $statusSql = "";
     foreach ($statusesToShow as $status) {
         if (strlen($statusSql) > 0) {
             $statusSql .= ",";
         }
         $statusSql .= "'" . $materialsRequest->escape($status) . "'";
     }
     $materialsRequest->whereAdd("status in ({$statusSql})");
     $materialsRequest->groupBy('userId, status');
     $materialsRequest->find();
     $userData = array();
     while ($materialsRequest->fetch()) {
         if (!array_key_exists($materialsRequest->userId, $userData)) {
             $userData[$materialsRequest->userId] = array();
             $userData[$materialsRequest->userId]['firstName'] = $materialsRequest->firstName;
             $userData[$materialsRequest->userId]['lastName'] = $materialsRequest->lastName;
             $barcodeProperty = $configArray['Catalog']['barcodeProperty'];
             $userData[$materialsRequest->userId]['barcode'] = $materialsRequest->{$barcodeProperty};
             $userData[$materialsRequest->userId]['totalRequests'] = 0;
             $userData[$materialsRequest->userId]['requestsByStatus'] = array();
         }
         $userData[$materialsRequest->userId]['requestsByStatus'][$materialsRequest->description] = $materialsRequest->numRequests;
         $userData[$materialsRequest->userId]['totalRequests'] += $materialsRequest->numRequests;
     }
     $interface->assign('userData', $userData);
     //Get a list of all of the statuses that will be shown
     $statuses = array();
     foreach ($userData as $userInfo) {
         foreach ($userInfo['requestsByStatus'] as $status => $numRequests) {
             $statuses[$status] = translate($status);
         }
     }
     $interface->assign('statuses', $statuses);
     //Check to see if we are exporting to Excel
     if (isset($_REQUEST['exportToExcel'])) {
         $this->exportToExcel($userData, $statuses);
     }
     $interface->setTemplate('userReport.tpl');
     $interface->setPageTitle('Materials Request User Report');
     $interface->assign('sidebar', 'MyAccount/account-sidebar.tpl');
     $interface->display('layout.tpl');
 }
Exemplo n.º 4
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');
     }
 }
Exemplo n.º 5
0
 function resetToDefault()
 {
     global $user;
     if ($user->hasRole('library_material_requests')) {
         $homeLibrary = Library::getPatronHomeLibrary();
         $materialRequestStatus = new MaterialsRequestStatus();
         $materialRequestStatus->libraryId = $homeLibrary->libraryId;
         $materialRequestStatus->delete();
         $materialRequestStatus = new MaterialsRequestStatus();
         $materialRequestStatus->libraryId = -1;
         $materialRequestStatus->find();
         while ($materialRequestStatus->fetch()) {
             $materialRequestStatus->id = null;
             $materialRequestStatus->libraryId = $homeLibrary->libraryId;
             $materialRequestStatus->insert();
         }
     }
     header("Location: /Admin/ManageStatuses");
 }
Exemplo n.º 6
0
 function launch()
 {
     global $configArray;
     global $interface;
     global $user;
     //Make sure that the user is valid
     $processForm = true;
     if (!$user) {
         $user = UserAccount::login();
         if ($user == null) {
             $interface->assign('error', 'Sorry, we could not log you in.  Please enter a valid barcode and pin number submit a materials request.');
             $processForm = false;
         }
     }
     if ($processForm) {
         //Check to see if the user type is ok to submit a request
         $enableMaterialsRequest = true;
         if (isset($configArray['MaterialsRequest']['allowablePatronTypes'])) {
             //Check to see if we need to do additonal restrictions by patron type
             $allowablePatronTypes = $configArray['MaterialsRequest']['allowablePatronTypes'];
             if (strlen($allowablePatronTypes) > 0 && $user) {
                 if (!preg_match("/^{$allowablePatronTypes}\$/i", $user->patronType)) {
                     $enableMaterialsRequest = false;
                 }
             }
         }
         if (!$enableMaterialsRequest) {
             $interface->assign('success', false);
             $interface->assign('error', 'Sorry, only residents may submit materials requests at this time.');
         } else {
             if ($_REQUEST['format'] == 'article' && $_REQUEST['acceptCopyright'] != 1) {
                 $interface->assign('success', false);
                 $interface->assign('error', 'Sorry, you must accept the copyright agreement before submitting a materials request.');
             } else {
                 //Check to see how many active materials request results the user has already.
                 $materialsRequest = new MaterialsRequest();
                 $materialsRequest->createdBy = $user->id;
                 $statusQuery = new MaterialsRequestStatus();
                 $homeLibrary = Library::getPatronHomeLibrary();
                 $statusQuery->libraryId = $homeLibrary->libraryId;
                 $statusQuery->isOpen = 1;
                 $materialsRequest->joinAdd($statusQuery);
                 $materialsRequest->selectAdd();
                 $materialsRequest->selectAdd('materials_request.*, description as statusLabel');
                 $materialsRequest->find();
                 if ($materialsRequest->N >= 5) {
                     $interface->assign('success', false);
                     $interface->assign('error', "You\\'ve already reached your maximum limit of five requests open at one time. Once we've processed your existing requests, you'll be able to submit again. To check the status of your current requests, visit your account page [link to account page].");
                 } else {
                     //Materials request can be submitted.
                     $materialsRequest = new MaterialsRequest();
                     $materialsRequest->phone = isset($_REQUEST['phone']) ? strip_tags($_REQUEST['phone']) : '';
                     $materialsRequest->email = strip_tags($_REQUEST['email']);
                     $materialsRequest->title = strip_tags($_REQUEST['title']);
                     $materialsRequest->season = isset($_REQUEST['season']) ? strip_tags($_REQUEST['season']) : '';
                     $materialsRequest->magazineTitle = isset($_REQUEST['magazineTitle']) ? strip_tags($_REQUEST['magazineTitle']) : '';
                     $materialsRequest->magazineDate = isset($_REQUEST['magazineDate']) ? strip_tags($_REQUEST['magazineDate']) : '';
                     $materialsRequest->magazineVolume = isset($_REQUEST['magazineVolume']) ? strip_tags($_REQUEST['magazineVolume']) : '';
                     $materialsRequest->magazineNumber = isset($_REQUEST['magazineNumber']) ? strip_tags($_REQUEST['magazineNumber']) : '';
                     $materialsRequest->magazinePageNumbers = isset($_REQUEST['magazinePageNumbers']) ? strip_tags($_REQUEST['magazinePageNumbers']) : '';
                     $materialsRequest->author = strip_tags($_REQUEST['author']);
                     $materialsRequest->format = strip_tags($_REQUEST['format']);
                     if ($materialsRequest->format == 'ebook' && isset($_REQUEST['ebookFormat'])) {
                         $materialsRequest->subFormat = strip_tags($_REQUEST['ebookFormat']);
                     } elseif ($materialsRequest->format == 'eaudio' && isset($_REQUEST['eaudioFormat'])) {
                         $materialsRequest->subFormat = strip_tags($_REQUEST['eaudioFormat']);
                     }
                     $materialsRequest->subFormat = isset($_REQUEST['subFormat']) ? strip_tags($_REQUEST['subFormat']) : '';
                     $materialsRequest->ageLevel = isset($_REQUEST['ageLevel']) ? strip_tags($_REQUEST['ageLevel']) : '';
                     $materialsRequest->bookType = isset($_REQUEST['bookType']) ? strip_tags($_REQUEST['bookType']) : '';
                     $materialsRequest->isbn = isset($_REQUEST['isbn']) ? strip_tags($_REQUEST['isbn']) : '';
                     $materialsRequest->upc = isset($_REQUEST['upc']) ? strip_tags($_REQUEST['upc']) : '';
                     $materialsRequest->issn = isset($_REQUEST['issn']) ? strip_tags($_REQUEST['issn']) : '';
                     $materialsRequest->oclcNumber = isset($_REQUEST['oclcNumber']) ? strip_tags($_REQUEST['oclcNumber']) : '';
                     $materialsRequest->publisher = strip_tags($_REQUEST['publisher']);
                     $materialsRequest->publicationYear = strip_tags($_REQUEST['publicationYear']);
                     if (isset($_REQUEST['abridged'])) {
                         if ($_REQUEST['abridged'] == 'abridged') {
                             $materialsRequest->abridged = 1;
                         } elseif ($_REQUEST['abridged'] == 'unabridged') {
                             $materialsRequest->abridged = 0;
                         } else {
                             $materialsRequest->abridged = 2;
                             //Not applicable
                         }
                     }
                     $materialsRequest->about = strip_tags($_REQUEST['about']);
                     $materialsRequest->comments = strip_tags($_REQUEST['comments']);
                     if (isset($_REQUEST['placeHoldWhenAvailable'])) {
                         $materialsRequest->placeHoldWhenAvailable = $_REQUEST['placeHoldWhenAvailable'];
                     } else {
                         $materialsRequest->placeHoldWhenAvailable = 0;
                     }
                     if (isset($_REQUEST['holdPickupLocation'])) {
                         $materialsRequest->holdPickupLocation = $_REQUEST['holdPickupLocation'];
                     }
                     if (isset($_REQUEST['bookmobileStop'])) {
                         $materialsRequest->bookmobileStop = $_REQUEST['bookmobileStop'];
                     }
                     if (isset($_REQUEST['illItem'])) {
                         $materialsRequest->illItem = $_REQUEST['illItem'];
                     } else {
                         $materialsRequest->illItem = 0;
                     }
                     $defaultStatus = new MaterialsRequestStatus();
                     $defaultStatus->isDefault = 1;
                     $userLibraryId = Library::getPatronHomeLibrary();
                     $defaultStatus->libraryId = $userLibraryId->libraryId;
                     if (!$defaultStatus->find(true)) {
                         $interface->assign('success', false);
                         $interface->assign('error', 'There was an error submitting your materials request, could not determine the default status.');
                     } else {
                         $materialsRequest->status = $defaultStatus->id;
                         $materialsRequest->dateCreated = time();
                         $materialsRequest->createdBy = $user->id;
                         $materialsRequest->dateUpdated = time();
                         if ($materialsRequest->insert()) {
                             $interface->assign('success', true);
                             $interface->assign('materialsRequest', $materialsRequest);
                         } else {
                             $interface->assign('success', false);
                             $interface->assign('error', 'There was an error submitting your materials request.');
                         }
                     }
                 }
             }
         }
     }
     $interface->setTemplate('submission-result.tpl');
     $interface->setPageTitle('Submission Result');
     $interface->display('layout.tpl');
 }