source: extensions/ConcoursPhoto/admin/audit.php @ 4370

Last change on this file since 4370 was 4370, checked in by tiico, 14 years ago

[ConcoursPhoto] Add method selection for audit page

File size: 7.2 KB
Line 
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
8if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
9include_once(CONCOURS_PATH . 'admin/functions.inc.php');
10
11global $template;
12
13// Get the concours id if present
14if (isset($_GET['concours']))
15{
16        $concours_id = $_GET['concours'];
17        // Get informations from base for concours_id
18        $concours = new Concours($concours_id);
19
20    // Send concours info to template
21    $template->assign( 'CONCOURS', array(
22            'ID'        => $concours->concours_infos['id'],
23            'NAME'      => $concours->concours_infos['name'],
24            'DESCR'     => $concours->concours_infos['descr'],
25            'BEGIN_DATE'        => $concours->concours_infos['begin_date'],
26            'END_DATE'  => $concours->concours_infos['end_date'],
27            'METHOD'    => l10n("concours_method".$concours->concours_infos['method'])
28            ));
29
30// Step 1 : recover all the picture for the concours
31// Step 2 :For each picture, recover the global note, the number of vote, the actual rank (?),
32// Step 3 : Display theses informations
33       
34       
35        // nb of users who vote for each image (for a selected concours
36        $query = 'SELECT img_id, COUNT(DISTINCT user_id) AS NBVOTE FROM ' . CONCOURS_DATA_TABLE 
37        .' WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id )
38        .' GROUP BY img_id '
39        .';';
40                       
41        $result = pwg_query($query);
42        $nbvotes = array();
43        while ($row = mysql_fetch_assoc($result))
44        {
45                $nbvotes[$row['img_id']] = $row['NBVOTE'];
46        }
47
48        // Get all the users who have notes for the concours
49        $query = 'SELECT distinct(user_id), USER.username'
50        .' FROM ' .CONCOURS_DATA_TABLE
51        .' INNER JOIN ' . USERS_TABLE.' AS USER on USER.id = user_id'
52        .' WHERE id_concours = '.$concours_id
53        .' ORDER BY username ASC'
54        .';';
55        $result = pwg_query($query);
56        // For each user
57        $user_list = array();
58        while ($row2 = mysql_fetch_assoc($result))
59                array_push($user_list, $row2); 
60
61
62
63        // Get criteria list and
64        $criteria_list = "";
65        $firstcriterias = $concours->get_firstlevel_criterias($concours_id);
66        $ident1 = 1;
67        $criteria_number = 0;   // total number of criterias
68        foreach ($firstcriterias as $criteria)
69        {
70                // format (id:name)
71                $criteria_list .= (strlen($criteria_list) ? "," : "")
72                                                        .$ident1.":".$criteria['name']
73                                                        ."(id=".$criteria['criteria_id'].")";
74                // First wit sub criterias
75                if ($concours->is_criterias_contains_sub($criteria['criteria_id'],$concours_id ))
76                {
77                        $ident2 = 1;
78                        $secondcriterias = $concours->get_subcriterias($criteria['criteria_id'], $concours_id );
79                        foreach ($secondcriterias as $subcriteria)
80                        {
81                                // format (id:name)
82                                $criteria_list .= (strlen($criteria_list) ? "," : "")
83                                                                  .$ident1.".".$ident2
84                                                                  .":".$subcriteria['name']."(id=".$subcriteria['criteria_id'].")";
85                                $ident2 ++;
86                                $criteria_number ++;
87                        }
88                }
89                else
90                $criteria_number ++;
91                $ident1++;
92        }
93               
94
95
96        // Get images for all the selected cconcours
97               
98        $category = $concours->concours_infos['category'];
99
100        $query = 'SELECT DISTINCT(img.id), img.name, img.file, img.path, img.tn_ext, img.author ,
101                          ic.category_id, cat.name AS catname'  //, conc.note'
102                        .' FROM ' . IMAGES_TABLE.' AS img'
103                        .' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON img.id = ic.image_id'
104                        .' INNER JOIN '.CATEGORIES_TABLE.' AS cat ON ic.category_id = cat.id'
105//                      .' INNER JOIN '.CONCOURS_RESULT_TABLE.' AS conc ON conc.img_id = img.id'
106                        .' WHERE ic.category_id = '.$concours->concours_infos['category']
107//                      .' ORDER by note DESC
108                        .';';
109
110        $result = pwg_query($query);
111//      echo $query;
112        $concours_img = array();
113
114        // Recover all pictures and informations (global note
115        while ($row = mysql_fetch_assoc($result))
116        {
117                // link on picture.php page
118                set_make_full_url();
119                if ( isset($row['category_id']) & isset($row['catname']) ) 
120                {
121                        $url = duplicate_picture_url(
122                        array(
123                        'image_id' => $row['id'],
124                        'image_file' => $row['file'],
125                        'category' => array(
126                                                        'id' => $row['category_id'],
127                                                        'name' => $row['catname'],
128                                                        'permalink' => ''
129                                                  )
130                        ),
131                        array('start')
132                        );
133                }
134                else
135                {
136                        $url = duplicate_picture_url(
137                          array(
138                                'image_id' => $row['id'],
139                                'image_file' => $row['file']
140                          ),
141                          array('start')
142                        );
143                }       
144                unset_make_full_url();
145               
146                // Get note (depending on the calling : global OR user)
147                $user_note = array();
148                $globalnote = 0;
149                if (isset($_GET['user_id']))    // for user
150                {
151                        $globalnote = $concours->get_img_globalnote_user($row['id'], $concours_id, $_GET['user_id']);
152                        $user_note = $concours->get_img_note_user($row['id'], $concours_id, $_GET['user_id']);
153                }
154                else    // global
155                {
156                        foreach ($user_list as $userid)
157                        $globalnote += $concours->get_img_globalnote_user($row['id'], null, $userid['user_id']);
158                }
159
160               
161                $concours_img[$row['id']]  = array(
162                                'img_id' => $row['id'],
163                                'name'  => $row['name'],
164                                'author'=> $row['author'],
165                                'file'  => $row['file'],
166                                'rang'  => 0,
167                                'thumb' => get_thumbnail_url($row),
168                                'url'   => $url,
169                                'note'  => $globalnote,
170                'moyenne'       => (isset($nbvotes[$row['id']]) && $nbvotes[$row['id']] !=0  ? $globalnote/(int)$nbvotes[$row['id']] : 0),
171                                'nbvotant' => isset($nbvotes[$row['id']]) ? $nbvotes[$row['id']] : 0
172                                );
173
174        }
175        /*
176        foreach ($concours_img  as $key => $value)
177        {
178                echo
179                                'img_id => '.$concours_img[$key]['img_id']
180                                .'author => '.$concours_img[$key]['author']
181                                .'name  => '.$concours_img[$key]['name']
182                                .'file  => '.$concours_img[$key]['file']
183                                .'rang  => '.$concours_img[$key]['rang']
184                                .'thumb => '.$concours_img[$key]['thumb']
185                                .'url   => '.$concours_img[$key]['url']
186                                .'note  => '.$concours_img[$key]['note'];
187        }
188        */
189
190        // Ordre image by "note" or "moyenne"
191    if ($concours->concours_infos['method'] == 1) // sum method
192        $concours_img = array_sort($concours_img, 'note', false);
193    elseif ($concours->concours_infos['method'] == 2) // moy method
194        $concours_img = array_sort($concours_img, 'moyenne', false);
195   
196        $rang = 1;
197        foreach ($concours_img  as $key => $value) 
198        {
199           $concours_img[$key]['rang'] = $rang;
200                $rang++;
201
202                $template->append( 'concours_note', array(
203                                'img_id' => $concours_img[$key]['img_id'],
204                                'author' => $concours_img[$key]['author'],
205                                'name'  => $concours_img[$key]['name'],
206                                'file'  => $concours_img[$key]['file'],
207                                'rang'  => $concours_img[$key]['rang'],
208                                'thumb' => $concours_img[$key]['thumb'],
209                                'url'   => $concours_img[$key]['url'],
210                                'note'  => $concours_img[$key]['note'],
211                'moyenne'       => $concours_img[$key]['moyenne'],
212                                'nbvotant' => $concours_img[$key]['nbvotant']
213
214                        ));
215        }
216
217}
218
219
220
221
222if (isset($_POST['submit'])) { 
223}
224
225
226$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/audit.tpl');
227$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
228
229
230// Function to sort the array
231// asc =  false ==> descendant
232function array_sort($array, $key, $asc=true)
233{
234        foreach ($array as $i => $o) 
235        {
236           $sort_values[$i] = $array[$i][$key];
237
238        }
239        if ($asc)
240                asort  ($sort_values);
241        else
242                arsort ($sort_values);
243        reset ($sort_values);
244
245
246        while (list ($arr_key, $arr_val) = each ($sort_values)) 
247        {
248                 $sorted_arr[] = $array[$arr_key];
249        }
250
251        unset($array);
252        return $sorted_arr;
253}
254
255
256?>
Note: See TracBrowser for help on using the repository browser.