PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/compare/compare_notikClass.php

https://bitbucket.org/spivovartsev/citrus.ua
PHP | 267 lines | 236 code | 22 blank | 9 comment | 23 complexity | cc6ec489bfe43e403152e3550b0de71d 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=620)
  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. $sql = "SELECT bie.`ID`,bie.`IBLOCK_ID`, bie.`NAME`,bie.`DETAIL_TEXT`,
  74. bi.`DETAIL_PAGE_URL`, bie.`IBLOCK_SECTION_ID`,
  75. bf1.`SUBDIR` AS PREVIEW_PICTURE_SUBDIR, bf1.`FILE_NAME` AS PREVIEW_PICTURE_NAME,
  76. bf2.`SUBDIR` AS DETAIL_PICTURE_SUBDIR, bf2.`FILE_NAME` AS DETAIL_PICTURE_NAME,
  77. bcp2.`PRICE` AS PRICE_OFFLINE, bcp2.`CURRENCY` AS CURRENCY_OFFLINE,
  78. bcpr.`QUANTITY`, bcpr.`QUANTITY_TRACE`,
  79. bcp.`PRICE`
  80. FROM `b_iblock_element` AS bie
  81. JOIN `b_iblock` AS bi ON bi.`ID` = bie.`IBLOCK_ID`
  82. AND bi.`ACTIVE` = 'Y'
  83. LEFt JOIN `b_file` AS bf1 ON bf1.`ID` = bie.`PREVIEW_PICTURE`
  84. LEFt JOIN `b_file` AS bf2 ON bf2.`ID` = bie.`DETAIL_PICTURE`
  85. JOIN `b_catalog_price` AS bcp ON bcp.`PRODUCT_ID` = bie.`ID`
  86. AND bcp.`CATALOG_GROUP_ID` = '3'
  87. AND bcp.`EXTRA_ID` IS NULL
  88. LEFT JOIN `b_catalog_price` AS bcp2 ON bcp2.`PRODUCT_ID` = bie.`ID`
  89. AND bcp2.`CATALOG_GROUP_ID` = '4'
  90. JOIN `b_catalog_product` AS bcpr ON bcpr.`ID` = bie.`ID`
  91. WHERE bie.NAME LIKE '%".$search."%'
  92. AND bie.`ACTIVE` = 'Y'
  93. AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
  94. ORDER BY bie.`NAME`";
  95. $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
  96. if (mysql_num_rows($result) > 0) {
  97. $row = mysql_fetch_assoc($result);
  98. $id = (int) $row['ID'];
  99. $arrResult['id'] = $id;
  100. $url = str_replace('#SITE_DIR#', '', $row['DETAIL_PAGE_URL']);
  101. $url = str_replace('#SECTION_ID#', $row['IBLOCK_SECTION_ID'], $url);
  102. $url = str_replace('#ID#', $id, $url);
  103. $arrResult['url'] = $url;
  104. $arrResult['buy_url'] = $url . '?action=BUY&id=' . $id;
  105. $arrResult['name'] = stripslashes($row['NAME']);
  106. $arrResult['text'] = stripslashes($row['DETAIL_TEXT']);
  107. $arrResult['price'] = (float) $row['PRICE'];
  108. $arrResult['price_offline'] = (float) $row['PRICE_OFFLINE'];
  109. $arrResult['quantity'] = (int) $row['QUANTITY'];
  110. $arrResult['quantity_trace'] = $row['QUANTITY_TRACE'];
  111. $sql2 = "SELECT bipe.VALUE FROM b_iblock_element AS bie,
  112. b_iblock_property AS bip,b_iblock_property_enum AS bipe,
  113. b_iblock_element_property AS biep
  114. Where bip.IBLOCK_ID = '".$row['IBLOCK_ID']."'
  115. AND bip.CODE = 'LENDING'
  116. AND bipe.PROPERTY_ID = bip.ID
  117. AND biep.IBLOCK_PROPERTY_ID = bip.ID
  118. AND biep.IBLOCK_ELEMENT_ID = '".$id."'
  119. AND biep.VALUE = bipe.ID LIMIT 1";
  120. $result2 = mysql_query($sql2, $this->_dbLink) or die(mysql_error());
  121. if (mysql_num_rows($result2) > 0) {
  122. $row2 = mysql_fetch_assoc($result2);
  123. $arrResult['lending'] = $row2['VALUE'];
  124. } else { $arrResult['lending'] = 'нет';}
  125. $sql3 = "SELECT biep.VALUE FROM b_iblock_element_property AS biep
  126. WHERE biep.IBLOCK_PROPERTY_ID = (select ID FROM b_iblock_property WHERE IBLOCK_ID = '".$row['IBLOCK_ID']."' AND CODE = 'MORE_PHOTO')
  127. AND biep.IBLOCK_ELEMENT_ID = '".$id."'";
  128. $result3 = mysql_query($sql3, $this->_dbLink) or die(mysql_error());
  129. if (mysql_num_rows($result3) > 0) {
  130. while ($row3 = mysql_fetch_assoc($result3)) {
  131. $arrResult['img'][] = $row3['VALUE'];
  132. } }
  133. if (strlen($row['PREVIEW_PICTURE_NAME']) > 0) {
  134. $arrResult['pic'] = '/upload/' . $row['PREVIEW_PICTURE_SUBDIR'] . '/' . $row['PREVIEW_PICTURE_NAME'];
  135. } else {
  136. $arrResult['pic'] = '/upload/' . $row['DETAIL_PICTURE_SUBDIR'] . '/' . $row['DETAIL_PICTURE_NAME'];
  137. }
  138. }
  139. return $arrResult;
  140. }
  141. // ћен€ем символы
  142. protected function _convertCyrToLat($string)
  143. {
  144. $string = strtr($string, "йцукенгшщзхъфывапролджэ€чсмитьбю", "qwertyuiop[]asdfghjkl;'zxcvbnm,.");
  145. $string = strtr($string, "…÷” ≈Ќ√Ўў«’Џ‘џ¬јѕ–ќЋƒ∆Ёя„—ћ»“№Ѕё", "QWERTYUIOP[]ASDFGHJKL;'ZXCVBNM,.");
  146. return $string;
  147. }
  148. // вывод моделей в список по шаблону %LIKE%
  149. public function searchTradeinModelName($search,$develop,$id)
  150. {
  151. $arrItems = array();
  152. $search = iconv('utf-8', 'cp1251', $search);
  153. $search = $this->_convertCyrToLat($search);
  154. $search = mysql_real_escape_string($search);
  155. $sql = "select bie.NAME from b_iblock_element as bie, b_iblock_element_property as biep
  156. WHERE bie.NAME LIKE '%{$search}%'
  157. AND biep.VALUE = '{$develop}'
  158. and bie.IBLOCK_ID = '{$id}'
  159. and bie.ID = biep.IBLOCK_ELEMENT_ID
  160. and bie.ACTIVE = 'Y'
  161. and bie.`WF_PARENT_ELEMENT_ID` IS NULL
  162. LIMIT 30";
  163. $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
  164. if (mysql_num_rows($result) > 0) {
  165. while ($row = mysql_fetch_assoc($result)) {
  166. $arrItems[] = stripslashes($row['NAME']);
  167. }
  168. }
  169. return $arrItems;
  170. }
  171. // ¬ывод каталогов в категории
  172. public function getShopCategories($id = '20')
  173. {
  174. $arrItems = array();
  175. $sql = "SELECT `ID`, `NAME`
  176. FROM `b_iblock_section`
  177. WHERE `IBLOCK_ID` = '".$id."'
  178. AND `IBLOCK_SECTION_ID` IS NULL
  179. AND `ACTIVE` = 'Y'
  180. ORDER BY `SORT`, `NAME`";
  181. $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
  182. if (mysql_num_rows($result) > 0) {
  183. while ($row = mysql_fetch_assoc($result)) {
  184. $arrItems[$row['ID']] = stripslashes($row['NAME']);
  185. }
  186. }
  187. return $arrItems;
  188. }
  189. // ¬ывод цены
  190. public function getShopGoodPriceById($id)
  191. {
  192. $id = (int) $id;
  193. $price = 0;
  194. $sql = "SELECT bcp.`PRICE`
  195. FROM `b_catalog_price` AS bcp
  196. WHERE bcp.`PRODUCT_ID` = '{$id}'
  197. AND bcp.`CATALOG_GROUP_ID` = '3'
  198. AND bcp.`EXTRA_ID` IS NULL
  199. LIMIT 1";
  200. $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
  201. if (mysql_num_rows($result) > 0) {
  202. $row = mysql_fetch_assoc($result);
  203. $price = (float) $row['PRICE'];
  204. }
  205. return $price;
  206. }
  207. // ¬ывод списка производителей
  208. public function getDevelopersById($id='20') {
  209. $id = (int) $id;
  210. $sql = "select bipe.ID, bipe.VALUE from b_iblock_property_enum as bipe
  211. where bipe.PROPERTY_ID = (select id from b_iblock_property where IBLOCK_ID = '".$id."' and CODE = 'developer')";
  212. $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
  213. if (mysql_num_rows($result) > 0) {
  214. while ($row = mysql_fetch_assoc($result)) {
  215. $id = (int) $row['ID'];
  216. $arrDevs[$id]['id'] = $id;
  217. $arrDevs[$id]['name'] = stripslashes($row['VALUE']);
  218. }
  219. }
  220. return $arrDevs;
  221. }
  222. public function getTradeinModels($develop,$id='20')
  223. {
  224. $develop = (int) $develop;
  225. $id = (int) $id;
  226. $arrItems = array();
  227. $sql = "select bie.ID ,bie.NAME from b_iblock_element as bie, b_iblock_element_property as biep
  228. WHERE biep.VALUE = '{$develop}'
  229. and bie.IBLOCK_ID = '{$id}'
  230. and bie.ID = biep.IBLOCK_ELEMENT_ID
  231. and bie.ACTIVE = 'Y'
  232. and bie.`WF_PARENT_ELEMENT_ID` IS NULL
  233. LIMIT 30";
  234. $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
  235. if (mysql_num_rows($result) > 0) {
  236. while ($row = mysql_fetch_assoc($result)) {
  237. $arrItems[$row['ID']] = stripslashes($row['NAME']);
  238. }
  239. } else {
  240. $arrItems['0'] = stripslashes('Ќет товаров');
  241. }
  242. return $arrItems;
  243. }
  244. }
  245. ?>