2019-08-05 13:42:01 +02:00
< ? php
/**
2023-07-21 14:23:42 +02:00
* ITSM setup .
2022-10-26 10:51:12 +02:00
*
* @ category Setup
* @ package Pandora FMS
* @ subpackage Opensource
* @ version 1.0 . 0
* @ license See below
*
2019-08-05 13:42:01 +02:00
* ______ ___ _______ _______ ________
2023-06-08 12:42:10 +02:00
* | __ \ .-----.--.--.--| |.-----.----.-----. | ___ | | | __ |
* | __ /| _ | | _ || _ | _ | _ | | ___ | | __ |
2019-08-05 13:42:01 +02:00
* | ___ | | ___ . _ | __ | __ | _____ || _____ | __ | | ___ . _ | | ___ | | __ | _ | __ | _______ |
*
* ============================================================================
2023-06-08 11:53:13 +02:00
* Copyright ( c ) 2005 - 2023 Pandora FMS
2023-06-08 13:19:01 +02:00
* Please see https :// pandorafms . com / community / for full contribution list
2019-08-05 13:42:01 +02:00
* 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 .
* ============================================================================
*/
2023-07-18 15:13:08 +02:00
use PandoraFMS\ITSM\ITSM ;
2022-10-26 10:51:12 +02:00
// Load globals.
2019-08-05 13:42:01 +02:00
global $config ;
check_login ();
if ( ! check_acl ( $config [ 'id_user' ], 0 , 'PM' ) && ! is_user_admin ( $config [ 'id_user' ])) {
2022-02-01 13:39:18 +01:00
db_pandora_audit (
AUDIT_LOG_ACL_VIOLATION ,
'Trying to access Setup Management'
);
2019-08-05 13:42:01 +02:00
include 'general/noaccess.php' ;
return ;
}
2023-07-18 15:13:08 +02:00
$error = '' ;
$group_values = [];
$priority_values = [];
$object_types_values = [];
$status_values = [];
try {
$ITSM = new ITSM ();
$has_connection = $ITSM -> ping ();
$group_values = $ITSM -> getGroups ();
$priority_values = $ITSM -> getPriorities ();
$status_values = $ITSM -> getStatus ();
$object_types_values = $ITSM -> getObjectypes ();
} catch ( \Throwable $th ) {
$error = $th -> getMessage ();
$has_connection = false ;
2019-09-02 17:01:41 +02:00
}
2023-07-21 14:23:42 +02:00
if ( $has_connection === false && $config [ 'ITSM_enabled' ]) {
2023-07-18 15:13:08 +02:00
ui_print_error_message ( __ ( 'ITSM API is not reachable, %s' , $error ));
2019-09-02 17:01:41 +02:00
}
2019-08-08 13:36:12 +02:00
2019-08-05 13:42:01 +02:00
$table_enable = new StdClass ();
$table_enable -> data = [];
$table_enable -> width = '100%' ;
2023-07-21 14:23:42 +02:00
$table_enable -> id = 'itsm-enable-setup' ;
2019-08-05 13:42:01 +02:00
$table_enable -> class = 'databox filters' ;
$table_enable -> size [ 'name' ] = '30%' ;
$table_enable -> style [ 'name' ] = 'font-weight: bold' ;
2023-07-21 14:23:42 +02:00
// Enable Pandora ITSM.
2019-08-05 13:42:01 +02:00
$row = [];
2023-07-21 14:23:42 +02:00
$row [ 'name' ] = __ ( 'Enable Pandora ITSM' );
$row [ 'control' ] = html_print_checkbox_switch ( 'ITSM_enabled' , 1 , $config [ 'ITSM_enabled' ], true );
$table_enable -> data [ 'ITSM_enabled' ] = $row ;
2019-08-05 13:42:01 +02:00
// Remote config table.
$table_remote = new StdClass ();
$table_remote -> data = [];
$table_remote -> width = '100%' ;
$table_remote -> styleTable = 'margin-bottom: 10px;' ;
2023-07-21 14:23:42 +02:00
$table_remote -> id = 'ITSM-remote-setup' ;
2023-03-22 16:42:03 +01:00
$table_remote -> class = 'databox filters filter-table-adv' ;
$table_remote -> size [ 'hostname' ] = '50%' ;
$table_remote -> size [ 'api_pass' ] = '50%' ;
2019-08-05 13:42:01 +02:00
2023-07-21 14:23:42 +02:00
// Enable ITSM user configuration.
2021-05-07 14:29:29 +02:00
$row = [];
2023-03-22 16:42:03 +01:00
$row [ 'user_level' ] = html_print_label_input_block (
2023-07-21 14:23:42 +02:00
__ ( 'Pandora ITSM configuration at user level' ),
2023-03-22 16:42:03 +01:00
html_print_checkbox_switch (
2023-07-21 14:23:42 +02:00
'ITSM_user_level_conf' ,
2023-03-22 16:42:03 +01:00
1 ,
2023-07-21 14:23:42 +02:00
$config [ 'ITSM_user_level_conf' ],
2023-03-22 16:42:03 +01:00
true
)
);
2023-07-21 14:23:42 +02:00
$table_remote -> data [ 'ITSM_user_level_conf' ] = $row ;
2021-05-07 14:29:29 +02:00
2023-07-21 14:23:42 +02:00
// ITSM hostname.
2019-08-05 13:42:01 +02:00
$row = [];
2023-03-22 16:42:03 +01:00
$row [ 'hostname' ] = html_print_label_input_block (
2023-07-21 14:23:42 +02:00
__ ( 'URL to Pandora ITSM setup' ) . ui_print_help_tip ( __ ( 'Full URL to your Pandora ITSM setup (e.g., http://192.168.1.20/integria/api/v1).' ), true ),
2023-03-22 16:42:03 +01:00
html_print_input_text (
2023-07-21 14:23:42 +02:00
'ITSM_hostname' ,
$config [ 'ITSM_hostname' ],
2023-03-22 16:42:03 +01:00
'' ,
30 ,
100 ,
true
),
2023-07-21 14:23:42 +02:00
[ 'div_class' => 'ITSM-remote-setup-ITSM_hostname' ]
2023-03-22 16:42:03 +01:00
);
2019-08-05 13:42:01 +02:00
2023-07-21 14:23:42 +02:00
// ITSM token.
2023-07-18 15:13:08 +02:00
$row [ 'password' ] = html_print_label_input_block (
2023-07-21 14:23:42 +02:00
__ ( 'Token' ),
2023-07-18 15:13:08 +02:00
html_print_input_password (
2023-07-21 14:23:42 +02:00
'ITSM_token' ,
io_output_password ( $config [ 'ITSM_token' ]),
2023-07-18 15:13:08 +02:00
'' ,
30 ,
100 ,
true
),
2023-07-21 14:23:42 +02:00
[ 'div_class' => 'ITSM-remote-setup-ITSM_token' ]
2023-07-18 15:13:08 +02:00
);
2023-07-21 14:23:42 +02:00
$table_remote -> data [ 'ITSM_token' ] = $row ;
2023-07-18 15:13:08 +02:00
2021-02-25 13:18:04 +01:00
$row = [];
2023-03-22 16:42:03 +01:00
$row [ 'control' ] = __ ( 'Inventory' );
$row [ 'control' ] .= html_print_button (
2022-10-26 10:51:12 +02:00
__ ( 'Sync inventory' ),
'sync-inventory' ,
false ,
'' ,
[
'icon' => 'cog' ,
'mode' => 'secondary mini' ,
],
true
);
2023-07-18 15:13:08 +02:00
$row [ 'control' ] .= '<span id="ITSM-spinner-sync" style="display:none;"> ' . html_print_image ( 'images/spinner.gif' , true ) . '</span>' ;
$row [ 'control' ] .= '<span id="ITSM-success-sync" style="display:none;"> ' . html_print_image ( 'images/status_sets/default/severity_normal.png' , true ) . '</span>' ;
$row [ 'control' ] .= '<span id="ITSM-failure-sync" style="display:none;"> ' . html_print_image ( 'images/status_sets/default/severity_critical.png' , true ) . '</span>' ;
2023-07-21 14:23:42 +02:00
$table_remote -> data [ 'ITSM_sync_inventory' ] = $row ;
2021-02-25 13:18:04 +01:00
2019-09-26 13:22:10 +02:00
// Alert settings.
$table_alert_settings = new StdClass ();
$table_alert_settings -> data = [];
2023-08-23 18:52:06 +02:00
$table_alert_settings -> rowspan = [];
2019-09-26 13:22:10 +02:00
$table_alert_settings -> width = '100%' ;
$table_alert_settings -> styleTable = 'margin-bottom: 10px;' ;
2023-07-21 14:23:42 +02:00
$table_alert_settings -> id = 'ITSM-settings-setup' ;
2023-03-23 17:44:04 +01:00
$table_alert_settings -> class = 'databox filters filter-table-adv' ;
$table_alert_settings -> size [ 0 ] = '50%' ;
$table_alert_settings -> size [ 1 ] = '50%' ;
2019-09-26 13:22:10 +02:00
2019-09-26 13:36:14 +02:00
// Alert incident title.
2023-08-23 18:52:06 +02:00
$table_alert_settings -> data [ 0 ][ 0 ] = html_print_label_input_block (
2023-03-23 17:44:04 +01:00
__ ( 'Title' ),
html_print_input_text (
'incident_title' ,
$config [ 'incident_title' ],
__ ( 'Name' ),
50 ,
100 ,
true ,
false ,
false
)
2021-05-05 13:02:53 +02:00
);
2019-09-26 13:22:10 +02:00
2019-09-26 13:36:14 +02:00
// Alert incident description.
2023-08-23 18:52:06 +02:00
$table_alert_settings -> rowspan [ 0 ][ 1 ] = 3 ;
$table_alert_settings -> data [ 0 ][ 1 ] = html_print_label_input_block (
2023-03-23 17:44:04 +01:00
__ ( 'Ticket body' ),
html_print_textarea (
'incident_content' ,
2023-08-23 18:52:06 +02:00
9 ,
2023-03-23 17:44:04 +01:00
25 ,
$config [ 'incident_content' ],
'' ,
true
)
2021-05-05 13:02:53 +02:00
);
2019-09-26 13:22:10 +02:00
2019-09-26 13:36:14 +02:00
// Alert default group.
2023-08-23 18:52:06 +02:00
$table_alert_settings -> data [ 1 ][ 0 ] = html_print_label_input_block (
2023-03-23 17:44:04 +01:00
__ ( 'Group' ),
html_print_select (
2023-07-18 15:13:08 +02:00
$group_values ,
2023-03-23 17:44:04 +01:00
'default_group' ,
$config [ 'default_group' ],
'' ,
'' ,
0 ,
true ,
false ,
true ,
'' ,
false
)
2019-09-26 13:22:10 +02:00
);
2019-09-26 13:36:14 +02:00
// Alert default owner.
2023-08-23 18:52:06 +02:00
$table_alert_settings -> data [ 2 ][ 0 ] = html_print_label_input_block (
2023-03-23 17:44:04 +01:00
__ ( 'Owner' ),
2023-07-21 14:23:42 +02:00
html_print_autocomplete_users_from_pandora_itsm (
2023-03-23 17:44:04 +01:00
'default_owner' ,
$config [ 'default_owner' ],
true ,
'30' ,
false ,
false ,
'w100p'
),
[ 'div_class' => 'inline' ]
2019-09-26 13:22:10 +02:00
);
2023-08-23 18:52:06 +02:00
// Alert default incident status.
$table_alert_settings -> data [ 3 ][ 0 ] = html_print_label_input_block (
__ ( 'Status' ),
2023-03-23 17:44:04 +01:00
html_print_select (
2023-08-23 18:52:06 +02:00
$status_values ,
'incident_status' ,
$config [ 'incident_status' ],
2023-03-23 17:44:04 +01:00
'' ,
__ ( 'Select' ),
0 ,
true ,
false ,
true ,
'' ,
false
)
2019-09-26 13:22:10 +02:00
);
2023-08-23 18:52:06 +02:00
// Alert default criticity.
$table_alert_settings -> data [ 3 ][ 1 ] = html_print_label_input_block (
__ ( 'Priority' ),
2023-03-23 17:44:04 +01:00
html_print_select (
2023-08-23 18:52:06 +02:00
$priority_values ,
'default_criticity' ,
$config [ 'default_criticity' ],
'' ,
__ ( 'Select' ),
0 ,
true ,
false ,
true ,
'' ,
false
)
);
// Alert default incident type.
$table_alert_settings -> data [ 4 ][ 0 ] = html_print_label_input_block (
__ ( 'Type' ),
html_print_select (
$object_types_values ,
'incident_type' ,
$config [ 'incident_type' ],
2023-03-23 17:44:04 +01:00
'' ,
__ ( 'Select' ),
0 ,
true ,
false ,
true ,
'' ,
false
)
2019-09-26 13:22:10 +02:00
);
2019-09-02 17:01:41 +02:00
// Custom response settings.
$table_cr_settings = new StdClass ();
$table_cr_settings -> data = [];
$table_cr_settings -> width = '100%' ;
$table_cr_settings -> styleTable = 'margin-bottom: 10px;' ;
2023-07-21 14:23:42 +02:00
$table_cr_settings -> id = 'ITSM-cr-settings-setup' ;
2023-03-23 17:44:04 +01:00
$table_cr_settings -> class = 'databox filters filter-table-adv' ;
$table_cr_settings -> size [ 0 ] = '50%' ;
$table_cr_settings -> size [ 1 ] = '50%' ;
2019-09-02 17:01:41 +02:00
2019-09-17 13:38:17 +02:00
// Custom response incident title.
2023-08-23 18:52:06 +02:00
$table_cr_settings -> data [ 0 ][ 0 ] = html_print_label_input_block (
2023-03-23 17:44:04 +01:00
__ ( 'Title' ),
html_print_input_text (
'cr_incident_title' ,
$config [ 'cr_incident_title' ],
__ ( 'Name' ),
50 ,
100 ,
true ,
false ,
false
)
2021-05-05 13:02:53 +02:00
);
2019-09-17 13:38:17 +02:00
// Custom response incident description.
2023-08-23 18:52:06 +02:00
$table_cr_settings -> rowspan [ 0 ][ 1 ] = 3 ;
$table_cr_settings -> data [ 0 ][ 1 ] = html_print_label_input_block (
2023-03-23 17:44:04 +01:00
__ ( 'Ticket body' ),
html_print_textarea (
'cr_incident_content' ,
2023-08-23 18:52:06 +02:00
9 ,
2023-03-23 17:44:04 +01:00
25 ,
$config [ 'cr_incident_content' ],
'' ,
true
)
2021-05-05 13:02:53 +02:00
);
2019-09-02 17:01:41 +02:00
// Custom response default group.
2023-08-23 18:52:06 +02:00
$table_cr_settings -> data [ 1 ][ 0 ] = html_print_label_input_block (
2023-03-23 17:44:04 +01:00
__ ( 'Group' ),
html_print_select (
2023-07-18 15:13:08 +02:00
$group_values ,
2023-03-23 17:44:04 +01:00
'cr_default_group' ,
$config [ 'cr_default_group' ],
'' ,
__ ( 'Select' ),
0 ,
true ,
false ,
true ,
'' ,
false
)
2019-09-02 17:01:41 +02:00
);
// Custom response default owner.
2023-08-23 18:52:06 +02:00
$table_cr_settings -> data [ 2 ][ 0 ] = html_print_label_input_block (
2023-03-23 17:44:04 +01:00
__ ( 'Owner' ),
2023-07-21 14:23:42 +02:00
html_print_autocomplete_users_from_pandora_itsm (
2023-03-23 17:44:04 +01:00
'cr_default_owner' ,
$config [ 'cr_default_owner' ],
true ,
'30' ,
false ,
false ,
'w100p'
),
[ 'div_class' => 'inline' ]
2019-09-02 17:01:41 +02:00
);
2019-09-17 13:38:17 +02:00
2023-08-23 18:52:06 +02:00
// Custom response default incident status.
$row = [];
$table_cr_settings -> data [ 3 ][ 0 ] = html_print_label_input_block (
__ ( 'Status' ),
2023-03-23 17:44:04 +01:00
html_print_select (
2023-08-23 18:52:06 +02:00
$status_values ,
'cr_incident_status' ,
$config [ 'cr_incident_status' ],
2023-03-23 17:44:04 +01:00
'' ,
__ ( 'Select' ),
0 ,
true ,
false ,
true ,
'' ,
false
)
2019-09-02 17:01:41 +02:00
);
2023-08-23 18:52:06 +02:00
// Custom response default criticity.
$table_cr_settings -> data [ 3 ][ 1 ] = html_print_label_input_block (
__ ( 'Priority' ),
2023-03-23 17:44:04 +01:00
html_print_select (
2023-08-23 18:52:06 +02:00
$priority_values ,
'cr_default_criticity' ,
$config [ 'cr_default_criticity' ],
'' ,
__ ( 'Select' ),
0 ,
true ,
false ,
true ,
'' ,
false
)
);
// Custom response default incident type.
$table_cr_settings -> data [ 4 ][ 0 ] = html_print_label_input_block (
__ ( 'Type' ),
html_print_select (
$object_types_values ,
'cr_incident_type' ,
$config [ 'cr_incident_type' ],
2023-03-23 17:44:04 +01:00
'' ,
__ ( 'Select' ),
0 ,
true ,
false ,
true ,
'' ,
false
)
2019-09-17 13:38:17 +02:00
);
2019-09-02 17:01:41 +02:00
2019-08-05 13:42:01 +02:00
// Test.
$row = [];
2023-05-08 12:16:12 +02:00
$row [ 'control' ] = __ ( 'Test connection' );
2023-03-22 16:42:03 +01:00
$row [ 'control' ] .= html_print_button (
2023-05-08 12:16:12 +02:00
__ ( 'Test' ),
2023-07-18 15:13:08 +02:00
'ITSM' ,
2022-10-26 10:51:12 +02:00
false ,
'' ,
[
'icon' => 'cog' ,
'mode' => 'secondary mini' ,
],
true
);
2023-07-18 15:13:08 +02:00
$row [ 'control' ] .= '<span id="ITSM-spinner" class="invisible"> ' . html_print_image ( 'images/spinner.gif' , true ) . '</span>' ;
$row [ 'control' ] .= '<span id="ITSM-success" class="invisible"> ' . html_print_image ( 'images/status_sets/default/severity_normal.png' , true ) . ' ' . __ ( 'Connection its OK' ) . '</span>' ;
$row [ 'control' ] .= '<span id="ITSM-failure" class="invisible"> ' . html_print_image ( 'images/status_sets/default/severity_critical.png' , true ) . ' ' . __ ( 'Connection failed' ) . '</span>' ;
$row [ 'control' ] .= ' <span id="ITSM-message" class="invisible"></span>' ;
2023-07-21 14:23:42 +02:00
$table_remote -> data [ 'ITSM_test' ] = $row ;
2019-08-05 13:42:01 +02:00
// Print.
2023-03-22 16:42:03 +01:00
echo '<div class="center pdd_b_10px mrgn_btn_20px white_box max_floating_element_size">' ;
2023-07-21 14:23:42 +02:00
echo '<a target="_blank" rel="noopener noreferrer" href="https://pandorafms.com/es/itsm/">' ;
2022-03-09 17:20:24 +01:00
html_print_image (
2023-08-14 10:59:56 +02:00
'images/pandoraITSM_logo.png' ,
2022-03-09 17:20:24 +01:00
false ,
2023-08-14 10:59:56 +02:00
[ 'class' => 'w600px mrgn_top_15px' ]
2022-03-09 17:20:24 +01:00
);
2019-08-05 13:42:01 +02:00
echo '</a>' ;
echo '<br />' ;
2023-07-21 14:23:42 +02:00
echo '<div class="ITSM_title">' ;
echo __ ( 'Pandora ITSM' );
2019-08-05 13:42:01 +02:00
echo '</div>' ;
2023-07-21 14:23:42 +02:00
echo '<a target="_blank" rel="noopener noreferrer" href="https://pandorafms.com/es/itsm/">' ;
echo 'https://pandorafms.com/es/itsm/' ;
2019-08-05 13:42:01 +02:00
echo '</a>' ;
echo '</div>' ;
2023-03-22 16:42:03 +01:00
echo " <form method='post' class='max_floating_element_size'> " ;
2019-09-02 17:01:41 +02:00
html_print_input_hidden ( 'update_config' , 1 );
2019-08-05 13:42:01 +02:00
// Form enable.
echo '<div id="form_enable">' ;
html_print_table ( $table_enable );
echo '</div>' ;
// Form remote.
2019-09-02 17:01:41 +02:00
echo '<div id="form_remote">' ;
echo '<fieldset>' ;
2023-07-21 14:23:42 +02:00
echo '<legend>' . __ ( 'Pandora ITSM API settings' ) . '</legend>' ;
2019-09-02 17:01:41 +02:00
html_print_table ( $table_remote );
echo '</fieldset>' ;
echo '</div>' ;
if ( $has_connection != false ) {
2019-09-26 13:22:10 +02:00
// Form alert default settings.
echo '<div id="form_alert_settings">' ;
2023-03-23 17:44:04 +01:00
echo '<fieldset class="mrgn_top_15px">' ;
2021-05-05 13:02:53 +02:00
echo '<legend>' . __ ( 'Alert default values' ) . ' ' . ui_print_help_icon ( 'alert_macros' , true ) . '</legend>' ;
2019-09-26 13:22:10 +02:00
html_print_table ( $table_alert_settings );
echo '</fieldset>' ;
echo '</div>' ;
// Form custom response default settings.
2019-09-02 17:01:41 +02:00
echo '<div id="form_custom_response_settings">' ;
2023-03-23 17:44:04 +01:00
echo '<fieldset class="mrgn_top_15px">' ;
2021-05-05 13:02:53 +02:00
echo '<legend>' . __ ( 'Event custom response default values' ) . ' ' . ui_print_help_icon ( 'alert_macros' , true ) . '</legend>' ;
2019-09-02 17:01:41 +02:00
html_print_table ( $table_cr_settings );
2019-08-05 13:42:01 +02:00
echo '</fieldset>' ;
echo '</div>' ;
2019-09-02 17:01:41 +02:00
2023-03-22 16:42:03 +01:00
$update_button = html_print_submit_button (
__ ( 'Update' ),
'update_button' ,
false ,
[ 'icon' => 'update' ],
true
2022-10-26 10:51:12 +02:00
);
2019-09-02 17:01:41 +02:00
} else {
2023-03-22 16:42:03 +01:00
$update_button = html_print_submit_button (
__ ( 'Update and continue' ),
'update_button' ,
false ,
[ 'icon' => 'update' ],
true
2022-10-26 10:51:12 +02:00
);
2019-09-02 17:01:41 +02:00
}
2023-03-22 16:42:03 +01:00
html_print_action_buttons ( $update_button );
2019-09-02 17:01:41 +02:00
echo '</form>' ;
2019-08-05 13:42:01 +02:00
2023-07-18 15:13:08 +02:00
ui_require_javascript_file ( 'ITSM' );
2019-08-05 13:42:01 +02:00
?>
< script type = " text/javascript " >
2023-07-21 14:23:42 +02:00
if ( $ ( 'input:checkbox[name="ITSM_user_level_conf"]' ) . is ( ':checked' ))
2021-05-07 14:29:29 +02:00
{
2023-07-21 14:23:42 +02:00
$ ( '.ITSM-remote-setup-ITSM_token' ) . hide ()
2021-05-07 14:29:29 +02:00
}
var handleUserLevel = function ( event ) {
2023-07-21 14:23:42 +02:00
var is_checked = $ ( 'input:checkbox[name="ITSM_enabled"]' ) . is ( ':checked' );
var is_checked_userlevel = $ ( 'input:checkbox[name="ITSM_user_level_conf"]' ) . is ( ':checked' );
2022-10-26 10:51:12 +02:00
2021-05-07 14:29:29 +02:00
if ( event . target . value == '1' && is_checked && ! is_checked_userlevel ) {
showUserPass ();
2023-07-21 14:23:42 +02:00
$ ( 'input:checkbox[name="ITSM_user_level_conf"]' ) . attr ( 'checked' , true );
2021-05-07 14:29:29 +02:00
}
else {
hideUserPass ();
2023-07-21 14:23:42 +02:00
$ ( 'input:checkbox[name="ITSM_user_level_conf"]' ) . attr ( 'checked' , false );
2021-05-07 14:29:29 +02:00
};
}
2023-07-21 14:23:42 +02:00
$ ( 'input:checkbox[name="ITSM_enabled"]' ) . change ( handleEnable );
$ ( 'input:checkbox[name="ITSM_user_level_conf"]' ) . change ( handleUserLevel );
2021-05-07 14:29:29 +02:00
2023-07-21 14:23:42 +02:00
if ( ! $ ( 'input:checkbox[name="ITSM_enabled"]' ) . is ( ':checked' )) {
2019-09-02 17:01:41 +02:00
$ ( '#form_remote' ) . hide ();
$ ( '#form_custom_response_settings' ) . hide ();
} else {
$ ( '#form_remote' ) . show ();
$ ( '#form_custom_response_settings' ) . show ();
}
2019-08-05 13:42:01 +02:00
2019-09-02 17:01:41 +02:00
$ ( '#form_enable' ) . css ( 'margin-bottom' , '20px' );
2019-08-05 13:42:01 +02:00
var showFields = function () {
$ ( '#form_remote' ) . show ();
2019-09-02 17:01:41 +02:00
$ ( '#form_custom_response_settings' ) . show ();
2019-08-05 13:42:01 +02:00
}
var hideFields = function () {
$ ( '#form_remote' ) . hide ();
2019-09-02 17:01:41 +02:00
$ ( '#form_custom_response_settings' ) . hide ();
2019-08-05 13:42:01 +02:00
}
var hideUserPass = function () {
2023-07-21 14:23:42 +02:00
$ ( '.ITSM-remote-setup-ITSM_token' ) . hide ();
2019-08-05 13:42:01 +02:00
}
var showUserPass = function () {
2023-07-21 14:23:42 +02:00
$ ( '.ITSM-remote-setup-ITSM_token' ) . show ();
2019-08-05 13:42:01 +02:00
}
var handleEnable = function ( event ) {
2023-07-21 14:23:42 +02:00
var is_checked = $ ( 'input:checkbox[name="ITSM_enabled"]' ) . is ( ':checked' );
2019-08-05 13:42:01 +02:00
if ( event . target . value == '1' && is_checked ) {
showFields ();
2023-07-21 14:23:42 +02:00
$ ( 'input:checkbox[name="ITSM_enabled"]' ) . attr ( 'checked' , true );
2019-08-05 13:42:01 +02:00
}
else {
hideFields ();
2023-07-21 14:23:42 +02:00
$ ( 'input:checkbox[name="ITSM_enabled"]' ) . attr ( 'checked' , false );
2019-08-05 13:42:01 +02:00
};
}
2023-07-21 14:23:42 +02:00
$ ( 'input:checkbox[name="ITSM_enabled"]' ) . change ( handleEnable );
2019-08-05 13:42:01 +02:00
2021-02-25 13:18:04 +01:00
var handleInventorySync = function ( event ) {
2022-10-26 10:51:12 +02:00
2021-02-25 13:18:04 +01:00
var badRequestMessage = '<?php echo __(' Empty user or password '); ?>' ;
var notFoundMessage = '<?php echo __(' User not found '); ?>' ;
var invalidPassMessage = '<?php echo __(' Invalid password '); ?>' ;
2022-10-26 10:51:12 +02:00
2021-02-25 13:18:04 +01:00
var hideLoadingImage = function () {
2023-07-18 15:13:08 +02:00
$ ( 'span#ITSM-spinner-sync' ) . hide ();
2021-02-25 13:18:04 +01:00
}
var showLoadingImage = function () {
2023-07-18 15:13:08 +02:00
$ ( 'span#ITSM-spinner-sync' ) . show ();
2021-02-25 13:18:04 +01:00
}
var hideSuccessImage = function () {
2023-07-18 15:13:08 +02:00
$ ( 'span#ITSM-success-sync' ) . hide ();
2021-02-25 13:18:04 +01:00
}
var showSuccessImage = function () {
2023-07-18 15:13:08 +02:00
$ ( 'span#ITSM-success-sync' ) . show ();
2021-02-25 13:18:04 +01:00
}
var hideFailureImage = function () {
2023-07-18 15:13:08 +02:00
$ ( 'span#ITSM-failure-sync' ) . hide ();
2021-02-25 13:18:04 +01:00
}
var showFailureImage = function () {
2023-07-18 15:13:08 +02:00
$ ( 'span#ITSM-failure-sync' ) . show ();
2021-02-25 13:18:04 +01:00
}
hideSuccessImage ();
hideFailureImage ();
showLoadingImage ();
2023-07-21 14:23:42 +02:00
var ITSM_token = $ ( 'input[name=ITSM_token]' ) . val ();
var api_hostname = $ ( 'input[name=ITSM_hostname]' ) . val ();
2021-02-25 13:18:04 +01:00
if ( ! api_hostname . match ( /^ [ a - zA - Z ] +: \ / \ //))
{
api_hostname = 'http://' + api_hostname ;
}
2023-07-21 14:23:42 +02:00
var url = api_hostname + '//include/api.php' ;
2021-02-25 13:18:04 +01:00
< ? php
// Retrieve all agents and codify string in the format that will be sent over in Ajax call.
$agent_fields = [
'nombre' ,
'alias' ,
'id_os' ,
'direccion' ,
'id_agente' ,
'id_grupo' ,
];
$agents = agents_get_agents ( false , $agent_fields );
$agents_query_string_array = [];
foreach ( $agents as $agent_data ) {
$agents_query_string_array [] = implode ( '|;|' , $agent_data );
}
?>
var agents_query_string_array = < ? php echo json_encode ( $agents_query_string_array ); ?> ;
var data = {
op : 'sync_pandora_agents_inventory' ,
2023-07-21 14:23:42 +02:00
user_pass : ITSM_token ,
2021-02-25 13:18:04 +01:00
params : agents_query_string_array ,
token : '|;|'
}
// AJAX call to check API connection.
$ . ajax ({
2021-04-15 12:12:06 +02:00
type : " POST " ,
2021-02-25 13:18:04 +01:00
url : url ,
dataType : " json " ,
data : data
})
. done ( function ( data , textStatus , xhr ) {
showSuccessImage ();
})
. fail ( function ( xhr , textStatus , errorThrown ) {
showFailureImage ();
})
. always ( function ( xhr , textStatus ) {
hideLoadingImage ();
});
}
2023-07-18 15:13:08 +02:00
$ ( '#button-ITSM' ) . click ( function () {
2023-07-21 14:23:42 +02:00
var pass = $ ( 'input#password-ITSM_token' ) . val ();
var host = $ ( 'input#text-ITSM_hostname' ) . val ();
2023-07-18 15:13:08 +02:00
testConectionApi ( pass , host );
});
//$('#button-sync-inventory').click(handleInventorySync);
2019-08-05 13:42:01 +02:00
</ script >