From 8881054e891a10df5a350266ed1e25d06a901b4a Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Sat, 23 Dec 2017 23:41:01 -0700 Subject: [PATCH] Update and rename number_translation.php to number_translations.php Completely rewrote classes/number_translation.php and don't need the class xml method because this is handled by the lua xml handler. Import method wasn't used by anything. --- .../resources/classes/number_translation.php | 179 ------------------ .../resources/classes/number_translations.php | 75 ++++++++ 2 files changed, 75 insertions(+), 179 deletions(-) delete mode 100644 app/number_translations/resources/classes/number_translation.php create mode 100644 app/number_translations/resources/classes/number_translations.php diff --git a/app/number_translations/resources/classes/number_translation.php b/app/number_translations/resources/classes/number_translation.php deleted file mode 100644 index aff51ed655..0000000000 --- a/app/number_translations/resources/classes/number_translation.php +++ /dev/null @@ -1,179 +0,0 @@ - - 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->app_uuid = '6ad54de6-4909-11e7-a919-92ebcb67fe33'; - $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_translations/resources/classes/number_translations.php b/app/number_translations/resources/classes/number_translations.php new file mode 100644 index 0000000000..1a00a32035 --- /dev/null +++ b/app/number_translations/resources/classes/number_translations.php @@ -0,0 +1,75 @@ +db) { + require_once "resources/classes/database.php"; + $database = new database; + $database->connect(); + $this->db = $database->db; + } + } + + /** + * 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 number_translations + */ + public function delete($number_translations) { + if (permission_exists('number_translation_delete')) { + + //delete multiple number_translations + if (is_array($number_translations)) { + //get the action + foreach($number_translations as $row) { + if ($row['action'] == 'delete') { + $action = 'delete'; + break; + } + } + //delete the checked rows + if ($action == 'delete') { + foreach($number_translations as $row) { + if ($row['action'] == 'delete' or $row['checked'] == 'true') { + $sql = "delete from v_number_translations "; + $sql .= "where number_translation_uuid = '".$row['number_translation_uuid']."'; "; + $this->db->query($sql); + unset($sql); + } + } + unset($number_translations); + } + } + } + } //end the delete function + + } //end the class +} + +/* +$obj = new number_translations; +$obj->delete(); +*/ + +?>