Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'dbconfig.php';
- const PATH_PHOTOS = 'http://sbdev2.kidsdial.com:81/php/site3/upload/';
- global $_FILES;
- class USER
- {
- private $conn;
- public function __construct()
- {
- $database = new Database();
- $db = $database->dbConnection();
- $this->conn = $db;
- }
- public function runQuery($sql)
- {
- $stmt = $this->conn->prepare($sql);
- return $stmt;
- }
- public function lasdID()
- {
- $stmt = $this->conn->lastInsertId();
- return $stmt;
- }
- public function register($uname,$email,$upass, $code, $phone, $street_address, $street_address_2 , $city , $state , $zip_code , $country)
- {
- try
- {
- $password = md5($upass);
- $stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass, tokenCode, phone, street_address, street_address_2 , city , state , zip_code , country)
- VALUES(:user_name, :user_mail, :user_pass, :active_code, :phone , :street_address, :street_address_2 , :city , :state , :zip_code , :country ");
- $stmt->bindparam(":user_name",$uname);
- $stmt->bindparam(":user_mail",$email);
- $stmt->bindparam(":user_pass",$password);
- $stmt->bindparam(":active_code",$code);
- $stmt->bindparam(":phone",$phone);
- $stmt->bindparam(":street_address",$street_address);
- $stmt->bindparam(":street_address_2",$street_address_2);
- $stmt->bindparam(":city",$city);
- $stmt->bindparam(":state",$state);
- $stmt->bindparam(":zip_code",$zip_code);
- $stmt->bindparam(":country",$country);
- $stmt->execute();
- return $stmt;
- }
- catch(PDOException $ex)
- {
- echo $ex->getMessage();
- }
- }
- /* php */
- public function update($uname,$email, $phone, $street_address,$street_address_2 , $city , $state , $zip_code , $country ,$sold_by ,
- $portfolio , $paypal_email_id, $account_holder_name, $account_number , $branch_name , $bank_name , $ifsc_code , $tax)
- {
- try {
- $stmt = $this->conn->prepare('UPDATE tbl_users SET userName = ?, userEmail = ?, phone = ?, street_address = ? , street_address_2 = ?
- , city = ? , state = ? , zip_code = ? , country = ? , sold_by = ? , portfolio = ? , paypal_email_id = ? , account_holder_name = ? ,
- account_number = ?, branch_name = ? , bank_name =? , ifsc_code =?, tax =? WHERE userID = ? ');
- $stmt->execute(array($uname,$email, $phone, $street_address, $street_address_2 , $city , $state , $zip_code , $country, $sold_by,
- $portfolio , $paypal_email_id, $account_holder_name, $account_number , $branch_name , $bank_name , $ifsc_code , $tax , $_SESSION['userSession']));
- return $stmt->fetch();
- } catch(PDOException $e) {
- echo '<p class="bg-danger">'.$e->getMessage().'</p>';
- }
- }
- /*php end */
- const PATH_PHOTOS = 'http://sbdev2.kidsdial.com:81/php/site3/upload/';
- public function add_photo($file){
- if(!$this->_upload_file($file))
- return false;
- return $this->_remove_previous_photo()->_add_file_to_db(self::PATH_PHOTOS . basename($file['name']));
- }
- protected function _remove_previous_photo() {
- $photo = $this->get_photo();
- if($photo)
- unlink($photo);
- return $this;
- }
- protected function get_photo(){
- $stmt = $this->conn->prepare('SELECT photo FROM tbl_users WHERE userID = ? ');
- $stmt->execute(array($_SESSION['userSession']));
- return $stmt->fetch();
- }
- protected function _upload_file($file) {
- $uploadfile = self::PATH_PHOTOS . basename($file['name']);
- return move_uploaded_file($file['tmp_name'], $uploadfile);
- }
- protected function _add_file_to_db($file_path) {
- try {
- $stmt = $this->conn->prepare('UPDATE tbl_users SET photo = ? WHERE userID = ? ');
- $stmt->execute(array($file_path, $_SESSION['userSession']));
- return $stmt->fetch();
- } catch(PDOException $e) {
- echo '<p class="bg-danger">'.$e->getMessage().'</p>';
- }
- }
- public function login($email,$upass)
- {
- try
- {
- $stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id");
- $stmt->execute(array(":email_id"=>$email));
- $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
- if($stmt->rowCount() == 1)
- {
- if($userRow['userStatus']=="Y")
- {
- if($userRow['userPass']==md5($upass))
- {
- $_SESSION['userSession'] = $userRow['userID'];
- return true;
- }
- else
- {
- header("Location: index.php?error");
- exit;
- }
- }
- else
- {
- header("Location: index.php?inactive");
- exit;
- }
- }
- else
- {
- header("Location: index.php?error");
- exit;
- }
- }
- catch(PDOException $ex)
- {
- echo $ex->getMessage();
- }
- }
- public function is_logged_in()
- {
- if(isset($_SESSION['userSession']))
- {
- return true;
- }
- }
- public function redirect($url)
- {
- header("Location: $url");
- }
- public function logout()
- {
- session_destroy();
- $_SESSION['userSession'] = false;
- }
- function send_mail($email,$message,$subject)
- {
- require_once('mailer/class.phpmailer.php');
- $mail = new PHPMailer();
- $mail->IsSMTP();
- $mail->SMTPDebug = 0;
- $mail->SMTPAuth = true;
- $mail->SMTPSecure = "ssl";
- $mail->Host = "smtp.gmail.com";
- $mail->Port = 465;
- $mail->AddAddress($email);
- $mail->Username="kidsdial5@gmail.com";
- $mail->Password="5dialkids";
- $mail->SetFrom('kidsdial5@gmail.com','stylebaby1');
- $mail->AddReplyTo("kidsdial5@gmail.com","stylebaby2");
- $mail->Subject = $subject;
- $mail->MsgHTML($message);
- $mail->Send();
- }
- }
Add Comment
Please, Sign In to add comment