Dotclear

Changeset 1015:10227e338321


Ignore:
Timestamp:
11/17/12 14:19:52 (13 years ago)
Author:
JcDenis
Branch:
default
Message:

Fix #1171 : Add ability to delete non empty category (and move its content)

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • admin/categories.php

    r907 r1015  
    2020     try 
    2121     { 
     22          # Check if category to delete exists 
    2223          $c = $core->blog->getCategory((integer) $_POST['del_cat']); 
    2324          if ($c->isEmpty()) { 
     
    2526          } 
    2627          unset($c); 
     28           
     29          # Check if category where to move posts exists 
     30          $mov_cat = (integer) $_POST['mov_cat']; 
     31          $mov_cat = $mov_cat ? $mov_cat : null; 
     32          if ($mov_cat !== null) { 
     33               $c = $core->blog->getCategory((integer) $_POST['del_cat']); 
     34               if ($c->isEmpty()) { 
     35                    throw new Exception(__('This category does not exist.')); 
     36               } 
     37               unset($c); 
     38          } 
     39           
     40          # Move posts 
     41          $core->blog->updPostsCategory($_POST['del_cat'],$mov_cat); 
     42           
     43          # Delete category 
    2744          $core->blog->delCategory($_POST['del_cat']); 
     45           
    2846          http::redirect('categories.php?del=1'); 
    2947     } 
     
    143161if (!$rs->isEmpty()) 
    144162{ 
    145      $deletable = array(); 
     163     $cats = array(); 
     164     $dest = array(' ' => ''); 
    146165     $l = $rs->level; 
    147166     $full_name = array($rs->cat_title); 
     
    154173          } 
    155174          $full_name[] = html::escapeHTML($rs->cat_title); 
    156           if ($rs->nb_post == 0) { 
    157                $deletable[implode(' / ',$full_name)] = $rs->cat_id; 
    158           } 
     175           
     176          $cats[implode(' / ',$full_name)] = $rs->cat_id; 
     177          $dest[implode(' / ',$full_name)] = $rs->cat_id; 
     178           
    159179          $l = $rs->level; 
    160180     } 
    161181      
    162      if (count($deletable) > 0) 
    163      { 
    164           echo 
    165           '<form action="categories.php" method="post" id="delete-category">'. 
    166           '<fieldset><legend>'.__('Remove a category').'</legend>'. 
    167           '<p><label for="del_cat">'.__('Choose a category to remove:').' '. 
    168           form::combo('del_cat',$deletable).'</label></p> '. 
    169           '<p><input type="submit" value="'.__('Delete').'" class="delete" /></p>'. 
    170           $core->formNonce(). 
    171           '</fieldset>'. 
    172           '</form>'; 
    173      } 
     182     echo 
     183     '<form action="categories.php" method="post" id="delete-category">'. 
     184     '<fieldset><legend>'.__('Remove a category').'</legend>'. 
     185     '<p><label for="del_cat">'.__('Choose a category to remove:').' '. 
     186     form::combo('del_cat',$cats).'</label></p> '. 
     187     '<p><label for="mov_cat">'.__('Move its content to another category:').' '. 
     188     form::combo('mov_cat',$dest).'</label></p> '. 
     189     '<p><input type="submit" value="'.__('Delete').'" class="delete" /></p>'. 
     190     $core->formNonce(). 
     191     '</fieldset>'. 
     192     '</form>'; 
    174193      
    175194     echo 
  • inc/core/class.dc.blog.php

    r970 r1015  
    13391339      
    13401340     /** 
     1341     Updates posts category. <var>$new_cat_id</var> can be null. 
     1342      
     1343     @param    old_cat_id     <b>integer</b>      Old category ID 
     1344     @param    new_cat_id     <b>integer</b>      New category ID 
     1345     */ 
     1346     public function updPostsCategory($old_cat_id,$new_cat_id) 
     1347     { 
     1348          if (!$this->core->auth->check('contentadmin,categories',$this->id)) { 
     1349               throw new Exception(__('You are not allowed to change entries category')); 
     1350          } 
     1351           
     1352          $old_cat_id = (integer) $old_cat_id; 
     1353          $new_cat_id = (integer) $new_cat_id; 
     1354           
     1355          $cur = $this->con->openCursor($this->prefix.'post'); 
     1356           
     1357          $cur->cat_id = ($new_cat_id ? $new_cat_id : null); 
     1358          $cur->post_upddt = date('Y-m-d H:i:s'); 
     1359           
     1360          $cur->update( 
     1361               'WHERE cat_id = '.$old_cat_id.' '. 
     1362               "AND blog_id = '".$this->con->escape($this->id)."' " 
     1363          ); 
     1364          $this->triggerBlog(); 
     1365     } 
     1366      
     1367     /** 
    13411368     Deletes a post. 
    13421369      
Note: See TracChangeset for help on using the changeset viewer.

Sites map