diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index d98eb9d3c6..4265e5d69f 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -380,6 +380,9 @@ if ($access_console_node === true) { $sub2['godmode/setup/setup§ion=external_tools']['text'] = __('External Tools'); $sub2['godmode/setup/setup§ion=external_tools']['refr'] = 0; + $sub2['godmode/setup/setup§ion=welcome_tips']['text'] = __('Welcome Tips'); + $sub2['godmode/setup/setup§ion=welcome_tips']['refr'] = 0; + if ((bool) $config['activate_gis'] === true) { $sub2['godmode/setup/setup§ion=gis']['text'] = __('Map conections GIS'); } diff --git a/pandora_console/godmode/setup/setup.php b/pandora_console/godmode/setup/setup.php index 8c8587b1ef..a72dba24ac 100644 --- a/pandora_console/godmode/setup/setup.php +++ b/pandora_console/godmode/setup/setup.php @@ -224,6 +224,11 @@ $buttons['external_tools'] = [ 'text' => ''.html_print_image('images/nettool.png', true, ['title' => __('External Tools'), 'class' => 'invert_filter']).'', ]; +$buttons['welcome_tips'] = [ + 'active' => false, + 'text' => ''.html_print_image('images/', true, ['title' => __('Welcome tips'), 'class' => 'invert_filter']).'', +]; + if ($config['activate_gis']) { $buttons['gis'] = [ 'active' => false, @@ -312,6 +317,20 @@ switch ($section) { $help_header = ''; break; + case 'welcome_tips': + $view = get_parameter('view', ''); + $title = __('Welcome tips'); + if ($view === 'create') { + $title = __('Create tip'); + } else if ($view === 'edit') { + $title = __('Edit tip'); + } + + $buttons['welcome_tips']['active'] = true; + $subpage = ' » '.$title; + $help_header = ''; + break; + case 'enterprise': $buttons['enterprise']['active'] = true; $subpage = ' » '.__('Enterprise'); @@ -409,6 +428,10 @@ switch ($section) { include_once $config['homedir'].'/godmode/setup/setup_external_tools.php'; break; + case 'welcome_tips': + include_once $config['homedir'].'/godmode/setup/welcome_tips.php'; + break; + default: enterprise_hook('setup_enterprise_select_tab', [$section]); break; diff --git a/pandora_console/godmode/setup/welcome_tips.php b/pandora_console/godmode/setup/welcome_tips.php new file mode 100644 index 0000000000..cb5f730299 --- /dev/null +++ b/pandora_console/godmode/setup/welcome_tips.php @@ -0,0 +1,79 @@ +getMessage(); + return; +} + +if ($view === 'create') { + if ($action === 'create') { + $secure_input = get_parameter('secure_input', ''); + $id_lang = get_parameter('id_lang', ''); + $title = get_parameter('title', ''); + $text = get_parameter('text', ''); + $url = get_parameter('url', ''); + $enable = get_parameter_switch('enable', ''); + $errors = []; + + if (empty($id_lang) === true) { + $errors[] = __('Language is empty'); + } + + if (empty($title) === true) { + $errors[] = __('Title is empty'); + } + + if (empty($text) === true) { + $errors[] = __('Text is empty'); + } + + if (count($errors) === 0) { + $response = $tipsWindow->createTip($id_lang, $title, $text, $url, $enable); + if ($response === false) { + $errors[] = __('Error in insert data'); + } + } + + $tipsWindow->viewCreate($errors); + } else { + $tipsWindow->viewCreate(); + } + + return; +} + +$tipsWindow->draw(); diff --git a/pandora_console/include/class/TipsWindow.class.php b/pandora_console/include/class/TipsWindow.class.php index 73d84190ea..fa8e9ea46d 100644 --- a/pandora_console/include/class/TipsWindow.class.php +++ b/pandora_console/include/class/TipsWindow.class.php @@ -45,6 +45,7 @@ class TipsWindow 'getRandomTip', 'renderView', 'setShowTipsAtStartup', + 'getTips', ]; /** @@ -263,4 +264,217 @@ class TipsWindow } } + + + public function draw() + { + try { + $columns = [ + 'title', + 'text', + ]; + + $column_names = [ + __('Title'), + __('Text'), + ]; + + // Load datatables user interface. + ui_print_datatable( + [ + 'id' => 'list_tips_windows', + 'class' => 'info_table', + 'style' => 'width: 100%', + 'columns' => $columns, + 'column_names' => $column_names, + 'ajax_url' => $this->ajaxController, + 'ajax_data' => ['method' => 'getTips'], + 'no_sortable_columns' => [-1], + 'order' => [ + 'field' => 'title', + 'direction' => 'asc', + ], + 'search_button_class' => 'sub filter float-right', + 'form' => [ + 'inputs' => [ + [ + 'label' => __('Search by title'), + 'type' => 'text', + 'name' => 'filter_title', + 'size' => 12, + ], + ], + ], + ] + ); + echo '
'; + echo ''; + html_print_submit_button( + __('Create tip'), + 'create', + false, + 'class="sub next"' + ); + echo ''; + echo '
'; + } catch (Exception $e) { + echo $e->getMessage(); + } + } + + + public function getTips() + { + global $config; + + // Init data. + $data = []; + // Count of total records. + $count = 0; + // Catch post parameters. + $start = get_parameter('start', 0); + $length = get_parameter('length', $config['block_size']); + $order_datatable = get_datatable_order(true); + $filters = get_parameter('filter', []); + $pagination = ''; + $filter = ''; + $order = ''; + + try { + ob_start(); + + if (key_exists('filter_title', $filters) === true) { + if (empty($filters['filter_title']) === false) { + $filter = ' WHERE title like "%'.$filters['filter_title'].'%"'; + } + } + + if (isset($order_datatable)) { + $order = sprintf( + ' ORDER BY %s %s', + $order_datatable['field'], + $order_datatable['direction'] + ); + } + + if (isset($length) && $length > 0 + && isset($start) && $start >= 0 + ) { + $pagination = sprintf( + ' LIMIT %d OFFSET %d ', + $length, + $start + ); + } + + $sql = sprintf( + 'SELECT title, text, url + FROM twelcome_tip %s %s %s', + $filter, + $order, + $pagination + ); + + $data = db_get_all_rows_sql($sql); + + if (empty($data) === true) { + $total = 0; + $data = []; + } else { + $total = $this->getTotalTips(); + } + + echo json_encode( + [ + 'data' => $data, + 'recordsTotal' => $total, + 'recordsFiltered' => $total, + ] + ); + // Capture output. + $response = ob_get_clean(); + } catch (Exception $e) { + echo json_encode(['error' => $e->getMessage()]); + exit; + } + + json_decode($response); + if (json_last_error() === JSON_ERROR_NONE) { + echo $response; + } else { + echo json_encode( + [ + 'success' => false, + 'error' => $response, + ] + ); + } + + exit; + } + + + public function viewCreate($errors=null) + { + if ($errors !== null) { + if (count($errors) > 0) { + foreach ($errors as $key => $value) { + ui_print_error_message($value); + } + } else { + ui_print_success_message(__('Tip created')); + } + } + + $table = new stdClass(); + $table->width = '100%'; + $table->class = 'databox filters'; + + $table->style[0] = 'font-weight: bold'; + + $table->data = []; + $table->data[0][0] = __('Language'); + $table->data[0][1] = html_print_select_from_sql( + 'SELECT id_language, name FROM tlanguage', + 'id_lang', + '', + '', + '', + '0', + true + ); + $table->data[1][0] = __('Title'); + $table->data[1][1] = html_print_input_text('title', '', '', 35, 100, true); + $table->data[2][0] = __('Text'); + $table->data[2][1] = html_print_textarea('text', 5, 1, '', '', true); + $table->data[3][0] = __('Url'); + $table->data[3][1] = html_print_input_text('url', '', '', 35, 100, true); + $table->data[4][0] = __('Enable'); + $table->data[4][1] = html_print_checkbox_switch('enable', true, true, true); + + echo '
'; + html_print_table($table); + echo '
'; + html_print_submit_button(__('Send'), 'submit_button', false, ['class' => 'sub next']); + + echo '
'; + echo '
'; + } + + + public function createTip($id_lang, $title, $text, $url, $enable) + { + return db_process_sql_insert( + 'twelcome_tip', + [ + 'id_lang' => $id_lang, + 'title' => $title, + 'text' => $text, + 'url' => $url, + 'enable' => $enable, + ] + ); + } + + } \ No newline at end of file