<?php
   if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
              if(RetRstField("SELECT fnid FROM tlproject WHERE ftproject_code='{$_REQUEST['fttrans_no']}'")) {
                    ?>
                    alert('Kode project sudah dipakai...');
                    OnChangeDate_fdtrans_date();
                    <?php
              }
              else {
                    ?>
                    submitbutton('Simpan','','','','');
                    <?php
              }
            break;

        }
        die("");
    }

    Getsecurity('project');
   
    $objAxpDB->ViewName("Daftar project");
    // $objAxpDB->ViewTable("vSAproject");
    $objAxpDB->ViewSQL("SELECT a.fnid, a.ftproject_code, a.ftproject_name,e.fttrans_status_name ,a.fttype_form FROM tlproject a 
	LEFT JOIN tstransaction_status e ON a.fnstatus = e.fntrans_status_code AND e.fntrans_group_code = 73");
								
    $objAxpDB->ViewCaption("ID, Kode project, Nama project, Status,Type Input");

	
	
    $objAxpDB->FormName("Project");
    $objAxpDB->FormSQL("SELECT ftproject_code,ftproject_name,fnstatus,fttype_form
                                FROM tlproject");

    $objAxpDB->FormCaption("Kode Project, Nama Project,Status,Type Input");


			$objAxpDB->Lookup("ftproject_category_code", "SELECT ftproject_category_code, ftproject_category_name FROM tlproject_category", "ftproject_category_code", "ftproject_category_name", -1,true);

			$objAxpDB->Lookup("fttype_form", "SELECT type,fnid FROM tltype_form", "type", "fnid", -1,true);			
			
			$objAxpDB->Lookup("fnstatus", 
			"SELECT fntrans_status_code,fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 73", 
			"fntrans_status_code", 
			"fttrans_status_name", 1,true);   

    $js1="if (this.value=='Agen') {SetIndexSeleted(2,document.getElementById('ftdistributor_code')) } else {SetIndexSeleted(-1,document.getElementById('ftdistributor_code')) };";
    $objAxpDB->FormScript(31, "onChange=\"{$js1}\"");

    $objAxpDB->SetStatus("id");
    $objAxpDB->FormPosition("TL,TL,TL,TL,TL");
    
    $ssql="SELECT ftproject_code FROM tlproject WHERE fnid='{$_REQUEST['id']}'";
    $rs=mysql_query($ssql);
    $r=mysql_fetch_assoc($rs);

    $objAxpDB->GridName(0, "User");
    $objAxpDB->GridSQL(0, "SELECT fnindex,ftuser_project FROM tlproject_user WHERE ftproject_code='{$r['ftproject_code']}' and ftstatus_user='user' #");
    $objAxpDB->GridCaption(0, "No. ,User Name , Kode User");
    $objAxpDB->GridLocked(0,'1,0');	
	$objAxpDB->LookupGrid(0,"ftuser_project", "SELECT ftusername, ftuser_group_code FROM tluser", "ftusername", "ftuser_group_code", 0,false);
    $objAxpDB->GridAllowAddNew(0, TRUE);
    $objAxpDB->GridAllowDelete(0, TRUE);
    $objAxpDB->GridAutoAdd(0, TRUE);

    $objAxpDB->GridName(1, "Support");
    $objAxpDB->GridSQL(1, "SELECT fnindex,ftuser_project FROM tlproject_user WHERE ftproject_code='{$r['ftproject_code']}' and ftstatus_user='support' #");
    $objAxpDB->GridCaption(1, "No. ,User Name , Kode User");
    $objAxpDB->GridLocked(1,'1,0');	
	$objAxpDB->LookupGrid(1,"ftuser_project", "SELECT ftusername, ftuser_group_code FROM tluser", "ftusername", "ftuser_group_code", 0,false);
    $objAxpDB->GridAllowAddNew(1, TRUE);
    $objAxpDB->GridAllowDelete(1, TRUE);
    $objAxpDB->GridAutoAdd(1, TRUE);
     

    if ($objAxpDB->GetStatus("id") == "") {
            $objAxpDB->ButtonShow("baru, cetak_daftar, export_excel , tutup");

    }
    elseif ($objAxpDB->GetStatus("id") == 0) {
            $objAxpDB->ButtonShow("reset, simpan, tutup");

    }
    elseif ($objAxpDB->GetStatus("id") != 0) {
            $objAxpDB->ButtonShow("update, hapus, tutup");
            $objAxpDB->FormLocked("1");
    }
    $objAxpDB->Process();
    $objAxpDB->WriteHtmlTable();
?>
