%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/ugotscom/public_html/sterren/application/modules/api/controllers/
Upload File :
Create Path :
Current File : /home/ugotscom/public_html/sterren/application/modules/api/controllers/Api.php

<?php

class Api extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('common_model', 'obj_common', TRUE);
    }

// code for login api//
    public function login() {
        $res['status'] = 'error';
        $api_key = $this->input->post_get('api_key');
        if ($api_key == $this->config->item('api_key')) {
            $username = $this->input->post_get('username');
            $pass = $this->input->post_get('password');

            if ($username != '' && $pass != '') {
                $pass = md5($pass);
                $field = 'user_id,name,phone,branch_id';
                $condition = array('username' => $username,
                    'password' => $pass);
                $result = $this->obj_common->get_all('users', $condition, $field);
                if ($result) {
                    $res['status'] = 'success';
                    $res['data'] = $result;
                } else {
                    $conditions = array('username' => $username);

                    $result = $this->obj_common->get_all('users', $conditions, $field);
                    if ($result) {
                        $res['message'] = 'Invalid Password or username';
                    } else {
                        $res['message'] = 'User not exist';
                    }
                    $res['status'] = 'error';
                }
            }
        } else {
            $res['message'] = 'Invalid api key';
        }
        echo json_encode($res);
    }

    public function enqiry() {
        $res['status'] = 'error';

        $api_key = $this->input->post_get('api_key');
        if ($api_key == $this->config->item('api_key')) {
            $this->load->helper(array('form', 'url'));
            $this->load->library('form_validation');
//                $this->form_validation->set_rules('enquiry_source', 'enquiry_source', 'xss_clean|trim');              
//                $this->form_validation->set_rules('customer_name', 'customer_name', 'xss_clean|trim');
////                $this->form_validation->set_rules('enquiry_source', 'product_price', 'xss_clean|trim');              
////                $this->form_validation->set_rules('alt_mobile_no', 'alt_mobile_no', 'xss_clean|trim');
////                $this->form_validation->set_rules('landline_no', 'landline_no', 'xss_clean|trim');              
////                $this->form_validation->set_rules('email', 'email', 'valid_email|xss_clean|trim');
////                $this->form_validation->set_rules('location', 'location', 'xss_clean|trim');              
////                $this->form_validation->set_rules('gender', 'gender', 'xss_clean|trim');
////                $this->form_validation->set_rules('dob', 'dob', 'xss_clean|trim');              
////                $this->form_validation->set_rules('aadhar_no', 'aadhar_no', 'xss_clean|trim');   
////                $this->form_validation->set_rules('product_category_id', 'product_category_id', 'xss_clean|trim');              
////                $this->form_validation->set_rules('lead_type_id', 'lead_type_id', 'xss_clean|trim'); 
//////                $this->form_validation->set_rules('followup_date', 'followup_date', 'xss_clean|trim');    
//                if ($this->form_validation->run() == FALSE)
//                {
//                         $res['status'] = 'error';
//                }
//                else
//                {
            $updated_time=date('Y-m-d H:i:s');
            $c_date = date('Y-m-d');
            $lead_array = array(
                'enquiry_source' => $this->input->post_get('enquiry_source'),
                'customer_name' => $this->input->post_get('customer_name'),
                'product_price' => $this->input->post_get('product_price'),
                'mobile_no' => $this->input->post_get('mobile_no'),
                'alt_mobile_no' => $this->input->post_get('alt_mobile_no'),
                'landline_no' => $this->input->post_get('landline_no'),
                'email' => $this->input->post_get('email'),
                'location' => $this->input->post_get('location'),
                'gender' => $this->input->post_get('gender'),
                'dob' => $this->input->post_get('dob'),
                'aadhar_no' => $this->input->post_get('aadhar_no'),
                'product_category_id' => $this->input->post_get('product_category_id'),
                'lead_type_id' => $this->input->post_get('lead_type_id'),
                'added_by' => $this->input->post_get('added_by'),
                'added_date' => $c_date,
                'followup_date' => $this->input->post_get('followup_date'),
                'payment_type' => $this->input->post_get('payment_type'),
                'test_ride_taken'=>$this->input->post_get('test_ride_taken'),
                'customer_type'=>$this->input->post_get('customer_type'),
                'cus_int_exe'=>$this->input->post_get('cus_int_exe'),
                'remarks'=>$this->input->post_get('remarks'),
                'enquiry_status'=>$this->input->post_get('enquiry_status'),
                'updated_date'=>$updated_time,
                'branch_id'=>$this->input->post_get('branch_id')
                
            );

            if($this->input->post_get('lead_id')>0){
                $condition=array('lead_id'=>$this->input->post_get('lead_id'));
                $this->obj_common->edit('leads',$condition,$lead_array);
                $enq_id=$this->input->post_get('lead_id');
            }else{
                $enq_id = $this->obj_common->add('leads', $lead_array);
            }
            $res['enq_id'] = $enq_id;
            if($this->input->post_get('temp_lead_id')){
                $res['temp_lead_id'] = $this->input->post_get('temp_lead_id');
            }
            $res['status'] = 'success';
        } else {
            $res['message'] = 'Invalid api key';
        }             // }
        echo json_encode($res);
    }

    public function get_leads() {
        $lead_type_array = $this->obj_common->get_all('lead_type');
        foreach ($lead_type_array as $resarray) {
            $res_array[$resarray['lead_type_id']] = $resarray['Lead_type'];
        }
        $res['status'] = 'error';
        $api_key = $this->input->post_get('api_key');
        if ($api_key == $this->config->item('api_key')) {
            $lastFetchedTime=$this->input->post_get('lastFetchedTimeStamp');
            //echo $lastFetchedTimeStamp;
           // $lastFetchedTime = date('Y-m-d H:i:s',$lastFetchedTimeStamp);
            $limit=$this->input->post_get('limit');  
            if($lastFetchedTime==0){
                $condition = array();
            }else{
                $condition = array('updated_date < '=>$lastFetchedTime);
            }
          
            $total_rows = $this->obj_common->countrows('leads', $condition);
          
            $res_data = $this->obj_common->get_all_data('leads',$limit, $condition, 'updated_date', 'asc');
           
            $i = 0;
            foreach ($res_data as $results) {   
                if($results['lead_type_id']){
                    $res_data[$i]['lead_type_name'] = $res_array[$results['lead_type_id']];
                }
                $i++;
            }
            if ($i > 0) {
                $res['status'] = 'success';
                $res['totalLeadCount'] = $total_rows;
                $res['data'] = $res_data;
            }
        } else {
            $res['message'] = 'Invalid api key';
        }             // }
        echo json_encode($res);
    }

    public function lead_type() {
        $condition = array();
        $res['status'] = 'error';
        $result = $this->obj_common->get_all('lead_type', $condition);
        if ($res) {
            $res['status'] = 'success';
            $res['data'] = $result;
        }
        echo json_encode($res);
    }

    public function enquiry_source() {

        $condition = array();
        $res['status'] = 'error';
        $result = $this->obj_common->get_all('enquiry_source', $condition);
        if ($res) {
            $res['status'] = 'success';
            $res['data'] = $result;
        }
        echo json_encode($res);
    }
  public function vehicle_model() {
       $api_key = $this->input->post_get('api_key');
        if ($api_key == $this->config->item('api_key')) {
    $this->db->select('*');
    $query = $this->db->get('model');

    $results = array();

    foreach ($query->result_array() as $row)
    {
        if(!isset($results[$row['model_name']]))
            $results[$row['model_name']] = array('id'=> $row['model_id'],'name' => $row['model_name'], 'submodel' => array());
        $results[$row['model_name']]['submodel'][] = $row['sub_model'];
    }

    //Rekey arrays so they aren't associative
    $results = array_values($results);
    $res['status'] = 'error';
if ($res) {
            $res['status'] = 'success';
            $res['data'] = $results;
        }
    $test = json_encode($res);
    echo $test;
    return $results;
        }
}

    public function dashboard() {

        $res['status'] = 'error';
        $api_key = $this->input->post_get('api_key');
        if ($api_key == $this->config->item('api_key')) {
            
            $res_data['total_enquiry'] = 8;
            $res_data['closed'] = 2;
            $res_data['hot'] = 4;
            $res_data['warm'] = 9;
            $res_data['cold'] = 5;
            $res_data['today_followup'] = 1;
            $res_data['total_pending'] = 6;
            $res['status'] = 'success';
            $res['data'] = $res_data;
        } else {
            $res['message'] = 'Invalid api key';
        }             // }
        echo json_encode($res);
    }

}

