C:\xampp2_not used\htdocs\kptv\ro\func\vote_old.php


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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<?php 
    
    
class Vote{
        
        private 
$db;
        
        public static 
$INT_0 0;
        public static 
$INT_1 10;
        public static 
$INT_2 50;
        public static 
$INT_3 100;
        public static 
$INT_4 150;
        public static 
$INT_5 200;
        
        public function 
__construct(){
            global 
$db_name;
            global 
$db_host;
            global 
$db_password;
            global 
$db_usrName;
                
            
$this->db = new Database($db_host$db_name$db_usrName$db_password);
            
            
// var_dump($this->db);
        
}
    
        public function 
getDBHandler(){
            return 
$this->db;
        }
    
        public function 
getNumberOfVote($ip$date){
            
$result $this->db->selectByConditions("vote", array("ip"=>$ip"datum"=>$date));            
            return 
count($result);
        }
        
        public function 
getNumberOfVotePlus($ip$date){
            
$result $this->db->selectByConditions("voteplus", array("ip"=>$ip"datum"=>$date));
            return 
count($result);
        }
        
        public function 
getNumberOfVoteBySongType($ip$date$type){
            
$result $this->db->selectByConditions("vote", array("ip"=>$ip"datum"=>$date"type_of_song"=>$type));            
            return 
count($result);
        }
        
        public function 
getNumberOfVotePlusBySongType($ip$date$type){
            
$result $this->db->selectByConditions("voteplus", array("ip"=>$ip"datum"=>$date"type_of_song"=>$type));
            return 
count($result);
        }
        
        public function 
getNrOfVotesBySong($table$ip$date$song) {
            
$result $this->db->selectByConditions($table, array("ip"=>$ip"datum"=>$date"song_id"=>$song));
            return 
count($result);
        }
        
        public function 
getTop20($orderBy "up"$order "DESC"$type_of_list){
            
$result $this->db->selectByConditions("top20", array("active"=>"1""type_of_list"=>$type_of_list), "ORDER BY (up + ( total * 0.8 )) ".$order." , prev_month =0, prev_month ASC , prev_month_2 =0, prev_month_2 ASC , months_in_top DESC, ID LIMIT 20");
            return 
$result;
        }
        
        public function 
orderPrevMonth($type_of_list){
            
$result $this->db->selectByConditions("top20", array("active"=>"1","type_of_list"=>$type_of_list), "ORDER BY prev_month =0, prev_month ASC , prev_month_2 =0, prev_month_2 ASC , months_in_top DESC, ID LIMIT 20");
            return 
$result;
        }
        
        public function 
getTop20Plus($orderBy "up"$order "DESC"$type_of_list){
            
$result $this->db->selectByConditions("top20plus", array("active"=>"1""type_of_list"=>$type_of_list), "ORDER BY ".$orderBy." ".$order." ,ID LIMIT 3");
            return 
$result;
        }
        
        public function 
increaseMonthsInTop($type_of_list){
            
$this->db->query("UPDATE top20 SET months_in_top = months_in_top+1 WHERE type_of_list=".$type_of_list);
        }
        
        public function 
sumTop20($type_of_list){
            
$top20 $this->getTop20("up","DESC"$type_of_list);
            foreach(
$top20 AS $t2) {
                
$this->db->update("top20", array("total"=>$t2['total'] + $t2['up']), $t2['ID'], array());
            }
        }
        
        public function 
sumTop20Plus($type_of_list){
            
$top20 $this->getTop20Plus(nullnull$type_of_list);
            foreach(
$top20 AS $t2) {
                
$this->db->update("top20plus", array("total"=>$t2['total'] + $t2['up']), $t2['ID'], array());
            }
        }
        
