diff --git a/app/vars/app_languages.php b/app/vars/app_languages.php index 74add23b85..4ef7075cea 100644 --- a/app/vars/app_languages.php +++ b/app/vars/app_languages.php @@ -221,25 +221,25 @@ $text['header-variables']['ru-ru'] = "Параметры FreeSwitch"; $text['header-variables']['sv-se'] = "Switch Variabler"; $text['header-variables']['uk-ua'] = "Задання змінних"; -$text['header-variable_edit']['en-us'] = "Variable"; -$text['header-variable_edit']['ar-eg'] = ""; -$text['header-variable_edit']['de-at'] = "Variable"; //copied from de-de -$text['header-variable_edit']['de-ch'] = "Variable"; //copied from de-de -$text['header-variable_edit']['de-de'] = "Variable"; -$text['header-variable_edit']['es-cl'] = "Editar Variable"; -$text['header-variable_edit']['es-mx'] = "Editar Variable"; //copied from es-cl -$text['header-variable_edit']['fr-ca'] = "Editer la Variable"; //copied from fr-fr -$text['header-variable_edit']['fr-fr'] = "Editer la Variable"; -$text['header-variable_edit']['he-il'] = ""; -$text['header-variable_edit']['it-it'] = "Variabile"; -$text['header-variable_edit']['nl-nl'] = "Variabelen"; -$text['header-variable_edit']['pl-pl'] = "Zmienna"; -$text['header-variable_edit']['pt-br'] = "Editar variável"; //copied from pt-pt -$text['header-variable_edit']['pt-pt'] = "Editar variável"; -$text['header-variable_edit']['ro-ro'] = ""; -$text['header-variable_edit']['ru-ru'] = "Переменная"; -$text['header-variable_edit']['sv-se'] = "Variabel"; -$text['header-variable_edit']['uk-ua'] = "Змінна"; +$text['header-variable']['en-us'] = "Variable"; +$text['header-variable']['ar-eg'] = ""; +$text['header-variable']['de-at'] = "Variable"; //copied from de-de +$text['header-variable']['de-ch'] = "Variable"; //copied from de-de +$text['header-variable']['de-de'] = "Variable"; +$text['header-variable']['es-cl'] = "Editar Variable"; +$text['header-variable']['es-mx'] = "Editar Variable"; //copied from es-cl +$text['header-variable']['fr-ca'] = "Editer la Variable"; //copied from fr-fr +$text['header-variable']['fr-fr'] = "Editer la Variable"; +$text['header-variable']['he-il'] = ""; +$text['header-variable']['it-it'] = "Variabile"; +$text['header-variable']['nl-nl'] = "Variabelen"; +$text['header-variable']['pl-pl'] = "Zmienna"; +$text['header-variable']['pt-br'] = "Editar variável"; //copied from pt-pt +$text['header-variable']['pt-pt'] = "Editar variável"; +$text['header-variable']['ro-ro'] = ""; +$text['header-variable']['ru-ru'] = "Переменная"; +$text['header-variable']['sv-se'] = "Variabel"; +$text['header-variable']['uk-ua'] = "Змінна"; $text['header-hostname']['en-us'] = "Hostname"; $text['header-hostname']['ar-eg'] = ""; diff --git a/app/vars/resources/classes/vars.php b/app/vars/resources/classes/vars.php new file mode 100644 index 0000000000..a02c628bd5 --- /dev/null +++ b/app/vars/resources/classes/vars.php @@ -0,0 +1,273 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2019 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +//define the vars class +if (!class_exists('vars')) { + class vars { + + /** + * 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() { + + //assign private variables + $this->app_name = 'vars'; + $this->app_uuid = '54e08402-c1b8-0a9d-a30a-f569fc174dd8'; + $this->permission_prefix = 'var_'; + $this->list_page = 'vars.php'; + $this->table = 'vars'; + $this->uuid_prefix = 'var_'; + $this->toggle_field = 'var_enabled'; + $this->toggle_values = ['true','false']; + + } + + /** + * 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 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) { + + //build the delete array + foreach ($records as $x => $record) { + if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['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); + + //unset the user defined variables + unset($_SESSION["user_defined_variables"]); + + //rewrite the xml + save_var_xml(); + + //set message + message::add($text['message-delete']); + } + unset($records); + } + } + } + + /** + * toggle records + */ + public function toggle($records) { + if (permission_exists($this->permission_prefix.'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->list_page); + exit; + } + + //toggle the checked records + if (is_array($records) && @sizeof($records) != 0) { + + //get current toggle state + foreach ($records as $x => $record) { + if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + $uuids[] = "'".$record['uuid']."'"; + } + } + if (is_array($uuids) && @sizeof($uuids) != 0) { + $sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." "; + $sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") "; + $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) { + $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid; + $array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0]; + $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); + + //unset the user defined variables + unset($_SESSION["user_defined_variables"]); + + //rewrite the xml + save_var_xml(); + + //set message + message::add($text['message-toggle']); + } + unset($records, $states); + } + + } + } + + /** + * copy records + */ + public function copy($records) { + if (permission_exists($this->permission_prefix.'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->list_page); + exit; + } + + //copy the checked records + if (is_array($records) && @sizeof($records) != 0) { + + //get checked records + foreach ($records as $x => $record) { + if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + $uuids[] = "'".$record['uuid']."'"; + } + } + + //create insert array from existing data + if (is_array($uuids) && @sizeof($uuids) != 0) { + $sql = "select * from v_".$this->table." "; + $sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") "; + $database = new database; + $rows = $database->select($sql, $parameters, 'all'); + if (is_array($rows) && @sizeof($rows) != 0) { + foreach ($rows as $x => $row) { + + //copy data + $array[$this->table][$x] = $row; + + //overwrite + $array[$this->table][$x][$this->uuid_prefix.'uuid'] = uuid(); + $array[$this->table][$x]['var_description'] = trim($row['var_description'].' ('.$text['label-copy'].')'); + + } + } + 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); + + //unset the user defined variables + unset($_SESSION["user_defined_variables"]); + + //rewrite the xml + save_var_xml(); + + //set message + message::add($text['message-copy']); + + } + unset($records); + } + + } + } + + } +} + +?> \ No newline at end of file diff --git a/app/vars/var_edit.php b/app/vars/var_edit.php index 862989302f..61a29c75d9 100644 --- a/app/vars/var_edit.php +++ b/app/vars/var_edit.php @@ -193,12 +193,7 @@ echo "\n"; echo "\n"; - if ($action == "add") { - echo "\n"; - } - if ($action == "update") { - echo "\n"; - } + echo "\n"; echo "
".$text['header-variable_add']."

