diff --git a/app/recordings/recordings.php b/app/recordings/recordings.php index 086f072f62..630e326a3e 100644 --- a/app/recordings/recordings.php +++ b/app/recordings/recordings.php @@ -25,29 +25,20 @@ James Rose */ +//set the max php execution time + ini_set('max_execution_time', 7200); + //includes include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; + require_once "resources/paging.php"; //add multi-lingual support $language = new text; $text = $language->get(); -//set the max php execution time - ini_set('max_execution_time',7200); - -//get the http get values and set them as php variables - $order_by = $_GET["order_by"]; - $order = $_GET["order"]; - -//set the default order - if ($order_by == '') { - $order_by = "recording_name"; - $order = "asc"; - } - -//download the recordings +//download the recording if ($_GET['a'] == "download" && (permission_exists('recording_play') || permission_exists('recording_download'))) { session_cache_limiter('public'); if ($_GET['type'] = "rec") { @@ -89,7 +80,7 @@ if (isset($_SERVER['HTTP_RANGE'])) { range_download($full_recording_path); } - + $fd = fopen($full_recording_path, "rb"); if ($_GET['t'] == "bin") { header("Content-Type: application/force-download"); @@ -124,8 +115,8 @@ //upload the recording if ( - permission_exists('recording_upload') - && $_POST['submit'] == $text['button-upload'] + $_POST['a'] == "upload" + && permission_exists('recording_upload') && $_POST['type'] == 'rec' && is_uploaded_file($_FILES['ulfile']['tmp_name']) ) { @@ -203,7 +194,7 @@ while (($recording_filename = readdir($dh)) !== false) { if (filetype($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$recording_filename) == "file") { - if (!in_array($recording_filename, $array_recordings)) { + if (!is_array($array_recordings) || !in_array($recording_filename, $array_recordings)) { //file not found in db, add it $recording_uuid = uuid(); $recording_name = ucwords(str_replace('_', ' ', pathinfo($recording_filename, PATHINFO_FILENAME))); @@ -261,27 +252,60 @@ } } - } //while + } closedir($dh); - } //if - } //if + } + } -//add paging - require_once "resources/paging.php"; +//get posted data + if (is_array($_POST['recordings'])) { + $action = $_POST['action']; + $search = $_POST['search']; + $recordings = $_POST['recordings']; + } + +//delete the recordings + if (permission_exists('recording_delete')) { + if ($action == 'delete' && is_array($recordings) && @sizeof($recordings) != 0) { + //delete + $obj = new switch_recordings; + $obj->delete($recordings); + //redirect + header('Location: recordings.php'.($search != '' ? '?search='.urlencode($search) : null)); + exit; + } + } + +//get order and order by + $order_by = $_GET["order_by"]; + $order = $_GET["order"]; + +//add the search term + $search = strtolower($_GET["search"]); + if (strlen($search) > 0) { + $sql_search = "and ("; + $sql_search .= "lower(recording_name) like :search "; + $sql_search .= "or lower(recording_filename) like :search "; + $sql_search .= "or lower(recording_description) like :search "; + $sql_search .= ") "; + $parameters['search'] = '%'.$search.'%'; + } //get total recordings from the database $sql = "select count(*) from v_recordings "; $sql .= "where domain_uuid = :domain_uuid "; + $sql .= $sql_search; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $database = new database; $num_rows = $database->select($sql, $parameters, 'column'); //prepare to page the results $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; - $param = "&order_by=".urlencode($order_by)."&order=".urlencode($order); - $page = $_GET['page']; - if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } - list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page); + $param = "&search=".$search; + $param .= "&order_by=".$order_by."&order=".$order; + $page = is_numeric($_GET['page']) ? $_GET['page'] : 0; + list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page); + list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true); $offset = $rows_per_page * $page; //get the recordings from the database @@ -292,72 +316,122 @@ } } $sql = str_replace('count(*)', 'recording_uuid, domain_uuid, recording_filename, '.$sql_file_size.' recording_name, recording_description', $sql); - $sql .= order_by($order_by, $order); + $sql .= order_by($order_by, $order, 'recording_name', 'asc'); $sql .= limit_offset($rows_per_page, $offset); $database = new database; $recordings = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); -//set alternate row styles - $c = 0; - $row_style["0"] = "row_style0"; - $row_style["1"] = "row_style1"; +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); //include the header $document['title'] = $text['title-recordings']; require_once "resources/header.php"; -//begin the content +//show the content + echo "
\n"; + echo "
".$text['title-recordings']." (".$num_rows.")
\n"; + echo "
\n"; if (permission_exists('recording_upload')) { - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
"; - echo "
"; + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','onclick'=>"$(this).fadeOut(250, function(){ $('span#form_upload').fadeIn(250); document.getElementById('ulfile').click(); });"]); + echo "\n"; + echo "
"; } - echo "".$text['title-recordings'].""; - echo "

