engelsystem/includes/pages/admin_news.php

70 lines
2.6 KiB
PHP
Raw Normal View History

2011-06-03 05:49:56 +02:00
<?php
2011-06-03 05:49:56 +02:00
function admin_news() {
2012-12-26 14:02:27 +01:00
global $user;
2014-08-22 22:34:13 +02:00
if (! isset($_GET["action"])) {
2012-12-30 18:27:45 +01:00
redirect(page_link_to("news"));
2012-12-26 14:02:27 +01:00
} else {
2014-12-06 21:40:16 +01:00
$html = '<div class="col-md-12"><h1>' . _("Edit news entry") . '</h1>' . msg();
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
2016-09-29 12:45:06 +02:00
$news_id = $_REQUEST['id'];
} else {
2014-08-22 22:34:13 +02:00
return error("Incomplete call, missing News ID.", true);
}
2014-08-22 22:34:13 +02:00
2016-09-29 12:45:06 +02:00
$news = sql_select("SELECT * FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1");
2014-08-22 22:34:13 +02:00
if (count($news) > 0) {
switch ($_REQUEST["action"]) {
default:
redirect(page_link_to('news'));
case 'edit':
list($news) = $news;
$user_source = User($news['UID']);
if ($user_source === false) {
engelsystem_error("Unable to load user.");
}
2014-08-22 22:34:13 +02:00
$html .= form([
2014-08-22 22:34:13 +02: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"))
2016-09-29 12:45:06 +02:00
], page_link_to('admin_news&action=save&id=' . $news_id));
2014-08-22 22:34:13 +02:00
2016-09-29 12:45:06 +02:00
$html .= '<a class="btn btn-danger" href="' . page_link_to('admin_news&action=delete&id=' . $news_id) . '"><span class="glyphicon glyphicon-trash"></span> ' . _("Delete") . '</a>';
2014-08-22 22:34:13 +02:00
break;
case 'save':
list($news) = $news;
2014-12-26 18:39:16 +01:00
sql_query("UPDATE `News` SET
`Datum`='" . sql_escape(time()) . "',
`Betreff`='" . sql_escape($_POST["eBetreff"]) . "',
`Text`='" . sql_escape($_POST["eText"]) . "',
`UID`='" . sql_escape($user['UID']) . "',
`Treffen`='" . sql_escape($_POST["eTreffen"]) . "'
2016-09-29 12:45:06 +02:00
WHERE `ID`='" . sql_escape($news_id) . "'");
2012-12-26 14:02:27 +01:00
engelsystem_log("News updated: " . $_POST["eBetreff"]);
2014-08-22 22:34:13 +02:00
success(_("News entry updated."));
2012-12-30 18:27:45 +01:00
redirect(page_link_to("news"));
2014-08-22 22:34:13 +02:00
break;
case 'delete':
list($news) = $news;
2016-09-29 12:45:06 +02:00
sql_query("DELETE FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1");
2012-12-26 14:02:27 +01:00
engelsystem_log("News deleted: " . $news['Betreff']);
2014-08-22 22:34:13 +02:00
success(_("News entry deleted."));
2012-12-30 18:27:45 +01:00
redirect(page_link_to("news"));
2014-08-22 22:34:13 +02:00
break;
}
} else
return error("No News found.", true);
2012-12-26 14:02:27 +01:00
}
2014-08-22 22:34:13 +02:00
return $html . '</div>';
2011-06-03 05:49:56 +02:00
}
?>