".$text['header-variable_edit']."

".$text['header-variable']."

"; echo " "; echo " \n"; diff --git a/app/vars/vars.php b/app/vars/vars.php index 93fac99403..c92c9bc520 100644 --- a/app/vars/vars.php +++ b/app/vars/vars.php @@ -23,10 +23,13 @@ Contributor(s): Mark J Crane */ + //includes include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; + require_once "resources/paging.php"; + //check permissions if (permission_exists('var_view')) { @@ -41,167 +44,217 @@ $language = new text; $text = $language->get(); -//toggle enabled state - if (is_uuid($_REQUEST['id']) && (strtolower($_REQUEST['enabled']) == 'true' || strtolower($_REQUEST['enabled']) == 'false')) { - //build array - $array['vars'][0]['var_uuid'] = $_REQUEST['id']; - $array['vars'][0]['var_enabled'] = strtolower($_REQUEST['enabled']); - - //grant temporary permissions - $p = new permissions; - $p->add('var_edit', 'temp'); - - //execute update - $database = new database; - $database->app_name = 'vars'; - $database->app_uuid = '54e08402-c1b8-0a9d-a30a-f569fc174dd8'; - $database->save($array); - unset($array); - - //revoke temporary permissions - $p->delete('var_edit', 'temp'); - - //unset the user defined variables - $_SESSION["user_defined_variables"] = ""; - - //synchronize the configuration - save_var_xml(); - - //set message - message::add($text['message-update']); - - //redirect - header("Location: vars.php?id=".$_REQUEST['id']); - exit; +//get posted data + if (is_array($_POST['vars'])) { + $action = $_POST['action']; + $search = $_POST['search']; + $vars = $_POST['vars']; } -//include the header - require_once "resources/header.php"; - $document['title'] = $text['title-variables']; +//process the http post data by action + if ($action != '' && is_array($vars) && @sizeof($vars) != 0) { + switch ($action) { + case 'copy': + if (permission_exists('var_add')) { + $obj = new vars; + $obj->copy($vars); + } + break; + case 'toggle': + if (permission_exists('var_edit')) { + $obj = new vars; + $obj->toggle($vars); + } + break; + case 'delete': + if (permission_exists('var_delete')) { + $obj = new vars; + $obj->delete($vars); + } + break; + } -//set http values as php variables + header('Location: vars.php'.($search != '' ? '?search='.urlencode($search) : null)); + exit; + } + +//get order and order by $order_by = $_GET["order_by"]; $order = $_GET["order"]; -//show the content - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
".$text['header-variables']."
\n"; - echo " ".$text['description-variables']."\n"; - echo "
\n"; +//add the search string + $search = strtolower($_GET["search"]); + if (strlen($search) > 0) { + $sql_search = "where ("; + $sql_search .= " lower(var_category) like :search "; + $sql_search .= " or lower(var_name) like :search "; + $sql_search .= " or lower(var_value) like :search "; + $sql_search .= " or lower(var_hostname) like :search "; + $sql_search .= " or lower(var_enabled) like :search "; + $sql_search .= " or lower(var_description) like :search "; + $sql_search .= ") "; + $parameters['search'] = '%'.$search.'%'; + } - $sql = "select * from v_vars "; - $sql .= $order_by != '' ? order_by($order_by, $order) : "order by var_category, var_order asc "; +//get the count + $sql = "select count(var_uuid) from v_vars "; + $sql .= $sql_search; $database = new database; - $result = $database->select($sql, null, 'all'); + $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 = $search ? "&search=".$search : null; + $param = $order_by ? "&order_by=".$order_by."&order=".$order : null; + $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 = str_replace('count(var_uuid)', '*', $sql); + $sql .= $order_by != '' ? order_by($order_by, $order) : " order by var_category, var_order asc, var_name asc "; + $sql .= limit_offset($rows_per_page, $offset); + $database = new database; + $vars = $database->select($sql, $parameters, 'all'); unset($sql); - $c = 0; - $row_style["0"] = "row_style0"; - $row_style["1"] = "row_style1"; +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); - echo "\n"; +//include the header + $document['title'] = $text['title-variables']; + require_once "resources/header.php"; - $tmp_var_header = "\n"; - $tmp_var_header .= th_order_by('var_name', $text['label-name'], $order_by, $order); - $tmp_var_header .= th_order_by('var_value', $text['label-value'], $order_by, $order); - $tmp_var_header .= th_order_by('var_hostname', $text['label-hostname'], $order_by, $order); - $tmp_var_header .= th_order_by('var_enabled', $text['label-enabled'], $order_by, $order); - $tmp_var_header .= "\n"; - $tmp_var_header .= "\n"; - $tmp_var_header .= "\n"; + if (permission_exists('var_add') && $vars) { + echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'onclick'=>"if (confirm('".$text['confirm-copy']."')) { list_action_set('copy'); list_form_submit('form_list'); } else { this.blur(); return false; }"]); + } + if (permission_exists('var_edit') && $vars) { + echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'onclick'=>"if (confirm('".$text['confirm-toggle']."')) { list_action_set('toggle'); list_form_submit('form_list'); } else { this.blur(); return false; }"]); + } + if (permission_exists('var_delete') && $vars) { + 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 ""; + echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search','style'=>($search != '' ? 'display: none;' : null)]); + echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'vars.php','style'=>($search == '' ? 'display: none;' : null)]); + if ($paging_controls_mini != '') { + echo "".$paging_controls_mini."\n"; + } + echo " \n"; + echo " \n"; + echo "
\n"; + echo "\n"; - if (is_array($result) && @sizeof($result) != 0) { - $prev_var_category = ''; - foreach($result as $row) { - $var_value = $row['var_value']; - $var_value = substr($var_value, 0, 50); - if ($prev_var_category != $row['var_category']) { - $c=0; - if (strlen($prev_var_category) > 0) { + echo $text['description-variables']."\n"; + echo "

