function displayFormAttachments($obj, $languages, $defaultLanguage)
    {
        global $currentIndex, $cookie;
        $obj = $this->loadObject(true);
        $languages = Language::getLanguages();
        $attach1 = Attachment::getAttachments($cookie->id_lang, $obj->id, true);
        $attach2 = Attachment::getAttachments($cookie->id_lang, $obj->id, false);
        echo '
		<a href="index.php?tab=AdminAttachments&addattachment&token=' . Tools::getAdminToken('AdminAttachments' . intval(Tab::getIdFromClassName('AdminAttachments')) . intval($cookie->id_employee)) . '">
			<img src="../img/admin/add.gif" alt="new" title="' . $this->l('Upload new attachment') . '" />&nbsp;' . $this->l('Upload new attachment') . '
		</a>
		<div class="clear">&nbsp;</div>
		<table><tr>
			<td>
				<select multiple id="selectAttachment1" name="attachments[]" style="width:300px;height:160px;">';
        foreach ($attach1 as $attach) {
            echo '	<option value="' . $attach['id_attachment'] . '">' . $attach['name'] . '</option>';
        }
        echo '	</select><br /><br />
				<a href="#" id="addAttachment" style="text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px">
					' . $this->l('Remove') . ' &gt;&gt;
				</a>
			</td>
			<td style="padding-left:20px;">
				<select multiple id="selectAttachment2" style="width:300px;height:160px;">';
        foreach ($attach2 as $attach) {
            echo '	<option value="' . $attach['id_attachment'] . '">' . $attach['name'] . '</option>';
        }
        echo '	</select><br /><br />
				<a href="#" id="removeAttachment" style="text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px">
					&lt;&lt; ' . $this->l('Add') . '
				</a>
			</div>
			</td>
		</tr></table>
		<div class="clear">&nbsp;</div>
		<input type="submit" name="submitAttachments" id="submitAttachments" value="' . $this->l('Update attachments') . '" class="button" />';
    }
