MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/crm_cafsindia_com/application/controllers/Other_campaigns.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once("Secure_Controller.php");
class Other_campaigns extends Secure_Controller{

    public function __construct(){
        parent::__construct('other_campaigns');
        $this->load->model('Other_campaigns_model');
        $this->load->model('All_leads_model');
        $this->load->model('Customer');
    }

    public function index(){
        if(!$this->Appconfig->isAppvalid()){
                redirect('config');
        }
        $data['table_headers'] = $this->xss_clean(get_other_campaigns_table_headers());
       // $data = "";
        $this->load->view('other_campaigns/manage',$data);
    }
    public function search(){
        $search = $this->input->get('search');
        $limit = $this->input->get('limit');
        $offset = $this->input->get('offset');
        $sort = $this->input->get('sort');
        $order = $this->input->get('order');
        $filters = array('start_date' => $this->input->get('start_date'), 'end_date' => $this->input->get('end_date'));

        $all_leads = $this->Other_campaigns_model->search($search, $filters, $limit, $offset, $sort, $order);
        $total_rows = $this->Other_campaigns_model->get_found_rows($search, $filters);
        $data_rows = array();
        foreach($all_leads->result() as $leads){
            $data_rows[] = get_other_campaigns_row($leads, $this);
        }
        echo json_encode(array('total' => $total_rows, 'rows' => $data_rows));
    }

    public function get_row($lead_ids){
        $lead_infos = $this->Other_campaigns_model->get_multiple_info($lead_ids);
        $result = array();
        foreach($lead_infos as $lead_info){
            $result[$lead_info->lead_id] = $this->xss_clean(get_item_data_row($lead_info, $this));
        }
        echo json_encode($result);
    }