//http://www.ugotechnologies.com/sterren/api/get_leads/[lead_type]/[pagination_start_from]?api_key=43a11e2c74bc458f9938e7a32bdedcd3275456c3

//http://www.ugotechnologies.com/sterren/api/dashboard/?api_key=43a11e2c74bc458f9938e7a32bdedcd3275456c3
//http://www.ugotechnologies.com/sterren/api/get_leads/2?api_key=43a11e2c74bc458f9938e7a32bdedcd3275456c3
//http://www.ugotechnologies.com/sterren/api/lead_type
//http://www.ugotechnologies.com/sterren/api/enquiry_source
//http://www.ugotechnologies.com/sterren/api/enqiry?api_key=43a11e2c74bc458f9938e7a32bdedcd3275456c3&enquiry_source=enquiry_source&customer_name=customer_name&product_price=100&mobile_no=11111&alt_mobile_no=alt_mobile_no&landline_no=landline_no&email=email&location=location&gender=gender&dob=2019-09-05&aadhar_no=aadhar_no&product_category_id=1&lead_type_id=2&added_by=3&followup_date=2019-09-05&lead_id=lead_id&
//lead_id=lead_id&payment_type=payment_type&test_ride_taken=yes&customer_type=N&cus_int_exe=yes&remarks=remarks&enquiry_status=enquiry_status&branch_id=1
 
//http://www.ugotechnologies.com/sterren/api/login?api_key=43a11e2c74bc458f9938e7a32bdedcd3275456c3&username=shitha&password=12345 
?>

Zerion Mini Shell 1.0