$subject, 'text' => $text, 'author' => $config['id_user'], 'timestamp' => $timestamp, 'id_group' => $id_group, 'modal' => $modal, 'expire' => $expire, 'expire_timestamp' => $expire_timestamp, ]; if ($subject === '') { $id_link = false; } else { $id_link = db_process_sql_insert('tnews', $values); } ui_print_result_message( $id_link, __('Successfully created'), __('Could not be created') ); } if (isset($_POST['update'])) { // if update $id_news = (int) get_parameter('id_news', 0); $subject = get_parameter('subject'); $text = get_parameter('text'); $id_group = get_parameter('id_group'); $modal = get_parameter('modal'); $expire = get_parameter('expire'); $expire_date = get_parameter('expire_date'); $expire_time = get_parameter('expire_time'); // Change the user's timezone to the system's timezone $expire_timestamp = (strtotime("$expire_date $expire_time") - get_fixed_offset()); $expire_timestamp = date('Y-m-d H:i:s', $expire_timestamp); // NOW() column exists in any table and always displays the current date and time, so let's get the value from a row in a table which can't be deleted. // This way we prevent getting no value for this variable $timestamp = db_get_value('NOW()', 'tconfig_os', 'id_os', 1); $values = [ 'subject' => $subject, 'text' => $text, 'timestamp' => $timestamp, 'id_group' => $id_group, 'modal' => $modal, 'expire' => $expire, 'expire_timestamp' => $expire_timestamp, ]; if ($subject === '') { $result = false; } else { $result = db_process_sql_update('tnews', $values, ['id_news' => $id_news]); } ui_print_result_message( $result, __('Successfully updated'), __('Not updated. Error updating data') ); } if (isset($_GET['borrar'])) { // if delete $id_news = (int) get_parameter('borrar', 0); $result = db_process_sql_delete('tnews', ['id_news' => $id_news]); ui_print_result_message( $result, __('Successfully deleted'), __('Could not be deleted') ); } // Main form view for Links edit if ((isset($_GET['form_add'])) || (isset($_GET['form_edit']))) { if (isset($_GET['form_edit'])) { $creation_mode = 0; $id_news = (int) get_parameter('id_news', 0); $result = db_get_row('tnews', 'id_news', $id_news); if ($result !== false) { $subject = $result['subject']; $text = $result['text']; $author = $result['author']; $timestamp = $result['timestamp']; $id_group = $result['id_group']; $modal = $result['modal']; $expire = $result['expire']; if ($expire) { $expire_timestamp = $result['expire_timestamp']; $expire_utimestamp = time_w_fixed_tz($expire_timestamp); } else { $expire_utimestamp = (get_system_time() + SECONDS_1WEEK); } $expire_date = date('Y/m/d', $expire_utimestamp); $expire_time = date('H:i:s', $expire_utimestamp); } else { ui_print_error_message(__('Name error')); } } else { // form_add $creation_mode = 1; $text = ''; $subject = ''; $author = $config['id_user']; $id_group = 0; $modal = 0; $expire = 0; $expire_date = date('Y/m/d', (get_system_time() + SECONDS_1WEEK)); $expire_time = date('H:i:s', get_system_time()); } // Create news $table = new stdClass(); $table->width = '100%'; $table->id = 'news'; $table->cellpadding = 4; $table->cellspacing = 4; $table->class = 'databox filters'; $table->head = []; $table->data = []; $table->style[0] = 'font-weight: bold;'; $table->style[1] = 'font-weight: bold;'; $table->style[2] = 'font-weight: bold;'; $table->style[3] = 'font-weight: bold;'; $table->style[4] = 'font-weight: bold;'; $data = []; $data[0] = __('Subject').'
'; $data[0] .= ''; $data[1] = __('Group').'
'; $data[1] .= '
'; $data[1] .= html_print_select_groups($config['id_user'], 'ER', users_can_manage_group_all(), 'id_group', $id_group, '', '', 0, true, false, false, ''); $data[1] .= '
'; $data[2] = __('Modal screen').'
'; $data[2] .= html_print_checkbox_extended('modal', 1, $modal, false, '', 'class="mrgn_top_5 mrg_btt_7"', true); $data[3] = __('Expire').'
'; $data[3] .= html_print_checkbox_extended('expire', 1, $expire, false, '', 'class="mrgn_top_5 mrg_btt_7"', true); $data[4] = __('Expiration').'
'; $data[4] .= html_print_input_text('expire_date', $expire_date, '', 12, 10, true).' '; $data[4] .= html_print_input_text('expire_time', $expire_time, '', 10, 7, true).' '; $table->rowclass[] = ''; $table->data[] = $data; $data = []; $data[0] = __('Text').'
'; $data[0] .= html_print_textarea('text', 25, 15, $text, '', true); $table->rowclass[] = ''; $table->colspan[1][0] = 5; $table->data[] = $data; echo '
'; if ($creation_mode == 1) { echo ""; } else { echo ""; } echo ""; html_print_table($table); echo ""; echo "
"; if (isset($_GET['form_add'])) { echo ""; } else { echo ""; } echo '
'; } else { $rows = db_get_all_rows_in_table('tnews', 'timestamp'); if ($rows === false) { $rows = []; ui_print_info_message(['no_close' => true, 'message' => __('There are no defined news') ]); } else { // Main list view for Links editor echo ""; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $color = 1; foreach ($rows as $row) { if ($color == 1) { $tdcolor = 'datos'; $color = 0; } else { $tdcolor = 'datos2'; $color = 1; } echo "'; if ($row['modal']) { echo "'; } else { echo "'; } echo "'; $utimestamp = time_w_fixed_tz($row['timestamp']); echo "'; if ($row['expire']) { $expire_utimestamp = time_w_fixed_tz($row['expire_timestamp']); $expire_in_secs = ($expire_utimestamp - $utimestamp); if ($expire_in_secs <= 0) { echo "'; } else { $expire_in = human_time_description_raw($expire_in_secs, false, 'large'); echo "'; } } else { echo "'; } echo ''; } echo '
'.__('Subject').''.__('Type').''.__('Author').''.__('Timestamp').''.__('Expiration').''.__('Delete').'
".$row['subject'].'".__('Modal').'".__('Board').'".$row['author'].'".date($config['date_format'], $utimestamp).'".__('Expired').'".$expire_in.'".__('No').''.html_print_image('images/cross.png', true, ['border' => '0', 'class' => 'invert_filter']).'
'; } echo ""; echo "
"; echo "
"; echo ""; echo '
'; } /* * We must add javascript here. Otherwise, the date picker won't * work if the date is not correct because php is returning. */ ui_include_time_picker(); ui_require_jquery_file('ui.datepicker-'.get_user_language(), 'include/javascript/i18n/'); // Include tiny for wysiwyg editor ui_require_javascript_file('tiny_mce', 'include/javascript/tiny_mce/'); ui_require_javascript_file('pandora'); ?>