    public function view($lead_id = -1){

        $emp_role = $this->session->userdata('emp_role');
        $info = $this->Other_campaigns_model->get_info($lead_id);
        foreach(get_object_vars($info) as $property => $value){
            $info->$property = $this->xss_clean($value);
        }
        $data['lead_info']     = $info;
        $data['existing_lead'] = $this->All_leads_model->get_leads_custid($info->cust_id);

        $met_info = $this->Other_campaigns_model->get_met_log($lead_id);
        $data['met_info'] = $met_info;

        $category_info[""] = "---- Select Category ----";
        foreach($this->Other_campaigns_model->get_category() as $row){
			if($row->cat_id !== '1'){
				$category_info[$this->xss_clean($row->cat_id)] = $this->xss_clean($row->cat_name);
			}
        }
        $data['category_info'] = $category_info;

        $company_info[""] = "---- Select Company ----";

        foreach($this->Other_campaigns_model->get_company() as $row){
            $company_info[$this->xss_clean($row->vendor_id)] = $this->xss_clean($row->vendorcompanyname);
        }
        $data['company_info'] = $company_info;

        $lead_status[""] = "---- Select Lead Status ----";
        foreach($this->Other_campaigns_model->get_status() as $row){
            $lead_status[$this->xss_clean($row->status_id)] = $this->xss_clean($row->statusname);
        }
        $data['lead_status'] = $lead_status;

        $prospect_info[""] = "---- Select Prospect----";
        foreach($this->Other_campaigns_model->get_prospect()->result_array() as $row){
          $prospect_info[$this->xss_clean($row['prospect_id'])] = $this->xss_clean($row['prospect_name']);
        }
        $data['prospect'] = $prospect_info;

        $tl_info[""] = "---- Select Team Leader----";
        if(($emp_role === "9") || ($emp_role === "10")){
            $tl_info[""] = "---- Select Area Manager----";
        }
        foreach($this->Other_campaigns_model->get_tl()->result_array() as $row){
          $tl_info[$this->xss_clean($row['id'])] = $this->xss_clean($row['first_name'] ." - ".$row['cat_name']);
        }
        $data['tl_info'] = $tl_info;

        $crm_info[""] = "---- Select CRM----";
        foreach($this->Other_campaigns_model->get_crm()->result_array() as $row){
          $crm_info[$this->xss_clean($row['id'])] = $this->xss_clean($row['first_name']);
        }
        $data['crm_info'] = $crm_info;

        $rm_info[""] = "---- Select RM----";
        foreach($this->Other_campaigns_model->get_rm()->result_array() as $row){
          $rm_info[$this->xss_clean($row['id'])] = $this->xss_clean($row['first_name']);
        }
        $data['rm_info'] = $rm_info;

        $this->load->view("other_campaigns/form", $data);
    }
    public function save($leads_info = -1){
        $role    = $this->session->userdata('emp_role');
        $mobile  = $this->input->post('cust_mobile');
        $cust_id = $this->Customer->mob_exists($mobile);
        if(!$cust_id){
            $customer_data = array(
                'cust_name'    => $this->input->post('cust_name'),
                'cust_mobile'  => $this->input->post('cust_mobile'),
                'cust_address' => $this->input->post('cust_address'),
                'cust_email'   => "",
                'created_by'   => $this->session->userdata('emp_id'),
                'created_date'   => date('Y-m-d h:i:s'),
            );
            $cust_id = $this->Customer->lead_save_customer($customer_data, $mobile);
        }

        $lead_id = $this->Other_campaigns_model->save_lead($cust_id, $leads_info);
        $current_control = $this->session->userdata('emp_id');
        $prospect_level  = $this->input->post('prospect_level');
        $crm_name = $this->input->post('crm_name');
        $tl = $this->input->post('team_leader');        
        $category = $this->input->post('category');
        if(!$crm_name){
          $crm_name =  $this->session->userdata('emp_id');
        }
        if($this->input->post('lead_status') === "4"){
          $current_control = $this->session->userdata('area_manager');
        }
        if($this->input->post('lead_status') === "5"){
          $current_control = $this->session->userdata('area_manager');
        }
        if($this->input->post('lead_status') === "6"){
          $current_control = $this->input->post('rm_name');
        }
        if(($this->input->post('lead_status') === "5") && ($role === "5")){
          $current_control = $this->session->userdata('rm_manager');
        }
        if(($this->input->post('lead_status') === "5") && ($role === "8")){
          $current_control = $this->session->userdata('re_manager');
        }        
        if((($this->input->post('lead_status') === "8") && ($category === "4"))  || (($this->input->post('lead_status') === "8") && ($category === "5"))){
            $current_control = "MIS";
        }
        if(($this->input->post('lead_status') === "8") && ($role === "5")){
          $current_control = "MIS";
        }
        if(($this->input->post('prospect_level') === "4") && ($role === "5")){
          $current_control = "MIS";
        }
        if($this->input->post('lead_status') === "3"){
          $prospect_level = '3';
        }
        if($role === "4"){
            $crm_name =  $this->input->post('hd_crm_name');
        }

        if($this->input->post('generated_by') === "1"){
            $current_control = $this->input->post('team_leader');
        }

        //Only for Other Campaigns
        $lead_status = $this->input->post('lead_status');
        $lead_mode = "2";
        if(!$category){
            $category = $this->session->userdata('emp_category');
        }
        if(($this->input->post('category') === "1") && ($this->input->post('lead_status') === "4")){
            $current_control = "MIS";
            $lead_status     = "8";
        }else
        if(($this->input->post('category') === "5") && ($this->input->post('lead_status') === "4")){
            $current_control = "MIS";
            $lead_status     = "8";
        }else
        if(($role === "6") && ($this->input->post('lead_status') === "5") && ($this->input->post('crm_name'))){
            $current_control = $this->input->post('crm_name');
            $lead_mode = "1";
        }
        //Sathish Deleted
        /*
        else
        if(($this->input->post('category') === "4") && ($this->input->post('lead_status') === "4")){
            $current_control = "MIS";
            $lead_status     = "8";
        } */
		
		// UDY Added Only for MF lead Flow - 10-JULY-2018
		if((($this->input->post('category') === "4") && ($this->input->post('lead_status') === "1")) || (($this->input->post('category') === "4") && ($this->input->post('lead_status') === "2")) || (($this->input->post('category') === "4") && ($this->input->post('lead_status') === "3")) || (($this->input->post('category') === "4") && ($this->input->post('lead_status') === "5"))){
			$current_control = $this->session->userdata('emp_id');
		}
		if(($this->input->post('category') === "4") && ($this->input->post('lead_status') === "8")){
			$current_control = "MF";
			//$current_control = $this->session->userdata('emp_id');
		}
        $rm_name = "";
        if(($this->input->post('category') === "4") && ($role === "5")){
            $crm_name = "";
            $rm_name = $this->session->userdata('emp_id');
        }

        $lead_info_data = array(
            'lead_id'           => $lead_id,
            'category'          => $category,
            'company'           => $this->input->post('company'),
            'lead_type'         => "1",
            'lead_status'       => $lead_status,
            'prospect_level'    => $prospect_level,
            'ncd'               => date('Y-m-d',strtotime($this->input->post('ncd'))),
            'remarks'           => $this->input->post('remarks'),
            'expected_value'    => $this->input->post('expected_value'),
            'expected_login'    => $this->input->post('expected_login'),
            'mf_prospect'       => $this->input->post('mf_prospect'),
            'mf_expected_value' => $this->input->post('mf_expected_value'),
            'mf_login_value'    => $this->input->post('mf_login_value'),
            'crm_name'          => $crm_name,
            'rm_name'           => $rm_name,
            'team_leader'       => $tl,
            'generated_by'      => $this->input->post('generated_by'),
            'current_control'   => $current_control,
            'lead_mode'         => $lead_mode,
        );
		
        if($this->Other_campaigns_model->save_lead_info($lead_info_data,$leads_info)){
            $lead_info_data = $this->xss_clean($lead_info_data);
            $cus_lead_id = $lead_info_data['lead_id'];
            $cust_name = $this->All_leads_model->get_cust_name($cus_lead_id);
            if($leads_info === -1){
                echo json_encode(array('success' => TRUE, 'message' => "Lead Added ".' '. $cust_name, 'id' => $lead_info_data['lead_id']));
            }else {
                echo json_encode(array('success' => TRUE, 'message' => "Lead Updated".' '. $cust_name, 'id' => $leads_info));
            }
        }else{
            $lead_info_data = $this->xss_clean($lead_info_data);
            echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('lead_error_adding_updating').' '.$lead_info_data['lead_id'], 'id' => -1));
        }
    }
    public function get_leadstatus($status){
      $status = $this->Other_campaigns_model->get_lead_status_byid($status)->row();
      echo $status->statusname;
    }
    public function get_product(){
		$category = $this->input->post('category');
		$product_info = $this->Other_campaigns_model->get_product($category);
		echo json_encode(array('success' => TRUE, 'product_info' => $product_info));
    }
	public function get_mobile($mobile){
      $result = $this->Other_campaigns_model->get_existing_data($mobile);
      $count  = $result->num_rows();
      if($count === 1){
        $cust_info = $result->row();
        $cust_id = $cust_info->cust_id;
        $lead_data    = $this->Other_campaigns_model->get_leads_custid($cust_id);
        echo json_encode(array('status' =>"SUCCESS", 'cust_info' => $cust_info,'lead_data'=>$lead_data));
      }else{
        echo json_encode(array('status' =>"NEW", 'cust_info' => $cust_info,'lead_data'=>$lead_data));
      }
    }
    public function delete() { 
      $leads_to_delete = $this->xss_clean($this->input->post('ids'));
      if($this->All_leads_model->delete_list($leads_to_delete)){
        echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('leads_successful_deleted').' '.
                count($leads_to_delete).' '.leads));
      }else{
        echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('leads_cannot_be_deleted')));
      }
    }
}
?>