Created
May 26, 2011 11:36
-
-
Save qawemlilo/992963 to your computer and use it in GitHub Desktop.
Joomla 1.6 Create new user Class - also creates a folder associated with user.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
**************************************************** | |
COPYRIGHT © 2011 Raging Flame | |
AUTHOR: Qawelesizwe Mlilo | |
Email: qawemlilo@gmail.com | |
**************************************************** | |
*/ | |
class createUser { | |
private $myarr, $id, $output = ''; | |
private function processForm() | |
{ | |
$arr = array(); | |
$arr['title'] = JRequest::getWord('title', '', 'POST'); | |
$arr['fullname'] = JRequest::getString('fullname', '', 'POST'); | |
$arr['email'] = JRequest::getString('email', '', 'POST'); | |
$arr['username'] = JRequest::getWord('username', '', 'POST'); | |
$arr['cell'] = JRequest::getInt('cell', '', 'POST'); | |
$arr['tel'] = JRequest::getInt('tel', '', 'POST'); | |
$arr['fax'] = JRequest::getInt('fax', '', 'POST' ); | |
$arr['password'] = JRequest::getString('password', '', 'POST'); | |
$arr['subscribe'] = JRequest::getInt('subscribe', 0, 'POST'); | |
if(!checkEmail($arr['email'])) { | |
echo '<script language="JavaScript"> | |
history.go(-1); | |
</script>'; | |
return; | |
} | |
$this->myarr = $arr; | |
return true; | |
} | |
public function create() | |
{ | |
$output=''; | |
$home = "index.php?option=com_addusers&view=addclient"; | |
$this->processForm(); | |
$user['fullname'] = $this->myarr['fullname']; | |
$user['email'] = $this->myarr['email']; | |
$user['username'] = $this->myarr['username']; | |
$password = $this->myarr['password']; | |
$salt = JUserHelper::genRandomPassword(32); | |
$crypt = JUserHelper::getCryptedPassword($password, $salt); | |
$password = $crypt.':'.$salt; | |
$instance = JUser::getInstance(); | |
$config = JComponentHelper::getParams('com_users'); | |
$defaultUserGroup = $config->get('new_usertype', 2); | |
$acl = JFactory::getACL(); | |
$instance->set('id', 0); | |
$instance->set('name', $user['fullname']); | |
$instance->set('username', $user['username']); | |
$instance->set('password', $password); | |
$instance->set('email', $user['email']); | |
$instance->set('usertype', 'deprecated'); | |
$instance->set('groups', array($defaultUserGroup)); | |
if ($instance->save()) | |
{ | |
$newUser =& JFactory::getUser($this->myarr['username']); | |
$this->id = $newUser->get('id'); | |
$this->addInfo(); | |
$this->createFolder(); | |
$output .= "<h2>New User created</h2>"; | |
$output .= "-----------------------------------------"; | |
$output .= "<p><strong>Name:</strong> \t ".$user['fullname']."</p>"; | |
$output .= "<p><strong>Username:</strong> \t ".$user['username']."</p>"; | |
$output .= "<p><strong>Password:</strong> \t ".$this->myarr['password']."</p>"; | |
$output .= "<br /> -----------------------------------------"; | |
$output .= "<p><a href=\"$home\">Go Back</a></p>"; | |
return $output; | |
} | |
else { | |
return JError::raiseWarning('SOME_ERROR_CODE', $instance->getError()); | |
} | |
} | |
private function addInfo() | |
{ | |
if (isset($this->id)) | |
{ | |
$title = $this->myarr['title']; | |
$cell = $this->myarr['cell']; | |
$tel = $this->myarr['tel']; | |
$fax = $this->myarr['fax']; | |
$user_id = $this->id; | |
$db =& JFactory::getDBO(); | |
$query = "INSERT INTO jos_customusers(user_id, title, cell, tel, fax) | |
VALUES('".$user_id."', '".$title."', '".$cell."', '".$tel."', '".$fax."')"; | |
$db->setQuery($query); | |
return $db->query(); | |
} | |
} | |
private function createFolder() | |
{ | |
if (isset($this->id)) { | |
$path = JPATH_SITE . DS . 'media' . DS . 'com_addusers' . DS . 'client_folders' . DS . 'user_' . $this->id; | |
if (!JFolder::exists($path)) | |
{ | |
if(!JFolder::create($path, 0777)) | |
{ | |
echo '<script language="JavaScript"> | |
alert ("Folder Already Exists, please delete old folders."); | |
</script>'; | |
return; | |
} | |
else return true; | |
} | |
elseif(!JFolder::create($path . '_', 0777)) | |
{ | |
echo '<script language="JavaScript"> | |
alert ("Folder Already Exists, please delete old folders."); | |
</script>'; | |
return; | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment