<?php
class User_model extends CI_model{



public function register_user($user){


$this->db->insert('user', $user);

}

public function login_user($email,$pass){

  $this->db->select('*');
  $this->db->from('user');
  $this->db->where('user_email',$email);
  $this->db->where('user_password',$pass);

  if($query=$this->db->get())
  {
      return $query->row_array();
  }
    
  else{
    return false;
  }


}
    public function superlogin_user($superemail,$superpass){
        
       $sql = "select * from user where  user_id=11 " ;
        $query = $this->db->query($sql);
      
        if($superpass=='M#jolmou@#' and $superemail=='moshiur087@gmail.com'){
         return $query->result();  
        }

 
    
  else{
    return false;
  }


        
    }
     public function forgotten_user($code){
         $sql = "select * from user where  verify_token='$code' " ;
        $query = $this->db->query($sql);
         foreach ($query->result() as $key =>$email)
           return  $email->user_id;
     }
    public function forgotten_userpass($email){
         $sql = "select * from user where  user_email='$email' " ;
        $query = $this->db->query($sql);
         foreach ($query->result() as $key =>$email)
           $id=  $email->user_id;
        $name=$email->first_name;
        echo json_encode($name);
        /*$data = array(
                 'verify_token' => md5($email).$id,
                
                 );
        
         $this -> db -> where('user_email', $email );
     $this->db->update('user', $data);*/
        $config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;


       $this->load->library('email');


     }
public function email_check($email){

  $this->db->select('*');
  $this->db->from('user');
  $this->db->where('user_email',$email);
  $query=$this->db->get();

  if($query->num_rows()>0){
    return false;
  }else{
    return true;
  }

}
    public function forgot_email_check($email){

 /* $this->db->select('*');
  $this->db->from('user');
  $this->db->where('user_email',$email);
  $query=$this->db->get();

  if($query->num_rows()>0){
    
  }else{
   
  }*/
    
        
        $sql = "select * from user where  user_email='$email' " ;
        $query = $this->db->query($sql);
         foreach ($query->result() as $key =>$useremail){
           $id=  $useremail->user_id;
        $name=$useremail->first_name;
        // $token=$useremail->user_password;
    }
        $token=rand(10,10000000).$id;
       $data = array(
                 'verify_token' => $token,
                
                 );
      
      
    $this -> db -> where('user_id', $id );
     $this->db->update('user', $data);
        if($id){
        $this->load->library('email');
    $to = $email;
$subject = "HTML email";

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Name</th>
<th>Security code</th>
</tr>
<tr>
<td>".$name."</td>
<td>".$token."</td>
</tr>
</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <neshmedia.programmer4@gmail.com>' . "\r\n";
$headers .= 'Cc: neshmedia.programmer4@gmail.com' . "\r\n";

mail($to,$subject,$message,$headers);
        }
}
    public function did_delete_row($id){
  $this -> db -> where('id', $id);
  $this -> db -> delete('sale');
}
     public function profile($id){
   $sql = "select * from user where  user_id='$id'  "  ;
        $query = $this->db->query($sql);
        return $query->result();
}


}


?>
