This commit is contained in:
antifaz 2013-08-28 17:29:31 +02:00
parent 56aeb7b48f
commit 8aca72a6a3
17 changed files with 1547 additions and 0 deletions

1
client/empty.php Normal file
View file

@ -0,0 +1 @@
vuota

247
client/function.php Normal file
View file

@ -0,0 +1,247 @@
<?
include_once("utils.php");
/*
* API HELP
*/
function help() {
print "<div>
<div> TechreAPI (ver ".VER."): <b>HELP</b> <div/>
<div> install()<div/>
<div> new()<div/>
<div> del()<div/>
<div> update()<div/>
<div> search()<div/>
<div/>";
}
/*
* DBSQLITE CONNECT
*/
function connect( ) {
try {
$db = new SQLite3( DEFAULT_DBNAME , SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE );
} catch (Exception $e) {
myerror("Unable to open DB ". DEFAULT_DBNAME .". (".$e->getMessage().")\n");
return Null;
}
return $db;
}
/* DBSQLITE DISCONNECT */
function disconnect( $db ){ if ($db) $db->close(); }
/*
* INSTALLAZIONE DEL NUOVO DB
*/
function rec_install( $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 = $db->exec( $sqlstring )) == FALSE ) {
myerror("impossibile installare"); exit;
}
}
/*
* CREO NUOVA REGISTRAZIONE
*/
function rec_new($db, $p) {
$title = ( isset($p['title']) ) ? $p['title'] : DEFAULT_TITLE;
$starttime = ( isset($p['starttime'] ) ) ? $p['starttime'] : DEFAULT_START;
$endtime = ( isset($p['endtime']) ) ? $p['endtime'] : DEFAULT_END;
if ( $starttime == DEFAULT_START ) {
$starttime = date("Y/m/d H:i" );
}
$sqlstring = "INSERT into registrazioni (title,starttime,endtime)
VALUES ('$title','$starttime','$endtime')";
try {
$db->exec($sqlstring);
mymessage("Informazioni registrate");
} catch (Exception $e) {
myerror("Errore registrazione informazioni". $e->getMessage() .")\n");
}
}
/*
* CANCELLA UNA REGISTRAZIONE
*/
function rec_del( $db, $id ) {
$sqlstring = "DELETE from registrazioni where id='$id'";
if ( ($result = $sq->exec($sqlstring)) == FALSE) {
myerror("Impossibile cancellare");
} else {
mymessage("Registrazione correttamente cancellata!");
}
}
/*
* MODIFICA UNA REGISTRAZIONE
*/
function rec_update( $db, $p ) {
$id = $p['id'];
$title = $p['title'];
$starttime = $p['starttime'];
$endtime = ( $p['endtime'] == DEFAULT_END) ? date("Y/m/d H:i") : $endtime = $p['endtime'] ;
$sqlstring = "UPDATE registrazioni
set title = '$title', starttime = '$starttime', endtime = '$endtime', stopped=1
where id='$id'";
if ( ($result = $db->exec($sqlstring)) == FALSE) {
myerror("Impossibile Modificare i contenut ($sqlstring)");
} else {
mymessage("Aggiornamento eseguito");
}
}
/*
* ESTRAI UNA REGISTRAZIONE
*/
function rec_extract( $db, $p ) {
// Get values from form
$id = $p['id'];
$title = $p['title'];
$starttime = $p['starttime'];
$endtime = $p['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 = $db->exec($sqlstring)) == FALSE) {
myerror( "Impossibile segnare come fermata");
}
mymessage( "Registrazione in processamento ma non segnalata come fermata ($sqlstring)");
} else {
myerror("Impossibile SALVARE la richiesta");
}
}
/*
* CERCA UNA REGISTRAZIONE
*/
function rec_get($db, $p) {
$order = "starttime desc";
# qui c'e' il bug perche' passo in input "starttime desc" e questo non viene rilevato
// if ( isset($p['sort']) && in_array($p['sort'], array("starttime","endtime","title") ) ) {
if ( isset($p['sort']) ) {
$order = $p['sort'];
}
$sqlstring = "SELECT *
FROM registrazioni
ORDER BY $order";
// debug purposes
myerror($sqlstring);
if ( ($result = $db->query( $sqlstring )) == FALSE) {
myerror("Impossibile prelevare dati");
}
print "
<table width=\"100%\">
<tr>
<td> <p> <a href=\"index.php?sort=title\">Titolo</a> (<a href=\"index.php?sort=title desc\">desc</a>)</p> </td>
<td> <p> <a href=\"index.php?sort=starttime\">Inizio</a> (<a href=\"index.php?sort=starttime desc\">desc</a>)</p> </td>
<td> <p> <a href=\"index.php?sort=endtime\">Fine</a> (<a href=\"index.php?sort=endtime desc\">desc</a>)</p> </td>
<td> Stop/Aggiorna </td>
<!-- <td> Aggiorna </td> -->
<td> Estrai </td>
<td> Download </td>
<td> Cancella </td>
</tr>";
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 "
<tr class=\"rec$updatedisabled\"><form action=\"index.php\" method=\"GET\">
<td><input type=\"text\" id=\"title\" name=\"title\" value=\"". $data['title'] ."\" $updatedisabled /></td>
<td><input type=\"text\" id=\"starttime\" name=\"starttime\" value=\"". $data['starttime'] ."\" $updatedisabled /> </td>
<td><input type=\"text\" id=\"endtime\" name=\"endtime\" value=\"". $data['endtime'] ."\" $updatedisabled /> </td>
<td><input type=\"hidden\" name=\"op\" value=\"update\">
<input type=\"hidden\" name=\"id\" value=\"". $data['id'] ."\">";
print "<input type=\"submit\" name=\"stop\" value=\"$stoplabel\" $updatedisabled > </td>";
// print "<td><input type=\"submit\" name=\"update\" value=\"aggiorna\" $aggiornadisabled> </td>";
print "<td><input type=\"submit\" name=\"extract\" value=\"estrai\" $extractiondisabled> </td>";
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 "<td>";
// print "<br>File: $f";
// print "<br>LogFile: $logfile";
// print "<br>logcontent: $logcontent";
if ( file_exists($f) ) {
print "<a href=\"".$f."\" title=\"log: \n$logcontent\"> scarica </a>";
} else {
print "<a href=\"#\" title=\"log: \n$logcontent\">..processando..</a> <br/> $f <br/> $logfile";
}
print "</td>";
} else {
print "<td>(estrai prima di scaricare)</td>";
}
print "<td><input type=\"submit\" name=\"delete\" value=\"cancella\"> </form> </td>";
print "</tr>";
}
print "</table>";
}
?>

