From 6b34a635eddfdd806434f9eb5e0b7375b43b27c4 Mon Sep 17 00:00:00 2001 From: Mafoo Date: Thu, 8 Jun 2017 16:35:36 +0100 Subject: [PATCH] NewApp [master] - number_translation (#2649) * NewApp - number_translation allows management of mod_translate profiles automatically importing existing configuration on app_defaults where the configuration file is not marked as autogenerated. import from separate files for presets * Russian translations for number_translation * German, Austrian and Swiss translations for number_translation --- app/number_translation/app_config.php | 114 +++++ app/number_translation/app_defaults.php | 79 ++++ app/number_translation/app_languages.php | 163 ++++++++ app/number_translation/app_menu.php | 29 ++ app/number_translation/cmd.php | 68 +++ .../number_translation_delete.php | 99 +++++ .../number_translation_detail_delete.php | 68 +++ .../number_translation_edit.php | 394 ++++++++++++++++++ .../number_translations.php | 241 +++++++++++ .../resources/classes/number_translation.php | 178 ++++++++ .../GB_national_to_e164.xml | 6 + .../e164_to_GB_national.xml | 6 + .../remove_leading_plus.xml | 3 + app/number_translation/root.php | 90 ++++ 14 files changed, 1538 insertions(+) create mode 100644 app/number_translation/app_config.php create mode 100644 app/number_translation/app_defaults.php create mode 100644 app/number_translation/app_languages.php create mode 100644 app/number_translation/app_menu.php create mode 100644 app/number_translation/cmd.php create mode 100644 app/number_translation/number_translation_delete.php create mode 100644 app/number_translation/number_translation_detail_delete.php create mode 100644 app/number_translation/number_translation_edit.php create mode 100644 app/number_translation/number_translations.php create mode 100644 app/number_translation/resources/classes/number_translation.php create mode 100644 app/number_translation/resources/switch/conf/number_translation/GB_national_to_e164.xml create mode 100644 app/number_translation/resources/switch/conf/number_translation/e164_to_GB_national.xml create mode 100644 app/number_translation/resources/switch/conf/number_translation/remove_leading_plus.xml create mode 100644 app/number_translation/root.php diff --git a/app/number_translation/app_config.php b/app/number_translation/app_config.php new file mode 100644 index 0000000000..54fbd92bd7 --- /dev/null +++ b/app/number_translation/app_config.php @@ -0,0 +1,114 @@ + \ No newline at end of file diff --git a/app/number_translation/app_defaults.php b/app/number_translation/app_defaults.php new file mode 100644 index 0000000000..26b89f1aa9 --- /dev/null +++ b/app/number_translation/app_defaults.php @@ -0,0 +1,79 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2017 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Matthew Vale +*/ + + if ($domains_processed == 1) { + //get the array of xml files + $xml_list = glob($_SERVER["PROJECT_ROOT"] . "/*/*/resources/switch/conf/number_translation/*.xml"); + + //number_translation class + $number_translation = new number_translation; + + //process the xml files + foreach ($xml_list as &$xml_file) { + //get and parse the xml + $number_translation->display_type = $display_type; + $number_translation->xml = file_get_contents($xml_file); + $number_translation->import(); + } + + //check for existing configuration + if (file_exists($_SESSION['switch']['conf']['dir']."/autoload_configs/translate.conf.xml")) { + //import existing data + $xml = file_get_contents($_SESSION['switch']['conf']['dir']."/autoload_configs/translate.conf.xml"); + //convert the xml string to an xml object + $xml = simplexml_load_string($xml); + //convert to json + $json = json_encode($xml); + //convert to an array + $number_translations = json_decode($json, true); + if (array_key_exists('include', $number_translations)) { + $number_translations = $number_translations['include']; + } + if ($number_translations['configuration']['@attributes']['autogenerated'] != 'true') { + foreach ($number_translations['configuration']['profiles']['profile'] as $profile) { + $json = json_encode($profile); + $number_translation->display_type = $display_type; + $number_translation->json = $json; + $number_translation->import(); + } + } + } + + //regenerate and reload + $number_translation->xml(); + //create the event socket connection + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + if ($fp) { + event_socket_request($fp, 'api reloadxml'); + event_socket_request($fp, 'api reload mod_translate'); + } + elseif ($display_type == 'text') { + echo "Failed to connect to event socket"; + } + unset($fp); + } + +?> diff --git a/app/number_translation/app_languages.php b/app/number_translation/app_languages.php new file mode 100644 index 0000000000..df8a2f4c82 --- /dev/null +++ b/app/number_translation/app_languages.php @@ -0,0 +1,163 @@ + \ No newline at end of file diff --git a/app/number_translation/app_menu.php b/app/number_translation/app_menu.php new file mode 100644 index 0000000000..5de36ce633 --- /dev/null +++ b/app/number_translation/app_menu.php @@ -0,0 +1,29 @@ + \ No newline at end of file diff --git a/app/number_translation/cmd.php b/app/number_translation/cmd.php new file mode 100644 index 0000000000..ead9257cc4 --- /dev/null +++ b/app/number_translation/cmd.php @@ -0,0 +1,68 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2017 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Matthew Vale +*/ + +include "root.php"; +require_once "resources/require.php"; +require_once "resources/check_auth.php"; +if (!if_group("superadmin")) { + echo "access denied"; + exit; +} + +//set the variables + $cmd = check_str($_GET['cmd']); + $rdr = check_str($_GET['rdr']); + +//create the event socket connection + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + if ($fp) { + + //reloadxml + if ($cmd == "api reloadxml") { + messages::add(rtrim(event_socket_request($fp, $cmd)), 'alert'); + unset($cmd); + } + + //reload mod_translate + if ($cmd == "api reload mod_translate") { + messages::add(rtrim(event_socket_request($fp, $cmd)), 'alert'); + unset($cmd); + } + + //close the connection + fclose($fp); + } + +//redirect the user + if ($rdr == "false") { + //redirect false + echo $response; + } + else { + header("Location: number_translations.php"); + } + +?> \ No newline at end of file diff --git a/app/number_translation/number_translation_delete.php b/app/number_translation/number_translation_delete.php new file mode 100644 index 0000000000..d8dc3853fa --- /dev/null +++ b/app/number_translation/number_translation_delete.php @@ -0,0 +1,99 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2017 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Matthew Vale +*/ + +include "root.php"; +require_once "resources/require.php"; +require_once "resources/check_auth.php"; +if (!permission_exists('number_translation_delete')) { + echo "access denied"; + exit; +} + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//set the number_translation uuid + $number_translation_uuids = $_REQUEST["id"]; + $app_uuid = check_str($_REQUEST['app_uuid']); + +//delete the number_translations + if (sizeof($number_translation_uuids) > 0) { + + //get number_translation contexts + foreach ($number_translation_uuids as $number_translation_uuid) { + //check each + $number_translation_uuid = check_str($number_translation_uuid); + + //get the number_translation data + $sql = "select * from v_number_translations "; + $sql .= "where number_translation_uuid = '".$number_translation_uuid."' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + foreach ($result as &$row) { + $database_number_translation_uuid = $row["number_translation_uuid"]; + $number_translation_contexts[] = $row["number_translation_context"]; + } + unset($prep_statement); + } + + //start the atomic transaction + $db->beginTransaction(); + + //delete number_translation and details + $number_translations_deleted = 0; + foreach ($number_translation_uuids as $number_translation_uuid) { + + //delete child data + $sql = "delete from v_number_translation_details "; + $sql .= "where number_translation_uuid = '".$number_translation_uuid."'; "; + $db->query($sql); + unset($sql); + + //delete parent data + $sql = "delete from v_number_translations "; + $sql .= "where number_translation_uuid = '".$number_translation_uuid."'; "; + $db->query($sql); + unset($sql); + + $number_translations_deleted++; + } + + //commit the atomic transaction + $db->commit(); + + //update the number_translation xml + $number_translations = new number_translation; + $number_translations->xml(); + + } + +//redirect the browser + $_SESSION["message"] = $text['message-delete'].(($number_translations_deleted > 1) ? ": ".$number_translations_deleted : null); + header("Location: ".PROJECT_PATH."/app/number_translation/number_translations.php".(($app_uuid != '') ? "?app_uuid=".$app_uuid : null)); + +?> \ No newline at end of file diff --git a/app/number_translation/number_translation_detail_delete.php b/app/number_translation/number_translation_detail_delete.php new file mode 100644 index 0000000000..f6957e0729 --- /dev/null +++ b/app/number_translation/number_translation_detail_delete.php @@ -0,0 +1,68 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2017 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Matthew Vale +*/ + +//includes + include "root.php"; + require_once "resources/require.php"; + require_once "resources/check_auth.php"; + +//check permissions + if (!permission_exists('number_translation_delete')) { + echo "access denied"; + exit; + } + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//set the variables + if (count($_GET) > 0) { + $number_translation_detail_uuid = check_str($_GET["id"]); + $number_translation_uuid = check_str($_REQUEST["number_translation_uuid"]); + } + +//delete the number_translation detail + if (strlen($number_translation_detail_uuid) > 0) { + //delete child data + $sql = "delete from v_number_translation_details "; + $sql .= "where number_translation_detail_uuid = '$number_translation_detail_uuid' "; + $db->query($sql); + unset($sql); + + //update the number_translation xml + $number_translations = new number_translation; + $number_translations->xml(); + } + +//save the message to a session variable + $_SESSION['message'] = $text['message-delete']; + +//redirect the browser + header("Location: number_translation_edit.php?id=$number_translation_uuid"); + exit; + +?> diff --git a/app/number_translation/number_translation_edit.php b/app/number_translation/number_translation_edit.php new file mode 100644 index 0000000000..f0587f3332 --- /dev/null +++ b/app/number_translation/number_translation_edit.php @@ -0,0 +1,394 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2017 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Matthew Vale +*/ + +//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('number_translation_add') || permission_exists('number_translation_edit') ) { + //access granted + } + else { + echo "access denied"; + exit; + } + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//set the action as an add or an update + if (is_uuid($_REQUEST["id"])) { + $action = "update"; + $number_translation_uuid = $_REQUEST["id"]; + } + else { + $action = "add"; + } + if (strlen($_REQUEST["app_uuid"]) > 0) { + $app_uuid = $_REQUEST["app_uuid"]; + } + +//get the http post values and set them as php variables + if (count($_POST) > 0) { + $hostname = check_str($_POST["hostname"]); + $number_translation_name = check_str($_POST["number_translation_name"]); + $number_translation_enabled = check_str($_POST["number_translation_enabled"]); + $number_translation_description = check_str($_POST["number_translation_description"]); + } + +//process and save the data + if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { + + //get the number_translation uuid + if ($action == "update") { + $number_translation_uuid = check_str($_POST["number_translation_uuid"]); + } + + //check for all required data + $msg = ''; + if (strlen($number_translation_name) == 0) { $msg .= $text['message-required'].$text['label-name']."
\n"; } + if (strlen($number_translation_enabled) == 0) { $msg .= $text['message-required'].$text['label-enabled']."
\n"; } + //if (strlen($number_translation_description) == 0) { $msg .= $text['message-required'].$text['label-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; + } + + //remove the invalid characters from the number_translation name + $number_translation_name = $_POST["number_translation_name"]; + $number_translation_name = str_replace(" ", "_", $number_translation_name); + $number_translation_name = str_replace("/", "", $number_translation_name); + + //build the array + $x = 0; + if (isset($_POST["number_translation_uuid"])) { + $array['number_translations'][$x]['number_translation_uuid'] = $_POST["number_translation_uuid"]; + } + $array['number_translations'][$x]['number_translation_name'] = $number_translation_name; + $array['number_translations'][$x]['number_translation_enabled'] = $_POST["number_translation_enabled"]; + $array['number_translations'][$x]['number_translation_description'] = $_POST["number_translation_description"]; + $y = 0; + if (is_array($_POST["number_translation_details"])) { + foreach ($_POST["number_translation_details"] as $row) { + if (strlen($row["number_translation_detail_regex"]) > 0) { + if (strlen($row["number_translation_detail_uuid"]) > 0) { + $array['number_translations'][$x]['number_translation_details'][$y]['number_translation_detail_uuid'] = $row["number_translation_detail_uuid"]; + }else{ + $array['number_translations'][$x]['number_translation_details'][$y]['number_translation_uuid'] = $_POST["number_translation_uuid"]; + } + $array['number_translations'][$x]['number_translation_details'][$y]['number_translation_detail_regex'] = $row["number_translation_detail_regex"]; + $array['number_translations'][$x]['number_translation_details'][$y]['number_translation_detail_replace'] = $row["number_translation_detail_replace"]; + $array['number_translations'][$x]['number_translation_details'][$y]['number_translation_detail_order'] = $row["number_translation_detail_order"]; + } + $y++; + } + } + + //add or update the database + if ($_POST["persistformvar"] != "true") { + $permissions = new permissions; + $permissions->add('number_translation_detail_add', 'temp'); + $permissions->add('number_translation_detail_edit', 'temp'); + $database = new database; + $database->app_name = 'number_translations'; + $database->save($array); + $permissions->delete('number_translation_detail_add', 'temp'); + $permissions->delete('number_translation_detail_edit', 'temp'); + if ($database->message['code'] != '200'){ + messages::add('Failed to update record(s), database reported:'.$database->message['message'], 'negative'); + header("Location: ?id=$number_translation_uuid"); + exit; + } + } + + //update the number_translation xml + $number_translations = new number_translation; + $number_translations->xml(); + + //set the message + if ($action == "add") { + $_SESSION['message'] = $text['message-add']; + } + else if ($action == "update") { + $_SESSION['message'] = $text['message-update']; + } + header("Location: ?id=$number_translation_uuid"); + exit; + + } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) + +//pre-populate the form + if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { + $sql = "select * from v_number_translations "; + $sql .= "where number_translation_uuid = '$number_translation_uuid' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + if (is_array($result)) foreach ($result as &$row) { + $domain_uuid = $row["domain_uuid"]; + //$app_uuid = $row["app_uuid"]; + $hostname = $row["hostname"]; + $number_translation_name = $row["number_translation_name"]; + $number_translation_enabled = $row["number_translation_enabled"]; + $number_translation_description = $row["number_translation_description"]; + } + unset ($prep_statement); + } + +//get the number_translation details in an array + $sql = "select * from v_number_translation_details "; + $sql .= "where number_translation_uuid = '$number_translation_uuid' "; + $sql .= "order by number_translation_detail_order asc"; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $results = $prep_statement->fetchAll(PDO::FETCH_NAMED); + $results_count = count($result); + unset ($prep_statement, $sql); + +//show the header + require_once "resources/header.php"; + $document['title'] = $text['title-number_translation_edit']; + +//show the content + echo "
\n"; + echo "\n"; + + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo" ".$text['title-number_translation_edit']."
\n"; + echo "
\n"; + echo " 0) ? "?app_uuid=".$app_uuid : null)."';\" value='".$text['button-back']."'>\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " ".$text['description-number_translation-edit']."\n"; + echo " \n"; + echo "
"; + echo "
\n"; + + echo "\n"; + echo "\n"; + echo ""; + echo ""; + echo ""; + echo "
\n"; + + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " ".$text['label-name']."\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " ".$text['label-hostname']."\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " ".$text['description-hostname']."\n"; + echo "
\n"; + + echo "
\n"; + + echo " \n"; + + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " ".$text['label-enabled']."\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " ".$text['label-description']."\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + + echo "
"; + echo "

