<?php
	//validasi apabila project yang sudah ada detail user nya tidak bisa dihapus
   switch($_REQUEST[mode]) {
    case "hapus":
         if(RetRstField("SELECT fnid FROM tlproject_user WHERE ftproject_code='{$_REQUEST['ftproject_code']}'")) {
            echo "<script>
                alert('data ini tidak dapat di delete karena sudah digunakan ...');
                window.history.back();
            </script>";   
            die("");            
         }

    break;   	
   }
   
   function SaveData() {
    global $objAxpDB;
    $strSQL=array();
    $objAxpDB->Allow_Save(false);
    switch($_REQUEST[mode]) {
    case "simpan":
      $_REQUEST["fdtrans_date"]=getDateYmd($_REQUEST["fdtrans_date"]);
      $strSQL['Insert Project'][]="
              INSERT INTO tlproject(
              ftproject_code,
              ftproject_name,  fnstatus,
              ftcreated_user, fdcreated_date
              ) SELECT
              '{$_REQUEST["ftproject_code"]}' AS ftproject_code, '{$_REQUEST["ftproject_name"]}' AS ftproject_name,
			  '".CCur($_REQUEST["fnstatus"])."' AS fnstatus,
              '{$_SESSION['username']}' AS ftcreated_user, now() AS fdcreated_date";

			  for($j=1; $j<count($_REQUEST['fnindexD0']); $j++) {
					   $strSQL['Insert DO Det'][]="
							   INSERT INTO tlproject_user
								  (fnindex, ftproject_code, ftuser_project, ftstatus_user, ftcreated_user, fdcreated_date, ftmodified_user, fdmodified_date)
								SELECT
								  '{$_REQUEST['fnindexD0'][$j]}', '{$_REQUEST['ftproject_code']}', '{$_REQUEST['ftuser_projectD0'][$j]}', 'user','{$_SESSION['username']}',now(),'{$_SESSION['username']}',now()";

			  }

			  for($k=1; $k<count($_REQUEST['fnindexD0']); $k++) {
					   $strSQL['Insert DO Det'][]="
							   INSERT INTO tlproject_user
								  (fnindex, ftproject_code, ftuser_project, ftstatus_user, ftcreated_user, fdcreated_date, ftmodified_user, fdmodified_date)
								SELECT
								  '{$_REQUEST['fnindexD1'][$k]}', '{$_REQUEST['ftproject_code']}', '{$_REQUEST['ftuser_projectD1'][$k]}', 'support','{$_SESSION['username']}',now(),'{$_SESSION['username']}',now()";

			  }
			  
      break;
    }

    return $strSQL;
   }

   
  function UpdateData() {
       global $objAxpDB;
        $strSQL=array();
        $objAxpDB->Allow_Save(true);
		switch($_REQUEST[mode]) {
			case "update":
                $strSQL["DELETE Tracking Support"][]="DELETE from tlproject_user where ftproject_code='{$_REQUEST['ftproject_code']}' ";
                $i=count($_REQUEST['fnindexD0']);
                for($j=1; $j< $i; $j++){
                    $strSQL["INSERT Tracking Support"][]="INSERT INTO tlproject_user(fnindex, ftproject_code, ftuser_project,ftstatus_user, ftcreated_user, fdcreated_date, ftmodified_user, fdmodified_date)
                                                         VALUES('{$_REQUEST['fnindexD0'][$j]}', '{$_REQUEST['ftproject_code']}', '{$_REQUEST['ftuser_projectD0'][$j]}','user','{$_SESSION['username']}',now(),'{$_SESSION['username']}',now());";
                }
				
                $n=count($_REQUEST['fnindexD1']);
                for($k=1; $k< $n; $k++){
                    $strSQL["INSERT Tracking Support"][]="INSERT INTO tlproject_user(fnindex, ftproject_code, ftuser_project,ftstatus_user, ftcreated_user, fdcreated_date, ftmodified_user, fdmodified_date)
                                                         VALUES('{$_REQUEST['fnindexD1'][$k]}', '{$_REQUEST['ftproject_code']}', '{$_REQUEST['ftuser_projectD1'][$k]}','support','{$_SESSION['username']}',now(),'{$_SESSION['username']}',now());";
                }
				
            break;
        }
     return $strSQL;
  }



?>
