PageRenderTime 31ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/storecommander/ead6f6fce09/SC/lib/cat/categorypanel/cat_categorypanel_get.php

https://gitlab.com/ptisky/API_prestashop
PHP | 212 lines | 164 code | 14 blank | 34 comment | 29 complexity | b11ef69abdaec93fa615dbea134aee3c MD5 | raw file
  1. <?php
  2. /**
  3. * Store Commander
  4. *
  5. * @category administration
  6. * @author Store Commander - support@storecommander.com
  7. * @version 2015-09-15
  8. * @uses Prestashop modules
  9. * @since 2009
  10. * @copyright Copyright &copy; 2009-2015, Store Commander
  11. * @license commercial
  12. * All rights reserved! Copying, duplication strictly prohibited
  13. *
  14. * *****************************************
  15. * * STORE COMMANDER *
  16. * * http://www.StoreCommander.com *
  17. * * V 2015-09-15 *
  18. * *****************************************
  19. *
  20. * Compatibility: PS version: 1.1 to 1.6.1
  21. *
  22. **/
  23. $id_lang=intval(Tools::getValue('id_lang'));
  24. $id_product=intval(Tools::getValue('id_product'));
  25. $for_mb = Tools::getValue('for_mb', 1);
  26. function getLevelFromDB($parent_id)
  27. {
  28. global $id_lang, $for_mb;
  29. if(SCMS && SCI::getSelectedShop()>0 && $for_mb==1)
  30. {
  31. $sql = "SELECT c.active,c.id_category,name FROM "._DB_PREFIX_."category c
  32. LEFT JOIN "._DB_PREFIX_."category_lang cl ON (cl.id_category=c.id_category AND cl.id_lang=".(int)$id_lang." AND cl.id_shop=".(int)SCI::getSelectedShop().")
  33. LEFT JOIN "._DB_PREFIX_."category_shop cs ON cs.id_category=c.id_category
  34. WHERE c.id_parent=".(int)$parent_id."
  35. AND cs.id_shop=".(int)SCI::getSelectedShop()."
  36. GROUP BY c.id_category
  37. ORDER BY cs.position, cl.name";
  38. }
  39. elseif(version_compare(_PS_VERSION_, '1.3.0.0', '>='))
  40. {
  41. $sql = "SELECT c.active,c.id_category,name FROM "._DB_PREFIX_."category c
  42. LEFT JOIN "._DB_PREFIX_."category_lang cl ON (cl.id_category=c.id_category AND cl.id_lang=".(int)$id_lang.")
  43. WHERE c.id_parent=".(int)$parent_id."
  44. GROUP BY c.id_category
  45. ORDER BY cl.name";
  46. }
  47. else
  48. {
  49. $sql = "SELECT c.active,c.id_category,name FROM "._DB_PREFIX_."category c
  50. LEFT JOIN "._DB_PREFIX_."category_lang cl ON (cl.id_category=c.id_category AND cl.id_lang=".(int)$id_lang.")
  51. WHERE c.id_parent=".(int)$parent_id."
  52. GROUP BY c.id_category
  53. ORDER BY cl.name";
  54. }
  55. $res=Db::getInstance()->ExecuteS($sql);
  56. if(!empty($res))
  57. {
  58. foreach($res as $k => $row){
  59. $style='';
  60. if (hideCategoryPosition($row['name'])=='')
  61. {
  62. $sql2 = "SELECT name FROM "._DB_PREFIX_."category_lang
  63. WHERE id_lang=".intval(Configuration::get('PS_LANG_DEFAULT'))."
  64. AND id_category=".$row['id_category'];
  65. $res2=Db::getInstance()->getRow($sql2);
  66. $style='style="background:lightblue" ';
  67. }
  68. $icon=($row['active']?'catalog.png':'folder_grey.png');
  69. if (sc_in_array(hideCategoryPosition($row['name']),array('SC Recycle Bin', 'SC Corbeille'),"catCategorypanel_corbeille"))
  70. $icon='folder_delete.png';
  71. /*if (!in_array(hideCategoryPosition($row['name']),array('SC Recycle Bin', 'SC Corbeille')))
  72. {*/
  73. echo "<row ".($style!='' ? $style:'').
  74. " id=\"".$row['id_category']."\"".($parent_id==0?' open="1"':'').">".
  75. "<cell>".$row['id_category']."</cell>".
  76. "<cell>0</cell>".
  77. "<cell image=\"../../".$icon."\"><![CDATA[".($style==''?formatText(hideCategoryPosition($row['name'])):_l('To Translate:').' '.formatText(hideCategoryPosition($res2['name'])))."]]></cell>".
  78. "<cell>3</cell>";
  79. getLevelFromDB($row['id_category']);
  80. echo '</row>'."\n";
  81. //}
  82. }
  83. }
  84. }
  85. function getLevelFromDB_PHP($id_parent)
  86. {
  87. global $id_lang,$for_mb,$array_cats,$array_children_cats;
  88. if(!empty($array_children_cats[$id_parent]))
  89. {
  90. ksort($array_children_cats[$id_parent]);
  91. foreach($array_children_cats[$id_parent] as $k => $id)
  92. {
  93. $row = $array_cats[$id];
  94. $style='';
  95. if (hideCategoryPosition($row['name'])=='SoColissimo')
  96. continue;
  97. if (hideCategoryPosition($row['name'])=='')
  98. {
  99. $sql2 = "SELECT name FROM "._DB_PREFIX_."category_lang
  100. WHERE id_lang=".intval(Configuration::get('PS_LANG_DEFAULT'))."
  101. AND id_category=".$row['id_category'];
  102. $res2=Db::getInstance()->getRow($sql2);
  103. $style='style="background:lightblue" ';
  104. }
  105. $icon=($row['active']?'catalog.png':'folder_grey.png');
  106. if (sc_in_array(hideCategoryPosition($row['name']),array('SC Recycle Bin', 'SC Corbeille'),"catCategorypanel_corbeille"))
  107. $icon='folder_delete.png';
  108. /*if (!in_array(hideCategoryPosition($row['name']),array('SC Recycle Bin', 'SC Corbeille')))
  109. {*/
  110. echo "<row ".($style!='' ? $style:'').
  111. " id=\"".$row['id_category']."\"".($row["id_parent"]==0?' open="1"':'').">".
  112. "<cell>".$row['id_category']."</cell>".
  113. "<cell>0</cell>".
  114. "<cell image=\"../../".$icon."\"><![CDATA[".($style==''?formatText(hideCategoryPosition($row['name'])):_l('To Translate:').' '.formatText(hideCategoryPosition($res2['name'])))."]]></cell>".
  115. "<cell>3</cell>";
  116. getLevelFromDB_PHP($row['id_category']);
  117. echo '</row>'."\n";
  118. //}
  119. }
  120. }
  121. }
  122. //XML HEADER
  123. //include XML Header (as response will be in xml format)
  124. if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
  125. header("Content-type: application/xhtml+xml"); } else {
  126. header("Content-type: text/xml");
  127. }
  128. echo("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  129. ?>
  130. <rows parent="0">
  131. <head>
  132. <beforeInit>
  133. <call command="attachHeader"><param><![CDATA[#text_filter,,#text_filter,]]></param></call>
  134. </beforeInit>
  135. <column id="id_category" width="40" type="ro" align="right" sort="int"><?php echo _l('ID')?></column>
  136. <column id="used" width="50" type="ch" align="center" sort="str"><?php echo _l('Used')?></column>
  137. <column id="name" width="250" type="tree" align="left" sort="str"><?php echo _l('Name')?></column>
  138. <column id="default" width="50" type="ra" align="center" sort="str"><?php echo _l('Default')?></column>
  139. </head>
  140. <?php
  141. echo '<userdata name="uisettings">'.uisettings::getSetting('cat_categorypanel').'</userdata>'."\n";
  142. if (version_compare(_PS_VERSION_, '1.5.0.0', '<'))
  143. echo "<row ".
  144. " id=\"1\">".
  145. "<cell>1</cell>".
  146. "<cell>0</cell>".
  147. "<cell image=\"catalog.png\"><![CDATA["._l('Home')."]]></cell>".
  148. "<cell>0</cell></row>";
  149. $id_root=0;
  150. $ps_root = 0;//SCI::getConfigurationValue("PS_ROOT_CATEGORY");
  151. $sql_root = "SELECT *
  152. FROM "._DB_PREFIX_."category
  153. WHERE id_parent = 0";
  154. $res_root=Db::getInstance()->ExecuteS($sql_root);
  155. if(!empty($res_root[0]["id_category"]))
  156. $ps_root = $res_root[0]["id_category"];
  157. if(!empty($ps_root))
  158. $id_root = $ps_root;
  159. $id_shop=SCI::getSelectedShop();
  160. if (SCMS && $id_shop > 0)
  161. {
  162. $shop = new Shop($id_shop);
  163. $categ = new Category($shop->id_category);
  164. $id_root = $categ->id_parent;
  165. }
  166. /* $sql = 'SELECT c.id_category
  167. FROM `'._DB_PREFIX_.'category` c
  168. WHERE c.`id_parent` = 0';
  169. $res=Db::getInstance()->getRow($sql);
  170. $id_category_root=$res['id_category'];*/
  171. if(version_compare(_PS_VERSION_, '1.4.0.0', '>='))
  172. {
  173. $array_cats = array();
  174. $array_children_cats = array();
  175. if(version_compare(_PS_VERSION_, '1.5.0.0', '>=') && !SCMS)
  176. {
  177. $id_shop = (int)Configuration::get('PS_SHOP_DEFAULT');
  178. }
  179. $sql = "SELECT c.*, cl.name, c.position ".(( (SCMS && $for_mb==1) || (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && !SCMS) ) && !empty($id_shop)?", cs.position":"")."
  180. FROM "._DB_PREFIX_."category c
  181. LEFT JOIN "._DB_PREFIX_."category_lang cl ON (cl.id_category=c.id_category AND cl.id_lang=".intval($id_lang).")
  182. ".(( (SCMS && $for_mb==1) || (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && !SCMS) ) && !empty($id_shop)?" INNER JOIN "._DB_PREFIX_."category_shop cs ON (cs.id_category=c.id_category AND cs.id_shop=".(int)$id_shop.") ":"")."
  183. GROUP BY c.id_category
  184. ORDER BY c.`nleft` ASC";
  185. $res=Db::getInstance()->ExecuteS($sql);
  186. foreach($res as $k => $row)
  187. {
  188. $array_cats[$row["id_category"]]=$row;
  189. if(!isset($array_children_cats[$row["id_parent"]]))
  190. $array_children_cats[$row["id_parent"]] = array();
  191. $array_children_cats[$row["id_parent"]][str_pad($row["position"], 5, "0", STR_PAD_LEFT).str_pad($row["id_category"], 12, "0", STR_PAD_LEFT)] = $row["id_category"];
  192. }
  193. getLevelFromDB_PHP($id_root);
  194. }
  195. else
  196. getLevelFromDB($id_root);
  197. ?>
  198. </rows>