Guest User

Untitled

a guest
May 25th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. <?php
  2.  
  3. // *****************************************************************************
  4. // Capital IT Inc.
  5. // Copyright (C) 2008. All Rights Reserved
  6. //
  7. // $Source: /cvsroot/smn/app/modules/Default/models/UsersModel.class.php,v $
  8. // $Revision: 1.7 $
  9. // $Date: 2008/11/01 18:21:02 $
  10. // $Author: btiernay $
  11. //
  12. // *****************************************************************************
  13.  
  14. class Default_UsersModel extends SMNDefaultBaseModel {
  15. public function login($username, $password) {
  16. $pdo = $this->getPdo();
  17. $stmt = $pdo->prepare('SELECT c.*, u.* FROM CubeCart_customer c INNER JOIN SMN_user u ON u.customer_id = c.customer_id WHERE c.email = ? AND c.password = ? AND c.type > 0 LIMIT 1');
  18. $stmt->execute(array ($username, md5($password)));
  19. $user = $stmt->fetch(PDO::FETCH_ASSOC);
  20.  
  21. if ($user) {
  22. $this->updateLogin($user['customer_id']);
  23. $user['birth_date'] = $this->formatDate($user['birth_date']);
  24. $user['start_date'] = $this->formatDate($user['start_date']);
  25. }
  26. return $user;
  27. }
  28.  
  29. public function getUser($id) {
  30. $pdo = $this->getPdo();
  31. $stmt = $pdo->prepare('SELECT c.*, u.* FROM CubeCart_customer c INNER JOIN SMN_user u ON u.customer_id = c.customer_id WHERE u.id = ? LIMIT 1');
  32. $stmt->execute(array($id));
  33. $user = $stmt->fetch(PDO::FETCH_ASSOC);
  34. if ($user) {
  35. $this->updateLogin($user['customer_id']);
  36. $user['birth_date'] = $this->formatDate($user['birth_date']);
  37. $user['start_date'] = $this->formatDate($user['start_date']);
  38. }
  39. return $user;
  40. }
  41.  
  42. private function updateLogin($customer_id) {
  43. $pdo = $this->getPdo();
  44. $stmt = $pdo->prepare("UPDATE SMN_user SET last_login_date=:date WHERE customer_id=:customer_id");
  45. $stmt->bindValue(":date", time());
  46. $stmt->bindValue(":customer_id", $customer_id);
  47. return $stmt->execute();
  48. }
  49.  
  50. public function updateProfile($customer_id, $birth_date, $weight, $goal_weight, $height, $gender, $start_date) {
  51. $pdo = $this->getPdo();
  52. $stmt = $pdo->prepare("UPDATE SMN_user SET birth_date=:birth_date, weight=:weight, goal_weight=:goal_weight, height=:height, gender=:gender, start_date=:start_date WHERE customer_id=:customer_id");
  53. $stmt->bindValue(':customer_id', $customer_id);
  54. $stmt->bindValue(':birth_date', $this->parseDate($birth_date));
  55. $stmt->bindValue(':weight', $weight);
  56. $stmt->bindValue(':goal_weight', $goal_weight);
  57. $stmt->bindValue(':height', $height);
  58. $stmt->bindValue(':gender', $gender);
  59. $stmt->bindValue(':start_date', $this->parseDate($start_date));
  60. return $stmt->execute();
  61. }
  62.  
  63. public function updateCustomer($customer_id, $firstName, $lastName, $add_1, $add_2, $town, $county, $postcode, $email, $password) {
  64. $pdo = $this->getPdo();
  65. $stmt = $pdo->prepare("UPDATE CubeCart_customer SET firstName=:firstName, lastName=:lastName, add_1=:add_1, add_2=:add_2, town=:town, county=:county, postcode=:postcode, email=:email, password=:password WHERE customer_id=:customer_id");
  66. $stmt->bindValue(':customer_id', $customer_id);
  67. $stmt->bindValue(':firstName', $firstName);
  68. $stmt->bindValue(':lastName', $lastName);
  69. $stmt->bindValue(':add_1', $add_1);
  70. $stmt->bindValue(':add_2', $add_2);
  71. $stmt->bindValue(':town', $town);
  72. $stmt->bindValue(':county', $county);
  73. $stmt->bindValue(':postcode', $postcode);
  74. $stmt->bindValue(':email', $email);
  75. $stmt->bindValue(':password', md5($password));
  76. return $stmt->execute();
  77. }
  78.  
  79. public function updateStatus($customer_id, $status) {
  80. $pdo = $this->getPdo();
  81. $stmt = $pdo->prepare("UPDATE SMN_user SET status=:status WHERE customer_id=:customer_id");
  82. $stmt->bindValue(":status", $status);
  83. $stmt->bindValue(":customer_id", $customer_id);
  84. return $stmt->execute();
  85. }
  86.  
  87. public function updateWeight($customer_id, $weightName, $weightValue) {
  88. $pdo = $this->getPdo();
  89. $stmt = $pdo->prepare('UPDATE SMN_user SET '.$weightName.'=:value WHERE customer_id=:customer_id');
  90. $stmt->bindValue(":value", $weightValue);
  91. $stmt->bindValue(":customer_id", $customer_id);
  92. return $stmt->execute();
  93. }
  94.  
  95. private function formatDate($value) {
  96. if ($value === null) {
  97. return null;
  98. }
  99. return date('m/d/Y', strtotime($value));
  100. }
  101. private function parseDate($value) {
  102. if ($value === null) {
  103. return null;
  104. }
  105. return date('Y-m-d',strtotime($value));
  106. }
  107. }
  108.  
  109. ?>
Add Comment
Please, Sign In to add comment