BIN
client/img/7915.orig.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
client/img/7915.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
client/img/ajax-loader.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 673 B

337
client/index-delete.php Normal file
View file

@ -0,0 +1,337 @@
<?
// phpinfo();
// exit;
include_once("utils.php");
?>
<html>
<head>
<!--[if lt IE 9]>
<script src="jquery-1.9.1.min.js"></script>
<![endif]-->
<!-- <meta http-equiv="refresh" content="30;url=https://techrec.ondarossa.info/index.php"> -->
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="message">
Le registrazioni antecendeti a dom 14 apr 2013, 23.00.00 non sono
disponibili.
</div>
<!-- PAGE CONTAINER -->
<div class="pagecontainer">
<div class="newrec">
<form action="index.php" method=POST>
<input type="hidden" name="op" value="new">
<input type="hidden" id="starttime" name="starttime" value="<? echo DEFAULT_START?>" />
<input type="hidden" id="endtime" name="endtime" value="<? echo DEFAULT_END?>" />
<div class="fieldtitle">
<p>titolo della registrazione</p>
<input type="text" id="title" name="title" value="<? echo DEFAULT_TITLE?>" />
</div>
<input type="submit" value="start now!" class="startbutton" />
</form>
</div>
<?php
/* DB SQLITE CONNECTION */
try {
$sq = new SQLite3( DEFAULT_DBNAME , SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE );
// $sq->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<br/>";
# 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']."<br/>";
print "UPDATE". $_GET['update']."<br/>";
print "STOP". $_GET['stop']."<br/>";
*/
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");
}
}
?>
<!--
Visualizzazione dati passati!
TODO: FORM per filtrare le richieste
-->
<div class="resultcontainer">
<?php
$order = "starttime desc";
# qui c'e' il bug perche' passo in input "starttime desc" e questo non viene rilevato
// if ( isset($_GET['sort']) && in_array($_GET['sort'], array("starttime","endtime","title") ) ) {
if ( isset($_GET['sort']) ) {
$order = $_GET['sort'];
}
$sqlstring = "SELECT * FROM registrazioni ORDER BY $order";
myerror($sqlstring);
if ( ($result = $sq->query( $sqlstring )) == FALSE) {
myerror("Impossibile prelevare dati");
}
print "
<table width=\"100%\">
<tr>
<td> <p> <a href=\"index.php?sort=title\">Titolo</a> (<a href=\"index.php?sort=title desc\">desc</a>)</p> </td>
<td> <p> <a href=\"index.php?sort=starttime\">Inizio</a> (<a href=\"index.php?sort=starttime desc\">desc</a>)</p> </td>
<td> <p> <a href=\"index.php?sort=endtime\">Fine</a> (<a href=\"index.php?sort=endtime desc\">desc</a>)</p> </td>
<td> Stop/Aggiorna </td>
<!-- <td> Aggiorna </td> -->
<td> Estrai </td>
<td> Download </td>
<td> Cancella </td>
</tr>";
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 "
<tr class=\"rec$updatedisabled\"><form action=\"index.php\" method=\"GET\">
<td><input type=\"text\" id=\"title\" name=\"title\" value=\"". $data['title'] ."\" $updatedisabled /></td>
<td><input type=\"text\" id=\"starttime\" name=\"starttime\" value=\"". $data['starttime'] ."\" $updatedisabled /> </td>
<td><input type=\"text\" id=\"endtime\" name=\"endtime\" value=\"". $data['endtime'] ."\" $updatedisabled /> </td>
<td><input type=\"hidden\" name=\"op\" value=\"update\">
<input type=\"hidden\" name=\"id\" value=\"". $data['id'] ."\">";
print "<input type=\"submit\" name=\"stop\" value=\"$stoplabel\" $updatedisabled > </td>";
// print "<td><input type=\"submit\" name=\"update\" value=\"aggiorna\" $aggiornadisabled> </td>";
print "<td><input type=\"submit\" name=\"extract\" value=\"estrai\" $extractiondisabled> </td>";
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 "<td>";
// print "<br>File: $f";
// print "<br>LogFile: $logfile";
// print "<br>logcontent: $logcontent";
if ( file_exists($f) ) {
print "<a href=\"".$f."\" title=\"log: \n$logcontent\"> scarica </a>";
} else {
print "<a href=\"#\" title=\"log: \n$logcontent\">..processando..</a> <br/> $f <br/> $logfile";
}
print "</td>";
} else {
print "<td>(estrai prima di scaricare)</td>";
}
print "<td><input type=\"submit\" name=\"delete\" value=\"cancella\"> </form> </td>";
print "</tr>";
}
print "
</table>";
$sq->close();
?>
</div>
<div style="clear:both;"></div>
</div>
<div id="footer">
techbl*c
</div>
</body>
</html>

