b2evolution PHP Cross Reference Blogging Systems

Source: /inc/generic/inc/_generic_recursive_listeditor.php - 309 lines - 8975 bytes - Text - Print

Description: This file implements the generic recursive list editor NOTE: It uses <code>$AdminUI->get_path(1).'.php'</code> to link back to the ID of the entry. If that causes problems later, we'd probably need to set a global like $listeditor_url.

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

title

Description

title

Description

title

Description

title

title

Body