Index: common/db/job.php
===================================================================
--- common/db/job.php	(revision 1178)
+++ common/db/job.php	(working copy)
@@ -103,7 +103,8 @@ function job_get_by_id($job_id, $contents = false) {
                    `user`.`username` AS `user_name`, `user`.`full_name` AS `user_fullname`,
                    `task`.`id` AS `task_id`,
                    `task`.`page_name` AS `task_page_name`, task.`title` AS `task_title`,
-                   `task`.`hidden` AS `task_hidden`, `task`.`user_id` AS `task_owner_id`,
+                   `task`.`security` AS `task_security`,
+                   `task`.`user_id` AS `task_owner_id`,
                    `task`.`open_source` AS `task_open_source`,
                    `task`.`open_tests` AS `task_open_tests`,
                    `round`.`id` AS `round_id`,
@@ -130,7 +131,7 @@ function job_get_by_id($job_id, $contents = false) {
 // that relate only to ia_job table
 function job_get_range_wheres_job($filters) {
     $user = getattr($filters, 'user');
-    $task_hidden = getattr($filters, 'task_hidden');
+    $task_security = getattr($filters, 'task_security');
 
     $task = getattr($filters, 'task');
     $round = getattr($filters, 'round');
@@ -203,7 +204,7 @@ function job_get_range_wheres_job($filters) {
 // that are not related to ia_job table
 function job_get_range_wheres($filters) {
     $user = getattr($filters, 'user');
-    $task_hidden = getattr($filters, 'task_hidden');
+    $task_security = getattr($filters, 'task_security');
 
     $task = getattr($filters, 'task');
     $round = getattr($filters, 'round');
@@ -225,8 +226,9 @@ function job_get_range_wheres($filters) {
     if (!is_null($score_end) && is_whole_number($score_end)) {
         $wheres[] = sprintf("(`job`.`score` <= '%s') AND (`round`.`public_eval` = 1)", db_escape($score_end));
     }
-    if (!is_null($task_hidden) && is_whole_number($task_hidden)) {
-        $wheres[] = sprintf("`task`.`hidden` = %s", db_escape($task_hidden));
+    if (array_key_exists($task_security, task_get_security_types())) {
+        $wheres[] = sprintf("`task`.`security` = %s",
+            db_escape($task_security));
     }
 
     return $wheres;
@@ -260,7 +262,7 @@ function job_get_range($filters, $start, $range) {
             `user`.`full_name` AS `user_fullname`,
             `task`.`page_name` AS `task_page_name`,
             `task`.`title` AS `task_title`,
-            `task`.`hidden` AS `task_hidden`,
+            `task`.`security` AS `task_security`,
             `task`.`user_id` AS `task_owner_id`,
             `task`.`open_source` AS `task_open_source`,
             `round`.`page_name` AS `round_page_name`,
@@ -292,6 +294,7 @@ function job_get_range($filters, $start, $range) {
             ORDER BY `id` DESC LIMIT {$start}, {$range}";
 
         $job_ids_fetched = db_fetch_all($subquery);
+        $job_ids = array();
         foreach ($job_ids_fetched as $job_id) {
             $job_ids[] = $job_id["ID"];
         }
@@ -320,7 +323,7 @@ function job_get_count($filters) {
         FROM
             `ia_job` AS `job`";
 
-    if (getattr($filters, 'task_hidden')) {
+    if (getattr($filters, 'task_security')) {
         $query .= "
             LEFT JOIN `ia_task` AS `task` ON `job`.`task_id` = `task`.`id`";
     }
@@ -406,5 +409,3 @@ function job_test_get_public($job_id) {
         implode(", ", array_map("db_quote", array_values($test_ids))));
     return db_fetch_all($query);
 }
-
-?>
Index: common/db/round.php
===================================================================
--- common/db/round.php	(revision 1178)
+++ common/db/round.php	(working copy)
@@ -70,7 +70,7 @@ function round_recompute_score($round_id) {
         (`user_id`, `round_id`, `score`)
         VALUES ";
     $first = true;
-    foreach($rows as $row) {
+    foreach ($rows as $row) {
         $user_id = $row['user_id'];
         $score = $row['score'];
 
@@ -118,7 +118,7 @@ function round_get_tasks($round_id, $first = 0, $count = null,
               "task.`title` AS `title`, ".
               "task.`page_name` AS `page_name`, ".
               "task.`source` AS `source`, ".
-              "task.`hidden` AS `hidden`, ".
+              "task.`security` AS `security`, ".
               "task.`type` AS `type`,
                task.`open_source` AS `open_source`,
                task.`open_tests` AS `open_tests`,
@@ -179,8 +179,7 @@ function round_get_tasks($round_id, $first = 0, $count = null,
     return $res;
 }
 
-function round_get_task_count($round_id, $user_id, $filter)
-{
+function round_get_task_count($round_id, $user_id, $filter) {
     if ($user_id && $filter) {
         $filter_clause = db_get_task_filter_clause($filter, 'ia_score_user_round_task');
         $query = sprintf("SELECT COUNT(*) FROM ia_round_task " .
@@ -237,7 +236,7 @@ function round_update_task_list($round_id, $old_tasks, $tasks) {
         db_query($query);
     }
 
-    foreach($old_tasks as $task) {
+    foreach ($old_tasks as $task) {
         // Update parent round cache for old tasks
         task_get_parent_rounds($task, true);
     }
@@ -254,7 +253,7 @@ function round_update_task_list($round_id, $old_tasks, $tasks) {
         $query = "INSERT INTO ia_round_task (round_id, task_id, order_id)
                   VALUES ". implode(', ', $values);
         db_query($query);
-        foreach($tasks as $task) {
+        foreach ($tasks as $task) {
             // Update parent round cache for new tasks
             task_get_parent_rounds($task, true);
         }
@@ -309,8 +308,7 @@ function round_unregister_user($round_id, $user_id) {
 
 // Returs list of registred user to round $round_id, order by rating
 // round can be
-function round_get_registered_users_range($round_id, $start, $range)
-{
+function round_get_registered_users_range($round_id, $start, $range) {
     log_assert(is_round_id($round_id));
     log_assert(is_whole_number($start));
     log_assert(is_whole_number($range));
@@ -335,8 +333,7 @@ function round_get_registered_users_range($round_id, $start, $range)
 }
 
 // Returns number of registered users in a certain round
-function round_get_registered_users_count($round_id)
-{
+function round_get_registered_users_count($round_id) {
     log_assert(is_round_id($round_id));
 
     // FIXME: don't differentiate on $round['type']
@@ -347,30 +344,30 @@ function round_get_registered_users_count($round_id)
     return db_query_value($query);
 }
 
-// Makes all tasks visible
+// Makes all tasks protected from private
 // No error handling.
-// FIXME: task.hidden is stupid, we need proper security
 function round_unhide_all_tasks($round_id) {
     log_assert(is_round_id($round_id));
     $query = <<<SQL
 UPDATE `ia_task`
     JOIN `ia_round_task` ON `ia_round_task`.`task_id` = `ia_task`.`id`
-    SET `hidden` = 0
+    SET `security` = 'protected'
     WHERE `ia_round_task`.`round_id` = '%s'
+    AND `ia_task`.`security` = 'private'
 SQL;
     db_query(sprintf($query, db_escape($round_id)));
 }
 
-// Makes all tasks hidden
+// Makes all tasks private from protected
 // No error handling.
-// FIXME: task.hidden is stupid, we need proper security
 function round_hide_all_tasks($round_id) {
     log_assert(is_round_id($round_id));
     $query = <<<SQL
 UPDATE `ia_task`
     JOIN `ia_round_task` ON `ia_round_task`.`task_id` = `ia_task`.`id`
-    SET `hidden` = 1
+    SET `security` = 'private'
     WHERE `ia_round_task`.`round_id` = '%s'
+    AND `ia_task`.`security` = 'protected'
 SQL;
     db_query(sprintf($query, db_escape($round_id)));
 }
@@ -578,5 +575,3 @@ function round_delete($round_id) {
                       db_quote($round_id));
     db_query($query);
 }
-
-?>
Index: common/db/task.php
===================================================================
--- common/db/task.php	(revision 1178)
+++ common/db/task.php	(working copy)
@@ -220,8 +220,7 @@ function task_get_authors($task_id, $no_cache = false) {
 
 // Task filter
 // Returns only tasks that contain all the tags
-// and are in 'arhiva' or in 'arhiva-educationala'
-// Task from 'arhiva-educationala' are shown first
+// and are public
 function task_filter_by_tags($tag_ids, $scores = true, $user_id = null) {
     log_assert(is_array($tag_ids), "tag_ids must be an array");
     foreach ($tag_ids as $tag_id) {
@@ -259,8 +258,8 @@ function task_filter_by_tags($tag_ids, $scores = true, $user_id = null) {
     LEFT JOIN ia_round_task AS round_task ON round_task.task_id = ia_task.id
     LEFT JOIN ia_round AS round ON round.id = round_task.round_id
     $join_score
-    WHERE (round.id = 'arhiva' OR round.id = 'arhiva-educationala')
-        AND ia_task.hidden = '0' $tag_filter
+    WHERE ia_task.security = 'public'
+    $tag_filter
     ORDER BY round.id DESC, round_task.`order_id`";
 
     $tasks = db_fetch_all($query);
Index: common/security.php
===================================================================
--- common/security.php	(revision 1178)
+++ common/security.php	(working copy)
@@ -132,11 +132,11 @@ function security_simplify_action($action) {
         case 'task-delete':
         case 'task-tag':
         case 'task-reeval':
-        case 'task-edit-ratings': 
+        case 'task-edit-ratings':
         case 'textblock-delete':
         case 'textblock-delete-revision':
         case 'round-tag':
-        case 'round-view-progress': 
+        case 'round-view-progress':
         case 'grader-overwrite':
         case 'grader-delete':
         case 'grader-rename':
@@ -386,7 +386,7 @@ function security_task($user, $action, $task) {
     switch ($action) {
         // Read-only access.
         case 'simple-view':
-            return ($task['hidden'] == false) || $is_boss;
+            return ($task['security'] != 'private') || $is_boss;
 
         // Edit access.
         case 'simple-rev-edit':
@@ -397,14 +397,7 @@ function security_task($user, $action, $task) {
 
         // View tags
         case 'task-view-tags':
-            $in_archive = false;
-            $rounds = task_get_submit_rounds($task['id'], $user['id']);
-            foreach ($rounds as $round_id) {
-                if ($round_id == 'arhiva' || $round_id == 'arhiva-educationala') {
-                    $in_archive = true;
-                }
-            }
-            return $in_archive || $is_boss;
+            return ($task['security'] == 'public') || $is_boss;
 
         // Admin stuff:
         case 'simple-critical':
@@ -414,21 +407,7 @@ function security_task($user, $action, $task) {
             if ($usersec == 'anonymous') {
                 return false;
             }
-            if ($is_admin) {
-                return true;
-            }
-            $is_valid = true;
-            $rounds = task_get_parent_rounds($task['id']);
-            foreach ($rounds as $rid) {
-                $r = round_get($rid);
-                // You can use a task in an user defined contest ONLY IF it's
-                // not being used in a waiting or running classic contest.
-                if ($r['type'] == 'classic' && $r['state'] != 'complete') {
-                    $is_valid = false;
-                    break;
-                }
-            }
-            return ($task['hidden'] == false && $is_valid);
+            return ($task['security'] == 'public') || $is_admin;
 
         // Special: submit. Check for at least one registered contest for the task.
         // FIXME: contest logic?
@@ -450,15 +429,11 @@ function security_task($user, $action, $task) {
                 $is_running = true;
                 break;
             }
-            return ($task['hidden'] == false && $is_running);
+            return ($task['security'] != 'private' && $is_running);
 
         case 'grader-download':
-            if ($task['open_tests']) {
-                $can_view = $task['hidden'] == false;
-            } else {
-                $can_view = false;
-            }
-            return $can_view || $is_owner || $is_admin;
+            return ($task['open_tests'] && $task['security'] == 'public')
+                    || $is_boss;
 
         case 'sensitive-info':
             return $is_boss;
@@ -593,7 +568,8 @@ function security_job($user, $action, $job) {
         return $is_admin || $is_intern;
     }
 
-    $can_view_job = ($job['task_hidden'] == false) || $is_task_owner || $is_admin;
+    $can_view_job = ($job['task_security'] != 'private') || $is_task_owner
+                 || $is_admin;
     $can_view_source = ($job['task_open_source'] == true) || $is_task_owner ||
                        $is_owner || $is_admin || $is_intern;
     // make ALL solved tasks visible
@@ -633,5 +609,3 @@ function security_job($user, $action, $job) {
             log_error('Invalid job action: '.$action);
     }
 }
-
-?>
Index: common/task.php
===================================================================
--- common/task.php	(revision 1178)
+++ common/task.php	(working copy)
@@ -11,6 +11,17 @@ function task_get_types() {
     );
 }
 
+/**
+ * Get valid task security types
+ * @return array
+ */
+function task_get_security_types() {
+    return array(
+            'private' => 'Private',
+            'protected' => 'Protected',
+            'public' => 'Public');
+}
+
 // Get parameter infos.
 function task_get_parameter_infos() {
     return array(
@@ -39,7 +50,7 @@ function task_init($task_id, $task_type, $user = null) {
             'id' => $task_id,
             'type' => $task_type,
             'title' => ucfirst($task_id),
-            'hidden' => 1,
+            'security' => 'private',
             'source' => 'ad-hoc',
             'page_name' => IA_TASK_TEXTBLOCK_PREFIX . $task_id,
             'open_source' => 0,
@@ -83,9 +94,9 @@ function task_validate($task) {
         $errors['user_id'] = 'ID de utilizator invalid';
     }
 
-    $hidden = getattr($task, 'hidden');
-    if ($hidden != '0' && $hidden != '1') {
-        $errors['hidden'] = 'Se accepta doar 0/1';
+    if (!array_key_exists(getattr($task, 'security'),
+            task_get_security_types())) {
+        $errors['security'] = 'Tipul securitatii este invalid';
     }
 
     $open_source = getattr($task, 'open_source');
@@ -291,5 +302,3 @@ function task_update_tags($task_id, $method_tags_id, $algorithm_tags_id) {
         tag_add('task', $task_id, $tag_id);
     }
 }
-
-?>
Index: scripts/db-strip
===================================================================
--- scripts/db-strip	(revision 1178)
+++ scripts/db-strip	(working copy)
@@ -41,9 +41,9 @@ db_query("DELETE FROM ia_file
 log_print("Clearing all submissions.");
 db_query("UPDATE ia_job SET file_contents='--gone--'");
 
-// Delete hidden tasks.
-log_print("Deleting hidden tasks.");
-db_query("DELETE FROM ia_task where hidden = 1");
+// Delete private tasks.
+log_print("Deleting private tasks.");
+db_query("DELETE FROM ia_task WHERE security = 'private'");
 
 // Only keep first 100 tasks to keep the dump small.
 log_print("Deleting all tasks except for the first 100.");
Index: scripts/migrate-task-security
new file mode 100755
===================================================================
--- scripts/migrate-task-security	(revision 0)
+++ scripts/migrate-task-security	(working copy)
@@ -0,0 +1,26 @@
+#! /usr/bin/env php
+<?php
+require_once(dirname($argv[0]) . '/utilities.php');
+require_once(IA_ROOT_DIR . 'common/db/db.php');
+require_once(IA_ROOT_DIR . 'common/db/db_mysql.php');
+require_once(IA_ROOT_DIR . 'common/db/task.php');
+
+db_connect();
+
+$result = db_fetch('DESCRIBE `ia_task` `security`');
+if (getattr($result, 'Type') == null) {
+    // We use direct aproach because the validation form task_get_all would fail
+    $tasks = db_fetch_all("SELECT * FROM `ia_task`");
+    db_query("ALTER TABLE `ia_task` CHANGE `hidden` `security` enum('private'"
+           . ", 'protected', 'public') DEFAULT 'private'");
+
+    // We correct the security type (hidden -> private, not hidden -> public)
+    foreach ($tasks as $task) {
+        $new_security = ($task['hidden'] == 0) ? 'public' : 'private';
+        db_query(sprintf("UPDATE `ia_task` SET `security` = '%s' WHERE "
+                       . " `ia_task`.`id` = '%s'", db_escape($new_security),
+                        db_escape($task['id'])));
+    }
+
+    db_query("CREATE INDEX `by_security` ON `ia_task` (`security`)");
+}
Index: scripts/task-difficulty
===================================================================
--- scripts/task-difficulty	(revision 1178)
+++ scripts/task-difficulty	(working copy)
@@ -55,7 +55,7 @@ function cluster_rows($rows, $pivot, $valueCol = null, $subpivot = null, $reduce
 
 
 
-$query = "SELECT id FROM ia_task WHERE hidden = 0";
+$query = "SELECT id FROM ia_task WHERE security != 'private'";
 $tasks = array_values(cluster_rows(db_fetch_all($query), 'id', 'id', null, 0));
 
 $diff = array();
Index: www/controllers/job_filters.php
===================================================================
--- www/controllers/job_filters.php	(revision 1178)
+++ www/controllers/job_filters.php	(working copy)
@@ -6,7 +6,7 @@ function job_get_filters() {
     $available_filters = array('task', 'user', 'round', 'job_begin', 'job_end',
                                'job_id', 'time_begin', 'time_end', 'compiler',
                                'status', 'score_begin', 'score_end',
-                               'eval_msg', 'task_hidden', 'remote_ip_info');
+                               'eval_msg', 'task_security', 'remote_ip_info');
 
     $filters = array();
     foreach ($available_filters as $filter) {
@@ -20,4 +20,3 @@ function job_get_filters() {
     }
     return $filters;
 }
-?>
Index: www/controllers/round.php
===================================================================
--- www/controllers/round.php	(revision 1178)
+++ www/controllers/round.php	(working copy)
@@ -284,8 +284,7 @@ function controller_round_task_order($round_id) {
 }
 
 // Creates a round. Minimalist
-function controller_round_create()
-{
+function controller_round_create() {
     global $identity_user;
 
     // Security check.
@@ -297,7 +296,6 @@ function controller_round_create()
 
     // Get form values
     $values['id'] = strtolower(request('id', ''));
-    // FIXME: type hidden
     $values['type'] = request('type', 'user-defined');
 
     if (request_is_post()) {
@@ -431,5 +429,3 @@ function controller_round_delete($round_id) {
     flash('Runda a fost stearsa.');
     redirect(url_home());
 }
-
-?>
Index: www/controllers/task.php
===================================================================
--- www/controllers/task.php	(revision 1178)
+++ www/controllers/task.php	(working copy)
@@ -43,7 +43,7 @@ function controller_task_details($task_id) {
     $errors = array();
 
     // Fill in form values from request, defaults in $task
-    $fields = array('type', 'source', 'hidden', 'title', 'page_name',
+    $fields = array('type', 'source', 'security', 'title', 'page_name',
                     'open_source', 'open_tests', 'test_count', 'test_groups',
                     'evaluator', 'use_ok_files', 'public_tests');
 
@@ -111,7 +111,7 @@ function controller_task_details($task_id) {
         $errors = $task_errors;
 
         // Check security.
-        if ($new_task['hidden'] != $task['hidden']) {
+        if ($new_task['security'] != $task['security']) {
             identity_require('task-change-security', $task);
         }
 
@@ -171,7 +171,7 @@ function controller_task_details($task_id) {
 
     // Create view.
     $view = array();
-    $view['title'] = 'Editeaza parametrii pentru problema '.$task['title'];
+    $view['title'] = 'Editeaza parametrii pentru problema '. $task['title'];
     $view['page_name'] = url_task_edit($task_id);
     $view['task_id'] = $task_id;
     $view['task'] = $task;
@@ -313,6 +313,7 @@ function controller_task_ratings($task_id) {
 
     $ratings = task_rating_get($task_id, $user_id);
 
+    $view = array();
     $view['title'] = "Editeaza ratingurile pentru problema " . $task['title'];
     $view['task_id'] = $task_id;
     $view['form_values'] = $ratings;
@@ -374,7 +375,8 @@ function controller_task_tag($task_id) {
     // Get tags for task_id
     $task_tags = tag_get('task', $task_id, 'algorithm');
 
-    $view['title'] = "Editeaza tagurile pentru problema ".$task['title'];
+    $view = array();
+    $view['title'] = "Editeaza tagurile pentru problema " . $task['title'];
     $view['task'] = $task;
     $view['tags_tree'] = $tags_tree;
     $view['task_tags'] = $task_tags;
@@ -383,7 +385,7 @@ function controller_task_tag($task_id) {
 
 // Gets a list of tags from request
 // Prints a list of tasks that contain all those tags
-// Tasks must be in 'arhiva' or in 'arhiva educationala'
+// Tasks security must be public
 function controller_task_search() {
     $tags = request('tag_id', null);
     if (is_null($tags)) {
@@ -422,10 +424,9 @@ function controller_task_search() {
         $tags = tag_build_tree(tag_get_by_ids($tags));
     }
 
+    $view = array();
     $view['title'] = "Rezultatele filtrării";
     $view['tasks'] = $tasks;
     $view['tags'] = $tags;
     execute_view_die('views/task_filter_results.php', $view);
 }
-
-?>
Index: www/views/task_create.php
===================================================================
--- www/views/task_create.php	(revision 1178)
+++ www/views/task_create.php	(working copy)
@@ -8,7 +8,7 @@ $form_fields = array (
                 'type' => 'enum',
                 'values' => task_get_types(),
                 'default' => 'classic',
-        ), 
+        ),
         'id' => array(
                 'name' => 'Id-ul problemei',
                 'description' => 'Identificatorul unic si permanent al problemei.',
Index: www/views/task_edit.php
===================================================================
--- www/views/task_edit.php	(revision 1178)
+++ www/views/task_edit.php	(working copy)
@@ -37,17 +37,12 @@ $form_fields = array(
                 'name' => "Sursa",
                 'type' => 'string',
         ),
-        'hidden' => array(
-                'name' => 'Vizibilitate',
-                'description' => 'Daca problema este vizibila pentru utilizatorii '.
-                                 'de rand. Cand o runda incepe probleme devin automat '.
-                                 'vizibile',
+        'security' => array(
+                'name' => 'Securitate',
+                'description' => 'Nivelul de securitate al problemei',
                 'type' => 'enum',
-                'values' => array(
-                        '1' => 'Task ascuns',
-                        '0' => 'Task vizibil',
-                ),
-                'default' => '1',
+                'values' => task_get_security_types(),
+                'default' => 'private',
         ),
         'type' => array(
                 'name' => 'Tipul problemei',
@@ -121,7 +116,7 @@ $form_fields = array(
         <?php } ?>
         <?= view_form_field_li($form_fields['source'], 'source') ?>
         <?php if (identity_can('task-change-security', $task)) { ?>
-           <?= view_form_field_li($form_fields['hidden'], 'hidden') ?>
+           <?= view_form_field_li($form_fields['security'], 'security') ?>
         <?php } ?>
    </ul>
     </fieldset>
