* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7541 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php'); class AdminAttachments extends AdminTab { private $_productAttachements = array(); public function __construct() { global $cookie; $this->table = 'attachment'; $this->className = 'Attachment'; $this->lang = true; $this->edit = true; $this->delete = true; $this->fieldsDisplay = array( 'id_attachment' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'name' => array('title' => $this->l('Name')), 'file' => array('title' => $this->l('File'))); parent::__construct(); } public function postProcess() { if (Tools::isSubmit('submitAdd'.$this->table)) { if ($id = (int)(Tools::getValue('id_attachment')) AND $a = new Attachment($id)) { $_POST['file'] = $a->file; $_POST['mime'] = $a->mime; } if (!sizeof($this->_errors)) { if (isset($_FILES['file']) AND is_uploaded_file($_FILES['file']['tmp_name'])) { if ($_FILES['file']['size'] > (Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024)) $this->_errors[] = $this->l('File too large, maximum size allowed:').' '.(Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024).' '.$this->l('kb').'. '.$this->l('File size you\'re trying to upload is:').number_format(($_FILES['file']['size']/1024), 2, '.', '').$this->l('kb'); else { do $uniqid = sha1(microtime()); while (file_exists(_PS_DOWNLOAD_DIR_.$uniqid)); if (!copy($_FILES['file']['tmp_name'], _PS_DOWNLOAD_DIR_.$uniqid)) $this->_errors[] = $this->l('File copy failed'); $_POST['file_name'] = $_FILES['file']['name']; @unlink($_FILES['file']['tmp_name']); $_POST['file'] = $uniqid; $_POST['mime'] = $_FILES['file']['type']; } } elseif (array_key_exists('file', $_FILES) && (int)$_FILES['file']['error'] === 1) { $max_upload = (int)(ini_get('upload_max_filesize')); $max_post = (int)(ini_get('post_max_size')); $upload_mb = min($max_upload, $max_post); $this->_errors[] = $this->l('the File').' '.$_FILES['file']['name'].' '.$this->l('exceeds the size allowed by the server. This limit is set to').' '.$upload_mb.$this->l('Mb').''; } elseif (!empty($_FILES['file']['tmp_name'])) $this->_errors[] = $this->l('No file or your file isn\'t uploadable, check your server configuration about the upload maximum size.'); } $this->validateRules(); } return parent::postProcess(); } public function displayForm($isMainTab = true) { global $currentIndex, $cookie; parent::displayForm(); if (!($obj = $this->loadObject(true))) return; echo '
'; } public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL) { parent::getList((int)$id_lang, $orderBy, $orderWay, $start, $limit); if (sizeof($this->_list)) $this->_productAttachements = Attachment::getProductAttached((int)$id_lang, $this->_list); } protected function _displayDeleteLink($token = NULL, $id) { global $currentIndex; $_cacheLang['Delete'] = $this->l('Delete'); $_cacheLang['DeleteItem'] = $this->l('Delete item #', __CLASS__, TRUE, FALSE); if (isset($this->_productAttachements[$id])) { $productList = ''; foreach($this->_productAttachements[$id] as $product) $productList .= $product.', '; } echo ' '; } }