* @copyright 2004 by http://wombat.exit0.net * @package wombatSite * @subpackage account */ /** * * * @version 0.1 * @package wombatSite * @subpackage account */ class wbAccount { /** * @access private * @var string $_tmplDir */ var $_tmplDir = 'account'; /** * @access private * @var string $_baseDir */ var $_baseDir; /** * request variables * @var array $_request */ var $_request = array(); /** * named groups to add new users * @var array $_defaultGroups */ var $_defaultGroups = array(); /** * email headers * @var array $_emailHeader */ var $_emailHeader = array( 'from' => 'Usermanager 'User account', 'x-mailer' => 'Wombat user account manager' ); /** * constructor creates datasource * @access public */ function __construct() { $this->_tmpl =& wbFactory::singleton( 'patTemplate' ); $this->_sess =& wbFactory::singleton( 'patSession' ); $this->_baseDir = wbFactory::getParam( 'baseDir' ) . '/templates'; } /** * constructor wrapper for PHP4 * @access public */ function wbAccount() { $this->__construct(); } /** * set template directory * * @access public * @param string $dir name of template-sub-dir * @param string $baseDir location of template dir * @return boolean true on success */ function setTemplateDir( $dir, $baseDir = null ) { $this->_tmplDir = $dir; if( $baseDir ) { $this->_baseDir = $baseDir; } return true; } /** * recieve template dir * * @access private * @return string $dir name of template-sub-dir */ function getTemplateDir() { return $this->_tmplDir; } /** * set request data (_POST, _GET) * * @access public * @param string $dir name of template-sub-dir * @return boolean true on success */ function setRequest( $req ) { $this->_request = $req; if( !isset( $this->_request['action'] ) ) { $this->_request['action'] = '_no_action_set_'; } return true; } /** * set default groups * * @access public * @param array $groups list of groups * @return boolean true on success */ function setDefaultGroups( $groups ) { $this->_defaultGroups = $groups; return true; } /** * set email header * * @access public * @param string $key name header name * @param string $value value string * @return boolean true on success */ function setEmailHeader( $key, $value ) { $this->_emailHeader[$key] = $value; return true; } /** * run account manager * - modify data of existing users * - change user flags * - manager group membership * * * @access private * @return boolean $result true on success */ function processManager() { switch( $this->_request['action'] ) { case 'userlist': return $this->_displayUserList(); break; case 'useradd': return $this->_displayUserAdd(); break; case 'useredit': return $this->_displayUserEdit(); break; case 'usersave': return $this->_displayUserSave(); break; case 'usercreatepasswd': return $this->_displayCreatePasswd(); break; case 'userdelete': return $this->_displayUserDelete(); break; case 'grouplist': return $this->_displayGroupList(); break; case 'groupadd': return $this->_displayGroupAdd(); break; case 'groupedit': return $this->_displayGroupEdit(); break; case 'groupsave': return $this->_displayGroupSave(); break; case 'groupdelete': return $this->_displayGroupDelete(); break; case 'usergroup': return $this->_displayUsergroup(); break; case 'usergroupsave': return $this->_displayUsergroupSave(); break; case 'groupuser': return $this->_displayGroupuser(); break; case 'groupusersave': return $this->_displayGroupuserSave(); break; case 'overview': default: return $this->_displayOverview(); break; } } /** * display overview and menu for user manager * - list unapproved users * - allow to approve user account * * * @access public * @return string $html */ function _displayOverview() { $this->_loadTemplates( 'accountmanager_overview' ); $user =& wbFactory::singleton( 'wbUser_Admin' ); // approve user if( isset( $this->_request['approve'] ) ) { $user->approveUser( $this->_request['approve'] ); } // display list if unapproved users $unapproved = $user->getUnapprovedUsers(); if( empty( $unapproved ) ) { return $this->_tmpl->getParsedTemplate( 'manager' ); } $this->_tmpl->setAttribute( 'unapproved', 'visibility', 'visible' ); $this->_tmpl->addRows( 'unapproved_entry', $unapproved ); return $this->_tmpl->getParsedTemplate( 'manager' ); } /** * handle process to create a new login password for users * * * - user must idetentify himeself * (by username, email, ...) * - create hash, that allows users to create new password * - recieve hash from user * - create new password and notify user * * @access private * @return boolean $result true on success */ function renewPassword() { $user = wbFactory::singleton( 'wbUser_Admin' ); // create new password if( $this->_request['action'] == 'renew' && isset( $this->_request['hash'] ) && $this->_request['id'] ) { $userData = $user->getUserData( $this->_request['id'] ); if( patErrorManager::isError( $userData ) ) { return $userData; } // password my only be changed if the ID is valid if( is_array( $userData ) ) { ksort( $userData ); $hash = md5( serialize( $userData ) ); if( $hash === $this->_request['hash'] ) { // create new password and notify user $new = array(); $new['password'] = $user->createPasswd(); $user->setUserData( $new, $this->_request['id'] ); $this->_notifyUser( $userData, $new, 'passwordrenew_completeemail' ); $this->_loadTemplates( 'passwordrenew_complete' ); return $this->_tmpl->getParsedTemplate( 'success' ); } } } $params = array( 'template' => 'passwordrenew', 'template_dir' => $this->_tmplDir, 'base_dir' => $this->_baseDir ); $form =& wbFactory::singleton( 'patForms', $params ); if( $this->_request['action'] === 'save' ) { $form->setSubmitted( true ); if( $form->validateForm() ) { $data = $form->getValues(); $users = $user->findUsers( $data ); if( count( $users ) === 1 ) { if( !$this->_checkReload() ) { // create hash $userData = $users[0]; ksort( $userData ); $hash = md5( serialize( $userData ) ); $mailData = array( 'hash' => $hash ); $this->_notifyUser( $userData, $mailData, 'passwordrenew_email' ); } $this->_loadTemplates( 'passwordrenew_identified' ); return $this->_tmpl->getParsedTemplate( 'success' ); } $error = array( 'field_name' => 'form', 'error_message' => 'The user could not be identified!' ); $this->_tmpl->addVars( 'formErrors_entry', $error ); $this->_tmpl->setAttribute( 'formErrors', 'visibility', 'visible' ); } } $form->renderForm( array( 'template' => 'form', 'errorTemplateContainer' => 'formErrors', 'errorTemplate' => 'formErrors_entry' ) ); return $this->_tmpl->getParsedTemplate( 'form' ); } /** * change details of account * * @access public * @return boolean $result true on success * @todo handle error */ function editAccountData() { $params = array( 'template' => 'accountedit', 'template_dir' => $this->_tmplDir, 'base_dir' => $this->_baseDir ); $form =& wbFactory::singleton( 'patForms', $params ); $user = wbFactory::singleton( 'wbUser_Admin' ); if( $this->_request['action'] === 'save' ) { $form->setSubmitted( true ); if( $form->validateForm() ) { if( !$this->_checkReload() ) { $data = $form->getValues(); $result = $user->setUserData( $data ); if( !$result['success'] ) { // handle error } } $this->_loadTemplates( 'accountedit_success' ); return $this->_tmpl->getParsedTemplate( 'success' ); } } else { $form->setValues( $user->getUserData() ); } $form->renderForm( array( 'template' => 'form', 'errorTemplateContainer' => 'formErrors', 'errorTemplate' => 'formErrors_entry' ) ); return $this->_tmpl->getParsedTemplate( 'form' ); } /** * change password of user * - check if user is logged on and allow to change password * * @access public * @return boolean $result true on success */ function changePassword() { $params = array( 'template' => 'password', 'template_dir' => $this->_tmplDir, 'base_dir' => $this->_baseDir ); $form =& wbFactory::singleton( 'patForms', $params ); // add rule to retype password $retype = &patForms::createRule( 'Retype' ); $retype->setFieldNames( 'new', 'retype' ); $form->addRule( $retype, PATFORMS_RULE_AFTER_VALIDATION ); if( $this->_request['action'] === 'save' ) { $form->setSubmitted( true ); if( $form->validateForm() && !$this->_checkReload() ) { $user = wbFactory::singleton( 'wbUser_Admin' ); $data = $form->getValues(); $result = $user->changePasswd( $data['old'], $data['new'], $data['retype'] ); $error = array(); switch( $result ) { // everything worked fine case 0: $this->_loadTemplates( 'password_success' ); return $this->_tmpl->getParsedTemplate( 'success' ); break; // wrong old password case 1: $el =& $form->getElement( 'old' ); $error = array( 'field_title' => $el->getAttribute( 'title' ), 'field_label' => $el->getAttribute( 'label' ), 'field_name' => 'old', 'error_message' => 'The current password was misspelled.' ); break; // passwod confirmation missmatch - catched by the rule case 2: $error = array( 'field_name' => 'form', 'error_message' => 'The new password and the repeated password don\'t match.' ); break; // user not logged in. case -1: break; } if( !empty( $error ) ) { $this->_tmpl->addVars( 'formErrors_entry', $error ); $this->_tmpl->setAttribute( 'formErrors', 'visibility', 'visible' ); } } } $form->renderForm( array( 'template' => 'form', 'errorTemplateContainer' => 'formErrors', 'errorTemplate' => 'formErrors_entry' ) ); return $this->_tmpl->getParsedTemplate( 'form' ); } /** * activate new account * - activate new users * - check login and password * * @access private * @return boolean $result true on success */ function activateAccount() { $user = wbFactory::singleton( 'wbUser_Admin' ); if( $user->isAuthenticated() ) { $this->_loadTemplates( 'activateaccount_old' ); return $this->_tmpl->getParsedTemplate( 'success' ); } $params = array( 'template' => 'activateaccount', 'base_dir' => $this->_baseDir ); $form =& wbFactory::singleton( 'patForms', $params ); if( $this->_request['action'] === 'save' ) { $form->setSubmitted( true ); if( $form->validateForm() ) { $data = $form->getValues(); $user = wbFactory::singleton( 'wbUser_Admin' ); $result = $user->activateUser( $data['user'], $data['password'] ); if( patErrorManager::isError( $result ) ) { return $result; } // if everything went right... if( $result ) { $this->_loadTemplates( 'activateaccount_success' ); return $this->_tmpl->getParsedTemplate( 'success' ); } $error = array( 'field_name' => 'form', 'error_message' => 'Could not activate user!' ); $this->_tmpl->addVars( 'formErrors_entry', $error ); $this->_tmpl->setAttribute( 'formErrors', 'visibility', 'visible' ); } } $form->renderForm( array( 'template' => 'form', 'errorTemplateContainer' => 'formErrors', 'errorTemplate' => 'formErrors_entry' ) ); return $this->_tmpl->getParsedTemplate( 'form' ); } /** * create new user account * - insert new user into database * - create user-password * - send notification email * * * @access public * @return string $result html code of this part */ function registerUser() { $params = array( 'template' => 'newaccount', 'template_dir' => $this->_tmplDir, 'base_dir' => $this->_baseDir ); $form =& wbFactory::singleton( 'patForms', $params ); if( $this->_request['action'] === 'save' ) { $form->setSubmitted( true ); if( $form->validateForm() ) { $data = $form->getValues(); $user = wbFactory::singleton( 'wbUser_Admin' ); $new = $user->addNewUser( $data, $this->_defaultGroups ); if( $new['success'] ) { $this->_notifyNewUser( $data['realname'], $data['email'], $new['password_clear'] ); $this->_loadTemplates( 'newaccount_success' ); return $this->_tmpl->getParsedTemplate( 'success' ); } if( $new['error'] == 'dublicates' ) { $el =& $form->getElement( 'user' ); $error = array( 'field_label' => $el->getAttribute( 'label' ), 'field_title' => $el->getAttribute( 'title' ), 'field_name' => 'user', 'error_message' => 'The entered login-name is already in use - please choose a different name.' ); $this->_tmpl->addVars( 'formErrors_entry', $error ); $this->_tmpl->setAttribute( 'formErrors', 'visibility', 'visible' ); } } } $form->renderForm( array( 'template' => 'form', 'errorTemplateContainer' => 'formErrors', 'errorTemplate' => 'formErrors_entry' ) ); return $this->_tmpl->getParsedTemplate( 'form' ); } /** * display editor for group membership * * * @access private * @param boolean $save * @param boolean $invert * @return string $html */ function _displayUsergroup( $save = false, $invert = false ) { if( !isset( $this->_request['id'] ) ) { return patErrorManager::raiseWarning( 'wbAccount:userEdit:1', 'Need user id!', 'Need request variable "id" - not set!' ); } $id = $this->_request['id']; $data = array(); $cands = array(); $members = array(); $user =& wbFactory::singleton( 'wbUser_Admin' ); // edit uses in group if( $invert ) { $tmpl = 'accountmanager_groupuser'; $baseData = $user->getGroupData( $id ); $primary = $user->getPrimaryKey( 'user' ); $membership = $user->getMembers( $id ); foreach( $membership as $ms ) { array_push( $members, $ms[$primary] ); } $memberCanditates = $user->getUsers( null ); foreach( $memberCanditates as $mc ) { array_push( $cands, array( 'value' => $mc[$primary], 'label' => addslashes( $mc['realname'] ) )); } } // edit groups of user else { $tmpl = 'accountmanager_usergroup'; $baseData = $user->getUserData( $id ); $primary = $user->getPrimaryKey( 'group' ); $membership = $user->getGroups( $id ); foreach( $membership as $ms ) { array_push( $members, $ms['groupname'] ); } $memberCanditates = $user->getGroups( null ); foreach( $memberCanditates as $mc ) { array_push( $cands, array( 'value' => addslashes( $mc['groupname'] ), 'label' => addslashes( $mc['groupname'] ) ) ); } } $params = array( 'template' => $tmpl . 'edit', 'base_dir' => $this->_baseDir ); $form =& wbFactory::singleton( 'patForms', $params ); $pool =& $form->getElement( 'member' ); $pool->setAttribute( 'candidates', $cands ); if( !$save ) { $data['member'] = implode( ',', $members ); $form->setValues( $data ); } else { $form->setSubmitted( true ); if( $form->validateForm() ) { $data = $form->getValues(); $member = explode( ',', $data['member'] ); // set member of a group if( $invert ) { $group = $user->getGroupData( $id ); $groupname = $group['groupname']; $users = $user->getUsers(); $primary = $user->getPrimaryKey( 'user' ); foreach( $users as $u ) { if( in_array( $u[$primary], $member ) ) { $user->addUserToGroups( $u[$primary], $groupname ); } else { $user->removeUserFromGroups( $u[$primary], $groupname ); } } } // add users into multiple groups else { $user->setUserGroups( $id, $member ); } $this->_loadTemplates( $tmpl . 'saved' ); return $this->_tmpl->getParsedTemplate( 'manager' ); } } $form->renderForm( array( 'template' => 'manager', 'errorTemplateContainer' => 'formErrors', 'errorTemplate' => 'formErrors_entry' ) ); $this->_tmpl->addVar( 'manager', 'id', $id ); $this->_tmpl->addVars( 'manager', $baseData ); return $this->_tmpl->getParsedTemplate( 'manager' ); } /** * display editor for group membership * * * @access private * @return string $html */ function _displayUsergroupSave() { return $this->_displayUsergroup( true ); } /** * display editor for group membership * * * @access private * @return string $html */ function _displayGroupuser() { return $this->_displayUsergroup( false, true ); } /** * display editor for group membership * * * @access private * @return string $html */ function _displayGroupuserSave() { return $this->_displayUsergroup( true, true ); } /** * display list of users * * @access private * @return string $html */ function _displayUserList() { $this->_loadTemplates( 'accountmanager_userlist' ); $user =& wbFactory::singleton( 'wbUser_Admin' ); $users = $user->getUsers(); $this->_tmpl->addVar( 'manager', 'count', count( $users ) ); $this->_tmpl->addRows( 'list_entry', $users ); return $this->_tmpl->getParsedTemplate( 'manager' ); } /** * display list of groups * * @access private * @return string $html */ function _displayGroupList() { $this->_loadTemplates( 'accountmanager_grouplist' ); $user =& wbFactory::singleton( 'wbUser_Admin' ); $groups = $user->getGroups(); $this->_tmpl->addVar( 'manager', 'count', count( $groups ) ); $this->_tmpl->addRows( 'list_entry', $groups ); return $this->_tmpl->getParsedTemplate( 'manager' ); } /** * display user editor * * @access private * @return string $html */ function _displayUserEdit() { if( !isset( $this->_request['id'] ) ) { return patErrorManager::raiseWarning( 'wbAccount:userEdit:1', 'Need user id!', 'Need request variable "id" - not set!' ); } $id = $this->_request['id']; if( isset( $this->_request['resume'] ) && !empty( $this->_request['resume'] ) ) { $data = $this->_sess->get( 'gsAccount_resume' ); } else { $user =& wbFactory::singleton( 'wbUser_Admin' ); $data = $user->getUserData( $id ); if( patErrorManager::isError( $data ) ) { return $data; } $data['flags'] = explode( ',', $data['flags'] ); } return $this->_displayEditor( 'accountmanager_useredit', $id, $data ); } /** * display group editor * * @access private * @return string $html */ function _displayGroupEdit() { if( !isset( $this->_request['id'] ) ) { return patErrorManager::raiseWarning( 'wbAccount:GroupEdit:1', 'Need user id!', 'Need request variable "id" - not set!' ); } $id = $this->_request['id']; if( isset( $this->_request['resume'] ) && !empty( $this->_request['resume'] ) ) { $data = $this->_sess->get( 'gsAccount_resume' ); } else { $user =& wbFactory::singleton( 'wbUser_Admin' ); $data = $user->getGroupData( $id ); if( patErrorManager::isError( $data ) ) { return $data; } } return $this->_displayEditor( 'accountmanager_groupedit', $id, $data ); } /** * display editor for new users * * @access private * @return string $html */ function _displayUserAdd() { $data = array(); return $this->_displayEditor( 'accountmanager_useredit', 'new', $data ); } /** * display editor for new users * * @access private * @return string $html */ function _displayGroupAdd() { $data = array(); return $this->_displayEditor( 'accountmanager_groupedit', 'new', $data ); } /** * save user data * * @access private * @return string $html */ function _displayUserSave() { if( !isset( $this->_request['id'] ) ) { return patErrorManager::raiseWarning( 'wbAccount:userSave:1', 'Need user id!', 'Need request variable "id" - not set!' ); } $id = $this->_request['id']; $ftmpl = 'accountmanager_useredit'; $params = array( 'template' => $ftmpl, 'base_dir' => $this->_baseDir ); $form =& wbFactory::singleton( 'patForms', $params ); $form->setSubmitted( true ); if( !$form->validateForm() ) { $form->renderForm( array( 'template' => 'manager', 'errorTemplateContainer' => 'formErrors', 'errorTemplate' => 'formErrors_entry' ) ); $this->_tmpl->addVar( 'manager', 'id', $id ); return $this->_tmpl->getParsedTemplate( 'manager' ); } $data = $form->getValues(); if( !$this->_checkReload() ) { $user =& wbFactory::singleton( 'wbUser_Admin' ); if( $id === 'new' ) { $data['password'] = '!_new_user'; $result = $user->addNewUser( $data, array() ); if( patErrorManager::isError( $result ) ) { return $result; } $this->_sess->set( 'gsAccount_newuser', $result['id'] ); } else { $result = $user->setUserData( $data, $id ); if( patErrorManager::isError( $result ) ) { return $result; } $this->_sess->set( 'gsAccount_newuser', false ); } // something went wrong if( !$result['success'] ) { $this->_checkReload( true ); $this->_sess->set( 'gsAccount_resume', $data ); $this->_loadTemplates( 'accountmanager_usersavederror' ); $this->_tmpl->addVars( 'manager', $result ); $this->_tmpl->addVar( 'manager', 'id', $id ); return $this->_tmpl->getParsedTemplate( 'manager' ); } $id = $result['id']; } if( $id === 'new' ) { $id = $this->_sess->get( 'gsAccount_newuser' ); } $this->_loadTemplates( 'accountmanager_usersaved' ); $this->_tmpl->addVar( 'manager', 'id', $id ); if( $this->_sess->get( 'gsAccount_newuser' ) ) { $this->_tmpl->addVar( 'manager', 'newuser', $id ); } return $this->_tmpl->getParsedTemplate( 'manager' ); } /** * save group data * * @access private * @return string $html */ function _displayGroupSave() { if( !isset( $this->_request['id'] ) ) { return patErrorManager::raiseWarning( 'wbAccount:groupSave:1', 'Need user id!', 'Need request variable "id" - not set!' ); } $id = $this->_request['id']; $ftmpl = 'accountmanager_groupedit'; $params = array( 'template' => $ftmpl, 'base_dir' => $this->_baseDir ); $form =& wbFactory::singleton( 'patForms', $params ); $form->setSubmitted( true ); if( !$form->validateForm() ) { $form->renderForm( array( 'template' => 'manager', 'errorTemplateContainer' => 'formErrors', 'errorTemplate' => 'formErrors_entry' ) ); $this->_tmpl->addVar( 'manager', 'id', $id ); return $this->_tmpl->getParsedTemplate( 'manager' ); } $data = $form->getValues(); if( !$this->_checkReload() ) { $user =& wbFactory::singleton( 'wbUser_Admin' ); if( $id === 'new' ) { $result = $user->addGroup( $data['groupname'] ); if( patErrorManager::isError( $result ) ) { return $result; } } else { $result = $user->setGroupData( $data, $id ); if( patErrorManager::isError( $result ) ) { return $result; } } // something went wrong if( !$result['success'] ) { $this->_checkReload( true ); $this->_sess->set( 'gsAccount_resume', $data ); $this->_loadTemplates( 'accountmanager_groupsavederror' ); $this->_tmpl->addVars( 'manager', $result ); $this->_tmpl->addVar( 'manager', 'id', $id ); return $this->_tmpl->getParsedTemplate( 'manager' ); } } $this->_loadTemplates( 'accountmanager_groupsaved' ); return $this->_tmpl->getParsedTemplate( 'manager' ); } /** * mark user as deleted * * @access private * @return boolean $result true on success */ function _displayUserDelete() { if( !isset( $this->_request['id'] ) ) { return patErrorManager::raiseWarning( 'wbAccount:userDelete:1', 'Need user id!', 'Need request variable "uid" - not set!' ); } $id = $this->_request['id']; if( isset( $this->_request['delete'] ) && $this->_request['delete'] === 'force' ) { $this->_loadTemplates( 'accountmanager_userdeletesuccess' ); $user =& wbFactory::singleton( 'wbUser_Admin' ); $result = $user->removeUser( $id ); if( patErrorManager::isError( $result ) ) { return $result; } $this->_tmpl->addVars( 'manager', $result ); return $this->_tmpl->getParsedTemplate( 'manager' ); } $user =& wbFactory::singleton( 'wbUser_Admin' ); $data = $user->getUserData( $id ); $this->_loadTemplates( 'accountmanager_userdelete' ); $this->_tmpl->addVars( 'manager', $data ); $this->_tmpl->addVar( 'manager', 'id', $id ); return $this->_tmpl->getParsedTemplate( 'manager' ); } /** * mark user as deleted * * @access private * @return boolean $result true on success */ function _displayGroupDelete() { if( !isset( $this->_request['id'] ) ) { return patErrorManager::raiseWarning( 'wbAccount:userDelete:1', 'Need user id!', 'Need request variable "uid" - not set!' ); } $id = $this->_request['id']; if( isset( $this->_request['delete'] ) && $this->_request['delete'] === 'force' ) { $this->_loadTemplates( 'accountmanager_groupdeletesuccess' ); $user =& wbFactory::singleton( 'wbUser_Admin' ); $result = $user->removeGroup( $id ); if( patErrorManager::isError( $result ) ) { return $result; } $this->_tmpl->addVars( 'manager', $result ); return $this->_tmpl->getParsedTemplate( 'manager' ); } $user =& wbFactory::singleton( 'wbUser_Admin' ); $data = $user->getGroupData( $id ); $mem = $user->countMembers( $id ); $this->_loadTemplates( 'accountmanager_groupdelete' ); $this->_tmpl->addVars( 'manager', $data ); $this->_tmpl->addVar( 'manager', 'id', $id ); $this->_tmpl->addVar( 'manager', 'members', $mem ); return $this->_tmpl->getParsedTemplate( 'manager' ); } /** * display editor * * @access private * @param string $ftmpl name for the form template * @param mixed $id either the id or "new" * @param array $data * * @return boolean $result true on success */ function _displayEditor( $ftmpl, $id, &$data ) { $params = array( 'template' => $ftmpl, 'base_dir' => $this->_baseDir ); $form =& wbFactory::singleton( 'patForms', $params ); $form->setValues( $data ); $form->renderForm( array( 'template' => 'manager', 'errorTemplateContainer' => 'formErrors', 'errorTemplate' => 'formErrors_entry' ) ); $this->_tmpl->addVar( 'manager', 'id', $id ); return $this->_tmpl->getParsedTemplate( 'manager' ); } /** * create user passwd and notify user * * @access public * @return boolean $result true on success */ function _displayCreatePasswd() { if( !isset( $this->_request['id'] ) ) { return patErrorManager::raiseWarning( 'wbAccount:userCreatePasswd:1', 'Need user id!', 'Need request variable "uid" - not set!' ); } $id = $this->_request['id']; $user =& wbFactory::singleton( 'wbUser_Admin' ); $pass = $user->createPasswd(); $data = array( 'password' => $pass ); $result = $user->setUserData( $data, $id ); if( patErrorManager::isError( $result ) ) { return $result; } $data = $user->getUserData( $id ); $email = $data['email']; $name = $data['realname']; $tmpl = 'accountmanager_createpasswdemail'; if( $this->_sess->get( 'gsAccount_newuser' ) ) { $tmpl = null; } $this->_notifyNewUser( $name, $email, $pass, $tmpl ); $this->_loadTemplates( 'accountmanager_createpasswd' ); return $this->_tmpl->getParsedTemplate( 'manager' ); } /** * send any notify mail to user * * @access private * @param array $user user data * @param array $data additional data to be added in the template * @param string $tmpl name of the template file * @return boolean $result true on success */ function _notifyUser( $user, $data, $tmpl ) { // mail body $this->_loadTemplates( $tmpl ); $this->_tmpl->addVars( 'email', $data ); $this->_tmpl->addVars( 'email', $user, 'USER_' ); // mail header $hdr = array(); $hdr['From'] = $this->_emailHeader['from']; $hdr['Subject'] = $this->_emailHeader['subject']; $hdr['X-Mailer'] = $this->_emailHeader['x-mailer']; $body = $this->_tmpl->getParsedTemplate( 'email' ); // run mailer $mailer =& wbFactory::singleton( 'Mail' ); if( wbDebugger::isActive() ) { wbDebugger::addMsg( 'Account', 'Notify user: ' . $user['email'], 'Mailer' ); wbDebugger::addMsg( 'Account', wbDebugger::sprint( $body ), 'Mailer' ); return true; } $result = $mailer->send( $user['email'], $hdr, $body ); if( PEAR::isError( $result ) ) { return false; } return true; } /** * send notification email to new user * * @access private * @param string $name login name of the user * @param string $email contact email address * @param string $password readable user password * @param string $tmpl name of email template file * @return boolean $result true on success */ function _notifyNewUser( $name, $email, $password, $tmpl = null ) { if( $tmpl === null ) { $tmpl = 'newaccount_email'; } $data = array( 'name' => $name, 'password' => $password ); $user = array( 'email' => $email ); return $this->_notifyUser( $user, $data, $tmpl ); } /** * load templates * - wrapper for patTemplate-readTemplateFromInput() * * @access private * @param string $name name of template file, without trailing '.tmpl' * @return boolean $result true on success */ function _loadTemplates( $name ) { $this->_tmpl->readTemplatesFromInput( $this->_tmplDir . '/' . $name . '.tmpl' ); return true; } /** * _checkReload * * @access private * @param boolean $reset * @return boolean $result true on success */ function _checkReload( $reset = false ) { if( $reset ) { $this->_sess->set( 'gsAccount_checksum', false ); return false; } // create checksum from request vars $req = array_merge( $_POST, $_GET ); ksort( $req ); $req = serialize( $req ); $newChecksum = md5( $req ); // get saved checksum $checksum = $this->_sess->get( 'gsAccount_checksum' ); if( $newChecksum == $checksum ) { return true; } $this->_sess->set( 'gsAccount_checksum', $newChecksum ); return false; } } ?>