add feedback

This commit is contained in:
marcos 2019-10-15 12:16:50 +02:00
parent edb3c806ce
commit a31e66a9bd
5 changed files with 518 additions and 14 deletions

View File

@ -0,0 +1,77 @@
<?php
/**
* Credential store
*
* @category HelperFeedBack
* @package Pandora FMS
* @subpackage Help Feedback
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2019 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.
* ============================================================================
*/
// Begin.
/**
* Class HelpFeedBack.
*/
global $config;
require_once $config['homedir'].'/include/class/HelpFeedBack.class.php';
$ajaxPage = 'general/help_feedback';
// Control call flow.
try {
// User access and validation is being processed on class constructor.
$helpfeedback = new HelpFeedBack($ajaxPage);
} catch (Exception $e) {
if (is_ajax()) {
echo json_encode(['error' => '[HelpFeedBack]'.$e->getMessage() ]);
exit;
} else {
echo '[HelpFeedBack]'.$e->getMessage();
}
// Stop this execution, but continue 'globally'.
return;
}
// Ajax controller.
if (is_ajax()) {
$method = get_parameter('method', '');
if (method_exists($helpfeedback, $method) === true) {
if ($helpfeedback->ajaxMethod($method) === true) {
$helpfeedback->{$method}();
} else {
$helpfeedback->error('Unavailable method.');
}
} else {
$helpfeedback->error('Method not found. ['.$method.']');
}
// Stop any execution.
exit;
} else {
// Run.
$helpfeedback->run();
}

View File