        public function 
handlePrevMonth($prevMonth) {
            
$count count($prevMonth);
            echo 
$count;
            
$j=1;
             for (
$i=0$i $count$i++) 
             {
                
$id $prevMonth[$i]['ID'];
                echo 
'=================<br>';
                
$array = array(
                    
"prev_month_2" => $j
                
);
                 echo 
$i ." "$id "</br>";
                 
$this->db->update('top20'$array $id);
                
$j++;
             }
        }
        
        public function 
copyCurrentMonthToPrevMonth($type_of_list){
            
$currentMonth =  $this->db->selectByConditions("top20", array("active"=>"1","type_of_list"=>$type_of_list), "ORDER BY ( up + ( total * 0.8 )) DESC ,ID LIMIT 20");
            
            
$count count($currentMonth);
            echo 
$count;
            
$j=1;
             for (
$i=0$i $count$i++) 
             {
                
$id $currentMonth[$i]['ID'];
                
$up $currentMonth[$i]['up'];
                 
$array = array(
                    
"prev_month" => $j //$up
                
);
                 
//echo $i ." ". $id . "</br>";
                 
$this->db->update('top20'$array $id);
                
$j++;
             }
            echo 
'masolas kesz'// . count ($currentMonth);
        
}
        
        public function 
copyCurrentMonthToPrevMonthInTop20Plus(){
            
$currentMonth =  $this->db->selectByConditions("top20plus", array("active"=>"1"), "ORDER BY \"up\" DESC ,ID LIMIT 20");
            
            
$count count($currentMonth);
            echo 
$count;
            
$j=1;
             for (
$i=0$i $count$i++) 
             {
                
$id $currentMonth[$i]['ID'];
                
$up $currentMonth[$i]['up'];
                 
$array = array(
                    
"prev_month" => $up
                
);
                 
//echo $i ." ". $id . "</br>";
                 
$this->db->update('top20plus'$array $id);
                
$j++;
             }
            echo 
'masolas kesz top20plus'// . count ($currentMonth);
        
}
        
        public function 
handleTop20Top20PlusLoc($top20$top20plus) {
    
            if(
$top20['17']['up'] < $top20plus['0']['up'] && 
                
$top20['18']['up'] < $top20plus['1']['up'] && 
                
$top20['19']['up'] < $top20plus['2']['up']) {
                
                
                    
$firstTop20     $top20['17'];
                    
$secondTop20     $top20['18'];
                    
$thirdTop20     $top20['19'];
                    
                    
$firstTop20Plus     $top20plus['0'];
                    
$secondTop20Plus    $top20plus['1'];
                    
$thirdTop20Plus     $top20plus['2'];
                    
                    
$firstTop20Plus['months_in_top'] = 0;
                    
$firstTop20Plus['prev_month'] = 0;
                    
                    
$secondTop20Plus['months_in_top'] = 0;
                    
$secondTop20Plus['prev_month'] = 0;
                    
                    
$thirdTop20Plus['months_in_top'] = 0;
                    
$thirdTop20Plus['prev_month'] = 0;
                    
                    
                    
//copy top20plus to top20
                    
$this->db->insert("top20"$firstTop20Plus, array("ID"));            
                    
$this->db->insert("top20"$secondTop20Plus, array("ID"));            
                    
$this->db->insert("top20"$thirdTop20Plus, array("ID"));            
                    
                    
//delete from top20plus
                    
$this->db->deleteById("top20plus"$firstTop20Plus['ID']);
                    
$this->db->deleteById("top20plus"$secondTop20Plus['ID']);
                    
$this->db->deleteById("top20plus"$thirdTop20Plus['ID']);
                    
                    
//delete from top20
                    
$this->db->deleteById("top20"$firstTop20['ID']);
                    
$this->db->deleteById("top20"$secondTop20['ID']);
                    
$this->db->deleteById("top20"$thirdTop20['ID']);
                    
                    
//insert, delete...
            
} else if($top20['18']['up'] < $top20plus['0']['up'] && 
                    
$top20['19']['up'] < $top20plus['1']['up']) {
                
                
$firstTop20     $top20['18'];
                
$secondTop20     $top20['19'];
                
                
$firstTop20Plus     $top20plus['0'];
                
$secondTop20Plus     $top20plus['1'];
                                        
                
$firstTop20Plus['months_in_top'] = 0;
                
$firstTop20Plus['prev_month'] = 0;
                
                
$secondTop20Plus['months_in_top'] = 0;
                
$secondTop20Plus['prev_month'] = 0;
                                        
                
//copy top20plus to top20
                
$this->db->insert("top20"$firstTop20Plus, array("ID"));            
                
$this->db->insert("top20"$secondTop20Plus, array("ID"));                    
                
                
//delete from top20plus
                
$this->db->deleteById("top20plus"$firstTop20Plus['ID']);
                
$this->db->deleteById("top20plus"$secondTop20Plus['ID']);
                
                
//delete from top20
                
$this->db->deleteById("top20"$firstTop20['ID']);
                
$this->db->deleteById("top20"$secondTop20['ID']);
                
            } else if(
$top20['19']['up'] < $top20plus['0']['up']) {
            
                
$firstTop20     $top20['19'];
                
$firstTop20Plus $top20plus['0'];
                
                
$firstTop20Plus['months_in_top'] = 0;
                
$firstTop20Plus['prev_month'] = 0;
                
                
//copy top20plus to top20
                
$this->db->insert("top20"$firstTop20Plus, array("ID"));                        
                
                
//delete from top20plus
                
$this->db->deleteById("top20plus"$firstTop20Plus['ID']);
                
                
//delete from top20
                
$this->db->deleteById("top20"$firstTop20['ID']);
            } else {

            }
            
        }
        
