b2evolution PHP Cross Reference Blogging Systems

Source: /inc/generic/inc/_generic_listeditor.php - 336 lines - 9562 bytes - Text - Print

Description: This file implements ther UI controler for element list edidor management. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements ther UI controler for element list edidor management.
   4   *
   5   * This file is part of the evoCore framework - {@link http://evocore.net/}
   6   * See also {@link http://sourceforge.net/projects/evocms/}.
   7   *
   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   9   * Parts of this file are copyright (c)2005-2006 by PROGIDISTRI - {@link http://progidistri.com/}.
  10   *
  11   * {@internal License choice
  12   * - If you have received this file as part of a package, please find the license.txt file in
  13   *   the same folder or the closest folder above for complete license terms.
  14   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  15   *   then you must choose one of the following licenses before using the file:
  16   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  17   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  18   * }}
  19   *
  20   * {@internal Open Source relicensing agreement:
  21   * PROGIDISTRI S.A.S. grants Francois PLANQUE the right to license
  22   * PROGIDISTRI S.A.S.'s contributions to this file and the b2evolution project
  23   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  24   * }}
  25   *
  26   * @package admin
  27   *
  28   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  29   * @author fplanque: Francois PLANQUE.
  30   * @author mbruneau: Marc BRUNEAU / PROGIDISTRI
  31   *
  32   * @version $Id: _generic_listeditor.php 6136 2014-03-08 07:59:48Z manuel $
  33   */
  34  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  35  
  36  
  37  param( 'action', 'string', 'list' );
  38  
  39  // Init fadeout result array:
  40  $result_fadeout = array();
  41  
  42  if( param( $GenericElementCache->dbIDname, 'integer', NULL, true, false, false ) )
  43  {
  44      if( ( $edited_GenericElement = & $GenericElementCache->get_by_ID( ${$GenericElementCache->dbIDname}, false ) ) === false )
  45      {    // We could not find the element to edit:
  46          unset( $edited_GenericElement );
  47          $Messages->add( sprintf( T_('Requested &laquo;%s&raquo; object does not exist any longer.'), T_('Element') ), 'error' );
  48          $action = 'nil';
  49      }
  50  }
  51  
  52  /**
  53   * Check locked elements
  54   */
  55  if( !empty( $locked_IDs )
  56          && in_array( $action, array( 'edit', 'update', 'delete' ) )
  57          && in_array( ${$GenericElementCache->dbIDname}, $locked_IDs ) )
  58  {
  59      $Messages->add( T_('This element is locked and cannot be edited!') );
  60      $action = 'list';
  61  }
  62  
  63  /**
  64   * Perform action:
  65   */
  66  switch( $action )
  67  {
  68  
  69      case 'new':
  70          // New element
  71  
  72          if( isset( $perm_name ) )
  73          {    // We need to Check permission:
  74              $current_User->check_perm( $perm_name, $perm_level, true );
  75          }
  76  
  77          $edited_GenericElement = & $GenericElementCache->new_obj();
  78          break;
  79  
  80  
  81      //case 'copy':
  82      case 'edit':
  83          // Edit element form...:
  84          // Make sure we got an ID:
  85          param( $GenericElementCache->dbIDname, 'integer', true );
  86  
  87          if( isset( $perm_name ) )
  88          {    // We need to Check permission:
  89              $current_User->check_perm( $perm_name, $perm_level, true );
  90          }
  91  
  92          // Get the page number we come from:
  93          $previous_page = param( 'results'.$GenericElementCache->dbprefix.'page', 'integer', 1, true );
  94          break;
  95  
  96  
  97      case 'create':
  98          // Insert new element...:
  99  
 100          // Check that this action request is not a CSRF hacked request:
 101          $Session->assert_received_crumb( 'element' );
 102  
 103          if( isset( $perm_name ) )
 104          {    // We need to Check permission:
 105              $current_User->check_perm( $perm_name, $perm_level, true );
 106          }
 107  
 108          $edited_GenericElement = & $GenericElementCache->new_obj();
 109  
 110          // load data from request
 111          if( $edited_GenericElement->load_from_Request() )
 112          {    // We could load data from form without errors:
 113              // Insert in DB:
 114              if( $edited_GenericElement->dbinsert() !== false )
 115              {
 116                  $Messages->add( T_('New element created.'), 'success' ); // TODO CHANGES THIS
 117                  // Add the ID of the new element to the result fadeout
 118                  $result_fadeout[$GenericElementCache->dbIDname][] = $edited_GenericElement->ID;
 119                  $action = 'list';
 120              }
 121          }
 122          break;
 123  
 124  
 125      case 'update':
 126          // Make sure we got an ID:
 127          param( $GenericElementCache->dbIDname, 'integer', true );
 128  
 129          // Check that this action request is not a CSRF hacked request:
 130          $Session->assert_received_crumb( 'element' );
 131  
 132          if( isset( $perm_name ) )
 133          {    // We need to Check permission:
 134              $current_User->check_perm( $perm_name, $perm_level, true );
 135          }
 136  
 137          // LOAD FORM DATA:
 138          if( $edited_GenericElement->load_from_Request() )
 139          {    // We could load data from form without errors:
 140              // Update in DB:
 141              if( $edited_GenericElement->dbupdate() !== false )
 142              {
 143                  $Messages->add( T_('Element updated.'), 'success' ); //ToDO change htis
 144                  // Add the ID of the updated element to the result fadeout
 145                  $result_fadeout[$GenericElementCache->dbIDname][] = $edited_GenericElement->ID;
 146                  unset( $edited_GenericElement );
 147                  forget_param( $GenericElementCache->dbIDname );
 148                  $action = 'list';
 149              }
 150          }
 151          else
 152          {
 153              // Get the page number we come from:
 154              $previous_page = param( 'results'.$GenericElementCache->dbprefix.'page', 'integer', 1, true );
 155          }
 156          break;
 157  
 158  
 159      case 'copy':
 160          // Duplicate an element by prefilling create form:
 161          param( $GenericElementCache->dbIDname, 'integer', true );
 162  
 163          if( isset( $perm_name ) )
 164          {    // We need to Check permission:
 165              $current_User->check_perm( $perm_name, $perm_level, true );
 166          }
 167  
 168          $new_Element = $edited_GenericElement;    // COPY
 169          $new_Element->ID = 0;
 170          $edited_GenericElement = & $new_Element;
 171          $AdminUI->append_to_titlearea( T_('Copy element...') );
 172          break;
 173  
 174  
 175      case 'move_up':
 176          // Move up the element order
 177          param( $GenericElementCache->dbIDname, 'integer', true );
 178  
 179          // Check that this action request is not a CSRF hacked request:
 180          $Session->assert_received_crumb( 'element' );
 181  
 182          if( isset( $perm_name ) )
 183          {    // We need to Check permission:
 184              $current_User->check_perm( $perm_name, $perm_level, true );
 185          }
 186  
 187          $GenericElementCache->move_up_by_ID( $edited_GenericElement->ID );
 188  
 189          break;
 190  
 191  
 192      case 'move_down':
 193          // Move down the element order
 194          param( $GenericElementCache->dbIDname, 'integer', true );
 195  
 196          // Check that this action request is not a CSRF hacked request:
 197          $Session->assert_received_crumb( 'element' );
 198  
 199          if( isset( $perm_name ) )
 200          {    // We need to Check permission:
 201              $current_User->check_perm( $perm_name, $perm_level, true );
 202          }
 203  
 204          $GenericElementCache->move_down_by_ID( $edited_GenericElement->ID );
 205  
 206          break;
 207  
 208  
 209      case 'delete':
 210          // Delete entry:
 211          param( $GenericElementCache->dbIDname, 'integer', true );
 212  
 213          // Check that this action request is not a CSRF hacked request:
 214          $Session->assert_received_crumb( 'element' );
 215  
 216          if( isset( $perm_name ) )
 217          {    // We need to Check permission:
 218              $current_User->check_perm( $perm_name, $perm_level, true );
 219          }
 220  
 221          // Set restrictions for element
 222          $edited_GenericElement->delete_restrictions = $delete_restrictions;
 223  
 224          if( param( 'confirm', 'integer', 0 ) )
 225          { // confirmed, Delete from DB:
 226              $msg = sprintf( T_('Element &laquo;%s&raquo; deleted.'), $edited_GenericElement->dget( 'name' ) );
 227              $GenericElementCache->dbdelete_by_ID( $edited_GenericElement->ID );
 228              unset($edited_GenericElement);
 229              forget_param( $GenericElementCache->dbIDname );
 230              $Messages->add( $msg, 'success' );
 231              $action = 'list';
 232          }
 233          else
 234          {    // not confirmed, Check for restrictions:
 235              // Get the page number we come from:
 236              $previous_page = param( 'results_'.$GenericElementCache->dbprefix.'page', 'integer', 1, true );
 237              if( ! $edited_GenericElement->check_delete( sprintf( T_('Cannot delete element &laquo;%s&raquo;'), $edited_GenericElement->dget( 'name' ) ) ) )
 238              {    // There are restrictions:
 239                  $action = 'edit';
 240              }
 241          }
 242          break;
 243  
 244      case 'sort_by_order':
 245          // The list is sorted by the order column now.
 246          $Results->order = '--A';
 247          set_param( 'results_'.$GenericElementCache->dbprefix.'order', '--A' );
 248          $action = 'list';
 249          break;
 250  
 251  }
 252  
 253  
 254  // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)
 255  $AdminUI->disp_html_head();
 256  
 257  // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)
 258  $AdminUI->disp_body_top();
 259  
 260  
 261  /**
 262   * Display payload:
 263   */
 264  switch( $action )
 265  {
 266      case 'nil':
 267          // Do nothing
 268          break;
 269  
 270      case 'new':
 271      case 'copy':
 272      case 'create':
 273      case 'edit':
 274      case 'update':
 275      case 'delete':
 276          // Begin payload block:
 277          $AdminUI->disp_payload_begin();
 278  
 279          if( $action == 'delete' )
 280          {    // We need to ask for confirmation:
 281              $edited_GenericElement->confirm_delete(
 282                      sprintf( T_('Delete element &laquo;%s&raquo;?'),  $edited_GenericElement->dget( 'name' ) ),
 283                      'element', $action, get_memorized( 'action' ) );
 284          }
 285  
 286          if( $form_below_list )
 287          {    // Display List VIEW before form VIEW:
 288              if( !empty( $list_view ) )
 289              {
 290                  $AdminUI->disp_view( $list_view );
 291              }
 292              else
 293              {
 294                  $AdminUI->disp_view( 'generic/views/_generic_list.inc.php' );
 295              }
 296          }
 297  
 298          // Display form:
 299          $edited_GenericElement->disp_form();
 300  
 301          // End payload block:
 302          $AdminUI->disp_payload_end();
 303          break;
 304  
 305      case 'list':
 306      default:
 307          // Begin payload block:
 308          $AdminUI->disp_payload_begin();
 309  
 310          // Display VIEW:
 311          if( !empty( $list_view ) )
 312          {
 313              $AdminUI->disp_view( $list_view );
 314          }
 315          else
 316          {
 317              $AdminUI->disp_view( 'generic/views/_generic_list.inc.php' );
 318          }
 319  
 320          if( $form_below_list )
 321          {    // Display form after list:
 322              $action = 'new';
 323              $edited_GenericElement = & $GenericElementCache->new_obj();
 324              $edited_GenericElement->disp_form();
 325          }
 326  
 327          // End payload block:
 328          $AdminUI->disp_payload_end();
 329          break;
 330  }
 331  
 332  
 333  // Display body bottom, debug info and close </html>:
 334  $AdminUI->disp_global_footer();
 335  
 336  ?>

title

Description

title

Description

title

Description

title

title

Body