diff --git a/app/dialplans/app_defaults.php b/app/dialplans/app_defaults.php index bd2e1fc446..e24dc10e17 100644 --- a/app/dialplans/app_defaults.php +++ b/app/dialplans/app_defaults.php @@ -84,31 +84,34 @@ } //update the dialplan order + $database = new database; $sql = "update v_dialplans set dialplan_order = '870' where dialplan_order = '980' and dialplan_name = 'cidlookup';\n"; - $db->query($sql); + $database->execute($sql); $sql = "update v_dialplans set dialplan_order = '880' where dialplan_order = '990' and dialplan_name = 'call_screen';\n"; - $db->query($sql); + $database->execute($sql); $sql = "update v_dialplans set dialplan_order = '890' where dialplan_order = '999' and dialplan_name = 'local_extension';\n"; - $db->query($sql); + $database->execute($sql); unset($sql); + //set empty strings to null + $database = new database; $sql = "update v_device_lines set outbound_proxy_primary = null where outbound_proxy_primary = '';\n"; - $db->query($sql); + $database->execute($sql); $sql = "update v_device_lines set outbound_proxy_secondary = null where outbound_proxy_secondary = '';\n"; - $db->query($sql); + $database->execute($sql); unset($sql); //change recording_slots to recording_id + $database = new database; $sql = "update v_dialplan_details set dialplan_detail_data = 'recording_id=true' "; $sql .= "where dialplan_uuid in (select dialplan_uuid from v_dialplans where app_uuid = '430737df-5385-42d1-b933-22600d3fb79e') "; $sql .= "and dialplan_detail_data = 'recording_slots=true'; \n"; - $db->query($sql); - unset($sql); + $database->execute($sql); $sql = "update v_dialplan_details set dialplan_detail_data = 'recording_id=false' "; $sql .= "where dialplan_uuid in (select dialplan_uuid from v_dialplans where app_uuid = '430737df-5385-42d1-b933-22600d3fb79e') "; $sql .= "and dialplan_detail_data = 'recording_slots=false'; \n"; - $db->query($sql); + $database->execute($sql); unset($sql); } @@ -116,18 +119,20 @@ if ($domains_processed == 1) { $sql = "select domain_name "; $sql .= "from v_domains \n"; - $prep_statement = $this->db->prepare(check_sql($sql)); - $prep_statement->execute(); - $results = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($results as $row) { - $dialplans = new dialplan; - $dialplans->source = "details"; - $dialplans->destination = "database"; - $dialplans->context = $row["domain_name"]; - $dialplans->is_empty = "dialplan_xml"; - $array = $dialplans->xml(); - //print_r($array); + $database = new database; + $results = $database->select($sql, null, 'all'); + if (is_array($results) && @sizeof($results) != 0) { + foreach ($results as $row) { + $dialplans = new dialplan; + $dialplans->source = "details"; + $dialplans->destination = "database"; + $dialplans->context = $row["domain_name"]; + $dialplans->is_empty = "dialplan_xml"; + $array = $dialplans->xml(); + //print_r($array); + } } + unset($sql, $results); $dialplans = new dialplan; $dialplans->source = "details"; $dialplans->destination = "database"; @@ -137,41 +142,59 @@ //delete the follow me bridge dialplan if ($domains_processed == 1) { + $database = new database; $sql = "delete from v_dialplan_details where dialplan_uuid = '8ed73d1f-698f-466c-8a7a-1cf4cd229f7f' "; - $db->query($sql); + $database->execute($sql); $sql = "delete from v_dialplans where dialplan_uuid = '8ed73d1f-698f-466c-8a7a-1cf4cd229f7f' "; - $db->query($sql); + $database->execute($sql); + unset($sql); } //add not found dialplan to inbound routes /* if ($domains_processed == 1) { if (is_readable($_SESSION['switch']['dialplan']['dir'])) { - $sql = "select count(*) as num_rows from v_dialplans "; + $sql = "select count(*) from v_dialplans "; $sql .= "where dialplan_uuid = 'ea5339de-1982-46ca-9695-c35176165314' "; - $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) { - $sql = "INSERT INTO v_dialplans "; - $sql .= "(dialplan_uuid, app_uuid, dialplan_context, dialplan_name, dialplan_continue, dialplan_order, dialplan_enabled) "; - $sql .= "VALUES ('ea5339de-1982-46ca-9695-c35176165314', 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4', 'public', 'not-found', 'false', '999', 'false');"; - $db->query($sql); + $database = new database; + $num_rows = $database->select($sql, null, 'column'); + if ($num_rows == 0) { + $array['dialplans'][0]['dialplan_uuid'] = 'ea5339de-1982-46ca-9695-c35176165314'; + $array['dialplans'][0]['app_uuid'] = 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4'; + $array['dialplans'][0]['dialplan_context'] = 'public'; + $array['dialplans'][0]['dialplan_name'] = 'not-found'; + $array['dialplans'][0]['dialplan_continue'] = 'false'; + $array['dialplans'][0]['dialplan_order'] = '999'; + $array['dialplans'][0]['dialplan_enabled'] = 'false'; - $sql = "INSERT INTO v_dialplan_details "; - $sql .= "(dialplan_uuid, dialplan_detail_uuid, dialplan_detail_tag, dialplan_detail_type, dialplan_detail_data, dialplan_detail_order) "; - $sql .= "VALUES ('ea5339de-1982-46ca-9695-c35176165314', '8a21744d-b381-4cb0-9930-55b776e4e461', 'condition', 'context', 'public', '10');"; - $db->query($sql); + $array['dialplan_details'][0]['dialplan_uuid'] = 'ea5339de-1982-46ca-9695-c35176165314'; + $array['dialplan_details'][0]['dialplan_detail_uuid'] = '8a21744d-b381-4cb0-9930-55b776e4e461'; + $array['dialplan_details'][0]['dialplan_detail_tag'] = 'condition'; + $array['dialplan_details'][0]['dialplan_detail_type'] = 'context'; + $array['dialplan_details'][0]['dialplan_detail_data'] = 'public'; + $array['dialplan_details'][0]['dialplan_detail_order'] = '10'; - $sql = "INSERT INTO v_dialplan_details "; - $sql .= "(dialplan_uuid, dialplan_detail_uuid, dialplan_detail_tag, dialplan_detail_type, dialplan_detail_data, dialplan_detail_order) "; - $sql .= "VALUES ('ea5339de-1982-46ca-9695-c35176165314', 'e391530c-4078-4b49-bc11-bda4a23ad566', 'action', 'log', '[inbound routes] 404 not found \${sip_network_ip}', '20');"; - $db->query($sql); - unset($sql); - } - unset($prep_statement); + $array['dialplan_details'][1]['dialplan_uuid'] = 'ea5339de-1982-46ca-9695-c35176165314'; + $array['dialplan_details'][1]['dialplan_detail_uuid'] = 'e391530c-4078-4b49-bc11-bda4a23ad566'; + $array['dialplan_details'][1]['dialplan_detail_tag'] = 'action'; + $array['dialplan_details'][1]['dialplan_detail_type'] = 'log'; + $array['dialplan_details'][1]['dialplan_detail_data'] = '[inbound routes] 404 not found \${sip_network_ip}'; + $array['dialplan_details'][1]['dialplan_detail_order'] = '20'; + + $p = new permissions; + $p->add('dialplan_add', 'temp'); + $p->add('dialplan_detail_add', 'temp'); + + $database = new database; + $database->app_name = 'dialplans'; + $database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db'; + $database->save($array); + unset($array); + + $p->delete('dialplan_add', 'temp'); + $p->delete('dialplan_detail_add', 'temp'); } + unset($sql, $num_rows); } } */ diff --git a/app/dialplans/dialplan_add.php b/app/dialplans/dialplan_add.php index 3b2ba58290..1c706263cf 100644 --- a/app/dialplans/dialplan_add.php +++ b/app/dialplans/dialplan_add.php @@ -49,34 +49,34 @@ //set the variables if (count($_POST) > 0) { - $dialplan_name = check_str($_POST["dialplan_name"]); + $dialplan_name = $_POST["dialplan_name"]; - $condition_field_1 = check_str($_POST["condition_field_1"]); - $condition_expression_1 = check_str($_POST["condition_expression_1"]); - $condition_field_2 = check_str($_POST["condition_field_2"]); - $condition_expression_2 = check_str($_POST["condition_expression_2"]); + $condition_field_1 = $_POST["condition_field_1"]; + $condition_expression_1 = $_POST["condition_expression_1"]; + $condition_field_2 = $_POST["condition_field_2"]; + $condition_expression_2 = $_POST["condition_expression_2"]; - $action_1 = check_str($_POST["action_1"]); + $action_1 = $_POST["action_1"]; //$action_1 = "transfer:1001 XML default"; $action_1_array = explode(":", $action_1); $action_application_1 = array_shift($action_1_array); $action_data_1 = join(':', $action_1_array); - $action_2 = check_str($_POST["action_2"]); + $action_2 = $_POST["action_2"]; //$action_2 = "transfer:1001 XML default"; $action_2_array = explode(":", $action_2); $action_application_2 = array_shift($action_2_array); $action_data_2 = join(':', $action_2_array); - //$action_application_1 = check_str($_POST["action_application_1"]); - //$action_data_1 = check_str($_POST["action_data_1"]); - //$action_application_2 = check_str($_POST["action_application_2"]); - //$action_data_2 = check_str($_POST["action_data_2"]); + //$action_application_1 = $_POST["action_application_1"]; + //$action_data_1 = $_POST["action_data_1"]; + //$action_application_2 = $_POST["action_application_2"]; + //$action_data_2 = $_POST["action_data_2"]; - $dialplan_context = check_str($_POST["dialplan_context"]); - $dialplan_order = check_str($_POST["dialplan_order"]); - $dialplan_enabled = check_str($_POST["dialplan_enabled"]); - $dialplan_description = check_str($_POST["dialplan_description"]); + $dialplan_context = $_POST["dialplan_context"]; + $dialplan_order = $_POST["dialplan_order"]; + $dialplan_enabled = $_POST["dialplan_enabled"]; + $dialplan_description = $_POST["dialplan_description"]; if (strlen($dialplan_enabled) == 0) { $dialplan_enabled = "true"; } //set default to enabled } @@ -110,145 +110,69 @@ $dialplan_name = str_replace(" ", "_", $dialplan_name); $dialplan_name = str_replace("/", "", $dialplan_name); - //start the atomic transaction - $db->exec("BEGIN;"); //returns affected rows - //add the main dialplan include entry $dialplan_uuid = uuid(); - $sql = "insert into v_dialplans "; - $sql .= "("; - $sql .= "domain_uuid, "; - $sql .= "dialplan_uuid, "; - $sql .= "app_uuid, "; - $sql .= "dialplan_name, "; - $sql .= "dialplan_order, "; - $sql .= "dialplan_continue, "; - $sql .= "dialplan_context, "; - $sql .= "dialplan_enabled, "; - $sql .= "dialplan_description "; - $sql .= ") "; - $sql .= "values "; - $sql .= "("; - $sql .= "'$domain_uuid', "; - $sql .= "'$dialplan_uuid', "; - $sql .= "'742714e5-8cdf-32fd-462c-cbe7e3d655db', "; - $sql .= "'$dialplan_name', "; - $sql .= "'$dialplan_order', "; - $sql .= "'false', "; - $sql .= "'$dialplan_context', "; - $sql .= "'$dialplan_enabled', "; - $sql .= "'$dialplan_description' "; - $sql .= ")"; - $db->exec(check_sql($sql)); - unset($sql); - + $array['dialplans'][0]['domain_uuid'] = $domain_uuid; + $array['dialplans'][0]['dialplan_uuid'] = $dialplan_uuid; + $array['dialplans'][0]['app_uuid'] = '742714e5-8cdf-32fd-462c-cbe7e3d655db'; + $array['dialplans'][0]['dialplan_name'] = $dialplan_name; + $array['dialplans'][0]['dialplan_order'] = $dialplan_order; + $array['dialplans'][0]['dialplan_continue'] = 'false'; + $array['dialplans'][0]['dialplan_context'] = $dialplan_context; + $array['dialplans'][0]['dialplan_enabled'] = $dialplan_enabled; + $array['dialplans'][0]['dialplan_description'] = $dialplan_description; + //add condition 1 $dialplan_detail_uuid = uuid(); - $sql = "insert into v_dialplan_details "; - $sql .= "("; - $sql .= "domain_uuid, "; - $sql .= "dialplan_uuid, "; - $sql .= "dialplan_detail_uuid, "; - $sql .= "dialplan_detail_tag, "; - $sql .= "dialplan_detail_type, "; - $sql .= "dialplan_detail_data, "; - $sql .= "dialplan_detail_order "; - $sql .= ") "; - $sql .= "values "; - $sql .= "("; - $sql .= "'$domain_uuid', "; - $sql .= "'$dialplan_uuid', "; - $sql .= "'$dialplan_detail_uuid', "; - $sql .= "'condition', "; - $sql .= "'$condition_field_1', "; - $sql .= "'$condition_expression_1', "; - $sql .= "'1' "; - $sql .= ")"; - $db->exec(check_sql($sql)); - unset($sql); - + $array['dialplan_details'][0]['domain_uuid'] = $domain_uuid; + $array['dialplan_details'][0]['dialplan_uuid'] = $dialplan_uuid; + $array['dialplan_details'][0]['dialplan_detail_uuid'] = $dialplan_detail_uuid; + $array['dialplan_details'][0]['dialplan_detail_tag'] = 'condition'; + $array['dialplan_details'][0]['dialplan_detail_type'] = $condition_field_1; + $array['dialplan_details'][0]['dialplan_detail_data'] = $condition_expression_1; + $array['dialplan_details'][0]['dialplan_detail_order'] = '1'; + //add condition 2 if (strlen($condition_field_2) > 0) { $dialplan_detail_uuid = uuid(); - $sql = "insert into v_dialplan_details "; - $sql .= "("; - $sql .= "domain_uuid, "; - $sql .= "dialplan_uuid, "; - $sql .= "dialplan_detail_uuid, "; - $sql .= "dialplan_detail_tag, "; - $sql .= "dialplan_detail_type, "; - $sql .= "dialplan_detail_data, "; - $sql .= "dialplan_detail_order "; - $sql .= ") "; - $sql .= "values "; - $sql .= "("; - $sql .= "'$domain_uuid', "; - $sql .= "'$dialplan_uuid', "; - $sql .= "'$dialplan_detail_uuid', "; - $sql .= "'condition', "; - $sql .= "'$condition_field_2', "; - $sql .= "'$condition_expression_2', "; - $sql .= "'2' "; - $sql .= ")"; - $db->exec(check_sql($sql)); - unset($sql); + $array['dialplan_details'][1]['domain_uuid'] = $domain_uuid; + $array['dialplan_details'][1]['dialplan_uuid'] = $dialplan_uuid; + $array['dialplan_details'][1]['dialplan_detail_uuid'] = $dialplan_detail_uuid; + $array['dialplan_details'][1]['dialplan_detail_tag'] = 'condition'; + $array['dialplan_details'][1]['dialplan_detail_type'] = $condition_field_2; + $array['dialplan_details'][1]['dialplan_detail_data'] = $condition_expression_2; + $array['dialplan_details'][1]['dialplan_detail_order'] = '2'; } //add action 1 $dialplan_detail_uuid = uuid(); - $sql = "insert into v_dialplan_details "; - $sql .= "("; - $sql .= "domain_uuid, "; - $sql .= "dialplan_uuid, "; - $sql .= "dialplan_detail_uuid, "; - $sql .= "dialplan_detail_tag, "; - $sql .= "dialplan_detail_type, "; - $sql .= "dialplan_detail_data, "; - $sql .= "dialplan_detail_order "; - $sql .= ") "; - $sql .= "values "; - $sql .= "("; - $sql .= "'$domain_uuid', "; - $sql .= "'$dialplan_uuid', "; - $sql .= "'$dialplan_detail_uuid', "; - $sql .= "'action', "; - $sql .= "'$action_application_1', "; - $sql .= "'$action_data_1', "; - $sql .= "'3' "; - $sql .= ")"; - $db->exec(check_sql($sql)); - unset($sql); + $array['dialplan_details'][2]['domain_uuid'] = $domain_uuid; + $array['dialplan_details'][2]['dialplan_uuid'] = $dialplan_uuid; + $array['dialplan_details'][2]['dialplan_detail_uuid'] = $dialplan_detail_uuid; + $array['dialplan_details'][2]['dialplan_detail_tag'] = 'action'; + $array['dialplan_details'][2]['dialplan_detail_type'] = $action_application_1; + $array['dialplan_details'][2]['dialplan_detail_data'] = $action_data_1; + $array['dialplan_details'][2]['dialplan_detail_order'] = '3'; //add action 2 if (strlen($action_application_2) > 0) { $dialplan_detail_uuid = uuid(); - $sql = "insert into v_dialplan_details "; - $sql .= "("; - $sql .= "domain_uuid, "; - $sql .= "dialplan_uuid, "; - $sql .= "dialplan_detail_uuid, "; - $sql .= "dialplan_detail_tag, "; - $sql .= "dialplan_detail_type, "; - $sql .= "dialplan_detail_data, "; - $sql .= "dialplan_detail_order "; - $sql .= ") "; - $sql .= "values "; - $sql .= "("; - $sql .= "'$domain_uuid', "; - $sql .= "'$dialplan_uuid', "; - $sql .= "'$dialplan_detail_uuid', "; - $sql .= "'action', "; - $sql .= "'$action_application_2', "; - $sql .= "'$action_data_2', "; - $sql .= "'4' "; - $sql .= ")"; - $db->exec(check_sql($sql)); - unset($sql); + $array['dialplan_details'][3]['domain_uuid'] = $domain_uuid; + $array['dialplan_details'][3]['dialplan_uuid'] = $dialplan_uuid; + $array['dialplan_details'][3]['dialplan_detail_uuid'] = $dialplan_detail_uuid; + $array['dialplan_details'][3]['dialplan_detail_tag'] = 'action'; + $array['dialplan_details'][3]['dialplan_detail_type'] = $action_application_2; + $array['dialplan_details'][3]['dialplan_detail_data'] = $action_data_2; + $array['dialplan_details'][3]['dialplan_detail_order'] = '4'; } - //commit the atomic transaction - $count = $db->exec("COMMIT;"); //returns affected rows - + //execute inserts + $database = new database; + $database->app_name = 'dialplans'; + $database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db'; + $database->save($array); + unset($array); + //synchronize the xml config save_dialplan_xml(); @@ -259,8 +183,8 @@ //send a message and redirect the user message::add($text['message-update']); header("Location: ".PROJECT_PATH."/app/dialplans/dialplans.php"); - return; - } //end if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) + exit; + } //initialize the destinations object $destination = new destinations; diff --git a/app/dialplans/dialplan_copy.php b/app/dialplans/dialplan_copy.php index 7a24051920..f8229896c2 100644 --- a/app/dialplans/dialplan_copy.php +++ b/app/dialplans/dialplan_copy.php @@ -52,8 +52,8 @@ $log = new Logging(); //set the http get/post variable(s) to a php variable - if (isset($_REQUEST["id"])) { - $id = check_str($_REQUEST["id"]); + if (is_uuid($_REQUEST["id"])) { + $id = $_REQUEST["id"]; $log->log("debug", "isset id."); $log->log("debug", $id); } @@ -61,60 +61,62 @@ //get the dialplan data if (is_uuid($id)) { $sql = "select * from v_dialplans "; - $sql .= "where dialplan_uuid = '$id' "; - $log->log("debug", check_sql($sql)); - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $dialplans = $prep_statement->fetchAll(PDO::FETCH_NAMED); - $log->log("debug", $result); - foreach ($dialplans as &$row) { - //create a new primary key for the new row - $dialplan_uuid = uuid(); - $row['dialplan_uuid'] = $dialplan_uuid; + $sql .= "where dialplan_uuid = :dialplan_uuid "; + $parameters['dialplan_uuid'] = $id; + $database = new database; + $dialplans = $database->select($sql, $parameters, 'all'); + if (is_array($dialplans) && @sizeof($dialplans) != 0) { + foreach ($dialplans as &$row) { + //create a new primary key for the new row + $dialplan_uuid = uuid(); + $row['dialplan_uuid'] = $dialplan_uuid; - //get the app_uuid - if (is_uuid($row["app_uuid"])) { - //get the app uuid - $app_uuid = $row["app_uuid"]; - //create a new app_uuid when copying a dialplan except for these exceptions - switch ($app_uuid) { - case "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4": break; //inbound routes - case "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3": break; //outbound routes - case "4b821450-926b-175a-af93-a03c441818b1": break; //time conditions - default: - $app_uuid = uuid(); - } - //set the app uuid - $row['app_uuid'] = $app_uuid; - } + //get the app_uuid + if (is_uuid($row["app_uuid"])) { + //get the app uuid + $app_uuid = $row["app_uuid"]; + //create a new app_uuid when copying a dialplan except for these exceptions + switch ($app_uuid) { + case "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4": break; //inbound routes + case "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3": break; //outbound routes + case "4b821450-926b-175a-af93-a03c441818b1": break; //time conditions + default: + $app_uuid = uuid(); + } + //set the app uuid + $row['app_uuid'] = $app_uuid; + } - //add copy to the name and description - //$row['dialplan_name'] = $row['dialplan_name'].'-copy'; - if (strlen($row['dialplan_description']) == 0) { - $dialplan_description = 'copy'; - } - else { - $dialplan_description = $row['dialplan_description'].'-copy'; - } - $row['dialplan_description'] = $dialplan_description; + //add copy to the name and description + //$row['dialplan_name'] = $row['dialplan_name'].'-copy'; + if (strlen($row['dialplan_description']) == 0) { + $dialplan_description = 'copy'; + } + else { + $dialplan_description = $row['dialplan_description'].'-copy'; + } + $row['dialplan_description'] = $dialplan_description; + } } - unset ($prep_statement); + unset($sql, $parameters, $row); } //get the the dialplan details if (is_uuid($id)) { $sql = "select * from v_dialplan_details "; - $sql .= "where dialplan_uuid = '$id' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $dialplan_details = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($dialplan_details as &$row) { - //create a new primary key for the new row - $row['dialplan_detail_uuid'] = uuid(); - //update the foreign relation uuid - $row['dialplan_uuid'] = $dialplan_uuid; + $sql .= "where dialplan_uuid = :dialplan_uuid "; + $parameters['dialplan_uuid'] = $id; + $database = new database; + $dialplan_details = $database->select($sql, $parameters, 'all'); + if (is_array($dialplan_details) && @sizeof($dialplan_details) != 0) { + foreach ($dialplan_details as &$row) { + //create a new primary key for the new row + $row['dialplan_detail_uuid'] = uuid(); + //update the foreign relation uuid + $row['dialplan_uuid'] = $dialplan_uuid; + } } - unset ($prep_statement); + unset($sql, $parameters); } //build the array @@ -123,17 +125,13 @@ $array['dialplans'][0]['dialplan_details'] = $dialplan_details; } -//debug info - //echo "
".print_r($array, true)."
\n"; - //exit; - //add or update the database $database = new database; $database->app_name = 'dialplans'; $database->app_uuid = $app_uuid; $database->uuid($dialplan_uuid); $database->save($array); - //$message = $database->message; + unset($array); //update the dialplan xml $dialplans = new dialplan; diff --git a/app/dialplans/dialplan_delete.php b/app/dialplans/dialplan_delete.php index 25a72032ba..c73721fa01 100644 --- a/app/dialplans/dialplan_delete.php +++ b/app/dialplans/dialplan_delete.php @@ -48,10 +48,10 @@ //set the dialplan uuid $dialplan_uuids = $_REQUEST["id"]; - $app_uuid = check_str($_REQUEST['app_uuid']); + $app_uuid = $_REQUEST['app_uuid']; //delete the dialplans - if (sizeof($dialplan_uuids) > 0) { + if (is_array($dialplan_uuids) && @sizeof($dialplan_uuids) != 0) { //get dialplan contexts foreach ($dialplan_uuids as $dialplan_uuid) { @@ -60,41 +60,43 @@ //get the dialplan data $sql = "select * from v_dialplans "; - $sql .= "where dialplan_uuid = '".$dialplan_uuid."' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($result as &$row) { - $database_dialplan_uuid = $row["dialplan_uuid"]; - $dialplan_contexts[] = $row["dialplan_context"]; + $sql .= "where dialplan_uuid = :dialplan_uuid "; + $parameters['dialplan_uuid'] = $dialplan_uuid; + $database = new database; + $result = $database->select($sql, $parameters, 'all'); + if (is_array($result) && @sizeof($result) != 0) { + foreach ($result as &$row) { + $database_dialplan_uuid = $row["dialplan_uuid"]; + $dialplan_contexts[] = $row["dialplan_context"]; + } } - unset($prep_statement); + unset($sql, $parameters, $result, $row); } - //start the atomic transaction - $db->beginTransaction(); - //delete dialplan and details $dialplans_deleted = 0; - foreach ($dialplan_uuids as $dialplan_uuid) { - - //delete child data - $sql = "delete from v_dialplan_details "; - $sql .= "where dialplan_uuid = '".$dialplan_uuid."'; "; - $db->query($sql); - unset($sql); - - //delete parent data - $sql = "delete from v_dialplans "; - $sql .= "where dialplan_uuid = '".$dialplan_uuid."'; "; - $db->query($sql); - unset($sql); - - $dialplans_deleted++; + foreach ($dialplan_uuids as $index => $dialplan_uuid) { + //child data + $array['dialplan_details'][$index]['dialplan_uuid'] = $dialplan_uuid; + //parent data + $array['dialplans'][$index]['dialplan_uuid'] = $dialplan_uuid; + //increment counter + $dialplans_deleted++; } + if (is_array($array) && @sizeof($array) != 0) { + $p = new permissions; + $p->add('dialplan_delete', 'temp'); + $p->add('dialplan_detail_delete', 'temp'); - //commit the atomic transaction - $db->commit(); + $database = new database; + $database->app_name = 'dialplans'; + $database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db'; + $database->delete($array); + unset($array); + + $p->delete('dialplan_delete', 'temp'); + $p->delete('dialplan_detail_delete', 'temp'); + } //synchronize the xml config save_dialplan_xml(); diff --git a/app/dialplans/dialplan_detail_delete.php b/app/dialplans/dialplan_detail_delete.php index 490895833b..133598298c 100644 --- a/app/dialplans/dialplan_detail_delete.php +++ b/app/dialplans/dialplan_detail_delete.php @@ -47,20 +47,26 @@ $text = $language->get(); //set the variables - if (count($_GET) > 0) { - $dialplan_detail_uuid = check_str($_GET["id"]); - $dialplan_uuid = check_str($_REQUEST["dialplan_uuid"]); - $app_uuid = check_str($_REQUEST["app_uuid"]); - } + $dialplan_detail_uuid = $_GET["id"]; + $dialplan_uuid = $_REQUEST["dialplan_uuid"]; + $app_uuid = $_REQUEST["app_uuid"]; //delete the dialplan detail if (is_uuid($dialplan_detail_uuid)) { //delete child data - $sql = "delete from v_dialplan_details "; - //$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; - $sql .= "where dialplan_detail_uuid = '$dialplan_detail_uuid' "; - $db->query($sql); - unset($sql); + $array['dialplan_details'][0]['dialplan_detail_uuid'] = $dialplan_detail_uuid; + //$array['dialplan_details'][0]['domain_uuid'] = $_SESSION['domain_uuid']; + + $p = new permissions; + $p->add('dialplan_detail_delete', 'temp'); + + $database = new database; + $database->app_name = 'dialplans'; + $database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db'; + $database->delete($array); + unset($array); + + $p->delete('dialplan_detail_delete', 'temp'); //synchronize the xml config save_dialplan_xml(); @@ -75,10 +81,10 @@ $dialplans->destination = "database"; $dialplans->uuid = $dialplan_uuid; $dialplans->xml(); - } -//save the message to a session variable - message::add($text['message-delete']); + //set message + message::add($text['message-delete']); + } //redirect the browser header("Location: dialplan_edit.php?id=".$dialplan_uuid.(($app_uuid != '') ? "&app_uuid=".$app_uuid : null)); diff --git a/app/dialplans/dialplan_detail_edit.php b/app/dialplans/dialplan_detail_edit.php index 31443bd5cf..80e642b3bb 100644 --- a/app/dialplans/dialplan_detail_edit.php +++ b/app/dialplans/dialplan_detail_edit.php @@ -48,33 +48,33 @@ else { $text = $language->get(); //set the action as an add or update - if (isset($_REQUEST["id"])) { + if (is_uuid($_REQUEST["id"])) { $action = "update"; - $dialplan_detail_uuid = check_str($_REQUEST["id"]); + $dialplan_detail_uuid = $_REQUEST["id"]; } else { $action = "add"; } - $dialplan_uuid = check_str($_REQUEST["dialplan_uuid"]); + $dialplan_uuid = $_REQUEST["dialplan_uuid"]; //get the http values and set them as php variables - $app_uuid = check_str($_REQUEST["app_uuid"]); + $app_uuid = $_REQUEST["app_uuid"]; if (count($_POST)>0) { - $dialplan_uuid = check_str($_POST["dialplan_uuid"]); - $dialplan_detail_tag = check_str($_POST["dialplan_detail_tag"]); - $dialplan_detail_order = check_str($_POST["dialplan_detail_order"]); - $dialplan_detail_type = check_str($_POST["dialplan_detail_type"]); - $dialplan_detail_data = check_str($_POST["dialplan_detail_data"]); - $dialplan_detail_break = check_str($_POST["dialplan_detail_break"]); - $dialplan_detail_inline = check_str($_POST["dialplan_detail_inline"]); - $dialplan_detail_group = check_str($_POST["dialplan_detail_group"]); + $dialplan_uuid = $_POST["dialplan_uuid"]; + $dialplan_detail_tag = $_POST["dialplan_detail_tag"]; + $dialplan_detail_order = $_POST["dialplan_detail_order"]; + $dialplan_detail_type = $_POST["dialplan_detail_type"]; + $dialplan_detail_data = $_POST["dialplan_detail_data"]; + $dialplan_detail_break = $_POST["dialplan_detail_break"]; + $dialplan_detail_inline = $_POST["dialplan_detail_inline"]; + $dialplan_detail_group = $_POST["dialplan_detail_group"]; } if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $msg = ''; if ($action == "update") { - $dialplan_detail_uuid = check_str($_POST["dialplan_detail_uuid"]); + $dialplan_detail_uuid = $_POST["dialplan_detail_uuid"]; } //check for all required data @@ -99,39 +99,27 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { if ($_POST["persistformvar"] != "true") { if ($action == "add" && permission_exists('dialplan_add')) { $dialplan_detail_uuid = uuid(); - $sql = "insert into v_dialplan_details "; - $sql .= "("; - $sql .= "dialplan_uuid, "; - $sql .= "dialplan_detail_uuid, "; - $sql .= "dialplan_detail_tag, "; - $sql .= "dialplan_detail_order, "; - $sql .= "dialplan_detail_type, "; - $sql .= "dialplan_detail_data, "; - $sql .= "dialplan_detail_break, "; - $sql .= "dialplan_detail_inline, "; - $sql .= "dialplan_detail_group, "; - $sql .= "domain_uuid "; - $sql .= ")"; - $sql .= "values "; - $sql .= "("; - $sql .= "'$dialplan_uuid', "; - $sql .= "'$dialplan_detail_uuid', "; - $sql .= "'$dialplan_detail_tag', "; - $sql .= "'$dialplan_detail_order', "; - $sql .= "'$dialplan_detail_type', "; - $sql .= "'$dialplan_detail_data', "; - $sql .= "'$dialplan_detail_break', "; - $sql .= "'$dialplan_detail_inline', "; - if (strlen($dialplan_detail_group) == 0) { - $sql .= "null, "; - } - else { - $sql .= "'$dialplan_detail_group', "; - } - $sql .= "'".$_SESSION['domain_uuid']."' "; - $sql .= ")"; - $db->exec(check_sql($sql)); - unset($sql); + $array['dialplan_details'][0]['dialplan_uuid'] = $dialplan_uuid; + $array['dialplan_details'][0]['dialplan_detail_uuid'] = $dialplan_detail_uuid; + $array['dialplan_details'][0]['dialplan_detail_tag'] = $dialplan_detail_tag; + $array['dialplan_details'][0]['dialplan_detail_order'] = $dialplan_detail_order; + $array['dialplan_details'][0]['dialplan_detail_type'] = $dialplan_detail_type; + $array['dialplan_details'][0]['dialplan_detail_data'] = $dialplan_detail_data; + $array['dialplan_details'][0]['dialplan_detail_break'] = $dialplan_detail_break; + $array['dialplan_details'][0]['dialplan_detail_inline'] = $dialplan_detail_inline; + $array['dialplan_details'][0]['dialplan_detail_group'] = $dialplan_detail_group != '' ? $dialplan_detail_group : null; + $array['dialplan_details'][0]['domain_uuid'] = $_SESSION['domain_uuid']; + + $p = new permissions; + $p->add('dialplan_detail_add', 'temp'); + + $database = new database; + $database->app_name = 'dialplans'; + $database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db'; + $database->save($array); + unset($array); + + $p->delete('dialplan_detail_add', 'temp'); //synchronize the xml config save_dialplan_xml(); @@ -144,27 +132,33 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { message::add($text['message-add']); header("Location: dialplan_edit.php?id=".$dialplan_uuid."&app_uuid=".$app_uuid); return; - } //if ($action == "add") + } if ($action == "update" && permission_exists('dialplan_edit')) { $sql = "update v_dialplan_details set "; - $sql .= "dialplan_uuid = '$dialplan_uuid', "; - $sql .= "dialplan_detail_tag = '$dialplan_detail_tag', "; - $sql .= "dialplan_detail_order = '$dialplan_detail_order', "; - $sql .= "dialplan_detail_type = '$dialplan_detail_type', "; - $sql .= "dialplan_detail_data = '$dialplan_detail_data', "; - $sql .= "dialplan_detail_break = '$dialplan_detail_break', "; - $sql .= "dialplan_detail_inline = '$dialplan_detail_inline', "; - if (strlen($dialplan_detail_group) == 0) { - $sql .= "dialplan_detail_group = null "; - } - else { - $sql .= "dialplan_detail_group = '$dialplan_detail_group' "; - } - $sql .= "where (domain_uuid = '".$_SESSION['domain_uuid']."' or domain_uuid is null) "; - $sql .= "and dialplan_detail_uuid = '$dialplan_detail_uuid'"; - $db->exec(check_sql($sql)); - unset($sql); + $sql .= "dialplan_uuid = :dialplan_uuid "; + $sql .= "dialplan_detail_tag = :dialplan_detail_tag, "; + $sql .= "dialplan_detail_order = :dialplan_detail_order, "; + $sql .= "dialplan_detail_type = :dialplan_detail_type, "; + $sql .= "dialplan_detail_data = :dialplan_detail_data, "; + $sql .= "dialplan_detail_break = :dialplan_detail_break, "; + $sql .= "dialplan_detail_inline = :dialplan_detail_inline, "; + $sql .= "dialplan_detail_group = :dialplan_detail_group "; + $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) "; + $sql .= "and dialplan_detail_uuid = :dialplan_detail_uuid "; + $parameters['dialplan_uuid'] = $dialplan_uuid; + $parameters['dialplan_detail_tag'] = $dialplan_detail_tag; + $parameters['dialplan_detail_order'] = $dialplan_detail_order; + $parameters['dialplan_detail_type'] = $dialplan_detail_type; + $parameters['dialplan_detail_data'] = $dialplan_detail_data; + $parameters['dialplan_detail_break'] = $dialplan_detail_break; + $parameters['dialplan_detail_inline'] = $dialplan_detail_inline; + $parameters['dialplan_detail_group'] = $dialplan_detail_group != '' ? $dialplan_detail_group : null; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $parameters['dialplan_detail_uuid'] = $dialplan_detail_uuid; + $database = new database; + $database->execute($sql, $parameters); + unset($sql, $parameters); //synchronize the xml config save_dialplan_xml(); @@ -187,12 +181,13 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { if (count($_GET)>0 && $_POST["persistformvar"] != "true") { $dialplan_detail_uuid = $_GET["id"]; $sql = "select * from v_dialplan_details "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and dialplan_detail_uuid = '$dialplan_detail_uuid' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($result as &$row) { + $sql .= "where domain_uuid = :domain_uuid "; + $sql .= "and dialplan_detail_uuid = :dialplan_detail_uuid "; + $parameters['domain_uuid'] = $domain_uuid; + $parameters['dialplan_detail_uuid'] = $dialplan_detail_uuid; + $database = new database; + $row = $database->select($sql, $parameters, 'row'); + if (is_array($row) && @sizeof($row) != 0) { $dialplan_uuid = $row["dialplan_uuid"]; $dialplan_detail_tag = $row["dialplan_detail_tag"]; $dialplan_detail_order = $row["dialplan_detail_order"]; @@ -202,7 +197,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $dialplan_detail_inline = $row["dialplan_detail_inline"]; $dialplan_detail_group = $row["dialplan_detail_group"]; } - unset ($prep_statement); + unset($sql, $parameters, $row); } //show the header diff --git a/app/dialplans/dialplan_edit.php b/app/dialplans/dialplan_edit.php index d9c9758907..75d4209563 100644 --- a/app/dialplans/dialplan_edit.php +++ b/app/dialplans/dialplan_edit.php @@ -63,22 +63,21 @@ } //set the app_uuid - if (strlen($_GET["app_uuid"]) > 0) { + if (is_uuid($_GET["app_uuid"])) { $app_uuid = $_GET["app_uuid"]; } //get the http post values and set them as php variables if (count($_POST) > 0) { - $hostname = check_str($_POST["hostname"]); - $dialplan_name = check_str($_POST["dialplan_name"]); - $dialplan_number = check_str($_POST["dialplan_number"]); - $dialplan_order = check_str($_POST["dialplan_order"]); - $dialplan_continue = check_str($_POST["dialplan_continue"]); + $hostname = $_POST["hostname"]; + $dialplan_name = $_POST["dialplan_name"]; + $dialplan_number = $_POST["dialplan_number"]; + $dialplan_order = $_POST["dialplan_order"]; + $dialplan_continue = $_POST["dialplan_continue"] != '' ? $_POST["dialplan_continue"] : 'false'; $dialplan_details = $_POST["dialplan_details"]; - if (strlen($dialplan_continue) == 0) { $dialplan_continue = "false"; } - $dialplan_context = check_str($_POST["dialplan_context"]); - $dialplan_enabled = check_str($_POST["dialplan_enabled"]); - $dialplan_description = check_str($_POST["dialplan_description"]); + $dialplan_context = $_POST["dialplan_context"]; + $dialplan_enabled = $_POST["dialplan_enabled"]; + $dialplan_description = $_POST["dialplan_description"]; } //get the list of applications @@ -131,14 +130,14 @@ //build the array $x = 0; - if (isset($_POST["dialplan_uuid"])) { + if (is_uuid($_POST["dialplan_uuid"])) { $array['dialplans'][$x]['dialplan_uuid'] = $_POST["dialplan_uuid"]; } else { $dialplan_uuid = uuid(); $array['dialplans'][$x]['dialplan_uuid'] = $dialplan_uuid; } - if (isset($_POST["domain_uuid"])) { + if (is_uuid($_POST["domain_uuid"])) { $array['dialplans'][$x]['domain_uuid'] = $_POST['domain_uuid']; } else { @@ -183,7 +182,7 @@ $database->app_uuid = $app_uuid; $database->uuid($dialplan_uuid); $database->save($array); - $message = $database->message; + unset($array); } //update the dialplan xml @@ -207,7 +206,7 @@ else if ($action == "update") { message::add($text['message-update']); } - header("Location: ?id=".escape($dialplan_uuid).(($app_uuid != '') ? "&app_uuid=".escape($app_uuid) : null)); + header("Location: ?id=".escape($dialplan_uuid).(is_uuid($app_uuid) ? "&app_uuid=".$app_uuid : null)); exit; } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) @@ -215,11 +214,11 @@ //pre-populate the form if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { $sql = "select * from v_dialplans "; - $sql .= "where dialplan_uuid = '$dialplan_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) { + $sql .= "where dialplan_uuid = :dialplan_uuid "; + $parameters['dialplan_uuid'] = $dialplan_uuid; + $database = new database; + $row = $database->select($sql, $parameters, 'row'); + if (is_array($row) && @sizeof($row) != 0) { $domain_uuid = $row["domain_uuid"]; $hostname = $row["hostname"]; $dialplan_name = $row["dialplan_name"]; @@ -231,7 +230,7 @@ $dialplan_enabled = $row["dialplan_enabled"]; $dialplan_description = $row["dialplan_description"]; } - unset ($prep_statement); + unset($sql, $parameters, $row); } //set the defaults @@ -248,13 +247,12 @@ //get the dialplan details in an array $sql = "select * from v_dialplan_details "; - $sql .= "where dialplan_uuid = '$dialplan_uuid' "; + $sql .= "where dialplan_uuid = :dialplan_uuid "; $sql .= "order by dialplan_detail_group asc, dialplan_detail_order asc"; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - $result_count = count($result); - unset ($prep_statement, $sql); + $parameters['dialplan_uuid'] = $dialplan_uuid; + $database = new database; + $result = $database->select($sql, $parameters, 'all'); + unset($sql, $parameters); //create a new array that is sorted into groups and put the tags in order conditions, actions, anti-actions //set the array index @@ -262,69 +260,81 @@ //define the array $details = array(); //conditions - if (is_array($result)) foreach($result as $row) { - if ($row['dialplan_detail_tag'] == "condition") { - $group = $row['dialplan_detail_group']; - foreach ($row as $key => $val) { - $details[$group][$x][$key] = $val; + if (is_array($result) && @sizeof($result) != 0) { + foreach ($result as $row) { + if ($row['dialplan_detail_tag'] == "condition") { + $group = $row['dialplan_detail_group']; + foreach ($row as $key => $val) { + $details[$group][$x][$key] = $val; + } } + $x++; } - $x++; } //regex - if (is_array($result)) foreach($result as $row) { - if ($row['dialplan_detail_tag'] == "regex") { - $group = $row['dialplan_detail_group']; - foreach ($row as $key => $val) { - $details[$group][$x][$key] = $val; + if (is_array($result) && @sizeof($result) != 0) { + foreach ($result as $row) { + if ($row['dialplan_detail_tag'] == "regex") { + $group = $row['dialplan_detail_group']; + foreach ($row as $key => $val) { + $details[$group][$x][$key] = $val; + } } + $x++; } - $x++; } //actions - if (is_array($result)) foreach($result as $row) { - if ($row['dialplan_detail_tag'] == "action") { - $group = $row['dialplan_detail_group']; - foreach ($row as $key => $val) { - $details[$group][$x][$key] = $val; + if (is_array($result) && @sizeof($result) != 0) { + foreach ($result as $row) { + if ($row['dialplan_detail_tag'] == "action") { + $group = $row['dialplan_detail_group']; + foreach ($row as $key => $val) { + $details[$group][$x][$key] = $val; + } } + $x++; } - $x++; } //anti-actions - if (is_array($result)) foreach($result as $row) { - if ($row['dialplan_detail_tag'] == "anti-action") { - $group = $row['dialplan_detail_group']; - foreach ($row as $key => $val) { - $details[$group][$x][$key] = $val; + if (is_array($result) && @sizeof($result) != 0) { + foreach ($result as $row) { + if ($row['dialplan_detail_tag'] == "anti-action") { + $group = $row['dialplan_detail_group']; + foreach ($row as $key => $val) { + $details[$group][$x][$key] = $val; + } } + $x++; } - $x++; } unset($result); //blank row - if (is_array($details)) foreach($details as $group => $row) { - //set the array key for the empty row - $x = "999"; - //get the highest dialplan_detail_order - if (is_array($row)) foreach ($row as $key => $field) { - $dialplan_detail_order = 0; - if ($dialplan_detail_order < $field['dialplan_detail_order']) { - $dialplan_detail_order = $field['dialplan_detail_order']; + if (is_array($details) && @sizeof($details) != 0) { + foreach ($details as $group => $row) { + //set the array key for the empty row + $x = "999"; + //get the highest dialplan_detail_order + if (is_array($row) && @sizeof($details) != 0) { + foreach ($row as $key => $field) { + $dialplan_detail_order = 0; + if ($dialplan_detail_order < $field['dialplan_detail_order']) { + $dialplan_detail_order = $field['dialplan_detail_order']; + } + } } - } - //increment the highest order by 5 - $dialplan_detail_order = $dialplan_detail_order + 10; - //set the rest of the empty array - //$details[$group][$x]['domain_uuid'] = ''; - //$details[$group][$x]['dialplan_uuid'] = ''; - $details[$group][$x]['dialplan_detail_tag'] = ''; - $details[$group][$x]['dialplan_detail_type'] = ''; - $details[$group][$x]['dialplan_detail_data'] = ''; - $details[$group][$x]['dialplan_detail_break'] = ''; - $details[$group][$x]['dialplan_detail_inline'] = ''; - $details[$group][$x]['dialplan_detail_group'] = $group; - $details[$group][$x]['dialplan_detail_order'] = $dialplan_detail_order; + //increment the highest order by 5 + $dialplan_detail_order = $dialplan_detail_order + 10; + //set the rest of the empty array + //$details[$group][$x]['domain_uuid'] = ''; + //$details[$group][$x]['dialplan_uuid'] = ''; + $details[$group][$x]['dialplan_detail_tag'] = ''; + $details[$group][$x]['dialplan_detail_type'] = ''; + $details[$group][$x]['dialplan_detail_data'] = ''; + $details[$group][$x]['dialplan_detail_break'] = ''; + $details[$group][$x]['dialplan_detail_inline'] = ''; + $details[$group][$x]['dialplan_detail_group'] = $group; + $details[$group][$x]['dialplan_detail_order'] = $dialplan_detail_order; + } } //sort the details array by group number if (is_array($details)) { @@ -521,18 +531,20 @@ echo " \n"; echo " \n"; echo " \n"; @@ -599,7 +611,7 @@ \n"; @@ -621,231 +633,233 @@ echo " \n"; echo "\n"; - if (is_array($group)) foreach($group as $index => $row) { + if (is_array($group) && @sizeof($group) != 0) { + foreach($group as $index => $row) { - //get the values from the database and set as variables - $dialplan_detail_uuid = $row['dialplan_detail_uuid']; - $dialplan_detail_tag = $row['dialplan_detail_tag']; - $dialplan_detail_type = $row['dialplan_detail_type']; - $dialplan_detail_data = $row['dialplan_detail_data']; - $dialplan_detail_break = $row['dialplan_detail_break']; - $dialplan_detail_inline = $row['dialplan_detail_inline']; - $dialplan_detail_group = $row['dialplan_detail_group']; - $dialplan_detail_order = $row['dialplan_detail_order']; + //get the values from the database and set as variables + $dialplan_detail_uuid = $row['dialplan_detail_uuid']; + $dialplan_detail_tag = $row['dialplan_detail_tag']; + $dialplan_detail_type = $row['dialplan_detail_type']; + $dialplan_detail_data = $row['dialplan_detail_data']; + $dialplan_detail_break = $row['dialplan_detail_break']; + $dialplan_detail_inline = $row['dialplan_detail_inline']; + $dialplan_detail_group = $row['dialplan_detail_group']; + $dialplan_detail_order = $row['dialplan_detail_order']; - //no border on last row - $no_border = ($index == 999) ? "border: none;" : null; + //no border on last row + $no_border = ($index == 999) ? "border: none;" : null; - //begin the row - echo "\n"; - //determine whether to hide the element - if (strlen($dialplan_detail_tag) == 0) { - $element['hidden'] = false; - $element['visibility'] = ""; - } - else { - $element['hidden'] = true; - $element['visibility'] = "display: none;"; - } - //add the primary key uuid - if (strlen($dialplan_detail_uuid) > 0) { - echo " \n"; - } - //tag - $selected = "selected=\"selected\" "; - echo "\n"; - if ($element['hidden']) { - echo " \n"; - } - echo " \n"; - echo "\n"; - //type - echo "\n"; - if ($element['hidden']) { - echo " \n"; - } - echo " \n"; + } + //tag + $selected = "selected=\"selected\" "; + echo "\n"; + if ($element['hidden']) { + echo " \n"; + } + echo " \n"; + echo "\n"; + //type + echo "\n"; + if ($element['hidden']) { + echo " \n"; + } + echo " \n"; - //echo " \n"; - echo "\n"; - //data - echo "\n"; - if ($element['hidden']) { - $dialplan_detail_data_mod = $dialplan_detail_data; - if ($dialplan_detail_type == 'bridge') { - // split up failover bridges and get variables in statement - $failover_bridges = explode('|', $dialplan_detail_data); - preg_match('/^\{.*\}/', $failover_bridges[0], $bridge_vars); - $bridge_vars = $bridge_vars[0]; - - // rename parse and rename each gateway - foreach ($failover_bridges as $bridge_statement_exploded) { - // parse out gateway uuid - $bridge_statement = str_replace($bridge_vars, '', explode('/', $bridge_statement_exploded)); - array_unshift($bridge_statement, $bridge_vars); - - if ($bridge_statement[1] == 'sofia' && $bridge_statement[2] == 'gateway' && is_uuid($bridge_statement[3])) { - // retrieve gateway name from db - $sql = "select gateway from v_gateways where gateway_uuid = '".$bridge_statement[3]."' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $gateways = $prep_statement->fetchAll(PDO::FETCH_NAMED); - if (is_array($gateways)) { - $gateway_name = $gateways[0]['gateway']; - $bridge_statement_exploded_mod = str_replace($bridge_statement[3], $gateway_name, $bridge_statement_exploded); + echo " \n"; + //} + echo " \n"; + //echo " \n"; + echo "\n"; + //data + echo "\n"; + if ($element['hidden']) { + $dialplan_detail_data_mod = $dialplan_detail_data; + if ($dialplan_detail_type == 'bridge') { + // split up failover bridges and get variables in statement + $failover_bridges = explode('|', $dialplan_detail_data); + preg_match('/^\{.*\}/', $failover_bridges[0], $bridge_vars); + $bridge_vars = $bridge_vars[0]; + + // rename parse and rename each gateway + foreach ($failover_bridges as $bridge_statement_exploded) { + // parse out gateway uuid + $bridge_statement = str_replace($bridge_vars, '', explode('/', $bridge_statement_exploded)); + array_unshift($bridge_statement, $bridge_vars); + + if ($bridge_statement[1] == 'sofia' && $bridge_statement[2] == 'gateway' && is_uuid($bridge_statement[3])) { + // retrieve gateway name from db + $sql = "select gateway from v_gateways where gateway_uuid = :gateway_uuid "; + $parameters['gateway_uuid'] = $bridge_statement[3]; + $database = new database; + $gateways = $database->select($sql, $parameters, 'all'); + if (is_array($gateways) && @sizeof($gateways) != 0) { + $gateway_name = $gateways[0]['gateway']; + $bridge_statement_exploded_mod = str_replace($bridge_statement[3], $gateway_name, $bridge_statement_exploded); + } + $dialplan_detail_data_mod = str_replace($bridge_statement_exploded, $bridge_statement_exploded_mod, $dialplan_detail_data_mod); + unset($sql, $parameters, $bridge_statement, $gateways, $bridge_statement_exploded, $bridge_statement_exploded_mod); } - $dialplan_detail_data_mod = str_replace($bridge_statement_exploded, $bridge_statement_exploded_mod, $dialplan_detail_data_mod); - unset ($prep_statement, $sql, $bridge_statement, $gateways, $bridge_statement_exploded, $bridge_statement_exploded_mod); } } + echo " \n"; } - echo " \n"; - } - echo " \n"; - echo "\n"; - //break - echo "\n"; - if ($element['hidden']) { - echo " \n"; - } - echo " \n"; - echo "\n"; - //inline - echo "\n"; - if ($element['hidden']) { - echo " \n"; - } - echo " \n"; - echo "\n"; - //group - echo "\n"; - if ($element['hidden']) { - echo " \n"; - } - echo " \n"; - /* - echo " \n"; - */ - echo "\n"; - //order - echo "\n"; - if ($element['hidden']) { - echo " \n"; - } - echo " \n"; - /* - echo " \n"; + echo "\n"; + //break + echo "\n"; + if ($element['hidden']) { + echo " \n"; } - if (strlen($i) == 2) { - echo " \n"; + echo " \n"; + echo "\n"; + //inline + echo "\n"; + if ($element['hidden']) { + echo " \n"; } - if (strlen($i) == 3) { + echo " \n"; + echo "\n"; + //group + echo "\n"; + if ($element['hidden']) { + echo " \n"; + } + echo " \n"; + /* + echo " \n"; - */ - echo "\n"; - //tools - echo " \n"; - if ($element['hidden']) { - //echo " $v_link_label_edit\n"; - echo " $v_link_label_delete\n"; - } - echo " \n"; - //end the row - echo "\n"; - //increment the value - $x++; + echo " \n"; + */ + echo "\n"; + //order + echo "\n"; + if ($element['hidden']) { + echo " \n"; + } + echo " \n"; + /* + echo " \n"; + */ + echo "\n"; + //tools + echo " \n"; + if ($element['hidden']) { + //echo " $v_link_label_edit\n"; + echo " $v_link_label_delete\n"; + } + echo " \n"; + //end the row + echo "\n"; + //increment the value + $x++; + } } $x++; } //end foreach - unset($sql, $details); + unset($details); echo ""; diff --git a/app/dialplans/dialplan_xml.php b/app/dialplans/dialplan_xml.php index fce91e334b..f3a3d44ff4 100644 --- a/app/dialplans/dialplan_xml.php +++ b/app/dialplans/dialplan_xml.php @@ -48,18 +48,18 @@ } //set the default app_uuid - if (strlen($app_uuid) == 0) { + if (!is_uuid($app_uuid)) { $app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db'; } //get the dialplan xml if (is_uuid($dialplan_uuid)) { $sql = "select * from v_dialplans "; - $sql .= "where dialplan_uuid = '".$dialplan_uuid."' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($result as &$row) { + $sql .= "where dialplan_uuid = :dialplan_uuid "; + $parameters['dialplan_uuid'] = $dialplan_uuid; + $database = new database; + $row = $database->select($sql, $parameters, 'row'); + if (is_array($row) && @sizeof($row) != 0) { $domain_uuid = $row["domain_uuid"]; //$app_uuid = $row["app_uuid"]; $dialplan_name = $row["dialplan_name"]; @@ -71,7 +71,7 @@ $dialplan_enabled = $row["dialplan_enabled"]; $dialplan_description = $row["dialplan_description"]; } - unset ($prep_statement); + unset($sql, $parameters, $row); } //process the HTTP POST @@ -87,19 +87,10 @@ $database = new database; $database->app_name = 'dialplans'; $database->app_uuid = $app_uuid; - //if (strlen($dialplan_uuid) > 0) { - // $database->uuid($dialplan_uuid); - //} $database->save($array); - $message = $database->message; + unset($array); - //debug info - //echo "
\n";
-			//print_r($message);
-			//echo "
\n"; - //exit; - - //clear the cache + //clear the cache $cache = new cache; $cache->delete("dialplan:".$dialplan_context); @@ -126,7 +117,7 @@ echo " \n"; echo " \n"; echo " \n"; echo "
\n"; - echo" ".$text['title-dialplan_edit']."
\n"; + echo " ".$text['title-dialplan_edit']."
\n"; echo "
\n"; echo " 0) ? "app_uuid=".$app_uuid : null)."';\" value='".$text['button-back']."'>\n"; diff --git a/app/dialplans/dialplans.php b/app/dialplans/dialplans.php index e8b7ed91de..c0380deecb 100644 --- a/app/dialplans/dialplans.php +++ b/app/dialplans/dialplans.php @@ -43,9 +43,9 @@ $text = $language->get(); //handle enable toggle - $dialplan_uuid = check_str($_REQUEST['id']); - $dialplan_enabled = check_str($_REQUEST['enabled']); - if (isset($dialplan_uuid) && is_uuid($dialplan_uuid) && $dialplan_enabled != '') { + $dialplan_uuid = $_REQUEST['id']; + $dialplan_enabled = $_REQUEST['enabled']; + if (is_uuid($dialplan_uuid) && $dialplan_enabled != '') { //make sure enabled is only true or false if ($dialplan_enabled == "true") { $dialplan_enabled = 'true'; @@ -55,20 +55,27 @@ } //get the dialplan context - $sql = "select * from v_dialplans "; - $sql .= "where dialplan_uuid = '".$dialplan_uuid."' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_NAMED); - $dialplan_context = $row["dialplan_context"]; - unset($sql); + $sql = "select dialplan_context from v_dialplans "; + $sql .= "where dialplan_uuid = :dialplan_uuid "; + $parameters['dialplan_uuid'] = $dialplan_uuid; + $database = new database; + $dialplan_context = $database->select($sql, $parameters, 'column'); + unset($sql, $parameters); //change the status - $sql = "update v_dialplans set "; - $sql .= "dialplan_enabled = '".$dialplan_enabled."' "; - $sql .= "where dialplan_uuid = '".$dialplan_uuid."'"; - $db->exec(check_sql($sql)); - unset($sql); + $array['dialplans'][0]['dialplan_uuid'] = $dialplan_uuid; + $array['dialplans'][0]['dialplan_enabled'] = $dialplan_enabled; + + $p = new permissions; + $p->add('dialplan_edit', 'temp'); + + $database = new database; + $database->app_name = 'dialplans'; + $database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db'; + $database->save($array); + unset($array); + + $p->delete('dialplan_edit', 'temp'); //clear the cache $cache = new cache; @@ -79,11 +86,11 @@ } //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; } - if (isset($_REQUEST["dialplan_context"])) { $dialplan_context = check_str($_REQUEST["dialplan_context"]); } else { $dialplan_context = null; } - if (isset($_REQUEST["app_uuid"])) { $app_uuid = check_str($_REQUEST["app_uuid"]); } else { $app_uuid = null; } + $search = $_REQUEST["search"]; + $order_by = $_REQUEST["order_by"]; + $order = $_REQUEST["order"]; + $dialplan_context = $_REQUEST["dialplan_context"]; + $app_uuid = $_REQUEST["app_uuid"]; //make sure all dialplans with context of public have the inbound route app_uuid if ($app_uuid == 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4') { @@ -91,7 +98,8 @@ $sql .= "app_uuid = 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4' "; $sql .= "where dialplan_context = 'public' "; $sql .= "and app_uuid is null; "; - $db->exec($sql); + $database = new database; + $database->execute($sql); unset($sql); } @@ -99,49 +107,50 @@ require_once "resources/header.php"; require_once "resources/paging.php"; -//get the number of rows in the dialplan - $sql = "select count(*) as num_rows from v_dialplans "; +//common sql where if ($_GET['show'] == "all" && permission_exists('dialplan_all')) { - $sql .= "where 1 = 1 "; + $sql_where = "where true "; } else { - $sql .= "where (domain_uuid = '$domain_uuid' or domain_uuid is null) "; + $sql_where .= "where (domain_uuid = :domain_uuid or domain_uuid is null) "; + $parameters['domain_uuid'] = $domain_uuid; } - if (strlen($app_uuid) == 0) { + if (!is_uuid($app_uuid)) { //hide inbound routes - $sql .= "and app_uuid <> 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4' "; + $sql_where .= "and app_uuid <> 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4' "; + $sql_where .= "and dialplan_context <> 'public' "; //hide outbound routes - $sql .= "and app_uuid <> '8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3' "; + $sql_where .= "and app_uuid <> '8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3' "; } else { - $sql .= "and app_uuid = '".$app_uuid."' "; - } - if (strlen($search) > 0) { - $search = strtolower($search); - $sql .= "and ("; - $sql .= " lower(dialplan_context) like '%".$search."%' "; - $sql .= " or lower(dialplan_name) like '%".$search."%' "; - $sql .= " or dialplan_number like '%".$search."%' "; - $sql .= " or dialplan_continue like '%".$search."%' "; - if (is_numeric($search)) { - $sql .= " or dialplan_order = '".$search."' "; - } - $sql .= " or dialplan_enabled like '%".$search."%' "; - $sql .= " or lower(dialplan_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']; + if ($app_uuid == 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4') { + $sql_where .= "and (app_uuid = :app_uuid or dialplan_context = 'public') "; } else { - $num_rows = '0'; + $sql_where .= "and app_uuid = :app_uuid "; } + $parameters['app_uuid'] = $app_uuid; } - unset($prep_statement, $result); + if (strlen($search) > 0) { + $sql_where .= "and ("; + $sql_where .= " dialplan_context like :search "; + $sql_where .= " or dialplan_name like :search "; + $sql_where .= " or dialplan_number like :search "; + $sql_where .= " or dialplan_continue like :search "; + if (is_numeric($search)) { + $sql_where .= " or dialplan_order = :search "; + } + $sql_where .= " or dialplan_enabled like :search "; + $sql_where .= " or dialplan_description like :search "; + $sql_where .= ") "; + $parameters['search'] = '%'.$search.'%'; + } + +//get the number of rows in the dialplan + $sql = "select count(*) from v_dialplans "; + $sql .= $sql_where; + $database = new database; + $num_rows = $database->select($sql, $parameters, 'column'); $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; $param = "&search=".escape($search); @@ -155,48 +164,12 @@ $offset = $rows_per_page * $page; //get the list of dialplans - $sql = "select * from v_dialplans "; - if ($_GET['show'] == "all" && permission_exists('dialplan_all')) { - $sql .= "where 1 = 1 "; - } - else { - $sql .= "where (domain_uuid = '$domain_uuid' or domain_uuid is null) "; - } - if (strlen($app_uuid) == 0) { - //hide inbound routes - $sql .= "and app_uuid <> 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4' "; - $sql .= "and dialplan_context <> 'public' "; - //hide outbound routes - $sql .= "and app_uuid <> '8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3' "; - } - else { - if ($app_uuid == 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4') { - $sql .= "and (app_uuid = '".$app_uuid."' or dialplan_context = 'public') "; - } - else { - $sql .= "and app_uuid = '".$app_uuid."' "; - } - } - if (strlen($search) > 0) { - $sql .= "and ("; - $sql .= " dialplan_context like '%".$search."%' "; - $sql .= " or dialplan_name like '%".$search."%' "; - $sql .= " or dialplan_number like '%".$search."%' "; - $sql .= " or dialplan_continue like '%".$search."%' "; - if (is_numeric($search)) { - $sql .= " or dialplan_order = '".$search."' "; - } - $sql .= " or dialplan_enabled like '%".$search."%' "; - $sql .= " or dialplan_description like '%".$search."%' "; - $sql .= ") "; - } - if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } else { $sql .= "order by dialplan_order asc, dialplan_name asc "; } - $sql .= " limit $rows_per_page offset $offset "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $dialplans = $prep_statement->fetchAll(PDO::FETCH_NAMED); - $dialplan_count = count($dialplans); - unset ($prep_statement, $sql); + $sql = str_replace('count(*)', '*', $sql); + $sql .= ($order_by != '' ? order_by($order_by, $order) : 'order by dialplan_order asc, dialplan_name asc '); + $sql .= limit_offset($rows_per_page, $offset); + $database = new database; + $dialplans = $database->select($sql, $parameters, 'all'); + unset($sql, $parameters); //set the alternating row style $c = 0; @@ -254,7 +227,7 @@ } } echo " "; - if (strlen($app_uuid) > 0) { + if (is_uuid($app_uuid)) { echo " "; } if (strlen($order_by) > 0) { @@ -299,7 +272,7 @@ echo "\n"; echo "\n"; echo "\n"; - if (permission_exists('dialplan_delete') && $dialplan_count > 0) { + if (permission_exists('dialplan_delete') && @sizeof($dialplans) != 0) { echo ""; } if ($_GET['show'] == "all" && permission_exists('destination_all')) { @@ -327,13 +300,13 @@ elseif (permission_exists('dialplan_add')) { echo "$v_link_label_add"; } - if (permission_exists('dialplan_delete') && $dialplan_count > 0) { + if (permission_exists('dialplan_delete') && @sizeof($dialplans) != 0) { echo "".$v_link_label_delete.""; } echo "\n"; echo "\n"; - if (is_array($dialplans)) { + if (is_array($dialplans) && @sizeof($dialplans) != 0) { foreach($dialplans as $row) { //get the application id @@ -421,10 +394,10 @@ } echo " \n"; echo "\n"; - if ($c==0) { $c=1; } else { $c=0; } - } //end foreach - unset($sql, $result, $row_count); - } //end if results + $c = $c == 0 ? 1 : 0; + } + } + unset($dialplans, $row); echo "\n"; echo "\n";
\n"; @@ -448,7 +421,7 @@ elseif (permission_exists('dialplan_add')) { echo "$v_link_label_add"; } - if (permission_exists('dialplan_delete') && $dialplan_count > 0) { + if (permission_exists('dialplan_delete') && @sizeof($dialplans) != 0) { echo "".$v_link_label_delete.""; } echo "