Changeset 1086 for trunk


Ignore:
Timestamp:
12/22/09 14:21:51 (2 years ago)
Author:
Prostu
Message:

Show and delete all the pages that have a round name in their text.

Reviewed: http://reviewboard.infoarena.ro/r/115/

Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/db/textblock.php

    r1074 r1086  
    243243 
    244244// Grep through textblocks. This is mostly a hack needed for macro_grep.php 
    245 function textblock_grep($substr, $page, $regexp = false) { 
     245// Also used for round deletion 
     246function textblock_grep($substr, $page, $regexp = false, $offset = 0, $count = 0) { 
    246247    if (!$regexp) { 
    247248        $compare = "LIKE"; 
     
    255256                      WHERE `name` LIKE '%s' AND 
    256257                            (`text` $compare '%s' OR `title` $compare '%s') 
    257                       ORDER BY `name`", 
     258                      ORDER BY `name` 
     259                      LIMIT %s, %s", 
     260                      db_escape($page), db_escape($substr), db_escape($substr), 
     261                      db_escape($offset), db_escape($count)); 
     262    return db_fetch_all($query); 
     263} 
     264 
     265function textblock_grep_count($substr, $page, $regexp = false) { 
     266    if (!$regexp) { 
     267        $compare = "LIKE"; 
     268    } else { 
     269        $compare = "REGEXP"; 
     270    } 
     271    $query = sprintf("SELECT COUNT(*) as `cnt` 
     272                      FROM ia_textblock 
     273                      WHERE `name` LIKE '%s' AND 
     274                            (`text` $compare '%s' OR `title` $compare '%s')", 
    258275                      db_escape($page), db_escape($substr), db_escape($substr)); 
    259     return db_fetch_all($query); 
     276    return db_fetch($query); 
    260277} 
    261278 
     
    278295    db_query("DELETE FROM `ia_textblock_revision` WHERE `name` = '$pageesc'"); 
    279296    db_query("DELETE FROM `ia_textblock` WHERE `name` = '$pageesc'"); 
    280     if (db_affected_rows() != 1) { 
    281         return true; 
    282     } 
     297 
     298    return (db_affected_rows() != 0); 
    283299} 
    284300 
  • trunk/www/controllers/attachment.php

    r1068 r1086  
    311311    $files = array(); 
    312312    $deleted = 0; 
     313 
    313314    foreach($arguments as $value) { 
    314315        if(is_numeric($value)) { 
  • trunk/www/controllers/round.php

    r1076 r1086  
    66require_once(IA_ROOT_DIR."common/round.php"); 
    77require_once(IA_ROOT_DIR."common/tags.php"); 
     8require_once(IA_ROOT_DIR."common/textblock.php"); 
     9require_once(IA_ROOT_DIR."www/format/pager.php"); 
    810 
    911// Displays form to either create a new round or edit an existing one. 
     
    4143    $round_types = array(); 
    4244    foreach (round_get_types() as $round_type => $pretty_name) { 
    43         if (identity_can("round-edit", round_init('round_id', $round_type,  
     45        if (identity_can("round-edit", round_init('round_id', $round_type, 
    4446            $identity_user))) 
    4547            $round_types[$round_type] = $pretty_name; 
     
    5153    $all_task_ids = array(); 
    5254    foreach ($all_tasks as $idx => $task) { 
    53         if ($round['type'] != 'user-defined' ||  
     55        if ($round['type'] != 'user-defined' || 
    5456            identity_can('task-use-in-user-round', $task)) { 
    5557            $all_task_ids[$task['id']] = true; 
     
    256258    $round_types = array(); 
    257259    foreach (round_get_types() as $round_type => $pretty_name) { 
    258         if (identity_can("round-create", round_init("round_id", $round_type,  
     260        if (identity_can("round-create", round_init("round_id", $round_type, 
    259261            $identity_user))) 
    260262            $round_types[$round_type] = $pretty_name; 
     
    272274} 
    273275 
     276function controller_round_delete($round_id) { 
     277    // Validate round_id 
     278    if (!is_round_id($round_id)) { 
     279        flash_error('Identificatorul rundei este invalid'); 
     280        redirect(url_home()); 
     281    } 
     282 
     283    // Get round 
     284    $round = round_get($round_id); 
     285    if (!$round) { 
     286        flash_error("Runda nu exista"); 
     287        redirect(url_home()); 
     288    } 
     289 
     290    // Security check 
     291    identity_require('round-delete', $round); 
     292 
     293    $options = pager_init_options(); 
     294 
     295    $textblock_list = textblock_grep('%"'.$round_id.'"%', '%', false, $options['first_entry'], 
     296                                     $options['display_entries']); 
     297 
     298    for ($i = 0; $i < count ($textblock_list); ++$i) { 
     299        $textblock_list[$i]['id'] = $options['first_entry'] + $i + 1; 
     300    } 
     301 
     302    // Form stuff. 
     303    $values = array(); 
     304    $errors = array(); 
     305 
     306    // Create view 
     307    $view = array(); 
     308    $view['textblock_list'] = $textblock_list; 
     309    $view['title'] = "Stergere textblockuri corelate cu $round_id"; 
     310    $view['page_name'] = url_round_delete($round_id); 
     311    $view['round_id'] = $round_id; 
     312    $view['round'] = $round; 
     313    $view['form_values'] = $values; 
     314    $view['form_errors'] = $errors; 
     315    $entries = textblock_grep_count('%"'.$round_id.'"%', '%', false); 
     316    $view['total_entries'] = $entries['cnt']; 
     317    $view['first_entry'] = $options['first_entry']; 
     318    $view['display_entries'] = $options['display_entries']; 
     319 
     320    execute_view_die("views/round_delete.php", $view); 
     321} 
     322 
    274323?> 
  • trunk/www/controllers/textblock.php

    r1038 r1086  
    216216} 
    217217 
     218// Delete a list of textblocks 
     219function controller_textblock_delete_many($textblocks, $redirect) { 
     220    $deleted = 0; 
     221    $not_deleted_because_of_permision = 0; 
     222    $bad_page_names = 0; 
     223 
     224    if (!is_array($textblocks)) { 
     225        flash_error("Nu au fost specificate pagini pentru a fi sterse"); 
     226        redirect($redirect); 
     227    } 
     228 
     229    foreach ($textblocks as $name) { 
     230        if (!is_page_name($name)) { 
     231            ++$bad_page_names; 
     232        } else if (identity_can("textblock-delete", textblock_get_revision($name))) { 
     233            $deleted += textblock_delete($name); 
     234        } else { 
     235            ++$not_deleted_because_of_permision; 
     236        } 
     237    } 
     238 
     239    flash($deleted." textblockuri au fost sterse."); 
     240    if ($not_deleted_because_of_permision) { 
     241        flash($not_deleted_because_of_permision. 
     242              " textblockuri nu au putut fi sterse din cauza permisiunilor."); 
     243    } 
     244    if ($bad_page_names) { 
     245        flash($bad_page_names." textblockuri au numele corupt"); 
     246    } 
     247    redirect($redirect); 
     248} 
     249 
    218250// Delete a certain revision 
    219251function controller_textblock_delete_revision($page = null, $rev_num = null) { 
  • trunk/www/index.php

    r1083 r1086  
    115115} 
    116116 
    117 // Round detail editor 
     117// Round detail editor and deleter 
    118118else if ($urlstart == 'admin' && getattr($pagepath, 1) == 'runda') { 
    119119    $obj_id = implode("/", array_slice($pagepath, 2)); 
    120120    require_once(IA_ROOT_DIR.'www/controllers/round.php'); 
    121     controller_round_details($obj_id); 
     121    require_once(IA_ROOT_DIR.'www/controllers/textblock.php'); 
     122    if ($action == 'sterge-runda') { 
     123        if (request('delete')) { 
     124            $v = request('textblocks'); 
     125            controller_textblock_delete_many($v, url_round_delete($obj_id)); 
     126        } else { 
     127            controller_round_delete($obj_id); 
     128        } 
     129    } else { 
     130        controller_round_details($obj_id); 
     131    } 
    122132} 
    123133 
  • trunk/www/url.php

    r1083 r1086  
    306306} 
    307307 
     308function url_round_delete($round_id) { 
     309    log_assert(is_round_id($round_id)); 
     310    return url_complex("admin/runda/$round_id", array('action' => 'sterge-runda')); 
     311} 
     312 
    308313// Job/monitor stuff. 
    309314 
  • trunk/www/views/round_edit.php

    r1077 r1086  
    7373<h1>Editare runda <?= format_link(url_textblock($round['page_name']), $round['title']) ?></h1> 
    7474 
     75<form action="<?= html_escape(url_round_delete($round['id'])) ?>" method="post" style="float: right"> 
     76    <input type="hidden" name="" value="<?= html_escape($round['id']) ?>" /> 
     77    <input onclick="" type="submit" value="Sterge runda" id="form_delete" class="button important" /> 
     78</form> 
     79 
    7580<?php if ($round['state'] == 'running') { ?> 
    7681    <div class="warning"> 
Note: See TracChangeset for help on using the changeset viewer.