%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 Vendorapi extends CI_Controller { function __construct() { parent::__construct(); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Credentials: true'); header('Access-Control-Allow-Headers: Content-Type, Origin, Accept, token'); if(strtolower($_SERVER['REQUEST_METHOD'])==='options'){ header('HTTP/1.1 200 OK'); header('Access-Control-Allow-Headers: Content-Type, Origin, Accept, token'); header('Access-Control-Allow-Methods: POST, GET, OPTIONS'); header('Access-Control-Max-Age: 86400'); die; } $headers=getallheaders(); if(strpos($headers['Content-Type'], 'application/json')!==FALSE){ $data=json_decode(file_get_contents("php://input"), true); $_POST=$data?$data:[]; unset($data); } $this->states=[ 'Andaman Nicobar Islands'=>'AN', 'Andhra Pradesh'=>'AP', 'Arunachal Pradesh'=>'AR', 'Assam'=>'AS', 'Bihar'=>'BR', 'Chandigarh'=>'CT', 'Chhattisgarh'=>'CH', 'Dadra And Nagar Haveli'=>'DN', 'Daman & Diu'=>'DD', 'Delhi'=>'DL', 'Goa'=>'GA', 'Gujarat'=>'GJ', 'Haryana'=>'HR', 'Himachal Pradesh'=>'HP', 'Jammu and Kashmir'=>'JK', 'Jharkhand'=>'JH', 'Karnataka'=>'KA', 'Kerala'=>'KL', 'Lakshadweep'=>'LA', 'Madhya Pradesh'=>'MP', 'Maharashtra'=>'MH', 'Manipur'=>'MN', 'Meghalaya'=>'ML', 'Mizoram'=>'MZ', 'Nagaland'=>'NG', 'Orissa'=>'OR', 'Pondicherry'=>'PY', 'Punjab'=>'PB', 'Rajasthan'=>'RJ', 'Sikkim'=>'SK', 'Tamil Nadu'=>'TN', 'Telangana'=>'TS', 'Tripura'=>'TR', 'Uttar Pradesh'=>'UP', 'Uttarakhand'=>'UT', 'West Bengal'=>'WB', ]; ini_set('memory_limit', '2048M'); set_time_limit(3000); session_write_close(); date_default_timezone_set('Asia/Kolkata'); $this->load->model("leads_model", "leads"); $token=$this->input->get_request_header("token"); if(!$token){ $token=$_POST['token']; } define('TOKEN', $token); define('USER_EMAIL', ''); /* 200 = Success 401 = Authentication failed 403 = Error/Data Missing 405 = Rejected (Duplicate lead) 406 = Rejected (State not allowed) 407 = Rejected (Crossed daily limit) */ } function addLeadTest(){ $res=['code'=>403, 'msg'=>'Error!']; $post=trim_array($this->input->post()); if(TOKEN!=='test-token'){ $res['code']=401; $res['msg']="Authentication failed!"; json_data($res); } if(!$post['mobile']){ $res['msg']="mobile required!"; json_data($res); } if(!$post['email']){ $res['msg']="email required!"; json_data($res); } if(!$post['name']){ $res['msg']="name required!"; json_data($res); } if(!$post['state_code']){ $res['msg']="state_code required!"; json_data($res); } if(strlen($post['state_code'])>2){ $post['state_code']=$this->states[$post['state_code']]; } if(!$post['program_name']){ $res['msg']="program_name required!"; json_data($res); } if(!$post['plan_name']){ //$res['msg']="plan_name required!"; //json_data($res); } $res['code']=200; $res['msg']="Success"; $res['data']=$post; //@file_put_contents("logs/".time().".html", json_encode($res)); json_data($res); } function addLead(){ $this->load->model("common_model", "common"); $res=['code'=>403, 'msg'=>'Error!']; $post=trim_array($this->input->post()); if(TOKEN==='test-token'){ $this->addLeadTest(); return; } $pdtl=$this->db->get_where("pub_api_config", ['auth_token'=>TOKEN])->row_array(); if(!$pdtl){ $res['code']=401; $res['msg']="Authentication failed!"; json_data($res); } if($pdtl['api_enabled']!=='Y'){ $res['msg']="Api is not enabled!"; json_data($res); } $publisher_id=(int)$pdtl['user_id']; define('USER_ID', $publisher_id); $daily_limit=(int)$pdtl['daily_limit']; $utm_source_id=(int)$pdtl['utm_source_id']; $utm_source=$this->db->select("title")->get_where("master_utm_sources", ['id'=>$utm_source_id])->row()->title; $state_codes=explode(",", $pdtl['state_codes']); //$lpage_id=$this->db->select("id")->get_where("landing_pages", ['isdefault'=>1])->row()->id; $lpage_id=136; if(!$lpage_id){ $res['msg']="Contact admin!"; json_data($res); } if(!$post['mobile']){ $res['msg']="mobile required!"; json_data($res); } if(strlen($post['mobile'])!==10){ $res['msg']="mobile must be 10 digits long!"; json_data($res); } if(!ctype_digit($post['mobile'])){ $res['msg']="mobile must be numeric!"; json_data($res); } if(!$post['email']){ $res['msg']="email required!"; json_data($res); } if(!is_email($post['email'])){ $res['msg']="email is not valid!"; json_data($res); } if(!$post['name']){ $res['msg']="name required!"; json_data($res); } if(!$post['state_code']){ $res['msg']="state_code required!"; json_data($res); } if(strlen($post['state_code'])>2){ $post['state_code']=$this->states[$post['state_code']]; } $state_id=$this->db->get_where("master_states", ['code'=>$post['state_code']])->row("id"); if(!$post['program_name']){ $res['msg']="program_name required!"; json_data($res); } if(!$post['plan_name']){ //$res['msg']="plan_name required!"; //json_data($res); } $d=[ 'publisher_id'=>$publisher_id, 'lpage_id'=>$lpage_id, 'state_code'=>$post['state_code'], 'mobile'=>$post['mobile'], 'email'=>$post['email'], 'name'=>$post['name'], 'program_name'=>$post['program_name'], 'plan_name'=>$post['plan_name'], 'created'=>currentDT(), ]; if(!$state_id){ $res['msg']="state_code is not valid!"; $d['status']='REJECTED'; $d['rejection_code']=$res['code']; $d['rejection_msg']=$res['msg']; $this->dba->save("api_leads", $d); json_data($res); } if($this->db->select("id")->get_where("applicants", ['mob'=>$d['mobile']])->row("id")){ $res['code']=405; $res['msg']="Rejected (Duplicate lead - Mobile)"; $d['status']='REJECTED'; $d['rejection_code']=$res['code']; $d['rejection_msg']=$res['msg']; $id=$this->dba->save("api_leads", $d); $mrd=[ 'lpage_id'=>$lpage_id, 'mob'=>$d['mobile'], 'utm_source'=>$utm_source?$utm_source:'', 'is_from_api'=>1, 'created'=>currentDT() ]; $this->db->insert("multi_registration_tried", $mrd); }elseif($this->db->select("id")->get_where("applicants", ['email'=>$d['email']])->row("id")){ $res['code']=405; $res['msg']="Rejected (Duplicate lead - Email)"; $d['status']='REJECTED'; $d['rejection_code']=$res['code']; $d['rejection_msg']=$res['msg']; $id=$this->dba->save("api_leads", $d); }elseif(!in_array($d['state_code'], $state_codes)){ $res['code']=406; $res['msg']="Rejected (State not allowed)"; $d['status']='REJECTED'; $d['rejection_code']=$res['code']; $d['rejection_msg']=$res['msg']; $id=$this->dba->save("api_leads", $d); }else{ $today=date('Y-m-d'); $cond=['publisher_id'=>$publisher_id, 'status'=>'SUCCESS', 'created>='=>$today, 'created<='=>$today.' 23:59:59']; $n=(int)$this->db->select("COUNT(id) n")->get_where("api_leads", $cond)->row("n"); if($n>=$daily_limit){ $res['code']=407; $res['msg']="Rejected (Crossed daily limit of $daily_limit)"; $d['status']='REJECTED'; $d['rejection_code']=$res['code']; $d['rejection_msg']=$res['msg']; $id=$this->dba->save("api_leads", $d); }else{ $err=FALSE; $this->db->trans_strict(FALSE); $this->db->trans_begin(); try{ $d['status']='SUCCESS'; $id=$this->dba->save("api_leads", $d); if($id){ $data=[ 'lpage_id'=>$lpage_id, 'name'=>$d['name'], 'email'=>$d['email'], 'mob'=>$d['mobile'], 'state_id'=>$state_id, 'utm_source_id'=>$utm_source_id, 'utm_source'=>$utm_source?$utm_source:'' ]; $applicant_id=$this->dba->save("applicants", $data); if($applicant_id){ $data=[ 'api_lead_id'=>$id, 'applicant_id'=>$applicant_id, 'step_completed'=>0 ]; $num=$this->leads->getCounter('application_no_count'); $data['application_no']=zero_format_no($num); $app_id=$this->dba->save("applications", $data); if($app_id){ $res['code']=200; $res['msg']='Success'; $this->common->sendSystemIdGenMsg($app_id); } } } }catch(Exception $e) { $err = TRUE; $msg = $e->getMessage(); } if($this->db->trans_status() === FALSE) { $err = TRUE; } if($err){ $this->db->trans_rollback(); }else{ $this->db->trans_commit(); } } } json_data($res); } } //EOF