\n"; + if (permission_exists('recording_delete') && $recordings) { + echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'onclick'=>"if (confirm('".$text['confirm-delete']."')) { list_action_set('delete'); list_form_submit('form_list'); } else { this.blur(); return false; }"]); + } + echo "\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo $text['description']."\n"; echo "

\n"; - echo "\n"; - echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; + echo "\n"; + $col_count = 0; + if (permission_exists('recording_delete')) { + echo " \n"; + $col_count++; + } echo th_order_by('recording_name', $text['label-recording_name'], $order_by, $order); + $col_count++; + if ($_SESSION['recordings']['storage_type']['text'] != 'base64') { + echo th_order_by('recording_filename', $text['label-file_name'], $order_by, $order, null, "class='hide-md-dn'"); + $col_count++; + } if (permission_exists('recording_play') || permission_exists('recording_download')) { - echo "\n"; + echo "\n"; + $col_count++; } + echo "\n"; + $col_count++; if ($_SESSION['recordings']['storage_type']['text'] != 'base64') { - echo th_order_by('recording_filename', $text['label-file_name'], $order_by, $order); + echo "\n"; + $col_count++; } - echo "\n"; - if ($_SESSION['recordings']['storage_type']['text'] != 'base64') { - echo "\n"; + echo th_order_by('recording_description', $text['label-description'], $order_by, $order, null, "class='hide-sm-dn' style='min-width: 30%;'"); + if (permission_exists('recording_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + echo " \n"; } - echo th_order_by('recording_description', $text['label-description'], $order_by, $order); - echo "\n"; echo "\n"; - //calculate colspan for progress bar - $colspan = 4; //min - if ($_SESSION['recordings']['storage_type']['text'] != 'base64') { $colspan += 2; } - if (is_array($recordings) && @sizeof($recordings) != 0) { + $x = 0; foreach($recordings as $row) { //playback progress bar - if (permission_exists('recording_play')) { - echo "\n"; + if (permission_exists('recording_play')) { + echo "\n"; + echo "\n"; // dummy row to maintain alternating background color + } + if (permission_exists('recording_edit')) { + $list_row_url = "recording_edit.php?id=".urlencode($row['recording_uuid']); + } + echo "\n"; + if (permission_exists('recording_delete')) { + echo " \n"; + } + echo " \n"; + if ($_SESSION['recordings']['storage_type']['text'] != 'base64') { + echo " \n"; } - $tr_link = (permission_exists('recording_edit')) ? "href='recording_edit.php?id=".escape($row['recording_uuid'])."'" : null; - echo "\n"; - echo " \n"; if (permission_exists('recording_play') || permission_exists('recording_download')) { - echo " \n"; } - if ($_SESSION['recordings']['storage_type']['text'] != 'base64') { - echo " \n"; - } if ($_SESSION['recordings']['storage_type']['text'] == 'base64') { $file_size = byte_convert($row['recording_size']); - echo " \n"; + echo " \n"; } else { $file_name = $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$row['recording_filename']; @@ -392,29 +463,28 @@ else { unset($file_size, $file_date); } - echo " \n"; - echo " \n"; + echo " \n"; + echo " \n"; } - echo " \n"; - echo " \n"; + if (permission_exists('recording_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + echo " \n"; } - if (permission_exists('recording_delete')) { - echo "$v_link_label_delete"; - } - echo " \n"; echo "\n"; - - $c = ($c) ? 0 : 1; + $x++; } + unset($recordings); } - unset($recordings, $row); + echo "
\n"; + echo " \n"; + echo " ".$text['label-tools']."".$text['label-tools']."".($_SESSION['recordings']['storage_type']['text'] == 'base64' ? $text['label-size'] : $text['label-file_size'])."".$text['label-uploaded']."".($_SESSION['recordings']['storage_type']['text'] == 'base64' ? $text['label-size'] : $text['label-file_size'])."".$text['label-uploaded']."  
\n"; + echo " \n"; + echo " \n"; + echo " "; + if (permission_exists('recording_edit')) { + echo "".escape($row['recording_name']).""; + } + else { + echo escape($row['recording_name']); + } + echo " ".str_replace('_', '_​', escape($row['recording_filename']))."
".escape($row['recording_name'])."".str_replace('_', '_​', escape($row['recording_filename']))."".$file_size."".$file_size."".$file_size."".$file_date."".$file_size."".$file_date."".escape($row['recording_description'])." "; - if (permission_exists('recording_edit')) { - echo "$v_link_label_edit"; + echo " ".escape($row['recording_description'])." "; + echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); + echo "
\n"; echo "
\n"; - echo "
".$paging_controls."
\n"; - echo "

