diff options
author | cos <cos> | 2016-07-17 20:09:33 +0200 |
---|---|---|
committer | cos <cos> | 2016-07-17 20:09:33 +0200 |
commit | 7ab3e35b073fe488315c6f9603151d2302a0261b (patch) | |
tree | 097e012d007128821a2c8069aeee748149f16345 | |
parent | f28631984cb8ea86193541c0564873182a9c79d6 (diff) | |
download | mat-7ab3e35b073fe488315c6f9603151d2302a0261b.zip |
Make code a tiny little bit more clean.
-rwxr-xr-x | cgi-bin/mat.cgi | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/cgi-bin/mat.cgi b/cgi-bin/mat.cgi index d61db32..52239d5 100755 --- a/cgi-bin/mat.cgi +++ b/cgi-bin/mat.cgi @@ -50,17 +50,18 @@ sub cmd_view($) my $db = DBI->connect($Config{'database'}, "", "", {HandleError => \&misconfigured, AutoCommit => 1}); - my $recipe_row = $db->selectrow_arrayref("SELECT name, storage, uri, ". - "amount, energy FROM recipes AS r JOIN inventory AS i ". - "ON i.recipe_id=r.id WHERE i.id=".$id.";"); - - print $id, "<br />", $$recipe_row[0], "<br />", $$recipe_row[1], "<br />"; - print ($$recipe_row[3] ? $$recipe_row[3]." g<br />" : ""), "<br />"; - print ($$recipe_row[4] ? $$recipe_row[4]." kJ<br />" : ""), "<br />"; - if(substr($$recipe_row[2], 0, 4) eq "http") { - print '<a href="'.$$recipe_row[2].'">'.$$recipe_row[2].'</a>', "<br />"; + my $portion = $db->selectrow_hashref("SELECT name, storage, uri, amount, ". + "energy FROM recipes AS r JOIN inventory AS i ON i.recipe_id=r.id ". + "WHERE i.id=".$id.";"); + + print $id, "<br />", $portion->{name}, "<br />\n"; + print $portion->{storage}, "<br />\n"; + print $portion->{amount} ? $portion->{amount}." g<br />" : "", "<br />\n"; + print $portion->{energy} ? $portion->{energy}." kJ<br />" : "", "<br />\n"; + if(substr($portion->{uri}, 0, 4) eq "http") { + print '<a href="'.$portion->{uri}.'">'.$portion->{uri}.'</a>', "<br />\n"; } else { - print $$recipe_row[2], "<br />"; + print $portion->{uri}, "<br />\n"; } if ($session->param('authenticated') eq "yes") { print "<font size=20>\n"; @@ -68,7 +69,7 @@ sub cmd_view($) print " <a href=".$Config{'label_id_prefix'}."$id/relocate/$store>". "$store</a> \n"; } - print "</font>"; + print "</font>\n"; } } @@ -90,8 +91,8 @@ misconfigured unless ($Config{'database'}); misconfigured unless $session; invalid_input unless ($id and $action); -invalid_input unless (($id =~ m/^[0-9]+$/) and ($action =~ m/^view|relocate$/) and - ($storage =~ /^[a-z0-9]*$/)); +invalid_input unless (($id =~ m/^[0-9]+$/) + and ($action =~ m/^view|relocate$/) and ($storage =~ /^[a-z0-9]*$/)); send_cookie; for ($action) { |