diff --git a/client/css/style.css b/client/css/style.css index 95fe974..f37bc57 100644 --- a/client/css/style.css +++ b/client/css/style.css @@ -17,7 +17,7 @@ a{ max-width:50%; margin:auto; background-color:#F6F7BD; - background-image: url("7915.png") ; + background-image: url("img/7915.png") ; background-repeat:no-repeat; background-attachment:fixed; background-position: 2% 35%; diff --git a/client/empty.php b/client/empty.php deleted file mode 100644 index 577232e..0000000 --- a/client/empty.php +++ /dev/null @@ -1 +0,0 @@ -vuota diff --git a/client/index-delete.php b/client/index-delete.php deleted file mode 100644 index 736e777..0000000 --- a/client/index-delete.php +++ /dev/null @@ -1,337 +0,0 @@ - - - - - - - - - - - - - - -
-Le registrazioni antecendeti a dom 14 apr 2013, 23.00.00 non sono -disponibili. -
- - -
- -
-
- - - -
-

titolo della registrazione

- -
- -
-
- -open( DEFAULT_DBNAME , SQLITE3_OPEN_READWRITE); -} catch (Exception $e) { - myerror("Unable to open DB ". DEFAULT_DBNAME .". (".$e->getMessage().")\n"); - exit; -} - -# http://www.sqlite.org/datatype3.html - -/* INSTALALZIONE DEL NUOVO DB */ -$sqlstring = "CREATE TABLE IF NOT EXISTS registrazioni ( - id INTEGER PRIMARY KEY, - starttime DATE, - endtime DATE, - stopped boolean DEFAULT 0, - extracted boolean DEFAULT 0, - title varchar(500), - outfile text - )"; - -if ( ($res = $sq->exec( $sqlstring )) == FALSE ) { - myerror("impossibile installare"); - exit; -} - -$title = ( isset($_POST['title']) ) ? $_POST['title'] : DEFAULT_TITLE; -$starttime = ( isset($_POST['starttime']) ) ? $_POST['starttime'] : DEFAULT_START; -$endtime = ( isset($_POST['endtime']) ) ? $_POST['endtime'] : DEFAULT_END; - -/* -* CREO NUOVA REGISTRAZIONE -*/ - -if ( isset($_POST['op']) && $_POST['op'] === "new" ) { - - //print "NewFile...".FIFO_DIR."/$title
"; - - # esempio: - # s="2012/02/14 10:20" - # e="2012/02/14 11:15" - # outfile="cross-55.mp3" - - if ( $starttime == DEFAULT_START ) { - $starttime = date("Y/m/d H:i" ); - } - - $sqlstring = "INSERT into registrazioni (title,starttime,endtime) - VALUES ('$title','$starttime','$endtime')"; - - try { - $sq->exec($sqlstring); - mymessage("Informazioni registrate"); - } catch (Exception $e) { - myerror("Errore registrazione informazioni". $e->getMessage() .")\n"); - } -} - -/* -* FERMO UNA NUOVA REGISTRAZIONE -*/ -/* -if ( isset($_GET['op']) && isset($_GET['stop']) && $_GET['stop'] == "stop" ) { - - print "QUIIIII" ; - $id = $_GET['id']; - // end time = NOW! - - if ( $_GET['endtime'] == DEFAULT_END) { - $endtime = date("Y/m/d H:i"); - } else { - $endtime = $_GET['endtime'] ; - } - - $sqlstring = "UPDATE registrazioni - set endtime='$endtime', stopped=1 - where id='$id'"; - - - if ( $sq->exec($sqlstring) == FALSE ) { - myerror("Impossibile Terminare la registrazione ($sqlstring)"); - } else { - mymessage("Registrazione fermata!"); - } -} -*/ - -/* -* CANCELLA UNA REGISTRAZIONE -*/ -if ( isset($_GET['op']) && isset($_GET['delete']) && $_GET['delete'] == "cancella" ) { - - $id = $_GET['id']; - - $sqlstring = "DELETE from registrazioni where id='$id'"; - - if ( ($result = $sq->exec($sqlstring)) == FALSE) { - myerror("Impossibile cancellare"); - } else { - mymessage("Registrazione correttamente cancellata!"); - } -} - -/* -* MODIFICA / FERMA UNA REGISTRAZIONE -*/ -/* print "OP". $_GET['op']."
"; -print "UPDATE". $_GET['update']."
"; -print "STOP". $_GET['stop']."
"; -*/ -if (isset($_GET['op']) && ( $_GET['op'] == "update" )) - { - - // Anyway, update! - - // Get values from form - $id = $_GET['id']; - $title = $_GET['title']; - $starttime = $_GET['starttime']; - $endtime = ( $_GET['endtime'] == DEFAULT_END) ? date("Y/m/d H:i") : $endtime = $_GET['endtime'] ; - - $sqlstring = "UPDATE registrazioni - set title = '$title', starttime = '$starttime', endtime = '$endtime', stopped=1 - where id='$id'"; - - if ( ($result = $sq->exec($sqlstring)) == FALSE) { - myerror("Impossibile Modificare i contenut ($sqlstring)"); - } else { - mymessage("Aggiornamento eseguito"); - } -} - -/* -* ESTRAI UNA REGISTRAZIONE -*/ -if ( isset($_GET['op']) && isset($_GET['extract']) && $_GET['extract'] == "estrai" ) { - - // Anyway, update! - - // Get values from form - $id = $_GET['id']; - $title = $_GET['title']; - $starttime = $_GET['starttime']; - $endtime = $_GET['endtime']; - $outfile = AUDIO_DIR."/".date("Y")."-".date("m")."/".date("d")."/".$title."-".date("U").".mp3"; - $content = "s=\"$starttime\"\ne=\"$endtime\"\noutfile=\"$outfile\"\n"; - $outfile_rel = AUDIO_DIR_R."/".date("Y")."-".date("m")."/".date("d")."/".$title."-".date("U").".mp3"; - - #s="2013/03/31 18:37" - #e="END" - #outfile="mimmo.mp3" - - if ( data2file( FIFO_DIR . "/$title.fifo", $content ) ) { - $sqlstring = "UPDATE registrazioni set outfile = '$outfile_rel ' , extracted = 1 where id='$id'"; - if ( ($result = $sq->exec($sqlstring)) == FALSE) { - myerror( "Impossibile segnare come fermata"); - } - mymessage( "Registrazione in processamento ma non segnalata come fermata ($sqlstring)"); - - } else { - myerror("Impossibile SALVARE la richiesta"); - } - - -} -?> - - - -
- -query( $sqlstring )) == FALSE) { - myerror("Impossibile prelevare dati"); - } - - print " - - - - - - - - - - - - "; - - while ($data = $result->fetchArray() ) - { - - // se e' stata stoppata (aggiornata almeno una volta) => Pulsate STOP/Aggiorna - $stoplabel = ( $data['stopped'] == 1) ? "aggiorna" : "stop"; - $updatedisabled = ( $data['extracted'] == 1) ? "disabled" : ""; - - $extractiondisabled = ( $data['stopped'] == 1 && $data['extracted'] == 0 ) ? "": "disabled" ; - - print " - - - - - "; - - // print ""; - - print ""; - - if ( $data['extracted'] == 1) { - $f = trim( str_replace( getcwd(), "", $data['outfile']) ); - // print "F" . $f; - // print "OUT" . $data['outfile']; - // print "OUT" .realpath( $data['outfile'] ); - // print "COMPLETE" . getcwd()."/".$data['outfile'] . " --- " . is_readable( $data['outfile'] ) ; - - // if ( ($f = fopen($data['outfile'] ,'r')) !== FALSE ) { - // if ( is_readable( getcwd()."/".$data['outfile'] ) ) { - //if ( is_readable( $data['outfile'] ) ) { - $finfo = pathinfo($f); - $logfile = urlencode( $f ).".log"; - $logfile = trim($f).".log"; - - $logcontent = file_get_contents( $logfile , FILE_USE_INCLUDE_PATH); - // print $logcontent; - print ""; - - } else { - print ""; - } - - print ""; - - print ""; - } - print " -

Titolo (desc)

Inizio (desc)

Fine (desc)

Stop/Aggiorna Estrai Download Cancella
- "; - - print " "; - // print "
File: $f"; - // print "
LogFile: $logfile"; - // print "
logcontent: $logcontent"; - - if ( file_exists($f) ) { - print " scarica "; - } else { - print "..processando..
$f
$logfile"; - } - print "
(estrai prima di scaricare)
"; - - $sq->close(); - -?> -
- -
- -
- - - - - - diff --git a/client/index.html b/client/index.html index 5014bcb..d8cd947 100644 --- a/client/index.html +++ b/client/index.html @@ -2,13 +2,13 @@ + TechREC - + - - - + + - diff --git a/client/js/reclibrary.js b/client/js/reclibrary.js index 9d7731a..b1d89ec 100644 --- a/client/js/reclibrary.js +++ b/client/js/reclibrary.js @@ -32,7 +32,7 @@ var rec_name_default = ""; /** * Perform Ajax async loading **/ -function async_load( destdiv, uri, postdata) { +function DELETEasync_load( destdiv, uri, postdata) { postdata = postdata || ''; console.log("[ASYNC] " + destdiv + " <- " + uri) @@ -40,7 +40,7 @@ function async_load( destdiv, uri, postdata) { $(destdiv).html("\
\ \"); console.log("Tolta uri" + uri + "NOW -> http://127.0.1.1:8000/sampleJSON"); - var request = $.ajax( { url: "http://127.0.0.1:8000/sampleJSON", + var request = $.ajax( { url: "http://127.0.0.1:8000/create", type:"GET", //data: postdata, //dataType: 'json', @@ -144,9 +144,8 @@ function rec_new( ) { var request = $.ajax({ type: "POST", - cache: false, - // url: "http://127.0.0.1:8000/sampleJSON", - url: "http://127.0.0.1:8000/sampleJSON", + cache: false, + url: "http://127.0.0.1:8000/create", data: dataString, dataType: "json" }); @@ -161,12 +160,12 @@ function rec_new( ) { console.log("req"+ request); } ); - request.fail(function (jqXHR, textStatus, errorThrown){ - // log the error to the console - console.error("The following error occured: "+ - jqXHR.status, +"-"+ textStatus + "-" + errorThrown - ); - }); + request.fail(function (jqXHR, textStatus, errorThrown){ + + console.error("The following error occured: "+ + jqXHR.status, +"-"+ textStatus + "-" + errorThrown + ); + }); }); diff --git a/client/new.html b/client/new.html index d205d76..fd75039 100644 --- a/client/new.html +++ b/client/new.html @@ -13,6 +13,8 @@ var txt_start = "Inizia"; var txt_stop = "Ferma"; var txt_download = "Scarica"; +var srvaddr = "http://127.0.1.1:8000/"; + var almostone = false; var noplusbotton = true; var maxrec = 0 ; @@ -23,23 +25,47 @@ var rec_name_default = ""; function async_load( destdiv, uri, postdata) { postdata = postdata || ''; - console.log("[ASYNC] " + destdiv + " <- " + uri + " --- DATA "+postdata ); + console.log("[ASYNC] " + destdiv + " <- " + uri) + console.log( postdata ); - $(destdiv).html("\
\ \"); - - var request = $.ajax( { url: uri, type:"POST", data: postdata } ); - - request.fail(function(jqXHR) { - - console.log("Errore async ajax: " + jqXHR.status) + $(destdiv).html("\
\ \"); + console.log("Tolta uri" + uri + "NOW -> http://127.0.1.1:8000/sampleJSON"); + var request = $.ajax( { url: "http://127.0.1.1:8000/sampleJSON", + type:"POST", + data: postdata, + dataType: 'json', + success : function( msg ) { + $(".imageloader").remove(); + resmsg = "["+jqXHR.status+"]"; + alert("Ma ci sei ?"); + $(destdiv).append( resmsg ); + }, + error: function(xhr) { + var errmsg = ""; + console.log("Errore async ajax: " + xhr.status ); + switch( xhr.status ) + { + case 0: errmsg="[0] Network Problem."; break; + case 404: errmsg="[404] Requested page not found."; break; + case 500: errmsg="[500] Internal Server Error."; break; + default: errmsg="[ErrCode: "+xhr.status+"] Error uncatched!"; break; + } + console.log("ErrMSG" + errmsg); + $(".imageloader").remove(); + //$(destdiv).html("Err: "+ errmsg); + alert("Err: "+ errmsg); + } + } + ).always(function( jqXHR ) { $(".imageloader").remove(); - $(destdiv).html("error code: " + jqXHR.status ); - }); - - request.done(function( msg ) { - $(".imageloader").remove(); - $(destdiv).append(msg); - }); + resmsg = "ALSWAST["+jqXHR.status+"]"; + $(destdiv).append( resmsg ); + } + ).complete( + function (jqXHR, msgstatus) { + alert("Comlpete " +jqXHR + " - " + msgstatus); + } + ); } @@ -49,6 +75,7 @@ function rs_trxname( code ) { return code+"_name"; } function rs_buttonarea( code ) { return code+"_buttonarea"; } function rs_inputstart( code ) { return code+"_startime"; } function rs_inputend( code ) { return code+"_endtime"; } +function rs_formid(code) { return "form-"+code; } function rs_id(code) { return code; } function rs_log(code) { return code + "_log"; } @@ -67,9 +94,15 @@ function rec_new( ) { $("#"+rs_trxarea(recid)).append( "
" ); // POPULATE BUTTON AREA - var str = "\"; + str = str + "\"; - + str = str + ""; + $("#"+formid).attr("action","#") .attr("method","post") //set the form attributes + $("#"+rs_buttonarea(recid)).html( str ); // DELETE BUTTON (NO FIRST ELEMENT) if ( recid > 0 ){ @@ -80,11 +113,24 @@ function rec_new( ) { $("#"+rs_trxarea(recid)).append( "
Nuova trasmissione
" ); // BINDING CLICK TO FUNCTION - $("#"+rs_button(recid) ).click(function(){ + // $("#"+rs_button(recid) ).click(function(){ + $("#"+rs_button(recid) ).submit(function(){ + rec_changestate( rs_button(recid) ); }); } +function download( eid ){ + alert("DEntro download"); + var trxnameobj = document.getElementById( rs_trxname(eid) ); + var trxname = trxnameobj.value; + var starttime = $("#"+rs_inputstart(eid)).val(); + var endtime = $("#"+rs_inputstart(eid)).val(); + var jsondata = {"name":'"'+trxname+'"', "starttime":'"'+ starttime +'"', "endtime":'"'+ endtime +'"'}; + async_load( destdiv, srvaddr, jsondata); + alert("FINE download"); +} + function rec_changestate( eid ) { console.log("[CS] change state for "+eid+""); @@ -104,6 +150,8 @@ function rec_changestate( eid ) { ***/ + console.log("RECBUTTON value :"+recbutton.value); + //console.log("TXT " + txt_star.toUpperCase() ); if ( recbutton.value.toUpperCase() == txt_start.toUpperCase() ) { /* @@ -117,9 +165,11 @@ function rec_changestate( eid ) { var str = "\"; str = str + "\"; - $("#"+rs_buttonarea(eid)).append( str ); + //$("#"+rs_buttonarea(eid)).append( str ); + var formid = rs_formid( eid ); + $("#"+formid).append(str) - console.log("[CS] rs_log(eid) " + rs_log(eid) ); + console.log("[CS] Update log div (" + rs_log(eid) +")"); $("#"+rs_log(eid)).append("
Inizio: "+displayDate); console.log("[CS] change text for "+eid); @@ -147,8 +197,40 @@ function rec_changestate( eid ) { $("#"+rs_log(eid)).append("
Fine: "+displayDate); + recbutton.type = "submit"; recbutton.value = txt_download; + $("#"+eid).click(function(e){ + e.preventDefault(); + + dataString = $("#JqAjaxForm").serialize(); + + $.ajax({ + type: "POST", + url: "http://127.0.1.1:8000/sampleJSON", + data: {"value":"value"}, + dataType: "json", + success: function(data) { + alert("QUI"+ data); + + }, + error: function (x) { + alert("error" + x.status); + } + }); + }); + + + $("#"+ rs_trxarea(eid)).css("background-color","green"); + console.log("EID" + eid); + $("#"+ rs_trxarea(eid)).append( "SCARICA LINK" ); + /*$("#but-down-"+eid).click(function(){ + var trxname = trxnameobj.value; + var starttime = $("#"+rs_inputstart(eid)).val(); + var endtime = $("#"+rs_inputstart(eid)).val(); + var jsondata = {"name":'"'+trxname+'"', "starttime":'"'+ starttime +'"', "endtime":'"'+ endtime +'"'}; + async_load( destdiv, srvaddr, jsondata); + });*/ } else if ( recbutton.value.toUpperCase() == txt_download.toUpperCase() ) { @@ -160,7 +242,9 @@ function rec_changestate( eid ) { console.log("[CS] GetID"+ eid+ "_name"); var trxname = trxnameobj.value; - + var starttime = $("#"+rs_inputstart(eid)).val(); + var endtime = $("#"+rs_inputstart(eid)).val(); + console.log("[CS] ID = "+eid+"_name ==> "+trxname ) ; console.log("[CS] "+trxname+" != "+rec_name_default); @@ -182,11 +266,16 @@ function rec_changestate( eid ) { } - console.log("recarea"+eid); - console.log($("#recarea"+eid).innerHTML); - $("#recarea"+eid).css("background-color","#ccc"); + console.log( "Recarea "+rs_trxarea(eid) +" -> " + $("#"+rs_trxarea(eid)).innerHTML ); + $("#"+rs_trxarea(eid)).css("background-color","#ccc"); + + // TODO: fare i controlli su starttime, endtime - async_load( "#"+rs_log(eid), "techrecapi.php?op=new", {location:"roma", name:"ciccio"}); + var jsondata = {"name":'"'+trxname+'"', "starttime":'"'+ starttime +'"', "endtime":'"'+ endtime +'"'}; + + destdiv = "#"+rs_log(eid) + console.log( destdiv +" <- " + srvaddr + "\n" + jsondata ); + async_load( destdiv, srvaddr, jsondata); } @@ -201,13 +290,11 @@ function rec_changestate( eid ) { } - /* GESTIONE CAMBIO DI STATO */ $(document).ready(function(){ rec_new(); }); - @@ -220,7 +307,7 @@ $(document).ready(function(){ L'INTERFACCIA COERENTE CON LA BASE DI DATI -->
-
+

techr*c

@@ -230,7 +317,7 @@ $(document).ready(function(){
-
+
diff --git a/server/server.py b/server/server.py index 3372290..2a316c4 100644 --- a/server/server.py +++ b/server/server.py @@ -3,23 +3,42 @@ import sys,os import logging logging.basicConfig(level=logging.INFO) +""" +RESPONSE HTML +http://stackoverflow.com/questions/6391280/simplehttprequesthandler-override-do-get +""" + +import ast # include data object from techrec import * +import SimpleHTTPServer """ CONNECTION HANDLER """ -class ConnHandler(SocketServer.BaseRequestHandler): - def __init__(self, db, *args, **keys): - self.db = db +# class ConnHandler(SocketServer.BaseRequestHandler): +class ConnHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): + def __init__(self, *args, **keys): + self.db = RecDB() + # logging.info("Connected from: %s" % self.client_address[0] ) SocketServer.BaseRequestHandler.__init__(self, *args, **keys) + # SimpleHTTPServer.SimpleHTTPRequestHandler.__init__(self, *args, **keys) + def strip_http_headers(self,http_reply): + p = http_reply.find('\r\n\r\n') + if p >= 0: + return http_reply[p+4:] + return http_reply + def handle(self): - + self.data = self.request.recv(1024).strip() - logging.debug("DATA: %s - %s" % (self.client_address[0], self.data) ) - - tmp = Rec(asjson=self.data) - - + body = [ ast.literal_eval( self.strip_http_headers( self.data ) ) ] + print("DATA:", self.data) + logging.debug("Received from %s:\n%s\n%s" % (self.client_address[0], self.data, body) ) + try: + tmp = Rec(asjson=body) + except: + self.request.send( "ERORE" ) + return if tmp.err(): respmsg = "Data ERROR" else: @@ -29,45 +48,64 @@ class ConnHandler(SocketServer.BaseRequestHandler): self.db.add( tmp ) self.db.printall() - self.request.sendall( respmsg ) - -def handler_factory(db): + + _responsemsg = "{}" + responsemsg = formatresponse( _responsemsg ) + # print "SEND RESPONSE:", responsemsg + # self.request.sendall( responsemsg ) + # self.request.send( responsemsg ) + _resmsg = json.dumps({'return':'ok'}) + print "SEnd BACK:" , _resmsg + #TODO: check response + #if True: + #else: + self.request.sendall( _resmsg ) + return + +def formatresponse( data ): + return "HTTP/1.0 200 OK\r\nContent-Type:application/json\r\nConnection:close\r\n\r\n{0}\r\n".format( data ) + +class MyTCPServer(SocketServer.ThreadingTCPServer): + allow_reuse_address = True + +"""def handler_factory(db): def createHandler(*args, **keys): return ConnHandler(db, *args, **keys) return createHandler - +""" """ MAIN SERVER """ class recserver: def __init__(self, host="localhost", port=9999): self.host = host self.port = port - self.db = RecDB() + def start(self): - try: - # self.server = SocketServer.TCPServer((self.host, self.port), ConnHandler) - self.server = SocketServer.TCPServer((self.host, self.port), handler_factory( self.db ) ) - except: - sys.exit("Bind error.") + + self.server = SocketServer.TCPServer((self.host, self.port), ConnHandler) + self.server = MyTCPServer((self.host, self.port), ConnHandler) + # self.server = SocketServer.TCPServer((self.host, self.port), handler_factory( self.db ) ) + logging.info("Server ready to serve forever.") - self.server.serve_forever() + try: + self.server.serve_forever() + except KeyboardInterrupt: + logging.debug("Closing Socket") + self.server.socket.close() -def loadall(): - """ - # Testing DB +def testdb(): db = RecDB() a = Rec(name="Mimmo1",starttime="ora",endtime="fine") db.add( a ) db.printall() db.search( Rec(name="Mimmo1") ) - """ - # Loading Server TODO: make thread + +def loadall(): + # TODO: make thread r = recserver() r.start() - # Loading Server if __name__ == "__main__": - loadall() - + loadall() \ No newline at end of file diff --git a/server/techrec.db b/server/techrec.db index 01604d5..35f48fe 100644 Binary files a/server/techrec.db and b/server/techrec.db differ diff --git a/server/techrec.py b/server/techrec.py index 6960ba1..082b0ef 100644 --- a/server/techrec.py +++ b/server/techrec.py @@ -45,14 +45,21 @@ class Rec(Base): self.starttime = starttime self.endtime = endtime else: - try: + #try: # dec = json.loads( unicode(asjson) ) - dec = yaml.load( asjson ) - except: - self.error = 0 - self.name = dec[0]['name'] - self.starttime = dec[0]['starttime'] - self.endtime = dec[0]['endtime'] + # dec = yaml.load( asjson ) + dec = json.dumps( asjson ) + # except: + # self.error = 0 + print("dec %s %s" % (dec,type(dec))) + print("asjson %s %s" % (asjson,type(asjson))) + + # self.name = dec[0]['name'] + # self.starttime = dec[0]['starttime'] + # self.endtime = dec[0]['endtime'] + self.name = asjson[0]['name'] + self.starttime = asjson[0]['starttime'] + self.endtime = asjson[0]['endtime'] # self.id = None self.state = QUEUE print "DECC" , dec @@ -94,18 +101,18 @@ class RecDB: # print all records def printall(self): - logging.info("DB") + print("DB") allrecords = self.session.query(Rec).all() for record in allrecords: - logging.info("R: %s " % record) + print("R: %s" % record) def execsql(self,sql): records = self.conn.execute( sql ) def search(self, name="", starttime="", endtime=""): - logging.info("Looking for %s" % recfilter) + logging.debug("Looking for %s" % recfilter) # self.session.query( Rec ).filter( Rec.name=name ).first()