Пример #2
0
 public function initFormAttachments($obj)
 {
     if (!$this->default_form_language) {
         $this->getLanguages();
     }
     $data = $this->createTemplate($this->tpl_form);
     $data->assign('default_form_language', $this->default_form_language);
     if ((bool) $obj->id) {
         if ($this->product_exists_in_shop) {
             $attachment_name = array();
             $attachment_description = array();
             foreach ($this->_languages as $language) {
                 $attachment_name[$language['id_lang']] = '';
                 $attachment_description[$language['id_lang']] = '';
             }
             $iso_tiny_mce = $this->context->language->iso_code;
             $iso_tiny_mce = file_exists(_PS_JS_DIR_ . 'tiny_mce/langs/' . $iso_tiny_mce . '.js') ? $iso_tiny_mce : 'en';
             $attachment_uploader = new HelperUploader('attachment_file');
             $attachment_uploader->setMultiple(false)->setUseAjax(true)->setUrl(Context::getContext()->link->getAdminLink('AdminProducts') . '&ajax=1&id_product=' . (int) $obj->id . '&action=AddAttachment')->setPostMaxSize(Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024)->setTemplate('attachment_ajax.tpl');
             $data->assign(array('obj' => $obj, 'table' => $this->table, 'ad' => __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_), 'iso_tiny_mce' => $iso_tiny_mce, 'languages' => $this->_languages, 'id_lang' => $this->context->language->id, 'attach1' => Attachment::getAttachments($this->context->language->id, $obj->id, true), 'attach2' => Attachment::getAttachments($this->context->language->id, $obj->id, false), 'default_form_language' => (int) Configuration::get('PS_LANG_DEFAULT'), 'attachment_name' => $attachment_name, 'attachment_description' => $attachment_description, 'PS_ATTACHMENT_MAXIMUM_SIZE' => Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE'), 'attachment_uploader' => $attachment_uploader->render()));
         } else {
             $this->displayWarning($this->l('You must save the product in this shop before adding attachements.'));
         }
     } else {
         $this->displayWarning($this->l('You must save this product before adding attachements.'));
     }
     $this->tpl_form_vars['custom_form'] = $data->fetch();
 }
 public function initFormAttachments($obj)
 {
     $data = $this->createTemplate($this->tpl_form);
     if ((bool) $obj->id) {
         if ($this->product_exists_in_shop) {
             $attachment_name = array();
             $attachment_description = array();
             foreach ($this->_languages as $language) {
                 $attachment_name[$language['id_lang']] = '';
                 $attachment_description[$language['id_lang']] = '';
             }
             $iso_tiny_mce = $this->context->language->iso_code;
             $iso_tiny_mce = file_exists(_PS_JS_DIR_ . 'tiny_mce/langs/' . $iso_tiny_mce . '.js') ? $iso_tiny_mce : 'en';
             $data->assign(array('obj' => $obj, 'table' => $this->table, 'ad' => dirname($_SERVER['PHP_SELF']), 'iso_tiny_mce' => $iso_tiny_mce, 'languages' => $this->_languages, 'attach1' => Attachment::getAttachments($this->context->language->id, $obj->id, true), 'attach2' => Attachment::getAttachments($this->context->language->id, $obj->id, false), 'default_form_language' => (int) Configuration::get('PS_LANG_DEFAULT'), 'attachment_name' => $attachment_name, 'attachment_description' => $attachment_description, 'PS_ATTACHMENT_MAXIMUM_SIZE' => Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE')));
         } else {
             $this->displayWarning($this->l('You must save the product in this shop before adding attachements.'));
         }
     } else {
         $this->displayWarning($this->l('You must save this product before adding attachements.'));
     }
     $this->tpl_form_vars['custom_form'] = $data->fetch();
 }
 /**
  * Method processAddAttachments() : Change name of file which are uploaded for this product
  * Rules:
  *      - For the first upload the filename has been : name-of-product.extention
  *      - For the second upload : name-of-product-1.extention
  *      - ...
  *
  * @module now_seo_links
  * @return void
  *
  * @see AdminProductsControllerCore::processAddAttachments()
  */
 public function processAddAttachments()
 {
     $languages = Language::getLanguages(false);
     $is_attachment_name_valid = false;
     foreach ($languages as $language) {
         $attachment_name_lang = Tools::getValue('attachment_name_' . (int) $language['id_lang']);
         if (Tools::strlen($attachment_name_lang) > 0) {
             $is_attachment_name_valid = true;
         }
         if (!Validate::isGenericName(Tools::getValue('attachment_name_' . (int) $language['id_lang']))) {
             $this->errors[] = Tools::displayError('Invalid Name');
         } elseif (Tools::strlen(Tools::getValue('attachment_name_' . (int) $language['id_lang'])) > 32) {
             $this->errors[] = sprintf(Tools::displayError('The name is too long (%d chars max).'), 32);
         }
         if (!Validate::isCleanHtml(Tools::getValue('attachment_description_' . (int) $language['id_lang']))) {
             $this->errors[] = Tools::displayError('Invalid description');
         }
     }
     if (!$is_attachment_name_valid) {
         $this->errors[] = Tools::displayError('An attachment name is required.');
     }
     if (empty($this->errors)) {
         if (isset($_FILES['attachment_file']) && is_uploaded_file($_FILES['attachment_file']['tmp_name'])) {
             if ($_FILES['attachment_file']['size'] > Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024) {
                 $this->errors[] = sprintf($this->l('The file is too large. Maximum size allowed is: %1$d kB. The file you\'re trying to upload is: %2$d kB.'), Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024, number_format($_FILES['attachment_file']['size'] / 1024, 2, '.', ''));
             } else {
                 do {
                     $uniqid = sha1(microtime());
                 } while (file_exists(_PS_DOWNLOAD_DIR_ . $uniqid));
                 if (!copy($_FILES['attachment_file']['tmp_name'], _PS_DOWNLOAD_DIR_ . $uniqid)) {
                     $this->errors[] = $this->l('File copy failed');
                 }
                 @unlink($_FILES['attachment_file']['tmp_name']);
             }
         } elseif ((int) $_FILES['attachment_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[] = sprintf($this->l('The file %1$s exceeds the size allowed by the server. The limit is set to %2$d MB.'), '<b>' . $_FILES['attachment_file']['name'] . '</b> ', '<b>' . $upload_mb . '</b>');
         } else {
             $this->errors[] = Tools::displayError('The file is missing.');
         }
         if (empty($this->errors) && isset($uniqid)) {
             $attachment = new Attachment();
             foreach ($languages as $language) {
                 if (Tools::getIsset('attachment_name_' . (int) $language['id_lang'])) {
                     $attachment->name[(int) $language['id_lang']] = Tools::getValue('attachment_name_' . (int) $language['id_lang']);
                 }
                 if (Tools::getIsset('attachment_description_' . (int) $language['id_lang'])) {
                     $attachment->description[(int) $language['id_lang']] = Tools::getValue('attachment_description_' . (int) $language['id_lang']);
                 }
             }
             if (Tools::getIsset('name_' . (int) Configuration::get('PS_LANG_DEFAULT'))) {
                 $sFilename = $_FILES['attachment_file']['name'];
                 $sExtention = substr($sFilename, strrpos($sFilename, '.') + 1);
                 $attachment->file_name = Tools::link_rewrite(trim(Tools::getValue('name_' . (int) Configuration::get('PS_LANG_DEFAULT'))));
                 // On regarde si c'est le premier document joint au produit ou pas
                 $aAttachmentOfProduct = $attachment->getAttachments(Context::getContext()->language->id, (int) Tools::getValue('id_product'));
                 $iNb = count($aAttachmentOfProduct);
                 if ($iNb > 0) {
                     $attachment->file_name .= '-' . $iNb;
                 }
                 $attachment->file_name .= '.' . $sExtention;
             }
             $attachment->file = $uniqid;
             $attachment->mime = $_FILES['attachment_file']['type'];
             if (empty($attachment->mime) || Tools::strlen($attachment->mime) > 128) {
                 $this->errors[] = Tools::displayError('Invalid file extension');
             }
             if (!Validate::isGenericName($attachment->file_name)) {
                 $this->errors[] = Tools::displayError('Invalid file name');
             }
             if (Tools::strlen($attachment->file_name) > 128) {
                 $this->errors[] = Tools::displayError('The file name is too long.');
             }
             if (empty($this->errors)) {
                 $res = $attachment->add();
                 if (!$res) {
                     $this->errors[] = Tools::displayError('This attachment was unable to be loaded into the database.');
                 } else {
                     $id_product = (int) Tools::getValue($this->identifier);
                     $res = $attachment->attachProduct($id_product);
                     if (!$res) {
                         $this->errors[] = Tools::displayError('We were unable to associate this attachment to a product.');
                     }
                 }
             } else {
                 $this->errors[] = Tools::displayError('Invalid file');
             }
         }
     }
 }
Пример #5
0
    function displayFormAttachments($obj, $languages, $defaultLanguage)
    {
        global $currentIndex, $cookie;
        if (!($obj = $this->loadObject(true))) {
            return;
        }
        $languages = Language::getLanguages(false);
        $attach1 = Attachment::getAttachments($cookie->id_lang, $obj->id, true);
        $attach2 = Attachment::getAttachments($cookie->id_lang, $obj->id, false);
        echo '
		' . ($obj->id ? '<input type="hidden" name="id_' . $this->table . '" value="' . $obj->id . '" />' : '') . '
			<fieldset><legend><img src="../img/t/AdminAttachments.gif" />' . $this->l('Attachment') . '</legend>
				<label>' . $this->l('Filename:') . ' </label>
				<div class="margin-form">';
        foreach ($languages as $language) {
            echo '	<div id="attachment_name_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;">
						<input size="33" type="text" name="attachment_name_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'attachment_name', (int) $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" /><sup> *</sup>
					</div>';
        }
        $this->displayFlags($languages, $defaultLanguage, 'attachment_name¤attachment_description', 'attachment_name');
        echo '	</div>
				<div class="clear">&nbsp;</div>
				<label>' . $this->l('Description:') . ' </label>
				<div class="margin-form">';
        foreach ($languages as $language) {
            echo '	<div id="attachment_description_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;">
						<textarea name="attachment_description_' . $language['id_lang'] . '">' . htmlentities($this->getFieldValue($obj, 'attachment_description', (int) $language['id_lang']), ENT_COMPAT, 'UTF-8') . '</textarea>
					</div>';
        }
        $this->displayFlags($languages, $defaultLanguage, 'attachment_name¤attachment_description', 'attachment_description');
        echo '	</div>
				<div class="clear">&nbsp;</div>
				<label>' . $this->l('File') . '</label>
				<div class="margin-form">
					<p><input type="file" name="attachment_file" /></p>
					<p>' . $this->l('Upload file from your computer') . '</p>
				</div>
				<div class="clear">&nbsp;</div>
				<div class="margin-form">
					<input type="submit" value="' . $this->l('Add a new attachment file') . '" name="submitAddAttachments" class="button" />
				</div>
				<div class="small"><sup>*</sup> ' . $this->l('Required field') . '</div>
			</fieldset>
		<div class="clear">&nbsp;</div>
		<table>
			<tr>
				<td>
					<p>' . $this->l('Attachments for this product:') . '</p>
					<select multiple id="selectAttachment1" name="attachments[]" style="width:300px;height:160px;">';
        foreach ($attach1 as $attach) {
            echo '<option value="' . $attach['id_attachment'] . '">' . $attach['name'] . '</option>';
        }
        echo '	</select><br /><br />
					<a href="#" id="addAttachment" style="text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px">
						' . $this->l('Remove') . ' &gt;&gt;
					</a>
				</td>
				<td style="padding-left:20px;">
					<p>' . $this->l('Available attachments:') . '</p>
					<select multiple id="selectAttachment2" style="width:300px;height:160px;">';
        foreach ($attach2 as $attach) {
            echo '<option value="' . $attach['id_attachment'] . '">' . $attach['name'] . '</option>';
        }
        echo '	</select><br /><br />
					<a href="#" id="removeAttachment" style="text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px">
						&lt;&lt; ' . $this->l('Add') . '
					</a>
				</div>
				</td>
			</tr>
		</table>
		<div class="clear">&nbsp;</div>
		<input type="submit" name="submitAttachments" id="submitAttachments" value="' . $this->l('Update attachments') . '" class="button" />';
    }
 private function initContentForAttachments()
 {
     if (Validate::isLoadedObject(${${"GLOBALS"}["vmqqtmkyw"]} = $this->object)) {
         ${${"GLOBALS"}["viwtuelcofr"]} = array();
         $yfgwtfjse = "iso_tiny_mce";
         ${"GLOBALS"}["ypeqpiyrxn"] = "languages";
         $ecoomiumv = "attachment_name";
         $uwxyfr = "ad";
         $wpvfmkpi = "languages";
         ${"GLOBALS"}["oyswhxryygq"] = "iso_tiny_mce";
         $wmdmyqfmjflc = "languages";
         ${${"GLOBALS"}["pqfqyy"]} = array();
         ${$wpvfmkpi} = Language::getLanguages(false);
         ${"GLOBALS"}["flhvdhdbegce"] = "language";
         foreach (${$wmdmyqfmjflc} as ${${"GLOBALS"}["flhvdhdbegce"]}) {
             ${"GLOBALS"}["lettfwur"] = "language";
             ${"GLOBALS"}["pzwxvpe"] = "attachment_name";
             ${"GLOBALS"}["xdwqxteju"] = "language";
             ${${"GLOBALS"}["pzwxvpe"]}[${${"GLOBALS"}["xdwqxteju"]}["id_lang"]] = "";
             ${${"GLOBALS"}["pqfqyy"]}[${${"GLOBALS"}["lettfwur"]}["id_lang"]] = "";
         }
         ${${"GLOBALS"}["oyswhxryygq"]} = $this->context->language->iso_code;
         ${${"GLOBALS"}["jccdkmwbanv"]} = file_exists(_PS_JS_DIR_ . "tiny_mce/langs/" . ${$yfgwtfjse} . ".js") ? ${${"GLOBALS"}["jccdkmwbanv"]} : "en";
         ${$uwxyfr} = str_replace("\\", "\\\\", dirname($_SERVER["PHP_SELF"]));
         self::$smarty->assign(array("languages" => ${${"GLOBALS"}["ypeqpiyrxn"]}, "attach1" => Attachment::getAttachments($this->context->language->id, $product->id, true), "attach2" => Attachment::getAttachments($this->context->language->id, $product->id, false), "default_form_language" => (int) Configuration::get("PS_LANG_DEFAULT"), "attachment_name" => ${$ecoomiumv}, "attachment_description" => ${${"GLOBALS"}["pqfqyy"]}, "PS_ATTACHMENT_MAXIMUM_SIZE" => Configuration::get("PS_ATTACHMENT_MAXIMUM_SIZE"), "isoTinyMCE" => ${${"GLOBALS"}["jccdkmwbanv"]}, "ad" => ${${"GLOBALS"}["kuvwml"]}));
     } else {
         $this->displayWarning($this->l('You must save this product in this shop before adding attachements.'));
     }
 }