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'); }
function launch() { global $interface; global $user; $period = isset($_REQUEST['period']) ? $_REQUEST['period'] : 'week'; if ($period == 'week') { $periodLength = new DateInterval("P1W"); } elseif ($period == 'day') { $periodLength = new DateInterval("P1D"); } elseif ($period == 'month') { $periodLength = new DateInterval("P1M"); } else { //year $periodLength = new DateInterval("P1Y"); } $interface->assign('period', $period); $endDate = isset($_REQUEST['endDate']) && strlen($_REQUEST['endDate']) > 0 ? DateTime::createFromFormat('m/d/Y', $_REQUEST['endDate']) : new DateTime(); $interface->assign('endDate', $endDate->format('m/d/Y')); if (isset($_REQUEST['startDate']) && strlen($_REQUEST['startDate']) > 0) { $startDate = DateTime::createFromFormat('m/d/Y', $_REQUEST['startDate']); } else { if ($period == 'day') { $startDate = new DateTime($endDate->format('m/d/Y') . " - 7 days"); } elseif ($period == 'week') { //Get the sunday after this $endDate->setISODate($endDate->format('Y'), $endDate->format("W"), 0); $endDate->modify("+7 days"); $startDate = new DateTime($endDate->format('m/d/Y') . " - 28 days"); } elseif ($period == 'month') { $endDate->modify("+1 month"); $numDays = $endDate->format("d"); $endDate->modify(" -{$numDays} days"); $startDate = new DateTime($endDate->format('m/d/Y') . " - 6 months"); } else { //year $endDate->modify("+1 year"); $numDays = $endDate->format("m"); $endDate->modify(" -{$numDays} months"); $numDays = $endDate->format("d"); $endDate->modify(" -{$numDays} days"); $startDate = new DateTime($endDate->format('m/d/Y') . " - 2 years"); } } $interface->assign('startDate', $startDate->format('m/d/Y')); //Set the end date to the end of the day $endDate->setTime(24, 0, 0); $startDate->setTime(0, 0, 0); //Create the periods that are being represented $periods = array(); $periodEnd = clone $endDate; while ($periodEnd >= $startDate) { array_unshift($periods, clone $periodEnd); $periodEnd->sub($periodLength); } //print_r($periods); //Load data for each period //this will be a two dimensional array // Period 1, Period 2, Period 3 //Status 1 //Status 2 //Status 3 $periodData = array(); for ($i = 0; $i < count($periods) - 1; $i++) { /** @var DateTime $periodStart */ $periodStart = clone $periods[$i]; /** @var DateTime $periodEnd */ $periodEnd = clone $periods[$i + 1]; $periodData[$periodStart->getTimestamp()] = array(); //Determine how many requests were created $materialsRequest = new MaterialsRequest(); $materialsRequest->joinAdd(new User(), 'INNER', 'user'); $materialsRequest->selectAdd(); $materialsRequest->selectAdd('COUNT(id) as numRequests'); $materialsRequest->whereAdd('dateCreated >= ' . $periodStart->getTimestamp() . ' AND dateCreated < ' . $periodEnd->getTimestamp()); 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) . ')'); } $materialsRequest->find(); while ($materialsRequest->fetch()) { $periodData[$periodStart->getTimestamp()]['Created'] = $materialsRequest->numRequests; } //Get a list of all requests by the status of the request $materialsRequest = new MaterialsRequest(); $materialsRequest->joinAdd(new MaterialsRequestStatus()); $materialsRequest->joinAdd(new User(), 'INNER', 'user'); $materialsRequest->selectAdd(); $materialsRequest->selectAdd('COUNT(materials_request.id) as numRequests,description'); $materialsRequest->whereAdd('dateUpdated >= ' . $periodStart->getTimestamp() . ' AND dateUpdated < ' . $periodEnd->getTimestamp()); 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) . ')'); } $materialsRequest->groupBy('status'); $materialsRequest->orderBy('status'); $materialsRequest->find(); while ($materialsRequest->fetch()) { $periodData[$periodStart->getTimestamp()][$materialsRequest->description] = $materialsRequest->numRequests; } } $interface->assign('periodData', $periodData, $periods); //Get a list of all of the statuses that will be shown $statuses = array(); foreach ($periodData as $periodInfo) { foreach ($periodInfo 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($periodData, $statuses); } else { //Generate the graph $this->generateGraph($periodData, $statuses); } $interface->setTemplate('summaryReport.tpl'); $interface->assign('sidebar', 'MyAccount/account-sidebar.tpl'); $interface->setPageTitle('Materials Request Summary Report'); $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 launch() { global $configArray; global $interface; global $user; global $library; $maxActiveRequests = isset($library) ? $library->maxOpenRequests : 5; $maxRequestsPerYear = isset($library) ? $library->maxRequestsPerYear : 60; $accountPageLink = $configArray['Site']['path'] . '/MaterialsRequest/MyRequests'; //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 additional 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 >= $maxActiveRequests) { $interface->assign('success', false); $interface->assign('error', "You've already reached your maximum limit of {$maxActiveRequests} 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 <a href='{$accountPageLink}'>account</a>."); } else { //Check the total number of requests created this year $lastYear = new DateTime(); $lastYear->modify('-365 days'); $materialsRequest = new MaterialsRequest(); $materialsRequest->createdBy = $user->id; $materialsRequest->whereAdd('dateCreated >= ' . $lastYear->getTimestamp()); //To be fair, don't include any requests that were cancelled by the patron $statusQuery = new MaterialsRequestStatus(); $statusQuery->isPatronCancel = 0; $materialsRequest->joinAdd($statusQuery); $materialsRequest->find(); if ($materialsRequest->N >= $maxRequestsPerYear) { $interface->assign('success', false); $interface->assign('error', "You've already reached your maximum limit of {$maxRequestsPerYear} requests per year. To check the status of your current requests, visit your <a href='{$accountPageLink}'>account page</a>."); } 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->assign('sidebar', 'Search/home-sidebar.tpl'); $interface->setTemplate('submission-result.tpl'); $interface->setPageTitle('Submission Result'); $interface->display('layout.tpl'); }