"; + + //number_translation details + if ($action == "update") { + ?> + + + 0) { + + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + $x=0; + $results[]['number_translation_uuid'] = $number_translation_uuid; + foreach($results as $index => $row) { + + //get the values from the database and set as variables + $number_translation_detail_uuid = $row['number_translation_detail_uuid']; + $number_translation_detail_regex = $row['number_translation_detail_regex']; + $number_translation_detail_replace = $row['number_translation_detail_replace']; + $number_translation_detail_order = (strlen($row['number_translation_detail_order']) > 0 ? $row['number_translation_detail_order'] : $number_translation_detail_order + 5 ); + + //no border on last row + $no_border = (strlen($number_translation_detail_uuid) == 0) ? "border: none;" : null; + + //begin the row + echo "\n"; + //determine whether to hide the element + if (strlen($number_translation_detail_regex) == 0) { + $element['hidden'] = false; + $element['visibility'] = ""; + } + else { + $element['hidden'] = true; + $element['visibility'] = "display: none;"; + } + //add the primary key uuid + if (strlen($number_translation_detail_uuid) > 0) { + echo " \n"; + } + //regex + echo "\n"; + //replace + echo "\n"; + //order + echo "\n"; + //tools + echo " \n"; + //end the row + echo "\n"; + //increment the value + $x++; + } + unset($sql, $result, $row_count); + + echo "
".$text['label-regex']."".$text['label-replace']."".$text['label-order']." 
\n"; + if ($element['hidden']) { + echo " \n"; + } + echo " \n"; + echo "\n"; + if ($element['hidden']) { + echo " \n"; + } + echo " \n"; + echo "\n"; + if ($element['hidden']) { + echo " \n"; + } + echo " \n"; + echo "\n"; + if ($element['hidden']) { + //echo " $v_link_label_edit\n"; + echo " $v_link_label_delete\n"; + } + echo "
"; + + } //end if results + + } //end if update + + echo "
\n"; + echo "
\n"; + if ($action == "update") { + echo " \n"; + } + echo " \n"; + echo "
\n"; + echo "

