Index: common/db/task_rating.php
===================================================================
--- common/db/task_rating.php	(revision 0)
+++ common/db/task_rating.php	(revision 0)
@@ -0,0 +1,76 @@
+<?php
+
+require_once(IA_ROOT_DIR."common/db/db.php");
+require_once(IA_ROOT_DIR."common/task_rating.php");
+
+function task_rating_get_all($task_id) {
+    $query = "SELECT user_id, idea, theory, coding FROM ia_task_ratings
+                WHERE task_id = " . db_quote($task_id);
+
+    $res = db_fetch_all($query);
+
+    return $res;
+}
+
+// Returns an array with ratings given by $user_id to $task_id
+function task_rating_get($task_id, $user_id) {
+    log_assert(is_task_id($task_id));
+    log_assert(is_user_id($user_id));
+
+    $query = sprintf("SELECT idea, theory, coding FROM ia_task_ratings
+                      WHERE task_id = %s AND user_id = %s",
+                      db_quote($task_id), db_quote($user_id));
+
+    $result = db_fetch($query);
+
+    if (!$result) {
+        $result = array(
+              'idea' => null,
+              'theory' => null,
+              'coding' => null,
+        );
+    }
+
+    return $result;
+}
+
+// Update the rating for task_id
+function task_rating_update($task_id) {
+    $res = task_rating_get_all($task_id);
+
+    $task_rating = task_rating_compute($res);
+
+    // Update the rating in db
+    $values = array(
+        'rating' => $task_rating
+    );
+    $where = "id = " . db_quote($task_id);
+
+    db_update('ia_task', $values, $where);
+}
+
+// Inserts new ratings for task_id by user user_id
+// ratings are specified in $ratings
+function task_rating_add($task_id, $user_id, $ratings) {
+    $values = array(
+        'task_id' => $task_id,
+        'user_id' => $user_id,
+        'idea' => $ratings['idea'],
+        'theory' => $ratings['theory'],
+        'coding' => $ratings['coding']
+    );
+
+    $where = "task_id = " . db_quote($task_id) . " AND user_id = " .
+                db_quote($user_id);
+
+
+    if (!db_query_value("SELECT COUNT(*) FROM ia_task_ratings WHERE $where")) {
+        db_insert('ia_task_ratings', $values);
+    } else {
+        db_update('ia_task_ratings', $values, $where);
+    }
+
+    task_rating_update($task_id);
+}
+
+?>
Index: common/security.php
===================================================================
--- common/security.php	(revision 1110)
+++ common/security.php	(working copy)
@@ -144,6 +144,7 @@
         case 'task-change-open':
         case 'textblock-change-security':
         case 'task-edit-owner':
+        case 'task-edit-ratings':
         case 'round-tag':
         case 'textblock-tag':
         case 'job-reeval':
Index: common/task_rating.php
===================================================================
--- common/task_rating.php	(revision 0)
+++ common/task_rating.php	(revision 0)
@@ -0,0 +1,36 @@
+<?php
+
+require_once(IA_ROOT_DIR."common/db/task_rating.php");
+
+// Computes the rating out of the array $ratings
+// $ratings contains arrays of ratings
+// FIXME: use smarter task rating function
+function task_rating_compute($ratings) {
+    $sum = 0;
+    $nr = 0;
+
+    foreach ($ratings as $rating) {
+        $sum += $rating['idea'] + $rating['theory'] + $rating['coding'];
+        $nr += 3;
+    }
+
+    $task_rating = 1.0 * $sum / $nr;
+
+    return $task_rating;
+}
+
+// Checks to see if a value is an int between 1 and 10.
+function task_is_rating_value($rating_value) {
+    if (!is_whole_number($rating_value)) {
+        return false;
+    }
+
+    $int_rating_value = intval($rating_value);
+    if ($int_rating_value < 1 || $int_rating_value > 10) {
+        return false;
+    }
+
+    return true;
+}
+
+?>
Index: scripts/add-db-task-ratings
===================================================================
--- scripts/add-db-task-ratings	(revision 0)
+++ scripts/add-db-task-ratings	(revision 0)
@@ -0,0 +1,24 @@
+#! /usr/bin/env php
+
+<?php
+
+// This scripts adds a new column in ia_task and new tabel for task ratings
+
+require_once(dirname($argv[0]) . "/utilities.php");
+
+db_connect();
+
+$query = "ALTER TABLE ia_task ADD COLUMN rating float";
+db_query($query);
+
+$query = "CREATE TABLE ia_task_ratings (
+    task_id VARCHAR(64) NOT NULL,
+    user_id int NOT NULL,
+    idea int NOT NULL,
+    theory int NOT NULL,
+    coding int NOT NULL,
+    PRIMARY KEY(task_id, user_id))";
+
+db_query($query);
+
+?>

