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