diff --git a/app/fifo/app_config.php b/app/fifo/app_config.php
index 336d276469..8e7f5eaee6 100644
--- a/app/fifo/app_config.php
+++ b/app/fifo/app_config.php
@@ -1,13 +1,13 @@
+?>
\ No newline at end of file
diff --git a/app/fifo/app_menu.php b/app/fifo/app_menu.php
index a75f8ae2ec..11ca10b67e 100644
--- a/app/fifo/app_menu.php
+++ b/app/fifo/app_menu.php
@@ -28,7 +28,7 @@
$apps[$x]['menu'][$y]['parent_uuid'] = "fd29e39c-c936-f5fc-8e2b-611681b266b5";
$apps[$x]['menu'][$y]['category'] = "internal";
$apps[$x]['menu'][$y]['icon'] = "";
- $apps[$x]['menu'][$y]['path'] = "/app/dialplans/dialplans.php?app_uuid=16589224-c876-aeb3-f59f-523a1c0801f7";
+ $apps[$x]['menu'][$y]['path'] = "/app/fifo/fifo.php";
$apps[$x]['menu'][$y]['order'] = "";
$apps[$x]['menu'][$y]['groups'][] = "admin";
$apps[$x]['menu'][$y]['groups'][] = "superadmin";
diff --git a/app/fifo/fifo.php b/app/fifo/fifo.php
new file mode 100644
index 0000000000..806941edf9
--- /dev/null
+++ b/app/fifo/fifo.php
@@ -0,0 +1,342 @@
+
+ Portions created by the Initial Developer are Copyright (C) 2018 - 2023
+ the Initial Developer. All Rights Reserved.
+*/
+
+//set the include path
+ $conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE);
+ set_include_path(parse_ini_file($conf[0])['document.root']);
+
+//includes files
+ require_once "resources/require.php";
+ require_once "resources/check_auth.php";
+ require_once "resources/paging.php";
+
+//check permissions
+ if (permission_exists('fifo_view')) {
+ //access granted
+ }
+ else {
+ echo "access denied";
+ exit;
+ }
+
+//add multi-lingual support
+ $language = new text;
+ $text = $language->get();
+
+//add the settings object
+ $settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]);
+
+//set from session variables
+ $list_row_edit_button = $settings->get('theme', 'list_row_edit_button', 'false');
+
+//get the http post data
+ if (!empty($_POST['fifo']) && is_array($_POST['fifo'])) {
+ $action = $_POST['action'];
+ $search = $_POST['search'];
+ $fifo = $_POST['fifo'];
+ }
+
+//process the http post data by action
+ if (!empty($action) && !empty($fifo) && is_array($fifo) && @sizeof($fifo) != 0) {
+
+ //validate the token
+ $token = new token;
+ if (!$token->validate($_SERVER['PHP_SELF'])) {
+ message::add($text['message-invalid_token'],'negative');
+ header('Location: fifo.php');
+ 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 'toggle':
+ if (permission_exists('fifo_edit')) {
+ $database->toggle($array);
+ //$obj = new fifo;
+ //$obj->toggle($fifo);
+ }
+ break;
+ case 'delete':
+ if (permission_exists('fifo_delete')) {
+ $database->delete($array);
+ //$obj = new fifo;
+ //$obj->delete($fifo);
+ }
+ break;
+ }
+
+ //redirect the user
+ header('Location: fifo.php'.($search != '' ? '?search='.urlencode($search) : null));
+ exit;
+ }
+
+//get order and order by
+ $order_by = $_GET["order_by"] ?? null;
+ $order = $_GET["order"] ?? null;
+
+//define the variables
+ $search = '';
+ $show = '';
+ $list_row_url = '';
+
+//add the search variable
+ if (!empty($_GET["search"])) {
+ $search = strtolower($_GET["search"]);
+ }
+
+//add the show variable
+ if (!empty($_GET["show"])) {
+ $show = $_GET["show"];
+ }
+
+//get the count
+ $sql = "select count(fifo_uuid) ";
+ $sql .= "from v_fifo ";
+ if (permission_exists('fifo_all') && $show == 'all') {
+ $sql .= "where true ";
+ }
+ else {
+ $sql .= "where domain_uuid = :domain_uuid ";
+ $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
+ }
+ if (!empty($search)) {
+ $sql .= "and ( ";
+ $sql .= " lower(fifo_name) like :search ";
+ $sql .= " or lower(fifo_extension) like :search ";
+ $sql .= " or lower(fifo_description) like :search ";
+ $sql .= ") ";
+ $parameters['search'] = '%'.$search.'%';
+ }
+ $database = new database;
+ $num_rows = $database->select($sql, $parameters ?? null, 'column');
+ unset($sql, $parameters);
+
+//prepare to page the results
+ $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
+ $param = !empty($search) ? "&search=".$search : null;
+ $param .= (!empty($_GET['page']) && $show == 'all' && permission_exists('fifo_all')) ? "&show=all" : null;
+ $page = !empty($_GET['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 list
+ $sql = "select ";
+ $sql .= "fifo_uuid, ";
+ $sql .= "fifo_name, ";
+ $sql .= "fifo_extension, ";
+ $sql .= "fifo_agent_queue, ";
+ $sql .= "fifo_agent_status, ";
+ $sql .= "fifo_music, ";
+ $sql .= "u.domain_uuid, ";
+ $sql .= "d.domain_name, ";
+ $sql .= "fifo_order, ";
+ $sql .= "cast(fifo_enabled as text), ";
+ $sql .= "fifo_description ";
+ $sql .= "from v_fifo as u, v_domains as d ";
+ if (permission_exists('fifo_all') && $show == 'all') {
+ $sql .= "where true ";
+ }
+ else {
+ $sql .= "where u.domain_uuid = :domain_uuid ";
+ $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
+ }
+ if (!empty($search)) {
+ $sql .= "and ( ";
+ $sql .= " lower(fifo_name) like :search ";
+ $sql .= " or lower(fifo_extension) like :search ";
+ $sql .= " or lower(fifo_description) like :search ";
+ $sql .= ") ";
+ $parameters['search'] = '%'.$search.'%';
+ }
+ $sql .= "and u.domain_uuid = d.domain_uuid ";
+ $sql .= order_by($order_by, $order, '', '');
+ $sql .= limit_offset($rows_per_page, $offset);
+ $database = new database;
+ $fifo = $database->select($sql, $parameters ?? null, 'all');
+ unset($sql, $parameters);
+
+//create token
+ $object = new token;
+ $token = $object->create($_SERVER['PHP_SELF']);
+
+//additional includes
+ $document['title'] = $text['title-fifos'];
+ require_once "resources/header.php";
+
+//show the content
+ echo "
\n";
+ echo "
".$text['title-fifos']." (".$num_rows.")
\n";
+ echo "
\n";
+ 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_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');"]);
+ }
+ if (permission_exists('fifo_delete') && $fifo) {
+ echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display:none;','onclick'=>"modal_open('modal-delete','btn_delete');"]);
+ }
+ echo "\n";
+ echo "
\n";
+ 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_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');"])]);
+ }
+ if (permission_exists('fifo_delete') && $fifo) {
+ echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]);
+ }
+
+ echo $text['title_description-fifo']."\n";
+ echo "
\n";
+
+ echo "\n";
+
+//include the footer
+ require_once "resources/footer.php";
+
+?>
\ No newline at end of file
diff --git a/app/fifo/fifo_add.php b/app/fifo/fifo_add.php
deleted file mode 100644
index f7bd6ed5a1..0000000000
--- a/app/fifo/fifo_add.php
+++ /dev/null
@@ -1,556 +0,0 @@
-
- Copyright (C) 2010 - 2023
- All Rights Reserved.
-
- Contributor(s):
- Mark J Crane
- Luis Daniel Lucio Quiroz
-*/
-
-//includes files
- require_once dirname(__DIR__, 2) . "/resources/require.php";
- require_once "resources/check_auth.php";
- require_once "resources/paging.php";
-
-//check permissions
- if (permission_exists('fifo_add')) {
- //access granted
- }
- else {
- echo "access denied";
- exit;
- }
-
-//add multi-lingual support
- $language = new text;
- $text = $language->get();
-
-//get http values and set them as variables
- if (count($_POST)>0) {
- $order_by = $_GET["order_by"] ?? null;
- $order = $_GET["order"] ?? null;
- $extension_name = $_POST["extension_name"];
- $queue_extension_number = $_POST["queue_extension_number"];
- $agent_queue_extension_number = $_POST["agent_queue_extension_number"];
- $agent_login_logout_extension_number = $_POST["agent_login_logout_extension_number"];
- $dialplan_order = $_POST["dialplan_order"];
- $pin_number = $_POST["pin_number"] ?? null;
- $profile = $_POST["profile"] ?? null;
- $flags = $_POST["flags"] ?? null;
- $dialplan_enabled = $_POST["dialplan_enabled"];
- $dialplan_description = $_POST["dialplan_description"];
- if (empty($dialplan_enabled)) { $dialplan_enabled = "true"; } //set default to enabled
- }
-
-//process the HTTP POST
- if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
-
- //validate the token
- $token = new token;
- if (!$token->validate($_SERVER['PHP_SELF'])) {
- message::add($text['message-invalid_token'],'negative');
- header('Location: dialplans.php');
- exit;
- }
-
- //check for all required data
- if (empty($domain_uuid)) { $msg .= $text['message-required']."domain_uuid
\n"; }
- if (empty($extension_name)) { $msg .= $text['message-required'].$text['label-name']."
\n"; }
- if (empty($queue_extension_number)) { $msg .= $text['message-required'].$text['label-extension']."
\n"; }
- if (!empty($msg) && empty($_POST["persistformvar"])) {
- require_once "resources/header.php";
- require_once "resources/persist_form_var.php";
- echo "\n";
- echo "
\n";
- echo $msg." ";
- echo " |
\n";
- persistformvar($_POST);
- echo "
\n";
- require_once "resources/footer.php";
- return;
- }
-
- if (!empty($queue_extension_number)) {
- //--------------------------------------------------------
- //Caller Queue [FIFO in]
- //
- //
- //
- //
- //
- //
- //
- //--------------------------------------------------------
- $queue_name = $extension_name."@\${domain_name}";
- $app_uuid = '16589224-c876-aeb3-f59f-523a1c0801f7';
- $dialplan_uuid = uuid();
- $dialplan_context = $_SESSION['domain_name'];
- $domain_uuid = $_SESSION['domain_uuid'];
- $dialplan_detail_order = 0;
-
- //start building the dialplan array
- $y=0;
- $array["dialplans"][$y]["domain_uuid"] = $domain_uuid;
- $array["dialplans"][$y]["dialplan_uuid"] = $dialplan_uuid;
- $array["dialplans"][$y]["app_uuid"] = $app_uuid;
- $array["dialplans"][$y]["dialplan_name"] = $extension_name;
- $array["dialplans"][$y]["dialplan_order"] = "$dialplan_order";
- $array["dialplans"][$y]["dialplan_context"] = $dialplan_context;
- $array["dialplans"][$y]["dialplan_enabled"] = $dialplan_enabled;
- $array["dialplans"][$y]["dialplan_order"] = $dialplan_order;
- $array["dialplans"][$y]["dialplan_description"] = $dialplan_description;
- $y++;
-
- if (is_uuid($dialplan_uuid)) {
- //set the destination number
- $array["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
- $array["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
- $array["dialplan_details"][$y]["dialplan_detail_tag"] = "condition";
- $array["dialplan_details"][$y]["dialplan_detail_type"] = "destination_number";
- $array["dialplan_details"][$y]["dialplan_detail_data"] = '^'.$queue_extension_number.'$';
- $array["dialplan_details"][$y]["dialplan_detail_inline"] = "";
- $array["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
- if ((strlen($agent_queue_extension_number) > 0) || (!empty($agent_login_logout_extension_number))) {
- $array["dialplan_details"][$y]["dialplan_detail_break"] = 'on-true';
- }
- $array["dialplan_details"][$y]["dialplan_detail_group"] = '1';
- $y++;
-
- //increment the dialplan detial order
- $dialplan_detail_order = $dialplan_detail_order + 10;
-
- //set the hold music
- $array["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
- $array["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
- $array["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
- $array["dialplan_details"][$y]["dialplan_detail_type"] = "set";
- $array["dialplan_details"][$y]["dialplan_detail_data"] = "fifo_music=\$\${hold_music}";
- $array["dialplan_details"][$y]["dialplan_detail_inline"] = "true";
- $array["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
- $array["dialplan_details"][$y]["dialplan_detail_group"] = '1';
- $y++;
-
- //increment the dialplan detial order
- $dialplan_detail_order = $dialplan_detail_order + 10;
-
- //action answer
- $array["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
- $array["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
- $array["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
- $array["dialplan_details"][$y]["dialplan_detail_type"] = "answer";
- $array["dialplan_details"][$y]["dialplan_detail_data"] = "";
- $array["dialplan_details"][$y]["dialplan_detail_inline"] = "";
- $array["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
- $array["dialplan_details"][$y]["dialplan_detail_group"] = '1';
- $y++;
-
- //increment the dialplan detial order
- $dialplan_detail_order = $dialplan_detail_order + 10;
-
- //action fifo
- $queue_action_data = $queue_name." in";
- $array["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
- $array["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
- $array["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
- $array["dialplan_details"][$y]["dialplan_detail_type"] = "fifo";
- $array["dialplan_details"][$y]["dialplan_detail_data"] = $queue_action_data;
- $array["dialplan_details"][$y]["dialplan_detail_inline"] = "";
- $array["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
- $array["dialplan_details"][$y]["dialplan_detail_group"] = '1';
- $y++;
- }
- }
-
- // Caller Queue / Agent Queue
- if (!empty($agent_queue_extension_number)) {
- //--------------------------------------------------------
- // Agent Queue [FIFO out]
- //
- //
- //
- //
- //
- //
- //
- //--------------------------------------------------------
- $queue_name = $extension_name."@\${domain_name}";
- if (is_uuid($dialplan_uuid)) {
-
- //set the dialplan detial order to zero
- $dialplan_detail_order = 0;
-
- //set the destination number
- $array["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
- $array["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
- $array["dialplan_details"][$y]["dialplan_detail_tag"] = "condition";
- $array["dialplan_details"][$y]["dialplan_detail_type"] = "destination_number";
- $array["dialplan_details"][$y]["dialplan_detail_data"] = '^'.$agent_queue_extension_number.'$';
- $array["dialplan_details"][$y]["dialplan_detail_inline"] = "";
- if (!empty($agent_login_logout_extension_number)) {
- $array["dialplan_details"][$y]["dialplan_detail_break"] = 'on-true';
- }
- $array["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
- $array["dialplan_details"][$y]["dialplan_detail_group"] = '2';
- $y++;
-
- //increment the dialplan detial order
- $dialplan_detail_order = $dialplan_detail_order + 10;
-
- //set the hold music
- $array["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
- $array["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
- $array["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
- $array["dialplan_details"][$y]["dialplan_detail_type"] = "set";
- $array["dialplan_details"][$y]["dialplan_detail_data"] = "fifo_music=\$\${hold_music}";
- $array["dialplan_details"][$y]["dialplan_detail_inline"] = "true";
- $array["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
- $array["dialplan_details"][$y]["dialplan_detail_group"] = '2';
- $y++;
-
- //increment the dialplan detial order
- $dialplan_detail_order = $dialplan_detail_order + 10;
-
- //action answer
- $array["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
- $array["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
- $array["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
- $array["dialplan_details"][$y]["dialplan_detail_type"] = "answer";
- $array["dialplan_details"][$y]["dialplan_detail_data"] = "";
- $array["dialplan_details"][$y]["dialplan_detail_inline"] = "";
- $array["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
- $array["dialplan_details"][$y]["dialplan_detail_group"] = '2';
- $y++;
-
- //increment the dialplan detial order
- $dialplan_detail_order = $dialplan_detail_order + 10;
-
- //action fifo
- $queue_action_data = $queue_name." out wait";
- $array["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
- $array["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
- $array["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
- $array["dialplan_details"][$y]["dialplan_detail_type"] = "fifo";
- $array["dialplan_details"][$y]["dialplan_detail_data"] = $queue_action_data;
- $array["dialplan_details"][$y]["dialplan_detail_inline"] = "";
- $array["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
- $array["dialplan_details"][$y]["dialplan_detail_group"] = '2';
- $y++;
- }
- }
-
- // agent or member login / logout
- if (!empty($agent_login_logout_extension_number)) {
- //--------------------------------------------------------
- // Agent Queue [FIFO login logout]
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //--------------------------------------------------------
- $queue_name = $extension_name."@\${domain_name}";
- if (is_uuid($dialplan_uuid)) {
-
- //set the dialplan detial order to zero
- $dialplan_detail_order = 0;
-
- //set the destination number
- $array["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
- $array["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
- $array["dialplan_details"][$y]["dialplan_detail_tag"] = "condition";
- $array["dialplan_details"][$y]["dialplan_detail_type"] = "destination_number";
- $array["dialplan_details"][$y]["dialplan_detail_data"] = '^'.$agent_login_logout_extension_number.'$';
- $array["dialplan_details"][$y]["dialplan_detail_inline"] = "";
- $array["dialplan_details"][$y]["dialplan_detail_break"] = 'on-true';
- $array["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
- $array["dialplan_details"][$y]["dialplan_detail_group"] = '3';
- $y++;
-
- //increment the dialplan detial order
- $dialplan_detail_order = $dialplan_detail_order + 10;
-
- //set the queue_name
- $array["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
- $array["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
- $array["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
- $array["dialplan_details"][$y]["dialplan_detail_type"] = "set";
- $array["dialplan_details"][$y]["dialplan_detail_data"] = 'queue_name='.$queue_name;
- $array["dialplan_details"][$y]["dialplan_detail_inline"] = "true";
- $array["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
- $array["dialplan_details"][$y]["dialplan_detail_group"] = '3';
- $y++;
-
- //increment the dialplan detial order
- $dialplan_detail_order = $dialplan_detail_order + 10;
-
- //set the user_name
- $array["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
- $array["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
- $array["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
- $array["dialplan_details"][$y]["dialplan_detail_type"] = "set";
- $array["dialplan_details"][$y]["dialplan_detail_data"] = 'user_name=${caller_id_number}@${domain_name}';
- $array["dialplan_details"][$y]["dialplan_detail_inline"] = "true";
- $array["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
- $array["dialplan_details"][$y]["dialplan_detail_group"] = '3';
- $y++;
-
- //increment the dialplan detial order
- $dialplan_detail_order = $dialplan_detail_order + 10;
-
- //set the fifo_simo
- $array["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
- $array["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
- $array["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
- $array["dialplan_details"][$y]["dialplan_detail_type"] = "set";
- $array["dialplan_details"][$y]["dialplan_detail_data"] = 'fifo_simo=1';
- $array["dialplan_details"][$y]["dialplan_detail_inline"] = "true";
- $array["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
- $array["dialplan_details"][$y]["dialplan_detail_group"] = '3';
- $y++;
-
- //increment the dialplan detial order
- $dialplan_detail_order = $dialplan_detail_order + 10;
-
- //set the fifo_timeout
- $array["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
- $array["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
- $array["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
- $array["dialplan_details"][$y]["dialplan_detail_type"] = "set";
- $array["dialplan_details"][$y]["dialplan_detail_data"] = 'fifo_timeout=10';
- $array["dialplan_details"][$y]["dialplan_detail_inline"] = "true";
- $array["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
- $array["dialplan_details"][$y]["dialplan_detail_group"] = '3';
- $y++;
-
- //increment the dialplan detial order
- $dialplan_detail_order = $dialplan_detail_order + 10;
-
- //set the fifo_lag
- $array["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
- $array["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
- $array["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
- $array["dialplan_details"][$y]["dialplan_detail_type"] = "set";
- $array["dialplan_details"][$y]["dialplan_detail_data"] = 'fifo_lag=10';
- $array["dialplan_details"][$y]["dialplan_detail_inline"] = "true";
- $array["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
- $array["dialplan_details"][$y]["dialplan_detail_group"] = '3';
- $y++;
-
- //increment the dialplan detial order
- $dialplan_detail_order = $dialplan_detail_order + 10;
-
- //set the pin_number
- $array["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
- $array["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
- $array["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
- $array["dialplan_details"][$y]["dialplan_detail_type"] = "set";
- $array["dialplan_details"][$y]["dialplan_detail_data"] = 'pin_number=';
- $array["dialplan_details"][$y]["dialplan_detail_inline"] = "true";
- $array["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
- $array["dialplan_details"][$y]["dialplan_detail_group"] = '3';
- $y++;
-
- //increment the dialplan detial order
- $dialplan_detail_order = $dialplan_detail_order + 10;
-
- //action lua
- $array["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
- $array["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
- $array["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
- $array["dialplan_details"][$y]["dialplan_detail_type"] = "lua";
- $array["dialplan_details"][$y]["dialplan_detail_data"] = "fifo_member.lua";
- $array["dialplan_details"][$y]["dialplan_detail_inline"] = "";
- $array["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
- $array["dialplan_details"][$y]["dialplan_detail_group"] = '3';
- $y++;
- }
- }
-
- //add the dialplan permission
- $p = new permissions;
- $p->add("dialplan_add", "temp");
- $p->add("dialplan_edit", "temp");
-
- //save to the data
- $database = new database;
- $database->app_name = 'fifo';
- $database->app_uuid = '16589224-c876-aeb3-f59f-523a1c0801f7';
- $database->save($array);
- //$message = $database->message;
-
- //remove the temporary permission
- $p->delete("dialplan_add", "temp");
- $p->delete("dialplan_edit", "temp");
-
- //clear the cache
- $cache = new cache;
- $cache->delete("dialplan:".$_SESSION["domain_name"]);
-
- //redirect the user
- message::add($text['message-add']);
- header("Location: ".PROJECT_PATH."/app/dialplans/dialplans.php?app_uuid=16589224-c876-aeb3-f59f-523a1c0801f7");
- return;
-
- }
-
-//create token
- $object = new token;
- $token = $object->create($_SERVER['PHP_SELF']);
-
-//includes and title
- require_once "resources/header.php";
- $document['title'] = $text['title-queue_add'];
-
-//show the content
- echo "";
-
-//show the footer
- require_once "resources/footer.php";
-
-?>
\ No newline at end of file
diff --git a/app/fifo/fifo_edit.php b/app/fifo/fifo_edit.php
new file mode 100644
index 0000000000..b2ad1cd9df
--- /dev/null
+++ b/app/fifo/fifo_edit.php
@@ -0,0 +1,639 @@
+
+ Portions created by the Initial Developer are Copyright (C) 2024
+ the Initial Developer. All Rights Reserved.
+*/
+
+
+//set the include path
+ $conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE);
+ set_include_path(parse_ini_file($conf[0])['document.root']);
+
+//includes files
+ require_once "resources/require.php";
+ require_once "resources/check_auth.php";
+
+//check permissions
+ if (permission_exists('fifo_add') || permission_exists('fifo_edit')) {
+ //access granted
+ }
+ else {
+ echo "access denied";
+ exit;
+ }
+
+//add multi-lingual support
+ $language = new text;
+ $text = $language->get();
+
+//add the settings object
+ $settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]);
+
+//set from session variables
+ $button_icon_back = $settings->get('theme', 'button_icon_back', '');
+ $button_icon_copy = $settings->get('theme', 'button_icon_copy', '');
+ $button_icon_delete = $settings->get('theme', 'button_icon_delete', '');
+ $button_icon_save = $settings->get('theme', 'button_icon_save', '');
+ $input_toggle_style = $settings->get('theme', 'input_toggle_style', 'switch round');
+
+//action add or update
+ if (is_uuid($_REQUEST["id"])) {
+ $action = "update";
+ $fifo_uuid = $_REQUEST["id"];
+ $id = $_REQUEST["id"];
+ }
+ else {
+ $action = "add";
+ }
+
+//get http post variables and set them to php variables
+ if (!empty($_POST)) {
+ $dialplan_uuid = $_POST["dialplan_uuid"];
+ $fifo_name = $_POST["fifo_name"];
+ $fifo_extension = $_POST["fifo_extension"];
+ $fifo_agent_status = $_POST["fifo_agent_status"];
+ $fifo_agent_queue = $_POST["fifo_agent_queue"];
+ $fifo_members = $_POST["fifo_members"];
+ $fifo_music = $_POST["fifo_music"];
+ $domain_uuid = $_POST["domain_uuid"];
+ $fifo_order = $_POST["fifo_order"];
+ $fifo_enabled = $_POST["fifo_enabled"];
+ $fifo_description = $_POST["fifo_description"];
+ }
+
+//process the data and save it to the database
+ if (!empty($_POST) && empty($_POST["persistformvar"])) {
+
+ //validate the token
+ $token = new token;
+ if (!$token->validate($_SERVER['PHP_SELF'])) {
+ message::add($text['message-invalid_token'],'negative');
+ header('Location: fifo.php');
+ exit;
+ }
+
+ //process the http post data by submitted action
+ if ($_POST['action'] != '' && strlen($_POST['action']) > 0) {
+
+ //prepare the array(s)
+ $x = 0;
+ if (is_array($_POST['fifo_members'])) {
+ foreach ($_POST['fifo_members'] as $row) {
+ if (is_uuid($row['fifo_member_uuid']) && $row['checked'] === 'true') {
+ $array['fifo'][$x]['checked'] = $row['checked'];
+ $array['fifo'][$x]['fifo_members'][]['fifo_member_uuid'] = $row['fifo_member_uuid'];
+ $x++;
+ }
+ }
+ }
+
+ //send the array to the database class
+ switch ($_POST['action']) {
+ case 'copy':
+ if (permission_exists('fifo_add')) {
+ $obj = new database;
+ $obj->copy($array);
+ }
+ break;
+ case 'delete':
+ if (permission_exists('fifo_delete')) {
+ $obj = new database;
+ $obj->delete($array);
+ }
+ break;
+ case 'toggle':
+ if (permission_exists('fifo_update')) {
+ $obj = new database;
+ $obj->toggle($array);
+ }
+ break;
+ }
+
+ //redirect the user
+ if (in_array($_POST['action'], array('copy', 'delete', 'toggle'))) {
+ header('Location: fifo_edit.php?id='.$id);
+ exit;
+ }
+ }
+
+ //check for all required data
+ $msg = '';
+ if (strlen($fifo_name) == 0) { $msg .= $text['message-required']." ".$text['label-fifo_name']."
\n"; }
+ if (strlen($fifo_extension) == 0) { $msg .= $text['message-required']." ".$text['label-fifo_extension']."
\n"; }
+ //if (strlen($fifo_agent_status) == 0) { $msg .= $text['message-required']." ".$text['label-fifo_agent_status']."
\n"; }
+ //if (strlen($fifo_agent_queue) == 0) { $msg .= $text['message-required']." ".$text['label-fifo_agent_queue']."
\n"; }
+ //if (strlen($fifo_members) == 0) { $msg .= $text['message-required']." ".$text['label-fifo_members']."
\n"; }
+ //if (strlen($fifo_music) == 0) { $msg .= $text['message-required']." ".$text['label-fifo_music']."
\n"; }
+ if (strlen($domain_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-domain_uuid']."
\n"; }
+ if (strlen($fifo_order) == 0) { $msg .= $text['message-required']." ".$text['label-fifo_order']."
\n"; }
+ //if (strlen($fifo_enabled) == 0) { $msg .= $text['message-required']." ".$text['label-fifo_enabled']."
\n"; }
+ //if (strlen($fifo_description) == 0) { $msg .= $text['message-required']." ".$text['label-fifo_description']."
\n"; }
+ if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
+ require_once "resources/header.php";
+ require_once "resources/persist_form_var.php";
+ echo "\n";
+ echo "
\n";
+ echo $msg." ";
+ echo " |
\n";
+ persistformvar($_POST);
+ echo "
\n";
+ require_once "resources/footer.php";
+ return;
+ }
+
+ //add the fifo_uuid
+ if (!is_uuid($_POST["fifo_uuid"])) {
+ $fifo_uuid = uuid();
+ }
+
+ //add a uuid to dialplan_uuid if it is empty
+ if (empty($dialplan_uuid) && !is_uuid($dialplan_uuid)) {
+ $dialplan_uuid = uuid();
+ }
+
+ //prepare the variables
+ $queue_name = $fifo_extension."@".$_SESSION['domain_name'];
+ $app_uuid = '16589224-c876-aeb3-f59f-523a1c0801f7';
+ $dialplan_context = $_SESSION['domain_name'];
+ $domain_uuid = $_SESSION['domain_uuid'];
+ $dialplan_detail_order = 0;
+
+ //prepare the array
+ $array['fifo'][0]['fifo_uuid'] = $fifo_uuid;
+ $array['fifo'][0]['domain_uuid'] = $_SESSION['domain_uuid'];
+ $array['fifo'][0]['dialplan_uuid'] = $dialplan_uuid;
+ $array['fifo'][0]['fifo_name'] = $fifo_name;
+ $array['fifo'][0]['fifo_extension'] = $fifo_extension;
+ $array['fifo'][0]['fifo_agent_status'] = $fifo_agent_status;
+ $array['fifo'][0]['fifo_agent_queue'] = $fifo_agent_queue;
+ $array['fifo'][0]['fifo_music'] = $fifo_music;
+ $array['fifo'][0]['fifo_order'] = $fifo_order;
+ $array['fifo'][0]['fifo_enabled'] = $fifo_enabled;
+ $array['fifo'][0]['fifo_description'] = $fifo_description;
+ $y = 0;
+ if (is_array($fifo_members)) {
+ foreach ($fifo_members as $row) {
+ if (strlen($row['member_contact']) > 0) {
+ $array['fifo'][0]['fifo_members'][$y]['fifo_member_uuid'] = $row["fifo_member_uuid"];
+ $array['fifo'][0]['fifo_members'][$y]['member_contact'] = $row["member_contact"];
+ $array['fifo'][0]['fifo_members'][$y]['member_call_timeout'] = $row["member_call_timeout"];
+ //$array['fifo'][0]['fifo_members'][$y]['member_simultaneous'] = $row["member_simultaneous"];
+ $array['fifo'][0]['fifo_members'][$y]['member_wrap_up_time'] = $row["member_wrap_up_time"];
+ $array['fifo'][0]['fifo_members'][$y]['member_enabled'] = $row["member_enabled"];
+ $y++;
+ }
+ }
+ }
+
+ //add the fifo dialplan
+ if (!empty($fifo_extension)) {
+ //escape the * symbol
+ $fifo_agent_status_xml = str_replace("*", "\*", $fifo_agent_status);
+ $fifo_agent_queue_xml = str_replace("*", "\*", $fifo_agent_queue);
+
+ //build the xml dialplan
+ $dialplan_xml = "\n";
+ $dialplan_xml .= " \n";
+ $dialplan_xml .= " \n";
+ $dialplan_xml .= " \n";
+ $dialplan_xml .= " \n";
+ $dialplan_xml .= " \n";
+ $dialplan_xml .= " \n";
+ $dialplan_xml .= " \n";
+ $dialplan_xml .= " \n";
+ $dialplan_xml .= " \n";
+ $dialplan_xml .= " \n";
+ $dialplan_xml .= " \n";
+ $dialplan_xml .= " \n";
+ $dialplan_xml .= " \n";
+ $dialplan_xml .= " \n";
+ $dialplan_xml .= " \n";
+ $dialplan_xml .= " \n";
+ $dialplan_xml .= "\n";
+
+ //start building the dialplan array
+ $y=0;
+ $array["dialplans"][$y]["domain_uuid"] = $domain_uuid;
+ $array["dialplans"][$y]["dialplan_uuid"] = $dialplan_uuid;
+ $array["dialplans"][$y]["app_uuid"] = $app_uuid;
+ $array["dialplans"][$y]["dialplan_name"] = $fifo_name;
+ $array["dialplans"][$y]["dialplan_number"] = $fifo_extension;
+ $array["dialplans"][$y]["dialplan_xml"] = $dialplan_xml;
+ $array["dialplans"][$y]["dialplan_order"] = $fifo_order;
+ $array["dialplans"][$y]["dialplan_context"] = $_SESSION['domain_name'];
+ $array["dialplans"][$y]["dialplan_enabled"] = $fifo_enabled;
+ $array["dialplans"][$y]["dialplan_description"] = $fifo_description;
+ $y++;
+ }
+
+ //add the dialplan permission
+ $p = new permissions;
+ $p->add("dialplan_add", "temp");
+ $p->add("dialplan_edit", "temp");
+
+ //save the data
+ $database = new database;
+ $database->app_name = 'fifo';
+ $database->app_uuid = '16589224-c876-aeb3-f59f-523a1c0801f7';
+ $result = $database->save($array);
+
+ //remove the temporary permission
+ $p->delete("dialplan_add", "temp");
+ $p->delete("dialplan_edit", "temp");
+
+ //redirect the user
+ if (isset($action)) {
+ if ($action == "add") {
+ $_SESSION["message"] = $text['message-add'];
+ }
+ if ($action == "update") {
+ $_SESSION["message"] = $text['message-update'];
+ }
+ //header('Location: fifo.php');
+ header('Location: fifo_edit.php?id='.urlencode($fifo_uuid));
+ return;
+ }
+ }
+
+//pre-populate the form
+ if (is_array($_GET) && $_POST["persistformvar"] != "true") {
+ $sql = "select ";
+ $sql .= " dialplan_uuid, ";
+ $sql .= " fifo_uuid, ";
+ $sql .= " fifo_name, ";
+ $sql .= " fifo_extension, ";
+ $sql .= " fifo_agent_status, ";
+ $sql .= " fifo_agent_queue, ";
+ $sql .= " fifo_music, ";
+ $sql .= " domain_uuid, ";
+ $sql .= " fifo_order, ";
+ $sql .= " cast(fifo_enabled as text), ";
+ $sql .= " fifo_description ";
+ $sql .= "from v_fifo ";
+ $sql .= "where fifo_uuid = :fifo_uuid ";
+ //$sql .= "and domain_uuid = :domain_uuid ";
+ //$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
+ $parameters['fifo_uuid'] = $fifo_uuid;
+ $database = new database;
+ $row = $database->select($sql, $parameters, 'row');
+ if (is_array($row) && @sizeof($row) != 0) {
+ $dialplan_uuid = $row["dialplan_uuid"];
+ $fifo_name = $row["fifo_name"];
+ $fifo_extension = $row["fifo_extension"];
+ $fifo_agent_status = $row["fifo_agent_status"];
+ $fifo_agent_queue = $row["fifo_agent_queue"];
+ $fifo_music = $row["fifo_music"];
+ $domain_uuid = $row["domain_uuid"];
+ $fifo_order = $row["fifo_order"];
+ $fifo_enabled = $row["fifo_enabled"];
+ $fifo_description = $row["fifo_description"];
+ }
+ unset($sql, $parameters, $row);
+ }
+
+//get the child data
+ if (is_uuid($fifo_uuid)) {
+ $sql = "select ";
+ $sql .= " fifo_member_uuid, ";
+ $sql .= " member_contact, ";
+ $sql .= " member_call_timeout, ";
+ //$sql .= " member_simultaneous, ";
+ $sql .= " member_wrap_up_time, ";
+ $sql .= " cast(member_enabled as text) ";
+ $sql .= "from v_fifo_members ";
+ $sql .= "where fifo_uuid = :fifo_uuid ";
+ //$sql .= "and domain_uuid = '".$domain_uuid."' ";
+ //$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
+ $parameters['fifo_uuid'] = $fifo_uuid;
+ $database = new database;
+ $fifo_members = $database->select($sql, $parameters, 'all');
+ unset ($sql, $parameters);
+ }
+
+//add a uuid to dialplan_uuid if it is empty
+ if (empty($dialplan_uuid) && !is_uuid($dialplan_uuid)) {
+ $dialplan_uuid = uuid();
+ }
+
+//add the $fifo_member_uuid
+ if (!is_uuid($fifo_member_uuid)) {
+ $fifo_member_uuid = uuid();
+ }
+
+//add an empty row
+ $x = is_array($fifo_members) ? count($fifo_members) : 0;
+ $fifo_members[$x]['domain_uuid'] = $_SESSION['domain_uuid'];
+ $fifo_members[$x]['fifo_uuid'] = $fifo_uuid;
+ $fifo_members[$x]['fifo_member_uuid'] = uuid();
+ $fifo_members[$x]['member_contact'] = '';
+ $fifo_members[$x]['member_call_timeout'] = '';
+ //$fifo_members[$x]['member_simultaneous'] = '';
+ $fifo_members[$x]['member_wrap_up_time'] = '';
+ $fifo_members[$x]['member_enabled'] = '';
+
+//create token
+ $object = new token;
+ $token = $object->create($_SERVER['PHP_SELF']);
+
+//initialize the destinations object
+ $destination = new destinations;
+
+//set the defaults
+ if (empty($fifo_order)) {
+ $fifo_order = 50;
+ }
+ if (!isset($fifo_enabled)) {
+ // $fifo_enabled = true;
+ }
+
+//show the header
+ $document['title'] = $text['title-fifo'];
+ require_once "resources/header.php";
+
+//show the content
+ echo "";
+
+//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/fifo.php
new file mode 100644
index 0000000000..4c9b789e6d
--- /dev/null
+++ b/app/fifo/resources/fifo.php
@@ -0,0 +1,242 @@
+app_name = 'fifo';
+ $this->app_uuid = '16589224-c876-aeb3-f59f-523a1c0801f7';
+ $this->name = 'fifo';
+ $this->table = 'fifo';
+ $this->toggle_field = 'fifo_enabled';
+ $this->toggle_values = ['true','false'];
+ $this->description_field = 'fifo_description';
+ $this->location = 'fifo.php';
+ }
+
+ /**
+ * 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);
+ }
+ }
+
+ /**
+ * delete rows from the database
+ */
+ public function delete($records) {
+ if (permission_exists($this->name.'_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->location);
+ exit;
+ }
+
+ //delete multiple records
+ if (is_array($records) && @sizeof($records) != 0) {
+ //build the delete array
+ $x = 0;
+ foreach ($records as $record) {
+ //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'];
+ }
+
+ //increment the id
+ $x++;
+ }
+
+ //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);
+
+ //set message
+ message::add($text['message-delete']);
+ }
+ unset($records);
+ }
+ }
+ }
+
+ /**
+ * toggle a field between two values
+ */
+ public function toggle($records) {
+ if (permission_exists($this->name.'_edit')) {
+
+ //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->location);
+ exit;
+ }
+
+ //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'])) {
+ $uuids[] = "'".$record['uuid']."'";
+ }
+ }
+ if (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) ";
+ $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) {
+ $states[$row['uuid']] = $row['toggle'];
+ }
+ }
+ unset($sql, $parameters, $rows, $row);
+ }
+
+ //build update array
+ $x = 0;
+ 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];
+
+ //increment the id
+ $x++;
+ }
+
+ //save the changes
+ if (is_array($array) && @sizeof($array) != 0) {
+ //save the array
+ $database = new database;
+ $database->app_name = $this->app_name;
+ $database->app_uuid = $this->app_uuid;
+ $database->save($array);
+ unset($array);
+
+ //set message
+ message::add($text['message-toggle']);
+ }
+ unset($records, $states);
+ }
+ }
+ }
+
+ /**
+ * copy rows from the database
+ */
+ public function copy($records) {
+ if (permission_exists($this->name.'_add')) {
+
+ //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->location);
+ exit;
+ }
+
+ //copy the checked records
+ if (is_array($records) && @sizeof($records) != 0) {
+
+ //get checked records
+ foreach($records as $record) {
+ if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
+ $uuids[] = "'".$record['uuid']."'";
+ }
+ }
+
+ //create the array from existing data
+ if (is_array($uuids) && @sizeof($uuids) != 0) {
+ $sql = "select * from v_".$this->table." ";
+ $sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
+ $sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
+ $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) {
+ //copy data
+ $array[$this->table][$x] = $row;
+
+ //add copy to the description
+ $array[$this->table][$x][$this->name.'_uuid'] = uuid();
+ $array[$this->table][$x][$this->description_field] = trim($row[$this->description_field]).' ('.$text['label-copy'].')';
+
+ //increment the id
+ $x++;
+ }
+ }
+ unset($sql, $parameters, $rows, $row);
+ }
+
+ //save the changes and set the message
+ if (is_array($array) && @sizeof($array) != 0) {
+ //save the array
+ $database = new database;
+ $database->app_name = $this->app_name;
+ $database->app_uuid = $this->app_uuid;
+ $database->save($array);
+ unset($array);
+
+ //set message
+ message::add($text['message-copy']);
+ }
+ unset($records);
+ }
+ }
+ }
+
+ }
+}
+
+?>
\ No newline at end of file