Skip to main content

CONTROLLER

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Webservice extends CI_Controller {
     
    public function __construct($config = 'rest')
    {
        header('Access-Control-Allow-Origin: *');
        header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
        parent::__construct();
        
        //SMTP & mail configuration
        $config = array(
                'protocol'  => 'smtp',
                'smtp_host' => 'smtp.postmarkapp.com',
                'smtp_port' =>  2525,
                'smtp_user' => 'ad624d9f-9999-4a6c-85b8-43f105729686',
                'smtp_pass' => 'ad624d9f-9999-4a6c-85b8-43f105729686',
                'mailtype'  => 'html',
                'charset'   => 'utf-8'
        );
        $this->email->initialize($config);
        $this->email->set_mailtype("html");
        $this->email->set_newline("\r\n");
        $this->email->from('no-reply@knoxweb.com', 'knoxweb');
    }
    
    public function index()
    {
        echo "Welcome To On Demand Home Services Webservice";
    }
    
    /* %%%%%%%%%%%%%%% Customer %%%%%%%%%%%%%% */
    /* %%%%%%%%%%%%%%% User App signup %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
    
    public function signup()
    {
        $username        = (trim($this->input->get('username')));
        $firstname       = (trim($this->input->get('firstname')));
        $lastname        = (trim($this->input->get('lastname')));
        $email           = (trim($this->input->get('email')));
        $mobile          = (trim($this->input->get('mobile')));
        $password        = md5($this->input->get('password'));
        $scheme          = (trim($this->input->get('scheme')));
        $image           = (trim($this->input->get('image')));
        $address         = (trim($this->input->get('address')));
        $apt             = (trim($this->input->get('apt')));
        $city            = (trim($this->input->get('city')));
        $state           = (trim($this->input->get('state')));
        $zip             = (trim($this->input->get('zip')));
        $billingaddresss = (trim($this->input->get('billingaddresss')));
        $billingapt      = (trim($this->input->get('billingapt')));
        $billingcity     = (trim($this->input->get('billingcity')));
        $billingstate    = (trim($this->input->get('billingstate')));
        $billingzip      = (trim($this->input->get('billingzip')));
        $cardname        = (trim($this->input->get('cardname')));
        $role            = 'user';
        
        $insertdata = array(
            'username' => $username,
            'firstname' => $firstname,
            'lastname' => $lastname,
            'email' => $email,
            'mobile' => $mobile,
            'password' => $password,
            'scheme' => $scheme,
            'image' => $image,
            'address' => $address,
            'apt' => $apt,
            'city' => $city,
            'state' => $state,
            'zip' => $zip,
            'billingaddresss' => $billingaddresss,
            'billingapt' => $billingapt,
            'billingcity' => $billingcity,
            'billingstate' => $billingstate,
            'billingzip' => $billingzip,
            'cardname' => $cardname,
            'role' => $role,                
            'date' => date('Y-m-d h:i:s')
        );
        
        $where_contact = array(
            'email' => $email,
            'username' => $username
        );
        $user_contact  = ($this->user_model->get_joins('user', '', '', '', '', '', '', '', '', $where_contact));
        if (!empty($user_contact)) {
            echo "false";
        } else {
            $is_insert = $this->user_model->INSERTDATA('user', $insertdata);
            if ($is_insert) {
                echo "true";
            } else {
                echo "false";
            }
        }
    }
    
    /* %%%%%%%%%%%%%%%%%%%%%%%%%% User App login %%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
    public function signin()
    {
        $username = ($this->input->get('username'));
        $password = md5($this->input->get('password'));
        
        $where   = array(
            'username' => $username,
            'password' => $password,
            'role' => 'user'
        );
        $coloumn = array(
            'user.*',
            'userscheme.is_active as planstatus',
            ' `userscheme`.`schemeid` as `schemeid`'
        );
        $join    = array(
            array(
                'table' => 'userscheme',
                'condition' => 'userscheme.userid=user.id',
                'jointype' => 'LEFT'
            )
        );
        
        $user_info = $this->user_model->get_joins('user', $where, $join, $coloumn);
        
        if ($user_info) {
            print_r(json_encode($user_info));
        } else {
            echo "false";
        }
    }
    
    /* %%%%%%%%%% On Demand App forgot password %%%%%%%%%%%%%% */
    
    public function forgetoldpassword()
    {
        $email  = trim($this->input->get('email'));
        $where  = array(
            'email' => $email
        );
        $forget = $this->user_model->get_joins('user', $where);
        if ($forget) {
            $id       = ($forget[0]['id']);
            $username = $forget[0]['username'];
            $email    = $forget[0]['email'];
            $data[]   = array(
                'id' => $id,
                'username' => $username,
                'email' => $email
            );
            print_r(json_encode($data));
        } else {
            echo "false";
        }
    }
    
    /* %%%%%%%%%%%%%%%%%%%%%%%% Forgot Password Send Email %%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
    public function forgetSendEmail()
    {
        $id       = $this->input->get('id');
        $username = ucwords($this->input->get('username'));
        $email    = $this->input->get('email');
        $links    = 'http://ondemandhome.betaplanets.com/Webservice/setNewPassword/' . base64_encode($id) . '/' . base64_encode($username);
        $link     = str_replace("=", " ", $links);
        
        //Email content
        $htmlContent = '<table>
                        <tr>
                            <td> <img width="50px" src="' . base_url('assets/app-icon.png') . '"></td>
                        </tr>
                        <tr>
                        <td><b>Hello ' . $username . ',</b></td>
                        </tr>
                        <tr>
                        <td>We received a request to reset your password. Click the link below to choose a new one:</td>
                        </tr>
                        <tr>
                            <td><a href="' . $link . '">Reset your password</a></td>
                        </tr>                    
                        <tr>
                        <td style="height:80px"> </td>
                        </tr>                    
                        <tr>
                            <td>Thank You</td>
                        </tr>                    
                    </table>';
        $this->email->to($email, $username);
        $this->email->subject('Request For Forgot Password');
        $this->email->message($htmlContent);
        $this->email->send();
    }
    
    
    
    /* %%%%%%%%%%%%%% On Demand App set New Password %%%%%%%%%%%%%%%%%%%% */
    
    public function setNewPassword()
    {
        
        if (isset($_POST['change'])) {
            $password    = md5(trim($this->input->post('password')));
            $userbasedid = $this->uri->segment(3);
            $isusername  = $this->uri->segment(4);
            
            $id       = base64_decode($userbasedid);
            $username = base64_decode($isusername);
            
            $condition = array(
                'id' => $id,
                'username' => $username
            );
            
            $updatedata = array(
                'password' => $password
            );
            
            $is_update = $this->query_model->UPDATEDATA('user', $condition, $updatedata);
            if ($is_update) {
                $this->session->set_flashdata('message', 'Thank You. Password change successfully.');
            } else {
                $this->session->set_flashdata('message', 'Please try again.');
            }
        }
        $this->load->view('forgotPassword');
    }    
    
    
    
    /* %%%%%%%%%%%%%%%%%%%% User Update %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
    public function updateUserData()
    {
        
        $id              = (trim($this->input->get('id')));
        $firstname       = (trim($this->input->get('firstname')));
        $lastname        = (trim($this->input->get('lastname')));
        $email           = (trim($this->input->get('email')));
        $mobile          = (trim($this->input->get('mobile')));
        $address         = (trim($this->input->get('address')));
        $apt             = (trim($this->input->get('apt')));
        $city            = (trim($this->input->get('city')));
        $state           = (trim($this->input->get('state')));
        $zip             = (trim($this->input->get('zip')));
        $billingaddresss = (trim($this->input->get('billingaddresss')));
        $billingapt      = (trim($this->input->get('billingapt')));
        $billingcity     = (trim($this->input->get('billingcity')));
        $billingstate    = (trim($this->input->get('billingstate')));
        $billingzip      = (trim($this->input->get('billingzip')));
        $role            = 'user';
        
        $updatedata = array(
            'firstname' => $firstname,
            'lastname' => $lastname,
            'email' => $email,
            'mobile' => $mobile,
            'address' => $address,
            'apt' => $apt,
            'city' => $city,
            'state' => $state,
            'zip' => $zip,
            'billingaddresss' => $billingaddresss,
            'billingapt' => $billingapt,
            'billingcity' => $billingcity,
            'billingstate' => $billingstate,
            'billingzip' => $billingzip,
            'role' => $role,
            'date' => date('Y-m-d h:i:s')
        );
        
        $where = array(
            'id' => $id
        );
        
        $update = $this->user_model->UPDATEDATA('user', $where, $updatedata);
        if ($update) {
            echo "true";
        } else {
            echo "false";
        }
    }
    
    /* %%%%%%%%%%%%%%%%%%%% User card info update %%%%%%%%%%%%%%%%%%%%%%%%%%% */
    public function updatecardinfo()
    {
        
        $userid       = (trim($this->input->get('userid')));
        $cardname     = (trim($this->input->get('cardname')));
        $cardtype     = (trim($this->input->get('cardtype')));
        $cardnumber   = (trim($this->input->get('cardnumber')));
        $cvc          = (trim($this->input->get('cvc')));
        $cardexpmonth = (trim($this->input->get('cardexpmonth')));
        $cardexpyear  = (trim($this->input->get('cardexpyear')));
        
        $updatedata = array(
            'cardname' => $cardname,
            'cardtype' => $cardtype,
            'cardnumber' => $cardnumber,
            'cvc' => $cvc,
            'cardexpmonth' => $cardexpmonth,
            'cardexpyear' => $cardexpyear,
            'date' => date('Y-m-d h:i:s')
        );
        
        $where = array(
            'id' => $userid
        );
        
        $update = $this->user_model->UPDATEDATA('user', $where, $updatedata);
        if ($update) {
            echo "true";
        } else {
            echo "false";
        }
    }
  
    
    /* %%%%%%%%%%%%%%%%%%%% User Update SCHEME %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
    public function updatescheme()
    {
        
        $userid = (trim($this->input->get('userid')));
        $scheme = (trim($this->input->get('scheme')));
        
        $updatedata = array(
            'scheme' => $scheme,
            'date' => date('Y-m-d h:i:s')
        );
        
        $where = array(
            'id' => $userid
        );
        
        $update = $this->user_model->UPDATEDATA('user', $where, $updatedata);
        if ($update) {
            echo "true";
        } else {
            echo "false";
        }
    }
    
/* %%%%%%%%%%%%%%%%%%%% User ADD SCHEME %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
public function schemebooking()
{
    $userid     = (trim($this->input->get('userid')));
    $schemeid   = (trim($this->input->get('schemeid')));
    $schemeplan = (trim($this->input->get('schemeplan')));
    
    /*
        Check if user already exists
    */
    $user = array(
                    'id'=>$userid
               );
               
    $checkuser = $this->user_model->get_joins('userscheme',$user);

    if($checkuser){

        $schemeuserid = $checkuser[0]['id'];
         // set start and end date        
        $today = date('Y-m-d h:i:s');
        
        if ($schemeplan == "monthly") {
            $adding_one_month = date('Y-m-d h:i:s', strtotime($today . "1 month"));
            $enddate          = $adding_one_month;
        }
        
        if ($schemeplan == "annually") {
            $adding_one_year = date('Y-m-d h:i:s', strtotime($today . "1 year"));
            $enddate         = $adding_one_year;
        }
        
        $updatewhere = array(
                        'id' => $schemeuserid
                    );
                
                    $updateis = array(
                        'userid' => $userid,
                        'schemeid' => $schemeid,
                        'schemeplan' => $schemeplan,
                        'startdate' => $today,
                        'enddate' => $enddate,
                        'is_active' => '1',
                        'date' => date('Y-m-d h:i:s')   
                    );
                    
                    $is_update = $this->user_model->UPDATEDATA('userscheme',$updatewhere, $updateis);
                    if($is_update){
                        echo "true";
                    }
                    else {
                        echo "false";
                    }
    }
    else{
        // set start and end date        
        $today = date('Y-m-d h:i:s');
        
        if ($schemeplan == "monthly") {
            $adding_one_month = date('Y-m-d h:i:s', strtotime($today . "1 month"));
            $enddate          = $adding_one_month;
        }
        
        if ($schemeplan == "annually") {
            $adding_one_year = date('Y-m-d h:i:s', strtotime($today . "1 year"));
            $enddate         = $adding_one_year;
        }
                
        $insertdata = array(
            'userid' => $userid,
            'schemeid' => $schemeid,
            'schemeplan' => $schemeplan,
            'startdate' => $today,
            'enddate' => $enddate,
            'is_active' => '1',
            'date' => date('Y-m-d h:i:s')
        );
        
        $is_insert = $this->user_model->INSERTDATA('userscheme', $insertdata);
        if ($is_insert) {
            echo "true";
        } else {
            echo "false";
        }
    }
    
    
}
    /* %%%%%%%%%%%%%%%%%%%% User ADD SCHEME %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
    public function viewuserscheme()
    {
        $userid   = (trim($this->input->get('userid')));
        $schemeid = (trim($this->input->get('schemeid')));
        
             
        $where = array(
            'userid' => $userid,
            'schemeid' => $schemeid
        );
        
        $join      = array(
            array(
                'table' => 'scheme',
                'condition' => 'scheme.id=userscheme.userid',
                'jointype' => 'INNER'
            )
        );
        $user_info = $this->user_model->get_joins('userscheme', $where, $join, '', '', '', '');
        
        if ($user_info) {
            print_r(json_encode($user_info));
        } else {
            echo "false";
        }
        
        
        
        
    }
    
    
    /* %%%%%%%%%%%%% USER GET technician services %%%%%%%%%%%%%%% */
    public function getallserviceavailable()
    {
        
        $serviceavailable = $this->user_model->get_joins('techservices');
        
        if ($serviceavailable) {
            print_r(json_encode($serviceavailable));
        } else {
            echo "false";
        }
        
    }
    
    /* %%%%%%%%%%%%%%%%%%%%%%%%%%% get all users %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
    public function getalluser()
    {
        
        $where = array(
            'role' => 'user'
        );
        
        $join = array(
            array(
                'table' => 'booking',
                'condition' => 'booking.userid=user.id',
                'jointype' => 'LEFT'
            )
        );
        
        
        $user_info = $this->user_model->get_joins('user', $where, $join);
        if ($user_info) {
            print_r(json_encode($user_info));
        } else {
            echo "false";
        }
    }
    
    /* %%%%%%%%%%%%%%%%%%%%%%%%%%% get all users %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
    public function getuserbystatus()
    {
        $techid = (trim($this->input->get('techid')));
        $where  = array(
            'techid' => $techid,
            'status' => 'accept'
        );
        
        $join = array(
            array(
                'table' => 'booking',
                'condition' => 'booking.techid = user.id',
                'jointype' => 'LEFT'
            )
        );
        
        $user_info = $this->user_model->get_joins('user', $where, $join, '', '', 'userid');
    
        if ($user_info) {
            print_r(json_encode($user_info));
        } else {
            echo "false";
        }
    }
    
    
    
    
    /* %%%%%%%%%%%%%%%%%%% get all users by id %%%%%%%%%%%%%%%%%%%%%%%%%%% */
    public function getalluserbyid()
    {
        
        $userid = $this->input->get('userid');
        
        $where = array(
            
            'id' => $userid,
            'role' => 'user'
        );
        
        
        $user_info = $this->user_model->get_joins('user', $where);
        if ($user_info) {
            print_r(json_encode($user_info));
        } else {
            echo "false";
        }
    }
    
    
    /* %%%%%%%%%%%%%%%%%%% get all users by id %%%%%%%%%%%%%%%%%%%%%%%%%%% */
    
    public function checkstatus()
    {
        
        $userid          = $this->input->get('userid');
        $bookingdatetime = $this->input->get('bookingdatetime');
  
        
        $where = array(
            'userid' => $userid,
            // 'booking_date' =>    $booking_date,                    
            'date' => $bookingdatetime
        );
        $field = array(
            'status',
            'date',
            'booking_date',
            'booking_time'
        );
        
        $user_info = $this->user_model->get_joins('booking', $where, '', $field);
        if ($user_info) {
            print_r(json_encode($user_info));
        } else {
            echo "false";
        }
    }
    /* %%%%%%%%%%%%%%%%%%% Check Technician OR  User exits or not %%%%%%%%%%%%%%%%%%% */
    public function checkUserExist()
    {
        $userid = trim($this->input->get('userid'));
        
        $where = array(
            'id' => $userid
        );
        
        $checkuser = $this->user_model->get_joins('user', $where);
        if ($checkuser) {
            echo "true";
        } else {
            echo "false";
        }
    }
    
    
    /* %%%%%%%%%%%%%%%%%%% Get ALL SCHEME %%%%%%%%%%%%%%%%%%% */
    public function getscheme()
    {
        
        $scheme = $this->user_model->get_joins('scheme');
        if ($scheme) {
            print_r(json_encode($scheme));
        } else {
            echo "false";
        }
    }
    
    /* %%%%%%%%%% Technician  %%%%%%%%%%%%%% */
    /* %%%%%%%%%%%%%%%%%%%%%%%%%% Technician App Sign Up %%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
    public function technicianSignUp()
    {
        $username        = (trim($this->input->get('username')));
        $firstname       = (trim($this->input->get('firstname')));
        $lastname        = (trim($this->input->get('lastname')));
        $email           = (trim($this->input->get('email')));
        $mobile          = (trim($this->input->get('mobile')));
        $password        = md5($this->input->get('password'));
        $image           = (trim($this->input->get('image')));
        $address         = (trim($this->input->get('address')));
        $apt             = (trim($this->input->get('apt')));
        $city            = (trim($this->input->get('city')));
        $state           = (trim($this->input->get('state')));
        $zip             = (trim($this->input->get('zip')));
        $billingaddresss = (trim($this->input->get('billingaddresss')));
        $billingapt      = (trim($this->input->get('billingapt')));
        $billingcity     = (trim($this->input->get('billingcity')));
        $billingstate    = (trim($this->input->get('billingstate')));
        $billingzip      = (trim($this->input->get('billingzip')));
        $cardname        = (trim($this->input->get('cardname')));
        $role            = 'technician';
        
        $insertdata = array(
            'username' => $username,
            'firstname' => $firstname,
            'lastname' => $lastname,
            'email' => $email,
            'mobile' => $mobile,
            'password' => $password,
            'image' => $image,
            'address' => $address,
            'apt' => $apt,
            'city' => $city,
            'state' => $state,
            'zip' => $zip,
            'billingaddresss' => $billingaddresss,
            'billingapt' => $billingapt,
            'billingcity' => $billingcity,
            'billingstate' => $billingstate,
            'billingzip' => $billingzip,
            'cardname' => $cardname,
            'role' => $role,
            'date' => date('Y-m-d h:i:s')
        );
        
        $where_contact = array(
            'email' => $email,
            'username' => $username
        );
        $user_contact  = ($this->user_model->get_joins('user', '', '', '', '', '', '', '', '', $where_contact));
        if (!empty($user_contact)) {
            echo "false";
        } else {
            $is_insert = $this->user_model->INSERTDATA('user', $insertdata);
            if ($is_insert) {
                echo "true";
            } else {
                echo "false";
            }
        }
    }
    
    /* %%%%%%%%%%%%%%%%%%%%%%%%%% Technician App login %%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
    public function technicianSignIn()
    {
        $username = ($this->input->get('username'));
        $password = md5($this->input->get('password'));
        
        $where = array(
            'username' => $username,
            'password' => $password,
            'role' => 'technician'
        );
        
        $user_info = $this->user_model->get_joins('user', $where);
        if ($user_info) {
            print_r(json_encode($user_info));
        } else {
            echo "false";
        }
    }
    
    /* %%%%%%%%%%%%%%%%%%%% Technician Update %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
    public function updateTechnicianData()
    {
        
        $id        = (trim($this->input->get('id')));
        $firstname = (trim($this->input->get('firstname')));
        $lastname  = (trim($this->input->get('lastname')));
        $email     = (trim($this->input->get('email')));
        $mobile    = (trim($this->input->get('mobile')));
        $address   = (trim($this->input->get('address')));
        $apt       = (trim($this->input->get('apt')));
        $city      = (trim($this->input->get('city')));
        $state     = (trim($this->input->get('state')));
        $zip       = (trim($this->input->get('zip')));
        $role      = 'technician';
        
        $updatedata = array(
            'firstname' => $firstname,
            'lastname' => $lastname,
            'email' => $email,
            'mobile' => $mobile,
            'address' => $address,
            'apt' => $apt,
            'city' => $city,
            'state' => $state,
            'zip' => $zip,
            'role' => $role,
            'date' => date('Y-m-d h:i:s')
        );
        
        $where = array(
            'id' => $id
        );
        
        $update = $this->user_model->UPDATEDATA('user', $where, $updatedata);
        if ($update) {
            echo "true";
        } else {
            echo "false";
        }
    }
    
    /* %%%%%%%%%%%%% Technician Add services %%%%%%%%%%%%%%% */
    public function addtechservicebyid()
    {
        
        $id       = (trim($this->input->get('userid')));
        $services = (trim($this->input->get('services')));
        
        $insertdata = array(
            'userid' => $id,
            'services' => $services
        );
        
        $is_insert = $this->user_model->INSERTDATA('techservices', $insertdata);
        if ($is_insert) {
            echo "true";
        } else {
            echo "false";
        }
        
    }
    
    /* %%%%%%%%%%%%% Technician GET services %%%%%%%%%%%%%%% */
    public function gettechservicebyid()
    {
        
        $id    = (trim($this->input->get('userid')));
        $where = array(
            'userid' => $id
        );
       
        $techservice = $this->user_model->get_joins('techservices', $where, '', '', '', '');
                
        if ($techservice) {
            print_r(json_encode($techservice));
        } else {
            echo "false";
        }
        
    }
    
    
    /* %%%%%%%%%%%%%%%%%%%%% image name update in DB  %%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
    
    public function profileimage()
    {
        
        $image      = $this->input->get('image');
        $userid     = $this->input->get('userid');
        $updatedata = array(
            'image' => $image
        );
        
        $where = array(
            'id' => $userid
        );
        
        $is_update = $this->user_model->UPDATEDATA('user', $where, $updatedata);
        if ($is_update) {
            echo "true";
        } else {
            echo "false";
        }
    }
    
    /* %%%%%%%%%%%%%%%%% BOOKING TECHNICIAN SERVICES  %%%%%%%%%%%%%%%%%%%%%%% */
    public function technicianBooking()
    {
        $userid       = $this->input->get('userid');
        $techid       = $this->input->get('techid');
        $username     = $this->input->get('username');
        $techname     = $this->input->get('techname');
        $schemeid     = $this->input->get('schemeid');
        $service      = $this->input->get('service');
        $serviceid    = $this->input->get('serviceid');
        $isservice    = str_replace('"', '', $service);
        $booking_date = $this->input->get('booking_date');
        $booking_time = $this->input->get('booking_time');
        $booking_add  = trim(ucwords($this->input->get('booking_add')));
        $contact      = trim($this->input->get('contact'));
        $techcontact  = trim($this->input->get('techcontact'));
        $status       = $this->input->get('status');
        $where        = array(
            'id' => $schemeid
        );
        $schemetimes  = $this->user_model->get_joins('scheme', $where);
        $duration     = $schemetimes[0]['duration'];
        $btime        = $schemetimes[0]['beforetime'];
        $atime        = $schemetimes[0]['aftertime'];
        $totaltime    = $duration + $atime;
        $beforetime   = date("H:i", strtotime("$booking_time -0 hours -$btime minutes"));
        $aftertime    = date("H:i", strtotime("$booking_time +0 hours +$totaltime minutes"));
        
        $insertdata = array(
            'userid' => $userid,
            'techid' => $techid,
            'username' => $username,
            'techname' => $techname,
            'schemeid' => $schemeid,
            'service' => $isservice,
            'serviceid' => $serviceid,
            'booking_date' => $booking_date,
            'booking_time' => $booking_time,
            'starttime' => $beforetime,
            'endtime' => $aftertime,
            'booking_add' => $booking_add,          
            'date' => date('Y-m-d h:i:s')
        );
        $is_insert  = $this->user_model->INSERTDATA('booking', $insertdata);
        if ($is_insert) {
            echo "true";
        } else {
            echo "false";
        }
    }
    
    
    /* %%%%%%%%%%%%%%%%%%%%%%%%%% get booking details by userid %%%%%%%%%%%%%%%%%%%%%% */
    public function getbookingbyid()
    {
        $userid = ($this->input->get('userid'));
        
        $where = array(
            'userid' => $userid
        );
        
        $user_info = $this->user_model->get_joins('booking', $where);
        if ($user_info) {
            print_r(json_encode($user_info));
        } else {
            echo "false";
        }
    }
    
    
    /* %%%%%%%%%% Register device Token %%%%%%%%%%%%%%%%% */
    public function tokenregister()
    {
        $email  = trim($this->input->get('email'));
        $token  = $this->input->get('token');
        $userid = $this->input->get('userid');
        
        $where = array(
            'userid' => $userid
        );
        
        $checktoken = $this->user_model->get_joins('devices', $where);
        
        if ($checktoken) {
            
            $updatewhere = array(
                'userid' => $userid
            );
            
            $updateis = array(
                'email' => $email,
                'token' => $token,
                'date' => date('Y-m-d h:i:s')
            );
            
            $is_update = $this->user_model->UPDATEDATA('devices', $updatewhere, $updateis);
            if ($is_update) {
                echo "true";
            } else {
                echo "false";
            }
        } else {
            
            $insertdata = array(
                'email' => $email,
                'token' => $token,
                'userid' => $userid,
                'date' => date('Y-m-d h:i:s')
            );
            
            $is_insert = $this->user_model->INSERTDATA('devices', $insertdata);
            if ($is_insert) {
                echo "true";
            } else {
                echo "false";
            }
        }
    }
    
    /* %%%%%%%%%% Get  Registered device Token by userid %%%%%%%%%%%%%%%%% */
    public function devicetokenbyid()
    {
        $userid = $this->input->get('userid');
        $where  = array(
            'userid' => $userid
        );
        
        $field = array(
            'devices.*',
            'GROUP_CONCAT(token) token'
        );
        
        $getStylitdevicetokan = $this->user_model->get_joins('devices', $where, '', $field, '', 'userid');
        if ($getStylitdevicetokan) {
            $data[] = (array(
                'token' => $getStylitdevicetokan[0]['token']
            ));
            print_r(json_encode($data));
        } else {
            echo "false";
        }
        
        
    }
    /* %%%%%%%%%% Get  Registered device %%%%%%%%%%%%%%%%% */
    public function getalltechniciantoken()
    {
               
        $columns = array(
            'GROUP_CONCAT(token) token'
        );
        // $join=array(
        //         array('table'=>'user','condition'=>'user.id=devices.userid','jointype'=>'LEFT'),                    
        //         array('table'=>'booking','condition'=>'booking.userid=devices.userid','jointype'=>'LEFT')                    
        //       );
        
        // $getdevicetoken = $this->user_model->get_joins('devices',$where,$join, $columns,'','','','','',$where_or);
        $getdevicetoken = $this->user_model->get_joins('devices', '', '', $columns);
        
        if ($getdevicetoken) {
            print_r(json_encode($getdevicetoken));
        } else {
            echo "false";
        }
    }
    
    
    /* %%%%%%%%%% GET USER PLAN DETAILS %%%%%%%%%%%%%%%%% */
    public function getplaninfo()
    {
        $userid = $this->input->get('userid');
        $where  = array(
            'userid' => $userid
        );
        
        $columns = array(
            'is_active'
        );
        
        $getstatus = $this->user_model->get_joins('userscheme', $where, '', $columns);
        
        if ($getstatus) {
            print_r(json_encode($getstatus));
        } else {
            echo "false";
        }
    }
    
    /* %%%%%%%%%%%%%%%%%% SEND Membership Email %%%%%%%%%%%%%%%%%%%%%%%% */
    public function BookingSendEmail()
    {
        
        $username    = ucwords($this->input->get('username'));
        $email       = $this->input->get('email');
        $orderID     = $this->input->get('orderID');
        $paid        = $this->input->get('paid');
        $bookingdate = $this->input->get('bookingdate');
        $userid      = $this->input->get('userid');
        $schemeid    = $this->input->get('schemeid');
        $token       = $this->input->get('token');
        
        $htmlContent = '<table>
                            <tr>
                                <td> <img src="' . base_url('assets/app-icon.png') . '" width="11%"></td>
                            </tr>
                            <tr>
                            <td><b>Hello ' . $username . '</b></td>
                            </tr>
                            <tr>
                                <td>Membership Id:- <b>' . $orderID . '</b></td>
                            </tr>                    
                            <tr>
                                <td>Paid Amount:- $' . $paid . '</td>
                            </tr>
                            <tr>
                                <td>Membership Date:- ' . $bookingdate . '</td>
                            </tr>    
                            <tr>
                                <td style="height:50px"> </td>
                            </tr>                                        
                            <tr>
                                <td>Thank You</td>
                            </tr>                    
                        </table>';
        $this->email->to($email, $username);
        $this->email->subject('OnDemandHomeService Membership And Payment');
        $this->email->message($htmlContent);
        $this->email->send();
        
        $wheretokan = array(
            'userid' => $userid
        );
        
        $field = array(
            'GROUP_CONCAT(token) token'
        );
        
        $getDemanddevicetokan = $this->user_model->get_joins('devices', $wheretokan, '', $field, '', '');
        if ($getDemanddevicetokan) {
            echo "true";
            //             $msgsend = $username.' Booked your Membership and Membership id is '.$orderID;            
            // header('location:http://ondemandhome.betaplanets.com/notifications/?title=Appointment&message='.$msgsend.'&firebase_token='.$getDemanddevicetokan[0]['token']);                      
        } else {
            echo "false";
        }
        
    }
    
    /* %%%%%%%%%%%%%%%%%% GET ALL USER REQUESTED STATUS %%%%%%%%%%%%%%%%%%%%%%%% */
    public function getrequestedbooking()
    {
        $where = array(
            'status' => 'requested'
        );
        
        $getstatus = $this->user_model->get_joins('booking', $where);
        
        if ($getstatus) {
            print_r(json_encode($getstatus));
        } else {
            echo "false";
        }
        
    }
    
    /* %%%%%%%%%%%%%%%%%% GET ALL USER REQUESTED STATUS %%%%%%%%%%%%%%%%%%%%%%%% */
    public function setrequesttoaccept()
    {
        $id          = trim($this->input->get('id'));
        $userid      = trim($this->input->get('userid'));
        $techid      = trim($this->input->get('techid'));
        $techname    = trim($this->input->get('techname'));
        $techcontact = trim($this->input->get('techcontact'));
        
        $updatewhere = array(
            'id' => $id
        );
        
        $updateis = array(
            'techid' => $techid,
            'techname' => $techname,
            'techcontact' => $techcontact,
            'status' => 'accept',
            'date' => date('Y-m-d h:i:s')
        );
        
        $is_update = $this->user_model->UPDATEDATA('booking', $updatewhere, $updateis);
        if ($is_update) {
            
            $wheretokan = array(
                'userid' => $userid
            );
            
            $field                = array(
                'GROUP_CONCAT(token) token'
            );
            $getDemanddevicetokan = $this->user_model->get_joins('devices', $wheretokan, '', $field, '', '');
            
            // print_r($getDemanddevicetokan[0]['token']);            
            if ($getDemanddevicetokan) {
                
                header('location:http://ondemandhome.betaplanets.com/notifications/?title=Accept&message=Your Request has been Accepted&firebase_token=' . $getDemanddevicetokan[0]['token']);
            } else {
                echo "false";
            }
            
        } else {
            echo "false";
        }
        
    }
    
    /* %%%%%%%%%%%%%%%%%% GET ALL USER REQUESTED STATUS %%%%%%%%%%%%%%%%%%%%%%%% */
    public function setaccepttocomplete()
    {
        $id       = trim($this->input->get('id'));
        $userid   = trim($this->input->get('userid'));
        $techid   = trim($this->input->get('techid'));
        $techname = trim($this->input->get('techname'));
        
        $updatewhere = array(
            'id' => $id
        );
        $updateis    = array(
            'techid' => $techid,
            'techname' => $techname,
            'status' => 'complete',
            'date' => date('Y-m-d h:i:s')
        );
        
        $is_update = $this->user_model->UPDATEDATA('booking', $updatewhere, $updateis);
        if ($is_update) {
            $wheretokan = array(
                'userid' => $userid
            );
            
            $field                = array(
                'GROUP_CONCAT(token) token'
            );
            $getDemanddevicetokan = $this->user_model->get_joins('devices', $wheretokan, '', $field, '', '');
            
            
            if ($getDemanddevicetokan) {
                // echo "true";
                header('location:http://ondemandhome.betaplanets.com/notifications/?title=Accept&message=Your job has been Completed &firebase_token=' . $getDemanddevicetokan[0]['token']);
            } else {
                echo "false";
            }
        } else {
            echo "false";
        }
        
    }
    
    /* %%%%%%%%%%% STATUS OF BOOKING %%%%%%%%%%%%%%%%%%%%%%%% */
    public function checkbookingstatus()
    {
        $id = trim($this->input->get('id'));
        
        $where     = array(
            'id' => $id
        );
        $field     = array(
            'status'
        );
        $getstatus = $this->user_model->get_joins('booking', $where, '', $field);
        
        if ($getstatus) {
            print_r(json_encode($getstatus));
        } else {
            echo "false";
        }
    }
    
    
    /* %%%%%%%%%%%%%%%%%% GET ACCEPT STATUS BY USER ID %%%%%%%%%%%%%%%%%%%%%%%% */
    public function getacceptstatus()
    {
        $userid = trim($this->input->get('userid'));
        
        $where = array(
            
            'userid' => $userid,
            'status' => 'accept'
            
        );
        
        $getstatus = $this->user_model->get_joins('booking', $where);
        
        if ($getstatus) {
            print_r(json_encode($getstatus));
        } else {
            echo "false";
        }
        
    }
    
    /* %%%%%%%%%%%%%%%%%% GET ACCEPT STATUS BY TECHNICIAN ID %%%%%%%%%%%%%%%%%%%%%%%% */
    public function gettechacceptstatus()
    {
        $techid = trim($this->input->get('techid'));
        
        $where = array(
            
            'techid' => $techid,
            'status' => 'accept'
            
        );
        
        $getstatus = $this->user_model->get_joins('booking', $where);
        
        if ($getstatus) {
            print_r(json_encode($getstatus));
        } else {
            echo "false";
        }
        
    }

    /* %%%%%%%%%%%%%%%%%% GET ACCEPT STATUS BY USER ID %%%%%%%%%%%%%%%%%%%%%%%% */
    public function getuseracceptstatus()
    {
        $userid = trim($this->input->get('userid'));
        
        $where = array(
            
            'userid' => $userid,
            'status' => 'accept'
            
        );
        
        $getstatus = $this->user_model->get_joins('booking', $where);
        
        if ($getstatus) {
            print_r(json_encode($getstatus));
        } else {
            echo "false";
        }
        
    }
    
    
    /* %%%%%%%%%%%%%%%%%% GET BOOKING BY USER ID %%%%%%%%%%%%%%%%%%%%%%%% */
    public function getdatabybookingid()
    {
        $bookid = trim($this->input->get('bookid'));
        
        $where = array(
            'booking.id' => $bookid
        );
        
        $join = array(
            array(
                'table' => 'user',
                'condition' => 'user.id=booking.userid',
                'jointype' => 'LEFT'
            )
        );
        
        $getstatus = $this->user_model->get_joins('booking', $where, $join);
        
        if ($getstatus) {
            print_r(json_encode($getstatus));
        } else {
            echo "false";
        }
        
    }
    
    // GET STRIPE CUSTOMER ID FROM DATABASE 
    public function getstripecustomerid()
    {
        
        $userid = $this->input->get('userid');
        
        $columns = array(
            'customerid'
        );
        
        $where = array(
            'userid' => $userid
        );
        
        $user_info = $this->user_model->get_distinct_col('userscheme', $where, '', $columns);
        if ($user_info) {
            print_r(json_encode($user_info));
        } else {
            echo "false";
        }
    }
    
    
    // GET STRIPE CUSTOMER INFO
    public function getstripeinfo()
    {
        $customerid = trim($this->input->get('customerid'));
        
        require_once('stripe_payment_gateway/stripe-php/init.php');
        
        //set api key
        $stripe = array(
            "secret_key" => "sk_test_bBcx24ld9rsUmP5kd1nNUS43",
            "publishable_key" => "pk_test_6C2zhCPDkgYTCvlU96n2WcIw"
        );
        
        \Stripe\Stripe::setApiKey($stripe['secret_key']);
        
        $customerinfo = \Stripe\Customer::retrieve($customerid);
        
        $card = $customerinfo->sources->retrieve($customerinfo->sources->data[0]['id']);
        
        //     $customerinfo->jsonSerialize();
        print_r(json_encode($card));
        
    }
    
    public function OnDemandAbout()
    {
        $aboutus = $this->user_model->get_joins('rawdata');
        
        if ($aboutus) {
            print_r(json_encode($aboutus));
        } else {
            echo "false";
        }
    }
    
    public function getAllServicesbyId()
    {
        $schemeid = $this->input->get('schemeid');
        
        $whereopt = array(
            'scheme.id' => $schemeid
        );
        $joinopt  = array(
            array(
                'table' => 'services',
                'condition' => 'services.package_id = scheme.id',
                'jointype' => 'RIGHT'
            )
        );
        $optplan  = $this->user_model->get_joins('scheme', $whereopt, $joinopt);
        
        if ($optplan) {
            print_r(json_encode($optplan));
        } else {
            echo "false";
        }
    }
    
