X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=mason%2Fsave;h=a34abe970ca4bae07d15c80c4eea51b9cc927ef0;hb=1c77410d03dd2442b7b11fb5c896bcac983219df;hp=372fe355dc0d2f7f89d883dc7aa01be7f7221376;hpb=f8d5a8b102d771ac6666202db71552dfdd90bc3b;p=nj-awaymsg.git diff --git a/mason/save b/mason/save index 372fe35..a34abe9 100755 --- a/mason/save +++ b/mason/save @@ -1,34 +1,52 @@ <%init> use AwayMsg; db_connect(); +www_begin($r,$m); <%args> -$textid $save => 0 $cancel => 0 $textid => undef +$desc +$subject +$text <%perl> -if ($save) { - my $ins; - $dbh->do('BEGIN'); - if ($textid eq 'new') { - my $ntextq = $dbh->prepare("SELECT textid FROM texts". - " ORDER BY textid DESC LIMIT 1"); - $ntextq->execute(); - my $ntextrow = $ntextq->fetchrow_hashref(); - if ($ntextrow) { - $textid = $ntextrow->{'textid'} + 1; - } else { - $textid = 1; - } - } else { - my $dtextq = $dbh->prepare("DELETE FROM texts WHERE textid = ?"); - my $ndeleted = $dtextq->execute($textid); - if (!$ndeleted) { - 'Error, editing deleted message'> -Message was deleted. -
< +if (!$save) { + $m->redirect("main"); + return; +} +my $ins; + +$dbh->do('BEGIN'); +if ($textid ne 'new') { + my $dtextq = $dbh->prepare("DELETE FROM texts WHERE textid = ?"); + my $ndeleted = $dtextq->execute($textid); + if (!$ndeleted) { + $textid = 'new'; + } +} - $ins = $dbh->prepare("INSERT INTO texts VALUES ( - $sth = $dbh-> +if ($textid eq 'new') { + my $textid = time; + my $ntextq = $dbh->prepare("SELECT textid FROM texts". + " ORDER BY textid DESC LIMIT 1"); + $ntextq->execute(); + my $ntextrow = $ntextq->fetchrow_hashref(); + if ($ntextrow) { + my $mintextid = $ntextrow->{'textid'} + 1; + $textid = $mintextid if $textid < $mintextid; + } } + +my $dinsertq = $dbh->prepare("INSERT INTO texts (textid, desc, subject, text)". + " VALUES (?,?,?,?)"); +$dinsertq->execute($textid, $desc, $subject, $text); + +db_commit(); + +<& htmlhead, subpage => "Saved \"$desc\"" &> +Message and configuration saved. +

+ + +