[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/action/admin/ -> adminmainaction.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
   5  
   6      /**
   7       * \ingroup Action
   8       * @private
   9       *
  10       * Sample action on how to develop our own actions.
  11       *
  12       * Please also refer to SampleView.class.php for more information
  13       */
  14      class AdminMainAction extends AdminAction 
  15      {
  16  
  17          /**
  18           * Constructor. If nothing else, it also has to call the constructor of the parent
  19           * class, BlogAction with the same parameters
  20           */
  21          function AdminMainAction( $actionInfo, $request )
  22          {
  23              $this->AdminAction( $actionInfo, $request );
  24          }
  25  
  26          /**
  27           * Validate if everything is correct
  28           */
  29          function validate()
  30          {
  31              // first of all, check if we have a valid blog id
  32              $this->_blogId = $this->_request->getValue( "blogId" );
  33              if( $this->_blogId == "" || $this->_blogId < 0 ) {
  34                  lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
  35                  
  36                  // check if the user really belongs to one or more blogs and if not, quit
  37                  $users = new Users();
  38                  $userBlogs = $users->getUsersBlogs( $this->_userInfo->getId(), BLOG_STATUS_ACTIVE );
  39                  if( count($userBlogs) == 0 ) {
  40                      lt_include( PLOG_CLASS_PATH."class/view/admin/adminsimpleerrorview.class.php" );    
  41                      $this->_view = new AdminSimpleErrorView();
  42                      $this->_view->setValue( "message", $this->_locale->tr("error_dont_belong_to_any_blog" ));
  43                      
  44                      return false;
  45                  }
  46                  
  47                  // if everything went fine, then we can continue...
  48                  lt_include( PLOG_CLASS_PATH."class/view/admin/admindashboardview.class.php" );    
  49  
  50                  $this->_view = new AdminDashboardView( $this->_userInfo, $userBlogs );
  51                  return false;
  52              }
  53  
  54              // load the blog
  55              lt_include( PLOG_CLASS_PATH . "class/dao/blogs.class.php" );
  56              $blogs = new Blogs();
  57              $this->_blogInfo = $blogs->getBlogInfo( $this->_blogId );
  58               
  59              // check if the blog really exists
  60              if( !$this->_blogInfo ) {
  61                  lt_include( PLOG_CLASS_PATH."class/view/admin/adminsimpleerrorview.class.php" );    
  62  
  63                  $this->_view = new AdminSimpleErrorView();
  64                  $this->_view->setValue( "message", $this->_locale->tr("error_incorrect_blog_id" ));
  65                  
  66                  return false;                      
  67              }
  68              
  69              // if so, check that it is active
  70              if( $this->_blogInfo->getStatus() != BLOG_STATUS_ACTIVE ) {
  71                  lt_include( PLOG_CLASS_PATH."class/view/admin/adminsimpleerrorview.class.php" );                    
  72                  $this->_view = new AdminSimpleErrorView();
  73                  $this->_view->setValue( "message", $this->_locale->tr("error_incorrect_blog_id" ));
  74                  
  75                  return false;                
  76              }
  77  
  78              // if the blog identifier is valid, now we should now check if the user belongs
  79              // to that blog so that we know for sure that nobody has tried to forge the
  80              // parameter in the meantime             
  81              $userPermissions = new UserPermissions();
  82              $blogUserPermissions = $userPermissions->getUserPermissions( $this->_userInfo->getId(), $this->_blogInfo->getId());
  83              if( (!$blogUserPermissions) && ($this->_blogInfo->getOwnerId() != $this->_userInfo->getId())) {
  84                  lt_include( PLOG_CLASS_PATH."class/view/admin/adminsimpleerrorview.class.php" );    
  85  
  86                  $this->_view = new AdminSimpleErrorView();
  87                  $this->_view->setValue( "message", $this->_locale->tr("error_no_permissions" ));
  88                  
  89                  return false;         
  90              }
  91  
  92              // if all correct, we can now set the blogInfo object in the session for later
  93              // use
  94              $this->_session->setValue( "blogInfo", $this->_blogInfo );
  95              $session = HttpVars::getSession();
  96              $session["SessionInfo"] = $this->_session;
  97              $session["SessionInfo"]->setValue( "blogId", $this->_blogInfo->getId() );
  98              HttpVars::setSession( $session );
  99  
 100              return true;
 101          }
 102  
 103          /**
 104           * Carries out the specified action
 105           */
 106          function perform()
 107          {
 108              // we don't have to worry about much more here, we can let the
 109              // $this->_nextAction action take care of everytyhing now...
 110              // If $this->_nextAction is null, we use "newPost" as default nextAction
 111                          
 112              $this->_nextAction = $this->_request->getValue( "action" );
 113  
 114              if ( $this->_nextAction ) {
 115                  AdminController::setForwardAction( $this->_nextAction );
 116              } else {
 117                  if( $this->userHasPermission( "new_post" ))
 118                      AdminController::setForwardAction( "newPost" );
 119                  else
 120                      AdminController::setForwardAction( "Manage" );
 121              }
 122              
 123              // better to return true if everything fine
 124              return true;
 125          }
 126      }
 127  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics