WIP: Near to finish

This commit is contained in:
Jose Gonzalez 2020-03-30 19:03:55 +02:00
parent fa372656f4
commit c2d81238d6

View File

@ -86,7 +86,7 @@ class ModuleTemplates extends HTML
/** /**
* Group for adding modules * Group for adding modules
* *
* @var string * @var string
*/ */
private $ncGroup; private $ncGroup;
@ -131,11 +131,14 @@ class ModuleTemplates extends HTML
$this->id_np = get_parameter('id_np', -1); $this->id_np = get_parameter('id_np', -1);
$this->name = get_parameter('name', ''); $this->name = get_parameter('name', '');
$this->description = get_parameter('description', ''); $this->description = get_parameter('description', '');
$this->pen = get_parameter('pen', ''); $pensList = get_parameter('pen', []);
// Separate all PENs received.
$this->pen = explode(',', $pensList);
$this->offset = get_parameter('offset', 0); $this->offset = get_parameter('offset', 0);
$this->ajaxController = $ajax_controller; $this->ajaxController = $ajax_controller;
$this->ncGroup = get_parameter('ncgroup', -1); $this->ncGroup = get_parameter('ncgroup', -1);
$this->ncFilter = get_parameter('ncfilter', ''); $this->ncFilter = get_parameter('ncfilter', '');
return $this; return $this;
} }
@ -205,19 +208,15 @@ class ModuleTemplates extends HTML
/** /**
* Undocumented function * Save or Update the data received.
* *
* @return void * @return void
*/ */
public function processData() public function processData()
{ {
// This data is sent always // Get action if is needed.
$name = get_parameter('name', '');
$description = get_parameter('description', '');
$pensList = get_parameter('pen', '');
$action = get_parameter('submit_button', ''); $action = get_parameter('submit_button', '');
// Evaluate the modules allowed.
// Evaluate the modules allowed
if (!empty($action)) { if (!empty($action)) {
$numberComponent = []; $numberComponent = [];
foreach ($_POST as $k => $value) { foreach ($_POST as $k => $value) {
@ -232,48 +231,51 @@ class ModuleTemplates extends HTML
$dbResult_tnp = db_process_sql_update( $dbResult_tnp = db_process_sql_update(
'tnetwork_profile', 'tnetwork_profile',
[ [
'name' => $name, 'name' => $this->name,
'description' => $description, 'description' => $this->description,
], ],
['id_np' => $this->id_np] ['id_np' => $this->id_np]
); );
// The update gone fine!
$getProfilePens = db_get_all_rows_sql(sprintf('SELECT pen FROM tpen WHERE id_np = %s', $this->id_np)); if ($dbResult_tnp != false) {
// Clean the PENs associated with this id_np.
$dbResult_pen = db_process_sql_update( db_process_sql_delete('tnetwork_profile_pen', ['id_np' => $this->id_np]);
'tpen', // Set again the new PENs associated.
[ foreach ($this->pen as $currentPen) {
'pen' => $pen, $dbResult_pen = db_process_sql_insert(
'manufacturer' => '', 'tnetwork_profile_pen',
'description' => '', [
'id_np' => $this->id_np, 'pen' => $currentPen,
], 'id_np' => $this->id_np,
['id_np' => $this->id_np] ]
); );
}
}
break; break;
case 'Create': case 'Create':
$dbResult_tnp = db_process_sql_insert( $dbResult_tnp = db_process_sql_insert(
'tnetwork_profile', 'tnetwork_profile',
[ [
'name' => $name, 'name' => $this->name,
'description' => $description, 'description' => $this->description,
] ]
); );
// The insert gone fine!
if ($dbResult_tnp != false) { if ($dbResult_tnp != false) {
foreach ($pensList as $currentPen) { // Set the new id_np.
$this->id_np = $dbResult_tnp;
// Insert all of new PENs associated with this id_np.
foreach ($this->pen as $currentPen) {
hd($currentPen);
$dbResult_pen = db_process_sql_insert( $dbResult_pen = db_process_sql_insert(
'tpen', 'tnetwork_profile_pen',
[ [
'pen' => $currentPen, 'pen' => $currentPen,
'manufacturer' => '', 'id_np' => $this->id_np,
'description' => '',
'id_np' => $this->id_np,
] ]
); );
// If something is wrong, is better stop.
if ($dbResult_pen === false) { if ($dbResult_pen === false) {
break; break;
} }
@ -296,6 +298,18 @@ class ModuleTemplates extends HTML
} }
/**
* Get the match between this id_np and one pen in db
*
* @param integer $pen
* @return void
*/
private function penMatch($pen)
{
return db_get_num_rows('SELECT * FROM tnetwork_profile_pen WHERE pen = %d AND id_np = %d', $pen, $this->id_np);
}
/** /**
* Undocumented function * Undocumented function
* *
@ -303,7 +317,6 @@ class ModuleTemplates extends HTML
*/ */
public function addingModulesForm() public function addingModulesForm()
{ {
// Get the groups for select input // Get the groups for select input
$result = db_get_all_rows_in_table('tnetwork_component_group', 'name'); $result = db_get_all_rows_in_table('tnetwork_component_group', 'name');
if ($result === false) { if ($result === false) {
@ -326,9 +339,8 @@ class ModuleTemplates extends HTML
$groups_compound[$row['id_sg']] .= $row['name']; $groups_compound[$row['id_sg']] .= $row['name'];
} }
# For erase // For erase
#$group_filter .= html_print_select($groups_compound, 'ncgroup', $ncgroup, 'javascript:this.form.submit();', __('Group').' - '.__('All'), -1, true, false, true, '" style="width:350px'); // $group_filter .= html_print_select($groups_compound, 'ncgroup', $ncgroup, 'javascript:this.form.submit();', __('Group').' - '.__('All'), -1, true, false, true, '" style="width:350px');
// Get the components for show in a list for select // Get the components for show in a list for select
if ($this->ncGroup > 0) { if ($this->ncGroup > 0) {
$sql = sprintf( $sql = sprintf(
@ -434,53 +446,53 @@ class ModuleTemplates extends HTML
true true
] ]
); );
/* /*
$table = new StdClasS(); $table = new StdClasS();
$table->head = []; $table->head = [];
$table->data = []; $table->data = [];
$table->align = []; $table->align = [];
$table->width = '100%'; $table->width = '100%';
$table->cellpadding = 0; $table->cellpadding = 0;
$table->cellspacing = 0; $table->cellspacing = 0;
$table->class = 'databox filters'; $table->class = 'databox filters';
$table->style[0] = 'font-weight: bold'; $table->style[0] = 'font-weight: bold';
// The form to submit when adding a list of components // The form to submit when adding a list of components
$filter = '<form name="filter_component" method="post" action="index.php?sec=gmodules&sec2=godmode/modules/manage_network_templates_form&ncgroup='.$ncgroup.'&id_np='.$id_np.'#filter">'; $filter = '<form name="filter_component" method="post" action="index.php?sec=gmodules&sec2=godmode/modules/manage_network_templates_form&ncgroup='.$ncgroup.'&id_np='.$id_np.'#filter">';
$filter .= html_print_input_text('ncfilter', $ncfilter, '', 50, 255, true); $filter .= html_print_input_text('ncfilter', $ncfilter, '', 50, 255, true);
$filter .= '&nbsp;&nbsp;'.html_print_submit_button(__('Filter'), 'ncgbutton', false, 'class="sub search"', true); $filter .= '&nbsp;&nbsp;'.html_print_submit_button(__('Filter'), 'ncgbutton', false, 'class="sub search"', true);
$filter .= '</form>'; $filter .= '</form>';
$group_filter = '<form name="filter_group" method="post" action="index.php?sec=gmodules&sec2=godmode/modules/manage_network_templates_form&id_np='.$id_np.'#filter">'; $group_filter = '<form name="filter_group" method="post" action="index.php?sec=gmodules&sec2=godmode/modules/manage_network_templates_form&id_np='.$id_np.'#filter">';
$group_filter .= '<div style="width:540px"><a name="filter"></a>'; $group_filter .= '<div style="width:540px"><a name="filter"></a>';
$result = db_get_all_rows_in_table('tnetwork_component_group', 'name'); $result = db_get_all_rows_in_table('tnetwork_component_group', 'name');
if ($result === false) { if ($result === false) {
$result = []; $result = [];
} }
// 2 arrays. 1 with the groups, 1 with the groups by parent // 2 arrays. 1 with the groups, 1 with the groups by parent
$groups = []; $groups = [];
$groups_compound = []; $groups_compound = [];
foreach ($result as $row) { foreach ($result as $row) {
$groups[$row['id_sg']] = $row['name']; $groups[$row['id_sg']] = $row['name'];
} }
foreach ($result as $row) { foreach ($result as $row) {
$groups_compound[$row['id_sg']] = ''; $groups_compound[$row['id_sg']] = '';
if ($row['parent'] > 1) { if ($row['parent'] > 1) {
$groups_compound[$row['id_sg']] = $groups[$row['parent']].' / '; $groups_compound[$row['id_sg']] = $groups[$row['parent']].' / ';
} }
$groups_compound[$row['id_sg']] .= $row['name']; $groups_compound[$row['id_sg']] .= $row['name'];
} }
$group_filter .= html_print_select($groups_compound, 'ncgroup', $ncgroup, 'javascript:this.form.submit();', __('Group').' - '.__('All'), -1, true, false, true, '" style="width:350px'); $group_filter .= html_print_select($groups_compound, 'ncgroup', $ncgroup, 'javascript:this.form.submit();', __('Group').' - '.__('All'), -1, true, false, true, '" style="width:350px');
$group_filter .= '</div></form>'; $group_filter .= '</div></form>';
if ($ncgroup > 0) { if ($ncgroup > 0) {
$sql = sprintf( $sql = sprintf(
" "
SELECT id_nc, name, id_group SELECT id_nc, name, id_group
@ -489,38 +501,38 @@ class ModuleTemplates extends HTML
ORDER BY name", ORDER BY name",
$ncgroup $ncgroup
); );
} else { } else {
$sql = " $sql = "
SELECT id_nc, name, id_group SELECT id_nc, name, id_group
FROM tnetwork_component FROM tnetwork_component
WHERE name LIKE '%".$ncfilter."%' WHERE name LIKE '%".$ncfilter."%'
ORDER BY name"; ORDER BY name";
} }
$result = db_get_all_rows_sql($sql); $result = db_get_all_rows_sql($sql);
$components = []; $components = [];
if ($result === false) { if ($result === false) {
$result = []; $result = [];
} }
foreach ($result as $row) { foreach ($result as $row) {
$components[$row['id_nc']] = $row['name']; $components[$row['id_nc']] = $row['name'];
} }
$components_select = '<form name="add_module" method="post" action="index.php?sec=gmodules&sec2=godmode/modules/manage_network_templates_form&id_np='.$id_np.'&add_module=1">'; $components_select = '<form name="add_module" method="post" action="index.php?sec=gmodules&sec2=godmode/modules/manage_network_templates_form&id_np='.$id_np.'&add_module=1">';
$components_select .= html_print_select($components, 'components[]', $id_nc, '', '', -1, true, true, false, '" style="width:350px'); $components_select .= html_print_select($components, 'components[]', $id_nc, '', '', -1, true, true, false, '" style="width:350px');
$table->data[0][0] = __('Filter'); $table->data[0][0] = __('Filter');
$table->data[0][1] = $filter; $table->data[0][1] = $filter;
$table->data[1][0] = __('Group'); $table->data[1][0] = __('Group');
$table->data[1][1] = $group_filter; $table->data[1][1] = $group_filter;
$table->data[2][0] = __('Components'); $table->data[2][0] = __('Components');
$table->data[2][1] = $components_select; $table->data[2][1] = $components_select;
html_print_table($table); html_print_table($table);
echo '<div style="width:'.$table->width.'; text-align:right">'; echo '<div style="width:'.$table->width.'; text-align:right">';
html_print_submit_button(__('Add'), 'crtbutton', false, 'class="sub wand"'); html_print_submit_button(__('Add'), 'crtbutton', false, 'class="sub wand"');
echo '</div></form>';*/ echo '</div></form>';*/
} }
@ -533,10 +545,11 @@ class ModuleTemplates extends HTML
private function setNetworkProfile() private function setNetworkProfile()
{ {
if ($this->id_np !== 0) { if ($this->id_np !== 0) {
$output = db_get_row('tnetwork_profile', 'id_np', $this->id_np); $profileInfo = db_get_row('tnetwork_profile', 'id_np', $this->id_np);
$this->name = $output['name']; $this->name = $profileInfo['name'];
$this->description = $output['description']; $this->description = $profileInfo['description'];
$this->pen = $output['pen']; $penInfo = db_get_all_rows_filter('tnetwork_profile_pen', ['id_np' => $this->id_np]);
$this->pen = $penInfo['pen'];
} }
} }