diff --git a/GlassesController.php b/GlassesController.php index 228bb09e9be34cf797e012e51834fa02d82dbee5..14f08c2513f9a424261d57d6c4cb7fd95e9c3a57 100644 --- a/GlassesController.php +++ b/GlassesController.php @@ -2,8 +2,11 @@ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); -require_once "./lib/HWlib.php"; +define( "APP_ROOT", realpath( dirname( __FILE__ ) ).'/' ); + +require_once APP_ROOT."lib/HWlib.php"; +$sitebasepath=$_SERVER['DOCUMENT_ROOT']; header("Content-Type: application/json; charset=UTF-8"); class GlassesController { @@ -29,17 +32,32 @@ class GlassesController { } function get($PARAM){ - @$data=$_REQUEST['data']; - $myObj=new StdClass(); - $myObj->content = array(); + @$longitude=$PARAM['longitude']; + @$latitude=$PARAM['latitude']; - // TODO Security issue, use statements + $statement=$this->db->prepare("insert into CrowdGlassesGPS(longitude,latitude) values (:long,:lat)"); + $statement->bindParam(":long",$longitude,PDO::PARAM_STR); + $statement->bindParam(":lat",$latitude,PDO::PARAM_STR); + $statement->execute(); + + $myObj=new StdClass(); - $table=$this->db->query("select id, user as name, text from CrowdGlassesMsg",PDO::FETCH_OBJ); + $table=$this->db->query("select id, user as name, text from CrowdGlassesMsg",PDO::FETCH_OBJ); foreach($table as $tuple) array_push($myObj->content,$tuple); return $myObj; } + + function getGPS($PARAM){ + $table==$this->db->query("select longitude,latitude from CrowdGlassesGPS order by id limit 1",PDO::FETCH_OBJ); + + $myObj=new StdClass(); + + $table=$this->db->query("select id, user as name, text from CrowdGlassesMsg",PDO::FETCH_OBJ); + foreach($table as $tuple) + array_push($myObj->content,$tuple); + return $myObj; + } } @@ -49,11 +67,7 @@ $manager = new GlassesController(); if (isset($_GET['action'])) { $action = $_GET['action']; - $PARAM=array(); - if (isset($_GET['msg'])) - $PARAM['msg']=$_GET['msg']; - else - $PARAM['msg']="empty"; + $PARAM=$_REQUEST; if (isset($_SESSION['id'])) $PARAM['user']=$_SESSION['id']; else diff --git a/projects/Crowd-glasses/crowd-glasses.sca b/projects/Crowd-glasses/crowd-glasses.sca index 7159fb7227f874a58ea03402b25f3264eb9db63e..014b4245ce61cb3edb68f83674699b67fdad30e6 100755 --- a/projects/Crowd-glasses/crowd-glasses.sca +++ b/projects/Crowd-glasses/crowd-glasses.sca @@ -8,6 +8,8 @@ "guardtip":"Nothing to check", "actiontip":"We instantiate the template", "actions": [ + "-- Empty chat", + "delete from CrowdGlassesMsg", "-- Load the template of the question.", "use 'Crowd-glasses-gui-1' as template", "-- Install the related question. Set a checker to filter the answer.", diff --git a/projects/Crowd-glasses/gui-1.tmpl b/projects/Crowd-glasses/gui-1.tmpl index ebe9d0028b165ca09aec14a5f987718f173a3fb5..181772a9323cc851241bb49bdb4b42be3fd2add5 100644 --- a/projects/Crowd-glasses/gui-1.tmpl +++ b/projects/Crowd-glasses/gui-1.tmpl @@ -1,14 +1,30 @@ <center> - <p> - <iframe id="inlineFrameExample" - title="Live stream from the emmergency site" - width="500" - height="500" - allow="camera;microphone" - src="https://wizzeye.app/istic"> -</iframe> - </p> +<table> + <tr> + <td colspan='2'> + <iframe id="inlineFrameExample" + title="Live stream from the emergency site" + width="100%" + height="500" + allow="camera;microphone" + src="https://wizzeye.app/istic"> + </iframe> + </td> + </tr> + <tr> + <td width="500" height="200" style="background-color:rgb(61,108,110);color:white;"> + <div id='glasses-chat'> + Starting message board...</br> + </div> + </td> + <td> + <div id="mapid" style="width: 600px; height: 400px;"></div> + </td> + </tr> +</table> +<br/> +<br/> <p> <input id="text" type="text"/> <button id="send" type="button" onClick="sendInfo()">Send</button> </p> @@ -34,12 +50,30 @@ function sendInfo(){ $value=$text.value; $text.value=""; - console.log("send"); var request = new XMLHttpRequest(); - request.open('GET', 'https://headwork.irisa.fr/headwork/GlassesController.php?action=insert&msg='+$value, true); + request.open('GET', 'GlassesController.php?action=insert&msg='+$value, true); + document.getElementById("glasses-chat").innerHTML += $value+'<br/>'; + console.log('GET https://headwork.irisa.fr/headwork/GlassesController.php?action=insert&msg='+$value); request.send(null); + } // TODO block submit on enter </script> +<script> + + var mymap = L.map('mapid').setView([48, -1], 13); + L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', { + maxZoom: 40, + attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' + + '<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' + + 'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>', + id: 'mapbox/streets-v11', + tileSize: 512, + zoomOffset: -1 + }).addTo(mymap); + mymap.flyTo([48.11576,-1.63755],16); + +</script> + diff --git a/projects/Crowd-glasses/init-workflow.sql b/projects/Crowd-glasses/init-workflow.sql index 431a8147342ffa356961916e531648e7474d29e8..134a14ae6485130dab7051a5782cafe460f00b8d 100644 --- a/projects/Crowd-glasses/init-workflow.sql +++ b/projects/Crowd-glasses/init-workflow.sql @@ -1,8 +1,11 @@ DROP TABLE IF EXISTS CrowdGlassesMsg; +DROP TABLE IF EXISTS CrowdGlassesGPS; + DELETE from Artifact where classid in (select id from ArtifactClass where project = 'Crowd-glasses'); DELETE from ArtifactClass where project = 'Crowd-glasses'; CREATE TABLE CrowdGlassesMsg(id int auto_increment primary key, user varchar(100),text varchar(300)); +CREATE TABLE CrowdGlassesGPS(id datetime default current_timestamp primary key, longitude varchar(100),latitude varchar(100)); insert into ArtifactClass(id,description,definition,tablename,project,autostart) values (10000,'Emergency Response','Crowd-glasses/crowd-glasses.sca', null, 'Crowd-glasses',true);