5
client/jquery-1.9.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long

242
client/new.html Normal file
View file

@ -0,0 +1,242 @@
<!DOCTYPE html>
<html>
<head>
<title> TechREC </title>
<script src="jquery-1.9.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<script>
var txt_start = "Inizia";
var txt_stop = "Ferma";
var txt_download = "Scarica";
var almostone = false;
var noplusbotton = true;
var maxrec = 0 ;
var rec_name_default = "";
/** Perform Ajax async loading **/
function async_load( destdiv, uri, postdata) {
postdata = postdata || '';
console.log("[ASYNC] " + destdiv + " <- " + uri + " --- DATA "+postdata );
$(destdiv).html("\<div class=\"imageloader\"\> \<img src=\"ajax-loader.gif\" /\> \</div\>");
var request = $.ajax( { url: uri, type:"POST", data: postdata } );
request.fail(function(jqXHR) {
console.log("Errore async ajax: " + jqXHR.status)
$(".imageloader").remove();
$(destdiv).html("error code: " + jqXHR.status );
});
request.done(function( msg ) {
$(".imageloader").remove();
$(destdiv).append(msg);
});
}
function rs_button( code ) { return code; }
function rs_trxarea( code ) { return "recarea-"+code; }
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_id(code) { return code; }
function rs_log(code) { return code + "_log"; }
/** New record **/
function rec_new( ) {
console.log("Nuova");
var recid = "rec-"+maxrec;
maxrec += 1; // increment number of active record
console.log("AGGIUNTO AL MAIN CONTAINER");
$("#buttonscontainer").append( "<div id=\""+rs_trxarea(recid)+"\" class=\"recarea\"> </div>" );
$("#"+rs_trxarea(recid)).append( "<div id=\""+rs_buttonarea(recid)+"\" class=\"buttonarea\"> </div>" );
// POPULATE BUTTON AREA
var str = "\<input type=\"button\" id=\""+rs_button(recid)+ "\" name=\""+rs_button(recid)+"\" ";
str = str + " class=\"recbutton\" value=\"Inizia\" /\>";
$("#"+rs_buttonarea(recid)).html( str );
// DELETE BUTTON (NO FIRST ELEMENT)
if ( recid > 0 ){
$("#"+rs_buttonarea(recid)).append( "\<div class=\"dellink\" \> <a href=\"#\"> cancella</a> \</div\>" );
}
// INSERT AND POPULATE BUTTON AREA
$("#"+rs_trxarea(recid)).append( "<div id=\""+rs_log(recid)+"\" class=\"logarea\">Nuova trasmissione </div>" );
// BINDING CLICK TO FUNCTION
$("#"+rs_button(recid) ).click(function(){
rec_changestate( rs_button(recid) );
});
}
function rec_changestate( eid ) {
console.log("[CS] change state for "+eid+"");
var recbutton = document.getElementById( eid );
var trxnameobj = document.getElementById( rs_trxname(eid) );
if (recbutton == null) {
alert("Impossibile trovare ID");
return;
}
console.log("[CS] "+eid+" == " +recbutton.value);
/***
Simple FSM - Finite State Machine
***/
if ( recbutton.value.toUpperCase() == txt_start.toUpperCase() ) {
/*
In this case, user presses START
*/
var myDate = new Date();
var displayDate = (myDate.getFullYear()+1) + '/' + (myDate.getMonth()+1) + '/' + myDate.getDate();
displayDate = displayDate +' '+ myDate.getHours()+':'+myDate.getMinutes()+':'+myDate.getSeconds();
var str = "\<input type=\"text\" id=\""+rs_trxname(eid)+"\" placeholder=\"Nome trasmissione\" /\>";
str = str + "\<input type=\"hidden\" id=\""+rs_inputstart(eid)+"\" value=\""+displayDate+"\" /\>";
$("#"+rs_buttonarea(eid)).append( str );
console.log("[CS] rs_log(eid) " + rs_log(eid) );
$("#"+rs_log(eid)).append("<br /\>Inizio: "+displayDate);
console.log("[CS] change text for "+eid);
recbutton.value = txt_stop;
console.log("[CS] change color for area "+eid);
$("#"+ rs_trxarea(eid) ).css("background-color","red");
almostone = true;
} else if ( recbutton.value.toUpperCase() == txt_stop.toUpperCase() ) {
/*
In this case, user presses STOP
*/
console.log("[CS] "+eid+" == " +txt_stop);
var myDate = new Date();
var displayDate = (myDate.getMonth()+1) + '/' + (myDate.getDate()) + '/' + myDate.getFullYear();
displayDate = displayDate +' '+ myDate.getHours()+':'+myDate.getMinutes()+':'+myDate.getSeconds();
var str = "\<input type=\"hidden\" id=\""+rs_inputend(eid)+"\" value=\""+displayDate+"\" /\>";
$("#"+rs_trxarea(eid)).append( str );
$("#"+rs_log(eid)).append("<br /\>Fine: "+displayDate);
recbutton.value = txt_download;
$("#"+ rs_trxarea(eid)).css("background-color","green");
} else if ( recbutton.value.toUpperCase() == txt_download.toUpperCase() ) {
/* In this case, user presses DOWNLOAD
Save name and block the record. No operations are (more) allowed.
*/
console.log("[CS] "+eid+" == " +txt_download);
console.log("[CS] GetID"+ eid+ "_name");
var trxname = trxnameobj.value;
console.log("[CS] ID = "+eid+"_name ==> "+trxname ) ;
console.log("[CS] "+trxname+" != "+rec_name_default);
if (trxname == rec_name_default) {
trxname = prompt("Inserire il nome della registrazione per salvarla", "");
// check if it is empty or null
while ( ( $.trim(trxname) == "") || (trxname == null) ) {
trxname = prompt("Non posso registrare senza un nome!", "");
}
/* no possible !!! */
if ( $.trim(trxname) == "") {
alert("Sei riuscito/a a registrare senza dare un nome.. pensi di farla franca '??????"+
"techbl*c contro il lampo negli occhi della protoscimmia");
}
trxnameobj.setAttribute("value", trxname);
}
console.log("recarea"+eid);
console.log($("#recarea"+eid).innerHTML);
$("#recarea"+eid).css("background-color","#ccc");
async_load( "#"+rs_log(eid), "techrecapi.php?op=new", {location:"roma", name:"ciccio"});
}
// if there is almost one button and the PLUSBOTTON has previously insered
if (almostone == true && noplusbotton == true) {
$("#addnewrecarea").prepend( "<a href=\"#\" id=\"newrecbutton\">+ nuova</a>" );
$("#newrecbutton").click(function(){
rec_new();
});
noplusbotton = false;
}
}
/* GESTIONE CAMBIO DI STATO */
$(document).ready(function(){
rec_new();
});
</script>
</head>
<body>
<!--
QUI ANDREBBE INSERITA UNA LOAD DEI DATI DAL DATABASE PER REDERE
L'INTERFACCIA COERENTE CON LA BASE DI DATI
-->
<div id="pagecontainer">
<form action="" method="POST">
<h1> techr*c </h1>
<h2> <a href="tempo.php"> macchina del tempo</a> </h2>
<div id="buttonscontainer"> </div>
<div id="addnewrecarea"> </div>
</form>
</div>
<div id="footer">
techbl*c
</div>
</body>
</html>

