[8946] | 1 | <?php |
---|
| 2 | |
---|
| 3 | // To add a concours, 2 steps are needed: |
---|
| 4 | // Step 1 : action=new |
---|
| 5 | // initialize a concours and store it to database (with elements on piwigo_concours table) |
---|
| 6 | // After storage on database, step 2 is called (action=new_crit) |
---|
| 7 | // Step 2 : action=new_crit & concours_id=XX |
---|
| 8 | |
---|
| 9 | // add_concours with action=view is called only to list informations about a concours id |
---|
| 10 | // add_concours with action=modify is called to modify informations about a concours. Like creation, 2 steps are needed |
---|
| 11 | // Step 1 : action=modify & concours_id=XX |
---|
| 12 | // List informations about concours id and modify it to store to piwifo_concours table |
---|
| 13 | // Go to Step 2 (if needed by client choice ==> 2 buttons) with action=modify_crit |
---|
| 14 | // Ste 2 : action=modify_crit & concours_id=XX |
---|
| 15 | // List informations about criterias and modify them |
---|
| 16 | // Warning : different cases are possible : |
---|
| 17 | // - delete criteria ou sub criteria |
---|
| 18 | // - modify criteria ou sub criteria ( |
---|
| 19 | // - add criteria ou sub criteria |
---|
| 20 | // For all theses actions, the command is sent by _GET method |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 26 | |
---|
| 27 | global $template; |
---|
| 28 | |
---|
| 29 | include_once(CONCOURS_PATH . 'admin/functions.inc.php'); |
---|
| 30 | load_language('plugin.lang', CONCOURS_PATH); |
---|
| 31 | |
---|
| 32 | $method_list = array(l10n('concours_method1'), l10n ('concours_method2') ); |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | // test for _GET informations needed |
---|
| 36 | if (!isset($_GET['action'])) |
---|
| 37 | die('Wrong parameters...1'); |
---|
| 38 | else |
---|
| 39 | $action = $_GET['action']; |
---|
| 40 | |
---|
| 41 | |
---|
[8965] | 42 | |
---|
[8946] | 43 | |
---|
| 44 | // Month initialization for date selection... |
---|
| 45 | $month_list = $lang['month']; |
---|
| 46 | $month_list[0]='------------'; |
---|
| 47 | ksort($month_list); |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | // concours initialize |
---|
| 51 | if ($action != "new") |
---|
| 52 | { |
---|
| 53 | if (!isset($_GET['concours'])) |
---|
| 54 | die('Wrong parameters...2'); |
---|
| 55 | |
---|
| 56 | $concours_id = $_GET['concours']; |
---|
| 57 | // Get informations from base for concours_id |
---|
| 58 | $concours = new Concours($concours_id); |
---|
| 59 | } |
---|
| 60 | else // creation |
---|
| 61 | { |
---|
| 62 | $concours = new Concours(); |
---|
| 63 | $query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id |
---|
| 64 | FROM ' . CONCOURS_TABLE . ' ;'; |
---|
| 65 | list($next_element_id) = mysql_fetch_array(pwg_query($query)); |
---|
| 66 | $concours_id = $next_element_id; |
---|
| 67 | } |
---|
| 68 | |
---|
[8965] | 69 | |
---|
| 70 | // Add informations from previous pages if present |
---|
| 71 | if (isset($_GET['infos']) && isset($concours)) |
---|
| 72 | { |
---|
| 73 | $infos = $_GET['infos']; |
---|
| 74 | switch($infos) |
---|
| 75 | { |
---|
| 76 | case "1" : |
---|
| 77 | array_push($page['errors'], sprintf( l10n('concours_end_date_change_to') ,$concours->concours_infos['end_date'] )); |
---|
| 78 | break; |
---|
| 79 | |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | } |
---|
| 83 | |
---|
[8946] | 84 | |
---|
| 85 | // Add criteria |
---|
| 86 | if (isset($_POST['add'])) |
---|
| 87 | redirect( PHPWG_ROOT_PATH . 'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&id_concours=' . $concours_id.'&action=add'); |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | if (isset($_POST['submit'])) |
---|
| 91 | { |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | if ($action == "modify_crit") |
---|
[8965] | 95 | { |
---|
| 96 | $concours->infos = 0; |
---|
| 97 | redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin§ion=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php&concours=' . $concours_id.(isset($concours->infos) ? '&infos=' .$concours->infos: '')); |
---|
| 98 | // redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin§ion=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php'); |
---|
| 99 | } |
---|
[8946] | 100 | |
---|
| 101 | if ($action == "edit") |
---|
| 102 | { |
---|
| 103 | if ($concours->is_closed($concours_id) AND ! $concours->is_result_present($concours_id)) |
---|
| 104 | $concours->update_concoursfield("method", $concours_id); |
---|
| 105 | |
---|
| 106 | redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin§ion=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php'); |
---|
| 107 | } |
---|
| 108 | |
---|
[8965] | 109 | $concours->concours_infos['method'] = $_POST['concours_method']; |
---|
| 110 | |
---|
[8946] | 111 | // Step 1 : action = modify |
---|
| 112 | // Step 2 : action = modify_crit |
---|
| 113 | |
---|
| 114 | /* |
---|
| 115 | // Verify date format. |
---|
| 116 | if (!preg_match( |
---|
| 117 | "/^([2][0]\d{2})\-([0]\d|[1][0-2])\-([0-2]\d|[3][0-1])\s([0-1]\d|[2][0-3])\:[0-5]\d\:[0-5]\d$/" |
---|
| 118 | , $_POST['concours_begin_date'])) |
---|
| 119 | { |
---|
| 120 | $_POST['concours_begin_date'] = date("Y-m-d H:m:s"); |
---|
| 121 | } |
---|
| 122 | */ |
---|
| 123 | |
---|
| 124 | // Get information from form |
---|
| 125 | $concours->concours_id = $concours_id; |
---|
| 126 | $concours->concours_infos['id'] = $concours_id; |
---|
| 127 | $concours->concours_infos['name'] = $_POST['concours_name']; |
---|
| 128 | $concours->concours_infos['descr'] = $_POST['concours_descr']; |
---|
| 129 | |
---|
| 130 | // $concours->concours_infos['begin_date'] = $_POST['concours_begin_date']; |
---|
| 131 | // $concours->concours_infos['end_date'] = AjoutJours($concours->concours_infos['begin_date'],$_POST['concours_end_date'] ); |
---|
| 132 | |
---|
| 133 | $concours->concours_infos['begin_date'] = sprintf("%04d-%02d-%02d %02d:%02d:%02d",$_POST['start_year'], $_POST['start_month'], $_POST['start_day'], $_POST['start_hour'], $_POST['start_min'], 0); |
---|
| 134 | $concours->concours_infos['end_date'] = sprintf("%04d-%02d-%02d %02d:%02d:%02d",$_POST['end_year'], $_POST['end_month'], $_POST['end_day'], $_POST['end_hour'], $_POST['end_min'], 0); |
---|
| 135 | |
---|
[8965] | 136 | if ($concours->debug) |
---|
| 137 | { |
---|
| 138 | echo "BEGIN=".$concours->concours_infos['begin_date']."\n"; |
---|
| 139 | echo "END=".$concours->concours_infos['end_date']."\n"; |
---|
| 140 | sleep(5); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | $BeginToEnd = NbJours($concours->concours_infos['begin_date'], $concours->concours_infos['end_date']); |
---|
| 144 | // echo "NB=".$BeginToEnd; |
---|
| 145 | // Test if end date is lower than end date |
---|
| 146 | if ($BeginToEnd == 0) |
---|
| 147 | { |
---|
| 148 | $tBeginDate = explodeDateArray($concours->concours_infos['begin_date']); |
---|
| 149 | $tEndDate = explodeDateArray($concours->concours_infos['end_date']); |
---|
| 150 | // echo "Hour=".intval($tBeginDate[3])." / ".intval($tEndDate[3]); |
---|
| 151 | // echo "Min=".intval($tBeginDate[4])." / ".intval($tEndDate[4]); |
---|
| 152 | if ( (intval(@$tEndDate[3]) < intval(@$tBeginDate[3])) // End hour is lower than begin hour |
---|
| 153 | OR ( (intval(@$tBeginDate[3]) == intval(@$tEndDate[3])) // End hour is equal to begin hour |
---|
| 154 | AND (intval(@$tEndDate[4]) < intval(@$tBeginDate[4]))) // End min is lower than begin hour |
---|
| 155 | ) |
---|
| 156 | { |
---|
| 157 | $concours->concours_infos['end_date'] = AjoutJours ($concours->concours_infos['begin_date'], 1); |
---|
| 158 | $concours->infos = 1; // sprintf( l10n('concours_end_date_change_to') ,$concours->concours_infos['end_date'] )); |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | elseif ($BeginToEnd < 0 ) |
---|
| 162 | { |
---|
| 163 | $concours->concours_infos['end_date'] = AjoutJours ($concours->concours_infos['begin_date'], 1); |
---|
| 164 | $concours->infos = 1; // sprintf( l10n('concours_end_date_change_to') ,$concours->concours_infos['end_date'] )); |
---|
| 165 | } |
---|
| 166 | // End test date |
---|
| 167 | |
---|
[8946] | 168 | $concours->concours_infos['groups'] = (!empty($_POST['groups']) ? '"' . implode(',', $_POST['groups']) . '"' : 'NULL'); |
---|
| 169 | $concours->concours_infos['guest'] = isset($_POST['guest']); |
---|
| 170 | $concours->concours_infos['category'] = $_POST['cat_selection']; |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | switch($action) |
---|
| 175 | { |
---|
| 176 | case "edit" : |
---|
| 177 | redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin§ion=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php'); |
---|
| 178 | break; |
---|
| 179 | case "new" : |
---|
| 180 | |
---|
| 181 | $concours->save_concours(); |
---|
| 182 | $concours->get_default_criterias(); |
---|
| 183 | if ($concours->debug) sleep(5); |
---|
| 184 | // Redirect to admin |
---|
[8965] | 185 | redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin§ion=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php&tab=add_concours&action=modify_crit&concours=' . $concours_id.(isset($concours->infos) ? '&infos=' .$concours->infos: '')); |
---|
[8946] | 186 | |
---|
| 187 | break; |
---|
| 188 | case "modify" : |
---|
[8965] | 189 | $concours->update_concours(); |
---|
| 190 | redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin§ion=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php&tab=add_concours&action=modify_crit&concours=' . $concours_id.(isset($concours->infos) ? '&infos=' .$concours->infos: '')); |
---|
[8946] | 191 | |
---|
| 192 | break; |
---|
| 193 | case "modify_crit" : |
---|
[8965] | 194 | // echo "ICI";sleep(5); |
---|
| 195 | $concours->infos = 0; |
---|
| 196 | redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin§ion=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php&concours=' . $concours_id.(isset($concours->infos) ? '&infos=' .$concours->infos: '')); |
---|
[8946] | 197 | break; |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | switch($action) |
---|
| 206 | { |
---|
| 207 | // Download the file |
---|
| 208 | case "file" : |
---|
| 209 | // TODO generate csv file |
---|
| 210 | $file = $concours->generate_csv(); |
---|
| 211 | // Get the existing filename or the new one if doesnt exist |
---|
| 212 | $filename = $concours->save_file($file); |
---|
| 213 | |
---|
| 214 | redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin§ion=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php'); |
---|
| 215 | break; |
---|
| 216 | |
---|
| 217 | // Geneate result |
---|
| 218 | case "result" : |
---|
| 219 | // Generate result and save it to DB |
---|
| 220 | $concours->create_result(); |
---|
| 221 | // Generate csv file |
---|
| 222 | // 1. Simple csv file |
---|
| 223 | // $file = $concours->generate_csv(); |
---|
| 224 | // 2. Complete csv file. |
---|
| 225 | $file = $concours->generate_detail_csv(); |
---|
| 226 | // Save file to directory |
---|
| 227 | $filename = $concours->save_file($file); |
---|
| 228 | |
---|
| 229 | redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin§ion=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php'); |
---|
| 230 | break; |
---|
| 231 | |
---|
| 232 | case "del" : |
---|
| 233 | // Suppress concours and all parameters |
---|
| 234 | $concours->delete_concours(); |
---|
| 235 | redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin§ion=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php'); |
---|
| 236 | break; |
---|
| 237 | |
---|
| 238 | case "new" : |
---|
| 239 | $concours->concours_infos['groups'] = array(); |
---|
| 240 | $concours->concours_infos['category'] = ''; |
---|
| 241 | $template->assign( 'CONCOURS', array( |
---|
| 242 | 'ID' => $concours_id, |
---|
| 243 | // 'BEGIN_DATE' => date("Y-m-d H:m:s"), |
---|
| 244 | // 'END_DATE' => 15 |
---|
| 245 | )); |
---|
| 246 | |
---|
| 247 | // Init begin and end date |
---|
| 248 | $form['start_year'] = $form['end_year'] = date('Y'); |
---|
| 249 | $form['start_month'] = $form['end_month'] = date('n'); |
---|
| 250 | $form['start_day'] = $form['end_day'] = date('j'); |
---|
| 251 | |
---|
| 252 | $template->assign( |
---|
| 253 | array( |
---|
| 254 | |
---|
| 255 | 'START_DAY_SELECTED' => @$form['start_day'], |
---|
| 256 | 'START_MONTH_SELECTED' => @$form['start_month'], |
---|
| 257 | 'START_YEAR' => @$form['start_year'], |
---|
| 258 | 'START_HOUR' => '12', |
---|
| 259 | 'START_MIN' => '00', |
---|
| 260 | |
---|
| 261 | 'END_DAY_SELECTED' => @$form['end_day'], |
---|
| 262 | 'END_MONTH_SELECTED' => @$form['end_month'], |
---|
| 263 | 'END_YEAR' => @$form['end_year'], |
---|
| 264 | 'END_HOUR' => '12', |
---|
| 265 | 'END_MIN' => '00', |
---|
| 266 | ) |
---|
| 267 | ); |
---|
| 268 | |
---|
| 269 | break; |
---|
| 270 | case "modify" : |
---|
| 271 | |
---|
| 272 | /* $info_concours['groups'] |
---|
| 273 | `create_date` datetime NOT NULL, |
---|
| 274 | `name` text NOT NULL, |
---|
| 275 | `descr` varchar(255) default NULL, |
---|
| 276 | `begin_date` datetime NOT NULL, |
---|
| 277 | `end_date` datetime NOT NULL, |
---|
| 278 | `category` smallint(5) default NULL, |
---|
| 279 | `groups` varchar(255) default NULL, |
---|
| 280 | */ |
---|
| 281 | // Format group list |
---|
| 282 | $concours->concours_infos['groups'] = explode(',', $concours->concours_infos['groups']); |
---|
| 283 | |
---|
| 284 | |
---|
| 285 | $tBeginDate = explodeDateArray($concours->concours_infos['begin_date']); |
---|
| 286 | $tEndDate = explodeDateArray($concours->concours_infos['end_date']); |
---|
| 287 | |
---|
| 288 | $template->assign( 'CONCOURS', array( |
---|
| 289 | 'ID' => $concours->concours_infos['id'], |
---|
| 290 | 'NAME' => $concours->concours_infos['name'], |
---|
| 291 | 'DESCR' => $concours->concours_infos['descr'], |
---|
| 292 | 'GUEST' => ($concours->concours_infos['guest'] ? 'checked="checked"' : ''), |
---|
| 293 | // 'BEGIN_DATE' => $concours->concours_infos['begin_date'], |
---|
| 294 | // 'END_DATE' => NbJours($concours->concours_infos['begin_date'], $concours->concours_infos['end_date']) |
---|
| 295 | )); |
---|
| 296 | $template->assign( |
---|
| 297 | array( |
---|
| 298 | |
---|
| 299 | 'START_DAY_SELECTED' => @$tBeginDate[2], |
---|
| 300 | 'START_MONTH_SELECTED' => @$tBeginDate[1], |
---|
| 301 | 'START_YEAR' => @$tBeginDate[0], |
---|
| 302 | 'START_HOUR' => @$tBeginDate[3], |
---|
| 303 | 'START_MIN' => @$tBeginDate[4], |
---|
| 304 | |
---|
| 305 | 'END_DAY_SELECTED' => @$tEndDate[2], |
---|
| 306 | 'END_MONTH_SELECTED' => @$tEndDate[1], |
---|
| 307 | 'END_YEAR' => @$tEndDate[0], |
---|
| 308 | 'END_HOUR' => @$tEndDate[3], |
---|
| 309 | 'END_MIN' => @$tEndDate[4], |
---|
| 310 | ) |
---|
| 311 | ); |
---|
| 312 | |
---|
| 313 | break; |
---|
| 314 | case "modify_crit" : |
---|
| 315 | case "edit" : |
---|
| 316 | $concours->concours_infos['groups'] = explode(',', $concours->concours_infos['groups']); |
---|
| 317 | |
---|
| 318 | $tBeginDate = explodeDateArray($concours->concours_infos['begin_date']); |
---|
| 319 | $tEndDate = explodeDateArray($concours->concours_infos['end_date']); |
---|
| 320 | |
---|
| 321 | $template->assign( 'CONCOURS', array( |
---|
| 322 | 'ID' => $concours->concours_infos['id'], |
---|
| 323 | 'NAME' => $concours->concours_infos['name'], |
---|
| 324 | 'DESCR' => $concours->concours_infos['descr'], |
---|
| 325 | 'GUEST' => ($concours->concours_infos['guest'] ? 'checked="checked"' : ''), |
---|
| 326 | // 'BEGIN_DATE' => $concours->concours_infos['begin_date'], |
---|
| 327 | // 'END_DATE' => NbJours($concours->concours_infos['begin_date'], $concours->concours_infos['end_date']) |
---|
| 328 | )); |
---|
| 329 | $template->assign( |
---|
| 330 | array( |
---|
| 331 | |
---|
| 332 | 'START_DAY_SELECTED' => @$tBeginDate[2], |
---|
| 333 | 'START_MONTH_SELECTED' => @$tBeginDate[1], |
---|
| 334 | 'START_YEAR' => @$tBeginDate[0], |
---|
| 335 | 'START_HOUR' => @$tBeginDate[3], |
---|
| 336 | 'START_MIN' => @$tBeginDate[4], |
---|
| 337 | |
---|
| 338 | 'END_DAY_SELECTED' => @$tEndDate[2], |
---|
| 339 | 'END_MONTH_SELECTED' => @$tEndDate[1], |
---|
| 340 | 'END_YEAR' => @$tEndDate[0], |
---|
| 341 | 'END_HOUR' => @$tEndDate[3], |
---|
| 342 | 'END_MIN' => @$tEndDate[4], |
---|
| 343 | ) |
---|
| 344 | ); |
---|
| 345 | |
---|
| 346 | $firstcriterias = $concours->get_firstlevel_criterias(); |
---|
| 347 | foreach ($firstcriterias as $criteria) |
---|
| 348 | { |
---|
| 349 | if ($concours->debug) echo "criteriaID=".$criteria['criteria_id']."\n"; |
---|
| 350 | // First without sub criterias |
---|
| 351 | if (!$concours->is_criterias_contains_sub($criteria['criteria_id'] )) |
---|
| 352 | { |
---|
| 353 | $template->append( 'concours_criteria', array( |
---|
| 354 | 'nosub' => true, |
---|
| 355 | 'level' => 1, |
---|
| 356 | 'id' => $criteria['criteria_id'], // id du critere |
---|
| 357 | 'name' => $criteria['name'], // id du critere |
---|
| 358 | 'lib' => $criteria['descr'], //.'(min='$criteria['min_value'].';max='.$criteria['min_value'].')', // libelle du critrer |
---|
| 359 | 'min' => $criteria['min_value'], // min |
---|
| 360 | 'max' => $criteria['max_value'], // max |
---|
| 361 | 'pond' => $criteria['ponderation'], // ponderation |
---|
| 362 | 'U_EDIT' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&id_concours=' . $concours->concours_id.'&action=modify&id='.$criteria['id'], |
---|
| 363 | 'U_DELETE' => !is_adviser() ? PHPWG_ROOT_PATH . 'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&id_concours=' . $concours->concours_id.'&action=delete&id='.$criteria['id'] : '', |
---|
| 364 | 'U_ADD' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&id_concours=' . $concours->concours_id.'&action=add&upcriteria='.$criteria['criteria_id'], |
---|
| 365 | )); |
---|
| 366 | } |
---|
| 367 | else |
---|
| 368 | { |
---|
| 369 | $template->append( 'concours_criteria', array( |
---|
| 370 | 'nosub' => false, |
---|
| 371 | 'level' => 1, |
---|
| 372 | 'id' => $criteria['criteria_id'], // id du critere |
---|
| 373 | 'name' => $criteria['name'], // id du critere |
---|
| 374 | 'lib' => $criteria['descr'], |
---|
| 375 | 'U_ADD' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&id_concours=' . $concours->concours_id.'&action=add&upcriteria='.$criteria['criteria_id'], |
---|
| 376 | )); |
---|
| 377 | $secondcriterias = $concours->get_subcriterias($criteria['criteria_id'] ); |
---|
| 378 | foreach ($secondcriterias as $subcriteria) |
---|
| 379 | { |
---|
| 380 | if ($concours->debug) echo "subcriteriaID=".$criteria['criteria_id']."\n"; |
---|
| 381 | $template->append( 'concours_criteria', array( |
---|
| 382 | 'nosub' => true, |
---|
| 383 | 'level' => 2, |
---|
| 384 | 'id' => $subcriteria['criteria_id'], // id du critere |
---|
| 385 | 'name' => $subcriteria['name'], // id du critere |
---|
| 386 | 'lib' => $subcriteria['descr'], //.'(min='$criteria['min_value'].';max='.$criteria['min_value'].')', // libelle du critrer |
---|
| 387 | 'min' => $subcriteria['min_value'], // min |
---|
| 388 | 'max' => $subcriteria['max_value'], // max |
---|
| 389 | 'pond' => $subcriteria['ponderation'], // ponderation |
---|
| 390 | 'U_EDIT' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&id_concours=' . $concours->concours_id.'&action=modify&id='.$subcriteria['id'], |
---|
| 391 | 'U_DELETE' => !is_adviser() ? PHPWG_ROOT_PATH . 'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&id_concours=' . $concours->concours_id.'&action=delete&id='.$subcriteria['id'] : '', |
---|
| 392 | )); |
---|
| 393 | |
---|
| 394 | } |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | break; |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | |
---|
| 403 | |
---|
| 404 | $template->assign( 'action', $action); |
---|
| 405 | $template->assign('IMG_URL', CONCOURS_IMG_PATH); |
---|
| 406 | |
---|
| 407 | |
---|
| 408 | // Add month list to template |
---|
| 409 | $template->assign(array('month_list' => $month_list)); |
---|
| 410 | |
---|
| 411 | // Add method list to |
---|
| 412 | $i=1; |
---|
| 413 | foreach ( $method_list as $order ) //on parcours le tableau |
---|
| 414 | { |
---|
| 415 | $template->append('concours_method', |
---|
| 416 | array( 'ID' => $i, |
---|
| 417 | 'NAME' => $order, |
---|
| 418 | 'SELECTED' => (isset($concours->concours_infos['method']) && $concours->concours_infos['method'] == $i ? 'selected' : ''))); |
---|
| 419 | $i++; |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | if ($concours->is_closed($concours_id) AND !$concours->is_result_present($concours_id)) |
---|
| 423 | $template->append('result_not_generated', true); |
---|
| 424 | |
---|
| 425 | |
---|
| 426 | // Groups selection |
---|
| 427 | $groups = get_all_groups(); |
---|
| 428 | if (!empty($groups)) |
---|
| 429 | { |
---|
| 430 | $template->assign('group_perm', array('GROUPSELECTION' => get_html_groups_selection($groups, 'groups', (isset($concours->concours_infos['groups']) ? $concours->concours_infos['groups'] : array())))); |
---|
| 431 | } |
---|
| 432 | |
---|
| 433 | |
---|
| 434 | // Category selection |
---|
| 435 | $query = ' |
---|
| 436 | SELECT id, name, uppercats, global_rank |
---|
| 437 | FROM '.CATEGORIES_TABLE.';'; |
---|
| 438 | |
---|
| 439 | $result = pwg_query($query); |
---|
| 440 | $categories = array(); |
---|
| 441 | if (!empty($result)) |
---|
| 442 | { |
---|
| 443 | while ($row = mysql_fetch_assoc($result)) |
---|
| 444 | array_push($categories, $row); |
---|
| 445 | } |
---|
| 446 | usort($categories, 'global_rank_compare'); |
---|
| 447 | |
---|
| 448 | if (!empty($result)) |
---|
| 449 | { |
---|
| 450 | foreach ($categories as $cat) |
---|
| 451 | $template->append('category_selection', |
---|
| 452 | array( 'ID' => $cat['id'], |
---|
| 453 | 'NAME' => get_cat_display_name_cache($cat['uppercats'],null,false), |
---|
| 454 | 'SELECTED' => ($concours->concours_infos['category'] == $cat['id'] ? 'selected' : '') |
---|
| 455 | )); |
---|
| 456 | } |
---|
| 457 | |
---|
| 458 | |
---|
| 459 | |
---|
| 460 | $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/add_concours.tpl')); |
---|
| 461 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 462 | |
---|
| 463 | // Explode a date format ("AAAA-MM-JJ HH:hh:ss") in array |
---|
| 464 | // Array(YYYY, MM, JJ, HH, mm, ss) |
---|
| 465 | function explodeDateArray($date) { |
---|
| 466 | |
---|
| 467 | $tDeb = explode("-", substr($date,0,strpos($date, ' '))); |
---|
| 468 | $tDebH = explode(":", substr($date,strpos($date, ' ')+1)); |
---|
| 469 | |
---|
| 470 | return array($tDeb[0], $tDeb[1], $tDeb[2], $tDebH[0], $tDebH[1], $tDebH[2]); |
---|
| 471 | |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | |
---|
| 475 | // NB of days between 2 dates "AAAA-MM-JJ HH:hh:ss" |
---|
| 476 | function NbJours($debut, $fin) { |
---|
| 477 | |
---|
| 478 | $tDeb = explode("-", substr($debut,0,strpos($debut, ' '))); |
---|
| 479 | $tFin = explode("-", substr($fin,0,strpos($fin, ' '))); |
---|
| 480 | |
---|
| 481 | $diff = mktime(0, 0, 0, $tFin[1], $tFin[2], $tFin[0]) - |
---|
| 482 | mktime(0, 0, 0, $tDeb[1], $tDeb[2], $tDeb[0]); |
---|
| 483 | |
---|
| 484 | return(($diff / 86400)); |
---|
| 485 | |
---|
| 486 | } |
---|
| 487 | function AjoutJours($debut, $jours) { |
---|
| 488 | $tDeb = explode("-", substr($debut,0,strpos($debut, ' '))); |
---|
| 489 | $tDebH = explode(":", substr($debut,strpos($debut, ' ')+1)); |
---|
| 490 | $tFin = ""; |
---|
| 491 | |
---|
| 492 | $nb_ans = (int)(($jours)/365); |
---|
| 493 | $nb_mois = (int)(( ($jours)%365) / 31); |
---|
| 494 | $nb_jours = (int)(( ($jours)%365) % 31); |
---|
| 495 | |
---|
| 496 | $tFin = date("Y-m-d H:m:s", mktime($tDebH[0], $tDebH[1], $tDebH[2], $tDeb[1] + $nb_mois, $tDeb[2] + $nb_jours, $tDeb[0] + $nb_ans)); |
---|
| 497 | |
---|
| 498 | return($tFin); |
---|
| 499 | |
---|
| 500 | } |
---|
| 501 | |
---|
| 502 | |
---|
[3905] | 503 | ?> |
---|