Index: common/db/textblock.php
===================================================================
--- common/db/textblock.php	(revision 1068)
+++ common/db/textblock.php	(working copy)
@@ -237,7 +237,8 @@
 }
 
 // Grep through textblocks. This is mostly a hack needed for macro_grep.php
-function textblock_grep($substr, $page, $regexp = false) {
+// Also used for round deletion
+function textblock_grep($substr, $page, $regexp = false, $offset = 0, $count = 0) {
     if (!$regexp) {
         $compare = "LIKE";
     } else {
@@ -249,11 +250,27 @@
                       FROM ia_textblock
                       WHERE `name` LIKE '%s' AND
                             (`text` $compare '%s' OR `title` $compare '%s')
-                      ORDER BY `name`",
-                      db_escape($page), db_escape($substr), db_escape($substr));
+                      ORDER BY `name`
+                      LIMIT %s, %s",
+                      db_escape($page), db_escape($substr), db_escape($substr),
+                      db_escape($offset), db_escape($count));
     return db_fetch_all($query);
 }
 
+function textblock_grep_count($substr, $page, $regexp = false) {
+    if (!$regexp) {
+        $compare = "LIKE";
+    } else {
+        $compare = "REGEXP";
+    }
+    $query = sprintf("SELECT COUNT(*) as `cnt`
+                      FROM ia_textblock
+                      WHERE `name` LIKE '%s' AND
+                            (`text` $compare '%s' OR `title` $compare '%s')",
+                      db_escape($page), db_escape($substr), db_escape($substr));
+    return db_fetch($query);
+}
+
 // Delete a certain page, including all revisions and attachments.
 // WARNING: This is irreversible.
 function textblock_delete($page_name) {
@@ -272,9 +289,8 @@
 
     db_query("DELETE FROM `ia_textblock_revision` WHERE `name` = '$pageesc'");
     db_query("DELETE FROM `ia_textblock` WHERE `name` = '$pageesc'");
-    if (db_affected_rows() != 1) {
-        return true;
-    }
+
+    return (db_affected_rows() != 0);
 }
 
 // Move a page from old_name to new_name.
