diff --git a/app/fifo/fifo.php b/app/fifo/fifo.php index 806941edf9..b63767e627 100644 --- a/app/fifo/fifo.php +++ b/app/fifo/fifo.php @@ -67,42 +67,24 @@ exit; } - //prepare the array - if (!empty($fifo)) { - foreach ($fifo as $row) { - $array['fifo'][$x]['checked'] = $row['checked']; - $array['fifo'][$x]['fifo_uuid'] = $row['fifo_uuid']; - $array['fifo'][$x]['fifo_enabled'] = $row['fifo_enabled']; - $x++; - } - } - - //prepare the database object - $database = new database; - $database->app_name = 'fifo'; - $database->app_uuid = '16589224-c876-aeb3-f59f-523a1c0801f7'; - //send the array to the database class switch ($action) { - case 'copy': - if (permission_exists('fifo_add')) { - $database->copy($array); - //$obj = new fifo; - //$obj->copy($fifo); - } - break; +// case 'copy': +// if (permission_exists('fifo_add')) { +// $obj = new fifo; +// $obj->copy($fifo); +// } +// break; case 'toggle': if (permission_exists('fifo_edit')) { - $database->toggle($array); - //$obj = new fifo; - //$obj->toggle($fifo); + $obj = new fifo; + $obj->toggle($fifo); } break; case 'delete': if (permission_exists('fifo_delete')) { - $database->delete($array); - //$obj = new fifo; - //$obj->delete($fifo); + $obj = new fifo; + $obj->delete($fifo); } break; } @@ -213,9 +195,9 @@ if (permission_exists('fifo_add')) { echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','name'=>'btn_add','link'=>'fifo_edit.php']); } - if (permission_exists('fifo_add') && $fifo) { - echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'id'=>'btn_copy','name'=>'btn_copy','style'=>'display:none;','onclick'=>"modal_open('modal-copy','btn_copy');"]); - } +// if (permission_exists('fifo_add') && $fifo) { +// echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'id'=>'btn_copy','name'=>'btn_copy','style'=>'display:none;','onclick'=>"modal_open('modal-copy','btn_copy');"]); +// } if (permission_exists('fifo_edit') && $fifo) { echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'id'=>'btn_toggle','name'=>'btn_toggle','style'=>'display:none;','onclick'=>"modal_open('modal-toggle','btn_toggle');"]); } @@ -241,9 +223,9 @@ echo "
\n"; echo "\n"; - if (permission_exists('fifo_add') && $fifo) { - echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]); - } +// if (permission_exists('fifo_add') && $fifo) { +// echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]); +// } if (permission_exists('fifo_edit') && $fifo) { echo modal::create(['id'=>'modal-toggle','type'=>'toggle','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_toggle','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('form_list');"])]); } @@ -290,7 +272,7 @@ if (permission_exists('fifo_add') || permission_exists('fifo_edit') || permission_exists('fifo_delete')) { echo "| \n";
- echo " \n";
+ echo " \n";
echo " \n"; echo $text['description-fifo_name']."\n"; echo " | \n";
@@ -439,7 +444,7 @@
echo " ".$text['label-fifo_extension']."\n";
echo "\n";
echo "\n";
- echo " \n";
+ echo " \n";
echo " \n"; echo $text['description-fifo_extension']."\n"; echo " | \n";
@@ -450,7 +455,7 @@
echo " ".$text['label-fifo_agent_status']."\n";
echo "\n";
echo "\n";
- echo " \n";
+ echo " \n";
echo " \n"; echo $text['description-fifo_agent_status']."\n"; echo " | \n";
@@ -461,7 +466,7 @@
echo " ".$text['label-fifo_agent_queue']."\n";
echo "\n";
echo "\n";
- echo " \n";
+ echo " \n";
echo " \n"; echo $text['description-fifo_agent_queue']."\n"; echo " | \n";
@@ -553,7 +558,7 @@
//echo " \n";
$ringbacks = new ringbacks;
- echo $ringbacks->select('fifo_music', $fifo_music);
+ echo $ringbacks->select('fifo_music', $fifo_music ?? null);
echo "\n"; if (substr($input_toggle_style, 0, 6) == 'switch') { echo " \n"; } @@ -639,7 +644,7 @@ echo " ".$text['label-fifo_description']."\n"; echo " | \n"; echo "\n";
- echo " \n";
+ echo " \n";
echo " \n"; echo $text['description-fifo_description']."\n"; echo " | \n";
@@ -656,5 +661,4 @@
//include the footer
require_once "resources/footer.php";
-?>
-
+?>
\ No newline at end of file
diff --git a/app/fifo/resources/fifo.php b/app/fifo/resources/classes/fifo.php
similarity index 73%
rename from app/fifo/resources/fifo.php
rename to app/fifo/resources/classes/fifo.php
index 4c9b789e6d..415b174a2c 100644
--- a/app/fifo/resources/fifo.php
+++ b/app/fifo/resources/classes/fifo.php
@@ -31,6 +31,7 @@ if (!class_exists('fifo')) {
$this->app_uuid = '16589224-c876-aeb3-f59f-523a1c0801f7';
$this->name = 'fifo';
$this->table = 'fifo';
+ $this->uuid_prefix = 'fifo_';
$this->toggle_field = 'fifo_enabled';
$this->toggle_values = ['true','false'];
$this->description_field = 'fifo_description';
@@ -67,14 +68,41 @@ if (!class_exists('fifo')) {
//delete multiple records
if (is_array($records) && @sizeof($records) != 0) {
+
+ //filter out unchecked queues, build where clause for below
+ $uuids = [];
+ foreach ($records as $record) {
+ if (!empty($record['checked']) && $record['checked'] == 'true' && !empty($record['uuid']) && is_uuid($record['uuid'])) {
+ $uuids[] = "'".$record['uuid']."'";
+ }
+ }
+
+ //get necessary fifo queue details
+ if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) {
+ $sql = "select ".$this->uuid_prefix."uuid as uuid, dialplan_uuid from v_".$this->table." ";
+ $sql .= "where domain_uuid = :domain_uuid ";
+ $sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
+ $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
+ $database = new database;
+ $rows = $database->select($sql, $parameters, 'all');
+ if (is_array($rows) && @sizeof($rows) != 0) {
+ foreach ($rows as $row) {
+ $fifos[$row['uuid']]['dialplan_uuid'] = $row['dialplan_uuid'];
+ }
+ }
+ unset($sql, $parameters, $rows, $row);
+ }
+
//build the delete array
$x = 0;
- foreach ($records as $record) {
+ foreach ($fifos as $fifo_uuid => $fifo) {
//add to the array
- if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
- $array[$this->table][$x][$this->name.'_uuid'] = $record['uuid'];
- $array[$this->table][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
- }
+ $array[$this->table][$x][$this->name.'_uuid'] = $fifo_uuid;
+ $array[$this->table][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
+ $array['fifo_members'][$x]['fifo_uuid'] = $fifo_uuid;
+ $array['fifo_members'][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
+ $array['dialplans'][$x]['dialplan_uuid'] = $fifo['dialplan_uuid'];
+ $array['dialplans'][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
//increment the id
$x++;
@@ -82,6 +110,11 @@ if (!class_exists('fifo')) {
//delete the checked rows
if (is_array($array) && @sizeof($array) != 0) {
+ //grant temporary permissions
+ $p = new permissions;
+ $p->add('fifo_member_delete', 'temp');
+ $p->add('dialplan_delete', 'temp');
+
//execute delete
$database = new database;
$database->app_name = $this->app_name;
@@ -89,6 +122,10 @@ if (!class_exists('fifo')) {
$database->delete($array);
unset($array);
+ //revoke temporary permissions
+ $p->delete('fifo_member_delete', 'temp');
+ $p->delete('dialplan_delete', 'temp');
+
//set message
message::add($text['message-delete']);
}
@@ -118,12 +155,12 @@ if (!class_exists('fifo')) {
//toggle the checked records
if (is_array($records) && @sizeof($records) != 0) {
//get current toggle state
- foreach($records as $record) {
- if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
+ foreach ($records as $record) {
+ if (!empty($record['checked']) && $record['checked'] == 'true' && !empty($record['uuid']) && is_uuid($record['uuid'])) {
$uuids[] = "'".$record['uuid']."'";
}
}
- if (is_array($uuids) && @sizeof($uuids) != 0) {
+ if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) {
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
@@ -140,7 +177,7 @@ if (!class_exists('fifo')) {
//build update array
$x = 0;
- foreach($states as $uuid => $state) {
+ foreach ($states as $uuid => $state) {
//create the array
$array[$this->table][$x][$this->name.'_uuid'] = $uuid;
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
@@ -202,6 +239,7 @@ if (!class_exists('fifo')) {
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
+
if (is_array($rows) && @sizeof($rows) != 0) {
$x = 0;
foreach ($rows as $row) {
@@ -221,6 +259,11 @@ if (!class_exists('fifo')) {
//save the changes and set the message
if (is_array($array) && @sizeof($array) != 0) {
+
+ //grant temporary permissions
+ $p = new permissions;
+ $p->add('fifo_member_add', 'temp');
+
//save the array
$database = new database;
$database->app_name = $this->app_name;
@@ -228,6 +271,9 @@ if (!class_exists('fifo')) {
$database->save($array);
unset($array);
+ //revoke temporary permissions
+ $p->delete('fifo_member_add', 'temp');
+
//set message
message::add($text['message-copy']);
}