b2evolution PHP Cross Reference Blogging Systems

Source: /inc/files/file_types.ctrl.php - 264 lines - 8252 bytes - Text - Print

Description: This file implements the file types. 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 the file types.
   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: file_types.ctrl.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  // Check minimum permission:
  38  $current_User->check_perm( 'options', 'view', true );
  39  
  40  
  41  param( 'action', 'string' );
  42  
  43  if( param( 'ftyp_ID', 'integer', '', true) )
  44  {// Load file type:
  45      $FiletypeCache = & get_FiletypeCache();
  46      if( ($edited_Filetype = & $FiletypeCache->get_by_ID( $ftyp_ID, false )) === false )
  47      {    // We could not find the file type to edit:
  48          unset( $edited_Filetype );
  49          forget_param( 'ftyp_ID' );
  50          $Messages->add( sprintf( T_('Requested &laquo;%s&raquo; object does not exist any longer.'), T_('File type') ), 'error' );
  51          $action = 'nil';
  52      }
  53  }
  54  
  55  if( isset($edited_Filetype) && ($edited_Filetype !== false) )
  56  {    // We are editing a division:
  57      $AdminUI->append_to_titlearea( '&laquo;<a href="'.regenerate_url('action','action=edit').
  58                                                                      '">'.$edited_Filetype->dget('name').'</a>&raquo;' );
  59  }
  60  
  61  if( $demo_mode && !empty($action) )
  62  {
  63      $Messages->add( 'You cannot make any edits on this screen while in demo mode.', 'error' );
  64      $action = '';
  65  }
  66  
  67  switch( $action )
  68  {
  69      case 'new':
  70          // Check permission:
  71          $current_User->check_perm( 'options', 'edit', true );
  72  
  73          $edited_Filetype = new Filetype();
  74          $AdminUI->append_to_titlearea( T_('Add a file type...') );
  75          break;
  76  
  77      case 'copy':
  78          // Check permission:
  79          $current_User->check_perm( 'options', 'edit', true );
  80  
  81          // Duplicate a file type by prefilling create form:
  82          param( 'ftyp_ID', 'integer', true );
  83          $new_Filetype = $edited_Filetype;    // COPY
  84          $new_Filetype->ID = 0;
  85          $edited_Filetype = & $new_Filetype;
  86          $AdminUI->append_to_titlearea( T_('Copy file type...') );
  87          break;
  88  
  89      case 'edit':
  90          // Edit file type form...:
  91  
  92          // Check permission:
  93          $current_User->check_perm( 'options', 'edit', true );
  94  
  95          // Make sure we got an ftyp_ID:
  96          param( 'ftyp_ID', 'integer', true );
  97           break;
  98  
  99      case 'create':
 100          // Insert new file type...:
 101  
 102          // Check that this action request is not a CSRF hacked request:
 103          $Session->assert_received_crumb( 'filetype' );
 104  
 105          $edited_Filetype = new Filetype();
 106  
 107          // Check permission:
 108          $current_User->check_perm( 'options', 'edit', true );
 109  
 110          // load data from request
 111          if( $edited_Filetype->load_from_Request() )
 112          {    // We could load data from form without errors:
 113              // Insert in DB:
 114              $edited_Filetype->dbinsert();
 115              $Messages->add( T_('New file type created.'), 'success' );
 116  
 117              // What next?
 118              param( 'submit', 'string', true );
 119              if( $submit == T_('Record, then Create Similar') ) // TODO: do not use submit value for this!
 120              {
 121                  $action = 'new';
 122              }
 123              elseif( $submit == T_('Record, then Create New') ) // TODO: do not use submit value for this!
 124              {
 125                  $action = 'new';
 126                  $edited_Filetype = new Filetype();
 127              }
 128              else
 129              {
 130                  $action = 'list';
 131                  // Redirect so that a reload doesn't write to the DB twice:
 132                  header_redirect( '?ctrl=filetypes', 303 ); // Will EXIT
 133                  // We have EXITed already at this point!!
 134              }
 135          }
 136          break;
 137  
 138      case 'update':
 139          // Edit file type form...:
 140  
 141          // Check that this action request is not a CSRF hacked request:
 142          $Session->assert_received_crumb( 'filetype' );
 143  
 144          // Check permission:
 145          $current_User->check_perm( 'options', 'edit', true );
 146  
 147          // Make sure we got an ftyp_ID:
 148          param( 'ftyp_ID', 'integer', true );
 149  
 150          // load data from request
 151          if( $edited_Filetype->load_from_Request() )
 152          {    // We could load data from form without errors:
 153              // Update in DB:
 154              $edited_Filetype->dbupdate();
 155              $Messages->add( T_('File type updated.'), 'success' );
 156              $action = 'list';
 157              //save fadeout item
 158              $Session->set('fadeout_id', $ftyp_ID);
 159              // Redirect so that a reload doesn't write to the DB twice:
 160              header_redirect( '?ctrl=filetypes', 303 ); // Will EXIT
 161              // We have EXITed already at this point!!
 162          }
 163          break;
 164  
 165      case 'delete':
 166          // Delete file type:
 167  
 168          // Check that this action request is not a CSRF hacked request:
 169          $Session->assert_received_crumb( 'filetype' );
 170  
 171          // Check permission:
 172          $current_User->check_perm( 'options', 'edit', true );
 173  
 174          // Make sure we got an ftyp_ID:
 175          param( 'ftyp_ID', 'integer', true );
 176  
 177          if( param( 'confirm', 'integer', 0 ) )
 178          { // confirmed, Delete from DB:
 179              $msg = sprintf( T_('File type &laquo;%s&raquo; deleted.'), $edited_Filetype->dget('name') );
 180              $edited_Filetype->dbdelete( true );
 181              unset( $edited_Filetype );
 182              forget_param( 'ftyp_ID' );
 183              $Messages->add( $msg, 'success' );
 184              $action = 'list';
 185              // Redirect so that a reload doesn't write to the DB twice:
 186              header_redirect( '?ctrl=filetypes', 303 ); // Will EXIT
 187              // We have EXITed already at this point!!
 188          }
 189          else
 190          {    // not confirmed, Check for restrictions:
 191              if( ! $edited_Filetype->check_delete( sprintf( T_('Cannot delete file type &laquo;%s&raquo;'), $edited_Filetype->dget('name') ) ) )
 192              {    // There are restrictions:
 193                  $action = 'view';
 194              }
 195          }
 196          break;
 197  }
 198  
 199  
 200  /**
 201   * We need make this call to build menu for all modules
 202   */
 203  $AdminUI->set_path( 'files' );
 204  
 205  file_controller_build_tabs();
 206  
 207  $AdminUI->set_path( 'files', 'settings', 'filetypes' );
 208  
 209  // fp> TODO: this here is a bit sketchy since we have Blog & fileroot not necessarilly in sync. Needs investigation / propositions.
 210  // Note: having both allows to post from any media dir into any blog.
 211  $AdminUI->breadcrumbpath_init( false );
 212  $AdminUI->breadcrumbpath_add( T_('Files'), '?ctrl=files&amp;blog=$blog$' );
 213  $AdminUI->breadcrumbpath_add( T_('Settings'), '?ctrl=fileset' );
 214  $AdminUI->breadcrumbpath_add( T_('File types'), '?ctrl=filetypes' );
 215  
 216  // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)
 217  $AdminUI->disp_html_head();
 218  
 219  // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)
 220  $AdminUI->disp_body_top();
 221  
 222  
 223  /**
 224   * Display payload:
 225   */
 226  switch( $action )
 227  {
 228      case 'nil':
 229          // Do nothing
 230          break;
 231  
 232  
 233      case 'delete':
 234          // We need to ask for confirmation:
 235          $edited_Filetype->confirm_delete(
 236                  sprintf( T_('Delete file type &laquo;%s&raquo;?'),  $edited_Filetype->dget('name') ),
 237                  'filetype', $action, get_memorized( 'action' ) );
 238          /* no break */
 239      case 'new':
 240      case 'copy':
 241      case 'create':    // we return in this state after a validation error
 242      case 'edit':
 243      case 'update':    // we return in this state after a validation error
 244          $AdminUI->disp_payload_begin();
 245          $AdminUI->disp_view( 'files/views/_filetype.form.php' );
 246          $AdminUI->disp_payload_end();
 247          break;
 248  
 249  
 250      default:
 251              // No specific request, list all file types:
 252              // Cleanup context:
 253              forget_param( 'ftype_ID' );
 254              // Display file types list:
 255              $AdminUI->disp_payload_begin();
 256              $AdminUI->disp_view( 'files/views/_filetype_list.view.php' );
 257              $AdminUI->disp_payload_end();
 258  
 259  }
 260  
 261  // Display body bottom, debug info and close </html>:
 262  $AdminUI->disp_global_footer();
 263  
 264  ?>

title

Description

title

Description

title

Description

title

title

Body