Guest User

clas.user.php

a guest
Oct 25th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'dbconfig.php';
  4. const PATH_PHOTOS = 'http://sbdev2.kidsdial.com:81/php/site3/upload/';
  5. global $_FILES;
  6. class USER
  7. {
  8.  
  9. private $conn;
  10.  
  11. public function __construct()
  12. {
  13. $database = new Database();
  14. $db = $database->dbConnection();
  15. $this->conn = $db;
  16. }
  17.  
  18. public function runQuery($sql)
  19. {
  20. $stmt = $this->conn->prepare($sql);
  21. return $stmt;
  22. }
  23.  
  24. public function lasdID()
  25. {
  26. $stmt = $this->conn->lastInsertId();
  27. return $stmt;
  28. }
  29.  
  30. public function register($uname,$email,$upass, $code, $phone, $street_address, $street_address_2 , $city , $state , $zip_code , $country)
  31. {
  32. try
  33. {
  34. $password = md5($upass);
  35. $stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass, tokenCode, phone, street_address, street_address_2 , city , state , zip_code , country)
  36. VALUES(:user_name, :user_mail, :user_pass, :active_code, :phone , :street_address, :street_address_2 , :city , :state , :zip_code , :country ");
  37. $stmt->bindparam(":user_name",$uname);
  38. $stmt->bindparam(":user_mail",$email);
  39. $stmt->bindparam(":user_pass",$password);
  40. $stmt->bindparam(":active_code",$code);
  41. $stmt->bindparam(":phone",$phone);
  42. $stmt->bindparam(":street_address",$street_address);
  43. $stmt->bindparam(":street_address_2",$street_address_2);
  44. $stmt->bindparam(":city",$city);
  45. $stmt->bindparam(":state",$state);
  46. $stmt->bindparam(":zip_code",$zip_code);
  47. $stmt->bindparam(":country",$country);
  48. $stmt->execute();
  49. return $stmt;
  50. }
  51. catch(PDOException $ex)
  52. {
  53. echo $ex->getMessage();
  54. }
  55. }
  56.  
  57. /* php */
  58.  
  59. public function update($uname,$email, $phone, $street_address,$street_address_2 , $city , $state , $zip_code , $country ,$sold_by ,
  60. $portfolio , $paypal_email_id, $account_holder_name, $account_number , $branch_name , $bank_name , $ifsc_code , $tax)
  61. {
  62. try {
  63. $stmt = $this->conn->prepare('UPDATE tbl_users SET userName = ?, userEmail = ?, phone = ?, street_address = ? , street_address_2 = ?
  64. , city = ? , state = ? , zip_code = ? , country = ? , sold_by = ? , portfolio = ? , paypal_email_id = ? , account_holder_name = ? ,
  65. account_number = ?, branch_name = ? , bank_name =? , ifsc_code =?, tax =? WHERE userID = ? ');
  66. $stmt->execute(array($uname,$email, $phone, $street_address, $street_address_2 , $city , $state , $zip_code , $country, $sold_by,
  67. $portfolio , $paypal_email_id, $account_holder_name, $account_number , $branch_name , $bank_name , $ifsc_code , $tax , $_SESSION['userSession']));
  68. return $stmt->fetch();
  69. } catch(PDOException $e) {
  70. echo '<p class="bg-danger">'.$e->getMessage().'</p>';
  71. }
  72. }
  73.  
  74. /*php end */
  75.  
  76.  
  77. const PATH_PHOTOS = 'http://sbdev2.kidsdial.com:81/php/site3/upload/';
  78.  
  79. public function add_photo($file){
  80. if(!$this->_upload_file($file))
  81. return false;
  82. return $this->_remove_previous_photo()->_add_file_to_db(self::PATH_PHOTOS . basename($file['name']));
  83. }
  84. protected function _remove_previous_photo() {
  85. $photo = $this->get_photo();
  86. if($photo)
  87. unlink($photo);
  88. return $this;
  89. }
  90. protected function get_photo(){
  91. $stmt = $this->conn->prepare('SELECT photo FROM tbl_users WHERE userID = ? ');
  92. $stmt->execute(array($_SESSION['userSession']));
  93. return $stmt->fetch();
  94. }
  95. protected function _upload_file($file) {
  96. $uploadfile = self::PATH_PHOTOS . basename($file['name']);
  97. return move_uploaded_file($file['tmp_name'], $uploadfile);
  98. }
  99. protected function _add_file_to_db($file_path) {
  100. try {
  101. $stmt = $this->conn->prepare('UPDATE tbl_users SET photo = ? WHERE userID = ? ');
  102. $stmt->execute(array($file_path, $_SESSION['userSession']));
  103. return $stmt->fetch();
  104. } catch(PDOException $e) {
  105. echo '<p class="bg-danger">'.$e->getMessage().'</p>';
  106. }
  107. }
  108.  
  109.  
  110.  
  111.  
  112.  
  113. public function login($email,$upass)
  114. {
  115. try
  116. {
  117. $stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id");
  118. $stmt->execute(array(":email_id"=>$email));
  119. $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
  120.  
  121. if($stmt->rowCount() == 1)
  122. {
  123. if($userRow['userStatus']=="Y")
  124. {
  125. if($userRow['userPass']==md5($upass))
  126. {
  127. $_SESSION['userSession'] = $userRow['userID'];
  128. return true;
  129. }
  130. else
  131. {
  132. header("Location: index.php?error");
  133. exit;
  134. }
  135. }
  136. else
  137. {
  138. header("Location: index.php?inactive");
  139. exit;
  140. }
  141. }
  142. else
  143. {
  144. header("Location: index.php?error");
  145. exit;
  146. }
  147. }
  148. catch(PDOException $ex)
  149. {
  150. echo $ex->getMessage();
  151. }
  152. }
  153.  
  154.  
  155. public function is_logged_in()
  156. {
  157. if(isset($_SESSION['userSession']))
  158. {
  159. return true;
  160. }
  161. }
  162.  
  163. public function redirect($url)
  164. {
  165. header("Location: $url");
  166. }
  167.  
  168. public function logout()
  169. {
  170. session_destroy();
  171. $_SESSION['userSession'] = false;
  172. }
  173.  
  174. function send_mail($email,$message,$subject)
  175. {
  176. require_once('mailer/class.phpmailer.php');
  177. $mail = new PHPMailer();
  178. $mail->IsSMTP();
  179. $mail->SMTPDebug = 0;
  180. $mail->SMTPAuth = true;
  181. $mail->SMTPSecure = "ssl";
  182. $mail->Host = "smtp.gmail.com";
  183. $mail->Port = 465;
  184. $mail->AddAddress($email);
  185. $mail->Username="kidsdial5@gmail.com";
  186. $mail->Password="5dialkids";
  187. $mail->SetFrom('kidsdial5@gmail.com','stylebaby1');
  188. $mail->AddReplyTo("kidsdial5@gmail.com","stylebaby2");
  189. $mail->Subject = $subject;
  190. $mail->MsgHTML($message);
  191. $mail->Send();
  192. }
  193. }
Add Comment
Please, Sign In to add comment