BIN
client/registrazioni.sqlite Normal file

Binary file not shown.

111
client/style.css Normal file
View file

@ -0,0 +1,111 @@
body {
background-color:#F6F7BD;
}
h1 {
font-size:2em;
}
a{
color:#A60000;
text-decoration:none;
}
/* Contenitore pagina */
#pagecontainer {
max-width:50%;
margin:auto;
background-color:#F6F7BD;
background-image: url("7915.png") ;
background-repeat:no-repeat;
background-attachment:fixed;
background-position: 2% 35%;
background-size: 100px;
min-height: 700px;
}
/* Rec Container */
.recarea {
border-bottom:1px solid black;
padding:10px;
margin:10px;
text-align:center;
min-height:150px;
width:99%;
float:left;
}
.recarea input {
margin:0px 10px 0px 10px;
}
.buttonarea {
padding:10px;
margin:10px;
text-align:center;
min-height:150px;
width:45%;
float:left;
}
.recbutton {
width:100px;
height:100px;
font-size:1.2em;
font-weight:bold;
}
#addnewrecarea {
width:100%;
text-align:right;
font-weight:bold;
}
#addnewrecarea a{
color:#A60000;
}
/* FOOTER */
#footer {
text-align: center;
width:70%;
margin:auto;
margin-top:10px;
font-size:0.7em;
font-weight:bold;
color:#A60000;
border-top: 1px dashed #A60000;
}
#newrec .logarea {
min-width:200px;
min-height:100px;
border:1px solid black;
}
#newrec, #formsearchrec {
border-bottom:2px dashed #A60000;
margin:10px;
padding:20px;
width:70%;
text-align:center;
}
#newrec input[type=button],
#formsearchrec input[type=button] {
width:100px;
height:100px;
}
#newrec input[type=text],
#formsearchrec input[type=text] {
float:left;
width:225px;
}
.logarea {
width:45%;
float:left;
}

