2020-03-16 20:48:38 +01:00
< ? php
2020-03-17 16:24:17 +01:00
/**
2020-04-01 16:21:28 +02:00
* Module Template feature .
2020-03-17 16:24:17 +01:00
*
* @ 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-04-01 16:21:28 +02:00
/**
* List of valid PENs
*
* @ var string
*/
private $validPen ;
/**
* Complete list of PENes .
*
* @ var array .
*/
private $penRefs ;
/**
* List of valid PENs
*
* @ var string
*/
private $action ;
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 );
2020-04-01 16:36:06 +02:00
$this -> action = get_parameter ( 'action_button' , '' );
2020-04-01 17:26:04 +02:00
// Profile exists. Set the attributes with the info.
2020-04-01 16:36:06 +02:00
if ( $this -> id_np > 0 || empty ( $this -> action )) {
2020-04-01 16:21:28 +02:00
$this -> setNetworkProfile ();
}
2020-04-06 17:27:50 +02:00
$this -> offset = ( int ) get_parameter ( 'offset' , 0 );
2020-03-20 15:35:30 +01:00
$this -> ajaxController = $ajax_controller ;
2020-04-01 16:21:28 +02:00
// Get all of PENs valid for autocomplete.
$getPENs = db_get_all_rows_sql ( 'SELECT pen,manufacturer FROM tpen' );
$outputPENs = [];
$this -> validPen = '' ;
$this -> penRefs = [];
foreach ( $getPENs as $pen ) {
$this -> validPen .= (( int ) $pen [ 'pen' ]) . ',' ;
$this -> penRefs [] = [
'label' => io_safe_output ( $pen [ 'manufacturer' ]),
'value' => $pen [ 'pen' ],
];
// Reverse autocompletion.
$this -> penRefs [] = [
'label' => $pen [ 'pen' ],
'value' => $pen [ 'pen' ],
];
}
chop ( $this -> validPen );
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-04-01 16:21:28 +02:00
// CSS.
2020-03-19 16:14:38 +01:00
ui_require_css_file ( 'wizard' );
ui_require_css_file ( 'discovery' );
2020-04-01 16:21:28 +02:00
// Javascript.
ui_require_javascript_file ( 'jquery.caret.min' );
2020-03-17 13:46:10 +01:00
// Breadcrums.
$this -> setBreadcrum ([]);
2020-04-01 16:21:28 +02:00
if ( $this -> id_np > 0 ) {
// Add a breadcrumb with the current template.
$urlToGo = $this -> baseUrl . '&id_np=' . $this -> id_np ;
$this -> prepareBreadcrum (
2020-03-30 17:00:48 +02:00
[
2020-04-01 16:21:28 +02:00
[ 'label' => __ ( 'Configuration' )],
[ 'label' => __ ( 'Templates' )],
[
'link' => $this -> baseUrl ,
'label' => __ ( 'Module template management' ),
'selected' => false ,
],
[
'link' => $urlToGo ,
'label' => $this -> name ,
'selected' => true ,
],
2020-03-30 17:00:48 +02:00
],
2020-04-01 16:21:28 +02:00
true
);
} else {
$this -> prepareBreadcrum (
2020-03-16 20:48:38 +01:00
[
2020-04-01 16:21:28 +02:00
[ 'label' => __ ( 'Configuration' )],
[ 'label' => __ ( 'Templates' )],
[
'link' => $this -> baseUrl ,
'label' => __ ( 'Module template management' ),
'selected' => true ,
],
2020-03-16 20:48:38 +01:00
],
2020-04-01 16:21:28 +02:00
true
);
}
2020-03-16 20:48:38 +01:00
2020-04-01 16:21:28 +02:00
// Prints the header.
2020-03-16 20:48:38 +01:00
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-04-01 16:36:06 +02:00
// Process the data if action is required.
2020-04-01 16:21:28 +02:00
if ( ! empty ( $this -> action )) {
$this -> processData ();
}
if ( $this -> id_np === - 1 ) {
// List all Module Blocks.
$this -> moduleTemplateList ();
} else {
// Show form for create or update template.
$this -> moduleTemplateForm ();
}
$this -> loadJS ();
2020-03-16 20:48:38 +01:00
}
2020-03-19 18:24:52 +01:00
/**
2020-04-01 16:21:28 +02:00
* Minor function to dump json message as ajax response .
*
* @ param string $type Type : result || error .
* @ param string $msg Message .
2020-03-19 18:24:52 +01:00
*
2020-04-01 16:21:28 +02:00
* @ return void
2020-03-19 18:24:52 +01:00
*/
2020-04-01 16:21:28 +02:00
private function ajaxMsg ( $type , $msg )
2020-03-19 18:24:52 +01:00
{
2020-04-01 16:21:28 +02:00
if ( $type == 'error' ) {
echo json_encode (
[
$type => ui_print_error_message (
__ ( $msg ),
'' ,
true
),
]
);
} else {
echo json_encode (
[
$type => ui_print_success_message (
__ ( $msg ),
'' ,
true
),
]
);
}
exit ;
2020-03-19 18:24:52 +01:00
}
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-04-01 16:21:28 +02:00
// Only needed if process data.
2020-04-02 12:48:25 +02:00
$modulesToAdd = get_parameter ( 'add-modules-components' , '' );
2020-03-30 19:03:55 +02:00
// Evaluate the modules allowed.
2020-04-01 16:21:28 +02:00
if ( ! empty ( $this -> action )) {
2020-04-02 12:48:25 +02:00
// Success variable.
$success = false ;
2020-04-01 16:36:06 +02:00
$this -> name = get_parameter ( 'name' , '' );
$this -> description = get_parameter ( 'description' , '' );
$this -> pen = get_parameter ( 'pen' , '' );
2020-04-01 16:21:28 +02:00
switch ( $this -> action ) {
2020-03-30 17:00:48 +02:00
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-04-06 11:58:42 +02:00
if ( empty ( $this -> pen )) {
$success = true ;
} else {
$pensList = explode ( ',' , $this -> pen );
2020-03-31 10:47:00 +02:00
// 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 ;
}
2020-03-30 19:03:55 +02:00
}
}
2020-04-01 16:21:28 +02:00
if ( $success === true ) {
$msg = __ ( 'Template %s successfully updated' , $this -> name );
} else {
$msg = __ ( 'Error updating template' );
}
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-04-06 11:58:42 +02:00
if ( empty ( $this -> pen )) {
2020-03-31 10:47:00 +02:00
$success = true ;
2020-04-06 11:58:42 +02:00
} else {
$pensList = explode ( ',' , $this -> pen );
// Insert all of new PENs associated with this id_np.
foreach ( $pensList as $currentPen ) {
$dbResult_pen = db_process_sql_insert (
'tnetwork_profile_pen' ,
[
'pen' => $currentPen ,
'id_np' => $this -> id_np ,
]
);
// If something is wrong, is better stop.
if ( $dbResult_pen === false ) {
break ;
}
$success = true ;
}
2020-03-30 17:00:48 +02:00
}
}
2020-04-01 16:21:28 +02:00
if ( $success === true ) {
$msg = __ ( 'Template %s successfully created' , $this -> name );
} else {
$msg = __ ( 'Error creating template' );
}
2020-03-30 17:00:48 +02:00
break ;
2020-03-31 10:47:00 +02:00
case 'Delete' :
2020-04-01 16:21:28 +02:00
$success = db_process_sql_delete ( 'tnetwork_profile' , [ 'id_np' => $this -> id_np ]);
2020-03-31 10:47:00 +02:00
2020-04-01 16:21:28 +02:00
if ( $success != false ) {
$msg = __ ( 'Template %s successfully deleted' , $this -> name );
} else {
$msg = __ ( 'Error deleting %s template' , $this -> name );
2020-03-31 10:47:00 +02:00
}
2020-04-01 16:21:28 +02:00
// Reset id_np for show the templates list.
$this -> id_np = - 1 ;
2020-03-31 10:47:00 +02:00
break ;
2020-04-06 12:14:57 +02:00
case 'Export' :
global $config ;
$id_network_profile = safe_int ( $this -> id_np );
if ( empty ( $id_network_profile )) {
return false ;
}
$filter [ 'id_np' ] = $id_network_profile ;
$profile_info = @ db_get_row_filter ( 'tnetwork_profile' , $filter , false );
if ( empty ( $profile_info )) {
$success = false ;
// ui_print_error_message(__('This template does not exist'));
return ;
}
// It's important to keep the structure and order in the same way for backwards compatibility.
switch ( $config [ 'dbtype' ]) {
case 'mysql' :
$sql = sprintf (
'
SELECT components . name , components . description , components . type , components . max , components . min , components . module_interval ,
components . tcp_port , components . tcp_send , components . tcp_rcv , components . snmp_community , components . snmp_oid ,
components . id_module_group , components . id_modulo , components . plugin_user , components . plugin_pass , components . plugin_parameter ,
components . max_timeout , components . max_retries , components . history_data , components . min_warning , components . max_warning , components . str_warning , components . min_critical ,
components . max_critical , components . str_critical , components . min_ff_event , components . dynamic_interval , components . dynamic_max , components . dynamic_min , components . dynamic_two_tailed , comp_group . name AS group_name , components . critical_instructions , components . warning_instructions , components . unknown_instructions
FROM `tnetwork_component` AS components , tnetwork_profile_component AS tpc , tnetwork_component_group AS comp_group
WHERE tpc . id_nc = components . id_nc
AND components . id_group = comp_group . id_sg
AND tpc . id_np = % d ' ,
$this -> id_np
);
break ;
case 'postgresql' :
$sql = sprintf (
'
SELECT components . name , components . description , components . type , components . max , components . min , components . module_interval ,
components . tcp_port , components . tcp_send , components . tcp_rcv , components . snmp_community , components . snmp_oid ,
components . id_module_group , components . id_modulo , components . plugin_user , components . plugin_pass , components . plugin_parameter ,
components . max_timeout , components . max_retries , components . history_data , components . min_warning , components . max_warning , components . str_warning , components . min_critical ,
components . max_critical , components . str_critical , components . min_ff_event , comp_group . name AS group_name , components . critical_instructions , components . warning_instructions , components . unknown_instructions
FROM " tnetwork_component " AS components , tnetwork_profile_component AS tpc , tnetwork_component_group AS comp_group
WHERE tpc . id_nc = components . id_nc
AND components . id_group = comp_group . id_sg
AND tpc . id_np = % d ' ,
$this -> id_np
);
break ;
case 'oracle' :
$sql = sprintf (
'
SELECT components . name , components . description , components . type , components . max , components . min , components . module_interval ,
components . tcp_port , components . tcp_send , components . tcp_rcv , components . snmp_community , components . snmp_oid ,
components . id_module_group , components . id_modulo , components . plugin_user , components . plugin_pass , components . plugin_parameter ,
components . max_timeout , components . max_retries , components . history_data , components . min_warning , components . max_warning , components . str_warning , components . min_critical ,
components . max_critical , components . str_critical , components . min_ff_event , comp_group . name AS group_name , components . critical_instructions , components . warning_instructions , components . unknown_instructions
FROM tnetwork_component AS components , tnetwork_profile_component AS tpc , tnetwork_component_group AS comp_group
WHERE tpc . id_nc = components . id_nc
AND components . id_group = comp_group . id_sg
AND tpc . id_np = % d ' ,
$this -> id_np
);
break ;
}
$components = db_get_all_rows_sql ( $sql );
$row_names = [];
$inv_names = [];
// Find the names of the rows that we are getting and throw away the duplicate numeric keys
foreach ( $components [ 0 ] as $row_name => $detail ) {
if ( is_numeric ( $row_name )) {
$inv_names [] = $row_name ;
} else {
$row_names [] = $row_name ;
}
}
2020-04-06 16:49:22 +02:00
$fileName = io_safe_output ( $profile_info [ 'name' ]);
2020-04-06 12:14:57 +02:00
// Send headers to tell the browser we're sending a file
header ( 'Content-type: application/octet-stream' );
2020-04-06 16:49:22 +02:00
header ( 'Content-Disposition: attachment; filename=' . preg_replace ( '/\s/' , '_' , $fileName ) . '.csv' );
2020-04-06 12:14:57 +02:00
header ( 'Pragma: no-cache' );
header ( 'Expires: 0' );
// Clean up output buffering
while ( @ ob_end_clean ()) {
}
// Then print the first line (row names)
echo '"' . implode ( '","' , $row_names ) . '"' ;
echo " \n " ;
// Then print the rest of the data. Encapsulate in quotes in case we have comma's in any of the descriptions
foreach ( $components as $row ) {
foreach ( $inv_names as $bad_key ) {
unset ( $row [ $bad_key ]);
}
echo '"' . implode ( '","' , $row ) . '"' ;
echo " \n " ;
}
// We're done here. The original page will still be there
exit ;
break ;
2020-03-30 17:00:48 +02:00
default :
2020-04-01 16:21:28 +02:00
// There is possible want do an action detailed.
$action_detailed = explode ( '_' , $this -> action );
// Action deletion.
if ( $action_detailed [ 0 ] === 'del' ) {
// Block or Module is affected.
switch ( $action_detailed [ 1 ]) {
case 'module' :
2020-04-02 08:10:37 +02:00
$success = db_process_sql_delete (
'tnetwork_profile_component' ,
'id_nc=' . $action_detailed [ 2 ] . ' AND id_np=' . $this -> id_np
);
2020-04-01 16:21:28 +02:00
if ( $success != false ) {
$msg = __ ( 'Module successfully deleted' );
} else {
$msg = __ ( 'Error deleting module' );
}
break ;
case 'block' :
2020-04-02 08:10:37 +02:00
$success = db_process_sql_delete (
'tnetwork_profile_component' ,
'id_nc in (' . $action_detailed [ 2 ] . ') AND id_np=' . $this -> id_np
);
2020-04-01 16:21:28 +02:00
if ( $success != false ) {
$msg = __ ( 'Block successfully deleted' );
} else {
$msg = __ ( 'Error deleting block' );
}
break ;
2020-04-02 08:10:37 +02:00
case 'template' :
if ( $action_detailed [ 2 ] === 'all' ) {
$success = db_process_sql_delete (
'tnetwork_profile' ,
[ '1' => 1 ]
);
if ( $success != false ) {
$msg = __ ( 'All templates deleted' );
} else {
$msg = __ ( 'Error deleting all templates' );
}
} else {
$success = db_process_sql_delete (
'tnetwork_profile' ,
'id_np in (' . $action_detailed [ 2 ] . ')'
);
if ( $success != false ) {
$msg = __ ( 'Selected templates deleted' );
} else {
$msg = __ ( 'Error deleting selected templates' );
}
}
$this -> id_np = - 1 ;
break ;
2020-04-01 16:21:28 +02:00
default :
// Do nothing.
break ;
}
} else {
$msg = __ ( 'Something gone wrong. Please, try again' );
}
2020-03-30 17:00:48 +02:00
break ;
}
2020-03-31 10:47:00 +02:00
if ( $success === false ) {
2020-04-01 16:21:28 +02:00
ui_print_error_message ( $msg );
2020-03-30 17:00:48 +02:00
} else {
2020-04-01 16:21:28 +02:00
ui_print_success_message ( $msg );
2020-03-30 17:00:48 +02:00
}
2020-04-02 12:48:25 +02:00
} else if ( $modulesToAdd != '' ) {
2020-03-31 13:00:07 +02:00
$modulesToAddList = explode ( ',' , $modulesToAdd );
foreach ( $modulesToAddList as $module ) {
db_process_sql_insert (
'tnetwork_profile_component' ,
[
'id_nc' => $module ,
'id_np' => $this -> id_np ,
]
);
}
2020-04-01 16:21:28 +02:00
$this -> ajaxMsg ( 'result' , __ ( 'Components added sucessfully' ));
2020-03-30 17:00:48 +02:00
}
2020-04-01 16:21:28 +02: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-04-01 16:21:28 +02:00
// Get the groups for select input.
2020-03-30 17:00:48 +02:00
$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-04-06 11:58:42 +02:00
2020-03-30 17:00:48 +02:00
foreach ( $result as $row ) {
$groups [ $row [ 'id_sg' ]] = $row [ 'name' ];
}
foreach ( $result as $row ) {
if ( $row [ 'parent' ] > 1 ) {
2020-04-03 07:43:38 +02:00
$groups_compound [ $row [ 'id_sg' ]] = $groups [ $row [ 'parent' ]] . ' / ' . $row [ 'name' ];
} else {
$groups_compound [ $row [ 'id_sg' ]] = $row [ 'name' ];
2020-03-30 17:00:48 +02:00
}
}
2020-04-03 07:43:38 +02:00
$result = db_get_all_rows_sql (
' SELECT id_nc , name , id_group
FROM tnetwork_component
ORDER BY name '
);
2020-03-30 17:00:48 +02:00
2020-04-03 07:43:38 +02:00
$entireComponentsList = [];
2020-03-30 17:00:48 +02:00
$components = [];
if ( $result === false ) {
$result = [];
}
foreach ( $result as $row ) {
2020-04-03 07:43:38 +02:00
$strIdGroup = ( string ) $row [ 'id_group' ];
if ( ! isset ( $entireComponentsList [ $strIdGroup ])) {
$entireComponentsList [ $strIdGroup ] = $row [ 'id_nc' ];
} else {
$entireComponentsList [ $strIdGroup ] .= ',' . $row [ 'id_nc' ];
}
2020-03-30 17:00:48 +02:00
$components [ $row [ 'id_nc' ]] = $row [ 'name' ];
}
2020-04-03 07:43:38 +02:00
$entireComponentsList = json_encode ( $entireComponentsList );
2020-03-30 17:00:48 +02:00
// Main form.
$form = [
'action' => $this -> baseUrl ,
'id' => 'add_module_form' ,
'method' => 'POST' ,
2020-04-01 16:21:28 +02:00
'class' => 'modal' ,
2020-03-30 17:00:48 +02:00
'extra' => '' ,
];
// Inputs.
$inputs = [];
$inputs [] = [
'id' => 'inp-id_np' ,
'arguments' => [
'name' => 'id_np' ,
'type' => 'hidden' ,
'value' => $this -> id_np ,
'return' => true ,
],
];
2020-04-03 07:43:38 +02:00
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' => [
'input_class' => 'flex-row' ,
2020-04-03 07:43:38 +02:00
'name' => 'filter' ,
2020-03-30 17:00:48 +02:00
'type' => 'text' ,
2020-04-08 12:17:22 +02:00
'size' => '40' ,
2020-04-03 07:43:38 +02:00
'class' => 'float-right' ,
2020-04-02 12:48:25 +02:00
'onKeyDown' => 'filterTextComponents(event);' ,
2020-03-30 17:00:48 +02:00
'value' => '' ,
'return' => true ,
],
];
$inputs [] = [
'label' => __ ( 'Group' ),
'id' => 'add-modules-group' ,
'arguments' => [
'input_class' => 'flex-row' ,
'type' => 'select' ,
2020-04-03 07:43:38 +02:00
'script' => 'filterGroupComponents(event);' ,
'class' => 'float-right' ,
2020-03-30 17:00:48 +02:00
'fields' => $groups_compound ,
2020-04-06 11:58:42 +02:00
'nothing' => 'Group - All' ,
2020-03-30 17:00:48 +02:00
'return' => true ,
],
];
2020-04-03 07:43:38 +02:00
$inputs [] = [
'id' => 'group-components' ,
'arguments' => [
'name' => 'group-components' ,
'type' => 'hidden' ,
'value' => $entireComponentsList ,
'return' => true ,
],
];
2020-03-30 17:00:48 +02:00
$inputs [] = [
'label' => __ ( 'Components' ),
2020-04-01 16:21:28 +02:00
'id' => 'slc-add-modules-components' ,
2020-03-30 17:00:48 +02:00
'arguments' => [
'name' => 'add-modules-components' ,
'input_class' => 'flex-row' ,
2020-04-03 07:43:38 +02:00
'style' => 'width:100%;margin-top: 1em;' ,
2020-03-30 17:00:48 +02:00
'type' => 'select' ,
'multiple' => true ,
'fields' => $components ,
'return' => true ,
],
];
2020-04-01 16:21:28 +02:00
$this -> printForm (
2020-03-30 17:00:48 +02:00
[
'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
$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
*
2020-04-01 16:21:28 +02:00
* @ return void
2020-03-17 13:46:10 +01:00
*/
2020-04-01 16:21:28 +02:00
public function moduleTemplateList ()
2020-03-17 13:46:10 +01:00
{
2020-03-19 16:14:38 +01:00
global $config ;
// Get the count of Blocks.
2020-04-02 08:10:37 +02:00
$countModuleTemplates = db_get_value (
2020-03-19 16:14:38 +01:00
'count(*)' ,
'tnetwork_profile'
);
// Get all the data.
2020-04-02 08:10:37 +02:00
$resultModuleTemplatesTable = db_get_all_rows_filter (
2020-03-19 16:14:38 +01:00
'tnetwork_profile' ,
[
'order' => 'name' ,
'limit' => $config [ 'block_size' ],
'offset' => $this -> offset ,
]
);
2020-04-06 17:27:50 +02:00
ui_pagination ( $countModuleTemplates , $this -> baseUrl , $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-04-02 08:10:37 +02:00
foreach ( $resultModuleTemplatesTable 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-04-01 16:21:28 +02:00
$data [ 3 ] = '<a href="' . $this -> baseUrl . '&action_button=Delete&id_np=' . $row [ 'id_np' ] . '" onclick="if (!confirm(\'' . __ ( 'Are you sure?' ) . '\')) return false;">' . html_print_image ( 'images/cross.png' , true , [ 'title' => __ ( 'Delete' )]) . '</a>' ;
2020-04-06 12:14:57 +02:00
$data [ 3 ] .= '<a href="' . $this -> baseUrl . '&action_button=Export&id_np=' . $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 ,
2020-04-02 08:10:37 +02:00
'id' => 'main_management_form' ,
2020-03-19 16:14:38 +01:00
];
$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-04-02 08:10:37 +02:00
$inputs [] = [
'arguments' => [
'label' => __ ( 'Delete selected' ),
'name' => 'erase' ,
'type' => 'button' ,
'attributes' => 'class="sub cancel"' ,
'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-04-01 16:21:28 +02:00
*
* @ return mixed
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-04-02 08:10:37 +02:00
$createNewTemplate = ( $this -> id_np == 0 ) ? true : false ;
2020-03-19 16:14:38 +01:00
2020-04-02 08:10:37 +02:00
if ( $createNewTemplate ) {
2020-03-19 16:14:38 +01:00
// 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-19 16:14:38 +01:00
// Main form.
$form = [
2020-03-20 15:35:30 +01:00
'action' => $this -> baseUrl ,
2020-04-01 16:21:28 +02:00
'id' => 'module_template_form' ,
2020-03-20 15:35:30 +01:00
'method' => 'POST' ,
'class' => 'databox filters' ,
2020-04-01 16:21:28 +02:00
'extra' => 'id="module_template_form"' ,
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-04-01 16:21:28 +02:00
$inputs [] = [
'id' => 'inp-valid-pen' ,
'arguments' => [
'name' => 'valid-pen' ,
'type' => 'hidden' ,
'value' => $this -> validPen ,
'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 ,
],
];
2020-04-08 16:52:34 +02:00
$availableButtons = [];
$availableButtons [] = [
2020-03-19 16:14:38 +01:00
'arguments' => [
2020-04-01 16:21:28 +02:00
'name' => 'action_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-04-08 16:52:34 +02:00
'attributes' => 'class="float-right ' . $formButtonClass . '"' ,
2020-03-19 16:14:38 +01:00
'return' => true ,
],
];
2020-04-02 08:10:37 +02:00
if ( $createNewTemplate === false ) {
2020-04-08 16:52:34 +02:00
$availableButtons [] = [
2020-04-01 17:26:04 +02:00
'arguments' => [
'name' => 'add_components_button' ,
'label' => __ ( 'Add components' ),
2020-04-13 10:57:32 +02:00
'type' => 'button' ,
'attributes' => 'class="float-right sub cog"' ,
2020-04-01 17:26:04 +02:00
'script' => 'showAddComponent();' ,
'return' => true ,
],
];
}
2020-04-08 16:52:34 +02:00
$inputs [] = [
'class' => 'action_button_list' ,
'direct' => false ,
'wrapper' => 'div' ,
'block_content' => $availableButtons ,
];
2020-04-01 16:21:28 +02:00
// Required for PEN field.
2020-03-20 15:35:30 +01:00
ui_require_jquery_file ( 'tag-editor' );
ui_require_css_file ( 'jquery.tag-editor' );
2020-04-02 08:10:37 +02:00
if ( $createNewTemplate === false ) {
2020-03-19 16:14:38 +01:00
// Get the data.
$sql = sprintf (
2020-04-07 15:20:30 +02:00
' SELECT npc . id_nc AS component_id , nc . name , nc . type , nc . description , nc . id_group AS `group` , nc . id_modulo AS `id_format` , ncg . name AS `group_name`
2020-03-19 16:14:38 +01:00
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-04-01 16:21:28 +02:00
2020-03-20 15:35:30 +01:00
if ( $moduleBlocks ) {
$blockTables = [];
2020-04-01 16:21:28 +02:00
// Build the information of the blocks.
2020-03-20 15:35:30 +01:00
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-04-07 15:20:30 +02:00
'id_format' => $block [ 'id_format' ],
2020-03-31 13:00:07 +02:00
];
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 ) {
2020-04-01 16:21:28 +02:00
// Data with all components.
2020-03-20 15:35:30 +01:00
$blockData = $blockTable [ 'data' ];
2020-04-01 16:21:28 +02:00
// Creation of list of all components.
$blockComponentList = '' ;
foreach ( $blockData as $component ) {
2020-04-02 08:10:37 +02:00
$blockComponentList .= $component [ 'component_id' ] . ',' ;
2020-04-01 16:21:28 +02:00
}
2020-04-02 08:10:37 +02:00
$blockComponentList = chop ( $blockComponentList , ',' );
2020-04-01 16:21:28 +02:00
// Title of Block.
$blockTitle = '<div style="padding-top: 8px;">' ;
$blockTitle .= $blockTable [ 'name' ];
$blockTitle .= '<div class="white_table_header_checkbox">' ;
$blockTitle .= html_print_input_image (
'del_block_' . $id_group . '_' ,
'images/cross.png' ,
1 ,
false ,
true ,
[
'title' => __ ( 'Delete this block' ),
'onclick' => 'if(confirm(\'' . __ ( 'Do you want delete this block?' ) . '\')){deleteModuleTemplate(\'block\',\'' . $blockComponentList . '\')};return false;' ,
]
);
$blockTitle .= '</div></div>' ;
2020-03-20 15:35:30 +01:00
$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' );
2020-04-07 15:20:30 +02:00
$table -> head [ 1 ] = '<span style="margin-left: 0">' . __ ( 'Format' ) . '</span>' ;
$table -> head [ 2 ] = '<span style="text-align: center">' . __ ( 'Type' ) . '</span>' ;
$table -> head [ 3 ] = __ ( 'Description' );
$table -> head [ 4 ] = '<span style="float:right;margin-right:1.2em;">' . __ ( 'Delete' ) . '</span>' ;
2020-03-20 15:35:30 +01:00
$table -> size = [];
2020-04-07 15:20:30 +02:00
$table -> size [ 0 ] = '15%' ;
$table -> size [ 3 ] = '65%' ;
$table -> size [ 4 ] = '15%' ;
2020-03-20 15:35:30 +01:00
$table -> align = [];
2020-04-07 15:20:30 +02:00
$table -> align [ 4 ] = 'right' ;
2020-03-20 15:35:30 +01:00
$table -> style = [];
2020-04-07 15:20:30 +02:00
$table -> style [ 4 ] = 'padding-right:2em' ;
2020-03-20 15:35:30 +01:00
$table -> data = [];
foreach ( $blockData as $module ) {
2020-04-07 15:20:30 +02:00
$data [ 0 ] = '<a href="' . ui_get_full_url ( 'index.php?sec=gmodules&sec2=godmode/modules/manage_network_components&id=' . $module [ 'component_id' ]) . '">' . $module [ 'name' ] . '</a>' ;
switch ( $module [ 'id_format' ]) {
case MODULE_NETWORK :
$formatInfo = html_print_image (
'images/network.png' ,
true ,
[ 'title' => __ ( 'Network module' )]
);
break ;
case MODULE_WMI :
$formatInfo = html_print_image (
'images/wmi.png' ,
true ,
[ 'title' => __ ( 'WMI module' )]
);
break ;
case MODULE_PLUGIN :
$formatInfo = html_print_image (
'images/plugin.png' ,
true ,
[ 'title' => __ ( 'Plug-in module' )]
);
break ;
default :
$formatInfo = $module [ 'id_format' ];
break ;
}
$data [ 1 ] = html_print_div (
[
'style' => 'margin: 0 auto;width: 50%;' ,
'content' => $formatInfo ,
],
true
);
$data [ 2 ] = ui_print_moduletype_icon ( $module [ 'type' ], true );
$data [ 3 ] = mb_strimwidth ( io_safe_output ( $module [ 'description' ]), 0 , 150 , '...' );
$data [ 4 ] = html_print_input_image (
2020-04-01 16:21:28 +02:00
'del_module_' . $module [ 'component_id' ] . '_' ,
'images/cross.png' ,
1 ,
'' ,
true ,
[
'title' => __ ( 'Delete this module' ),
'onclick' => 'if(confirm(\'' . __ ( 'Do you want delete this module?' ) . '\')){deleteModuleTemplate(\'module\',' . $module [ 'component_id' ] . ')};return false;' ,
]
);
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 ,
true
]
);
2020-04-02 08:10:37 +02:00
if ( $createNewTemplate === false ) {
2020-04-01 16:21:28 +02:00
echo '<div style="display:none;" id="modal"></div>' ;
echo '<div style="display:none;" id="msg"></div>' ;
2020-03-31 10:47:00 +02:00
}
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-04-01 16:21:28 +02:00
/**
* Loads JS and return code .
*
* @ return string
*/
public function loadJS ()
{
$str = '' ;
ob_start ();
?>
< script type = " text/javascript " >
2020-04-02 08:10:37 +02:00
/**
* Function for action of delete modules or blocks in template form
*/
2020-04-01 16:21:28 +02:00
function deleteModuleTemplate ( type , id ){
2020-04-02 08:10:37 +02:00
var input_hidden = '<input type="hidden" name="action_button" value="del_' + type + '_' + id + '"/>' ;
$ ( '#module_template_form' ) . append ( input_hidden );
$ ( '#module_template_form' ) . submit ();
2020-04-01 16:21:28 +02:00
}
2020-04-02 08:10:37 +02:00
2020-04-02 12:48:25 +02:00
/**
* Filter with text the components form
*/
function filterTextComponents ( e ){
var text_search = e . target . value ;
text_search = text_search . toLowerCase ();
$ ( '#add-modules-components' ) . children () . each ( function (){
var name = $ ( this ) . text () . toLowerCase ();
if ( name . indexOf ( text_search ) === - 1 ) {
$ ( this ) . css ( 'display' , 'none' );
} else {
$ ( this ) . css ( 'display' , 'block' );
}
});
}
2020-04-03 07:43:38 +02:00
/**
* Filter with group the components form
*/
function filterGroupComponents ( e ){
var selectedGroup = e . target . value ;
var entireList = JSON . parse ( $ ( '#hidden-group-components' ) . val ());
var componentsToShow = entireList [ selectedGroup ];
$ ( '#add-modules-components' ) . children () . each ( function (){
var id = $ ( this ) . val ();
if ( typeof componentsToShow === 'undefined' && selectedGroup != '0' ) {
$ ( this ) . css ( 'display' , 'none' );
} else if ( selectedGroup == '0' || componentsToShow . includes ( id )) {
$ ( this ) . css ( 'display' , 'block' );
} else {
$ ( this ) . css ( 'display' , 'none' );
}
});
}
2020-04-02 08:10:37 +02:00
/**
* Show the modal with list of entire components
*/
2020-04-01 16:21:28 +02:00
function showAddComponent () {
var btn_ok_text = " <?php echo __('OK'); ?> " ;
var btn_cancel_text = " <?php echo __('Cancel'); ?> " ;
var title = " <?php echo __('Add components'); ?> " ;
load_modal ({
target : $ ( " #modal " ),
form : " add_module_form " ,
url : " <?php echo ui_get_full_url('ajax.php', false, false, false); ?> " ,
ajax_callback : showMsg ,
modal : {
title : title ,
ok : btn_ok_text ,
cancel : btn_cancel_text
},
extradata : [
{
name : " id_np " ,
value : " <?php echo $this->id_np ; ?> "
}
],
onshow : {
page : " <?php echo $this->ajaxController ; ?> " ,
method : " addingModulesForm "
},
onsubmit : {
page : " <?php echo $this->ajaxController ; ?> " ,
method : " processData "
}
});
2020-04-02 12:48:25 +02:00
2020-04-01 16:21:28 +02:00
}
/**
* Process ajax responses and shows a dialog with results .
*/
function showMsg ( data ) {
var title = " <?php echo __('Success'); ?> " ;
var text = " " ;
var failed = 0 ;
try {
data = JSON . parse ( data );
text = data [ " result " ];
} catch ( err ) {
title = " <?php echo __('Failed'); ?> " ;
text = err . message ;
failed = 1 ;
}
if ( ! failed && data [ " error " ] != undefined ) {
title = " <?php echo __('Failed'); ?> " ;
text = data [ " error " ];
failed = 1 ;
}
if ( data [ " report " ] != undefined ) {
data [ " report " ] . forEach ( function ( item ) {
text += " <br> " + item ;
});
}
$ ( " #msg " ) . empty ();
$ ( " #msg " ) . html ( text );
$ ( " #msg " ) . dialog ({
width : 450 ,
position : {
my : " center " ,
at : " center " ,
of : window ,
collision : " fit "
},
title : title ,
buttons : [
{
class :
" ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next " ,
text : " OK " ,
click : function ( e ) {
if ( ! failed ) {
$ ( " .ui-dialog-content " ) . dialog ( " close " );
$ ( " .info " ) . hide ();
2020-04-01 17:26:04 +02:00
var id_np = < ? php echo $this -> id_np ; ?> ;
window . location = window . location . href + '&id_np=' + id_np ;
2020-04-01 16:21:28 +02:00
} else {
$ ( this ) . dialog ( " close " );
}
}
}
]
});
}
$ ( document ) . ready ( function () {
2020-04-02 08:10:37 +02:00
//Main module template form deleting selected items
$ ( '#button-erase' ) . click ( function (){
var message = '' ;
var templatesList = '' ;
if ( $ ( '#checkbox-all_delete' ) . prop ( 'checked' ) == true ){
message = " <?php echo __('Do you want delete all templates?'); ?> " ;
templatesList = 'all' ;
} else {
message = " <?php echo __('Do you want delete the selected templates?'); ?> " ;
$ ( " [id*=checkbox-delete_multiple] " ) . each ( function (){
if ( $ ( this ) . prop ( 'checked' ) == true ) {
templatesList = templatesList + $ ( this ) . val () + ',' ;
}
});
// Clean the last comma
templatesList = templatesList . slice ( 0 , - 1 );
}
if ( confirm ( message )) {
let hidden = '<input type="hidden" name="action_button" value="del_template_' + templatesList + '">' ;
$ ( '#main_management_form' ) . append ( hidden );
$ ( '#main_management_form' ) . submit ();
}
});
2020-04-01 16:21:28 +02:00
var listValidPens = $ ( " #hidden-valid-pen " ) . val ();
try {
listValidPens = listValidPens . split ( ',' );
} catch ( e ) {
console . error ( e );
return ;
}
//Adding tagEditor for PEN management.
$ ( " #text-pen " ) . tagEditor ({
beforeTagSave : function ( field , editor , tags , tag , val ) {
if ( listValidPens . indexOf ( val ) == - 1 ) {
return false ;
}
},
autocomplete : {
source : < ? php echo json_encode ( $this -> penRefs ); ?>
}
});
//Values for add.
$ ( " #add-modules-components " ) . change ( function () {
var valores = $ ( " #add-modules-components " )
. val ()
. join ( " , " );
2020-04-02 12:48:25 +02:00
//$("#hidden-add-modules-components-values").val(valores);
2020-04-01 16:21:28 +02:00
});
});
</ script >
< ? php
$str = ob_get_clean ();
echo $str ;
return $str ;
}
2020-03-16 20:48:38 +01:00
}