示例#1
0
 /**
  * Checks out an eContent Record to a user.  The record must be available to the user for the checkout to succeed.
  *
  * Parameters:
  * <ul>
  * <li>username - The barcode of the user.  Can be truncated to the last 7 or 9 digits.</li>
  * <li>password - The pin number for the user. </li>
  * <li>recordId - The id of the record within the eContent database.</li>
  * </ul>
  *
  * Returns JSON encoded data as follows:
  * <ul>
  * <li>success � true if the account is valid and the item could be checked out, false if the username or password were incorrect or the record could not be checked out.</li>
  * <li>message � a reason why the method failed if success is false, or information indicating success.</li>
  * </ul>
  *
  * Sample Call:
  * <code>
  * http://catalog.douglascountylibraries.org/API/UserAPI?method=checkoutEContentItem&username=23025003575917&password=1234&recordId=530
  * </code>
  *
  * Sample Response (checkout):
  * <code>
  * {"result":{
  *   "success":true,
  *   "message":"The title was checked out to you successfully.  You may read it from the My eContent page within your account."
  * }}
  * </code>
  *
  * Sample Response (failed):
  * <code>
  * {"result":{
  *   "success":false,
  *   "holdMessage":"There are no available copies of this title, please place a hold instead."
  * }}
  * </code>
  *
  * @author Mark Noble <*****@*****.**>
  */
 function checkoutEContentItem()
 {
     $username = $_REQUEST['username'];
     $password = $_REQUEST['password'];
     $recordId = $_REQUEST['recordId'];
     global $user;
     $user = UserAccount::validateAccount($username, $password);
     if ($user && !PEAR_Singleton::isError($user)) {
         require_once ROOT_DIR . '/Drivers/EContentDriver.php';
         $driver = new EContentDriver();
         $response = $driver->checkoutRecord($recordId, $user);
         return array('success' => $response['result'], 'message' => $response['message']);
     } else {
         return array('success' => false, 'message' => 'Login unsuccessful');
     }
 }
示例#2
0
 function launch()
 {
     global $interface;
     global $configArray;
     global $user;
     $driver = new EContentDriver();
     $id = strip_tags($_REQUEST['id']);
     $interface->assign('id', $id);
     global $logger;
     //Get title information for the record.
     $eContentRecord = new EContentRecord();
     $eContentRecord->id = $id;
     if (!$eContentRecord->find(true)) {
         PEAR_Singleton::raiseError("Unable to find eContent record for id: {$id}");
     }
     if (isset($_POST['submit']) || $user) {
         if (isset($_REQUEST['username']) && isset($_REQUEST['password'])) {
             //Log the user in
             $user = UserAccount::login();
         }
         if (!PEAR_Singleton::isError($user) && $user) {
             //The user is already logged in
             $return = $driver->checkoutRecord($id, $user);
             $interface->assign('result', $return['result']);
             $message = $return['message'];
             $interface->assign('message', $message);
             global $logger;
             $logger->log("Result of checkout " . print_r($return, true), PEAR_LOG_DEBUG);
             $showMessage = true;
         } else {
             $message = 'Incorrect Patron Information';
             $interface->assign('message', $message);
             $interface->assign('focusElementId', 'username');
             $showMessage = true;
         }
     } else {
         //Get the referrer so we can go back there.
         if (isset($_SERVER['HTTP_REFERER'])) {
             $referer = $_SERVER['HTTP_REFERER'];
             $_SESSION['checkout_referrer'] = $referer;
         }
         //Showing checkout form.
         if (!PEAR_Singleton::isError($user) && $user) {
             //set focus to the submit button if the user is logged in since the campus will be correct most of the time.
             $interface->assign('focusElementId', 'submit');
         } else {
             //set focus to the username field by default.
             $interface->assign('focusElementId', 'username');
         }
     }
     if (isset($return) && $showMessage) {
         $hold_message_data = array('successful' => $return['result'] ? 'all' : 'none', 'error' => isset($return['error']) ? $return['error'] : null, 'titles' => array($return));
         $_SESSION['checkout_message'] = $hold_message_data;
         if (isset($_SESSION['checkout_referrer'])) {
             $logger->log('Checkout Referrer is set, redirecting to there.  referrer = ' . $_SESSION['checkout_referrer'], PEAR_LOG_INFO);
             header("Location: " . $_SESSION['checkout_referrer']);
             unset($_SESSION['checkout_referrer']);
             if (isset($_SESSION['autologout'])) {
                 unset($_SESSION['autologout']);
                 UserAccount::softLogout();
             }
         } else {
             $logger->log('No referrer set, but there is a message to show, go to the main eContent page', PEAR_LOG_INFO);
             header("Location: /MyAccount/CheckedOut");
         }
     } else {
         $logger->log('eContent checkout finished, do not need to show a message', PEAR_LOG_INFO);
         $interface->setPageTitle('Checkout Item');
         $interface->assign('subTemplate', 'checkout.tpl');
         $interface->setTemplate('checkout.tpl');
         $interface->display('layout.tpl', 'RecordHold' . $_GET['id']);
     }
 }