2011-06-03 05:49:56 +02:00
|
|
|
<?php
|
2016-09-29 10:53:17 +02:00
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
use Engelsystem\Database\DB;
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function admin_news()
|
|
|
|
{
|
|
|
|
global $user;
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-03 14:12:17 +01:00
|
|
|
if (!isset($_GET['action'])) {
|
|
|
|
redirect(page_link_to('news'));
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-21 19:37:42 +01:00
|
|
|
$html = '<div class="col-md-12"><h1>' . _('Edit news entry') . '</h1>' . msg();
|
2017-01-21 19:47:44 +01:00
|
|
|
if (isset($_REQUEST['id']) && preg_match('/^\d{1,11}$/', $_REQUEST['id'])) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$news_id = $_REQUEST['id'];
|
|
|
|
} 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
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
$news = DB::select('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
|
|
|
|
2017-01-03 14:12:17 +01:00
|
|
|
switch ($_REQUEST['action']) {
|
2017-01-02 15:43:36 +01:00
|
|
|
case 'edit':
|
2017-01-21 13:58:53 +01:00
|
|
|
$news = array_shift($news);
|
2017-01-02 15:43:36 +01:00
|
|
|
$user_source = User($news['UID']);
|
|
|
|
|
|
|
|
$html .= form([
|
2017-01-03 14:12:17 +01:00
|
|
|
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-01-02 15:43:36 +01: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) . '">'
|
2017-01-21 19:37:42 +01:00
|
|
|
. '<span class="glyphicon glyphicon-trash"></span> ' . _('Delete')
|
2017-01-02 15:43:36 +01:00
|
|
|
. '</a>';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'save':
|
2017-01-21 13:58:53 +01:00
|
|
|
DB::update('
|
|
|
|
UPDATE `News` SET
|
|
|
|
`Datum`=?,
|
|
|
|
`Betreff`=?,
|
|
|
|
`Text`=?,
|
|
|
|
`UID`=?,
|
|
|
|
`Treffen`=?
|
|
|
|
WHERE `ID`=?
|
|
|
|
',
|
|
|
|
[
|
|
|
|
time(),
|
|
|
|
$_POST["eBetreff"],
|
|
|
|
$_POST["eText"],
|
|
|
|
$user['UID'],
|
|
|
|
isset($_POST["eTreffen"]) ? 1 : 0,
|
|
|
|
$news_id
|
|
|
|
]
|
|
|
|
);
|
2017-01-03 14:12:17 +01:00
|
|
|
engelsystem_log('News updated: ' . $_POST['eBetreff']);
|
|
|
|
success(_('News entry updated.'));
|
|
|
|
redirect(page_link_to('news'));
|
2017-01-02 15:43:36 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'delete':
|
2017-01-21 13:58:53 +01:00
|
|
|
$news = array_shift($news);
|
|
|
|
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.'));
|
|
|
|
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
|
|
|
}
|