PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/admin800/tabs/AdminAttachments.php

http://marocmall.googlecode.com/
PHP | 134 lines | 100 code | 9 blank | 25 comment | 15 complexity | 95cc5dc342ade901fadab7f1bd5c286b MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /*
  3. * 2007-2011 PrestaShop
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@prestashop.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  18. * versions in the future. If you wish to customize PrestaShop for your
  19. * needs please refer to http://www.prestashop.com for more information.
  20. *
  21. * @author PrestaShop SA <contact@prestashop.com>
  22. * @copyright 2007-2011 PrestaShop SA
  23. * @version Release: $Revision: 6594 $
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. * International Registered Trademark & Property of PrestaShop SA
  26. */
  27. include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php');
  28. class AdminAttachments extends AdminTab
  29. {
  30. public function __construct()
  31. {
  32. global $cookie;
  33. $this->table = 'attachment';
  34. $this->className = 'Attachment';
  35. $this->lang = true;
  36. $this->edit = true;
  37. $this->delete = true;
  38. $this->fieldsDisplay = array(
  39. 'id_attachment' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
  40. 'name' => array('title' => $this->l('Name')),
  41. 'file' => array('title' => $this->l('File')));
  42. parent::__construct();
  43. }
  44. public function postProcess()
  45. {
  46. if (Tools::isSubmit('submitAdd'.$this->table))
  47. {
  48. if ($id = (int)(Tools::getValue('id_attachment')) AND $a = new Attachment($id))
  49. {
  50. $_POST['file'] = $a->file;
  51. $_POST['mime'] = $a->mime;
  52. }
  53. if (!sizeof($this->_errors))
  54. {
  55. if (isset($_FILES['file']) AND is_uploaded_file($_FILES['file']['tmp_name']))
  56. {
  57. if ($_FILES['file']['size'] > (Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024))
  58. $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');
  59. else
  60. {
  61. do $uniqid = sha1(microtime()); while (file_exists(_PS_DOWNLOAD_DIR_.$uniqid));
  62. if (!copy($_FILES['file']['tmp_name'], _PS_DOWNLOAD_DIR_.$uniqid))
  63. $this->_errors[] = $this->l('File copy failed');
  64. $_POST['file_name'] = $_FILES['file']['name'];
  65. @unlink($_FILES['file']['tmp_name']);
  66. $_POST['file'] = $uniqid;
  67. $_POST['mime'] = $_FILES['file']['type'];
  68. }
  69. }
  70. else if (array_key_exists('file', $_FILES) && (int)$_FILES['file']['error'] === 1)
  71. {
  72. $max_upload = (int)(ini_get('upload_max_filesize'));
  73. $max_post = (int)(ini_get('post_max_size'));
  74. $upload_mb = min($max_upload, $max_post);
  75. $this->_errors[] = $this->l('the File').' <b>'.$_FILES['file']['name'].'</b> '.$this->l('exceeds the size allowed by the server. This limit is set to').' <b>'.$upload_mb.$this->l('Mb').'</b>';
  76. }
  77. else if (!empty($_FILES['file']['tmp_name']))
  78. $this->_errors[] = $this->l('No file or your file isn\'t uploadable, check your server configuration about the upload maximum size.');
  79. }
  80. $this->validateRules();
  81. }
  82. return parent::postProcess();
  83. }
  84. public function displayForm($isMainTab = true)
  85. {
  86. global $currentIndex, $cookie;
  87. parent::displayForm();
  88. if (!($obj = $this->loadObject(true)))
  89. return;
  90. echo '
  91. <form action="'.$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'" method="post" enctype="multipart/form-data">
  92. '.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
  93. <fieldset><legend><img src="../img/t/AdminAttachments.gif" />'.$this->l('Attachment').'</legend>
  94. <label>'.$this->l('Filename:').' </label>
  95. <div class="margin-form">';
  96. foreach ($this->_languages as $language)
  97. echo ' <div id="cname_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
  98. <input size="33" type="text" name="name_'.$language['id_lang'].'" value="'.htmlentities($this->getFieldValue($obj, 'name', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'" /><sup> *</sup>
  99. </div>';
  100. $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'cname?cdescription', 'cname');
  101. echo ' </div>
  102. <div class="clear">&nbsp;</div>
  103. <label>'.$this->l('Description:').' </label>
  104. <div class="margin-form">';
  105. foreach ($this->_languages as $language)
  106. echo ' <div id="cdescription_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
  107. <textarea name="description_'.$language['id_lang'].'">'.htmlentities($this->getFieldValue($obj, 'description', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'</textarea>
  108. </div>';
  109. $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'cname?cdescription', 'cdescription');
  110. echo ' </div>
  111. <div class="clear">&nbsp;</div>
  112. <label>'.$this->l('File').'</label>
  113. <div class="margin-form">
  114. <p><input type="file" name="file" /></p>
  115. <p>'.$this->l('Upload file from your computer').'</p>
  116. </div>
  117. <div class="clear">&nbsp;</div>
  118. <div class="margin-form">
  119. <input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
  120. </div>
  121. <div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
  122. </fieldset>
  123. </form>';
  124. }
  125. }