From 1c77410d03dd2442b7b11fb5c896bcac983219df Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 5 Sep 2012 18:21:39 +0100 Subject: [PATCH] wip --- mason/edit | 2 +- mason/save | 67 +++++++++++++++++++++++++++++++++--------------------- 2 files changed, 42 insertions(+), 27 deletions(-) diff --git a/mason/edit b/mason/edit index 6f256ef..8dddaa2 100755 --- a/mason/edit +++ b/mason/edit @@ -43,7 +43,7 @@ if (!$tx) { die "no such text $textid"; } <& htmlhead, subpage => "Edit \"$tx->{'desc'}\"" &>
<&| txtable, tx => $tx, inputs => 1 &> - diff --git a/mason/save b/mason/save index 2b96224..a34abe9 100755 --- a/mason/save +++ b/mason/save @@ -6,32 +6,47 @@ www_begin($r,$m); $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. - - -<%perl> - } - return; +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'; } } -$m->redirect("main"); - + +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. +

+

+ +
-- 2.30.2