[6768] | 1 | <?php |
---|
| 2 | if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 3 | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[9975] | 5 | // Modification des résultats |
---|
[6768] | 6 | // +-----------------------------------------------------------------------+ |
---|
[9200] | 7 | if (isset($_POST['results_modify'])) { |
---|
| 8 | pwg_query("DELETE FROM " . CR_TABLE_2 . " WHERE `contest_id` = " . $_GET['contest_id'] .";"); |
---|
[6768] | 9 | |
---|
[9745] | 10 | $registered_ids = array(); |
---|
| 11 | $_DUPLICATE = array(); |
---|
| 12 | |
---|
[9975] | 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 | );"); |
---|
[9745] | 33 | |
---|
[9975] | 34 | } else { |
---|
| 35 | $_DUPLICATE[] = $data; |
---|
| 36 | } |
---|
[9745] | 37 | } |
---|
[6768] | 38 | } |
---|
| 39 | |
---|
[9745] | 40 | if (isset($_GET['redirect']) AND $_GET['redirect'] == 'page') { |
---|
[9975] | 41 | redirect(CR_PUBLIC . $_GET['contest_id'] . '-' . str2url(trigger_event('render_category_name', get_contest_name($_GET['contest_id']))) . '#results'); |
---|
[9745] | 42 | } else if (!isset($_DUPLICATE)) { |
---|
| 43 | $page['infos'][] = l10n('CR_results_saved'); |
---|
| 44 | } |
---|
[6768] | 45 | } |
---|
| 46 | |
---|
| 47 | // +-----------------------------------------------------------------------+ |
---|
[9975] | 48 | // Affichage des résultats |
---|
[6768] | 49 | // +-----------------------------------------------------------------------+ |
---|
[9745] | 50 | |
---|
| 51 | if (!get_contest_name($_GET['contest_id'])) { |
---|
| 52 | redirect(CR_ADMIN .'-manage&msg=errors.notavailable'); |
---|
[9419] | 53 | |
---|
[9745] | 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)); |
---|
[9200] | 58 | |
---|
[9745] | 59 | $template->assign(array( |
---|
[9975] | 60 | 'NAME' => trigger_event('render_category_name', $contest['name']), |
---|
[9745] | 61 | 'CONTEST_ID' => $_GET['contest_id'] |
---|
| 62 | )); |
---|
[6768] | 63 | |
---|
[9975] | 64 | // Résultats en double |
---|
[9745] | 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 | } |
---|
[6768] | 94 | |
---|
[9975] | 95 | // Résultats enregistrés |
---|
[9745] | 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 | ); |
---|
[9200] | 105 | |
---|
[9745] | 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)) { |
---|
[9975] | 112 | $data['TN_SRC'] = 'admin/themes/default/icon/errors.png'; |
---|
[9745] | 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); |
---|
[6782] | 123 | } |
---|
[9745] | 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'); |
---|
[6768] | 130 | } |
---|
| 131 | |
---|
| 132 | ?> |
---|