PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_pago/models/client.php

https://gitlab.com/lankerd/paGO---Testing-Site
PHP | 297 lines | 178 code | 91 blank | 28 comment | 32 complexity | 503785a0f10d1b03d9a9c8600056af34 MD5 | raw file
  1. <?php
  2. /**
  3. * @package paGO Commerce
  4. * @author 'corePHP', LLC
  5. * @copyright (C) 2013 - 'corePHP' LLC and paGO Commerce
  6. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
  7. **/
  8. // no direct access
  9. defined('_JEXEC') or die('Restricted access');
  10. jimport( 'joomla.application.component.helper');
  11. jimport( 'joomla.application.component.model');
  12. class PagoModelClient extends JModelLegacy
  13. {
  14. var $_data;
  15. var $_order = array();
  16. function __construct()
  17. {
  18. parent::__construct();
  19. $array = JFactory::getApplication()->input->get('cid', 0, 'array');
  20. $this->setId((int)$array[0]);
  21. }
  22. function setId($id)
  23. {
  24. // Set id and wipe data
  25. $this->_id = $id;
  26. $this->_data = null;
  27. }
  28. function getData()
  29. {
  30. // Load the data]
  31. $this->cid = JFactory::getApplication()->input->get('cid', array(0), 'array' );
  32. $id = $this->cid[0];
  33. if (empty( $this->_data )) {
  34. $query = "SELECT * FROM #__pago_user_info
  35. WHERE user_id = $id";
  36. $this->_db->setQuery( $query );
  37. //$this->_data = $this->_db->loadObject();
  38. $data = $this->_db->loadObjectList();
  39. $this->_data = $data[0];
  40. if(isset($data[1]))
  41. foreach($data[1] as $k=>$v){
  42. $this->_data->{"m_$k"} = $v;
  43. }
  44. }
  45. if (!$this->_data) {
  46. $this->_data = new stdClass();
  47. $this->_data->id = 0;
  48. $this->_data->user_id = 0;
  49. $this->_data->address_type = false;
  50. $this->_data->address_type_name = false;
  51. $this->_data->company = false;
  52. $this->_data->title = false;
  53. $this->_data->last_name = false;
  54. $this->_data->first_name = false;
  55. $this->_data->middle_name = false;
  56. $this->_data->phone_1 = false;
  57. $this->_data->phone_2 = false;
  58. $this->_data->fax = false;
  59. $this->_data->address_1 = false;
  60. $this->_data->address_2 = false;
  61. $this->_data->city = false;
  62. $this->_data->state = false;
  63. $this->_data->country = false;
  64. $this->_data->zip = false;
  65. $this->_data->user_email = false;
  66. $this->_data->cdate = date( 'Y-m-d H:i:s', time() );
  67. $this->_data->mdate = date( 'Y-m-d H:i:s', time() );
  68. }
  69. return $this->_data;
  70. }
  71. function store()
  72. {
  73. $error=false;
  74. $row = $this->getTable();
  75. $data = JFactory::getApplication()->input->getArray($_POST);
  76. $data = $data['params'];
  77. $create = false;
  78. $id = $data['id'];
  79. $user = $this->get_user( $data );
  80. if(!$user) return false;
  81. $data['user_id'] = $user->id;
  82. if($id == 0){
  83. $data['cdate'] = date( 'Y-m-d H:i:s', time() );
  84. }
  85. if (!$row->bind($data)) JError::raiseWarning( 500, $row->getError() ); $error=$row->getError();
  86. if (!$row->check()) JError::raiseWarning( 500, $row->getError() ); $error=$row->getError();
  87. if (!$row->store()) JError::raiseWarning( 500, $row->getError() ); $error=$row->getError();
  88. if($error){
  89. return false;
  90. }
  91. if($id == 0){
  92. $ulid = $user->id .'_b';
  93. $db = $row->_db;
  94. $query = "UPDATE #__pago_user_info SET id = '$ulid', address_type='b' WHERE id=0";
  95. $db->setQuery($query);
  96. $result = $db->query();
  97. }
  98. else {
  99. $data['id'] = $user->id .'_m';
  100. }
  101. //mailing address stuff
  102. $data['address_type'] = 'm';
  103. if($data[ 'm_address_1']){
  104. foreach( $data as $k=>$v ){
  105. if( isset( $data[ 'm_' . $k ] ) ){
  106. $data[$k] = $data[ 'm_' . $k ];
  107. }
  108. }
  109. }
  110. if (!$row->bind($data)) JError::raiseWarning( 500, $row->getError() ); $error=$row->getError();
  111. if (!$row->check()) JError::raiseWarning( 500, $row->getError() ); $error=$row->getError();
  112. if (!$row->store()) JError::raiseWarning( 500, $row->getError() ); $error=$row->getError();
  113. if($error){
  114. return false;
  115. }
  116. if($id == 0){
  117. $id = $user->id .'_m';
  118. $db = $row->_db;
  119. $query = "UPDATE #__pago_user_info SET id = '$id', address_type='m' WHERE id=0";
  120. $db->setQuery($query);
  121. $result = $db->query();
  122. }
  123. return $user->id;
  124. }
  125. function get_user( $kdata ){
  126. if( $kdata['user_id'] ){
  127. $user = JFactory::getUser( $kdata['user_id'] );
  128. return $user;
  129. } else {
  130. $user = JFactory::getUser( 0 );
  131. }
  132. //print_r($user);die();
  133. // get the ACL
  134. $acl = JFactory::getACL();
  135. /* get the com_user params */
  136. jimport('joomla.user.helper');
  137. jimport('joomla.application.component.helper'); // include libraries/application/component/helper.php
  138. $usersParams = &JComponentHelper::getParams( 'com_users' ); // load the Params
  139. // "generate" a new JUser Object
  140. //$user = JFactory::getUser(0); // it's important to set the "0" otherwise your admin user information will be loaded
  141. $data = array(); // array for all user settings
  142. // get the default usertype
  143. $usertype = $usersParams->get( 'new_usertype' );
  144. if (!$usertype) {
  145. $usertype = 'Registered';
  146. }
  147. // set up the "main" user information
  148. $data['name'] = $kdata['first_name'].' '.$kdata['last_name']; // add first- and lastname
  149. $data['username'] = $kdata['username']; // add username
  150. $data['email'] = $kdata['user_email']; // add email
  151. $data['gid'] = $acl->get_group_id( '', $usertype, 'ARO' ); // generate the gid from the usertype
  152. /* no need to add the usertype, it will be generated automaticaly from the gid */
  153. $password = JUserHelper::genRandomPassword();
  154. $data['password'] = $password; // set the password
  155. $data['password2'] = $password; // confirm the password
  156. $data['sendEmail'] = 1; // should the user receive system mails?
  157. /* Now we can decide, if the user will need an activation */
  158. //$useractivation = $usersParams->get( 'useractivation' ); // in this example, we load the config-setting
  159. $useractivation = false;
  160. if ($useractivation == 1) { // yeah we want an activation
  161. jimport('joomla.user.helper'); // include libraries/user/helper.php
  162. $data['block'] = 1; // block the User
  163. $data['activation'] =JUtility::getHash( JUserHelper::genRandomPassword() ); // set activation hash (don't forget to send an activation email)
  164. }
  165. else { // no we need no activation
  166. $data['block'] = 0; // don't block the user
  167. }
  168. if (!$user->bind($data)) { // now bind the data to the JUser Object, if it not works....
  169. JError::raiseWarning('', JText::_( $user->getError())); // ...raise an Warning
  170. return false; // if you're in a method/function return false
  171. }
  172. if (!$user->save()) { // if the user is NOT saved...
  173. JError::raiseWarning('', JText::_( $user->getError())); // ...raise an Warning
  174. return false; // if you're in a method/function return false
  175. }
  176. //send password to user
  177. $mail = JFactory::getMailer();
  178. $mail->to = array();
  179. $mail->isHTML(true);
  180. $conf =& JFactory::getConfig();
  181. //$email_body = $params->get( 'transaction_completed' );
  182. $email_body = 'username:' . $kdata['username'] . ' password:' . $password;
  183. //$email_body = str_replace( '{first_name}', $user_data->first_name, $email_body);
  184. //$email_body = str_replace( '{last_name}', $user_data->last_name, $email_body);
  185. //$email_body = str_replace( '{receipt}', $this->get_receipt($tpl), $email_body);
  186. $mail->setBody( $email_body );
  187. $mail->setSubject("Account Created " . $kdata['username'] );
  188. //$mail->setSender( $params->get( 'store_email' ) );
  189. $mail->setSender( 'adam.docherty@gmail.com' );
  190. //$mail->addRecipient( 'adam.docherty@gmail.com' );
  191. $mail->addRecipient( $kdata['user_email'] );
  192. if($conf->get('mailer') == 'smtp'){
  193. $mail->useSMTP(
  194. $conf->get('smtpauth'),
  195. $conf->get('smtphost'),
  196. $conf->get('smtpuser'),
  197. $conf->get('smtppass'),
  198. $conf->get('smtpsecure'),
  199. $conf->get('smtpport')
  200. );
  201. }
  202. if($mail->Send() === true){
  203. }
  204. return $user; // else return the new JUser object
  205. }
  206. }