IVR Menu - Edit: Integrate checkboxes on Options for bulk delete on Save (uses token).

This commit is contained in:
Nate 2020-02-19 19:56:11 -07:00
parent 7e6fbcbf1d
commit 9cf52ba33d
2 changed files with 114 additions and 25 deletions

View File

@ -126,6 +126,7 @@
$ivr_menu_cid_prefix = $_POST["ivr_menu_cid_prefix"];
$ivr_menu_enabled = $_POST["ivr_menu_enabled"];
$ivr_menu_description = $_POST["ivr_menu_description"];
$ivr_menu_options_delete = $_POST["ivr_menu_options_delete"];
$dialplan_uuid = $_POST["dialplan_uuid"];
//set the context for users that do not have the permission
@ -374,6 +375,18 @@
$p->delete("dialplan_add", "temp");
$p->delete("dialplan_edit", "temp");
//remove checked options
if (
$action == 'update'
&& permission_exists('ivr_menu_option_delete')
&& is_array($ivr_menu_options_delete)
&& @sizeof($ivr_menu_options_delete) != 0
) {
$obj = new ivr_menu;
$obj->ivr_menu_uuid = $ivr_menu_uuid;
$obj->delete_options($ivr_menu_options_delete);
}
//clear the cache
$cache = new cache;
$cache->delete("dialplan:".$_SESSION["context"]);
@ -460,10 +473,12 @@
if (count($ivr_menu_options) == 0) {
$rows = $_SESSION['ivr_menu']['option_add_rows']['numeric'];
$id = 0;
$show_option_delete = false;
}
if (count($ivr_menu_options) > 0) {
$rows = $_SESSION['ivr_menu']['option_edit_rows']['numeric'];
$id = count($ivr_menu_options)+1;
$show_option_delete = true;
}
for ($x = 0; $x < $rows; $x++) {
$ivr_menu_options[$id]['ivr_menu_option_digits'] = '';
@ -919,23 +934,25 @@
echo " <td class='vtable' align='left'>";
echo " <table border='0' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td class='vtable'>".$text['label-option']."</td>\n";
echo " <td class='vtable' style='text-align: center;'>".$text['label-option']."</td>\n";
echo " <td class='vtable'>".$text['label-destination']."</td>\n";
echo " <td class='vtable'>".$text['label-order']."</td>\n";
echo " <td class='vtable'>".$text['label-description']."</td>\n";
echo " <td></td>\n";
if ($show_option_delete) {
echo " <td class='vtable'>".$text['label-delete']."</td>\n";
}
echo " </tr>\n";
if (is_array($ivr_menu_options)) {
$c = 0;
$x = 0;
foreach($ivr_menu_options as $field) {
//add the primary key uuid
if (strlen($field['ivr_menu_option_uuid']) > 0) {
echo " <input name='ivr_menu_options[".$c."][ivr_menu_option_uuid]' type='hidden' value=\"".escape($field['ivr_menu_option_uuid'])."\">\n";
echo " <input name='ivr_menu_options[".$x."][ivr_menu_option_uuid]' type='hidden' value=\"".escape($field['ivr_menu_option_uuid'])."\">\n";
}
echo "<td class='formfld' align='left'>\n";
echo " <input class='formfld' style='width:70px' type='text' name='ivr_menu_options[".$c."][ivr_menu_option_digits]' maxlength='255' value='".escape($field['ivr_menu_option_digits'])."'>\n";
echo "<td class='formfld' align='center'>\n";
echo " <input class='formfld' style='width: 50px; text-align: center;' type='text' name='ivr_menu_options[".$x."][ivr_menu_option_digits]' maxlength='255' value='".escape($field['ivr_menu_option_digits'])."'>\n";
echo "</td>\n";
echo "<td class='formfld' align='left' nowrap='nowrap'>\n";
@ -943,17 +960,17 @@
if (strlen($field['ivr_menu_option_action'].$field['ivr_menu_option_param']) > 0) {
$destination_action = $field['ivr_menu_option_action'].':'.$field['ivr_menu_option_param'];
} else { $destination_action = ''; }
echo $destination->select('ivr', 'ivr_menu_options['.$c.'][ivr_menu_option_param]', $destination_action);
echo $destination->select('ivr', 'ivr_menu_options['.$x.'][ivr_menu_option_param]', $destination_action);
unset($destination_action);
echo "</td>\n";
echo "<td class='formfld' align='left'>\n";
echo " <select name='ivr_menu_options[".$c."][ivr_menu_option_order]' class='formfld' style='width:55px'>\n";
echo " <select name='ivr_menu_options[".$x."][ivr_menu_option_order]' class='formfld' style='width:55px'>\n";
//echo " <option></option>\n";
if (strlen(htmlspecialchars($field['ivr_menu_option_order']))> 0) {
if (strlen($field['ivr_menu_option_order']) == 1) { $field['ivr_menu_option_order'] = "00".$field['ivr_menu_option_order']; }
if (strlen($field['ivr_menu_option_order']) == 2) { $field['ivr_menu_option_order'] = "0".$field['ivr_menu_option_order']; }
echo " <option selected='yes' value='".escape($field['ivr_menu_option_order'])."'>".escape($field['ivr_menu_option_order'])."</option>\n";
echo " <option value='".escape($field['ivr_menu_option_order'])."'>".escape($field['ivr_menu_option_order'])."</option>\n";
}
$i=0;
while($i<=999) {
@ -966,21 +983,22 @@
echo "</td>\n";
echo "<td class='formfld' align='left'>\n";
echo " <input class='formfld' style='width:100px' type='text' name='ivr_menu_options[".$c."][ivr_menu_option_description]' maxlength='255' value=\"".$field['ivr_menu_option_description']."\">\n";
echo " <input class='formfld' style='width:100px' type='text' name='ivr_menu_options[".$x."][ivr_menu_option_description]' maxlength='255' value=\"".$field['ivr_menu_option_description']."\">\n";
echo "</td>\n";
echo " <td class='list_control_icons'>";
if (strlen($field['ivr_menu_option_uuid']) > 0) {
//echo " <a href='ivr_menu_option_edit.php?id=".$field['ivr_menu_option_uuid']."&ivr_menu_uuid=".$field['ivr_menu_uuid']."' alt='edit'>$v_link_label_edit</a>";
echo " <a href='ivr_menu_option_delete.php?id=".escape($field['ivr_menu_option_uuid'])."&ivr_menu_uuid=".escape($field['ivr_menu_uuid'])."&a=delete' alt='delete' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
echo "<td style='text-align: center;'>";
if (is_uuid($field['ivr_menu_option_uuid'])) {
echo " <input type='checkbox' name='ivr_menu_options_delete[".$x."][checked]' value='true'>\n";
echo " <input type='hidden' name='ivr_menu_options_delete[".$x."][uuid]' value='".escape($field['ivr_menu_option_uuid'])."' />\n";
}
else {
echo " &nbsp;\n";
echo "&nbsp;\n";
}
echo " </td>\n";
echo " </tr>\n";
echo "</td>\n";
$c++;
echo "</tr>\n";
$x++;
}
}
unset($sql, $result);

View File

@ -54,12 +54,7 @@ if (!class_exists('ivr_menu')) {
//assign private variables
$this->app_name = 'ivr_menus';
$this->app_uuid = 'a5788e9b-58bc-bd1b-df59-fff5d51253ab';
$this->permission_prefix = 'ivr_menu_';
$this->list_page = 'ivr_menus.php';
$this->table = 'ivr_menus';
$this->uuid_prefix = 'ivr_menu_';
$this->toggle_field = 'ivr_menu_enabled';
$this->toggle_values = ['true','false'];
}
@ -92,6 +87,11 @@ if (!class_exists('ivr_menu')) {
* delete records
*/
public function delete($records) {
//assign private variables
$this->permission_prefix = 'ivr_menu_';
$this->table = 'ivr_menus';
$this->uuid_prefix = 'ivr_menu_';
if (permission_exists($this->permission_prefix.'delete')) {
//add multi-lingual support
@ -147,7 +147,7 @@ if (!class_exists('ivr_menu')) {
//grant temporary permissions
$p = new permissions;
$p->add('ivr_menu_options_delete', 'temp');
$p->add('ivr_menu_option_delete', 'temp');
$p->add('dialplan_delete', 'temp');
//execute delete
@ -158,7 +158,7 @@ if (!class_exists('ivr_menu')) {
unset($array);
//revoke temporary permissions
$p->delete('ivr_menu_options_delete', 'temp');
$p->delete('ivr_menu_option_delete', 'temp');
$p->delete('dialplan_delete', 'temp');
//synchronize the xml config
@ -181,10 +181,76 @@ if (!class_exists('ivr_menu')) {
}
}
public function delete_options($records) {
//assign private variables
$this->permission_prefix = 'ivr_menu_option_';
$this->table = 'ivr_menu_options';
$this->uuid_prefix = 'ivr_menu_option_';
if (permission_exists($this->permission_prefix.'delete')) {
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->list_page);
exit;
}
//delete multiple records
if (is_array($records) && @sizeof($records) != 0) {
//filter out unchecked ivr menu options, build delete array
$x = 0;
foreach ($records as $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
$array[$this->table][$x]['ivr_menu_uuid'] = $this->ivr_menu_uuid;
$x++;
}
}
//get ivr menu context
if (is_array($uuids) && @sizeof($uuids) != 0) {
$sql = "select ivr_menu_context from v_ivr_menus ";
$sql .= "where (domain_uuid = :domain_uuid) ";
$sql .= "and ivr_menu_uuid = :ivr_menu_uuid ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['ivr_menu_uuid'] = $this->ivr_menu_uuid;
$database = new database;
$ivr_menu_context = $database->select($sql, $parameters, 'column');
unset($sql, $parameters);
}
//delete the checked rows
if (is_array($array) && @sizeof($array) != 0) {
//execute delete
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->delete($array);
unset($array);
}
unset($records);
}
}
}
/**
* toggle records
*/
public function toggle($records) {
//assign private variables
$this->permission_prefix = 'ivr_menu_';
$this->table = 'ivr_menus';
$this->uuid_prefix = 'ivr_menu_';
$this->toggle_field = 'ivr_menu_enabled';
$this->toggle_values = ['true','false'];
if (permission_exists($this->permission_prefix.'edit')) {
//add multi-lingual support
@ -274,6 +340,11 @@ if (!class_exists('ivr_menu')) {
* copy records
*/
public function copy($records) {
//assign private variables
$this->permission_prefix = 'ivr_menu_';
$this->table = 'ivr_menus';
$this->uuid_prefix = 'ivr_menu_';
if (permission_exists($this->permission_prefix.'add')) {
//add multi-lingual support