PageRenderTime 126ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/shops/functions.php

http://nukeviet-shop.googlecode.com/
PHP | 263 lines | 238 code | 11 blank | 14 comment | 41 complexity | e76183704b8fea500d64d34cfcfcfc69 MD5 | raw file
  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. $arr_cat_title = array();
  18. $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";
  19. $result = $db->sql_query( $sql );
  20. 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 ) )
  21. {
  22. $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 . "";
  23. $global_array_cat[$catid_i] = array(
  24. "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
  25. );
  26. if ( $alias_cat_url == $alias_i )
  27. {
  28. $catid = $catid_i;
  29. $parentid = $parentid_i;
  30. }
  31. }
  32. unset( $result, $alias_cat_url, $catid_i, $parentid_i, $title_i, $alias_i );
  33. /*group*/
  34. $global_array_group = array();
  35. $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";
  36. $result = $db->sql_query( $sql );
  37. 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 ) )
  38. {
  39. $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;
  40. $global_array_group[$groupid_i] = array(
  41. "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
  42. );
  43. }
  44. /*end group*/
  45. $page = 0;
  46. $per_page = $pro_config['per_page'];
  47. $count_op = count( $array_op );
  48. if ( ! empty( $array_op ) and $op == "main" )
  49. {
  50. if ( $catid == 0 )
  51. {
  52. $contents = $lang_module['nocatpage'] . $array_op[0];
  53. if ( ! empty( $array_op[1] ) )
  54. {
  55. if ( substr( $array_op[1], 0, 5 ) == "page-" )
  56. {
  57. $page = intval( substr( $array_op[1], 5 ) );
  58. }
  59. }
  60. }
  61. else
  62. {
  63. $op = "main";
  64. if ( $count_op == 1 or substr( $array_op[1], 0, 5 ) == "page-" )
  65. {
  66. $op = "viewcat";
  67. if ( $count_op > 1 )
  68. {
  69. //$set_viewcat = "viewcat_page_new";
  70. $page = intval( substr( $array_op[1], 5 ) );
  71. }
  72. }
  73. elseif ( $count_op == 2 )
  74. {
  75. $array_page = explode( "-", $array_op[1] );
  76. $id = intval( end( $array_page ) );
  77. $number = strlen( $id ) + 1;
  78. $alias_url = substr( $array_op[1], 0, - $number );
  79. if ( $id > 0 and $alias_url != "" )
  80. {
  81. $op = "detail";
  82. }
  83. }
  84. $parentid = $catid;
  85. while ( $parentid > 0 )
  86. {
  87. $array_cat_i = $global_array_cat[$parentid];
  88. $array_mod_title[] = array(
  89. 'catid' => $parentid, 'title' => $array_cat_i['title'], 'link' => $array_cat_i['link']
  90. );
  91. $parentid = $array_cat_i['parentid'];
  92. }
  93. sort( $array_mod_title, SORT_NUMERIC );
  94. }
  95. }
  96. function GetCatidInParent ( $catid )
  97. {
  98. global $global_array_cat, $array_cat;
  99. $array_cat[] = $catid;
  100. $subcatid = explode( ",", $global_array_cat[$catid]['subcatid'] );
  101. if ( ! empty( $subcatid ) )
  102. {
  103. foreach ( $subcatid as $id )
  104. {
  105. if ( $id > 0 )
  106. {
  107. if ( $global_array_cat[$id]['numsubcat'] == 0 )
  108. {
  109. $array_cat[] = $id;
  110. }
  111. else
  112. {
  113. $array_cat_temp = GetCatidInParent( $id );
  114. foreach ( $array_cat_temp as $catid_i )
  115. {
  116. $array_cat[] = $catid_i;
  117. }
  118. }
  119. }
  120. }
  121. }
  122. return array_unique( $array_cat );
  123. }
  124. function GetDataIn ( $result, $catid )
  125. {
  126. global $global_array_cat, $module_name, $db, $link, $module_info;
  127. $data_content = array();
  128. $data = array();
  129. while ( list( $id, $listcatid, $publtime, $title, $alias, $hometext, $address, $homeimgalt, $homeimgthumb, $product_price, $product_discounts, $money_unit,$showprice ) = $db->sql_fetchrow( $result ) )
  130. {
  131. $thumb = explode( "|", $homeimgthumb );
  132. if ( ! empty( $thumb[0] ) && ! nv_is_url( $thumb[0] ) )
  133. {
  134. $thumb[0] = NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name . "/" . $thumb[0];
  135. }
  136. else
  137. {
  138. $thumb[0] = NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_name . "/no-image.jpg";
  139. }
  140. $data[] = array(
  141. "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
  142. );
  143. }
  144. $data_content['id'] = $catid;
  145. $data_content['title'] = $global_array_cat[$catid]['title'];
  146. $data_content['data'] = $data;
  147. $data_content['alias'] = $global_array_cat[$catid]['alias'];
  148. return $data_content;
  149. }
  150. function GetDataInGroup ( $result, $groupid )
  151. {
  152. global $global_array_group, $module_name, $db, $link, $module_info,$global_array_cat;
  153. $data_content = array();
  154. $data = array();
  155. while ( list( $id, $listcatid, $publtime, $title, $alias, $hometext, $address, $homeimgalt, $homeimgthumb, $product_price, $product_discounts, $money_unit,$showprice ) = $db->sql_fetchrow( $result ) )
  156. {
  157. $thumb = explode( "|", $homeimgthumb );
  158. if ( ! empty( $thumb[0] ) && ! nv_is_url( $thumb[0] ) )
  159. {
  160. $thumb[0] = NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name . "/" . $thumb[0];
  161. }
  162. else
  163. {
  164. $thumb[0] = NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_name . "/no-image.jpg";
  165. }
  166. $data[] = array(
  167. "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
  168. );
  169. }
  170. $data_content['id'] = $groupid;
  171. $data_content['title'] = $global_array_group[$groupid]['title'];
  172. $data_content['data'] = $data;
  173. $data_content['alias'] = $global_array_group[$groupid]['alias'];
  174. return $data_content;
  175. }
  176. function FormatNumber ( $number, $decimals = 0, $thousand_separator = '&nbsp;', $decimal_point = '.' )
  177. {
  178. $str = number_format( $number, 0, ',', '.' );
  179. return $str;
  180. }
  181. //eg : echo CurrencyConversion ( 100000, 'USD', 'VND' );
  182. /*return string money eg: 100 000 000*/
  183. function CurrencyConversion ( $price, $currency_curent, $currency_convert )
  184. {
  185. global $money_config, $pro_config; //die($price." ");
  186. $str = number_format( $price, 0, '.', ' ' );
  187. if ( ! empty( $money_config ) )
  188. {
  189. if ( $currency_curent == $pro_config['money_unit'] )
  190. {
  191. $value = doubleval( $money_config[$currency_convert]['exchange'] );
  192. $price = doubleval( $price * $value );
  193. $str = number_format( $price, 0, '.', ' ' );
  194. $ss = "~";
  195. }
  196. elseif ( $currency_convert == $pro_config['money_unit'] )
  197. {
  198. $value = doubleval( $money_config[$currency_curent]['exchange'] );
  199. $price = doubleval( $price / $value );
  200. $str = number_format( $price, 0, '.', ' ' );
  201. }
  202. }
  203. $ss = ( $currency_curent == $currency_convert ) ? "" : "~";
  204. return $ss . $str;
  205. }
  206. //eg : echo CurrencyConversion ( 100000, 'USD', 'VND' );
  207. /*return double money eg: 100000000 */
  208. function CurrencyConversionToNumber ( $price, $currency_curent, $currency_convert )
  209. {
  210. global $money_config, $pro_config;
  211. if ( ! empty( $money_config ) )
  212. {
  213. if ( $currency_curent == $pro_config['money_unit'] )
  214. {
  215. $value = doubleval( $money_config[$currency_convert]['exchange'] );
  216. $price = doubleval( $price * $value );
  217. }
  218. elseif ( $currency_convert == $pro_config['money_unit'] )
  219. {
  220. $value = doubleval( $money_config[$currency_curent]['exchange'] );
  221. $price = doubleval( $price / $value );
  222. }
  223. }
  224. return $price;
  225. }
  226. /*set view old product*/
  227. function SetSessionProView ( $id, $title, $alias, $addtime, $link,$homeimgthumb )
  228. {
  229. global $module_data;
  230. if ( ! isset( $_SESSION[$module_data . '_proview'] ) ) $_SESSION[$module_data . '_proview'] = array();
  231. if ( ! isset( $_SESSION[$module_data . '_proview'][$id] ) )
  232. {
  233. $_SESSION[$module_data . '_proview'][$id] = array(
  234. 'title' => $title, 'alias' => $alias, 'addtime' => $addtime, 'link' => $link, 'homeimgthumb' => $homeimgthumb
  235. );
  236. }
  237. }
  238. function redict_link ( $lang_view, $lang_back, $nv_redirect )
  239. {
  240. global $lang_module;
  241. $contents = "<div class=\"frame\">";
  242. $contents .= $lang_view . "<br /><br />\n";
  243. $contents .= "<img border=\"0\" src=\"" . NV_BASE_SITEURL . "images/load_bar.gif\"><br /><br />\n";
  244. $contents .= "<a href=\"" . $nv_redirect . "\">" . $lang_back . "</a>";
  245. $contents .= "</div>";
  246. $contents .= "<meta http-equiv=\"refresh\" content=\"2;url=" . $nv_redirect . "\" />";
  247. include ( NV_ROOTDIR . "/includes/header.php" );
  248. echo nv_site_theme( $contents );
  249. include ( NV_ROOTDIR . "/includes/footer.php" );
  250. exit();
  251. }
  252. ?>