<?php include_once "header.php" ?>
<?php

$user->log($user_id, 8, "");

function build_table($array){
  // start table
  //$html = '<table id="waristable" class="table table-bordered table-hover"><thead>';
  // header row
  $html .= "    <tr>\r\n";
  foreach($array[0] as $key=>$value){
          $html .= "      <th>" . $key . "</th>\r\n";
  }
  $html .= "    </tr>\r\n";
  $html .= "  </thead>\r\n";
  $html .= "  <tbody>\r\n";

  // data rows
  foreach( $array as $key=>$value){
      $html .= "    <tr>\r\n";
      foreach($value as $key2=>$value2){
        $html .= "      <td>" . $value2 . "</td>\r\n";
      }
      $html .= "    </tr>\r\n";
  }

  // finish table and return it
  //$html .= '</tbody></table>';
  $html .= "  </tbody>\r\n";
  $html .= "  <tfoot>\r\n";
  $html .= "    <tr>\r\n";
  foreach($array[0] as $key=>$value){
          $html .= "      <th>" . $key . "</th>\r\n";
  }
      
  return $html;
}

// Open connection
if (!isset($conn)) $conn = ew_Connect();

$user_id_withrank = trim(ew_RemoveXSS(ew_StripSlashes($_SESSION['ARMYNOWITHRANK'])));

// KIOSK 3 - Withdrawal
$sql = "SELECT *
          FROM [dbo].[KIOSKWRS]
         WHERE NoAskar='$user_id_withrank'
       ";
$rs  = ew_Execute($sql);
if ($rs->RecordCount() > 0) {
  $rs->MoveFirst();
  $sData = "";
  $myarray = array();
  while ($rs && !$rs->EOF) {
    $nowaris   = $rs->fields['NoWaris' ];
    $nama      = $rs->fields['Nama'    ];
    $nokp      = $rs->fields['NoKP'    ];
    $alamat    = $rs->fields['Alamat'  ];
    $poskod    = $rs->fields['Poskod'  ];
    $bandar    = $rs->fields['Bandar'  ];
    $negeri    = $rs->fields['Negeri'  ];
    $notel     = $rs->fields['NoTel'   ];
    
    $txt = $alamat.", ".$poskod." ".$bandar.", ".$negeri;
    
    $myarray[] = array('No'=>$nowaris, 'Nama'=>$nama, 'No KP'=>$nokp, 'No Tel'=>$notel, 'Alamat'=>$txt);
        
    $rs->MoveNext();
  }
  //echo $sData;
  $rs->Close();
} else {
  //$this->setFailureMessage("No records are found.");
} 

//$array = array(
//    array('first'=>'tom', 'last'=>'smith', 'email'=>'tom@example.org', 'company'=>'example ltd'),
//    array('first'=>'hugh', 'last'=>'blogs', 'email'=>'hugh@example.org', 'company'=>'example ltd'),
//    array('first'=>'steph', 'last'=>'brown', 'email'=>'steph@example.org', 'company'=>'example ltd')
//);

//print_r($myarray);


?>


<!-- Full Width Column -->
<div class="content-wrapper">
    <div class="container">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            Waris
            <small>Status Penamaan Waris</small>
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i class="active">Laman Utama</a></li>
            <li>Waris</li>
            <!--
            <li><a href="#">Layout</a></li>
            <li class="active">Top Navigation</li>
            -->
          </ol>
        </section>    
    
        <!-- Main content -->
        <section class="content">
            <!-- Default box -->
            <div class="box box-primary">
                <div class="box-body">


Dibawah adalah maklumat pendaftaran penamaan waris. Sila periksa maklumat yang disediakan dibawah. Untuk maklumat lanjut, sila hubungi LTAT.

<div>
<?php 
  if (isset($myarray))
  {
      echo "\r\n<table id=\"investorunits\" class=\"table table-striped table-bordered table-hover display responsive nowrap\"  width=\"100%\" cellspacing=\"0\">\r\n";
      echo "  <thead>\r\n";
      echo build_table($myarray); 
      echo "    </tr>\r\n";
      echo "  </tfoot>\r\n";
      echo "</table>\r\n";
  } else {
    echo "<br><br>Tiada rekod dijumpai.";
  }
?>
</div>


                </div>   
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.container -->
</div>
<!-- /.content-wrapper -->



<?php include_once "footer.php" ?>