Portions created by the Initial Developer are Copyright (C) 2008-2016 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane Lewis Hallam */ //includes require_once "root.php"; require_once "resources/require.php"; //check permissions require_once "resources/check_auth.php"; if (permission_exists('call_flow_add') || permission_exists('call_flow_edit')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //action add or update if (isset($_REQUEST["id"])) { $action = "update"; $call_flow_uuid = check_str($_REQUEST["id"]); } else { $action = "add"; } //get http post variables and set them to php variables if (is_array($_POST)) { //set the variables from the http values $call_flow_uuid = check_str($_POST["call_flow_uuid"]); $dialplan_uuid = check_str($_POST["dialplan_uuid"]); $call_flow_name = check_str($_POST["call_flow_name"]); $call_flow_extension = check_str($_POST["call_flow_extension"]); $call_flow_feature_code = check_str($_POST["call_flow_feature_code"]); $call_flow_context = check_str($_POST["call_flow_context"]); $call_flow_status = check_str($_POST["call_flow_status"]); $call_flow_pin_number = check_str($_POST["call_flow_pin_number"]); $call_flow_label = check_str($_POST["call_flow_label"]); $call_flow_sound = check_str($_POST["call_flow_sound"]); $call_flow_destination = check_str($_POST["call_flow_destination"]); //$call_flow_app = check_str($_POST["call_flow_app"]); //$call_flow_data = check_str($_POST["call_flow_data"]); $call_flow_alternate_label = check_str($_POST["call_flow_alternate_label"]); $call_flow_alternate_sound = check_str($_POST["call_flow_alternate_sound"]); $call_flow_alternate_destination = check_str($_POST["call_flow_alternate_destination"]); //$call_flow_alternate_app = check_str($_POST["call_flow_alternate_app"]); //$call_flow_alternate_data = check_str($_POST["call_flow_alternate_data"]); $call_flow_description = check_str($_POST["call_flow_description"]); //unset the values unset($_POST["call_flow_destination"]); unset($_POST["call_flow_alternate_destination"]); //seperate the action and the param $destination_array = explode(":", $call_flow_destination); $call_flow_app = array_shift($destination_array); $call_flow_data = join(':', $destination_array); //seperate the action and the param call_flow_alternate_app $alternate_destination_array = explode(":", $call_flow_alternate_destination); $call_flow_alternate_app = array_shift($alternate_destination_array); $call_flow_alternate_data = join(':', $alternate_destination_array); //set the context for users that are not in the superadmin group if (!if_group("superadmin")) { $call_flow_context = $_SESSION['domain_name']; } } //process the user data and save it to the database if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { //get the uuid from the POST if ($action == "update") { $call_flow_uuid = check_str($_POST["call_flow_uuid"]); } //set the call flow application and data $_POST["call_flow_app"] = $call_flow_app; $_POST["call_flow_data"] = $call_flow_data; $_POST["call_flow_alternate_app"] = $call_flow_alternate_app; $_POST["call_flow_alternate_data"] = $call_flow_alternate_data; //check for all required data $msg = ''; //if (strlen($domain_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-domain_uuid']."
\n"; } //if (strlen($call_flow_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-call_flow_uuid']."
\n"; } //if (strlen($dialplan_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-dialplan_uuid']."
\n"; } //if (strlen($call_flow_name) == 0) { $msg .= $text['message-required']." ".$text['label-call_flow_name']."
\n"; } if (strlen($call_flow_extension) == 0) { $msg .= $text['message-required']." ".$text['label-call_flow_extension']."
\n"; } if (strlen($call_flow_feature_code) == 0) { $msg .= $text['message-required']." ".$text['label-call_flow_feature_code']."
\n"; } if (strlen($call_flow_context) == 0) { $msg .= $text['message-required']." ".$text['label-call_flow_context']."
\n"; } //if (strlen($call_flow_status) == 0) { $msg .= $text['message-required']." ".$text['label-call_flow_status']."
\n"; } //if (strlen($call_flow_pin_number) == 0) { $msg .= $text['message-required']." ".$text['label-call_flow_pin_number']."
\n"; } //if (strlen($call_flow_label) == 0) { $msg .= $text['message-required']." ".$text['label-call_flow_label']."
\n"; } //if (strlen($call_flow_sound) == 0) { $msg .= $text['message-required']." ".$text['label-call_flow_sound']."
\n"; } if (strlen($call_flow_app) == 0) { $msg .= $text['message-required']." ".$text['label-call_flow_app']."
\n"; } if (strlen($call_flow_data) == 0) { $msg .= $text['message-required']." ".$text['label-call_flow_data']."
\n"; } //if (strlen($call_flow_alternate_label) == 0) { $msg .= $text['message-required']." ".$text['label-call_flow_alternate_label']."
\n"; } //if (strlen($call_flow_alternate_sound) == 0) { $msg .= $text['message-required']." ".$text['label-call_flow_alternate_sound']."
\n"; } //if (strlen($call_flow_alternate_app) == 0) { $msg .= $text['message-required']." ".$text['label-call_flow_alternate_app']."
\n"; } //if (strlen($call_flow_alternate_data) == 0) { $msg .= $text['message-required']." ".$text['label-call_flow_alternate_data']."
\n"; } if (strlen($call_flow_description) == 0) { $msg .= $text['message-required']." ".$text['label-call_flow_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; } //set the domain_uuid $_POST["domain_uuid"] = $_SESSION["domain_uuid"]; //add the call_flow_uuid if (strlen($_POST["call_flow_uuid"]) == 0) { $call_flow_uuid = uuid(); $_POST["call_flow_uuid"] = $call_flow_uuid; } //add the dialplan_uuid if (!isset($_POST["dialplan_uuid"])) { $dialplan_uuid = uuid(); $_POST["dialplan_uuid"] = $dialplan_uuid; } //build the xml dialplan $dialplan_xml = "\n"; $dialplan_xml .= " \n"; $dialplan_xml .= " \n"; $dialplan_xml .= " \n"; $dialplan_xml .= " \n"; $dialplan_xml .= " \n"; $dialplan_xml .= " \n"; $dialplan_xml .= " \n"; $dialplan_xml .= " \n"; $dialplan_xml .= " \n"; $dialplan_xml .= "\n"; //build the dialplan array $dialplan["domain_uuid"] = $_SESSION['domain_uuid']; $dialplan["dialplan_uuid"] = $dialplan_uuid; $dialplan["dialplan_name"] = $call_flow_name; $dialplan["dialplan_number"] = $call_flow_extension; $dialplan["dialplan_context"] = $_SESSION['context']; $dialplan["dialplan_continue"] = "false"; $dialplan["dialplan_xml"] = $dialplan_xml; $dialplan["dialplan_order"] = "333"; $dialplan["dialplan_enabled"] = "true"; $dialplan["dialplan_description"] = $call_flow_description; $dialplan["app_uuid"] = "b1b70f85-6b42-429b-8c5a-60c8b02b7d14"; //prepare the array $array['call_flows'][] = $_POST; $array['dialplans'][] = $dialplan; //save to the data $orm = new orm; //$orm->name('call_flows'); $orm->app_name = 'call_flows'; $orm->app_uuid = 'b1b70f85-6b42-429b-8c5a-60c8b02b7d14'; if (strlen($call_flow_uuid) > 0) { $orm->uuid($call_flow_uuid); } $orm->save($array); $message = $orm->message; //debug info //echo "
";
			//print_r($message);
			//echo "
