IVR Menus: Database class integration.
This commit is contained in:
+120
-121
@@ -44,130 +44,129 @@
|
||||
$text = $language->get();
|
||||
|
||||
//set the http get/post variable(s) to a php variable
|
||||
if (isset($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
|
||||
$ivr_menu_uuid = $_GET["id"];
|
||||
$ivr_menu_uuid = $_GET["id"];
|
||||
|
||||
if (is_uuid($ivr_menu_uuid)) {
|
||||
|
||||
//get the ivr_menus data
|
||||
$sql = "select * from v_ivr_menus ";
|
||||
$sql .= "where ivr_menu_uuid = :ivr_menu_uuid ";
|
||||
$sql .= "and domain_uuid = :domain_uuid ";
|
||||
$parameters['ivr_menu_uuid'] = $ivr_menu_uuid;
|
||||
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
|
||||
$database = new database;
|
||||
$ivr_menus = $database->select($sql, $parameters, 'all');
|
||||
if (!is_array($ivr_menus)) {
|
||||
echo "access denied 63";
|
||||
exit;
|
||||
}
|
||||
unset($sql, $parameters);
|
||||
|
||||
//get the the ivr menu options
|
||||
$sql = "select * from v_ivr_menu_options ";
|
||||
$sql .= "where ivr_menu_uuid = :ivr_menu_uuid ";
|
||||
$sql .= "and domain_uuid = :domain_uuid ";
|
||||
$sql .= "order by ivr_menu_uuid asc ";
|
||||
$parameters['ivr_menu_uuid'] = $ivr_menu_uuid;
|
||||
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
|
||||
$database = new database;
|
||||
$ivr_menu_options = $database->select($sql, $parameters, 'all');
|
||||
unset($sql, $parameters);
|
||||
|
||||
//create the uuids
|
||||
$ivr_menu_uuid = uuid();
|
||||
$dialplan_uuid = uuid();
|
||||
|
||||
//set the row id
|
||||
$x = 0;
|
||||
|
||||
//set the variables
|
||||
$ivr_menu_name = $ivr_menus[$x]['ivr_menu_name'];
|
||||
$ivr_menu_extension = $ivr_menus[$x]['ivr_menu_extension'];
|
||||
$ivr_menu_ringback = $ivr_menus[$x]['ivr_menu_ringback'];
|
||||
$ivr_menu_description = $ivr_menus[$x]['ivr_menu_description'].' ('.$text['label-copy'].')';
|
||||
|
||||
//prepare the ivr menu array
|
||||
$ivr_menus[$x]['ivr_menu_uuid'] = $ivr_menu_uuid;
|
||||
$ivr_menus[$x]['dialplan_uuid'] = $dialplan_uuid;
|
||||
$ivr_menus[$x]['ivr_menu_name'] = $ivr_menu_name;
|
||||
$ivr_menus[$x]['ivr_menu_description'] = $ivr_menu_description;
|
||||
|
||||
//get the the ivr menu options
|
||||
$y = 0;
|
||||
foreach ($ivr_menu_options as &$row) {
|
||||
//update the uuids
|
||||
$row['ivr_menu_uuid'] = $ivr_menu_uuid;
|
||||
$row['ivr_menu_option_uuid'] = uuid();
|
||||
//add the row to the array
|
||||
$ivr_menus[$x]["ivr_menu_options"][$y] = $row;
|
||||
//increment the ivr menu option row id
|
||||
$y++;
|
||||
}
|
||||
|
||||
//build the xml dialplan
|
||||
$dialplan_xml = "<extension name=\"".$ivr_menu_name."\" continue=\"\" uuid=\"".$dialplan_uuid."\">\n";
|
||||
$dialplan_xml .= " <condition field=\"destination_number\" expression=\"^".$ivr_menu_extension."\">\n";
|
||||
$dialplan_xml .= " <action application=\"answer\" data=\"\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"sleep\" data=\"1000\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"set\" data=\"hangup_after_bridge=true\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"set\" data=\"ringback=".$ivr_menu_ringback."\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"set\" data=\"transfer_ringback=".$ivr_menu_ringback."\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"set\" data=\"ivr_menu_uuid=".$ivr_menu_uuid."\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"ivr\" data=\"".$ivr_menu_uuid."\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"hangup\" data=\"\"/>\n";
|
||||
$dialplan_xml .= " </condition>\n";
|
||||
$dialplan_xml .= "</extension>\n";
|
||||
|
||||
//build the dialplan array
|
||||
$dialplan[$x]["domain_uuid"] = $_SESSION['domain_uuid'];
|
||||
$dialplan[$x]["dialplan_uuid"] = $dialplan_uuid;
|
||||
$dialplan[$x]["dialplan_name"] = $ivr_menu_name;
|
||||
$dialplan[$x]["dialplan_number"] = $ivr_menu_extension;
|
||||
$dialplan[$x]["dialplan_context"] = $_SESSION["context"];
|
||||
$dialplan[$x]["dialplan_continue"] = "false";
|
||||
$dialplan[$x]["dialplan_xml"] = $dialplan_xml;
|
||||
$dialplan[$x]["dialplan_order"] = "101";
|
||||
$dialplan[$x]["dialplan_enabled"] = "true";
|
||||
$dialplan[$x]["dialplan_description"] = $ivr_menu_description;
|
||||
$dialplan[$x]["app_uuid"] = "a5788e9b-58bc-bd1b-df59-fff5d51253ab";
|
||||
|
||||
//prepare the array
|
||||
$array['ivr_menus'] = $ivr_menus;
|
||||
$array['dialplans'] = $dialplan;
|
||||
|
||||
//add the dialplan permission
|
||||
$p = new permissions;
|
||||
$p->add("dialplan_add", "temp");
|
||||
$p->add("dialplan_edit", "temp");
|
||||
|
||||
//save the array to the database
|
||||
$database = new database;
|
||||
$database->app_name = 'ivr_menus';
|
||||
$database->app_uuid = 'a5788e9b-58bc-bd1b-df59-fff5d51253ab';
|
||||
if (is_uuid($ivr_menu_uuid)) {
|
||||
$database->uuid($ivr_menu_uuid);
|
||||
}
|
||||
$database->save($array);
|
||||
$message = $database->message;
|
||||
|
||||
//remove the temporary permission
|
||||
$p->delete("dialplan_add", "temp");
|
||||
$p->delete("dialplan_edit", "temp");
|
||||
|
||||
//synchronize the xml config
|
||||
save_dialplan_xml();
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$_SESSION["context"]);
|
||||
|
||||
//set message
|
||||
message::add($text['message-copy']);
|
||||
}
|
||||
else {
|
||||
echo "access denied";
|
||||
exit;
|
||||
}
|
||||
|
||||
//get the ivr_menus data
|
||||
$sql = "select * from v_ivr_menus ";
|
||||
$sql .= "where ivr_menu_uuid = '$ivr_menu_uuid' ";
|
||||
$sql .= "and domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$ivr_menus = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
if (!is_array($ivr_menus)) {
|
||||
echo "access denied 63";
|
||||
exit;
|
||||
}
|
||||
|
||||
//get the the ivr menu options
|
||||
$sql = "select * from v_ivr_menu_options ";
|
||||
$sql .= "where ivr_menu_uuid = '$ivr_menu_uuid' ";
|
||||
$sql .= "and domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
||||
$sql .= "order by ivr_menu_uuid asc ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$ivr_menu_options = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
|
||||
//create the uuids
|
||||
$ivr_menu_uuid = uuid();
|
||||
$dialplan_uuid = uuid();
|
||||
|
||||
//set the row id
|
||||
$x = 0;
|
||||
|
||||
//set the variables
|
||||
$ivr_menu_name = 'copy-'.$ivr_menus[$x]['ivr_menu_name'];
|
||||
$ivr_menu_extension = $ivr_menus[$x]['ivr_menu_extension'];
|
||||
$ivr_menu_ringback = $ivr_menus[$x]['ivr_menu_ringback'];
|
||||
$ivr_menu_description = 'copy-'.$ivr_menus[$x]['ivr_menu_description'];
|
||||
|
||||
//prepare the ivr menu array
|
||||
$ivr_menus[$x]['ivr_menu_uuid'] = $ivr_menu_uuid;
|
||||
$ivr_menus[$x]['dialplan_uuid'] = $dialplan_uuid;
|
||||
$ivr_menus[$x]['ivr_menu_name'] = $ivr_menu_name;
|
||||
$ivr_menus[$x]['ivr_menu_description'] = $ivr_menu_description;
|
||||
|
||||
//get the the ivr menu options
|
||||
$y = 0;
|
||||
foreach ($ivr_menu_options as &$row) {
|
||||
|
||||
//update the uuids
|
||||
$row['ivr_menu_uuid'] = $ivr_menu_uuid;
|
||||
$row['ivr_menu_option_uuid'] = uuid();
|
||||
|
||||
//add the row to the array
|
||||
$ivr_menus[$x]["ivr_menu_options"][$y] = $row;
|
||||
|
||||
//increment the ivr menu option row id
|
||||
$y++;
|
||||
|
||||
}
|
||||
|
||||
//build the xml dialplan
|
||||
$dialplan_xml = "<extension name=\"".$ivr_menu_name."\" continue=\"\" uuid=\"".$dialplan_uuid."\">\n";
|
||||
$dialplan_xml .= " <condition field=\"destination_number\" expression=\"^".$ivr_menu_extension."\">\n";
|
||||
$dialplan_xml .= " <action application=\"answer\" data=\"\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"sleep\" data=\"1000\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"set\" data=\"hangup_after_bridge=true\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"set\" data=\"ringback=".$ivr_menu_ringback."\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"set\" data=\"transfer_ringback=".$ivr_menu_ringback."\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"set\" data=\"ivr_menu_uuid=".$ivr_menu_uuid."\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"ivr\" data=\"".$ivr_menu_uuid."\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"hangup\" data=\"\"/>\n";
|
||||
$dialplan_xml .= " </condition>\n";
|
||||
$dialplan_xml .= "</extension>\n";
|
||||
|
||||
//build the dialplan array
|
||||
$dialplan[$x]["domain_uuid"] = $_SESSION['domain_uuid'];
|
||||
$dialplan[$x]["dialplan_uuid"] = $dialplan_uuid;
|
||||
$dialplan[$x]["dialplan_name"] = $ivr_menu_name;
|
||||
$dialplan[$x]["dialplan_number"] = $ivr_menu_extension;
|
||||
$dialplan[$x]["dialplan_context"] = $_SESSION["context"];
|
||||
$dialplan[$x]["dialplan_continue"] = "false";
|
||||
$dialplan[$x]["dialplan_xml"] = $dialplan_xml;
|
||||
$dialplan[$x]["dialplan_order"] = "101";
|
||||
$dialplan[$x]["dialplan_enabled"] = "true";
|
||||
$dialplan[$x]["dialplan_description"] = $ivr_menu_description;
|
||||
$dialplan[$x]["app_uuid"] = "a5788e9b-58bc-bd1b-df59-fff5d51253ab";
|
||||
|
||||
//prepare the array
|
||||
$array['ivr_menus'] = $ivr_menus;
|
||||
$array['dialplans'] = $dialplan;
|
||||
|
||||
//add the dialplan permission
|
||||
$p = new permissions;
|
||||
$p->add("dialplan_add", "temp");
|
||||
$p->add("dialplan_edit", "temp");
|
||||
|
||||
//save the array to the database
|
||||
$database = new database;
|
||||
$database->app_name = 'ivr_menus';
|
||||
$database->app_uuid = 'a5788e9b-58bc-bd1b-df59-fff5d51253ab';
|
||||
if (strlen($ivr_menu_uuid) > 0) {
|
||||
$database->uuid($ivr_menu_uuid);
|
||||
}
|
||||
$database->save($array);
|
||||
$message = $database->message;
|
||||
|
||||
//remove the temporary permission
|
||||
$p->delete("dialplan_add", "temp");
|
||||
$p->delete("dialplan_edit", "temp");
|
||||
|
||||
//synchronize the xml config
|
||||
save_dialplan_xml();
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$_SESSION["context"]);
|
||||
|
||||
//redirect the user
|
||||
message::add($text['message-copy']);
|
||||
header("Location: ivr_menus.php");
|
||||
return;
|
||||
exit;
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user