Guest User

Untitled

a guest
Jul 31st, 2018
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1. <?php
  2. /*
  3. ****************************************************
  4. COPYRIGHT © 2011 Raging Flame
  5. AUTHOR: Qawelesizwe Mlilo
  6. Email: qawemlilo@gmail.com
  7. ****************************************************
  8. */
  9.  
  10. class createUser {
  11.  
  12. private $myarr, $id, $output = '';
  13.  
  14. private function processForm()
  15. {
  16. $arr = array();
  17. $arr['title'] = JRequest::getWord('title', '', 'POST');
  18. $arr['fullname'] = JRequest::getString('fullname', '', 'POST');
  19. $arr['email'] = JRequest::getString('email', '', 'POST');
  20. $arr['username'] = JRequest::getWord('username', '', 'POST');
  21. $arr['cell'] = JRequest::getInt('cell', '', 'POST');
  22. $arr['tel'] = JRequest::getInt('tel', '', 'POST');
  23. $arr['fax'] = JRequest::getInt('fax', '', 'POST' );
  24. $arr['password'] = JRequest::getString('password', '', 'POST');
  25. $arr['subscribe'] = JRequest::getInt('subscribe', 0, 'POST');
  26.  
  27. if(!checkEmail($arr['email'])) {
  28. echo '<script language="JavaScript">
  29. history.go(-1);
  30. </script>';
  31. return;
  32. }
  33.  
  34. $this->myarr = $arr;
  35. return true;
  36. }
  37.  
  38. public function create()
  39. {
  40. $output='';
  41. $home = "index.php?option=com_addusers&view=addclient";
  42. $this->processForm();
  43.  
  44. $user['fullname'] = $this->myarr['fullname'];
  45. $user['email'] = $this->myarr['email'];
  46. $user['username'] = $this->myarr['username'];
  47. $password = $this->myarr['password'];
  48.  
  49. $salt = JUserHelper::genRandomPassword(32);
  50. $crypt = JUserHelper::getCryptedPassword($password, $salt);
  51. $password = $crypt.':'.$salt;
  52.  
  53. $instance = JUser::getInstance();
  54. $config = JComponentHelper::getParams('com_users');
  55. $defaultUserGroup = $config->get('new_usertype', 2);
  56. $acl = JFactory::getACL();
  57.  
  58. $instance->set('id', 0);
  59. $instance->set('name', $user['fullname']);
  60. $instance->set('username', $user['username']);
  61. $instance->set('password', $password);
  62. $instance->set('email', $user['email']);
  63. $instance->set('usertype', 'deprecated');
  64. $instance->set('groups', array($defaultUserGroup));
  65.  
  66.  
  67. if ($instance->save())
  68. {
  69. $newUser =& JFactory::getUser($this->myarr['username']);
  70. $this->id = $newUser->get('id');
  71. $this->addInfo();
  72. $this->createFolder();
  73.  
  74. $output .= "<h2>New User created</h2>";
  75. $output .= "-----------------------------------------";
  76. $output .= "<p><strong>Name:</strong> \t ".$user['fullname']."</p>";
  77. $output .= "<p><strong>Username:</strong> \t ".$user['username']."</p>";
  78. $output .= "<p><strong>Password:</strong> \t ".$this->myarr['password']."</p>";
  79. $output .= "<br /> -----------------------------------------";
  80.  
  81. $output .= "<p><a href=\"$home\">Go Back</a></p>";
  82.  
  83.  
  84.  
  85. return $output;
  86. }
  87. else {
  88. return JError::raiseWarning('SOME_ERROR_CODE', $instance->getError());
  89. }
  90. }
  91.  
  92. private function addInfo()
  93. {
  94. if (isset($this->id))
  95. {
  96. $title = $this->myarr['title'];
  97. $cell = $this->myarr['cell'];
  98. $tel = $this->myarr['tel'];
  99. $fax = $this->myarr['fax'];
  100. $user_id = $this->id;
  101.  
  102. $db =& JFactory::getDBO();
  103. $query = "INSERT INTO jos_customusers(user_id, title, cell, tel, fax)
  104. VALUES('".$user_id."', '".$title."', '".$cell."', '".$tel."', '".$fax."')";
  105. $db->setQuery($query);
  106.  
  107. return $db->query();
  108. }
  109. }
  110.  
  111. private function createFolder()
  112. {
  113. if (isset($this->id)) {
  114. $path = JPATH_SITE . DS . 'media' . DS . 'com_addusers' . DS . 'client_folders' . DS . 'user_' . $this->id;
  115.  
  116. if (!JFolder::exists($path))
  117. {
  118. if(!JFolder::create($path, 0777))
  119. {
  120. echo '<script language="JavaScript">
  121. alert ("Folder Already Exists, please delete old folders.");
  122. </script>';
  123. return;
  124. }
  125. else return true;
  126. }
  127. elseif(!JFolder::create($path . '_', 0777))
  128. {
  129. echo '<script language="JavaScript">
  130. alert ("Folder Already Exists, please delete old folders.");
  131. </script>';
  132. return;
  133. }
  134. }
  135. }
  136. }
  137. ?>
Add Comment
Please, Sign In to add comment