"; //exit; //save the xml save_dialplan_xml(); //apply settings reminder $_SESSION["reload_xml"] = true; //clear the cache $cache = new cache; $cache->delete("dialplan:".$call_flow_context); //redirect the user if (isset($action)) { if ($action == "add") { $_SESSION["message"] = $text['message-add']; } if ($action == "update") { $_SESSION["message"] = $text['message-update']; } header("Location: call_flows.php"); return; } } //(is_array($_POST) && strlen($_POST["persistformvar"]) == 0) //initialize the destinations object $destination = new destinations; //pre-populate the form if (is_array($_GET) && $_POST["persistformvar"] != "true") { $call_flow_uuid = check_str($_GET["id"]); $sql = "select * from v_call_flows "; $sql .= "where domain_uuid = '".$_SESSION["domain_uuid"]."' "; $sql .= "and call_flow_uuid = '$call_flow_uuid' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { //set the php variables $call_flow_uuid = $row["call_flow_uuid"]; $dialplan_uuid = $row["dialplan_uuid"]; $call_flow_name = $row["call_flow_name"]; $call_flow_extension = $row["call_flow_extension"]; $call_flow_feature_code = $row["call_flow_feature_code"]; $call_flow_context = $row["call_flow_context"]; $call_flow_status = $row["call_flow_status"]; $call_flow_pin_number = $row["call_flow_pin_number"]; $call_flow_label = $row["call_flow_label"]; $call_flow_sound = $row["call_flow_sound"]; $call_flow_app = $row["call_flow_app"]; $call_flow_data = $row["call_flow_data"]; $call_flow_alternate_label = $row["call_flow_alternate_label"]; $call_flow_alternate_sound = $row["call_flow_alternate_sound"]; $call_flow_alternate_app = $row["call_flow_alternate_app"]; $call_flow_alternate_data = $row["call_flow_alternate_data"]; $call_flow_description = $row["call_flow_description"]; //if superadmin show both the app and data if (if_group("superadmin")) { $destination_label = $call_flow_app.':'.$call_flow_data; } else { $destination_label = $call_flow_data; } //if superadmin show both the app and data if (if_group("superadmin")) { $alternate_destination_label = $call_flow_alternate_app.':'.$call_flow_alternate_data; } else { $alternate_destination_label = $call_flow_alternate_data; } } unset ($prep_statement); } //set the context for users that are not in the superadmin group if (strlen($call_flow_context) == 0) { $call_flow_context = $_SESSION['domain_name']; } //get the recordings $sql = "select recording_name, recording_filename from v_recordings "; $sql .= "where domain_uuid = '".$_SESSION["domain_uuid"]."' "; $sql .= "order by recording_name asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $recordings = $prep_statement->fetchAll(PDO::FETCH_ASSOC); if (if_group("superadmin")) { echo "\n"; echo "\n"; } function sound_select_list($var, $name, $description_name, $load_sound=false) { global $text, $recordings, $db; echo "\n"; echo "\n"; echo " ".$text['label-' . $description_name]."\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo $text['description-' . $description_name]."\n"; echo "\n"; echo "\n"; } //show the header require_once "resources/header.php"; //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 "\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 "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; sound_select_list($call_flow_sound, 'call_flow_sound', 'call_flow_sound', true); /* echo "\n"; echo "\n"; echo "\n"; echo "\n"; */ echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; sound_select_list($call_flow_alternate_sound, 'call_flow_alternate_sound', 'call_flow_alternate_sound', true); /* 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 " \n"; echo " \n"; echo " "; echo "
".$text['title-call_flow']."

\n"; echo " "; echo " "; echo "
\n"; echo " ".$text['label-call_flow_name']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-call_flow_name']."\n"; echo "
\n"; echo " ".$text['label-call_flow_extension']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-call_flow_extension']."\n"; echo "
\n"; echo " ".$text['label-call_flow_feature_code']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-call_flow_feature_code']."\n"; echo "
\n"; echo " ".$text['label-call_flow_context']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-call_flow_context']."\n"; echo "
\n"; echo " ".$text['label-call_flow_status']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-call_flow_status']."\n"; echo "
\n"; echo " ".$text['label-call_flow_pin_number']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-call_flow_pin_number']."\n"; echo "
\n"; echo " ".$text['label-call_flow_label']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-call_flow_label']."\n"; echo "
\n"; echo " ".$text['label-call_flow_sound']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-call_flow_sound']."\n"; echo "
\n"; echo " ".$text['label-call_flow_destination']."\n"; echo "\n"; $select_value = ''; //set the selected value if (strlen($call_flow_app.$call_flow_data) > 0) { $select_value = $call_flow_app.':'.$call_flow_data; } //show the destination list echo $destination->select('dialplan', 'call_flow_destination', $select_value); unset($select_value); echo "
\n"; echo $text['description-call_flow_destination']."\n"; echo "
\n"; echo " ".$text['label-call_flow_alternate_label']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-call_flow_alternate_label']."\n"; echo "
\n"; echo " ".$text['label-call_flow_alternate_sound']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-call_flow_alternate_sound']."\n"; echo "
\n"; echo " ".$text['label-call_flow_alternate_destination']."\n"; echo "\n"; $select_value = ''; if (strlen($call_flow_alternate_app.$call_flow_alternate_data) > 0) { $select_value = $call_flow_alternate_app.':'.$call_flow_alternate_data; } echo $destination->select('dialplan', 'call_flow_alternate_destination', $select_value); unset($select_value); echo "
\n"; echo $text['description-call_flow_alternate_destination']."\n"; echo "
\n"; echo " ".$text['label-call_flow_description']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-call_flow_description']."\n"; echo "
\n"; if ($action == "update") { echo " \n"; echo " \n"; } echo " \n"; echo "
"; echo "
"; echo "

"; //include the footer require_once "resources/footer.php"; ?>