<?php
                        // HTTP/1.0
           if($_REQUEST['ajax']) {
            switch($_REQUEST['code']) {
                case "transno":

                  if(RetRstField("SELECT fnid FROM tluser WHERE ftusername='{$_REQUEST['fttrans_no']}'")) {
                      ?>

                      alert('User Name sudah dipakai... ');
                <?php
                  }
                  else {
                        ?>
                         submitbutton('Simpan','','','','');

                <?php
                  }
                break;
            }
            die("");
        }
       function GetGridUser($n) {
       $x='';
       $ftusername='';

       $ssql="SELECT ftusername FROM tluser WHERE fnid='{$_REQUEST['id']}'";
       $rs=mysql_query($ssql) or die($ssql);
       $r=mysql_fetch_assoc($rs);
       $ftusername=$r['ftusername'];

       $ssql="SELECT a.fx, A.ftsecurity_code as fnsecurity_access,IFNULL(B.ftusername,'{$ftusername}') AS ftusername,a.ftmodule_code, A.ftparent_code as ftsecurity_description,a.ftsecurity_name as ftsecurity_subdescription,IFNULL(B.fbaccess,0) AS fnsecurity
                FROM (
					select 0 as fx,ftsecurity_code,ftmodule_code,ftparent_code,ftsecurity_name from tlsecurity
					union all
					select 1 as fx,concat('laporan_',ftreport_group,'_',ftreport_code) as ftsecurity_code,ftreport_group as ftmodule_code, concat('Laporan ',ftreport_group) as ftparent_code,ftreport_name from tlreport
					)
					A LEFT JOIN tluser_access B ON A.ftsecurity_code=B.ftsecurity_code AND (B.ftusername ='{$ftusername}' OR B.ftusername IS NULL)
                WHERE
                    a.ftmodule_code='{$n}'";
//               die($ssql);
                $rs=mysql_query("select distinct  ftsecurity_description from ($ssql) m order by fx") or die($ssql) ;

                $x.= "<table class='ewTable' id='TransactionDetail{$n}' name='TransactionDetail{$n}' border='0' width='100%' cellspacing='0' celpadding='0'>
                    <tr class='is_edit_header_row' width=100%>
                    <td valign=top width=30 align=center>No</th>
                    <td valign=top     align=center>Keterangan</th>
					<td valign=top width=30 align=center>No</th>
                    <td valign=top     align=center>Keterangan</th>
					<td valign=top width=30 align=center>No</th>
                    <td valign=top     align=center>Keterangan</th>
                    </tr>";

                $i=0;
                $j=0;
				$row1=1;
		while($r = mysql_fetch_assoc($rs))
		 {
					
                    if ($i%2) {
                            $class1="ewTableRow";
                            $class2="ISGridTDeven";
                    } else {
                            $class1="ISGridTRodd";
                            $class2="ISGridTDodd";
                    }
                     $j++;
					 if($row1==1) {
						$x.= "<tr class='$class1'>";
					}
                          	   $x.=" <td class='$class2' valign=top>{$j}</td>
                           	   <td class='$class2' valign=top><b>".ucwords(str_replace("_"," ",$r['ftsecurity_description'])) ."</b> ";

			   $rs1=mysql_query($ssql." and A.ftparent_code='".$r['ftsecurity_description']."'") or die("m");
              
               $i=0;
			   while($r1 = mysql_fetch_assoc($rs1)) {
                            if($i==0) {
                                 $namex="cAll_{$r1['fnsecurity_access']}";
                                 $checkx= " 
                                        <input type=checkbox id='{$namex}' name='{$namex}' value='0' onClick=\"CheckSecurityAll('{$namex}')\">ALL";
                       
                                 $x.="$checkx<table class='ewTable'  border='0'  cellspacing='0' celpadding='0'  width='100%'>";

                            }
                             $i++;
                     		if($r1['fnsecurity']==0){
                            		$c="";
                     		}
                     		else {
                       	   	 	$c=" checked ";
                     		}
                            $x.="<tr  class='$class1'>";
                            $x.="<td class='$class2'>";
                     		 $x.= " <input type=hidden name=fnS[] value='{$r1['fnsecurity_access']}'>
                           	   <input type=checkbox id='{$namex}_{$i}' name='c{$r1['fnsecurity_access']}' value='1' $c ></td><td>
                               ".ucwords(str_replace("_"," ",$r1['ftsecurity_subdescription'])) ." ";
                                $x.="</td>";
                                $x.="</tr>";
                            
			 	 }
                 $x.="</table>";
                 $x.="<input type=hidden name='{$namex}_count'  id='{$namex}_count' value={$i}>";
			     $x.="</td>";
				 if((mysql_num_rows($rs)==$j)||($row1==3)) {
					if(mysql_num_rows($rs)==$j) {
						if($row1==1) {
							$x.="<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";
						}
						elseif($row1==2) {
							$x.="<td>&nbsp;</td><td>&nbsp;</td>";
						}
					}
					$x.="</tr>";
				 }
				 if($row1==3) $row1=0;
				 $row1++;
                     $i++;
		 }
		$x.="</table>";

                return $x;

    }
    function GetUser() {


        $x.="
            <link rel='stylesheet' type='text/css' href='tab-view/tab-view.css' />
            <div class='TabView' id='TabView' style='width: 100%;'>


            <div class='Tabs' style='width: 100%;height=100%'>            
             <a class='Current' >System</a>
              <a >Security</a>
	      <a>Saldo Awal</a>
              <a>pembelian</a>
              <a>Inventory Bahan Baku</a>
               <a>Inventory Setengah Jadi</a>
              <a>preproduksi</a>
              <a>penjualan</a>
              <a>inventory</a>
              <a>keuangan</a>
              <a>absensi</a>
              <a>hrd</a>
            </div>




            <div class='Pages' style=' style='width: 100%;' >
              <div class='Page' style='display: block;'><div class='Pad'>";

            $x.=GetGridUser('system');
            $x.="</div></div>
            <div class='Page' style='display:  none;'><div class='Pad'>";
            $x.=GetGridUser('security');

             $x.="</div></div>
            <div class='Page' style='display:  none;'><div class='Pad'>";
            $x.=GetGridUser('saldoawal');
            
            $x.="</div></div>
            <div class='Page' style='display:  none;'><div class='Pad'>";
            $x.=GetGridUser('pembelian');

            $x.="</div></div>
            <div class='Page' style='display:  none;'><div class='Pad'>";
            $x.=GetGridUser('Inventory_Bahan_Baku');
             $x.="</div></div>
            <div class='Page' style='display:  none;'><div class='Pad'>";
            $x.=GetGridUser('inventory_setengah_jadi');
            
            $x.="</div></div>
            <div class='Page' style='display:  none;'><div class='Pad'>";
            $x.=GetGridUser('preproduksi');
            $x.=" </div></div>
            <div class='Page' style='display:  none;'><div class='Pad'>";
            $x.=GetGridUser('penjualan');
            $x.="</div></div>
            <div class='Page' style='display:  none;'><div class='Pad'>";
            $x.=GetGridUser('inventory');
            $x.="</div></div><div class='Page' style='display:  none;'><div class='Pad'>";
            $x.=GetGridUser('keuangan');
            $x.="</div></div><div class='Page' style='display:  none;'><div class='Pad'>";
            $x.=GetGridUser('absensi');
            $x.="</div></div><div class='Page' style='display:  none;'><div class='Pad'>";
            $x.=GetGridUser('hrd');
            $x.="</div></div>
        </div>
        </div>
        <script type='text/javascript' src='tab-view/tab-view.js'></script>
        <script type='text/javascript'>
            tabview_initialize('TabView');
        </script>";
        return $x;


    }

    Getsecurity(7);
    $objAxpDB->ViewName("Daftar User");
    $objAxpDB->ViewSQL('SELECT fnid,ftusername,ftfirst_name,ftuser_group_code FROM tluser ORDER BY ftusername,ftfirst_name,ftuser_group_code');
    $objAxpDB->ViewCaption('ID, User Name, Nama, Group User');

    $objAxpDB->FormName("User");
    $objAxpDB->FormSQL('SELECT ftusername,ftpassword,ftpassword as password_confirm,ftuser_group_code,ftfirst_name,
                        ftmiddle_name,ftlast_name,ftdepartment,
                        fnstatus FROM tluser
                        ');
    $objAxpDB->FormCaption(' User Name,Password, Confirm Password , Group User, Nama Depan, Nama Tengah, Nama Belakang,  Departemen,Status ');

    $objAxpDB->Lookup('ftuser_group_code', 'SELECT ftuser_group_code, ftuser_group_name FROM tluser_group', 'ftuser_group_code', 'ftuser_group_name', -1,true);
    $objAxpDB->Lookup('fnstatus', 'SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status where fntrans_group_code=9', 'fntrans_status_code', 'fttrans_status_name', 1,true);
    $objAxpDB->FormPosition('TL, TL, TL, TL,TL,TL,TR,TR,TR');
    $password="document.getElementById('ftpassword').type='password';
              document.getElementById('password_confirm').type='password';";

    $objAxpDB->FormJS("{$password}");

    $objAxpDB->GridSQL(0, "SELECT fnid FROM tluser");
    $m=GetUser();
    #die($m);
    $objAxpDB->GridReplace(0, $m);

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

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

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


?>