/* ######################## TECHNICIAN GET REQUESTS ############################### */
    
    /*
        Get all requested booking from booking table 
    */
    function getstatusrequested()
    {
        $currentDate = date('m/d/Y'); 
        $where       = array(
            'booking_date >='=>$currentDate,
            'status' => 'requested'

        );
        $getnulltech = $this->user_model->get_joins('booking', $where);
        if ($getnulltech) {
            return $getnulltech;
        } else {
            return false;
        }
    }
    
    /*
        Get all accept booking from booking table of specific technician
    */
    function getstatusaccept($techid)
    {
        $where     = array(
            'techid' => $techid,
            'status' => 'accept'
        );
        $getstatus = $this->user_model->get_joins('booking', $where);
        if ($getstatus) {
            return $getstatus;
        } else {
            return false;
        }
    }
    
    
    public function comparebookingtimes()
    {
        $id = $this->input->get('techid');
        /*
        Get data from Both the functions
        */
        $allrequestedbooking = $this->getstatusrequested();
        $allacceptedbooking  = $this->getstatusaccept($id);
        
        if (!empty($allacceptedbooking)) {
            /* 
            Convert Current time in TimeStamp
            */
            // $currenttime = strtotime(date('h:i')); 
            // $currentDate = date('m/d/Y'); 
            
            $availableJson = array();
            
            foreach ($allacceptedbooking as $bookvar) {
                
                /*
                Get each start and endtime of reserved technician 
                And convert them into timestamp
                */
                
                $acptstarttime = strtotime($bookvar['starttime']);
                $acptendtime   = strtotime($bookvar['endtime']);
                $acptDate      = strtotime($bookvar['booking_date']);
                
                foreach ($allrequestedbooking as $reqvar) {
                    /*
                    Now compare each requested booking 
                    */
                    $reqstarttime = strtotime($reqvar['starttime']);
                    $reqendtime   = strtotime($reqvar['endtime']);
                    $bookingtime  = strtotime($reqvar['booking_time']);
                    $reqDate      = strtotime($reqvar['booking_date']);
                    
                    if (!(($bookingtime > $acptstarttime) && ($bookingtime < $acptendtime) && ($acptDate <= $reqDate) && ($acptDate >= $reqDate))) {
                        $data = array(
                            'id' => $reqvar['id'],
                            'userid' => $reqvar['userid'],
                            'techid' => $reqvar['techid'],
                            'username' => $reqvar['username'],
                            'techname' => $reqvar['techname'],
                            'schemeid' => $reqvar['schemeid'],
                            'service' => $reqvar['service'],
                            'serviceid' => $reqvar['serviceid'],
                            'booking_date' => $reqvar['booking_date'],
                            'booking_time' => $reqvar['booking_time'],
                            'starttime' => $reqvar['starttime'],
                            'endtime' => $reqvar['endtime'],
                            'booking_add' => $reqvar['booking_add'],
                            'amount' => $reqvar['amount'],
                            'total_amount' => $reqvar['total_amount'],
                            'contact' => $reqvar['contact'],
                            'techcontact' => $reqvar['techcontact'],
                            'status' => $reqvar['status'],
                            'date' => $reqvar['date']
                        );
                        array_push($availableJson, $data);
                    }
                    
                }
                print_r(json_encode($availableJson));
            }
            
        }
         else {
            $allrequestedbooking = $this->getstatusrequested();
            print_r(json_encode($allrequestedbooking));
        }
        
        
    }
    
    /* ################# Check notification of status is requested or accept ############ */
    function sendNotification($value)
    {
        /*    send notification to requested tokens */
        // header('location:http://ondemandhome.betaplanets.com/notifications/?title=' . $value['title'] . '&message=&firebase_token=' . $value['token']);
          /*  $title = $this->input->get('title');
            $message = $this->input->get('message');        
            $fbasetoken = $this->input->get('fbasetoken');   */   
            $title = $value['title'];
            $message = $value['message'];        
            $fbasetoken = $value['token'];

          
            /*$title = $_GET['title'];
            $message = isset($_GET['message'])?$_GET['message']:'';     
            */      
                
            $firebase_api = 'AIzaSyD5F88TM5LcnXLmyJ4X4bk14Thn84MlH0g';        
      
            //$firebase_token = $_GET['firebase_token'];
            // $firebase_token = explode(',',$_GET['firebase_token']);
            $firebase_token = explode(',',$fbasetoken);        
            
            foreach($firebase_token as $firebase_token){ 
                            
                $fields = '{"to":"'.$firebase_token.'", "priority": "high", "notification": { "title": "'.$title.'", "text": "'.$message.'", "click_action":"FCM_PLUGIN_ACTIVITY", "content_available": true } "data": { "badge": 1, "sound": "default", "alert": "OnDemandHomeService", "title": "'.$title.'", "message": "'.$message.'" }}';
            

                            // Set POST variables
                            $url = 'https://fcm.googleapis.com/fcm/send';
     
                            $headers = array(
                                'Authorization: key=' . $firebase_api,
                                'Content-Type: application/json'
                            );
                            
                            // Open connection
                            $ch = curl_init();
     
                            // Set the url, number of POST vars, POST data
                            curl_setopt($ch, CURLOPT_URL, $url);
     
                            curl_setopt($ch, CURLOPT_POST, true);
                            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     
                            // Disabling SSL Certificate support temporarily
                            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     
                            curl_setopt($ch, CURLOPT_POSTFIELDS, ($fields));
     
                            // Execute post
                            $result = curl_exec($ch);
                            if($result === FALSE){                                 
                                die('Curl failed: ' . curl_error($ch));             
                                
                            }

                            // Close connection
                            curl_close($ch);


            }
        
    }
    
    function alltechtokens()
    {
        /*
        Return All Technician's Device tokens  
        */
        $where          = array(
            'role' => 'technician'
        );
        $columns        = array(
            'GROUP_CONCAT(token) token'
        );
        $join           = array(
            array(
                'table' => 'user',
                'condition' => 'user.id=devices.userid',
                'jointype' => 'RIGHT'
            )
        );
        $getdevicetoken = $this->user_model->get_joins('devices', $where, $join, $columns, '', '', '', '', '', '');
        if ($getdevicetoken) {
            return $getdevicetoken;
        } else {
            return false;
        }
    }
    
    function getacceptbookings()
    {
        /*
        Return All Accepted Bookings
        */
        
        $where     = array(
            'status' => 'accept'
        );
        $getstatus = $this->user_model->get_joins('booking', $where);
        if ($getstatus) {
            return $getstatus;
        } else {
            return false;
        }
    }
    public function checkNotification()
    {
        $title = $this->input->get('title');
        $message = $this->input->get('message');
        
        $allrequestedbooking = $this->getstatusrequested(); // All requested bookings
        $allacceptedbooking  = $this->getacceptbookings(); // All accept bookings
        
        /*    Check Whether Booking is Available or Not */
        
        if (empty($allacceptedbooking)) {
            
            /* Send Notifications to all Technicians */
            $allTokens = $this->alltechtokens();
            $notiToken = array(
                'title' => $title,
                'message' => $message,
                'token' => $allTokens[0]['token']
            );
            // echo "first".$notiToken;
            $this->sendNotification($notiToken);
            
        } else {
            
            /*  Start I Iteration */
            foreach ($allacceptedbooking as $bookvar) {
                //    Get each start and endtime of reserved technician And convert them into timestamp
                
                $acptstarttime = strtotime($bookvar['starttime']);
                $acptendtime   = strtotime($bookvar['endtime']);
                $acptDate      = strtotime($bookvar['booking_date']);
                
                /*  Start II Iteration */
                
                foreach ($allrequestedbooking as $reqvar) {
                    /*
                    Now compare each requested booking 
                    */
                    
                    $reqstarttime = strtotime($reqvar['starttime']);
                    $reqendtime   = strtotime($reqvar['endtime']);
                    $bookingtime  = strtotime($reqvar['booking_time']);
                    $reqDate      = strtotime($reqvar['booking_date']);
                if (($bookingtime > $acptstarttime) && ($bookingtime < $acptendtime) && ($acptDate <= $reqDate) && ($acptDate >= $reqDate)) {
                        $acpttechid = $bookvar['techid'];

                        /*
                        Select all technician token except booked one 
                        */
                        $column     = array(
                            'GROUP_CONCAT(token) token'
                        );
                        $where      = array(
                            'userid !=' => $acpttechid
                        );
                        $techtok    = $this->user_model->get_joins('devices', $where, '', $column);
                        
                        $acptnotiToken = array(
                            'title' => $title,
                            'message' => $message,
                            'token' => $techtok[0]['token']
                        );
                      
                        $this->sendNotification($acptnotiToken);
                        
                    }
                     else
                    {   
                  
                    // send notification to all
                    $allTokens = $this->alltechtokens();
                      
                    $notiToken = array(                
                    'title' => $title,
                    'message' => $message,
                    'token'=>$allTokens[0]['token']
                    );
                    // echo "third";
                    // print_r($notiToken);    
                        $this->sendNotification($notiToken);
                    } 
                    
                }
                /*  End II Iteration */
                
            }
            /*  End I Iteration */
        }
        
        
    }
    
  /*
    View Customer's Package
*/
public function customerpackage()
{

    $userid = $this->input->get('userid');

    $where = array( 'userid' => $userid );
                            
    $join=array(
                    array('table'=>'scheme','condition'=>'scheme.id=userscheme.schemeid','jointype'=>'LEFT')                    
                  );

    $getpackage = $this->user_model->get_joins('userscheme',$where,$join,'','','','','','',''); 
    $result = array();
    if($getpackage){
        /*
            Check Customer's opted Plan 
        */
        $schemeplan = $getpackage[0]['schemeplan'];
        if($schemeplan=='monthly'){
        
            $data = array(
                'id'=> $getpackage[0]['id'],
                'userid'=> $getpackage[0]['userid'],
                'schemeid'=> $getpackage[0]['schemeid'],
                'schemeplan'=> $getpackage[0]['schemeplan'],                
                'type'=> $getpackage[0]['type'],
                'amount'=> $getpackage[0]['monthfee'],
                'customerid'=> $getpackage[0]['customerid']

            );
            array_push($result, $data);

        }
        if($schemeplan=='annually'){
    
            $data = array(
                'id'=> $getpackage[0]['id'],
                'userid'=> $getpackage[0]['userid'],
                'schemeid'=> $getpackage[0]['schemeid'],
                'schemeplan'=> $getpackage[0]['schemeplan'],
                'type'=> $getpackage[0]['type'],
                'amount'=> $getpackage[0]['annuallfee'],
                'customerid'=> $getpackage[0]['customerid']
            );
            array_push($result, $data);
        }

     print_r(json_encode($result)); // Gives Plan details

    }   else
    {   
        echo "false";
    }
    
}  
   
    /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
}