Property changes on: scripts/add-db-task-ratings
___________________________________________________________________
Added: svn:executable
   + *

Index: www/controllers/task.php
===================================================================
--- www/controllers/task.php	(revision 1110)
+++ www/controllers/task.php	(working copy)
@@ -3,6 +3,7 @@
 require_once(IA_ROOT_DIR . "common/db/task.php");
 require_once(IA_ROOT_DIR . "common/task.php");
 require_once(IA_ROOT_DIR . "common/tags.php");
+require_once(IA_ROOT_DIR . "common/task_rating.php");
 
 // Displays form to either create a new task or edit an existing one.
 // This form does not edit task content (its associated textblock)
@@ -161,8 +162,8 @@
             }
             mem_cache_delete("task-authors-by-id:".$new_task["id"]);
 
-            flash("Task-ul a fost modificat cu succes.");
-            redirect(url_task_edit($task_id));
+            flash("Parametrii au fost salvati cu succes!");
+            redirect(url_task_edit($task_id, 'task-edit-params'));
         } else {
             flash_error("Sunt erori in datele introduse.");
         }
@@ -170,7 +171,7 @@
 
     // Create view.
     $view = array();
-    $view['title'] = $task_id;
+    $view['title'] = 'Editeaza parametrii pentru problema '.$task['title'];
     $view['page_name'] = url_task_edit($task_id);
     $view['task_id'] = $task_id;
     $view['task'] = $task;
@@ -223,7 +224,7 @@
             // This should never fail.
             log_assert(task_create($task, $task_params, remote_ip_info()));
             flash("Un nou task a fost creeat, acum poti sa-l editezi");
-            redirect(url_task_edit($task['id']));
+            redirect(url_task_edit($task['id'], 'task-edit-params'));
         }
     }
 
@@ -267,6 +268,59 @@
     redirect(url_home());
 }
 
+// Edit ratings for a task
+function controller_task_ratings($task_id) {
+    // Validate task id
+    if (!is_task_id($task_id)) {
+        flash_error("Problema inexistenta");
+        redirect(url_home());
+    }
+
+    // Get task
+    $task = task_get($task_id);
+    if (!$task) {
+        falsh_error("Problema inexistenta");
+        redirect(url_home());
+    }
+
+    // Security check
+    identity_require('task-edit-ratings', $task);
+    $user_id = identity_get_user_id();
+
+    // Form stuff
+    $ratings = array();
+    $errors = array();
+
+    if (request_is_post()) {
+        $rating_fields = array('idea', 'theory', 'coding');
+
+        foreach ($rating_fields as $rating_field) {
+            $rating_value = request($rating_field);
+
+            if (!task_is_rating_value($rating_value)) {
+                flash_error("Datele introduse nu sunt valide!");
+                redirect(url_task_edit($task_id, 'task-edit-ratings'));
+            }
+
+            $ratings[$rating_field] = $rating_value;
+        }
+
+        task_rating_add($task_id, $user_id, $ratings);
+
+        flash("Ratingurile au fost salvate cu succes!");
+        redirect(url_task_edit($task_id, 'task-edit-ratings'));
+    }
+
+    $ratings = task_rating_get($task_id, $user_id);
+
+    $view['title'] = "Editeaza ratingurile pentru problema " . $task['title'];
+    $view['task_id'] = $task_id;
+    $view['form_values'] = $ratings;
+    $view['form_errors'] = $errors;
+
+    execute_view_die('views/task_rating_edit.php', $view);
+}
+
 // Tag a task
 function controller_task_tag($task_id) {
     if (!is_task_id($task_id)) {
@@ -288,13 +342,13 @@
 
         if (!is_array($algorithm_tags_id)) {
             flash_error("Datele trimise sunt invalide. Raporteaza aceasta problema unui admin.");
-            redirect(url_task_edit_tags($task_id));
+            redirect(url_task_edit($task_id, 'task-edit-tags'));
         }
 
         foreach ($algorithm_tags_id as $tag_id) {
             if (!is_tag_id($tag_id)) {
                 flash_error("Datele trimise sunt invalide. Raporteaza aceasta problema unui admin.");
-                redirect(url_task_edit_tags($task_id));
+                redirect(url_task_edit($task_id, 'task-edit-tags'));
             }
         }
 
@@ -307,11 +361,12 @@
         }
         if ($count != count($algorithm_tags_id)) {
             flash_error("Datele trimise sunt invalide. Raporteaza aceasta problema unui admin.");
-            redirect(url_task_edit_tags($task_id));
+            redirect(url_task_edit($task_id, 'task-edit-tags'));
         }
 
         task_update_tags($task_id, $method_tags_id, $algorithm_tags_id);
-        flash("Tagurile au fost salvate cu succes");
+        flash("Tagurile au fost salvate cu succes!");
+        redirect(url_task_edit($task_id, 'task-edit-tags'));
     }
 
     $tags_tree = tag_build_tree(tag_get_all(array("method", "algorithm")));
