]> ruin.nu Git - ndwebbie.git/commitdiff
better error handling
authorMichael Andreen <harv@ruin.nu>
Fri, 15 Dec 2006 10:34:05 +0000 (10:34 +0000)
committerMichael Andreen <harv@ruin.nu>
Fri, 15 Dec 2006 10:34:05 +0000 (10:34 +0000)
13 files changed:
addintel.pl
calls.pl
defrequest.pl
editRaid.pl
index.pl
intel.pl
templates/addintel.tmpl
templates/calls.tmpl
templates/defrequest.tmpl
templates/editRaid.tmpl
templates/intel.tmpl
templates/skel.tmpl
templates/users.tmpl

index 2d023f74d85c2dd57b40606df0ad71df0638a61a..13b52a96523f12a6b90a11243db0b70d097bdb77 100644 (file)
@@ -24,30 +24,30 @@ $ND::TEMPLATE->param(TITLE => 'Add Intel and Scans');
 our $BODY;
 our $DBH;
 our $LOG;
-
-
+my $error;
 
 die "You don't have access" unless isMember();
 
 if (param('cmd') eq 'submit' || param('cmd') eq 'submit_message'){
-               my $findscan = $DBH->prepare("SELECT scan_id FROM scans WHERE scan_id = ? AND tick >= tick() - 48");
-               my $addscan = $DBH->prepare('INSERT INTO scans (scan_id,tick,"type") VALUES (?,tick(),?)');
-               my $addpoint = $DBH->prepare('UPDATE users SET scan_points = scan_points + 1 WHERE uid = ? ');
+       my $findscan = $DBH->prepare("SELECT scan_id FROM scans WHERE scan_id = ? AND tick >= tick() - 48");
+       my $addscan = $DBH->prepare('INSERT INTO scans (scan_id,tick,"type") VALUES (?,tick(),?)');
+       my $addpoint = $DBH->prepare('UPDATE users SET scan_points = scan_points + 1 WHERE uid = ? ');
        my $intel = param('intel');
        my @scans;
        while ($intel =~ m/http:\/\/game.planetarion.com\/showscan.pl\?scan_id=(\d+)/g){
                my %scan;
                $scan{Scan} = $1;
+               $scan{Message} = "Scan $1: ";
                $findscan->execute($1);
                if ($findscan->rows == 0){
                        if ($addscan->execute($1,$ND::UID)){
                                $addpoint->execute($ND::UID);
-                               $scan{Message} = '<i>added</i>';
+                               $scan{Message} .= '<i>added</i>';
                        }else{
-                               $scan{Message} = "<b>something went wrong:</b> <i>$DBH->errstr</i>";
+                               $scan{Message} .= "<b>something went wrong:</b> <i>$DBH->errstr</i>";
                        }
                }else{
-                               $scan{Message} = '<b>already exists</b>';
+                               $scan{Message} .= '<b>already exists</b>';
                }
                push @scans,\%scan;
        }
@@ -56,13 +56,16 @@ if (param('cmd') eq 'submit' || param('cmd') eq 'submit_message'){
        $tick = param('tick') if $tick =~ /^(\d+)$/;
        my $addintel = $DBH->prepare(qq{SELECT add_intel(?,?,?,?,?,?,?,?,?,?,?)});
        while ($intel =~ m/(\d+):(\d+):(\d+)\*?\s+(\d+):(\d+):(\d+)\*?\s+.+(?:Ter|Cat|Xan|Zik)?\s+(\d+)\s+(Attack|Defend)\s+(\d+)/g){
-               $addintel->execute($tick,$9, $1,$2,$3,$4,$5,$6,$7,$8,$ND::UID) or print $DBH->errstr;
+               $addintel->execute($tick,$9, $1,$2,$3,$4,$5,$6,$7,$8,$ND::UID) or $error .= $DBH->errstr;
        }
 }
 if (param('cmd') eq 'submit_message'){
        my $query = $DBH->prepare(q{INSERT INTO intel_messages (uid,message) VALUES(?,?)});
-       $query->execute($ND::UID,escapeHTML(param('intel'))) or print $DBH->errstr;
+       if($query->execute($ND::UID,escapeHTML(param('intel')))){
+               $error .= 'Intel messaged added';
+       }else{
+               $error .= $DBH->errstr;
+       }
 }
-
-
+$BODY->param(Error => $error);
 1;
index b5b4374f0b45d3b8b77b608760256905f053ec4c..b56a639e41aac5ba77e0c820baf47a43376c2bbe 100644 (file)
--- a/calls.pl
+++ b/calls.pl
@@ -22,6 +22,7 @@ use POSIX;
 our $BODY;
 our $DBH;
 our $LOG;
+my $error;
 
 $ND::TEMPLATE->param(TITLE => 'Defense Calls');
 
@@ -47,7 +48,7 @@ if ($call){
                                $call->{landing_tick} = param('tick');
                                $LOG->execute($ND::UID,"DC updated landing tick for call $call->{id}");
                        }else{
-                               print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                        }
                }
                if (param('cinfo')){
@@ -56,12 +57,12 @@ if ($call){
                                $call->{info} = param('info');
                                $LOG->execute($ND::UID,"DC updated info for call $call->{id}");
                        }else{
-                               print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                        }
                }