\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
".$text['label-description'].""; +//show the content + echo "
\n"; + echo "
".$text['header-variables']." (".$num_rows.")
\n"; + echo "
\n"; if (permission_exists('var_add')) { - $tmp_var_header .= "$v_link_label_add"; + echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'link'=>'var_edit.php']); } - $tmp_var_header .= "
\n"; + function write_header($modifier) { + global $text, $order_by, $order, $vars; + $modifier = str_replace('/', '', $modifier); + $modifier = str_replace(' ', ' ', $modifier); + $modifier = str_replace(' ', '_', $modifier); + $modifier = str_replace(':', '', $modifier); + $modifier = strtolower(trim($modifier)); + echo "\n"; + echo "\n"; + if (permission_exists('var_edit') || permission_exists('var_delete')) { + echo " \n"; + } + echo th_order_by('var_name', $text['label-name'], $order_by, $order, null, "class='pct-30'"); + echo th_order_by('var_value', $text['label-value'], $order_by, $order, null, "class='pct-40'"); + echo th_order_by('var_hostname', $text['label-hostname'], $order_by, $order, null, "class='hide-sm-dn'"); + echo th_order_by('var_enabled', $text['label-enabled'], $order_by, $order, null, "class='center'"); + echo "\n"; + if (permission_exists('var_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + echo "\n"; + } + echo "\n"; + } + if (is_array($vars) && @sizeof($vars) != 0) { + $previous_category = ''; + foreach ($vars as $x => $row) { + //write category and column headings + if ($previous_category != $row["var_category"]) { echo "\n"; - echo "\n"; echo "\n"; + write_header($row["var_category"]); } - echo "\n"; - echo $tmp_var_header; - } - - $tr_link = (permission_exists('var_edit')) ? "href='var_edit.php?id=".$row['var_uuid']."'" : null; - echo "\n"; - echo " \n"; + if (permission_exists('var_add') || permission_exists('var_edit') || permission_exists('var_delete')) { + $modifier = strtolower(trim($row["var_category"])); + $modifier = str_replace('/', '', $modifier); + $modifier = str_replace(' ', ' ', $modifier); + $modifier = str_replace(' ', '_', $modifier); + $modifier = str_replace(':', '', $modifier); + echo " \n"; + } + echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - $var_description = str_replace("\n", "
", trim(substr(base64_decode($row['var_description']),0,40))); - $var_description = str_replace(" ", "       ", $var_description); - echo " \n"; - echo " \n"; + echo " \n"; if (permission_exists('var_edit')) { - echo "$v_link_label_edit"; + echo " \n"; + echo " \n"; + if (permission_exists('var_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + echo " \n"; + } echo "\n"; - $prev_var_category = $row['var_category']; - $c = $c ? 0 : 1; + $previous_category = $row["var_category"]; + + $x++; } } - unset($result, $row); + unset($vars); - echo "\n"; - echo "\n"; - echo "\n"; - - echo "
\n"; + echo " \n"; + echo " ".$text['label-description']." 
\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
  "; - if (permission_exists('var_add')) { - echo "$v_link_label_add"; - } - echo "
