Index: common/db/round.php
===================================================================
--- common/db/round.php	(revision 989)
+++ common/db/round.php	(working copy)
@@ -213,6 +213,21 @@
     return db_insert('ia_user_round', $insert_fields);
 }
 
+// Unregisters user $user_id from round $round_id
+// NOTE: This does not check if user is registered
+// Returns false if failed
+function round_unregister_user($round_id, $user_id) {
+    log_assert(is_round_id($round_id));
+    log_assert(is_user_id($user_id));
+
+    $query = sprintf("DELETE FROM `ia_user_round`".
+                     "WHERE `user_id` = %s AND `round_id` = %s",
+                     db_quote($user_id), db_quote($round_id));
+
+    db_query($query);
+    return db_affected_rows() == 1;
+}
+
 // 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)
Index: www/controllers/round_register.php
===================================================================
--- www/controllers/round_register.php	(revision 989)
+++ www/controllers/round_register.php	(working copy)
@@ -6,45 +6,46 @@
 
 // Displays form to register remote user to given round_id
 function controller_round_register($round_id) {
-    global $identity_user;
-
     if (!is_round_id($round_id)) {
         flash_error("Identificatorul rundei este invalid");
         redirect(url_home());
     }
     $round = round_get($round_id);
-    $submit = request_is_post();
 
     // check round_id & permissions
     if ($round) {
         identity_require('round-register', $round);
-    }
-    else {
+    } else {
         flash_error('Runda specificata nu exista in baza de date!');
         redirect(url_home());
     }
 
-    // check whether user is already registered
-    if (round_is_registered($round['id'], $identity_user['id'])) {
-        flash_error('Esti deja inregistrat in runda "'.$round['title'].'"!');
-        redirect(url_textblock($round['page_name']));
-    }
+    $user_is_registered = round_is_registered($round['id'], identity_get_user_id());
 
-    if ($submit) {
-        // process input
-        round_register_user($round['id'], $identity_user['id']);
-        // FIXME: should redirect to referrer
-        flash('Ai fost inregistrat la "'.$round['title'].'"!');
+    if (request_is_post()) {
+        // Toggle user's registration status
+        if (!$user_is_registered) {
+            round_register_user($round['id'], identity_get_user_id());
+            flash('Ai fost inregistrat la "'.$round['title'].'"!');
+        } else {
+            round_unregister_user($round['id'], identity_get_user_id());
+            flash('Ai fost deinregistrat de la "'.$round['title'].'"!');
+        }
         redirect(url_textblock($round['page_name']));
-    }
-    else {
-        // display form
+    } else {
+        // Display confirmation form
         $view = array(
             'round' => $round,
-            'title' => 'Inregistrare la '.$round['title'],
             'action' => url_round_register($round['id']),
         );
-        execute_view_die('views/round_register.php', $view);
+
+        if (!$user_is_registered) {
+            $view["title"] = "Inregistrare la " . $round["title"];
+            execute_view_die('views/round_register.php', $view);
+        } else {
+            $view["title"] = "Deinregistrare de la " . $round["title"];
+            execute_view_die('views/round_unregister.php', $view);
+        }
     }
 }
 
@@ -59,15 +60,14 @@
     // check round_id & permissions
     if ($round) {
         identity_require('round-register-view', $round);
-    }
-    else {
+    } else {
         flash_error('Runda specificata nu exista in baza de date!');
         redirect(url_home());
     }
 
     $options = pager_init_options();
     $view = array();
-    $view['title'] = 'Utilizatori inregistrati la '.$round['title'];
+    $view['title'] = 'Utilizatori inregistrati la ' . $round['title'];
     $view['round'] = $round;
     $view['users'] = round_get_registered_users_range($round['id'], 
                      $options['first_entry'], $options['display_entries']);
Index: www/macros/macro_roundregister.php
===================================================================
--- www/macros/macro_roundregister.php	(revision 989)
+++ www/macros/macro_roundregister.php	(working copy)
@@ -29,10 +29,12 @@
 
     if ($is_registered) {
         $class = "round-registered";
-        $msg = "Te-ai inscris la <em>{$round['title']}</em>."
+        $msg = "<p>Te-ai inscris la <em>".html_escape($round['title'])."</em>."
                ." <a href=\"".html_escape(url_round_register_view($round['id']))."\">"
                ."Vezi cine s-a mai inscris"
-               ."</a>.";
+               ."</a>.</p><p>In caz ca nu mai poti participa te poti deinscrie"
+               ." <a href=\"".html_escape(url_round_register($round['id']))
+               ."\">aici</a>.";
     }
     else {
         // too late?
Index: www/static/css/screen.css
===================================================================
--- www/static/css/screen.css	(revision 989)
+++ www/static/css/screen.css	(working copy)
@@ -1263,19 +1263,21 @@
 /* round registration */
 .round-register, .round-registered, .round-expired {
     width: 50%;
-    padding: .2em .5em .2em .5em;
+    padding: 0 1em;
     background-color: #fff;
 }
 
 .round-registered {
+    border: 2px solid silver;
 }
 
 .round-register {
-    border: 2px dashed red;
+    background-color: #ffa;
+    border: 2px solid red;
 }
 
 .round-expired {
-    border: 2px dashed silver;
+    border: 2px solid silver;
 }
 
 .round-register a {
Index: www/views/round_unregister.php
===================================================================
--- www/views/round_unregister.php	(revision 0)
+++ www/views/round_unregister.php	(revision 0)
@@ -0,0 +1,17 @@
+<?php
+include('views/header.php');
+?>
+
+<h1>Deinregistrare de la <?= format_link(url_textblock($round['page_name']), $round['title']) ?></h1>
+
+<?php wiki_include('template/deinscriere', array('round' => $round['id'])) ?>
+
+<form action="<?= html_escape(getattr($view, 'action')) ?>" method="post" class="register">
+    <ul class="form">
+        <li id="form_submit">
+            <input type="submit" value="Confirma deinscrierea" id="form_submit" class="button important" />
+        </li>
+    </ul>
+</form>
+
+<?php include('footer.php'); ?>

Property changes on: www/views/round_unregister.php
___________________________________________________________________
Added: svn:mergeinfo

