PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/controllers/admin/AdminQuickAccessesController.php

https://github.com/netplayer/PrestaShop
PHP | 172 lines | 131 code | 16 blank | 25 comment | 8 complexity | 41bcc9ce69ec89847afe2f4bb02eb698 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, LGPL-3.0
  1. <?php
  2. /*
  3. * 2007-2014 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-2014 PrestaShop SA
  23. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  24. * International Registered Trademark & Property of PrestaShop SA
  25. */
  26. class AdminQuickAccessesControllerCore extends AdminController
  27. {
  28. public function __construct()
  29. {
  30. $this->bootstrap = true;
  31. $this->table = 'quick_access';
  32. $this->className = 'QuickAccess';
  33. $this->lang = true;
  34. $this->addRowAction('edit');
  35. $this->addRowAction('delete');
  36. $this->context = Context::getContext();
  37. if (!Tools::getValue('realedit'))
  38. $this->deleted = false;
  39. $this->bulk_actions = array(
  40. 'delete' => array(
  41. 'text' => $this->l('Delete selected'),
  42. 'confirm' => $this->l('Delete selected items?'),
  43. 'icon' => 'icon-trash'
  44. )
  45. );
  46. $this->fields_list = array(
  47. 'id_quick_access' => array(
  48. 'title' => $this->l('ID'),
  49. 'align' => 'center',
  50. 'class' => 'fixed-width-xs'
  51. ),
  52. 'name' => array(
  53. 'title' => $this->l('Name')
  54. ),
  55. 'link' => array(
  56. 'title' => $this->l('Link')
  57. ),
  58. 'new_window' => array(
  59. 'title' => $this->l('New window'),
  60. 'align' => 'center',
  61. 'type' => 'bool',
  62. 'active' => 'new_window',
  63. 'class' => 'fixed-width-sm'
  64. )
  65. );
  66. $this->fields_form = array(
  67. 'legend' => array(
  68. 'title' => $this->l('Quick Access menu'),
  69. 'icon' => 'icon-align-justify'
  70. ),
  71. 'input' => array(
  72. array(
  73. 'type' => 'text',
  74. 'label' => $this->l('Name'),
  75. 'name' => 'name',
  76. 'lang' => true,
  77. 'maxlength' => 32,
  78. 'required' => true,
  79. 'hint' => $this->l('Forbidden characters:').' &lt;&gt;;=#{}'
  80. ),
  81. array(
  82. 'type' => 'text',
  83. 'label' => $this->l('URL'),
  84. 'name' => 'link',
  85. 'maxlength' => 128,
  86. 'required' => true,
  87. 'hint' => $this->l('If it\'s a URL that comes from your Back Office, you MUST remove the security token.')
  88. ),
  89. array(
  90. 'type' => 'switch',
  91. 'label' => $this->l('Open in new window'),
  92. 'name' => 'new_window',
  93. 'required' => false,
  94. 'values' => array(
  95. array(
  96. 'id' => 'new_window_on',
  97. 'value' => 1,
  98. 'label' => '<img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" />'
  99. ),
  100. array(
  101. 'id' => 'new_window_off',
  102. 'value' => 0,
  103. 'label' => '<img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" />'
  104. )
  105. )
  106. )
  107. ),
  108. 'submit' => array(
  109. 'title' => $this->l('Save'),
  110. )
  111. );
  112. parent::__construct();
  113. }
  114. public function initPageHeaderToolbar()
  115. {
  116. if (empty($this->display))
  117. $this->page_header_toolbar_btn['new_quick_access'] = array(
  118. 'href' => self::$currentIndex.'&addquick_access&token='.$this->token,
  119. 'desc' => $this->l('Add new quick access', null, null, false),
  120. 'icon' => 'process-icon-new'
  121. );
  122. parent::initPageHeaderToolbar();
  123. }
  124. public function initProcess()
  125. {
  126. if ((isset($_GET['new_window'.$this->table]) || isset($_GET['new_window'])) && Tools::getValue($this->identifier))
  127. {
  128. if ($this->tabAccess['edit'] === '1')
  129. $this->action = 'newWindow';
  130. else
  131. $this->errors[] = Tools::displayError('You do not have permission to edit this.');
  132. }
  133. parent::initProcess();
  134. }
  135. public function processAdd()
  136. {
  137. // Enable the creation of quick links from the URL
  138. $_POST = array_merge($_POST, $_GET);
  139. return parent::processAdd();
  140. }
  141. public function processNewWindow()
  142. {
  143. if (Validate::isLoadedObject($object = $this->loadObject()))
  144. {
  145. if ($object->toggleNewWindow())
  146. $this->redirect_after = self::$currentIndex.'&conf=5&token='.$this->token;
  147. else
  148. $this->errors[] = Tools::displayError('An error occurred while updating new window property.');
  149. }
  150. else
  151. $this->errors[] = Tools::displayError('An error occurred while updating the new window property for this object.').
  152. ' <b>'.$this->table.'</b> '.
  153. Tools::displayError('(cannot load object)');
  154. return $object;
  155. }
  156. }