votefun.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. //增加投票
  3. function AddVote($voteid,$vote){
  4. global $empire,$dbtbpre,$public_r;
  5. $voteid=(int)$voteid;
  6. if(empty($voteid))
  7. {
  8. printerror("NotVote","history.go(-1)",1);
  9. }
  10. $lasttime=getcvar('lastvotetime');
  11. if($lasttime)
  12. {
  13. if(time()-$lasttime<$public_r['revotetime'])
  14. {
  15. printerror("VoteOutTime","history.go(-1)",1);
  16. }
  17. }
  18. $r=$empire->fetch1("select voteid,voteip,votetext,voteclass,doip,dotime from {$dbtbpre}enewsvote where voteid='$voteid'");
  19. if(empty($r['voteid'])||empty($r['votetext']))
  20. {
  21. printerror("NotVote","history.go(-1)",1);
  22. }
  23. $re=DoVote($r,$vote);
  24. $sql=$empire->query("update {$dbtbpre}enewsvote set votetext='".addslashes($re['votetext'])."',voteip='$re[voteip]',votenum=votenum+".$re['votetotal']." where voteid='$voteid'");
  25. if($sql)
  26. {
  27. esetcookie("lastvotetime",time(),time()+3600*24);//设置最后发表时间
  28. printerror("VoteSuccess","../tool/vote/?voteid=".$voteid,1);
  29. }
  30. else
  31. {
  32. printerror("DbError","history.go(-1)",1);
  33. }
  34. }
  35. //添加信息投票
  36. function AddInfoVote($classid,$id,$vote){
  37. global $empire,$dbtbpre,$class_r,$public_r;
  38. $classid=(int)$classid;
  39. $id=(int)$id;
  40. if(empty($id)||empty($classid)||!$class_r[$classid]['tbname'])
  41. {
  42. printerror("NotVote","history.go(-1)",1);
  43. }
  44. $lasttime=getcvar('lastivotetime');
  45. if($lasttime)
  46. {
  47. if(time()-$lasttime<$public_r['revotetime'])
  48. {
  49. printerror("VoteOutTime","history.go(-1)",1);
  50. }
  51. }
  52. $pubid=ReturnInfoPubid($classid,$id);
  53. $r=$empire->fetch1("select id,voteip,votetext,voteclass,doip,dotime from {$dbtbpre}enewsinfovote where pubid='$pubid' limit 1");
  54. if(empty($r['id'])||empty($r['votetext']))
  55. {
  56. printerror("NotVote","history.go(-1)",1);
  57. }
  58. $re=DoVote($r,$vote);
  59. $sql=$empire->query("update {$dbtbpre}enewsinfovote set votetext='".addslashes($re['votetext'])."',voteip='$re[voteip]',votenum=votenum+".$re['votetotal']." where pubid='$pubid' limit 1");
  60. if($sql)
  61. {
  62. esetcookie("lastivotetime",time(),time()+3600*24);//设置最后发表时间
  63. printerror("VoteSuccess","../public/vote/?classid=$classid&id=$id",1);
  64. }
  65. else
  66. {
  67. printerror("DbError","history.go(-1)",1);
  68. }
  69. }
  70. //处理投票
  71. function DoVote($r,$vote){
  72. //投票期限
  73. if($r['dotime']<>"0000-00-00")
  74. {
  75. $endtime=to_date($r['dotime']);
  76. if($endtime<time())
  77. {
  78. printerror("VoteOutDate","history.go(-1)",1);
  79. }
  80. }
  81. //IP限制
  82. if(empty($r['voteip']))
  83. {
  84. $r['voteip']='|';
  85. }
  86. $ip=egetip();
  87. if($r['doip'])
  88. {
  89. if(strstr($r['voteip'],'|'.$ip.'|'))
  90. {
  91. printerror("ReVote","history.go(-1)",1);
  92. }
  93. $r['voteip']=$r['voteip'].$ip."|";
  94. }
  95. $VoteField="::::::";
  96. $VoteRecord="\r\n";
  97. $vote_r=explode($VoteRecord,$r['votetext']);
  98. $new_vote_total=0;
  99. if($r['voteclass'])//多选
  100. {
  101. $vote_count=count($vote);
  102. if(empty($vote_count))
  103. {
  104. printerror("EmptyChangeVote","history.go(-1)",1);
  105. }
  106. for($j=0;$j<$vote_count;$j++)
  107. {
  108. $new_vote_total++;
  109. $v_r=explode($VoteField,$vote_r[$vote[$j]-1]);
  110. if(empty($v_r[0]))
  111. {
  112. continue;
  113. }
  114. $vote_num=$v_r[1]+1;
  115. $vote_r[$vote[$j]-1]=$v_r[0].$VoteField.$vote_num;
  116. }
  117. }
  118. else//单选
  119. {
  120. if(empty($vote))
  121. {
  122. printerror("NotChangeVote","history.go(-1)",1);
  123. }
  124. $v_r=explode($VoteField,$vote_r[$vote-1]);
  125. if(empty($v_r[0]))
  126. {
  127. printerror("NotChangeVote","history.go(-1)",1);
  128. }
  129. $vote_num=$v_r[1]+1;
  130. $vote_r[$vote-1]=$v_r[0].$VoteField.$vote_num;
  131. $new_vote_total=1;
  132. }
  133. for($n=0;$n<count($vote_r);$n++)
  134. {
  135. $new_votetext.=$vote_r[$n].$VoteRecord;
  136. }
  137. $new_votetext=substr($new_votetext,0,strlen($new_votetext)-2);//去掉最后的字符
  138. //返回数组
  139. $re['votetotal']=(int)$new_vote_total;
  140. $re['votetext']=$new_votetext;
  141. $re['voteip']=addslashes($r['voteip']);
  142. return $re;
  143. }
  144. //评分
  145. function AddInfoPfen($add){
  146. global $empire,$dbtbpre,$class_r;
  147. $id=(int)$add['id'];
  148. $classid=(int)$add['classid'];
  149. $fen=(int)$add['fen'];
  150. $doajax=(int)$add['doajax'];
  151. if(!$id||!$classid||!$class_r[$classid]['tbname'])
  152. {
  153. $doajax==1?ajax_printerror('','','ErrorUrl',1):printerror('ErrorUrl','',1);
  154. }
  155. //连续发表
  156. if(getcvar('lastforfenid')==$classid.'n'.$id)
  157. {
  158. $doajax==1?ajax_printerror('','','ReDoForPl',1):printerror('ReDoForPl','',1);
  159. }
  160. //字段
  161. $fnum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsf where tbname='".$class_r[$classid]['tbname']."' and (f='infopfen' or f='infopfennum')");
  162. if(empty($fnum))
  163. {
  164. $doajax==1?ajax_printerror('','','ErrorUrl',1):printerror('ErrorUrl','',1);
  165. }
  166. if($fen<1)
  167. {
  168. $fen=1;
  169. }
  170. if($fen>5)
  171. {
  172. $fen=5;
  173. }
  174. $sql=$empire->query("update {$dbtbpre}ecms_".$class_r[$classid]['tbname']." set infopfen=infopfen+$fen,infopfennum=infopfennum+1 where id='$id' and classid='$classid' limit 1");
  175. if($sql)
  176. {
  177. esetcookie('lastforfenid',$classid.'n'.$id,time()+30*24*3600); //最后发布
  178. if($doajax==1)
  179. {
  180. $nr=$empire->fetch1("select infopfen,infopfennum from {$dbtbpre}ecms_".$class_r[$classid]['tbname']." where id='$id' and classid='$classid' limit 1");
  181. $infopfen=$nr[infopfennum]?round($nr[infopfen]/$nr[infopfennum]):0;
  182. ajax_printerror($infopfen,RepPostVar($add['ajaxarea']),'AddInfoPfen',1);
  183. }
  184. else
  185. {
  186. printerror('AddInfoPfen',EcmsGetReturnUrl(),1);
  187. }
  188. }
  189. else
  190. {
  191. $doajax==1?ajax_printerror('','','DbError',1):printerror('DbError','',1);
  192. }
  193. }
  194. ?>