Comments

Popular posts from this blog

SQL

****** Count "yes" or "no" ************** SELECT COUNT(case when decision="yes" THEN decision end )as yes, COUNT(case when decision="no" THEN decision end )as no, COUNT(case when decision="unsure" THEN decision end ) as unsure,COUNT(decision) FROM `election` WHERE `dispute_id` = '2' _____________________________________________ SELECT MAX(`date`) FROM stylist_payment WHERE `stylitid` ='390' > SELECT MAX(`date`) FROM stylist_payment GROUP BY `stylitid` > SELECT `stylist_payment`.`stylitid`, `stylitamount`, `percentage`, `si_amount`, `stylist_payment`.`date` FROM `stylist_payment` LEFT JOIN `booking` ON `booking`.`stylitid` = `stylist_payment`.`stylitid`GROUP BY `stylitid` SELECT MAX(`stylist_payment`.`date`) FROM stylist_payment LEFT JOIN `user` ON `user`.`id` = `stylist_payment`.`stylitid` GROUP BY `stylitid` SELECT stylitid,total_amount,user.username,user.firstname,user.lastname,user.contact,user.ema...

NGrok Setup

 https://dashboard.ngrok.com/get-started/setup 1. Unzip to install On Linux or Mac OS X you can unzip ngrok from a terminal with the following command. On Windows, just double click ngrok.zip to extract it. unzip /path/to/ngrok.zip 2. Connect your account Running this command will add your authtoken to the default ngrok.yml configuration file. This will grant you access to more features and longer session times. Running tunnels will be listed on the endpoints page of the dashboard. ngrok config add-authtoken 1woFn9zVqcI4VeGuSIiN2VtmnPa_ZXuAuF1AAPkqApr7WVsQ 3. Fire it up Read the documentation on how to use ngrok. Try it out by running it from the command line: ngrok help To start a HTTP tunnel forwarding to your local port 80, run this next: ngrok http 80

Update Node on Mac and Windows

Using brew: brew update brew upgrade node Using nvm:   NVM (Node Version Manager) is a tool that allows you to manage multiple versions of Node on your system. You can use nvm to install, update, and switch between different versions of Node. To update your version of Node using nvm, do the following: 1. Check if you already have nvm installed on your system:   
nvm --version 2. If it's not installed, install nvm using this command:    
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash 3. Once nvm is installed, check your current version of Node by running the following command: 
node -v 4. Then update your version of Node using the following command:   
nvm install node --reinstall-packages-from=node 5. And finally, verify that your update is complete by rechecking your Node version:   
node -v ———————————————————————————————————— Using NPM: To update Node using NPM, do the following: 1. Open the Terminal and check your curren...