2020-03-16 20:48:38 +01:00
< ? php
2020-03-17 16:24:17 +01:00
/**
* Module Block feature .
*
* @ category Class
* @ package Pandora FMS
* @ subpackage SNMP
* @ version 0.0 . 1
* @ license See below
*
* ______ ___ _______ _______ ________
* | __ \ .-----.--.--.--| |.-----.----.-----. | ___ | | | __ |
* | __ /| _ | | _ || _ | _ | _ | | ___ | | __ |
* | ___ | | ___ . _ | __ | __ | _____ || _____ | __ | | ___ . _ | | ___ | | __ | _ | __ | _______ |
*
* ============================================================================
* 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 .
* ============================================================================
*/
2020-03-16 20:48:38 +01:00
global $config ;
require_once $config [ 'homedir' ] . '/include/class/HTML.class.php' ;
2020-03-17 13:46:10 +01:00
/**
2020-03-30 17:00:48 +02:00
* Class ModuleTemplates
2020-03-17 13:46:10 +01:00
*/
2020-03-30 17:00:48 +02:00
class ModuleTemplates extends HTML
2020-03-16 20:48:38 +01:00
{
2020-03-17 13:46:10 +01:00
/**
* Var that contain very cool stuff
*
* @ var string
*/
private $ajaxController ;
/**
* Undocumented variable
*
* @ var [ type ]
*/
private $offset ;
2020-03-17 18:27:56 +01:00
/**
* Base URL for internal purposes
*
* @ var string
*/
private $baseUrl ;
2020-03-19 18:24:52 +01:00
/**
* Id of the Thing ? ? ?
*
* @ var integer
*/
private $id_np ;
2020-03-20 15:35:30 +01:00
/**
* Name of Block Template
*
* @ var [ type ]
*/
private $name ;
/**
* Description of Block Template
*
* @ var [ type ]
*/
private $description ;
/**
* Private Enterprise Numbers of Block Templates
*
2020-03-31 10:47:00 +02:00
* @ var array
2020-03-20 15:35:30 +01:00
*/
private $pen ;
2020-03-30 17:00:48 +02:00
/**
* Group for adding modules
2020-03-30 19:03:55 +02:00
*
2020-03-30 17:00:48 +02:00
* @ var string
*/
private $ncGroup ;
/**
* Filter for adding modules
*
* @ var string
*/
private $ncFilter ;
2020-03-16 20:48:38 +01:00
2020-03-17 13:46:10 +01:00
/**
* Constructor
*
* @ param string $ajax_controller Pues hace cosas to wapas .
*/
public function __construct ( string $ajax_controller )
2020-03-16 20:48:38 +01:00
{
global $config ;
// Check access.
check_login ();
if ( ! check_acl ( $config [ 'id_user' ], 0 , 'AR' )) {
db_pandora_audit (
'ACL Violation' ,
'Trying to access event viewer'
);
if ( is_ajax ()) {
echo json_encode ([ 'error' => 'noaccess' ]);
}
include 'general/noaccess.php' ;
exit ;
}
2020-03-20 15:35:30 +01:00
// Set baseUrl for use it in several locations in this class.
2020-03-30 17:00:48 +02:00
$this -> baseUrl = ui_get_full_url ( 'index.php?sec=gmodules&sec2=godmode/modules/manage_module_templates' );
2020-03-20 15:35:30 +01:00
// Capture all parameters before start.
$this -> id_np = get_parameter ( 'id_np' , - 1 );
$this -> name = get_parameter ( 'name' , '' );
$this -> description = get_parameter ( 'description' , '' );
2020-03-31 10:47:00 +02:00
$this -> pen = get_parameter ( 'pen' , '' );
2020-03-20 15:35:30 +01:00
$this -> offset = get_parameter ( 'offset' , 0 );
$this -> ajaxController = $ajax_controller ;
2020-03-31 13:00:07 +02:00
$this -> ncGroup = get_parameter ( 'add-modules-group' , '0' );
$this -> ncFilter = get_parameter ( 'add-modules-filter' , '' );
2020-03-30 19:03:55 +02:00
2020-03-16 20:48:38 +01:00
return $this ;
}
/**
2020-03-17 13:46:10 +01:00
* Run main page .
2020-03-16 20:48:38 +01:00
*
* @ return void
*/
public function run ()
{
2020-03-19 16:14:38 +01:00
// Require specific CSS and JS.
ui_require_css_file ( 'wizard' );
ui_require_css_file ( 'discovery' );
2020-03-17 13:46:10 +01:00
// Header section.
// Breadcrums.
$this -> setBreadcrum ([]);
2020-03-16 20:48:38 +01:00
$this -> prepareBreadcrum (
[
[
2020-03-17 13:46:10 +01:00
'link' => '' ,
2020-03-16 20:48:38 +01:00
'label' => __ ( 'Configuration' ),
2020-03-17 13:46:10 +01:00
'selected' => false ,
2020-03-16 20:48:38 +01:00
],
2020-03-30 17:00:48 +02:00
[
'link' => '' ,
'label' => __ ( 'Templates' ),
'selected' => false ,
],
2020-03-16 20:48:38 +01:00
[
2020-03-19 18:24:52 +01:00
'link' => $this -> baseUrl ,
2020-03-30 17:00:48 +02:00
'label' => __ ( 'Module template management' ),
2020-03-17 13:46:10 +01:00
'selected' => true ,
2020-03-16 20:48:38 +01:00
],
],
true
);
ui_print_page_header (
2020-03-30 17:00:48 +02:00
__ ( 'Module template management' ),
2020-03-16 20:48:38 +01:00
'' ,
false ,
'' ,
true ,
'' ,
false ,
'' ,
GENERIC_SIZE_TEXT ,
'' ,
$this -> printHeader ( true )
);
}
2020-03-19 18:24:52 +01:00
/**
* Get the value of this current thing ? ? ?
*
* @ return integer Id of this thing ? ? ?
*/
public function getIdNp ()
{
return $this -> id_np ;
}
2020-03-23 15:16:54 +01:00
/**
2020-03-30 19:03:55 +02:00
* Save or Update the data received .
2020-03-23 15:16:54 +01:00
*
2020-03-30 17:00:48 +02:00
* @ return void
2020-03-23 15:16:54 +01:00
*/
2020-03-30 17:00:48 +02:00
public function processData ()
2020-03-23 15:16:54 +01:00
{
2020-03-30 19:03:55 +02:00
// Get action if is needed.
2020-03-31 13:00:07 +02:00
$action = get_parameter ( 'submit_button' , '' );
$modules_submit = get_parameter ( 'add-modules-submit' , '' );
2020-03-31 10:47:00 +02:00
// Success variable.
$success = false ;
2020-03-30 19:03:55 +02:00
// Evaluate the modules allowed.
2020-03-30 17:00:48 +02:00
if ( ! empty ( $action )) {
$numberComponent = [];
foreach ( $_POST as $k => $value ) {
if ( strpos ( $k , 'module_check_' ) >= 0 && $value == 1 ) {
$tmpNumberComponent = explode ( '_' , $k );
$numberComponent [] = $tmpNumberComponent [ 2 ];
}
}
switch ( $action ) {
case 'Update' :
$dbResult_tnp = db_process_sql_update (
'tnetwork_profile' ,
[
2020-03-30 19:03:55 +02:00
'name' => $this -> name ,
'description' => $this -> description ,
2020-03-30 17:00:48 +02:00
],
[ 'id_np' => $this -> id_np ]
);
2020-03-31 10:47:00 +02:00
if ( $dbResult_tnp === false ) {
$success = false ;
} else {
2020-03-30 19:03:55 +02:00
db_process_sql_delete ( 'tnetwork_profile_pen' , [ 'id_np' => $this -> id_np ]);
2020-03-31 10:47:00 +02:00
$pensList = explode ( ',' , $this -> pen );
if ( count ( $pensList ) > 0 ) {
// Set again the new PENs associated.
foreach ( $pensList as $currentPen ) {
$dbResult_pen = db_process_sql_insert (
'tnetwork_profile_pen' ,
[
'pen' => $currentPen ,
'id_np' => $this -> id_np ,
]
);
if ( $dbResult_pen === false ) {
$success = false ;
break ;
}
$success = true ;
}
} else {
$success = true ;
2020-03-30 19:03:55 +02:00
}
}
2020-03-30 17:00:48 +02:00
break ;
case 'Create' :
$dbResult_tnp = db_process_sql_insert (
'tnetwork_profile' ,
[
2020-03-30 19:03:55 +02:00
'name' => $this -> name ,
'description' => $this -> description ,
2020-03-30 17:00:48 +02:00
]
);
2020-03-30 19:03:55 +02:00
// The insert gone fine!
2020-03-30 17:00:48 +02:00
if ( $dbResult_tnp != false ) {
2020-03-30 19:03:55 +02:00
// Set the new id_np.
$this -> id_np = $dbResult_tnp ;
2020-03-31 10:47:00 +02:00
$pensList = explode ( ',' , $this -> pen );
2020-03-30 19:03:55 +02:00
// Insert all of new PENs associated with this id_np.
2020-03-31 10:47:00 +02:00
foreach ( $pensList as $currentPen ) {
2020-03-30 17:00:48 +02:00
$dbResult_pen = db_process_sql_insert (
2020-03-30 19:03:55 +02:00
'tnetwork_profile_pen' ,
2020-03-30 17:00:48 +02:00
[
2020-03-30 19:03:55 +02:00
'pen' => $currentPen ,
'id_np' => $this -> id_np ,
2020-03-30 17:00:48 +02:00
]
);
2020-03-30 19:03:55 +02:00
// If something is wrong, is better stop.
2020-03-30 17:00:48 +02:00
if ( $dbResult_pen === false ) {
break ;
}
2020-03-31 10:47:00 +02:00
$success = true ;
2020-03-30 17:00:48 +02:00
}
}
break ;
2020-03-31 10:47:00 +02:00
case 'Delete' :
// Only in this case, catch delete_profile.
$deleteProfile = get_parameter ( 'delete_profile' , - 1 );
$dbResult = db_process_sql_delete ( 'tnetwork_profile' , [ 'id_np' => $deleteProfile ]);
if ( $dbResult != false ) {
$success = true ;
}
break ;
2020-03-30 17:00:48 +02:00
default :
2020-03-31 10:47:00 +02:00
$success = false ;
2020-03-30 17:00:48 +02:00
break ;
}
2020-03-31 10:47:00 +02:00
if ( $success === false ) {
2020-03-30 17:00:48 +02:00
ui_print_error_message ( __ ( 'Error saving data' ));
} else {
ui_print_success_message ( __ ( 'Changes saved sucessfully' ));
}
2020-03-31 13:00:07 +02:00
} else if ( $modules_submit != '' ) {
$modulesToAdd = get_parameter ( 'add-modules-components-values' , '' );
$modulesToAddList = explode ( ',' , $modulesToAdd );
foreach ( $modulesToAddList as $module ) {
db_process_sql_insert (
'tnetwork_profile_component' ,
[
'id_nc' => $module ,
'id_np' => $this -> id_np ,
]
);
}
2020-03-30 17:00:48 +02:00
}
2020-03-23 15:16:54 +01:00
}
2020-03-30 19:03:55 +02:00
/**
2020-03-31 10:47:00 +02:00
* Show the adding modules form
2020-03-20 15:35:30 +01:00
*
* @ return void
*/
2020-03-30 17:00:48 +02:00
public function addingModulesForm ()
2020-03-20 15:35:30 +01:00
{
2020-03-30 17:00:48 +02:00
// Get the groups for select input
$result = db_get_all_rows_in_table ( 'tnetwork_component_group' , 'name' );
if ( $result === false ) {
$result = [];
}
// 2 arrays. 1 with the groups, 1 with the groups by parent
$groups = [];
$groups_compound = [];
2020-03-31 13:00:07 +02:00
// Default group filter.
2020-03-31 10:47:00 +02:00
$groups_compound [ 0 ] = 'Group - All' ;
2020-03-30 17:00:48 +02:00
foreach ( $result as $row ) {
$groups [ $row [ 'id_sg' ]] = $row [ 'name' ];
}
foreach ( $result as $row ) {
$groups_compound [ $row [ 'id_sg' ]] = '' ;
if ( $row [ 'parent' ] > 1 ) {
$groups_compound [ $row [ 'id_sg' ]] = $groups [ $row [ 'parent' ]] . ' / ' ;
}
$groups_compound [ $row [ 'id_sg' ]] .= $row [ 'name' ];
}
// Get the components for show in a list for select
if ( $this -> ncGroup > 0 ) {
$sql = sprintf (
"
SELECT id_nc , name , id_group
FROM tnetwork_component
WHERE id_group = % d AND name LIKE '%".$this->ncFilter."%'
ORDER BY name " ,
$this -> ncGroup
);
} else {
$sql = "
SELECT id_nc , name , id_group
FROM tnetwork_component
WHERE name LIKE '%".$this->ncFilter."%'
ORDER BY name " ;
}
$result = db_get_all_rows_sql ( $sql );
$components = [];
if ( $result === false ) {
$result = [];
}
foreach ( $result as $row ) {
$components [ $row [ 'id_nc' ]] = $row [ 'name' ];
}
// Main form.
$form = [
'action' => $this -> baseUrl ,
'id' => 'add_module_form' ,
'method' => 'POST' ,
'class' => 'databox filters' ,
'extra' => '' ,
];
// Inputs.
$inputs = [];
$inputs [] = [
'id' => 'inp-id_np' ,
'arguments' => [
'name' => 'id_np' ,
'type' => 'hidden' ,
'value' => $this -> id_np ,
'return' => true ,
],
];
2020-03-31 13:00:07 +02:00
$inputs [] = [
'id' => 'add-modules-components-values' ,
'arguments' => [
'name' => 'add-modules-components-values' ,
'type' => 'hidden' ,
'value' => '' ,
'return' => true ,
],
];
2020-03-30 17:00:48 +02:00
$inputs [] = [
'label' => __ ( 'Filter' ),
2020-03-31 13:00:07 +02:00
'id' => 'txt-add-modules-filter' ,
2020-03-30 17:00:48 +02:00
'arguments' => [
'name' => 'add-modules-filter' ,
'input_class' => 'flex-row' ,
'type' => 'text' ,
'value' => '' ,
'return' => true ,
],
];
$inputs [] = [
'label' => __ ( 'Group' ),
'id' => 'add-modules-group' ,
'arguments' => [
'name' => 'add-modules-group' ,
'input_class' => 'flex-row' ,
'type' => 'select' ,
'script' => 'this.form.submit()' ,
'fields' => $groups_compound ,
2020-03-31 13:00:07 +02:00
'nothing' => $groups_compound [ $this -> ncGroup ],
2020-03-30 17:00:48 +02:00
'return' => true ,
],
];
$inputs [] = [
'label' => __ ( 'Components' ),
2020-03-31 13:00:07 +02:00
'id' => 'slc-add-modules-components2' ,
2020-03-30 17:00:48 +02:00
'arguments' => [
'name' => 'add-modules-components' ,
'input_class' => 'flex-row' ,
'type' => 'select' ,
'multiple' => true ,
'fields' => $components ,
'return' => true ,
],
];
$inputs [] = [
'arguments' => [
'label' => __ ( 'Add components' ),
'name' => 'add-modules-submit' ,
'type' => 'submit' ,
'attributes' => 'class="sub wand"' ,
'return' => true ,
],
];
$this -> printFormAsList (
[
'form' => $form ,
'inputs' => $inputs ,
true
]
);
2020-03-20 15:35:30 +01:00
}
2020-03-30 17:00:48 +02:00
/**
2020-03-31 10:47:00 +02:00
* General setter
2020-03-30 17:00:48 +02:00
*
* @ return void
*/
2020-03-20 15:35:30 +01:00
private function setNetworkProfile ()
{
2020-03-31 10:47:00 +02:00
// Get t
$profileInfo = db_get_row ( 'tnetwork_profile' , 'id_np' , $this -> id_np );
$this -> name = $profileInfo [ 'name' ];
$this -> description = $profileInfo [ 'description' ];
$penInfo = db_get_all_rows_filter ( 'tnetwork_profile_pen' , [ 'id_np' => $this -> id_np ]);
$penList = [];
foreach ( $penInfo as $pen ) {
$penList [] = $pen [ 'pen' ];
2020-03-20 15:35:30 +01:00
}
2020-03-31 10:47:00 +02:00
$this -> pen = implode ( ',' , $penList );
2020-03-20 15:35:30 +01:00
}
2020-03-17 13:46:10 +01:00
/**
2020-03-19 16:14:38 +01:00
* Create the table with the list of Blocks Templates
2020-03-17 13:46:10 +01:00
*
* @ return html Formed table
*/
public function moduleBlockList ()
{
2020-03-19 16:14:38 +01:00
global $config ;
// Get the count of Blocks.
$countModuleBlocks = db_get_value (
'count(*)' ,
'tnetwork_profile'
);
// Get all the data.
$resultModuleBlocksTable = db_get_all_rows_filter (
'tnetwork_profile' ,
[
'order' => 'name' ,
'limit' => $config [ 'block_size' ],
'offset' => $this -> offset ,
]
);
ui_pagination ( $countModuleBlocks , false , $this -> offset );
2020-03-17 13:46:10 +01:00
// Create the table with Module Block list.
$table = new StdClasS ();
$table -> class = 'databox data' ;
$table -> width = '75%' ;
$table -> styleTable = 'margin: 2em auto 0;border: 1px solid #ddd;background: white;' ;
$table -> rowid = [];
$table -> data = [];
$table -> cellpadding = 0 ;
$table -> cellspacing = 0 ;
$table -> width = '100%' ;
$table -> class = 'info_table' ;
$table -> head = [];
$table -> head [ 0 ] = html_print_checkbox ( 'all_delete' , 0 , false , true , false );
2020-03-19 16:14:38 +01:00
2020-03-17 13:46:10 +01:00
$table -> head [ 1 ] = __ ( 'Name' );
$table -> head [ 2 ] = __ ( 'Description' );
$table -> head [ 3 ] = '<span style="margin-right:7%;">' . __ ( 'Action' ) . '</span>' ;
$table -> size = [];
$table -> size [ 0 ] = '20px' ;
$table -> size [ 2 ] = '65%' ;
$table -> size [ 3 ] = '15%' ;
$table -> align = [];
$table -> align [ 3 ] = 'left' ;
$table -> data = [];
2020-03-19 16:14:38 +01:00
foreach ( $resultModuleBlocksTable as $row ) {
2020-03-17 13:46:10 +01:00
$data = [];
2020-03-17 16:24:17 +01:00
$data [ 0 ] = html_print_checkbox_extended ( 'delete_multiple[]' , $row [ 'id_np' ], false , false , '' , 'class="check_delete"' , true );
2020-03-17 18:27:56 +01:00
$data [ 1 ] = '<a href="' . $this -> baseUrl . '&id_np=' . $row [ 'id_np' ] . '">' . io_safe_output ( $row [ 'name' ]) . '</a>' ;
2020-03-17 16:24:17 +01:00
$data [ 2 ] = ui_print_truncate_text ( io_safe_output ( $row [ 'description' ]), 'description' , true , true , true , '[…]' );
2020-03-17 13:46:10 +01:00
$table -> cellclass [][ 3 ] = 'action_buttons' ;
$data [ 3 ] = html_print_input_image (
'delete_profile' ,
'images/cross.png' ,
$row [ 'id_np' ],
'' ,
true ,
[ 'onclick' => 'if (!confirm(\'' . __ ( 'Are you sure?' ) . '\')) return false;' ]
);
$data [ 3 ] .= html_print_input_image (
'export_profile' ,
'images/csv.png' ,
$row [ 'id_np' ],
'' ,
true ,
[ 'title' => 'Export to CSV' ]
);
2020-03-31 10:47:00 +02:00
$data [ 3 ] = '<a href="' . $this -> baseUrl . '&submit_button=Delete&delete_profile=' . $row [ 'id_np' ] . '" ' . 'onclick="if (!confirm(\'' . __ ( 'Are you sure?' ) . '\')) return false;">' . html_print_image ( 'images/cross.png' , true , [ 'title' => __ ( 'Delete' )]) . '</a>' ;
2020-03-17 18:27:56 +01:00
$data [ 3 ] .= '<a href="' . $this -> baseUrl . '&export_profile=' . $row [ 'id_np' ] . '">' . html_print_image ( 'images/csv.png' , true , [ 'title' => __ ( 'Export to CSV' )]) . '</a>' ;
2020-03-17 13:46:10 +01:00
array_push ( $table -> data , $data );
}
2020-03-19 16:14:38 +01:00
html_print_table ( $table );
2020-03-17 16:24:17 +01:00
2020-03-19 18:24:52 +01:00
$output = '<div style="float:right;" class="">' ;
2020-03-17 16:24:17 +01:00
2020-03-19 16:14:38 +01:00
$form = [
'method' => 'POST' ,
'action' => $this -> baseUrl ,
];
$inputs [] = [
'arguments' => [
'name' => 'id_np' ,
'type' => 'hidden' ,
'value' => 0 ,
'return' => true ,
],
];
$inputs [] = [
'arguments' => [
'label' => __ ( 'Create' ),
'name' => 'crt' ,
'type' => 'submit' ,
'attributes' => 'class="sub wand"' ,
'return' => true ,
],
];
2020-03-19 18:24:52 +01:00
$output .= $this -> printForm (
2020-03-17 16:24:17 +01:00
[
2020-03-19 16:14:38 +01:00
'form' => $form ,
'inputs' => $inputs ,
2020-03-19 18:24:52 +01:00
],
true
2020-03-17 16:24:17 +01:00
);
2020-03-17 13:46:10 +01:00
2020-03-19 18:24:52 +01:00
$output .= '</div>' ;
2020-03-19 16:14:38 +01:00
2020-03-19 18:24:52 +01:00
echo $output ;
2020-03-19 16:14:38 +01:00
}
2020-03-17 18:27:56 +01:00
/**
2020-03-19 18:24:52 +01:00
* Prints Form for template management
2020-03-17 18:27:56 +01:00
*/
2020-03-20 15:35:30 +01:00
public function moduleTemplateForm ()
2020-03-17 18:27:56 +01:00
{
2020-03-30 17:00:48 +02:00
$createNewBlock = ( $this -> id_np == 0 ) ? true : false ;
2020-03-19 16:14:38 +01:00
if ( $createNewBlock ) {
// Assignation for submit button.
$formButtonClass = 'sub wand' ;
2020-03-30 17:00:48 +02:00
$formButtonValue = 'create' ;
2020-03-17 18:27:56 +01:00
$formButtonLabel = __ ( 'Create' );
} else {
2020-03-19 16:14:38 +01:00
// Assignation for submit button.
2020-03-19 18:24:52 +01:00
$formButtonClass = 'sub upd' ;
2020-03-30 17:00:48 +02:00
$formButtonValue = 'update' ;
2020-03-17 18:27:56 +01:00
$formButtonLabel = __ ( 'Update' );
2020-03-20 15:35:30 +01:00
// Profile exists. Set the attributes with the info.
$this -> setNetworkProfile ();
2020-03-17 18:27:56 +01:00
}
2020-03-19 16:14:38 +01:00
// Main form.
$form = [
2020-03-20 15:35:30 +01:00
'action' => $this -> baseUrl ,
'id' => 'module_block_form' ,
'method' => 'POST' ,
'class' => 'databox filters' ,
'extra' => '' ,
2020-03-19 16:14:38 +01:00
];
// Inputs.
$inputs = [];
2020-03-23 15:16:54 +01:00
// Inputs.
$rawInputs = '' ;
2020-03-19 16:14:38 +01:00
2020-03-30 17:00:48 +02:00
$inputs [] = [
'id' => 'inp-id_np' ,
'arguments' => [
'name' => 'id_np' ,
'type' => 'hidden' ,
'value' => $this -> id_np ,
'return' => true ,
],
];
2020-03-19 16:14:38 +01:00
$inputs [] = [
'label' => __ ( 'Name' ),
'id' => 'inp-name' ,
'arguments' => [
'name' => 'name' ,
'input_class' => 'flex-row' ,
'type' => 'text' ,
2020-03-20 15:35:30 +01:00
'value' => $this -> name ,
2020-03-19 16:14:38 +01:00
'return' => true ,
],
];
$inputs [] = [
'label' => __ ( 'Description' ),
'id' => 'inp-description' ,
'arguments' => [
'name' => 'description' ,
'input_class' => 'flex-row' ,
'type' => 'textarea' ,
2020-03-20 15:35:30 +01:00
'value' => $this -> description ,
2020-03-19 16:14:38 +01:00
'return' => true ,
],
];
$inputs [] = [
'label' => __ ( 'PEN' ),
'id' => 'inp-pen' ,
'arguments' => [
'name' => 'pen' ,
'input_class' => 'flex-row' ,
'type' => 'text' ,
2020-03-20 15:35:30 +01:00
'value' => $this -> pen ,
2020-03-19 16:14:38 +01:00
'return' => true ,
],
];
$inputs [] = [
'arguments' => [
2020-03-30 17:00:48 +02:00
'name' => 'submit_button' ,
2020-03-19 16:14:38 +01:00
'label' => $formButtonLabel ,
2020-03-20 15:35:30 +01:00
'type' => 'submit' ,
2020-03-30 17:00:48 +02:00
'value' => $formButtonValue ,
2020-03-19 16:14:38 +01:00
'attributes' => 'class="' . $formButtonClass . '"' ,
'return' => true ,
],
];
2020-03-20 15:35:30 +01:00
ui_require_jquery_file ( 'tag-editor' );
ui_require_css_file ( 'jquery.tag-editor' );
$js = '$(\'#text-pen\').tagEditor();' ;
2020-03-19 16:14:38 +01:00
if ( $createNewBlock === false ) {
// Get the data.
$sql = sprintf (
' SELECT npc . id_nc AS component_id , nc . name , nc . type , nc . description , nc . id_group AS `group` , ncg . name AS `group_name`
FROM tnetwork_profile_component AS npc , tnetwork_component AS nc
INNER JOIN tnetwork_component_group AS ncg ON ncg . id_sg = nc . id_group
WHERE npc . id_nc = nc . id_nc AND npc . id_np = % d ' ,
2020-03-20 15:35:30 +01:00
$this -> id_np
2020-03-19 16:14:38 +01:00
);
$moduleBlocks = db_get_all_rows_sql ( $sql );
2020-03-31 13:00:07 +02:00
// hd($moduleBlocks);
2020-03-20 15:35:30 +01:00
if ( $moduleBlocks ) {
$blockTables = [];
// Build the information of the blocks
foreach ( $moduleBlocks as $block ) {
if ( key_exists ( $block [ 'group' ], $blockTables ) === false ) {
$blockTables [ $block [ 'group' ]] = [
'name' => $block [ 'group_name' ],
'data' => [],
];
}
2020-03-31 13:00:07 +02:00
$blockTables [ $block [ 'group' ]][ 'data' ][] = [
'component_id' => $block [ 'component_id' ],
'name' => $block [ 'name' ],
'type' => $block [ 'type' ],
'description' => $block [ 'description' ],
];
2020-03-19 16:14:38 +01:00
}
2020-03-20 15:35:30 +01:00
if ( count ( $blockTables ) === 0 ) {
ui_print_info_message ( __ ( 'No module blocks for this profile' ));
} else {
foreach ( $blockTables as $id_group => $blockTable ) {
$blockData = $blockTable [ 'data' ];
$blockTitle = $blockTable [ 'name' ];
$blockTitle .= '<div class="white_table_header_checkbox">' . html_print_checkbox_switch_extended ( 'block_id_' . $id_group , 1 , 0 , false , '' , '' , true ) . '</div>' ;
$table = new StdClasS ();
$table -> class = 'databox data' ;
$table -> width = '75%' ;
$table -> styleTable = 'margin: 2em auto 0;border: 1px solid #ddd;background: white;' ;
$table -> rowid = [];
$table -> data = [];
$table -> cellpadding = 0 ;
$table -> cellspacing = 0 ;
$table -> width = '100%' ;
$table -> class = 'info_table' ;
$table -> head = [];
$table -> head [ 0 ] = __ ( 'Module Name' );
$table -> head [ 1 ] = __ ( 'Type' );
$table -> head [ 2 ] = __ ( 'Description' );
$table -> head [ 3 ] = '<span style="float:right;margin-right:2em;">' . __ ( 'Add' ) . '</span>' ;
$table -> size = [];
$table -> size [ 0 ] = '20%' ;
$table -> size [ 2 ] = '65%' ;
$table -> size [ 3 ] = '15%' ;
$table -> align = [];
$table -> align [ 3 ] = 'right' ;
$table -> style = [];
$table -> style [ 3 ] = 'padding-right:2em' ;
$table -> data = [];
foreach ( $blockData as $module ) {
$data [ 0 ] = $module [ 'name' ];
$data [ 1 ] = ui_print_moduletype_icon ( $module [ 'type' ], true );
$data [ 2 ] = mb_strimwidth ( io_safe_output ( $module [ 'description' ]), 0 , 150 , '...' );
2020-03-30 17:00:48 +02:00
$data [ 3 ] = html_print_checkbox_switch_extended ( 'module_check_' . $id_group . '_' . $module [ 'component_id' ], 1 , 0 , false , 'switchBlockControl(event)' , '' , true );
2020-03-23 15:16:54 +01:00
2020-03-20 15:35:30 +01:00
array_push ( $table -> data , $data );
}
$content = html_print_table ( $table , true );
2020-03-23 15:16:54 +01:00
$rawInputs .= ui_toggle ( $content , $blockTitle , '' , '' , false , true );
2020-03-19 18:24:52 +01:00
}
2020-03-19 16:14:38 +01:00
}
2020-03-20 15:35:30 +01:00
} else {
ui_print_info_message ( __ ( 'No module blocks for this profile' ));
2020-03-19 16:14:38 +01:00
}
}
2020-03-23 15:16:54 +01:00
$this -> printFormAsList (
[
'form' => $form ,
'inputs' => $inputs ,
'rawInputs' => $rawInputs ,
'js' => $js ,
true
]
);
2020-03-20 15:35:30 +01:00
$javascript = "
< script >
function switchBlockControl ( e ){
var switchId = e . target . id . split ( '_' );
var blockNumber = switchId [ 1 ];
var switchNumber = switchId [ 2 ];
$ ( '[id*=checkbox-switch_' + blockNumber + ']' ) . each ( function (){
console . log ( $ ( this ) . val ());
})
console . log ( blockNumber );
console . log ( switchNumber );
}
</ script >
" ;
echo $javascript ;
2020-03-31 10:47:00 +02:00
if ( $createNewBlock === false ) {
2020-03-31 13:00:07 +02:00
echo '<h1>Add modules</h1>' ;
2020-03-31 10:47:00 +02:00
$this -> addingModulesForm ();
}
2020-03-30 17:00:48 +02:00
2020-03-20 15:35:30 +01:00
$this -> printGoBackButton ( $this -> baseUrl );
2020-03-17 18:27:56 +01:00
}
2020-03-16 20:48:38 +01:00
}