b2evolution PHP Cross Reference Blogging Systems

Source: /inc/sessions/goals.ctrl.php - 287 lines - 7742 bytes - Text - Print

Description: This file implements the goals. b2evolution - {@link http://b2evolution.net/} Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}

   1  <?php
   2  /**
   3   * This file implements the goals.
   4   *
   5   * b2evolution - {@link http://b2evolution.net/}
   6   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
   7   *
   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   9   *
  10   * @package admin
  11   *
  12   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  13   * @author fplanque: Francois PLANQUE.
  14   *
  15   * @version $Id: goals.ctrl.php 6136 2014-03-08 07:59:48Z manuel $
  16   */
  17  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  18  
  19  load_class( 'sessions/model/_goal.class.php', 'Goal' );
  20  load_funcs('sessions/model/_hitlog.funcs.php');
  21  
  22  /**
  23   * @var User
  24   */
  25  global $current_User;
  26  
  27  global $dispatcher;
  28  
  29  $blog = 0;
  30  
  31  // Do we have permission to view all stats (aggregated stats) ?
  32  $current_User->check_perm( 'stats', 'view', true );
  33  
  34  $tab3 = param( 'tab3', 'string', 'goals', true );
  35  $AdminUI->set_path( 'stats', 'goals', $tab3 );
  36  
  37  param_action();
  38  
  39  if( param( 'goal_ID', 'integer', '', true) )
  40  {// Load file type:
  41      $GoalCache = & get_GoalCache();
  42      if( ($edited_Goal = & $GoalCache->get_by_ID( $goal_ID, false )) === false )
  43      {    // We could not find the goal to edit:
  44          unset( $edited_Goal );
  45          forget_param( 'goal_ID' );
  46          $Messages->add( sprintf( T_('Requested &laquo;%s&raquo; object does not exist any longer.'), T_('Goal') ), 'error' );
  47          $action = 'nil';
  48      }
  49  }
  50  
  51  switch( $action )
  52  {
  53  
  54      case 'new':
  55      case 'copy':
  56          // Check permission:
  57          $current_User->check_perm( 'stats', 'edit', true );
  58  
  59          if( ! isset($edited_Goal) )
  60          {    // We don't have a model to use, start with blank object:
  61              $edited_Goal = new Goal();
  62          }
  63          else
  64          {    // Duplicate object in order no to mess with the cache:
  65              $edited_Goal = duplicate( $edited_Goal ); // PHP4/5 abstraction
  66              $edited_Goal->ID = 0;
  67          }
  68          break;
  69  
  70      case 'edit':
  71          // Edit file type form...:
  72  
  73          // Check permission:
  74          $current_User->check_perm( 'stats', 'edit', true );
  75  
  76          // Make sure we got an ftyp_ID:
  77          param( 'goal_ID', 'integer', true );
  78           break;
  79  
  80      case 'create': // Record new goal
  81      case 'create_new': // Record goal and create new
  82      case 'create_copy': // Record goal and create similar
  83          // Insert new file type...:
  84          $edited_Goal = new Goal();
  85  
  86          // Check that this action request is not a CSRF hacked request:
  87          $Session->assert_received_crumb( 'goal' );
  88  
  89          // Check permission:
  90          $current_User->check_perm( 'stats', 'edit', true );
  91  
  92          // load data from request
  93          if( $edited_Goal->load_from_Request() )
  94          {    // We could load data from form without errors:
  95  
  96              // Insert in DB:
  97              $DB->begin();
  98              $q = $edited_Goal->dbexists();
  99              if($q)
 100              {    // We have a duplicate entry:
 101  
 102                  param_error( 'goal_key',
 103                      sprintf( T_('This goal already exists. Do you want to <a %s>edit the existing goal</a>?'),
 104                          'href="?ctrl=goals&amp;action=edit&amp;goal_ID='.$q.'"' ) );
 105              }
 106              else
 107              {
 108                  $edited_Goal->dbinsert();
 109                  $Messages->add( T_('New goal created.'), 'success' );
 110              }
 111              $DB->commit();
 112  
 113              if( empty($q) )
 114              {    // What next?
 115                  switch( $action )
 116                  {
 117                      case 'create_copy':
 118                          // Redirect so that a reload doesn't write to the DB twice:
 119                          header_redirect( '?ctrl=goals&action=new&goal_ID='.$edited_Goal->ID, 303 ); // Will EXIT
 120                          // We have EXITed already at this point!!
 121                          break;
 122                      case 'create_new':
 123                          // Redirect so that a reload doesn't write to the DB twice:
 124                          header_redirect( '?ctrl=goals&action=new', 303 ); // Will EXIT
 125                          // We have EXITed already at this point!!
 126                          break;
 127                      case 'create':
 128                          // Redirect so that a reload doesn't write to the DB twice:
 129                          header_redirect( '?ctrl=goals', 303 ); // Will EXIT
 130                          // We have EXITed already at this point!!
 131                          break;
 132                  }
 133              }
 134          }
 135          break;
 136  
 137      case 'update':
 138          // Edit file type form...:
 139  
 140          // Check that this action request is not a CSRF hacked request:
 141          $Session->assert_received_crumb( 'goal' );
 142  
 143          // Check permission:
 144          $current_User->check_perm( 'stats', 'edit', true );
 145  
 146          // Make sure we got an ftyp_ID:
 147          param( 'goal_ID', 'integer', true );
 148  
 149          // load data from request
 150          if( $edited_Goal->load_from_Request() )
 151          {    // We could load data from form without errors:
 152  
 153              // Update in DB:
 154              $DB->begin();
 155              $q = $edited_Goal->dbexists();
 156              if($q)
 157              {    // We have a duplicate entry:
 158  
 159                  param_error( 'goal_key',
 160                      sprintf( T_('This goal already exists. Do you want to <a %s>edit the existing goal</a>?'),
 161                          'href="?ctrl=goals&amp;action=edit&amp;goal_ID='.$q.'"' ) );
 162              }
 163              else
 164              {
 165                  $edited_Goal->dbupdate();
 166                  $Messages->add( T_('Goal updated.'), 'success' );
 167              }
 168              $DB->commit();
 169  
 170              if( empty($q) )
 171              {
 172                  $action = 'list';
 173                  // Redirect so that a reload doesn't write to the DB twice:
 174                  header_redirect( '?ctrl=goals', 303 ); // Will EXIT
 175                  // We have EXITed already at this point!!
 176              }
 177          }
 178  
 179  
 180          break;
 181  
 182      case 'delete':
 183          // Delete file type:
 184  
 185          // Check that this action request is not a CSRF hacked request:
 186          $Session->assert_received_crumb( 'goal' );
 187  
 188          // Check permission:
 189          $current_User->check_perm( 'stats', 'edit', true );
 190  
 191          // Make sure we got an ftyp_ID:
 192          param( 'goal_ID', 'integer', true );
 193  
 194          if( param( 'confirm', 'integer', 0 ) )
 195          { // confirmed, Delete from DB:
 196              $msg = sprintf( T_('Goal &laquo;%s&raquo; deleted.'), $edited_Goal->dget('name') );
 197              $edited_Goal->dbdelete( true );
 198              unset( $edited_Goal );
 199              forget_param( 'goal_ID' );
 200              $Messages->add( $msg, 'success' );
 201              // Redirect so that a reload doesn't write to the DB twice:
 202              header_redirect( '?ctrl=goals', 303 ); // Will EXIT
 203              // We have EXITed already at this point!!
 204          }
 205          else
 206          {    // not confirmed, Check for restrictions:
 207              if( ! $edited_Goal->check_delete( sprintf( T_('Cannot delete goal &laquo;%s&raquo;'), $edited_Goal->dget('name') ) ) )
 208              {    // There are restrictions:
 209                  $action = 'view';
 210              }
 211          }
 212          break;
 213  
 214  }
 215  
 216  $AdminUI->breadcrumbpath_init();
 217  $AdminUI->breadcrumbpath_add( T_('Analytics'), '?ctrl=stats' );
 218  $AdminUI->breadcrumbpath_add( T_('Goal tracking'), '?ctrl=goals' );
 219  switch( $tab3 )
 220  {
 221      case 'goals':
 222          $AdminUI->breadcrumbpath_add( T_('Goal definitions'), '?ctrl=goals' );
 223          break;
 224      case 'stats':
 225          $AdminUI->breadcrumbpath_add( T_('Goal hit stats'), '?ctrl=goals&amp;tab3=stats' );
 226          break;
 227  }
 228  
 229  // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)
 230  $AdminUI->disp_html_head();
 231  
 232  // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)
 233  $AdminUI->disp_body_top();
 234  
 235  $AdminUI->disp_payload_begin();
 236  
 237  /**
 238   * Display payload:
 239   */
 240  switch( $action )
 241  {
 242      case 'nil':
 243          // Do nothing
 244          break;
 245  
 246  
 247      case 'delete':
 248          // We need to ask for confirmation:
 249          $edited_Goal->confirm_delete(
 250                  sprintf( T_('Delete goal &laquo;%s&raquo;?'), $edited_Goal->dget('name') ),
 251                  'goal', $action, get_memorized( 'action' ) );
 252          /* no break */
 253      case 'new':
 254      case 'copy':
 255      case 'create':    // we return in this state after a validation error
 256      case 'create_new':    // we return in this state after a validation error
 257      case 'create_copy':    // we return in this state after a validation error
 258      case 'edit':
 259      case 'update':    // we return in this state after a validation error
 260          $AdminUI->disp_view( 'sessions/views/_goal.form.php' );
 261          break;
 262  
 263  
 264      default:
 265          // No specific request, list all file types:
 266          switch( $tab3 )
 267          {
 268              case 'goals':
 269                  // Cleanup context:
 270                  forget_param( 'goal_ID' );
 271                  // Display goals list:
 272                  $AdminUI->disp_view( 'sessions/views/_stats_goals.view.php' );
 273                  break;
 274  
 275              case 'stats':
 276                  $AdminUI->disp_view( 'sessions/views/_goal_hitsummary.view.php' );
 277                  break;
 278          }
 279  
 280  }
 281  
 282  $AdminUI->disp_payload_end();
 283  
 284  // Display body bottom, debug info and close </html>:
 285  $AdminUI->disp_global_footer();
 286  
 287  ?>

title

Description

title

Description

title

Description

title

title

Body