\n"; + echo "
"; + + if (file_exists($_SERVER["PROJECT_ROOT"]."/app/billing/app_config.php")){ + echo "

".$text['billing-warning']."

"; + } + +//show the footer + require_once "resources/footer.php"; + +?> diff --git a/app/number_translation/number_translations.php b/app/number_translation/number_translations.php new file mode 100644 index 0000000000..20abeef2d8 --- /dev/null +++ b/app/number_translation/number_translations.php @@ -0,0 +1,241 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2017 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Matthew Vale +*/ + +require_once "root.php"; +require_once "resources/require.php"; + +//check permissions + require_once "resources/check_auth.php"; + if (!permission_exists('number_translation_view')) { + echo "access denied"; + exit; + } + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//handle enable toggle + $number_translation_uuid = check_str($_REQUEST['id']); + $number_translation_enabled = check_str($_REQUEST['enabled']); + if ($number_translation_uuid != '' && $number_translation_enabled != '') { + $array['number_translations'][0]['number_translation_uuid'] = $number_translation_uuid; + $array['number_translations'][0]['number_translation_enabled'] = $number_translation_enabled; + $database = new database; + $database->app_name = 'number_translations'; + $database->save($array); + $number_translation = new number_translation; + $number_translation->xml(); + messages::add($text['message-update']); + unset($array, $number_translation); + } + +//set the http values as php variables + if (isset($_REQUEST["search"])) { $search = check_str($_REQUEST["search"]); } else { $search = null; } + if (isset($_REQUEST["order_by"])) { $order_by = check_str($_REQUEST["order_by"]); } else { $order_by = null; } + if (isset($_REQUEST["order"])) { $order = check_str($_REQUEST["order"]); } else { $order = null; } + +//includes + require_once "resources/header.php"; + require_once "resources/paging.php"; + +//get the number of rows in the number_translation + $sql = "select count(*) as num_rows from v_number_translations "; + $sql .= "where true "; + if (strlen($search) > 0) { + $sql .= "and ("; + $sql .= " number_translation_name like '%".$search."%' "; + $sql .= " or number_translation_description like '%".$search."%' "; + $sql .= ") "; + } + $prep_statement = $db->prepare(check_sql($sql)); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + if ($row['num_rows'] > 0) { + $num_rows = $row['num_rows']; + } + else { + $num_rows = '0'; + } + } + unset($prep_statement, $result); + + $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; + $param = ""; + if (strlen($app_uuid) > 0) { $param = "&app_uuid=".$app_uuid; } + $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); + $offset = $rows_per_page * $page; + +//get the list of number_translations + $sql = "select * from v_number_translations "; + $sql .= "where true "; + if (strlen($search) > 0) { + $sql .= "and ("; + $sql .= " number_translation_name like '%".$search."%' "; + $sql .= " or number_translation_description like '%".$search."%' "; + $sql .= ") "; + } + if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } else { $sql .= "order by number_translation_name asc "; } + $sql .= " limit $rows_per_page offset $offset "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $number_translations = $prep_statement->fetchAll(PDO::FETCH_NAMED); + $result_count = count($number_translations); + unset ($prep_statement, $sql); + +//set the alternating row style + $c = 0; + $row_style["0"] = "row_style0"; + $row_style["1"] = "row_style1"; + +//set the title + $document['title'] = $text['title-number_translation']; + +//show the content + echo "\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + + echo " \n"; + echo " \n"; + echo "\n"; + echo "
\n"; + echo " \n"; + echo " ".$text['header-number_translation']."\n"; + echo " \n"; + echo "

