3 // Precondition: $body is already sanitised
4 function article_add($topic, $body)
6 $query = sprintf("INSERT INTO article (topic,uid,status,body,created,remote_addr) ".
7 "VALUES (%d,%d,%d,'%s',now(),'%s')",
8 $topic, $_SESSION['uid'], 1, pg_escape_string($body),
9 $_SERVER['REMOTE_ADDR']);
11 $sth = db_query($query);
18 function topic_add($zid, $topic, $body)
20 db_query('BEGIN TRANSACTION');
22 $query = sprintf("INSERT INTO topics (zeitung,topic,created,modified) ".
23 "VALUES (%d,'%s',now(),now())",
26 $sth = db_query($query);
32 $id = db_last_id('topics', 'id');
38 if (article_add($id, $body) === false) {
48 function process_topic()
53 if (isset($_GET['zeitung']) && is_numeric($_GET['zeitung']))
54 $zid = $_GET['zeitung'];
55 elseif (isset($_POST['zeitung']) && is_numeric($_POST['zeitung']))
56 $zid = $_POST['zeitung'];
58 $ret = warning('Keine Zeitung oder Magazin gefunden!');
61 $try = format_newspaper($zid, true);
63 $ret .= warning('Keine Zeitung oder Magazin gefunden!');
70 if (!isset($_SESSION['uid']))
71 $ret .= warning('Um eine neue Diskussion zu beginnen, müssen Sie angemeldet sein.');
73 $replace = array('zeitung' => $zid);
74 if (!isset($_POST['zeitung'])) {
75 $ret .= information('Sie beginnen eine neue Diskussion im Forum.');
77 $replace['topic'] = htmlspecialchars($_POST['topic']);
78 $replace['body'] = string_sanitise($_POST['body']);
80 if (strlen($_POST['topic'])) {
81 if (strlen($_POST['body'])) {
82 if (($tid = topic_add($zid, $replace['topic'], $replace['body'])) !== false) {
83 header(sprintf('Location: %stopic/%d.html', $cfg['home'], $tid));
85 $ret .= warning('Es ist ein Datenbankfehler aufgetreten.');
87 $ret .= warning('Sie haben keinen Text für die Diskussion angegeben!');
89 $ret .= warning('Sie haben keinen Titel für die Diskussion angegeben!');
92 $ret .= load_javascript('topic.js') . load_template('topic.html', $replace);
99 // Sideeffect: May set $zlist['redirect']
100 function process_reply()
105 if (isset($_GET['topic']) && is_numeric($_GET['topic']))
106 $topic = $_GET['topic'];
107 elseif (isset($_POST['topic']) && is_numeric($_POST['topic']))
108 $topic = $_POST['topic'];
110 $ret = warning('Keine passende Diskussion gefunden!');
113 $discussion = format_topic($topic);
114 if (isset($zlist['zid'])) {
115 $ret .= format_newspaper($zlist['zid'], true);
117 if (isset($_POST['body'])) {
118 if (article_add($topic, string_sanitise($_POST['body'])) === true) {
119 $ret .= information('Danke für Ihren Beitrag. Sie werden automatisch zur Diskussion weitergeleitet.');
120 header(sprintf('Location: %stopic/%d.html', $cfg['home'], $topic));
122 $ret .= warning('Ihr Beitrag konnte nicht aufgenommen werden.');
124 $replace = array('topic' => $topic,
125 'title' => $zlist['topic'],
126 'body' => htmlspecialchars($_POST['body']));
127 $ret .= load_javascript('reply.js') . load_template('reply.html', $replace);
131 $replace = array('topic' => $topic,
132 'title' => $zlist['topic']);
133 $ret .= load_javascript('reply.js') . load_template('reply.html', $replace);