Changeset 1006
- Timestamp:
- 02/28/09 18:14:02 (3 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 8 edited
-
common/db/round.php (modified) (4 diffs)
-
common/round.php (modified) (6 diffs)
-
common/security.php (modified) (4 diffs)
-
scripts/migrate-virtual-contest (added)
-
tests/round.php (modified) (9 diffs)
-
www/controllers/round.php (modified) (9 diffs)
-
www/macros/macro_roundlist.php (added)
-
www/static/css/screen.css (modified) (1 diff)
-
www/static/images/hourglass.png (added)
-
www/static/images/run.png (added)
-
www/views/round_create.php (modified) (1 diff)
-
www/views/round_edit.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/common/db/round.php
r997 r1006 179 179 $values[] = "('".db_escape($round_id)."', '".db_escape($task_id)."')"; 180 180 } 181 $query = "INSERT INTO ia_round_task (round_id, task_id) 181 $query = "INSERT INTO ia_round_task (round_id, task_id) 182 182 VALUES ". implode(', ', $values); 183 183 db_query($query); … … 230 230 231 231 // Returs list of registred user to round $round_id, order by rating 232 // round can be 232 // round can be 233 233 function round_get_registered_users_range($round_id, $start, $range) 234 234 { … … 312 312 $query = <<<SQL 313 313 SELECT * FROM `ia_round` 314 WHERE `state` != 'running' AND 315 `start_time` <= '%s' AND 314 WHERE `state` != 'running' AND 315 `start_time` <= '%s' AND 316 316 DATE_ADD(`start_time`, INTERVAL ($duration_subquery) * 60 * 60 SECOND) > '%s' 317 317 LIMIT 1 … … 370 370 } 371 371 372 function round_get_many($options) { 373 $field_list = "`ia_round`.*"; 374 $where = Array(); 375 if (getattr($options, "name_regexp")) { 376 $where[] = "`ia_round`.`id` REGEXP " . db_quote($options["name_regexp"]); 377 } 378 if (getattr($options, "type")) { 379 $where[] = "`ia_round`.`type` = " . db_quote($options["type"]); 380 } 381 382 // Add a join for username. 383 $join = ""; 384 if (getattr($options, 'username', false) == true) { 385 $field_list .= ", `ia_user`.`username` AS `user_name`" . 386 ", `ia_user`.`full_name` AS `user_fullname`" . 387 ", `ia_user`.`rating_cache` AS `user_rating`"; 388 $join = "LEFT JOIN ia_user ON `ia_round`.`user_id` = `ia_user`.`id`"; 389 } 390 391 if (strtolower(getattr($options, "order", "desc") == "desc")) { 392 $order = "DESC"; 393 } else { 394 $order = "ASC"; 395 } 396 397 $limit = db_quote(getattr($options, "limit", 50)); 398 $offset = db_quote(getattr($options, "offset", 0)); 399 400 if (!empty($where)) { 401 $where = " WHERE (" . implode(") AND (", $where) . ")"; 402 } else { 403 $where = ""; 404 } 405 406 $query = "SELECT $field_list FROM `ia_round` $join $where"; 407 $query .= " ORDER BY `ia_round`.`start_time` $order, `ia_round`.`id` $order"; 408 $query .= " LIMIT $offset, $limit"; 409 410 $rounds = db_fetch_all($query); 411 412 if (getattr($options, "get_count")) { 413 $query = "SELECT COUNT(*) FROM `ia_round` $where"; 414 $rounds["count"] = db_fetch($query); 415 $rounds["count"] = array_pop($rounds["count"]); 416 } 417 418 return $rounds; 419 } 420 372 421 ?> -
trunk/common/round.php
r911 r1006 7 7 'classic' => 'Concurs clasic', 8 8 'archive' => 'Arhiva de pregatire', 9 'user-defined' => 'Concurs virtual', 9 10 ); 10 11 } … … 27 28 'type' => 'bool', 28 29 ), 29 ),30 ), 30 31 'archive' => array( 31 32 'duration' => array( … … 35 36 'type' => 'float', 36 37 ), 37 ), 38 ); 38 ), 39 'user-defined' => array( 40 'duration' => array( 41 'name' => 'Durata', 42 'description' => "Durata concursului, in ore", 43 'default' => '4.5', 44 'type' => 'float', 45 ), 46 ), 47 ); 39 48 } 40 49 … … 42 51 function round_validate_parameters($round_type, $parameters) { 43 52 $errors = array(); 44 if ($round_type == 'classic' ) {53 if ($round_type == 'classic' or $round_type == 'user-defined') { 45 54 // Check duration 46 55 $duration = getattr($parameters, 'duration'); … … 69 78 'state' => 'waiting', 70 79 'start_time' => NULL, 71 'public_eval' => (($round_type == 'archive') ? 1 : 0) 80 'public_eval' => (($round_type == 'archive') ? 1 : 0), 81 'user_id' => $user['id'] 72 82 ); 73 83 … … 111 121 } 112 122 123 if (!is_user_id(getattr($round, 'user_id', ''))) { 124 $errors['user_id'] = "ID-ul userului este invalid"; 125 } 126 113 127 return $errors; 114 128 } -
trunk/common/security.php
r1002 r1006 129 129 case 'task-create': 130 130 case 'task-delete': 131 case 'round-edit':132 case 'round-create':133 131 case 'round-delete': 134 132 case 'textblock-delete': … … 154 152 case 'grader-download': 155 153 case 'task-submit': 154 case 'round-edit': 155 case 'round-create': 156 156 case 'round-submit': 157 157 case 'round-view-tasks': … … 449 449 switch ($action) { 450 450 case 'simple-view': 451 return true; 451 return true; 452 453 case 'round-create': 454 if ($round['type'] == 'user-defined') { 455 return $usersec != 'anonymous'; 456 } else { 457 return $is_admin; 458 } 459 460 case 'round-edit': 461 case 'simple-rev-edit': 462 if ($usersec == 'anonymous') { 463 return false; 464 } 465 if ($round['type'] == 'user-defined') { 466 return $user['id'] == $round['user_id'] || $is_admin; 467 } else { 468 return $is_admin; 469 } 452 470 453 471 case 'round-view-tasks': … … 456 474 return $round['public_eval'] == true || $is_admin; 457 475 458 case 'simple-rev-edit':459 476 case 'simple-edit': 460 477 case 'simple-critical': -
trunk/tests/round.php
r852 r1006 11 11 log_print("WARNING: This test requires the evaluator."); 12 12 13 log_print("Helper1 looks at new round page, fails");13 log_print("Helper1 looks at new round page, works"); 14 14 $res = curl_test(array( 15 15 'url' => url_round_create(), 16 16 'user' => 'test_helper1', 17 17 )); 18 log_assert($res['url'] != url_absolute(url_round_create())); 18 log_assert_equal($res['url'], url_absolute(url_round_create())); 19 20 21 log_print("Helper1 tries to create a new round, works"); 22 $res = curl_test(array( 23 'url' => url_round_create(), 24 'user' => 'test_helper1', 25 'post' => array( 26 'id' => 'tEst_Round', 27 'type' => 'user-defined', 28 ))); 29 log_assert_equal($res['url'], url_absolute(url_round_edit('tEst_Round'))); 19 30 20 31 … … 24 35 'user' => 'test_helper1', 25 36 'post' => array( 26 'id' => 'tEst_Round', 27 ))); 28 log_assert_equal($res['url'], url_absolute(url_home())); 29 30 31 log_print("Helper2 looks at round page, but it's not there"); 37 'id' => 'tEst_Round', 38 'type' => 'classic', 39 ))); 40 log_assert_equal($res['url'], url_absolute(url_round_create())); 41 42 43 log_print("Helper2 looks at round page, and it's there"); 32 44 $res = curl_test(array( 33 45 'url' => url_textblock('runda/tEst_Round'), 34 46 'user' => 'test_helper2', 35 47 )); 36 log_assert_equal($res['url'], url_absolute(url_textblock _edit('runda/test_round')));48 log_assert_equal($res['url'], url_absolute(url_textblock('runda/tEst_Round'))); 37 49 38 50 … … 45 57 46 58 47 log_print("Admin creates round .");59 log_print("Admin creates round, already exists."); 48 60 $res = curl_test(array( 49 61 'url' => url_round_create(), … … 52 64 'id' => 'tEst_Round', 53 65 ))); 54 log_assert_equal($res['url'], url_absolute(url_round_ edit('tEst_Round')));66 log_assert_equal($res['url'], url_absolute(url_round_create())); 55 67 log_assert(strstr($res['content'], 'tEst_Round')); 56 68 … … 117 129 log_assert_equal($res['url'], url_absolute(url_textblock('runda/tEst_Round'))); 118 130 log_assert(strstr($res['content'], 'xzx-round-title-xzx')); 119 log_assert(strstr($res['content'], ' <span class="round status waiting">'));131 log_assert(strstr($res['content'], 'Nu esti inscris la')); 120 132 log_assert(!strstr($res['content'], '<a href="'. 121 133 url_textblock('problema/cmmdc'))); … … 150 162 log_assert_equal($res['url'], url_absolute(url_textblock('runda/tEst_Round'))); 151 163 log_assert(strstr($res['content'], 'xzx-round-title-xzx')); 152 log_assert(strstr($res['content'], ' <span class="round status waiting">'));153 log_assert(!strstr($res['content'], ' <span class="round status running">'));154 log_assert(!strstr($res['content'], ' <span class="round status complete">'));164 log_assert(strstr($res['content'], 'Nu esti inscris la')); 165 log_assert(!strstr($res['content'], 'Nu se mai pot face inscrieri')); 166 log_assert(!strstr($res['content'], 'Runda s-a incheiat')); 155 167 log_assert(strstr($res['content'], '<a href="'. 156 168 url_textblock('problema/cmmdc'))); … … 162 174 163 175 // Yuck 164 log_print("Waiting for 4seconds...");165 usleep( 4* 1000000);176 log_print("Waiting for 5 seconds..."); 177 usleep(5 * 1000000); 166 178 167 179 … … 172 184 log_assert_equal($res['url'], url_absolute(url_textblock('runda/tEst_Round'))); 173 185 log_assert(strstr($res['content'], 'xzx-round-title-xzx')); 174 log_assert(!strstr($res['content'], '<span class="round status waiting">'), "Round still waiting"); 175 log_assert(strstr($res['content'], '<span class="round status running">')); 176 log_assert(!strstr($res['content'], '<span class="round status complete">')); 186 log_assert(!strstr($res['content'], 'Nu esti inscris la'), 187 "Round still waiting, is the evaluator ON?"); 188 log_assert(strstr($res['content'], 'Nu se mai pot face inscrieri')); 189 log_assert(!strstr($res['content'], 'Runda s-a incheiat')); 177 190 log_assert(strstr($res['content'], '<a href="'. 178 191 url_textblock('problema/cmmdc'))); … … 186 199 //test_cleanup(); 187 200 201 188 202 ?> -
trunk/www/controllers/round.php
r997 r1006 20 20 // with the user-submitted data and their corresponding errors. 21 21 function controller_round_details($round_id) { 22 // validate round_id 22 global $identity_user; 23 24 // Validate round_id 23 25 if (!is_round_id($round_id)) { 24 26 flash_error('Identificatorul rundei este invalid'); … … 35 37 // Security check 36 38 identity_require('round-edit', $round); 39 40 // Filter for available round types. 41 $round_types = array(); 42 foreach (round_get_types() as $round_type => $pretty_name) { 43 if (identity_can("round-edit", round_init('round_id', $round_type, 44 $identity_user))) 45 $round_types[$round_type] = $pretty_name; 46 } 37 47 38 48 // get parameter list for rounds (in general, not for this specific round) … … 148 158 // If posting with no errors then do the db monkey 149 159 if (request_is_post() && !$errors) { 160 // Don't forget about security. 161 identity_require("round-edit", $new_round); 150 162 // FIXME: error handling? Is that even remotely possible in php? 151 163 log_print_r($_REQUEST); … … 172 184 $view['param_infos'] = $param_infos; 173 185 $view['all_tasks'] = $all_tasks; 186 $view['round_types'] = $round_types; 174 187 175 188 execute_view_die("views/round_edit.php", $view); … … 181 194 global $identity_user; 182 195 183 // Security check. FIXME: sort of a hack.196 // Security check. 184 197 identity_require_login(); 185 identity_require("round-create",186 round_init('new_round', 'classic', $identity_user));187 198 188 199 // Form stuff. … … 193 204 $values['id'] = request('id', ''); 194 205 // FIXME: type hidden 195 $values['type'] = request('type', ' classic');206 $values['type'] = request('type', 'user-defined'); 196 207 197 208 if (request_is_post()) { … … 210 221 $values['type'], 211 222 $identity_user); 223 identity_require("round-create", $round); 212 224 $round_params = array(); 213 225 // FIXME: array_ magic? … … 223 235 redirect(url_round_edit($round['id'])); 224 236 } 237 } 238 239 // Filter for available round types. 240 $round_types = array(); 241 foreach (round_get_types() as $round_type => $pretty_name) { 242 if (identity_can("round-create", round_init("round_id", $round_type, 243 $identity_user))) 244 $round_types[$round_type] = $pretty_name; 225 245 } 226 246 … … 231 251 $view['form_values'] = $values; 232 252 $view['form_errors'] = $errors; 253 $view['round_types'] = $round_types; 233 254 234 255 execute_view_die("views/round_create.php", $view); -
trunk/www/static/css/screen.css
r997 r1006 1485 1485 } 1486 1486 1487 /* Round status icons */ 1488 .round-complete, .round-waiting, .round-running { 1489 width: 16px; 1490 height: 16px; 1491 display: block; 1492 } 1493 1494 .round-complete { 1495 width: 14px; 1496 height: 11px; 1497 background: url("../images/complete.gif"); 1498 } 1499 1500 .round-waiting { 1501 background: url("../images/hourglass.png"); 1502 } 1503 1504 .round-running { 1505 background: url("../images/run.png"); 1506 } -
trunk/www/views/round_create.php
r934 r1006 12 12 'name' => 'Tipul rundei', 13 13 'type' => 'enum', 14 'values' => round_get_types(),15 'default' => ' classic',14 'values' => $round_types, 15 'default' => 'user-defined', 16 16 ), 17 17 ); 18 18 19 19 ?> 20 21 20 <h1><?= html_escape($title) ?></h1> 22 21 -
trunk/www/views/round_edit.php
r934 r1006 55 55 'name' => 'Tipul rundei', 56 56 'type' => 'enum', 57 'values' => round_get_types(),58 'default' => ' classic',57 'values' => $round_types, 58 'default' => 'user-defined', 59 59 ), 60 60 'public_eval' => array( … … 71 71 <?php if ($round['state'] == 'running') { ?> 72 72 <div class="warning"> 73 Atentie! Runda este activa chiar acum. Orice modificare poate avea urmari neplacute .73 Atentie! Runda este activa chiar acum. Orice modificare poate avea urmari neplacute! 74 74 </div> 75 75 <?php } elseif ($round['state'] == 'waiting') { ?>
Note: See TracChangeset
for help on using the changeset viewer.
![[infoarena] development](/chrome/site/logo.png)