-               $DBH->commit or print "<p> Something went wrong: ".$DBH->errstr."</p>";
+               $DBH->commit or $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
        }elsif(param('cmd') =~ /^(Cover|Uncover|Ignore|Open|Take) call$/){
-               print "test";
+               $error .= "test";
                my $extra_vars = '';
                if (param('cmd') eq 'Cover call'){
                        $extra_vars = ", covered = TRUE, open = FALSE";
@@ -78,7 +79,7 @@ if ($call){
                        $call->{open} = (param('cmd') =~ /^(Uncover|Open) call$/);
                        $call->{DC} = $ND::USER;
                }else{
-                       print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                }
        }elsif(param('cmd') eq 'Remove'){
                $DBH->begin_work;
@@ -88,11 +89,11 @@ if ($call){
                                if($query->execute($1,$call->{id})){
                                        $LOG->execute($ND::UID,"DC deleted fleet: $1, call $call->{id}");
                                }else{
-                                       print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                                }
                        }
                }
-               $DBH->commit or print "<p> Something went wrong: ".$DBH->errstr."</p>";
+               $DBH->commit or $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
        }elsif(param('cmd') eq 'Change'){
                $DBH->begin_work;
                my $query = $DBH->prepare(q{UPDATE incomings SET shiptype = ? WHERE id = ? AND call = ?});
@@ -102,11 +103,11 @@ if ($call){
                                if($query->execute($shiptype,$1,$call->{id})){
                                        $LOG->execute($ND::UID,"DC set fleet: $1, call $call->{id} to: $shiptype");
                                }else{
-                                       print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                                }
                        }
                }
-               $DBH->commit or print "<p> Something went wrong: ".$DBH->errstr."</p>";
+               $DBH->commit or $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
        }
 }
 
@@ -184,8 +185,8 @@ FROM calls c
 WHERE $where
 GROUP BY c.id, p.x,p.y,p.z, u.username, c.landing_tick, c.info,u.defense_points
 ORDER BY c.landing_tick DESC
-               })or print $DBH->errstr;
-       $query->execute or print $DBH->errstr;
+               })or $error .= $DBH->errstr;
+       $query->execute or $error .= $DBH->errstr;
        my @calls;
        my $i = 0;
        while (my $call = $query->fetchrow_hashref){
@@ -195,4 +196,5 @@ ORDER BY c.landing_tick DESC
        }
        $BODY->param(Calls => \@calls);
 }
+$BODY->param(Error => $error);
 1;
index b1d457789cf12275e2080bbbc0dec5618a672cb5..07c68c164536bb9550c2977c1475b050f04654eb 100644 (file)
@@ -24,8 +24,7 @@ $ND::TEMPLATE->param(TITLE => 'Request Defense');
 our $BODY;
 our $DBH;
 our $LOG;
-
-
+my $error;
 
 die "You don't have access" unless isMember();
 
