lifetype-1.1.6/class/action/admin/adminaddbloguseraction.class.php
Go to the documentation of this file.00001 <?php
00002
00003 include_once( PLOG_CLASS_PATH."class/action/admin/blogowneradminaction.class.php" );
00004 include_once( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" );
00005 include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00006 include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
00007 include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
00008 include_once( PLOG_CLASS_PATH."class/view/admin/adminbloguserslistview.class.php" );
00009 include_once( PLOG_CLASS_PATH."class/mail/emailservice.class.php" );
00010
00017 class AdminAddBlogUserAction extends BlogOwnerAdminAction
00018 {
00019
00020 var $_sendNotification;
00021 var $_notificationText;
00022 var $_newUsername;
00023
00024 function AdminAddBlogUserAction( $actionInfo, $request )
00025 {
00026 $this->BlogOwnerAdminAction( $actionInfo, $request );
00027
00028
00029 $this->registerFieldValidator( "newBlogUserName", new StringValidator());
00030 $this->_sendNotification = ($this->_request->getValue( "sendNotification" ) != "" );
00031 if( $this->_sendNotification )
00032 $this->registerFieldValidator( "newBlogUserText", new StringValidator());
00033 else
00034 $this->registerField( "newBlogUserText" );
00035 $this->registerField( "sendNotification" );
00036 $view = new AdminTemplatedView( $this->_blogInfo, "addbloguser" );
00037 $view->setErrorMessage( $this->_locale->tr("error_adding_user"));
00038 $this->setValidationErrorView( $view );
00039 }
00040
00041 function sendNotificationEmail( $userInfo )
00042 {
00043
00044
00045 if( $userInfo->getEmail() != "" ) {
00046
00047 $message = new EmailMessage();
00048 $message->setBody( $this->_notificationText );
00049 $message->setSubject( "LifeType Notification" );
00050 $message->addTo( $userInfo->getEmail());
00051 $message->setFrom( $this->_userInfo->getEmail());
00052
00053 $emailService = new EmailService();
00054 $emailService->sendMessage( $message );
00055 }
00056
00057 return true;
00058 }
00059
00060 function perform()
00061 {
00062 $this->_notificationText = $this->_request->getValue( "newBlogUserText" );
00063 $this->_newUsername = Textfilter::filterAllHTML($this->_request->getValue( "newBlogUserName" ));
00064
00065
00066 $users = new Users();
00067 $userInfo = $users->getUserInfoFromUsername( $this->_newUsername );
00068 if( !$userInfo ) {
00069 $this->_view = new AdminTemplatedView( $this->_blogInfo, "addbloguser" );
00070 $this->_view->setErrorMessage( $this->_locale->pr("error_invalid_user"), $this->_newUsername );
00071 $this->_form->setFieldValidationStatus( "newBlogUserName", false );
00072 $this->setCommonData( true );
00073
00074 return false;
00075 }
00076 $this->notifyEvent( EVENT_USER_LOADED, Array( "user" => &$userInfo ));
00077
00078
00079 $userPerms = new UserPermissions();
00080 $perm = new UserPermission( $userInfo->getId(), $this->_blogInfo->getId(), PERMISSION_BLOG_USER );
00081 $res = $userPerms->grantPermission( $perm );
00082 $this->notifyEvent( EVENT_PRE_USER_UPDATE, Array( "user" => &$userInfo ));
00083 if( !$res ) {
00084
00085 $this->_view = new AdminTemplatedView( $this->_blogInfo, "addbloguser" );
00086 $this->_view->setErrorMessage( $this->_locale->pr("error_adding_user", $userInfo->getUsername()));
00087 $this->setCommonData();
00088
00089 return false;
00090 }
00091 $this->notifyEvent( EVENT_POST_USER_UPDATE, Array( "user" => &$userInfo ));
00092
00093
00094 if( $this->_sendNotification ) {
00095 $this->sendNotificationEmail( $userInfo );
00096 }
00097
00098 $this->_view = new AdminBlogUsersListView( $this->_blogInfo );
00099 $this->_view->setSuccessMessage( $this->_locale->pr("user_added_to_blog_ok", $userInfo->getUsername()));
00100 $this->setCommonData();
00101
00102 return true;
00103 }
00104 }
00105 ?>