Extension Edit/Import/Export - Action bar, button and list updates.

This commit is contained in:
Nate 2020-01-11 11:06:49 -07:00
parent 02c9326143
commit 4de20fd969
3 changed files with 168 additions and 169 deletions

View File

@ -25,19 +25,19 @@
*/
//includes
include "root.php";
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
require_once "resources/paging.php";
//check permissions
if (permission_exists('extension_export')) {
//access granted
}
else {
echo "access denied";
exit;
}
if (permission_exists('extension_export')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
@ -131,8 +131,17 @@
//get the extensions from the database and send them as output
if (is_array($_REQUEST["column_group"]) && @sizeof($_REQUEST["column_group"]) != 0) {
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: extension_download.php');
exit;
}
//validate submitted columns
foreach($_REQUEST["column_group"] as $column_name) {
foreach ($_REQUEST["column_group"] as $column_name) {
if (in_array($column_name, $available_columns)) {
$selected_columns[] = $column_name;
}
@ -145,73 +154,60 @@
$extensions = $database->select($sql, $parameters, 'all');
unset($sql, $parameters, $selected_columns);
download_send_headers("data_export_".date("Y-m-d").".csv");
download_send_headers("extension_export_".date("Y-m-d").".csv");
echo array2csv($extensions);
exit;
}
}
//set the row styles
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
//begin the page content
//include the header
$document['title'] = $text['title-extension_export'];
require_once "resources/header.php";
echo "<form method='post' name='frm' action='extension_download.php' autocomplete='off'>\n";
//show the content
echo "<form method='post' name='frm'>\n";
echo "<div style='float: right;'>\n";
echo "<input type='button' class='btn' alt='".$text['button-back']."' onclick=\"window.location='extensions.php'\" value='".$text['button-back']."'>\n";
echo "<input type='submit' class='btn' value='".$text['button-export']."'>\n";
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['header-extension_export']."</b></div>\n";
echo " <div class='actions'>\n";
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'link'=>'extensions.php']);
echo button::create(['type'=>'submit','label'=>$text['button-export'],'icon'=>$_SESSION['theme']['button_icon_export'],'style'=>'margin-left: 15px;']);
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo "<b>".$text['header-extension_export']."</b>\n";
echo "<br /><br />\n";
echo "<table class='tr_hover' width='100%' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo " <th style='padding: 0;'><input type='checkbox' id='selectall' onclick='checkbox_toggle();'/></th>\n";
echo " <th width='100%'>".$text['label-column_name']."</th>\n";
echo "<table class='list'>\n";
echo "<tr class='list-header'>\n";
echo " <th class='checkbox'>\n";
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle();' ".($available_columns ?: "style='visibility: hidden;'").">\n";
echo " </th>\n";
echo " <th>".$text['label-column_name']."</th>\n";
echo "</tr>\n";
foreach ($available_columns as $column_name) {
$tr_link = "onclick=\"document.getElementById('checkbox_".$column_name."').checked = document.getElementById('checkbox_".$column_name."').checked ? false : true;\"";
echo "<tr>\n";
echo " <td valign='middle' class='".$row_style[$c]."' style='padding: 0;'><input class='checkbox1' type='checkbox' name='column_group[]' id=\"checkbox_".$column_name."\" value=\"".$column_name."\" /></td>\n";
echo " <td valign='middle' class='".$row_style[$c]."' ".$tr_link.">".$column_name."</td>\n";
echo "</tr>\n";
$c = $c ? 0 : 1;
if (is_array($available_columns) && @sizeof($available_columns) != 0) {
$x = 0;
foreach ($available_columns as $column_name) {
$list_row_onclick = "if (!this.checked) { document.getElementById('checkbox_all').checked = false; }";
echo "<tr class='list-row' href='".$list_row_url."'>\n";
echo " <td class='checkbox'>\n";
echo " <input type='checkbox' name='column_group[]' id='checkbox_".$x."' value=\"".$column_name."\" onclick=\"".$list_row_onclick."\">\n";
echo " </td>\n";
echo " <td onclick=\"document.getElementById('checkbox_".$x."').checked = document.getElementById('checkbox_".$x."').checked ? false : true; ".$list_row_onclick."\">".$column_name."</td>";
echo "</tr>";
$x++;
}
}
echo "<tr>\n";
echo " <td colspan='2' align='right'>\n";
echo " <br>\n";
echo " <input type='submit' class='btn' value='".$text['button-export']."'>\n";
echo " </td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<br><br>\n";
echo "<br />\n";
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "</form>\n";
//define the checkbox_toggle function
echo "<script type=\"text/javascript\">\n";
echo " function checkbox_toggle(item) {\n";
echo " var inputs = document.getElementsByTagName(\"input\");\n";
echo " for (var i = 0, max = inputs.length; i < max; i++) {\n";
echo " if (inputs[i].type === 'checkbox') {\n";
echo " if (document.getElementById('selectall').checked == true) {\n";
echo " inputs[i].checked = true;\n";
echo " }\n";
echo " else {\n";
echo " inputs[i].checked = false;\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo "</script>\n";
//include the footer
require_once "resources/footer.php";
?>
?>

View File

@ -872,39 +872,39 @@
echo "</script>";
echo "<form method='post' name='frm' id='frm' action=''>\n";
if (is_numeric($page)) {
echo "<input type='hidden' name='page' value='".$page."'>\n";
}
echo "<table width='100%' border='0' cellpdding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'>";
if ($action == "add") {
echo "<td width='30%' nowrap='nowrap' align='left' valign='top'><b>".$text['header-extension-add']."</b></td>\n";
echo "<b>".$text['header-extension-add']."</b>";
}
if ($action == "update") {
echo "<td width='30%' nowrap='nowrap' align='left' valign='top'><b>".$text['header-extension-edit']."</b></td>\n";
echo "<b>".$text['header-extension-edit']."</b>";
}
echo "<td width='70%' align='right' valign='top'>\n";
echo " <input type='button' class='btn' alt='".$text['button-back']."' onclick=\"window.location='extensions.php".(is_numeric($page) ? '?page='.$page : null)."'\" value='".$text['button-back']."'>\n";
echo "</div>\n";
echo " <div class='actions'>\n";
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'style'=>'margin-right: 15px;','link'=>'extensions.php'.(is_numeric($page) ? '?page='.$page : null)]);
if ($action == 'update' && permission_exists('xml_cdr_view')) {
echo " <input type='button' class='btn' alt='".$text['button-cdr']."' onclick=\"window.location='../xml_cdr/xml_cdr.php?extension_uuid=".urlencode($extension_uuid)."';\" value='".$text['button-cdr']."'>\n";
echo button::create(['type'=>'button','label'=>$text['button-cdr'],'icon'=>'info-circle','link'=>'../xml_cdr/xml_cdr.php?extension_uuid='.urlencode($extension_uuid)]);
}
if ($action == 'update' && (permission_exists('follow_me') || permission_exists('call_forward') || permission_exists('do_not_disturb'))) {
echo " <input type='button' class='btn' alt='".$text['button-call_routing']."' onclick=\"window.location='../calls/call_edit.php?id=".urlencode($extension_uuid)."';\" value='".$text['button-call_routing']."'>\n";
echo button::create(['type'=>'button','label'=>$text['button-call_routing'],'icon'=>'project-diagram','link'=>'../calls/call_edit.php?id='.urlencode($extension_uuid)]);
}
if ($action == "update" && permission_exists('extension_copy')) {
echo " <input type='button' class='btn' alt='".$text['button-copy']."' onclick=\"copy_extension();\" value='".$text['button-copy']."'>\n";
echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'onclick'=>"copy_extension();"]);
}
echo " <input type='submit' class='btn' value='".$text['button-save']."' onclick=''>\n";
echo " <br /><br />\n";
echo "</td>\n";
echo "</tr>\n";
echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'style'=>'margin-left: 15px;']);
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo "<td width='30%' class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-extension']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo "<td width='70%' class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='extension' autocomplete='new-password' maxlength='255' value=\"".escape($extension)."\" required='required'>\n";
echo "<br />\n";
echo $text['description-extension']."\n";
@ -1006,8 +1006,7 @@
echo " <option value='".escape($field['user_uuid'])."'>".escape($field['username'])."</option>\n";
}
echo " </select>";
echo " <input type='submit' class='btn' value=\"".$text['button-add']."\" onclick=''>\n";
echo button::create(['type'=>'submit','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add']]);
echo " <br>\n";
echo " ".$text['description-user_list']."\n";
echo " <br />\n";
@ -1178,7 +1177,7 @@
echo "</select>\n";
echo " </td>\n";
echo " <td>\n";
echo " <input type='submit' class='btn' value=\"".$text['button-add']."\" onclick=''>\n";
echo button::create(['type'=>'submit','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add']]);
echo " </td>\n";
echo " </table>\n";
echo " <br />\n";
@ -1719,7 +1718,8 @@
echo " <tr>\n";
echo " <td width=\"30%\" valign=\"top\" class=\"vncell\">&nbsp;</td>\n";
echo " <td width=\"70%\" class=\"vtable\">\n";
echo " <input type=\"button\" class=\"btn\" onClick=\"show_advanced_config()\" value=\"".$text['button-advanced']."\"></input>\n";
echo button::create(['type'=>'button','label'=>$text['button-advanced'],'icon'=>'tools','onclick'=>'show_advanced_config();']);
// echo " <input type=\"button\" class=\"btn\" onClick=\"show_advanced_config()\" value=\"".$text['button-advanced']."\"></input>\n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
@ -1955,27 +1955,27 @@
echo $text['description-description']."\n";
echo "</td>\n";
echo "</tr>\n";
echo " <tr>\n";
echo " <td colspan='2' align='right'>\n";
if ($action == "update") {
echo " <input type='hidden' name='extension_uuid' value='".escape($extension_uuid)."'>\n";
echo " <input type='hidden' name='id' id='id' value='".escape($extension_uuid)."'>";
if (!permission_exists('extension_domain')) {
echo " <input type='hidden' name='domain_uuid' id='domain_uuid' value='".$_SESSION['domain_uuid']."'>";
}
echo " <input type='hidden' name='delete_type' id='delete_type' value=''>";
echo " <input type='hidden' name='delete_uuid' id='delete_uuid' value=''>";
}
echo " <input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo " <br>";
echo " <input type='submit' class='btn' value='".$text['button-save']."' onclick=''>\n";
echo " </td>\n";
echo " </tr>";
echo "</table>";
echo "<br><br>";
if (is_numeric($page)) {
echo "<input type='hidden' name='page' value='".$page."'>\n";
}
if ($action == "update") {
echo "<input type='hidden' name='extension_uuid' value='".escape($extension_uuid)."'>\n";
echo "<input type='hidden' name='id' id='id' value='".escape($extension_uuid)."'>";
if (!permission_exists('extension_domain')) {
echo "<input type='hidden' name='domain_uuid' id='domain_uuid' value='".$_SESSION['domain_uuid']."'>";
}
echo "<input type='hidden' name='delete_type' id='delete_type' value=''>";
echo "<input type='hidden' name='delete_uuid' id='delete_uuid' value=''>";
}
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "</form>";
//include the footer
require_once "resources/footer.php";
?>
?>

