3 // Precondition: $body is already sanitised
4 function article_add($topic, $body)
9 $query = sprintf("INSERT INTO article (topic,uid,status,body,created,remote_addr) ".
10 "VALUES (%d,%d,%d,'%s',now(),'%s')",
11 $topic, $_SESSION['uid'], 1, pg_escape_string($body),
12 $_SERVER['REMOTE_ADDR']);
14 $sth = db_query($query);
21 function topic_add($zid, $topic, $body)
23 db_query('BEGIN TRANSACTION');
25 $query = sprintf("INSERT INTO topics (zeitung,topic,created,modified) ".
26 "VALUES (%d,'%s',now(),now())",
29 $sth = db_query($query);
35 $id = db_last_id('topics', 'id');
41 if (article_add($id, $body) === false) {
51 function process_topic()
58 if (isset($_GET['zeitung']) && is_numeric($_GET['zeitung']))
59 $zid = $_GET['zeitung'];
60 elseif (isset($_POST['zeitung']) && is_numeric($_POST['zeitung']))
61 $zid = $_POST['zeitung'];
63 $ret = warning('Keine Zeitung oder Magazin gefunden!');
66 $try = format_newspaper($zid, true);
68 $ret .= warning('Keine Zeitung oder Magazin gefunden!');
75 if (!isset($_SESSION['uid']))
76 $ret .= warning('Um eine neue Diskussion zu beginnen, müssen Sie angemeldet sein.');
78 $replace = array('zeitung' => $zid);
79 if (!isset($_POST['zeitung'])) {
80 $ret .= information('Sie beginnen eine neue Diskussion im Forum.');
82 $replace['topic'] = htmlspecialchars($_POST['topic']);
83 $replace['body'] = string_sanitise($_POST['body']);
85 if (strlen($_POST['topic'])) {
86 if (strlen($_POST['body'])) {
87 if (($tid = topic_add($zid, $replace['topic'], $replace['body'])) !== false) {
88 header(sprintf('Location: %stopic/%d.html', $cfg['home'], $tid));
90 $ret .= warning('Es ist ein Datenbankfehler aufgetreten.');
92 $ret .= warning('Sie haben keinen Text für die Diskussion angegeben!');
94 $ret .= warning('Sie haben keinen Titel für die Diskussion angegeben!');
97 $ret .= load_javascript('topic.js') . load_template('topic.html', $replace);
104 // Sideeffect: May set $zlist['redirect']
105 function process_reply()
112 if (isset($_GET['topic']) && is_numeric($_GET['topic']))
113 $topic = $_GET['topic'];
114 elseif (isset($_POST['topic']) && is_numeric($_POST['topic']))
115 $topic = $_POST['topic'];
117 $ret = warning('Keine passende Diskussion gefunden!');
120 $discussion = format_topic($topic);
121 if (isset($zlist['zid'])) {
122 $ret .= format_newspaper($zlist['zid'], true);
124 if (isset($_POST['body'])) {
125 if (article_add($topic, string_sanitise($_POST['body'])) === true) {
126 $ret .= information('Danke für Ihren Beitrag. Sie werden automatisch zur Diskussion weitergeleitet.');
127 header(sprintf('Location: %stopic/%d.html', $cfg['home'], $topic));
129 $ret .= warning('Ihr Beitrag konnte nicht aufgenommen werden.');
131 $replace = array('topic' => $topic,
132 'title' => $zlist['topic'],
133 'body' => htmlspecialchars($_POST['body']));
134 $ret .= load_javascript('reply.js') . load_template('reply.html', $replace);
138 $replace = array('topic' => $topic,
139 'title' => $zlist['topic']);
140 $ret .= load_javascript('reply.js') . load_template('reply.html', $replace);