1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
4 | include_once CONCOURS_PATH.'/stuffs_module/functions.inc.php'; |
---|
5 | |
---|
6 | global $template; |
---|
7 | |
---|
8 | // Publish the result on a global page. |
---|
9 | // Mode global ==> simply display global result |
---|
10 | // Mode full ==> display global result and user notations |
---|
11 | |
---|
12 | $ap_id = explode('concours/' , $_SERVER['REQUEST_URI']); |
---|
13 | $id_concours = $ap_id[1]; |
---|
14 | |
---|
15 | $user['ipguest'] = null; |
---|
16 | if (is_a_guest()) |
---|
17 | { |
---|
18 | if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) |
---|
19 | $IP = $_SERVER['HTTP_X_FORWARDED_FOR']; |
---|
20 | elseif(isset($_SERVER['HTTP_CLIENT_IP'])) |
---|
21 | $IP = $_SERVER['HTTP_CLIENT_IP']; |
---|
22 | else |
---|
23 | $IP = $_SERVER['REMOTE_ADDR']; |
---|
24 | |
---|
25 | // store ip |
---|
26 | $user['ipguest'] = $IP; |
---|
27 | } |
---|
28 | |
---|
29 | |
---|
30 | |
---|
31 | $concours = new Concours($id_concours); |
---|
32 | |
---|
33 | $template->assign( 'CONCOURS', array( |
---|
34 | 'ID' => $concours->concours_infos['id'], |
---|
35 | 'NAME' => $concours->concours_infos['name'], |
---|
36 | 'DESCR' => $concours->concours_infos['descr'], |
---|
37 | 'BEGIN_DATE' => $concours->concours_infos['begin_date'], |
---|
38 | 'END_DATE' => $concours->concours_infos['end_date'], |
---|
39 | 'METHOD' => l10n("concours_method".$concours->concours_infos['method']), |
---|
40 | 'METHODNB' => $concours->concours_infos['method'], |
---|
41 | 'DAYS' => NbJours($concours->concours_infos['begin_date'], $concours->concours_infos['end_date']), |
---|
42 | 'NB_VOTANT' => count($concours->get_user_list($concours->concours_infos['id']))+count($concours->get_guest_list($concours->concours_infos['id'])), |
---|
43 | 'NBIMG' => $concours->nb_img_by_concours($concours->concours_infos['id']) |
---|
44 | |
---|
45 | )); |
---|
46 | |
---|
47 | |
---|
48 | $category = $concours->concours_infos['category']; |
---|
49 | |
---|
50 | if (!(isset($concours->concours_infos['method']))) |
---|
51 | $concours->concours_infos['method'] = 1; |
---|
52 | |
---|
53 | $query = 'SELECT DISTINCT(img.id), img.name, img.file, img.path, img.author, img.added_by, |
---|
54 | ic.category_id, cat.name AS catname, conc.note, conc.moyenne, conc.moderation1, conc.moderation2, conc.nbvotant' |
---|
55 | .' FROM ' . IMAGES_TABLE.' AS img' |
---|
56 | .' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON img.id = ic.image_id' |
---|
57 | .' INNER JOIN '.CATEGORIES_TABLE.' AS cat ON ic.category_id = cat.id' |
---|
58 | .' INNER JOIN '.CONCOURS_RESULT_TABLE.' AS conc ON conc.img_id = img.id' |
---|
59 | .' WHERE ic.category_id = '.$concours->concours_infos['category'] |
---|
60 | .' AND conc.id_concours = '.$concours->concours_infos['id']; |
---|
61 | |
---|
62 | |
---|
63 | switch ($concours->concours_infos['method']) |
---|
64 | { |
---|
65 | case 1 :// total |
---|
66 | $query .= ' ORDER BY note DESC'; |
---|
67 | break; |
---|
68 | case 2 :// moyenne |
---|
69 | $query .= ' ORDER BY moyenne DESC'; |
---|
70 | break; |
---|
71 | case 3 :// moderation1 |
---|
72 | $query .= ' ORDER BY moderation1 DESC'; |
---|
73 | break; |
---|
74 | case 4 :// moderation2 |
---|
75 | $query .= ' ORDER BY moderation2 DESC'; |
---|
76 | break; |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | $query .=';'; |
---|
81 | // .' ORDER by note DESC;'; |
---|
82 | $result = pwg_query($query); |
---|
83 | $rang = 1; |
---|
84 | $previousNote = $previousMoy = 0; |
---|
85 | while ($row = pwg_db_fetch_array($result)) |
---|
86 | { |
---|
87 | // link on picture.php page |
---|
88 | set_make_full_url(); |
---|
89 | if ( isset($row['category_id']) & isset($row['catname']) ) |
---|
90 | { |
---|
91 | $url = duplicate_picture_url( |
---|
92 | array( |
---|
93 | 'image_id' => $row['id'], |
---|
94 | 'image_file' => $row['file'], |
---|
95 | 'category' => array( |
---|
96 | 'id' => $row['category_id'], |
---|
97 | 'name' => $row['catname'], |
---|
98 | 'permalink' => '' |
---|
99 | ) |
---|
100 | ), |
---|
101 | array('start') |
---|
102 | ); |
---|
103 | } |
---|
104 | else |
---|
105 | { |
---|
106 | $url = duplicate_picture_url( |
---|
107 | array( |
---|
108 | 'image_id' => $row['id'], |
---|
109 | 'image_file' => $row['file'] |
---|
110 | ), |
---|
111 | array('start') |
---|
112 | ); |
---|
113 | } |
---|
114 | unset_make_full_url(); |
---|
115 | |
---|
116 | // Check the exaequos |
---|
117 | if ($concours->my_config['check_exaequo']) |
---|
118 | { |
---|
119 | if ( ($concours->concours_infos['method'] == 1 // total |
---|
120 | AND ($row['note'] == $previousNote)) |
---|
121 | OR ($concours->concours_infos['method'] == 2 // moyenne |
---|
122 | AND ($row['moyenne'] == $previousMoy)) |
---|
123 | OR ($concours->concours_infos['method'] == 3 // moderation1 |
---|
124 | AND ($row['moderation1'] == $previousMoy)) |
---|
125 | OR ($concours->concours_infos['method'] == 4 // moderation2 |
---|
126 | AND ($row['moderation2'] == $previousMoy))) |
---|
127 | |
---|
128 | { |
---|
129 | // echo "Rang=".$rang."\n"; |
---|
130 | $rang --; |
---|
131 | |
---|
132 | } |
---|
133 | } |
---|
134 | $usernote = $concours->get_img_globalnote_user($row['id'], null, null, $user['ipguest']); |
---|
135 | $template->append( 'concours_note', array( |
---|
136 | 'img_id' => $row['id'], |
---|
137 | 'name' => $row['name'], |
---|
138 | 'file' => $row['file'], |
---|
139 | 'author' => (strlen($row['author']) === 0 ? get_username($row['added_by']): $row['author']), |
---|
140 | 'addedby' => get_username($row['added_by']), |
---|
141 | 'rang' => $rang, |
---|
142 | // 'thumb' => DerivativeImage::thumb_url($row), |
---|
143 | 'thumb' => DerivativeImage::url(IMG_XXSMALL, $row), |
---|
144 | 'url' => $url, |
---|
145 | 'note' => ($row['note'] == 0 ? 'N/A' :$row['note']), |
---|
146 | 'moyenne' => ($row['moyenne'] == 0 ? 'N/A' : round($row['moyenne'] , 2)), |
---|
147 | 'moderation1' => ($row['moderation1'] == 0 ? 'N/A' : round($row['moderation1'], 2) ), |
---|
148 | 'moderation2' => ($row['moderation2'] == 0 ? 'N/A' : round($row['moderation2'], 2)), |
---|
149 | 'nbvotant' => $row['nbvotant'], |
---|
150 | 'usernote' => ($usernote < 0 ? "N/A" : $usernote) |
---|
151 | |
---|
152 | )); |
---|
153 | $rang ++; |
---|
154 | |
---|
155 | // echo "Rang=".$rang."\n"; |
---|
156 | $previousNote = $row['note']; |
---|
157 | $previousMoy = $row['moyenne']; |
---|
158 | |
---|
159 | } |
---|
160 | // Envoi de la page |
---|
161 | $template->assign(array( |
---|
162 | 'TITLE' => "Concours : ".$concours->concours_infos['name'])); |
---|
163 | |
---|
164 | $template->assign('IMG_URL', CONCOURS_IMG_PATH); |
---|
165 | |
---|
166 | $template->set_filenames(array('concours_result' => CONCOURS_ROOT.'/template/result.tpl')); |
---|
167 | $template->concat('PLUGIN_INDEX_CONTENT_BEGIN', $template->parse('concours_result', true)); |
---|
168 | |
---|
169 | |
---|
170 | $template->assign('PLUGIN_INDEX_ACTIONS' , ' |
---|
171 | <li><a href="' . make_index_url() . '" title="' . l10n('return to homepage') . '"> |
---|
172 | <img src="' . $template->get_themeconf('icon_dir') . '/home.png" class="button" alt="' . l10n('home') . '"/></a> |
---|
173 | </li>'); |
---|
174 | |
---|
175 | if (is_admin()) |
---|
176 | { |
---|
177 | $template->assign('U_EDIT', PHPWG_ROOT_PATH . 'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&concours=' . $id_concours.'&action=edit'); |
---|
178 | } |
---|
179 | |
---|
180 | $template->clear_assign(array('U_MODE_POSTED', 'U_MODE_CREATED')); |
---|
181 | |
---|
182 | |
---|
183 | ?> |
---|