Changeset 1109


Ignore:
Timestamp:
03/16/10 00:23:44 (2 years ago)
Author:
Prostu
Message:

Added a new button in the page generated by /admin/[round]?action=sterge-runda
that erases all the information regarding the round from the database.
Information relation to a round is found in the following tables:
ia_job_test
ia_job
ia_parameter_value
ia_round_task
ia_user_round
ia_round_task
ia_round

Location:
trunk
Files:
1 added
4 edited

Legend:

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

    r1094 r1109  
    423423} 
    424424 
     425function round_delete($round_id) { 
     426    log_assert(is_round_id($round_id)); 
     427 
     428    // Delete round from cache 
     429    _round_cache_delete($round_id); 
     430 
     431    // Delete job_tests 
     432    $query = sprintf("SELECT `id` 
     433                      FROM `ia_job` 
     434                      WHERE `round_id` = %s", 
     435                      db_quote($round_id)); 
     436 
     437    $job_ids_fetched = db_fetch_all($query); 
     438 
     439    $job_ids = array(); 
     440    foreach ($job_ids_fetched as $job) { 
     441        $job_ids[] = (int)$job["id"]; 
     442    } 
     443 
     444    if (count($job_ids)) { 
     445        $formated_job_ids = implode(", ", array_map("db_quote", $job_ids)); 
     446        $query = sprintf("DELETE FROM `ia_job_test` 
     447                          WHERE `job_id` IN (%s)", 
     448                          $formated_job_ids); 
     449        db_query($query); 
     450 
     451        $query = sprintf("DELETE FROM `ia_job` 
     452                          WHERE `id` IN (%s)", 
     453                          $formated_job_ids); 
     454        db_query($query); 
     455    } 
     456 
     457    // Delete entries from ia_parameter_value... 
     458    $query = sprintf("DELETE FROM `ia_parameter_value` 
     459                      WHERE `object_type` = 'round' 
     460                        AND `object_id` = %s", 
     461                      db_quote($round_id)); 
     462    db_query($query); 
     463 
     464    // Delete entries from round-task 
     465    $query = sprintf("DELETE FROM `ia_round_task` 
     466                      WHERE `round_id` = %s", 
     467                      db_quote($round_id)); 
     468    db_query($query); 
     469 
     470    // Delete entries from user-round 
     471    $query = sprintf("DELETE FROM `ia_user_round` 
     472                      WHERE `round_id` = %s", 
     473                      db_quote($round_id)); 
     474    db_query($query); 
     475 
     476    // Delete entries from round-task 
     477    $query = sprintf("DELETE FROM `ia_round_task` 
     478                      WHERE `round_id` = %s", 
     479                      db_quote($round_id)); 
     480    db_query($query); 
     481 
     482    // Delete entries from ia_score 
     483    $query = sprintf("DELETE FROM `ia_score` 
     484                      WHERE `round_id` = %s", 
     485                      db_quote($round_id)); 
     486    db_query($query); 
     487 
     488    // ACTUALLY DELETE THE ROUND 
     489    $query = sprintf("DELETE FROM `ia_round` 
     490                      WHERE `id` = %s", 
     491                      db_quote($round_id)); 
     492    db_query($query); 
     493} 
     494 
    425495?> 
  • trunk/www/controllers/round.php

    r1091 r1109  
    270270} 
    271271 
    272 function controller_round_delete($round_id) { 
     272function controller_round_delete_view($round_id) { 
    273273    // Validate round_id 
    274274    if (!is_round_id($round_id)) { 
     
    324324} 
    325325 
     326function controller_round_delete($round_id) { 
     327    if (!request_is_post()) { 
     328        flash_error('Runda nu a putut fi stearsa.'); 
     329    } 
     330 
     331    // Validate round_id 
     332    if (!is_round_id($round_id)) { 
     333        flash_error('Identificatorul rundei este invalid.'); 
     334        redirect(url_home()); 
     335    } 
     336 
     337    // Get round 
     338    $round = round_get($round_id); 
     339    if (!$round) { 
     340        flash_error('Runda nu exista.'); 
     341        redirect(url_home()); 
     342    } 
     343 
     344    // Security check 
     345    identity_require('round-delete', $round); 
     346 
     347    // Delete all the round related information from the database 
     348    round_delete($round_id); 
     349 
     350    flash('Runda a fost stearsa.'); 
     351    redirect(url_home()); 
     352} 
     353 
    326354?> 
  • trunk/www/index.php

    r1095 r1109  
    127127    require_once(IA_ROOT_DIR.'www/controllers/textblock.php'); 
    128128    if ($action == 'sterge-runda') { 
    129         if (request('delete')) { 
     129        if (request('delete-pages')) { 
    130130            $v = request('textblocks'); 
    131131            controller_textblock_delete_many($v, url_round_delete($obj_id)); 
     132        } elseif (request('delete-round')) { 
     133            controller_round_delete($obj_id); 
    132134        } else { 
    133             controller_round_delete($obj_id); 
     135            controller_round_delete_view($obj_id); 
    134136        } 
    135137    } else { 
  • trunk/www/views/round_delete.php

    r1086 r1109  
    7070        if ($view['total_entries']) { 
    7171    ?> 
    72         <br /><input type="submit" value="Sterge Paginile" class="button" name="delete" onclick="return confirm('Aceasta actiune este ireversibila! Doresti sa continui?');" /> 
     72        <br /><input type="submit" value="Sterge Paginile" class="button" name="delete-pages" onclick="return confirm('Aceasta actiune este ireversibila! Doresti sa continui?');" /> 
    7373    <?php } ?> 
    7474    </form> 
    7575 
     76    <form method = 'post' action = ''> 
     77    <input type="submit" value="Sterge Runda, Forever..." class="button" name="delete-round" onclick="return confirm('Aceasta actiune este ireversibila! Doresti sa continui?');" /> 
     78    </form> 
     79 
    7680<?php include('footer.php'); ?> 
Note: See TracChangeset for help on using the changeset viewer.