<?php
      if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
			case "transno":
              if(RetRstField("SELECT fnid FROM txtracking_hdr WHERE ftcustomer_code='{$_REQUEST['fttrans_no']}'")) {
                  ?>

                  alert('Kode aktivitas sudah dipakai...');
                  OnChangeDate_fdtrans_date();
            <?php
              }
              else {
                    ?>


                  submitbutton('Simpan','','','','');

            <?php
              }
            break;

				
            
        }
        
    }

    Getsecurity('Tracking');

	//kondisi peruser
    $ssql="select ftusername,ftuser_group_code from tluser where ftusername='{$_SESSION['username']}'";
    $rs=mysql_query($ssql) or die($ssql);
    $r=mysql_fetch_assoc($rs);
    
    if($r['ftuser_group_code']=='administrator'){
        $where="";
    }else if($r['ftuser_group_code']!='administrator') {
        $where="LEFT JOIN tluser c ON a.ftusername = c.ftusername WHERE c.ftusername='{$r['ftusername']}' or a.ftsupport_code = '{$r['ftusername']}'";
    }else {
        $where="";
    }
	
    $objAxpDB->ViewName("Daftar Tracking");
    //$objAxpDB->ViewTable("vSACustomer");
    $objAxpDB->ViewSQL("SELECT a.fnid, a.fdtrans_date,g.ftproject_name,a.ftket_customer,a.ftket_internal,e.fttrans_status_name,a.ftsupport_code,a.ftusername,a.fdproses_date,a.fdqc_date,a.fdselesai_date,f.fttrans_status_name AS status_kunci FROM txtracking_det a
	LEFT JOIN tstransaction_status e ON a.ftstatus_aktivitas = e.fntrans_status_code AND e.fntrans_group_code = 71 
    LEFT JOIN tstransaction_status f ON a.ftstatus_customer = f.fntrans_status_code AND f.fntrans_group_code = 72
	LEFT JOIN tlproject g ON a.ftproject_code = g.ftproject_code {$where} order by a.ftstatus_customer,a.fdtrans_date,a.ftstatus_aktivitas ASC");
    $objAxpDB->ViewCaption("fnid,Tanggal,Nama Project,Keterangan,Catatan,Status Aktivitas,Dilaporkan Oleh,Dikerjakan Oleh,Tanggal Proses,Tanggal QC,Tanggal Selesai,Konfirmasi Customer");
	$objAxpDB->ViewPeriod(TRUE);

 
    
	
	
	if ($_REQUEST['id'] == 0) {
		
   //= HEADER FORM INPUT ===============================================
    $objAxpDB->FormName("Project Tracking");
    $objAxpDB->FormSQL("SELECT ftproject_code FROM tlproject");
    $objAxpDB->FormCaption("Project");
    $objAxpDB->FormPosition("TL,TL");
    
	
		$objAxpDB->Lookup("ftproject_code"
			, "SELECT a.ftproject_code,a.ftproject_name FROM tlproject a "
			, "ftproject_code"
			, "ftproject_name", -1,true);		
						
	
    $ajaxGrid="ajax_do_grid0('tracking.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=grid&ftproject_code='+ document.getElementById('ftproject_code').value);";
    $objAxpDB->FormScript(0,"onChange=\"{$ajaxGrid}\"");

	
		//FORM AWAL =======================================
		//$m.='Untuk Menampilkan Form Silahkan Pilih Project';
		$objAxpDB->GridSQL(0, "Select a.fnid,a.ftproject_code, a.ftproject_name FROM tlproject a");
		$objAxpDB->GridCaption(0, "No., Project kode,Nama Project");
		$objAxpDB->GridHidden(0,"0, 0, 0");
		//$objAxpDB->GridReplace(0,$m);
		$objAxpDB->GridAllowAddNew(0, false);
		$objAxpDB->GridAllowDelete(0, false);
		$objAxpDB->GridAutoAdd(0, false);
	}
	else
		{
		// FORM EDIT ============================================================================
		$objAxpDB->FormName("Tracking");
		$objAxpDB->FormSQL("SELECT fnid,fdtrans_date,ftproject_code,ftket_customer,ftket_internal,ftstatus_aktivitas,ftsupport_code,ftusername,fdproses_date,fdqc_date,fdselesai_date,ftstatus_customer FROM txtracking_det");
		$objAxpDB->FormCaption("ID,Tanggal,Project,Keterangan,Catatan,Status Aktivitas,Dilaporkan Oleh,Dikerjakan Oleh,Tanggal Proses,Tanggal QC,Tanggal Selesai,Konfirmasi Customer");
		
		$objAxpDB->FormPosition("TL,TL,TL,TL,TL,TL,TR,TR,TR,TR,TR,TR");
    
		
			$objAxpDB->Lookup("ftsupport_code"
			, "SELECT concat(ftusername,fnstatus), ftfirst_name FROM tluser "
			, "ftusername"
			, "ftfirst_name", 0,true);
			
			$objAxpDB->Lookup("ftproject_code"
			, "SELECT ftproject_code, ftproject_name FROM tlproject"
			, "ftproject_code"
			, "ftproject_name", -1,true);		
			$objAxpDB->Lookup("ftusername"
			, "SELECT ftusername, ftfirst_name FROM tluser where ftuser_group_code='support'"
			, "ftusername"
			, "ftfirst_name", -1,true);
			$objAxpDB->Lookup("ftstatus_aktivitas", 
			"SELECT fntrans_status_code,fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 71", 
			"fntrans_status_code", 
			"fttrans_status_name", 1,true);
			$objAxpDB->Lookup("ftstatus_customer", 
			"SELECT fntrans_status_code,fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 72", 
			"fntrans_status_code", 
			"fttrans_status_name", 0,true);
		}
	
    $objAxpDB->SetStatus("id");
    
 

    if ($objAxpDB->GetStatus("id") == ""){
		//kondisi peruser
		$ssql="select ftusername,ftuser_group_code from tluser where ftusername='{$_SESSION['username']}'";
		$rs=mysql_query($ssql) or die($ssql);
		$r=mysql_fetch_assoc($rs);
		
		if($r['ftuser_group_code']=='support'){
			$objAxpDB->ButtonShow("cetak_daftar, export_excel , tutup");
		}else if($r['ftuser_group_code']!='support') {
			$objAxpDB->ButtonShow("baru, cetak_daftar, export_excel , tutup");
		}	

   } elseif ($objAxpDB->GetStatus("id") == 0) {
            //$objAxpDB->GridAllowAddNew(0,true);
            //$objAxpDB->GridAllowDelete(0,true);
            $objAxpDB->FormLocked("0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1");
            $objAxpDB->GridLocked(0, "1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1");
            $objAxpDB->GridAllowDelete(0,true);
            $objAxpDB->ButtonShow("reset, simpan, tutup");
    }
    elseif ($objAxpDB->GetStatus("fnstatus") == 0) {
		


			
		//kondisi peruser
	$ssql="select ftusername,ftuser_group_code from tluser where ftusername='{$_SESSION['username']}'";
	$rs=mysql_query($ssql) or die($ssql);
	$r=mysql_fetch_assoc($rs);
	
		if($r['ftuser_group_code']=='support'){
			//user support jika status selesai dan belum selesai
				$ssql2="select ftstatus_aktivitas from txtracking_det where fnid='{$objAxpDB->GetStatus("id")}'";
				$rs2=mysql_query($ssql2) or die($ssql2);
				$r2=mysql_fetch_assoc($rs2);
					if($r2['ftstatus_aktivitas']==0){		
						//$objAxpDB->ButtonShow("update, hapus, tutup");
						$objAxpDB->ButtonShow("revisi,  tutup");
						$objAxpDB->FormLocked("1,1,1,1,1,1,1,1,1,1,1,1");
					}
					else{
						$objAxpDB->FormLocked("1,1,1,1,0,0,1,1,0,0,0,1");
						$objAxpDB->ButtonShow("update, tutup");
					}			
						
		}else if($r['ftuser_group_code']=='CS') {	
				$ssql2="select ftstatus_customer from txtracking_det where fnid='{$objAxpDB->GetStatus("id")}'";
				$rs2=mysql_query($ssql2) or die($ssql2);
				$r2=mysql_fetch_assoc($rs2);
					if($r2['ftstatus_customer']==1){	
						$objAxpDB->FormLocked("1,1,1,0,1,1,1,1,1,1,1,0");
						$objAxpDB->ButtonShow("update, tutup");	
					}
					else
					{
						$objAxpDB->FormLocked("1,1,1,1,1,1,1,1,1,1,1,1");
						$objAxpDB->ButtonShow("tutup");	
					}
												
					
		}else{
				$objAxpDB->FormLocked("1,0,0,0,0,0,0,0,0,0,0,0");
				$objAxpDB->ButtonShow("update, tutup");
		}		
			
    }

    if($_REQUEST['ajax']) {
           if($_REQUEST['code']=="grid") {
			   
			   $ssql="select fttype_form from tlproject where ftproject_code='{$_REQUEST['ftproject_code']}'";
			   $rs=mysql_query($ssql) or die($ssql);
			   $r=mysql_fetch_assoc($rs);
			
				if($r['fttype_form']=='single'){
				//= Form SINGLE ===================================
					ob_start();
						echo  '
						<table width="100%">
						<tr bgcolor="#F7F7F9" style="border:1px solid #E1E1E8">
                                <td width="50%" valign="top">
								<br>
                                    <!-- BEGIN: Form Header TL (Top Left) -->
                                    <table width="100%" style="font-size:12px">
                                                                                        <tbody><tr valign="middle">
                                                    <td align="right" style="padding-bottom:2px;"><div id="divCap_fnid">ID :  &nbsp;</div></td>
                                                    <td style="padding-bottom:2px;"><table class="is_edit_table" cellpadding="0" cellspacing="0"><tbody><tr><td><div id="DivCtl_fnid">                            <input type="text" class="form-control" id="fnid" name="fnid" size="5" maxlength="5" value="17" >
                                </div></td></tr></tbody></table></td>
                                                </tr>
                                                                                                <tr valign="middle">
                                                    <td align="right" style="padding-bottom:2px;"><div id="divCap_fdtrans_date">Tanggal :  &nbsp;</div></td>
                                                    <td style="padding-bottom:2px;"><table class="is_edit_table" cellpadding="0" cellspacing="0"><tbody><tr><td><div id="DivCtl_fdtrans_date">                        <table border="0" cellpadding="0" cellspacing="0">
                            <tbody><tr>
                                <td>
                                    <input size="12" id="fdtrans_date" name="fdtrans_date" maxlength="10" value="26/04/2017" ></td><td><input type="button" onclick="if (self.gfPop)
                                                            gfPop.fPopCalendar(document.frmMain.fdtrans_date);
                                                        return false;" id="cmdTanggal" name="cmdTanggal" value="..." disabled="">
                                </td>
                            </tr>
                        </tbody></table>
                            </div></td></tr></tbody></table></td>
                                                </tr>
                                                                                                
                                                                                                <tr valign="middle">
                                                    <td align="right" style="padding-bottom:2px;"><div id="divCap_ftket_customer">Keterangan :  &nbsp;</div></td>
                                                    <td style="padding-bottom:2px;"><table class="is_edit_table" cellpadding="0" cellspacing="0"><tbody><tr><td><div id="DivCtl_ftket_customer">                        <input class="form-control input-sm" type="text" id="ftket_customer" name="ftket_customer" size="30" maxlength="80" value="erorr pada saat login" >
                        </div></td></tr></tbody></table></td>
                                                </tr>
                                                                                                <tr valign="middle">
                                                    <td align="right" style="padding-bottom:2px;"><div id="divCap_ftket_internal">Catatan :  &nbsp;</div></td>
                                                    <td style="padding-bottom:2px;"><table class="is_edit_table" cellpadding="0" cellspacing="0"><tbody><tr><td><div id="DivCtl_ftket_internal">                        <input class="form-control input-sm" type="text" id="ftket_internal" name="ftket_internal" size="30" maxlength="90" value="Update program" >
                        </div></td></tr></tbody></table></td>
                                                </tr>
                                                                                                <tr valign="middle">
                                                    <td align="right" style="padding-bottom:2px;"><div id="divCap_ftstatus_aktivitas">Status Aktivitas :  &nbsp;</div></td>
                                                    <td style="padding-bottom:2px;"><table class="is_edit_table" cellpadding="0" cellspacing="0"><tbody><tr><td><div id="DivCtl_ftstatus_aktivitas">                        <select class="form-control input-sm" id="ftstatus_aktivitas" name="ftstatus_aktivitas" onfocus="this.initialSelect = this.selectedIndex;" onclick="this.initialSelect = this.selectedIndex;" onchange="this.selectedIndex = this.initialSelect;" style="background-color: #E0E0E0">
                            <option value="" selected="">--- Pilih ---</option>
                                                            <option value="0">0 -- Selesai</option>
                                                                            <option value="1" selected="">1 -- Belum Selesai</option>
                                                                            <option value="2">2 -- Selesai Perbaikan</option>
                                                                            <option value="3">3 -- Diperbaiki Lagi</option>
                                                                            <option value="4">4 -- Proses</option>
                                                                </select>
                                </div></td></tr></tbody></table></td>
                                                </tr>
                                                                                    </tbody></table>
                                    <!-- END: Form Header TL (Top Left) -->
                                    <br>
                                </td>
                                <td>&nbsp;</td>
                                <td width="50%" valign="top">
								<br>
                                    <!-- BEGIN: Form Header TR (Top Right) -->
                                    <table width="100%" style="font-size:12px">
                                                                                    <tbody><tr valign="middle">
                                                    <td align="right" style="padding-bottom:2px;"><div id="divCap_ftsupport_code">Dilaporkan Oleh :  &nbsp;</div></td>
                                                    <td style="padding-bottom:2px;"><table class="is_edit_table" cellpadding="0" cellspacing="0"><tbody><tr><td><div id="DivCtl_ftsupport_code">                        <select class="form-control input-sm" id="ftsupport_code" name="ftsupport_code" onfocus="this.initialSelect = this.selectedIndex;" onclick="this.initialSelect = this.selectedIndex;" onchange="this.selectedIndex = this.initialSelect;" style="background-color: #E0E0E0">
                            <option value="" selected="">--- Pilih ---</option>
                                                            <option value=""> -- administrator</option>
                                                                            <option value=""> -- customer 2</option>
                                                                            <option value=""> -- Customer 1</option>
                                                                            <option value=""> -- muhammad</option>
                                                                </select>
                                </div></td></tr></tbody></table></td>
                                                </tr>
                                                                                                <tr valign="middle">
                                                    <td align="right" style="padding-bottom:2px;"><div id="divCap_ftusername">Dikerjakan Oleh :  &nbsp;</div></td>
                                                    <td style="padding-bottom:2px;"><table class="is_edit_table" cellpadding="0" cellspacing="0"><tbody><tr><td><div id="DivCtl_ftusername">                        <select class="form-control input-sm" id="ftusername" name="ftusername" onfocus="this.initialSelect = this.selectedIndex;" onclick="this.initialSelect = this.selectedIndex;" onchange="this.selectedIndex = this.initialSelect;" style="background-color: #E0E0E0">
                            <option value="" selected="">--- Pilih ---</option>
                                                            <option value="ridwan" selected="">ridwan -- muhammad</option>
                                                                </select>
                                </div></td></tr></tbody></table></td>
                                                </tr>
                                                                                                <tr valign="middle">
                                                    <td align="right" style="padding-bottom:2px;"><div id="divCap_fdproses_date">Tanggal Proses :  &nbsp;</div></td>
                                                    <td style="padding-bottom:2px;"><table class="is_edit_table" cellpadding="0" cellspacing="0"><tbody><tr><td><div id="DivCtl_fdproses_date">                        <table border="0" cellpadding="0" cellspacing="0">
                            <tbody><tr>
                                <td>
                                    <input size="12" id="fdproses_date" name="fdproses_date" maxlength="10" value="26/04/2017" ></td><td><input type="button" onclick="if (self.gfPop)
                                                            gfPop.fPopCalendar(document.frmMain.fdproses_date);
                                                        return false;" id="cmdTanggal" name="cmdTanggal" value="..." disabled="">
                                </td>
                            </tr>
                        </tbody></table>
                            </div></td></tr></tbody></table></td>
                                                </tr>
                                                                                                <tr valign="middle">
                                                    <td align="right" style="padding-bottom:2px;"><div id="divCap_fdqc_date">Tanggal QC :  &nbsp;</div></td>
                                                    <td style="padding-bottom:2px;"><table class="is_edit_table" cellpadding="0" cellspacing="0"><tbody><tr><td><div id="DivCtl_fdqc_date">                        <table border="0" cellpadding="0" cellspacing="0">
                            <tbody><tr>
                                <td>
                                    <input size="12" id="fdqc_date" name="fdqc_date" maxlength="10" value="26/04/2017" ></td><td><input type="button" onclick="if (self.gfPop)
                                                            gfPop.fPopCalendar(document.frmMain.fdqc_date);
                                                        return false;" id="cmdTanggal" name="cmdTanggal" value="..." disabled="">
                                </td>
                            </tr>
                        </tbody></table>
                            </div></td></tr></tbody></table></td>
                                                </tr>
                                                                                                <tr valign="middle">
                                                    <td align="right" style="padding-bottom:2px;"><div id="divCap_fdselesai_date">Tanggal Selesai :  &nbsp;</div></td>
                                                    <td style="padding-bottom:2px;"><table class="is_edit_table" cellpadding="0" cellspacing="0"><tbody><tr><td><div id="DivCtl_fdselesai_date">                        <table border="0" cellpadding="0" cellspacing="0">
                            <tbody><tr>
                                <td>
                                    <input size="12" id="fdselesai_date" name="fdselesai_date" maxlength="10" value="26/04/2017" ></td><td><input type="button" onclick="if (self.gfPop)
                                                            gfPop.fPopCalendar(document.frmMain.fdselesai_date);
                                                        return false;" id="cmdTanggal" name="cmdTanggal" value="..." disabled="">
                                </td>
                            </tr>
                        </tbody></table>
                            </div></td></tr></tbody></table></td>
                                                </tr>
                                                                                                <tr valign="middle">
                                                    <td align="right" style="padding-bottom:2px;"><div id="divCap_ftstatus_customer">Konfirmasi Customer :  &nbsp;</div></td>
                                                    <td style="padding-bottom:2px;"><table class="is_edit_table" cellpadding="0" cellspacing="0"><tbody><tr><td><div id="DivCtl_ftstatus_customer">                        <select class="form-control input-sm" id="ftstatus_customer" name="ftstatus_customer" onfocus="this.initialSelect = this.selectedIndex;" onclick="this.initialSelect = this.selectedIndex;" onchange="this.selectedIndex = this.initialSelect;" style="background-color: #E0E0E0">
                            <option value="" selected="">--- Pilih ---</option>
                                                            <option value="1">1 -- Open</option>
                                                                            <option value="2" selected="">2 -- Close</option>
                                                                            <option value="3">3 -- Cancel</option>
                                                                </select>
                                </div></td></tr></tbody></table></td>
                                                </tr>
                                                                                    </tbody></table>
                                    <!-- END: Form Header TL (Top Left) -->
                                </td>
                            </tr>
							</table>						
						';
					
					$html = ob_get_contents();
					ob_end_clean();
					?>

						div = document.getElementById('txtHint0');
						var m='<?php echo js_esc($html); ?>';
						m= m.replace(/^\s*|\s*$/g,"");

						div.innerHTML =m;
						RowIndex0();
						reSize();
					<?php
				}else{
					//= Form MULTIPLE ===================================
		$objAxpDB->GridAllowAddNew(0, TRUE);
		$objAxpDB->GridAllowDelete(0, TRUE);
		$objAxpDB->GridAutoAdd(0, TRUE);					
					ob_start();
					$objAxpDB->GridSQL(0, "SELECT a.fnid,a.ftproject_code, a.ftproject_name FROM tlproject a WHERE a.ftproject_code='99999999' #");

					$objAxpDB->Process();
					$objAxpDB->setGrid2(0);
					
					$html = ob_get_contents();
					ob_end_clean();
					?>

						div = document.getElementById('txtHint0');
						var m='<?php echo js_esc($html); ?>';
						m= m.replace(/^\s*|\s*$/g,"");

						div.innerHTML =m;
						RowIndex0();
						reSize();
					<?php					
					}
           }
		   
           die("");
           exit;
    }

    $objAxpDB->Process();

    $objAxpDB->WriteHtmlTable();