Guest User

class.usr.php1

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