@@ -34,9 +33,8 @@ if (param('cmd') eq 'submit'){
        if($insert->execute($ND::UID,param('message'))){
                $BODY->param(Reply => param('message'));
        }else{
-               print "<b>".$DBH->errstr."</b>";
+               $error .= "<b>".$DBH->errstr."</b>";
        }
 }
-
-
+$BODY->param(Error => $error);
 1;
index e39e279b2dc669d91ad2defa3b0c4e8dcf209d0b..fd109320880459d6edab93e7740f5b1c3be9bae0 100644 (file)
@@ -22,6 +22,7 @@ use POSIX;
 our $BODY;
 our $DBH;
 our $LOG;
+my $error;
 
 $ND::TEMPLATE->param(TITLE => 'Create/Edit Raids');
 
@@ -42,7 +43,7 @@ if (param('cmd') eq 'submit'){
                my $query = $DBH->prepare(q{SELECT id,tick,waves,message,released_coords,open FROM raids WHERE id = ?});
                $raid = $DBH->selectrow_hashref($query,undef,$raid);
        }else{
-               print "<p> Something went wrong: ".$DBH->errstr."</p>";
+               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
        }
 }
 
@@ -74,14 +75,14 @@ if ($raid){
                $raid->{tick} = param('tick');
                unless ($DBH->do(qq{UPDATE raids SET message = ?, tick = ?, waves = ? WHERE id = ?}
                                ,undef,$message,param('tick'),param('waves'),$raid->{id})){
-                       print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                }
                my $sizelimit = '';
                if (param('sizelimit') =~ /^(\d+)$/){
                        $sizelimit = "AND p.size >= $1";
                        unless ($DBH->do(qq{DELETE FROM raid_targets WHERE id IN (SELECT t.id FROM current_planet_stats p 
        JOIN raid_targets t ON p.id = t.planet WHERE p.size < ? AND t.raid = ?)},undef,$1,$raid->{id})){
-                               print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                        }
                }
                my $targets = param('targets');
@@ -89,7 +90,7 @@ if ($raid){
        SELECT ?, id FROM current_planet_stats p WHERE x = ? AND y = ? AND COALESCE(z = ?,TRUE) $sizelimit)});
                while ($targets =~ m/(\d+):(\d+)(?::(\d+))?/g){
                        unless ($addtarget->execute($raid->{id},$1,$2,$3)){
-                               print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                        }
                }
                if (param('alliance') =~ /^(\d+)$/ && $1 != 1){
@@ -97,7 +98,7 @@ if ($raid){
                        my $addtarget = $DBH->prepare(qq{INSERT INTO raid_targets(raid,planet) (
        SELECT ?,id FROM current_planet_stats p WHERE alliance_id = ? $sizelimit)});
                        unless ($addtarget->execute($raid->{id},$1)){
-                               print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                        }
                }
                my $groups = $DBH->prepare('SELECT gid,groupname FROM groups WHERE attack');
@@ -113,19 +114,19 @@ if ($raid){
                        }
                        if ($query){
                                unless ($query->execute($raid->{id},$group->{gid})){
-                                       print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                                }
                        }
                }
                unless ($DBH->commit){
-                       print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                }
        }
        if (param('removeTarget')){
-               print "test";
+               $error .= "test";
                unless($DBH->do(q{DELETE FROM raid_targets WHERE raid = ? AND id = ?}
                                ,undef,$raid->{id},param('removeTarget'))){
-                       print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                }
        }
 }
@@ -174,7 +175,7 @@ if ($raid){
                FROM current_planet_stats p JOIN raid_targets r ON p.id = r.planet 
                WHERE r.raid = ?
                ORDER BY $order});