5
client/techrec/jquery-1.9.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,229 @@
#!/bin/bash
# TODO: mettere le vars in un file di configurazione con le funzioni
# Liquidsoap's archive
W_F_BASEDIR="/rec/ror/"
# file to handle
W_F_FIFODIR="/tmp/rorrec/"
W_F_LOGDIR="/var/log/techrec/"
function err {
echo -e $1
exit
}
function err2file {
echo -e "$1" >> "$2"
}
if test -z "`which ffmpeg`"; then
err "Install ffmpeg"
fi
if test -z "`which inotifywatch `"; then
err "Install ffmpeg"
fi
# ESEMPIO: /rec/ror/2012-11/14/rec-2012-11-14-10-00-00-ror.mp3
function get_basedir {
# $1 anno
# $2 mese
# $3 giorno
echo "${W_F_BASEDIR}/${1}-${2}/${3}/"
}
function get_filename {
# $1 anno
# $2 mese
# $3 giorno
# $4 ora
echo "`get_basedir ${1} ${2} ${3}`/rec-${1}-${2}-${3}-${4}-00-00-ror.mp3"
}
function mp3extractor {
echo "COMPUTE MP3extator with $1"
sleep 2 # support inotify latency ..
source $1
# s="$1"
# e="$2"
# outfile="$3"
# Create dir for filess
outdir="`dirname ${outfile}`"
mkdir -p ${outdir}/ &>/dev/null
chmod g+w -R ${outdir}
logfile="${outfile}.log"
echo "S: $s -- E: $e -- OUTFILE:${outfile} -- LOGFILE:${logfile}"
if test -z "${s}" -o -z "${e}" -o -z "${outfile}"; then
err "$0 <starttime> <endtime> <outfile>\n\t$0 2012-11-14-10-20 2012-11-14-12-12 file.mp3\n"
fi
sa=`date -d "${s}" +%Y`
sm=`date -d "${s}" +%m`
sg=`date -d "${s}" +%d`
so=`date -d "${s}" +%H`
si=`date -d "${s}" +%M`
s_u=`date -d "${s}" +%s`
ea=`date -d "${e}" +%Y`
em=`date -d "${e}" +%m`
eg=`date -d "${e}" +%d`
eo=`date -d "${e}" +%H`
ei=`date -d "${e}" +%M`
e_u=`date -d "${e}" +%s`
if test ${s_u} -gt ${e_u}; then
err2file "Start TIME >> END TIME" "${logfile}"
err "Start TIME >> END TIME"
fi
# echo "STARTTIME ${sa} ${sm} ${sg} ${so} ${si} ${s_u}"
# echo "ENDTIME ${ea} ${em} ${eg} ${eo} ${ei} ${e_u}"
# check starttime and endtime dir
sdir="`get_basedir ${sa} ${sm} ${sg}`"
edir="`get_basedir ${ea} ${em} ${eg}`"
test ! -d "${sdir}" && err "starttime dir (${sdir}) error"
test ! -d "${edir}" && err "endtime dir (${edir}) error"
sf=`get_filename ${sa} ${sm} ${sg} ${so}`
ef=`get_filename ${ea} ${em} ${eg} ${eo}`
duration_u=`expr ${e_u} - ${s_u}`
echo ""
echo -e "\tStart file ${sf}"
echo -e "\tEnd file ${ef}"
echo -e "\tDuration: ${duration_u} seconds"
if test ${duration_u} -ge `expr 120 \* 60`; then
err2file "MP3 richiesto > 2 ore..." "${logfile}"
err "$0 works only with two files!"
fi
# Se inizio == fine, mi basta un solo comando
if test "${sf}" = "${ef}" ; then
duration=`expr ${ei} - ${si}`
echo "INIZIO = FINE .. durata (${ei} - ${si}) ${duration}"
cmd="ffmpeg -i ${sf} -acodec copy -t 00:${duration}:00 -ss 00:${si}:00 ${outfile}"
echo "EXEC: ${cmd}"
${cmd}
ret=$?
echo "EXEC RET: $ret"
err2file "CMD: $cmd -- RET: $ret" "${logfile}"
[ $ret -ne 0 ] && err2file "ERRORE INIZIO=FINE" "${logfile}"
rm $1
exit
fi
intro="/tmp/intro-`basename "${outfile}"`.mp3" # Aggiungere casualita' per esecuzioni concorrenti
coda="/tmp/coda-`basename "${outfile}"`.mp3"
echo ""
echo "Compute intro.."
cmd="ffmpeg -i ${sf} -acodec copy -ss 00:${si}:00 -t 00:`expr 60 - ${si}`:00 ${intro}"
echo "EXEC: ${cmd}"
${cmd}
ret=$?
err2file "CMD: $cmd -- RET: $ret" "${logfile}"
[ $ret -ne 0 ] && err "ERRORE ESTRAZIONE INTRO"
echo "Compute end.."
cmd="ffmpeg -i ${ef} -acodec copy -ss 00:00:00 -t 00:${ei}:00 ${coda}"
echo "EXEC: ${cmd}"
${cmd}
ret=$?
err2file "CMD: $cmd -- RET: $ret" "${logfile}"
[ $ret -ne 0 ] && err "ERRORE ESTRAZIONE CODA"
# MERGE
ffmpeg -i concat:${intro}\|${coda} -acodec copy ${outfile}
ret=$?
err2file "CMD: $cmd -- RET: $ret" "${logfile}"
rm ${intro} ${coda}
[ $ret -ne 0 ] && err2file "ERRORE CONCAT" "${outfile}"
# DELETE FIFO FILES::::
rm $1
exit
}
#
#
# ::: MAIN :::
#
#
# TODO: GESTIRE IL PROBLEMA DEI PERMESSI
mkdir -p ${W_F_LOGDIR} ${W_F_FIFODIR} &> /dev/null
chown www-data -R ${W_F_LOGDIR} ${W_F_FIFODIR}
if test ! -d "${W_F_BASEDIR}"; then
err "No AUdio file dir (${W_F_BASEDIR})"
fi
s="$1"
e="$2"
outfile="$3"
# err "$0 <starttime> <endtime> <outfile>\n\t$0 2012-11-14-10-20 2012-11-14-12-12 file.mp3\n
if test ! -z "${s}" -a ! -z "${e}" -a ! -z "${outfile}" ; then
echo "direct call"
echo -e "s=\"${s}\"\ne=\"${e}\"\noutfile=\"${outfile}\"\n" > /tmp/tmpfile
mp3extractor /tmp/tmpfile
exit
fi
echo "No input parameter.. inotify mode"
echo "es: $0 \"2013/04/11 11:25\" \"2013/04/11 11:30\" outfile.mp3"
# esempio:
# mp3wrapper "2012/11/14 10:20" "2012/11/14 10:25"
while [ 1 = 1 ]; do
res=`inotifywait ${W_F_FIFODIR} 2> /dev/null`
echo ${res}
if test `echo ${res} | grep -c CREATE` -eq 0; then
echo "No relevant task - ${res}"
continue
fi
newfile=`echo ${res} | grep CREATE | sed -e 's/\ CREATE\ //g'`
echo "Newfile: ${newfile}"
mp3extractor "${newfile}" >> ${W_F_LOGDIR}/access.log &
done
exit

