PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/upload/admin/vote.php

https://gitlab.com/BGCX261/zishashop-svn-to-git
PHP | 399 lines | 252 code | 72 blank | 75 comment | 30 complexity | 4a3c5971af67163e6956f4fc0b95fed7 MD5 | raw file
  1. <?php
  2. /**
  3. * ECSHOP 调查管理程序
  4. * ============================================================================
  5. * 版权所有 2005-2008 上海商派网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.ecshop.com;
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * $Author: testyang $
  12. * $Id: vote.php 15013 2008-10-23 09:31:42Z testyang $
  13. */
  14. define('IN_ECS', true);
  15. require(dirname(__FILE__) . '/includes/init.php');
  16. /* act操作项的初始化 */
  17. if (empty($_REQUEST['act']))
  18. {
  19. $_REQUEST['act'] = 'list';
  20. }
  21. else
  22. {
  23. $_REQUEST['act'] = trim($_REQUEST['act']);
  24. }
  25. $exc = new exchange($ecs->table("vote"), $db, 'vote_id', 'vote_name');
  26. $exc_opn = new exchange($ecs->table("vote_option"), $db, 'option_id', 'option_name');
  27. /*------------------------------------------------------ */
  28. //-- 投票列表页面
  29. /*------------------------------------------------------ */
  30. if ($_REQUEST['act'] == 'list')
  31. {
  32. /* 模板赋值 */
  33. $smarty->assign('ur_here', $_LANG['list_vote']);
  34. $smarty->assign('action_link', array('text' => $_LANG['add_vote'], 'href'=>'vote.php?act=add'));
  35. $smarty->assign('full_page', 1);
  36. $vote_list = get_votelist();
  37. $smarty->assign('list', $vote_list['list']);
  38. $smarty->assign('filter', $vote_list['filter']);
  39. $smarty->assign('record_count', $vote_list['record_count']);
  40. $smarty->assign('page_count', $vote_list['page_count']);
  41. /* 显示页面 */
  42. assign_query_info();
  43. $smarty->display('vote_list.htm');
  44. }
  45. /*------------------------------------------------------ */
  46. //-- 排序、分页、查询
  47. /*------------------------------------------------------ */
  48. elseif ($_REQUEST['act'] == 'query')
  49. {
  50. $vote_list = get_votelist();
  51. $smarty->assign('list', $vote_list['list']);
  52. $smarty->assign('filter', $vote_list['filter']);
  53. $smarty->assign('record_count', $vote_list['record_count']);
  54. $smarty->assign('page_count', $vote_list['page_count']);
  55. make_json_result($smarty->fetch('vote_list.htm'), '',
  56. array('filter' => $vote_list['filter'], 'page_count' => $vote_list['page_count']));
  57. }
  58. /*------------------------------------------------------ */
  59. //-- 添加新的投票页面
  60. /*------------------------------------------------------ */
  61. elseif ($_REQUEST['act'] == 'add')
  62. {
  63. /* 权限检查 */
  64. admin_priv('vote_priv');
  65. /* 日期初始化 */
  66. $vote = array('start_time' => local_date('Y-m-d'), 'end_time' => local_date('Y-m-d', local_strtotime('+2 weeks')));
  67. /* 模板赋值 */
  68. $smarty->assign('ur_here', $_LANG['add_vote']);
  69. $smarty->assign('action_link', array('href'=>'vote.php?act=list', 'text' => $_LANG['list_vote']));
  70. $smarty->assign('action', 'add');
  71. $smarty->assign('form_act', 'insert');
  72. $smarty->assign('vote_arr', $vote);
  73. $smarty->assign('cfg_lang', $_CFG['lang']);
  74. /* 显示页面 */
  75. assign_query_info();
  76. $smarty->display('vote_info.htm');
  77. }
  78. elseif ($_REQUEST['act'] == 'insert')
  79. {
  80. admin_priv('vote_priv');
  81. /* 获得广告的开始时期与结束日期 */
  82. $start_time = local_strtotime($_POST['start_time']);
  83. $end_time = local_strtotime($_POST['end_time']);
  84. /* 查看广告名称是否有重复 */
  85. $sql = "SELECT COUNT(*) FROM " .$ecs->table('vote'). " WHERE vote_name='$_POST[vote_name]'";
  86. if ($db->getOne($sql) == 0)
  87. {
  88. /* 插入数据 */
  89. $sql = "INSERT INTO ".$ecs->table('vote')." (vote_name, start_time, end_time, can_multi, vote_count)
  90. VALUES ('$_POST[vote_name]', '$start_time', '$end_time', '$_POST[can_multi]', '0')";
  91. $db->query($sql);
  92. $new_id = $db->Insert_ID();
  93. /* 记录管理员操作 */
  94. admin_log($_POST['vote_name'], 'add', 'vote');
  95. /* 清除缓存 */
  96. clear_cache_files();
  97. /* 提示信息 */
  98. $link[0]['text'] = $_LANG['continue_add_option'];
  99. $link[0]['href'] = 'vote.php?act=option&id='.$new_id;
  100. $link[1]['text'] = $_LANG['continue_add_vote'];
  101. $link[1]['href'] = 'vote.php?act=add';
  102. $link[2]['text'] = $_LANG['back_list'];
  103. $link[2]['href'] = 'vote.php?act=list';
  104. sys_msg($_LANG['add'] . "&nbsp;" .$_POST['vote_name'] . "&nbsp;" . $_LANG['attradd_succed'],0, $link);
  105. }
  106. else
  107. {
  108. $link[] = array('text' => $_LANG['go_back'], 'href'=>'javascript:history.back(-1)');
  109. sys_msg($_LANG['vote_name_exist'], 0, $link);
  110. }
  111. }
  112. /*------------------------------------------------------ */
  113. //-- 在线调查编辑页面
  114. /*------------------------------------------------------ */
  115. elseif ($_REQUEST['act'] == 'edit')
  116. {
  117. admin_priv('vote_priv');
  118. /* 获取数据 */
  119. $vote_arr = $db->GetRow("SELECT * FROM ".$ecs->table('vote')." WHERE vote_id='$_REQUEST[id]'");
  120. $vote_arr['start_time'] = local_date('Y-m-d', $vote_arr['start_time']);
  121. $vote_arr['end_time'] = local_date('Y-m-d', $vote_arr['end_time']);
  122. /* 模板赋值 */
  123. $smarty->assign('ur_here', $_LANG['edit_vote']);
  124. $smarty->assign('action_link', array('href'=>'vote.php?act=list', 'text' => $_LANG['list_vote']));
  125. $smarty->assign('form_act', 'update');
  126. $smarty->assign('vote_arr', $vote_arr);
  127. assign_query_info();
  128. $smarty->display('vote_info.htm');
  129. }
  130. elseif ($_REQUEST['act'] == 'update')
  131. {
  132. /* 获得广告的开始时期与结束日期 */
  133. $start_time = local_strtotime($_POST['start_time']);
  134. $end_time = local_strtotime($_POST['end_time']);
  135. /* 更新信息 */
  136. $sql = "UPDATE " .$ecs->table('vote'). " SET ".
  137. "vote_name = '$_POST[vote_name]', ".
  138. "start_time = '$start_time', ".
  139. "end_time = '$end_time', ".
  140. "can_multi = '$_POST[can_multi]' ".
  141. "WHERE vote_id = '$_REQUEST[id]'";
  142. $db->query($sql);
  143. /* 清除缓存 */
  144. clear_cache_files();
  145. /* 记录管理员操作 */
  146. admin_log($_POST['vote_name'], 'edit', 'vote');
  147. /* 提示信息 */
  148. $link[] = array('text' => $_LANG['back_list'], 'href'=>'vote.php?act=list');
  149. sys_msg($_LANG['edit'] .' '.$_POST['vote_name'].' '. $_LANG['attradd_succed'], 0, $link);
  150. }
  151. /*------------------------------------------------------ */
  152. //-- 调查选项列表页面
  153. /*------------------------------------------------------ */
  154. elseif ($_REQUEST['act'] == 'option')
  155. {
  156. $id = !empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
  157. /* 模板赋值 */
  158. $smarty->assign('ur_here', $_LANG['list_vote_option']);
  159. $smarty->assign('action_link', array('href'=>'vote.php?act=list', 'text' => $_LANG['list_vote']));
  160. $smarty->assign('full_page', 1);
  161. $smarty->assign('id', $id);
  162. $smarty->assign('option_arr', get_optionlist($id));
  163. /* 显示页面 */
  164. assign_query_info();
  165. $smarty->display('vote_option.htm');
  166. }
  167. /*------------------------------------------------------ */
  168. //-- 调查选项查询
  169. /*------------------------------------------------------ */
  170. elseif ($_REQUEST['act'] == 'query_option')
  171. {
  172. $id = intval($_GET['vid']);
  173. $smarty->assign('id', $id);
  174. $smarty->assign('option_arr', get_optionlist($id));
  175. make_json_result($smarty->fetch('vote_option.htm'));
  176. }
  177. /*------------------------------------------------------ */
  178. //-- 添加新调查选项
  179. /*------------------------------------------------------ */
  180. elseif ($_REQUEST['act'] == 'new_option')
  181. {
  182. check_authz_json('vote_priv');
  183. $option_name = json_str_iconv(trim($_POST['option_name']));
  184. $vote_id = intval($_POST['id']);
  185. if (!empty($option_name))
  186. {
  187. /* 查看调查标题是否有重复 */
  188. $sql = 'SELECT COUNT(*) FROM ' .$ecs->table('vote_option').
  189. " WHERE option_name = '$option_name' AND vote_id = '$vote_id'";
  190. if ($db->getOne($sql) != 0)
  191. {
  192. make_json_error($_LANG['vote_option_exist']);
  193. }
  194. else
  195. {
  196. $sql = 'INSERT INTO ' .$ecs->table('vote_option'). ' (vote_id, option_name, option_count) '.
  197. "VALUES ('$vote_id', '$option_name', 0)";
  198. $db->query($sql);
  199. clear_cache_files();
  200. admin_log($option_name, 'add', 'vote');
  201. $url = 'vote.php?act=query_option&vid='.$vote_id.'&' . str_replace('act=new_option', '', $_SERVER['QUERY_STRING']);
  202. ecs_header("Location: $url\n");
  203. exit;
  204. }
  205. }
  206. else
  207. {
  208. make_json_error($_LANG['js_languages']['option_name_empty']);
  209. }
  210. }
  211. /*------------------------------------------------------ */
  212. //-- 编辑调查主题
  213. /*------------------------------------------------------ */
  214. elseif ($_REQUEST['act'] == 'edit_vote_name')
  215. {
  216. check_authz_json('vote_priv');
  217. $id = intval($_POST['id']);
  218. $vote_name = json_str_iconv(trim($_POST['val']));
  219. /* 检查名称是否重复 */
  220. if ($exc->num("vote_name", $vote_name, $id) != 0)
  221. {
  222. make_json_error(sprintf($_LANG['vote_name_exist'], $vote_name));
  223. }
  224. else
  225. {
  226. if ($exc->edit("vote_name = '$vote_name'", $id))
  227. {
  228. admin_log($vote_name, 'edit', 'vote');
  229. make_json_result(stripslashes($vote_name));
  230. }
  231. }
  232. }
  233. /*------------------------------------------------------ */
  234. //-- 编辑调查选项
  235. /*------------------------------------------------------ */
  236. elseif ($_REQUEST['act'] == 'edit_option_name')
  237. {
  238. check_authz_json('vote_priv');
  239. $id = intval($_POST['id']);
  240. $option_name = json_str_iconv(trim($_POST['val']));
  241. /* 检查名称是否重复 */
  242. $vote_id = $db->getOne('SELECT vote_id FROM ' .$ecs->table('vote_option'). " WHERE option_id='$id'");
  243. $sql = 'SELECT COUNT(*) FROM ' .$ecs->table('vote_option').
  244. " WHERE option_name = '$option_name' AND vote_id = '$vote_id' AND option_id <> $id";
  245. if ($db->getOne($sql) != 0)
  246. {
  247. make_json_error(sprintf($_LANG['vote_option_exist'], $option_name));
  248. }
  249. else
  250. {
  251. if ($exc_opn->edit("option_name = '$option_name'", $id))
  252. {
  253. admin_log($option_name, 'edit', 'vote');
  254. make_json_result(stripslashes($option_name));
  255. }
  256. }
  257. }
  258. /*------------------------------------------------------ */
  259. //-- 删除在线调查主题
  260. /*------------------------------------------------------ */
  261. elseif ($_REQUEST['act'] == 'remove')
  262. {
  263. check_authz_json('vote_priv');
  264. $id = intval($_GET['id']);
  265. if ($exc->drop($id))
  266. {
  267. /* 同时删除调查选项 */
  268. $db->query("DELETE FROM " .$ecs->table('vote_option'). " WHERE vote_id = '$id'");
  269. clear_cache_files();
  270. admin_log('', 'remove', 'ads_position');
  271. }
  272. $url = 'vote.php?act=query&' . str_replace('act=remove', '', $_SERVER['QUERY_STRING']);
  273. ecs_header("Location: $url\n");
  274. exit;
  275. }
  276. /*------------------------------------------------------ */
  277. //-- 删除在线调查选项
  278. /*------------------------------------------------------ */
  279. elseif ($_REQUEST['act'] == 'remove_option')
  280. {
  281. check_authz_json('vote_priv');
  282. $id = intval($_GET['id']);
  283. $vote_id = $db->getOne('SELECT vote_id FROM ' .$ecs->table('vote_option'). " WHERE option_id='$id'");
  284. if ($exc_opn->drop($id))
  285. {
  286. clear_cache_files();
  287. admin_log('', 'remove', 'vote');
  288. }
  289. $url = 'vote.php?act=query_option&vid='.$vote_id.'&' . str_replace('act=remove_option', '', $_SERVER['QUERY_STRING']);
  290. ecs_header("Location: $url\n");
  291. exit;
  292. }
  293. /* 获取在线调查数据列表 */
  294. function get_votelist()
  295. {
  296. $filter = array();
  297. /* 记录总数以及页数 */
  298. $sql = 'SELECT COUNT(*) FROM ' . $GLOBALS['ecs']->table('vote');
  299. $filter['record_count'] = $GLOBALS['db']->getOne($sql);
  300. $filter = page_and_size($filter);
  301. /* 查询数据 */
  302. $sql = 'SELECT * FROM ' .$GLOBALS['ecs']->table('vote'). ' ORDER BY vote_id DESC';
  303. $res = $GLOBALS['db']->selectLimit($sql, $filter['page_size'], $filter['start']);
  304. $list = array();
  305. while ($rows = $GLOBALS['db']->fetchRow($res))
  306. {
  307. $rows['begin_date'] = local_date('Y-m-d', $rows['start_time']);
  308. $rows['end_date'] = local_date('Y-m-d', $rows['end_time']);
  309. $list[] = $rows;
  310. }
  311. return array('list' => $list, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
  312. }
  313. /* 获取调查选项列表 */
  314. function get_optionlist($id)
  315. {
  316. $list = array();
  317. $sql = 'SELECT option_id, vote_id, option_name, option_count'.
  318. ' FROM ' .$GLOBALS['ecs']->table('vote_option').
  319. " WHERE vote_id = '$id' ORDER BY option_id DESC";
  320. $res = $GLOBALS['db']->query($sql);
  321. while ($rows = $GLOBALS['db']->fetchRow($res))
  322. {
  323. $list[] = $rows;
  324. }
  325. return $list;
  326. }
  327. ?>