What if you could reduce administrative complexity?

This commit is contained in:
nik gaffney 2021-08-24 19:43:29 +02:00
parent cd41aa4f2f
commit 6983ef36ed

View file

@ -1,45 +1,47 @@
#!/usr/bin/perl #!/usr/bin/perl
use Switch;
use DBI; use DBI;
use CGI qw(:cgi); use CGI qw(:cgi);
############################################################################### use feature qw(switch);
no warnings qw(experimental::smartmatch);
# configuration ##############################################################################
# #
### server # configuration #
$website_url='https://www.feraltrade.org/budget'; # #
#### local ##############################################################################
#$website_url='http://localhost';
## project
$projectname='f20 budget'; $projectname='f20 budget';
$script_name='f20_budget.pl'; $script_name='f20_budget.pl';
### server
$website_url='https://www.feraltrade.org';
$feral_logo="$website_url/budget/feral_pigeon.jpg";
### local
#$website_url='http://localhost';
$currency='€'; $currency='€';
$logo_url="$website_url/budget/logo/"; ## server
$logo_path='/home/feraltrade/htdocs/budget/logo/'; $website_url='https://www.feraltrade.org';
$arrow="$website_url/im6/arrow.jpg"; $feral_logo="$website_url/budget/feral_pigeon.jpg";
$locations_script_name='./locations.pl'; ## database connection
$agents_script_name='./agents/agents.pl';
$locations_image_url="$website_url/locn_image/thumb/";
$locations_image_path='/home/feraltrade/htdocs/budget/locn_image/thumb/';
# database connection
$db_conect="DBI:mysql:feralbudget"; $db_conect="DBI:mysql:feralbudget";
$db_user="feraltrade"; $db_user="feraltrade";
$db_pass="********"; $db_pass="********";
############################################################################### ## possibly unused
# main loop # $logo_url="$website_url/budget/logo/";
# $logo_path='/home/feraltrade/htdocs/budget/logo/';
# $arrow="$website_url/im6/arrow.jpg";
# $locations_script_name='./locations.pl';
# $agents_script_name='./agents/agents.pl';
# $locations_image_url="$website_url/locn_image/thumb/";
# $locations_image_path='/home/feraltrade/htdocs/budget/locn_image/thumb/';
##############################################################################
# #
# main CGI loop #
# #
##############################################################################
$CGI::DISABLE_UPLOADS = 0; $CGI::DISABLE_UPLOADS = 0;
$CGI::POST_MAX = '10000000'; $CGI::POST_MAX = '10000000';
@ -47,6 +49,7 @@ $CGI::POST_MAX = '10000000';
$q = new CGI; $q = new CGI;
$action=$q->param("action"); $action=$q->param("action");
$password=$q->param('password'); $password=$q->param('password');
$askpassword=$q->param('askpassword'); $askpassword=$q->param('askpassword');
@ -137,7 +140,6 @@ for ( $i=0; $i<=50; $i+=1) {
$cost{$i} = $q->param("cost$i"); $cost{$i} = $q->param("cost$i");
$new_cost{$i}=~ s/\€/@euro/g; $new_cost{$i}=~ s/\€/@euro/g;
$new_cost{$i} = $q->param("new_cost$i"); $new_cost{$i} = $q->param("new_cost$i");
$currency{$i} = $q->param("currency$i"); $currency{$i} = $q->param("currency$i");
} }
@ -157,47 +159,60 @@ $new_print_date=$q->param('new_print_year') . $q->param("new_print_month") . $q-
$new_deliver_day=$q->param("new_deliver_day"); $new_deliver_day=$q->param("new_deliver_day");
$new_deliver_date=$q->param('new_deliver_year') . $q->param("new_deliver_month") . $q->param("new_deliver_day"); $new_deliver_date=$q->param('new_deliver_year') . $q->param("new_deliver_month") . $q->param("new_deliver_day");
if ($new_name eq '') {$new_name=$new_auto_name; }
if ($new_location eq '') {$new_location=$new_auto_location; }
if ($new_remarks eq '') {$new_remarks=$new_auto_remarks; }
if ($new_url eq '') {$new_remarks=$new_auto_url; }
switch ($action) if ($new_name eq '') {
{ $new_name=$new_auto_name;
'select_budget' {&select_budget; } }
'add_form' {&add_form; } if ($new_location eq '') {
'add_budget' {&add_budget; } $new_location=$new_auto_location;
'add_budget_information' {&add_budget_information; } }
'prepare_agents' {&prepare_agents; } if ($new_remarks eq '') {
'input_agents' {&input_agents; } $new_remarks=$new_auto_remarks;
'edit_agent' {&edit_agent; } }
'update_agent' {&update_agent; } if ($new_url eq '') {
'edit_form' {&edit_form; } $new_remarks=$new_auto_url;
'edit_select_form' {&edit_select_form; } }
'edit_budget' {&edit_budget; }
'list_budgets' {&list_budgets; } given ($action) {
'prepare_budget' {&prepare_budget; } when('select_budget') {&select_budget; }
'prepare_money' {&prepare_money; } when('add_form') {&add_form; }
'input_budget' {&input_budget; } when('add_budget') {&add_budget; }
'input_money' {&input_money; } when('add_budget_information') {&add_budget_information; }
'prepare_expenditure' {&prepare_expenditure; } when('prepare_agents') {&prepare_agents; }
'input_expenditure' {&input_expenditure; } when('input_agents') {&input_agents; }
'compile_budget' {&compile_budget; } when('edit_agent') {&edit_agent; }
'display_budgets' {&display_budgets; } when('update_agent') {&update_agent; }
'present_budget' {&present_budget; } when('edit_form') {&edit_form; }
'delete_form' {&delete_form; } when('edit_select_form') {&edit_select_form; }
'delete_budget' {&delete_budget; } when('edit_budget') {&edit_budget; }
'select_budget' {&select_budget; } when('list_budgets') {&list_budgets; }
'upload_image' {&upload_image; } when('prepare_budget') {&prepare_budget; }
#else {&display_budgets; } when('prepare_money') {&prepare_money; }
else {&select_budget; } when('input_budget') {&input_budget; }
when('input_money') {&input_money; }
when('prepare_expenditure') {&prepare_expenditure; }
when('input_expenditure') {&input_expenditure; }
when('compile_budget') {&compile_budget; }
when('display_budgets') {&display_budgets; }
when('present_budget') {&present_budget; }
when('delete_form') {&delete_form; }
when('delete_budget') {&delete_budget; }
when('select_budget') {&select_budget; }
when('upload_image') {&upload_image; }
#default {&display_budgets; }
default {
&select_budget;
}
} }
exit; exit;
###############################################################################
# select budget ##############################################################################
# #
# select budget #
# #
##############################################################################
sub select_budget { sub select_budget {
@ -212,22 +227,22 @@ my $sql2 = qq( SELECT DISTINCT firstname, lastname from agents ORDER BY firstnam
my $sth2 = $dbh->prepare($sql2); my $sth2 = $dbh->prepare($sql2);
$sth2->execute; $sth2->execute;
&header; &print_header;
print "<center>\n";
print(qq(<table width="700" cellspacing="20" cellpadding="0" bgcolor="#cccccc">\n));
print "<tr><td><table width=\"700\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n";
print "<tr><td class=\"lge\" align=\"center\" bgcolor=\"#fff000\" colspan=\"5\"><font color=\"#000000\"><b>feral budget generator: enter agent </b></td></tr>\n";
print "<tr><td height=\"20\">&nbsp;</td></tr>\n";
print "<tr><td colspan=\"1\">budget:</td> ";
print "<FORM ACTION=\"$script_name\"METHOD=\"GET\">\n";
print "<input type=\"hidden\" name=\"action\" value=\"prepare_budget\">\n";
print <<END;
<center>
<table width="700" cellspacing="20" cellpadding="0" bgcolor="#cccccc">
<tr><td><table width="700" cellspacing="5" cellpadding="2" bgcolor="#ffffff" border="0">
<tr><td class="lge" align="center" bgcolor="#fff000" colspan="5"><font color="#000000">
<b>feral budget generator: enter agent </b></td></tr>
<tr><td height="20">&nbsp;</td></tr>
<tr><td colspan="1">budget:</td>
<FORM ACTION="$script_name"METHOD="GET">
<input type="hidden" name="action" value="prepare_budget">
END
## name budget ## name budget
print "<td height=\"10\" colspan=\"2\"><select name=\"new_name\">"; print "<td height=\"10\" colspan=\"2\"><select name=\"new_name\">";
while (my $record = $sth->fetchrow_hashref) { while (my $record = $sth->fetchrow_hashref) {
if ($record->{name} eq 'f20') { if ($record->{name} eq 'f20') {
@ -237,25 +252,30 @@ $sth2->execute;
print "</select></td></tr>\n"; print "</select></td></tr>\n";
## enter agent code ## enter agent code
print "<tr><td colspan=\"1\">enter your agent codename:</td> ";
print "<FORM ACTION=\"$script_name\"METHOD=\"GET\">\n";
print "<td colspan=\"3\"><input type=\"text\" name=\"new_codename\" value=\"\" size=\"5\" maxsize=\"5\"></td></tr>\n";
print "<tr><td colspan=\"2\"><INPUT TYPE=\"submit\" VALUE=\"ENTER\"></td></tr>\n";
print "</td></tr>\n";
print "</FORM>\n";
print "</td></tr></table></table>\n"; &footer;
print <<END;
<tr><td colspan="1">enter your agent codename:</td>
<FORM ACTION="$script_name"METHOD="GET">
<td colspan="3">
<input type="text" name="new_codename" value="" size="5" maxsize="5">
</td></tr>
<tr><td colspan="2">
<INPUT TYPE="submit" VALUE="ENTER"></td></tr>
</td></tr>
</FORM>
</td></tr></table></table>
END
&print_footer;
$dbh->disconnect; $dbh->disconnect;
} }
##############################################################################
############################################################################### # #
# prepare budget # prepare budget #
# #
##############################################################################
sub prepare_budget { sub prepare_budget {
@ -278,34 +298,46 @@ $sth2->execute;
my $sql3 = qq( SELECT * from finance LEFT JOIN agents ON finance.agent_id=agents.id WHERE finance.budget_id='$record->{id}' AND finance.agent_id ='$record2->{id}' ); my $sql3 = qq( SELECT * from finance LEFT JOIN agents ON finance.agent_id=agents.id WHERE finance.budget_id='$record->{id}' AND finance.agent_id ='$record2->{id}' );
my $sth3 = $dbh->prepare($sql3); my $sth3 = $dbh->prepare($sql3);
$sth3->execute; $sth3->execute;
&header;
print "<center>\n";
print "<table width=\"1000\" cellspacing=\"20\" cellpadding=\"0\" bgcolor=\"#ffffff\">\n";
print "<tr><td><table width=\"900\" cellspacing=\"1\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n";
print "<tr><td class=\"lge\" align=\"center\" bgcolor=\"#fff000\" colspan=\"5\"><font color=\"#000000\"><b>feral budget generator</b></td></tr>\n";
print "<tr><td height=\"10\" class=\"medbig\" colspan=\"5\"><b> Instructions</td></tr>";
print "<tr><td height=\"10\" class=\"\" colspan=\"2\"><td align=\"center\" valign=\"top\"><BR><img src=\"$feral_logo\"></td>\n";
print "<td><table width=\"500\" border=\"0\"<tr><td class=\"serif\">";
print "Enter your budget requests &amp; contributions. You can return to edit your entries at any time. ";
# print "MONEY<font size=\"2px\">[1]</font> will remain anonymous, RESOURCES<font size=\"2px\">[2]</font> will be linked to the resource giver when the budget is activated. ";
# print "The MONEY & RESOURCES will together serve to bankroll the $record->{name} as a whole.";
print "<BR><BR></td></tr></table>\n";
print "<tr><table width=\"1000\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\"><td colspan=\"1\">budget name:</td> "; &print_header;
print "<FORM ACTION=\"$script_name\"METHOD=\"GET\">\n";
print "<input type=\"hidden\" name=\"action\" value=\"input_budget\">\n";
print "<input type=\"hidden\" name=\"budget_id\" value=\"$record->{id}\">\n";
print "<input type=\"hidden\" name=\"agent_id\" value=\"$record2->{id}\">\n";
print "<input type=\"hidden\" name=\"new_codename\" value=\"$new_codename\">\n";
print "<td height=\"10\" colspan=\"2\" class=\"medbig\">"; print <<END;
print "<b>$record->{name}</b></td><tr>\n"; <center>
<table width="1000" cellspacing="20" cellpadding="0" bgcolor="#ffffff">
<tr><td><table width="900" cellspacing="1" cellpadding="2" bgcolor="#ffffff" border="0">
<tr><td class="lge" align="center" bgcolor="#fff000" colspan="5"><font color="#000000"><b>feral budget generator</b></td></tr>
<tr><td height="10" class="medbig" colspan="5"><b> Instructions</td></tr>
<tr><td height="10" class="" colspan="2"><td align="center" valign="top"><BR>
print "<tr><td colspan=\"1\">your name:</td> "; <img src="$feral_logo"></td>
print "<td height=\"10\" colspan=\"3\" class=\"medbig\">$record2->{firstname} $record2->{lastname}</td></tr>\n";
print "<tr><td colspan=\"1\" class=\"medbig\"><b>request money</b></td><td colspan=\"3\">your monetary requests from the f20 budget (all sums in &euro;)</td></tr>"; <td><table width="500" border="0"<tr><td class="serif">
print "</td></tr>\n"; Enter your budget requests &amp; contributions. You can return to edit your entries at any time. <BR><BR></td></tr></table>
print "<tr><td>\n";
<tr><table width="1000" cellspacing="5" cellpadding="2" bgcolor="#ffffff" border="0"><td colspan="1">budget name:</td>
<FORM ACTION="$script_name"METHOD="GET">
<input type="hidden" name="action" value="input_budget">
<input type="hidden" name="budget_id" value="$record->{id}">
<input type="hidden" name="agent_id" value="$record2->{id}">
<input type="hidden" name="new_codename" value="$new_codename">
<td height="10" colspan="2" class="medbig">
<b>$record->{name}</b></td><tr>
<tr><td colspan="1">your name:</td>
<td height="10" colspan="3" class="medbig">
$record2->{firstname} $record2->{lastname}
</td></tr>
<tr><td colspan="1" class="medbig">
<b>request money</b></td><td colspan="3">
your monetary requests from the f20 budget (all sums in &euro;)</td></tr>
</td></tr>
<tr><td>
END
my $sql4 = qq( SELECT * from expenditure where budget_id='$record->{id}' AND agent_id ='$record2->{id}' ); my $sql4 = qq( SELECT * from expenditure where budget_id='$record->{id}' AND agent_id ='$record2->{id}' );
my $sth4 = $dbh->prepare($sql4); my $sth4 = $dbh->prepare($sql4);
@ -323,7 +355,9 @@ $sth2->execute;
@cats = ('select category', 'fee', 'materials', 'misc'); @cats = ('select category', 'fee', 'materials', 'misc');
foreach $cat(@cats) { foreach $cat(@cats) {
print "<option"; print "<option";
if ($cat eq $record4->{type}) {print " selected"; } if ($cat eq $record4->{type}) {
print " selected";
}
print ">$cat</option>\n"; print ">$cat</option>\n";
} }
print "</select></td>\n"; print "</select></td>\n";
@ -343,7 +377,9 @@ $sth2->execute;
@cats = ('select category', 'fee', 'materials', 'misc'); @cats = ('select category', 'fee', 'materials', 'misc');
foreach $cat(@cats) { foreach $cat(@cats) {
print "<option"; print "<option";
if ($cat eq $record4->{type}) {print " selected"; } if ($cat eq $record4->{type}) {
print " selected";
}
print ">$cat</option>\n"; print ">$cat</option>\n";
} }
print "</select></td>\n"; print "</select></td>\n";
@ -377,7 +413,10 @@ $sth2->execute;
while (my $record5 = $sth5->fetchrow_hashref) { while (my $record5 = $sth5->fetchrow_hashref) {
print "<tr><td colspan=\"1\"><b>$i.</b></td>\n"; print "<tr><td colspan=\"1\"><b>$i.</b></td>\n";
print "<td><input type=\"checkbox\" NAME=\"new_lstatus$i\" VALUE=\"delivered\""; print "<td><input type=\"checkbox\" NAME=\"new_lstatus$i\" VALUE=\"delivered\"";
if ($record5->{status} eq 'delivered') { print "CHECKED"}; if ($record5->{status} eq 'delivered') {
print "CHECKED";
}
;
print "></td>\n"; print "></td>\n";
print "<td colspan=\"3\"><input type=\"text\" name=\"new_labour$i\" value=\"$record5->{item}\" size=\"100\" maxsize=\"200\"></td></tr>\n"; print "<td colspan=\"3\"><input type=\"text\" name=\"new_labour$i\" value=\"$record5->{item}\" size=\"100\" maxsize=\"200\"></td></tr>\n";
$i++ $i++
@ -385,7 +424,10 @@ $sth2->execute;
if ($i<=5) { if ($i<=5) {
print "<tr><td colspan=\"1\"><b>$i.</b></td>\n"; print "<tr><td colspan=\"1\"><b>$i.</b></td>\n";
print "<td><input type=\"checkbox\" NAME=\"new_lstatus$i\" VALUE=\"delivered\""; print "<td><input type=\"checkbox\" NAME=\"new_lstatus$i\" VALUE=\"delivered\"";
if ($record5->{status} eq 'delivered') { print "CHECKED"}; if ($record5->{status} eq 'delivered') {
print "CHECKED";
}
;
print "></td>\n"; print "></td>\n";
print "<td colspan=\"3\"><input type=\"text\" name=\"new_labour$i\" size=\"100\" maxsize=\"200\"></td></tr>\n"; print "<td colspan=\"3\"><input type=\"text\" name=\"new_labour$i\" size=\"100\" maxsize=\"200\"></td></tr>\n";
} }
@ -402,7 +444,10 @@ $sth2->execute;
while (my $record5 = $sth5->fetchrow_hashref) { while (my $record5 = $sth5->fetchrow_hashref) {
print "<tr><td colspan=\"1\"><b>$i.</b></td>\n"; print "<tr><td colspan=\"1\"><b>$i.</b></td>\n";
print "<td><input type=\"checkbox\" NAME=\"new_rstatus$i\" VALUE=\"delivered\""; print "<td><input type=\"checkbox\" NAME=\"new_rstatus$i\" VALUE=\"delivered\"";
if ($record5->{status} eq 'delivered') { print "CHECKED"}; if ($record5->{status} eq 'delivered') {
print "CHECKED";
}
;
print "></td>\n"; print "></td>\n";
print "<td colspan=\"3\"><input type=\"text\" name=\"new_resource$i\" value=\"$record5->{item}\" size=\"100\" maxsize=\"200\"></td></tr>\n"; print "<td colspan=\"3\"><input type=\"text\" name=\"new_resource$i\" value=\"$record5->{item}\" size=\"100\" maxsize=\"200\"></td></tr>\n";
$i++ $i++
@ -410,40 +455,36 @@ $sth2->execute;
if ($i<=5) { if ($i<=5) {
print "<tr><td colspan=\"1\"><b>$i.</b></td>\n"; print "<tr><td colspan=\"1\"><b>$i.</b></td>\n";
print "<td><input type=\"checkbox\" NAME=\"new_rstatus$i\" VALUE=\"delivered\""; print "<td><input type=\"checkbox\" NAME=\"new_rstatus$i\" VALUE=\"delivered\"";
if ($record5->{status} eq 'delivered') { print "CHECKED"}; if ($record5->{status} eq 'delivered') {
print "CHECKED";
}
print "></td>\n"; print "></td>\n";
print "<td colspan=\"3\"><input type=\"text\" name=\"new_resource$i\" size=\"100\" maxsize=\"200\"></td></tr>\n"; print "<td colspan=\"3\"><input type=\"text\" name=\"new_resource$i\" size=\"100\" maxsize=\"200\"></td></tr>\n";
} }
} }
print "<tr><td colspan=\"1\"></td><td colspan=\"1\"></td><td colspan=\"1\"><INPUT TYPE=\"submit\" VALUE=\"SUBMIT\"></td></tr>\n"; print "<tr><td colspan=\"1\"></td><td colspan=\"1\"></td><td colspan=\"1\"><INPUT TYPE=\"submit\" VALUE=\"SUBMIT\"></td></tr>\n";
print "</td></tr>\n"; print "</td></tr>\n";
print "</FORM>\n"; print "</FORM>\n";
print "<tr><td height=\"10\"></td></tr>\n"; print "<tr><td height=\"10\"></td></tr>\n";
print "<tr><td colspan=\"5\"></td><td colspan=\"3\" class=\"serif_sm\">Notes:</td></tr>\n"; print "<tr><td colspan=\"5\"></td><td colspan=\"3\" class=\"serif_sm\">Notes:</td></tr>\n";
print "</td></tr></table></table>\n"; print "</td></tr></table></table>\n";
} else { } else {
& print_header;
& header; print "codename not recognised. please retry\n";
print "codeame not recognised. please retry\n";
# }
} }
} }
&print_footer;
&footer;
$dbh->disconnect; $dbh->disconnect;
} }
##############################################################################
############################################################################### # #
# input budget: input individual budet items - money & resources # input budget: input individual budet items - money & resources #
# #
##############################################################################
sub input_budget { sub input_budget {
@ -467,7 +508,7 @@ sub input_budget {
my $dbh = DBI->connect($db_conect,$db_user,$db_pass) my $dbh = DBI->connect($db_conect,$db_user,$db_pass)
or die ("can't connect: $DBI::errstr"); or die ("can't connect: $DBI::errstr");
&header; &print_header;
print "<center>\n"; print "<center>\n";
print "<table width=\"700\" cellspacing=\"20\" cellpadding=\"0\" bgcolor=\"#ffffff\">\n"; print "<table width=\"700\" cellspacing=\"20\" cellpadding=\"0\" bgcolor=\"#ffffff\">\n";
print "<tr><td><<table width=\"700\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n"; print "<tr><td><<table width=\"700\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n";
@ -562,7 +603,6 @@ while (my $recordn = $sthn->fetchrow_hashref) {
$sth->execute; $sth->execute;
while (my $record = $sth->fetchrow_hashref) { while (my $record = $sth->fetchrow_hashref) {
print "<FORM ACTION=\"$script_name\"METHOD=\"GET\">\n"; print "<FORM ACTION=\"$script_name\"METHOD=\"GET\">\n";
print "<input type=\"hidden\" name=\"action\" value=\"prepare_budget\">\n"; print "<input type=\"hidden\" name=\"action\" value=\"prepare_budget\">\n";
print "<input type=\"hidden\" name=\"new_name\" value=\"$record->{name}\">\n"; print "<input type=\"hidden\" name=\"new_name\" value=\"$record->{name}\">\n";
@ -583,13 +623,8 @@ while (my $record = $sth->fetchrow_hashref) {
print "<tr><td colspan=\"1\"><INPUT TYPE=\"submit\" VALUE=\"go to view the budget as a whole\"></td></tr>\n"; print "<tr><td colspan=\"1\"><INPUT TYPE=\"submit\" VALUE=\"go to view the budget as a whole\"></td></tr>\n";
print "</td></tr></table>\n"; print "</td></tr></table>\n";
print "</FORM>\n"; print "</FORM>\n";
} }
&print_footer;
&footer;
# }
# }
} }
############################################################################### ###############################################################################
@ -600,7 +635,7 @@ sub input_money {
my $dbh = DBI->connect($db_conect,$db_user,$db_pass) my $dbh = DBI->connect($db_conect,$db_user,$db_pass)
or die ("can't connect: $DBI::errstr"); or die ("can't connect: $DBI::errstr");
&header; &print_header;
print "<center>\n"; print "<center>\n";
print "<table width=\"700\" cellspacing=\"20\" cellpadding=\"0\" bgcolor=\"#ffffff\">\n"; print "<table width=\"700\" cellspacing=\"20\" cellpadding=\"0\" bgcolor=\"#ffffff\">\n";
print "<tr><td><table width=\"700\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n"; print "<tr><td><table width=\"700\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n";
@ -624,7 +659,6 @@ while (my $record = $sth->fetchrow_hashref) {
} }
## input money into finance ## input money into finance
# if ($new_amount ne '') {
if ($new_amount eq '') { if ($new_amount eq '') {
$new_amount=0; $new_amount=0;
} }
@ -652,7 +686,7 @@ while (my $record = $sth->fetchrow_hashref) {
print "</td></tr></table>\n"; print "</td></tr></table>\n";
print "</FORM>\n"; print "</FORM>\n";
&footer; &print_footer;
} }
@ -743,7 +777,7 @@ sub compile_budget {
my $sthex = $dbh->prepare($sqlex); my $sthex = $dbh->prepare($sqlex);
$sthex->execute; $sthex->execute;
&header; &print_header;
print "<META HTTP-EQUIV=\"Refresh\" CONTENT=20; URL=\"$script_name\">\n"; print "<META HTTP-EQUIV=\"Refresh\" CONTENT=20; URL=\"$script_name\">\n";
print "<table width=\"1200\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"1\">\n"; print "<table width=\"1200\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"1\">\n";
@ -945,7 +979,7 @@ sub compile_budget {
$dbh->disconnect; $dbh->disconnect;
&footer; &print_footer;
} }
@ -966,7 +1000,7 @@ my $sqln = qq( SELECT name FROM budgets where id = $budget_id);
my $sthn = $dbh->prepare($sqln); my $sthn = $dbh->prepare($sqln);
$sthn->execute; $sthn->execute;
&header; &print_header;
print "<center>\n"; print "<center>\n";
print "<table width=\"700\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#ffffff\">\n"; print "<table width=\"700\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#ffffff\">\n";
print "<tr><td><table width=\"700\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n"; print "<tr><td><table width=\"700\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n";
@ -1006,7 +1040,9 @@ for ($i=1;$i<=23;$i++) {
@currencies = ('&euro;'); @currencies = ('&euro;');
foreach $currency(@currencies) { foreach $currency(@currencies) {
print "<option"; print "<option";
if ($currency eq $record->{currency}) {print " selected"; } if ($currency eq $record->{currency}) {
print " selected";
}
print ">$currency</option>\n"; print ">$currency</option>\n";
} }
print "</select></td></tr>\n"; print "</select></td></tr>\n";
@ -1022,17 +1058,16 @@ for ($i=1;$i<=23;$i++) {
@currencies = ('&euro;'); @currencies = ('&euro;');
foreach $currency(@currencies) { foreach $currency(@currencies) {
print "<option"; print "<option";
if ($currency eq $record->{currency}) {print " selected"; } if ($currency eq $record->{currency}) {
print " selected";
}
print ">$currency</option>\n"; print ">$currency</option>\n";
} }
print "</select></td></tr>\n"; print "</select></td></tr>\n";
} }
print "<tr><td><INPUT TYPE=\"submit\" VALUE=\"submit\"></td></tr>\n"; print "<tr><td><INPUT TYPE=\"submit\" VALUE=\"submit\"></td></tr>\n";
print "</FORM>\n"; print "</FORM>\n";
print "<tr><td><BR><BR></td></tr>\n"; print "<tr><td><BR><BR></td></tr>\n";
} }
@ -1063,7 +1098,8 @@ my $dbh = DBI->connect($db_conect,$db_user,$db_pass)
my $sth2 = $dbh->prepare($sql2); my $sth2 = $dbh->prepare($sql2);
$sth2->execute; $sth2->execute;
&header; &print_header;
print "<center>\n"; print "<center>\n";
print "<table width=\"700\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#ffffff\">\n"; print "<table width=\"700\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#ffffff\">\n";
print "<tr><td><table width=\"700\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n"; print "<tr><td><table width=\"700\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n";
@ -1122,9 +1158,6 @@ while (my $record = $sth->fetchrow_hashref) {
print "</html>\n"; print "</html>\n";
$dbh->disconnect; $dbh->disconnect;
} }
@ -1148,7 +1181,7 @@ my $sqln = qq( SELECT name FROM budgets where id = $budget_id);
my $sthn = $dbh->prepare($sqln); my $sthn = $dbh->prepare($sqln);
$sthn->execute; $sthn->execute;
&header; &print_header;
print "<center>\n"; print "<center>\n";
print "<table width=\"700\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#ffffff\">\n"; print "<table width=\"700\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#ffffff\">\n";
print "<tr><td><table width=\"700\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n"; print "<tr><td><table width=\"700\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n";
@ -1195,14 +1228,9 @@ while (my $recordc = $sthc->fetchrow_hashref) {
# $i++ # $i++
} }
} }
print "<tr><td><INPUT TYPE=\"submit\" VALUE=\"submit\"></td></tr>\n"; print "<tr><td><INPUT TYPE=\"submit\" VALUE=\"submit\"></td></tr>\n";
print "</FORM>\n"; print "</FORM>\n";
print "<tr><td><BR><BR></td></tr>\n"; print "<tr><td><BR><BR></td></tr>\n";
} }
@ -1216,7 +1244,7 @@ my $dbh = DBI->connect($db_conect,$db_user,$db_pass)
# read in agent data # read in agent data
&header; &print_header;
print "<center>\n"; print "<center>\n";
print "<table width=\"700\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#ffffff\">\n"; print "<table width=\"700\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#ffffff\">\n";
print "<tr><td><table width=\"700\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n"; print "<tr><td><table width=\"700\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n";
@ -1255,7 +1283,6 @@ my $dbh = DBI->connect($db_conect,$db_user,$db_pass)
print "</html>\n"; print "</html>\n";
$dbh->disconnect; $dbh->disconnect;
} }
############################################################################ ############################################################################
@ -1272,7 +1299,7 @@ my $dbh = DBI->connect($db_conect,$db_user,$db_pass)
# read back agent info # read back agent info
&header; &print_header;
print "<center>\n"; print "<center>\n";
print "<table width=\"700\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#ffffff\">\n"; print "<table width=\"700\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#ffffff\">\n";
print "<tr><td><table width=\"700\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n"; print "<tr><td><table width=\"700\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n";
@ -1294,8 +1321,6 @@ my $dbh = DBI->connect($db_conect,$db_user,$db_pass)
print "</html>\n"; print "</html>\n";
$dbh->disconnect; $dbh->disconnect;
} }
@ -1318,7 +1343,7 @@ my $dbh = DBI->connect($db_conect,$db_user,$db_pass)
# read back agent info # read back agent info
&header; &print_header;
print "<center>\n"; print "<center>\n";
print "<table width=\"700\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#ffffff\">\n"; print "<table width=\"700\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#ffffff\">\n";
print "<tr><td><table width=\"700\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n"; print "<tr><td><table width=\"700\" cellspacing=\"5\" cellpadding=\"2\" bgcolor=\"#ffffff\" border=\"0\">\n";
@ -1341,7 +1366,6 @@ my $dbh = DBI->connect($db_conect,$db_user,$db_pass)
print "</html>\n"; print "</html>\n";
$dbh->disconnect; $dbh->disconnect;
} }
############################################################################ ############################################################################
@ -1349,7 +1373,7 @@ $dbh->disconnect;
sub add_form { sub add_form {
&header; &print_header;
print "<center>\n"; print "<center>\n";
print "<b> $projectname:</b> add a budget \n"; print "<b> $projectname:</b> add a budget \n";
@ -1390,12 +1414,11 @@ print "<tr><td><br><INPUT TYPE=\"submit\" VALUE=\"add\"></td></tr>\n";
print "</FORM>\n"; print "</FORM>\n";
print "</table>\n"; print "</table>\n";
&footer; &print_footer;
$dbh->disconnect; $dbh->disconnect;
} }
###############################################################################
############################################################################### ###############################################################################
# add budget # add budget
@ -1416,7 +1439,9 @@ sub add_budget {
$sth->execute; $sth->execute;
while (my $record = $sth->fetchrow_hashref) { while (my $record = $sth->fetchrow_hashref) {
if ($record->{name} eq $new_name) {$new_name_found='true'; } if ($record->{name} eq $new_name) {
$new_name_found='true';
}
} }
if ($new_name_found eq 'false') { if ($new_name_found eq 'false') {
@ -1431,7 +1456,7 @@ sub add_budget {
$dbh->disconnect; $dbh->disconnect;
&header; &print_header;
while (my $record2 = $sth2->fetchrow_hashref) { while (my $record2 = $sth2->fetchrow_hashref) {
print "<center>\n"; print "<center>\n";
@ -1439,37 +1464,30 @@ sub add_budget {
print "<tr><td>budget added <a href=\"$script_name?action=edit_form&edit_id=$record2->{id}\">$new_name</a></td></tr>\n"; print "<tr><td>budget added <a href=\"$script_name?action=edit_form&edit_id=$record2->{id}\">$new_name</a></td></tr>\n";
print "</table>\n"; print "</table>\n";
} }
&print_footer;
&footer;
} else { } else {
&print_header;
&header;
print "duplicate budget entry<br>\n"; print "duplicate budget entry<br>\n";
&footer; &print_footer;
} }
} else { } else {
&print_header;
&header;
print "no budget entered<br>\n"; print "no budget entered<br>\n";
&footer; &print_footer;
} }
#} else { #} else {
#&header; #&print_header;
#print "<h3>Wrong password !</h3><p>\n"; #print "<h3>Wrong password !</h3><p>\n";
#&footer; #&print_footer;
# } # }
} }
############################################################################### ###############################################################################
# add budget information # add budget information
sub add_budget_information { sub add_budget_information {
@ -1482,7 +1500,7 @@ my $sth = $dbh->prepare($sql);
$sth->execute; $sth->execute;
$dbh->disconnect; $dbh->disconnect;
&header; &print_header;
print "<center>\n"; print "<center>\n";
print "<b> $projectname:</b> $new_name added "; print "<b> $projectname:</b> $new_name added ";
@ -1490,7 +1508,7 @@ print "<b> $projectname:</b> $new_name added ";
print "<p><a href=\"$script_name?action=display_budgets\">view all budgets</a></p>\n"; print "<p><a href=\"$script_name?action=display_budgets\">view all budgets</a></p>\n";
print "<p><a href=\"$script_name\"></a></p>\n"; print "<p><a href=\"$script_name\"></a></p>\n";
&footer; &print_footer;
} }
############################################################################### ###############################################################################
@ -1505,7 +1523,7 @@ my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id);
my $sth = $dbh->prepare($sql); my $sth = $dbh->prepare($sql);
$sth->execute; $sth->execute;
&header; &print_header;
print "<center>\n"; print "<center>\n";
print "<b> edit a budget <br> \n"; print "<b> edit a budget <br> \n";
@ -1523,9 +1541,7 @@ print "</table>\n";
$dbh->disconnect; $dbh->disconnect;
&footer; &print_footer;
} }
@ -1541,7 +1557,7 @@ my $sql = qq( SELECT DISTINCT * FROM budgets WHERE id=$edit_id);
my $sth = $dbh->prepare($sql); my $sth = $dbh->prepare($sql);
$sth->execute; $sth->execute;
&header; &print_header;
print "<center>\n"; print "<center>\n";
@ -1571,7 +1587,8 @@ $sth->execute;
print "</table>\n"; print "</table>\n";
} }
&footer; &print_footer;
}
############################################################################### ###############################################################################
# present budget: present singlebudget # present budget: present singlebudget
@ -1585,7 +1602,7 @@ my $sql = qq( SELECT DISTINCT * FROM budgets WHERE id=$edit_id);
my $sth = $dbh->prepare($sql); my $sth = $dbh->prepare($sql);
$sth->execute; $sth->execute;
&header; &print_header;
# print "<center>\n"; # print "<center>\n";
@ -1615,13 +1632,10 @@ $sth->execute;
print "</table>\n"; print "</table>\n";
} }
&footer; &print_footer;
} }
############################################################################### ###############################################################################
# edit budget: edit budget results # edit budget: edit budget results
@ -1632,7 +1646,7 @@ sub edit_budget {
#if ($password eq $admin_password) { #if ($password eq $admin_password) {
&header; &print_header;
### update budgets table ### update budgets table
@ -1658,7 +1672,7 @@ sub edit_budget {
} }
$dbh->disconnect; $dbh->disconnect;
&footer; &print_footer;
} }
@ -1673,7 +1687,7 @@ my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id);
my $sth = $dbh->prepare($sql); my $sth = $dbh->prepare($sql);
$sth->execute; $sth->execute;
&header; &print_header;
print "<center>\n"; print "<center>\n";
print "<b> delete a budget <br> \n"; print "<b> delete a budget <br> \n";
@ -1694,7 +1708,7 @@ print "</FORM>\n";
print "</table>\n"; print "</table>\n";
$dbh->disconnect; $dbh->disconnect;
&footer; &print_footer;
} }
############################################################################### ###############################################################################
@ -1715,13 +1729,13 @@ my $sth2 = $dbh->prepare($sql2);
while (my $record = $sth->fetchrow_hashref) { while (my $record = $sth->fetchrow_hashref) {
&header; &print_header;
print "$record->{name} deleted\n"; print "$record->{name} deleted\n";
} }
&footer; &print_footer;
$dbh->disconnect; $dbh->disconnect;
} }
@ -1737,7 +1751,7 @@ my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id);
my $sth = $dbh->prepare($sql); my $sth = $dbh->prepare($sql);
$sth->execute; $sth->execute;
&header; &print_header;
print "<center>\n"; print "<center>\n";
print "<h3> $projectname: all budgets: edit mode</h3>\n"; print "<h3> $projectname: all budgets: edit mode</h3>\n";
@ -1757,7 +1771,7 @@ while (my $record = $sth->fetchrow_hashref) {
$dbh->disconnect; $dbh->disconnect;
print"</table>\n"; print"</table>\n";
&footer; &print_footer;
} }
@ -1772,7 +1786,7 @@ my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id);
my $sth = $dbh->prepare($sql); my $sth = $dbh->prepare($sql);
$sth->execute; $sth->execute;
&header; &print_header;
print "<center>\n"; print "<center>\n";
print "<h3> $projectname: all budgets: read-only</h3>\n"; print "<h3> $projectname: all budgets: read-only</h3>\n";
@ -1792,7 +1806,7 @@ while (my $record = $sth->fetchrow_hashref) {
$dbh->disconnect; $dbh->disconnect;
print"</table>\n"; print"</table>\n";
&footer; &print_footer;
} }
############################################################################################## ##############################################################################################
@ -1805,14 +1819,22 @@ sub select_start_date {
print "<td colspan=\"2\"><select name=\"new_start_day\">\n"; print "<td colspan=\"2\"><select name=\"new_start_day\">\n";
for ( $i=1; $i<10; $i+=1) { for ( $i=1; $i<10; $i+=1) {
print "<option"; print "<option";
if ($new_start_day eq "0$i") {print " selected"; } if ($new_start_day eq "0$i") {
if (($new_start_day eq "") && ($currentdayofmonth eq $i)) {print " selected"; } print " selected";
}
if (($new_start_day eq "") && ($currentdayofmonth eq $i)) {
print " selected";
}
print ">0$i</option>\n"; print ">0$i</option>\n";
} }
for ( $i=10; $i<32; $i+=1) { for ( $i=10; $i<32; $i+=1) {
print "<option"; print "<option";
if ($new_start_day eq $i) {print " selected"; } if ($new_start_day eq $i) {
if (($new_start_day eq "") && ($currentdayofmonth eq $i)) {print " selected"; } print " selected";
}
if (($new_start_day eq "") && ($currentdayofmonth eq $i)) {
print " selected";
}
print ">$i</option>\n"; print ">$i</option>\n";
} }
print "</select>\n"; print "</select>\n";
@ -1821,14 +1843,22 @@ print "</select>\n";
print "<select name=\"new_start_month\">\n"; print "<select name=\"new_start_month\">\n";
for ( $j=1; $j<10; $j+=1) { for ( $j=1; $j<10; $j+=1) {
print "<option"; print "<option";
if ($new_start_month eq "0$j") {print " selected"; } if ($new_start_month eq "0$j") {
if (($new_start_month eq "") && ($currentmonth eq $j)) {print " selected"; } print " selected";
}
if (($new_start_month eq "") && ($currentmonth eq $j)) {
print " selected";
}
print ">0$j</option>\n"; print ">0$j</option>\n";
} }
for ( $j=10; $j<13; $j+=1) { for ( $j=10; $j<13; $j+=1) {
print "<option"; print "<option";
if ($new_start_month eq $j) {print " selected"; } if ($new_start_month eq $j) {
if (($new_start_month eq "") && ($currentmonth eq $j)) {print " selected"; } print " selected";
}
if (($new_start_month eq "") && ($currentmonth eq $j)) {
print " selected";
}
print ">$j</option>\n"; print ">$j</option>\n";
} }
print "</select>\n"; print "</select>\n";
@ -1837,27 +1867,28 @@ print "</select>\n";
print "<select name=\"new_start_year\">\n"; print "<select name=\"new_start_year\">\n";
for ( $j=2003; $j<2022; $j+=1) { for ( $j=2003; $j<2022; $j+=1) {
print "<option"; print "<option";
if ($new_start_year eq $j) {print " selected"; } if ($new_start_year eq $j) {
if (($new_start_year eq "") && ($currentyear eq $j)) {print " selected"; } print " selected";
}
if (($new_start_year eq "") && ($currentyear eq $j)) {
print " selected";
}
print ">$j</option>\n"; print ">$j</option>\n";
} }
print "</select></td></tr>\n"; print "</select></td></tr>\n";
} }
############################################################################### ###############################################################################
# print_header subroutine
# header subroutine sub print_header {
sub header {
print <<END; print <<END;
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width"> <meta name="viewport" content="width=device-width">
<title>feral budget generator</title> <title>feral budget generator</title>
<link rel="stylesheet" href="css/styles.css"> <link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="css/print.css" media="print"> <link rel="stylesheet" href="css/print.css" media="print">
</head> </head>
@ -1865,9 +1896,9 @@ END
} }
############################################################################### ###############################################################################
# footer subroutine # print_footer subroutine
sub footer { sub print_footer {
print <<END; print <<END;
</body> </body>
</html> </html>
@ -1889,6 +1920,3 @@ print "</body>\n";
print "</html>\n"; print "</html>\n";
} }
}