-       $targetquery->execute($raid->{id}) or print $DBH->errstr;
+       $targetquery->execute($raid->{id}) or $error .= $DBH->errstr;
        my @targets;
        while (my $target = $targetquery->fetchrow_hashref){
                push @targets,$target;
@@ -184,5 +185,6 @@ if ($raid){
        $BODY->param(Waves => 3);
        $BODY->param(LandingTick => $ND::TICK+12);
 }
+$BODY->param(Error => $error);
 
 1;
index 11789fa70378bfd883ab1e16ec3edf2394f42351..b41a889c5c5979cdd77fadb54977c524ceaf2542 100755 (executable)
--- a/index.pl
+++ b/index.pl
@@ -32,6 +32,7 @@ chdir $ENV{'DOCUMENT_ROOT'};
 
 our $DBH = undef;
 our $USER = $ENV{'REMOTE_USER'};
+my $error;
 
 our $TEMPLATE = HTML::Template->new(filename => 'templates/skel.tmpl');
 
@@ -81,9 +82,9 @@ if ($XML){
 
 
 unless (my $return = do "${page}.pl"){
-       print "<p><b>couldn't parse $page: $@</b></p>" if $@;
-       print "<p><b>couldn't do $page: $!</b></p>"    unless defined $return;
-       print "<p><b>couldn't run $page</b></p>"       unless $return;
+       $error .= "<p><b>couldn't parse $page: $@</b></p>" if $@;
+       $error .= "<p><b>couldn't do $page: $!</b></p>"    unless defined $return;
+       $error .= "<p><b>couldn't run $page</b></p>"       unless $return;
 }
 
 unless ($XML){
@@ -100,6 +101,7 @@ unless ($XML){
                $ND::TEMPLATE->param(Targets => listTargets());
        }
        $TEMPLATE->param(Coords => param('coords') ? param('coords') : '1:1:1');
+       $TEMPLATE->param(Error => $error);
 
 }
 $ND::TEMPLATE->param(BODY => $ND::BODY->output);
index d596957149e74e6865c09d08d7e7426dc58d5cc3..65f847a46921823807a09f90eed602c74c95f12c 100644 (file)
--- a/intel.pl
+++ b/intel.pl
@@ -22,6 +22,7 @@ use POSIX;
 our $BODY;
 our $DBH;
 our $LOG;
+my $error;
 
 $ND::TEMPLATE->param(TITLE => 'Intel');
 
@@ -73,7 +74,7 @@ if ($planet){
                                        ,undef,$value,$planet->{id})){
                                $planet->{nick} = $value;
                        }else{
-                               print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                        }
                }
                if (param('cchannel')){
@@ -82,7 +83,7 @@ if ($planet){
                                        ,undef,$value,$planet->{id})){
                                $planet->{channel} = $value;
                        }else{
-                               print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                        }
                }
                if (param('cstatus')){
@@ -91,7 +92,7 @@ if ($planet){
                                        ,undef,$value,$planet->{id})){
                                $planet->{planet_status} = $value;
                        }else{
-                               print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                        }
                }
                if (param('calliance')){
@@ -99,10 +100,10 @@ if ($planet){
                                        ,undef,param('alliance'),$planet->{id})){
                                $planet->{alliance_id} = param('alliance');
                        }else{
-                               print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                        }
                }
-               $DBH->commit or print "<p> Something went wrong: ".$DBH->errstr."</p>";
+               $DBH->commit or $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
        }
 }
 