@ -404,13 +404,42 @@ class Wizard
/**
* Print a block of inputs.
* Example, using direct to 'anidate' inputs directly to wrapper:
* [
* 'wrapper' => 'div',
* 'block_id' => 'example_id',
* 'class' => 'your class',
* 'direct' => 1,
* 'block_content' => [
* [
* 'arguments' => [
* 'label' => __('Sugesstion'),
* 'type' => 'button',
* 'attributes' => 'class="sub ok btn_sug"',
* 'name' => 'option_1',
* 'id' => 'option_1',
* 'script' => 'change_option1()',
* ],
* ],
* [
* 'arguments' => [
* 'label' => __('Something is not quite right'),
* 'type' => 'button',
* 'attributes' => 'class="sub ok btn_something"',
* 'name' => 'option_2',
* 'id' => 'option_2',
* 'script' => 'change_option2()',
* ],
* ],
* ],
* ].
*
* @param array $input Definition of target block to be printed.
* @param boolean $return Return as string or direct output.
*
* @return string HTML content.
*/
public function printBlock(array $input, bool $return=false)
public function printBlock(array $input, bool $return=false, bool $not_direct=false)
{
$output = '';
if ($input['hidden'] == 1) {
@ -424,33 +453,47 @@ class Wizard
}
if (is_array($input['block_content']) === true) {
$not_direct = (bool) $input['direct'];
// Print independent block of inputs.
$output .= '<li id="li-'.$input['block_id'].'" class="'.$class.'">';
if ($input['wrapper']) {
$output .= '<li id="li-'.$input['block_id'].'" class="'.$class.'">';
$output .= '<'.$input['wrapper'].' id="'.$input['block_id'].'" class="'.$class.'">';
} else {
$output .= '<li id="'.$input['block_id'].'" class="'.$class.'">';
}
$output .= '<ul class="wizard '.$input['block_class'].'">';
if (!$not_direct) {
// Avoid encapsulation if input is direct => 1.
$output .= '<ul class="wizard '.$input['block_class'].'">';
}
foreach ($input['block_content'] as $input) {
$output .= $this->printBlock($input, $return);
$output .= $this->printBlock($input, $return, (bool) $not_direct);
}
// Close block.
if ($input['wrapper']) {
$output .= '</ul></'.$input['wrapper'].'>';
} else {
$output .= '</ul></li>';
if (!$not_direct) {
$output .= '</ul>';
}
if ($input['wrapper']) {
$output .= '</'.$input['wrapper'].'>';
}
$output .= '</li>';
} else {
if ($input['arguments']['type'] != 'hidden') {
$output .= '<li id="'.$input['id'].'" class="'.$class.'">';
if (!$not_direct) {
$output .= '<li id="'.$input['id'].'" class="'.$class.'">';
}
$output .= '<label>'.$input['label'].'</label>';
$output .= $this->printInput($input['arguments']);
// Allow dynamic content.
$output .= $input['extra'];
$output .= '</li>';
if (!$not_direct) {
$output .= '</li>';
}
} else {
$output .= $this->printInput($input['arguments']);
// Allow dynamic content.

View File

@ -0,0 +1,310 @@
<?php
/**
* Credential store
*
* @category Class
* @package Pandora FMS
* @subpackage Help Feedback
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2019 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.
* ============================================================================
*/
// 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;
/**
* 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()
{
ui_require_css_file('help_feedback');
$help_url = get_parameter('url', null);
if ($help_url === null) {
echo __('Page not found');
} else {
?>
<iframe width="100%" height="100%" frameBorder="0"
src="<?php echo $help_url; ?>">
<?php echo __('Browser not compatible.'); ?>
</iframe>
<?php
}
echo '<div class="help_feedback">';
// Load feedback form.
echo $this->loadFeedbackForm();
echo '</div>';
}
/**
* Loads a feedback form
*
* @return string HTML code for form.
*
* @return Function loadFeedbackForm.
*/
public function loadFeedbackForm()
{
global $config;
ui_require_css_file('helper');
$form = [
'action' => '#',
'id' => 'feedback_form',
'onsubmit' => 'return false;',
];
$inputs = [
[
'wrapper' => 'div',
'block_id' => 'ejemplo',
'class' => 'flex movida o lo que quieras',
'direct' => 1,
'block_content' => [
[
'arguments' => [
'label' => __('Sugesstion'),
'type' => 'button',
'attributes' => 'class="sub ok btn_sug"',
'name' => 'option_1',
'id' => 'option_1',
'script' => 'change_option1()',
],
],
[
'arguments' => [
'label' => __('Something is not quite right'),
'type' => 'button',
'attributes' => 'class="sub ok btn_something"',
'name' => 'option_2',
'id' => 'option_2',
'script' => 'change_option2()',
],
],
],
],
[
'label' => __('What Happend?'),
'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',
'type' => 'text',
],
],
[
'arguments' => [
'button_class' => 'btn_submit',
'class' => 'btn_submit',
'attributes' => 'class="sub next btn_submit_feed_back"',
'type' => 'submit',
'id' => 'submit_feedback',
'label' => __('Submit'),
],
],
];
$output = ui_toggle(
$this->printForm(
[
'form' => $form,
'inputs' => $inputs,
],
true
),
__('Feedback'),
'',
'',
true,
false,
'',
'no-border'
);
$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.
*
* @return integer Status of the email send task.
*/
public function sendMailMethod()
{
$subject = get_parameter('feedback_option', null);
$feedback_text = get_parameter('feedback_text', null);
$feedback_mail = get_parameter('feedback_email', null);
$subject;
if ($subject === null) {
echo json_encode(['error' => __('No ha seleccionado una opcion')]);
exit;
}
enterprise_include_once('include/functions_cron.php');
$feedback_text .= '
From '.$feedback_mail.' ';
$res = enterprise_hook('send_email_attachment', ['marcos.alconada@artica.es', $feedback_text, $subject]);
return $res;
}
public function loadJS()
{
ob_start();
?>
<script type="text/javascript">
var option_selected = "";
function change_option1() {
option_selected = "<?php echo __('Suggestion'); ?>";
document.getElementById("button-option_2").className = "btn_sug_not_selected";
document.getElementById("button-option_1").className = "sub ok btn_sug";
}
function change_option2() {
option_selected = "<?php echo __('Something is not quite rigth'); ?>";
document.getElementById("button-option_1").className = "btn_sug_not_selected";
document.getElementById("button-option_2").className = "sub ok btn_sug";
}
console.log(option_selected);
// Set values to data.
$("#feedback_form").on('submit', function() {
// Make the AJAX call to send mails.
$.ajax({
type: "POST",
url: "ajax.php",
dataType: "html",
data: {
page: "<?php echo $this->ajaxController; ?>",
method: 'sendMailMethod',
feedback_option: option_selected,
feedback_text: $("textarea[name=feedback_text]").val(),
feedback_email: $("input[name=feedback_email]").val()
},
success: function (data) {
console.log(data);
if (data == 1) {
alert('Message sent');
} else {
console.error("Error in AJAX call to send help feedback mail")
}
},
error: function (data) {
console.error("Fatal error in AJAX call to send help feedback mail")
}
});
});
</script>
<?php
return ob_get_clean();
}
}

View File

@ -56,7 +56,7 @@ function ui_bbcode_to_html($text, $allowed_tags=['[url]'])
$html_bbcode = '<a target="_blank" rel="noopener noreferrer" href="http://$1">$2</a>';
}
// Replace bbcode format [url=www.example.org] String [/url] with or without http and slashes
// Replace bbcode format [url=www.example.org] String [/url] with or without http and slashes.
$return = preg_replace('/\[url(?|](((?:https?:\/\/)?[^[]+))|(?:=[\'"]?((?:https?:\/\/)?[^]]+?)[\'"]?)](.+?))\[\/url]/', $html_bbcode, $text);
}
@ -1405,7 +1405,7 @@ function ui_print_help_icon(
[
'class' => 'img_help',
'title' => __('Help'),
'onclick' => "open_help ('".$url."')",
'onclick' => "open_help ('".ui_get_full_url('index.php?sec=view&sec2=general/help_feedback&pure=1&url='.$url)."')",
'id' => $id,
],
false,

View File

@ -0,0 +1,74 @@
html,
body {
width: 100%;
height: 100%;
}
div.help_feedback {
position: fixed;
bottom: 0;
background: white;
height: auto;
width: 320px;
padding-left: 10px;
padding-right: 10px;
}
.btn_sug {
margin-right: 10px;
margin-top: 10px;
margin-left: 10px;
}
.btn_something {
margin-top: 10px;
margin-left: 10px;
}
.textarea_feedback {
margin-left: 11px;
max-width: 200px;
margin-top: 10px;
font-weight: bolder;
}
.email_feedback {
max-width: 200px;
margin-left: 39px;
margin-top: 10px;
margin-bottom: 10px;
font-weight: bolder;
}
.btn_submit_feed_back {
margin-right: 10px;
margin-top: 5px;
margin-bottom: 10px;
}
.btn_sug_not_selected {
font-weight: normal;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
font-size: 1.2em;
background-color: lightgrey;
background-repeat: no-repeat;
background-position: 92% 10px;
color: #000;
padding-bottom: 10px;
padding-top: 10px;
padding-left: 10px;
border: 1px solid #888;
font-family: "lato", "Open Sans", sans-serif;
cursor: pointer;
margin-right: 20px;
margin-top: 10px;
margin-left: 10px;
background-image: url(../../images/input_tick.png);
padding-right: 30px;
}
.c {
display: flex;
}