From a05db79b3766041ed286ee1bb9f73f89a66c102a Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Sun, 9 Jul 2017 23:52:34 -0600 Subject: [PATCH] Update app_defaults.php --- app/vars/app_defaults.php | 221 ++++++++++++-------------------------- 1 file changed, 68 insertions(+), 153 deletions(-) diff --git a/app/vars/app_defaults.php b/app/vars/app_defaults.php index 6fa6c4ca7c..d03a537344 100644 --- a/app/vars/app_defaults.php +++ b/app/vars/app_defaults.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2012 + Portions created by the Initial Developer are Copyright (C) 2008-2017 the Initial Developer. All Rights Reserved. Contributor(s): @@ -26,51 +26,71 @@ if ($domains_processed == 1) { -//create a json string -$vars = <<prepare(check_sql($sql)); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + if ($row['num_rows'] == 0) { + //get the xml + if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf/vars.xml')) { + $xml_file = '/usr/share/examples/fusionpbx/resources/templates/conf/vars.xml'; + } + elseif (file_exists('/usr/local/share/fusionpbx/resources/templates/conf/vars.xml')) { + $xml_file = '/usr/local/share/fusionpbx/resources/templates/conf/vars.xml'; + } + else { + $xml_file = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/conf/vars.xml'; + } + + //load the xml and save it into an array + $xml_string = file_get_contents($xml_file); + $xml = simplexml_load_string($xml_string); + $json = json_encode($xml); + $variables = json_decode($json, true); + // + $x = 0; + foreach ($variables['X-PRE-PROCESS'] as $variable) { + $cmd = $variable['@attributes']['cmd']; + + $data = explode('=', $variable['@attributes']['data']); + $var_name = $data[0]; + $var_value = $data[1]; + + $var_cat = $variable['@attributes']['category']; + $var_enabled = $variable['@attributes']['enabled']; + $var_order = ''; + $var_description = ''; + + $array['vars'][$x]['var_uuid'] = uuid(); + $array['vars'][$x]['var_name'] = $var_name; + $array['vars'][$x]['var_value'] = $var_value; + $array['vars'][$x]['var_cat'] = $var_cat; + $array['vars'][$x]['var_enabled'] = $var_enabled; + $array['vars'][$x]['var_order'] = $var_order; + $array['vars'][$x]['var_description'] = $var_description; + $x++; + } + + //add the dialplan permission + $p = new permissions; + $p->add("var_add", "temp"); + $p->add("var_edit", "temp"); + + //save to the data + $database = new database; + $database->app_name = 'vars'; + $database->app_uuid = '54e08402-c1b8-0a9d-a30a-f569fc174dd8'; + $database->save($array); + $message = $database->message; + + //remove the temporary permission + $p->delete("var_add", "temp"); + $p->delete("var_edit", "temp"); + + } + } // Set country depend variables as country code and international direct dialing code (exit code) if (!function_exists('set_country_vars')) { @@ -208,117 +228,11 @@ EOD; $x++; } } - unset($prep_statement, $sql); - - unset($countries); + unset($prep_statement, $sql, $countries); } } } - //import default variables - $result = json_decode($vars, true); - - //import ringtones from vars.xml - $vars_xml = simplexml_load_file($_SERVER["PROJECT_ROOT"] . "/resources/templates/conf/vars.xml"); - foreach($vars_xml->{'X-PRE-PROCESS'} as $item) { - if($item->attributes()->cmd == 'set') { - $value = explode('=', $item->attributes()->data, 2); - if(preg_match("/-ring/", $value[0])){ - $row = Array(); - $row['var_cat'] = 'Ringtones'; - $row['var_name'] = $value[0]; - $row['var_value'] = $value[1]; - $row['var_enabled'] = $item->attributes()->enabled; - if(!isset($row['var_enabled'])){ - $row['var_enabled'] = 'true'; - } - $row['var_description'] = $item->attributes()->description; - if(!isset($row['var_description'])){ - $row['var_description'] = base64_encode('Imported from vars.xml'); - } - $result[] = $row; - } - elseif(preg_match("/-tone/", $value[0])){ - $row = Array(); - $row['var_cat'] = 'Tones'; - $row['var_name'] = $value[0]; - $row['var_value'] = $value[1]; - $row['var_enabled'] = $item->attributes()->enabled; - if(!isset($row['var_enabled'])){ - $row['var_enabled'] = 'true'; - } - $row['var_description'] = $item->attributes()->description; - if(!isset($row['var_description'])){ - $row['var_description'] = base64_encode('Imported from vars.xml'); - } - $result[] = $row; - } - } - } - - //migrate old ringtones - $sql = "update v_vars "; - $sql .= "set var_cat = 'Ringtones' "; - $sql .= "where var_name like '%-ring' "; - $sql .= "and var_cat = 'Defaults' "; - $sql .= "and var_description = '' "; - $prep_statement = $db->prepare(check_sql($sql)); - if ($prep_statement) { - $prep_statement->execute(); - } - - $sql = "update v_vars "; - $sql .= "set var_cat = 'Ringtones' "; - $sql .= "where var_name like '%-ring' "; - $sql .= "and var_cat = 'Defaults' "; - $prep_statement = $db->prepare(check_sql($sql)); - if ($prep_statement) { - $prep_statement->execute(); - } - unset($prep_statement, $sql); - - //add missing variables - $x = 1; - foreach($result as $row) { - - $sql = "select count(*) as num_rows from v_vars "; - $sql .= "where var_name = '".$row['var_name']."' "; - $sql .= "and var_cat = '".$row['var_cat']."' "; - $prep_statement = $db->prepare(check_sql($sql)); - if ($prep_statement) { - $prep_statement->execute(); - $row2 = $prep_statement->fetch(PDO::FETCH_ASSOC); - if ($row2['num_rows'] == 0) { - - $sql = "insert into v_vars "; - $sql .= "("; - $sql .= "var_uuid, "; - $sql .= "var_name, "; - $sql .= "var_value, "; - $sql .= "var_cat, "; - $sql .= "var_enabled, "; - $sql .= "var_order, "; - $sql .= "var_description "; - $sql .= ") "; - $sql .= "values "; - $sql .= "("; - $sql .= "'".uuid()."', "; - $sql .= "'".$row['var_name']."', "; - $sql .= "'".$row['var_value']."', "; - $sql .= "'".$row['var_cat']."', "; - $sql .= "'".$row['var_enabled']."', "; - $sql .= "'".$x."', "; - $sql .= "'".$row['var_description']."' "; - $sql .= ");"; - $db->exec($sql); - unset($sql); - $x++; - } - } - unset($prep_statement, $row2); - } - unset($result, $row); - //adjust the variables required variables //set variables that depend on the number of domains if (count($_SESSION['domains']) > 1) { @@ -371,4 +285,5 @@ EOD; //save the vars.xml file save_var_xml(); } + ?>