Guest User

class1

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