engelsystem/includes/pages/admin_news.php

104 lines
3.3 KiB
PHP
Raw Normal View History

2011-06-03 05:49:56 +02:00
<?php
use Engelsystem\Database\DB;
2018-10-09 21:47:31 +02:00
use Engelsystem\Models\User\User;
2017-01-03 03:22:48 +01:00
/**
* @return string
*/
2017-01-02 03:57:23 +01:00
function admin_news()
{
2018-10-08 21:15:56 +02:00
global $privileges;
$user = Auth()->user();
$request = request();
2017-01-02 15:43:36 +01:00
if (!$request->has('action')) {
2017-01-03 14:12:17 +01:00
redirect(page_link_to('news'));
2017-01-02 03:57:23 +01:00
}
2017-01-02 15:43:36 +01:00
$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');
2017-01-02 03:57:23 +01:00
} else {
2017-01-03 14:12:17 +01:00
return error('Incomplete call, missing News ID.', true);
2017-01-02 03:57:23 +01:00
}
2017-01-02 15:43:36 +01:00
$news = DB::selectOne('SELECT * FROM `News` WHERE `ID`=? LIMIT 1', [$news_id]);
2017-01-02 03:57:23 +01:00
if (empty($news)) {
2017-01-03 14:12:17 +01:00
return error('No News found.', true);
2017-01-02 03:57:23 +01:00
}
2017-01-03 03:22:48 +01:00
switch ($request->input('action')) {
2017-01-02 15:43:36 +01:00
case 'edit':
2018-10-09 21:47:31 +02:00
$user_source = User::find($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
);
}
2017-01-02 15:43:36 +01:00
2017-08-28 16:21:10 +02:00
$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'))
2017-08-28 16:21:10 +02:00
],
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')
2017-01-02 15:43:36 +01:00
. '</a>';
break;
case 'save':
$text = $request->postData('eText');
if (!in_array('admin_news_html', $privileges)) {
$text = strip_tags($text);
}
DB::update('
2017-01-22 01:02:52 +01:00
UPDATE `News` SET
`Datum`=?,
`Betreff`=?,
`Text`=?,
`UID`=?,
`Treffen`=?
WHERE `ID`=?
',
[
time(),
strip_tags($request->postData('eBetreff')),
$text,
2018-10-08 21:15:56 +02:00
$user->id,
$request->has('eTreffen') ? 1 : 0,
$news_id
]
);
engelsystem_log('News updated: ' . $request->postData('eBetreff'));
success(__('News entry updated.'));
2017-01-03 14:12:17 +01:00
redirect(page_link_to('news'));
2017-01-02 15:43:36 +01:00
break;
case 'delete':
DB::delete('DELETE FROM `News` WHERE `ID`=? LIMIT 1', [$news_id]);
2017-01-03 14:12:17 +01:00
engelsystem_log('News deleted: ' . $news['Betreff']);
success(__('News entry deleted.'));
2017-01-03 14:12:17 +01:00
redirect(page_link_to('news'));
2017-01-02 15:43:36 +01:00
break;
2017-01-03 03:22:48 +01:00
default:
redirect(page_link_to('news'));
2017-01-02 15:43:36 +01:00
}
2017-01-02 03:57:23 +01:00
return $html . '</div>';
2011-06-03 05:49:56 +02:00
}