2011-06-03 05:49:56 +02:00
|
|
|
<?php
|
2016-09-29 10:53:17 +02:00
|
|
|
|
2019-11-10 21:30:26 +01:00
|
|
|
use Engelsystem\Models\News;
|
2017-01-21 13:58:53 +01:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function admin_news()
|
|
|
|
{
|
2017-07-18 21:38:53 +02:00
|
|
|
$request = request();
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-07-18 21:38:53 +02:00
|
|
|
if (!$request->has('action')) {
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(page_link_to('news'));
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-08-29 21:55:32 +02:00
|
|
|
$html = '<div class="col-md-12"><h1>' . __('Edit news entry') . '</h1>' . msg();
|
2017-07-18 21:38:53 +02:00
|
|
|
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
|
|
|
|
2019-10-31 20:02:34 +01:00
|
|
|
$news = News::find($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
|
|
|
|
2017-07-18 21:38:53 +02:00
|
|
|
switch ($request->input('action')) {
|
2017-01-02 15:43:36 +01:00
|
|
|
case 'edit':
|
2019-10-31 20:02:34 +01:00
|
|
|
$user_source = $news->user;
|
2017-12-26 14:35:01 +01:00
|
|
|
if (
|
2018-11-12 14:41:23 +01:00
|
|
|
!auth()->can('admin_news_html')
|
2019-10-31 20:02:34 +01:00
|
|
|
&& strip_tags($news->text) != $news->text
|
2017-12-26 14:35:01 +01:00
|
|
|
) {
|
|
|
|
$html .= warning(
|
2018-08-29 21:55:32 +02:00
|
|
|
__('This message contains HTML. After saving the post some formatting will be lost!'),
|
2017-12-26 14:35:01 +01:00
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-08-28 16:21:10 +02:00
|
|
|
$html .= form(
|
|
|
|
[
|
2020-04-03 10:40:23 +02:00
|
|
|
form_info(__('Date'), $news->created_at->format(__('Y-m-d H:i'))),
|
2018-08-29 21:55:32 +02:00
|
|
|
form_info(__('Author'), User_Nick_render($user_source)),
|
2019-10-31 20:02:34 +01:00
|
|
|
form_text('eBetreff', __('Subject'), $news->title),
|
|
|
|
form_textarea('eText', __('Message'), $news->text),
|
2019-11-10 21:30:26 +01:00
|
|
|
form_checkbox('eTreffen', __('Meeting'), $news->is_meeting, 1),
|
2018-08-29 21:55:32 +02:00
|
|
|
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])
|
|
|
|
. '">'
|
2018-08-29 21:55:32 +02:00
|
|
|
. '<span class="glyphicon glyphicon-trash"></span> ' . __('Delete')
|
2017-01-02 15:43:36 +01:00
|
|
|
. '</a>';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'save':
|
2017-08-29 22:22:53 +02:00
|
|
|
$text = $request->postData('eText');
|
2018-11-12 14:41:23 +01:00
|
|
|
if (!auth()->can('admin_news_html')) {
|
2017-08-29 22:22:53 +02:00
|
|
|
$text = strip_tags($text);
|
|
|
|
}
|
|
|
|
|
2019-10-31 20:02:34 +01:00
|
|
|
$news->title = strip_tags($request->postData('eBetreff'));
|
|
|
|
$news->text = $text;
|
|
|
|
$news->is_meeting = $request->has('eTreffen');
|
|
|
|
$news->save();
|
2017-08-29 16:21:25 +02:00
|
|
|
|
|
|
|
engelsystem_log('News updated: ' . $request->postData('eBetreff'));
|
2018-08-29 21:55:32 +02:00
|
|
|
success(__('News entry updated.'));
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(page_link_to('news'));
|
2017-01-02 15:43:36 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'delete':
|
2019-10-31 20:02:34 +01:00
|
|
|
$news->delete();
|
|
|
|
engelsystem_log('News deleted: ' . $news->title);
|
2018-08-29 21:55:32 +02:00
|
|
|
success(__('News entry deleted.'));
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(page_link_to('news'));
|
2017-01-02 15:43:36 +01:00
|
|
|
break;
|
2017-01-03 03:22:48 +01:00
|
|
|
default:
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_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
|
|
|
}
|