2019-10-15 12:16:50 +02:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Credential store
|
|
|
|
|
*
|
|
|
|
|
* @category Class
|
|
|
|
|
* @package Pandora FMS
|
|
|
|
|
* @subpackage Help Feedback
|
|
|
|
|
* @version 1.0.0
|
|
|
|
|
* @license See below
|
|
|
|
|
*
|
|
|
|
|
* ______ ___ _______ _______ ________
|
|
|
|
|
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
|
|
|
|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
|
|
|
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
|
|
|
|
*
|
|
|
|
|
* ============================================================================
|
2020-11-27 13:52:35 +01:00
|
|
|
|
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
|
2019-10-15 12:16:50 +02:00
|
|
|
|
* Please see http://pandorafms.org for full contribution list
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation for version 2.
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
* ============================================================================
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Begin.
|
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
|
|
require_once $config['homedir'].'/godmode/wizards/Wizard.main.php';
|
|
|
|
|
ui_require_css_file('pandora');
|
|
|
|
|
/**
|
|
|
|
|
* Class HelpFeedBack.
|
|
|
|
|
*/
|
|
|
|
|
class HelpFeedBack extends Wizard
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Allowed methods to be called using AJAX request.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
public $AJAXMethods = [
|
|
|
|
|
'loadFeedbackForm',
|
|
|
|
|
'sendMailMethod',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Url of controller.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
public $ajaxController;
|
|
|
|
|
|
2019-11-07 18:33:03 +01:00
|
|
|
|
|
2019-10-15 12:16:50 +02:00
|
|
|
|
/**
|
|
|
|
|
* Checks if target method is available to be called using AJAX.
|
|
|
|
|
*
|
|
|
|
|
* @param string $method Target method.
|
|
|
|
|
*
|
|
|
|
|
* @return boolean True allowed, false not.
|
|
|
|
|
*/
|
|
|
|
|
public function ajaxMethod($method)
|
|
|
|
|
{
|
|
|
|
|
return in_array($method, $this->AJAXMethods);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor.
|
|
|
|
|
*
|
|
|
|
|
* @param string $ajax_controller Controller.
|
|
|
|
|
*
|
|
|
|
|
* @return object
|
|
|
|
|
*/
|
|
|
|
|
public function __construct($ajax_controller)
|
|
|
|
|
{
|
|
|
|
|
$this->ajaxController = $ajax_controller;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Main method.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function run()
|
|
|
|
|
{
|
2019-11-07 17:26:32 +01:00
|
|
|
|
ui_require_css_File('discovery');
|
2019-10-15 12:16:50 +02:00
|
|
|
|
ui_require_css_file('help_feedback');
|
|
|
|
|
|
2019-11-21 18:21:46 +01:00
|
|
|
|
$help_url = get_parameter('b', null);
|
2022-11-03 13:53:10 +01:00
|
|
|
|
$help_url = io_safe_input(base64_decode($help_url));
|
|
|
|
|
|
2019-10-15 12:16:50 +02:00
|
|
|
|
if ($help_url === null) {
|
|
|
|
|
echo __('Page not found');
|
|
|
|
|
} else {
|
|
|
|
|
?>
|
2019-11-21 18:21:46 +01:00
|
|
|
|
<iframe width="100%" height="100%" frameBorder="0" id="h_Viewer"
|
2019-10-15 12:16:50 +02:00
|
|
|
|
src="<?php echo $help_url; ?>">
|
|
|
|
|
<?php echo __('Browser not compatible.'); ?>
|
|
|
|
|
</iframe>
|
|
|
|
|
<?php
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-07 19:39:50 +01:00
|
|
|
|
$hidden = '<input type="hidden" value="'.$help_url.'" ';
|
|
|
|
|
$hidden .= ' form="feedback_form" name="help_url" />';
|
|
|
|
|
|
|
|
|
|
echo $hidden;
|
|
|
|
|
|
2019-10-15 12:16:50 +02:00
|
|
|
|
echo '<div class="help_feedback">';
|
|
|
|
|
// Load feedback form.
|
|
|
|
|
echo $this->loadFeedbackForm();
|
2021-03-11 15:40:23 +01:00
|
|
|
|
echo '</div><div id="back" class="invisible"></div>';
|
2019-10-15 12:16:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Loads a feedback form
|
|
|
|
|
*
|
|
|
|
|
* @return string HTML code for form.
|
|
|
|
|
*
|
|
|
|
|
* @return Function loadFeedbackForm.
|
|
|
|
|
*/
|
|
|
|
|
public function loadFeedbackForm()
|
|
|
|
|
{
|
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
|
|
$form = [
|
|
|
|
|
'action' => '#',
|
|
|
|
|
'id' => 'feedback_form',
|
|
|
|
|
'onsubmit' => 'return false;',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$inputs = [
|
|
|
|
|
[
|
|
|
|
|
'wrapper' => 'div',
|
2019-11-07 17:26:32 +01:00
|
|
|
|
'block_id' => 'flex-row-baseline w100p',
|
|
|
|
|
'class' => 'flex-row-baseline w100p',
|
2019-10-15 12:16:50 +02:00
|
|
|
|
'direct' => 1,
|
|
|
|
|
'block_content' => [
|
|
|
|
|
[
|
|
|
|
|
'arguments' => [
|
2019-11-21 18:21:46 +01:00
|
|
|
|
'label' => __('Suggestion'),
|
2019-11-07 17:26:32 +01:00
|
|
|
|
'type' => 'radio_button',
|
|
|
|
|
'attributes' => 'class="btn"',
|
|
|
|
|
'name' => 'suggestion',
|
|
|
|
|
'id' => 'suggestion',
|
|
|
|
|
'script' => 'disableRadio(\'report\')',
|
|
|
|
|
'return' => true,
|
2019-10-15 12:16:50 +02:00
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'arguments' => [
|
2019-11-21 18:21:46 +01:00
|
|
|
|
'label' => __('Something is wrong'),
|
2019-11-07 17:26:32 +01:00
|
|
|
|
'type' => 'radio_button',
|
|
|
|
|
'attributes' => 'class="btn"',
|
|
|
|
|
'name' => 'report',
|
|
|
|
|
'id' => 'report',
|
|
|
|
|
'script' => 'disableRadio(\'suggestion\')',
|
|
|
|
|
'return' => true,
|
2019-10-15 12:16:50 +02:00
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
|
2019-11-07 17:26:32 +01:00
|
|
|
|
'label' => __('What happened?'),
|
|
|
|
|
'class' => 'explain',
|
2019-10-15 12:16:50 +02:00
|
|
|
|
'arguments' => [
|
|
|
|
|
'class' => 'textarea_feedback',
|
|
|
|
|
'id' => 'feedback_text',
|
|
|
|
|
'type' => 'textarea',
|
|
|
|
|
'name' => 'feedback_text',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'label' => __('Your Email'),
|
|
|
|
|
'arguments' => [
|
|
|
|
|
'id' => 'feedback_email',
|
|
|
|
|
'name' => 'feedback_email',
|
|
|
|
|
'input_class' => 'email_feedback',
|
|
|
|
|
'class' => 'email_feedback',
|
2019-11-07 19:39:50 +01:00
|
|
|
|
'type' => 'email',
|
|
|
|
|
'required' => true,
|
2019-10-15 12:16:50 +02:00
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'arguments' => [
|
|
|
|
|
'button_class' => 'btn_submit',
|
|
|
|
|
'class' => 'btn_submit',
|
|
|
|
|
'attributes' => 'class="sub next btn_submit_feed_back"',
|
|
|
|
|
'type' => 'submit',
|
|
|
|
|
'id' => 'submit_feedback',
|
|
|
|
|
'label' => __('Submit'),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
2019-11-07 17:26:32 +01:00
|
|
|
|
$output = ui_print_toggle(
|
|
|
|
|
[
|
2019-11-07 18:33:03 +01:00
|
|
|
|
'id' => 'toggle_help_feedback',
|
2019-11-07 17:26:32 +01:00
|
|
|
|
'content' => $this->printForm(
|
|
|
|
|
[
|
|
|
|
|
'form' => $form,
|
|
|
|
|
'inputs' => $inputs,
|
|
|
|
|
],
|
|
|
|
|
true
|
|
|
|
|
),
|
|
|
|
|
'name' => __('Feedback'),
|
|
|
|
|
'return' => true,
|
|
|
|
|
'class' => 'no-border',
|
|
|
|
|
'img_a' => 'images/arrow_down_white.png',
|
|
|
|
|
'img_b' => 'images/arrow_up_white.png',
|
|
|
|
|
|
|
|
|
|
]
|
2019-10-15 12:16:50 +02:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$output .= $this->loadJS();
|
|
|
|
|
return $output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Function send_mail_method,we use send_email_attachment method
|
|
|
|
|
* from functions_cron.php.
|
|
|
|
|
*
|
|
|
|
|
* @param string $feedback_option type fo mail.
|
|
|
|
|
* @param string $feedback_text text mail.
|
|
|
|
|
* @param string $feedback_mail costumer mail.
|
|
|
|
|
*
|
2019-11-07 18:33:03 +01:00
|
|
|
|
* @return void.
|
2019-10-15 12:16:50 +02:00
|
|
|
|
*/
|
|
|
|
|
public function sendMailMethod()
|
|
|
|
|
{
|
2021-01-28 13:20:36 +01:00
|
|
|
|
global $config;
|
2019-11-07 18:33:03 +01:00
|
|
|
|
$suggestion = get_parameter('type', 'false');
|
2019-10-15 12:16:50 +02:00
|
|
|
|
$feedback_text = get_parameter('feedback_text', null);
|
|
|
|
|
$feedback_mail = get_parameter('feedback_email', null);
|
2019-11-07 19:39:50 +01:00
|
|
|
|
$help_url = get_parameter('help_url', 'unknown');
|
|
|
|
|
|
|
|
|
|
$section = explode('title=', $help_url, 2);
|
|
|
|
|
|
|
|
|
|
$subject = '';
|
|
|
|
|
if (is_array($section) === true && isset($section[1]) === true) {
|
|
|
|
|
$subject = '['.$section[1].']';
|
|
|
|
|
}
|
2019-10-15 12:16:50 +02:00
|
|
|
|
|
2019-11-07 18:33:03 +01:00
|
|
|
|
if ($suggestion !== 'false') {
|
2019-11-07 19:39:50 +01:00
|
|
|
|
$subject .= __('[pandorafms wiki] New suggestion');
|
2019-11-07 18:33:03 +01:00
|
|
|
|
} else {
|
2019-11-07 19:39:50 +01:00
|
|
|
|
$subject .= __('[pandorafms wiki] New report');
|
2019-11-07 18:33:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($feedback_mail) === true) {
|
|
|
|
|
$error = [
|
|
|
|
|
'error' => __(
|
|
|
|
|
'Please provide your email address, we promise not to bother you'
|
|
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($feedback_text) === true) {
|
|
|
|
|
if ($suggestion !== 'false') {
|
|
|
|
|
$msg = 'Please provide some feedback. Write something awesome!';
|
|
|
|
|
} else {
|
|
|
|
|
$msg = 'Please provide some feedback. We\'ll appreciate it!';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$error = [
|
|
|
|
|
'error' => __($msg),
|
|
|
|
|
];
|
|
|
|
|
}
|
2019-10-15 12:16:50 +02:00
|
|
|
|
|
2019-11-07 18:33:03 +01:00
|
|
|
|
if ($error !== null) {
|
|
|
|
|
echo json_encode($error);
|
2019-10-15 12:16:50 +02:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enterprise_include_once('include/functions_cron.php');
|
|
|
|
|
|
2019-11-07 18:33:03 +01:00
|
|
|
|
$uid = $config['pandora_uid'];
|
|
|
|
|
if (empty($uid) === true) {
|
|
|
|
|
$uid = 'not registered';
|
|
|
|
|
}
|
2019-10-15 12:16:50 +02:00
|
|
|
|
|
2019-11-07 19:39:50 +01:00
|
|
|
|
$body = '<ul><li><b>User mail</b> '.$feedback_mail.'</li>';
|
|
|
|
|
$body .= '<li><b>Console</b> <i>'.$uid.'</i></li>';
|
|
|
|
|
$body .= '<li><b>URL</b> '.$help_url.'</li></ul>';
|
|
|
|
|
$body .= '<h2>Message</h2>';
|
2019-11-07 18:33:03 +01:00
|
|
|
|
$body .= '<p>'.$feedback_text.'</p>';
|
2019-10-15 12:16:50 +02:00
|
|
|
|
|
2019-11-07 18:33:03 +01:00
|
|
|
|
$res = enterprise_hook(
|
|
|
|
|
'send_email_attachment',
|
|
|
|
|
[
|
2019-11-07 19:41:23 +01:00
|
|
|
|
'feedback@artica.es',
|
2019-11-07 18:33:03 +01:00
|
|
|
|
$body,
|
|
|
|
|
$subject,
|
|
|
|
|
]
|
|
|
|
|
);
|
2019-10-15 12:16:50 +02:00
|
|
|
|
|
2019-11-07 18:33:03 +01:00
|
|
|
|
// Response.
|
|
|
|
|
if ($res == 1) {
|
|
|
|
|
$r = ['error' => ''];
|
|
|
|
|
} else {
|
|
|
|
|
$r = ['error' => __('Something went wrong while sending the report.')];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo json_encode($r);
|
|
|
|
|
|
|
|
|
|
exit;
|
2019-10-15 12:16:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-11-07 18:33:03 +01:00
|
|
|
|
/**
|
|
|
|
|
* Load extra JS.
|
|
|
|
|
*
|
|
|
|
|
* @return string JS content.
|
|
|
|
|
*/
|
2019-10-15 12:16:50 +02:00
|
|
|
|
public function loadJS()
|
|
|
|
|
{
|
|
|
|
|
ob_start();
|
|
|
|
|
?>
|
|
|
|
|
<script type="text/javascript">
|
2019-11-07 17:26:32 +01:00
|
|
|
|
function disableRadio(id) {
|
|
|
|
|
$('#'+id).prop('checked', false)
|
2019-10-15 12:16:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set values to data.
|
|
|
|
|
$("#feedback_form").on('submit', function() {
|
|
|
|
|
// Make the AJAX call to send mails.
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: "POST",
|
|
|
|
|
url: "ajax.php",
|
2019-11-07 18:33:03 +01:00
|
|
|
|
dataType: "json",
|
2019-10-15 12:16:50 +02:00
|
|
|
|
data: {
|
|
|
|
|
page: "<?php echo $this->ajaxController; ?>",
|
|
|
|
|
method: 'sendMailMethod',
|
2019-11-07 18:33:03 +01:00
|
|
|
|
type: $('#suggestion').prop('checked'),
|
2019-10-15 12:16:50 +02:00
|
|
|
|
feedback_text: $("textarea[name=feedback_text]").val(),
|
2019-11-07 19:39:50 +01:00
|
|
|
|
feedback_email: $("input[name=feedback_email]").val(),
|
|
|
|
|
help_url: $("input[name=help_url]").val(),
|
2019-10-15 12:16:50 +02:00
|
|
|
|
},
|
|
|
|
|
success: function (data) {
|
2019-11-07 18:33:03 +01:00
|
|
|
|
var title;
|
|
|
|
|
var content;
|
|
|
|
|
var failed = 0;
|
|
|
|
|
var className='submit-next';
|
|
|
|
|
|
|
|
|
|
if (data.error != "") {
|
|
|
|
|
title = '<?php echo __('Failed'); ?>';
|
|
|
|
|
content = data.error;
|
|
|
|
|
failed = 1;
|
|
|
|
|
className='submit-cancel';
|
2019-10-15 12:16:50 +02:00
|
|
|
|
} else {
|
2019-11-07 18:33:03 +01:00
|
|
|
|
title = '<?php echo __('Success'); ?>';
|
|
|
|
|
content = '<?php echo __('Your report had been successfully sent to Artica.').'<br>'.__('Thank you!'); ?>';
|
2019-10-15 12:16:50 +02:00
|
|
|
|
}
|
2019-11-07 18:33:03 +01:00
|
|
|
|
$('#back').html(content);
|
|
|
|
|
$('#back').dialog({
|
|
|
|
|
title: title,
|
|
|
|
|
buttons: [
|
|
|
|
|
{
|
|
|
|
|
class:
|
|
|
|
|
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd " + className,
|
|
|
|
|
text: '<?php echo __('OK'); ?>',
|
|
|
|
|
click: function() {
|
|
|
|
|
$(this).dialog("close");
|
|
|
|
|
if (failed == 0) {
|
|
|
|
|
$('#toggle_help_feedback').empty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
})
|
2019-10-15 12:16:50 +02:00
|
|
|
|
},
|
|
|
|
|
error: function (data) {
|
2019-11-07 18:33:03 +01:00
|
|
|
|
console.error("Fatal error in AJAX call to send help feedback mail")
|
2019-10-15 12:16:50 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
<?php
|
|
|
|
|
return ob_get_clean();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|