Index: branches/RC/core/units/general/cat_event_handler.php =================================================================== diff -u -r9398 -r9598 --- branches/RC/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 9398) +++ branches/RC/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 9598) @@ -13,14 +13,16 @@ { parent::mapPermissions(); $permissions = Array( - 'OnExport' => Array('self' => 'view|advanced:export'), - 'OnExportBegin' => Array('self' => 'view|advanced:export'), - 'OnSaveSettings' => Array('self' => 'add|edit|advanced:import'), - 'OnBeforeDeleteOriginal' => Array('self' => 'edit|advanced:approve'), + 'OnExport' => Array('self' => 'view|advanced:export'), + 'OnExportBegin' => Array('self' => 'view|advanced:export'), + 'OnSaveSettings' => Array('self' => 'add|edit|advanced:import'), + 'OnBeforeDeleteOriginal' => Array('self' => 'edit|advanced:approve'), - 'OnCancelAction' => Array('self' => true), - ); + 'OnDownloadFile' => Array('self' => 'view'), + 'OnCancelAction' => Array('self' => true), + ); + $this->permMapping = array_merge($this->permMapping, $permissions); } @@ -717,6 +719,12 @@ $image_helper->LoadItemImages($object); + // linking existing files for item with virtual fields + $file_helper =& $this->Application->recallObject('FileHelper'); + /* @var $file_helper FileHelper */ + + $file_helper->LoadItemFiles($object); + // set item's additional categories to virtual field (used in editing) $item_categories = $this->getItemCategories($object->GetDBField('ResourceId')); $object->SetDBField('MoreCategories', $item_categories ? '|'.implode('|', $item_categories).'|' : ''); @@ -740,6 +748,12 @@ // process image upload in virtual fields $image_helper->SaveItemImages($object); + $file_helper =& $this->Application->recallObject('FileHelper'); + /* @var $file_helper FileHelper */ + + // process file upload in virtual fields + $file_helper->SaveItemFiles($object); + if ($event->Special != '-item') { // don't touch categories during cloning $this->processAdditionalCategories($object, 'update'); @@ -768,6 +782,12 @@ // process image upload in virtual fields $image_helper->SaveItemImages($object); + $file_helper =& $this->Application->recallObject('FileHelper'); + /* @var $file_helper FileHelper */ + + // process file upload in virtual fields + $file_helper->SaveItemFiles($object); + if ($event->Special != '-item') { // don't touch categories during cloning $this->processAdditionalCategories($object, 'create'); @@ -2027,8 +2047,8 @@ $owner_field = $this->getOwnerField($event->Prefix); - $image_helper =& $this->Application->recallObject('ImageHelper'); - /* @var $image_helper ImageHelper */ + $file_helper =& $this->Application->recallObject('FileHelper'); + /* @var $file_helper FileHelper */ foreach ($items_info as $id => $field_values) { $object->Load($id); @@ -2038,7 +2058,7 @@ // pending editing enabled + not pending copy -> get/create pending copy & save changes to it $original_id = $object->GetID(); $original_resource_id = $object->GetDBField('ResourceId'); - $image_helper->PreserveItemImages($field_values); + $file_helper->PreserveItemFiles($field_values); $object->Load($original_id, 'OrgId'); if (!$object->isLoaded()) { @@ -2283,12 +2303,40 @@ */ function OnAfterConfigRead(&$event) { - $image_helper =& $this->Application->recallObject('ImageHelper'); - /* @var $image_helper ImageHelper */ + $file_helper =& $this->Application->recallObject('FileHelper'); + /* @var $file_helper FileHelper */ - $image_helper->createItemImages($event->Prefix); + $file_helper->createItemFiles($event->Prefix, true); // create image fields + $file_helper->createItemFiles($event->Prefix, false); // create file fields } + /** + * Returns file contents associated with item + * + * @param kEvent $event + */ + function OnDownloadFile(&$event) + { + $object =& $event->getObject(); + /* @var $object kDBItem */ + + $event->status = erSTOP; + + $field = $this->Application->GetVar('field'); + if (!preg_match('/^File([\d]+)/', $field)) { + return ; + } + + $filename = $object->GetField($field, 'full_path'); + + $content_type = function_exists('mime_content_type') ? mime_content_type($filename) : 'application/octet-stream'; + + header('Content-type: '.$content_type); + header('Content-Disposition: attachment; filename="'.basename($filename).'"'); + header('Content-Length: '.filesize($filename)); + readfile($filename); + flush(); + } } ?> \ No newline at end of file