\n"; + + echo "\n"; + + echo "\n"; //include the footer require_once "resources/footer.php"; @@ -510,4 +580,4 @@ fclose($fp); } -?> +?> \ No newline at end of file diff --git a/app/recordings/resources/classes/switch_recordings.php b/app/recordings/resources/classes/switch_recordings.php index b2f64f98de..6806c47086 100644 --- a/app/recordings/resources/classes/switch_recordings.php +++ b/app/recordings/resources/classes/switch_recordings.php @@ -17,30 +17,64 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2016 + Portions created by the Initial Developer are Copyright (C) 2016-2019 All Rights Reserved. Contributor(s): Mark J Crane Matthew Vale */ -include "root.php"; //define the switch_recordings class +if (!class_exists('switch_recordings')) { class switch_recordings { + /** + * declare public variables + */ public $domain_uuid; + /** + * declare private variables + */ + private $app_name; + private $app_uuid; + private $permission_prefix; + private $list_page; + private $table; + private $uuid_prefix; + private $toggle_field; + private $toggle_values; + + /** + * called when the object is created + */ public function __construct() { $this->domain_uuid = $_SESSION['domain_uuid']; + + //assign private variables + $this->app_name = 'recordings'; + $this->app_uuid = '83913217-c7a2-9e90-925d-a866eb40b60e'; + $this->permission_prefix = 'recording_'; + $this->list_page = 'recordings.php'; + $this->table = 'recordings'; + $this->uuid_prefix = 'recording_'; + } + /** + * called when there are no references to a particular object + * unset the variables used in the class + */ public function __destruct() { foreach ($this as $key => $value) { unset($this->$key); } } + /** + * list recordings + */ public function list_recordings() { $sql = "select recording_uuid, recording_filename, recording_base64 "; $sql .= "from v_recordings "; @@ -57,6 +91,75 @@ include "root.php"; return $recordings; } - } + /** + * delete records + */ + public function delete($records) { + if (permission_exists($this->permission_prefix.'delete')) { + + //add multi-lingual support + $language = new text; + $text = $language->get(); + + //validate the token + $token = new token; + if (!$token->validate($_SERVER['PHP_SELF'])) { + message::add($text['message-invalid_token'],'negative'); + header('Location: '.$this->list_page); + exit; + } + + //delete multiple records + if (is_array($records) && @sizeof($records) != 0) { + + //get recording filename, build delete array + foreach ($records as $x => $record) { + if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + + //get filename + $sql = "select recording_filename from v_recordings "; + $sql .= "where domain_uuid = :domain_uuid "; + $sql .= "and recording_uuid = :recording_uuid "; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $parameters['recording_uuid'] = $record['uuid']; + $database = new database; + $filenames[] = $database->select($sql, $parameters, 'column'); + unset($sql, $parameters); + + //build delete array + $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid']; + $array[$this->table][$x]['domain_uuid'] = $_SESSION['domain_uuid']; + } + } + + //delete the checked rows + if (is_array($array) && @sizeof($array) != 0) { + + //execute delete + $database = new database; + $database->app_name = $this->app_name; + $database->app_uuid = $this->app_uuid; + $database->delete($array); + unset($array); + + //delete recording files + if (is_array($filenames) && @sizeof($filenames) != 0) { + foreach ($filenames as $filename) { + if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$filename)) { + @unlink($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$filename); + } + } + } + + //set message + message::add($text['message-delete']); + } + unset($records); + } + } + } //method + + } //class +} ?> \ No newline at end of file