setContent(fetchAllNews() ?: []); $cache->save(); } // --------------------------------------------------------------------------- // Mutations // --------------------------------------------------------------------------- if ($_SERVER['REQUEST_METHOD'] === 'POST') { $do = (string)($_POST['do'] ?? ''); $id = intv($_POST['id'] ?? 0); if ($do === 'delete' && $id > 0) { db()->execute("DELETE FROM `znote_news` WHERE `id` = ? LIMIT 1;", [$id]); acp_news_rebuild_cache(); acp_log('news.delete', '#' . $id); acp_flash_success(t('acp.news.deleted')); acp_redirect('news'); } if ($do === 'create') { $charId = intv($_POST['selected_char'] ?? 0); $title = trim((string)($_POST['title'] ?? '')); $text = (string)($_POST['text'] ?? ''); if ($charId > 0 && $title !== '' && trim($text) !== '') { db()->execute(" INSERT INTO `znote_news` (`title`, `text`, `date`, `pid`) VALUES (?, ?, ?, ?); ", [$title, $text, time(), $charId]); acp_news_rebuild_cache(); acp_log('news.create', $title); acp_flash_success(t('acp.news.published')); acp_redirect('news'); } acp_flash_error(t('acp.news.fill_fields')); acp_redirect('news', ['action' => 'add']); } if ($do === 'update' && $id > 0) { $title = trim((string)($_POST['title'] ?? '')); $text = (string)($_POST['text'] ?? ''); db()->execute(" UPDATE `znote_news` SET `title` = ?, `text` = ? WHERE `id` = ? LIMIT 1; ", [$title, $text, $id]); acp_news_rebuild_cache(); acp_log('news.update', $title !== '' ? $title : ('#' . $id)); acp_flash_success(t('acp.news.updated')); acp_redirect('news'); } } // --------------------------------------------------------------------------- // View state // --------------------------------------------------------------------------- $action = (string)($_GET['action'] ?? ''); $editId = intv($_GET['id'] ?? 0); $news = fetchAllNews(); $news = is_array($news) ? $news : []; $editing = null; if ($action === 'edit' && $editId > 0) { foreach ($news as $n) { if ((int)$n['id'] === $editId) { $editing = $n; break; } } if ($editing === null) { acp_flash_error(t('acp.news.not_found')); acp_redirect('news'); } } // Staff characters on the admin's own account can be set as author. $authors = []; if ($action === 'add') { $charList = user_character_list($user_data['id']); if (is_array($charList)) { foreach ($charList as $row) { $charName = (string)($row['name'] ?? ''); if ($charName === '') { continue; } $charId = (int)user_character_id($charName); $charD = user_character_data($charId, 'group_id', 'id'); if (is_array($charD) && (int)($charD['group_id'] ?? 0) > 1) { $authors[$charId] = $charName; } } } } ?>
group_id > 1']) ?>
| = t('acp.news.col_date') ?> | = t('acp.news.col_author') ?> | = t('acp.news.col_title') ?> | = t('acp.news.col_actions') ?> |
|---|---|---|---|
| = h(getClock((int)($n['date'] ?? 0), true)) ?> | = h($nm) ?> | = h((string)($n['title'] ?? '')) ?> | = t('acp.news.edit') ?> |