@@ -132,7 +133,7 @@ if ($planet){
        $BODY->param(Alliances => \@alliances);
 
        my $query = $DBH->prepare(intelquery('o.alliance AS oalliance,coords(o.x,o.y,o.z) AS origin',"t.id = ? $showticks"));
-       $query->execute($planet->{id}) or print $DBH->errstr;
+       $query->execute($planet->{id}) or $error .= $DBH->errstr;
        my @intellists;
        my @intel;
        while (my $intel = $query->fetchrow_hashref){
@@ -146,7 +147,7 @@ if ($planet){
        push @intellists,{Message => 'Incoming fleets', Intel => \@intel, Origin => 1};
 
        my $query = $DBH->prepare(intelquery('t.alliance AS talliance,coords(t.x,t.y,t.z) AS target',"o.id = ? $showticks"));
-       $query->execute($planet->{id}) or print $DBH->errstr;
+       $query->execute($planet->{id}) or $error .= $DBH->errstr;
        my @intel;
        while (my $intel = $query->fetchrow_hashref){
                if ($intel->{ingal}){
@@ -166,7 +167,7 @@ if ($planet){
                                OR ( t.alliance_id = o.alliance_id AND i.mission = 'Attack'))
                        AND i.sender NOT IN (SELECT planet FROM users u NATURAL JOIN groupmembers gm WHERE gid = 8 AND planet IS NOT NULL)
                        $showticks}));
-       $query->execute() or print $DBH->errstr;
+       $query->execute() or $error .= $DBH->errstr;
 
        my @intellists;
        my @intel;
@@ -191,4 +192,5 @@ while (my $message = $query->fetchrow_hashref){
        push @messages,$message;
 }
 $BODY->param(IntelMessages => \@messages);
+$BODY->param(Error => $error);
 1;
index 5364cc7bd649d4eb2d63d224b3aa0fec9d6e466b..b30dc8f4c42fba36f23bc3631d7314e21f868263 100644 (file)
@@ -1,3 +1,4 @@
+<TMPL_VAR NAME=Error>
 <TMPL_LOOP Scans>
 <p><TMPL_VAR NAME=Scan> <TMPL_VAR NAME=Message></p>
 </TMPL_LOOP>
index 298a848fb022c4a20df09ccb08657f1aefa8e2db..da9420cd3b2bd32840a38cd1a24826446e09c3d8 100644 (file)
@@ -1,3 +1,4 @@
+<TMPL_VAR NAME=Error>
 <TMPL_IF Call>
 <form action="/index.pl" method="post"><fieldset> <legend>Call details, call# <TMPL_VAR NAME=Call></legend>
        <input type="hidden" name="page" value="calls"/>
index 10d92733f1121ecc36965e4636b4ae7978285cc3..78cbfd43048646a3ee381856154bbf984d4253f8 100644 (file)
@@ -1,3 +1,4 @@
+<TMPL_VAR NAME=Error>
 <TMPL_IF Reply><p>Sent the message '<TMPL_VAR NAME=Reply>' to def
 channel</p></TMPL_IF>
 <form action="index.pl" method="post"><fieldset> <legend>Launch confirmation</legend>
index 83dea6bdecabf04cc786b907d141565772d34921..4a656ccc43e590786377db1c304fb4d9edce89b6 100644 (file)
@@ -1,3 +1,4 @@
+<TMPL_VAR NAME=Error>
 <form action="/index.pl" method="post">
        <fieldset> <legend><TMPL_IF Raid>Edit raid<TMPL_ELSE>New raid</TMPL_IF></legend>
                <input type="hidden" name="page" value="editRaid"/>
index 4ce53c4df6b5bf335ca335a4f7479bcb7151d218..5649740aed80e3ce5cc0de243654a15601566672 100644 (file)
@@ -1,3 +1,4 @@
+<TMPL_VAR NAME=Error>
 <form action="index.pl" method="post"><p>
        <input type="text" name="coords" value="<TMPL_VAR NAME=Coords>"/>
        <input type="submit" value="Check"/>
index 4c46decf901eb73e9aaf887ff3ceced9d8c4ac0e..9c4685c7c09225cf0be12d71fa39fede6a508951 100644 (file)
@@ -64,6 +64,7 @@
                </TMPL_IF>
        <TMPL_VAR NAME=LEFTBAR>
 </div>
+<TMPL_VAR NAME=Error>
 <TMPL_VAR NAME=BODY>
 </body>
 </html>
index 391606d339008476b7c0a4de2ec5935b8a1110b5..e63f4df119b130b3d4e3f1d150064de8acddc162 100644 (file)
@@ -40,7 +40,7 @@
        </tr>
        </table>
        <TMPL_IF RemoveGroups>
-               <p>User is a member of the following groups</p>
+               <p><TMPL_VAR NAME=Username> is a member of the following groups</p>
                <table>
                        <tr><th>Group</th><th>Remove</th></tr>
                <TMPL_LOOP RemoveGroups>
@@ -49,7 +49,7 @@
                        </table>                
                </TMPL_IF>
                <TMPL_IF AddGroups>
-                       <p>These does not have access to the raid</p>
+                       <p><TMPL_VAR NAME=Username> is not a member of the following groups</p>
                        <table>
                        <tr><th>Group</th><th>Add</th></tr>
                <TMPL_LOOP AddGroups>