Recordings: Database class integration.

This commit is contained in:
Nate
2019-08-12 07:32:23 -06:00
parent 96c1ff5edf
commit c1d1fa5f20
5 changed files with 240 additions and 203 deletions
+43 -25
View File
@@ -36,11 +36,12 @@
if (is_array($_SESSION['recordings']['storage_type']) && $_SESSION['recordings']['storage_type']['text'] == 'base64') { if (is_array($_SESSION['recordings']['storage_type']) && $_SESSION['recordings']['storage_type']['text'] == 'base64') {
//get recordings without base64 in db //get recordings without base64 in db
$sql = "select recording_uuid, domain_uuid, recording_filename "; $sql = "select recording_uuid, domain_uuid, recording_filename ";
$sql .= "from v_recordings where recording_base64 is null or recording_base64 = '' "; $sql .= "from v_recordings ";
$prep_statement = $db->prepare(check_sql($sql)); $sql .= "where recording_base64 is null ";
$prep_statement->execute(); $sql .= "or recording_base64 = '' ";
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $database = new database;
if (is_array($result)) { $result = $database->select($sql, null, 'all');
if (is_array($result) && @sizeof($result) != 0) {
foreach ($result as &$row) { foreach ($result as &$row) {
$recording_uuid = $row['recording_uuid']; $recording_uuid = $row['recording_uuid'];
$recording_domain_uuid = $row['domain_uuid']; $recording_domain_uuid = $row['domain_uuid'];
@@ -49,30 +50,38 @@
$recording_directory = $_SESSION['switch']['recordings']['dir'].'/'.$domain_name; $recording_directory = $_SESSION['switch']['recordings']['dir'].'/'.$domain_name;
//encode recording file (if exists) //encode recording file (if exists)
if (file_exists($recording_directory.'/'.$recording_filename)) { if (file_exists($recording_directory.'/'.$recording_filename)) {
$recording_base64 = base64_encode(file_get_contents($recording_directory.'/'.$recording_filename)); //build array
$recording_base64 = base64_encode(file_get_contents($recording_directory.'/'.$recording_filename));
$array['recordings'][0]['recording_uuid'] = $recording_uuid;
$array['recordings'][0]['domain_uuid'] = $recording_domain_uuid;
$array['recordings'][0]['recording_base64'] = $recording_base64;
//grant temporary permissions
$p = new permissions;
$p->add('recording_edit', 'temp');
//update recording record with base64 //update recording record with base64
$sql = "update v_recordings set "; $database = new database;
$sql .= "recording_base64 = '".$recording_base64."' "; $database->app_name = 'recordings';
$sql .= "where domain_uuid = '".$recording_domain_uuid."' "; $database->app_uuid = '83913217-c7a2-9e90-925d-a866eb40b60e';
$sql .= "and recording_uuid = '".$recording_uuid."' "; $database->save($array);
$db->exec(check_sql($sql)); unset($array);
unset($sql); //revoke temporary permissions
$p->delete('recording_edit', 'temp');
//remove local recording file //remove local recording file
@unlink($recording_directory.'/'.$recording_filename); @unlink($recording_directory.'/'.$recording_filename);
} }
} }
} }
unset($sql, $prep_statement, $result, $row); unset($sql, $result, $row);
} }
//if not base64, decode to local files, remove base64 data from db //if not base64, decode to local files, remove base64 data from db
else if (is_array($_SESSION['recordings']['storage_type']) && $_SESSION['recordings']['storage_type']['text'] != 'base64') { else if (is_array($_SESSION['recordings']['storage_type']) && $_SESSION['recordings']['storage_type']['text'] != 'base64') {
//get recordings with base64 in db //get recordings with base64 in db
$sql = "select recording_uuid, domain_uuid, recording_filename, recording_base64 "; $sql = "select recording_uuid, domain_uuid, recording_filename, recording_base64 ";
$sql .= "from v_recordings where recording_base64 is not null "; $sql .= "from v_recordings ";
$prep_statement = $db->prepare(check_sql($sql)); $sql .= "where recording_base64 is not null ";
$prep_statement->execute(); $database = new database;
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $result = $database->select($sql, null, 'all');
if (count($result) > 0) { if (is_array($result) && @sizeof($result) != 0) {
foreach ($result as &$row) { foreach ($result as &$row) {
$recording_uuid = $row['recording_uuid']; $recording_uuid = $row['recording_uuid'];
$recording_domain_uuid = $row['domain_uuid']; $recording_domain_uuid = $row['domain_uuid'];
@@ -87,15 +96,24 @@
//decode base64, save to local file //decode base64, save to local file
$recording_decoded = base64_decode($recording_base64); $recording_decoded = base64_decode($recording_base64);
file_put_contents($recording_directory.'/'.$recording_filename, $recording_decoded); file_put_contents($recording_directory.'/'.$recording_filename, $recording_decoded);
$sql = "update v_recordings "; //build array
$sql .= "set recording_base64 = null "; $array['recordings'][0]['recording_uuid'] = $recording_uuid;
$sql .= "where domain_uuid = '".$recording_domain_uuid."' "; $array['recordings'][0]['domain_uuid'] = $recording_domain_uuid;
$sql .= "and recording_uuid = '".$recording_uuid."' "; $array['recordings'][0]['recording_base64'] = null;
$db->exec(check_sql($sql)); //grant temporary permissions
unset($sql); $p = new permissions;
$p->add('recording_edit', 'temp');
//update recording record
$database = new database;
$database->app_name = 'recordings';
$database->app_uuid = '83913217-c7a2-9e90-925d-a866eb40b60e';
$database->save($array);
unset($array);
//revoke temporary permissions
$p->delete('recording_edit', 'temp');
} }
} }
unset($sql, $prep_statement, $result, $row); unset($sql, $result, $row);
} }
} }
+24 -23
View File
@@ -39,40 +39,41 @@ else {
$text = $language->get(); $text = $language->get();
//get the id //get the id
if (count($_GET) > 0) { $recording_uuid = $_GET["id"];
$id = $_GET["id"];
}
if (strlen($id)>0) { if (is_uuid($recording_uuid)) {
//get filename //get filename
$sql = "select * from v_recordings "; $sql = "select recording_filename from v_recordings ";
$sql .= "where recording_uuid = '$id' "; $sql .= "where recording_uuid = :recording_uuid ";
$sql .= "and domain_uuid = '$domain_uuid' "; $sql .= "and domain_uuid = :domain_uuid ";
$prep_statement = $db->prepare(check_sql($sql)); $parameters['recording_uuid'] = $recording_uuid;
$prep_statement->execute(); $parameters['domain_uuid'] = $domain_uuid;
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $database = new database;
foreach ($result as &$row) { $filename = $database->select($sql, $parameters, 'column');
$filename = $row["recording_filename"]; unset($prep_statement);
break; //limit to 1 row
} //build array
unset ($prep_statement); $array['recordings'][0]['recording_uuid'] = $recording_uuid;
$array['recordings'][0]['domain_uuid'] = $domain_uuid;
//delete recording from the database //delete recording from the database
$sql = "delete from v_recordings "; $database = new database;
$sql .= "where recording_uuid = '$id' "; $database->app_name = 'recordings';
$sql .= "and domain_uuid = '$domain_uuid' "; $database->app_uuid = '83913217-c7a2-9e90-925d-a866eb40b60e';
$prep_statement = $db->prepare(check_sql($sql)); $database->delete($array);
$prep_statement->execute(); unset($array);
unset($sql);
//delete the recording //delete the recording
if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$filename)) { if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$filename)) {
@unlink($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$filename); @unlink($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$filename);
} }
//set message
message::add($text['message-delete']);
} }
//redirect the user //redirect the user
message::add($text['message-delete']);
header("Location: recordings.php"); header("Location: recordings.php");
return; exit;
?> ?>
+37 -31
View File
@@ -40,16 +40,16 @@ else {
$text = $language->get(); $text = $language->get();
//get recording id //get recording id
if (isset($_REQUEST["id"])) { if (is_uuid($_REQUEST["id"])) {
$recording_uuid = check_str($_REQUEST["id"]); $recording_uuid = $_REQUEST["id"];
} }
//get the form value and set to php variables //get the form value and set to php variables
if (count($_POST) > 0) { if (count($_POST) > 0) {
$recording_filename = check_str($_POST["recording_filename"]); $recording_filename = $_POST["recording_filename"];
$recording_filename_original = check_str($_POST["recording_filename_original"]); $recording_filename_original = $_POST["recording_filename_original"];
$recording_name = check_str($_POST["recording_name"]); $recording_name = $_POST["recording_name"];
$recording_description = check_str($_POST["recording_description"]); $recording_description = $_POST["recording_description"];
//clean the recording filename and name //clean the recording filename and name
$recording_filename = str_replace(" ", "_", $recording_filename); $recording_filename = str_replace(" ", "_", $recording_filename);
@@ -59,7 +59,7 @@ else {
if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
//get recording uuid to edit //get recording uuid to edit
$recording_uuid = check_str($_POST["recording_uuid"]); $recording_uuid = $_POST["recording_uuid"];
//check for all required data //check for all required data
$msg = ''; $msg = '';
@@ -86,40 +86,46 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
rename($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename_original, $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename); rename($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename_original, $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename);
} }
//update the database with the new data //build array
$sql = "update v_recordings set "; $array['recordings'][0]['domain_uuid'] = $domain_uuid;
$sql .= "domain_uuid = '".$domain_uuid."', "; $array['recordings'][0]['recording_filename'] = $recording_filename;
$sql .= "recording_filename = '".$recording_filename."', "; $array['recordings'][0]['recording_name'] = $recording_name;
$sql .= "recording_name = '".$recording_name."', "; $array['recordings'][0]['recording_description'] = $recording_description;
$sql .= "recording_description = '".$recording_description."' "; $array['recordings'][0]['domain_uuid'] = $domain_uuid;
$sql .= "where domain_uuid = '".$domain_uuid."'"; $array['recordings'][0]['recording_uuid'] = $recording_uuid;
$sql .= "and recording_uuid = '".$recording_uuid."'";
$db->exec(check_sql($sql));
unset($sql);
message::add($text['message-update']); //execute update
header("Location: recordings.php"); $database = new database;
return; $database->app_name = 'recordings';
} //if (permission_exists('recording_edit')) { $database->app_uuid = '83913217-c7a2-9e90-925d-a866eb40b60e';
} //if ($_POST["persistformvar"] != "true") $database->save($array);
} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) unset($array);
// set message
message::add($text['message-update']);
//redirect
header("Location: recordings.php");
exit;
}
}
}
//pre-populate the form //pre-populate the form
if (count($_GET)>0 && $_POST["persistformvar"] != "true") { if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
$recording_uuid = $_GET["id"]; $recording_uuid = $_GET["id"];
$sql = "select * from v_recordings "; $sql = "select * from v_recordings ";
$sql .= "where domain_uuid = '".$domain_uuid."' "; $sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and recording_uuid = '".$recording_uuid."' "; $sql .= "and recording_uuid = :recording_uuid ";
$prep_statement = $db->prepare(check_sql($sql)); $parameters['domain_uuid'] = $domain_uuid;
$prep_statement->execute(); $parameters['recording_uuid'] = $recording_uuid;
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $database = new database;
foreach ($result as &$row) { $row = $database->select($sql, $parameters, 'row');
if (is_array($row) && @sizeof($row) != 0) {
$recording_filename = $row["recording_filename"]; $recording_filename = $row["recording_filename"];
$recording_name = $row["recording_name"]; $recording_name = $row["recording_name"];
$recording_description = $row["recording_description"]; $recording_description = $row["recording_description"];
break; //limit to 1 row
} }
unset ($prep_statement); unset($sql, $parameters, $row);
} }
//show the header //show the header
+5 -5
View File
@@ -65,16 +65,16 @@
if ($file_ext == "wav") { if ($file_ext == "wav") {
//HTML5 method //HTML5 method
if ($browser_name == "Google Chrome" || $browser_name == "Mozilla Firefox") { if ($browser_name == "Google Chrome" || $browser_name == "Mozilla Firefox") {
echo "<audio src=\"recordings.php?a=download&type=".$type."&filename=".base64_encode($filename)."\" autoplay=\"true\" ></audio>"; echo "<audio src=\"recordings.php?a=download&type=".escape($type)."&filename=".base64_encode($filename)."\" autoplay=\"true\" ></audio>";
} }
else { else {
echo "<audio src=\"http://localhost:8000/mod/recordings/recordings.php?a=download&type=".$type."&filename=".base64_encode($filename)."\" autoplay=\"autoplay\"></audio>"; echo "<audio src=\"http://localhost:8000/mod/recordings/recordings.php?a=download&type=".escape($type)."&filename=".base64_encode($filename)."\" autoplay=\"autoplay\"></audio>";
echo "<embed src=\"recordings.php?a=download&type=".$type."&filename=".base64_encode($filename)."\" autostart=\"true\" width=\"300\" height=\"90\" name=\"sound_".$filename."\" enablejavascript=\"true\">\n"; echo "<embed src=\"recordings.php?a=download&type=".escape($type)."&filename=".base64_encode($filename)."\" autostart=\"true\" width=\"300\" height=\"90\" name=\"sound_".$filename."\" enablejavascript=\"true\">\n";
} }
} }
if ($file_ext == "mp3") { if ($file_ext == "mp3") {
echo "<object type=\"application/x-shockwave-flash\" width=\"400\" height=\"17\" data=\"slim.swf?autoplay=true&song_title=".urlencode($filename)."&song_url=recordings.php?a=download&type=".$type."&filename=".base64_encode($filename)."\">\n"; echo "<object type=\"application/x-shockwave-flash\" width=\"400\" height=\"17\" data=\"slim.swf?autoplay=true&song_title=".urlencode($filename)."&song_url=recordings.php?a=download&type=".escape($type)."&filename=".base64_encode($filename)."\">\n";
echo "<param name=\"movie\" value=\"slim.swf?autoplay=true&song_url=recordings.php?a=download&type=".$type."&filename=".base64_encode($filename)."\" />\n"; echo "<param name=\"movie\" value=\"slim.swf?autoplay=true&song_url=recordings.php?a=download&type=".escape($type)."&filename=".base64_encode($filename)."\" />\n";
echo "<param name=\"quality\" value=\"high\"/>\n"; echo "<param name=\"quality\" value=\"high\"/>\n";
echo "<param name=\"bgcolor\" value=\"#E6E6E6\"/>\n"; echo "<param name=\"bgcolor\" value=\"#E6E6E6\"/>\n";
echo "</object>\n"; echo "</object>\n";
+129 -117
View File
@@ -55,32 +55,32 @@
$path = $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']; $path = $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name'];
//if from recordings, get recording details from db //if from recordings, get recording details from db
$recording_uuid = check_str($_GET['id']); //recordings $recording_uuid = $_GET['id']; //recordings
if ($recording_uuid != '') { if ($recording_uuid != '') {
$sql = "select recording_filename, recording_base64 from v_recordings "; $sql = "select recording_filename, recording_base64 ";
$sql .= "where domain_uuid = '".$domain_uuid."' "; $sql .= "from v_recordings ";
$sql .= "and recording_uuid = '".$recording_uuid."' "; $sql .= "where domain_uuid = :domain_uuid ";
$prep_statement = $db->prepare(check_sql($sql)); $sql .= "and recording_uuid = :recording_uuid ";
$prep_statement->execute(); $parameters['domain_uuid'] = $domain_uuid;
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); $parameters['recording_uuid'] = $recording_uuid;
if (count($result) > 0) { $database = new database;
foreach($result as &$row) { $row = $database->select($sql, $parameters, 'row');
$recording_filename = $row['recording_filename']; if (is_array($row) && @sizeof($row) != 0) {
if ($_SESSION['recordings']['storage_type']['text'] == 'base64' && $row['recording_base64'] != '') { $recording_filename = $row['recording_filename'];
$recording_decoded = base64_decode($row['recording_base64']); if ($_SESSION['recordings']['storage_type']['text'] == 'base64' && $row['recording_base64'] != '') {
file_put_contents($path.'/'.$recording_filename, $recording_decoded); $recording_decoded = base64_decode($row['recording_base64']);
} file_put_contents($path.'/'.$recording_filename, $recording_decoded);
break;
} }
} }
unset ($sql, $prep_statement, $result, $recording_decoded); unset($sql, $parameters, $row, $recording_decoded);
} }
// build full path // build full path
if(substr($recording_filename,0,1) == '/'){ if (substr($recording_filename,0,1) == '/'){
$full_recording_path = $path . $recording_filename; $full_recording_path = $path.$recording_filename;
} else { }
$full_recording_path = $path . '/' . $recording_filename; else {
$full_recording_path = $path.'/'.$recording_filename;
} }
//send the headers and then the data stream //send the headers and then the data stream
@@ -109,7 +109,7 @@
header('Content-Disposition: attachment; filename="'.$recording_filename.'"'); header('Content-Disposition: attachment; filename="'.$recording_filename.'"');
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
// header("Content-Length: " . filesize($full_recording_path)); // header("Content-Length: ".filesize($full_recording_path));
ob_clean(); ob_clean();
fpassthru($fd); fpassthru($fd);
} }
@@ -123,29 +123,32 @@
} }
//upload the recording //upload the recording
if (permission_exists('recording_upload')) { if (
if ($_POST['submit'] == $text['button-upload'] && $_POST['type'] == 'rec' && is_uploaded_file($_FILES['ulfile']['tmp_name'])) { permission_exists('recording_upload')
&& $_POST['submit'] == $text['button-upload']
&& $_POST['type'] == 'rec'
&& is_uploaded_file($_FILES['ulfile']['tmp_name'])
) {
//remove special characters //remove special characters
$recording_filename = str_replace(" ", "_", $_FILES['ulfile']['name']); $recording_filename = str_replace(" ", "_", $_FILES['ulfile']['name']);
$recording_filename = str_replace("'", "", $recording_filename); $recording_filename = str_replace("'", "", $recording_filename);
//make sure the destination directory exists //make sure the destination directory exists
if (!is_dir($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'])) { if (!is_dir($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'])) {
event_socket_mkdir($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name']); event_socket_mkdir($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name']);
} }
//move the uploaded files //move the uploaded files
move_uploaded_file($_FILES['ulfile']['tmp_name'], $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename); move_uploaded_file($_FILES['ulfile']['tmp_name'], $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename);
//set the message //set the message
message::add($text['message-uploaded'].": ".htmlentities($recording_filename)); message::add($text['message-uploaded'].": ".htmlentities($recording_filename));
//set the file name to be inserted as the recording description //set the file name to be inserted as the recording description
$recording_description = base64_encode($_FILES['ulfile']['name']); $recording_description = base64_encode($_FILES['ulfile']['name']);
header("Location: recordings.php?rd=".$recording_description); header("Location: recordings.php?rd=".$recording_description);
exit; exit;
}
} }
//check the permission //check the permission
@@ -158,26 +161,41 @@
} }
//get existing recordings //get existing recordings
$sql = "select recording_uuid, recording_filename, recording_base64 from v_recordings "; $sql = "select recording_uuid, recording_filename, recording_base64 ";
$sql .= "where domain_uuid = '".$domain_uuid."' "; $sql .= "from v_recordings ";
$prep_statement = $db->prepare(check_sql($sql)); $sql .= "where domain_uuid = :domain_uuid ";
$prep_statement->execute(); $parameters['domain_uuid'] = $domain_uuid;
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $database = new database;
foreach ($result as &$row) { $result = $database->select($sql, $parameters, 'all');
$array_recordings[$row['recording_uuid']] = $row['recording_filename']; if (is_array($result) && @sizeof($result) != 0) {
$array_base64_exists[$row['recording_uuid']] = ($row['recording_base64'] != '') ? true : false; foreach ($result as &$row) {
//if not base64, convert back to local files and remove base64 from db $array_recordings[$row['recording_uuid']] = $row['recording_filename'];
if ($_SESSION['recordings']['storage_type']['text'] != 'base64' && $row['recording_base64'] != '') { $array_base64_exists[$row['recording_uuid']] = ($row['recording_base64'] != '') ? true : false;
if (!file_exists($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$row['recording_filename'])) { //if not base64, convert back to local files and remove base64 from db
$recording_decoded = base64_decode($row['recording_base64']); if ($_SESSION['recordings']['storage_type']['text'] != 'base64' && $row['recording_base64'] != '') {
file_put_contents($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$row['recording_filename'], $recording_decoded); if (!file_exists($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$row['recording_filename'])) {
$sql = "update v_recordings set recording_base64 = null where domain_uuid = '".$domain_uuid."' and recording_uuid = '".$row['recording_uuid']."' "; $recording_decoded = base64_decode($row['recording_base64']);
$db->exec(check_sql($sql)); file_put_contents($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$row['recording_filename'], $recording_decoded);
unset($sql); //build array
$array['recordings'][0]['recording_uuid'] = $row['recording_uuid'];
$array['recordings'][0]['domain_uuid'] = $domain_uuid;
$array['recordings'][0]['recording_base64'] = null;
//set temporary permissions
$p = new permissions;
$p->add('recording_edit', 'temp');
//execute update
$database = new database;
$database->app_name = 'recordings';
$database->app_uuid = '83913217-c7a2-9e90-925d-a866eb40b60e';
$database->save($array);
unset($array);
//remove temporary permissions
$p->delete('recording_edit', 'temp');
}
} }
} }
} }
unset ($prep_statement); unset($sql, $parameters, $result, $row);
//add recordings to the database //add recordings to the database
if (is_dir($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/')) { if (is_dir($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/')) {
@@ -187,34 +205,30 @@
if (!in_array($recording_filename, $array_recordings)) { if (!in_array($recording_filename, $array_recordings)) {
//file not found in db, add it //file not found in db, add it
$recording_uuid = uuid(); $recording_uuid = uuid();
$recording_name = ucwords(str_replace('_', ' ', pathinfo($recording_filename, PATHINFO_FILENAME))); $recording_name = ucwords(str_replace('_', ' ', pathinfo($recording_filename, PATHINFO_FILENAME)));
$recording_description = check_str(base64_decode($_GET['rd'])); $recording_description = base64_decode($_GET['rd']);
$sql = "insert into v_recordings "; //build array
$sql .= "("; $array['recordings'][0]['domain_uuid'] = $domain_uuid;
$sql .= "domain_uuid, "; $array['recordings'][0]['recording_uuid'] = $recording_uuid;
$sql .= "recording_uuid, "; $array['recordings'][0]['recording_filename'] = $recording_filename;
$sql .= "recording_filename, "; $array['recordings'][0]['recording_name'] = $recording_name;
$sql .= "recording_name, "; $array['recordings'][0]['recording_description'] = $recording_description;
$sql .= "recording_description "; if ($_SESSION['recordings']['storage_type']['text'] == 'base64') {
if ($_SESSION['recordings']['storage_type']['text'] == 'base64') { $recording_base64 = base64_encode(file_get_contents($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename));
$sql .= ", recording_base64 "; $array['recordings'][0]['recording_base64'] = $recording_base64;
} }
$sql .= ")"; //set temporary permissions
$sql .= "values "; $p = new permissions;
$sql .= "("; $p->add('recording_add', 'temp');
$sql .= "'".$domain_uuid."', "; //execute insert
$sql .= "'".$recording_uuid."', "; $database = new database;
$sql .= "'".$recording_filename."', "; $database->app_name = 'recordings';
$sql .= "'".$recording_name."', "; $database->app_uuid = '83913217-c7a2-9e90-925d-a866eb40b60e';
$sql .= "'".$recording_description."' "; $database->save($array);
if ($_SESSION['recordings']['storage_type']['text'] == 'base64') { unset($array);
$recording_base64 = base64_encode(file_get_contents($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename)); //remove temporary permissions
$sql .= ", '".$recording_base64."' "; $p->delete('recording_add', 'temp');
}
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
} }
else { else {
//file found in db, check if base64 present //file found in db, check if base64 present
@@ -222,12 +236,21 @@
$found_recording_uuid = array_search($recording_filename, $array_recordings); $found_recording_uuid = array_search($recording_filename, $array_recordings);
if (!$array_base64_exists[$found_recording_uuid]) { if (!$array_base64_exists[$found_recording_uuid]) {
$recording_base64 = base64_encode(file_get_contents($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename)); $recording_base64 = base64_encode(file_get_contents($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename));
$sql = "update v_recordings set "; //build array
$sql .= "recording_base64 = '".$recording_base64."' "; $array['recordings'][0]['domain_uuid'] = $domain_uuid;
$sql .= "where domain_uuid = '".$domain_uuid."' "; $array['recordings'][0]['recording_uuid'] = $found_recording_uuid;
$sql .= "and recording_uuid = '".$found_recording_uuid."' "; $array['recordings'][0]['recording_base64'] = $recording_base64;
$db->exec(check_sql($sql)); //set temporary permissions
unset($sql); $p = new permissions;
$p->add('recording_edit', 'temp');
//execute update
$database = new database;
$database->app_name = 'recordings';
$database->app_uuid = '83913217-c7a2-9e90-925d-a866eb40b60e';
$database->save($array);
unset($array);
//remove temporary permissions
$p->delete('recording_edit', 'temp');
} }
} }
} }
@@ -247,15 +270,11 @@
require_once "resources/paging.php"; require_once "resources/paging.php";
//get total recordings from the database //get total recordings from the database
$sql = "select count(recording_uuid) as num_rows from v_recordings \n"; $sql = "select count(*) from v_recordings ";
$sql = "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "where domain_uuid = :domain_uuid ";
$prep_statement = $db->prepare($sql); $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
if ($prep_statement) { $database = new database;
$prep_statement->execute(); $num_rows = $database->select($sql, $parameters, 'column');
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
$num_rows = $row['num_rows'];
}
unset($prep_statement, $row);
//prepare to page the results //prepare to page the results
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
@@ -266,14 +285,12 @@
$offset = $rows_per_page * $page; $offset = $rows_per_page * $page;
//get the recordings from the database //get the recordings from the database
$sql = "select recording_uuid, domain_uuid, recording_filename, recording_name, recording_description from v_recordings "; $sql = str_replace('count(*)', 'recording_uuid, domain_uuid, recording_filename, recording_name, recording_description', $sql);
$sql .= "where domain_uuid = '".$domain_uuid."' "; $sql .= order_by($order_by, $order);
$sql .= "order by ".$order_by." ".$order." "; $sql .= limit_offset($rows_per_page, $offset);
$sql .= "limit ".$rows_per_page." offset ".$offset." "; $database = new database;
$prep_statement = $db->prepare(check_sql($sql)); $recordings = $database->select($sql, $parameters, 'all');
$prep_statement->execute(); unset($sql, $parameters);
$recordings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
unset ($prep_statement, $sql);
//set alternate row styles //set alternate row styles
$c = 0; $c = 0;
@@ -319,11 +336,11 @@
echo "</tr>\n"; echo "</tr>\n";
//calculate colspan for progress bar //calculate colspan for progress bar
$colspan = 5; //max $colspan = 6; //max
if ($_SESSION['recordings']['storage_type']['text'] == 'base64') { $colspan = $colspan - 2; } if ($_SESSION['recordings']['storage_type']['text'] == 'base64') { $colspan = $colspan - 2; }
if (!(permission_exists('recording_edit') || permission_exists('recording_delete'))) { $colspan = $colspan - 1; } if (!(permission_exists('recording_edit') || permission_exists('recording_delete'))) { $colspan = $colspan - 1; }
if (is_array($recordings)) { if (is_array($recordings) && @sizeof($recordings) != 0) {
foreach($recordings as $row) { foreach($recordings as $row) {
//playback progress bar //playback progress bar
if (permission_exists('recording_play')) { if (permission_exists('recording_play')) {
@@ -381,9 +398,9 @@
echo "</tr>\n"; echo "</tr>\n";
$c = ($c) ? 0 : 1; $c = ($c) ? 0 : 1;
} //end foreach }
unset($sql, $result, $row_count); }
} //end if results unset($recordings, $row);
echo "</table>\n"; echo "</table>\n";
echo "<br />\n"; echo "<br />\n";
@@ -395,7 +412,6 @@
function range_download($file) { function range_download($file) {
$fp = @fopen($file, 'rb'); $fp = @fopen($file, 'rb');
$size = filesize($file); // File size $size = filesize($file); // File size
@@ -426,7 +442,6 @@ function range_download($file) {
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2); list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
// Make sure the client hasn't sent us a multibyte range // Make sure the client hasn't sent us a multibyte range
if (strpos($range, ',') !== false) { if (strpos($range, ',') !== false) {
// (?) Shoud this be issued here, or should the first // (?) Shoud this be issued here, or should the first
// range be used? Or should the header be ignored and // range be used? Or should the header be ignored and
// we output the whole content? // we output the whole content?
@@ -439,12 +454,10 @@ function range_download($file) {
// If not, we forward the file pointer // If not, we forward the file pointer
// And make sure to get the end byte if spesified // And make sure to get the end byte if spesified
if ($range0 == '-') { if ($range0 == '-') {
// The n-number of the last bytes is requested // The n-number of the last bytes is requested
$c_start = $size - substr($range, 1); $c_start = $size - substr($range, 1);
} }
else { else {
$range = explode('-', $range); $range = explode('-', $range);
$c_start = $range[0]; $c_start = $range[0];
$c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size; $c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
@@ -488,7 +501,6 @@ function range_download($file) {
} }
fclose($fp); fclose($fp);
} }
?> ?>