%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
<?php class Leads extends MY_Controller { function __construct() { parent::__construct(); not_logged_res(); ini_set('memory_limit', '2048M'); $this->checkAccess('lead_view'); $this->load->model("leads_model", "leads"); $this->load->model("master_model", "master"); $this->load->model("dataset_model", "dataset"); $this->load->model("user_model", "user"); } function init(){ $lvOpt=$this->dataset->detail(0, USER_ID); $states=$this->common->states(); $data['states']=[]; if($lvOpt['states']){ foreach($states as $i=>$r){ if(in_array($r['id'], $lvOpt['states'])){ $data['states'][]=$r; } } }else{ $data['states']=$states; } $cities=$this->common->cities(); $data['cities']=[]; if($lvOpt['cities']){ foreach($lvOpt['cities'] as $state_id=>$city_ids){ foreach($cities as $r){ if(in_array($r['id'], $city_ids)){ $data['cities'][]=$r; } } } } if(!$data['cities']){ $data['cities']=$cities; } $programs=$this->common->programs(); $data['programs']=[]; if($lvOpt['programs']){ foreach($programs as $i=>$r){ if(in_array($r['id'], $lvOpt['programs'])){ $data['programs'][]=$r; } } }else{ $data['programs']=$programs; } $utm_sources=$this->common->allUtmSources(true, true); $data['utm_sources']=[]; if($lvOpt['utm_sources']){ foreach($utm_sources as $i=>$r){ if(in_array($r['id'], $lvOpt['utm_sources'])){ $data['utm_sources'][]=$r; } } }else{ $data['utm_sources']=$utm_sources; } $data['lpages']=$this->common->allLandingPages(true); $data['utm_groups']=$this->common->utmGroups(true); $data['remarks_cats']=$this->leads->remarks_cats(); $data['remarks']=$this->leads->remarks(); $data['lead_restrict']=LEAD_RESTRICT; $data['appointment_times']=appointment_times(); $data['users']=$this->user->active_users(!IS_ADMIN); $data['USER_ID']=USER_ID; $this->json_data($data); } function lists(){ $qs=trim_array($_REQUEST); if(LEAD_RESTRICT){ $_REQUEST['fromDate']=''; $_REQUEST['toDate']=''; if(!$qs['k']){ $data['result']=[]; }else{ $data=$this->leads->lists(); } }else{ if($qs['step_completed'] && in_array('0', $qs['step_completed'])){ $data=$this->leads->listsStepZero(); }else{ $data=$this->leads->lists(); } } $this->json_data($data); } function exportLists(){ $qs=trim_array($_REQUEST); $data=$this->leads->lists(TRUE); download_leads_csv($data['result'], leadsKeysLabels()); } function save(){ $post=trim_array($this->input->post()); $inf=array('success'=>false, 'msg'=>'Error!','errors'=>array()); $id=$post['id']=(int)$post['id']; if(!$id){ $this->checkAccess('lead_add'); $defaultUtmSource = $this->db->from('master_utm_sources')->where(['default_for_admin'=>'1'])->select('id,title')->limit(1)->get()->row_array(); if($defaultUtmSource){ $post['utm_source_id']=$defaultUtmSource['id']; $post['utm_source']=$defaultUtmSource['title']; } }else{ $this->checkAccess('lead_edit'); } $this->form_validation->set_rules('name', 'Name', "required|callback_valid_name", $this->req); $this->form_validation->set_rules('email', 'Email', "required|valid_email|is_unique[applicants.email.id!='$id']", $this->req); $this->form_validation->set_rules('mob', 'mob', "required|integer|exact_length[10]|is_unique[applicants.mob.id!='$id']", $this->req); $this->form_validation->set_rules('state_id', 'State', "required", $this->req); $this->form_validation->set_rules('program_id', 'Center of Excellence', "required", $this->req); $this->form_validation->set_rules('appointment_date', 'Appointment date', "required|callback_valid_date", $this->req); $this->form_validation->set_rules('appointment_time', 'Appointment time', "required", $this->req); /* $this->form_validation->set_rules('lpage_id', 'Landing page', "required", $this->req); */ if(@$this->form_validation->run() == FALSE){ $inf['errors']=$this->form_validation->get_errors(); $inf['msg']=reset($inf['errors']); }else if(!$id && !$defaultUtmSource){ $inf['msg']="No Default Lead Source Found"; }else{ if((!$post['city_id'] || $post['city_id']<=0) && !$post['city']){ $inf['msg']="City is required"; $this->json_data($inf); } if(!$id){ if(strtotime($post['appointment_date'])<=strtotime(date('Y-m-d'))){ $inf['msg']="Apointment date must be future date"; $this->json_data($inf); } } if($post['city_id'] && $post['city_id']>0){ $post['city']=$this->db->select("title")->get_where("master_cities", ['id'=>$post['city_id']])->row()->title; } $data=filter_value($post, array('id', 'name', 'email', 'mob', 'state_id', 'city_id', 'city', 'address', 'pincode', 'program_id', 'lpage_id','utm_source_id','utm_source')); $data['appointment_datetime']=get_date($post['appointment_date'], '', 'Y-m-d').' '.get_date($post['appointment_time'], '', 'H:i:s'); if($this->leads->save($data)){ $inf['success']=true; $inf['msg']='Lead '.($id?'updated':'created').' successfully'; } } $this->json_data($inf); } /** */ function detail_to_edit($id=0){ $data['dtl']=$this->leads->detail_to_edit($id); $this->json_data($data); } function detail($id=0){ $data['dtl']=$this->leads->detail($id); $data['followups']=$this->leads->get_follow_ups($id); $this->json_data($data); } function delete(){ $this->checkAccess('lead_delete'); $inf=array('success'=>'F', 'msg'=>'Can not deleted!'); $id=intval($this->input->post('id')); if($this->leads->delete($id)){ $inf['success']='T'; $inf['msg']="Lead deleted successfully"; } $this->json_data($inf); } /** Follow-up */ function get_follow_ups($id=''){ $data['result']=$this->leads->get_follow_ups($id); $this->json_data($data); } function follow_up_detail($id=0){ $data=$this->leads->follow_up_detail($id); $this->json_data($data); } function save_follow_up(){ $post=trim_array($this->input->post()); $inf=array('success'=>false, 'msg'=>'Error!', 'result'=>null); $id=$post['id']=(int)$post['id']; $this->form_validation->set_rules('applicant_id', 'Applicant', "required", $this->req); $this->form_validation->set_rules('remarks_id', 'Disposition', "required", $this->req); $this->form_validation->set_rules('subremarks', 'Remarks', "required", $this->req); $this->form_validation->set_rules('feedback', 'Comment', "required", $this->req); if(@$this->form_validation->run() == FALSE){ $inf['errors']=$this->form_validation->get_errors(); $inf['msg']=reset($inf['errors']); }else{ $data=filter_value($post, array('id', 'applicant_id', 'remarks_id', 'subremarks', 'feedback')); if($id=$this->common->save($data, "applicants_remarks")){ $d=['id'=>$data['applicant_id'], 'followup_by'=>USER_ID, 'last_followup_id'=>$id]; $this->dba->save("applicants", $d); $inf['followup_by']=USER_ID; $inf['success']=true; $inf['result']=$this->leads->get_follow_ups($data['applicant_id']); $inf['msg']='Remarks/Comments '.($id?'updated':'added').' successfully'; } } $this->json_data($inf); } function delete_follow_up(){ $inf=array('success'=>false, 'msg'=>'Can not deleted!'); $id=intval($this->input->post('id')); $ar=$this->db->from('applicants_remarks')->select('applicant_id')->where(['id'=>$id])->get()->row_array(); if($this->leads->delete_follow_up($id)){ $d=['id'=>$ar['applicant_id'], 'followup_by'=>0, 'last_followup_id'=>0]; $lastFB=$this->db->from('applicants_remarks')->select('id, created_by')->where(['applicant_id'=>$ar['applicant_id']])->order_by("id", "DESC")->limit(1)->get()->row_array(); if($lastFB){ $d['followup_by']=$lastFB['created_by']; $d['last_followup_id']=$lastFB['id']; } $this->dba->save("applicants", $d); $inf['followup_by']=$d['followup_by']; $inf['success']=true; $inf['result']=$this->leads->get_follow_ups($ar['applicant_id']); $inf['msg']="remark/feedback successfully"; } $this->json_data($inf); } } //EOF