<?php
  $dcommtypes = array(0 => "RS-485", 1 => "TCP/IP", 2 => "KACO Standard", 3 => "KACO Generic");
  $dswapmodes = array(0 => "N/A", 1 => "Byte and Word Swap", 2 => "Byte Swap", 3 => "Word Swap");

   class MyDB extends SQLite3 {
      function __construct() {
         $this->open('/kirac/db/sungateway.db');
      }
   }

   $db = new MyDB();
   if(!$db) {
      echo $db->lastErrorMsg();
   }

   $sql =<<<EOF
      SELECT * from tblmbusdevices;
EOF;

  echo '<table id="tableDeviceList">
				<tr class="tableHeader">
				<th style="display:none;">Record No</th>
				<th>İstasyon ID</th>
				<th>Haberleşme Tipi</th>
				<th>Modbus Slave ID</th>
				<th>Swap Modu</th>
				<th>Slave IP</th>
				<th>TCP Port</th>
				<th>Cihaz Tanımı</th>
				<th>Aktif</th>
				</tr>';

   $ret = $db->query($sql);
   while($row = $ret->fetchArray(SQLITE3_ASSOC) ) {
     echo '<tr class="tableData" onclick="tableRowClick(this,1)" ondblclick="cihazEkle(1)">';
     echo '<td id="colRecordNo" style="display:none;">' . $row['kno'] . '</td>';
     echo '<td id="colStationID">' . $row['station_id'] . '</td>';
     echo '<td id="colCommType">' . $dcommtypes[$row['comm_type']] . '</td>';
     echo '<td id="colID">'. $row['device_id'] .'</td>';
     echo '<td id="colSwapMode">' . $dswapmodes[$row['swap_mode']] . '</td>';
     echo '<td id="colIP">'. $row['device_ip'] .'</td>';
     echo '<td id="colTCPPort">'. $row['tcp_port'] .'</td>';
     echo '<td id="colDefinition">'. $row['device_def'] .'</td>';
     echo '<td id="colActive">'. $row['active'] .'</td>';
     echo '</tr>';
   }

   echo '</table>';

   $db->close();
?>
