Changeset 1076 for trunk


Ignore:
Timestamp:
12/13/09 18:05:25 (2 years ago)
Author:
gcosmin
Message:

Constraints for virtual contests.

Solves ticket #372.
Review URL: http://reviewboard.infoarena.ro/r/116/

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/common.php

    r1074 r1076  
    7878define("IA_TLF_TRIED", '2'); 
    7979define("IA_TLF_SOLVED", '3'); 
     80 
     81// Constants for IA user-defined rounds 
     82// Users can't create rounds lasting 123141231223 hours 
     83define("IA_USER_DEFINED_ROUND_DURATION_LIMIT", '48'); 
     84// Users can't create rounds 5412312421 days before the round starts 
     85define("IA_USER_DEFINED_ROUND_DAYSBEFORE_LIMIT", '30'); 
     86// Users can't create user defined rounds with too many problems 
     87define("IA_USER_DEFINED_ROUND_TASK_LIMIT", '25'); 
    8088 
    8189// Windows hack for checkdnsrr function. 
  • trunk/common/round.php

    r1046 r1076  
    5151function round_validate_parameters($round_type, $parameters) { 
    5252    $errors = array(); 
    53     if ($round_type == 'classic' or $round_type == 'user-defined') { 
     53    if ($round_type == 'classic' or $round_type == 'user-defined' 
     54            or $round_type == 'archive') { 
    5455        // Check duration 
    5556        $duration = getattr($parameters, 'duration'); 
     
    5758            $errors['duration'] = "Durata trebuie specificata"; 
    5859        } 
     60 
     61        if ($round_type == 'user-defined') { 
     62            if ($duration > IA_USER_DEFINED_ROUND_DURATION_LIMIT) { 
     63                $errors['duration'] = "Durata maxim admisa este de " . 
     64                    IA_USER_DEFINED_ROUND_DURATION_LIMIT . " ore"; 
     65            } 
     66        } 
     67 
    5968        if (!is_numeric($duration) || $duration < 0) { 
    6069            $errors['duration'] = "Durata trebuie sa fie un numar pozitiv"; 
    6170        } 
    62     } elseif ($round_type == 'archive') { 
    63         // Empty... 
    6471    } else { 
    6572        log_error("Bad round_type"); 
     
    119126    if (!is_db_date(getattr($round, 'start_time', db_date_format()))) { 
    120127        $errors['start_time'] = "Timpul trebuie specificat ca YYYY-MM-DD HH:MM:SS"; 
     128    } else { 
     129        if ($round['type'] == 'user-defined') { 
     130            $current_time = db_date_parse(date("Y-m-d H:i:s")); 
     131            $round_time = db_date_parse($round['start_time']); 
     132 
     133            if (($round_time - $current_time) > 
     134                    IA_USER_DEFINED_ROUND_DAYSBEFORE_LIMIT * 60 * 60 * 24) { 
     135                $errors['start_time'] = "Nu poti creea o runda cu mai mult de " 
     136                    . IA_USER_DEFINED_ROUND_DAYSBEFORE_LIMIT . " zile inainte"; 
     137            } 
     138        } 
    121139    } 
    122140 
  • trunk/www/controllers/round.php

    r1069 r1076  
    116116    // Validate task list. 
    117117    $new_round_tasks = $values['tasks']; 
     118 
    118119    if (!is_array($new_round_tasks)) { 
    119120        $errors['tasks'] = 'Valori invalide.'; 
     
    130131        } 
    131132    } 
     133 
     134    if (request_is_post() && count($values['tasks']) == 0) { 
     135        $errors['tasks'] = "Trebuie sa alegi cel putin o problema"; 
     136    } 
     137 
     138    // Additional validation for user defined tasks 
     139    if (!array_key_exists('tasks', $errors) 
     140        && $values['type'] == 'user-defined' && 
     141        count($values['tasks']) > IA_USER_DEFINED_ROUND_TASK_LIMIT) { 
     142            $errors['tasks'] = "Nu poti alege mai mult de " . 
     143            IA_USER_DEFINED_ROUND_TASK_LIMIT . " probleme"; 
     144        } 
     145 
    132146    if (array_key_exists('tasks', $errors)) { 
    133147        $values['tasks'] = array(); 
Note: See TracChangeset for help on using the changeset viewer.