Dotclear


Ignore:
Timestamp:
08/19/13 11:39:45 (11 years ago)
Author:
Dsls
Branch:
default
Message:

Added entries list in posts_actions.php, ability to uncheck some entries in this page. see #1540
Added proper message when no entry selected, or no action set. closes #1527

File:
1 edited

Legend:

Unmodified
Added
Removed
  • admin/posts_actions.php

    r1399 r1471  
    1717$params = array(); 
    1818 
     19class FieldsList { 
     20     protected $hidden; 
     21     protected $entries; 
     22     public function __construct() { 
     23          $this->hidden=array(); 
     24          $this->entries =array(); 
     25     } 
     26     public function addHidden($name,$value) { 
     27          $this->hidden[] = form::hidden($name,$value); 
     28          return $this; 
     29     } 
     30     public function addEntry($id,$title) { 
     31          $this->entries[$id]=$title; 
     32          return $this; 
     33     } 
     34 
     35     public function getHidden() { 
     36          return join('',$this->hidden); 
     37     } 
     38      
     39     public function getEntries ($hidden=false) { 
     40          $ret = ''; 
     41          if ($hidden) { 
     42               foreach ($this->entries as $id=> $e) { 
     43                    $ret .= form::hidden('entries[]',$id); 
     44               } 
     45          } else { 
     46               $ret =  
     47                    '<table class="posts-list"><tr>'. 
     48                    '<th colspan="2">'.__('Title').'</th>'. 
     49                    '</tr>'; 
     50               foreach ($this->entries as $id=>$title) { 
     51                    $ret .=  
     52                         '<tr><td>'. 
     53                         form::checkbox(array('entries[]'),$id,true,'','').'</td>'. 
     54                         '<td>'.   $title.'</td></tr>'; 
     55               } 
     56               $ret .= '</table>'; 
     57          } 
     58          return $ret; 
     59     } 
     60      
     61     public function __toString() { 
     62          return join('',$this->hidden).$this->getEntries(true); 
     63     } 
     64} 
     65 
     66 
     67function listEntries($titles) { 
     68     $ret =  
     69          '<table class="posts-list"><tr>'. 
     70          '<th colspan="2">'.__('Title').'</th>'. 
     71          '</tr>'; 
     72     foreach ($titles as $id=>$title) { 
     73          $ret .=  
     74               '<tr><td>'. 
     75               form::checkbox(array('entries[]'),$id,true,'','').'</td>'. 
     76               '<td>'.   $title.'</td></tr>'; 
     77     } 
     78     $ret .= '</table>'; 
     79     return $ret; 
     80} 
     81 
    1982/* Actions 
    2083-------------------------------------------------------- */ 
     
    175238          } 
    176239     } 
    177 } 
    178  
     240} else { 
     241     if (empty($_POST['entries'])) { 
     242          $core->error->add(__('At least one entry should be selected')); 
     243     } else { 
     244          $core->error->add(__('No action specified.')); 
     245     } 
     246     dcPage::open( 
     247          __('Entries'),'',dcPage::breadcrumb( 
     248          array( 
     249               html::escapeHTML($core->blog->name) => '', 
     250               __('Entries') => 'posts.php', 
     251               '<span class="page-title">'.__('Entries actions').'</span>' => '' 
     252          )) 
     253     ); 
     254 
     255     dcPage::close(); 
     256     exit; 
     257} 
    179258/* DISPLAY 
    180259-------------------------------------------------------- */ 
     
    211290} 
    212291 
    213 $hidden_fields = ''; 
     292$fields = new FieldsList(); 
    214293while ($posts->fetch()) { 
    215      $hidden_fields .= form::hidden(array('entries[]'),$posts->post_id); 
     294     $fields->addEntry($posts->post_id,$posts->post_title); 
    216295} 
    217296 
    218297if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false) 
    219298{ 
    220      $hidden_fields .= form::hidden(array('redir'),html::escapeURL($_POST['redir'])); 
     299     $fields->addHidden(array('redir'),html::escapeURL($_POST['redir'])); 
    221300} 
    222301else 
    223302{ 
    224      $hidden_fields .= 
    225      form::hidden(array('user_id'),$_POST['user_id']). 
    226      form::hidden(array('cat_id'),$_POST['cat_id']). 
    227      form::hidden(array('status'),$_POST['status']). 
    228      form::hidden(array('selected'),$_POST['selected']). 
    229      form::hidden(array('month'),$_POST['month']). 
    230      form::hidden(array('lang'),$_POST['lang']). 
    231      form::hidden(array('sortby'),$_POST['sortby']). 
    232      form::hidden(array('order'),$_POST['order']). 
    233      form::hidden(array('page'),$_POST['page']). 
    234      form::hidden(array('nb'),$_POST['nb']); 
     303     $fields 
     304          ->addHidden(array('user_id'),$_POST['user_id']) 
     305          ->addHidden(array('cat_id'),$_POST['cat_id']) 
     306          ->addHidden(array('status'),$_POST['status']) 
     307          ->addHidden(array('selected'),$_POST['selected']) 
     308          ->addHidden(array('month'),$_POST['month']) 
     309          ->addHidden(array('lang'),$_POST['lang']) 
     310          ->addHidden(array('sortby'),$_POST['sortby']) 
     311          ->addHidden(array('order'),$_POST['order']) 
     312          ->addHidden(array('page'),$_POST['page']) 
     313          ->addHidden(array('nb'),$_POST['nb']) 
     314     ; 
    235315} 
    236316 
    237317if (isset($_POST['post_type'])) { 
    238      $hidden_fields .= form::hidden(array('post_type'),$_POST['post_type']); 
     318     $fields->addHidden(array('post_type'),$_POST['post_type']); 
    239319} 
    240320 
    241321# --BEHAVIOR-- adminPostsActionsContent 
    242 $core->callBehavior('adminPostsActionsContent',$core,$action,$hidden_fields); 
     322$core->callBehavior('adminPostsActionsContent',$core,$action,$fields); 
    243323 
    244324if ($action == 'category') 
    245325{ 
    246      echo '<h2 class="page-title">'.__('Change category for entries').'</h2>'; 
    247       
     326     echo dcPage::breadcrumb( 
     327          array( 
     328               html::escapeHTML($core->blog->name) => '', 
     329               __('Entries') => 'posts.php', 
     330               __('Change category for entries') => '' 
     331     )); 
     332 
    248333     # categories list 
    249334     # Getting categories 
     
    262347     echo 
    263348     '<form action="posts_actions.php" method="post">'. 
    264      '<p><label for="new_cat_id" class="classic">'.__('Category:').'</label> '. 
    265      form::combo('new_cat_id',$categories_combo,''); 
    266       
    267      echo 
    268      $hidden_fields. 
     349     $fields->getEntries(). 
     350     '<p><label for="new_cat_id" class="classic">'.__('Category:').' '. 
     351     form::combo('new_cat_id',$categories_combo,''). 
     352     '</label> '; 
     353      
     354     echo 
     355     $fields->getHidden(). 
    269356     $core->formNonce(). 
    270357     form::hidden(array('action'),'category'). 
     
    274361elseif ($action == 'lang') 
    275362{ 
    276      echo '<h2 class="page-title">'.__('Change language for entries').'</h2>'; 
     363     echo dcPage::breadcrumb( 
     364          array( 
     365               html::escapeHTML($core->blog->name) => '', 
     366               __('Entries') => 'posts.php', 
     367               '<span class="page-title">'.__('Change language for entries').'</span>' => '' 
     368     )); 
    277369      
    278370     # lang list 
     
    294386     echo 
    295387     '<form action="posts_actions.php" method="post">'. 
    296      '<p><label for="new_lang" class="classic">'.__('Entry lang:').'</label> '. 
    297      form::combo('new_lang',$lang_combo,''); 
    298       
    299      echo 
    300      $hidden_fields. 
     388     $fields->getEntries().    
     389     '<p><label for="new_lang" class="classic">'.__('Entry lang:').' '. 
     390     form::combo('new_lang',$lang_combo,''). 
     391     '</label> '; 
     392      
     393     echo 
     394     $fields->getHidden(). 
    301395     $core->formNonce(). 
    302396     form::hidden(array('action'),'lang'). 
     
    307401elseif ($action == 'author' && $core->auth->check('admin',$core->blog->id)) 
    308402{ 
    309      echo '<h2 class="page-title">'.__('Change author for entries').'</h2>'; 
     403     echo dcPage::breadcrumb( 
     404          array( 
     405               html::escapeHTML($core->blog->name) => '', 
     406               __('Entries') => 'posts.php', 
     407               '<span class="page-title">'.__('Change author for entries').'</span>' => '' 
     408     )); 
    310409      
    311410     echo 
    312411     '<form action="posts_actions.php" method="post">'. 
    313      '<p><label for="new_auth_id" class="classic">'.__('Author ID:').'</label> '. 
    314      form::field('new_auth_id',20,255); 
    315       
    316      echo 
    317      $hidden_fields. 
     412     $fields->getEntries(). 
     413     '<p><label for="new_auth_id" class="classic">'.__('Author ID:').' '. 
     414     form::field('new_auth_id',20,255). 
     415     '</label> '; 
     416      
     417     echo 
     418     $fields->getHidden(). 
    318419     $core->formNonce(). 
    319420     form::hidden(array('action'),'author'). 
Note: See TracChangeset for help on using the changeset viewer.

Sites map