You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.3 KiB
PHTML

14 years ago
<?php
use Engelsystem\Database\DB;
/**
* @return string
*/
8 years ago
function admin_news()
{
global $privileges;
$user = Auth()->user();
$request = request();
8 years ago
if (!$request->has('action')) {
redirect(page_link_to('news'));
8 years ago
}
8 years ago
$html = '<div class="col-md-12"><h1>' . __('Edit news entry') . '</h1>' . msg();
if ($request->has('id') && preg_match('/^\d{1,11}$/', $request->input('id'))) {
$news_id = $request->input('id');
8 years ago
} else {
return error('Incomplete call, missing News ID.', true);
8 years ago
}
8 years ago
$news = DB::selectOne('SELECT * FROM `News` WHERE `ID`=? LIMIT 1', [$news_id]);
8 years ago
if (empty($news)) {
return error('No News found.', true);
8 years ago
}
switch ($request->input('action')) {
8 years ago
case 'edit':
$user_source = User($news['UID']);
if (
!in_array('admin_news_html', $privileges)
&& strip_tags($news['Text']) != $news['Text']
) {
$html .= warning(
__('This message contains HTML. After saving the post some formatting will be lost!'),
true
);
}
8 years ago
$html .= form(
[
form_info(__('Date'), date('Y-m-d H:i', $news['Datum'])),
form_info(__('Author'), User_Nick_render($user_source)),
form_text('eBetreff', __('Subject'), $news['Betreff']),
form_textarea('eText', __('Message'), $news['Text']),
form_checkbox('eTreffen', __('Meeting'), $news['Treffen'] == 1, 1),
form_submit('submit', __('Save'))
],
page_link_to('admin_news', ['action' => 'save', 'id' => $news_id])
);
$html .= '<a class="btn btn-danger" href="'
. page_link_to('admin_news', ['action' => 'delete', 'id' => $news_id])
. '">'
. '<span class="glyphicon glyphicon-trash"></span> ' . __('Delete')
8 years ago
. '</a>';
break;
case 'save':
$text = $request->postData('eText');
if (!in_array('admin_news_html', $privileges)) {
$text = strip_tags($text);
}
DB::update('
8 years ago
UPDATE `News` SET
`Datum`=?,
`Betreff`=?,
`Text`=?,
`UID`=?,
`Treffen`=?
WHERE `ID`=?
',
[
time(),
strip_tags($request->postData('eBetreff')),
$text,
$user->id,
$request->has('eTreffen') ? 1 : 0,
$news_id
]
);
engelsystem_log('News updated: ' . $request->postData('eBetreff'));
success(__('News entry updated.'));
redirect(page_link_to('news'));
8 years ago
break;
case 'delete':
DB::delete('DELETE FROM `News` WHERE `ID`=? LIMIT 1', [$news_id]);
engelsystem_log('News deleted: ' . $news['Betreff']);
success(__('News entry deleted.'));
redirect(page_link_to('news'));
8 years ago
break;
default:
redirect(page_link_to('news'));
8 years ago
}
8 years ago
return $html . '</div>';
14 years ago
}