PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/database/table/user.php

https://gitlab.com/endomorphosis/OLAAaction
PHP | 341 lines | 169 code | 47 blank | 125 comment | 29 complexity | 1bd605bc553428bd95a72617e6e97832 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: user.php 14401 2010-01-26 14:10:00Z louis $
  4. * @package Joomla.Framework
  5. * @subpackage Table
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
  7. * @license GNU/GPL, see LICENSE.php
  8. * Joomla! is free software. This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. * See COPYRIGHT.php for copyright notices and details.
  13. */
  14. // Check to ensure this file is within the rest of the framework
  15. defined('JPATH_BASE') or die();
  16. /**
  17. * Users table
  18. *
  19. * @package Joomla.Framework
  20. * @subpackage Table
  21. * @since 1.0
  22. */
  23. class JTableUser extends JTable
  24. {
  25. /**
  26. * Unique id
  27. *
  28. * @var int
  29. */
  30. var $id = null;
  31. /**
  32. * The users real name (or nickname)
  33. *
  34. * @var string
  35. */
  36. var $name = null;
  37. /**
  38. * The login name
  39. *
  40. * @var string
  41. */
  42. var $username = null;
  43. /**
  44. * The email
  45. *
  46. * @var string
  47. */
  48. var $email = null;
  49. /**
  50. * MD5 encrypted password
  51. *
  52. * @var string
  53. */
  54. var $password = null;
  55. /**
  56. * Description
  57. *
  58. * @var string
  59. */
  60. var $usertype = null;
  61. /**
  62. * Description
  63. *
  64. * @var int
  65. */
  66. var $block = null;
  67. /**
  68. * Description
  69. *
  70. * @var int
  71. */
  72. var $sendEmail = null;
  73. /**
  74. * The group id number
  75. *
  76. * @var int
  77. */
  78. var $gid = null;
  79. /**
  80. * Description
  81. *
  82. * @var datetime
  83. */
  84. var $registerDate = null;
  85. /**
  86. * Description
  87. *
  88. * @var datetime
  89. */
  90. var $lastvisitDate = null;
  91. /**
  92. * Description
  93. *
  94. * @var string activation hash
  95. */
  96. var $activation = null;
  97. /**
  98. * Description
  99. *
  100. * @var string
  101. */
  102. var $params = null;
  103. /**
  104. * @param database A database connector object
  105. */
  106. function __construct( &$db )
  107. {
  108. parent::__construct( '#__users', 'id', $db );
  109. //initialise
  110. $this->id = 0;
  111. $this->gid = 0;
  112. $this->sendEmail = 0;
  113. }
  114. /**
  115. * Validation and filtering
  116. *
  117. * @return boolean True is satisfactory
  118. */
  119. function check()
  120. {
  121. jimport('joomla.mail.helper');
  122. // Validate user information
  123. if (trim( $this->name ) == '') {
  124. $this->setError( JText::_( 'Please enter your name.' ) );
  125. return false;
  126. }
  127. if (trim( $this->username ) == '') {
  128. $this->setError( JText::_( 'Please enter a user name.') );
  129. return false;
  130. }
  131. if (preg_match( "#[<>\"'%;()&]#i", $this->username) || strlen(utf8_decode($this->username )) < 2) {
  132. $this->setError( JText::sprintf( 'VALID_AZ09', JText::_( 'Username' ), 2 ) );
  133. return false;
  134. }
  135. if ((trim($this->email) == "") || ! JMailHelper::isEmailAddress($this->email) ) {
  136. $this->setError( JText::_( 'WARNREG_MAIL' ) );
  137. return false;
  138. }
  139. if ($this->registerDate == null) {
  140. // Set the registration timestamp
  141. $now =& JFactory::getDate();
  142. $this->registerDate = $now->toMySQL();
  143. }
  144. // check for existing username
  145. $query = 'SELECT id'
  146. . ' FROM #__users '
  147. . ' WHERE username = ' . $this->_db->Quote($this->username)
  148. . ' AND id != '. (int) $this->id;
  149. ;
  150. $this->_db->setQuery( $query );
  151. $xid = intval( $this->_db->loadResult() );
  152. if ($xid && $xid != intval( $this->id )) {
  153. $this->setError( JText::_('WARNREG_INUSE'));
  154. return false;
  155. }
  156. // check for existing email
  157. $query = 'SELECT id'
  158. . ' FROM #__users '
  159. . ' WHERE email = '. $this->_db->Quote($this->email)
  160. . ' AND id != '. (int) $this->id
  161. ;
  162. $this->_db->setQuery( $query );
  163. $xid = intval( $this->_db->loadResult() );
  164. if ($xid && $xid != intval( $this->id )) {
  165. $this->setError( JText::_( 'WARNREG_EMAIL_INUSE' ) );
  166. return false;
  167. }
  168. return true;
  169. }
  170. function store( $updateNulls=false )
  171. {
  172. $acl =& JFactory::getACL();
  173. $section_value = 'users';
  174. $k = $this->_tbl_key;
  175. $key = $this->$k;
  176. if ($key)
  177. {
  178. // existing record
  179. $ret = $this->_db->updateObject( $this->_tbl, $this, $this->_tbl_key, $updateNulls );
  180. // syncronise ACL
  181. // single group handled at the moment
  182. // trivial to expand to multiple groups
  183. $object_id = $acl->get_object_id( $section_value, $this->$k, 'ARO' );
  184. $groups = $acl->get_object_groups( $object_id, 'ARO' );
  185. $acl->del_group_object( $groups[0], $section_value, $this->$k, 'ARO' );
  186. $acl->add_group_object( $this->gid, $section_value, $this->$k, 'ARO' );
  187. $acl->edit_object( $object_id, $section_value, $this->_db->getEscaped( $this->name ), $this->$k, 0, 0, 'ARO' );
  188. }
  189. else
  190. {
  191. // new record
  192. $ret = $this->_db->insertObject( $this->_tbl, $this, $this->_tbl_key );
  193. // syncronise ACL
  194. $acl->add_object( $section_value, $this->name, $this->$k, null, null, 'ARO' );
  195. $acl->add_group_object( $this->gid, $section_value, $this->$k, 'ARO' );
  196. }
  197. if( !$ret )
  198. {
  199. $this->setError( strtolower(get_class( $this ))."::". JText::_( 'store failed' ) ."<br />" . $this->_db->getErrorMsg() );
  200. return false;
  201. }
  202. else
  203. {
  204. return true;
  205. }
  206. }
  207. function delete( $oid=null )
  208. {
  209. $acl =& JFactory::getACL();
  210. $k = $this->_tbl_key;
  211. if ($oid) {
  212. $this->$k = intval( $oid );
  213. }
  214. $aro_id = $acl->get_object_id( 'users', $this->$k, 'ARO' );
  215. $acl->del_object( $aro_id, 'ARO', true );
  216. $query = 'DELETE FROM '. $this->_tbl
  217. . ' WHERE '. $this->_tbl_key .' = '. (int) $this->$k
  218. ;
  219. $this->_db->setQuery( $query );
  220. if ($this->_db->query()) {
  221. // cleanup related data
  222. // private messaging
  223. $query = 'DELETE FROM #__messages_cfg'
  224. . ' WHERE user_id = '. (int) $this->$k
  225. ;
  226. $this->_db->setQuery( $query );
  227. if (!$this->_db->query()) {
  228. $this->setError( $this->_db->getErrorMsg() );
  229. return false;
  230. }
  231. $query = 'DELETE FROM #__messages'
  232. . ' WHERE user_id_to = '. (int) $this->$k
  233. ;
  234. $this->_db->setQuery( $query );
  235. if (!$this->_db->query()) {
  236. $this->setError( $this->_db->getErrorMsg() );
  237. return false;
  238. }
  239. return true;
  240. } else {
  241. $this->setError( $this->_db->getErrorMsg() );
  242. return false;
  243. }
  244. }
  245. /**
  246. * Updates last visit time of user
  247. *
  248. * @param int The timestamp, defaults to 'now'
  249. * @return boolean False if an error occurs
  250. */
  251. function setLastVisit( $timeStamp=null, $id=null )
  252. {
  253. // check for User ID
  254. if (is_null( $id )) {
  255. if (isset( $this )) {
  256. $id = $this->id;
  257. } else {
  258. // do not translate
  259. jexit( 'WARNMOSUSER' );
  260. }
  261. }
  262. // if no timestamp value is passed to functon, than current time is used
  263. $date =& JFactory::getDate($timeStamp);
  264. // updates user lastvistdate field with date and time
  265. $query = 'UPDATE '. $this->_tbl
  266. . ' SET lastvisitDate = '.$this->_db->Quote($date->toMySQL())
  267. . ' WHERE id = '. (int) $id
  268. ;
  269. $this->_db->setQuery( $query );
  270. if (!$this->_db->query()) {
  271. $this->setError( $this->_db->getErrorMsg() );
  272. return false;
  273. }
  274. return true;
  275. }
  276. /**
  277. * Overloaded bind function
  278. *
  279. * @access public
  280. * @param array $hash named array
  281. * @return null|string null is operation was satisfactory, otherwise returns an error
  282. * @see JTable:bind
  283. * @since 1.5
  284. */
  285. function bind($array, $ignore = '')
  286. {
  287. if (key_exists( 'params', $array ) && is_array( $array['params'] )) {
  288. $registry = new JRegistry();
  289. $registry->loadArray($array['params']);
  290. $array['params'] = $registry->toString();
  291. }
  292. return parent::bind($array, $ignore);
  293. }
  294. }