Ejemplo n.º 1
0
 public function Save()
 {
     $vn_checkin_count = 0;
     foreach ($_REQUEST as $vs_k => $vs_v) {
         if (preg_match('!^caClientLibraryCheckin_item_id_([\\d]+)$!', $vs_k, $va_matches)) {
             if (isset($_REQUEST['caClientLibraryCheckin_' . $va_matches[1] . '_delete'])) {
                 continue;
             }
             $vn_item_id = $va_matches[1];
             $t_order_item = new ca_commerce_order_items($vn_item_id);
             if ($t_order_item->getPrimaryKey()) {
                 $t_order_item->setMode(ACCESS_WRITE);
                 $t_order_item->set('loan_return_date', time(), array('SET_DIRECT_DATE' => true));
                 $t_order_item->set('notes', $this->request->getParameter('caClientLibraryCheckin_notes_' . $vn_item_id, pString));
                 $t_order_item->update();
                 if ($t_order_item->numErrors()) {
                     $this->notification->addNotification(_t('Could not check in item %1: %2', $vn_item_id, join("; ", $t_order_item->getErrors())), __NOTIFICATION_TYPE_ERROR__);
                     continue;
                 }
                 $vn_checkin_count++;
             }
         }
     }
     $this->notification->addNotification($vn_checkin_count == 1 ? _t('Checked in %1 item', $vn_checkin_count) : _t('Checked in %1 items', $vn_checkin_count), __NOTIFICATION_TYPE_INFO__);
     $this->Index();
 }
 public function RecordRepresentationSelection()
 {
     $pn_item_id = $this->request->getParameter('item_id', pInteger);
     $pn_representation_id = $this->request->getParameter('representation_id', pInteger);
     $pn_selected = $this->request->getParameter('selected', pInteger);
     $va_errors = array();
     $t_order_item = new ca_commerce_order_items($pn_item_id);
     if (!$t_order_item->getPrimaryKey()) {
         $va_errors[] = _t("Invalid set item");
     }
     if (!sizeof($va_errors)) {
         $t_order = new ca_commerce_orders($t_order_item->get('order_id'));
         if (!$t_order->getPrimaryKey()) {
             $va_errors[] = _t("Invalid order");
         }
         if (!sizeof($va_errors)) {
             if ((bool) $pn_selected) {
                 $t_order_item->addRepresentations(array($pn_representation_id));
             } else {
                 $t_order_item->removeRepresentations(array($pn_representation_id));
             }
             $va_errors = $t_order_item->getErrors();
         }
     }
     $this->view->setVar("errors", $va_errors);
     $this->view->setVar('representation_id', $pn_representation_id);
     $this->view->setVar('item_id', $pn_item_id);
     $this->render("ajax_select_representation_json.php");
 }
Ejemplo n.º 3
0
 /**
  * 
  */
 public function removeItem($pn_item_id, $pa_options = null)
 {
     if (isset($pa_options['order_id']) && (int) $pa_options['order_id']) {
         $vn_order_id = (int) $pa_options['order_id'];
     } else {
         $vn_order_id = $this->getPrimaryKey();
     }
     if (!$vn_order_id) {
         return null;
     }
     $t_item = new ca_commerce_order_items($pn_item_id);
     if (!$t_item->getPrimaryKey()) {
         return false;
     }
     if ($t_item->get('order_id') != $vn_order_id) {
         return false;
     }
     $t_item->setMode(ACCESS_WRITE);
     $t_item->delete(true);
     if ($t_item->numErrors()) {
         $this->errors = $t_item->errors;
         return false;
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  *
  */
 public function Download()
 {
     $pn_item_id = $this->request->getParameter('item_id', pInteger);
     $t_item = new ca_commerce_order_items($pn_item_id);
     $t_order = new ca_commerce_orders($t_item->get('order_id'));
     $t_transaction = new ca_commerce_transactions($t_order->get('transaction_id'));
     $o_media = new Media();
     if ($t_item->getPrimaryKey() && $t_order->getPrimaryKey()) {
         // Is the order paid for...
         if (!in_array($t_order->get('order_status'), array('PROCESSED', 'PROCESSED_AWAITING_DIGITIZATION', 'COMPLETED'))) {
             $this->notification->addNotification(_t("This order must be processed before you can download items"), __NOTIFICATION_TYPE_ERROR__);
             $this->Index();
             return;
         }
         // ... and accessible by this user?
         if ($t_transaction->get('user_id') != $this->request->getUserID()) {
             $this->notification->addNotification(_t("You may not download this item"), __NOTIFICATION_TYPE_ERROR__);
             $this->Index();
             return;
         }
         // Is this item downloadable?
         if ($t_item->get('fullfillment_method') != 'DOWNLOAD') {
             $this->notification->addNotification(_t("This item cannot be downloaded"), __NOTIFICATION_TYPE_ERROR__);
             $this->Index();
             return;
         }
         // Which reps, and what versions?
         $t_object = new ca_objects($t_item->get('object_id'));
         $va_services_list = array();
         if (is_array($va_service_groups = $this->opo_client_services_config->getAssoc("service_groups"))) {
             foreach ($va_service_groups as $vs_group => $va_services_in_group) {
                 foreach ($va_services_in_group['services'] as $vs_service => $va_service_info) {
                     $va_services_list[$vs_service] = $va_service_info;
                 }
             }
         }
         if (!($vs_version = $va_services_list[$t_item->get('service')]['download_version'])) {
             $vs_version = 'small';
         }
         $va_reps = $t_object->getRepresentations(array($vs_version));
         $va_reps_to_download = $t_item->getRepresentationIDs();
         $o_zip = new ZipFile();
         $va_files = array();
         $vn_size = 0;
         foreach ($va_reps as $va_rep) {
             if (!isset($va_reps_to_download[$va_rep['representation_id']]) || !$va_reps_to_download[$va_rep['representation_id']]) {
                 continue;
             }
             $va_tmp = explode('.', $va_rep['paths'][$vs_version]);
             $vs_ext = array_pop($va_tmp);
             if ($va_rep['original_filename']) {
                 $va_tmp2 = explode(".", $va_rep['original_filename']);
                 if (sizeof($va_tmp2) > 1) {
                     array_pop($va_tmp2);
                 }
                 $vs_filename = join(".", $va_tmp2) . ".{$vs_ext}";
             } else {
                 $vs_filename = $t_object->get('idno') . "_" . $va_rep['representation_id'] . ".{$vs_ext}";
             }
             $vn_size += $va_files[$va_rep['paths'][$vs_version]] = filesize($va_rep['paths'][$vs_version]);
             $o_zip->addFile($va_rep['paths'][$vs_version], $vs_filename, 0, array('compression' => 0));
         }
         $this->view->setVar('zip', $o_zip);
         $this->view->setVar('version_download_name', date('dmY', $t_order->get('created_on', array('GET_DIRECT_DATE' => true))) . '-' . $t_order->getPrimaryKey());
         // Log fulfillment
         $t_item->logFulfillmentEvent('DOWNLOAD', array('ip_addr' => $_SERVER['REMOTE_ADDR'], 'user_id' => $this->request->getUserID(), 'datetime' => time(), 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'files' => $va_files, 'size' => $vn_size, 'representation_ids' => $va_reps_to_download));
         return $this->render('Account/download_binary.php');
     }
     $this->notification->addNotification(_t("You may not download this"), __NOTIFICATION_TYPE_ERROR__);
     $this->Index();
     return;
 }