PageRenderTime 35ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/miles/GlobalMBA/mba/sns_00/upload/home/source/space_poll.php

#
PHP | 257 lines | 190 code | 44 blank | 23 comment | 52 complexity | 705fcfe5303c0f3b91937ac008568eda MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /*
  3. [UCenter Home] (C) 2007-2008 Comsenz Inc.
  4. $Id: space_poll.php 13206 2009-08-20 02:31:30Z liguode $
  5. */
  6. if(!defined('IN_UCHOME')) {
  7. exit('Access Denied');
  8. }
  9. $page = empty($_GET['page'])?1:intval($_GET['page']);
  10. if($page<1) $page=1;
  11. $pid = empty($_GET['pid'])?0:intval($_GET['pid']);
  12. if($pid) {
  13. $perpage = 20;
  14. $start = ($page-1)*$perpage;
  15. //检查开始数
  16. ckstart($start, $perpage);
  17. $newpoll = $hotpoll = $poll = $option = array();
  18. $query = $_SGLOBAL['db']->query("SELECT pf.*, p.* FROM ".tname('poll')." p LEFT JOIN ".tname('pollfield')." pf ON pf.pid=p.pid WHERE p.pid='$pid'");
  19. $poll = $_SGLOBAL['db']->fetch_array($query);
  20. if(empty($poll)) {
  21. showmessage('view_to_info_did_not_exist');
  22. }
  23. if($poll['credit'] && $poll['percredit'] && $poll['credit'] < $poll['percredit']) {
  24. $poll['percredit'] = $poll['credit'];
  25. }
  26. realname_set($poll['uid'], $poll['username']);//实名
  27. //限制投票
  28. $allowedvote = true;
  29. if(!empty($poll['sex']) && $poll['sex'] != $_SGLOBAL['member']['sex']) {
  30. $allowedvote = false;
  31. }
  32. $expiration = false;
  33. //过期同样禁止投票
  34. if($poll['expiration'] && $poll['expiration'] < $_SGLOBAL['timestamp']) {
  35. $allowedvote = false;
  36. $expiration = true;
  37. if(empty($poll['summary']) && !$poll['notify']) {
  38. @include_once(S_ROOT.'./source/function_cp.php');
  39. $note = cplang('note_poll_finish', array("space.php?uid=$poll[uid]&do=poll&pid=$poll[pid]", $poll['subject']));
  40. $supe_uid = $_SGLOBAL['supe_uid'];
  41. $supe_username = $_SGLOBAL['supe_username'];
  42. $_SGLOBAL['supe_uid'] = 0;
  43. $_SGLOBAL['supe_username'] = '';
  44. notification_add($poll['uid'], 'poll', $note);
  45. $_SGLOBAL['supe_uid'] = $supe_uid;
  46. $_SGLOBAL['supe_username'] = $supe_username;
  47. updatetable('pollfield', array('notify'=>1), array('pid'=>$poll['pid']));
  48. }
  49. }
  50. $hasvoted = $_SGLOBAL['db']->result($_SGLOBAL['db']->query("SELECT COUNT(*) FROM ".tname('polluser')." WHERE uid='$_SGLOBAL[supe_uid]' AND pid='$pid' "),0);
  51. //总投票数
  52. $allvote = 0;
  53. //取出所有投票项
  54. $query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('polloption')." WHERE pid='$pid' ORDER BY oid");
  55. while($value = $_SGLOBAL['db']->fetch_array($query)) {
  56. $allvote += intval($value['votenum']);
  57. $option[] = $value;
  58. }
  59. //计算百分比
  60. foreach($option as $key => $value) {
  61. if($value['votenum'] && $allvote) {
  62. $value['percent'] = round($value['votenum']/$allvote, 2);
  63. $value['width'] = round($value['percent']*160);
  64. $value['percent'] = $value['percent']*100;
  65. } else {
  66. $value['width'] = $value['percent'] = 0;
  67. }
  68. $option[$key] = $value;
  69. }
  70. $isfriend = 1;
  71. if($poll['noreply']) {
  72. //是否好友
  73. $isfriend = $space['self'];
  74. if($space['friends'] && in_array($_SGLOBAL['supe_uid'], $space['friends'])) {
  75. $isfriend = 1;//是好友
  76. }
  77. }
  78. if($isfriend) {
  79. //评论
  80. $count = $poll['replynum'];
  81. $list = array();
  82. if($count) {
  83. $cid = empty($_GET['cid'])?0:intval($_GET['cid']);
  84. $csql = $cid?"cid='$cid' AND":'';
  85. $query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('comment')." WHERE $csql id='$pid' AND idtype='pid' ORDER BY dateline LIMIT $start,$perpage");
  86. while ($value = $_SGLOBAL['db']->fetch_array($query)) {
  87. realname_set($value['authorid'], $value['author']);//实名
  88. $list[] = $value;
  89. }
  90. }
  91. //分页
  92. $multi = multi($count, $perpage, $page, "space.php?uid=$poll[uid]&do=$do&pid=$pid", '', 'div_main_content');
  93. }
  94. //取出最新投票
  95. $query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('poll')." ORDER BY dateline DESC LIMIT 0, 10");
  96. while($value = $_SGLOBAL['db']->fetch_array($query)) {
  97. realname_set($value['uid'], $value['username']);//实名
  98. $newpoll[] = $value;
  99. }
  100. //取出最热的投票
  101. $timerange = $_SGLOBAL['timestamp']-2592000;
  102. $query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('poll')." WHERE lastvote >= '$timerange' ORDER BY voternum DESC LIMIT 0, 10");
  103. while($value = $_SGLOBAL['db']->fetch_array($query)) {
  104. realname_set($value['uid'], $value['username']);//实名
  105. $hotpoll[] = $value;
  106. }
  107. //相关热点
  108. $topic = topic_get($poll['topicid']);
  109. //实名
  110. realname_get();
  111. $_TPL['css'] = 'poll';
  112. include_once template("space_poll_view");
  113. } else {
  114. $_GET['view'] = $_GET['view'] ? trim($_GET['view']) : 'new';
  115. if($_GET['view'] == 'all') $_GET['view'] = 'new';
  116. //分页
  117. $perpage = 10;
  118. $start = ($page-1)*$perpage;
  119. //检查开始数
  120. ckstart($start, $perpage);
  121. $wherearr = $list = array();
  122. $userlist = array();
  123. $count = $pricount = 0;
  124. $wheresql = $indexsql = $leftsql = '';
  125. $ordersql = 'p.dateline';
  126. $counttable = tname('poll').' p ';
  127. if($_GET['view'] == 'new') {
  128. $indexsql = 'USE INDEX (dateline)';
  129. $theurl = "space.php?uid=$space[uid]&do=$do&view=new";
  130. } elseif($_GET['view'] == 'hot') {
  131. $_GET['filtrate'] = empty($_GET['filtrate']) ? 'all' : trim($_GET['filtrate']);
  132. $indexsql = 'USE INDEX (voternum)';
  133. $ordersql = 'p.voternum';
  134. $timerange = 0;
  135. if($_GET['filtrate']=='week') {
  136. $timerange = $_SGLOBAL['timestamp']-604800;
  137. } elseif($_GET['filtrate']=='month') {
  138. $timerange = $_SGLOBAL['timestamp']-2592000;
  139. }
  140. if($timerange) {
  141. $wherearr[] = "p.lastvote >= '$timerange'";
  142. }
  143. $filtrate = array($_GET['filtrate']=>' class="active"');
  144. $theurl = "space.php?uid=$space[uid]&do=$do&view=hot";
  145. } elseif($_GET['view'] == 'friend') {
  146. $indexsql = 'USE INDEX (dateline)';
  147. $wherearr[] = "p.uid IN ($space[feedfriend])";
  148. $theurl = "space.php?uid=$space[uid]&do=$do&view=friend";
  149. } elseif($_GET['view'] == 'reward') {
  150. $indexsql = 'USE INDEX (percredit)';
  151. $ordersql = 'p.percredit DESC, p.dateline';
  152. $wherearr[] = "p.percredit > 0";
  153. $theurl = "space.php?uid=$space[uid]&do=$do&view=reward";
  154. } else {
  155. $_GET['filtrate'] = empty($_GET['filtrate']) ? 'me' : trim($_GET['filtrate']);
  156. if($_GET['filtrate'] == 'join') {
  157. $leftsql = tname('polluser')." pu LEFT JOIN ";
  158. $indexsql = ' ON p.pid=pu.pid ';
  159. $wherearr[] = "pu.uid='$space[uid]'";
  160. $ordersql = 'pu.dateline';
  161. $counttable = tname('polluser').' pu ';
  162. } elseif($_GET['filtrate'] == 'expiration') {
  163. $counttable = tname('polluser').' pu, '.tname('poll').' p';
  164. $ordersql = 'pu.dateline';
  165. $wherearr[] = "pu.uid='$space[uid]' AND pu.pid=p.pid AND p.expiration>0 AND p.expiration<='$_SGLOBAL[timestamp]'";
  166. } else {
  167. $wherearr[] = "p.uid='$space[uid]'";
  168. }
  169. $filtrate = array($_GET['filtrate']=>' class="active"');
  170. $theurl = "space.php?uid=$space[uid]&do=$do&view=me&filtrate=".$_GET['filtrate'];
  171. }
  172. //搜索
  173. if($searchkey = stripsearchkey($_GET['searchkey'])) {
  174. $wherearr[] = "p.subject LIKE '%$searchkey%'";
  175. $theurl .= "&searchkey=$_GET[searchkey]";
  176. cksearch($theurl);
  177. }
  178. if($wherearr) {
  179. $wheresql = ' WHERE '.implode(' AND ', $wherearr);
  180. }
  181. $count = $_SGLOBAL['db']->result($_SGLOBAL['db']->query("SELECT COUNT(*) FROM $counttable $wheresql"),0);
  182. //更新统计
  183. if($wheresql == "p.uid='$space[uid]'" && $space['pollnum'] != $count) {
  184. updatetable('space', array('pollnum' => $count), array('uid'=>$space['uid']));
  185. }
  186. if($count) {
  187. if($_GET['filtrate'] == 'expiration') {
  188. $query = $_SGLOBAL['db']->query("SELECT p.*,pf.* FROM ".tname('polluser')." pu, ".tname('poll')." p,".tname('pollfield')." pf $wheresql AND p.pid=pf.pid ORDER BY $ordersql DESC LIMIT $start,$perpage");
  189. } else {
  190. $query = $_SGLOBAL['db']->query("SELECT p.*,pf.* FROM $leftsql ".tname('poll')." p $indexsql
  191. LEFT JOIN ".tname('pollfield')." pf ON pf.pid=p.pid
  192. $wheresql
  193. ORDER BY $ordersql DESC LIMIT $start,$perpage");
  194. }
  195. while ($value = $_SGLOBAL['db']->fetch_array($query)) {
  196. if($value['credit'] && $value['percredit'] && $value['credit'] < $value['percredit']) {
  197. $value['percredit'] = $value['credit'];
  198. }
  199. realname_set($value['uid'], $value['username']);
  200. $value['option'] = unserialize($value['option']);
  201. $list[] = $value;
  202. $userlist[$value['uid']] = $value['username'];
  203. }
  204. }
  205. //分页
  206. $multi = multi($count, $perpage, $page, $theurl);
  207. //实名
  208. realname_get();
  209. $actives = array($_GET['view']=>' class="active"');
  210. $_TPL['css'] = 'poll';
  211. include_once template("space_poll_list");
  212. }
  213. ?>