        public function 
handleUp($top20$table){
            
$i 1;
            foreach(
$top20 AS $t2) {
                
$this->db->update($table, array("up"=>$i), $t2['ID'], array());
                
$i++;
            }
        }
        
        public function 
reset(){            
            
$this->db->query("UPDATE top20 SET up = '0'");
            
$this->db->query("UPDATE top20plus SET up = '0'");
            
            
$this->db->query("TRUNCATE vote");
            
$this->db->query("TRUNCATE voteplus");
        }
        
        public static function 
getThisCurrentVoteSymbol($up) {
            global 
$BASE_URL;
            
            if(
$up == Vote::$INT_0) {
                return 
$BASE_URL."voting/images/step0.png";
            } else if(
$up Vote::$INT_0 && $up <= Vote::$INT_1) {
                return 
$BASE_URL."voting/images/step1.png";
            } else if(
$up Vote::$INT_1 && $up <= Vote::$INT_2) {
                return 
$BASE_URL."voting/images/step2.png";
            } else if(
$up Vote::$INT_2 && $up <= Vote::$INT_3) {
                return 
$BASE_URL."voting/images/step3.png";
            } else if(
$up Vote::$INT_3 && $up <= Vote::$INT_4) {
                return 
$BASE_URL."voting/images/step4.png";
            } else {
                return 
$BASE_URL."voting/images/step5.png";
            }
        }
        
        public static function 
getSymbolHTML($up$tagId) {
            return 
"<img id = '".$tagId."' src='".Vote::getThisCurrentVoteSymbol($up)."' border='0'>";
        }
        
        public function 
deleteSongs($type_of_list){
            
$list $this->orderPrevMonth($type_of_list);
            
$id_list "";
            
            for(
$i 0$i count($list); $i++){
                
$id_list .= "'".$list[$i][ID]."'";
                if(
$i != (sizeof($list)-1)){
                    
$id_list .= ",";
                }
            }            
            if(
count($id_list) > 0) {
                
$to_delete $this->db->query("SELECT * FROM `top20` WHERE `type_of_list` = ".$type_of_list." AND ID NOT IN (".$id_list.") ");
                
                while (
$row mysql_fetch_assoc($to_delete)) {
                    
$this->db->deleteById("top20"$row['ID']);
                }
            }            
        }
    }

?>
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586