WIP: PEN form near to clear
This commit is contained in:
parent
8d8474e67e
commit
86cbecc9a0
|
@ -140,18 +140,18 @@ if (check_acl($config['id_user'], 0, 'PM')) {
|
|||
$sub['godmode/modules/manage_network_components']['text'] = __('Remote components');
|
||||
$sub['godmode/modules/manage_network_components']['id'] = 'Network components';
|
||||
enterprise_hook('components_submenu');
|
||||
$sub['godmode/modules/configuration_wizard_setup']['text'] = __('Wizard Setup');
|
||||
$sub['godmode/modules/configuration_wizard_setup']['id'] = 'Wizard Setup';
|
||||
$sub['godmode/modules/configuration_wizard_setup']['type'] = 'direct';
|
||||
$sub['godmode/modules/configuration_wizard_setup']['subtype'] = 'nolink';
|
||||
$sub['configuration_wizard_setup']['text'] = __('Wizard Setup');
|
||||
$sub['configuration_wizard_setup']['id'] = 'Wizard Setup';
|
||||
$sub['configuration_wizard_setup']['type'] = 'direct';
|
||||
$sub['configuration_wizard_setup']['subtype'] = 'nolink';
|
||||
$sub2 = [];
|
||||
$sub2['private_enterprise_numbers']['text'] = __('Private Enterprise Numbers');
|
||||
$sub2['private_enterprise_numbers']['id'] = 'Private Enterprise Numbers';
|
||||
$sub2['SNMP_modules']['text'] = __('SNMP Modules');
|
||||
$sub2['SNMP_modules']['id'] = 'SNMP Modules';
|
||||
$sub2['WMI_modules']['text'] = __('WMI Modules');
|
||||
$sub2['WMI_modules']['id'] = 'WMI Modules';
|
||||
$sub['godmode/modules/configuration_wizard_setup']['sub2'] = $sub2;
|
||||
$sub2['godmode/modules/private_enterprise_numbers']['text'] = __('Private Enterprise Numbers');
|
||||
$sub2['godmode/modules/private_enterprise_numbers']['id'] = 'Private Enterprise Numbers';
|
||||
$sub2['godmode/modules/SNMP_modules']['text'] = __('SNMP Modules');
|
||||
$sub2['godmode/modules/SNMP_modules']['id'] = 'SNMP Modules';
|
||||
$sub2['godmode/modules/WMI_modules']['text'] = __('WMI Modules');
|
||||
$sub2['godmode/modules/WMI_modules']['id'] = 'WMI Modules';
|
||||
$sub['configuration_wizard_setup']['sub2'] = $sub2;
|
||||
$sub['godmode/modules/manage_block_templates']['text'] = __('Module blocks');
|
||||
$sub['godmode/modules/manage_block_templates']['id'] = 'Module blocks';
|
||||
$sub['godmode/modules/manage_network_templates']['text'] = __('Module templates <i>(legacy)</i>');
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2020 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation for version 2.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// Load global vars
|
||||
// TESTING
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
// END
|
||||
global $config;
|
||||
|
||||
check_login();
|
||||
|
||||
if (! check_acl($config['id_user'], 0, 'PM')) {
|
||||
db_pandora_audit(
|
||||
'ACL Violation',
|
||||
'Trying to access Network Profile Management'
|
||||
);
|
||||
include 'general/noaccess.php';
|
||||
return;
|
||||
}
|
||||
|
||||
require_once $config['homedir'].'/include/class/ConfigPEN.class.php';
|
||||
|
||||
try {
|
||||
$configPEN = new ConfigPEN();
|
||||
// Run the page.
|
||||
$configPEN->run();
|
||||
} catch (Exception $ex) {
|
||||
ui_print_error_message(__('Something went wrong. Please, take a look in the Pandora FMS log'));
|
||||
echo '[PEN Configuration]'.$ex->getMessage();
|
||||
}
|
||||
?>
|
||||
<script>
|
||||
|
||||
function SendPENsAjax(action, id, number, manufacturer, description){
|
||||
console.log(action);
|
||||
console.log(id);
|
||||
console.log(number);
|
||||
console.log(manufacturer);
|
||||
console.log(description);
|
||||
$.ajax({
|
||||
async: true,
|
||||
type: "POST",
|
||||
url: $("#hidden-ajax_file").val(),
|
||||
data: {
|
||||
page: "include/ajax/wizardSetup.ajax",
|
||||
action: action,
|
||||
pen_id: id,
|
||||
pen_number: number,
|
||||
pen_manufacturer: manufacturer,
|
||||
pen_description: description,
|
||||
},
|
||||
success: function(d) {
|
||||
console.log(d);
|
||||
console.log(action);
|
||||
if (action == 'add' || action == 'delete') {
|
||||
$('#main_table_area').html(d);
|
||||
} else {
|
||||
$('#message_show_area').html(d);
|
||||
}
|
||||
},
|
||||
error: function(d) {
|
||||
alert('Something goes wrong! -> '+String(data));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function deletePEN(e){
|
||||
var action = 'delete';
|
||||
var pen_id = e.target.value;
|
||||
SendPENsAjax(action, '2', pen_id, '', '');
|
||||
}
|
||||
|
||||
function addNewPEN(){
|
||||
var action = 'add';
|
||||
var pen_id = '2';
|
||||
var pen_number = $('#text-pen_number');
|
||||
var pen_number_val = pen_number.val();
|
||||
var pen_manufacturer = $('#text-pen_manufacturer');
|
||||
var pen_manufacturer_val = pen_manufacturer.val();
|
||||
var pen_description = $('#text-pen_description');
|
||||
var pen_description_val = pen_description.val();
|
||||
|
||||
if (pen_number_val == '' || isNaN(pen_number_val)) {
|
||||
pen_number.css('border','1px solid red');
|
||||
} else if (pen_manufacturer_val == '') {
|
||||
pen_manufacturer.css('border','1px solid red');
|
||||
} else if (pen_description_val == '') {
|
||||
pen_description.css('border','1px solid red');
|
||||
} else {
|
||||
SendPENsAjax(action, pen_id, pen_number_val, pen_manufacturer_val, pen_description_val);
|
||||
}
|
||||
}
|
||||
|
||||
function modifyPENLine(e){
|
||||
var action = 'update';
|
||||
var pen_id = e.target.value;
|
||||
|
||||
var changed = false;
|
||||
$("span[id$='_"+pen_id+"']").each(function(){
|
||||
let thisElement = $(this);
|
||||
if (thisElement.attr('contenteditable') === 'false') {
|
||||
thisElement.attr('contenteditable', 'true');
|
||||
thisElement.css('border', '1px solid #e2e2e2').css('background-color','ghostwhite');
|
||||
$('#'+e.target.id).attr('src','images/file.png');
|
||||
} else {
|
||||
thisElement.attr('contenteditable', 'false');
|
||||
thisElement.css('border', '0').css('background-color','transparent');
|
||||
changed = true;
|
||||
$('#'+e.target.id).attr('src','images/edit.png')
|
||||
}
|
||||
});
|
||||
|
||||
if (changed === true) {
|
||||
|
||||
let pen_number = $('#pen_number_'+pen_id).html();
|
||||
let pen_manufacturer = $('#pen_manufacturer_'+pen_id).html();
|
||||
let pen_description = $('#pen_description_'+pen_id).html();
|
||||
|
||||
SendPENsAjax(action, '2', pen_number, pen_manufacturer, pen_description);
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
/**
|
||||
* Manage AJAX response for Wizard Setup pages.
|
||||
*
|
||||
* @category Ajax
|
||||
* @package Pandora FMS
|
||||
* @subpackage Wizard Setup
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation for version 2.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Begin.
|
||||
global $config;
|
||||
// File requirements.
|
||||
require_once 'include/functions_ui.php';
|
||||
require_once 'include/functions_db.php';
|
||||
require_once 'include/functions_io.php';
|
||||
require_once 'include/functions.php';
|
||||
require_once $config['homedir'].'/include/class/ConfigPEN.class.php';
|
||||
// Security.
|
||||
if (! check_acl($config['id_user'], 0, 'PM')
|
||||
&& ! check_acl($config['id_user'], 0, 'EW')
|
||||
&& ! check_acl($config['id_user'], 0, 'EM')
|
||||
) {
|
||||
db_pandora_audit(
|
||||
'ACL Violation',
|
||||
'Trying to access to Wizard Setup'
|
||||
);
|
||||
include 'general/noaccess.php';
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all paramaters.
|
||||
$action = get_parameter('action');
|
||||
$pen_id_np = get_parameter('pen_id');
|
||||
$pen_number = get_parameter('pen_number');
|
||||
$pen_manufacturer = get_parameter('pen_manufacturer');
|
||||
$pen_description = get_parameter('pen_description');
|
||||
|
||||
// Set the variables needed here.
|
||||
$configPEN = new ConfigPEN();
|
||||
$output = '';
|
||||
// Let's do something.
|
||||
// First, get the current data.
|
||||
$actual_pen = db_get_row('tpen', 'pen', $pen_number);
|
||||
switch ($action) {
|
||||
// Add new line.
|
||||
case 'add':
|
||||
if ($actual_pen === false) {
|
||||
$work = db_process_sql_insert(
|
||||
'tpen',
|
||||
[
|
||||
'id_np' => $pen_id_np,
|
||||
'pen' => $pen_number,
|
||||
'manufacturer' => $pen_manufacturer,
|
||||
'description' => $pen_description,
|
||||
]
|
||||
);
|
||||
if ($work === false) {
|
||||
$output = ui_print_error_message(__('Error inserting new PEN'));
|
||||
} else {
|
||||
$output = $configPEN->createMainTable();
|
||||
}
|
||||
} else {
|
||||
$output = ui_print_error_message(sprintf(__('The PEN %s exists already'), $pen_number));
|
||||
}
|
||||
break;
|
||||
|
||||
// Update one record.
|
||||
case 'update':
|
||||
if ($actual_pen['pen'] != $pen_number
|
||||
|| $actual_pen['manufacturer'] != $pen_manufacturer
|
||||
|| $actual_pen['description'] != $pen_description
|
||||
) {
|
||||
$work = db_process_sql_update(
|
||||
'tpen',
|
||||
[
|
||||
'pen' => $pen_number,
|
||||
'manufacturer' => $pen_manufacturer,
|
||||
'description' => $pen_description,
|
||||
],
|
||||
['pen' => $pen_number]
|
||||
);
|
||||
|
||||
if ($work === false) {
|
||||
$output = ui_print_error_message(__('Error updating data'));
|
||||
} else {
|
||||
$output = ui_print_success_message(__('PEN updated in DB'));
|
||||
}
|
||||
} else {
|
||||
$output = ui_print_error_message(__('No changes applied'));
|
||||
}
|
||||
break;
|
||||
|
||||
// Delete one record.
|
||||
case 'delete':
|
||||
if ($actual_pen != false) {
|
||||
db_process_sql_delete(
|
||||
'tpen',
|
||||
['pen' => $pen_number]
|
||||
);
|
||||
$output = $configPEN->createMainTable();
|
||||
} else {
|
||||
$output = ui_print_error_message(__('Something goes wrong. Please, retry'));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Nothing to do.
|
||||
break;
|
||||
}
|
||||
|
||||
// Return data.
|
||||
return $output;
|
|
@ -36,9 +36,9 @@ class ConfigPEN extends HTML
|
|||
{
|
||||
|
||||
/**
|
||||
* Undocumented variable
|
||||
* URL Base
|
||||
*
|
||||
* @var [type]
|
||||
* @var string
|
||||
*/
|
||||
private $baseUrl;
|
||||
|
||||
|
@ -58,15 +58,16 @@ class ConfigPEN extends HTML
|
|||
'ACL Violation',
|
||||
'Trying to access event viewer'
|
||||
);
|
||||
|
||||
if (is_ajax()) {
|
||||
/*
|
||||
if (is_ajax()) {
|
||||
echo json_encode(['error' => 'noaccess']);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
include 'general/noaccess.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->offset = '';
|
||||
$this->baseUrl = 'index.php?sec=configuration_wizard_setup&sec2=godmode/modules/private_enterprise_numbers';
|
||||
|
||||
}
|
||||
|
@ -117,36 +118,47 @@ class ConfigPEN extends HTML
|
|||
$this->printHeader(true)
|
||||
);
|
||||
|
||||
$this->createMainTable();
|
||||
// Definition for AJAX.
|
||||
html_print_input_hidden(
|
||||
'ajax_file',
|
||||
ui_get_full_url('ajax.php', false, false, false)
|
||||
);
|
||||
|
||||
// Allow message area.
|
||||
html_print_div(['id' => 'message_show_area']);
|
||||
// Prints the main table.
|
||||
html_print_div(
|
||||
[
|
||||
'id' => 'main_table_area',
|
||||
'content' => $this->createMainTable(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Create the main table with the PENs info
|
||||
*
|
||||
* @return void
|
||||
* @return string Return entire the table
|
||||
*/
|
||||
private function createMainTable()
|
||||
public function createMainTable()
|
||||
{
|
||||
global $config;
|
||||
// Get the count of PENs.
|
||||
$countPENs = db_get_value(
|
||||
'count(*)',
|
||||
'tnetwork_profile'
|
||||
'tpen'
|
||||
);
|
||||
|
||||
// Get all the data.
|
||||
$resultPENs = db_get_all_rows_filter(
|
||||
'tnetwork_profile',
|
||||
'tpen',
|
||||
[
|
||||
'order' => 'id_np',
|
||||
'limit' => $config['block_size'],
|
||||
]
|
||||
);
|
||||
|
||||
hd($resultPENs);
|
||||
|
||||
ui_pagination($countPENs, false, $this->offset);
|
||||
// Create the table with Module Block list.
|
||||
$table = new StdClasS();
|
||||
|
@ -181,15 +193,15 @@ class ConfigPEN extends HTML
|
|||
|
||||
foreach ($resultPENs as $row) {
|
||||
$data = [];
|
||||
$data[0] = html_print_checkbox_extended('delete_multiple[]', $row['id_np'], false, false, '', 'class="check_delete"', true);
|
||||
$data[1] = '<span id="pen_id_'.$row['id_np'].'" style="padding: 5px;" contenteditable="false">'.$row['id_np'].'</span>';
|
||||
$data[2] = '<span id="pen_name_'.$row['id_np'].'" style="padding: 5px;" contenteditable="false">'.$row['name'].'</span>';
|
||||
$data[3] = '<span id="pen_desc_'.$row['id_np'].'" style="padding: 5px;" contenteditable="false">'.ui_print_truncate_text(io_safe_output($row['description']), 'description', true, true, true, '[…]').'</span>';
|
||||
$table->cellclass[][3] = 'action_buttons';
|
||||
$data[0] = html_print_checkbox_extended('delete_multiple[]', $row['pen'], false, false, '', 'class="check_delete"', true);
|
||||
$data[1] = '<span id="pen_number_'.$row['pen'].'" style="padding: 5px;" contenteditable="false">'.$row['pen'].'</span>';
|
||||
$data[2] = '<span id="pen_manufacturer_'.$row['pen'].'" style="padding: 5px;" contenteditable="false">'.$row['manufacturer'].'</span>';
|
||||
$data[3] = '<span id="pen_description_'.$row['pen'].'" style="padding: 5px;" contenteditable="false">'.ui_print_truncate_text(io_safe_output($row['description']), 'description', true, true, true, '[…]').'</span>';
|
||||
$table->cellclass[][4] = 'action_buttons';
|
||||
$data[4] = html_print_input_image(
|
||||
'edit_pen_'.$row['id_np'].'_',
|
||||
'edit_pen_',
|
||||
'images/edit.png',
|
||||
$row['id_np'],
|
||||
$row['pen'],
|
||||
'max-width: 27px;',
|
||||
true,
|
||||
[
|
||||
|
@ -198,22 +210,43 @@ class ConfigPEN extends HTML
|
|||
]
|
||||
);
|
||||
$data[4] .= html_print_input_image(
|
||||
'delete_pen_'.$row['id_np'].'_',
|
||||
'delete_pen_',
|
||||
'images/cross.png',
|
||||
$row['id_np'],
|
||||
$row['pen'],
|
||||
'',
|
||||
true,
|
||||
[
|
||||
'title' => 'Delete PEN',
|
||||
'onclick' => 'if (!confirm(\''.__('Are you sure?').'\')) return false;',
|
||||
'onclick' => 'if (confirm(\''.__('Are you sure?').'\')) deletePEN(event);',
|
||||
]
|
||||
);
|
||||
|
||||
array_push($table->data, $data);
|
||||
}
|
||||
|
||||
html_print_table($table);
|
||||
// Last line for adding new PENs.
|
||||
$data = [];
|
||||
$data[0] = '';
|
||||
$data[1] = html_print_input_text('pen_number', '', '', 10, 255, true);
|
||||
$data[2] = html_print_input_text('pen_manufacturer', '', '', 30, 255, true);
|
||||
$data[3] = html_print_input_text('pen_description', '', '', 80, 255, true);
|
||||
$table->cellclass[][4] = 'action_buttons';
|
||||
$data[4] = html_print_input_image(
|
||||
'add_new_pen',
|
||||
'images/add_mc.png',
|
||||
'',
|
||||
'margin: 0 auto; display: block;',
|
||||
true,
|
||||
[
|
||||
'title' => 'Add new PEN',
|
||||
'onclick' => 'javascript:addNewPEN()',
|
||||
]
|
||||
);
|
||||
|
||||
// Add last line.
|
||||
array_push($table->data, $data);
|
||||
// Return the entire table.
|
||||
return html_print_table($table, true);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue