1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | global $template, $user, $tpl_var; |
---|
5 | |
---|
6 | |
---|
7 | $page['title'] = 'Global Concours'; |
---|
8 | |
---|
9 | // Display all photo with criterias in 1 global page. |
---|
10 | |
---|
11 | $ap_id = explode('concours_vote/' , $_SERVER['REQUEST_URI']); |
---|
12 | $id_concours = $ap_id[1]; |
---|
13 | |
---|
14 | |
---|
15 | $sortby = (isset($_GET['concours_sort_order']) ? $_GET['concours_sort_order'] : 'score'); |
---|
16 | |
---|
17 | if (isset($_POST['concours_SORT_submit']) OR isset($_POST['concours_submit'])) |
---|
18 | { |
---|
19 | $sortby = $_POST['concours_sort_order']; |
---|
20 | // echo 'sortby='.$sortby; |
---|
21 | $template->assign('sort_order',$sortby); |
---|
22 | } |
---|
23 | |
---|
24 | $template->assign('sort_order',$sortby); |
---|
25 | |
---|
26 | $img_array = array(); |
---|
27 | |
---|
28 | $user['ipguest'] = null; |
---|
29 | if (is_a_guest()) |
---|
30 | { |
---|
31 | if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) |
---|
32 | $IP = $_SERVER['HTTP_X_FORWARDED_FOR']; |
---|
33 | elseif(isset($_SERVER['HTTP_CLIENT_IP'])) |
---|
34 | $IP = $_SERVER['HTTP_CLIENT_IP']; |
---|
35 | else |
---|
36 | $IP = $_SERVER['REMOTE_ADDR']; |
---|
37 | |
---|
38 | // store ip |
---|
39 | $user['ipguest'] = $IP; |
---|
40 | } |
---|
41 | |
---|
42 | $concours = new Concours($id_concours); |
---|
43 | |
---|
44 | if (isset($concours->my_config['active_global_score_page']) AND $concours->my_config['active_global_score_page']) // only if option is activated |
---|
45 | { |
---|
46 | $concours_maxnote = $concours->get_concours_maxnote($id_concours); |
---|
47 | |
---|
48 | if (strtotime($concours->concours_infos['end_date'])-time() < 0) // Concours finished |
---|
49 | { |
---|
50 | } |
---|
51 | elseif (strtotime($concours->concours_infos['begin_date'])-time() > 0) |
---|
52 | { |
---|
53 | $template->assign('begin_concours_min', (strtotime($concours->concours_infos['begin_date'])-time())); |
---|
54 | $template->assign('deadline_type',$concours->my_config['concours_deadline']); |
---|
55 | $template->assign('begin_concours', $concours->concours_infos['begin_date']); |
---|
56 | } |
---|
57 | else |
---|
58 | { |
---|
59 | |
---|
60 | $authorized_groups = explode(',', $concours->concours_infos['groups']); |
---|
61 | if ( (!empty($concours->user_groups && array_intersect($concours->user_groups, $authorized_groups) != array())) |
---|
62 | OR (is_a_guest() AND $concours->concours_infos['guest']) |
---|
63 | OR !is_a_guest() |
---|
64 | ) |
---|
65 | { |
---|
66 | |
---|
67 | $template->assign('end_concours', $concours->concours_infos['end_date']); |
---|
68 | $template->assign('end_concours_min', (strtotime($concours->concours_infos['end_date'])-time())); |
---|
69 | $template->assign('deadline_type',$concours->my_config['concours_deadline']); |
---|
70 | |
---|
71 | $template->assign( 'CONCOURS', array( |
---|
72 | 'ID' => $concours->concours_infos['id'], |
---|
73 | 'NAME' => $concours->concours_infos['name'], |
---|
74 | 'DESCR' => $concours->concours_infos['descr'], |
---|
75 | 'BEGIN_DATE' => $concours->concours_infos['begin_date'], |
---|
76 | 'END_DATE' => $concours->concours_infos['end_date'], |
---|
77 | 'end_concours', $concours->concours_infos['end_date'], |
---|
78 | 'end_concours_min', (strtotime($concours->concours_infos['end_date'])-time()), |
---|
79 | 'deadline_type',$concours->my_config['concours_deadline'] |
---|
80 | )); |
---|
81 | |
---|
82 | |
---|
83 | $category = $concours->concours_infos['category']; |
---|
84 | |
---|
85 | $query = 'SELECT DISTINCT(img.id) AS id, img.name, img.file, img.path, img.author, |
---|
86 | ic.category_id, cat.name AS catname, ' |
---|
87 | .' conc.id as concours_id' |
---|
88 | .' FROM ' . IMAGES_TABLE.' AS img' |
---|
89 | .' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON img.id = ic.image_id' |
---|
90 | .' INNER JOIN '.CATEGORIES_TABLE.' AS cat ON ic.category_id = cat.id' |
---|
91 | .' INNER JOIN '.CONCOURS_TABLE.' AS conc ON conc.category = cat.id' |
---|
92 | .' WHERE ic.category_id = '.$concours->concours_infos['category'] |
---|
93 | .' AND conc.id = '.$concours->concours_infos['id'] |
---|
94 | // .' AND time_to_sec(TIMEDIFF(now(), conc.end_date)) < 0' |
---|
95 | ; |
---|
96 | |
---|
97 | $query .=';'; |
---|
98 | |
---|
99 | $result = pwg_query($query); |
---|
100 | $array_note_user = array(); |
---|
101 | |
---|
102 | while ($row = pwg_db_fetch_array($result)) |
---|
103 | { |
---|
104 | |
---|
105 | |
---|
106 | if ( !$concours->check_img_user($row['id'])) |
---|
107 | { |
---|
108 | |
---|
109 | // link on picture.php page |
---|
110 | set_make_full_url(); |
---|
111 | if ( isset($row['category_id']) & isset($row['catname']) ) |
---|
112 | { |
---|
113 | $url = duplicate_picture_url( |
---|
114 | array( |
---|
115 | 'image_id' => $row['id'], |
---|
116 | 'image_file' => $row['file'], |
---|
117 | 'category' => array( |
---|
118 | 'id' => $row['category_id'], |
---|
119 | 'name' => $row['catname'], |
---|
120 | 'permalink' => '' |
---|
121 | ) |
---|
122 | ), |
---|
123 | array('start') |
---|
124 | ); |
---|
125 | } |
---|
126 | else |
---|
127 | { |
---|
128 | $url = duplicate_picture_url( |
---|
129 | array( |
---|
130 | 'image_id' => $row['id'], |
---|
131 | 'image_file' => $row['file'] |
---|
132 | ), |
---|
133 | array('start') |
---|
134 | ); |
---|
135 | } |
---|
136 | unset_make_full_url(); |
---|
137 | |
---|
138 | |
---|
139 | $firstcriterias = $concours->get_firstlevel_criterias($concours->concours_infos['id']); |
---|
140 | |
---|
141 | |
---|
142 | // save all note |
---|
143 | if (isset($_POST['concours_submit'])) |
---|
144 | { |
---|
145 | // array_push($page['infos'] , l10n('concours_vote_saved')); |
---|
146 | $user_note = ""; |
---|
147 | // DEBUG |
---|
148 | if ($this->debug) echo "SUBMIT"; |
---|
149 | // END DEBUG |
---|
150 | |
---|
151 | // concat all the notes to save on db |
---|
152 | foreach ($firstcriterias as $criteria) |
---|
153 | { |
---|
154 | // First without sub criterias |
---|
155 | if (!$concours->is_criterias_contains_sub($criteria['criteria_id'],$concours->concours_infos['id'] )) |
---|
156 | { |
---|
157 | if (isset($_POST[$row['id']."_".$criteria['criteria_id']])) // vote present |
---|
158 | { |
---|
159 | // Check value |
---|
160 | $value = str_replace(",",".",(isset($_POST[$row['id']."_".$criteria['criteria_id']]) ? $_POST[$row['id']."_".$criteria['criteria_id']] : floatval($criteria['min_value']))); |
---|
161 | $value = str_replace(" ","",$value); |
---|
162 | $value = floatval($value); |
---|
163 | if ($value < floatval($criteria['min_value'])) |
---|
164 | $value = floatval($criteria['min_value']); |
---|
165 | if ($value > floatval($criteria['max_value'])) |
---|
166 | $value = floatval($criteria['max_value']); |
---|
167 | |
---|
168 | $user_note .= (strlen($user_note) != 0 ? ";" : "").$criteria['criteria_id']."=".$value; |
---|
169 | } |
---|
170 | } |
---|
171 | else |
---|
172 | { |
---|
173 | $secondcriterias = $concours->get_subcriterias($criteria['criteria_id'], $concours->concours_infos['id'] ); |
---|
174 | foreach ($secondcriterias as $subcriteria) |
---|
175 | { |
---|
176 | if (isset($_POST[$row['id']."_".$subcriteria['criteria_id']])) // vote present |
---|
177 | { |
---|
178 | |
---|
179 | // Check value |
---|
180 | $value = str_replace(",",".",(isset($_POST[$row['id']."_".$subcriteria['criteria_id']]) ? $_POST[$row['id']."_".$subcriteria['criteria_id']] : floatval($subcriteria['min_value']))); |
---|
181 | $value = str_replace(" ","",$value); |
---|
182 | $value = floatval($value); |
---|
183 | if ($value < floatval($subcriteria['min_value'])) |
---|
184 | $value = floatval($subcriteria['min_value']); |
---|
185 | if ($value > floatval($subcriteria['max_value'])) |
---|
186 | $value = floatval($subcriteria['max_value']); |
---|
187 | |
---|
188 | $user_note .= (strlen($user_note) != 0 ? ";" : "").$subcriteria['criteria_id']."=".$value; |
---|
189 | } |
---|
190 | } |
---|
191 | } |
---|
192 | } |
---|
193 | |
---|
194 | if ($user_note != "") // store only if criterias are presents |
---|
195 | { |
---|
196 | $concours->store_img_note_user($row['id'], $user_note, $concours->concours_infos['id'], $user['ipguest']); |
---|
197 | // comment on global page |
---|
198 | $concours->store_img_comment_user($row['id'], $_POST[$row['id'].'_concours_comment'], $concours->concours_infos['id'], $user['ipguest']); |
---|
199 | } |
---|
200 | } |
---|
201 | |
---|
202 | |
---|
203 | |
---|
204 | $user_notes = $concours->get_img_note_user($row['id'], $row['concours_id'], $user['id'], $user['ipguest']); |
---|
205 | |
---|
206 | $real_criteria_nb = 0; |
---|
207 | |
---|
208 | foreach ($firstcriterias as $criteria) |
---|
209 | { |
---|
210 | // First without sub criterias |
---|
211 | if (!$concours->is_criterias_contains_sub($criteria['criteria_id'],$concours->concours_infos['id'] )) |
---|
212 | { |
---|
213 | // echo "---1---<br>\n"; |
---|
214 | $array_note_user[$row['id']][$criteria['criteria_id']] = array( |
---|
215 | 'nosub' => true, |
---|
216 | 'level' => 1, |
---|
217 | 'id' => $criteria['criteria_id'], // id du critere |
---|
218 | 'name' => $criteria['name'], // id du critere |
---|
219 | 'lib' => $criteria['descr'], //.'(min='$criteria['min_value'].';max='.$criteria['min_value'].')', // libelle du critrer |
---|
220 | 'val' => (isset($user_notes[$criteria['criteria_id']])?$user_notes[$criteria['criteria_id']] : $criteria['min_value']), // valeur du critere |
---|
221 | 'min' => $criteria['min_value'], // min |
---|
222 | 'max' => $criteria['max_value'] // max |
---|
223 | ); |
---|
224 | $real_criteria_nb ++; |
---|
225 | } |
---|
226 | else |
---|
227 | { |
---|
228 | // echo "---2---criteriaID=".$criteria['criteria_id']."<br>\n"; |
---|
229 | |
---|
230 | $secondcriterias = $concours->get_subcriterias($criteria['criteria_id'], $concours->concours_infos['id'] ); |
---|
231 | foreach ($secondcriterias as $subcriteria) |
---|
232 | { |
---|
233 | // echo "---3---<br>\n"; |
---|
234 | // DEBUG |
---|
235 | $array_note_user[$row['id']][$subcriteria['criteria_id']] = array( |
---|
236 | 'nosub' => true, |
---|
237 | 'level' => 2, |
---|
238 | 'id' => $subcriteria['criteria_id'], // id du critere |
---|
239 | 'name' => $criteria['name'].' : '.$subcriteria['name'], // id du critere |
---|
240 | 'lib' => $subcriteria['descr'], //.'(min='$criteria['min_value'].';max='.$criteria['min_value'].')', // libelle du critrer |
---|
241 | 'val' => (isset($user_notes[$subcriteria['criteria_id']])?$user_notes[$subcriteria['criteria_id']] : $subcriteria['min_value']), |
---|
242 | 'min' => $subcriteria['min_value'], // min |
---|
243 | 'max' => $subcriteria['max_value'] // max |
---|
244 | ); |
---|
245 | $real_criteria_nb ++; |
---|
246 | |
---|
247 | } |
---|
248 | } |
---|
249 | } |
---|
250 | |
---|
251 | $user_global_note = $concours->get_img_globalnote_user($row['id'], $concours->concours_infos['id'], $user['id'], $user['ipguest']); |
---|
252 | |
---|
253 | array_push($img_array, array( |
---|
254 | 'img_id' => $row['id'], |
---|
255 | 'name' => $row['name'], |
---|
256 | 'file' => $row['file'], |
---|
257 | 'author' => $row['author'], |
---|
258 | 'thumb' => DerivativeImage::url(IMG_XSMALL, $row), |
---|
259 | |
---|
260 | 'url' => $url, |
---|
261 | 'score' => $array_note_user[$row['id']] , |
---|
262 | 'max_note' => $concours_maxnote, |
---|
263 | 'note' => ($user_global_note >= 0 ? $user_global_note : 0), |
---|
264 | 'concours_comment' => $concours->get_img_comment_user($row['id'], $concours->concours_infos['id'], $user['id'], $user['ipguest']), |
---|
265 | 'change_note' => ($user_global_note == -1 OR $concours->my_config['concours_change_score']) ? true : false, |
---|
266 | |
---|
267 | )); |
---|
268 | |
---|
269 | |
---|
270 | /* |
---|
271 | $template->append( 'concours_note', array( |
---|
272 | 'img_id' => $row['id'], |
---|
273 | 'name' => $row['name'], |
---|
274 | 'file' => $row['file'], |
---|
275 | 'author' => $row['author'], |
---|
276 | 'thumb' => DerivativeImage::url(IMG_XSMALL, $row), |
---|
277 | |
---|
278 | 'url' => $url, |
---|
279 | 'score' => $array_note_user[$row['id']] , |
---|
280 | 'max_note' => $concours_maxnote, |
---|
281 | 'note' => ($user_global_note >= 0 ? $user_global_note : 0), |
---|
282 | 'concours_comment' => $concours->get_img_comment_user($row['id'], $concours->concours_infos['id'], $user['id'], $user['ipguest']), |
---|
283 | 'change_note' => ($user_global_note == -1 OR $concours->my_config['concours_change_score']) ? true : false, |
---|
284 | |
---|
285 | )); |
---|
286 | */ |
---|
287 | } |
---|
288 | |
---|
289 | } |
---|
290 | |
---|
291 | /* |
---|
292 | foreach ($img_array as $i=>$img) |
---|
293 | { |
---|
294 | echo "<br>;i=".$i; |
---|
295 | foreach ($img as $j=>$value) |
---|
296 | echo "<br>j=".$j." ->".$value.' ;'; |
---|
297 | |
---|
298 | } |
---|
299 | */ |
---|
300 | // Order photo by score |
---|
301 | if ($sortby == 'score') |
---|
302 | { |
---|
303 | foreach (array_sort($img_array, 'note', SORT_DESC) as $i=>$img) |
---|
304 | $template->append( 'concours_note', $img); |
---|
305 | } |
---|
306 | else |
---|
307 | { |
---|
308 | foreach ($img_array as $i=>$img) |
---|
309 | $template->append( 'concours_note', $img); |
---|
310 | } |
---|
311 | |
---|
312 | // $template->append( 'concours_note', array_sort($img_array, 'note', SORT_DESC)); |
---|
313 | |
---|
314 | $template->assign( 'TEXT_OVERLAY', $concours->my_config['text_overlay']); |
---|
315 | $template->assign('NB_CRITERIAS_CONCOURS', ( isset($real_criteria_nb) ? $real_criteria_nb : 0)); |
---|
316 | // Envoi de la page |
---|
317 | |
---|
318 | } |
---|
319 | } |
---|
320 | |
---|
321 | $template->assign( 'SCORE_MODE', $concours->my_config['score_mode']); |
---|
322 | |
---|
323 | $template->assign('IMG_URL', CONCOURS_IMG_PATH); |
---|
324 | |
---|
325 | $template->set_filenames(array('concours_vote' => CONCOURS_ROOT.'/template/concours_vote.tpl')); |
---|
326 | $template->concat('PLUGIN_INDEX_CONTENT_BEGIN', $template->parse('concours_vote', true)); |
---|
327 | |
---|
328 | |
---|
329 | $template->assign('PLUGIN_INDEX_ACTIONS' , ' |
---|
330 | <li><a href="' . make_index_url() . '" title="' . l10n('return to homepage') . '"> |
---|
331 | <img src="' . $template->get_themeconf('icon_dir') . '/home.png" class="button" alt="' . l10n('home') . '"/></a> |
---|
332 | </li>'); |
---|
333 | |
---|
334 | if (is_admin()) |
---|
335 | { |
---|
336 | $template->assign('U_EDIT', PHPWG_ROOT_PATH . 'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&concours=' . $id_concours.'&action=edit'); |
---|
337 | } |
---|
338 | |
---|
339 | $template->clear_assign(array('U_MODE_POSTED', 'U_MODE_CREATED')); |
---|
340 | } |
---|
341 | |
---|
342 | |
---|
343 | |
---|
344 | function array_sort($array, $on, $order=SORT_ASC) |
---|
345 | { |
---|
346 | $new_array = array(); |
---|
347 | $sortable_array = array(); |
---|
348 | |
---|
349 | if (count($array) > 0) { |
---|
350 | foreach ($array as $k => $v) { |
---|
351 | if (is_array($v)) { |
---|
352 | foreach ($v as $k2 => $v2) { |
---|
353 | if ($k2 == $on) { |
---|
354 | $sortable_array[$k] = $v2; |
---|
355 | } |
---|
356 | } |
---|
357 | } else { |
---|
358 | $sortable_array[$k] = $v; |
---|
359 | } |
---|
360 | } |
---|
361 | |
---|
362 | switch ($order) { |
---|
363 | case SORT_ASC: |
---|
364 | asort($sortable_array); |
---|
365 | break; |
---|
366 | case SORT_DESC: |
---|
367 | arsort($sortable_array); |
---|
368 | break; |
---|
369 | } |
---|
370 | |
---|
371 | foreach ($sortable_array as $k => $v) { |
---|
372 | $new_array[$k] = $array[$k]; |
---|
373 | } |
---|
374 | } |
---|
375 | |
---|
376 | return $new_array; |
---|
377 | } |
---|
378 | |
---|
379 | ?> |
---|