\n"; + echo "
\n"; + echo "
\n"; + echo " "; + if (strlen($order_by) > 0) { + echo " "; + echo " "; + } + echo " "; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo " " . $text['description-number_translation'] . "\n"; + echo " \n"; + echo "
"; + echo "
"; + + echo "
\n"; + echo "\n"; + echo "\n"; + if (permission_exists('number_translation_delete') && $result_count > 0) { + echo ""; + } + echo th_order_by('number_translation_name', $text['label-name'], $order_by, $order, $app_uuid, null, (($search != '') ? "search=".$search : null)); + echo th_order_by('number_translation_enabled', $text['label-enabled'], $order_by, $order, $app_uuid, "style='text-align: center;'", (($search != '') ? "search=".$search : null)); + echo th_order_by('number_translation_description', $text['label-description'], $order_by, $order, $app_uuid, null, (($search != '') ? "search=".$search : null)); + echo "\n"; + echo "\n"; + + if ($result_count > 0) { + foreach($number_translations as $row) { + $tr_link = "href='number_translation_edit.php?id=".$row['number_translation_uuid']."'"; + echo "\n"; + if (permission_exists("number_translation_delete")) { + echo " \n"; + $number_translation_ids[] = 'checkbox_'.$row['number_translation_uuid']; + } + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "\n"; + if ($c==0) { $c=1; } else { $c=0; } + } //end foreach + unset($sql, $result, $row_count); + } //end if results + + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
"; + if (permission_exists('number_translation_delete') && $result_count > 0) { + echo "".$v_link_label_delete.""; + } + echo "
"; + echo $row['number_translation_name']; + echo " ".((strlen($row['number_translation_description']) > 0) ? $row['number_translation_description'] : " ")."\n"; + if (permission_exists('number_translation_edit')) { + echo " $v_link_label_edit"; + } + if (permission_exists('number_translation_delete')) { + echo " $v_link_label_delete"; + } + echo "
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
 ".$paging_controls.""; + if (permission_exists('number_translation_edit')) { + echo " $v_link_label_add"; + } + if (permission_exists('number_translation_delete') && $result_count > 0) { + echo " ".$v_link_label_delete.""; + } + echo "
