chiark / gitweb /
wip
[nj-awaymsg.git] / mason / save
1 <%init>
2 use AwayMsg;
3 db_connect();
4 www_begin($r,$m);
5 </%init><%args>
6 $save => 0
7 $cancel => 0
8 $textid => undef
9 $desc
10 $subject
11 $text
12 </%args><%perl>
13 if (!$save) {
14     $m->redirect("main");
15     return;
16 }
17 my $ins;
18
19 $dbh->do('BEGIN');
20
21 if ($textid ne 'new') {
22     my $dtextq = $dbh->prepare("DELETE FROM texts WHERE textid = ?");
23     my $ndeleted = $dtextq->execute($textid);
24     if (!$ndeleted) {
25         $textid = 'new';
26     }
27 }
28
29 if ($textid eq 'new') {
30     my $textid = time;
31     my $ntextq = $dbh->prepare("SELECT textid FROM texts".
32                                " ORDER BY textid DESC LIMIT 1");
33     $ntextq->execute();
34     my $ntextrow = $ntextq->fetchrow_hashref();
35     if ($ntextrow) {
36         my $mintextid = $ntextrow->{'textid'} + 1;
37         $textid = $mintextid if $textid < $mintextid;
38     }
39 }
40
41 my $dinsertq = $dbh->prepare("INSERT INTO texts (textid, desc, subject, text)".
42                              " VALUES (?,?,?,?)");
43 $dinsertq->execute($textid, $desc, $subject, $text);
44
45 db_commit();
46
47 </%perl><& htmlhead, subpage => "Saved \"$desc\"" &>
48 Message and configuration saved.
49 <p>
50 <form action="main" method="get">
51 <input type="submit" value="OK">
52 </form>