array('filter' => FILTER_SANITIZE_NUMBER_INT, 'flags' => FILTER_REQUIRE_ARRAY))); if(isset($configdevices['configdevices'])) $configdevices = $configdevices['configdevices']; $applied = filter_input(INPUT_GET, 'applied', FILTER_SANITIZE_NUMBER_INT); $download = filter_input(INPUT_GET, 'download', FILTER_SANITIZE_SPECIAL_CHARS); // local vars $db; // init sql database if necessary if ( ! file_exists( $dbpath ) ) $newdb = new SQLiteDatabase( $dbpath, 0660 ); if ( ! file_exists( $dbpath ) ) die( "Unable to create database file at " . $dbpath ); // Connect to the database with PDO try { $db = new PDO('sqlite:'.$dbpath); } catch (Exception $e) { die ($e); } // Create table if doesn't exist $q = $db->query("PRAGMA table_info(DEVICES)"); if ( $q->rowCount() == 0 ) { $db->query( "CREATE TABLE DEVICES ( id INTEGER PRIMARY KEY, config TEXT, ready INTEGER, sent INTEGER, applied INTEGER );" ); } /********** RUNTIME SECTIONS **********/ // Always get devices from database try { $devicelist = $db->prepare('SELECT * FROM DEVICES;'); $devicelist->execute(); } catch (Exception $e) { die ($e); } // if requested, download unconfigured devices from MyDatavation if(strlen($download) > 0) { // TODO: placeholder $devices[time()] = time(); $devices[time()+1] = time(); $devices[time()+2] = time(); $devices[time()+3] = time(); // save devices in database try { $stmt = $db->prepare("INSERT INTO DEVICES (id, config) VALUES (:id, :config);"); $stmt->bindParam(':id', $i); $stmt->bindParam(':config', $c); foreach($devices as $di => $dc) { $i = $di; $c = $dc; $stmt->execute(); } } catch (Exception $e) { die ($e); } } // if requested, begin configuring devices if($configdevices != false && count($configdevices) > 0) { // update device status in DB try { $stmt = $db->prepare("UPDATE DEVICES SET ready=1 WHERE id=:id"); $stmt->bindParam(':id', $i); } catch (Exception $e) { die ($e); } foreach($configdevices as $d => $di) { $i = $di; $stmt->execute(); } } ?>

Devices