function get_sensor_name_list () {
	
	$sensor_list = apc_fetch('sensor_list');
	//var_dump($sensor_list);
		
	if (!$sensor_list) // if not available in APC then read the list from DB, then save the list in APC  
		{
			//echo "must read sesnor list from db";  
			
			$static_db = open_static_data_db(true);
			$results = $static_db->query('SELECT * FROM sensor_names;');
			while ($row = $results->fetchArray()) {
				$sensor_id = $row['id'];
				$sensor_name = $row['sensor_name'];
				$sensor_list[$sensor_id] = $sensor_name;
				//var_dump($sensor_list);
				// save the sensor list in APC	
			}
			$static_db->close();
			apc_store('sensor_list', $sensor_list);
	}
	
	return $sensor_list;
	
}
Beispiel #2
0
 /**
  * log in with post data
  */
 private function dologinWithPostData()
 {
     // check login form contents
     //        if (empty($_POST['user_name'])) {
     //           $this->errors[] = "Username field was empty.";
     //       } elseif (empty($_POST['user_password'])) {
     if (empty($_POST['user_password'])) {
         $this->errors[] = "Password field was empty.";
     } elseif (!empty($_POST['user_password'])) {
         $access_password = apc_fetch('access_password');
         if (!$access_password) {
             // get password from static DB
             $static_db = open_static_data_db();
             $results = $static_db->query('SELECT * FROM login_password');
             while ($row = $results->fetchArray()) {
                 $access_password = $row['Password'];
             }
             apc_store('access_password', $access_password);
         }
         //error_log("-------------------------------------" . $access_password);
         // create a database connection, using the constants from config/db.php (which we loaded in index.php)
         // $this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
         // change character set to utf8 and check it
         //  if (!$this->db_connection->set_charset("utf8")) {
         //       $this->errors[] = $this->db_connection->error;
         //   }
         // if no connection errors (= working database connection)
         // if (!$this->db_connection->connect_errno) {
         // escape the POST stuff
         //    $user_name = $this->db_connection->real_escape_string($_POST['user_name']);
         // database query, getting all the info of the selected user (allows login via email address in the
         // username field)
         /*     $sql = "SELECT user_name, user_email, user_password_hash
                                 FROM users
                                 WHERE user_name = '" . $user_name . "' OR user_email = '" . $user_name . "';";
                         $result_of_login_check = $this->db_connection->query($sql);
         */
         // if this user exists
         //   if ($result_of_login_check->num_rows == 1) {
         // get result row (as an object)
         //       $result_row = $result_of_login_check->fetch_object();
         // using PHP 5.5's password_verify() function to check if the provided password fits
         // the hash of that user's password
         //   if (password_verify($_POST['user_password'], $result_row->user_password_hash)) {
         if ($_POST['user_password'] == $access_password) {
             // write user data into PHP SESSION (a file on your server)
             $_SESSION['user_name'] = "harvestgenie";
             $_SESSION['user_email'] = "";
             $_SESSION['user_login_status'] = 1;
         } else {
             $this->errors[] = "Wrong password. Try again.";
         }
         /* } else {
                $this->errors[] = "This user does not exist.";
            }*/
         /* } else {
                $this->errors[] = "Database connection problem.";
            }*/
     }
 }
function save_trigger($trigger_id, $description)
{
    $static_db = open_static_data_db();
    //error_log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" . $trigger_id .  $description);
    if ($trigger_id == 0) {
        $results = $static_db->query('INSERT INTO triggers values (NULL,"' . $description . '",0);');
    } else {
        $results = $static_db->query('UPDATE triggers SET `description` = "' . $description . '" where `id` = ' . $trigger_id . ';');
    }
    $static_db->close();
    save_static_db_in_storage();
}
function get_pin_status ($pin_nr) {
	$static_db = open_static_data_db();
	$results = $static_db->query('select enabled from  pins where id = ' . $pin_nr . ' ;');
	if ($row = $results->fetchArray()) {
		//var_dump($row);
		$pin_status = $row['enabled'];
		}
	$static_db->close();
	return 	$pin_status;
 }