\n"; + echo "
\n"; - echo "
\n"; - echo "
\n"; - echo " ".$row['var_category']." 
"; if (permission_exists('var_edit')) { - echo "".substr($row['var_name'],0,32).""; + $list_row_url = "var_edit.php?id=".urlencode($row['var_uuid']); + } + echo "
\n"; + echo " \n"; + echo " \n"; + echo " "; + if (permission_exists('var_edit')) { + echo "".escape($row['var_name']).""; } else { - echo substr($row['var_name'],0,32); + echo escape($row['var_name']); } echo " ".substr($var_value,0,30)."".$row['var_hostname']." "; - echo " ".(($row['var_enabled'] == 'true') ? $text['option-true'] : $text['option-false']).""; - echo " ".$var_description." "; + echo " ".$row['var_value']."".$row['var_hostname']." \n"; + echo $text['label-'.$row['var_enabled']]; } echo " ".escape($row['var_description'])."\n"; + echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); + echo "
\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
 $paging_controls"; - if (permission_exists('var_add')) { - echo "$v_link_label_add"; - } - echo "
\n"; - echo "
"; - echo "

"; + echo "
\n"; + echo "
\n"; + echo "
".$paging_controls."
\n"; + echo "\n"; + echo "\n"; //include the footer require_once "resources/footer.php"; -?> +?> \ No newline at end of file