source: extensions/ContestResults/admin/results.php @ 9975

Last change on this file since 9975 was 9975, checked in by mistic100, 13 years ago
  • many corrections
File size: 4.2 KB
Line 
1<?php
2if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4// +-----------------------------------------------------------------------+
5//                              Modification des résultats
6// +-----------------------------------------------------------------------+
7if (isset($_POST['results_modify'])) {
8        pwg_query("DELETE FROM " . CR_TABLE_2 . " WHERE `contest_id` = " . $_GET['contest_id'] .";");
9       
10        $registered_ids = array();
11        $_DUPLICATE = array();
12       
13        if (isset($_POST['results'])) {
14                foreach ($_POST['results'] AS $i => $data) {
15                        if (!in_array($data['image_id'], $registered_ids)) {
16                                $registered_ids[] = $data['image_id'];
17                               
18                                pwg_query("INSERT INTO " . CR_TABLE_2 . "
19                                        (
20                                                image_id,
21                                                contest_id,
22                                                rank,
23                                                comment,
24                                                author
25                                        )
26                                        VALUES(
27                                                '" . $data['image_id'] ."',
28                                                '" . $_GET['contest_id'] ."',
29                                                '" . $data['rank'] ."',
30                                                '" . $data['comment'] ."',
31                                                '" . $data['author'] . "'
32                                        );");
33                       
34                        } else {
35                                $_DUPLICATE[] = $data;
36                        }
37                }
38        }
39       
40        if (isset($_GET['redirect']) AND $_GET['redirect'] == 'page') {
41                redirect(CR_PUBLIC . $_GET['contest_id'] . '-' . str2url(trigger_event('render_category_name', get_contest_name($_GET['contest_id']))) . '#results');
42        } else if (!isset($_DUPLICATE)) {
43                $page['infos'][] = l10n('CR_results_saved');
44        }
45}
46
47// +-----------------------------------------------------------------------+
48//                              Affichage des résultats
49// +-----------------------------------------------------------------------+
50
51if (!get_contest_name($_GET['contest_id'])) {
52        redirect(CR_ADMIN .'-manage&amp;msg=errors.notavailable');
53       
54} else {
55        // Nom du concours
56        $query = "SELECT name FROM " . CR_TABLE_1 . " WHERE id = " . $_GET['contest_id'] . ";";
57        $contest = pwg_db_fetch_assoc(pwg_query($query));
58
59        $template->assign(array(
60                'NAME' => trigger_event('render_category_name', $contest['name']),
61                'CONTEST_ID' => $_GET['contest_id']
62        ));
63
64        // Résultats en double
65        if (isset($_DUPLICATE)) {
66                foreach ($_DUPLICATE AS $result) {
67                        $data = array(
68                                'RANK' => 0,
69                                'IMAGE_ID' => $result['image_id'],
70                                'AUTHOR' => $result['author'],
71                                'COMMENT' => $result['comment'],
72                                'ERROR' => true,
73                        );
74                       
75                        // Infos de l'image
76                        $image = pwg_query("SELECT id, name, file, path, tn_ext
77                                FROM " . IMAGES_TABLE . "
78                                WHERE id = " . $result['image_id'] . ";");
79                       
80                        if (!pwg_db_num_rows($image)) {
81                                $themeconf = $template->get_template_vars('themeconf');
82                                $data['TN_SRC'] = $themeconf['admin_icon_dir'] . '/errors.png';
83                                $data['IMAGE_NAME'] = 'N/A';           
84                        } else {
85                                $image = pwg_db_fetch_assoc($image);
86                                $data['TN_SRC'] = get_thumbnail_url($image);
87                                $data['IMAGE_NAME'] = (empty($image['name'])) ? get_name_from_file($image['file']) : $image['name'];
88                        }
89                       
90                        $page['errors'][] = l10n_dec('CR_duplicate_result %d', 'CR_duplicate_result %d', $result['image_id']);
91                        $template->append('results', $data);
92                }
93        }
94
95        // Résultats enregistrés
96        $results = pwg_query("SELECT * FROM " . CR_TABLE_2 . " WHERE contest_id = " . $_GET['contest_id'] . " ORDER BY rank;");
97
98        while ($result = pwg_db_fetch_assoc($results)) {
99                $data = array(
100                        'RANK' => $result['rank'],
101                        'IMAGE_ID' => $result['image_id'],
102                        'AUTHOR' => $result['author'],
103                        'COMMENT' => $result['comment'],
104                );
105               
106                // Infos de l'image
107                $image = pwg_query("SELECT id, name, file, path, tn_ext
108                        FROM " . IMAGES_TABLE . "
109                        WHERE id = " . $result['image_id'] . ";");
110               
111                if (!pwg_db_num_rows($image)) {
112                        $data['TN_SRC'] = 'admin/themes/default/icon/errors.png';
113                        $data['IMAGE_NAME'] = 'N/A';
114                        $data['ERROR'] = true;
115                        $page['errors'][] = l10n_dec('CR_id_unknown %d', 'CR_id_unknown %d', $result['image_id']);
116                } else {
117                        $image = pwg_db_fetch_assoc($image);
118                        $data['TN_SRC'] = get_thumbnail_url($image);
119                        $data['IMAGE_NAME'] = (empty($image['name'])) ? get_name_from_file($image['file']) : $image['name'];
120                }
121               
122                $template->append('results', $data);
123        }
124
125        // +-----------------------------------------------------------------------+
126        //                              Template
127        // +-----------------------------------------------------------------------+
128        $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/results.tpl'));
129        $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
130}
131
132?>
Note: See TracBrowser for help on using the repository browser.