[ 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/ -> adminaddbloguseraction.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/view/admin/adminnewbloguserview.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
   8      lt_include( PLOG_CLASS_PATH."class/view/admin/adminbloguserslistview.class.php" );
   9      lt_include( PLOG_CLASS_PATH."class/mail/emailservice.class.php" );
  10  
  11      /**
  12       * \ingroup Action
  13       * @private
  14       *
  15       * Adds a user to the blog
  16       */
  17      class AdminAddBlogUserAction extends AdminAction 
  18      {
  19  
  20          var $_sendNotification;
  21          var $_notificationText;
  22          var $_newUsername;
  23          var $_permissions;
  24  
  25      	function AdminAddBlogUserAction( $actionInfo, $request )
  26          {
  27              $this->AdminAction( $actionInfo, $request );
  28              
  29              // data validation
  30              $this->registerFieldValidator( "newBlogUserName", new StringValidator());
  31              
  32              $this->_sendNotification = ($this->_request->getValue( "sendNotification" ) != "" );
  33              
  34              if( $this->_sendNotification ) {
  35                  $this->registerFieldValidator( "newBlogUserText", new StringValidator());
  36              }
  37              else {
  38                  $this->registerField( "newBlogUserText" );        
  39              }        
  40                          
  41              $this->registerField( "sendNotification" );
  42              $this->registerField( "perm" );
  43              $view = new AdminNewBlogUserView( $this->_blogInfo );
  44              $view->setErrorMessage( $this->_locale->tr("error_adding_user"));
  45              $this->setValidationErrorView( $view );
  46              
  47              $this->requirePermission( "add_blog_user" );
  48          }
  49  
  50          function sendNotificationEmail( &$userInfo )
  51          {
  52              // if everything went fine, we can now send the confirmation email
  53              // only if the user specified a valid email address
  54              if( $userInfo->getEmail() != "" ) {
  55                  // build an email message
  56                  $message = new EmailMessage();
  57                  $message->setBody( $this->_notificationText );
  58                  $message->setSubject( $this->_locale->tr("notification_subject") );
  59                  $message->addTo( $userInfo->getEmail());
  60                  $message->setFrom( $this->_userInfo->getEmail());
  61                  // and finally send it
  62                  $emailService = new EmailService();
  63                  $emailService->sendMessage( $message );
  64              }
  65  
  66              return true;
  67          }
  68  
  69          function perform()
  70          {
  71              $this->_notificationText = $this->_request->getValue( "newBlogUserText" );
  72              $this->_newUsername = Textfilter::filterAllHTML($this->_request->getValue( "newBlogUserName" ));
  73              $this->_perms = $this->_request->getValue( "perm" );
  74          
  75              // see if the user exists
  76              $users = new Users();
  77              $userInfo = $users->getUserInfoFromUsername( $this->_newUsername );
  78              if( !$userInfo ) {
  79                  $this->_view = new AdminNewBlogUserView( $this->_blogInfo );
  80                  $this->_view->setErrorMessage( $this->_locale->pr("error_invalid_user"), $this->_newUsername );
  81                  $this->_form->setFieldValidationStatus( "newBlogUserName", false );
  82                  $this->setCommonData( true );
  83  
  84                  return false;
  85              }
  86              $this->notifyEvent( EVENT_USER_LOADED, Array( "user" => &$userInfo ));            
  87  
  88              // get the permissions that this user will be granted
  89              $userPerms = new UserPermissions();
  90              if( is_array( $this->_perms )) {
  91                  foreach( $this->_perms as $val => $permId ) {
  92                      $perm = new UserPermission( $userInfo->getId(), $this->_blogInfo->getId(), $permId );
  93                      $res = $userPerms->grantPermission( $perm );
  94                  }
  95              }
  96              
  97              $this->notifyEvent( EVENT_PRE_USER_UPDATE, Array( "user" => &$userInfo ));
  98              if( !$res ) {
  99                  // there was an error adding the user to the blog
 100                  $this->_view = new AdminNewBlogUserView( $this->_blogInfo );
 101                  $this->_view->setErrorMessage( $this->_locale->pr("error_adding_user", $userInfo->getUsername()));
 102                  $this->setCommonData();
 103  
 104                  return false;
 105              }
 106              $this->notifyEvent( EVENT_POST_USER_UPDATE, Array( "user" => &$userInfo ));
 107  
 108              // send a notification if enabled
 109              if( $this->_sendNotification ) {
 110                  $this->sendNotificationEmail( $userInfo );
 111              }
 112  
 113              if( $this->userHasPermission( "view_blog_users" ))  {
 114                  $this->_view = new AdminBlogUsersListView( $this->_blogInfo );
 115              }
 116              else {
 117                  $this->_view = new AdminNewBlogUserView( $this->_blogInfo );
 118              }
 119                  
 120              $this->_view->setSuccessMessage( $this->_locale->pr("user_added_to_blog_ok", $userInfo->getUsername()));
 121              $this->setCommonData();
 122  
 123              return true;
 124          }
 125          
 126      }
 127  ?>


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