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