Index: www/controllers/attachment.php
===================================================================
--- www/controllers/attachment.php	(revision 1068)
+++ www/controllers/attachment.php	(working copy)
@@ -310,6 +310,7 @@
 function controller_attachment_delete_many($page_name, $arguments) {
     $files = array();
     $deleted = 0;
+
     foreach($arguments as $value) {
         if(is_numeric($value)) {
             $files[] = request($value);
Index: www/controllers/round.php
===================================================================
--- www/controllers/round.php	(revision 1068)
+++ www/controllers/round.php	(working copy)
@@ -5,6 +5,8 @@
 require_once(IA_ROOT_DIR."common/db/task.php");
 require_once(IA_ROOT_DIR."common/round.php");
 require_once(IA_ROOT_DIR."common/tags.php");
+require_once(IA_ROOT_DIR."common/textblock.php");
+require_once(IA_ROOT_DIR."www/format/pager.php");
 
 // Displays form to either create a new round or edit an existing one.
 // This form does not edit round content (its associated textblock)
@@ -40,7 +42,7 @@
     // Filter for available round types.
     $round_types = array();
     foreach (round_get_types() as $round_type => $pretty_name) {
-        if (identity_can("round-edit", round_init('round_id', $round_type, 
+        if (identity_can("round-edit", round_init('round_id', $round_type,
             $identity_user)))
             $round_types[$round_type] = $pretty_name;
     }
@@ -50,7 +52,7 @@
     $all_tasks = task_get_all();
     $all_task_ids = array();
     foreach ($all_tasks as $idx => $task) {
-        if ($round['type'] != 'user-defined' || 
+        if ($round['type'] != 'user-defined' ||
             identity_can('task-use-in-user-round', $task)) {
             $all_task_ids[$task['id']] = true;
         } else {
@@ -241,7 +243,7 @@
     // Filter for available round types.
     $round_types = array();
     foreach (round_get_types() as $round_type => $pretty_name) {
-        if (identity_can("round-create", round_init("round_id", $round_type, 
+        if (identity_can("round-create", round_init("round_id", $round_type,
             $identity_user)))
             $round_types[$round_type] = $pretty_name;
     }
@@ -257,4 +259,51 @@
     execute_view_die("views/round_create.php", $view);
 }
 
+function controller_round_delete($round_id) {
+    // Validate round_id
+    if (!is_round_id($round_id)) {
+        flash_error('Identificatorul rundei este invalid');
+        redirect(url_home());
+    }
+
+    // Get round
+    $round = round_get($round_id);
+    if (!$round) {
+        flash_error("Runda nu exista");
+        redirect(url_home());
+    }
+
+    // Security check
+    identity_require('round-delete', $round);
+
+    $options = pager_init_options();
+
+    $textblock_list = textblock_grep('%"'.$round_id.'"%', '%', false, $options['first_entry'],
+                                     $options['display_entries']);
+
+    for ($i = 0; $i < count ($textblock_list); ++$i) {
+        $textblock_list[$i]['id'] = $options['first_entry'] + $i + 1;
+    }
+
+    // Form stuff.
+    $values = array();
+    $errors = array();
+
+    // Create view
+    $view = array();
+    $view['textblock_list'] = $textblock_list;
+    $view['title'] = "Stergere textblockuri corelate cu $round_id";
+    $view['page_name'] = url_round_delete($round_id);
+    $view['round_id'] = $round_id;
+    $view['round'] = $round;
+    $view['form_values'] = $values;
+    $view['form_errors'] = $errors;
+    $entries = textblock_grep_count('%"'.$round_id.'"%', '%', false);
+    $view['total_entries'] = $entries['cnt'];
+    $view['first_entry'] = $options['first_entry'];
+    $view['display_entries'] = $options['display_entries'];
+
+    execute_view_die("views/round_delete.php", $view);
+}
+
 ?>
Index: www/controllers/textblock.php
===================================================================
--- www/controllers/textblock.php	(revision 1068)
+++ www/controllers/textblock.php	(working copy)
@@ -215,6 +215,25 @@
     redirect(url_home());
 }
 
+// Delete a list of textblocks
+function controller_textblock_delete_many($textblocks, $redirect) {
+    $deleted = 0;
+    $not_deleted_because_of_permision = 0;
+
+    foreach ($textblocks as $name) {
+        if (identity_can("textblock-delete", textblock_get_revision($name)))
+            $deleted += textblock_delete($name);
+        else
+            ++$not_deleted_because_of_permision;
+    }
+
+    flash($deleted." textblockuri au fost sterse.");
+    if ($not_deleted_because_of_permision)
+        flash($not_deleted_because_of_permision.
+              " textblockuri nu au putut fi sterse din cauza permisiunilor.");
+    redirect($redirect);
+}
+
 // Delete a certain revision
 function controller_textblock_delete_revision($page = null, $rev_num = null) {
     if (!request_is_post()) {
Index: www/index.php
===================================================================
--- www/index.php	(revision 1068)
+++ www/index.php	(working copy)
@@ -95,14 +95,24 @@
     controller_round_create();
 }
 
-// Round detail editor
+// Round detail editor and deleter
 else if ($urlstart == 'admin' && getattr($pagepath, 1) == 'runda') {
     $obj_id = implode("/", array_slice($pagepath, 2));
     require_once(IA_ROOT_DIR.'www/controllers/round.php');
-    controller_round_details($obj_id);
+    require_once(IA_ROOT_DIR.'www/controllers/textblock.php');
+    if ($action == 'sterge-runda') {
+        if (request('delete')) {
+            $v = request('textblocks');
+            controller_textblock_delete_many($v, url_round_delete($obj_id));
+        } else {
+            controller_round_delete($obj_id);
+        }
+    } else {
+        controller_round_details($obj_id);
+    }
 }
 
-// Round registration 
+// Round registration
 else if ($urlstart == 'inregistrare-runda') {
     $obj_id = implode("/", array_slice($pagepath, 1));
     require_once(IA_ROOT_DIR.'www/controllers/round_register.php');
Index: www/url.php
===================================================================
--- www/url.php	(revision 1068)
+++ www/url.php	(working copy)
@@ -284,6 +284,11 @@
     return url_complex("lista-inregistrare/$round_id");
 }
 
+function url_round_delete($round_id) {
+    log_assert(is_round_id($round_id));
+    return url_complex("admin/runda/$round_id", array('action' => 'sterge-runda'));
+}
+
 // Job/monitor stuff.
 
 function url_submit() {
Index: www/views/round_delete.php
===================================================================
--- www/views/round_delete.php	(revision 0)
+++ www/views/round_delete.php	(revision 0)
@@ -0,0 +1,76 @@
+<?php
+include('header.php');
+require_once(IA_ROOT_DIR . "www/format/table.php");
+require_once(IA_ROOT_DIR . "www/format/format.php");
+
+// Format the checkbox
+function format_check($row) {
+    // Nice trick to put the arguments in an array
+    $id = html_escape('textblocks[]');
+    $name = html_escape($row['name']);
+    $html_checkbox = "<input type='checkbox' name='$id' value='$name'>";
+
+    return $html_checkbox;
+}
+
+// Format the ID
+function format_textblock_id($row) {
+    $id = $row['id'];
+    return "#$id";
+}
+
+// Format the name
+function format_textblock_name($row) {
+    global $page_name;
+
+    $textblockurl = '<span id="link_'.$row['id'].'">';
+    $textblockurl .= format_link(url_textblock($row['name']), $row['name']);
+    $textblockurl .= '</span>';
+
+    return $textblockurl;
+}
+
+$column_infos = array(
+    array(
+        'title' => '',
+        'key' => 'ckeck',
+        'rowform' => 'format_check'
+    ),
+    array(
+        'title' => 'Numar',
+        'key' => 'id',
+        'rowform' => 'format_textblock_id'
+    ),
+    array(
+        'title' => 'Nume',
+        'key' => 'name',
+        'rowform' => 'format_textblock_name'
+    ),
+);
+
+?>
+
+    <form method = 'post' action = ''>
+
+    <h1>Paginile corelate cu runda <?= format_link(url_round_edit($view['round_id']), $view['round_id']); ?></h1>
+
+    <?php
+        $options = array(
+            'display_entries' => $view['display_entries'],
+            'total_entries' => $view['total_entries'],
+            'first_entry' => $view['first_entry'],
+            'pager_style' => 'standard',
+            'show_count' => true,
+            'show_display_entries' => true,
+            'css_class' => 'fill-screen',
+        );
+
+        echo format_table($view['textblock_list'], $column_infos, $options);
+
+        if ($view['total_entries']) {
+    ?>
+        <br /><input type="submit" value="Sterge Paginile" class="button" name="delete" onclick="return confirm('Aceasta actiune este ireversibila! Doresti sa continui?');" />
+    <?php } ?>
+    </form>
+
+<?php include('footer.php'); ?>

Property changes on: www/views/round_delete.php
___________________________________________________________________
Added: svn:executable
   + *

