function launch() { global $configArray; global $interface; global $user; global $locationSingleton; if ($user) { $interface->assign('defaultPhone', $user->phone); $interface->assign('defaultEmail', $user->email); $locations = $locationSingleton->getPickupBranches($user, $user->homeLocationId); } else { $locations = $locationSingleton->getPickupBranches(false, -1); } $interface->assign('pickupLocations', $locations); //Get a list of formats to show $availableFormats = MaterialsRequest::getFormats(); $interface->assign('availableFormats', $availableFormats); //Setup a default title based on the search term $interface->assign('new', true); if (isset($_REQUEST['lookfor']) && strlen($_REQUEST['lookfor']) > 0) { $request = new MaterialsRequest(); $searchType = isset($_REQUEST['basicType']) ? $_REQUEST['basicType'] : (isset($_REQUEST['type']) ? $_REQUEST['type '] : 'Keyword'); if (strcasecmp($searchType, 'author') == 0) { $request->author = $_REQUEST['lookfor']; } else { $request->title = $_REQUEST['lookfor']; } $interface->assign('materialsRequest', $request); } $interface->assign('showPhoneField', $configArray['MaterialsRequest']['showPhoneField']); $interface->assign('showAgeField', $configArray['MaterialsRequest']['showAgeField']); $interface->assign('showBookTypeField', $configArray['MaterialsRequest']['showBookTypeField']); $interface->assign('showEbookFormatField', $configArray['MaterialsRequest']['showEbookFormatField']); $interface->assign('showEaudioFormatField', $configArray['MaterialsRequest']['showEaudioFormatField']); $interface->assign('showPlaceHoldField', $configArray['MaterialsRequest']['showPlaceHoldField']); $interface->assign('showIllField', $configArray['MaterialsRequest']['showIllField']); $interface->assign('requireAboutField', $configArray['MaterialsRequest']['requireAboutField']); $useWorldCat = false; if (isset($configArray['WorldCat']) && isset($configArray['WorldCat']['apiKey'])) { $useWorldCat = strlen($configArray['WorldCat']['apiKey']) > 0; } $interface->assign('useWorldCat', $useWorldCat); $interface->setTemplate('new.tpl'); $interface->assign('sidebar', 'Search/home-sidebar.tpl'); $interface->setPageTitle('Materials Request'); $interface->display('layout.tpl'); }
function launch() { global $configArray; global $interface; global $user; //Load the materials request to determine if it can be edited $materialsRequest = new MaterialsRequest(); $materialsRequest->id = $_REQUEST['id']; if (!$materialsRequest->find(true)) { $materialsRequest = null; $requestUser = false; } else { $requestUser = new User(); $requestUser->id = $materialsRequest->createdBy; if ($requestUser->find(true)) { $interface->assign('requestUser', $requestUser); } else { $requestUser = false; } } //Make sure that the user is valid $processForm = true; if ($materialsRequest == null) { $interface->assign('success', false); $interface->assign('error', 'Sorry, we could not find a request with that id.'); $processForm = false; } else { if (!$user) { $interface->assign('error', 'Sorry, you must be logged in to update a materials request.'); $processForm = false; } else { if ($user->hasRole('cataloging')) { //Ok to process the form even if it wasn't created by the current user } else { if ($user->hasRole('library_material_requests') && $requestUser && Library::getLibraryForLocation($requestUser->homeLocationId)->libraryId == Library::getLibraryForLocation($user->homeLocationId)->libraryId) { //Ok to process because they are an admin for the user's home library } else { if ($user->id != $materialsRequest->createdBy) { $interface->assign('error', 'Sorry, you do not have permission to update this materials request.'); $processForm = false; } } } } } if ($processForm) { //Materials request can be submitted. $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']); $materialsRequest->subFormat = isset($_REQUEST['subFormat']) ? strip_tags($_REQUEST['subFormat']) : ''; $materialsRequest->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->comments = strip_tags($_REQUEST['comments']); $materialsRequest->dateUpdated = time(); if ($materialsRequest->update()) { $interface->assign('success', true); $interface->assign('materialsRequest', $materialsRequest); } else { $interface->assign('success', false); $interface->assign('error', 'There was an error updating the materials request.'); } } else { $interface->assign('success', false); $interface->assign('error', 'Sorry, we could not find a request with that id.'); } //Get a list of formats to show $availableFormats = MaterialsRequest::getFormats(); $interface->assign('availableFormats', $availableFormats); $interface->assign('showPhoneField', $configArray['MaterialsRequest']['showPhoneField']); $interface->assign('showAgeField', $configArray['MaterialsRequest']['showAgeField']); $interface->assign('showBookTypeField', $configArray['MaterialsRequest']['showBookTypeField']); $interface->assign('showEbookFormatField', $configArray['MaterialsRequest']['showEbookFormatField']); $interface->assign('showEaudioFormatField', $configArray['MaterialsRequest']['showEaudioFormatField']); $interface->assign('showPlaceHoldField', $configArray['MaterialsRequest']['showPlaceHoldField']); $interface->assign('showIllField', $configArray['MaterialsRequest']['showIllField']); $interface->setTemplate('update-result.tpl'); $interface->setPageTitle('Update Result'); $interface->display('layout.tpl'); }
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'); } }
function UpdateMaterialsRequest() { global $interface; global $configArray; $useWorldCat = false; if (isset($configArray['WorldCat']) && isset($configArray['WorldCat']['apiKey'])) { $useWorldCat = strlen($configArray['WorldCat']['apiKey']) > 0; } $interface->assign('useWorldCat', $useWorldCat); if (!isset($_REQUEST['id'])) { $interface->assign('error', 'Please provide an id of the materials request to view.'); } else { $id = $_REQUEST['id']; $materialsRequest = new MaterialsRequest(); $materialsRequest->id = $id; if ($materialsRequest->find(true)) { $canUpdate = false; //Load user information $requestUser = new User(); $requestUser->id = $materialsRequest->createdBy; if ($requestUser->find(true)) { $interface->assign('requestUser', $requestUser); } global $user; if ($user) { if ($user->hasRole('cataloging')) { $canUpdate = true; } elseif ($user->id == $materialsRequest->createdBy) { $canUpdate = true; } else { if ($user->hasRole('library_material_requests')) { //User can update if the home library of the requester is their library $canUpdate = Library::getLibraryForLocation($requestUser->homeLocationId)->libraryId == Library::getLibraryForLocation($user->homeLocationId)->libraryId; } } } if ($canUpdate) { //Get a list of formats to show $availableFormats = MaterialsRequest::getFormats(); $interface->assign('availableFormats', $availableFormats); $interface->assign('showPhoneField', $configArray['MaterialsRequest']['showPhoneField']); $interface->assign('showAgeField', $configArray['MaterialsRequest']['showAgeField']); $interface->assign('showBookTypeField', $configArray['MaterialsRequest']['showBookTypeField']); $interface->assign('showEbookFormatField', $configArray['MaterialsRequest']['showEbookFormatField']); $interface->assign('showEaudioFormatField', $configArray['MaterialsRequest']['showEaudioFormatField']); $interface->assign('showPlaceHoldField', $configArray['MaterialsRequest']['showPlaceHoldField']); $interface->assign('showIllField', $configArray['MaterialsRequest']['showIllField']); $interface->assign('requireAboutField', $configArray['MaterialsRequest']['requireAboutField']); $interface->assign('materialsRequest', $materialsRequest); $interface->assign('showUserInformation', true); } else { $interface->assign('error', 'Sorry, you don\'t have permission to update this request.'); } } else { $interface->assign('error', 'Sorry, we couldn\'t find a materials request for that id.'); } } $return = array('title' => 'Update Materials Request', 'modalBody' => $interface->fetch('MaterialsRequest/ajax-update-request.tpl'), 'modalButtons' => "<span class='btn btn-primary' onclick='\$(\"#materialsRequestUpdateForm\").submit();'>Update Request</span>"); return $return; }