PageRenderTime 67ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/classes/User.class.php

https://github.com/BrianPrz/worklist
PHP | 1941 lines | 1330 code | 202 blank | 409 comment | 194 complexity | 033f5ee484ab5b04820652eb839ca66d MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // Copyright (c) 2010, LoveMachine Inc.
  3. // All Rights Reserved.
  4. // http://www.lovemachineinc.com
  5. // This class handles a User if you need more functionality don't hesitate to add it.
  6. // But please be as fair as you comment your (at least public) methods - maybe another developer
  7. // needs them too.
  8. class User {
  9. protected $id;
  10. protected $username;
  11. protected $password;
  12. protected $added;
  13. protected $budget;
  14. protected $nickname;
  15. protected $confirm;
  16. protected $confirm_string;
  17. protected $about;
  18. protected $contactway;
  19. protected $payway;
  20. protected $timezone;
  21. protected $w9_status;
  22. protected $w9_accepted;
  23. protected $first_name;
  24. protected $last_name;
  25. protected $is_runner;
  26. protected $is_payer;
  27. protected $is_active;
  28. protected $is_admin;
  29. protected $is_internal;
  30. protected $last_seen;
  31. protected $journal_nick;
  32. protected $is_guest;
  33. protected $int_code;
  34. protected $country;
  35. protected $city;
  36. protected $has_sandbox;
  37. protected $unixusername;
  38. protected $forgot_hash;
  39. protected $forgot_expire;
  40. protected $projects;
  41. protected $projects_checkedout;
  42. protected $filter;
  43. protected $avatar;
  44. protected $annual_salary;
  45. protected $picture;
  46. protected $manager;
  47. protected $referred_by;
  48. protected $paypal;
  49. protected $paypal_email;
  50. protected $paypal_verified;
  51. protected $paypal_hash;
  52. protected $bidding_notif;
  53. protected $review_notif;
  54. protected $self_notif;
  55. protected $has_W2;
  56. protected $findus;
  57. protected $sound_settings;
  58. /**
  59. * All about budget
  60. */
  61. protected $remainingFunds;
  62. protected $allocated;
  63. protected $submitted;
  64. protected $paid;
  65. protected $transfered;
  66. protected $allFees;
  67. protected $managed;
  68. private $auth_tokens = array();
  69. /**
  70. * With this constructor you can create a user by passing an array or a user id.
  71. *
  72. * @param mixed $options
  73. * @return User $this
  74. */
  75. public function __construct($options = null)
  76. {
  77. if (is_array($options)) {
  78. $this->setOptions($options);
  79. } else if (is_numeric($options) && $options) {
  80. $this->findUserById((int) $options);
  81. }
  82. return $this;
  83. }
  84. /**
  85. * This method tries to fetch a user by any expression.
  86. *
  87. * @param (mixed) $expr Expression, either User object, numbers for ids, email str (usernames) and non emails for nicknames
  88. * @return (mixed) Either the User or false.
  89. */
  90. public static function find($expr)
  91. {
  92. $user = new User();
  93. if (is_object($expr) && (get_class($expr) == 'User' || is_subclass_of($expr, 'User'))) {
  94. $user = $expr;
  95. } else {
  96. if (is_numeric($expr)) {
  97. // id
  98. $user->findUserById((int) $expr);
  99. } else {
  100. if (filter_var($expr, FILTER_VALIDATE_EMAIL)) {
  101. // username
  102. $user->findUserByUsername($expr);
  103. } else {
  104. // nickname
  105. $user->findUserByNickname($expr);
  106. }
  107. }
  108. }
  109. return $user;
  110. }
  111. /**
  112. * This method fetches a user by his id.
  113. *
  114. * @param (integer) $id Id
  115. * @return (mixed) Either the User or false.
  116. */
  117. public function findUserById($id)
  118. {
  119. $where = sprintf('`id` = %d', (int)$id);
  120. return $this->loadUser($where);
  121. }
  122. /**
  123. * This method fetches a user by his nickname.
  124. *
  125. * @param (string) $nick Nickname
  126. * @return (mixed) Either the User or false.
  127. */
  128. public function findUserByNickname($nick) {
  129. $nick = mysql_real_escape_string((string)$nick);
  130. $where = sprintf('`nickname` = "%s"', $nick);
  131. return $this->loadUser($where);
  132. }
  133. /**
  134. * This method fetches a user by his username.
  135. *
  136. * @param (string) $user Username
  137. * @return (mixed) Either the User or false.
  138. */
  139. public function findUserByUsername($user)
  140. {
  141. $user = mysql_real_escape_string((string)$user);
  142. $where = sprintf('`username` = "%s"', $user);
  143. return $this->loadUser($where);
  144. }
  145. public function findUserByPPUsername($paypal_email, $hash) {
  146. $paypal_email = mysql_real_escape_string((string) $paypal_email);
  147. $hash = mysql_real_escape_string((string) $hash);
  148. $where = sprintf('`paypal_email` = "%s" && `paypal_hash` = "%s"', $paypal_email, $hash);
  149. return $this->loadUser($where);
  150. }
  151. /**
  152. * TODO:
  153. * I'm not sure why the __get() overload isn't always being applied, but
  154. * the error log is showing entries like:
  155. * PHP Fatal error: Call to undefined method User::isEligible() in \
  156. * .../worklist/workitem.inc on line 1718
  157. * Determine the cause and fix properly.
  158. * -Alexi 2011-11-22
  159. */
  160. public function isEligible() {
  161. return $this->getIsEligible();
  162. }
  163. public function getIsEligible() {
  164. if ($this->getHas_W2()) {
  165. return true;
  166. }
  167. if ($this->isUsCitizen()) {
  168. // Quick and dirty fix to disable w9 verification - leo@lovemachineinc.com
  169. if (! $this->isW9Approved()) {
  170. return false;
  171. }
  172. }
  173. if ($this->isPaypalVerified()) {
  174. return true;
  175. } else {
  176. return false;
  177. }
  178. }
  179. /**
  180. * Use this method to update or insert a user.
  181. *
  182. * @return (boolean)
  183. */
  184. public function save() {
  185. if (null === $this->getId()) {
  186. $id = $this->insert();
  187. if ($id !== false) {
  188. $this->setId($id);
  189. return true;
  190. }
  191. return false;
  192. } else {
  193. return $this->update();
  194. }
  195. }
  196. /**
  197. * A method to check if this user is a US citizen.
  198. *
  199. * @return (boolean)
  200. */
  201. public function isUsCitizen() {
  202. if ($this->getCountry() === 'US') {
  203. return true;
  204. }
  205. return false;
  206. }
  207. /**
  208. * A method to check if this user has a W9 approval.
  209. *
  210. * @return (boolean)
  211. */
  212. public function isW9Approved() {
  213. if ($this->getW9_status() === 'approved') {
  214. return true;
  215. }
  216. return false;
  217. }
  218. /**
  219. * A method to check if this user is a Runner.
  220. *
  221. * @return (boolean)
  222. */
  223. public function isRunner()
  224. {
  225. if ((int)$this->getIs_runner() === 1) {
  226. return true;
  227. }
  228. return false;
  229. }
  230. /**
  231. * A method to check if this user is a payer.
  232. *
  233. * @return (boolean)
  234. */
  235. public function isPayer()
  236. {
  237. if ((int)$this->getIs_payer() === 1) {
  238. return true;
  239. }
  240. return false;
  241. }
  242. /**
  243. * A method to check if this user is an internal / hifi team member.
  244. *
  245. * @return (boolean)
  246. */
  247. public function isInternal()
  248. {
  249. if ((int) $this->getIs_internal() == 1) {
  250. return true;
  251. }
  252. return false;
  253. }
  254. /**
  255. * A method to check if this user is active or not.
  256. * Attention a user can also be secured and it would return false!
  257. *
  258. * @return (boolean)
  259. */
  260. public function isActive()
  261. {
  262. if ((int)$this->getIs_active() === 1) {
  263. return true;
  264. }
  265. return false;
  266. }
  267. /**
  268. * Authenticates against given password
  269. *
  270. * @param string $password Cleartext password
  271. *
  272. * @throws User_Exception
  273. * @return boolean
  274. */
  275. public function authenticate($password) {
  276. if (substr($this->getPassword(), 0, 7) == '{crypt}') {
  277. $encrypted = substr($this->getPassword(), 7);
  278. return ($encrypted == crypt($password, $encrypted));
  279. } else {
  280. return (sha1($password) == $this->getPassword());
  281. }
  282. }
  283. /**
  284. * Checks if the setter for the property exists and calls it
  285. *
  286. * @param string $name Name of the property
  287. * @param string $value Value of the property
  288. * @throws Exception
  289. * @return void
  290. */
  291. public function __set($name, $value)
  292. {
  293. $method = 'set' . ucfirst($name);
  294. if (!method_exists($this, $method)) {
  295. throw new Exception('Invalid ' . __CLASS__ . ' property');
  296. }
  297. $this->$method($value);
  298. }
  299. /**
  300. * Checks if the getter for the property exists and calls it
  301. *
  302. * @param string $name Name of the property
  303. * @param string $value Value of the property
  304. * @throws Exception
  305. * @return void
  306. *
  307. * TODO: Determine if this is worth keeping
  308. * What value does this provide? If you try to access a property that
  309. * doesn't exist, you'll get an exception anyway. This also adds a layer
  310. * of confusion to developers who don't know that we've overridden
  311. * the -> operator and that they need to name their function
  312. * getWhatever(), but call it by a different name: $this->whatever().
  313. * -alexi 2011-11-22
  314. */
  315. public function __get($name)
  316. {
  317. $method = 'get' . ucfirst($name);
  318. if (!method_exists($this, $method)) {
  319. throw new Exception('Invalid ' . __CLASS__ . ' property');
  320. }
  321. $this->$method();
  322. }
  323. /**
  324. * Automatically sets the options array
  325. * Array: Name => Value
  326. *
  327. * @param array $options
  328. * @return User $this
  329. */
  330. private function setOptions(array $options)
  331. {
  332. $methods = get_class_methods($this);
  333. foreach ($options as $key => $value) {
  334. $method = 'set' . ucfirst($key);
  335. if (in_array($method, $methods)) {
  336. $this->$method($value);
  337. }
  338. }
  339. return $this;
  340. }
  341. /**
  342. * @return the $id
  343. */
  344. public function getId() {
  345. return $this->id;
  346. }
  347. public function getPicture() {
  348. return $this->picture;
  349. }
  350. public function setPicture($picture) {
  351. $this->picture = $picture;
  352. }
  353. /**
  354. * @param $id the $id to set
  355. */
  356. public function setId($id) {
  357. $this->id = $id;
  358. }
  359. /**
  360. * @return the $username
  361. */
  362. public function getUsername() {
  363. return $this->username;
  364. }
  365. /**
  366. * @param $username the $username to set
  367. */
  368. public function setUsername($username) {
  369. $this->username = $username;
  370. return $this;
  371. }
  372. /**
  373. * @return the $password
  374. */
  375. public function getPassword() {
  376. return $this->password;
  377. }
  378. /**
  379. * @param $password the $password to set
  380. */
  381. public function setPassword($password) {
  382. $this->password = $password;
  383. return $this;
  384. }
  385. /**
  386. * @return the $added
  387. */
  388. public function getAdded() {
  389. return $this->added;
  390. }
  391. /**
  392. * @param $added the $added to set
  393. */
  394. public function setAdded($added) {
  395. $this->added = $added;
  396. return $this;
  397. }
  398. public function getBudget() {
  399. return $this->budget;
  400. }
  401. public function setBudget($budget) {
  402. $this->budget = $budget;
  403. return $this;
  404. }
  405. public function updateBudget($amount, $budget_id = 0, $budgetDepletedMessage = true) {
  406. $budgetDepletedSent = false;
  407. if ($budget_id > 0) {
  408. $budget = new Budget();
  409. if ($budget->loadById($budget_id) ) {
  410. $remainingFunds = $budget->getRemainingFunds();
  411. $budget->remaining = $remainingFunds;
  412. $budget->save("id");
  413. if ($remainingFunds <= 0 && $budgetDepletedMessage == true) {
  414. $runnerNickname = $this->getNickname();
  415. $subject = "Depleted - Budget " . $budget_id . " (For " . $budget->reason . ")";
  416. $link = SECURE_SERVER_URL . "team?showUser=".$this->getId() . "&tab=tabBudgetHistory";
  417. $body = '<p>Hi ' . $runnerNickname . '</p>';
  418. $body .= "<p>Budget " . $budget_id . " for " . $budget->reason . "<br/> is now depleted.</p>";
  419. $body .= '<p>If your budget has gone under 0.00, you will need to ask the user who ' .
  420. 'granted you the Budget to close out this budget for you.</p>';
  421. $body .= '<p>To go to the Team Page, click <a href="' . $link . '">here</a></p>';
  422. $body .= '<p>- Worklist.net</p>';
  423. $plain = 'Hi ' . $runnerNickname . '\n\n';
  424. $plain .= "Budget " . $budget_id . " for " . $budget->reason . "\n is now depleted.\n\n";
  425. $plain .= 'If your budget has gone under 0.00, you will need to ask the user who ' .
  426. 'granted you the Budget to close out this budget for you.\n\n';
  427. $plain .= 'To go to the Team Page, click ' . $link . "\n\n";
  428. $plain .= '- Worklist.net\n\n';
  429. if (!send_email($this->getUsername(), $subject, $body, $plain)) {
  430. error_log("User.class.php: send_email failed on depleted Runner warning");
  431. }
  432. $budgetDepletedSent = true;
  433. }
  434. } else {
  435. error_log("User.class.php: send_email failed on depleted budget Runner warning - invalid budget id:" . $budget_id);
  436. }
  437. }
  438. $this->setBudget($this->setRemainingFunds());
  439. $this->save();
  440. }
  441. public function getRemainingFunds()
  442. {
  443. if (null === $this->remainingFunds) {
  444. $this->setRemainingFunds();
  445. }
  446. return $this->remainingFunds;
  447. }
  448. public function setRemainingFunds()
  449. {
  450. $this->remainingFunds = 0;
  451. $remaining = null;
  452. $remainingFunds = 0;
  453. $budget_filter = " AND " . WORKLIST . ".budget_id > 0 AND " . BUDGETS . ".id = " . WORKLIST . ".budget_id AND " .
  454. BUDGETS . ".active = 1 ";
  455. $budget_filter2 = " AND " . FEES . ".budget_id > 0 AND " . BUDGETS . ".id = " . FEES . ".budget_id AND " .
  456. BUDGETS . ".active = 1 ";
  457. $allocatedFunds = 0;
  458. $sql = 'SELECT SUM(`' . FEES . '`.`amount`) AS `allocated` FROM `' . FEES . '`, `' . WORKLIST . '`, `' . BUDGETS . '` WHERE `' .
  459. WORKLIST . '`.`runner_id` = ' . $this->getId() . ' AND `' . FEES . '`.`worklist_id` = `' .
  460. WORKLIST . '`.`id` AND `' . WORKLIST . '`.`status` IN ("Working", "Functional", "SvnHold", "Review", "Completed") AND `' .
  461. FEES . '`.`withdrawn` != 1 ' . $budget_filter;
  462. $result = mysql_query($sql);
  463. if ($result && (mysql_num_rows($result) == 1)) {
  464. $row = mysql_fetch_assoc($result);
  465. $allocatedFunds = $row['allocated'];
  466. }
  467. $submittedFunds = 0;
  468. $sql = 'SELECT SUM(`' . FEES . '`.`amount`) AS `submitted` FROM `' . FEES . '`, `' . WORKLIST . '`, `' . BUDGETS . '` WHERE `' .
  469. WORKLIST . '`.`runner_id` = ' . $this->getId() . ' AND `' . FEES . '`.`worklist_id` = `' . WORKLIST .
  470. '`.`id` AND `' . WORKLIST . '`.`status` IN ("Done") AND `' . FEES . '`.`paid` = 0 AND `' . FEES . '`.`withdrawn` != 1 ' . $budget_filter;
  471. $result = mysql_query($sql);
  472. if ($result && (mysql_num_rows($result) == 1)) {
  473. $row = mysql_fetch_assoc($result);
  474. $submittedFunds = $row['submitted'];
  475. }
  476. $sql = 'SELECT SUM(`' . FEES . '`.`amount`) AS `submitted` FROM `' . FEES . '`, `' . BUDGETS . '` WHERE `' .
  477. FEES . '`.`payer_id` = ' . $this->getId() . ' AND `' . FEES . '`.`worklist_id` = 0 AND `' . FEES . '`.`paid` = 0 AND `' . FEES . '`.`withdrawn` != 1 ' . $budget_filter2;
  478. $result = mysql_query($sql);
  479. if ($result && (mysql_num_rows($result) == 1)) {
  480. $row = mysql_fetch_assoc($result);
  481. $submittedFunds = $submittedFunds + $row['submitted'];
  482. }
  483. $paidFunds = 0;
  484. $sql = 'SELECT SUM(`' . FEES . '`.`amount`) AS `paid` FROM `' . FEES . '`, `' . WORKLIST . '`, `' . BUDGETS . '` WHERE `' .
  485. WORKLIST . '`.`runner_id` = ' . $this->getId() . ' AND `' . FEES . '`.`worklist_id` = `' . WORKLIST .
  486. '`.`id` AND `' . WORKLIST . '`.`status` IN ("Done") AND `' . FEES . '`.`paid` = 1 AND `' . FEES . '`.`withdrawn` != 1 ' . $budget_filter;
  487. $result = mysql_query($sql);
  488. if ($result && (mysql_num_rows($result) == 1)) {
  489. $row = mysql_fetch_assoc($result);
  490. $paidFunds = $row['paid'];
  491. }
  492. $sql = 'SELECT SUM(`' . FEES . '`.`amount`) AS `paid` FROM `' . FEES . '`, `' . BUDGETS . '` WHERE `' .
  493. FEES . '`.`payer_id` = ' . $this->getId() . ' AND `' . FEES . '`.`worklist_id` = 0 AND `' . FEES . '`.`paid` = 1 AND `' . FEES . '`.`withdrawn` != 1 ' . $budget_filter2;
  494. $result = mysql_query($sql);
  495. if ($result && (mysql_num_rows($result) == 1)) {
  496. $row = mysql_fetch_assoc($result);
  497. $paidFunds = $paidFunds + $row['paid'];
  498. }
  499. $transferedFunds = 0;
  500. $sql = 'SELECT SUM(s.`amount_granted`) AS `transfered` FROM ' . BUDGET_SOURCE . " AS s " .
  501. "INNER JOIN " . BUDGETS . " AS b ON s.budget_id = b.id AND b.active = 1 " .
  502. ' WHERE s.`giver_id` = ' . $this->getId() ;
  503. $result = mysql_query($sql);
  504. if ($result && (mysql_num_rows($result) == 1)) {
  505. $row = mysql_fetch_assoc($result);
  506. $transferedFunds = $row['transfered'];
  507. }
  508. $receivedFunds = 0;
  509. $sql = 'SELECT SUM(`' . BUDGETS . '`.`amount`) AS `received` FROM `' . BUDGETS . '` WHERE `' .
  510. BUDGETS . '`.`receiver_id` = ' . $this->getId() . " AND " . BUDGETS . ".active = 1 ";
  511. $result = mysql_query($sql);
  512. if ($result && (mysql_num_rows($result) == 1)) {
  513. $row = mysql_fetch_assoc($result);
  514. $receivedFunds = $row['received'];
  515. }
  516. $remainingFunds = 0;
  517. $sql = 'SELECT SUM(`' . BUDGETS . '`.`remaining`) AS `remaining` FROM `' . BUDGETS . '` WHERE `' .
  518. BUDGETS . '`.`receiver_id` = ' . $this->getId() . " AND " . BUDGETS . ".active = 1 ";
  519. $result = mysql_query($sql);
  520. if ($result && (mysql_num_rows($result) == 1)) {
  521. $row = mysql_fetch_assoc($result);
  522. $remainingFunds = $row['remaining'];
  523. }
  524. $this->setAllocated($allocatedFunds);
  525. $this->setSubmitted($submittedFunds);
  526. $this->setPaid($paidFunds);
  527. $this->setTransfered($transferedFunds);
  528. $remaining = $receivedFunds - $allocatedFunds - $submittedFunds - $paidFunds - $transferedFunds;
  529. $this->remainingFunds = $this->getBudget();
  530. return $remainingFunds;
  531. }
  532. public function getTransfered()
  533. {
  534. if (null === $this->transfered) {
  535. $this->setTransfered(0);
  536. }
  537. return $this->transfered;
  538. }
  539. public function getAllocated()
  540. {
  541. if (null === $this->allocated) {
  542. $this->setAllocated(0);
  543. }
  544. return $this->allocated;
  545. }
  546. public function setAllocated($value)
  547. {
  548. $this->allocated = $value;
  549. return $this;
  550. }
  551. public function setTransfered($value)
  552. {
  553. $this->transfered = $value;
  554. return $this;
  555. }
  556. public function getSubmitted()
  557. {
  558. if (null === $this->submitted) {
  559. $this->setSubmitted(0);
  560. }
  561. return $this->submitted;
  562. }
  563. public function setSubmitted($value)
  564. {
  565. $this->submitted = $value;
  566. return $this;
  567. }
  568. public function getPaid()
  569. {
  570. if (null === $this->paid) {
  571. $this->setPaid(0);
  572. }
  573. return $this->paid;
  574. }
  575. public function setPaid($value)
  576. {
  577. $this->paid = $value;
  578. return $this;
  579. }
  580. public function getActiveBudgets()
  581. {
  582. // Query to get User's Budget entries
  583. $query = ' SELECT amount, remaining, reason, id '
  584. . ' FROM ' . BUDGETS
  585. . ' WHERE receiver_id = ' . $this->getId()
  586. . ' AND active = 1 '
  587. . ' ORDER BY id DESC ';
  588. $result = mysql_query($query);
  589. $ret = "";
  590. if ($result) {
  591. while ($row = mysql_fetch_assoc($result)) {
  592. $ret[] = $row;
  593. }
  594. }
  595. return $ret;
  596. }
  597. public function getBudgetCombo($budget_id = 0)
  598. {
  599. $userid = isset($_SESSION['userid']) ? $_SESSION['userid'] : 0;
  600. // Query to get User's Budget entries
  601. $query = ' SELECT amount, remaining, reason, id '
  602. . ' FROM ' . BUDGETS
  603. . ' WHERE receiver_id = ' . $userid
  604. . ' AND active = 1 '
  605. . ' ORDER BY id DESC ';
  606. $result = mysql_query($query);
  607. $ret = "";
  608. if ($result) {
  609. while ($row = mysql_fetch_assoc($result)) {
  610. if (isset($budget_id) && $budget_id == $row['id']) {
  611. $selected = "selected='selected'";
  612. } else {
  613. $selected = "";
  614. }
  615. $ret .= '<option value="' . $row['id'] . '" ' . $selected . ' data-amount="' . $row['remaining'] . '">' .
  616. $row['reason'] . ' ($' . $row['remaining'] . ")</option>\n";
  617. }
  618. }
  619. return $ret;
  620. }
  621. public function getTotalManaged() {
  622. $sql = 'SELECT SUM(`amount`) AS `managed`
  623. FROM `' . BUDGETS . '`
  624. WHERE `receiver_id` = ' . $_SESSION['userid'] . ' ';
  625. $res = mysql_query($sql);
  626. if ($res && $row = mysql_fetch_assoc($res)) {
  627. return $row['managed'];
  628. }
  629. return false;
  630. }
  631. /**
  632. * @return the $nickname
  633. */
  634. public function getNickname() {
  635. return $this->getSubNickname($this->nickname);
  636. }
  637. /**
  638. * @param $nickname the $nickname to set
  639. */
  640. public function setNickname($nickname) {
  641. $this->nickname = $nickname;
  642. return $this;
  643. }
  644. /**
  645. * @return the $nickname
  646. */
  647. public function getCity() {
  648. return $this->city;
  649. }
  650. /**
  651. * @param $nickname the $nickname to set
  652. */
  653. public function setCity($city) {
  654. $this->city = $city;
  655. return $this;
  656. }
  657. /**
  658. * @return the $confirm
  659. */
  660. public function getConfirm() {
  661. return $this->confirm;
  662. }
  663. /**
  664. * @param $confirm the $confirm to set
  665. */
  666. public function setConfirm($confirm) {
  667. $this->confirm = $confirm;
  668. return $this;
  669. }
  670. /**
  671. * @return the $confirm_string
  672. */
  673. public function getConfirm_string() {
  674. return $this->confirm_string;
  675. }
  676. /**
  677. * @param $confirm_string the $confirm_string to set
  678. */
  679. public function setConfirm_string($confirm_string) {
  680. $this->confirm_string = $confirm_string;
  681. return $this;
  682. }
  683. public function getForgot_hash() {
  684. return $this->forgot_hash;
  685. }
  686. /**
  687. * @param $token
  688. */
  689. public function setForgot_hash($token) {
  690. $this->forgot_hash = $token;
  691. return $this;
  692. }
  693. /**
  694. * @return the $about
  695. */
  696. public function getAbout() {
  697. return $this->about;
  698. }
  699. /**
  700. * @param $about the $about to set
  701. */
  702. public function setAbout($about) {
  703. $this->about = $about;
  704. return $this;
  705. }
  706. public function getSystems() {
  707. $system = new UserSystemModel();
  708. return $system->getUserSystems($this->getId());
  709. }
  710. public function getSystemsCount() {
  711. $system = new UserSystemModel();
  712. return $system->numberOfUserSystems($this->getId());
  713. }
  714. /**
  715. * @return the $findus
  716. */
  717. public function getFindus() {
  718. return $this->findus;
  719. }
  720. /**
  721. * @param $findus to set
  722. */
  723. public function setFindus($findus) {
  724. $this->findus = $findus;
  725. return $this;
  726. }
  727. /**
  728. * @return the $sound_settings
  729. */
  730. public function getSound_settings() {
  731. return $this->sound_settings;
  732. }
  733. /**
  734. * @param $sound_settings to set
  735. */
  736. public function setSound_settings($sound_settings) {
  737. $this->sound_settings = $sound_settings;
  738. return $this;
  739. }
  740. /**
  741. * @return the $contactway
  742. */
  743. public function getContactway() {
  744. return $this->contactway;
  745. }
  746. /**
  747. * @param $contactway the $contactway to set
  748. */
  749. public function setContactway($contactway) {
  750. $this->contactway = $contactway;
  751. return $this;
  752. }
  753. /**
  754. * @return the $payway
  755. */
  756. public function getPayway() {
  757. return $this->payway;
  758. }
  759. /**
  760. * @param $payway the $payway to set
  761. */
  762. public function setPayway($payway) {
  763. $this->payway = $payway;
  764. return $this;
  765. }
  766. /**
  767. * @return the $timezone
  768. */
  769. public function getTimezone() {
  770. return $this->timezone;
  771. }
  772. /**
  773. * @param $timezone the $timezone to set
  774. */
  775. public function setTimezone($timezone) {
  776. $this->timezone = $timezone;
  777. return $this;
  778. }
  779. public function getW9_status() {
  780. return $this->w9_status;
  781. }
  782. public function setW9_status($status) {
  783. $this->w9_status = $status;
  784. return $this;
  785. }
  786. /**
  787. * @return the $w9_accepted
  788. */
  789. public function getW9_accepted() {
  790. return $this->w9_accepted;
  791. }
  792. /**
  793. * @param $w9_accepted the $w9_accepted to set
  794. */
  795. public function setW9_accepted($w9_accepted) {
  796. $this->w9_accepted = $w9_accepted;
  797. return $this;
  798. }
  799. /**
  800. * @return the $first_name
  801. */
  802. public function getFirst_name() {
  803. return $this->first_name;
  804. }
  805. /**
  806. * @param $first_name the $first_name to set
  807. */
  808. public function setFirst_name($first_name) {
  809. $this->first_name = $first_name;
  810. return $this;
  811. }
  812. /**
  813. * @return the $last_name
  814. */
  815. public function getLast_name() {
  816. return $this->last_name;
  817. }
  818. /**
  819. * @param $last_name the $last_name to set
  820. */
  821. public function setLast_name($last_name) {
  822. $this->last_name = $last_name;
  823. return $this;
  824. }
  825. /**
  826. * @param $gitHubId
  827. * @return bool if user has authorized the app with github, false otherwise
  828. */
  829. public function isGithub_connected($gitHubId = GITHUB_OAUTH2_CLIENT_ID) {
  830. $userId = getSessionUserId();
  831. if ($userId == 0) {
  832. return false;
  833. }
  834. $sql = "SELECT COUNT(*) AS count FROM `" . USERS_AUTH_TOKENS . "`
  835. WHERE user_id = " . (int)$userId . " AND github_id = '" . mysql_real_escape_string($gitHubId) . "'";
  836. $result = mysql_query($sql);
  837. if ($result && mysql_num_rows($result) > 0) {
  838. $row = mysql_fetch_assoc($result);
  839. return (int)$row['count'] > 0;
  840. } else {
  841. return false;
  842. }
  843. }
  844. /**
  845. * @return the $is_active
  846. */
  847. public function getIs_active() {
  848. return $this->is_active;
  849. }
  850. /**
  851. * @param $is_active the $is_active to set
  852. */
  853. public function setIs_active($is_active) {
  854. $this->is_active = $is_active;
  855. return $this;
  856. }
  857. public function getLast_seen() {
  858. return $this->last_seen;
  859. }
  860. public function setLast_seen($last_seen) {
  861. $this->last_seen = $last_seen;
  862. return $this;
  863. }
  864. public function getTimeLastSeen() {
  865. $sql = "SELECT TIMESTAMPDIFF(SECOND, NOW(), `last_seen`) AS last_seen FROM " . USERS ." WHERE id = " . $this->getId();
  866. $query = mysql_query($sql);
  867. if ($query && mysql_num_rows($query) > 0) {
  868. $row = mysql_fetch_assoc($query);
  869. return $row['last_seen'];
  870. } else {
  871. return false;
  872. }
  873. }
  874. /**
  875. * @return the $is_runner
  876. */
  877. public function getIs_runner() {
  878. return $this->is_runner;
  879. }
  880. /**
  881. * @param $is_runner the $is_runner to set
  882. */
  883. public function setIs_runner($is_runner) {
  884. $this->is_runner = $is_runner;
  885. return $this;
  886. }
  887. /**
  888. * @return the $is_admin
  889. */
  890. public function getIs_admin() {
  891. return $this->is_admin;
  892. }
  893. /**
  894. * @param $is_admin the $is_admin to set
  895. */
  896. public function setIs_admin($is_admin) {
  897. $this->is_admin = $is_admin;
  898. return $this;
  899. }
  900. /**
  901. * @return bool $is_internal
  902. */
  903. public function getIs_internal() {
  904. return $this->is_internal;
  905. }
  906. /**
  907. * @param bool $is_internal the $is_internal to set
  908. */
  909. public function setIs_internal($is_internal) {
  910. $this->is_internal = $is_internal;
  911. return $this;
  912. }
  913. public function getPaypal() {
  914. return $this->paypal;
  915. }
  916. public function setPaypal($paypal) {
  917. $this->paypal = $paypal;
  918. return $this;
  919. }
  920. public function getPaypal_email() {
  921. return $this->paypal_email;
  922. }
  923. public function setPaypal_email($paypal_email) {
  924. $this->paypal_email = $paypal_email;
  925. return $this;
  926. }
  927. public function getPaypal_hash() {
  928. return $this->paypal_hash;
  929. }
  930. public function setPaypal_hash($paypal_hash) {
  931. $this->paypal_hash = $paypal_hash;
  932. return $this;
  933. }
  934. public function getPaypal_verified() {
  935. return $this->paypal_verified;
  936. }
  937. public function isPaypalVerified() {
  938. if ((int)$this->getPaypal_verified() === 1) {
  939. return true;
  940. }
  941. return false;
  942. }
  943. public function setPaypal_verified($paypal_verified) {
  944. $this->paypal_verified = $paypal_verified;
  945. return $this;
  946. }
  947. /**
  948. * @return the $is_payer
  949. */
  950. public function getIs_payer() {
  951. return $this->is_payer;
  952. }
  953. /**
  954. * @param $is_payer the $is_payer to set
  955. */
  956. public function setIs_payer($is_payer) {
  957. $this->is_payer = $is_payer;
  958. return $this;
  959. }
  960. /**
  961. * @return the $unixusername
  962. */
  963. public function getAnnual_salary() {
  964. return $this->annual_salary;
  965. }
  966. /**
  967. * @param $unixusername: unix username to set
  968. */
  969. public function setAnnual_salary($annual_salary) {
  970. $this->annual_salary = $annual_salary;
  971. return $this;
  972. }
  973. /**
  974. * @return the $journal_nick
  975. */
  976. public function getJournal_nick() {
  977. return $this->journal_nick;
  978. }
  979. /**
  980. * @param $journal_nick the $journal_nick to set
  981. */
  982. public function setJournal_nick($journal_nick) {
  983. $this->journal_nick = $journal_nick;
  984. return $this;
  985. }
  986. /**
  987. * @return the $is_guest
  988. */
  989. public function getIs_guest() {
  990. return $this->is_guest;
  991. }
  992. /**
  993. * @param $is_guest the $is_guest to set
  994. */
  995. public function setIs_guest($is_guest) {
  996. $this->is_guest = $is_guest;
  997. return $this;
  998. }
  999. /**
  1000. * @return string
  1001. */
  1002. public function getInt_code()
  1003. {
  1004. return $this->int_code;
  1005. }
  1006. /**
  1007. * @param string $intCode
  1008. * @return User
  1009. */
  1010. public function setInt_code($intCode)
  1011. {
  1012. $this->int_code = $intCode;
  1013. return $this;
  1014. }
  1015. /**
  1016. * @return the $country
  1017. */
  1018. public function getCountry() {
  1019. return $this->country;
  1020. }
  1021. /**
  1022. * @param $country the $country to set
  1023. */
  1024. public function setCountry($country) {
  1025. $this->country = $country;
  1026. return $this;
  1027. }
  1028. /**
  1029. * @return the $manager
  1030. */
  1031. public function getManager() {
  1032. return $this->manager;
  1033. }
  1034. /**
  1035. * @param $manager the $manager to set
  1036. */
  1037. public function setManager($manager) {
  1038. $this->manager = $manager;
  1039. return $this;
  1040. }
  1041. /**
  1042. * @return the $referrer
  1043. */
  1044. public function getReferred_by() {
  1045. return $this->referred_by;
  1046. }
  1047. /**
  1048. * @param $referred_by the $referred_by to set
  1049. */
  1050. public function setReferred_by($referred_by) {
  1051. $this->referred_by = $referred_by;
  1052. return $this;
  1053. }
  1054. /**
  1055. * @return the $has_sandbox
  1056. */
  1057. public function getHas_sandbox() {
  1058. return $this->has_sandbox;
  1059. }
  1060. /**
  1061. * @param $sendbox_status: status of the sandbox
  1062. */
  1063. public function setHas_sandbox($sendbox_status) {
  1064. $this->has_sandbox = $sendbox_status;
  1065. return $this;
  1066. }
  1067. /**
  1068. * @return the $unixusername
  1069. */
  1070. public function getUnixusername() {
  1071. return $this->unixusername;
  1072. }
  1073. /**
  1074. * @param $unixusername: unix username to set
  1075. */
  1076. public function setUnixusername($unixusername) {
  1077. $this->unixusername = $unixusername;
  1078. return $this;
  1079. }
  1080. /**
  1081. * Given a user's chosen nickname, generate their unixusername.
  1082. * This is done by:
  1083. * - lowercasing their nickname
  1084. * - stripping non-alphanumeric
  1085. * - verifying uniqueness in passwd file & user table
  1086. * - if not unique, append a number :/
  1087. * (not the greatest, but it can be changed later)
  1088. *
  1089. */
  1090. public function generateUnixUsername($nickname) {
  1091. // lowercase
  1092. $unixname = strtolower($nickname);
  1093. // find alphanumeric-only parts to use as unixname
  1094. $disallowed_characters = "/[^a-z0-9]/";
  1095. $unixname = preg_replace($disallowed_characters, "", $unixname);
  1096. // make sure first character is alpha character (can't start w/ a #)
  1097. if (preg_match("/^[a-z]/", $unixname) == 0) {
  1098. // lets not be fancy.. just prepend an "a" to their name.
  1099. $unixname = "a".$unixname;
  1100. }
  1101. // append numbers to the end of the name if it's not unique
  1102. // to both the password file AND the user table
  1103. // Test SanboxUtil last since that could be a remote call
  1104. $attempted_unixname = $unixname;
  1105. $x = 0;
  1106. while (User::unixusernameExists($attempted_unixname) ||
  1107. SandBoxUtil::inPasswdFile($attempted_unixname)) {
  1108. $x++;
  1109. $attempted_unixname = $unixname.$x;
  1110. }
  1111. $unixname = $attempted_unixname;
  1112. return $unixname;
  1113. }
  1114. /**
  1115. * @return true if the supplied username is in the database
  1116. *
  1117. */
  1118. public function unixusernameExists($username) {
  1119. $username = mysql_real_escape_string($username);
  1120. $query_string = "
  1121. SELECT
  1122. id
  1123. FROM
  1124. ".USERS."
  1125. WHERE
  1126. unixusername='".$username."'";
  1127. $query = mysql_query($query_string);
  1128. if (mysql_num_rows($query) > 0) {
  1129. return true;
  1130. }
  1131. return false;
  1132. }
  1133. /**
  1134. * @return the $projects_checkedout
  1135. */
  1136. public function getProjects_checkedout() {
  1137. $query = mysql_query("SELECT `project_id`, `checked_out` FROM `".PROJECT_USERS."`
  1138. WHERE `user_id`=" . $this->getId() . "
  1139. AND `checked_out` = 1");
  1140. if ($query && mysql_num_rows($query)) {
  1141. while ($row = mysql_fetch_assoc($query)) {
  1142. $this->projects[] = $row;
  1143. }
  1144. } else {
  1145. return null;
  1146. }
  1147. return $this->projects;
  1148. }
  1149. public function getProjects() {
  1150. return $this->projects ;
  1151. }
  1152. /**
  1153. * @param $projects_checkedout: projects checked out for user
  1154. */
  1155. public function setProjects_checkedout($projects_checkedout) {
  1156. $this->projects_checkedout = $projects_checkedout;
  1157. return $this;
  1158. }
  1159. public function isProjectCheckedOut($project_id) {
  1160. foreach ($this->projects as $project) {
  1161. if ($project['project_id'] == $project_id) {
  1162. if ($project['checked_out'] == 1) {
  1163. return true;
  1164. } else {
  1165. return false;
  1166. }
  1167. }
  1168. }
  1169. }
  1170. public function checkoutProject($project_id) {
  1171. $query = mysql_query("INSERT INTO `".PROJECT_USERS."` VALUES ('', ".$this->getId().", ".$project_id.", 1)");
  1172. if ($query) {
  1173. return mysql_insert_id();
  1174. } else {
  1175. return false;
  1176. }
  1177. }
  1178. /**
  1179. * @return the $filter
  1180. */
  1181. public function getFilter() {
  1182. return $this->filter;
  1183. }
  1184. /**
  1185. * Get a list of active users.
  1186. *
  1187. * @param $active int Show only active users if 1
  1188. * @param $active int Show only runner users if 1
  1189. * @param $populate int Populate a user by id
  1190. * @return array Userlist
  1191. *
  1192. */
  1193. public static function getUserList($populate = 0, $active = 0, $runner = 0) {
  1194. $sql = "";
  1195. if ($active) {
  1196. $user_where = "( users.id = runner_id OR users.id = mechanic_id OR users.id = creator_id )";
  1197. $sql .= "SELECT DISTINCT " . USERS . ".* FROM " . USERS . "," . WORKLIST . "
  1198. WHERE
  1199. " . WORKLIST . ".status_changed > DATE_SUB(NOW(), INTERVAL 30 DAY) AND
  1200. {$user_where}";
  1201. $sql .= $runner ? ' AND `is_runner` = 1' : '';
  1202. $sql .= " UNION
  1203. SELECT DISTINCT " . USERS . ".* FROM " . USERS . "
  1204. WHERE
  1205. " . USERS . ".added > DATE_SUB(NOW(), INTERVAL 15 DAY) ";
  1206. $sql .= $runner ? ' AND `is_runner` = 1' : '';
  1207. }
  1208. else {
  1209. $sql .= "SELECT users.* FROM users
  1210. WHERE users.is_active > 0 AND users.confirm = 1";
  1211. $sql .= $runner ? ' AND `is_runner` = 1' : '';
  1212. }
  1213. $sql .= " UNION SELECT users.* FROM users WHERE users.id = {$populate}";
  1214. // Final Query: wrap unioned queries and sort by nickname
  1215. $sql = "SELECT DISTINCT * FROM ({$sql}) DistinctUsers ORDER BY nickname ASC";
  1216. $result = mysql_query($sql);
  1217. $i = (int) $populate > 0 ? (int) 1 : 0;
  1218. while ($result && ($row = mysql_fetch_assoc($result))) {
  1219. $user = new User();
  1220. if ($populate != $row['id']) {
  1221. $userlist[$i++] = $user->setOptions($row);
  1222. } else {
  1223. $userlist[0] = $user->setOptions($row);
  1224. }
  1225. }
  1226. ksort($userlist);
  1227. return ((!empty($userlist)) ? $userlist : false);
  1228. }
  1229. public static function getRunnerlist() {
  1230. $runnerlist = array();
  1231. $sql = 'SELECT `' . USERS . '`.`id` FROM `' . USERS . '` WHERE `' . USERS . '`.`is_runner` = 1
  1232. OR `' . USERS . '`.`id` IN (SELECT `runner_id` FROM `' . PROJECT_RUNNERS . '`)';
  1233. $result = mysql_query($sql);
  1234. while ($result && ($row = mysql_fetch_assoc($result))) {
  1235. $user = new User();
  1236. $runnerlist[] = $user->findUserById($row['id']);
  1237. }
  1238. return ((!empty($runnerlist)) ? $runnerlist : false);
  1239. }
  1240. public static function getRelRunnerlist($project_id) {
  1241. $relrunnerlist = array();
  1242. $sql = 'SELECT `runner_id` FROM `' . PROJECT_RUNNERS . '` WHERE `project_id` = ' . $project_id . ' ';
  1243. $result = mysql_query($sql);
  1244. while ($result && ($row = mysql_fetch_assoc($result))) {
  1245. $user = new User();
  1246. $relrunnerlist[] = $user->findUserById($row['id']);
  1247. }
  1248. return ((!empty($relrunnerlist)) ? $relrunnerlist : false);
  1249. }
  1250. public static function getPayerList() {
  1251. $payerlist = array();
  1252. $sql = 'SELECT `' . USERS . '`.`id` FROM `' . USERS . '` WHERE `' . USERS . '`.`is_payer` = 1;';
  1253. $result = mysql_query($sql);
  1254. while ($result && ($row = mysql_fetch_assoc($result))) {
  1255. $user = new User();
  1256. $payerlist[] = $user->findUserById($row['id']);
  1257. }
  1258. return ((!empty($payerlist)) ? $payerlist : false);
  1259. }
  1260. /**
  1261. * @param $filter the $filter to set
  1262. */
  1263. public function setFilter($filter) {
  1264. $this->filter = $filter;
  1265. }
  1266. protected function loadUser($where)
  1267. {
  1268. // now we build the sql query
  1269. $sql = 'SELECT * FROM `' . USERS . '` WHERE ' . $where . ' LIMIT 1;';
  1270. // and get the result
  1271. $result = mysql_query($sql);
  1272. if ($result && (mysql_num_rows($result) == 1)) {
  1273. $options = mysql_fetch_assoc($result);
  1274. $this->setOptions($options);
  1275. return $this;
  1276. }
  1277. return false;
  1278. }
  1279. private function getUserColumns()
  1280. {
  1281. $columns = array();
  1282. $result = mysql_query('SHOW COLUMNS FROM `' . USERS . '`');
  1283. if (mysql_num_rows($result) > 0) {
  1284. while ($row = mysql_fetch_assoc($result)) {
  1285. $columns[] = $row;
  1286. }
  1287. return $columns;
  1288. }
  1289. return false;
  1290. }
  1291. private function prepareData()
  1292. {
  1293. $columns = $this->getUserColumns();
  1294. $cols = array(); $values = array();
  1295. foreach ($columns as $col) {
  1296. $method = 'get' . ucfirst($col['Field']);
  1297. if (method_exists($this, $method) && (null !== $this->$method())) {
  1298. $cols[] = $col['Field'];
  1299. if (preg_match('/(char|text|blob)/i', $col['Type']) === 1) {
  1300. $values[] = mysql_real_escape_string($this->$method());
  1301. } else {
  1302. $values[] = $this->$method();
  1303. }
  1304. }
  1305. }
  1306. return array(
  1307. 'columns' => $cols,
  1308. 'values' => $values
  1309. );
  1310. }
  1311. private function insert()
  1312. {
  1313. $data = $this->prepareData();
  1314. $sql = 'INSERT INTO `' . USERS . '` (`' . implode('`,`', $data['columns']) . '`) VALUES ("' . implode('","', $data['values']) . '")';
  1315. $result = mysql_query($sql);
  1316. if ($result) {
  1317. return mysql_insert_id();
  1318. }
  1319. return false;
  1320. }
  1321. private function update()
  1322. {
  1323. $flag = false;
  1324. $data = $this->prepareData();
  1325. $sql = 'UPDATE `' . USERS . '` SET ';
  1326. foreach ($data['columns'] as $index => $column) {
  1327. if ($column == 'id') {
  1328. continue;
  1329. }
  1330. if ($flag === true) {
  1331. $sql .= ', ';
  1332. }
  1333. if( $column == "w9_accepted" && $data['values'][$index] == "NOW()" ){
  1334. $sql .= '`' . $column . '` = ' . $data['values'][$index];
  1335. } else {
  1336. $sql .= '`' . $column . '` = "' . $data['values'][$index] . '"';
  1337. }
  1338. $flag = true;
  1339. }
  1340. $sql .= ' WHERE `id` = ' . (int)$this->getId() . ';';
  1341. $result = mysql_query($sql);
  1342. if ($result) {
  1343. return true;
  1344. }
  1345. return false;
  1346. }
  1347. //Garth
  1348. /**
  1349. * Checks to see if image exists in the cloud
  1350. * @param string $imageName
  1351. * @return bool
  1352. */
  1353. protected function imageExistsS3($imageName) {
  1354. //Don't look for resizeds since we already looked in the db
  1355. if (strpos($imageName,'w:')) { error_log("S3: don't look for thumbnails $imageName"); return false; }
  1356. S3::setAuth(S3_ACCESS_KEY, S3_SECRET_KEY);
  1357. try {
  1358. if (! $result = S3::getObject(S3_BUCKET,'image/'.$imageName,false)) {
  1359. error_log("image not found on s3");
  1360. return false;
  1361. } ;
  1362. //Use to Debug S3 filecheck
  1363. //error_log("imageExistsS3: $imageName . ".print_r($result->code,true));
  1364. if ($result->code==200) {
  1365. return true;
  1366. }
  1367. return false;
  1368. } catch ( Exception $e ) {
  1369. throw new Exception("imageExistsS3:getObject caught: $e imageName");
  1370. }
  1371. }
  1372. /**
  1373. * Determine the avatar for the user from the `picture` field
  1374. *
  1375. * - If no picture is set, return placeholder image
  1376. * - If picture is URL, return it as is
  1377. * - Otherwise, preprend the APP_IMAGE_URL
  1378. *
  1379. * @return the $avatar
  1380. */
  1381. public function getAvatar($w = 50, $h = 50)
  1382. {
  1383. if (empty($this->picture)) {
  1384. return SERVER_URL ."thumb.php?src=no_picture.png&h=".$h."&w=".$w."&zc=0";
  1385. } else {
  1386. if ((!(substr($this->picture, 0, 7) == 'http://')) && (!(substr($this->picture, 0, 8) == 'https://'))) {
  1387. return APP_IMAGE_URL . $this->picture;
  1388. } else {
  1389. return $this->picture;
  1390. }
  1391. }
  1392. }
  1393. /**
  1394. * Retrieves the url to the avatar
  1395. */
  1396. public function setAvatar()
  1397. {
  1398. $this->avatar = $this->picture;
  1399. return $this;
  1400. }
  1401. /**
  1402. * @return the $notifications
  1403. */
  1404. public function getBidding_notif() {
  1405. return $this->bidding_notif;
  1406. }
  1407. public function getReview_notif() {
  1408. return $this->review_notif;
  1409. }
  1410. public function getSelf_notif() {
  1411. return $this->self_notif;
  1412. }
  1413. /**
  1414. * @param set notifications
  1415. */
  1416. public function setBidding_notif($bidding_notif) {
  1417. $this->bidding_notif = $bidding_notif;
  1418. return $this;
  1419. }
  1420. public function setReview_notif($review_notif) {
  1421. $this->review_notif = $review_notif;
  1422. return $this;
  1423. }
  1424. public function setSelf_notif($self_notif) {
  1425. $this->self_notif = $self_notif;
  1426. return $this;
  1427. }
  1428. /**
  1429. * Return a trimmed version of the nickname
  1430. */
  1431. public function getSubNickname($nickname, $length = 13) {
  1432. if (strlen($nickname) > $length) {
  1433. return substr($nickname, 0, $length) . '...';
  1434. } else {
  1435. return $nickname;
  1436. }
  1437. }
  1438. /**
  1439. * @return the $has_W2
  1440. */
  1441. public function getHas_W2() {
  1442. return $this->has_W2;
  1443. }
  1444. /**
  1445. * @param $has_W2 the $has_W2 to set
  1446. */
  1447. public function setHas_W2($has_W2) {
  1448. $this->has_W2 = $has_W2;
  1449. return $this;
  1450. }
  1451. public function isRunnerOfWorkitem($workitem) {
  1452. if (!is_object($workitem->getRunner())) {
  1453. return false;
  1454. }
  1455. if ($this->id == 0 || $this->id != $workitem->getRunner()->getId()) {
  1456. return false;
  1457. }
  1458. return true;
  1459. }
  1460. /* Updates the current calling user status, saves it to the database and sends a message to the journal
  1461. * @param status is the text status submitted to be udpated
  1462. */
  1463. public static function update_status($status = "") {
  1464. error_log('update_satus ' . $status);
  1465. if (isset($_SESSION['userid'])){
  1466. if ($status != "") {
  1467. $journal_message = '@' . $_SESSION['nickname'] . ' is *' . $status . '*';
  1468. // Insert new status to the database
  1469. $insert = "INSERT INTO " . USER_STATUS . "(id, status, timeplaced) VALUES(" . $_SESSION['userid'] . ", '" . mysql_real_escape_string($status) . "', NOW())";
  1470. if (!mysql_query($insert)) {
  1471. error_log("update_status.mysq: ".mysql_error());
  1472. }
  1473. //Send message to the Journal
  1474. $journal_message = sendJournalNotification($journal_message);
  1475. if ($journal_message != 'ok') {
  1476. error_log("failed to send notification ".$journal_message);
  1477. return;
  1478. }
  1479. }
  1480. }
  1481. return;
  1482. }
  1483. /*
  1484. * Return a list of all admin users
  1485. */
  1486. public function getAdminEMails() {
  1487. $adminEmails = array();
  1488. $sql = "SELECT username FROM users WHERE is_admin = 1";
  1489. if ($result = mysql_query($sql)) {
  1490. while ($row = mysql_fetch_assoc($result)) {
  1491. $adminEmails[] = $row['username'];
  1492. }
  1493. }
  1494. return $adminEmails;
  1495. }
  1496. public function isTwilioSupported($forced = false) {
  1497. if (!defined("TWILIO_SID") || !defined("TWILIO_TOKEN") || !Utils::validPhone($this->phone)) {
  1498. return false;
  1499. }
  1500. if ($forced) {
  1501. return true;
  1502. } else {
  1503. $sql =
  1504. ' SELECT COUNT(*) AS c ' .
  1505. ' FROM ' . COUNTRIES .
  1506. ' WHERE country_phone_prefix = ' . $this->int_code .
  1507. ' AND country_twilio_enabled = 1';
  1508. if (!$result = mysql_query($sql)) {
  1509. return null;
  1510. }
  1511. $row = mysql_fetch_assoc($result);
  1512. if ($row['c'] == 0) {
  1513. return false;
  1514. }
  1515. }
  1516. return substr($this->phone_verified, 0, 10) != '0000-00-00'
  1517. && substr($this->phone_rejected, 0, 10) == '0000-00-00';
  1518. }
  1519. public function getBudgetTransfersDetails(){
  1520. $sql = 'SELECT s.id, b.reason, s.transfer_date, b.receiver_id, u.nickname, s.amount_granted'
  1521. . ' FROM ' . BUDGET_SOURCE . ' AS `s` '
  1522. . ' INNER JOIN ' . BUDGETS .' AS `b` ON s.budget_id = b.id AND b.active = 1'
  1523. . ' INNER JOIN ' . USERS . ' AS `u` ON b.receiver_id = u.id'
  1524. . ' WHERE s.giver_id = ' . $this->getId();
  1525. if (!$result = mysql_query($sql)) {
  1526. return null;
  1527. }
  1528. $ret = array();
  1529. while($row = mysql_fetch_assoc($result)) {
  1530. $ret[] = $row;
  1531. }
  1532. return $ret;
  1533. }
  1534. /**
  1535. * returns user's github authorization token for GitHub application
  1536. * @param $github_id
  1537. * @return null|mixed
  1538. */
  1539. public function authTokenForGitHubId($github_id) {
  1540. if (isset($this->auth_tokens[$github_id])) {
  1541. return $this->auth_tokens[$github_id];

Large files files are truncated, but you can click here to view the full file