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