Guest User

c1

a guest
Oct 25th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.58 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. /*php end.... */
  79.  
  80.  
  81.  
  82. //$dbConn = new Database();
  83. //$dbConn->dbConnection();
  84.  
  85. //$user_home = new USER();
  86.  
  87. public function uploadUserPhoto($uid) {
  88. global $dbConn;
  89. if(isset($_FILES["photo"]["error"])) {
  90. if($_FILES["photo"]["error"] > 0) {
  91. echo "Error: " . $_FILES["photo"]["error"] . "<br>";
  92.  
  93. } else {
  94. $allowed = array("jpg" => "image/jpg", "jpeg" => "image/jpeg", "gif" => "image/gif", "png" => "image/png");
  95. $filename = $_FILES["photo"]["name"];
  96. $filetype = $_FILES["photo"]["type"];
  97. $filesize = $_FILES["photo"]["size"];
  98.  
  99. $userDir = $uid;
  100.  
  101. // Verify file extension
  102. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  103. if(!array_key_exists($ext, $allowed)) die("Error: Please select a valid file format.");
  104.  
  105. // Verify file size - 5MB maximum
  106. $maxsize = 5 * 1024 * 1024;
  107. if($filesize > $maxsize) die("Error: File size is larger than the allowed limit.");
  108.  
  109. // Verify MYME type of the file
  110. if(in_array($filetype, $allowed)) {
  111. if(!is_dir('upload/'.$uid)) {
  112. mkdir('upload/'.$uid);
  113. }
  114.  
  115. $photoname = time().$uid.'_photo'.'.'.$ext;
  116.  
  117. // delete all the files in this directory
  118. $files = glob('upload/'.$uid.'/*'); // get all file names
  119. foreach($files as $file){ // iterate files
  120. if(is_file($file))
  121. unlink($file); // delete file
  122. }
  123.  
  124. // Upload the photo
  125. move_uploaded_file($_FILES["photo"]["tmp_name"], "upload/" . $uid . '/'. $photoname);
  126.  
  127. $updateData = array(':userID' => $uid, ':photo' => $photoname);
  128. $stmt = $dbConn->conn->prepare("UPDATE tbl_users SET photo=:photo WHERE userID=:uid");
  129. $stmt->execute($updateData);
  130.  
  131. echo "Your file was uploaded successfully.";
  132. } else {
  133. echo "Error: There was a problem uploading your file - please try again.";
  134. }
  135. }
  136. } else {
  137. echo "";
  138. }
  139. }
  140.  
  141.  
  142.  
  143. public function login($email,$upass)
  144. {
  145. try
  146. {
  147. $stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id");
  148. $stmt->execute(array(":email_id"=>$email));
  149. $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
  150.  
  151. if($stmt->rowCount() == 1)
  152. {
  153. if($userRow['userStatus']=="Y")
  154. {
  155. if($userRow['userPass']==md5($upass))
  156. {
  157. $_SESSION['userSession'] = $userRow['userID'];
  158. return true;
  159. }
  160. else
  161. {
  162. header("Location: index.php?error");
  163. exit;
  164. }
  165. }
  166. else
  167. {
  168. header("Location: index.php?inactive");
  169. exit;
  170. }
  171. }
  172. else
  173. {
  174. header("Location: index.php?error");
  175. exit;
  176. }
  177. }
  178. catch(PDOException $ex)
  179. {
  180. echo $ex->getMessage();
  181. }
  182. }
  183.  
  184.  
  185. public function is_logged_in()
  186. {
  187. if(isset($_SESSION['userSession']))
  188. {
  189. return true;
  190. }
  191. }
  192.  
  193. public function redirect($url)
  194. {
  195. header("Location: $url");
  196. }
  197.  
  198. public function logout()
  199. {
  200. session_destroy();
  201. $_SESSION['userSession'] = false;
  202. }
  203.  
  204. function send_mail($email,$message,$subject)
  205. {
  206. require_once('mailer/class.phpmailer.php');
  207. $mail = new PHPMailer();
  208. $mail->IsSMTP();
  209. $mail->SMTPDebug = 0;
  210. $mail->SMTPAuth = true;
  211. $mail->SMTPSecure = "ssl";
  212. $mail->Host = "smtp.gmail.com";
  213. $mail->Port = 465;
  214. $mail->AddAddress($email);
  215. $mail->Username="kidsdial5@gmail.com";
  216. $mail->Password="5dialkids";
  217. $mail->SetFrom('kidsdial5@gmail.com','stylebaby1');
  218. $mail->AddReplyTo("kidsdial5@gmail.com","stylebaby2");
  219. $mail->Subject = $subject;
  220. $mail->MsgHTML($message);
  221. $mail->Send();
  222. }
  223. }
Add Comment
Please, Sign In to add comment