include_once 'includes/dbcon.php'; include_once 'includes/device.php'; $deviceObj = new Device(); if (isset($_POST["device"])) { $device = $_POST["device"]; $result = $deviceObj->get_components($device); $controls = $result['details']; $controls = substr($controls, 0, strlen($controls) - 1); $controlsArray = explode("!", $controls); //$controls = //TubeLight:12!RedLight:11!Fan:10! foreach ($controlsArray as $control) { $controlArray = explode(":", $control); echo "<option value=" . $controlArray[1] . ">" . $controlArray[0] . "</option>"; } } else { $list = $deviceObj->get_all_devices(); echo "<option class='redClass' value='0'>Select a device</option>"; foreach ($list as $item) { echo "<option value=" . $item['name'] . ">" . $item['name'] . "</option>"; } } /*echo "<input id='ip' hidden value='". $ip."'>"; $result = $deviceObj->get_controls($ip); $controls = $result['details']; $controls = substr($controls,0,strlen($controls)-1); $controlsArray = explode("!",$controls); //$controls = //TubeLight:12!RedLight:11!Fan:10! echo "<table align='center' id='controlList'>";
<?php include_once 'includes/dbcon.php'; include_once 'includes/device.php'; $deviceObj = new Device(); $devices = $deviceObj->get_all_devices(); echo "<tr>\n\t\t<th>Device ID</th>\n\t\t<th>Type</th>\n\t\t<th>IP address</th>\n\t\t<th>Action</th>\n\t </tr>"; foreach ($devices as $dev) { echo "<tr>\n\t\t\t\t<td>" . $dev['name'] . "</td>\n\t\t\t\t<td>" . $dev['type'] . "</td>\n\t\t\t\t<td>" . $dev['ip'] . "</td>\n\t\t\t\t<td>\n\t\t\t\t\t<form action='devices.php' method='post'>\n\t\t\t\t\t\n\t\t\t\t\t\t<input hidden type='text' name='dName' value='" . $dev['name'] . "'> \n\t\t\t\t\t \t<input type='submit' value='Open'>\n\t\t\t\t\t</form> \n\t\t\t\t</td>\n\t\t\t</tr>"; } //<input hidden type='text' name='ip' value='".$dev['ip']."'> //changing ip to name //<button onclick=\"location.href = 'devices.php?ip=".$dev['ip']."';\">Check</button> //$file = 'connections.txt'; //$data = file_get_contents($file); // $dataArr = explode("<br>", $data); /* foreach ($dataArr as $device) { if($device!=null){ $deviceArr = explode("/", $device); echo "<tr> <td>Device 1</td> <td>".$deviceArr[0]."</td> <td> <button onclick=\"location.href = 'device.php?ip=$deviceArr[0]';\">Check</button> </td> </tr>"; } }*/