Example #1
0
function insertData($climate)
{
    global $climate_db;
    global $device_db;
    //Open MySQL Connection inorder to get last data point for a device.
    $database = sql_dmca();
    $climate = arrayEscape($climate, $database);
    $climate_results['error'] = "";
    // Check that the foreign key will be valid
    $device_check = getDevice($climate);
    // If the device doesn't already exist then create it in the device table
    if ($device_check["info"]->num_rows == 0) {
        $device_add_results = addDevice($climate);
        if ($device_add_results['error']) {
            $climate_results['error'] .= $device_add_results['error'];
        }
    }
    $climate_results['statement'] = "INSERT INTO {$climate_db}\n \t\t\t\t\t\t\t\t\t(location_id, time, temp)\n \t\t\t\t\t\t\t\t\tVALUES\n \t\t\t\t\t\t\t\t\t( (SELECT id FROM {$device_db} WHERE building='{$climate['building']}' AND room = '{$climate['room']}'), \n \t\t\t\t\t\t\t\t\t\t'{$climate['timestamp']}', \n \t\t\t\t\t\t\t\t\t\t'{$climate['temperature']}')";
    $climate_results['info'] = $database->query($climate_results['statement']);
    $climate_results['error'] .= $database->error;
    if ($climate_results['error']) {
        $climate_results['results'] .= "Climate Insertion Error {$climate['building']} {$climate['room']} {$climate['timestamp']}";
    } else {
        $climate_results['results'] .= "Climate Insertion Success {$climate['building']} {$climate['room']} {$climate['timestamp']}";
    }
    $database->close();
    return $climate_results;
}
Example #2
0
 if ($_GET['action'] == "show_device_type") {
     DisplayDeviceType();
 } else {
     if ($_GET['action'] == "edit_device_type") {
         EditDeviceType();
     } else {
         if ($_GET['action'] == "archive_device_type") {
             ArchiveDeviceType();
         } else {
             if ($_GET['action'] == "add_device_type") {
                 AddDeviceType();
             } else {
                 if ($_GET['action'] == add && $_SESSION['access'] >= 50) {
                     //add the device
                     if (isset($_POST['addData'])) {
                         addDevice($devices);
                     } else {
                         if (isset($_POST['addType'])) {
                             $deviceType = new Device_type();
                             addDeviceType($deviceType);
                         } else {
                             if (isset($_POST['addLocation'])) {
                                 $location = new Location();
                                 addLocation($location);
                             } else {
                                 addDeviceForm($devices);
                             }
                         }
                     }
                 } else {
                     if ($_GET['action'] == remove && $_SESSION['access'] >= 50) {
$lati[1] = $_POST["lati2"];
$long[1] = $_POST["long2"];
$ip[2] = $_POST["ip3"];
$comm[2] = $_POST["lb3"];
$mac[2] = $_POST["mac3"];
$sn[2] = $_POST["sn3"];
$lati[2] = $_POST["lati3"];
$long[2] = $_POST["long3"];
for ($i = 0; $i < 3; $i++) {
    # code...
    if ($ip[$i] != "" && $comm[$i] != "") {
        # code...
        if (ifPingable($ip[$i]) != false) {
            # code...
            echo $ip[$i] . " : " . $comm[$i];
            addDevice($ip[$i], $comm[$i], $mac[$i], $sn[$i], $lati[$i], $long[$i]);
        }
        if (ifPingable($ip[$i]) == false) {
            # code...
            echo $ip[$i] . " is not reachable!<br>";
        }
    }
}
echo "<br>";
echo "<br>";
echo "System needs to take a while for synchorizaiton.";
echo "<br>";
echo "<br>";
echo "<button onclick=closeWin()>Close</button>";
echo "<script>\nfunction closeWin() {\n\twindow.close();\n}\n</script>";
// the helper function that double chekcs the device is really reachable