示例#1
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');
 }