/application/controllers/customer/master.php
PHP | 1597 lines | 1145 code | 114 blank | 338 comment | 130 complexity | e66237e858eec354975262f6f9be3e27 MD5 | raw file
Possible License(s): GPL-2.0, MIT, LGPL-3.0, LGPL-2.1, GPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- class master extends CI_Controller
- {
- /*------------------------------------------------------------------------------*/
- /* Beginning of master data customer */
- /*------------------------------------------------------------------------------*/
-
- private $IdNegara;
- function __construct()
- {
- parent::__construct();
- $this->load->library(array("jqlib","mnuauth"));
- $this->load->helper("form");
- $this->lang->load("abdi");
- $this->config->load('sqlconfig', TRUE);
-
- global $jqQr;
- global $jqField;
- global $jqID;
- global $jqRowIgnored;
- global $path_self;
- global $start;
-
- #$this->session->set_userdata('idNegara', 'MY');
- $userCountry= $this->Gmodel->getClinicInfo($this->session->userdata("IdKlinik"))->row();
- if(strtoupper($this->session->userdata('username'))=='MANFRED')
- {
- $sqlinvoice="";
- $sqlRestricted = '';
- }else{
- $sqlinvoice=", if(
- (select count(zz.isLunas) from invoice zz where zz.idkonsumen=a.idkonsumen and zz.isLunas='0')>0,
- 'Not Fully Paid',if((select count(za.isLunas) from invoice za where za.idkonsumen=a.idkonsumen and za.isLunas='1')>0,'Paid in Full','')
- ) as Invoice";
- $sqlRestricted = "
- INNER JOIN user d
- ON a.AddUser = d.Username
- INNER JOIN klinik e
- ON d.IdKlinik = e.IdKlinik
- LEFT JOIN invoice i ON i.IdKonsumen = a.IdKonsumen
- WHERE e.IdNegara = '" . $userCountry->IdNegara . "'
- ";
- /*
- $sqlRestricted = "
- INNER JOIN user d
- ON a.AddUser = d.Username
- INNER JOIN klinik e
- ON d.IdKlinik = e.IdKlinik
- WHERE e.IdNegara = ''";
- */
- }
-
- $userCountry= $this->Gmodel->getClinicInfo($this->session->userdata("IdKlinik"))->row();
-
-
- $IdNegara=$this->session->userdata('idNegara');
- $reg_country= "#^(ID)$#";
- if( preg_match($reg_country, $IdNegara) ){
- $this->jqsql= "
- SELECT a.IdKonsumen, a.NamaAwal, a.NamaAkhir, a.Email, a.NoHP,
- CASE a.JenisKelamin
- WHEN '0' THEN 'Female'
- WHEN '1' THEN 'Male'
- ELSE 'Not set' END AS Sex,
- CASE a.TanggalLahir
- WHEN null THEN '0'
- ELSE F_GET_AGE(a.TanggalLahir) END AS Age,
- b.Agama, c.NamaPekerjaan,
- CASE a.KonsumenStatus
- WHEN '0' THEN 'Pending'
- WHEN '1' THEN 'Active'
- WHEN '2' THEN 'Opt Out'
- ELSE 'Deceased'
- END AS Status,
- a.AddUser,
- DATE_FORMAT(TanggalLahir, '%d-%m-%Y') AS TanggalLahir
- , DATE_FORMAT(TanggalLahir, '%d-%M-%Y') AS TanggalLahir2
- $sqlinvoice
- FROM konsumen a
- LEFT JOIN m_agama b
- ON a.IdAgama = b.IdAgama
- LEFT JOIN m_pekerjaan c
- ON a.IdPekerjaan = c.IdPekerjaan
- $sqlRestricted
- GROUP BY a.IdKonsumen
- ORDER BY NamaAwal";
- }else{
- $this->jqsql= "
- SELECT a.IdKonsumen, a.NamaAkhir, a.NamaAwal, a.Email, a.NoHP,
- CASE a.JenisKelamin
- WHEN '0' THEN 'Female'
- WHEN '1' THEN 'Male'
- ELSE 'Not set' END AS Sex,
- CASE a.TanggalLahir
- WHEN null THEN '0'
- ELSE F_GET_AGE(a.TanggalLahir) END AS Age,
- b.Agama, c.NamaPekerjaan,
- CASE a.KonsumenStatus
- WHEN '0' THEN 'Pending'
- WHEN '1' THEN 'Active'
- WHEN '2' THEN 'Opt Out'
- ELSE 'Deceased'
- END AS Status,
- a.AddUser,
- DATE_FORMAT(TanggalLahir, '%d-%m-%Y') AS TanggalLahir
- , DATE_FORMAT(TanggalLahir, '%d-%M-%Y') AS TanggalLahir2
- $sqlinvoice
- FROM konsumen a
- LEFT JOIN m_agama b
- ON a.IdAgama = b.IdAgama
- LEFT JOIN m_pekerjaan c
- ON a.IdPekerjaan = c.IdPekerjaan
- $sqlRestricted
- GROUP BY a.IdKonsumen
- ORDER BY NamaAkhir";
- }
- /*
- CONCAT(DAY(a.TanggalLahir) ,' ', MONTHNAME(a.TanggalLahir), ' ', YEAR(a.TanggalLahir)) AS TanggalLahir
- print_r($this->jqsql);
- exit;
- echo $this->db->last_query();
- exit;
- */
-
- $this->IdNegara= $this->session->userdata("idNegara");
-
- $IdNegara= $this->IdNegara;
- $lc_group= array("SG"=>"en_GB", "KR"=>"en_GB", "ID"=>"id_ID", "MY"=>"en_GB");
- $this->db->query("SET lc_time_names = '" . $lc_group[$IdNegara] . "'");
-
- $this->jqID = "IdKonsumen";
- $this->jqRowIgnored = "IdKonsumen";
- #$this->jqRowIgnored = array("IdKonsumen", "TanggalLahir2");
- $rownum= 10;
- $this->jqQr= $this->Gmodel->jqGrid($this->jqsql, $rownum);
- //Untuk tes dapetin query
- /*
- echo $this->db->last_query();
- exit;
- */
- $this->jqField = $this->jqQr["query"]->list_fields();
-
- //returning the sequence number of rows
- $this->start = $this->jqQr["start"];
-
- $this->path_self = $this->uri->segment("2") . "/" . __CLASS__ . "/";
-
- $this->IdNegara= $this->session->userdata('idNegara');
- if($this->session->userdata('login')!==TRUE){
- redirect($this->configlib->site_url().'/login');
- }
- }
-
- function cek_config(){
- $data= $this->config->item('sqlconfig');
- print_r($data);
- }
-
- //Function to show the jqgrid table
- function getlist()
- {
- $this->jqlib->data = $this->jqQr;
- $this->jqlib->rowlist = $this->jqField;
- $this->jqlib->rowIgnored = $this->jqRowIgnored;
- /*
- $this->jqlib->customColName = array(lang("abdi.id_customer"), lang("abdi.first_name"),lang("abdi.last_name"),"Email",lang("abdi.mobile_no"),lang("abdi.sex"),lang("abdi.age"),lang("abdi.religion"),lang("abdi.pekerjaan"),lang("abdi.status"),lang("abdi.add_user"));
- $this->jqlib->colWidth = array("100","100","100","150","120","80","50","120","150","100","100","100");
- */
- $IdNegara=$this->session->userdata('idNegara');
- $reg_country= "#^(ID)$#";
- if( preg_match($reg_country, $IdNegara) ){
- $this->jqlib->customColName = array(lang("abdi.first_name"),lang("abdi.last_name"),
- lang("abdi.email"),lang("abdi.mobile_no"),lang("abdi.sex"),lang("abdi.age"),lang("abdi.religion"),
- lang("abdi.pekerjaan"),lang("abdi.status"),lang("abdi.add_user"),"Birth Date","Status Invoice");
- }else{
- $this->jqlib->customColName = array(lang("abdi.last_name"),lang("abdi.first_name"),
- lang("abdi.email"),lang("abdi.mobile_no"),lang("abdi.sex"),lang("abdi.age"),lang("abdi.religion"),
- lang("abdi.pekerjaan"),lang("abdi.status"),lang("abdi.add_user"),"Birth Date","Status Invoice");
- }
- $this->jqlib->colWidth = array("100","150","120","80","50","120","150","100","100","100","150","100");
- $this->jqlib->caption = lang("abdi.basic_info");
- $this->jqlib->url = "/" . $this->path_self . "xml/null";
- #$this->jqlib->url = "/" . $this->path_self . "xml";
- $this->jqlib->sortname = "NamaAwal";
- $data["jscript"] = $this->jqlib->stream() . $this->extra_js();
- $data["frmID"] = "frmAddCus"; //form default ID, this id will be called when edit button clicked
- $data['extramenu']= '<img src="' . $this->config->item("img_url") . '/browse.png" id="btnCari" ' .
- 'title="Search" style="cursor: pointer;" width= 32 height=32 />';
- $data['extramenu'].= '<img src="' . $this->config->item("img_url") . '/book-search.png" id="btnLastVisit" ' .
- 'title=" Show last 10 visited customers" style="cursor: pointer;" />';
- $data['extramenu'].= '<img src="' . $this->config->item("img_url") . '/view_detail.png" id="btnCustDetail" ' .
- 'title="View Detail" style="cursor: pointer;" />';
-
- //$data['extramenu'].= '<button id="btnhidden" name="btnhidden">Hidden</button>';
- show_template("vCommon",$data);
- }
-
- function datashow(){
- $this->xml("newcus", "02006000000056");
- #$this->xml("", true);
- }
-
- function xml($id="", $lastVisit=false)
- {
- /*
- print_r($this->jqQr['query']->result_array());
- exit;
- */
- $idAkses= $this->session->userdata("idAkses");
- if($id == "" && preg_match("#^(SUA|CST|DIR|MGR|MEX|DPS)$#", $idAkses) ){ // Fetch Untuk Default
- /*
- $this->jqlib->IgnoredRow= array("IdKonsumen","TanggalLahir");
- echo $this->jqlib->createXML($this->jqQr,$this->jqID,$this->jqField,$this->jqRowIgnored,$this->start);
- */
- #$this->jqlib->IgnoredRow= array("TanggalLahir");
- echo $this->jqlib->XML($this->jqQr,$this->jqID,$this->jqField,$this->jqRowIgnored,$this->start);
- }elseif($id == "newcus"){ // Fetch Untuk New Customer
- $sql = "SELECT * FROM (" . $this->jqsql . ") AS x WHERE IdKonsumen= '" . $lastVisit . "'";
-
-
-
-
-
- $jqQr = $this->Gmodel->jqGrid($sql);
- $start = $jqQr["start"];
- echo $this->jqlib->XML($jqQr,$this->jqID,$this->jqField,$this->jqRowIgnored,$start);
- }elseif($lastVisit == TRUE){ // Fetch Untuk Last Visit
- //$sql = "SELECT * FROM ($this->jqsql) AS x WHERE AddUser = '".$this->session->userdata("username")."' AND invoice='Not Fully Paid'";
-
- //if(count($this->db->query($sql)->result_array())<1)
- //{
- $sql = "SELECT * FROM ($this->jqsql) AS x WHERE AddUser = '".$this->session->userdata("username")."'";
- //}
- ///echo $this->db->last_query();
- //exit;
- $rownum = "10";
- $jqQr = $this->Gmodel->jqGrid($sql, $rownum);
- //echo $sql;
- //exit;
- $start = $jqQr["start"];
- echo $this->jqlib->XML($jqQr,$this->jqID,$this->jqField,$this->jqRowIgnored,$start);
- }/*else{
- echo $this->jqlib->XML($this->jqQr,$this->jqID,$this->jqField,$this->jqRowIgnored,$this->start);
- #echo "test";
- }*/
- }
-
- //Fungsi yang akan meload view ketika popup dipanggil
- function popup($action=null,$customerID=null)
- {
- if($action=="edit"){
- $data["row"] = $this->Gmodel->getCustomerInfo($customerID)->row_array();
- $data["rowRel"]= $this->Gmodel->getCustomerInfo($customerID,TRUE)->row_array();
- /*
- echo "<pre>";
- print_r($data["row"]);
- echo "<br/>";
- print_r($data["rowRel"]);
- echo "<br/>";
- echo "</pre>";
- */
- /*
- print_r($data["row"]);
- echo "<br/>";
- print_r($data["rowRel"]);
- echo "<br/>";
- */
- //echo $this->db->last_query();
- //exit;
- $this->load->view($this->path_self. "/vEdit",$data);
- }
- if($action=="add")
- {
- $data["row"] = array("IdKonsumen"=>$this->Gmodel->getLastId());
- $data['IdNegara']= $this->IdNegara;
- $this->load->view($this->path_self . "/vAdd",$data);
- }
- }
-
- //Fungsi untuk menyimpan data (add new atau edit)
- function save($act)
- {
- exit;
- $POST= $this->input->post();
- # print_r($POST);
- /*
- if( isset($POST["frmname"]) && $POST["frmname"] != "frmAddCus" ){
- print_r($POST);
- }
- */
-
- $idKonsumen= ( isset($POST['IdKonsumen']) ) ? $POST['IdKonsumen'] : "";
- /*
- echo $idKonsumen;
- exit;
- echo $POST["TanggalLahir"] . "->";
- */
-
- $POST["AddUser"] = $this->session->userdata("username");
- $POST["ModifUser"] = $this->session->userdata("username");
- $POST["AddDate"] = date("Y-m-d");
- $POST["ModifDate"] = date("Y-m-d");
-
- // Tambah Salutation
- if( isset($POST['NamaSapaan']) || isset($POST['NamaSapaanKeluarga']) ){
- $Sapaan= ( isset($POST['NamaSapaan']) ) ? $POST['NamaSapaan'] : $POST['NamaSapaanKeluarga'];
-
- // Cek NamaSapaan tidak ada
- $NamaSapaan= strtolower($Sapaan);
- if( $this->db->get_where('m_sapaan', array('NamaSapaan'=>$NamaSapaan))->num_rows() ){
- echo "Salutation is already exists !";
- exit;
- }
- // Insert Data New Salutation
- $AddUser= $this->session->userdata('username');
- $AddDate= date("Y-m-d");
- $ins_sapaan= array('NamaSapaan'=>$NamaSapaan, 'AddUser'=>$AddUser, 'AddDate'=>$AddDate);
- $this->db->insert('m_sapaan', $ins_sapaan);
- if( isset($POST['NamaSapaan']) ){
- $POST['IdSapaan']= $this->db->insert_id();
- }else{
- $POST['IdSapaanKeluarga']= $this->db->insert_id();
- }
- unset($POST['NamaSapaan'],$POST['NamaSapaanKeluarga']); // Unset NamaSapaan tidak digunakan lagi
- }
-
- # Insert $IdNegara sesuai dengan form
- if( isset($POST['IdNegara']) || isset($POST['IdNegaraKeluarga']) ){
- $IdNegara= ( $POST['frmname'] == "frmAddCus" ) ? $POST['IdNegara'] : $POST['IdNegaraKeluarga'];
- }
-
- # Insert ke m_region jika ada $POST['NamaRegion'] dan $POST['NamaRegionKeluarga']
- if( isset($POST['NamaRegion']) || isset($POST['NamaRegionKeluarga']) ){
- $Region= ( isset($POST['NamaRegion']) ) ? $POST['NamaRegion'] : $POST['NamaRegionKeluarga'];
-
- //$NamaRegion= strtolower($Region);
-
- $NamaRegion= $Region;
- $this->db->select("IdRegion");
- $query_region= $this->db->get_where('m_region', array('NamaRegion'=>$NamaRegion));
- if( $query_region->num_rows() ){ # Jika region ada fetch data
- $region= $query_region->row_array();
- $IdRegion= $region['IdRegion'];
- }else{ # Insert data region baru
- $IdRegion= $IdNegara . "-" . substr($NamaRegion, 0, 3); // MY-PEN
- $ins_region= array("IdRegion"=>$IdRegion, "NamaRegion"=>$NamaRegion, "IdNegara"=>$IdNegara,
- "AddUser"=>$POST["AddUser"], "AddDate"=>$POST["AddDate"]);
- $this->db->insert("m_region", $ins_region);
- }
-
- // Set $POST sesuai dengan form
- if( isset($POST['NamaRegion']) ){
- $POST['IdRegion']= $IdRegion;
- }else{
- $POST['IdRegionKeluarga']= $IdRegion;
- }
-
- }
-
- # Insert ke m_kota jika ada $POST['NamaKota'] dan $POST['NamaKotaKeluarga']
- if( isset($POST['NamaKota']) || isset($POST['NamaKotaKeluarga']) ){
- $Kota= ( isset($POST['NamaKota']) ) ? $POST['NamaKota'] : $POST['NamaKotaKeluarga'];
-
- //$NamaKota= strtolower($Kota);
- $NamaKota= $Kota;
- $this->db->flush_cache();
- $this->db->select("IdKota");
- $query_kota= $this->db->get_where('m_kota', array('NamaKota'=>$NamaKota));
- if( $query_kota->num_rows() ){ # Jika kota ada fetch data
- $kota= $query_kota->row_array();
- $IdKota= $kota['IdKota'];
- }else{ # Insert data kota baru
- $ins_kota= array("NamaKota"=>$NamaKota,"IdRegion"=>$IdRegion,
- "AddUser"=>$POST["AddUser"], "AddDate"=>$POST["AddDate"]);
- $this->db->insert("m_kota",$ins_kota);
- $IdKota= $this->db->insert_id();
- }
-
- // Set $POST sesuai dengan form
- if( isset($POST['NamaKota']) ){
- $POST['IdKota']= $IdKota;
- }else{
- $POST['IdKotaKeluarga']= $IdKota;
- }
- }
-
- unset($POST['NamaKota'], $POST['NamaRegion'], $POST['NamaKotaKeluarga'], $POST['NamaRegionKeluarga']);
- if($this->input->post("frmname") == "frmAddCus")
- {
- //
- $edit_allow= array("KodeTelponKantor","KodeTelponRumah", "KodeTelponRumah2");
- if( $act == "edit" ){ // Jika $act == edit
- foreach( $edit_allow as $value ){ // Tetapkan nilai default untuk field kumpulan field Kode
- $POST[$value]= "";
- }
- }
- $POST["TanggalLahir"]= date("Y-m-d", strtotime($POST['TanggalLahir'])); //untuk merubah tanggal menjadi d-m-y lk
-
- if( isset($POST["TelponKantor"]) ){
- $POST["TelponKantor"] = $POST["KodeTelp1"] . $POST['KodeTelponKantor'] . $POST["TelponKantor"];
- unset($POST["KodeTelp1"]);
- unset($POST["KodeTelponKantor"]);
-
- }
- else{
- $POST["TelponKantor"]="";
- }
- if( isset($POST["NoHP"]) ){
- $POST["NoHP"] = $POST["KodeTelp2"] . $POST["NoHP"];
- }
- else
- {
- $POST["NoHP"]="";
- }
- if(isset($POST["NoHP2"])){
- $POST["NoHP2"] = $POST["KodeTelp2"] . $POST["NoHP2"];
- unset($POST["KodeTelp2"]);
- }
- else{$POST["NoHP2"]="";
- }
- if(isset($POST["TelponRumah"])){
- $POST["TelponRumah"] = $POST["KodeTelp3"] . $POST['KodeTelponRumah'] . $POST["TelponRumah"];
- //unset($POST["KodeTelp"]);
- unset($POST['KodeTelponRumah']);
- }
- else{$POST["TelponRumah"]="";
- }
- if(isset($POST["TelponRumah2"])){
- $POST["TelponRumah2"] = $POST["KodeTelp3"] . $POST['KodeTelponRumah2'] . $POST["TelponRumah2"];
- unset($POST["KodeTelp3"]);
- unset($POST['KodeTelponRumah2']);
- }
- else
- {
- $POST["TelponRumah2"]="";
- }
- if( $this->IdNegara == "MY" ){
- $POST["Alamat"] = $POST["namajalan"];
- $POST["Alamat2"] = $POST["namajalan3"];
- }else{
- $POST["Alamat"] = $POST["namajalan"] . "~" . $POST["houseno"] . "~" . $POST["unitno"];
- }
-
- unset($POST["namajalan"]);
- unset($POST["houseno"]);
- unset($POST["unitno"]);
- unset($POST["namajalan3"]);
- $table = "konsumen";
- }
- else{
- // Form Keluarga
- $konsumen_keluarga= array("IdSapaanKeluarga","NamaAwalKeluarga",
- "NamaAkhirKeluarga","PanggilanKeluarga","JenisKelaminKeluarga",
- "IdPekerjaanKeluarga","IdAgamaKeluarga","TempatLahirKeluarga",
- "TanggalLahirKeluarga","AlamatKeluarga","namajalan2","houseno2","AlamatKeluarga2","namajalan4",
- "unitno2","KodePosKeluarga","IdNegaraKeluarga","IdRegionKeluarga",
- "IdKotaKeluarga","KodeTelp4","TelponKantorKeluarga",
- "KodeTelp5","NoHPKeluarga","KodeTelp7","NoHPKeluarga2","KodeTelp6","TelponRumahKeluarga","KodeTelp8","TelponRumahKeluarga2","EmailKeluarga",
- "AddUser","ModifUser","AddDate","ModifDate");
-
- foreach( $konsumen_keluarga as $value ){
- $POST[$value]= isset($POST[$value]) ? $POST[$value] : "";
- }
- if($POST["TanggalLahirKeluarga"]=="1970-01-01")
- {
- unset($POST["TanggalLahirKeluarga"]);
- }
- else
- {
- $POST["TanggalLahirKeluarga"]= date("Y-m-d", strtotime($POST['TanggalLahirKeluarga'])); //untuk merubah tanggal menjadi d-m-y
-
- }
- if( $this->IdNegara == "MY" ){
- $POST["AlamatKeluarga"] = $POST["namajalan2"];
- $POST["AlamatKeluarga2"] = $POST["namajalan4"];
- }else{
- $POST["AlamatKeluarga"] = $POST["namajalan2"] . "~" . $POST["houseno2"] . "~" . $POST["unitno2"];
- }
- unset($POST["namajalan2"]);
- unset($POST["houseno2"]);
- unset($POST["unitno2"]);
- unset($POST["namajalan4"]);
- #if( $act == "add" ){
- // Unset Data $POST dg value kosong
- $allowme= array("IdNegaraKeluarga","IdRegionKeluarga","IdKotaKeluarga","JenisKelaminKeluarga");
- foreach( $POST as $key=>$value ){
- if( empty($value) && ! in_array($key, $allowme) ){
- unset($POST[$key]);
- }
- }
-
- $edit_allow= array("KodeTelponKantorKeluarga",
- "KodeTelponRumahKeluarga", "KodeTelponRumahKeluarga2");
- if( $act == "edit" ){ // Jika $act == edit
- foreach( $edit_allow as $value ){ // Tetapkan nilai default untuk field kumpulan field Kode
- $POST[$value]= "";
- }
- }
-
- if( isset($POST["TelponKantorKeluarga"]) ){
- $POST["TelponKantorKeluarga"]= $POST["KodeTelp4"] . $POST["KodeTelponKantorKeluarga"] . $POST["TelponKantorKeluarga"];
- }else{
- $POST["TelponKantorKeluarga"]="";
- }
- unset($POST["KodeTelp4"], $POST["KodeTelponKantorKeluarga"]);
-
- if( isset($POST["NoHPKeluarga"]) ){
- $POST["NoHPKeluarga"]= $POST["KodeTelp5"] . $POST["NoHPKeluarga"];
- //unset($POST["KodeTelp5"]);
- }
- else
- {
- $POST["NoHPKeluarga"]="";
- }
- //unset($POST["KodeTelp5"]);
- if( isset($POST["NoHPKeluarga2"]) ){
- $POST["NoHPKeluarga2"]= $POST["KodeTelp7"] . $POST["NoHPKeluarga2"];
- //unset($POST["KodeTelp7"]);
- }
- else
- {
- $POST["NoHPKeluarga2"]="";
- }
- if( isset($POST["TelponRumahKeluarga"]) ){
- $POST["TelponRumahKeluarga"]= $POST["KodeTelp6"] . $POST['KodeTelponRumahKeluarga'] .
- $POST["TelponRumahKeluarga"];
- //if( isset($POST["TelponRumahKeluarga"]) ){
- // $POST["TelponRumahKeluarga"]= $POST["KodeTelp6"] . $POST["TelponRumahKeluarga"];
- //unset($POST["KodeTelp6"]);
- // unset($POST["KodeTelponRumahKeluarga"]);
- }
- else
- {
- $POST["TelponRumahKeluarga"]="";
- }
- if( isset($POST["TelponRumahKeluarga2"]) ){
- $POST["TelponRumahKeluarga2"]= $POST["KodeTelp8"] . $POST['KodeTelponRumahKeluarga2'] .
- $POST["TelponRumahKeluarga2"];
- /*if( isset($POST["TelponRumahKeluarga2"]) ){
- $POST["TelponRumahKeluarga2"]= $POST["KodeTelp8"] . $POST["TelponRumahKeluarga2"];*/
- // unset($POST["KodeTelp8"]);
- // unset($POST["KodeTelponRumahKeluarga2"]);
- }
- else
- {
- $POST["TelponRumahKeluarga2"]="";
- }
- unset($POST["KodeTelp4"], $POST["KodeTelp5"], $POST["KodeTelp6"], $POST["KodeTelp7"],
- $POST["KodeTelp8"], $POST['KodeTelponKantorKeluarga'], $POST['KodeTelponRumahKeluarga'], $POST['KodeTelponRumahKeluarga2']);
- #}
- if( $POST["IdKeluarga"] == "" ){
- $POST["JenisKelaminKeluarga"]= "";
- }
- $table = "konsumen_keluarga";
- #unset($POST["frmname"]);
- }
-
-
- if( $act=="add" )
- {
- if( $POST["frmname"] == "frmAddCus" ){
- $idKonsumen= $this->Gmodel->getLastId(); // Set the default value to call the method __updatestatus
- // The Post IdKonsumen variable Will automaticly truncated when system try to save the konsumen_keluarga
- $POST['IdKonsumen']= $idKonsumen;
- }
-
- if(isset($POST["IdSource"]))
- {
- $opt= $POST["IdSource"];
- $this->db->select('IdMediaType');
- $this->db->group_by('MediaType');
- $media= $this->db->get('m_media_type')->result_array();
- $type= array();
- foreach( $media as $key=>$value ){
- $IdMediaType= str_replace("-", "\-", $value['IdMediaType']);
- $type[]= $IdMediaType;
- }
-
- $regsource= implode("|", $type);
- $regsource= "#^(" . $regsource . ")$#";
- if( preg_match($regsource, $opt) ){ // Insert to source_by_advertisement table wat Source Information
- $sources= array("IdKonsumen","IdSource","IdMediaKategori","IdMedia");
- foreach( $sources as $value ){
- $POST[$value]= ( isset($POST[$value]) ) ? $POST[$value] : "";
- }
- unset($POST["Title"], $POST["HospitalName"]);
- #$title= ( isset($POST['Title']) ) ? $POST['Title'] : "";
- $source= array("IdKonsumen"=>$POST["IdKonsumen"],
- "IdMediaType"=>$POST["IdSource"],"IdMediaKategori"=>$POST["IdMediaKategori"],
- "IdMedia"=>$POST["IdMedia"],"AddDate"=>date("Y-m-d"),
- "AddUser"=>$this->session->userdata("username"));
- $this->Gmodel->add("source_by_advertisement", $source);
- }else{
- switch($POST["IdSource"]) //Untuk menyimpan data customer source infomation
- {
- case "1" :
- break;
- case "6" : // Untuk simpan data konsumen dengan source information : doctor_referral
- $this->Gmodel->add("source_by_doctor_referral",array("IdKonsumen"=>$POST["IdKonsumen"],
- "NamaKlinik"=>$POST["NamaKlinik"],"NamaDokter"=>$POST["NamaDokter"],
- "AddDate"=>date("Y-m-d")));
- break;
- default : // simpan data ke table source_by_dump
- $this->Gmodel->add("source_by_dump",array("IdKonsumen"=>$POST["IdKonsumen"],
- "AddDate"=>date("Y-m-d"), "IdSource"=>$POST["IdSource"]));
- break;
- }
- }
- }
-
- //Hapus semua array dengan index yang diinsert pada source information karena index tersebut tidak digunakan untuk insert ke tabel konsumen
- if(isset($POST["IdMediaType"])) unset($POST["IdMediaType"]);
- if(isset($POST["IdMediaType"])) unset($POST["IdMediaType"]);
- if(isset($POST["IdMediaKategori"])) unset($POST["IdMediaKategori"]);
- if(isset($POST["IdMedia"])) unset($POST["IdMedia"]);
- if(isset($POST["IdIklan"])) unset($POST["IdIklan"]);
- if(isset($POST["NamaKlinik"])) unset($POST["NamaKlinik"]);
- if(isset($POST["NamaDokter"])) unset($POST["NamaDokter"]);
- if(isset($POST["event"])) unset($POST["event"]);
- if(isset($POST["IdSource"])) unset($POST["IdSource"]);
- if(isset($POST["NamaMedia"])) unset($POST["NamaMedia"]);
-
- /*
- if( isset($POST["frmname"]) && $POST["frmname"] == "frmAddOther" ){
- print_r($POST);
- }
- */
-
- if( $POST["frmname"] == "frmAddCus" ){
- $base_url= base_url();
- if( $base_url != "http://thsgcrmid.com/crm_test/" ){
- // Insert Data To SQL Server
- /*
- $sqlserver['hostname'] = "E-FUN\HIMSA";
- $sqlserver['username'] = "sa";
- $sqlserver['password'] = "1234";
- $sqlserver['database'] = "NOAHSystem";
- $sqlserver['dbdriver'] = "mssql";
- $sqlserver['dbprefix'] = "";
- $sqlserver['pconnect'] = FALSE;
- $sqlserver['db_debug'] = TRUE;
- $sqlserver['cache_on'] = FALSE;
- $sqlserver['cachedir'] = "";
- $sqlserver['char_set'] = "utf8";
- $sqlserver['dbcollat'] = "utf8_general_ci";
- $sqlserver['autoinit'] = TRUE;
- $sqlserver['stricton'] = FALSE;
-
- $sqlserver= $this->config->item('sqlconfig');
- $server= $this->load->database($sqlserver, TRUE);
- $tgl= date("m/d/Y g:i:s A");
- $data= array('UserID'=>'8',
- 'CreateDate'=>$tgl,
- 'FirstName'=>$POST['NamaAwal'],
- 'LastName'=>$POST['NamaAkhir']);
- $response= $server->insert('Client', $data);
- $POST['NoahID']= $server->insert_id();
- if( ! $response ){
- exit;
- }
- */
- }
-
- $msg= "IdKonsumen" . "," . $idKonsumen;
- }else{
- $msg= "1";
- }
- unset($POST["frmname"]);
- /*
- if( $POST["frmname"] == "frmAddOther" ){
- print_r($POST);
- }
- */
-
-
-
- if($this->Gmodel->add($table, $POST))
- {
- echo $msg;
- }else{
- echo 0;
- }
-
- }elseif($act=="edit")
- {
- $doesExists = $this->Gmodel->isExist($table,array("IdKonsumen"=>$idKonsumen));
- if( $doesExists ) // Klo Ada
- {
- /*
- $base_url= base_url();
- if( $base_url != "http://thsgcrmid.com/crm_test/" ){
- print_r($POST);
- if( $table == "konsumen" ){
- $sqlserver= $this->config->item('sqlconfig');
- $server= $this->load->database($sqlserver, TRUE);
- // Get NoahID
- $noahdt= $this->db->get_where('konsumen', array('IdKonsumen'=>$POST['IdKonsumen']))->row_array();
- // Update Data to NOAH
- $data= array('FirstName'=>$POST['NamaAwal'],
- 'LastName'=>$POST['NamaAkhir']);
- $server->where('ID', $noahdt['NoahID']);
-
- $response= $server->update('Client', $data);
-
- }
- }
- */
-
- if( $table == "konsumen_keluarga" && $POST['IdKeluarga'] == "" ){
- $tbl_fields= $this->db->list_fields('konsumen_keluarga');
- $reg_exception= "#^(IdKonsumen|IdKeluarga|AddUser|AddDate|ModifUser|ModifDate)$#";
- foreach( $tbl_fields as $field ){
- if( ! preg_match($reg_exception, $field) ){
- $POST[$field]= "";
- }
- }
- }
-
- unset($POST["IdKonsumen"]);
- unset($POST["frmname"]);
- //print_r($table);
- //exit;
- $where= array("IdKonsumen"=>$idKonsumen);
- #print_r($POST);
- if($this->Gmodel->edit($table, $POST, $where) != "-1")
- {
- echo 1;
- }else{
- echo 0;
- }
- }else{ // Klo gak ada
- if($this->Gmodel->add($table, $POST))
- {
- echo 1;
- }else{
- echo 0;
- }
- }
- }elseif($act=="proceed")
- {
- if(isset($_POST["IdSource"]))
- {
- switch($_POST["IdSource"]) //Untuk menyimpan data customer source infomation
- {
- case "1" :
- break;
- case "3" : //Untuk insert data konsumen dengan source information : event
- $this->Gmodel->add("source_by_event",array("IdKonsumen"=>$_POST["IdKonsumen"],"IdEvent"=>$_POST["event"],
- "AddUser"=>$this->session->userdata("username"),"AddDate"=>date("Y-m-d")));
- break;
- case "4" : //Untuk insert data konsumen dengan source information : advertisement
- $this->Gmodel->add("source_by_advertisement",array("IdKonsumen"=>$_POST["IdKonsumen"],
- "IdMediaType"=>$_POST["IdMediaType"],"IdMediaKategori"=>$_POST["IdMediaKategori"],
- "IdMedia"=>$_POST["IdMedia"],"AddDate"=>date("Y-m-d"),
- "AddUser"=>$this->session->userdata("username")));
- break;
- case "6" : //Untuk simpan data konsumen dengan source information : doctor_referral
- $this->Gmodel->add("source_by_doctor_referral",array("IdKonsumen"=>$_POST["IdKonsumen"],
- "NamaKlinik"=>$_POST["NamaKlinik"],"NamaDokter"=>$_POST["NamaDokter"],"AddDate"=>date("Y-m-d")));
- break;
- default : //simpan data ke table source_by_dump
- $this->Gmodel->add("source_by_dump",array("IdKonsumen"=>$_POST["IdKonsumen"],"AddDate"=>date("Y-m-d"),
- "IdSource"=>$_POST["IdSource"]));
- break;
- }
- }
-
- //Hapus semua array dengan index yang diinsert pada source information karena index tersebut tidak digunakan untuk insert ke tabel konsumen
- if(isset($_POST["IdMediaType"])) unset($_POST["IdMediaType"]);
- if(isset($_POST["IdMediaType"])) unset($_POST["IdMediaType"]);
- if(isset($_POST["IdMediaKategori"])) unset($_POST["IdMediaKategori"]);
- if(isset($_POST["IdMedia"])) unset($_POST["IdMedia"]);
- if(isset($_POST["IdIklan"])) unset($_POST["IdIklan"]);
- if(isset($_POST["NamaKlinik"])) unset($_POST["NamaKlinik"]);
- if(isset($_POST["NamaDokter"])) unset($_POST["NamaDokter"]);
- if(isset($_POST["event"])) unset($_POST["event"]);
- if(isset($_POST["IdSource"])) unset($_POST["IdSource"]);
-
- if($this->Gmodel->proceed($table,$_POST))
- {
- echo 1;
- }else{
- echo 0;
- }
- }
-
- #$this->update_status($idKonsumen);
- }
-
- //fungsi untuk menghapus data
- function delete()
- {
- $id= $this->input->post("id");
- $base_url= base_url();
- if( $base_url != "http://thsgcrmid.com/crm_test/" ){
- $sqlserver= $this->config->item('sqlconfig');
- $server= $this->load->database($sqlserver, TRUE);
- // Get NoahID
- $noahdt= $this->db->get_where('konsumen', array('IdKonsumen'=>$id))->row_array();
- // Delete Data in NOAH
- $server->where('ID', $noahdt['NoahID']);
- $response= $server->delete('Client');
- }
-
- $where = array("IdKonsumen"=>$id);
- if($this->Gmodel->delete("konsumen",$where))
- {
- if($this->Gmodel->delete("konsumen_keluarga",$where))
- {
- echo "1";
- }else{
- echo "2";
- }
- }else{
- echo "0";
- }
- }
-
- function auto_complete($opt){
- #$str= $_GET["term"];
- $GET= $this->input->get();
-
- $regopt= "#^(namakotakeluarga|namakota)$#";
- if( preg_match($regopt, $opt) ){
- $sqlSearch = "SELECT * FROM m_kota a
- INNER JOIN m_region b ON b.IdRegion = a.IdRegion
- INNER JOIN m_negara c ON c.IdNegara = b.IdNegara
- WHERE a.NamaKota LIKE '%" . $GET['IdVal'] . "%' AND c.IdNegara = '" .
- $GET['IdNegara'] . "'";
- }else{
- $sqlSearch = "SELECT * FROM m_region a
- INNER JOIN m_negara c ON c.IdNegara = a.IdNegara
- WHERE a.NamaRegion LIKE '%" . $GET['IdVal'] . "%' AND c.IdNegara = '" .
- $GET['IdNegara'] . "'";
-
- }
-
-
-
- /*
- #print_r($hasil);
- echo $this->db->last_query();
- exit;
- */
- $rows= $this->db->query($sqlSearch)->result_array();
- $data= array();
- foreach( $rows as $row )
- {
- $text= ( preg_match($regopt, $opt) ) ? $row['NamaKota'] : $row['NamaRegion'];
- $data[]= array("id"=>$text, "label"=>$text, "value"=>$text);
- }
-
- echo json_encode($data);
- }
-
- //Fungsi untuk mendapatkan kota dan region
- function getAJAX($opt,$id="")
- {
- if( $this->IdNegara == "SG" ){
- switch($opt)
- {
- case "region" :
- //echo "<option value=''>--".lang('abdi.select_region')."--</option>";
- foreach($this->Gmodel->getRegionByNegara($id) as $region)
- {
- echo "<option value=\"".$region->IdRegion."\">".$region->NamaRegion."</option>";
- }
- break;
- case "kota" :
- //echo "<option value=''>--".lang('abdi.select_city')."--</option>";
- foreach($this->Gmodel->getKotaByRegion($id) as $kota)
- {
- echo "<option value=\"".$kota->IdKota."\">".$kota->NamaKota."</option>";
- }
- break;
- }
- }else{
- switch($opt)
- {
- case "region" :
- echo "<option value=''>--".lang('abdi.select_region')."--</option>";
- foreach($this->Gmodel->getRegionByNegara($id) as $region)
- {
- echo "<option value=\"".$region->IdRegion."\">".$region->NamaRegion."</option>";
- }
- break;
- case "kota" :
- echo "<option value=''>--".lang('abdi.select_city')."--</option>";
- foreach($this->Gmodel->getKotaByRegion($id) as $kota)
- {
- echo "<option value=\"".$kota->IdKota."\">".$kota->NamaKota."</option>";
- }
- break;
- }
- }
- }
-
- /*------ Function2 dibawah ini digunakan untuk merender objek2 html yang diperlukan untuk source information ---*/
-
- function update_me(){
- $IdKonsumen= "02001000000683";
- $this->update_status($IdKonsumen);
- }
-
- //update the customer status 0=Pending, 1=Active, 2=Opt Out, 3=Deceased.
- public function update_status($IdKonsumen,$opt="")
- {
- if($opt != "" && $opt != "remove")
- {
- switch($opt)
- {
- case "optout" :
- $set = array("KonsumenStatus"=>"2");
- break;
- case "deceased" :
- $set = array("KonsumenStatus"=>"3");
- break;
- case "remove" :
- $set = array("KonsumenStatus"=>"0");
- break;
- default :
- break;
- }
- }else{
- $where= array("IdKonsumen"=>$IdKonsumen);
- $qr= $this->Gmodel->getRecordArray("konsumen_keluarga",$where);
- $passed= TRUE;
- /*
- echo "<pre>";
- print_r($qr);
- echo "<pre>";
- */
- foreach( $qr as $key=>$row ){
- $group_fields= array("MY"=>array("PanggilanKeluarga"),
- "KR"=>array("PanggilanKeluarga", "TempatLahirKeluarga", "AlamatKeluarga2"),
- "ID"=>array("AlamatKeluarga2"),
- "SG"=>array("AlamatKeluarga2")
- );
- $gselected= ( isset($group_fields[$this->IdNegara]) ) ? $group_fields[$this->IdNegara] : array();
- if( ! in_array($key, $gselected) ){
- #echo $key . "->" . strlen($row) . "\n";
- if( ! strlen($row) ){
- $passed= FALSE;
- }
- }
-
- }
- #exit;
- $set= ( $passed ) ? array("KonsumenStatus"=>"1") : array("KonsumenStatus"=>"0");
- /*
- if($passed)
- {
- $set= array("KonsumenStatus"=>"1");
- }else{
- $set= array("KonsumenStatus"=>"0");
- }
- print_r($set);
- exit;
- */
- #print_r($set);
- }
-
- $where = array("IdKonsumen"=>$IdKonsumen);
- return $this->Gmodel->edit("konsumen", $set, $where);
- }
-
- function getMedia($local=""){
- if( empty($local) ){
- $POST= $this->input->post();
- }else{
- $POST= $local;
- }
- /*
- print_r($POST);
- exit;
- */
- foreach( $POST as $key=>$value ){
- $$key= $value;
- }
-
- $html= "";
- switch($opt){
- case "IdMediaType" :
- $html= "";
- if( !empty($id) ){
- /*
- echo $opt . "->" . $id;
- exit;
- */
- $this->db->order_by("MediaKategori","asc");
- $data= $this->db->get_where('m_media_kategori', array($opt=>$id))->result_array();
- if( ! empty($data) ){
- $html= "
- <tr id='rowAdded'>
- <td>Media Category</td>
- <td>:</td>
- <td>
- <select name='IdMediaKategori' id='IdMediaKategori' class='required'>
- <option value=\"\">-- Select Category --</option>";
- foreach( $data as $value )
- {
- $html.= "<option value=\"" . $value['IdMediaKategori'] . "\">" .
- $value['MediaKategori'] . "</option>";
- }
- $html.= "
- </select>
- </td>
- </tr>
- ";
- }else{
- #$this->IdNegara= "ID";
- $data= $this->db->get_where("m_media_type", array("IdMediaType"=>$id))->row_array();
- if( $data['MediaType'] != "WALK IN" ){
- $sql= "SELECT * FROM m_media a
- INNER JOIN user b ON b.Username= a.AddUser
- INNER JOIN klinik c ON c.IdKlinik= b.IdKlinik
- WHERE c.IdNegara= '" . $this->IdNegara . "' AND a.IdMediaType= '" . $id . "'
- ORDER BY a.NamaMedia ASC
- ";
- $data= $this->db->query($sql)->result_array();
- /*
- $this->db->order_by("NamaMedia","asc");
- $data= $this->db->get_where('m_media', array($opt=>$id))->result_array();
- */
- $html= "
- <tr id='rowAdded'>
- <td>Event </td>
- <td>:</td>
- <td>
- <select name='IdMedia' id='IdMedia' class='required'>
- ";
- if( ! empty($data) ){
- foreach( $data as $value )
- {
- $html.= "<option value=\"" . $value['IdMedia'] . "\">" .
- $value['NamaMedia'] . "</option>";
- }
- }else{
- $html.= "<option value=\"\">--- Event is empty ---</option>";
- }
- $html.= "
- </select>
- </td>
- </tr>
- ";
- }
- }
- #$data.= "<option value=\"02001-CAT0013\">OTHER</option>";
- }
- break;
- case "IdMediaKategori" :
- $html= "";
- /*
- $sql= "SELECT a.MediaType FROM m_media_type a
- INNER JOIN m_media_kategori b ON b.IdMediaType= a.IdMediaType
- WHERE b.IdMediaKategori= '" . $MediaCat . "'";
- $row= $this->db->query($sql)->row_array();
- print_r($row
- */
- #$this->IdNegara= "ID";
- if( !empty($id) ){
- $sql= "SELECT * FROM m_media a
- INNER JOIN user b ON b.Username= a.AddUser
- INNER JOIN klinik c ON c.IdKlinik= b.IdKlinik
- WHERE c.IdNegara= '" . $this->IdNegara . "' AND a.IdMediaKategori= '" . $id . "'
- GROUP BY a.NamaMedia
- ORDER BY a.NamaMedia ASC
- ";
- $data= $this->db->query($sql)->result_array();
- /* Old Script
- $this->db->order_by("NamaMedia","asc");
- $this->db->group_by('NamaMedia');
- $data= $this->db->get_where('m_media', array($opt=>$id))->result_array();
- */
- $html= "<tr id='rowAdded'>";
- if( ! empty($data) ){
- $cat= $this->db->get_where('m_media_kategori', array('IdMediaKategori'=>$id))->row_array();
- if( $cat['MediaKategori'] == "FACEBOOK" ){
- $html.= "<td>Event </td>
- <td>:</td>
- <td>";
- $html.= "<select name='NamaMedia' id='NamaMedia' class='required'>";
- $html.= "<option value=\"\">-- Select Event --</option>";
- foreach( $data as $value )
- {
- $html.= "<option value=\"" . $value['NamaMedia'] . "\">" .
- $value['NamaMedia'] . "</option>";
- }
- }else{
- $title= "Event";
-
- $sql= "SELECT a.MediaType FROM m_media_type a
- INNER JOIN m_media_kategori b ON b.IdMediaType= a.IdMediaType
- WHERE b.IdMediaKategori= '" . $id . "'";
- $row= $this->db->query($sql)->row_array();
- #echo $row['MediaType'] . "\n";
- if( $row['MediaType'] == "MEDICAL" ){ // Jika Media Source == MEDICAL
- $sql= "SELECT a.MediaType FROM m_media_type a
- INNER JOIN m_media_kategori b ON b.IdMediaType= a.IdMediaType
- WHERE b.IdMediaKategori= '" . $id . "'";
- /*
- $kategori= $this->db->select('MediaKategori')->
- get_where('m_media_kategori', array("IdMediaKategori"=>$id))->row_array();
- */
- #if( $kategori['MediaKategori'] == "HOSPITAL" ){
- $html.= "<td>Hospital/Clinic/Company Name </td>
- <td>:</td>
- <td>";
- $html.= "<select name='HospitalName' id='HospitalName' class='required'>";
- // SQL Hospitals
- $sql= "SELECT HospitalName FROM m_media a
- INNER JOIN user b ON b.Username= a.AddUser
- INNER JOIN klinik c ON c.IdKlinik= b.IdKlinik
- WHERE HospitalName != '' AND HospitalName IS NOT NULL
- AND IdMediaKategori= '" . $id . "' AND c.IdNegara= '" . $this->IdNegara . "'
- GROUP BY HospitalName";
- $hospitals= $this->db->query($sql)->result_array();
- $html.= '<option value="">--- Select ---</option>';
- foreach( $hospitals as $hospital ){
- $html.= '<option value="' . $hospital['HospitalName'] . '">' .
- $hospital['HospitalName'] . '</option>';
- }
- $html.= "
- </select>
- </td>
- </tr>
- ";
- $html.= "<tr id='rowAdded'>";
- #}
- /*
- else{
- echo "title";
- exit;
- $html.= "<td>Title </td>
- <td>:</td>
- <td>";
- $html.= "<select name='Title' id='Title' class='required'>";
- $sql= "SELECT Title FROM m_media
- WHERE Title != '' AND Title IS NOT NULL
- AND HospitalName != ''
- GROUP BY Title";
- $titles= $this->db->query($sql)->result_array();
- $html.= '<option value="">--- Select ---</option>';
- foreach( $titles as $title ){
- $html.= '<option value="' . $title['Title'] . '">' .
- $title['Title'] . '</option>';
- }
- $html.= "
- </select>
- </td>
- </tr>
- ";
- $html.= "<tr id='rowAdded'>";
- #$title= "Name";
- }
- */
- }else{
- $html.= "<td>" . $title . "</td>
- <td>:</td>
- <td>";
- #$html.= "<select name='" . $name . "' id='" . $name . "' class='required'>";
- $html.= "<select name='IdMedia' id='IdMedia' class='required'>";
- $html.= '<option value="">--- Select ---</option>';
- foreach( $data as $value )
- {
- $html.= "<option value=\"" . $value['IdMedia'] . "\">" .
- $value['NamaMedia'] . "</option>";
- }
- }
- }
- }else{
- /*
- echo "gp";
- exit;
- */
- $title= "Event";
- $cat= $this->db->get_where('m_media_kategori', array('IdMediaKategori'=>$id))->row_array();
- $name= ( $cat['MediaKategori'] == "FACEBOOK" ) ? "NamaMedia" : "IdMedia";
-
- $sql= "SELECT a.MediaType FROM m_media_type a
- INNER JOIN m_media_kategori b ON b.IdMediaType= a.IdMediaType
- WHERE b.IdMediaKategori= '" . $id . "'";
- $row= $this->db->query($sql)->row_array();
- #echo $row['MediaType'] . "\n";
- if( $row['MediaType'] == "MEDICAL" ){
- $title= "Hospital/Clinic/Company Name ";
- $name= "HospitalName";
- }
-
- $html.= "<td>" . $title . "</td>
- <td>:</td>
- <td>";
- $html.= "<select name='" . $name . "' id='" . $name . "' class='required'>";
- $html.= "<option value=\"\">--- Event is empty ---</option>";
- }
- $html.= "
- </select>
- </td>
- </tr>
- ";
- }
- break;
- case "NamaMedia":
- $html= "";
- if( !empty($id) ){
- $data= $this->db->get_where('m_media', array($opt=>$id))->result_array();
- $html= "
- <tr id='rowAdded'>
- <td>Area </td>
- <td>:</td>
- <td>
- <select name='Area' id='Area' class='required'>
- ";
- if( ! empty($data) ){
- foreach( $data as $value )
- {
- $html.= "<option value=\"" . $value['IdMedia'] . "\">" .
- $value['Area'] . "</option>";
- }
- }else{
- $html.= "<option value=\"\">--- Area is empty ---</option>";
- }
-
- $html.= "
- </select>
- </td>
- </tr>
- ";
- }
- break;
- case "HospitalName":
- $html= "";
- #$html= "title";
- if( !empty($id) ){
- /* Yang Pake Title
- $data= $this->db->select('IdMedia,NamaMedia')->get_where('m_media', array($opt=>$id))->result_array();
- $html.= "
- <tr id='rowAdded'>
- <td>Title </td>
- <td>:</td>
- <td>
- <select name='Title' id='Title' class='required'>
- ";
- $sql= "SELECT Title FROM m_media
- WHERE Title != '' AND Title IS NOT NULL
- AND HospitalName= '" . $id . "'
- GROUP BY Title";
- $titles= $this->db->query($sql)->result_array();
- $html.= '<option value="">--- Select ---</option>';
- foreach( $titles as $title ){
- $html.= '<option value="' . $title['Title'] . '">' .
- $title['Title'] . '</option>';
- }
- $html.= "
- </select>
- </td>
- </tr>
- ";
- */
- $data= $this->db->select('IdMedia,NamaMedia')->get_where('m_media', array($opt=>$id))->result_array();
- $html.= "
- <tr id='rowAdded'>
- <td>Name </td>
- <td>:</td>
- <td>
- <select name='IdMedia' id='IdMedia' class='required'>
- ";
- if( ! empty($data) ){
- foreach( $data as $value )
- {
- $html.= "<option value=\"" . $value['IdMedia'] . "\">" .
- ucwords(strtolower($value['NamaMedia'])) . "</option>";
- }
- }else{
- $html.= "<option value=\"\">--- Data is empty ---</option>";
- }
- $html.= "
- </select>
- </td>
- </tr>
- ";
- }
- break;
- case "Title":
- $html= "";
- #$html= "title";
- if( !empty($id) ){
- $data= $this->db->select('IdMedia,NamaMedia')->get_where('m_media', array($opt=>$id, "HospitalName"=>$hospital))->result_array();
- $html.= "
- <tr id='rowAdded'>
- <td>Name </td>
- <td>:</td>
- <td>
- <select name='IdMedia' id='IdMedia' class='required'>
- ";
- if( ! empty($data) ){
- foreach( $data as $value )
- {
- $html.= "<option value=\"" . $value['IdMedia'] . "\">" .
- ucwords(strtolower($value['NamaMedia'])) . "</option>";
- }
- }else{
- $html.= "<option value=\"\">--- Data is empty ---</option>";
- }
- $html.= "
- </select>
- </td>
- </tr>
- ";
- }
- break;
- }
- echo $html;
- #echo $this->db->last_query();
- exit();
- }
-
- //Fungsi untuk memproses enquiry source dan mengembalikan objek2 html yang akan di bentuk
- public function source_process()
- {
- $POST= $this->input->post();
- $opt= $POST["IdSource"];
-
- $this->db->select('IdMediaType');
- $this->db->group_by('MediaType');
- $media= $this->db->get('m_media_type')->result_array();
- $type= array();
- foreach( $media as $key=>$value ){
- $IdMediaType= str_replace("-", "\-", $value['IdMediaType']);
- $type[]= $IdMediaType;
- }
-
- $regsource= implode("|", $type);
- $regsource= "#^(" . $regsource . ")$#";
- if( preg_match($regsource, $opt) ){
- $option= array('opt'=>'IdMediaType','id'=>$opt);
- $this->getMedia($option);
- /*
- $sql= "SELECT IdMediaType, MediaType FROM m_media_type
- GROUP BY MediaType";
- $data= $this->db->query($sql)->result_array();
- $html= "
- <tr id='rowAdded'>
- <td>Media Type</td>
- <td>:</td>
- <td>
- <select name='IdMediaType' id='IdMediaType'>
- <option value='' selected='selected'>--Please Select--</option>
- ";
- foreach( $data as $value ){
- $html.= "<option value=\"" . $value['IdMediaType'] . "\">" . $value['MediaType'] . "</option>";
- }
-
- $html.="
- </select>
- </td>
- </tr>
- ";
- */
- }else{
- switch($opt)
- {
- case "2":
- $html = "
- <tr id='rowAdded'>
- <td>Event</td>
- <td>:</td>
- <td>
- <select id='event' name='event'>
- ";
- foreach($this->Gmodel->getRecords("event",array("IdEvent","NamaEvent","Awal","Akhir")) as $record){
- $awal = date_format(date_create($record->Awal),"d M Y");
- $akhir = date_format(date_create($record->Akhir),"d M Y");
- $html .= "<option value=\"".$record->IdEvent."\">".$record->NamaEvent." (".$awal." - ".$akhir.")"."</option>";
- }
- $html .= "
- </select>
- </td>
- </tr>
- ";
- break;
- case "Doctor Referral":
- $html = "
- <tr id='rowAdded'>
- <td>Country</td>
- <td>:</td>
- <td>
- <select onchange='getClinic($(this).val())'>
- <option value=''>--Please Select--</option>
- ";
- foreach($this->Gmodel->getRecords("m_negara",array("IdNegara","NamaNegara")) as $record){
- $html .= " <option value=\"".$record->IdNegara."\">".$record->NamaNegara."</option>";
- }
- $html .="
- </select>
- </td>
- </tr>
- ";
- break;
- default :
- return;
- }
- }
- echo $html;
- }
-
- //Function untuk me-render combo box mediakategori
- public function get_media_category()
- {
- $MediaType = $_POST["MediaType"];
- $html = "
- <tr id='rowMediaCat'>
- <td>Media Category</td>
- <td>:</td>
- <td>
- <select name='IdMediaKategori' onchange='getMedia($(this).val())'>
- <option value='' selected='selected'>--Please Select--</option>
- ";
- foreach($this->Gmodel->getRecords("m_media_kategori",array("IdMediaKategori","MediaKategori"),null,null,array("IdMediaType"=>$MediaType)) as $record)
- {
- $html .= "<option value='".$record->IdMediaKategori."'>".$record->MediaKategori."</option>";
- }
-
- $html .="
- </td>
- </tr>
- ";
-
- echo $html;
- }
-
- //Function untuk me-render combo box media
- public function get_media()
- {
- $POST= $this->input->post();
- $MediaCat = $POST["MediaCat"];
-
- if( $row['MediaType'] == "MEDICAL" ){
-
- }else{
- $html = "
- <tr id='rowMedia'>
- <td>Media</td>
- <td>:</td>
- <td>
- <select id='media' name='IdMedia' onchange='getAdv($(this).val())'>
- <option value=''>--Please Select--</option>
- ";
- foreach($this->Gmodel->getRecords("m_media",array("IdMedia","NamaMedia"), null, null,
- array("IdMediaKategori"=>$MediaCat)) as $record)
- {
- $html .= "<option value='" . $record->IdMedia . "'>" . $record->NamaMedia . "</option>";
- }
-
- $html .="
- </select>
- </td>
- </tr>
- ";
- }
- echo $html;
- }
-
- //Function untuk me-render combo box advertising
- public function get_adv()
- {
- $Media = $_POST["Media"];
- $html = "
- <tr id='rowAdv'>
- …
Large files files are truncated, but you can click here to view the full file