PageRenderTime 63ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/php/includes_bak/lib_insert.php

https://github.com/matthewxu/doc
PHP | 369 lines | 253 code | 48 blank | 68 comment | 28 complexity | 8e422ea838f98fd80553edabafb6ce93 MD5 | raw file
  1. <?php
  2. /**
  3. * ECSHOP 动态内容函数库
  4. * ============================================================================
  5. * 版权所有 2005-2010 上海商派网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.ecshop.com;
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * $Author: liuhui $
  12. * $Id: lib_insert.php 17063 2010-03-25 06:35:46Z liuhui $
  13. */
  14. if (!defined('IN_ECS'))
  15. {
  16. die('Hacking attempt');
  17. }
  18. /**
  19. * 获得查询次数以及查询时间
  20. *
  21. * @access public
  22. * @return string
  23. */
  24. function insert_query_info()
  25. {
  26. if ($GLOBALS['db']->queryTime == '')
  27. {
  28. $query_time = 0;
  29. }
  30. else
  31. {
  32. if (PHP_VERSION >= '5.0.0')
  33. {
  34. $query_time = number_format(microtime(true) - $GLOBALS['db']->queryTime, 6);
  35. }
  36. else
  37. {
  38. list($now_usec, $now_sec) = explode(' ', microtime());
  39. list($start_usec, $start_sec) = explode(' ', $GLOBALS['db']->queryTime);
  40. $query_time = number_format(($now_sec - $start_sec) + ($now_usec - $start_usec), 6);
  41. }
  42. }
  43. /* 内存占用情况 */
  44. if ($GLOBALS['_LANG']['memory_info'] && function_exists('memory_get_usage'))
  45. {
  46. $memory_usage = sprintf($GLOBALS['_LANG']['memory_info'], memory_get_usage() / 1048576);
  47. }
  48. else
  49. {
  50. $memory_usage = '';
  51. }
  52. /* 是否启用了 gzip */
  53. $gzip_enabled = gzip_enabled() ? $GLOBALS['_LANG']['gzip_enabled'] : $GLOBALS['_LANG']['gzip_disabled'];
  54. $online_count = $GLOBALS['db']->getOne("SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('sessions'));
  55. /* 加入触发cron代码 */
  56. $cron_method = empty($GLOBALS['_CFG']['cron_method']) ? '<img src="api/cron.php?t=' . gmtime() . '" alt="" style="width:0px;height:0px;" />' : '';
  57. return sprintf($GLOBALS['_LANG']['query_info'], $GLOBALS['db']->queryCount, $query_time, $online_count) . $gzip_enabled . $memory_usage . $cron_method;
  58. }
  59. /**
  60. * 调用浏览历史
  61. *
  62. * @access public
  63. * @return string
  64. */
  65. function insert_history()
  66. {
  67. $str = '';
  68. if (!empty($_COOKIE['ECS']['history']))
  69. {
  70. $where = db_create_in($_COOKIE['ECS']['history'], 'goods_id');
  71. $sql = 'SELECT goods_id, goods_name, goods_thumb, shop_price FROM ' . $GLOBALS['ecs']->table('goods') .
  72. " WHERE $where AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0";
  73. $query = $GLOBALS['db']->query($sql);
  74. $res = array();
  75. while ($row = $GLOBALS['db']->fetch_array($query))
  76. {
  77. $goods['goods_id'] = $row['goods_id'];
  78. $goods['goods_name'] = $row['goods_name'];
  79. $goods['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
  80. $goods['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
  81. $goods['shop_price'] = price_format($row['shop_price']);
  82. $goods['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
  83. $str.='<ul class="clearfix"><li class="goodsimg"><a href="'.$goods['url'].'" target="_blank"><img src="'.$goods['goods_thumb'].'" alt="'.$goods['goods_name'].'" class="B_blue" /></a></li><li><a href="'.$goods['url'].'" target="_blank" title="'.$goods['goods_name'].'">'.$goods['short_name'].'</a><br />'.$GLOBALS['_LANG']['shop_price'].'<font class="f1">'.$goods['shop_price'].'</font><br /></li></ul>';
  84. }
  85. $str .= '<ul id="clear_history"><a onclick="clear_history()">' . $GLOBALS['_LANG']['clear_history'] . '</a></ul>';
  86. }
  87. return $str;
  88. }
  89. /**
  90. * 调用购物车信息
  91. *
  92. * @access public
  93. * @return string
  94. */
  95. function insert_cart_info()
  96. {
  97. $sql = 'SELECT SUM(goods_number) AS number, SUM(goods_price * goods_number) AS amount' .
  98. ' FROM ' . $GLOBALS['ecs']->table('cart') .
  99. " WHERE session_id = '" . SESS_ID . "' AND rec_type = '" . CART_GENERAL_GOODS . "'";
  100. $row = $GLOBALS['db']->GetRow($sql);
  101. if ($row)
  102. {
  103. $number = intval($row['number']);
  104. $amount = floatval($row['amount']);
  105. }
  106. else
  107. {
  108. $number = 0;
  109. $amount = 0;
  110. }
  111. $str = sprintf($GLOBALS['_LANG']['cart_info'], $number, price_format($amount, false));
  112. return '<a href="flow.php" title="' . $GLOBALS['_LANG']['view_cart'] . '">' . $str . '</a>';
  113. }
  114. /**
  115. * 调用指定的广告位的广告
  116. *
  117. * @access public
  118. * @param integer $id 广告位ID
  119. * @param integer $num 广告数量
  120. * @return string
  121. */
  122. function insert_ads($arr)
  123. {
  124. static $static_res = NULL;
  125. $time = gmtime();
  126. if (!empty($arr['num']) && $arr['num'] != 1)
  127. {
  128. $sql = 'SELECT a.ad_id, a.position_id, a.media_type, a.ad_link, a.ad_code, a.ad_name, p.ad_width, ' .
  129. 'p.ad_height, p.position_style, RAND() AS rnd ' .
  130. 'FROM ' . $GLOBALS['ecs']->table('ad') . ' AS a '.
  131. 'LEFT JOIN ' . $GLOBALS['ecs']->table('ad_position') . ' AS p ON a.position_id = p.position_id ' .
  132. "WHERE enabled = 1 AND start_time <= '" . $time . "' AND end_time >= '" . $time . "' ".
  133. "AND a.position_id = '" . $arr['id'] . "' " .
  134. 'ORDER BY rnd LIMIT ' . $arr['num'];
  135. $res = $GLOBALS['db']->GetAll($sql);
  136. }
  137. else
  138. {
  139. if ($static_res[$arr['id']] === NULL)
  140. {
  141. $sql = 'SELECT a.ad_id, a.position_id, a.media_type, a.ad_link, a.ad_code, a.ad_name, p.ad_width, '.
  142. 'p.ad_height, p.position_style, RAND() AS rnd ' .
  143. 'FROM ' . $GLOBALS['ecs']->table('ad') . ' AS a '.
  144. 'LEFT JOIN ' . $GLOBALS['ecs']->table('ad_position') . ' AS p ON a.position_id = p.position_id ' .
  145. "WHERE enabled = 1 AND a.position_id = '" . $arr['id'] .
  146. "' AND start_time <= '" . $time . "' AND end_time >= '" . $time . "' " .
  147. 'ORDER BY rnd LIMIT 1';
  148. $static_res[$arr['id']] = $GLOBALS['db']->GetAll($sql);
  149. }
  150. $res = $static_res[$arr['id']];
  151. }
  152. $ads = array();
  153. $position_style = '';
  154. foreach ($res AS $row)
  155. {
  156. if ($row['position_id'] != $arr['id'])
  157. {
  158. continue;
  159. }
  160. $position_style = $row['position_style'];
  161. switch ($row['media_type'])
  162. {
  163. case 0: // 图片广告
  164. $src = (strpos($row['ad_code'], 'http://') === false && strpos($row['ad_code'], 'https://') === false) ?
  165. DATA_DIR . "/afficheimg/$row[ad_code]" : $row['ad_code'];
  166. $ads[] = "<a href='affiche.php?ad_id=$row[ad_id]&amp;uri=" .urlencode($row["ad_link"]). "'
  167. target='_blank'><img src='$src' width='" .$row['ad_width']. "' height='$row[ad_height]'
  168. border='0' /></a>";
  169. break;
  170. case 1: // Flash
  171. $src = (strpos($row['ad_code'], 'http://') === false && strpos($row['ad_code'], 'https://') === false) ?
  172. DATA_DIR . "/afficheimg/$row[ad_code]" : $row['ad_code'];
  173. $ads[] = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" " .
  174. "codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" " .
  175. "width='$row[ad_width]' height='$row[ad_height]'>
  176. <param name='movie' value='$src'>
  177. <param name='quality' value='high'>
  178. <embed src='$src' quality='high'
  179. pluginspage='http://www.macromedia.com/go/getflashplayer'
  180. type='application/x-shockwave-flash' width='$row[ad_width]'
  181. height='$row[ad_height]'></embed>
  182. </object>";
  183. break;
  184. case 2: // CODE
  185. $ads[] = $row['ad_code'];
  186. break;
  187. case 3: // TEXT
  188. $ads[] = "<a href='affiche.php?ad_id=$row[ad_id]&amp;uri=" .urlencode($row["ad_link"]). "'
  189. target='_blank'>" .htmlspecialchars($row['ad_code']). '</a>';
  190. break;
  191. }
  192. }
  193. $position_style = 'str:' . $position_style;
  194. $need_cache = $GLOBALS['smarty']->caching;
  195. $GLOBALS['smarty']->caching = false;
  196. $GLOBALS['smarty']->assign('ads', $ads);
  197. $val = $GLOBALS['smarty']->fetch($position_style);
  198. $GLOBALS['smarty']->caching = $need_cache;
  199. return $val;
  200. }
  201. /**
  202. * 调用会员信息
  203. *
  204. * @access public
  205. * @return string
  206. */
  207. function insert_member_info()
  208. {
  209. $need_cache = $GLOBALS['smarty']->caching;
  210. $GLOBALS['smarty']->caching = false;
  211. if ($_SESSION['user_id'] > 0)
  212. {
  213. $GLOBALS['smarty']->assign('user_info', get_user_info());
  214. }
  215. else
  216. {
  217. if (!empty($_COOKIE['ECS']['username']))
  218. {
  219. $GLOBALS['smarty']->assign('ecs_username', stripslashes($_COOKIE['ECS']['username']));
  220. }
  221. $captcha = intval($GLOBALS['_CFG']['captcha']);
  222. if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)
  223. {
  224. $GLOBALS['smarty']->assign('enabled_captcha', 1);
  225. $GLOBALS['smarty']->assign('rand', mt_rand());
  226. }
  227. }
  228. $output = $GLOBALS['smarty']->fetch('library/member_info.lbi');
  229. $GLOBALS['smarty']->caching = $need_cache;
  230. return $output;
  231. }
  232. /**
  233. * 调用评论信息
  234. *
  235. * @access public
  236. * @return string
  237. */
  238. function insert_comments($arr)
  239. {
  240. $need_cache = $GLOBALS['smarty']->caching;
  241. $need_compile = $GLOBALS['smarty']->force_compile;
  242. $GLOBALS['smarty']->caching = false;
  243. $GLOBALS['smarty']->force_compile = true;
  244. /* 验证码相关设置 */
  245. if ((intval($GLOBALS['_CFG']['captcha']) & CAPTCHA_COMMENT) && gd_version() > 0)
  246. {
  247. $GLOBALS['smarty']->assign('enabled_captcha', 1);
  248. $GLOBALS['smarty']->assign('rand', mt_rand());
  249. }
  250. $GLOBALS['smarty']->assign('username', stripslashes($_SESSION['user_name']));
  251. $GLOBALS['smarty']->assign('email', $_SESSION['email']);
  252. $GLOBALS['smarty']->assign('comment_type', $arr['type']);
  253. $GLOBALS['smarty']->assign('id', $arr['id']);
  254. $cmt = assign_comment($arr['id'], $arr['type']);
  255. $GLOBALS['smarty']->assign('comments', $cmt['comments']);
  256. $GLOBALS['smarty']->assign('pager', $cmt['pager']);
  257. $val = $GLOBALS['smarty']->fetch('library/comments_list.lbi');
  258. $GLOBALS['smarty']->caching = $need_cache;
  259. $GLOBALS['smarty']->force_compile = $need_compile;
  260. return $val;
  261. }
  262. /**
  263. * 调用商品购买记录
  264. *
  265. * @access public
  266. * @return string
  267. */
  268. function insert_bought_notes($arr)
  269. {
  270. $need_cache = $GLOBALS['smarty']->caching;
  271. $need_compile = $GLOBALS['smarty']->force_compile;
  272. $GLOBALS['smarty']->caching = false;
  273. $GLOBALS['smarty']->force_compile = true;
  274. /* 商品购买记录 */
  275. $sql = 'SELECT u.user_name, og.goods_number, oi.add_time, IF(oi.order_status IN (2, 3, 4), 0, 1) AS order_status ' .
  276. 'FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS oi LEFT JOIN ' . $GLOBALS['ecs']->table('users') . ' AS u ON oi.user_id = u.user_id, ' . $GLOBALS['ecs']->table('order_goods') . ' AS og ' .
  277. 'WHERE oi.order_id = og.order_id AND ' . time() . ' - oi.add_time < 2592000 AND og.goods_id = ' . $arr['id'] . ' ORDER BY oi.add_time DESC LIMIT 5';
  278. $bought_notes = $GLOBALS['db']->getAll($sql);
  279. foreach ($bought_notes as $key => $val)
  280. {
  281. $bought_notes[$key]['add_time'] = local_date("Y-m-d G:i:s", $val['add_time']);
  282. }
  283. $sql = 'SELECT count(*) ' .
  284. 'FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS oi LEFT JOIN ' . $GLOBALS['ecs']->table('users') . ' AS u ON oi.user_id = u.user_id, ' . $GLOBALS['ecs']->table('order_goods') . ' AS og ' .
  285. 'WHERE oi.order_id = og.order_id AND ' . time() . ' - oi.add_time < 2592000 AND og.goods_id = ' . $arr['id'];
  286. $count = $GLOBALS['db']->getOne($sql);
  287. /* 商品购买记录分页样式 */
  288. $pager = array();
  289. $pager['page'] = $page = 1;
  290. $pager['size'] = $size = 5;
  291. $pager['record_count'] = $count;
  292. $pager['page_count'] = $page_count = ($count > 0) ? intval(ceil($count / $size)) : 1;;
  293. $pager['page_first'] = "javascript:gotoBuyPage(1,$arr[id])";
  294. $pager['page_prev'] = $page > 1 ? "javascript:gotoBuyPage(" .($page-1). ",$arr[id])" : 'javascript:;';
  295. $pager['page_next'] = $page < $page_count ? 'javascript:gotoBuyPage(' .($page + 1) . ",$arr[id])" : 'javascript:;';
  296. $pager['page_last'] = $page < $page_count ? 'javascript:gotoBuyPage(' .$page_count. ",$arr[id])" : 'javascript:;';
  297. $GLOBALS['smarty']->assign('notes', $bought_notes);
  298. $GLOBALS['smarty']->assign('pager', $pager);
  299. $val= $GLOBALS['smarty']->fetch('library/bought_notes.lbi');
  300. $GLOBALS['smarty']->caching = $need_cache;
  301. $GLOBALS['smarty']->force_compile = $need_compile;
  302. return $val;
  303. }
  304. /**
  305. * 调用在线调查信息
  306. *
  307. * @access public
  308. * @return string
  309. */
  310. function insert_vote()
  311. {
  312. $vote = get_vote();
  313. if (!empty($vote))
  314. {
  315. $GLOBALS['smarty']->assign('vote_id', $vote['id']);
  316. $GLOBALS['smarty']->assign('vote', $vote['content']);
  317. }
  318. $val = $GLOBALS['smarty']->fetch('library/vote.lbi');
  319. return $val;
  320. }
  321. ?>