Пример #1
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;
 }