<?php
include '../include/connection.php';
class User{
public $db;

/*** for registration process ***/
public function reg_user($name,$username,$password,$email){
$conn     = db();
$password = md5($password);
$sql="SELECT * FROM users WHERE uname='$username' OR uemail='$email'";
//checking if the username or email is available in db
$check     = $conn->query($sql);
$count_row = $check->num_rows;
//if the username is not in db then insert to the table
if ($count_row == 0){
$sql="INSERT INTO users SET uname='$username', upass='$password', fullname='$name', uemail='$email'";
$result = $conn->query($sql);
return $result;
}
else {
return false;
}
}
/*** for login process ***/
public function check_login($emailusername, $password){
$conn = db();
$password = md5($password);
$sql="SELECT uid from tbl_admin WHERE (username='$emailusername' or email='$emailusername') and apassword='$password'";
//checking if the username is available in the table
$result    = $conn->query($sql);
$user_data = $result->fetch_assoc();
$count_row = $result->num_rows;
if ($count_row == 1) {
// this login variable will use for the session thing
$_SESSION['login'] = true;
$_SESSION['uid']=$user_data['uid'];
return true;
}
else{
return false;
}
}
/*** for showing the web config ***/
public function get_webinfo(){
$qry="SELECT * FROM tbl_website_management WHERE website_id = '1'";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for showing the last login ***/
public function get_lastlogin(){
$qry="SELECT * FROM tbl_admin where 1 order by last_login_date_time desc limit 1";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}

/*** for showing the Member/admin info ***/
public function get_memberinfo($uid)
{
$conn      = db();
$sql       = "SELECT * FROM tbl_admin WHERE uid = $uid";
$seldta    = $conn->query($sql);
return $seldta;
}
/*** starting the session ***/
public function get_session()
{
return $_SESSION['login'];
}
public function user_logout()
{
$_SESSION['login'] = FALSE;
session_destroy();
}
/*** for showing the Newsletter ***/
public function get_Newsletterinfo(){
$qry="SELECT * FROM tbl_newsletter WHERE 1";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for showing the User Inquiry ***/
public function get_userinquiry(){
$qry="SELECT * FROM tbl_inquiry WHERE 1 order by inquiry_id desc";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for showing the Update Page ***/
public function FetchPageEdit($table,$id){
$qry="SELECT * FROM $table WHERE pg_id='$id'";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for showing the Pages ***/
public function FetchPage(){
$qry="SELECT * FROM tbl_page WHERE 1";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}

/*** for showing the location ***/

public function Fetchlocation(){
$qry="SELECT * FROM tbl_location";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/***for showing the Update location ***/
public function FetchlocationEdit($table,$id){
$qry="SELECT * FROM $table WHERE location_id='$id'";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for showing the Update Banner ***/
public function FetchBannerEdit($id){
$qry="SELECT * FROM tbl_banner WHERE banner_id='$id'";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for showing the Banners ***/
public function FetchBanner(){
$qry="SELECT * FROM tbl_banner WHERE 1";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for showing the Update Gallery ***/
public function FetchGalleryEdit($id){
$qry="SELECT * FROM tbl_gallery WHERE gallery_id='$id'";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for showing the Gallery ***/
public function FetchGallery(){
$qry="SELECT * FROM tbl_gallery WHERE 1";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for showing the Update Category ***/
public function FetchCategoryEdit($id){
$qry="SELECT * FROM tbl_product_category WHERE product_cat_id='$id'";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for showing the Category ***/
public function FetchCategory($parentid){
$qry="SELECT * FROM tbl_product_category WHERE parent_id='$parentid'";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for showing the Update Category ***/
public function FetchProductEdit($id){
$qry="SELECT * FROM tbl_product WHERE product_cat='$id'";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for showing the Update Member ***/
public function FetchMemberEdit($id){
$qry="SELECT * FROM tbl_member WHERE member_id='$id'";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for showing the Member ***/
public function FetchMember(){
$qry="SELECT * FROM tbl_member";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for showing Inquiry ***/
public function FetchInquiry(){
$qry="SELECT * FROM tbl_inquiry order by inquiry_id desc";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for showing Blog Category ***/
public function FetchBlogCategory(){
$qry="SELECT * FROM tbl_blog_category";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}

/*** for showing the Update Blog Category ***/
public function FetchBlogCategoryEdit($id){
$qry="SELECT * FROM tbl_blog_category WHERE blog_cat_id='$id'";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}

/*** for showing Blog ***/
public function FetchBlog(){
$qry="SELECT * FROM tbl_blog";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}

/*** for showing the Update Blog ***/
public function FetchBlogEdit($id){
$qry="SELECT * FROM tbl_blog WHERE blog_id='$id'";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for showing Sub Doamin Content ***/
public function FetchDomainContaint(){
$qry="SELECT * FROM subcontent_tbl";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for Update Testimonial ***/
public function FetchDomainContaintEdit($id){
$qry="SELECT * FROM subcontent_tbl WHERE subcontent_id='$id'";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}

/*** for showing Testimonial ***/
public function FetchTestimonial(){
$qry="SELECT * FROM tbl_testimonial";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for Update Testimonial ***/
public function FetchTestimonialEdit($id){
$qry="SELECT * FROM tbl_testimonial WHERE testimonial_id='$id'";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}

/*** for showing Faq ***/
public function FetchFaq(){
$qry="SELECT * FROM tbl_faq";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for Update Faq ***/
public function FetchFaqEdit($id){
$qry="SELECT * FROM tbl_faq WHERE faq_id='$id'";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}

/*** for Update Contact ***/
public function FetchContact($contactid){
$qry="SELECT * FROM tbl_contact WHERE contact_id='$contactid'";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for Change Password ***/
public function FetchChangepass($id){
$qry="SELECT * FROM tbl_admin WHERE uid='$id'";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for Update Profile ***/
public function FetchAdminProfile($id){
$qry="SELECT * FROM tbl_admin WHERE uid='$id'";
$conn      = db();
$recordObj = $conn->query($qry);
return $recordObj;
//$this->db->close();
$conn->close();
}
/*** for Forgot Password ***/
public function Forgetpass($emailid){
$qry="SELECT * FROM tbl_admin WHERE email='$emailid'";
$conn      = db();
$result = $conn->query($qry);
$fpuser_data = $result->fetch_object();
echo $count_row = $result->num_rows;
$pname=$fpuser_data->name;
$pass=$fpuser_data->password;
if ($count_row == 1)
{


$email_subject ="Your Password at brandbugleindia.com";
$email_to1="iandu445@gmail.com";
$email_to=$useremailid;
$email_from = "info@brandbugleindia.com";
$headers = 'From: '.$email_from."\r\n";
$headers .= "X-Mailer: PHP/". phpversion();
$headers .= "X-Priority: 3 \n";
$headers .= "MIME-version: 1.0\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
$message = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
  <head>
    <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
    <title>".$website_title."</title>
  </head>
  <body>
    <br />
    <u></u>
    <div bgcolor='#ffffff' style='width:100%'>
      <table cellpadding='0' cellspacing='0' width='100%' style='border-left: 1px solid #ccc; border-top:1px solid #ccc; border-right: 1px solid #ccc; max-width: 600px;'>
        <tbody>
          <tr>
            <td bgcolor='#f5f4f3' width='10'>&nbsp;</td>
            <td align='left' bgcolor='#f5f4f3' height='50' valign='middle'><a href='".$website_url."' target='_blank'> <img  style='margin-top:10px' src='".$website_url."/upload/".$website_logo."' alt='".$website_title."' title='".$website_title."' border='0' height='50' /> </a> </td>
            <td align='right' bgcolor='#efe7fd' height='50' valign='middle'><a href='".$website_url."' target='_blank'>  </a> </td>
            <td bgcolor='#f5f4f3' width='10'>&nbsp;</td>
          </tr>
        </tbody>
      </table>
      <table cellpadding='0' cellspacing='0' width='100%' style='max-width:600px;border-left: 1px solid #ab12a2; border-top:1px solid #ab12a2; border-right: 1px solid #ab12a2; font-size: 11px;
        color: #99BACF;
        line-height: 14px;'>
      </table>
      <table cellpadding='0' cellspacing='0' width='100%' style=' font-family:Arial, Helvetica, sans-serif; max-width:600px;border-left-style:solid;border-left-width:1px;border-left-color:rgb(230,230,230);border-right-style:solid;border-right-width:1px;border-right-color:rgb(230,230,230)'>
        <tbody>
          <tr>
            <td align='left' bgcolor='#F9F9F9'  style='color:rgb(44,44,44);display:block;line-height:20px;font-weight:300;margin:0px auto;clear:both;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(230,230,230);padding:20px;background-color:rgb(249,249,249)' valign='top'><p style='padding:0px;margin:0px;font-weight:bold;font-size:13px'>Dear $pname, </p>
            <br />
            <p style='padding:0px;margin:0px;font-weight:bold;font-size:13px'>Please note your password at ".$website_domain."</p>
            <p style='padding:0px;margin:0px;font-weight:bold;font-size:13px'>Password : $pass</p>
            <br />
          </td>
        </tr>
      </tbody>
    </table>
    <table cellpadding='0' cellspacing='0' width='100%' style='max-width:600px;border-left-style:solid;border-left-width:1px;border-left-color:rgb(230,230,230);border-right-style:solid;border-right-width:1px;border-right-color:rgb(230,230,230)'>
      
    </table>
    <table cellpadding='0' cellspacing='0' width='100%' style='max-width:600px;border-left-style:solid;border-left-width:1px;border-left-color:rgb(230,230,230);border-right-style:solid;border-right-width:1px;border-right-color:rgb(230,230,230)'>
      <tbody>
        <tr>
          <td colspan='2' align='center' valign='top' width='300' style='background-color:rgb(249,249,249)'><br />
            <table cellpadding='0' cellspacing='0' width='100%'>
              <tbody>
                <tr>
                  <td align='left' valign='top' style='padding:0px 10px 15px 20px;margin:0px'><p style='padding:0px;margin:0px 0px 7px;font-size:16px;color:rgb(86,86,86); font-family:Arial, Helvetica, sans-serif;'>Any Questions?</p>
                  <p style='padding:0px;margin:0px;font-size:11px;color:rgb(86,86,86);line-height:20px; font-family:Arial, Helvetica, sans-serif;'> Get in touch with our 24x7 <a href='#' target='_blank'><span style='color:rgb(102,102,102);font-size:11px'>Customer Care</span></a> team. </p></td>
                </tr>
              </tbody>
            </table></td>
          </tr>
        </tbody>
      </table>
      <table cellpadding='0' cellspacing='0' width='100%' style='max-width:600px;border-style:none solid solid;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-right-color:rgb(230,230,230);border-bottom-color:rgb(230,230,230);border-left-color:rgb(230,230,230)'>
        <tbody>
          <tr>
            <td align='center' bgcolor='#F9F9F9' valign='top' style='text-align: center; display: block; margin: 0px auto; clear: both; background-color: rgb(249, 249, 249); padding: 15px 40px;'><p style='padding:0px;margin:0px 0px 7px'> <a title='' href='".$website_url."' target='_blank' style='text-decoration:none;color:rgb(86,86,86)'><span style='color:rgb(86,86,86);font-size:13px; font-family:Arial, Helvetica, sans-serif;'>".$website_domain."</span></a> </p>
            <p style='padding:10px 0px 0px;margin:0px;border-top-style:solid;border-top-width:1px;border-top-color:rgb(204,204,204);font-size:11px;color:rgb(86,86,86);font-family:Arial, Helvetica, sans-serif; '> 24x7 Customer Support&nbsp; | &nbsp;Buyer Protection&nbsp; | &nbsp;Flexible Payment Options&nbsp; | &nbsp;Largest Collection </p></td>
          </tr>
        </tbody>
      </table>
    </div>
  </body>
</html>";
//@mail($email_to, $email_subject, $message, $headers);
@mail($email_to1, $email_subject, $message, $headers);
return TRUE;
}
else
{
return FALSE;
}
//$this->db->close();
$conn->close();
}

}
?>