diff --git a/pandora_console/godmode/setup/welcome_tips.php b/pandora_console/godmode/setup/welcome_tips.php index 514beea60e..ec56b0ff2b 100644 --- a/pandora_console/godmode/setup/welcome_tips.php +++ b/pandora_console/godmode/setup/welcome_tips.php @@ -42,11 +42,10 @@ try { if ($view === 'create') { if ($action === 'create') { $files = $_FILES; - $secure_input = get_parameter('secure_input', ''); $id_lang = get_parameter('id_lang', ''); - $title = get_parameter('title', ''); - $text = get_parameter('text', ''); - $url = get_parameter('url', ''); + $title = io_safe_input(get_parameter('title', '')); + $text = io_safe_input(get_parameter('text', '')); + $url = io_safe_input(get_parameter('url', '')); $enable = get_parameter_switch('enable', ''); $errors = []; @@ -76,8 +75,8 @@ if ($view === 'create') { $response = $tipsWindow->createTip($id_lang, $title, $text, $url, $enable, $uploadImages); - if ($response === false) { - $errors[] = __('Error in insert data'); + if ($response === 0) { + $errors[] = __('Error in insert tip'); } } @@ -89,4 +88,22 @@ if ($view === 'create') { return; } -$tipsWindow->draw(); +if ($action === 'delete') { + $idTip = get_parameter('idTip', ''); + $errors = []; + if (empty($idTip) === true) { + $errors[] = __('Tip required'); + } + + if (count($errors) === 0) { + $response = $tipsWindow->deleteTip($idTip); + hd($response, true); + if ($response === 0) { + $errors[] = __('Error in delete tip'); + } + } + + $tipsWindow->draw($errors); +} else { + $tipsWindow->draw(); +} diff --git a/pandora_console/include/class/TipsWindow.class.php b/pandora_console/include/class/TipsWindow.class.php index 4303ac02db..79da5e84bc 100644 --- a/pandora_console/include/class/TipsWindow.class.php +++ b/pandora_console/include/class/TipsWindow.class.php @@ -56,13 +56,6 @@ class TipsWindow */ public $ajaxController; - /** - * Total tips - * - * @var integer - */ - public $totalTips; - /** * Array of tips * @@ -142,12 +135,12 @@ class TipsWindow ui_require_javascript_file('tipsWindow'); ui_require_javascript_file('jquery.bxslider.min'); echo '
'; - $this->totalTips = $this->getTotalTips(); - if ($this->totalTips > 0) { + $totalTips = $this->getTotalTipsEnabled(); + if ($totalTips > 0) { ?> @@ -190,12 +183,13 @@ class TipsWindow $exclude = get_parameter('exclude', ''); $sql = 'SELECT id, title, text, url - FROM twelcome_tip'; + FROM twelcome_tip + WHERE enable = "1" '; if (empty($exclude) === false && $exclude !== null) { $exclude = implode(',', json_decode($exclude, true)); if ($exclude !== '') { - $sql .= sprintf(' WHERE id NOT IN (%s)', $exclude); + $sql .= sprintf(' AND id NOT IN (%s)', $exclude); } } @@ -204,6 +198,10 @@ class TipsWindow $tip = db_get_row_sql($sql); $tip['files'] = $this->getFilesFromTip($tip['id']); + $tip['title'] = io_safe_output($tip['title']); + $tip['text'] = io_safe_output($tip['text']); + $tip['url'] = io_safe_output($tip['url']); + if ($return) { if (empty($tip) === false) { return $tip; @@ -228,6 +226,12 @@ class TipsWindow } + public function getTotalTipsEnabled() + { + return db_get_sql('SELECT count(*) FROM twelcome_tip WHERE enable = "1"'); + } + + public function getFilesFromTip($idTip) { if (empty($idTip) === true) { @@ -267,17 +271,35 @@ class TipsWindow } - public function draw() + public function draw($errors=null) { + ui_require_css_file('tips_window'); + + if ($errors !== null) { + if (count($errors) > 0) { + foreach ($errors as $key => $value) { + ui_print_error_message($value); + } + } else { + ui_print_success_message(__('Tip deleted')); + } + } + try { $columns = [ + 'language', 'title', 'text', + 'enable', + 'actions', ]; $columnNames = [ + __('Language'), __('Title'), __('Text'), + __('Enable'), + __('Actions'), ]; // Load datatables user interface. @@ -324,6 +346,24 @@ class TipsWindow } + public function deleteTip($idTip) + { + $files = $this->getFilesFromTip($idTip); + if ($files !== false) { + if (count($files) > 0) { + foreach ($files as $key => $file) { + unlink($file['path'].'/'.$file['filename']); + } + } + } + + return db_process_sql_delete( + 'twelcome_tip', + ['id' => $idTip] + ); + } + + public function getTips() { global $config; @@ -369,8 +409,10 @@ class TipsWindow } $sql = sprintf( - 'SELECT title, text, url - FROM twelcome_tip %s %s %s', + 'SELECT id, name AS language, title, text, url, enable + FROM twelcome_tip t + LEFT JOIN tlanguage l ON t.id_lang = l.id_language + %s %s %s', $filter, $order, $pagination @@ -378,6 +420,30 @@ class TipsWindow $data = db_get_all_rows_sql($sql); + foreach ($data as $key => $row) { + if ($row['enable'] === '1') { + $data[$key]['enable'] = ''; + } else { + $data[$key]['enable'] = ''; + } + + $data[$key]['title'] = io_safe_output($row['title']); + $data[$key]['text'] = io_safe_output($row['text']); + $data[$key]['url'] = io_safe_output($row['url']); + + $data[$key]['actions'] = '
'; + $data[$key]['actions'] .= html_print_input_image( + 'button_delete_tip', + 'images/delete.png', + '', + '', + true, + ['onclick' => 'if (!confirm(\''.__('Are you sure?').'\')) return false;'] + ); + $data[$key]['actions'] .= html_print_input_hidden('idTip', $row['id'], true); + $data[$key]['actions'] .= '
'; + } + if (empty($data) === true) { $total = 0; $data = []; diff --git a/pandora_console/include/styles/tips_window.css b/pandora_console/include/styles/tips_window.css index 08bcbddc50..aa9a4f050b 100644 --- a/pandora_console/include/styles/tips_window.css +++ b/pandora_console/include/styles/tips_window.css @@ -163,3 +163,19 @@ span.count-round-tip.active { .action_image { margin: 10px 0px; } +span.enable { + display: block; + width: 15px; + height: 15px; + border-radius: 15px; + background-color: #82b92e; + margin: 0 auto; +} +span.disable { + display: block; + width: 15px; + height: 15px; + border-radius: 15px; + background-color: #e63c52; + margin: 0 auto; +}