PageRenderTime 60ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/webroot/updates/concrete5.6.0.2/concrete/core/models/userinfo.php

https://bitbucket.org/microwebedu/registratie_carem
PHP | 766 lines | 547 code | 111 blank | 108 comment | 105 complexity | 3171a464a28babad963df373b4def577 MD5 | raw file
Possible License(s): MIT, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. defined('C5_EXECUTE') or die("Access Denied.");
  3. /**
  4. * @package Users
  5. * @author Andrew Embler <andrew@concrete5.org>
  6. * @copyright Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
  7. * @license http://www.concrete5.org/license/ MIT License
  8. *
  9. */
  10. /**
  11. * While the User object deals more with logging users in and relating them to core Concrete items, like Groups, the UserInfo object is made to grab auxiliary data about a user, including their user attributes. Additionally, the UserInfo object is the object responsible for adding/registering users in the system.
  12. *
  13. * @package Users
  14. * @category Concrete
  15. * @copyright Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
  16. * @license http://www.concrete5.org/license/ MIT License
  17. *
  18. */
  19. class Concrete5_Model_UserInfo extends Object {
  20. public function __toString() {
  21. return 'UserInfo: ' . $this->getUserID();
  22. }
  23. /* magic method for user attributes. This is db expensive but pretty damn cool */
  24. // so if the attrib handle is "my_attribute", then get the attribute with $ui->getUserMyAttribute(), or "uFirstName" become $ui->getUserUfirstname();
  25. public function __call($nm, $a) {
  26. if (substr($nm, 0, 7) == 'getUser') {
  27. $nm = preg_replace('/(?!^)[[:upper:]]/','_\0', $nm);
  28. $nm = strtolower($nm);
  29. $nm = str_replace('get_user_', '', $nm);
  30. return $this->getAttribute($nm);
  31. }
  32. }
  33. /**
  34. * returns the UserInfo object for a give user's uID
  35. * @param int $uID
  36. * @return UserInfo
  37. */
  38. public static function getByID($uID) {
  39. return UserInfo::get('where uID = ?', $uID);
  40. }
  41. /**
  42. * returns the UserInfo object for a give user's username
  43. * @param string $uName
  44. * @return UserInfo
  45. */
  46. public static function getByUserName($uName) {
  47. return UserInfo::get('where uName = ?', $uName);
  48. }
  49. /**
  50. * returns the UserInfo object for a give user's email address
  51. * @param string $uEmail
  52. * @return UserInfo
  53. */
  54. public static function getByEmail($uEmail) {
  55. return UserInfo::get('where uEmail = ?', $uEmail);
  56. }
  57. /**
  58. * Returns a user object by open ID. Does not log a user in.
  59. * @param string $uOpenID
  60. * @return UserInfo
  61. */
  62. public function getByOpenID($uOpenID) {
  63. return UserInfo::get('inner join UserOpenIDs on Users.uID = UserOpenIDs.uID where uOpenID = ?', $uOpenID);
  64. }
  65. /**
  66. * @param string $uHash
  67. * @param boolean $unredeemedHashesOnly
  68. * @return UserInfo
  69. */
  70. public static function getByValidationHash($uHash, $unredeemedHashesOnly = true) {
  71. $db = Loader::db();
  72. if ($unredeemedHashesOnly) {
  73. $uID = $db->GetOne("select uID from UserValidationHashes where uHash = ? and uDateRedeemed = 0", array($uHash));
  74. } else {
  75. $uID = $db->GetOne("select uID from UserValidationHashes where uHash = ?", array($uHash));
  76. }
  77. if ($uID) {
  78. $ui = UserInfo::getByID($uID);
  79. return $ui;
  80. }
  81. }
  82. private function get($where, $var) {
  83. $db = Loader::db();
  84. $q = "select Users.uID, Users.uLastLogin, Users.uLastIP, Users.uIsValidated, Users.uPreviousLogin, Users.uIsFullRecord, Users.uNumLogins, Users.uDateAdded, Users.uIsActive, Users.uLastOnline, Users.uHasAvatar, Users.uName, Users.uEmail, Users.uPassword, Users.uTimezone from Users " . $where;
  85. $r = $db->query($q, array($var));
  86. if ($r && $r->numRows() > 0) {
  87. $ui = new UserInfo;
  88. $row = $r->fetchRow();
  89. $ui->setPropertiesFromArray($row);
  90. $r->free();
  91. }
  92. if (is_object($ui)) {
  93. return $ui;
  94. }
  95. }
  96. const ADD_OPTIONS_NOHASH = 0;
  97. const ADD_OPTIONS_SKIP_CALLBACK = 1;
  98. /**
  99. * @param array $data
  100. * @param array | false $options
  101. * @return UserInfo
  102. */
  103. public static function add($data,$options=false) {
  104. $options = is_array($options) ? $options : array();
  105. $db = Loader::db();
  106. $dh = Loader::helper('date');
  107. $uDateAdded = $dh->getSystemDateTime();
  108. if ($data['uIsValidated'] == 1) {
  109. $uIsValidated = 1;
  110. } else if (isset($data['uIsValidated']) && $data['uIsValidated'] == 0) {
  111. $uIsValidated = 0;
  112. } else {
  113. $uIsValidated = -1;
  114. }
  115. if (isset($data['uIsFullRecord']) && $data['uIsFullRecord'] == 0) {
  116. $uIsFullRecord = 0;
  117. } else {
  118. $uIsFullRecord = 1;
  119. }
  120. $password_to_insert = $data['uPassword'];
  121. if (!in_array(self::ADD_OPTIONS_NOHASH, $options)) {
  122. $password_to_insert = User::encryptPassword($password_to_insert);
  123. }
  124. if (isset($data['uDefaultLanguage']) && $data['uDefaultLanguage'] != '') {
  125. $uDefaultLanguage = $data['uDefaultLanguage'];
  126. }
  127. $v = array($data['uName'], $data['uEmail'], $password_to_insert, $uIsValidated, $uDateAdded, $uIsFullRecord, $uDefaultLanguage, 1);
  128. $r = $db->prepare("insert into Users (uName, uEmail, uPassword, uIsValidated, uDateAdded, uIsFullRecord, uDefaultLanguage, uIsActive) values (?, ?, ?, ?, ?, ?, ?, ?)");
  129. $res = $db->execute($r, $v);
  130. if ($res) {
  131. $newUID = $db->Insert_ID();
  132. $ui = UserInfo::getByID($newUID);
  133. if (is_object($ui) && !in_array(self::ADD_OPTIONS_SKIP_CALLBACK,$options)) {
  134. // run any internal event we have for user add
  135. Events::fire('on_user_add', $ui, $data['uPassword']);
  136. }
  137. return $ui;
  138. }
  139. }
  140. public function addSuperUser($uPasswordEncrypted, $uEmail) {
  141. $db = Loader::db();
  142. $dh = Loader::helper('date');
  143. $uDateAdded = $dh->getSystemDateTime();
  144. $v = array(USER_SUPER_ID, USER_SUPER, $uEmail, $uPasswordEncrypted, 1, $uDateAdded);
  145. $r = $db->prepare("insert into Users (uID, uName, uEmail, uPassword, uIsActive, uDateAdded) values (?, ?, ?, ?, ?, ?)");
  146. $res = $db->execute($r, $v);
  147. if ($res) {
  148. $newUID = $db->Insert_ID();
  149. return UserInfo::getByID($newUID);
  150. }
  151. }
  152. /**
  153. * Deletes a user
  154. * @return void
  155. */
  156. public function delete(){
  157. // we will NOT let you delete the admin user
  158. if ($this->uID == USER_SUPER_ID) {
  159. return false;
  160. }
  161. // run any internal event we have for user deletion
  162. $ret = Events::fire('on_user_delete', $this);
  163. if ($ret < 0) {
  164. return false;
  165. }
  166. $db = Loader::db();
  167. $r = $db->Execute('select avID, akID from UserAttributeValues where uID = ?', array($this->uID));
  168. Loader::model('attribute/categories/user');
  169. while ($row = $r->FetchRow()) {
  170. $uak = UserAttributeKey::getByID($row['akID']);
  171. $av = $this->getAttributeValueObject($uak);
  172. if (is_object($av)) {
  173. $av->delete();
  174. }
  175. }
  176. $r = $db->query("DELETE FROM UsersFriends WHERE friendUID = ?",array(intval($this->uID)) );
  177. $r = $db->query("DELETE FROM UserSearchIndexAttributes WHERE uID = ?",array(intval($this->uID)) );
  178. $r = $db->query("DELETE FROM UserGroups WHERE uID = ?",array(intval($this->uID)) );
  179. $r = $db->query("DELETE FROM UserOpenIDs WHERE uID = ?",array(intval($this->uID)));
  180. $r = $db->query("DELETE FROM Users WHERE uID = ?",array(intval($this->uID)));
  181. $r = $db->query("DELETE FROM UserValidationHashes WHERE uID = ?",array(intval($this->uID)));
  182. $r = $db->query("DELETE FROM Piles WHERE uID = ?",array(intval($this->uID)));
  183. $r = $db->query("UPDATE Blocks set uID=? WHERE uID = ?",array( intval(USER_SUPER_ID), intval($this->uID)));
  184. $r = $db->query("UPDATE Pages set uID=? WHERE uID = ?",array( intval(USER_SUPER_ID), intval($this->uID)));
  185. }
  186. /**
  187. * Called only by the getGroupMembers function it sets the "type" of member for this group. Typically only used programmatically
  188. * @param string $type
  189. * @return void
  190. */
  191. public function setGroupMemberType($type) {
  192. $this->gMemberType = $type;
  193. }
  194. public function getGroupMemberType() {
  195. return $this->gMemberType;
  196. }
  197. public function canReadPrivateMessage($msg) {
  198. return $msg->getMessageUserID() == $this->getUserID();
  199. }
  200. public function sendPrivateMessage($recipient, $subject, $text, $inReplyTo = false) {
  201. Loader::model('user_private_message');
  202. if(UserPrivateMessageLimit::isOverLimit($this->getUserID())) {
  203. return UserPrivateMessageLimit::getErrorObject();
  204. }
  205. $antispam = Loader::helper('validation/antispam');
  206. $messageText = t('Subject: %s', $subject);
  207. $messageText .= "\n";
  208. $messageText .= t('Message: %s', $text);
  209. $additionalArgs = array('user' => $this);
  210. if (!$antispam->check($messageText, 'private_message', $additionalArgs)) {
  211. return false;
  212. }
  213. $subject = ($subject == '') ? t('(No Subject)') : $subject;
  214. $db = Loader::db();
  215. $dt = Loader::helper('date');
  216. $v = array($this->getUserID(), $dt->getLocalDateTime(), $subject, $text, $recipient->getUserID());
  217. $db->Execute('insert into UserPrivateMessages (uAuthorID, msgDateCreated, msgSubject, msgBody, uToID) values (?, ?, ?, ?, ?)', $v);
  218. $msgID = $db->Insert_ID();
  219. if ($msgID > 0) {
  220. // we add the private message to the sent box of the sender, and the inbox of the recipient
  221. $v = array($db->Insert_ID(), $this->getUserID(), $this->getUserID(), UserPrivateMessageMailbox::MBTYPE_SENT, 0, 1);
  222. $db->Execute('insert into UserPrivateMessagesTo (msgID, uID, uAuthorID, msgMailboxID, msgIsNew, msgIsUnread) values (?, ?, ?, ?, ?, ?)', $v);
  223. $v = array($db->Insert_ID(), $recipient->getUserID(), $this->getUserID(), UserPrivateMessageMailbox::MBTYPE_INBOX, 1, 1);
  224. $db->Execute('insert into UserPrivateMessagesTo (msgID, uID, uAuthorID, msgMailboxID, msgIsNew, msgIsUnread) values (?, ?, ?, ?, ?, ?)', $v);
  225. }
  226. // If the message is in reply to another message, we make a note of that here
  227. if (is_object($inReplyTo)) {
  228. $db->Execute('update UserPrivateMessagesTo set msgIsReplied = 1 where uID = ? and msgID = ?', array($this->getUserID(), $inReplyTo->getMessageID()));
  229. }
  230. // send the email notification
  231. if ($recipient->getAttribute('profile_private_messages_notification_enabled')) {
  232. $mh = Loader::helper('mail');
  233. $mh->addParameter('msgSubject', $subject);
  234. $mh->addParameter('msgBody', $text);
  235. $mh->addParameter('msgAuthor', $this->getUserName());
  236. $mh->addParameter('msgDateCreated', $msgDateCreated);
  237. $mh->addParameter('profileURL', BASE_URL . View::url('/profile', 'view', $this->getUserID()));
  238. $mh->addParameter('profilePreferencesURL', BASE_URL . View::url('/profile/edit'));
  239. $mh->to($recipient->getUserEmail());
  240. Loader::library('mail/importer');
  241. $mi = MailImporter::getByHandle("private_message");
  242. if (is_object($mi) && $mi->isMailImporterEnabled()) {
  243. $mh->load('private_message_response_enabled');
  244. // we store information ABOUT the message here. The mail handler has to know how to handle this.
  245. $data = new stdClass;
  246. $data->msgID = $msgID;
  247. $data->toUID = $recipient->getUserID();
  248. $data->fromUID = $this->getUserID();
  249. $mh->enableMailResponseProcessing($mi, $data);
  250. } else {
  251. $mh->load('private_message');
  252. }
  253. $mh->sendMail();
  254. }
  255. }
  256. /**
  257. * gets the user object of the current UserInfo object ($this)
  258. * @return User
  259. */
  260. public function getUserObject() {
  261. // returns a full user object - groups and everything - for this userinfo object
  262. $nu = User::getByUserID($this->uID);
  263. return $nu;
  264. }
  265. /**
  266. * Sets the attribute of a user info object to the specified value, and saves it in the database
  267. */
  268. public function setAttribute($ak, $value) {
  269. Loader::model('attribute/categories/user');
  270. if (!is_object($ak)) {
  271. $ak = UserAttributeKey::getByHandle($ak);
  272. }
  273. $ak->setAttribute($this, $value);
  274. $this->reindex();
  275. }
  276. public function clearAttribute($ak) {
  277. $db = Loader::db();
  278. if (!is_object($ak)) {
  279. $ak = UserAttributeKey::getByHandle($ak);
  280. }
  281. $cav = $this->getAttributeValueObject($ak);
  282. if (is_object($cav)) {
  283. $cav->delete();
  284. }
  285. $this->reindex();
  286. }
  287. public function reindex() {
  288. $attribs = UserAttributeKey::getAttributes($this->getUserID(), 'getSearchIndexValue');
  289. $db = Loader::db();
  290. $db->Execute('delete from UserSearchIndexAttributes where uID = ?', array($this->getUserID()));
  291. $searchableAttributes = array('uID' => $this->getUserID());
  292. $rs = $db->Execute('select * from UserSearchIndexAttributes where uID = -1');
  293. AttributeKey::reindex('UserSearchIndexAttributes', $searchableAttributes, $attribs, $rs);
  294. }
  295. /**
  296. * Gets the value of the attribute for the user
  297. */
  298. public function getAttribute($ak, $displayMode = false) {
  299. Loader::model('attribute/categories/user');
  300. if (!is_object($ak)) {
  301. $ak = UserAttributeKey::getByHandle($ak);
  302. }
  303. if (is_object($ak)) {
  304. $av = $this->getAttributeValueObject($ak);
  305. if (is_object($av)) {
  306. $args = func_get_args();
  307. if (count($args) > 1) {
  308. array_shift($args);
  309. return call_user_func_array(array($av, 'getValue'), $args);
  310. } else {
  311. return $av->getValue($displayMode);
  312. }
  313. }
  314. }
  315. }
  316. public function getAttributeField($ak) {
  317. Loader::model('attribute/categories/user');
  318. if (!is_object($ak)) {
  319. $ak = UserAttributeKey::getByHandle($ak);
  320. }
  321. $value = $this->getAttributeValueObject($ak);
  322. $ak->render('form', $value);
  323. }
  324. public function getAttributeValueObject($ak, $createIfNotFound = false) {
  325. $db = Loader::db();
  326. $av = false;
  327. $v = array($this->getUserID(), $ak->getAttributeKeyID());
  328. $avID = $db->GetOne("select avID from UserAttributeValues where uID = ? and akID = ?", $v);
  329. if ($avID > 0) {
  330. $av = UserAttributeValue::getByID($avID);
  331. if (is_object($av)) {
  332. $av->setUser($this);
  333. $av->setAttributeKey($ak);
  334. }
  335. }
  336. if ($createIfNotFound) {
  337. $cnt = 0;
  338. // Is this avID in use ?
  339. if (is_object($av)) {
  340. $cnt = $db->GetOne("select count(avID) from UserAttributeValues where avID = ?", $av->getAttributeValueID());
  341. }
  342. if ((!is_object($av)) || ($cnt > 1)) {
  343. $av = $ak->addAttributeValue();
  344. }
  345. }
  346. return $av;
  347. }
  348. public function update($data) {
  349. $db = Loader::db();
  350. if ($this->uID) {
  351. $uName = $this->getUserName();
  352. $uEmail = $this->getUserEmail();
  353. $uHasAvatar = $this->hasAvatar();
  354. $uTimezone = $this->getUserTimezone();
  355. if (isset($data['uName'])) {
  356. $uName = $data['uName'];
  357. }
  358. if (isset($data['uEmail'])) {
  359. $uEmail = $data['uEmail'];
  360. }
  361. if (isset($data['uHasAvatar'])) {
  362. $uHasAvatar = $data['uHasAvatar'];
  363. }
  364. if( isset($data['uTimezone'])) {
  365. $uTimezone = $data['uTimezone'];
  366. }
  367. $ux = $this->getUserObject();
  368. $uDefaultLanguage = $ux->getUserDefaultLanguage();
  369. if (isset($data['uDefaultLanguage']) && $data['uDefaultLanguage'] != '') {
  370. $uDefaultLanguage = $data['uDefaultLanguage'];
  371. }
  372. $testChange = false;
  373. if ($data['uPassword'] != null) {
  374. if (User::encryptPassword($data['uPassword']) == User::encryptPassword($data['uPasswordConfirm'])) {
  375. $v = array($uName, $uEmail, User::encryptPassword($data['uPassword']), $uHasAvatar, $uTimezone, $uDefaultLanguage, $this->uID);
  376. $r = $db->prepare("update Users set uName = ?, uEmail = ?, uPassword = ?, uHasAvatar = ?, uTimezone = ?, uDefaultLanguage = ? where uID = ?");
  377. $res = $db->execute($r, $v);
  378. $testChange = true;
  379. } else {
  380. $updateGroups = false;
  381. }
  382. } else {
  383. $v = array($uName, $uEmail, $uHasAvatar, $uTimezone, $uDefaultLanguage, $this->uID);
  384. $r = $db->prepare("update Users set uName = ?, uEmail = ?, uHasAvatar = ?, uTimezone = ?, uDefaultLanguage = ? where uID = ?");
  385. $res = $db->execute($r, $v);
  386. }
  387. // now we check to see if the user is updated his or her own logged in record
  388. if (isset($_SESSION['uID']) && $_SESSION['uID'] == $this->uID) {
  389. $_SESSION['uName'] = $uName; // make sure to keep the new uName in there
  390. }
  391. // run any internal event we have for user update
  392. $ui = UserInfo::getByID($this->uID);
  393. Events::fire('on_user_update', $ui);
  394. if ($testChange) {
  395. Events::fire('on_user_change_password', $ui, $data['uPassword']);
  396. }
  397. return $res;
  398. }
  399. }
  400. public function updateGroups($groupArray) {
  401. $db = Loader::db();
  402. $q = "select gID from UserGroups where uID = '{$this->uID}'";
  403. $r = $db->query($q);
  404. if ($r) {
  405. $existingGIDArray = array();
  406. while ($row = $r->fetchRow()) {
  407. $existingGIDArray[] = $row['gID'];
  408. }
  409. }
  410. $dh = Loader::helper('date');
  411. $datetime = $dh->getSystemDateTime();
  412. if (is_array($groupArray)) {
  413. foreach ($groupArray as $gID) {
  414. $key = array_search($gID, $existingGIDArray);
  415. if ($key !== false) {
  416. // we remove this item from the existing GID array
  417. unset($existingGIDArray[$key]);
  418. } else {
  419. // this item is new, so we add it.
  420. $q = "insert into UserGroups (uID, gID, ugEntered) values ({$this->uID}, $gID, '{$datetime}')";
  421. $r = $db->query($q);
  422. }
  423. }
  424. }
  425. // now we go through the existing GID Array, and remove everything, since whatever is left is not wanted.
  426. if (count($existingGIDArray) > 0) {
  427. $inStr = implode(',', $existingGIDArray);
  428. $q2 = "delete from UserGroups where uID = '{$this->uID}' and gID in ({$inStr})";
  429. $r2 = $db->query($q2);
  430. }
  431. }
  432. /**
  433. * @param array $data
  434. * @return UserInfo
  435. */
  436. public function register($data) {
  437. // slightly different than add. this is public facing
  438. if (defined("USER_VALIDATE_EMAIL")) {
  439. if (USER_VALIDATE_EMAIL > 0) {
  440. $data['uIsValidated'] = 0;
  441. }
  442. }
  443. $ui = UserInfo::add($data);
  444. return $ui;
  445. }
  446. public function setupValidation() {
  447. $db = Loader::db();
  448. $hash = $db->GetOne("select uHash from UserValidationHashes where uID = ? order by uDateGenerated desc", array($this->uID));
  449. if ($hash) {
  450. return $hash;
  451. } else {
  452. $h = Loader::helper('validation/identifier');
  453. $hash = $h->generate('UserValidationHashes', 'uHash');
  454. $db->Execute("insert into UserValidationHashes (uID, uHash, uDateGenerated) values (?, ?, ?)", array($this->uID, $hash, time()));
  455. return $hash;
  456. }
  457. }
  458. function markValidated() {
  459. $db = Loader::db();
  460. $v = array($this->uID);
  461. $db->query("update Users set uIsValidated = 1, uIsFullRecord = 1 where uID = ?", $v);
  462. $db->query("update UserValidationHashes set uDateRedeemed = " . time() . " where uID = ?", $v);
  463. Events::fire('on_user_validate', $this);
  464. return true;
  465. }
  466. function changePassword($newPassword) {
  467. $db = Loader::db();
  468. if ($this->uID) {
  469. $v = array(User::encryptPassword($newPassword), $this->uID);
  470. $q = "update Users set uPassword = ? where uID = ?";
  471. $r = $db->prepare($q);
  472. $res = $db->execute($r, $v);
  473. Events::fire('on_user_change_password', $this, $newPassword);
  474. return $res;
  475. }
  476. }
  477. function activate() {
  478. $db = Loader::db();
  479. $q = "update Users set uIsActive = 1 where uID = '{$this->uID}'";
  480. $r = $db->query($q);
  481. Events::fire('on_user_activate', $this);
  482. }
  483. function deactivate() {
  484. $db = Loader::db();
  485. $q = "update Users set uIsActive = 0 where uID = '{$this->uID}'";
  486. $r = $db->query($q);
  487. Events::fire('on_user_deactivate', $this);
  488. }
  489. function resetUserPassword() {
  490. // resets user's password, and returns the value of the reset password
  491. $db = Loader::db();
  492. if ($this->uID > 0) {
  493. $newPassword = '';
  494. $salt = "abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
  495. for ($i = 0; $i < 7; $i++) {
  496. $newPassword .= substr($salt, rand() %strlen($salt), 1);
  497. }
  498. $v = array(User::encryptPassword($newPassword), $this->uID);
  499. $q = "update Users set uPassword = ? where uID = ?";
  500. $r = $db->query($q, $v);
  501. if ($r) {
  502. return $newPassword;
  503. }
  504. }
  505. }
  506. function hasAvatar() {
  507. return $this->uHasAvatar;
  508. }
  509. function getLastLogin() {
  510. return $this->uLastLogin;
  511. }
  512. function getLastIPAddress() {
  513. return long2ip($this->uLastIP);
  514. }
  515. function getPreviousLogin() {
  516. return $this->uPreviousLogin;
  517. }
  518. function isActive() {
  519. return $this->uIsActive;
  520. }
  521. public function isValidated() {
  522. return $this->uIsValidated;
  523. }
  524. public function isFullRecord() {
  525. return $this->uIsFullRecord;
  526. }
  527. function getNumLogins() {
  528. return $this->uNumLogins;
  529. }
  530. function getUserID() {
  531. return $this->uID;
  532. }
  533. function getUserName() {
  534. return $this->uName;
  535. }
  536. function getUserPassword() {
  537. return $this->uPassword;
  538. }
  539. function getUserEmail() {
  540. return $this->uEmail;
  541. }
  542. /*
  543. * returns the user's timezone
  544. * @return string timezone
  545. */
  546. function getUserTimezone() {
  547. return $this->uTimezone;
  548. }
  549. /**
  550. * Gets the date a user was added to the system,
  551. * if user is specified, returns in the current user's timezone
  552. * @param string $type (system || user)
  553. * @return string date formated like: 2009-01-01 00:00:00
  554. */
  555. function getUserDateAdded($type = 'system', $datemask = 'Y-m-d H:i:s') {
  556. $dh = Loader::helper('date');
  557. if(ENABLE_USER_TIMEZONES && $type == 'user') {
  558. return $dh->getLocalDateTime($this->uDateAdded, $datemask);
  559. } else {
  560. return $dh->date($datemask, strtotime($this->uDateAdded));
  561. }
  562. }
  563. /* userinfo permissions modifications - since users can now have their own permissions on a collection, block ,etc..*/
  564. function canRead() {
  565. return strpos($this->permissionSet, 'r') > -1;
  566. }
  567. function canReadVersions() {
  568. return strpos($this->permissionSet, 'rv') > -1;
  569. }
  570. function canLimitedWrite() {
  571. return strpos($this->permissionSet, 'wu') > -1;
  572. }
  573. function canWrite() {
  574. return strpos($this->permissionSet, 'wa') > -1;
  575. }
  576. function canDeleteBlock() {
  577. return strpos($this->permissionSet, 'db') > -1;
  578. }
  579. function canDeleteCollection() {
  580. return strpos($this->permissionSet, 'dc') > -1;
  581. }
  582. function canApproveCollection() {
  583. return strpos($this->permissionSet, 'av') > -1;
  584. }
  585. function canAddSubContent() {
  586. return strpos($this->permissionSet, 'as') > -1;
  587. }
  588. function canAddSubCollection() {
  589. return strpos($this->permissionSet, 'ac') > -1;
  590. }
  591. function canAddBlock() {
  592. return strpos($this->permissionSet, 'ab') > -1;
  593. }
  594. function canAdminCollection() {
  595. return strpos($this->permissionSet, 'adm') > -1;
  596. }
  597. function canAdmin() {
  598. return strpos($this->permissionSet, 'adm') > -1;
  599. }
  600. /**
  601. * File manager permissions at the user level
  602. */
  603. public function canSearchFiles() {
  604. return $this->permissions['canSearch'];
  605. }
  606. public function getFileReadLevel() {
  607. return $this->permissions['canRead'];
  608. }
  609. public function getFileSearchLevel() {
  610. return $this->permissions['canSearch'];
  611. }
  612. public function getFileWriteLevel() {
  613. return $this->permissions['canWrite'];
  614. }
  615. public function getFileAdminLevel() {
  616. return $this->permissions['canAdmin'];
  617. }
  618. public function getFileAddLevel() {
  619. return $this->permissions['canAdd'];
  620. }
  621. public function getAllowedFileExtensions() {
  622. return $this->permissions['canAddExtensions'];
  623. }
  624. function getUserStartDate($type = 'system') {
  625. // time-release permissions for users
  626. if(ENABLE_USER_TIMEZONES && $type == 'user') {
  627. $dh = Loader::helper('date');
  628. return $dh->getLocalDateTime($this->upStartDate);
  629. } else {
  630. return $this->upStartDate;
  631. }
  632. }
  633. /**
  634. * Gets the date a user was last active on the site
  635. * if user is specified, returns in the current user's timezone
  636. * @param string $type (system || user)
  637. * @return string date formated like: 2009-01-01 00:00:00
  638. */
  639. function getLastOnline($type = 'system') {
  640. if(ENABLE_USER_TIMEZONES && $type == 'user') {
  641. $dh = Loader::helper('date');
  642. return $dh->getLocalDateTime($this->uLastOnline);
  643. } else {
  644. return $this->uLastOnline;
  645. }
  646. }
  647. function getUserEndDate($type = 'system') {
  648. if(ENABLE_USER_TIMEZONES && $type == 'user') {
  649. $dh = Loader::helper('date');
  650. return $dh->getLocalDateTime($this->upEndDate);
  651. } else {
  652. return $this->upEndDate;
  653. }
  654. }
  655. }