small code style improvements

main
msquare 8 years ago
parent 42144ed21c
commit 676f5e1627

@ -5,63 +5,62 @@ function admin_news() {
if (! isset($_GET["action"])) { if (! isset($_GET["action"])) {
redirect(page_link_to("news")); redirect(page_link_to("news"));
}
$html = '<div class="col-md-12"><h1>' . _("Edit news entry") . '</h1>' . msg();
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
$news_id = $_REQUEST['id'];
} else { } else {
$html = '<div class="col-md-12"><h1>' . _("Edit news entry") . '</h1>' . msg(); return error("Incomplete call, missing News ID.", true);
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) { }
$news_id = $_REQUEST['id'];
} else {
return error("Incomplete call, missing News ID.", true);
}
$news = sql_select("SELECT * FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1"); $news = sql_select("SELECT * FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1");
if (count($news) > 0) { if (empty($news)) {
switch ($_REQUEST["action"]) { return error("No News found.", true);
default: }
redirect(page_link_to('news')); switch ($_REQUEST["action"]) {
case 'edit': default:
list($news) = $news; redirect(page_link_to('news'));
case 'edit':
list($news) = $news;
$user_source = User($news['UID']); $user_source = User($news['UID']);
$html .= form([ $html .= form([
form_info(_("Date"), date("Y-m-d H:i", $news['Datum'])), form_info(_("Date"), date("Y-m-d H:i", $news['Datum'])),
form_info(_("Author"), User_Nick_render($user_source)), form_info(_("Author"), User_Nick_render($user_source)),
form_text('eBetreff', _("Subject"), $news['Betreff']), form_text('eBetreff', _("Subject"), $news['Betreff']),
form_textarea('eText', _("Message"), $news['Text']), form_textarea('eText', _("Message"), $news['Text']),
form_checkbox('eTreffen', _("Meeting"), $news['Treffen'] == 1, 1), form_checkbox('eTreffen', _("Meeting"), $news['Treffen'] == 1, 1),
form_submit('submit', _("Save")) form_submit('submit', _("Save"))
], page_link_to('admin_news&action=save&id=' . $news_id)); ], 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") . '</a>'; $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>';
break; break;
case 'save': case 'save':
list($news) = $news; list($news) = $news;
sql_query("UPDATE `News` SET sql_query("UPDATE `News` SET
`Datum`='" . sql_escape(time()) . "', `Datum`='" . sql_escape(time()) . "',
`Betreff`='" . sql_escape($_POST["eBetreff"]) . "', `Betreff`='" . sql_escape($_POST["eBetreff"]) . "',
`Text`='" . sql_escape($_POST["eText"]) . "', `Text`='" . sql_escape($_POST["eText"]) . "',
`UID`='" . sql_escape($user['UID']) . "', `UID`='" . sql_escape($user['UID']) . "',
`Treffen`='" . sql_escape($_POST["eTreffen"]) . "' `Treffen`='" . sql_escape($_POST["eTreffen"]) . "'
WHERE `ID`='" . sql_escape($news_id) . "'"); WHERE `ID`='" . sql_escape($news_id) . "'");
engelsystem_log("News updated: " . $_POST["eBetreff"]); engelsystem_log("News updated: " . $_POST["eBetreff"]);
success(_("News entry updated.")); success(_("News entry updated."));
redirect(page_link_to("news")); redirect(page_link_to("news"));
break; break;
case 'delete': case 'delete':
list($news) = $news; list($news) = $news;
sql_query("DELETE FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1"); sql_query("DELETE FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1");
engelsystem_log("News deleted: " . $news['Betreff']); engelsystem_log("News deleted: " . $news['Betreff']);
success(_("News entry deleted.")); success(_("News entry deleted."));
redirect(page_link_to("news")); redirect(page_link_to("news"));
break; break;
}
} else {
return error("No News found.", true);
}
} }
return $html . '</div>'; return $html . '</div>';
} }

@ -374,11 +374,11 @@ function render_table($columns, $rows, $data = true) {
foreach ($rows as $row) { foreach ($rows as $row) {
$html .= '<tr>'; $html .= '<tr>';
foreach ($columns as $key => $column) { foreach ($columns as $key => $column) {
$value = "&nbsp;";
if (isset($row[$key])) { if (isset($row[$key])) {
$html .= '<td class="column_' . $key . '">' . $row[$key] . '</td>'; $value = $row[$key];
} else {
$html .= '<td class="column_' . $key . '">&nbsp;</td>';
} }
$html .= '<td class="column_' . $key . '">' . $value . '</td>';
} }
$html .= '</tr>'; $html .= '</tr>';
} }

Loading…
Cancel
Save