PageRenderTime 47ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/NukeViet3.2/modules/shops/functions.php

http://nuke-viet.googlecode.com/
PHP | 280 lines | 252 code | 12 blank | 16 comment | 43 complexity | 8e718e265626ae0a90b796da5436d001 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.0
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @copyright 2009
  6. * @createdate 12/31/2009 0:51
  7. */
  8. if ( ! defined( 'NV_SYSTEM' ) ) die( 'Stop!!!' );
  9. define( 'NV_IS_MOD_SHOPS', true );
  10. require_once ( NV_ROOTDIR . "/modules/" . $module_file . "/global.functions.php" );
  11. global $global_array_cat,$global_array_group;
  12. $global_array_cat = array();
  13. $catid = 0;
  14. $parentid = 0;
  15. $set_viewcat = "";
  16. $alias_cat_url = isset( $array_op[0] ) ? $array_op[0] : "";
  17. //Xac dinh RSS
  18. if ($module_info['rss'])
  19. {
  20. $rss[] = array(//
  21. 'title' => $module_info['custom_title'], //
  22. 'src' => NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=rss"//
  23. );
  24. }
  25. $arr_cat_title = array();
  26. $sql = "SELECT catid, parentid, lev," . NV_LANG_DATA . "_title, " . NV_LANG_DATA . "_alias, viewcat, numsubcat, subcatid, numlinks, del_cache_time, " . NV_LANG_DATA . "_description, inhome, " . NV_LANG_DATA . "_keywords, who_view, groups_view FROM `" . $db_config['prefix'] . "_" . $module_data . "_catalogs` ORDER BY `order` ASC";
  27. $result = $db->sql_query( $sql );
  28. while ( list( $catid_i, $parentid_i, $lev_i, $title_i, $alias_i, $viewcat_i, $numsubcat_i, $subcatid_i, $numlinks_i, $del_cache_time_i, $description_i, $inhome_i, $keywords_i, $who_view_i, $groups_view_i ) = $db->sql_fetchrow( $result ) )
  29. {
  30. $link_i = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $alias_i . "";
  31. $global_array_cat[$catid_i] = array(
  32. "catid" => $catid_i, "parentid" => $parentid_i, "title" => $title_i, "alias" => $alias_i, "link" => $link_i, "viewcat" => $viewcat_i, "numsubcat" => $numsubcat_i, "subcatid" => $subcatid_i, "numlinks" => $numlinks_i, "description" => $description_i, "inhome" => $inhome_i, "keywords" => $keywords_i, "who_view" => $who_view_i, "groups_view" => $groups_view_i, 'lev' => $lev_i
  33. );
  34. if ( $alias_cat_url == $alias_i )
  35. {
  36. $catid = $catid_i;
  37. $parentid = $parentid_i;
  38. }
  39. //Xac dinh RSS
  40. if ( $module_info['rss'])
  41. {
  42. $rss[] = array( //
  43. 'title' => $module_info['custom_title'] . ' - ' . $title_i, //
  44. 'src' => NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=rss/" . $alias_i//
  45. );
  46. }
  47. }
  48. unset( $result, $alias_cat_url, $catid_i, $parentid_i, $title_i, $alias_i );
  49. /*group*/
  50. $global_array_group = array();
  51. $sql = "SELECT groupid, parentid, lev," . NV_LANG_DATA . "_title, " . NV_LANG_DATA . "_alias, viewgroup, numsubgroup, subgroupid, numlinks, del_cache_time, " . NV_LANG_DATA . "_description, inhome, " . NV_LANG_DATA . "_keywords, who_view, groups_view FROM `" . $db_config['prefix'] . "_" . $module_data . "_group` ORDER BY `order` ASC";
  52. $result = $db->sql_query( $sql );
  53. while ( list( $groupid_i, $parentid_i, $lev_i, $title_i, $alias_i, $viewgroup_i, $numsubgroup_i, $subgroupid_i, $numlinks_i, $del_cache_time_i, $description_i, $inhome_i, $keywords_i, $who_view_i, $groups_view_i ) = $db->sql_fetchrow( $result ) )
  54. {
  55. $link_i = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=group/" . $alias_i . "-" . $groupid_i;
  56. $global_array_group[$groupid_i] = array(
  57. "group" => $groupid_i, "parentid" => $parentid_i, "title" => $title_i, "alias" => $alias_i, "link" => $link_i, "viewgroup" => $viewgroup_i, "numsubgroup" => $numsubgroup_i, "subgroupid" => $subgroupid_i, "numlinks" => $numlinks_i, "description" => $description_i, "inhome" => $inhome_i, "keywords" => $keywords_i, "who_view" => $who_view_i, "groups_view" => $groups_view_i, 'lev' => $lev_i
  58. );
  59. }
  60. /*end group*/
  61. $page = 0;
  62. $per_page = $pro_config['per_page'];
  63. $count_op = count( $array_op );
  64. if ( ! empty( $array_op ) and $op == "main" )
  65. {
  66. if ( $catid == 0 )
  67. {
  68. $contents = $lang_module['nocatpage'] . $array_op[0];
  69. if ( ! empty( $array_op[1] ) )
  70. {
  71. if ( substr( $array_op[1], 0, 5 ) == "page-" )
  72. {
  73. $page = intval( substr( $array_op[1], 5 ) );
  74. }
  75. }
  76. }
  77. else
  78. {
  79. $op = "main";
  80. if ( $count_op == 1 or substr( $array_op[1], 0, 5 ) == "page-" )
  81. {
  82. $op = "viewcat";
  83. if ( $count_op > 1 )
  84. {
  85. //$set_viewcat = "viewcat_page_new";
  86. $page = intval( substr( $array_op[1], 5 ) );
  87. }
  88. }
  89. elseif ( $count_op == 2 )
  90. {
  91. $array_page = explode( "-", $array_op[1] );
  92. $id = intval( end( $array_page ) );
  93. $number = strlen( $id ) + 1;
  94. $alias_url = substr( $array_op[1], 0, - $number );
  95. if ( $id > 0 and $alias_url != "" )
  96. {
  97. $op = "detail";
  98. }
  99. }
  100. $parentid = $catid;
  101. while ( $parentid > 0 )
  102. {
  103. $array_cat_i = $global_array_cat[$parentid];
  104. $array_mod_title[] = array(
  105. 'catid' => $parentid, 'title' => $array_cat_i['title'], 'link' => $array_cat_i['link']
  106. );
  107. $parentid = $array_cat_i['parentid'];
  108. }
  109. sort( $array_mod_title, SORT_NUMERIC );
  110. }
  111. }
  112. function GetCatidInParent ( $catid )
  113. {
  114. global $global_array_cat, $array_cat;
  115. $array_cat[] = $catid;
  116. $subcatid = explode( ",", $global_array_cat[$catid]['subcatid'] );
  117. if ( ! empty( $subcatid ) )
  118. {
  119. foreach ( $subcatid as $id )
  120. {
  121. if ( $id > 0 )
  122. {
  123. if ( $global_array_cat[$id]['numsubcat'] == 0 )
  124. {
  125. $array_cat[] = $id;
  126. }
  127. else
  128. {
  129. $array_cat_temp = GetCatidInParent( $id );
  130. foreach ( $array_cat_temp as $catid_i )
  131. {
  132. $array_cat[] = $catid_i;
  133. }
  134. }
  135. }
  136. }
  137. }
  138. return array_unique( $array_cat );
  139. }
  140. function GetDataIn ( $result, $catid )
  141. {
  142. global $global_array_cat, $module_name, $db, $link, $module_info;
  143. $data_content = array();
  144. $data = array();
  145. while ( list( $id, $listcatid, $publtime, $title, $alias, $hometext, $address, $homeimgalt, $homeimgthumb, $product_price, $product_discounts, $money_unit,$showprice ) = $db->sql_fetchrow( $result ) )
  146. {
  147. $thumb = explode( "|", $homeimgthumb );
  148. if ( ! empty( $thumb[0] ) && ! nv_is_url( $thumb[0] ) )
  149. {
  150. $thumb[0] = NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name . "/" . $thumb[0];
  151. }
  152. else
  153. {
  154. $thumb[0] = NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_name . "/no-image.jpg";
  155. }
  156. $data[] = array(
  157. "id" => $id, "publtime" => $publtime, "title" => $title, "alias" => $alias, "hometext" => $hometext, "address" => $address, "homeimgalt" => $homeimgalt, "homeimgthumb" => $thumb[0], "product_price" => $product_price, "product_discounts" => $product_discounts, "money_unit" => $money_unit,"showprice" => $showprice, "link_pro" => $link . $global_array_cat[$listcatid]['alias'] . "/" . $alias . "-" . $id, "link_order" => $link . "setcart&amp;id=" . $id
  158. );
  159. }
  160. $data_content['id'] = $catid;
  161. $data_content['title'] = $global_array_cat[$catid]['title'];
  162. $data_content['data'] = $data;
  163. $data_content['alias'] = $global_array_cat[$catid]['alias'];
  164. return $data_content;
  165. }
  166. function GetDataInGroup ( $result, $groupid )
  167. {
  168. global $global_array_group, $module_name, $db, $link, $module_info,$global_array_cat;
  169. $data_content = array();
  170. $data = array();
  171. while ( list( $id, $listcatid, $publtime, $title, $alias, $hometext, $address, $homeimgalt, $homeimgthumb, $product_price, $product_discounts, $money_unit,$showprice ) = $db->sql_fetchrow( $result ) )
  172. {
  173. $thumb = explode( "|", $homeimgthumb );
  174. if ( ! empty( $thumb[0] ) && ! nv_is_url( $thumb[0] ) )
  175. {
  176. $thumb[0] = NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name . "/" . $thumb[0];
  177. }
  178. else
  179. {
  180. $thumb[0] = NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_name . "/no-image.jpg";
  181. }
  182. $data[] = array(
  183. "id" => $id, "publtime" => $publtime, "title" => $title, "alias" => $alias, "hometext" => $hometext, "address" => $address, "homeimgalt" => $homeimgalt, "homeimgthumb" => $thumb[0], "product_price" => $product_price, "product_discounts" => $product_discounts, "money_unit" => $money_unit,"showprice" => $showprice, "link_pro" => $link . $global_array_cat[$listcatid]['alias'] . "/" . $alias . "-" . $id, "link_order" => $link . "setcart&amp;id=" . $id
  184. );
  185. }
  186. $data_content['id'] = $groupid;
  187. $data_content['title'] = $global_array_group[$groupid]['title'];
  188. $data_content['data'] = $data;
  189. $data_content['alias'] = $global_array_group[$groupid]['alias'];
  190. return $data_content;
  191. }
  192. function FormatNumber ( $number, $decimals = 0, $thousand_separator = '&nbsp;', $decimal_point = '.' )
  193. {
  194. $str = number_format( $number, 0, ',', '.' );
  195. return $str;
  196. }
  197. //eg : echo CurrencyConversion ( 100000, 'USD', 'VND' );
  198. /*return string money eg: 100 000 000*/
  199. function CurrencyConversion ( $price, $currency_curent, $currency_convert )
  200. {
  201. global $money_config, $pro_config; //die($price." ");
  202. $str = number_format( $price, 0, '.', ' ' );
  203. if ( ! empty( $money_config ) )
  204. {
  205. if ( $currency_curent == $pro_config['money_unit'] )
  206. {
  207. $value = doubleval( $money_config[$currency_convert]['exchange'] );
  208. $price = doubleval( $price * $value );
  209. $str = number_format( $price, 0, '.', ' ' );
  210. $ss = "~";
  211. }
  212. elseif ( $currency_convert == $pro_config['money_unit'] )
  213. {
  214. $value = doubleval( $money_config[$currency_curent]['exchange'] );
  215. $price = doubleval( $price / $value );
  216. $str = number_format( $price, 0, '.', ' ' );
  217. }
  218. }
  219. $ss = ( $currency_curent == $currency_convert ) ? "" : "~";
  220. return $ss . $str;
  221. }
  222. //eg : echo CurrencyConversion ( 100000, 'USD', 'VND' );
  223. /*return double money eg: 100000000 */
  224. function CurrencyConversionToNumber ( $price, $currency_curent, $currency_convert )
  225. {
  226. global $money_config, $pro_config;
  227. if ( ! empty( $money_config ) )
  228. {
  229. if ( $currency_curent == $pro_config['money_unit'] )
  230. {
  231. $value = doubleval( $money_config[$currency_convert]['exchange'] );
  232. $price = doubleval( $price * $value );
  233. }
  234. elseif ( $currency_convert == $pro_config['money_unit'] )
  235. {
  236. $value = doubleval( $money_config[$currency_curent]['exchange'] );
  237. $price = doubleval( $price / $value );
  238. }
  239. }
  240. return $price;
  241. }
  242. /*set view old product*/
  243. function SetSessionProView ( $id, $title, $alias, $addtime, $link,$homeimgthumb )
  244. {
  245. global $module_data;
  246. if ( ! isset( $_SESSION[$module_data . '_proview'] ) ) $_SESSION[$module_data . '_proview'] = array();
  247. if ( ! isset( $_SESSION[$module_data . '_proview'][$id] ) )
  248. {
  249. $_SESSION[$module_data . '_proview'][$id] = array(
  250. 'title' => $title, 'alias' => $alias, 'addtime' => $addtime, 'link' => $link, 'homeimgthumb' => $homeimgthumb
  251. );
  252. }
  253. }
  254. function redict_link ( $lang_view, $lang_back, $nv_redirect )
  255. {
  256. global $lang_module;
  257. $contents = "<div class=\"frame\">";
  258. $contents .= $lang_view . "<br /><br />\n";
  259. $contents .= "<img border=\"0\" src=\"" . NV_BASE_SITEURL . "images/load_bar.gif\"><br /><br />\n";
  260. $contents .= "<a href=\"" . $nv_redirect . "\">" . $lang_back . "</a>";
  261. $contents .= "</div>";
  262. $contents .= "<meta http-equiv=\"refresh\" content=\"2;url=" . $nv_redirect . "\" />";
  263. include ( NV_ROOTDIR . "/includes/header.php" );
  264. echo nv_site_theme( $contents );
  265. include ( NV_ROOTDIR . "/includes/footer.php" );
  266. exit();
  267. }
  268. ?>