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.

83 lines
2.6 KiB
PHTML

14 years ago
<?php
use Engelsystem\Database\DB;
/**
* @return string
*/
8 years ago
function admin_news()
{
global $user;
8 years ago
if (!isset($_GET['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 (isset($_REQUEST['id']) && preg_match('/^\d{1,11}$/', $_REQUEST['id'])) {
8 years ago
$news_id = $_REQUEST['id'];
} else {
return error('Incomplete call, missing News ID.', true);
8 years ago
}
8 years ago
$news = DB::select('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['action']) {
8 years ago
case 'edit':
$news = array_shift($news);
8 years ago
$user_source = User($news['UID']);
$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'))
8 years ago
], 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':
DB::update('
8 years ago
UPDATE `News` SET
`Datum`=?,
`Betreff`=?,
`Text`=?,
`UID`=?,
`Treffen`=?
WHERE `ID`=?
',
[
time(),
$_POST["eBetreff"],
$_POST["eText"],
$user['UID'],
isset($_POST["eTreffen"]) ? 1 : 0,
$news_id
]
);
engelsystem_log('News updated: ' . $_POST['eBetreff']);
success(_('News entry updated.'));
redirect(page_link_to('news'));
8 years ago
break;
case 'delete':
$news = array_shift($news);
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
}