PageRenderTime 66ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/application/controllers/customer/master.php

https://bitbucket.org/remobius/crm
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

  1. <?php
  2. class master extends CI_Controller
  3. {
  4. /*------------------------------------------------------------------------------*/
  5. /* Beginning of master data customer */
  6. /*------------------------------------------------------------------------------*/
  7. private $IdNegara;
  8. function __construct()
  9. {
  10. parent::__construct();
  11. $this->load->library(array("jqlib","mnuauth"));
  12. $this->load->helper("form");
  13. $this->lang->load("abdi");
  14. $this->config->load('sqlconfig', TRUE);
  15. global $jqQr;
  16. global $jqField;
  17. global $jqID;
  18. global $jqRowIgnored;
  19. global $path_self;
  20. global $start;
  21. #$this->session->set_userdata('idNegara', 'MY');
  22. $userCountry= $this->Gmodel->getClinicInfo($this->session->userdata("IdKlinik"))->row();
  23. if(strtoupper($this->session->userdata('username'))=='MANFRED')
  24. {
  25. $sqlinvoice="";
  26. $sqlRestricted = '';
  27. }else{
  28. $sqlinvoice=", if(
  29. (select count(zz.isLunas) from invoice zz where zz.idkonsumen=a.idkonsumen and zz.isLunas='0')>0,
  30. 'Not Fully Paid',if((select count(za.isLunas) from invoice za where za.idkonsumen=a.idkonsumen and za.isLunas='1')>0,'Paid in Full','')
  31. ) as Invoice";
  32. $sqlRestricted = "
  33. INNER JOIN user d
  34. ON a.AddUser = d.Username
  35. INNER JOIN klinik e
  36. ON d.IdKlinik = e.IdKlinik
  37. LEFT JOIN invoice i ON i.IdKonsumen = a.IdKonsumen
  38. WHERE e.IdNegara = '" . $userCountry->IdNegara . "'
  39. ";
  40. /*
  41. $sqlRestricted = "
  42. INNER JOIN user d
  43. ON a.AddUser = d.Username
  44. INNER JOIN klinik e
  45. ON d.IdKlinik = e.IdKlinik
  46. WHERE e.IdNegara = ''";
  47. */
  48. }
  49. $userCountry= $this->Gmodel->getClinicInfo($this->session->userdata("IdKlinik"))->row();
  50. $IdNegara=$this->session->userdata('idNegara');
  51. $reg_country= "#^(ID)$#";
  52. if( preg_match($reg_country, $IdNegara) ){
  53. $this->jqsql= "
  54. SELECT a.IdKonsumen, a.NamaAwal, a.NamaAkhir, a.Email, a.NoHP,
  55. CASE a.JenisKelamin
  56. WHEN '0' THEN 'Female'
  57. WHEN '1' THEN 'Male'
  58. ELSE 'Not set' END AS Sex,
  59. CASE a.TanggalLahir
  60. WHEN null THEN '0'
  61. ELSE F_GET_AGE(a.TanggalLahir) END AS Age,
  62. b.Agama, c.NamaPekerjaan,
  63. CASE a.KonsumenStatus
  64. WHEN '0' THEN 'Pending'
  65. WHEN '1' THEN 'Active'
  66. WHEN '2' THEN 'Opt Out'
  67. ELSE 'Deceased'
  68. END AS Status,
  69. a.AddUser,
  70. DATE_FORMAT(TanggalLahir, '%d-%m-%Y') AS TanggalLahir
  71. , DATE_FORMAT(TanggalLahir, '%d-%M-%Y') AS TanggalLahir2
  72. $sqlinvoice
  73. FROM konsumen a
  74. LEFT JOIN m_agama b
  75. ON a.IdAgama = b.IdAgama
  76. LEFT JOIN m_pekerjaan c
  77. ON a.IdPekerjaan = c.IdPekerjaan
  78. $sqlRestricted
  79. GROUP BY a.IdKonsumen
  80. ORDER BY NamaAwal";
  81. }else{
  82. $this->jqsql= "
  83. SELECT a.IdKonsumen, a.NamaAkhir, a.NamaAwal, a.Email, a.NoHP,
  84. CASE a.JenisKelamin
  85. WHEN '0' THEN 'Female'
  86. WHEN '1' THEN 'Male'
  87. ELSE 'Not set' END AS Sex,
  88. CASE a.TanggalLahir
  89. WHEN null THEN '0'
  90. ELSE F_GET_AGE(a.TanggalLahir) END AS Age,
  91. b.Agama, c.NamaPekerjaan,
  92. CASE a.KonsumenStatus
  93. WHEN '0' THEN 'Pending'
  94. WHEN '1' THEN 'Active'
  95. WHEN '2' THEN 'Opt Out'
  96. ELSE 'Deceased'
  97. END AS Status,
  98. a.AddUser,
  99. DATE_FORMAT(TanggalLahir, '%d-%m-%Y') AS TanggalLahir
  100. , DATE_FORMAT(TanggalLahir, '%d-%M-%Y') AS TanggalLahir2
  101. $sqlinvoice
  102. FROM konsumen a
  103. LEFT JOIN m_agama b
  104. ON a.IdAgama = b.IdAgama
  105. LEFT JOIN m_pekerjaan c
  106. ON a.IdPekerjaan = c.IdPekerjaan
  107. $sqlRestricted
  108. GROUP BY a.IdKonsumen
  109. ORDER BY NamaAkhir";
  110. }
  111. /*
  112. CONCAT(DAY(a.TanggalLahir) ,' ', MONTHNAME(a.TanggalLahir), ' ', YEAR(a.TanggalLahir)) AS TanggalLahir
  113. print_r($this->jqsql);
  114. exit;
  115. echo $this->db->last_query();
  116. exit;
  117. */
  118. $this->IdNegara= $this->session->userdata("idNegara");
  119. $IdNegara= $this->IdNegara;
  120. $lc_group= array("SG"=>"en_GB", "KR"=>"en_GB", "ID"=>"id_ID", "MY"=>"en_GB");
  121. $this->db->query("SET lc_time_names = '" . $lc_group[$IdNegara] . "'");
  122. $this->jqID = "IdKonsumen";
  123. $this->jqRowIgnored = "IdKonsumen";
  124. #$this->jqRowIgnored = array("IdKonsumen", "TanggalLahir2");
  125. $rownum= 10;
  126. $this->jqQr= $this->Gmodel->jqGrid($this->jqsql, $rownum);
  127. //Untuk tes dapetin query
  128. /*
  129. echo $this->db->last_query();
  130. exit;
  131. */
  132. $this->jqField = $this->jqQr["query"]->list_fields();
  133. //returning the sequence number of rows
  134. $this->start = $this->jqQr["start"];
  135. $this->path_self = $this->uri->segment("2") . "/" . __CLASS__ . "/";
  136. $this->IdNegara= $this->session->userdata('idNegara');
  137. if($this->session->userdata('login')!==TRUE){
  138. redirect($this->configlib->site_url().'/login');
  139. }
  140. }
  141. function cek_config(){
  142. $data= $this->config->item('sqlconfig');
  143. print_r($data);
  144. }
  145. //Function to show the jqgrid table
  146. function getlist()
  147. {
  148. $this->jqlib->data = $this->jqQr;
  149. $this->jqlib->rowlist = $this->jqField;
  150. $this->jqlib->rowIgnored = $this->jqRowIgnored;
  151. /*
  152. $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"));
  153. $this->jqlib->colWidth = array("100","100","100","150","120","80","50","120","150","100","100","100");
  154. */
  155. $IdNegara=$this->session->userdata('idNegara');
  156. $reg_country= "#^(ID)$#";
  157. if( preg_match($reg_country, $IdNegara) ){
  158. $this->jqlib->customColName = array(lang("abdi.first_name"),lang("abdi.last_name"),
  159. lang("abdi.email"),lang("abdi.mobile_no"),lang("abdi.sex"),lang("abdi.age"),lang("abdi.religion"),
  160. lang("abdi.pekerjaan"),lang("abdi.status"),lang("abdi.add_user"),"Birth Date","Status Invoice");
  161. }else{
  162. $this->jqlib->customColName = array(lang("abdi.last_name"),lang("abdi.first_name"),
  163. lang("abdi.email"),lang("abdi.mobile_no"),lang("abdi.sex"),lang("abdi.age"),lang("abdi.religion"),
  164. lang("abdi.pekerjaan"),lang("abdi.status"),lang("abdi.add_user"),"Birth Date","Status Invoice");
  165. }
  166. $this->jqlib->colWidth = array("100","150","120","80","50","120","150","100","100","100","150","100");
  167. $this->jqlib->caption = lang("abdi.basic_info");
  168. $this->jqlib->url = "/" . $this->path_self . "xml/null";
  169. #$this->jqlib->url = "/" . $this->path_self . "xml";
  170. $this->jqlib->sortname = "NamaAwal";
  171. $data["jscript"] = $this->jqlib->stream() . $this->extra_js();
  172. $data["frmID"] = "frmAddCus"; //form default ID, this id will be called when edit button clicked
  173. $data['extramenu']= '<img src="' . $this->config->item("img_url") . '/browse.png" id="btnCari" ' .
  174. 'title="Search" style="cursor: pointer;" width= 32 height=32 />';
  175. $data['extramenu'].= '<img src="' . $this->config->item("img_url") . '/book-search.png" id="btnLastVisit" ' .
  176. 'title=" Show last 10 visited customers" style="cursor: pointer;" />';
  177. $data['extramenu'].= '<img src="' . $this->config->item("img_url") . '/view_detail.png" id="btnCustDetail" ' .
  178. 'title="View Detail" style="cursor: pointer;" />';
  179. //$data['extramenu'].= '<button id="btnhidden" name="btnhidden">Hidden</button>';
  180. show_template("vCommon",$data);
  181. }
  182. function datashow(){
  183. $this->xml("newcus", "02006000000056");
  184. #$this->xml("", true);
  185. }
  186. function xml($id="", $lastVisit=false)
  187. {
  188. /*
  189. print_r($this->jqQr['query']->result_array());
  190. exit;
  191. */
  192. $idAkses= $this->session->userdata("idAkses");
  193. if($id == "" && preg_match("#^(SUA|CST|DIR|MGR|MEX|DPS)$#", $idAkses) ){ // Fetch Untuk Default
  194. /*
  195. $this->jqlib->IgnoredRow= array("IdKonsumen","TanggalLahir");
  196. echo $this->jqlib->createXML($this->jqQr,$this->jqID,$this->jqField,$this->jqRowIgnored,$this->start);
  197. */
  198. #$this->jqlib->IgnoredRow= array("TanggalLahir");
  199. echo $this->jqlib->XML($this->jqQr,$this->jqID,$this->jqField,$this->jqRowIgnored,$this->start);
  200. }elseif($id == "newcus"){ // Fetch Untuk New Customer
  201. $sql = "SELECT * FROM (" . $this->jqsql . ") AS x WHERE IdKonsumen= '" . $lastVisit . "'";
  202. $jqQr = $this->Gmodel->jqGrid($sql);
  203. $start = $jqQr["start"];
  204. echo $this->jqlib->XML($jqQr,$this->jqID,$this->jqField,$this->jqRowIgnored,$start);
  205. }elseif($lastVisit == TRUE){ // Fetch Untuk Last Visit
  206. //$sql = "SELECT * FROM ($this->jqsql) AS x WHERE AddUser = '".$this->session->userdata("username")."' AND invoice='Not Fully Paid'";
  207. //if(count($this->db->query($sql)->result_array())<1)
  208. //{
  209. $sql = "SELECT * FROM ($this->jqsql) AS x WHERE AddUser = '".$this->session->userdata("username")."'";
  210. //}
  211. ///echo $this->db->last_query();
  212. //exit;
  213. $rownum = "10";
  214. $jqQr = $this->Gmodel->jqGrid($sql, $rownum);
  215. //echo $sql;
  216. //exit;
  217. $start = $jqQr["start"];
  218. echo $this->jqlib->XML($jqQr,$this->jqID,$this->jqField,$this->jqRowIgnored,$start);
  219. }/*else{
  220. echo $this->jqlib->XML($this->jqQr,$this->jqID,$this->jqField,$this->jqRowIgnored,$this->start);
  221. #echo "test";
  222. }*/
  223. }
  224. //Fungsi yang akan meload view ketika popup dipanggil
  225. function popup($action=null,$customerID=null)
  226. {
  227. if($action=="edit"){
  228. $data["row"] = $this->Gmodel->getCustomerInfo($customerID)->row_array();
  229. $data["rowRel"]= $this->Gmodel->getCustomerInfo($customerID,TRUE)->row_array();
  230. /*
  231. echo "<pre>";
  232. print_r($data["row"]);
  233. echo "<br/>";
  234. print_r($data["rowRel"]);
  235. echo "<br/>";
  236. echo "</pre>";
  237. */
  238. /*
  239. print_r($data["row"]);
  240. echo "<br/>";
  241. print_r($data["rowRel"]);
  242. echo "<br/>";
  243. */
  244. //echo $this->db->last_query();
  245. //exit;
  246. $this->load->view($this->path_self. "/vEdit",$data);
  247. }
  248. if($action=="add")
  249. {
  250. $data["row"] = array("IdKonsumen"=>$this->Gmodel->getLastId());
  251. $data['IdNegara']= $this->IdNegara;
  252. $this->load->view($this->path_self . "/vAdd",$data);
  253. }
  254. }
  255. //Fungsi untuk menyimpan data (add new atau edit)
  256. function save($act)
  257. {
  258. exit;
  259. $POST= $this->input->post();
  260. # print_r($POST);
  261. /*
  262. if( isset($POST["frmname"]) && $POST["frmname"] != "frmAddCus" ){
  263. print_r($POST);
  264. }
  265. */
  266. $idKonsumen= ( isset($POST['IdKonsumen']) ) ? $POST['IdKonsumen'] : "";
  267. /*
  268. echo $idKonsumen;
  269. exit;
  270. echo $POST["TanggalLahir"] . "->";
  271. */
  272. $POST["AddUser"] = $this->session->userdata("username");
  273. $POST["ModifUser"] = $this->session->userdata("username");
  274. $POST["AddDate"] = date("Y-m-d");
  275. $POST["ModifDate"] = date("Y-m-d");
  276. // Tambah Salutation
  277. if( isset($POST['NamaSapaan']) || isset($POST['NamaSapaanKeluarga']) ){
  278. $Sapaan= ( isset($POST['NamaSapaan']) ) ? $POST['NamaSapaan'] : $POST['NamaSapaanKeluarga'];
  279. // Cek NamaSapaan tidak ada
  280. $NamaSapaan= strtolower($Sapaan);
  281. if( $this->db->get_where('m_sapaan', array('NamaSapaan'=>$NamaSapaan))->num_rows() ){
  282. echo "Salutation is already exists !";
  283. exit;
  284. }
  285. // Insert Data New Salutation
  286. $AddUser= $this->session->userdata('username');
  287. $AddDate= date("Y-m-d");
  288. $ins_sapaan= array('NamaSapaan'=>$NamaSapaan, 'AddUser'=>$AddUser, 'AddDate'=>$AddDate);
  289. $this->db->insert('m_sapaan', $ins_sapaan);
  290. if( isset($POST['NamaSapaan']) ){
  291. $POST['IdSapaan']= $this->db->insert_id();
  292. }else{
  293. $POST['IdSapaanKeluarga']= $this->db->insert_id();
  294. }
  295. unset($POST['NamaSapaan'],$POST['NamaSapaanKeluarga']); // Unset NamaSapaan tidak digunakan lagi
  296. }
  297. # Insert $IdNegara sesuai dengan form
  298. if( isset($POST['IdNegara']) || isset($POST['IdNegaraKeluarga']) ){
  299. $IdNegara= ( $POST['frmname'] == "frmAddCus" ) ? $POST['IdNegara'] : $POST['IdNegaraKeluarga'];
  300. }
  301. # Insert ke m_region jika ada $POST['NamaRegion'] dan $POST['NamaRegionKeluarga']
  302. if( isset($POST['NamaRegion']) || isset($POST['NamaRegionKeluarga']) ){
  303. $Region= ( isset($POST['NamaRegion']) ) ? $POST['NamaRegion'] : $POST['NamaRegionKeluarga'];
  304. //$NamaRegion= strtolower($Region);
  305. $NamaRegion= $Region;
  306. $this->db->select("IdRegion");
  307. $query_region= $this->db->get_where('m_region', array('NamaRegion'=>$NamaRegion));
  308. if( $query_region->num_rows() ){ # Jika region ada fetch data
  309. $region= $query_region->row_array();
  310. $IdRegion= $region['IdRegion'];
  311. }else{ # Insert data region baru
  312. $IdRegion= $IdNegara . "-" . substr($NamaRegion, 0, 3); // MY-PEN
  313. $ins_region= array("IdRegion"=>$IdRegion, "NamaRegion"=>$NamaRegion, "IdNegara"=>$IdNegara,
  314. "AddUser"=>$POST["AddUser"], "AddDate"=>$POST["AddDate"]);
  315. $this->db->insert("m_region", $ins_region);
  316. }
  317. // Set $POST sesuai dengan form
  318. if( isset($POST['NamaRegion']) ){
  319. $POST['IdRegion']= $IdRegion;
  320. }else{
  321. $POST['IdRegionKeluarga']= $IdRegion;
  322. }
  323. }
  324. # Insert ke m_kota jika ada $POST['NamaKota'] dan $POST['NamaKotaKeluarga']
  325. if( isset($POST['NamaKota']) || isset($POST['NamaKotaKeluarga']) ){
  326. $Kota= ( isset($POST['NamaKota']) ) ? $POST['NamaKota'] : $POST['NamaKotaKeluarga'];
  327. //$NamaKota= strtolower($Kota);
  328. $NamaKota= $Kota;
  329. $this->db->flush_cache();
  330. $this->db->select("IdKota");
  331. $query_kota= $this->db->get_where('m_kota', array('NamaKota'=>$NamaKota));
  332. if( $query_kota->num_rows() ){ # Jika kota ada fetch data
  333. $kota= $query_kota->row_array();
  334. $IdKota= $kota['IdKota'];
  335. }else{ # Insert data kota baru
  336. $ins_kota= array("NamaKota"=>$NamaKota,"IdRegion"=>$IdRegion,
  337. "AddUser"=>$POST["AddUser"], "AddDate"=>$POST["AddDate"]);
  338. $this->db->insert("m_kota",$ins_kota);
  339. $IdKota= $this->db->insert_id();
  340. }
  341. // Set $POST sesuai dengan form
  342. if( isset($POST['NamaKota']) ){
  343. $POST['IdKota']= $IdKota;
  344. }else{
  345. $POST['IdKotaKeluarga']= $IdKota;
  346. }
  347. }
  348. unset($POST['NamaKota'], $POST['NamaRegion'], $POST['NamaKotaKeluarga'], $POST['NamaRegionKeluarga']);
  349. if($this->input->post("frmname") == "frmAddCus")
  350. {
  351. //
  352. $edit_allow= array("KodeTelponKantor","KodeTelponRumah", "KodeTelponRumah2");
  353. if( $act == "edit" ){ // Jika $act == edit
  354. foreach( $edit_allow as $value ){ // Tetapkan nilai default untuk field kumpulan field Kode
  355. $POST[$value]= "";
  356. }
  357. }
  358. $POST["TanggalLahir"]= date("Y-m-d", strtotime($POST['TanggalLahir'])); //untuk merubah tanggal menjadi d-m-y lk
  359. if( isset($POST["TelponKantor"]) ){
  360. $POST["TelponKantor"] = $POST["KodeTelp1"] . $POST['KodeTelponKantor'] . $POST["TelponKantor"];
  361. unset($POST["KodeTelp1"]);
  362. unset($POST["KodeTelponKantor"]);
  363. }
  364. else{
  365. $POST["TelponKantor"]="";
  366. }
  367. if( isset($POST["NoHP"]) ){
  368. $POST["NoHP"] = $POST["KodeTelp2"] . $POST["NoHP"];
  369. }
  370. else
  371. {
  372. $POST["NoHP"]="";
  373. }
  374. if(isset($POST["NoHP2"])){
  375. $POST["NoHP2"] = $POST["KodeTelp2"] . $POST["NoHP2"];
  376. unset($POST["KodeTelp2"]);
  377. }
  378. else{$POST["NoHP2"]="";
  379. }
  380. if(isset($POST["TelponRumah"])){
  381. $POST["TelponRumah"] = $POST["KodeTelp3"] . $POST['KodeTelponRumah'] . $POST["TelponRumah"];
  382. //unset($POST["KodeTelp"]);
  383. unset($POST['KodeTelponRumah']);
  384. }
  385. else{$POST["TelponRumah"]="";
  386. }
  387. if(isset($POST["TelponRumah2"])){
  388. $POST["TelponRumah2"] = $POST["KodeTelp3"] . $POST['KodeTelponRumah2'] . $POST["TelponRumah2"];
  389. unset($POST["KodeTelp3"]);
  390. unset($POST['KodeTelponRumah2']);
  391. }
  392. else
  393. {
  394. $POST["TelponRumah2"]="";
  395. }
  396. if( $this->IdNegara == "MY" ){
  397. $POST["Alamat"] = $POST["namajalan"];
  398. $POST["Alamat2"] = $POST["namajalan3"];
  399. }else{
  400. $POST["Alamat"] = $POST["namajalan"] . "~" . $POST["houseno"] . "~" . $POST["unitno"];
  401. }
  402. unset($POST["namajalan"]);
  403. unset($POST["houseno"]);
  404. unset($POST["unitno"]);
  405. unset($POST["namajalan3"]);
  406. $table = "konsumen";
  407. }
  408. else{
  409. // Form Keluarga
  410. $konsumen_keluarga= array("IdSapaanKeluarga","NamaAwalKeluarga",
  411. "NamaAkhirKeluarga","PanggilanKeluarga","JenisKelaminKeluarga",
  412. "IdPekerjaanKeluarga","IdAgamaKeluarga","TempatLahirKeluarga",
  413. "TanggalLahirKeluarga","AlamatKeluarga","namajalan2","houseno2","AlamatKeluarga2","namajalan4",
  414. "unitno2","KodePosKeluarga","IdNegaraKeluarga","IdRegionKeluarga",
  415. "IdKotaKeluarga","KodeTelp4","TelponKantorKeluarga",
  416. "KodeTelp5","NoHPKeluarga","KodeTelp7","NoHPKeluarga2","KodeTelp6","TelponRumahKeluarga","KodeTelp8","TelponRumahKeluarga2","EmailKeluarga",
  417. "AddUser","ModifUser","AddDate","ModifDate");
  418. foreach( $konsumen_keluarga as $value ){
  419. $POST[$value]= isset($POST[$value]) ? $POST[$value] : "";
  420. }
  421. if($POST["TanggalLahirKeluarga"]=="1970-01-01")
  422. {
  423. unset($POST["TanggalLahirKeluarga"]);
  424. }
  425. else
  426. {
  427. $POST["TanggalLahirKeluarga"]= date("Y-m-d", strtotime($POST['TanggalLahirKeluarga'])); //untuk merubah tanggal menjadi d-m-y
  428. }
  429. if( $this->IdNegara == "MY" ){
  430. $POST["AlamatKeluarga"] = $POST["namajalan2"];
  431. $POST["AlamatKeluarga2"] = $POST["namajalan4"];
  432. }else{
  433. $POST["AlamatKeluarga"] = $POST["namajalan2"] . "~" . $POST["houseno2"] . "~" . $POST["unitno2"];
  434. }
  435. unset($POST["namajalan2"]);
  436. unset($POST["houseno2"]);
  437. unset($POST["unitno2"]);
  438. unset($POST["namajalan4"]);
  439. #if( $act == "add" ){
  440. // Unset Data $POST dg value kosong
  441. $allowme= array("IdNegaraKeluarga","IdRegionKeluarga","IdKotaKeluarga","JenisKelaminKeluarga");
  442. foreach( $POST as $key=>$value ){
  443. if( empty($value) && ! in_array($key, $allowme) ){
  444. unset($POST[$key]);
  445. }
  446. }
  447. $edit_allow= array("KodeTelponKantorKeluarga",
  448. "KodeTelponRumahKeluarga", "KodeTelponRumahKeluarga2");
  449. if( $act == "edit" ){ // Jika $act == edit
  450. foreach( $edit_allow as $value ){ // Tetapkan nilai default untuk field kumpulan field Kode
  451. $POST[$value]= "";
  452. }
  453. }
  454. if( isset($POST["TelponKantorKeluarga"]) ){
  455. $POST["TelponKantorKeluarga"]= $POST["KodeTelp4"] . $POST["KodeTelponKantorKeluarga"] . $POST["TelponKantorKeluarga"];
  456. }else{
  457. $POST["TelponKantorKeluarga"]="";
  458. }
  459. unset($POST["KodeTelp4"], $POST["KodeTelponKantorKeluarga"]);
  460. if( isset($POST["NoHPKeluarga"]) ){
  461. $POST["NoHPKeluarga"]= $POST["KodeTelp5"] . $POST["NoHPKeluarga"];
  462. //unset($POST["KodeTelp5"]);
  463. }
  464. else
  465. {
  466. $POST["NoHPKeluarga"]="";
  467. }
  468. //unset($POST["KodeTelp5"]);
  469. if( isset($POST["NoHPKeluarga2"]) ){
  470. $POST["NoHPKeluarga2"]= $POST["KodeTelp7"] . $POST["NoHPKeluarga2"];
  471. //unset($POST["KodeTelp7"]);
  472. }
  473. else
  474. {
  475. $POST["NoHPKeluarga2"]="";
  476. }
  477. if( isset($POST["TelponRumahKeluarga"]) ){
  478. $POST["TelponRumahKeluarga"]= $POST["KodeTelp6"] . $POST['KodeTelponRumahKeluarga'] .
  479. $POST["TelponRumahKeluarga"];
  480. //if( isset($POST["TelponRumahKeluarga"]) ){
  481. // $POST["TelponRumahKeluarga"]= $POST["KodeTelp6"] . $POST["TelponRumahKeluarga"];
  482. //unset($POST["KodeTelp6"]);
  483. // unset($POST["KodeTelponRumahKeluarga"]);
  484. }
  485. else
  486. {
  487. $POST["TelponRumahKeluarga"]="";
  488. }
  489. if( isset($POST["TelponRumahKeluarga2"]) ){
  490. $POST["TelponRumahKeluarga2"]= $POST["KodeTelp8"] . $POST['KodeTelponRumahKeluarga2'] .
  491. $POST["TelponRumahKeluarga2"];
  492. /*if( isset($POST["TelponRumahKeluarga2"]) ){
  493. $POST["TelponRumahKeluarga2"]= $POST["KodeTelp8"] . $POST["TelponRumahKeluarga2"];*/
  494. // unset($POST["KodeTelp8"]);
  495. // unset($POST["KodeTelponRumahKeluarga2"]);
  496. }
  497. else
  498. {
  499. $POST["TelponRumahKeluarga2"]="";
  500. }
  501. unset($POST["KodeTelp4"], $POST["KodeTelp5"], $POST["KodeTelp6"], $POST["KodeTelp7"],
  502. $POST["KodeTelp8"], $POST['KodeTelponKantorKeluarga'], $POST['KodeTelponRumahKeluarga'], $POST['KodeTelponRumahKeluarga2']);
  503. #}
  504. if( $POST["IdKeluarga"] == "" ){
  505. $POST["JenisKelaminKeluarga"]= "";
  506. }
  507. $table = "konsumen_keluarga";
  508. #unset($POST["frmname"]);
  509. }
  510. if( $act=="add" )
  511. {
  512. if( $POST["frmname"] == "frmAddCus" ){
  513. $idKonsumen= $this->Gmodel->getLastId(); // Set the default value to call the method __updatestatus
  514. // The Post IdKonsumen variable Will automaticly truncated when system try to save the konsumen_keluarga
  515. $POST['IdKonsumen']= $idKonsumen;
  516. }
  517. if(isset($POST["IdSource"]))
  518. {
  519. $opt= $POST["IdSource"];
  520. $this->db->select('IdMediaType');
  521. $this->db->group_by('MediaType');
  522. $media= $this->db->get('m_media_type')->result_array();
  523. $type= array();
  524. foreach( $media as $key=>$value ){
  525. $IdMediaType= str_replace("-", "\-", $value['IdMediaType']);
  526. $type[]= $IdMediaType;
  527. }
  528. $regsource= implode("|", $type);
  529. $regsource= "#^(" . $regsource . ")$#";
  530. if( preg_match($regsource, $opt) ){ // Insert to source_by_advertisement table wat Source Information
  531. $sources= array("IdKonsumen","IdSource","IdMediaKategori","IdMedia");
  532. foreach( $sources as $value ){
  533. $POST[$value]= ( isset($POST[$value]) ) ? $POST[$value] : "";
  534. }
  535. unset($POST["Title"], $POST["HospitalName"]);
  536. #$title= ( isset($POST['Title']) ) ? $POST['Title'] : "";
  537. $source= array("IdKonsumen"=>$POST["IdKonsumen"],
  538. "IdMediaType"=>$POST["IdSource"],"IdMediaKategori"=>$POST["IdMediaKategori"],
  539. "IdMedia"=>$POST["IdMedia"],"AddDate"=>date("Y-m-d"),
  540. "AddUser"=>$this->session->userdata("username"));
  541. $this->Gmodel->add("source_by_advertisement", $source);
  542. }else{
  543. switch($POST["IdSource"]) //Untuk menyimpan data customer source infomation
  544. {
  545. case "1" :
  546. break;
  547. case "6" : // Untuk simpan data konsumen dengan source information : doctor_referral
  548. $this->Gmodel->add("source_by_doctor_referral",array("IdKonsumen"=>$POST["IdKonsumen"],
  549. "NamaKlinik"=>$POST["NamaKlinik"],"NamaDokter"=>$POST["NamaDokter"],
  550. "AddDate"=>date("Y-m-d")));
  551. break;
  552. default : // simpan data ke table source_by_dump
  553. $this->Gmodel->add("source_by_dump",array("IdKonsumen"=>$POST["IdKonsumen"],
  554. "AddDate"=>date("Y-m-d"), "IdSource"=>$POST["IdSource"]));
  555. break;
  556. }
  557. }
  558. }
  559. //Hapus semua array dengan index yang diinsert pada source information karena index tersebut tidak digunakan untuk insert ke tabel konsumen
  560. if(isset($POST["IdMediaType"])) unset($POST["IdMediaType"]);
  561. if(isset($POST["IdMediaType"])) unset($POST["IdMediaType"]);
  562. if(isset($POST["IdMediaKategori"])) unset($POST["IdMediaKategori"]);
  563. if(isset($POST["IdMedia"])) unset($POST["IdMedia"]);
  564. if(isset($POST["IdIklan"])) unset($POST["IdIklan"]);
  565. if(isset($POST["NamaKlinik"])) unset($POST["NamaKlinik"]);
  566. if(isset($POST["NamaDokter"])) unset($POST["NamaDokter"]);
  567. if(isset($POST["event"])) unset($POST["event"]);
  568. if(isset($POST["IdSource"])) unset($POST["IdSource"]);
  569. if(isset($POST["NamaMedia"])) unset($POST["NamaMedia"]);
  570. /*
  571. if( isset($POST["frmname"]) && $POST["frmname"] == "frmAddOther" ){
  572. print_r($POST);
  573. }
  574. */
  575. if( $POST["frmname"] == "frmAddCus" ){
  576. $base_url= base_url();
  577. if( $base_url != "http://thsgcrmid.com/crm_test/" ){
  578. // Insert Data To SQL Server
  579. /*
  580. $sqlserver['hostname'] = "E-FUN\HIMSA";
  581. $sqlserver['username'] = "sa";
  582. $sqlserver['password'] = "1234";
  583. $sqlserver['database'] = "NOAHSystem";
  584. $sqlserver['dbdriver'] = "mssql";
  585. $sqlserver['dbprefix'] = "";
  586. $sqlserver['pconnect'] = FALSE;
  587. $sqlserver['db_debug'] = TRUE;
  588. $sqlserver['cache_on'] = FALSE;
  589. $sqlserver['cachedir'] = "";
  590. $sqlserver['char_set'] = "utf8";
  591. $sqlserver['dbcollat'] = "utf8_general_ci";
  592. $sqlserver['autoinit'] = TRUE;
  593. $sqlserver['stricton'] = FALSE;
  594. $sqlserver= $this->config->item('sqlconfig');
  595. $server= $this->load->database($sqlserver, TRUE);
  596. $tgl= date("m/d/Y g:i:s A");
  597. $data= array('UserID'=>'8',
  598. 'CreateDate'=>$tgl,
  599. 'FirstName'=>$POST['NamaAwal'],
  600. 'LastName'=>$POST['NamaAkhir']);
  601. $response= $server->insert('Client', $data);
  602. $POST['NoahID']= $server->insert_id();
  603. if( ! $response ){
  604. exit;
  605. }
  606. */
  607. }
  608. $msg= "IdKonsumen" . "," . $idKonsumen;
  609. }else{
  610. $msg= "1";
  611. }
  612. unset($POST["frmname"]);
  613. /*
  614. if( $POST["frmname"] == "frmAddOther" ){
  615. print_r($POST);
  616. }
  617. */
  618. if($this->Gmodel->add($table, $POST))
  619. {
  620. echo $msg;
  621. }else{
  622. echo 0;
  623. }
  624. }elseif($act=="edit")
  625. {
  626. $doesExists = $this->Gmodel->isExist($table,array("IdKonsumen"=>$idKonsumen));
  627. if( $doesExists ) // Klo Ada
  628. {
  629. /*
  630. $base_url= base_url();
  631. if( $base_url != "http://thsgcrmid.com/crm_test/" ){
  632. print_r($POST);
  633. if( $table == "konsumen" ){
  634. $sqlserver= $this->config->item('sqlconfig');
  635. $server= $this->load->database($sqlserver, TRUE);
  636. // Get NoahID
  637. $noahdt= $this->db->get_where('konsumen', array('IdKonsumen'=>$POST['IdKonsumen']))->row_array();
  638. // Update Data to NOAH
  639. $data= array('FirstName'=>$POST['NamaAwal'],
  640. 'LastName'=>$POST['NamaAkhir']);
  641. $server->where('ID', $noahdt['NoahID']);
  642. $response= $server->update('Client', $data);
  643. }
  644. }
  645. */
  646. if( $table == "konsumen_keluarga" && $POST['IdKeluarga'] == "" ){
  647. $tbl_fields= $this->db->list_fields('konsumen_keluarga');
  648. $reg_exception= "#^(IdKonsumen|IdKeluarga|AddUser|AddDate|ModifUser|ModifDate)$#";
  649. foreach( $tbl_fields as $field ){
  650. if( ! preg_match($reg_exception, $field) ){
  651. $POST[$field]= "";
  652. }
  653. }
  654. }
  655. unset($POST["IdKonsumen"]);
  656. unset($POST["frmname"]);
  657. //print_r($table);
  658. //exit;
  659. $where= array("IdKonsumen"=>$idKonsumen);
  660. #print_r($POST);
  661. if($this->Gmodel->edit($table, $POST, $where) != "-1")
  662. {
  663. echo 1;
  664. }else{
  665. echo 0;
  666. }
  667. }else{ // Klo gak ada
  668. if($this->Gmodel->add($table, $POST))
  669. {
  670. echo 1;
  671. }else{
  672. echo 0;
  673. }
  674. }
  675. }elseif($act=="proceed")
  676. {
  677. if(isset($_POST["IdSource"]))
  678. {
  679. switch($_POST["IdSource"]) //Untuk menyimpan data customer source infomation
  680. {
  681. case "1" :
  682. break;
  683. case "3" : //Untuk insert data konsumen dengan source information : event
  684. $this->Gmodel->add("source_by_event",array("IdKonsumen"=>$_POST["IdKonsumen"],"IdEvent"=>$_POST["event"],
  685. "AddUser"=>$this->session->userdata("username"),"AddDate"=>date("Y-m-d")));
  686. break;
  687. case "4" : //Untuk insert data konsumen dengan source information : advertisement
  688. $this->Gmodel->add("source_by_advertisement",array("IdKonsumen"=>$_POST["IdKonsumen"],
  689. "IdMediaType"=>$_POST["IdMediaType"],"IdMediaKategori"=>$_POST["IdMediaKategori"],
  690. "IdMedia"=>$_POST["IdMedia"],"AddDate"=>date("Y-m-d"),
  691. "AddUser"=>$this->session->userdata("username")));
  692. break;
  693. case "6" : //Untuk simpan data konsumen dengan source information : doctor_referral
  694. $this->Gmodel->add("source_by_doctor_referral",array("IdKonsumen"=>$_POST["IdKonsumen"],
  695. "NamaKlinik"=>$_POST["NamaKlinik"],"NamaDokter"=>$_POST["NamaDokter"],"AddDate"=>date("Y-m-d")));
  696. break;
  697. default : //simpan data ke table source_by_dump
  698. $this->Gmodel->add("source_by_dump",array("IdKonsumen"=>$_POST["IdKonsumen"],"AddDate"=>date("Y-m-d"),
  699. "IdSource"=>$_POST["IdSource"]));
  700. break;
  701. }
  702. }
  703. //Hapus semua array dengan index yang diinsert pada source information karena index tersebut tidak digunakan untuk insert ke tabel konsumen
  704. if(isset($_POST["IdMediaType"])) unset($_POST["IdMediaType"]);
  705. if(isset($_POST["IdMediaType"])) unset($_POST["IdMediaType"]);
  706. if(isset($_POST["IdMediaKategori"])) unset($_POST["IdMediaKategori"]);
  707. if(isset($_POST["IdMedia"])) unset($_POST["IdMedia"]);
  708. if(isset($_POST["IdIklan"])) unset($_POST["IdIklan"]);
  709. if(isset($_POST["NamaKlinik"])) unset($_POST["NamaKlinik"]);
  710. if(isset($_POST["NamaDokter"])) unset($_POST["NamaDokter"]);
  711. if(isset($_POST["event"])) unset($_POST["event"]);
  712. if(isset($_POST["IdSource"])) unset($_POST["IdSource"]);
  713. if($this->Gmodel->proceed($table,$_POST))
  714. {
  715. echo 1;
  716. }else{
  717. echo 0;
  718. }
  719. }
  720. #$this->update_status($idKonsumen);
  721. }
  722. //fungsi untuk menghapus data
  723. function delete()
  724. {
  725. $id= $this->input->post("id");
  726. $base_url= base_url();
  727. if( $base_url != "http://thsgcrmid.com/crm_test/" ){
  728. $sqlserver= $this->config->item('sqlconfig');
  729. $server= $this->load->database($sqlserver, TRUE);
  730. // Get NoahID
  731. $noahdt= $this->db->get_where('konsumen', array('IdKonsumen'=>$id))->row_array();
  732. // Delete Data in NOAH
  733. $server->where('ID', $noahdt['NoahID']);
  734. $response= $server->delete('Client');
  735. }
  736. $where = array("IdKonsumen"=>$id);
  737. if($this->Gmodel->delete("konsumen",$where))
  738. {
  739. if($this->Gmodel->delete("konsumen_keluarga",$where))
  740. {
  741. echo "1";
  742. }else{
  743. echo "2";
  744. }
  745. }else{
  746. echo "0";
  747. }
  748. }
  749. function auto_complete($opt){
  750. #$str= $_GET["term"];
  751. $GET= $this->input->get();
  752. $regopt= "#^(namakotakeluarga|namakota)$#";
  753. if( preg_match($regopt, $opt) ){
  754. $sqlSearch = "SELECT * FROM m_kota a
  755. INNER JOIN m_region b ON b.IdRegion = a.IdRegion
  756. INNER JOIN m_negara c ON c.IdNegara = b.IdNegara
  757. WHERE a.NamaKota LIKE '%" . $GET['IdVal'] . "%' AND c.IdNegara = '" .
  758. $GET['IdNegara'] . "'";
  759. }else{
  760. $sqlSearch = "SELECT * FROM m_region a
  761. INNER JOIN m_negara c ON c.IdNegara = a.IdNegara
  762. WHERE a.NamaRegion LIKE '%" . $GET['IdVal'] . "%' AND c.IdNegara = '" .
  763. $GET['IdNegara'] . "'";
  764. }
  765. /*
  766. #print_r($hasil);
  767. echo $this->db->last_query();
  768. exit;
  769. */
  770. $rows= $this->db->query($sqlSearch)->result_array();
  771. $data= array();
  772. foreach( $rows as $row )
  773. {
  774. $text= ( preg_match($regopt, $opt) ) ? $row['NamaKota'] : $row['NamaRegion'];
  775. $data[]= array("id"=>$text, "label"=>$text, "value"=>$text);
  776. }
  777. echo json_encode($data);
  778. }
  779. //Fungsi untuk mendapatkan kota dan region
  780. function getAJAX($opt,$id="")
  781. {
  782. if( $this->IdNegara == "SG" ){
  783. switch($opt)
  784. {
  785. case "region" :
  786. //echo "<option value=''>--".lang('abdi.select_region')."--</option>";
  787. foreach($this->Gmodel->getRegionByNegara($id) as $region)
  788. {
  789. echo "<option value=\"".$region->IdRegion."\">".$region->NamaRegion."</option>";
  790. }
  791. break;
  792. case "kota" :
  793. //echo "<option value=''>--".lang('abdi.select_city')."--</option>";
  794. foreach($this->Gmodel->getKotaByRegion($id) as $kota)
  795. {
  796. echo "<option value=\"".$kota->IdKota."\">".$kota->NamaKota."</option>";
  797. }
  798. break;
  799. }
  800. }else{
  801. switch($opt)
  802. {
  803. case "region" :
  804. echo "<option value=''>--".lang('abdi.select_region')."--</option>";
  805. foreach($this->Gmodel->getRegionByNegara($id) as $region)
  806. {
  807. echo "<option value=\"".$region->IdRegion."\">".$region->NamaRegion."</option>";
  808. }
  809. break;
  810. case "kota" :
  811. echo "<option value=''>--".lang('abdi.select_city')."--</option>";
  812. foreach($this->Gmodel->getKotaByRegion($id) as $kota)
  813. {
  814. echo "<option value=\"".$kota->IdKota."\">".$kota->NamaKota."</option>";
  815. }
  816. break;
  817. }
  818. }
  819. }
  820. /*------ Function2 dibawah ini digunakan untuk merender objek2 html yang diperlukan untuk source information ---*/
  821. function update_me(){
  822. $IdKonsumen= "02001000000683";
  823. $this->update_status($IdKonsumen);
  824. }
  825. //update the customer status 0=Pending, 1=Active, 2=Opt Out, 3=Deceased.
  826. public function update_status($IdKonsumen,$opt="")
  827. {
  828. if($opt != "" && $opt != "remove")
  829. {
  830. switch($opt)
  831. {
  832. case "optout" :
  833. $set = array("KonsumenStatus"=>"2");
  834. break;
  835. case "deceased" :
  836. $set = array("KonsumenStatus"=>"3");
  837. break;
  838. case "remove" :
  839. $set = array("KonsumenStatus"=>"0");
  840. break;
  841. default :
  842. break;
  843. }
  844. }else{
  845. $where= array("IdKonsumen"=>$IdKonsumen);
  846. $qr= $this->Gmodel->getRecordArray("konsumen_keluarga",$where);
  847. $passed= TRUE;
  848. /*
  849. echo "<pre>";
  850. print_r($qr);
  851. echo "<pre>";
  852. */
  853. foreach( $qr as $key=>$row ){
  854. $group_fields= array("MY"=>array("PanggilanKeluarga"),
  855. "KR"=>array("PanggilanKeluarga", "TempatLahirKeluarga", "AlamatKeluarga2"),
  856. "ID"=>array("AlamatKeluarga2"),
  857. "SG"=>array("AlamatKeluarga2")
  858. );
  859. $gselected= ( isset($group_fields[$this->IdNegara]) ) ? $group_fields[$this->IdNegara] : array();
  860. if( ! in_array($key, $gselected) ){
  861. #echo $key . "->" . strlen($row) . "\n";
  862. if( ! strlen($row) ){
  863. $passed= FALSE;
  864. }
  865. }
  866. }
  867. #exit;
  868. $set= ( $passed ) ? array("KonsumenStatus"=>"1") : array("KonsumenStatus"=>"0");
  869. /*
  870. if($passed)
  871. {
  872. $set= array("KonsumenStatus"=>"1");
  873. }else{
  874. $set= array("KonsumenStatus"=>"0");
  875. }
  876. print_r($set);
  877. exit;
  878. */
  879. #print_r($set);
  880. }
  881. $where = array("IdKonsumen"=>$IdKonsumen);
  882. return $this->Gmodel->edit("konsumen", $set, $where);
  883. }
  884. function getMedia($local=""){
  885. if( empty($local) ){
  886. $POST= $this->input->post();
  887. }else{
  888. $POST= $local;
  889. }
  890. /*
  891. print_r($POST);
  892. exit;
  893. */
  894. foreach( $POST as $key=>$value ){
  895. $$key= $value;
  896. }
  897. $html= "";
  898. switch($opt){
  899. case "IdMediaType" :
  900. $html= "";
  901. if( !empty($id) ){
  902. /*
  903. echo $opt . "->" . $id;
  904. exit;
  905. */
  906. $this->db->order_by("MediaKategori","asc");
  907. $data= $this->db->get_where('m_media_kategori', array($opt=>$id))->result_array();
  908. if( ! empty($data) ){
  909. $html= "
  910. <tr id='rowAdded'>
  911. <td>Media Category</td>
  912. <td>:</td>
  913. <td>
  914. <select name='IdMediaKategori' id='IdMediaKategori' class='required'>
  915. <option value=\"\">-- Select Category --</option>";
  916. foreach( $data as $value )
  917. {
  918. $html.= "<option value=\"" . $value['IdMediaKategori'] . "\">" .
  919. $value['MediaKategori'] . "</option>";
  920. }
  921. $html.= "
  922. </select>
  923. </td>
  924. </tr>
  925. ";
  926. }else{
  927. #$this->IdNegara= "ID";
  928. $data= $this->db->get_where("m_media_type", array("IdMediaType"=>$id))->row_array();
  929. if( $data['MediaType'] != "WALK IN" ){
  930. $sql= "SELECT * FROM m_media a
  931. INNER JOIN user b ON b.Username= a.AddUser
  932. INNER JOIN klinik c ON c.IdKlinik= b.IdKlinik
  933. WHERE c.IdNegara= '" . $this->IdNegara . "' AND a.IdMediaType= '" . $id . "'
  934. ORDER BY a.NamaMedia ASC
  935. ";
  936. $data= $this->db->query($sql)->result_array();
  937. /*
  938. $this->db->order_by("NamaMedia","asc");
  939. $data= $this->db->get_where('m_media', array($opt=>$id))->result_array();
  940. */
  941. $html= "
  942. <tr id='rowAdded'>
  943. <td>Event </td>
  944. <td>:</td>
  945. <td>
  946. <select name='IdMedia' id='IdMedia' class='required'>
  947. ";
  948. if( ! empty($data) ){
  949. foreach( $data as $value )
  950. {
  951. $html.= "<option value=\"" . $value['IdMedia'] . "\">" .
  952. $value['NamaMedia'] . "</option>";
  953. }
  954. }else{
  955. $html.= "<option value=\"\">--- Event is empty ---</option>";
  956. }
  957. $html.= "
  958. </select>
  959. </td>
  960. </tr>
  961. ";
  962. }
  963. }
  964. #$data.= "<option value=\"02001-CAT0013\">OTHER</option>";
  965. }
  966. break;
  967. case "IdMediaKategori" :
  968. $html= "";
  969. /*
  970. $sql= "SELECT a.MediaType FROM m_media_type a
  971. INNER JOIN m_media_kategori b ON b.IdMediaType= a.IdMediaType
  972. WHERE b.IdMediaKategori= '" . $MediaCat . "'";
  973. $row= $this->db->query($sql)->row_array();
  974. print_r($row
  975. */
  976. #$this->IdNegara= "ID";
  977. if( !empty($id) ){
  978. $sql= "SELECT * FROM m_media a
  979. INNER JOIN user b ON b.Username= a.AddUser
  980. INNER JOIN klinik c ON c.IdKlinik= b.IdKlinik
  981. WHERE c.IdNegara= '" . $this->IdNegara . "' AND a.IdMediaKategori= '" . $id . "'
  982. GROUP BY a.NamaMedia
  983. ORDER BY a.NamaMedia ASC
  984. ";
  985. $data= $this->db->query($sql)->result_array();
  986. /* Old Script
  987. $this->db->order_by("NamaMedia","asc");
  988. $this->db->group_by('NamaMedia');
  989. $data= $this->db->get_where('m_media', array($opt=>$id))->result_array();
  990. */
  991. $html= "<tr id='rowAdded'>";
  992. if( ! empty($data) ){
  993. $cat= $this->db->get_where('m_media_kategori', array('IdMediaKategori'=>$id))->row_array();
  994. if( $cat['MediaKategori'] == "FACEBOOK" ){
  995. $html.= "<td>Event </td>
  996. <td>:</td>
  997. <td>";
  998. $html.= "<select name='NamaMedia' id='NamaMedia' class='required'>";
  999. $html.= "<option value=\"\">-- Select Event --</option>";
  1000. foreach( $data as $value )
  1001. {
  1002. $html.= "<option value=\"" . $value['NamaMedia'] . "\">" .
  1003. $value['NamaMedia'] . "</option>";
  1004. }
  1005. }else{
  1006. $title= "Event";
  1007. $sql= "SELECT a.MediaType FROM m_media_type a
  1008. INNER JOIN m_media_kategori b ON b.IdMediaType= a.IdMediaType
  1009. WHERE b.IdMediaKategori= '" . $id . "'";
  1010. $row= $this->db->query($sql)->row_array();
  1011. #echo $row['MediaType'] . "\n";
  1012. if( $row['MediaType'] == "MEDICAL" ){ // Jika Media Source == MEDICAL
  1013. $sql= "SELECT a.MediaType FROM m_media_type a
  1014. INNER JOIN m_media_kategori b ON b.IdMediaType= a.IdMediaType
  1015. WHERE b.IdMediaKategori= '" . $id . "'";
  1016. /*
  1017. $kategori= $this->db->select('MediaKategori')->
  1018. get_where('m_media_kategori', array("IdMediaKategori"=>$id))->row_array();
  1019. */
  1020. #if( $kategori['MediaKategori'] == "HOSPITAL" ){
  1021. $html.= "<td>Hospital/Clinic/Company Name </td>
  1022. <td>:</td>
  1023. <td>";
  1024. $html.= "<select name='HospitalName' id='HospitalName' class='required'>";
  1025. // SQL Hospitals
  1026. $sql= "SELECT HospitalName FROM m_media a
  1027. INNER JOIN user b ON b.Username= a.AddUser
  1028. INNER JOIN klinik c ON c.IdKlinik= b.IdKlinik
  1029. WHERE HospitalName != '' AND HospitalName IS NOT NULL
  1030. AND IdMediaKategori= '" . $id . "' AND c.IdNegara= '" . $this->IdNegara . "'
  1031. GROUP BY HospitalName";
  1032. $hospitals= $this->db->query($sql)->result_array();
  1033. $html.= '<option value="">--- Select ---</option>';
  1034. foreach( $hospitals as $hospital ){
  1035. $html.= '<option value="' . $hospital['HospitalName'] . '">' .
  1036. $hospital['HospitalName'] . '</option>';
  1037. }
  1038. $html.= "
  1039. </select>
  1040. </td>
  1041. </tr>
  1042. ";
  1043. $html.= "<tr id='rowAdded'>";
  1044. #}
  1045. /*
  1046. else{
  1047. echo "title";
  1048. exit;
  1049. $html.= "<td>Title </td>
  1050. <td>:</td>
  1051. <td>";
  1052. $html.= "<select name='Title' id='Title' class='required'>";
  1053. $sql= "SELECT Title FROM m_media
  1054. WHERE Title != '' AND Title IS NOT NULL
  1055. AND HospitalName != ''
  1056. GROUP BY Title";
  1057. $titles= $this->db->query($sql)->result_array();
  1058. $html.= '<option value="">--- Select ---</option>';
  1059. foreach( $titles as $title ){
  1060. $html.= '<option value="' . $title['Title'] . '">' .
  1061. $title['Title'] . '</option>';
  1062. }
  1063. $html.= "
  1064. </select>
  1065. </td>
  1066. </tr>
  1067. ";
  1068. $html.= "<tr id='rowAdded'>";
  1069. #$title= "Name";
  1070. }
  1071. */
  1072. }else{
  1073. $html.= "<td>" . $title . "</td>
  1074. <td>:</td>
  1075. <td>";
  1076. #$html.= "<select name='" . $name . "' id='" . $name . "' class='required'>";
  1077. $html.= "<select name='IdMedia' id='IdMedia' class='required'>";
  1078. $html.= '<option value="">--- Select ---</option>';
  1079. foreach( $data as $value )
  1080. {
  1081. $html.= "<option value=\"" . $value['IdMedia'] . "\">" .
  1082. $value['NamaMedia'] . "</option>";
  1083. }
  1084. }
  1085. }
  1086. }else{
  1087. /*
  1088. echo "gp";
  1089. exit;
  1090. */
  1091. $title= "Event";
  1092. $cat= $this->db->get_where('m_media_kategori', array('IdMediaKategori'=>$id))->row_array();
  1093. $name= ( $cat['MediaKategori'] == "FACEBOOK" ) ? "NamaMedia" : "IdMedia";
  1094. $sql= "SELECT a.MediaType FROM m_media_type a
  1095. INNER JOIN m_media_kategori b ON b.IdMediaType= a.IdMediaType
  1096. WHERE b.IdMediaKategori= '" . $id . "'";
  1097. $row= $this->db->query($sql)->row_array();
  1098. #echo $row['MediaType'] . "\n";
  1099. if( $row['MediaType'] == "MEDICAL" ){
  1100. $title= "Hospital/Clinic/Company Name ";
  1101. $name= "HospitalName";
  1102. }
  1103. $html.= "<td>" . $title . "</td>
  1104. <td>:</td>
  1105. <td>";
  1106. $html.= "<select name='" . $name . "' id='" . $name . "' class='required'>";
  1107. $html.= "<option value=\"\">--- Event is empty ---</option>";
  1108. }
  1109. $html.= "
  1110. </select>
  1111. </td>
  1112. </tr>
  1113. ";
  1114. }
  1115. break;
  1116. case "NamaMedia":
  1117. $html= "";
  1118. if( !empty($id) ){
  1119. $data= $this->db->get_where('m_media', array($opt=>$id))->result_array();
  1120. $html= "
  1121. <tr id='rowAdded'>
  1122. <td>Area </td>
  1123. <td>:</td>
  1124. <td>
  1125. <select name='Area' id='Area' class='required'>
  1126. ";
  1127. if( ! empty($data) ){
  1128. foreach( $data as $value )
  1129. {
  1130. $html.= "<option value=\"" . $value['IdMedia'] . "\">" .
  1131. $value['Area'] . "</option>";
  1132. }
  1133. }else{
  1134. $html.= "<option value=\"\">--- Area is empty ---</option>";
  1135. }
  1136. $html.= "
  1137. </select>
  1138. </td>
  1139. </tr>
  1140. ";
  1141. }
  1142. break;
  1143. case "HospitalName":
  1144. $html= "";
  1145. #$html= "title";
  1146. if( !empty($id) ){
  1147. /* Yang Pake Title
  1148. $data= $this->db->select('IdMedia,NamaMedia')->get_where('m_media', array($opt=>$id))->result_array();
  1149. $html.= "
  1150. <tr id='rowAdded'>
  1151. <td>Title </td>
  1152. <td>:</td>
  1153. <td>
  1154. <select name='Title' id='Title' class='required'>
  1155. ";
  1156. $sql= "SELECT Title FROM m_media
  1157. WHERE Title != '' AND Title IS NOT NULL
  1158. AND HospitalName= '" . $id . "'
  1159. GROUP BY Title";
  1160. $titles= $this->db->query($sql)->result_array();
  1161. $html.= '<option value="">--- Select ---</option>';
  1162. foreach( $titles as $title ){
  1163. $html.= '<option value="' . $title['Title'] . '">' .
  1164. $title['Title'] . '</option>';
  1165. }
  1166. $html.= "
  1167. </select>
  1168. </td>
  1169. </tr>
  1170. ";
  1171. */
  1172. $data= $this->db->select('IdMedia,NamaMedia')->get_where('m_media', array($opt=>$id))->result_array();
  1173. $html.= "
  1174. <tr id='rowAdded'>
  1175. <td>Name </td>
  1176. <td>:</td>
  1177. <td>
  1178. <select name='IdMedia' id='IdMedia' class='required'>
  1179. ";
  1180. if( ! empty($data) ){
  1181. foreach( $data as $value )
  1182. {
  1183. $html.= "<option value=\"" . $value['IdMedia'] . "\">" .
  1184. ucwords(strtolower($value['NamaMedia'])) . "</option>";
  1185. }
  1186. }else{
  1187. $html.= "<option value=\"\">--- Data is empty ---</option>";
  1188. }
  1189. $html.= "
  1190. </select>
  1191. </td>
  1192. </tr>
  1193. ";
  1194. }
  1195. break;
  1196. case "Title":
  1197. $html= "";
  1198. #$html= "title";
  1199. if( !empty($id) ){
  1200. $data= $this->db->select('IdMedia,NamaMedia')->get_where('m_media', array($opt=>$id, "HospitalName"=>$hospital))->result_array();
  1201. $html.= "
  1202. <tr id='rowAdded'>
  1203. <td>Name </td>
  1204. <td>:</td>
  1205. <td>
  1206. <select name='IdMedia' id='IdMedia' class='required'>
  1207. ";
  1208. if( ! empty($data) ){
  1209. foreach( $data as $value )
  1210. {
  1211. $html.= "<option value=\"" . $value['IdMedia'] . "\">" .
  1212. ucwords(strtolower($value['NamaMedia'])) . "</option>";
  1213. }
  1214. }else{
  1215. $html.= "<option value=\"\">--- Data is empty ---</option>";
  1216. }
  1217. $html.= "
  1218. </select>
  1219. </td>
  1220. </tr>
  1221. ";
  1222. }
  1223. break;
  1224. }
  1225. echo $html;
  1226. #echo $this->db->last_query();
  1227. exit();
  1228. }
  1229. //Fungsi untuk memproses enquiry source dan mengembalikan objek2 html yang akan di bentuk
  1230. public function source_process()
  1231. {
  1232. $POST= $this->input->post();
  1233. $opt= $POST["IdSource"];
  1234. $this->db->select('IdMediaType');
  1235. $this->db->group_by('MediaType');
  1236. $media= $this->db->get('m_media_type')->result_array();
  1237. $type= array();
  1238. foreach( $media as $key=>$value ){
  1239. $IdMediaType= str_replace("-", "\-", $value['IdMediaType']);
  1240. $type[]= $IdMediaType;
  1241. }
  1242. $regsource= implode("|", $type);
  1243. $regsource= "#^(" . $regsource . ")$#";
  1244. if( preg_match($regsource, $opt) ){
  1245. $option= array('opt'=>'IdMediaType','id'=>$opt);
  1246. $this->getMedia($option);
  1247. /*
  1248. $sql= "SELECT IdMediaType, MediaType FROM m_media_type
  1249. GROUP BY MediaType";
  1250. $data= $this->db->query($sql)->result_array();
  1251. $html= "
  1252. <tr id='rowAdded'>
  1253. <td>Media Type</td>
  1254. <td>:</td>
  1255. <td>
  1256. <select name='IdMediaType' id='IdMediaType'>
  1257. <option value='' selected='selected'>--Please Select--</option>
  1258. ";
  1259. foreach( $data as $value ){
  1260. $html.= "<option value=\"" . $value['IdMediaType'] . "\">" . $value['MediaType'] . "</option>";
  1261. }
  1262. $html.="
  1263. </select>
  1264. </td>
  1265. </tr>
  1266. ";
  1267. */
  1268. }else{
  1269. switch($opt)
  1270. {
  1271. case "2":
  1272. $html = "
  1273. <tr id='rowAdded'>
  1274. <td>Event</td>
  1275. <td>:</td>
  1276. <td>
  1277. <select id='event' name='event'>
  1278. ";
  1279. foreach($this->Gmodel->getRecords("event",array("IdEvent","NamaEvent","Awal","Akhir")) as $record){
  1280. $awal = date_format(date_create($record->Awal),"d M Y");
  1281. $akhir = date_format(date_create($record->Akhir),"d M Y");
  1282. $html .= "<option value=\"".$record->IdEvent."\">".$record->NamaEvent." (".$awal." - ".$akhir.")"."</option>";
  1283. }
  1284. $html .= "
  1285. </select>
  1286. </td>
  1287. </tr>
  1288. ";
  1289. break;
  1290. case "Doctor Referral":
  1291. $html = "
  1292. <tr id='rowAdded'>
  1293. <td>Country</td>
  1294. <td>:</td>
  1295. <td>
  1296. <select onchange='getClinic($(this).val())'>
  1297. <option value=''>--Please Select--</option>
  1298. ";
  1299. foreach($this->Gmodel->getRecords("m_negara",array("IdNegara","NamaNegara")) as $record){
  1300. $html .= " <option value=\"".$record->IdNegara."\">".$record->NamaNegara."</option>";
  1301. }
  1302. $html .="
  1303. </select>
  1304. </td>
  1305. </tr>
  1306. ";
  1307. break;
  1308. default :
  1309. return;
  1310. }
  1311. }
  1312. echo $html;
  1313. }
  1314. //Function untuk me-render combo box mediakategori
  1315. public function get_media_category()
  1316. {
  1317. $MediaType = $_POST["MediaType"];
  1318. $html = "
  1319. <tr id='rowMediaCat'>
  1320. <td>Media Category</td>
  1321. <td>:</td>
  1322. <td>
  1323. <select name='IdMediaKategori' onchange='getMedia($(this).val())'>
  1324. <option value='' selected='selected'>--Please Select--</option>
  1325. ";
  1326. foreach($this->Gmodel->getRecords("m_media_kategori",array("IdMediaKategori","MediaKategori"),null,null,array("IdMediaType"=>$MediaType)) as $record)
  1327. {
  1328. $html .= "<option value='".$record->IdMediaKategori."'>".$record->MediaKategori."</option>";
  1329. }
  1330. $html .="
  1331. </td>
  1332. </tr>
  1333. ";
  1334. echo $html;
  1335. }
  1336. //Function untuk me-render combo box media
  1337. public function get_media()
  1338. {
  1339. $POST= $this->input->post();
  1340. $MediaCat = $POST["MediaCat"];
  1341. if( $row['MediaType'] == "MEDICAL" ){
  1342. }else{
  1343. $html = "
  1344. <tr id='rowMedia'>
  1345. <td>Media</td>
  1346. <td>:</td>
  1347. <td>
  1348. <select id='media' name='IdMedia' onchange='getAdv($(this).val())'>
  1349. <option value=''>--Please Select--</option>
  1350. ";
  1351. foreach($this->Gmodel->getRecords("m_media",array("IdMedia","NamaMedia"), null, null,
  1352. array("IdMediaKategori"=>$MediaCat)) as $record)
  1353. {
  1354. $html .= "<option value='" . $record->IdMedia . "'>" . $record->NamaMedia . "</option>";
  1355. }
  1356. $html .="
  1357. </select>
  1358. </td>
  1359. </tr>
  1360. ";
  1361. }
  1362. echo $html;
  1363. }
  1364. //Function untuk me-render combo box advertising
  1365. public function get_adv()
  1366. {
  1367. $Media = $_POST["Media"];
  1368. $html = "
  1369. <tr id='rowAdv'>

Large files files are truncated, but you can click here to view the full file