11
client/techrec/note Normal file
View file

@ -0,0 +1,11 @@
Decidere il formato del file (parametri, campi e valori di default in un
file PHP separato che viene incluso.. oppure in un file YAML...)
Aggiungere controlli funzioni
Visualizzazione
CONTROLLARE CEH GIA' ESISTE UNA REGISTRAZIONE
METTERE UN DB ?!??!?!?
LINK SCARICA

129
client/techrec/style.css Normal file
View file

@ -0,0 +1,129 @@
body {
/*background-color:#BF4D28;*/
background-color:#F6F7BD;
}
h1 {
font-size:1em;
}
/* Contenitore pagina */
.pagecontainer {
max-width:98%;
margin:auto;
background-color:#F6F7BD;
background-image: url("7915.png") ;
background-repeat:no-repeat;
background-attachment:fixed;
background-position: 2% 35%;
background-size: 100px;
min-height: 700px;
}
/* Area nuova registrazione */
.newrec {
width: 50%;
margin:auto;
margin-top:10px;
padding-top:10px;
text-align: center;
border:0px solid black;
}
/* Area registrazioni passate */
.resultcontainer {
width:80%;
margin:auto;
}
/* campo titolo */
.fieldtitle {
margin-top:30px;
float:left;
}
p {
margin:0px; padding:0px;
}
/* GESTIONE DEI MESSAGGI */
.info {
border:0px solid black;
max-width:70%;
margin:auto;
font-size: 0.9em;
font-weight: bolder;
padding:10px;
}
#footer {
text-align: center;
width:70%;
margin:auto;
margin-top:10px;
font-size:0.7em;
}
/* BUTTON STYLE */
input[type=text] {
border:1px solid black;
width:150px;
font-size:0.8em;
}
input[type=submit] {
margin:10px;
font-weight:bold;
border: 1px solid black;
min-width:20%;
border:1px solid black;
color: white; font-size: 1em;
background-color: #E6AC27;
}
input:disabled {
background-color:white;
color: #E6AC27;
text-decoration: line-through;
color: black;
}
.recdisabled {
background-color:#F2D694;
}
.startbutton {
min-height:80px;
}
/* END BUTTON STYLE */
table {
margin-top:10px;
padding-bottom:20px;
}
table td {
border-bottom:1px dashed black;
line-height:2em;
top:40%;
font-size: 0.8em;
text-align:center;
}
/* GESTIONE MESSAGGI */
.message {
background-color:#D0E799;
}
.error {
background-color:#F2D694;
}
a{
text-decoration: none;
color:black;
}