View File

@ -43,7 +43,7 @@
$text = $language->get();
//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduct the functionality but requirs PHP 5.1.0 or higher
if(!function_exists('str_getcsv')) {
if (!function_exists('str_getcsv')) {
function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") {
$fp = fopen("php://memory", 'r+');
fputs($fp, $input);
@ -90,9 +90,9 @@
//get the schema
$x = 0;
include ("app/extensions/app_config.php");
include "app/extensions/app_config.php";
$i = 0;
foreach($apps[0]['db'] as $table) {
foreach ($apps[0]['db'] as $table) {
//get the table name and parent name
$table_name = $table["table"]['name'];
$parent_name = $table["table"]['parent'];
@ -109,7 +109,7 @@
if ($table_name == "extensions") {
$schema[$i]['table'] = $table_name;
$schema[$i]['parent'] = $parent_name;
foreach($table['fields'] as $row) {
foreach ($table['fields'] as $row) {
if ($row['deprecated'] !== 'true') {
if (is_array($row['name'])) {
$field_name = $row['name']['text'];
@ -133,45 +133,49 @@
//match the column names to the field names
if (strlen($delimiter) > 0 && file_exists($_SESSION['file']) && $action != 'import') {
//form to match the fields to the column names
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: extension_imports.php');
exit;
}
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
//include header
$document['title'] = $text['title-extension_import'];
require_once "resources/header.php";
echo "<form action='extension_imports.php' method='POST' enctype='multipart/form-data' name='frmUpload' onSubmit=''>\n";
//form to match the fields to the column names
echo "<form name='frmUpload' method='post' enctype='multipart/form-data'>\n";
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['header-import']."</b></div>\n";
echo " <div class='actions'>\n";
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'style'=>'margin-right: 15px;','link'=>'extension_imports.php']);
echo button::create(['type'=>'submit','label'=>$text['button-import'],'icon'=>$_SESSION['theme']['button_icon_import']]);
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo $text['description-import']."\n";
echo "<br /><br />\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo " <td valign='top' align='left' nowrap='nowrap'>\n";
echo " <b>".$text['header-import']."</b><br />\n";
echo " </td>\n";
echo " <td valign='top' align='right'>\n";
echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='../extensions/extensions.php'\" value='".$text['button-back']."'>\n";
echo " <input name='submit' type='submit' class='btn' id='import' value=\"".$text['button-import']."\">\n";
echo " </td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo " <td colspan='2' align='left'>\n";
echo " ".$text['description-import']."\n";
echo " </td>\n";
echo "</tr>\n";
//echo "<tr>\n";
//echo "<td align='left' width='30%' nowrap='nowrap'><b>".$text['header-import']."</b></td>\n";
//echo "<td width='70%' align='right'>\n";
//echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='../extensions/extensions.php'\" value='".$text['button-back']."'>\n";
//echo "</td>\n";
//echo "</tr>\n";
//loop through user columns
$x = 0;
foreach ($line_fields as $line_field) {
$line_field = trim(trim($line_field), $enclosure);
echo "<tr>\n";
echo " <td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " <td width='30%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
//echo " ".$text['label-zzz']."\n";
echo $line_field;
echo " </td>\n";
echo " <td class='vtable' align='left'>\n";
echo " <td width='70%' class='vtable' align='left'>\n";
echo " <select class='formfld' style='' name='fields[$x]'>\n";
echo " <option value=''></option>\n";
foreach($schema as $row) {
@ -195,18 +199,16 @@
$x++;
}
echo "<tr>\n";
echo " <td colspan='2' valign='top' align='right' nowrap='nowrap'>\n";
echo " <input name='action' type='hidden' value='import'>\n";
echo " <input name='from_row' type='hidden' value='$from_row'>\n";
echo " <input name='data_delimiter' type='hidden' value='$delimiter'>\n";
echo " <input name='data_enclosure' type='hidden' value='$enclosure'>\n";
echo " <input type='submit' class='btn' id='import' value=\"".$text['button-import']."\">\n";
echo " </td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<input name='action' type='hidden' value='import'>\n";
echo "<input name='from_row' type='hidden' value='$from_row'>\n";
echo "<input name='data_delimiter' type='hidden' value='$delimiter'>\n";
echo "<input name='data_enclosure' type='hidden' value='$enclosure'>\n";
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "</form>\n";
require_once "resources/footer.php";
//normalize the column names
@ -234,8 +236,13 @@
//upload the csv
if (file_exists($_SESSION['file']) && $action == 'import') {
//form to match the fields to the column names
//require_once "resources/header.php";
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: extension_imports.php');
exit;
}
//user selected fields
$fields = $_POST['fields'];
@ -345,28 +352,30 @@
}
}
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
//include the header
$document['title'] = $text['title-extension_import'];
require_once "resources/header.php";
//begin the content
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td valign='top' align='left' width='30%' nowrap='nowrap'>\n";
echo " <b>".$text['header-extension_import']."</b><br />\n";
echo " ".$text['description-import']."\n";
echo " </td>\n";
echo " <td valign='top' width='70%' align='right'>\n";
echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='extensions.php'\" value='".$text['button-back']."'>\n";
//echo " <input name='submit' type='submit' class='btn' id='import' value=\"".$text['button-import']."\">\n";
echo " </td>\n";
echo " </tr>\n";
echo "</table>";
echo "<br />\n";
//show content
echo "<form action='' method='POST' enctype='multipart/form-data' name='frmUpload' onSubmit=''>\n";
echo " <table border='0' cellpadding='0' cellspacing='0' width='100%'>\n";
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['header-extension_import']."</b></div>\n";
echo " <div class='actions'>\n";
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'style'=>'margin-right: 15px;','link'=>'extensions.php']);
echo button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>$_SESSION['theme']['button_icon_upload']]);
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo $text['description-import']."\n";
echo "<br /><br />\n";
echo "<table border='0' cellpadding='0' cellspacing='0' width='100%'>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
@ -435,21 +444,15 @@
echo "</td>\n";
echo "</tr>\n";
echo " <tr>\n";
echo " <td valign='bottom'>\n";
echo " &nbsp;\n";
echo " </td>\n";
echo " <td valign='bottom' align='right' nowrap>\n";
echo " <input name='type' type='hidden' value='csv'>\n";
echo " <br />\n";
echo " <input name='submit' type='submit' class='btn' id='import' value=\"".$text['button-import']."\">\n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</table>\n";
echo "<br><br>";
echo "<input name='type' type='hidden' value='csv'>\n";
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "</form>";
//include the footer
require_once "resources/footer.php";
?>
?>