b2evolution PHP Cross Reference Blogging Systems

Source: /inc/users/userfieldsgroups.ctrl.php - 267 lines - 8703 bytes - Text - Print

Description: 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 is part of the evoCore framework - {@link http://evocore.net/}

   4   * See also {@link http://sourceforge.net/projects/evocms/}.

   5   *

   6   * @copyright (c)2009-2014 by Francois PLANQUE - {@link http://fplanque.net/}

   7   * Parts of this file are copyright (c)2009 by The Evo Factory - {@link http://www.evofactory.com/}.

   8   *

   9   * {@internal License choice

  10   * - If you have received this file as part of a package, please find the license.txt file in

  11   *   the same folder or the closest folder above for complete license terms.

  12   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)

  13   *   then you must choose one of the following licenses before using the file:

  14   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php

  15   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php

  16   * }}

  17   *

  18   * {@internal Open Source relicensing agreement:

  19   * The Evo Factory grants Francois PLANQUE the right to license

  20   * The Evo Factory's contributions to this file and the b2evolution project

  21   * under any OSI approved OSS license (http://www.opensource.org/licenses/).

  22   * }}

  23   *

  24   * @package evocore

  25   *

  26   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  27   * @author evofactory-test

  28   * @author fplanque: Francois Planque.

  29   *

  30   * @version $Id: userfieldsgroups.ctrl.php 6136 2014-03-08 07:59:48Z manuel $

  31   */
  32  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  33  
  34  // Load Userfield class:

  35  load_class( 'users/model/_userfieldgroup.class.php', 'UserfieldGroup' );
  36  
  37  /**

  38   * @var User

  39   */
  40  global $current_User;
  41  
  42  // Check minimum permission:

  43  $current_User->check_perm( 'users', 'view', true );
  44  
  45  // Set options path:

  46  $AdminUI->set_path( 'users', 'usersettings', 'userfields' );
  47  
  48  // Get action parameter from request:

  49  param_action();
  50  
  51  if( param( 'ufgp_ID', 'integer', '', true) )
  52  {// Load userfield group from cache:
  53      $UserfieldGroupCache = & get_UserFieldGroupCache();
  54      if( ($edited_UserfieldGroup = & $UserfieldGroupCache->get_by_ID( $ufgp_ID, false )) === false )
  55      {    // We could not find the user field to edit:
  56          unset( $edited_UserfieldGroup );
  57          forget_param( 'ufgp_ID' );
  58          $Messages->add( sprintf( T_('Requested &laquo;%s&raquo; object does not exist any longer.'), T_('User field group') ), 'error' );
  59          $action = 'nil';
  60      }
  61  }
  62  
  63  
  64  switch( $action )
  65  {
  66  
  67      case 'new':
  68          // Check permission:

  69          $current_User->check_perm( 'users', 'edit', true );
  70  
  71          if( ! isset($edited_UserfieldGroup) )
  72          {    // We don't have a model to use, start with blank object:
  73              $edited_UserfieldGroup = new UserfieldGroup();
  74          }
  75          else
  76          {    // Duplicate object in order no to mess with the cache:
  77              $edited_UserfieldGroup = duplicate( $edited_UserfieldGroup ); // PHP4/5 abstraction

  78              $edited_UserfieldGroup->ID = 0;
  79          }
  80          break;
  81  
  82      case 'edit':
  83          // Check permission:

  84          $current_User->check_perm( 'users', 'edit', true );
  85  
  86          // Make sure we got an ufgp_ID:

  87          param( 'ufgp_ID', 'integer', true );
  88          break;
  89  
  90      case 'create': // Record new UserfieldGroup
  91      case 'create_new': // Record UserfieldGroup and create new
  92      case 'create_copy': // Record UserfieldGroup and create similar
  93          // Insert new user field group...:

  94          $edited_UserfieldGroup = new UserfieldGroup();
  95  
  96          // Check that this action request is not a CSRF hacked request:

  97          $Session->assert_received_crumb( 'userfieldgroup' );
  98  
  99          // Check permission:

 100          $current_User->check_perm( 'users', 'edit', true );
 101  
 102          // load data from request

 103          if( $edited_UserfieldGroup->load_from_Request() )
 104          {    // We could load data from form without errors:
 105  
 106              // Insert in DB:

 107              $DB->begin();
 108              // because of manual assigning ID,

 109              // member function Userfield::dbexists() is overloaded for proper functionality

 110              $q = $edited_UserfieldGroup->dbexists();
 111              if($q)
 112              {    // We have a duplicate entry:
 113  
 114                  param_error( 'ufgp_ID',
 115                      sprintf( T_('This user field group already exists. Do you want to <a %s>edit the existing user field group</a>?'),
 116                          'href="?ctrl=userfieldsgroups&amp;action=edit&amp;ufgp_ID='.$q.'"' ) );
 117              }
 118              else
 119              {
 120                  $edited_UserfieldGroup->dbinsert();
 121                  $Messages->add( T_('New User field group created.'), 'success' );
 122              }
 123              $DB->commit();
 124  
 125              if( empty($q) )
 126              {    // What next?
 127              switch( $action )
 128                  {
 129                      case 'create_copy':
 130                          // Redirect so that a reload doesn't write to the DB twice:

 131                          header_redirect( '?ctrl=userfieldsgroups&action=new&ufgp_ID='.$edited_UserfieldGroup->ID, 303 ); // Will EXIT

 132                          // We have EXITed already at this point!!

 133                          break;
 134                      case 'create_new':
 135                          // Redirect so that a reload doesn't write to the DB twice:

 136                          header_redirect( '?ctrl=userfieldsgroups&action=new', 303 ); // Will EXIT

 137                          // We have EXITed already at this point!!

 138                          break;
 139                      case 'create':
 140                          // Redirect so that a reload doesn't write to the DB twice:

 141                          header_redirect( '?ctrl=userfields', 303 ); // Will EXIT

 142                          // We have EXITed already at this point!!

 143                          break;
 144                  }
 145              }
 146          }
 147          break;
 148  
 149      case 'update':
 150          // Edit user field form...:

 151  
 152          // Check that this action request is not a CSRF hacked request:

 153          $Session->assert_received_crumb( 'userfieldgroup' );
 154  
 155          // Check permission:

 156          $current_User->check_perm( 'users', 'edit', true );
 157  
 158          // Make sure we got an ufgp_ID:

 159          param( 'ufgp_ID', 'integer', true );
 160  
 161          // load data from request

 162          if( $edited_UserfieldGroup->load_from_Request() )
 163          {    // We could load data from form without errors:
 164  
 165              // Update in DB:

 166              $DB->begin();
 167  
 168              $edited_UserfieldGroup->dbupdate();
 169              $Messages->add( T_('User field group updated.'), 'success' );
 170  
 171              $DB->commit();
 172  
 173              header_redirect( '?ctrl=userfields', 303 ); // Will EXIT

 174              // We have EXITed already at this point!!

 175          }
 176          break;
 177  
 178      case 'delete':
 179          // Delete user field:

 180  
 181          // Check that this action request is not a CSRF hacked request:

 182          $Session->assert_received_crumb( 'userfieldgroup' );
 183  
 184          // Check permission:

 185          $current_User->check_perm( 'users', 'edit', true );
 186  
 187          // Make sure we got an ufgp_ID:

 188          param( 'ufgp_ID', 'integer', true );
 189  
 190          if( param( 'confirm', 'integer', 0 ) )
 191          { // confirmed, Delete from DB:
 192              $msg = sprintf( T_('User field group &laquo;%s&raquo; deleted.'), $edited_UserfieldGroup->dget('name') );
 193              $edited_UserfieldGroup->dbdelete( true );
 194              unset( $edited_UserfieldGroup );
 195              forget_param( 'ufgp_ID' );
 196              $Messages->add( $msg, 'success' );
 197              // Redirect so that a reload doesn't write to the DB twice:

 198              header_redirect( '?ctrl=userfields', 303 ); // Will EXIT

 199              // We have EXITed already at this point!!

 200  
 201          }
 202          else
 203          {    // not confirmed, Check for restrictions:
 204              if( ! $edited_UserfieldGroup->check_delete( sprintf( T_('Cannot delete user field group &laquo;%s&raquo;'), $edited_UserfieldGroup->dget('name') ) ) )
 205              {    // There are restrictions:
 206                  $action = 'view';
 207              }
 208          }
 209          break;
 210  
 211  }
 212  
 213  $AdminUI->breadcrumbpath_init( false );  // fp> I'm playing with the idea of keeping the current blog in the path here...

 214  $AdminUI->breadcrumbpath_add( T_('Users'), '?ctrl=users' );
 215  $AdminUI->breadcrumbpath_add( T_('Settings'), '?ctrl=usersettings' );
 216  $AdminUI->breadcrumbpath_add( T_('User fields configuration'), '?ctrl=userfields' );
 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  $AdminUI->disp_payload_begin();
 225  
 226  /**

 227   * Display payload:

 228   */
 229  switch( $action )
 230  {
 231      case 'nil':
 232          // Do nothing

 233          break;
 234  
 235  
 236      case 'delete':
 237          // We need to ask for confirmation:

 238          $edited_UserfieldGroup->confirm_delete(
 239                  sprintf( T_('Delete user field &laquo;%s&raquo;?'), $edited_UserfieldGroup->dget('name') ),
 240                  'userfieldgroup', $action, get_memorized( 'action' ) );
 241          /* no break */

 242      case 'new':
 243      case 'create':
 244      case 'create_new':
 245      case 'create_copy':
 246      case 'edit':
 247      case 'update':    // we return in this state after a validation error
 248          $AdminUI->disp_view( 'users/views/_userfieldsgroup.form.php' );
 249          break;
 250  
 251  
 252      default:
 253          // No specific request, list all user fields:

 254          // Cleanup context:

 255          forget_param( 'ufgp_ID' );
 256          // Display user fields list:

 257          $AdminUI->disp_view( 'users/views/_userfields.view.php' );
 258          break;
 259  
 260  }
 261  
 262  $AdminUI->disp_payload_end();
 263  
 264  // Display body bottom, debug info and close </html>:

 265  $AdminUI->disp_global_footer();
 266  
 267  ?>

title

Description

title

Description

title

Description

title

title

Body