58
client/techrecapi.php Normal file
View file

@ -0,0 +1,58 @@
<?
include_once("function.php");
$op = $_GET['op'];
mymessage("<div>TechreAPI (ver ".VER."): OP=$op <div/>");
print "<br /> POST ";
print_r ($_POST);
print "<br /> GET ";
print_r($_GET);
switch ($op) {
case "install":
$db = connect();
rec_install();
disconnect($db);
break;
case "new":
$db = connect();
rec_new( $db, $_POST );
disconnect($db);
break;
case "del":
$db = connect();
rec_del( $db, $_GET['id'] );
disconnect($db);
break;
case "update":
$db = connect();
rec_update($db, $_POST );
disconnect($db);
break;
case "search":
$db = connect();
rec_get($db, $_GET );
disconnect($db);
break;
case "help":
help();
break;
default:
exit( -1 );
}
?>

112
client/tempo.php Normal file
View file

@ -0,0 +1,112 @@
<!DOCTYPE html>
<html>
<?php
include "utils.php";
?>
<head>
<title> TechREC :: macchina del tempo</title>
<script src="jquery-1.9.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<script>
// fetch record
function fetch_rec( outid ) {
var serializedData = $("#searchform").serialize();
var request = $.ajax({
url: "/techrecapi.php?op=getrec",
type: "post",
data: serializedData
});
// callback handler that will be called on success
request.done(function (response, textStatus, jqXHR){
// log a message to the console
console.log("Hooray, it worked!");
$("#"+outid).innerHTML = response;
});
// callback handler that will be called on failure
request.fail(function (jqXHR, textStatus, errorThrown){
// log the error to the console
console.error(
"The following error occured: "+
textStatus, errorThrown
);
alert("Errore acquisizione info");
});
request.always(function () {
// alert("Chiamato sempre");
});
}
$(document).ready(function(){
$("#trxnewbutton").click( function (){
console.log("start");
alert("start");
fetch_rec("resultcontainer");
alert("start");
});
$("#searchbutton").click ( function () {
alert("Click search-- load ajax");
});
});
</script>
</head>
<body>
<div id="pagecontainer">
<form action="" method="POST">
<h1> techr*c :: macchina del tempo </h1>
<h2> <a href="new.html"> Nuova registrazione</a> </h2>
<div id="newrec">
<form id="searchform" name="searchform" action="#" method=POST>
<input type="hidden" name="op" value="new">
<input type="text" id="trxname" name="trxname" placeholder="Nome Registrazione" />
<input type="text" id="starttime" name="starttime" placeholder="Inizio, es:2013/03/23 13:42:53" />
<input type="text" id="endtime" name="endtime" placeholder="Fine, es:2013/03/23 13:45:23" />
<input type="button" id="trxnewbutton" value="Crea" class="newrecbutton" />
</form>
</div>
<div id="formsearchrec">
<form action="" method="GET">
<input type="text" name="trxname" id="trxname" placeholder="Cerca una trasmissione" />
<input type="text" name="trxtime" id="trxtime" placeholder="Data, es:2013/03/23 13:45:23" />
<input type="button" name="searchbutton" id="searchbutton" value="Cerca" />
</form>
</div>
<div id="oldrec">
<table>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</div>
</form>
<div id="resultcontainer">
</div>
</div>
<div id="footer">
techbl*c
</div>
</body>
</html>

