Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.41 KB | None | 0 0
  1. <?php
  2.  
  3. if ( !defined('_CAN_LOAD_FILES_'))
  4. exit;
  5.  
  6. #doc
  7. # classname: CustomerProfile
  8. # scope: PUBLIC
  9. #
  10. #/doc
  11.  
  12. class CustomerProfile extends Module
  13. {
  14. # internal variables
  15. protected $error = false;
  16.  
  17. # Constructor
  18. function __construct ( )
  19. {
  20. $this->name = 'customerprofile';
  21. $this->tableRef = 'refCoiffeur';
  22. $this->tab = 'front_office_features';
  23. $this->version = '1.0';
  24. $this->author = 'Mathieu Basili';
  25.  
  26. parent::__construct();
  27.  
  28. $this->displayName = $this->l('Customer Profile');
  29. $this->description = $this->l('Permet de rajouter des infos au profil utilisateur');
  30. $this->confirmUninstall = $this->l('Vous �tes certain de vouloir desinstaller ce module?');
  31. }
  32.  
  33.  
  34. public function install ()
  35. {
  36.  
  37. $query = "CREATE TABLE `" . _DB_PREFIX_ . $this->name . "` (
  38. `id` INT( 22 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  39. `name` VARCHAR( 50 ) NOT NULL ,
  40. `value` TEXT NULL ,
  41. `description` TEXT NOT NULL
  42. ) ENGINE = "._MYSQL_ENGINE_." default CHARSET=utf8";
  43.  
  44. $queryRefCoiffeurs = "CREATE TABLE `" . _DB_PREFIX_ . $this->tableRef . "` (
  45. `id` INT( 22 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  46. `name` VARCHAR( 50 ) NOT NULL ,
  47. `ref` TEXT NULL
  48. ) ENGINE = "._MYSQL_ENGINE_." default CHARSET=utf8";
  49.  
  50.  
  51. echo $query;
  52. if(!parent::install() ||
  53. !Db::getInstance()->Execute($query) ||
  54. !Db::getInstance()->Execute($queryRefCoiffeurs) ||
  55. !self::registerHook ('backOfficeHeader'))
  56. return false;
  57. else
  58. return true;
  59. }
  60.  
  61. public function hookBackOfficeHeader($params){
  62.  
  63.  
  64.  
  65. // Assign hook outputs for own hooks
  66. global $smarty;
  67.  
  68.  
  69. Tools::addCss($this->_path.'/css/ui.jqgrid.css', 'all');
  70. Tools::addJS(_PS_MODULE_DIR_ . 'customerprofile/js/jquery.jqGrid.min.js', 'all');
  71. /*
  72.  
  73. Tools::addCSS(_THEME_CSS_DIR_ . 'fx/typography.css', 'all');
  74. Tools::addCSS(_THEME_CSS_DIR_ . 'fx/print.css', 'print');
  75. Tools::addCSS(_THEME_CSS_DIR_ . 'global.css', 'all');
  76.  
  77. */
  78. }
  79.  
  80. public function uninstall ()
  81. {
  82. $query = "DROP TABLE `" . _DB_PREFIX_ . $this->name . "`";
  83. $queryRefCoiffeurs = "DROP TABLE `" . _DB_PREFIX_ . $this->tableRef . "`";
  84. if(!parent::uninstall() || !Db::getInstance()->Execute($query) || !Db::getInstance()->Execute($queryRefCoiffeurs))
  85. return false;
  86. else
  87. return true;
  88. }
  89.  
  90. public function getContent ()
  91. {
  92.  
  93. if(Tools::isSubmit('submitRef')){
  94. $name = Tools::getValue('name');
  95. if(isset($name) && $name != ''){
  96. $ref = Tools::getValue('ref');
  97. if(isset($ref) && $ref!= ''){
  98. $this->addRef(Tools::getValue('name'), Tools::getValue('ref'));
  99. $html .= $this->displayConfirmation($this->l('Settings updated.'));
  100. }
  101. else $html .= $this->displayError($this->l('Invalid ref.'));
  102. }
  103. else
  104. $html .= $this->displayError($this->l('Invalid name.'));
  105.  
  106. }
  107.  
  108. $this->_html = "<h2>". $this->displayName ."</h2>";
  109.  
  110.  
  111. $this->_displayList();
  112. $this->_displayForm();
  113.  
  114.  
  115. return $this->_html;
  116. }
  117.  
  118.  
  119. public function _displayForm ()
  120. {
  121.  
  122. $this->_html .= '
  123.  
  124.  
  125. <fieldset class="space">
  126.  
  127. <legend><img src="'.$this->_path.'logo.gif" >Ajouter une r&eacute;f&eacute;rence</legend>
  128.  
  129.  
  130. <form action="'.$_SERVER['REQUEST_URI'].'" method="post">
  131.  
  132. <label>'.$this->l('Name').'</label>
  133. <div class="margin-form">
  134. <input type="text" name="name" />
  135. </div>
  136.  
  137. <label>'.$this->l('Ref').'</label>
  138. <div class="margin-form">
  139. <input type="text" name="ref" />
  140. </div>
  141.  
  142. <div class="clear center">
  143. <input class="button" type="submit" name="submitRef" value="'.$this->l(' Add ').'" />
  144. </div>
  145. </fieldset>
  146. </form>
  147.  
  148. </fieldset>
  149. ';
  150. }
  151.  
  152.  
  153. public function _displayList ()
  154. {
  155. //$this->addRef('Hello', '12345675432FDSFFD');
  156. $this->_html .= '
  157.  
  158.  
  159. <fieldset class="space">
  160.  
  161. <legend><img src="'.$this->_path.'logo.gif" >R&eacute;f&eacute;rences</legend>
  162. <label>A label</label><input type="submit" class="button">
  163.  
  164. <table>
  165. <caption>Tableau des r&eacute;f&eacute;rences</caption>
  166. <colgroup />
  167. <colgroup span="2" title="title" />
  168. <thead>
  169. <tr>
  170. <th scope="col">ID</th>
  171. <th scope="col">Name</th>
  172. <th scope="col">Ref</th>
  173. </tr>
  174. </thead>
  175. <tfoot>
  176. <tr>
  177. <td>ID</td>
  178. <td>Name</td>
  179. <td>Ref</td>
  180. </tr>
  181. </tfoot>
  182. <tbody>
  183.  
  184. ';
  185.  
  186. $refs = $this->getRefs();
  187.  
  188.  
  189. foreach ($refs as $ref) {
  190. $this->_html .= '
  191. <tr>
  192. <td>' . $ref['id'] . '</td>
  193. <td>' . $ref['name'] . '</td>
  194. <td>' . $ref['ref'] . '</td>
  195. </tr>
  196. ';
  197. }
  198.  
  199. $this->_html .= '
  200. </tbody>
  201. </table>
  202. </fieldset>
  203. ';
  204.  
  205.  
  206. }
  207.  
  208. public function getRefs (){
  209. $results = array();
  210.  
  211. if (!$refs = Db::getInstance()->ExecuteS('SELECT `id`, `name`, `ref` FROM ' . _DB_PREFIX_ . $this->tableRef . ((int)(Configuration::get('PS_TABLEREF_ORDERWAY')) == 1 ? ' ORDER BY `id` DESC' : '')))
  212. return false;
  213. $i = 0;
  214.  
  215. foreach ($refs as $ref) {
  216. $results[$i]['id'] = $ref['id'];
  217. $results[$i]['name'] = $ref['name'];
  218. $results[$i++]['ref'] = $ref['ref'];
  219.  
  220. if (!$texts) {
  221.  
  222. }
  223. }
  224.  
  225. return $results;
  226. }
  227.  
  228. public function addRef ( $name, $ref ){
  229.  
  230. if ( !Db::getInstance()->Execute( 'INSERT INTO ' . _DB_PREFIX_ . $this->tableRef . ' VALUES (\'\', \'' . pSQL($name) . '\', \'' . pSQL($ref) . '\' )'))
  231. return false;
  232. }
  233.  
  234. public function updateRef ( $id, $name, $ref){
  235. if ( !Db::getInstance()->Execute( 'UPDATE ' . _DB_PREFIX_ . $this->tableRef . 'SET
  236. `name` = \'' . pSQL($name) . '\',
  237. `ref` = \'' . pSQL($name) . '\'
  238. WHERE `id` = ' . (int)($id)))
  239. return false;
  240. }
  241.  
  242. public function deleteRef ( $id ){
  243. if ( !Db::getInstance()->Execute( 'DELETE FROM ' . _DB_PREFIX_ . $this->tableRef .' WHERE `id` = ` ' . (int)($id) . '`' ))
  244. return false;
  245. }
  246.  
  247. }
  248. ###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement