PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/compare/notik/compareClass.php

https://bitbucket.org/spivovartsev/citrus.ua
PHP | 329 lines | 235 code | 35 blank | 59 comment | 23 complexity | 60cafcd066f16c26650f0741f8233d96 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. //error_reporting(E_ALL);
  3. class Compare
  4. {
  5. protected $_dbLink = null;
  6. protected $_dbHost = '';
  7. protected $_dbUser = '';
  8. protected $_dbPass = '';
  9. protected $_dbName = '';
  10. public function __construct($dbLink=null)
  11. {
  12. require '/var/www/beta.citrus.ua/application/config/application.php';
  13. $this->_dbHost = $dbHost;
  14. $this->_dbUser = $dbUser;
  15. $this->_dbPass = $dbPass;
  16. $this->_dbName = $dbName;
  17. if (!$dbLink) {
  18. $this->_dbLink = mysql_connect($this->_dbHost, $this->_dbUser, $this->_dbPass, true) or die(mysql_error());
  19. } else {
  20. $this->_dbLink = $dbLink;
  21. }
  22. mysql_select_db($this->_dbName, $this->_dbLink) or die(mysql_error());
  23. mysql_query("SET NAMES cp1251", $this->_dbLink) or die(mysql_error());
  24. }
  25. // ¬озвращаем список товаров в категории
  26. public function getShopGoodsList($catId=189)
  27. {
  28. $arrItems = array();
  29. $catId = (int) $catId;
  30. $sql = "SELECT bie.`ID`, bie.`NAME`,
  31. bf1.`SUBDIR` AS PREVIEW_PICTURE_SUBDIR, bf1.`FILE_NAME` AS PREVIEW_PICTURE_NAME,
  32. bf2.`SUBDIR` AS DETAIL_PICTURE_SUBDIR, bf2.`FILE_NAME` AS DETAIL_PICTURE_NAME,
  33. bcp.`PRICE`
  34. FROM `b_iblock_section_element` AS bise
  35. JOIN `b_iblock_element` AS bie ON bie.`ID` = bise.`IBLOCK_ELEMENT_ID`
  36. AND bie.`ACTIVE` = 'Y'
  37. AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
  38. LEFt JOIN `b_file` AS bf1 ON bf1.`ID` = bie.`PREVIEW_PICTURE`
  39. LEFt JOIN `b_file` AS bf2 ON bf2.`ID` = bie.`DETAIL_PICTURE`
  40. JOIN `b_catalog_price` AS bcp ON bcp.`PRODUCT_ID` = bie.`ID`
  41. AND bcp.`CATALOG_GROUP_ID` = '3'
  42. AND bcp.`EXTRA_ID` IS NULL
  43. JOIN `b_catalog_product` AS bcpr ON bcpr.`ID` = bie.`ID`
  44. AND bcpr.`QUANTITY` > '0'
  45. AND bcpr.`QUANTITY_TRACE` = 'Y'
  46. WHERE bise.`IBLOCK_SECTION_ID` = '{$catId}'
  47. AND bise.`ADDITIONAL_PROPERTY_ID` IS NULL
  48. ORDER BY bie.`NAME`";
  49. $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
  50. if (mysql_num_rows($result) > 0) {
  51. while ($row = mysql_fetch_assoc($result)) {
  52. $id = (int) $row['ID'];
  53. $arrItems[$id]['id'] = $id;
  54. $arrItems[$id]['name'] = stripslashes($row['NAME']);
  55. $arrItems[$id]['price'] = stripslashes($row['PRICE']);
  56. if (strlen($row['PREVIEW_PICTURE_NAME']) > 0) {
  57. $arrItems[$id]['pic'] = '/upload/' . $row['PREVIEW_PICTURE_SUBDIR'] . '/' . $row['PREVIEW_PICTURE_NAME'];
  58. } else {
  59. $arrItems[$id]['pic'] = '/upload/' . $row['DETAIL_PICTURE_SUBDIR'] . '/' . $row['DETAIL_PICTURE_NAME'];
  60. }
  61. }
  62. }
  63. return $arrItems;
  64. }
  65. // ƒетально товар
  66. public function searchModelParam($choice,$search)
  67. {
  68. $arrResult = array();
  69. $choice = (int) $choice; // ID производител€
  70. $search = iconv('utf-8', 'cp1251', $search);
  71. //$search = $this->_convertCyrToLat($search);
  72. $search = mysql_real_escape_string($search);
  73. /*
  74. SELECT bie.`ID`,bie.`IBLOCK_ID`, bie.`NAME`, bie.`IBLOCK_SECTION_ID`
  75. FROM `b_iblock_element` AS bie
  76. JOIN `b_iblock` AS bi ON bi.`ID` = bie.`IBLOCK_ID`
  77. AND bi.`ACTIVE` = 'Y'
  78. JOIN `b_catalog_product` AS bcpr ON bcpr.`ID` = bie.`ID`
  79. WHERE bie.NAME LIKE '%Samsung NP300E7Z-S01UA%'
  80. AND bie.`ACTIVE` = 'Y'
  81. AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
  82. ORDER BY bie.`NAME`
  83. SELECT bie.`ID`,bie.`IBLOCK_ID`, bie.`NAME`, bie.`IBLOCK_SECTION_ID`
  84. FROM `b_iblock_element` AS bie
  85. JOIN `b_iblock` AS bi ON bi.`ID` = bie.`IBLOCK_ID`
  86. AND bi.`ACTIVE` = 'Y'
  87. WHERE bie.NAME LIKE '%Samsung NP300E7Z-S01UA%'
  88. AND bie.`ACTIVE` = 'Y'
  89. AND bie.`IBLOCK_ID` = 69
  90. AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
  91. ORDER BY bie.`NAME`
  92. SELECT bie.`ID`,bie.`IBLOCK_ID`, bie.`NAME`,bie.`DETAIL_TEXT`,
  93. bi.`DETAIL_PAGE_URL`, bie.`IBLOCK_SECTION_ID`,
  94. bf1.`SUBDIR` AS PREVIEW_PICTURE_SUBDIR, bf1.`FILE_NAME` AS PREVIEW_PICTURE_NAME,
  95. bf2.`SUBDIR` AS DETAIL_PICTURE_SUBDIR, bf2.`FILE_NAME` AS DETAIL_PICTURE_NAME,
  96. bcp2.`PRICE` AS PRICE_OFFLINE, bcp2.`CURRENCY` AS CURRENCY_OFFLINE,
  97. bcp.`PRICE`
  98. FROM `b_iblock_element` AS bie
  99. JOIN `b_iblock` AS bi ON bi.`ID` = bie.`IBLOCK_ID`
  100. AND bi.`ACTIVE` = 'Y'
  101. LEFt JOIN `b_file` AS bf1 ON bf1.`ID` = bie.`PREVIEW_PICTURE`
  102. LEFt JOIN `b_file` AS bf2 ON bf2.`ID` = bie.`DETAIL_PICTURE`
  103. JOIN `b_catalog_price` AS bcp ON bcp.`PRODUCT_ID` = bie.`ID`
  104. AND bcp.`CATALOG_GROUP_ID` = '3'
  105. AND bcp.`EXTRA_ID` IS NULL
  106. LEFT JOIN `b_catalog_price` AS bcp2 ON bcp2.`PRODUCT_ID` = bie.`ID`
  107. AND bcp2.`CATALOG_GROUP_ID` = '4'
  108. WHERE bie.NAME LIKE '%Samsung NP300E7Z-S01UA%'
  109. AND bie.`ACTIVE` = 'Y'
  110. AND bie.`IBLOCK_ID`=69
  111. AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
  112. ORDER BY bie.`NAME`
  113. */
  114. $sql = "SELECT bie.`ID`,bie.`IBLOCK_ID`, bie.`NAME`,bie.`DETAIL_TEXT`,
  115. bi.`DETAIL_PAGE_URL`, bie.`IBLOCK_SECTION_ID`,
  116. bf1.`SUBDIR` AS PREVIEW_PICTURE_SUBDIR, bf1.`FILE_NAME` AS PREVIEW_PICTURE_NAME,
  117. bf2.`SUBDIR` AS DETAIL_PICTURE_SUBDIR, bf2.`FILE_NAME` AS DETAIL_PICTURE_NAME,
  118. bcp2.`PRICE` AS PRICE_OFFLINE, bcp2.`CURRENCY` AS CURRENCY_OFFLINE,
  119. bcp.`PRICE`
  120. FROM `b_iblock_element` AS bie
  121. JOIN `b_iblock` AS bi ON bi.`ID` = bie.`IBLOCK_ID`
  122. AND bi.`ACTIVE` = 'Y'
  123. LEFt JOIN `b_file` AS bf1 ON bf1.`ID` = bie.`PREVIEW_PICTURE`
  124. LEFt JOIN `b_file` AS bf2 ON bf2.`ID` = bie.`DETAIL_PICTURE`
  125. JOIN `b_catalog_price` AS bcp ON bcp.`PRODUCT_ID` = bie.`ID`
  126. AND bcp.`CATALOG_GROUP_ID` = '3'
  127. AND bcp.`EXTRA_ID` IS NULL
  128. LEFT JOIN `b_catalog_price` AS bcp2 ON bcp2.`PRODUCT_ID` = bie.`ID`
  129. AND bcp2.`CATALOG_GROUP_ID` = '4'
  130. WHERE bie.NAME LIKE '%".$search."%'
  131. AND bie.`ACTIVE` = 'Y'
  132. AND bie.`IBLOCK_ID`=69
  133. AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
  134. ORDER BY bie.`NAME`";
  135. $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
  136. if (mysql_num_rows($result) > 0) {
  137. $row = mysql_fetch_assoc($result);
  138. $id = (int) $row['ID'];
  139. $arrResult['id'] = $id;
  140. $url = str_replace('#SITE_DIR#', '', $row['DETAIL_PAGE_URL']);
  141. $url = str_replace('#SECTION_ID#', $row['IBLOCK_SECTION_ID'], $url);
  142. $url = str_replace('#ID#', $id, $url);
  143. $arrResult['url'] = $url;
  144. $arrResult['buy_url'] = $url . '?action=BUY&id=' . $id;
  145. $arrResult['name'] = stripslashes($row['NAME']);
  146. $arrResult['text'] = stripslashes($row['DETAIL_TEXT']);
  147. $arrResult['price'] = (float) $row['PRICE'];
  148. $arrResult['price_offline'] = (float) $row['PRICE_OFFLINE'];
  149. $arrResult['quantity'] = (int) $row['QUANTITY'];
  150. $arrResult['quantity_trace'] = $row['QUANTITY_TRACE'];
  151. $sql2 = "SELECT bipe.VALUE FROM b_iblock_element AS bie,
  152. b_iblock_property AS bip,b_iblock_property_enum AS bipe,
  153. b_iblock_element_property AS biep
  154. Where bip.IBLOCK_ID = '".$row['IBLOCK_ID']."'
  155. AND bip.CODE = 'LENDING'
  156. AND bipe.PROPERTY_ID = bip.ID
  157. AND biep.IBLOCK_PROPERTY_ID = bip.ID
  158. AND biep.IBLOCK_ELEMENT_ID = '".$id."'
  159. AND biep.VALUE = bipe.ID LIMIT 1";
  160. $result2 = mysql_query($sql2, $this->_dbLink) or die(mysql_error());
  161. if (mysql_num_rows($result2) > 0) {
  162. $row2 = mysql_fetch_assoc($result2);
  163. $arrResult['lending'] = $row2['VALUE'];
  164. } else { $arrResult['lending'] = 'нет';}
  165. $sql3 = "SELECT biep.VALUE FROM b_iblock_element_property AS biep
  166. WHERE biep.IBLOCK_PROPERTY_ID = (select ID FROM b_iblock_property WHERE IBLOCK_ID = '".$row['IBLOCK_ID']."' AND CODE = 'MORE_PHOTO')
  167. AND biep.IBLOCK_ELEMENT_ID = '".$id."'";
  168. $result3 = mysql_query($sql3, $this->_dbLink) or die(mysql_error());
  169. if (mysql_num_rows($result3) > 0) {
  170. while ($row3 = mysql_fetch_assoc($result3)) {
  171. $arrResult['img'][] = $row3['VALUE'];
  172. } }
  173. if (strlen($row['PREVIEW_PICTURE_NAME']) > 0) {
  174. $arrResult['pic'] = '/upload/' . $row['PREVIEW_PICTURE_SUBDIR'] . '/' . $row['PREVIEW_PICTURE_NAME'];
  175. } else {
  176. $arrResult['pic'] = '/upload/' . $row['DETAIL_PICTURE_SUBDIR'] . '/' . $row['DETAIL_PICTURE_NAME'];
  177. }
  178. }
  179. return $arrResult;
  180. }
  181. // ћен€ем символы
  182. protected function _convertCyrToLat($string)
  183. {
  184. $string = strtr($string, "йцукенгшщзхъфывапролджэ€чсмитьбю", "qwertyuiop[]asdfghjkl;'zxcvbnm,.");
  185. $string = strtr($string, "…÷” ≈Ќ√Ўў«’Џ‘џ¬јѕ–ќЋƒ∆Ёя„—ћ»“№Ѕё", "QWERTYUIOP[]ASDFGHJKL;'ZXCVBNM,.");
  186. return $string;
  187. }
  188. // вывод моделей в список по шаблону %LIKE%
  189. public function searchTradeinModelName($search,$develop,$id)
  190. {
  191. $arrItems = array();
  192. $search = iconv('utf-8', 'cp1251', $search);
  193. $search = $this->_convertCyrToLat($search);
  194. $search = mysql_real_escape_string($search);
  195. $sql = "select bie.NAME from b_iblock_element as bie, b_iblock_element_property as biep
  196. WHERE bie.NAME LIKE '%{$search}%'
  197. AND biep.VALUE = '{$develop}'
  198. and bie.IBLOCK_ID = '{$id}'
  199. and bie.ID = biep.IBLOCK_ELEMENT_ID
  200. and bie.ACTIVE = 'Y'
  201. and bie.`WF_PARENT_ELEMENT_ID` IS NULL
  202. LIMIT 30";
  203. $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
  204. if (mysql_num_rows($result) > 0) {
  205. while ($row = mysql_fetch_assoc($result)) {
  206. $arrItems[] = stripslashes($row['NAME']);
  207. }
  208. }
  209. return $arrItems;
  210. }
  211. // ¬ывод каталогов в категории
  212. public function getShopCategories($id = '20')
  213. {
  214. $arrItems = array();
  215. $sql = "SELECT `ID`, `NAME`
  216. FROM `b_iblock_section`
  217. WHERE `IBLOCK_ID` = '".$id."'
  218. AND `IBLOCK_SECTION_ID` IS NULL
  219. AND `ACTIVE` = 'Y'
  220. ORDER BY `SORT`, `NAME`";
  221. $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
  222. if (mysql_num_rows($result) > 0) {
  223. while ($row = mysql_fetch_assoc($result)) {
  224. $arrItems[$row['ID']] = stripslashes($row['NAME']);
  225. }
  226. }
  227. return $arrItems;
  228. }
  229. // ¬ывод цены
  230. public function getShopGoodPriceById($id)
  231. {
  232. $id = (int) $id;
  233. $price = 0;
  234. $sql = "SELECT bcp.`PRICE`
  235. FROM `b_catalog_price` AS bcp
  236. WHERE bcp.`PRODUCT_ID` = '{$id}'
  237. AND bcp.`CATALOG_GROUP_ID` = '3'
  238. AND bcp.`EXTRA_ID` IS NULL
  239. LIMIT 1";
  240. $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
  241. if (mysql_num_rows($result) > 0) {
  242. $row = mysql_fetch_assoc($result);
  243. $price = (float) $row['PRICE'];
  244. }
  245. return $price;
  246. }
  247. // ¬ывод списка производителей
  248. public function getDevelopersById($id='20') {
  249. $id = (int) $id;
  250. $sql = "select bipe.ID, bipe.VALUE from b_iblock_property_enum as bipe
  251. where bipe.PROPERTY_ID = (select id from b_iblock_property where IBLOCK_ID = '".$id."' and CODE = 'developer')";
  252. $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
  253. if (mysql_num_rows($result) > 0) {
  254. while ($row = mysql_fetch_assoc($result)) {
  255. $id = (int) $row['ID'];
  256. $arrDevs[$id]['id'] = $id;
  257. $arrDevs[$id]['name'] = stripslashes($row['VALUE']);
  258. }
  259. }
  260. return $arrDevs;
  261. }
  262. public function getTradeinModels($develop,$id='20')
  263. {
  264. $develop = (int) $develop;
  265. $id = (int) $id;
  266. $arrItems = array();
  267. $sql = "select bie.ID ,bie.NAME from b_iblock_element as bie, b_iblock_element_property as biep
  268. WHERE biep.VALUE = '{$develop}'
  269. and bie.IBLOCK_ID = '{$id}'
  270. and bie.ID = biep.IBLOCK_ELEMENT_ID
  271. and bie.ACTIVE = 'Y'
  272. and bie.`WF_PARENT_ELEMENT_ID` IS NULL
  273. LIMIT 30";
  274. $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
  275. if (mysql_num_rows($result) > 0) {
  276. while ($row = mysql_fetch_assoc($result)) {
  277. $arrItems[$row['ID']] = stripslashes($row['NAME']);
  278. }
  279. } else {
  280. $arrItems['0'] = stripslashes('Ќет товаров');
  281. }
  282. return $arrItems;
  283. }
  284. }
  285. ?>