60
client/utils.php Normal file
View file

@ -0,0 +1,60 @@
<?php
# DEFAULT VALUES FOR FORMS
define("DEFAULT_TITLE", "Undefined");
define("DEFAULT_DESC", "");
define("DEFAULT_START", "");
define("DEFAULT_END", "");
define("VER", "0.1");
# SQLITE DB PARAMETER
define("DEFAULT_DBNAME", "registrazioni.sqlite");
# VARIABLES 2 DAEMON
define("FIFO_DIR", "/tmp/rorrec/");
define("AUDIO_DIR", getcwd()."/files/");
define("AUDIO_DIR_R", "./files/");
define("GUI_WEB_URI", "");
function mymessage($s) { myprint("message", $s); }
function myerror($s) { myprint("error", $s); }
function myprint($type, $s) {
print "<div class=\"info $type\"> ".
$s
."</div>";
}
function data2file($filename, $content)
{
if (! is_writable( dirname($filename) )) {
print "Non scrivibile (".dirname($filename).")<br>";
return FALSE;
}
if (!$handle = fopen($filename, 'w')) {
print "Cannot open file ($filename)<br>";
return FALSE;
}
if (fwrite($handle, $content) === FALSE) {
print "Cannot write to file ($filename)<br>";
return FALSE;
}
fclose($handle);
return TRUE;
}
function array2yamlfile( $r, $fname ) {
//TODO: Gestione errori
$sYAMLdata = yaml_emit ( $r );
echo "write to ".$fname;
$fp = fopen ( $fname, 'w' );
fwrite ( $fp, $sYAMLdata );
fclose ( $fp );
}
?>