Index: www/index.php
===================================================================
--- www/index.php	(revision 1110)
+++ www/index.php	(working copy)
@@ -88,18 +88,27 @@
     controller_task_search();
 }
 
-// Task detail editor
-else if ($urlstart == 'admin' && getattr($pagepath, 1) == 'problema') {
+// Task edit parameters
+else if ($urlstart == 'problema' && $action == 'task-edit-params') {
     require_once(IA_ROOT_DIR.'www/controllers/task.php');
-    $obj_id = implode("/", array_slice($pagepath, 2));
-    $action = request('action');
-    if ($action == 'tag-edit') {
-        controller_task_tag($obj_id);
-    } else {
-        controller_task_details($obj_id);
-    }
+    $task_id = implode("/", array_slice($pagepath, 1));
+    controller_task_details($task_id);
 }
 
+// Task edit tags
+else if ($urlstart == 'problema' && $action == 'task-edit-tags') {
+    require_once(IA_ROOT_DIR.'www/controllers/task.php');
+    $task_id = implode("/", array_slice($pagepath, 1));
+    controller_task_tag($task_id);
+}
+
+// Task edit ratings
+else if ($urlstart == 'problema' && $action == 'task-edit-ratings') {
+    require_once(IA_ROOT_DIR.'www/controllers/task.php');
+    $task_id = implode("/", array_slice($pagepath, 1));
+    controller_task_ratings($task_id);
+}
+
 // Task algorithm tags
 else if ($page == 'admin/task-tags') {
     require_once(IA_ROOT_DIR.'www/controllers/task_tags.php');
Index: www/url.php
===================================================================
--- www/url.php	(revision 1110)
+++ www/url.php	(working copy)
@@ -254,16 +254,11 @@
     return url_complex("problema/$task_id");
 }
 
-function url_task_edit($task_id) {
+function url_task_edit($task_id, $action = 'edit') {
     log_assert(is_task_id($task_id));
-    return url_complex("admin/problema/$task_id");
+    return url_complex("problema/$task_id", array('action' => $action));
 }
 
-function url_task_edit_tags($task_id) {
-    log_assert(is_task_id($task_id));
-    return url_complex("admin/problema/{$task_id}", array( 'action' => 'tag-edit'));
-}
-
 function url_task_create() {
     return url_complex("admin/problema-noua");
 }
Index: www/views/task_edit.php
===================================================================
--- www/views/task_edit.php	(revision 1110)
+++ www/views/task_edit.php	(working copy)
@@ -2,6 +2,7 @@
 require_once(IA_ROOT_DIR."common/task.php");
 require_once(IA_ROOT_DIR."common/tags.php");
 require_once(IA_ROOT_DIR."www/format/form.php");
+require_once(IA_ROOT_DIR."www/views/task_edit_header.php");
 
 $view['head'] = getattr($view, 'head').
     "<script type=\"text/javascript\" src=\"" . html_escape(url_static("js/parameditor.js")) . "\"></script>";
@@ -9,6 +10,8 @@
 include('views/header.php');
 include('views/tags_header.php');
 
+echo task_edit_tabs($view['task_id'], request("action"));
+
 // Validate task.
 log_assert_valid(task_validate($task));
 
@@ -94,7 +97,8 @@
 
 ?>
 
-<h1>Editare <a href="<?= html_escape(url_task($view['task_id'])) ?>"><?= html_escape($view['title']) ?></a></h1>
+<h1>Editare parametri <a href="<?= html_escape(url_task($view['task_id'])) ?>">
+<?= html_escape($view['task_id']) ?></a></h1>
 
 <?php if (identity_can("task-delete", $task)) { ?>
 <form action="<?= html_escape(url_task_delete()) ?>" method="post" style="float: right">
@@ -103,7 +107,7 @@
 </form>
 <?php } ?>
 
-<form action="<?= html_escape(url_task_edit($task_id)) ?>"
+<form action="<?= html_escape(url_task_edit($task_id, 'task-edit-params')) ?>"
       method="post"
       class="task"
       <?= tag_form_event() ?>>
Index: www/views/task_edit_header.php
===================================================================
--- www/views/task_edit_header.php	(revision 0)
+++ www/views/task_edit_header.php	(revision 0)
@@ -0,0 +1,32 @@
+<?php
+
+require_once(IA_ROOT_DIR . "www/format/format.php");
+require_once(IA_ROOT_DIR . "www/format/list.php");
+require_once(IA_ROOT_DIR . "www/url.php");
+
+function task_edit_tabs($task_id, $active) {
+    $tabs = array();
+
+    $tab_names = array('edit' => 'Enunț',
+                       'task-edit-params' => 'Parametri',
+                       'task-edit-tags' => 'Taguri',
+                       'task-edit-ratings' => 'Ratinguri');
+
+    $permissions = array('edit' => 'task-edit',
+                         'task-edit-params' => 'task-edit',
+                         'task-edit-tags' => 'task-tag',
+                         'task-edit-ratings' => 'task-edit-ratings');
+
+    $task = task_get($task_id);
+    foreach ($tab_names as $action => $text) {
+        if (identity_can($permissions[$action], $task)) {
+            $tabs[$action] = format_link(
+                                url_task_edit($task_id, $action), $text);
+        }
+    }
+    $tabs[$active] = array($tabs[$active], array('class' => 'active'));
+
+    return format_ul($tabs, 'htabs');
+}
+
+?>
Index: www/views/task_rating_edit.php
===================================================================
--- www/views/task_rating_edit.php	(revision 0)
+++ www/views/task_rating_edit.php	(revision 0)
@@ -0,0 +1,55 @@
+<?php
+
+require_once(IA_ROOT_DIR . "www/format/form.php");
+require_once(IA_ROOT_DIR . "www/views/task_edit_header.php");
+
+include('views/header.php');
+
+echo task_edit_tabs($view['task_id'], request("action"));
+
+$form_fields = array(
+    'idea' => array(
+            'name' => 'Rating idee',
+            'description' => 'Notă pentru ideea de rezolvare.',
+            'type' => 'string',
+    ),
+    'theory' => array(
+            'name' => 'Rating teorie',
+            'description' => 'Notă pentru noțiunile teoretice necesare.',
+            'type' => 'string',
+    ),
+    'coding' => array(
+            'name' => 'Rating implementare',
+            'description' => 'Notă pentru nivelul de implementare.',
+            'type' => 'string',
+    )
+);
+?>
+
+<h1>Editare ratinguri <a href="<?= html_escape(url_task($view['task_id'])) ?>">
+<?= html_escape($view['task_id']) ?></a></h1>
+
+<form action="<?= html_escape(url_task_edit($task_id, 'task-edit-ratings')) ?>"
+      method="post" class="task">
+<fieldset>
+<legend>Ratinguri</legend>
+<ul class="form">
+<?php
+    echo view_form_field_li($form_fields['idea'], 'idea');
+    echo view_form_field_li($form_fields['theory'], 'theory');
+    echo view_form_field_li($form_fields['coding'], 'coding');
+?>
+</ul>
+</fieldset>
+
+<div class="submit">
+    <ul class="form">
+        <li id="field_submit">
+            <input type="submit" value="Salveaza" id="form_submit"
+                   class="button important" />
+        </li>
+    </ul>
+</div>
+</form>
+
+<?php include('views/footer.php');
Index: www/views/task_tag_edit.php
===================================================================
--- www/views/task_tag_edit.php	(revision 1110)
+++ www/views/task_tag_edit.php	(working copy)
@@ -1,11 +1,17 @@
 <?php
+    require_once(IA_ROOT_DIR."www/views/task_edit_header.php");
+
     include('header.php');
+    $task_id = $view['task']['id'];
     $task_link = url_task($view['task']['id']);
     $task_title = $view['task']['title'];
-    $action_link = url_task_edit_tags($view['task']['id']);
+    $action_link = url_task_edit($view['task']['id'], 'task-edit-tags');
     $task_tags = $view['task_tags'];
+
+    echo task_edit_tabs($task_id, request("action"));
 ?>
-<h1>Taguri pentru problema <a href="<?= $task_link ?>"><?= $task_title ?></a></h1>
+
+<h1>Editare taguri <a href="<?= $task_link ?>"><?= $task_id ?></a></h1>
 <form name="task_tags" action="<?= $action_link ?>" method="post">
 <?php
     $tags_tree = $view['tags_tree'];
@@ -27,7 +33,7 @@
         echo "</ul>";
     }
 ?>
-<input type="submit" class="button important" value="Submit" />
+<input type="submit" class="button important" value="Salveaza" />
 </form>
 
 <?php include('footer.php'); ?>
Index: www/views/textblock_edit.php
===================================================================
--- www/views/textblock_edit.php	(revision 1110)
+++ www/views/textblock_edit.php	(working copy)
@@ -5,7 +5,16 @@
 
 include('views/header.php');
 include('views/tags_header.php');
+
+// insert task edit tabs
+if (($task_id = textblock_security_is_task($page['security'])) &&
+    (identity_can('task-edit', task_get($task_id)))) {
+    require_once(IA_ROOT_DIR."www/views/task_edit_header.php");
+    echo task_edit_tabs($task_id, request("action"));
 ?>
+<h1>Editare enunț <a href="<?= html_escape(url_task($task_id)) ?>">
+<?= html_escape($task_id) ?></a></h1>
+<?php } ?>
 
 <form accept-charset="utf-8" action="<?= html_escape(url_textblock_edit($page_name)) ?>" method="post" id="form_wikiedit" <?= tag_form_event() ?>>
 <input type="hidden" id="form_page_name" value="<?= html_escape(isset($page_name) ? $page_name : '') ?>" />
Index: www/views/textblock_header.php
===================================================================
--- www/views/textblock_header.php	(revision 1110)
+++ www/views/textblock_header.php	(working copy)
@@ -5,22 +5,18 @@
 // Check view parameters.
 require_once(IA_ROOT_DIR . "common/textblock.php");
 log_assert_valid(textblock_validate($textblock));
- 
 ?>
 <div id="wikiOps">
     <ul>
-<?php if (($task_id = textblock_security_is_task($textblock['security'])) && identity_can('task-edit', $task = task_get($task_id))) { ?>
-<li><?= format_link_access(url_task_edit($task['id']), 'Editează parametrii', 'p') ?></li>
+<?php if (($task_id = textblock_security_is_task($textblock['security'])) &&
+          identity_can('task-edit', $task = task_get($task_id))) { ?>
+<li><?= format_link_access(url_task_edit($task['id']), 'Editează', 'e') ?></li>
+<?php } elseif(identity_can('textblock-edit', $textblock)) { ?>
+<li><?= format_link_access(url_textblock_edit($textblock['name']), 'Editează', 'e') ?></li>
 <?php } ?>
-<?php if ($task_id && identity_can('task-tag', $task)) { ?>
-<li><?= format_link_access(url_task_edit_tags($task['id']), 'Editează tag-uri', 't') ?></li>
-<?php } ?>
 <?php if (($round_id = textblock_security_is_round($textblock['security'])) && identity_can('round-edit', $round = round_get($round_id))) { ?>
-<li><?= format_link_access(url_round_edit($round['id']), 'Editează parametrii', 'p') ?></li>
+<li><?= format_link_access(url_round_edit($round['id']), 'Editează parametri', 'p') ?></li>
 <?php } ?>
-<?php if (identity_can('textblock-edit', $textblock)) { ?>
-<li><?= format_link_access(url_textblock_edit($textblock['name']), ($task_id) ? 'Editează enunţ' : 'Editează', 'e') ?></li>
-<?php } ?>
 <?php if (identity_can('textblock-history', $textblock)) { ?>
 <li><?= format_link_access(url_textblock_history($textblock['name']), 'Istoria', 'i') ?></li>
 <?php } ?>
