1 | <?php |
---|
2 | |
---|
3 | // file to audit concours configutation and votes |
---|
4 | // --> if _GET['concours'] ==> concours audit (with id) |
---|
5 | // if _GET['user_id'] ==> audit for a user |
---|
6 | // --> else ==> list concours to be audited |
---|
7 | |
---|
8 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
9 | include_once(CONCOURS_PATH . 'admin/functions.inc.php'); |
---|
10 | |
---|
11 | global $template; |
---|
12 | |
---|
13 | |
---|
14 | if (isset($_POST['user_list'])) |
---|
15 | $user_id = $_POST['user_list']; |
---|
16 | else |
---|
17 | $user_id = 0; |
---|
18 | |
---|
19 | // echo "USER_ID=".$user_id; |
---|
20 | |
---|
21 | // Get the concours id if present |
---|
22 | if (isset($_GET['concours'])) |
---|
23 | { |
---|
24 | $concours_id = $_GET['concours']; |
---|
25 | // Get informations from base for concours_id |
---|
26 | $concours = new Concours($concours_id); |
---|
27 | |
---|
28 | // Get group authorized to participate |
---|
29 | $users = array(); // contain {id;username} or each |
---|
30 | $groups = $concours->concours_infos['groups']; |
---|
31 | $query = 'SELECT distinct(user_id), username FROM ' . USER_GROUP_TABLE |
---|
32 | .' INNER JOIN ' . USERS_TABLE .' ON id = user_id' |
---|
33 | .($groups != NULL ? ' WHERE group_id IN ('.$groups.')' : '') |
---|
34 | // = '.$groups : '') |
---|
35 | .' ORDER BY username ASC' |
---|
36 | .';'; |
---|
37 | // echo $query."\n"; |
---|
38 | $result = pwg_query($query); |
---|
39 | while ($row = mysql_fetch_assoc($result)) |
---|
40 | { |
---|
41 | array_push($users, $row); |
---|
42 | } |
---|
43 | |
---|
44 | // Add user list |
---|
45 | $template->append('user_list', |
---|
46 | array( 'ID' => '0', |
---|
47 | 'NAME' => l10n('all_users'), |
---|
48 | 'SELECTED' => ($user_id == 0 ? 'selected' : ''))); |
---|
49 | |
---|
50 | foreach ( $users as $userid ) //on parcours le tableau |
---|
51 | { |
---|
52 | $template->append('user_list', |
---|
53 | array( 'ID' => $userid['user_id'], |
---|
54 | 'NAME' => $userid['username'], |
---|
55 | 'SELECTED' => ($user_id == $userid['user_id'] ? 'selected' : ''))); |
---|
56 | } |
---|
57 | |
---|
58 | // Add the guest list (if coucours OK for guest) |
---|
59 | $ipguest = $concours->get_guest_list(); |
---|
60 | if ($concours->concours_infos['guest']) |
---|
61 | { |
---|
62 | foreach ( $ipguest as $i => $userid ) //on parcours le tableau |
---|
63 | { |
---|
64 | $template->append('user_list', |
---|
65 | array( 'ID' => 'G'.$i, //$userid['user_id'], |
---|
66 | 'NAME' => $userid, |
---|
67 | 'SELECTED' => ($user_id == 'G'.$i ? 'selected' : ''))); |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | // Send concours info to template |
---|
72 | $template->assign( 'CONCOURS', array( |
---|
73 | 'ID' => $concours->concours_infos['id'], |
---|
74 | 'NAME' => $concours->concours_infos['name'], |
---|
75 | 'DESCR' => $concours->concours_infos['descr'], |
---|
76 | 'BEGIN_DATE' => $concours->concours_infos['begin_date'], |
---|
77 | 'END_DATE' => $concours->concours_infos['end_date'], |
---|
78 | 'METHOD' => l10n("concours_method".$concours->concours_infos['method']) |
---|
79 | )); |
---|
80 | |
---|
81 | // Step 1 : recover all the picture for the concours |
---|
82 | // Step 2 :For each picture, recover the global note, the number of vote, the actual rank (?), |
---|
83 | // Step 3 : Display theses informations |
---|
84 | |
---|
85 | // Get the nb of vote for the concours |
---|
86 | $nbvotes = $concours->nb_votes_by_img(); |
---|
87 | |
---|
88 | |
---|
89 | // Get all the users who have notes for the concours |
---|
90 | $query = 'SELECT distinct user_id, USER.username' |
---|
91 | .' FROM ' .CONCOURS_DATA_TABLE |
---|
92 | .' INNER JOIN ' . USERS_TABLE.' AS USER on USER.id = user_id' |
---|
93 | .' WHERE id_concours = '.$concours_id |
---|
94 | // Dont take the guest informations because |
---|
95 | .' AND user_id <> '.$conf['guest_id'] |
---|
96 | .' ORDER BY username ASC' |
---|
97 | .';'; |
---|
98 | $result = pwg_query($query); |
---|
99 | // For each user |
---|
100 | $user_list = array(); |
---|
101 | while ($row2 = mysql_fetch_assoc($result)) |
---|
102 | // Dont take the guest informations because |
---|
103 | // if ($row2['user_id'] != $conf['guest_id']) |
---|
104 | array_push($user_list, $row2); |
---|
105 | |
---|
106 | |
---|
107 | // Get criteria list and |
---|
108 | $criteria_list = ""; |
---|
109 | $firstcriterias = $concours->get_firstlevel_criterias($concours_id); |
---|
110 | $ident1 = 1; |
---|
111 | $criteria_number = 0; // total number of criterias |
---|
112 | foreach ($firstcriterias as $criteria) |
---|
113 | { |
---|
114 | // format (id:name) |
---|
115 | $criteria_list .= (strlen($criteria_list) ? "," : "") |
---|
116 | .$ident1.":".$criteria['name'] |
---|
117 | ."(id=".$criteria['criteria_id'].")"; |
---|
118 | // First wit sub criterias |
---|
119 | if ($concours->is_criterias_contains_sub($criteria['criteria_id'],$concours_id )) |
---|
120 | { |
---|
121 | $ident2 = 1; |
---|
122 | $secondcriterias = $concours->get_subcriterias($criteria['criteria_id'], $concours_id ); |
---|
123 | foreach ($secondcriterias as $subcriteria) |
---|
124 | { |
---|
125 | // format (id:name) |
---|
126 | $criteria_list .= (strlen($criteria_list) ? "," : "") |
---|
127 | .$ident1.".".$ident2 |
---|
128 | .":".$subcriteria['name']."(id=".$subcriteria['criteria_id'].")"; |
---|
129 | $ident2 ++; |
---|
130 | $criteria_number ++; |
---|
131 | } |
---|
132 | } |
---|
133 | else |
---|
134 | $criteria_number ++; |
---|
135 | $ident1++; |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | |
---|
140 | // Get images for all the selected cconcours |
---|
141 | |
---|
142 | $category = $concours->concours_infos['category']; |
---|
143 | |
---|
144 | $query = 'SELECT DISTINCT(img.id), img.name, img.file, img.path, img.tn_ext, img.author , |
---|
145 | ic.category_id, cat.name AS catname' //, conc.note' |
---|
146 | .' FROM ' . IMAGES_TABLE.' AS img' |
---|
147 | .' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON img.id = ic.image_id' |
---|
148 | .' INNER JOIN '.CATEGORIES_TABLE.' AS cat ON ic.category_id = cat.id' |
---|
149 | // .' INNER JOIN '.CONCOURS_RESULT_TABLE.' AS conc ON conc.img_id = img.id' |
---|
150 | .' WHERE ic.category_id = '.$concours->concours_infos['category'] |
---|
151 | // .' ORDER by note DESC |
---|
152 | .';'; |
---|
153 | |
---|
154 | $result = pwg_query($query); |
---|
155 | // echo $query; |
---|
156 | $concours_img = array(); |
---|
157 | |
---|
158 | // Recover all pictures and informations (global note |
---|
159 | while ($row = mysql_fetch_assoc($result)) |
---|
160 | { |
---|
161 | // link on picture.php page |
---|
162 | set_make_full_url(); |
---|
163 | if ( isset($row['category_id']) & isset($row['catname']) ) |
---|
164 | { |
---|
165 | $url = duplicate_picture_url( |
---|
166 | array( |
---|
167 | 'image_id' => $row['id'], |
---|
168 | 'image_file' => $row['file'], |
---|
169 | 'category' => array( |
---|
170 | 'id' => $row['category_id'], |
---|
171 | 'name' => $row['catname'], |
---|
172 | 'permalink' => '' |
---|
173 | ) |
---|
174 | ), |
---|
175 | array('start') |
---|
176 | ); |
---|
177 | } |
---|
178 | else |
---|
179 | { |
---|
180 | $url = duplicate_picture_url( |
---|
181 | array( |
---|
182 | 'image_id' => $row['id'], |
---|
183 | 'image_file' => $row['file'] |
---|
184 | ), |
---|
185 | array('start') |
---|
186 | ); |
---|
187 | } |
---|
188 | unset_make_full_url(); |
---|
189 | |
---|
190 | // Get note (depending on the calling : global OR user) |
---|
191 | $user_note = array(); |
---|
192 | $globalnote = 0; |
---|
193 | // echo "USER=".$user_id."\n"; |
---|
194 | if (!is_numeric($user_id) OR $user_id != 0) // for user |
---|
195 | { |
---|
196 | // echo "USERNON0=".$user_id."\n"; |
---|
197 | $pos = strpos($user_id, 'G'); |
---|
198 | if ($pos === false) |
---|
199 | { |
---|
200 | $globalnote = $concours->get_img_globalnote_user($row['id'], $concours_id, $user_id); |
---|
201 | $user_note = $concours->get_img_note_user($row['id'], $concours_id, $user_id); |
---|
202 | } |
---|
203 | else |
---|
204 | { |
---|
205 | // echo "G...".substr($user_id, $pos+1)." = ".substr($user_id, $pos+1)."\n"; |
---|
206 | // echo "IPGUEST=".$ipguest[substr($user_id, $pos+1)]."\n"; |
---|
207 | $globalnote = $concours->get_img_globalnote_user($row['id'], $concours_id, $conf['guest_id'], $ipguest[substr($user_id, $pos+1)]); |
---|
208 | $user_note = $concours->get_img_note_user($row['id'], $concours_id, $conf['guest_id'], $ipguest[substr($user_id, $pos+1)]); |
---|
209 | } |
---|
210 | } |
---|
211 | elseif (is_numeric($user_id) AND $user_id == 0) // for user // global |
---|
212 | { |
---|
213 | // echo "USER00=".$user_id."\n"; |
---|
214 | |
---|
215 | foreach ($user_list as $i => $userid) |
---|
216 | $globalnote += $concours->get_img_globalnote_user($row['id'], null, $userid['user_id']); |
---|
217 | |
---|
218 | foreach ($ipguest as $i => $ipguestt) |
---|
219 | { |
---|
220 | $globalnote += $concours->get_img_globalnote_user($row['id'], null, $conf['guest_id'], $ipguestt); |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | |
---|
225 | $concours_img[$row['id']] = array( |
---|
226 | 'img_id' => $row['id'], |
---|
227 | 'name' => $row['name'], |
---|
228 | 'author'=> $row['author'], |
---|
229 | 'file' => $row['file'], |
---|
230 | 'rang' => 0, |
---|
231 | 'thumb' => get_thumbnail_url($row), |
---|
232 | 'url' => $url, |
---|
233 | 'note' => $globalnote, |
---|
234 | 'moyenne' => (isset($nbvotes[$row['id']]) && $nbvotes[$row['id']] !=0 ? $globalnote/(int)$nbvotes[$row['id']] : 0), |
---|
235 | 'nbvotant' => isset($nbvotes[$row['id']]) ? $nbvotes[$row['id']] : 0 |
---|
236 | ); |
---|
237 | |
---|
238 | } |
---|
239 | /* |
---|
240 | foreach ($concours_img as $key => $value) |
---|
241 | { |
---|
242 | echo |
---|
243 | 'img_id => '.$concours_img[$key]['img_id'] |
---|
244 | .'author => '.$concours_img[$key]['author'] |
---|
245 | .'name => '.$concours_img[$key]['name'] |
---|
246 | .'file => '.$concours_img[$key]['file'] |
---|
247 | .'rang => '.$concours_img[$key]['rang'] |
---|
248 | .'thumb => '.$concours_img[$key]['thumb'] |
---|
249 | .'url => '.$concours_img[$key]['url'] |
---|
250 | .'note => '.$concours_img[$key]['note']; |
---|
251 | } |
---|
252 | */ |
---|
253 | |
---|
254 | // Ordre image by "note" or "moyenne" |
---|
255 | if ($concours->concours_infos['method'] == 1) // sum method |
---|
256 | $concours_img = array_sort($concours_img, 'note', false); |
---|
257 | elseif ($concours->concours_infos['method'] == 2) // moy method |
---|
258 | $concours_img = array_sort($concours_img, 'moyenne', false); |
---|
259 | |
---|
260 | $rang = 1; |
---|
261 | $previousNote = $previousMoy = 0; |
---|
262 | |
---|
263 | foreach ($concours_img as $key => $value) |
---|
264 | { |
---|
265 | |
---|
266 | // Check the exaequos |
---|
267 | if ($concours->my_config['check_exaequo']) |
---|
268 | { |
---|
269 | if ( ($concours->concours_infos['method'] == 1 // total |
---|
270 | AND ($concours_img[$key]['note'] == $previousNote)) |
---|
271 | OR ($concours->concours_infos['method'] == 2 // moyenne |
---|
272 | AND ($concours_img[$key]['moyenne'] == $previousMoy))) |
---|
273 | { |
---|
274 | $rang --; |
---|
275 | |
---|
276 | } |
---|
277 | } |
---|
278 | // echo "RANG=".$rang."\n"; |
---|
279 | $concours_img[$key]['rang'] = $rang; |
---|
280 | |
---|
281 | $template->append( 'concours_note', array( |
---|
282 | 'img_id' => $concours_img[$key]['img_id'], |
---|
283 | 'author' => $concours_img[$key]['author'], |
---|
284 | 'name' => $concours_img[$key]['name'], |
---|
285 | 'file' => $concours_img[$key]['file'], |
---|
286 | 'rang' => $concours_img[$key]['rang'], |
---|
287 | 'thumb' => $concours_img[$key]['thumb'], |
---|
288 | 'url' => $concours_img[$key]['url'], |
---|
289 | 'note' => $concours_img[$key]['note'], |
---|
290 | 'moyenne' => $concours_img[$key]['moyenne'], |
---|
291 | 'nbvotant' => $concours_img[$key]['nbvotant'] |
---|
292 | |
---|
293 | )); |
---|
294 | $rang++; |
---|
295 | |
---|
296 | $previousNote = $concours_img[$key]['note']; |
---|
297 | $previousMoy = $concours_img[$key]['moyenne']; |
---|
298 | } |
---|
299 | |
---|
300 | } |
---|
301 | |
---|
302 | |
---|
303 | |
---|
304 | |
---|
305 | if (isset($_POST['submit'])) { |
---|
306 | } |
---|
307 | |
---|
308 | |
---|
309 | $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/audit.tpl'); |
---|
310 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
311 | |
---|
312 | |
---|
313 | // Function to sort the array |
---|
314 | // asc = false ==> descendant |
---|
315 | function array_sort($array, $key, $asc=true) |
---|
316 | { |
---|
317 | foreach ($array as $i => $o) |
---|
318 | { |
---|
319 | $sort_values[$i] = $array[$i][$key]; |
---|
320 | |
---|
321 | } |
---|
322 | if ($asc) |
---|
323 | asort ($sort_values); |
---|
324 | else |
---|
325 | arsort ($sort_values); |
---|
326 | reset ($sort_values); |
---|
327 | |
---|
328 | |
---|
329 | while (list ($arr_key, $arr_val) = each ($sort_values)) |
---|
330 | { |
---|
331 | $sorted_arr[] = $array[$arr_key]; |
---|
332 | } |
---|
333 | |
---|
334 | unset($array); |
---|
335 | return $sorted_arr; |
---|
336 | } |
---|
337 | |
---|
338 | |
---|
339 | ?> |
---|