\n"; + echo "
"; + echo "

"; + echo "
"; + + if (sizeof($number_translation_ids) > 0) { + echo "\n"; + } + +//include the footer + require_once "resources/footer.php"; + +//unset the variables + unset ($result_count); + unset ($result); + unset ($key); + unset ($val); + unset ($c); + +?> \ No newline at end of file diff --git a/app/number_translation/resources/classes/number_translation.php b/app/number_translation/resources/classes/number_translation.php new file mode 100644 index 0000000000..4c1cc43704 --- /dev/null +++ b/app/number_translation/resources/classes/number_translation.php @@ -0,0 +1,178 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2017 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Matthew Vale +*/ +include "root.php"; + +//define the number_translation class + if (!class_exists('number_translation')) { + class number_translation { + //variables + public $db; + public $xml; + public $json; + public $display_type; + + //class constructor + public function __construct() { + //connect to the database if not connected + if (!$this->db) { + require_once "resources/classes/database.php"; + $database = new database; + $database->connect(); + $this->db = $database->db; + } + + } + + public function number_translation_exists($name) { + $sql = "select number_translation_uuid from v_number_translations "; + $sql .= "where number_translation_name = '$name' "; + $prep_statement = $this->db->prepare(check_sql($sql)); + if ($prep_statement) { + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); + if (count($result)) { + return true; + } + else { + return false; + } + } + unset($sql, $prep_statement, $result); + } + + public function import() { + if (strlen($this->xml) > 0) { + //convert the xml string to an xml object + $xml = simplexml_load_string($this->xml); + //convert to json + $json = json_encode($xml); + //convert to an array + $number_translation = json_decode($json, true); + } + elseif (strlen($this->json) > 0) { + //convert to an array + $number_translation = json_decode($this->json, true); + } + else { + throw new Exception("require either json or xml to import"); + } + //check if the number_translation exists + if (!$this->number_translation_exists($number_translation['@attributes']['name'])) { + $permissions = new permissions; + $permissions->add('number_translation_add', 'temp'); + $permissions->add('number_translation_detail_add', 'temp'); + $x=0; + $array['number_translations'][$x]['number_translation_name'] = $number_translation['@attributes']['name']; + $array['number_translations'][$x]['number_translation_enabled'] = "true"; + if (strlen($number_translation['@attributes']['enabled']) > 0) { + $array['number_translations'][$x]['number_translation_enabled'] = $number_translation['@attributes']['enabled']; + } + $array['number_translations'][$x]['number_translation_description'] = $number_translation['@attributes']['description']; + + //loop through the condition array + $order = 5; + if (isset($number_translation['rule'])) { + foreach ($number_translation['rule'] as &$row) { + if(array_key_exists('@attributes', $row)) + $row = $row['@attributes']; + $array['number_translations'][$x]['number_translation_details'][$order]['number_translation_detail_regex'] = $row['regex']; + $array['number_translations'][$x]['number_translation_details'][$order]['number_translation_detail_replace'] = $row['replace']; + $array['number_translations'][$x]['number_translation_details'][$order]['number_translation_detail_order'] = $order; + $order = $order + 5; + } + } + $database = new database; + $database->app_name = 'number_translations'; + $database->save($array); + if ($this->display_type == "text") { + if ($database->message['code'] != '200') { + echo "number_translation:".$number_translation['@attributes']['name'].": failed: ".$database->message['message']."\n"; + } + else { + echo "number_translation:".$number_translation['@attributes']['name'].": added with ".(($order/5)-1)." entries\n"; + } + } + $permissions->delete('number_translation_add', 'temp'); + $permissions->delete('number_translation_detail_add', 'temp'); + } + unset ($this->xml, $this->json); + } + + //reads number_translation details from the database to build the xml + public function xml () { + + $xml = "\n"; + $xml .= ' '."\n"; + $xml .= " \n"; + + $sql = "select * \n"; + $sql .= "from v_number_translations \n"; + $sql .= "order by \n"; + $sql .= "number_translation_name asc \n"; + $prep_statement = $this->db->prepare(check_sql($sql)); + $prep_statement->execute(); + $results = $prep_statement->fetchAll(PDO::FETCH_NAMED); + + foreach ($results as $row) { + $number_translation_uuid = $row["number_translation_uuid"]; + $number_translation_name = $row["number_translation_name"]; + $number_translation_description = $row["number_translation_description"]; + + $xml .= " \n"; + + $sql = "select "; + $sql .= "number_translation_detail_uuid, number_translation_detail_regex, number_translation_detail_replace, number_translation_detail_order \n"; + $sql .= "from v_number_translation_details \n"; + $sql .= "where number_translation_uuid = '$number_translation_uuid' \n"; + $sql .= "order by \n"; + $sql .= "number_translation_detail_order asc \n"; + $prep_statement = $this->db->prepare(check_sql($sql)); + $prep_statement->execute(); + $results = $prep_statement->fetchAll(PDO::FETCH_NAMED); + foreach ($results as $row) { + $number_translation_detail_regex = $row["number_translation_detail_regex"]; + $number_translation_detail_replace = $row["number_translation_detail_replace"]; + + $xml .= " \n"; + } + + $xml .= " \n"; + } + $xml .= " \n"; + $xml .= " \n"; + $xml .= ""; + + $fout = fopen($_SESSION['switch']['conf']['dir']."/autoload_configs/translate.conf.xml","w"); + fwrite($fout, $xml); + unset($xml); + fclose($fout); + + $_SESSION["reload_xml"] = true; + } + } // end class + } // class_exists + +?> diff --git a/app/number_translation/resources/switch/conf/number_translation/GB_national_to_e164.xml b/app/number_translation/resources/switch/conf/number_translation/GB_national_to_e164.xml new file mode 100644 index 0000000000..3e13275979 --- /dev/null +++ b/app/number_translation/resources/switch/conf/number_translation/GB_national_to_e164.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/number_translation/resources/switch/conf/number_translation/e164_to_GB_national.xml b/app/number_translation/resources/switch/conf/number_translation/e164_to_GB_national.xml new file mode 100644 index 0000000000..25e59a1d20 --- /dev/null +++ b/app/number_translation/resources/switch/conf/number_translation/e164_to_GB_national.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/number_translation/resources/switch/conf/number_translation/remove_leading_plus.xml b/app/number_translation/resources/switch/conf/number_translation/remove_leading_plus.xml new file mode 100644 index 0000000000..b1614cff71 --- /dev/null +++ b/app/number_translation/resources/switch/conf/number_translation/remove_leading_plus.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/app/number_translation/root.php b/app/number_translation/root.php new file mode 100644 index 0000000000..6fdf32f37b --- /dev/null +++ b/app/number_translation/root.php @@ -0,0 +1,90 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +// make sure the PATH_SEPARATOR is defined + umask(2); + if (!defined("PATH_SEPARATOR")) { + if (strpos($_ENV["OS"], "Win") !== false) { + define("PATH_SEPARATOR", ";"); + } else { + define("PATH_SEPARATOR", ":"); + } + } + + if (!isset($output_format)) $output_format = (PHP_SAPI == 'cli') ? 'text' : 'html'; + + // make sure the document_root is set + $_SERVER["SCRIPT_FILENAME"] = str_replace("\\", '/', $_SERVER["SCRIPT_FILENAME"]); + if(PHP_SAPI == 'cli'){ + chdir(pathinfo(realpath($_SERVER["PHP_SELF"]), PATHINFO_DIRNAME)); + $script_full_path = str_replace("\\", '/', getcwd() . '/' . $_SERVER["SCRIPT_FILENAME"]); + $dirs = explode('/', pathinfo($script_full_path, PATHINFO_DIRNAME)); + if (file_exists('/project_root.php')) { + $path = '/'; + } else { + $i = 1; + $path = ''; + while ($i < count($dirs)) { + $path .= '/' . $dirs[$i]; + if (file_exists($path. '/project_root.php')) { + break; + } + $i++; + } + } + $_SERVER["DOCUMENT_ROOT"] = $path; + }else{ + $_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]); + } + $_SERVER["DOCUMENT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"]); +// try to detect if a project path is being used + if (!defined('PROJECT_PATH')) { + if (is_dir($_SERVER["DOCUMENT_ROOT"]. '/fusionpbx')) { + define('PROJECT_PATH', '/fusionpbx'); + } elseif (file_exists($_SERVER["DOCUMENT_ROOT"]. '/project_root.php')) { + define('PROJECT_PATH', ''); + } else { + $dirs = explode('/', str_replace('\\', '/', pathinfo($_SERVER["PHP_SELF"], PATHINFO_DIRNAME))); + $i = 1; + $path = $_SERVER["DOCUMENT_ROOT"]; + while ($i < count($dirs)) { + $path .= '/' . $dirs[$i]; + if (file_exists($path. '/project_root.php')) { + break; + } + $i++; + } + if(!file_exists($path. '/project_root.php')){ + die("Failed to locate the Project Root by searching for project_root.php please contact support for assistance"); + } + $project_path = str_replace($_SERVER["DOCUMENT_ROOT"], "", $path); + define('PROJECT_PATH', $project_path); + } + $_SERVER["PROJECT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH); + set_include_path(get_include_path() . PATH_SEPARATOR . $_SERVER["PROJECT_ROOT"]); + } + +?> \ No newline at end of file