From 6983ef36edc1a2bdb37c51b6c6e7ca6c1dd07613 Mon Sep 17 00:00:00 2001 From: nik gaffney Date: Tue, 24 Aug 2021 19:43:29 +0200 Subject: [PATCH] What if you could reduce administrative complexity? --- f20-budget.pl | 3816 +++++++++++++++++++++++++------------------------ 1 file changed, 1922 insertions(+), 1894 deletions(-) diff --git a/f20-budget.pl b/f20-budget.pl index 63b45a8..0a5080f 100644 --- a/f20-budget.pl +++ b/f20-budget.pl @@ -1,1894 +1,1922 @@ -#!/usr/bin/perl - -use Switch; -use DBI; -use CGI qw(:cgi); - -############################################################################### - -# configuration - -### server -$website_url='https://www.feraltrade.org/budget'; -#### local -#$website_url='http://localhost'; - -$projectname='f20 budget'; -$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='€'; - -$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/'; - -# database connection -$db_conect="DBI:mysql:feralbudget"; -$db_user="feraltrade"; -$db_pass="********"; - -############################################################################### -# main loop - -$CGI::DISABLE_UPLOADS = 0; -$CGI::POST_MAX = '10000000'; - -$q = new CGI; - -$action=$q->param("action"); -$password=$q->param('password'); -$askpassword=$q->param('askpassword'); - -$delete_id=$q->param("delete_id"); -$edit_id=$q->param("edit_id"); -$budget_id=$q->param("budget_id"); -$agent_id=$q->param("agent_id"); -$edit_agent_id=$q->param("edit_agent_id"); - -$new_auto_name=$q->param('new_auto_name'); -$new_auto_name =~ s/\'/\'\'/g; -$new_auto_location=$q->param('new_auto_location'); -$new_auto_location =~ s/\'/\'\'/g; -$new_auto_remarks=$q->param('new_auto_remarks'); -$new_auto_remarks =~ s/\'/\'\'/g; -$new_auto_url=$q->param('new_auto_url'); -$new_auto_url =~ s/\'/\'\'/g; - -$new_name=$q->param('new_name'); -$new_name =~ s/\'/\'\'/g; -$new_codename=$q->param('new_codename'); -$new_codename =~ s/\'/\'\'/g; -$new_pseudo=$q->param('new_pseudo'); -$new_pseudo =~ s/\'/\'\'/g; -$new_firstname=$q->param('new_firstname'); -$new_firstname =~ s/\'/\'\'/g; -$new_lastname=$q->param('new_lastname'); -$new_lastname =~ s/\'/\'\'/g; -$new_lastname=$q->param('new_lastname'); -$new_fullname =~ s/\'/\'\'/g; -$new_fullname=$q->param('new_fullname'); - -$new_agent=$q->param('new_agent'); -$new_location=$q->param('new_location'); -$new_location =~ s/\'/\'\'/g; -$new_remarks=$q->param('new_remarks'); -$new_remarks =~ s/\'/\'\'/g; -$new_url=$q->param('new_url'); -$new_url =~ s/\'/\'\'/g; - -$new_amount=$q->param('new_amount'); -$new_amount = sprintf "%.2f",$new_amount; ## 2 decimal places - -$new_url=$q->param("new_url"); -#$new_url=~ s/http\:\/\///g; # don't remove http:// - -$new_item = $q->param("new_item"); -$new_item =~ s/\'/\'\'/g; -$new_item =~ s/\x92/’/g; -$new_labour = $q->param("new_labour"); -$new_labour =~ s/\'/\'\'/g; -$new_labour =~ s/\x92/’/g; -$new_resource = $q->param("new_resource"); -$new_resource =~ s/\'/\'\'/g; -$new_resource =~ s/\x92/’/g; -$new_status = $q->param("new_status"); -$new_lstatus = $q->param("new_lstatus"); -$new_rstatus = $q->param("new_rstatus"); -$type = $q->param("type"); - -for ( $i=0; $i<=50; $i+=1) { - $new_status{$i} = $q->param("new_status$i"); - $type{$i} = $q->param("type$i"); - $new_item{$i} = $q->param("new_item$i"); - $new_item{$i} =~ s/\'/\'\'/g; - $new_item{$i} =~ s/\x92/’/g; - $new_resource{$i} = $q->param("new_resource$i"); - $new_resource{$i} =~ s/\'/\'\'/g; - $new_resource{$i} =~ s/\x92/’/g; - $new_labour{$i} = $q->param("new_labour$i"); - $new_labour{$i} =~ s/\'/\'\'/g; - $new_labour{$i} =~ s/\x92/’/g; - $new_status{$i} = $q->param("new_status$i"); - $new_lstatus{$i} = $q->param("new_lstatus$i"); - $new_rstatus{$i} = $q->param("new_rstatus$i"); - - $new_firstname{$i} = $q->param("new_firstname$i"); - $new_firstname{$i} =~ s/\'/\'\'/g; - $new_firstname{$i} =~ s/\x92/’/g; - $new_lastname{$i} = $q->param("new_lastname$i"); - $new_lastname{$i} =~ s/\'/\'\'/g; - $new_lastname{$i} =~ s/\x92/’/g; - $new_codename{$i} = $q->param("new_codename$i"); - $new_codename{$i} =~ s/\'/\'\'/g; - $new_codename{$i} =~ s/\x92/’/g; - - $cost{$i}=~ s/\€/@euro/g; - $cost{$i} = $q->param("cost$i"); - $new_cost{$i}=~ s/\€/@euro/g; - $new_cost{$i} = $q->param("new_cost$i"); - - $currency{$i} = $q->param("currency$i"); - } - - -($second, $minute, $hour, $currentdayofmonth, $month, $year, $weekday, $dayofyear, $IsDST) = localtime(time); -$currentmonth=$month+1; -$currentyear=$year+'1900'; - -$new_day=$q->param("'new_day"); -$new_month=$q->param("new_month"); -$new_year=$q->param("new_year"); - -$new_date=$q->param('new_year') . $q->param("new_month") . $q->param("new_day"); -$new_start_date=$q->param('new_start_year') . $q->param("new_start_month") . $q->param("new_start_day"); -$new_end_date=$q->param('new_end_year') . $q->param("new_end_month") . $q->param("new_end_day"); -$new_print_date=$q->param('new_print_year') . $q->param("new_print_month") . $q->param("new_print_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"); - -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) -{ - 'select_budget' {&select_budget; } - 'add_form' {&add_form; } - 'add_budget' {&add_budget; } - 'add_budget_information' {&add_budget_information; } - 'prepare_agents' {&prepare_agents; } - 'input_agents' {&input_agents; } - 'edit_agent' {&edit_agent; } - 'update_agent' {&update_agent; } - 'edit_form' {&edit_form; } - 'edit_select_form' {&edit_select_form; } - 'edit_budget' {&edit_budget; } - 'list_budgets' {&list_budgets; } - 'prepare_budget' {&prepare_budget; } - 'prepare_money' {&prepare_money; } - 'input_budget' {&input_budget; } - 'input_money' {&input_money; } - 'prepare_expenditure' {&prepare_expenditure; } - 'input_expenditure' {&input_expenditure; } - 'compile_budget' {&compile_budget; } - 'display_budgets' {&display_budgets; } - 'present_budget' {&present_budget; } - 'delete_form' {&delete_form; } - 'delete_budget' {&delete_budget; } - 'select_budget' {&select_budget; } - 'upload_image' {&upload_image; } - #else {&display_budgets; } - else {&select_budget; } -} - -exit; - -############################################################################### - -# select budget - -sub select_budget { - -my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - -my $sql = qq( SELECT DISTINCT name from budgets ORDER BY id DESC); -my $sth = $dbh->prepare($sql); -$sth->execute; - -my $sql2 = qq( SELECT DISTINCT firstname, lastname from agents ORDER BY firstname); -my $sth2 = $dbh->prepare($sql2); -$sth2->execute; - - &header; - - print "
\n"; - - print(qq(\n)); - - print "
\n"; - print "\n"; - print "\n"; - print " "; - print "\n"; - - print "\n"; - - -## name budget - print "\n"; - -## enter agent code - print " "; - print "\n"; - print "\n"; - - - print "\n"; - print "\n"; - print "\n"; - -print "
feral budget generator: enter agent
 
budget:
enter your agent codename:
\n"; &footer; - -$dbh->disconnect; - -} - - - -############################################################################### -# prepare budget - -sub prepare_budget { - -my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - -my $sql = qq( SELECT * from budgets WHERE name="$new_name" ); -my $sth = $dbh->prepare($sql); -$sth->execute; - -## identify agent by codename -my $sql2 = qq( SELECT * from agents where codename ="$new_codename" ); -my $sth2 = $dbh->prepare($sql2); -$sth2->execute; - - while (my $record = $sth->fetchrow_hashref) { - if (my $record2 = $sth2->fetchrow_hashref) { -# while (my $record2 = $sth2->fetchrow_hashref) { -# if ($record2->{codename} ne '') { - 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); - $sth3->execute; - &header; - print "
\n"; - print "\n"; - print "
\n"; - print "\n"; - print ""; - print "\n"; - print "
feral budget generator
Instructions

"; - print "Enter your budget requests & contributions. You can return to edit your entries at any time. "; -# print "MONEY[1] will remain anonymous, RESOURCES[2] 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 "

\n"; - - print "
"; - print "\n"; - print "\n"; - print "{id}\">\n"; - print "{id}\">\n"; - print "\n"; - - print "\n"; - - print " "; - print "\n"; - print ""; - print "\n"; - print "\n"; - - print "\n"; - print "\n"; - - print "\n"; - $i++ - } - - if ($i<=5) { - - print "\n"; - - print "\n"; - - print "\n"; - print "\n"; - } - } - - print "
budget name:
"; - print "$record->{name}
your name:$record2->{firstname} $record2->{lastname}
request moneyyour monetary requests from the f20 budget (all sums in €)
\n"; - - my $sql4 = qq( SELECT * from expenditure where budget_id='$record->{id}' AND agent_id ='$record2->{id}' ); - my $sth4 = $dbh->prepare($sql4); - $sth4->execute; - - for ($i=1;$i<=5;$i++) { - while (my $record4 = $sth4->fetchrow_hashref) { - print "
$i. \n"; - print "$currency"; - print "{cost}\" "; - print " size=\"2\" maxsize=\"5\">item {item}\" size=\"70\" maxsize=\"100\">
$i. \n"; - print "€ item {item}\" size=\"70\" maxsize=\"100\">
\n"; - - print "
"; - print ""; - print "\n"; - - -## resources section !!! read-in notworking !!! - - print "\n"; - print ""; - - my $sql5 = qq( SELECT * from nonfinance where budget_id=$record->{id} AND agent_id =$record2->{id} AND kind='labour' ); - my $sth5 = $dbh->prepare($sql5); - $sth5->execute; - - for ($i=1;$i<=8;$i++) { - while (my $record5 = $sth5->fetchrow_hashref) { - print "\n"; - print "\n"; - print "\n"; - $i++ - } - if ($i<=5) { - print "\n"; - print "\n"; - print "\n"; - } - } - - print "\n"; - print ""; - - my $sql5 = qq( SELECT * from nonfinance where budget_id=$record->{id} AND agent_id =$record2->{id} AND kind='resources' ); - my $sth5 = $dbh->prepare($sql5); - $sth5->execute; - - for ($i=1;$i<=8;$i++) { - while (my $record5 = $sth5->fetchrow_hashref) { - print "\n"; - print "\n"; - print "\n"; - $i++ - } - if ($i<=5) { - print "\n"; - print "\n"; - print "\n"; - } - } - - - print "\n"; - print "\n"; - print "\n"; - - print "\n"; - print "\n"; - - print "
input moneyyour monetary contribution to the budget (direct payments for materials/services, donations to f20, as a sum total)
fetchrow_hashref) { - print "value=\"$record3->{amount}\" "; - } - print " size=\"3\" maxsize=\"5\">
 
input labourthings you commit to doing, non-remunerated. (check the box if this labour has already been deployed)
$i.{status} eq 'delivered') { print "CHECKED"}; - print ">{item}\" size=\"100\" maxsize=\"200\">
$i.{status} eq 'delivered') { print "CHECKED"}; - print ">
 
input resourcesmaterials, spaces, tools, previous work etc (check the box if your resource has already been deployed)
$i.{status} eq 'delivered') { print "CHECKED"}; - print ">{item}\" size=\"100\" maxsize=\"200\">
$i.{status} eq 'delivered') { print "CHECKED"}; - print ">
Notes:
\n"; - - } else { - - & header; - print "codeame not recognised. please retry\n"; -# } - } -} - -&footer; - -$dbh->disconnect; - -} - - - -############################################################################### -# input budget: input individual budet items - money & resources - -sub input_budget { - -#for ($i=1; $i<=8; $i++) { -# if (('$type{$i}' eq 'select category') && ('$new_item{$i}' ne '')) { - -# print "
\n"; -# print "\n"; -# print "\n"; -# print "\n"; -# print "{name}\">\n"; -# print "\n"; -# print "\n"; -# print "{fullname}\">\n"; -# print "{codename}\">\n"; -# print "\n"; -# print "\n"; - -#} else { - - my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - -&header; -print "
\n"; -print "
\n"; -print "
<\n"; - -## delete expenditure line for agent + budget, if exists - my $sqld = qq( DELETE from expenditure where budget_id="$budget_id" AND agent_id="$agent_id"); - my $sthd= $dbh->prepare($sqld); - $sthd->execute; - -## input new expenditure lines for agent - - for ($i=1; $i<=8; $i++) { - if ($new_item{$i} ne '') { - my $sql = (qq{INSERT INTO expenditure (budget_id, agent_id, status, type, item, cost, currency) VALUES ($budget_id, $agent_id, '$new_status{$i}', '$type{$i}', '$new_item{$i}', $new_cost{$i}, '€')}); - my $sth = $dbh->prepare($sql); - $sth->execute; - } - } - - -## read in finance for agent - -my $sql = qq( SELECT * from finance LEFT JOIN agents ON finance.agent_id=agents.id - LEFT JOIN budgets ON finance.budget_id = budgets.id WHERE finance.budget_id="$budget_id" AND finance.agent_id="$agent_id"); -my $sth = $dbh->prepare($sql); -$sth->execute; - -#while (my $record = $sth->fetchrow_hashref) { - print "\n"; - -## delete finance line for agent + budget, if exists - my $sqld = qq( DELETE from finance where budget_id="$budget_id" AND agent_id="$agent_id"); - my $sthd= $dbh->prepare($sqld); - $sthd->execute; - -## input money into finance -# if ($new_amount ne '') { - if ($new_amount eq '') { - $new_amount=0; - } - my $sqli = (qq{INSERT INTO finance (budget_id, agent_id, amount) VALUES ($budget_id, $agent_id, $new_amount)}); - my $sthi = $dbh->prepare($sqli); - $sthi->execute; - - my $sqld = qq( DELETE from nonfinance where budget_id="$budget_id" AND agent_id="$agent_id"); - my $sthd= $dbh->prepare($sqld); - $sthd->execute; - -## input labour into nonfinance for agent - - for ($i=1; $i<=8; $i++) { - if ($new_labour{$i} ne '') { - my $sqll = (qq{INSERT INTO nonfinance (budget_id, agent_id, item, kind, status) VALUES ($budget_id, $agent_id, "$new_labour{$i}", "labour", "$new_lstatus{$i}")}); - my $sthl = $dbh->prepare($sqll); - $sthl->execute; - } - } - -## input resources into nonfinance for agent - for ($i=1; $i<=8; $i++) { - if ($new_resource{$i} ne '') { - my $sqlr = (qq{INSERT INTO nonfinance (budget_id, agent_id, item, kind, status) VALUES ($budget_id, $agent_id, "$new_resource{$i}", "resources", "$new_rstatus{$i}")}); - my $sthr = $dbh->prepare($sqlr); - $sthr->execute; - } - } - -## read back in to get these values from the db, not from the cgi - - my $sqlv = (qq{SELECT DISTINCT item, cost, expenditure.currency, type, fullname from expenditure RIGHT JOIN agents on expenditure.agent_id=agents.id LEFT JOIN finance on expenditure.agent_id=finance.agent_id - WHERE expenditure.agent_id=$agent_id AND expenditure.budget_id=$budget_id}); - my $sthv = $dbh->prepare($sqlv); - $sthv->execute; -my $sqln = (qq{ SELECT fullname from agents where id=$agent_id}); -my $sthn = $dbh->prepare($sqln); -$sthn->execute; - -while (my $recordn = $sthn->fetchrow_hashref) { - print " "; - } - -# print "\n"; - } - } - - print "\n"; - print "\n"; - -$sth->execute; -while (my $record = $sth->fetchrow_hashref) { - - - print "\n"; - print "\n"; - print "{name}\">\n"; - print "\n"; - print "\n"; - print "{fullname}\">\n"; - print "{codename}\">\n"; - print "\n"; - print "\n"; - - print "\n"; - print "\n"; - print "{name}\">\n"; - print "\n"; - print "\n"; - print "{fullname}\">\n"; - print "{codename}\">\n"; - print "\n"; - print "
feral budget generator: $record->{name}
$projectname: $recordn->{fullname}
your PROPOSITION: "; - while (my $recordv = $sthv->fetchrow_hashref) { - if ($recordv->{item} ne '') { - print "
$recordv->{$currency} $recordv->{$cost} $recordv->{$item} $recordv->{$type}
\n"; - print "\n"; - - - } - - &footer; -# } -# } -} - -############################################################################### -# input money - -sub input_money { - - my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - -&header; -print "
\n"; -print "\n"; -print "
\n"; - - -## read in finance for agent+ budget - -my $sql = qq( SELECT * from finance LEFT JOIN agents ON finance.agent_id=agents.id - LEFT JOIN budgets ON finance.budget_id = budgets.id WHERE finance.budget_id="$budget_id" AND finance.agent_id="$agent_id"); -my $sth = $dbh->prepare($sql); -$sth->execute; - -while (my $record = $sth->fetchrow_hashref) { - if ($record->{id} ne '') { - -## delete finance line for agent + budget, if exists - my $sqld = qq( DELETE from finance where budget_id="$budget_id" AND agent_id="$agent_id"); - my $sthd= $dbh->prepare($sqld); - $sthd->execute; - } - } - -## input money into finance -# if ($new_amount ne '') { - if ($new_amount eq '') { - $new_amount=0; - } - my $sqli = (qq{INSERT INTO finance (budget_id, agent_id, amount) VALUES ($budget_id, $agent_id, $new_amount)}); - my $sthi = $dbh->prepare($sqli); - $sthi->execute; -#} - print "\n"; - print " "; - print "\n"; - print "\n"; - - print " "; - print "\n"; - print "\n"; - - print "\n"; - print "\n"; - print "{name}\">\n"; - print "\n"; - print "\n"; - print "{fullname}\">\n"; - print "{codename}\">\n"; - print "\n"; - print "
feral budget generator: $record->{name}
your name:$new_fullname
your monetary contribution:€$new_amount
\n"; - print "\n"; - - &footer; - -} - - -############################################################################### -# compile budget: lay out the whole budget as it assembles - -sub compile_budget { - - my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - - my $sqld = qq( SELECT * FROM nonfinance LEFT JOIN agents on nonfinance.agent_id=agents.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id - LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id AND nonfinance.status='delivered' ORDER BY nonfinance.item); - my $sthd = $dbh->prepare($sqld); - $sthd->execute; - - my $sqlol = qq( SELECT * FROM nonfinance LEFT JOIN agents on nonfinance.agent_id=agents.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id - LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id AND nonfinance.status!='delivered' AND kind='labour' ORDER BY nonfinance.item); - my $sthol = $dbh->prepare($sqlol); - $sthol->execute; - - my $sqlor = qq( SELECT * FROM nonfinance LEFT JOIN agents on nonfinance.agent_id=agents.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id - LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id AND nonfinance.status!='delivered' AND kind='resources' ORDER BY nonfinance.item); - my $sthor = $dbh->prepare($sqlor); - $sthor->execute; - - my $sqldl = qq( SELECT * FROM nonfinance LEFT JOIN agents on nonfinance.agent_id=agents.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id - LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id AND nonfinance.status='delivered' AND kind='labour' ORDER BY nonfinance.item); - my $sthdl = $dbh->prepare($sqldl); - $sthdl->execute; - - my $sqldr = qq( SELECT * FROM nonfinance LEFT JOIN agents on nonfinance.agent_id=agents.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id - LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id AND nonfinance.status='delivered' AND kind='resources' ORDER BY nonfinance.item); - my $sthdr = $dbh->prepare($sqldr); - $sthdr->execute; - - -## count potential deposits - my $sqla = qq( SELECT COUNT(fullname) AS qty FROM agents WHERE budget_id=$budget_id AND status!='staff'); - my $stha = $dbh->prepare($sqla); - $stha->execute; - -## count deposits received - my $sqlar = qq( SELECT COUNT(fullname) AS qty FROM agents WHERE budget_id=$budget_id AND status='deposit'); - my $sthar = $dbh->prepare($sqlar); - $sthar->execute; - - my $sqlc = qq( SELECT COUNT(*) FROM nonfinance LEFT JOIN agents on nonfinance.agent_id=agent.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id - LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id); - my $sthc = $dbh->prepare($sqlc); - $sthc->execute; - - my $sqlf = qq( SELECT * FROM finance WHERE budget_id=$budget_id ORDER by amount); - my $sthf = $dbh->prepare($sqlf); - $sthf->execute; - - my $sqlb = qq( SELECT *, date_format(deliver_date,'%d-%m-%Y') AS end_date FROM budgets LEFT JOIN locations on budgets.location=locations.structure WHERE budgets.id=$budget_id); - my $sthb = $dbh->prepare($sqlb); - $sthb->execute; - - my $sqlfc = qq( SELECT COUNT(id) AS count FROM finance WHERE budget_id=$budget_id); - my $sthfc = $dbh->prepare($sqlfc); - $sthfc->execute; - - my $sqls = qq( SELECT SUM(amount) FROM finance WHERE budget_id=$budget_id); - my $sths = $dbh->prepare($sqls); - $sths->execute; - - my $sqlse = qq( SELECT SUM(cost) FROM expenditure WHERE budget_id=$budget_id); - my $sthse = $dbh->prepare($sqlse); - $sthse->execute; - - my $sqlr = qq( SELECT name, fullname, codename from finance LEFT JOIN agents ON finance.agent_id=agents.id - LEFT JOIN budgets ON finance.budget_id = budgets.id WHERE finance.budget_id="$budget_id" AND finance.agent_id="$agent_id"); - my $sthr = $dbh->prepare($sqlr); - $sthr->execute; - - my $sqlef = qq( SELECT budget_id, item, cost, currency, type FROM expenditure LEFT JOIN budgets on expenditure.budget_id=budgets.id WHERE expenditure.budget_id = '$budget_id' AND type='fee' ORDER BY expenditure.item); - my $sthef = $dbh->prepare($sqlef); - $sthef->execute; - - my $sqlem = qq( SELECT budget_id, item, cost, currency, type FROM expenditure LEFT JOIN budgets on expenditure.budget_id=budgets.id WHERE expenditure.budget_id = '$budget_id' AND type='materials' ORDER BY expenditure.item); - my $sthem = $dbh->prepare($sqlem); - $sthem->execute; - - my $sqlex = qq( SELECT budget_id, item, cost, currency, type FROM expenditure LEFT JOIN budgets on expenditure.budget_id=budgets.id WHERE expenditure.budget_id = '$budget_id' AND type='misc' ORDER BY expenditure.item); - my $sthex = $dbh->prepare($sqlex); - $sthex->execute; - - &header; - - print "\n"; - print "\n"; - print "\n"; - - print "
\n"; - print "
feral budget generator     | |     https://feraltrade.org/cgi-bin/budget/f20_budget.pl
\n"; -# print "
\n"; - - $sthb->execute; - while (my $recordb = $sthb->fetchrow_hashref) { - print "
\n"; - print "
$projectname    | | $recordb->{location}    "; - - print "   | | budget adjustments to $currentdayofmonth/$currentmonth/$currentyear
"; - -# print "   | | Budget"; - while (my $recordd = $sthd->fetchrow_hashref) { - $title = substr($recordd->{item}, 0, 30) ; -# print ": $title "; - } -# print "
"; - - print "\n"; - print "\n"; - - print "\n\n"; - } - - $sthr->execute; - while (my $recordr = $sthr->fetchrow_hashref) { - - print "\n"; - - print "\n"; - print "{name}\">\n"; - print "\n"; - print "\n"; - print "{fullname}\">\n"; - print "{codename}\">\n"; - print "\n"; - print "\n\n"; - } - - if ($agent_id eq "") { - print "\n"; - print "\n"; - print "{name}\">\n"; - print "\n"; - print "\n"; - print "\n"; - print "

\n\n"; - - } else { - print "\n"; - print "\n"; - print "{name}\">\n"; - print "\n"; - print "\n"; - - print "\n"; - print "

\n\n"; - } - - print "
\n"; - if ($agent_id ne "") { - while (my $recordfc = $sthfc->fetchrow_hashref) { - print " Contributing agents [$recordfc->{count}]. This budget will remain open for negotiations until $recordb->{end_date}.\n"; - print " Monetary items will be kept anonymous (although visible to the budget r/administrators) labour & resources will be tagged with the ID of the resourcer.\n"; - } - } - print "

\n"; - print "\n\n"; - - print "\n"; - -$dbh->disconnect; - -&footer; - -} - - -############################################################################ -# prepare expenditure - -sub prepare_expenditure { - -my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - -my $sql = qq( SELECT item, cost, currency, firstname, lastname, type FROM expenditure LEFT JOIN agents on expenditure.agent_id = agents.id WHERE expenditure.budget_id = $budget_id ORDER BY fullname); -my $sth = $dbh->prepare($sql); -$sth->execute; - -my $sqln = qq( SELECT name FROM budgets where id = $budget_id); -my $sthn = $dbh->prepare($sqln); -$sthn->execute; - -&header; -print "
\n"; -print "
"; - - print "\n"; - print "\n"; - - - print "\n"; - while (my $recordef = $sthef->fetchrow_hashref) { - my $cost = $recordef->{cost}; - $display_cost = sprintf "%.2f",$cost; - $display_cost =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma - print " \n"; - } - - print "\n"; - while (my $recordem = $sthem->fetchrow_hashref) { - my $cost = $recordem->{cost}; - $display_cost = sprintf "%.2f",$cost; - $display_cost =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma - print " \n"; - } - - print "\n"; - while (my $recordex = $sthex->fetchrow_hashref) { - my $cost = $recordex->{cost}; - $display_cost = sprintf "%.2f",$cost; - $display_cost =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma - print " \n"; - } - - - print "\n"; - print "\n"; -# print "\n"; - print "\n"; - while(my @sum = $sths->fetchrow_array()) { - $deposits = $recordar->{qty}*50; - $running = $sum[0]+$deposits; - $display_running = sprintf "%.2f",$running; - $display_running =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma - print "\n"; - } - } - - while (my @sumex = $sthse->fetchrow_array()) { - $runningex = $sumex[0]; - $surplus = $running - $runningex; - $display_runningex = sprintf "%.2f",$runningex; - $display_runningex =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma - $display_surplus = sprintf "%.2f",$surplus; - $display_surplus =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma - print "\n"; - print "\n"; - } - - - print "
FINANCIAL
OUTGOINGS: / money requested or supplied
Fees
$recordef->{item} $recordef->{currency}$display_cost
Materials
$recordem->{item} $recordem->{currency}$display_cost
Miscellaneous
$recordex->{item} $recordex->{currency}$display_cost
 
INCOME: / donations, contributions, sums, funds
MONEY:
"; - while (my $recordf = $sthf->fetchrow_hashref) { - print "€$recordf->{amount}  "; - } - print "\n"; - -## actual paid deposits - while (my $recordar = $sthar->fetchrow_hashref) { - print "
 
RUNNING total IN:€$display_running
RUNNING total OUT:€$display_runningex
BALANCE OF FINANCIAL TRADE:€$display_surplus
\
\n"; - - - print "\n"; - print "\n"; - - print "\n"; - $sthdl->execute; - while (my $record = $sthdl->fetchrow_hashref) { - $record->{item} =~ s/^([a-z])/\U$1/; ## capitalise first letter - my $first=$record->{firstname} ; - my $last=$record->{lastname} ; - $first_init = substr($first, 0, 1); - $last_init = substr($last, 0, 1); - $first_init =~ s/^([a-z])/\U$1/; ## capitalise first letter - $last_init =~ s/^([a-z])/\U$1/; ## capitalise first letter - print "\n"; -# print "\n"; - } - - print "\n"; - while (my $record = $sthdr->fetchrow_hashref) { - $record->{item} =~ s/^([a-z])/\U$1/; ## capitalise first letter - my $first=$record->{firstname} ; - my $last=$record->{lastname} ; - $first_init = substr($first, 0, 1); - $last_init = substr($last, 0, 1); - $first_init =~ s/^([a-z])/\U$1/; ## capitalise first letter - $last_init =~ s/^([a-z])/\U$1/; ## capitalise first letter - print "\n"; - } - - - print "\n"; - $sthol->execute; - while (my $record = $sthol->fetchrow_hashref) { - $record->{item} =~ s/^([a-z])/\U$1/; ## capitalise first letter - my $first=$record->{firstname} ; - my $last=$record->{lastname} ; - $first_init = substr($first, 0, 1); - $last_init = substr($last, 0, 1); - $first_init =~ s/^([a-z])/\U$1/; ## capitalise first letter - $last_init =~ s/^([a-z])/\U$1/; ## capitalise first letter - print "\n"; - } - - - print "\n"; - while (my $record = $sthor->fetchrow_hashref) { - $record->{item} =~ s/^([a-z])/\U$1/; ## capitalise first letter - my $first=$record->{firstname} ; - my $last=$record->{lastname} ; - $first_init = substr($first, 0, 1); - $last_init = substr($last, 0, 1); - $first_init =~ s/^([a-z])/\U$1/; ## capitalise first letter - $last_init =~ s/^([a-z])/\U$1/; ## capitalise first letter - print "\n"; - } - - print "
NONFINANCIAL
Human and nonhuman budget contributions: / labour and resources, deployed &/or offfered, latent, awaiting activation
Labour / deployed
$record->{item} [$first_init$last_init]
$record->{item} [$first_init$last_init]
Resources / deployed
$record->{item} [$first_init$last_init]
Labour / offered
$record->{item} [$first_init$last_init]
Resources / offered
$record->{item} [$first_init$last_init]
\n"; -print "
\n"; - -print "\n"; - -while (my $recordn = $sthn->fetchrow_hashref) { - print ""; - } - -print "\n"; -print "\n"; -print "\n"; -print "\n"; - -print "\n"; - -for ($i=1;$i<=23;$i++) { - while (my $record = $sth->fetchrow_hashref) { - - my $cost = $record->{cost}; - $dec_cost = sprintf "%.2f",$cost; ## 2 decimal places - - my $first=$record->{firstname} ; - my $last=$record->{lastname} ; - $first_init = substr($first, 0, 1); - $last_init = substr($last, 0, 1); - $first_init =~ s/^([a-z])/\U$1/; ## capitalise first letter - $last_init =~ s/^([a-z])/\U$1/; ## capitalise first letter - - print "\n"; - print "\n"; - print "\n"; - print "\n"; - - $i++ - } - print "\n"; - print "\n"; - print "\n"; - print "\n"; -} - -print "\n"; -print "\n"; -print "\n"; - - -} - - -############################################################################ -# input expenditure - -sub input_expenditure { - -my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - - # clear previous entries - my $sql_del = (qq{DELETE FROM expenditure WHERE budget_id=$budget_id}); - my $sth_del = $dbh->prepare($sql_del); - $sth_del->execute; - - for ($i=1; $i<=25; $i++) { - if ($new_item{$i} ne '') { - my $sql = (qq{INSERT INTO expenditure (budget_id, item, cost, currency) VALUES ($budget_id, '$new_item{$i}', $cost{$i}, '$currency{$i}')}); - my $sth = $dbh->prepare($sql); - $sth->execute; - } - } - - # read back expenditure info - - my $sql2 = qq( SELECT budget_id, item, cost, currency FROM expenditure LEFT JOIN budgets on expenditure.budget_id=budgets.id WHERE expenditure.budget_id = '$budget_id' ORDER BY expenditure.id); - my $sth2 = $dbh->prepare($sql2); - $sth2->execute; - - &header; - print "
\n"; - print "
feral budget generator
Expenditure: $recordn->{name}
agentitemcostkind
$i.[$first_init$last_init] {item}\" size=80 maxsize=100>
$i.


\n"; - print "
\n"; - print "\n"; - print ""; - - print "
feral budget generator
Expenditure
\n"; - print " \n"; - while (my $record2 = $sth2->fetchrow_hashref) { - my $cost = $record2->{cost}; - $dec_cost = sprintf "%.2f",$cost; ## 2 decimal places - -# print " \n"; - print " \n"; - } - print "\n"; - print "
item cost
$record2->{item} $record2->{currency}$record2->{cost}
$record2->{item} $dec_cost
\n"; - - print "\n"; - print "
\n"; - -my $sql = qq( SELECT * from finance LEFT JOIN agents ON finance.agent_id=agents.id - LEFT JOIN budgets ON finance.budget_id = budgets.id WHERE finance.budget_id="$budget_id" AND finance.agent_id="$agent_id"); -my $sth = $dbh->prepare($sql); -$sth->execute; - -$sth->execute; -while (my $record = $sth->fetchrow_hashref) { - - print "
\n"; - print "\n"; - print "{name}\">\n"; - print "\n"; - print "\n"; - print "{fullname}\">\n"; - print "{codename}\">\n"; - print "\n"; - print "\n"; - - print "\n"; - print "\n"; - print "{name}\">\n"; - print "\n"; - print "\n"; - print "{fullname}\">\n"; - print "{codename}\">\n"; - print "\n"; - print "
\n"; - print "\n"; - } - -# print "

add or ammend more expenditure items\n"; -# print "

got to view the budget as a whole\n"; - print "\n"; - print "\n"; - print "\n"; - -$dbh->disconnect; - - - -} - - -############################################################################ -# prepare agents - -sub prepare_agents { - -my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - -my $sql = qq( SELECT * FROM agents WHERE budget_id = $budget_id ORDER BY lastname); -my $sth = $dbh->prepare($sql); -$sth->execute; - -my $sqlc = qq( SELECT COUNT(*) AS count FROM agents WHERE budget_id = $budget_id); -my $sthc = $dbh->prepare($sqlc); -$sthc->execute; - -my $sqln = qq( SELECT name FROM budgets where id = $budget_id); -my $sthn = $dbh->prepare($sqln); -$sthn->execute; - -&header; -print "
\n"; -print "\n"; -print "
\n"; - -print "\n"; - -while (my $recordn = $sthn->fetchrow_hashref) { - print ""; - } - -print "\n"; - -for ($i=1;$i<=50;$i++) { - while (my $record = $sth->fetchrow_hashref) { - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "{id}\">\n"; - print "{firstname}\">\n"; - print "{lastname}\">\n"; - print "{codename}\">\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - $i++ - } - } - - print "\n"; - print "\n"; - print "\n"; - print "\n"; - -while (my $recordc = $sthc->fetchrow_hashref) { - my $c = ($recordc->{count}); - for ($i=1+$c;$i<=50;$i++) { - print "\n"; - print "\n"; - print "\n"; - print "\n"; -# $i++ - } -} - - - -print "\n"; -print "\n"; -print "\n"; - - -} - - -############################################################################ -# edit agent - - sub edit_agent { - -my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - - # read in agent data - - &header; - print "
\n"; - print "
feral budget generator
Agents: $recordn->{name}
firstnamelastnamecodename
$record->{firstname}$record->{lastname}$record->{codename}
$i.


\n"; - print "\n"; -} - -############################################################################### - -# header subroutine - -sub header { - print < - - - - - - feral budget generator - - - - -END -} - -############################################################################### -# footer subroutine - -sub footer { - print < - -END -} - -############################################################################### -# adminfooter subroutine - -sub adminfooter { - -print "\n"; -print "\n"; -print "
\n"; - print "\n"; - print ""; - - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - - print "
feral budget generator
Edit agent
\n"; - - print "\n"; - print "
\n"; - - print "
\n"; - print "\n"; - print "{name}\">\n"; - print "\n"; - print "\n"; - print "{fullname}\">\n"; - print "{codename}\">\n"; - print "\n"; - print "\n"; - - print "\n"; - print "\n"; - print "\n"; - -$dbh->disconnect; - -} - -############################################################################ -# update agent - -sub update_agent { - -my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - - my $sql = (qq{UPDATE agents set firstname='$new_firstname', lastname='$new_lastname', fullname='$new_firstname $new_lastname', codename='$new_codename' WHERE budget_id=$budget_id AND id=$edit_agent_id}); - my $sth = $dbh->prepare($sql); - $sth->execute; - - # read back agent info - - &header; - print "
\n"; - print "
\n"; - print "
\n"; - print "\n"; - - print "
feral budget generator
\n"; - print "
\n"; - - print "
\n"; - print "\n"; - print "{name}\">\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - - print "\n"; - print "\n"; - print "\n"; - -$dbh->disconnect; - - -} - - -############################################################################ -# input agents - - sub input_agents { - -my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - - for ($i=1; $i<=50; $i++) { - if ($new_firstname{$i} ne '') { - my $sql = (qq{INSERT INTO agents (budget_id, firstname, lastname, fullname, codename) VALUES ($budget_id, '$new_firstname{$i}', '$new_lastname{$i}', '$new_firstname{$i} $new_lastname{$i} ','$new_codename{$i}')}); -# my $sql = (qq{INSERT INTO agents (budget_id, firstname, lastname, codename) VALUES ($budget_id, '$new_firstname{i}', '$new_lastname{i}', '$new_codename{i}')}); - my $sth = $dbh->prepare($sql); - $sth->execute; - } - } - - # read back agent info - - &header; - print "
\n"; - print "
\n"; - print "
\n"; - print "\n"; - - - print "
feral budget generator
\n"; - print "
\n"; - - print "
\n"; - print "\n"; - print "{name}\">\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - - print "\n"; - print "\n"; - print "\n"; - -$dbh->disconnect; - -} - -############################################################################ -# add form - -sub add_form { - -&header; -print "
\n"; -print " $projectname: add a budget \n"; - -my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - -my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id); -my $sth = $dbh->prepare($sql); -$sth->execute; - -print "

 

\n"; -print "\n"; -print "
\n"; -print ""; -while (my $record = $sth->fetchrow_hashref) { - print ""; - print ""; - print ""; - print ""; - } -print "\n"; - -$dbh->disconnect; - -print "\n"; -print "\n"; -print "\n"; -print "\n"; -#print "\n"; -#print "\n"; -print "\n"; -print "\n"; -print "
BudgetDate
"; - print "{id}\">$record->{name} $record->{date}
 
add a new budget
\n"; -print "
date
"; - -print "

\n"; - -print "
 
password

\n"; - -&footer; - -$dbh->disconnect; -} - -############################################################################### - -############################################################################### -# add budget - -sub add_budget { - -#if ($password eq $admin_password) { - - ### test if workshop exists already in database - if ($new_name ne '') { - - $new_name_found='false'; - my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - - my $sql = qq( SELECT DISTINCT name FROM budgets); - my $sth = $dbh->prepare($sql); - $sth->execute; - - while (my $record = $sth->fetchrow_hashref) { - if ($record->{name} eq $new_name) {$new_name_found='true'; } - } - - if ($new_name_found eq 'false') { - - my $sql = (qq{INSERT INTO budgets (name) VALUES ('$new_name')}); - my $sth = $dbh->prepare($sql); - $sth->execute; - - my $sql2 = (qq{ SELECT * from budgets where name='$new_name'}); - my $sth2 = $dbh->prepare($sql2); - $sth2->execute; - - $dbh->disconnect; - - &header; - - while (my $record2 = $sth2->fetchrow_hashref) { - print "
\n"; - print "\n"; - print "\n"; - print "
budget added {id}\">$new_name
\n"; - } - - &footer; - - } else { - - &header; - print "duplicate budget entry
\n"; - &footer; - - } - - } else { - - &header; - print "no budget entered
\n"; - &footer; - - } - -#} else { - -#&header; -#print "

Wrong password !

\n"; -#&footer; - -# } -} - - -############################################################################### - -# add budget information - -sub add_budget_information { - -my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); -my $sql = (qq{UPDATE budgets SET location='$new_location', deliver_date='$new_deliver_date', remarks='$new_remarks', - WHERE name='$new_name'}); -my $sth = $dbh->prepare($sql); -$sth->execute; - -$dbh->disconnect; -&header; - -print "

\n"; -print " $projectname: $new_name added "; -#print "$add_information \n"; -print "

view all budgets

\n"; -print "

\n"; - -&footer; -} - -############################################################################### -# edit select form: select which budget to edit - -sub edit_select_form { - -my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - -my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id); -my $sth = $dbh->prepare($sql); -$sth->execute; - -&header; - -print "
\n"; -print " edit a budget
\n"; -print "\n"; -print "\n"; -print "\n"; - while (my $record = $sth->fetchrow_hashref) { - print " \n"; - print " \n"; -print "\n"; -print "
{id}\"$record->{name}\n"; - } - -print "
\n"; - -$dbh->disconnect; - -&footer; - - - -} - -############################################################################### -# edit form: edit selected budget - -sub edit_form { - -my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - -my $sql = qq( SELECT DISTINCT * FROM budgets WHERE id=$edit_id); -my $sth = $dbh->prepare($sql); -$sth->execute; - -&header; - - print "
\n"; - - print "

$projectname: edit budget

\n"; -# print "\"\"\n"; - - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - - while (my $record = $sth->fetchrow_hashref) { - - print "\n"; - print "\n"; - print "\n"; - - print "\n"; - print "\n"; - - print "\n"; -# print "\n"; - print "\n"; - print "\n"; - print "
 
{name}\"size=50 maxsize=100>
{location}\"size=50 maxsize=100> location
{url}\"size=100 maxsize=100> url
Remarks: When, where, who
password
\n"; - print "
\n"; - - } - &footer; - -############################################################################### -# present budget: present singlebudget - -sub present_budget { - -my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - -my $sql = qq( SELECT DISTINCT * FROM budgets WHERE id=$edit_id); -my $sth = $dbh->prepare($sql); -$sth->execute; - -&header; - -# print "
\n"; - - print "

$projectname: budget notes

\n"; -# print "\"\"\n"; - - print "\n"; - print "\n"; - - while (my $record = $sth->fetchrow_hashref) { - - $record->{remarks} =~ s/\n/\
/g; - - print "\n"; - print "\n"; -# print "\n"; - - print "\n"; - print "\n"; -# print "\n"; - - -# print "\n"; - print "\n"; - print "
$record->{name}, \n"; - print "$record->{location} 
{url}\">$record->{url}
Remarks: When, where, who
$record->{remarks}
password
\n"; - print "
\n"; - - } - &footer; - } - - - - - -############################################################################### -# edit budget: edit budget results - -sub edit_budget { - - my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - -#if ($password eq $admin_password) { - -&header; - -### update budgets table - - my $sql_update = (qq{UPDATE budgets SET name='$new_name', location='$new_location', url='$new_url', remarks='$new_remarks', deliver_date="$new_deliver_date" WHERE id='$edit_id'}); - my $sth_update = $dbh->prepare($sql_update); - $sth_update->execute; - - - ### display results - - my $sql = qq( SELECT * FROM budgets WHERE id = '$edit_id'); - my $sth = $dbh->prepare($sql); - $sth->execute; - - while (my $record = $sth->fetchrow_hashref) { - - print "
\n"; -# print "\"\"\n"; - print "\n"; - print "\n"; - print "\n"; - print "
updated
$record->{name}

"; - } - - $dbh->disconnect; - &footer; - -} - -############################################################################### -# delete form: select a budget to delete - -sub delete_form { - -my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); -my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id); -my $sth = $dbh->prepare($sql); -$sth->execute; - -&header; - -print "
\n"; -print " delete a budget
\n"; -print "\n"; -print "\n"; -print "\n"; - -while (my $record = $sth->fetchrow_hashref) { -# print "{name}\">\n"; - print " \n"; - print " \n"; -print "\n"; -print "\n"; -print "
{id}\"$record->{name}\n"; - print "$record->{location}\n"; - } - -print "
password
\n"; - -$dbh->disconnect; -&footer; -} - -############################################################################### -# delete budget: budget delete results - -sub delete_budget { - -my $dbh = DBI->connect($db_conect,$db_user,$db_pass) - or die ("can't connect: $DBI::errstr"); - -my $sql = (qq{SELECT * FROM budgets WHERE id = '$delete_id'}); -my $sth = $dbh->prepare($sql); - $sth->execute; - -my $sql2 = (qq{DELETE FROM budgets WHERE id = '$delete_id'}); -my $sth2 = $dbh->prepare($sql2); - $sth2->execute; - -while (my $record = $sth->fetchrow_hashref) { - - &header; - - print "$record->{name} deleted\n"; - - } - - &footer; - $dbh->disconnect; - -} - -############################################################################### -# display budget: displays all budgets - -sub display_budgets { - -my $dbh = DBI->connect($db_conect,$db_user,$db_pass) -or die ("can't connect: $DBI::errstr"); -my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id); -my $sth = $dbh->prepare($sql); -$sth->execute; - -&header; - -print "
\n"; -print "

$projectname: all budgets: edit mode

\n"; - -print "\n"; -print "\n"; -while (my $record = $sth->fetchrow_hashref) { - print "\n"; - print ""; - print ""; - print ""; - print ""; -# print ""; - print "\n"; - } - -$dbh->disconnect; - -print"
BudgetLocationDateURL
{id}\">$record->{name}$record->{location}$record->{deliver_date}{url}\">$record->{url}{id}.jpg\" width=\"100\"border=\"0\" title=\"edit $record->{name}\" alt=\"\">
\n"; -&footer; -} - - -############################################################################### -# list budgets: list all budgets, non-edit mode - -sub list_budgets { - -my $dbh = DBI->connect($db_conect,$db_user,$db_pass) -or die ("can't connect: $DBI::errstr"); -my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id); -my $sth = $dbh->prepare($sql); -$sth->execute; - -&header; - -print "
\n"; -print "

$projectname: all budgets: read-only

\n"; - -print "\n"; -print "\n"; -while (my $record = $sth->fetchrow_hashref) { - print "\n"; - print ""; - print ""; - print ""; - print ""; -# print ""; - print "\n"; - } - -$dbh->disconnect; - -print"
BudgetLocationDateURL
{id}\">$record->{name}$record->{location}$record->{deliver_date}{url}\">$record->{url}{id}.jpg\" width=\"100\"border=\"0\" title=\"edit $record->{name}\" alt=\"\">
\n"; -&footer; -} - -############################################################################################## - -# select start date subroutine - -sub select_start_date { - -### day -print "
\n"; - -### month -print "\n"; - -### year -print "

all budgets: edit

all budgets: list

add a budget \ \; \|\n"; -print "delete a budget \ \; \n"; - -print "\n"; -print "\n"; -print "\n"; - -} - - -} +#!/usr/bin/perl + +use DBI; +use CGI qw(:cgi); + +use feature qw(switch); +no warnings qw(experimental::smartmatch); + +############################################################################## +# # +# configuration # +# # +############################################################################## + +## project +$projectname='f20 budget'; +$script_name='f20_budget.pl'; +$currency='€'; + +## server +$website_url='https://www.feraltrade.org'; +$feral_logo="$website_url/budget/feral_pigeon.jpg"; + +## database connection +$db_conect="DBI:mysql:feralbudget"; +$db_user="feraltrade"; +$db_pass="********"; + +## possibly unused +# $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::POST_MAX = '10000000'; + +$q = new CGI; + +$action=$q->param("action"); + +$password=$q->param('password'); +$askpassword=$q->param('askpassword'); + +$delete_id=$q->param("delete_id"); +$edit_id=$q->param("edit_id"); +$budget_id=$q->param("budget_id"); +$agent_id=$q->param("agent_id"); +$edit_agent_id=$q->param("edit_agent_id"); + +$new_auto_name=$q->param('new_auto_name'); +$new_auto_name =~ s/\'/\'\'/g; +$new_auto_location=$q->param('new_auto_location'); +$new_auto_location =~ s/\'/\'\'/g; +$new_auto_remarks=$q->param('new_auto_remarks'); +$new_auto_remarks =~ s/\'/\'\'/g; +$new_auto_url=$q->param('new_auto_url'); +$new_auto_url =~ s/\'/\'\'/g; + +$new_name=$q->param('new_name'); +$new_name =~ s/\'/\'\'/g; +$new_codename=$q->param('new_codename'); +$new_codename =~ s/\'/\'\'/g; +$new_pseudo=$q->param('new_pseudo'); +$new_pseudo =~ s/\'/\'\'/g; +$new_firstname=$q->param('new_firstname'); +$new_firstname =~ s/\'/\'\'/g; +$new_lastname=$q->param('new_lastname'); +$new_lastname =~ s/\'/\'\'/g; +$new_lastname=$q->param('new_lastname'); +$new_fullname =~ s/\'/\'\'/g; +$new_fullname=$q->param('new_fullname'); + +$new_agent=$q->param('new_agent'); +$new_location=$q->param('new_location'); +$new_location =~ s/\'/\'\'/g; +$new_remarks=$q->param('new_remarks'); +$new_remarks =~ s/\'/\'\'/g; +$new_url=$q->param('new_url'); +$new_url =~ s/\'/\'\'/g; + +$new_amount=$q->param('new_amount'); +$new_amount = sprintf "%.2f",$new_amount; ## 2 decimal places + +$new_url=$q->param("new_url"); +#$new_url=~ s/http\:\/\///g; # don't remove http:// + +$new_item = $q->param("new_item"); +$new_item =~ s/\'/\'\'/g; +$new_item =~ s/\x92/’/g; +$new_labour = $q->param("new_labour"); +$new_labour =~ s/\'/\'\'/g; +$new_labour =~ s/\x92/’/g; +$new_resource = $q->param("new_resource"); +$new_resource =~ s/\'/\'\'/g; +$new_resource =~ s/\x92/’/g; +$new_status = $q->param("new_status"); +$new_lstatus = $q->param("new_lstatus"); +$new_rstatus = $q->param("new_rstatus"); +$type = $q->param("type"); + +for ( $i=0; $i<=50; $i+=1) { + $new_status{$i} = $q->param("new_status$i"); + $type{$i} = $q->param("type$i"); + $new_item{$i} = $q->param("new_item$i"); + $new_item{$i} =~ s/\'/\'\'/g; + $new_item{$i} =~ s/\x92/’/g; + $new_resource{$i} = $q->param("new_resource$i"); + $new_resource{$i} =~ s/\'/\'\'/g; + $new_resource{$i} =~ s/\x92/’/g; + $new_labour{$i} = $q->param("new_labour$i"); + $new_labour{$i} =~ s/\'/\'\'/g; + $new_labour{$i} =~ s/\x92/’/g; + $new_status{$i} = $q->param("new_status$i"); + $new_lstatus{$i} = $q->param("new_lstatus$i"); + $new_rstatus{$i} = $q->param("new_rstatus$i"); + + $new_firstname{$i} = $q->param("new_firstname$i"); + $new_firstname{$i} =~ s/\'/\'\'/g; + $new_firstname{$i} =~ s/\x92/’/g; + $new_lastname{$i} = $q->param("new_lastname$i"); + $new_lastname{$i} =~ s/\'/\'\'/g; + $new_lastname{$i} =~ s/\x92/’/g; + $new_codename{$i} = $q->param("new_codename$i"); + $new_codename{$i} =~ s/\'/\'\'/g; + $new_codename{$i} =~ s/\x92/’/g; + + $cost{$i}=~ s/\€/@euro/g; + $cost{$i} = $q->param("cost$i"); + $new_cost{$i}=~ s/\€/@euro/g; + $new_cost{$i} = $q->param("new_cost$i"); + $currency{$i} = $q->param("currency$i"); +} + + +($second, $minute, $hour, $currentdayofmonth, $month, $year, $weekday, $dayofyear, $IsDST) = localtime(time); +$currentmonth=$month+1; +$currentyear=$year+'1900'; + +$new_day=$q->param("'new_day"); +$new_month=$q->param("new_month"); +$new_year=$q->param("new_year"); + +$new_date=$q->param('new_year') . $q->param("new_month") . $q->param("new_day"); +$new_start_date=$q->param('new_start_year') . $q->param("new_start_month") . $q->param("new_start_day"); +$new_end_date=$q->param('new_end_year') . $q->param("new_end_month") . $q->param("new_end_day"); +$new_print_date=$q->param('new_print_year') . $q->param("new_print_month") . $q->param("new_print_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"); + + +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; +} + +given ($action) { + when('select_budget') {&select_budget; } + when('add_form') {&add_form; } + when('add_budget') {&add_budget; } + when('add_budget_information') {&add_budget_information; } + when('prepare_agents') {&prepare_agents; } + when('input_agents') {&input_agents; } + when('edit_agent') {&edit_agent; } + when('update_agent') {&update_agent; } + when('edit_form') {&edit_form; } + when('edit_select_form') {&edit_select_form; } + when('edit_budget') {&edit_budget; } + when('list_budgets') {&list_budgets; } + when('prepare_budget') {&prepare_budget; } + when('prepare_money') {&prepare_money; } + 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; + + +############################################################################## +# # +# select budget # +# # +############################################################################## + +sub select_budget { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + my $sql = qq( SELECT DISTINCT name from budgets ORDER BY id DESC); + my $sth = $dbh->prepare($sql); + $sth->execute; + + my $sql2 = qq( SELECT DISTINCT firstname, lastname from agents ORDER BY firstname); + my $sth2 = $dbh->prepare($sql2); + $sth2->execute; + + &print_header; + + print < + +
+ + + + + +END + + ## name budget + + print "\n"; + + ## enter agent code + + print < + + + + + +
+ feral budget generator: enter agent
 
budget:
enter your agent codename: + +
+
+END + &print_footer; + $dbh->disconnect; + +} + + +############################################################################## +# # +# prepare budget # +# # +############################################################################## + +sub prepare_budget { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + my $sql = qq( SELECT * from budgets WHERE name="$new_name" ); + my $sth = $dbh->prepare($sql); + $sth->execute; + + ## identify agent by codename + my $sql2 = qq( SELECT * from agents where codename ="$new_codename" ); + my $sth2 = $dbh->prepare($sql2); + $sth2->execute; + + while (my $record = $sth->fetchrow_hashref) { + if (my $record2 = $sth2->fetchrow_hashref) { + # while (my $record2 = $sth2->fetchrow_hashref) { + # if ($record2->{codename} ne '') { + 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); + $sth3->execute; + + &print_header; + + print < + +
+ + + + +
feral budget generator
Instructions

+ +
+ Enter your budget requests & contributions. You can return to edit your entries at any time.

+ +
+ + + + + + + + + + + + + + + + \n"; + + print "\n"; + print "\n"; + + print "\n"; + $i++ + } + + if ($i<=5) { + + print "\n"; + + print "\n"; + + print "\n"; + print "\n"; + } + } + + print "
budget name:
+ + $record->{name}
your name: + $record2->{firstname} $record2->{lastname} +
+ request money + your monetary requests from the f20 budget (all sums in €)
+END + + my $sql4 = qq( SELECT * from expenditure where budget_id='$record->{id}' AND agent_id ='$record2->{id}' ); + my $sth4 = $dbh->prepare($sql4); + $sth4->execute; + + for ($i=1;$i<=5;$i++) { + while (my $record4 = $sth4->fetchrow_hashref) { + print "
$i. \n"; + print "$currency"; + print "{cost}\" "; + print " size=\"2\" maxsize=\"5\">item {item}\" size=\"70\" maxsize=\"100\">
$i. \n"; + print "€ item {item}\" size=\"70\" maxsize=\"100\">
\n"; + + print "
"; + print ""; + print "\n"; + + + ## resources section !!! read-in notworking !!! + + print "\n"; + print ""; + + my $sql5 = qq( SELECT * from nonfinance where budget_id=$record->{id} AND agent_id =$record2->{id} AND kind='labour' ); + my $sth5 = $dbh->prepare($sql5); + $sth5->execute; + + for ($i=1;$i<=8;$i++) { + while (my $record5 = $sth5->fetchrow_hashref) { + print "\n"; + print "\n"; + print "\n"; + $i++ + } + if ($i<=5) { + print "\n"; + print "\n"; + print "\n"; + } + } + + print "\n"; + print ""; + + my $sql5 = qq( SELECT * from nonfinance where budget_id=$record->{id} AND agent_id =$record2->{id} AND kind='resources' ); + my $sth5 = $dbh->prepare($sql5); + $sth5->execute; + + for ($i=1;$i<=8;$i++) { + while (my $record5 = $sth5->fetchrow_hashref) { + print "\n"; + print "\n"; + print "\n"; + $i++ + } + if ($i<=5) { + print "\n"; + print "\n"; + print "\n"; + } + } + + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "
input moneyyour monetary contribution to the budget (direct payments for materials/services, donations to f20, as a sum total)
fetchrow_hashref) { + print "value=\"$record3->{amount}\" "; + } + print " size=\"3\" maxsize=\"5\">
 
input labourthings you commit to doing, non-remunerated. (check the box if this labour has already been deployed)
$i.{status} eq 'delivered') { + print "CHECKED"; + } + ; + print ">{item}\" size=\"100\" maxsize=\"200\">
$i.{status} eq 'delivered') { + print "CHECKED"; + } + ; + print ">
 
input resourcesmaterials, spaces, tools, previous work etc (check the box if your resource has already been deployed)
$i.{status} eq 'delivered') { + print "CHECKED"; + } + ; + print ">{item}\" size=\"100\" maxsize=\"200\">
$i.{status} eq 'delivered') { + print "CHECKED"; + } + print ">
Notes:
\n"; + + } else { + & print_header; + print "codename not recognised. please retry\n"; + } + } + &print_footer; + $dbh->disconnect; +} + + +############################################################################## +# # +# input budget: input individual budet items - money & resources # +# # +############################################################################## + +sub input_budget { + + #for ($i=1; $i<=8; $i++) { + # if (('$type{$i}' eq 'select category') && ('$new_item{$i}' ne '')) { + + # print "
\n"; + # print "\n"; + # print "\n"; + # print "\n"; + # print "{name}\">\n"; + # print "\n"; + # print "\n"; + # print "{fullname}\">\n"; + # print "{codename}\">\n"; + # print "\n"; + # print "\n"; + + #} else { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + &print_header; + print "
\n"; + print "
\n"; + print "
<\n"; + + ## delete expenditure line for agent + budget, if exists + my $sqld = qq( DELETE from expenditure where budget_id="$budget_id" AND agent_id="$agent_id"); + my $sthd= $dbh->prepare($sqld); + $sthd->execute; + + ## input new expenditure lines for agent + + for ($i=1; $i<=8; $i++) { + if ($new_item{$i} ne '') { + my $sql = (qq{INSERT INTO expenditure (budget_id, agent_id, status, type, item, cost, currency) VALUES ($budget_id, $agent_id, '$new_status{$i}', '$type{$i}', '$new_item{$i}', $new_cost{$i}, '€')}); + my $sth = $dbh->prepare($sql); + $sth->execute; + } + } + + + ## read in finance for agent + + my $sql = qq( SELECT * from finance LEFT JOIN agents ON finance.agent_id=agents.id + LEFT JOIN budgets ON finance.budget_id = budgets.id WHERE finance.budget_id="$budget_id" AND finance.agent_id="$agent_id"); + my $sth = $dbh->prepare($sql); + $sth->execute; + + #while (my $record = $sth->fetchrow_hashref) { + print "\n"; + + ## delete finance line for agent + budget, if exists + my $sqld = qq( DELETE from finance where budget_id="$budget_id" AND agent_id="$agent_id"); + my $sthd= $dbh->prepare($sqld); + $sthd->execute; + + ## input money into finance + # if ($new_amount ne '') { + if ($new_amount eq '') { + $new_amount=0; + } + my $sqli = (qq{INSERT INTO finance (budget_id, agent_id, amount) VALUES ($budget_id, $agent_id, $new_amount)}); + my $sthi = $dbh->prepare($sqli); + $sthi->execute; + + my $sqld = qq( DELETE from nonfinance where budget_id="$budget_id" AND agent_id="$agent_id"); + my $sthd= $dbh->prepare($sqld); + $sthd->execute; + + ## input labour into nonfinance for agent + + for ($i=1; $i<=8; $i++) { + if ($new_labour{$i} ne '') { + my $sqll = (qq{INSERT INTO nonfinance (budget_id, agent_id, item, kind, status) VALUES ($budget_id, $agent_id, "$new_labour{$i}", "labour", "$new_lstatus{$i}")}); + my $sthl = $dbh->prepare($sqll); + $sthl->execute; + } + } + + ## input resources into nonfinance for agent + for ($i=1; $i<=8; $i++) { + if ($new_resource{$i} ne '') { + my $sqlr = (qq{INSERT INTO nonfinance (budget_id, agent_id, item, kind, status) VALUES ($budget_id, $agent_id, "$new_resource{$i}", "resources", "$new_rstatus{$i}")}); + my $sthr = $dbh->prepare($sqlr); + $sthr->execute; + } + } + + ## read back in to get these values from the db, not from the cgi + + my $sqlv = (qq{SELECT DISTINCT item, cost, expenditure.currency, type, fullname from expenditure RIGHT JOIN agents on expenditure.agent_id=agents.id LEFT JOIN finance on expenditure.agent_id=finance.agent_id + WHERE expenditure.agent_id=$agent_id AND expenditure.budget_id=$budget_id}); + my $sthv = $dbh->prepare($sqlv); + $sthv->execute; + my $sqln = (qq{ SELECT fullname from agents where id=$agent_id}); + my $sthn = $dbh->prepare($sqln); + $sthn->execute; + + while (my $recordn = $sthn->fetchrow_hashref) { + print " "; + } + + # print "\n"; + } + } + + print "\n"; + print "\n"; + + $sth->execute; + while (my $record = $sth->fetchrow_hashref) { + + print "\n"; + print "\n"; + print "{name}\">\n"; + print "\n"; + print "\n"; + print "{fullname}\">\n"; + print "{codename}\">\n"; + print "\n"; + print "\n"; + + print "\n"; + print "\n"; + print "{name}\">\n"; + print "\n"; + print "\n"; + print "{fullname}\">\n"; + print "{codename}\">\n"; + print "\n"; + print "
feral budget generator: $record->{name}
$projectname: $recordn->{fullname}
your PROPOSITION: "; + while (my $recordv = $sthv->fetchrow_hashref) { + if ($recordv->{item} ne '') { + print "
$recordv->{$currency} $recordv->{$cost} $recordv->{$item} $recordv->{$type}
\n"; + print "\n"; + } + &print_footer; +} + +############################################################################### +# input money + +sub input_money { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + &print_header; + print "
\n"; + print "\n"; + print "
\n"; + + + ## read in finance for agent+ budget + + my $sql = qq( SELECT * from finance LEFT JOIN agents ON finance.agent_id=agents.id + LEFT JOIN budgets ON finance.budget_id = budgets.id WHERE finance.budget_id="$budget_id" AND finance.agent_id="$agent_id"); + my $sth = $dbh->prepare($sql); + $sth->execute; + + while (my $record = $sth->fetchrow_hashref) { + if ($record->{id} ne '') { + + ## delete finance line for agent + budget, if exists + my $sqld = qq( DELETE from finance where budget_id="$budget_id" AND agent_id="$agent_id"); + my $sthd= $dbh->prepare($sqld); + $sthd->execute; + } + } + + ## input money into finance + if ($new_amount eq '') { + $new_amount=0; + } + my $sqli = (qq{INSERT INTO finance (budget_id, agent_id, amount) VALUES ($budget_id, $agent_id, $new_amount)}); + my $sthi = $dbh->prepare($sqli); + $sthi->execute; + #} + print "\n"; + print " "; + print "\n"; + print "\n"; + + print " "; + print "\n"; + print "\n"; + + print "\n"; + print "\n"; + print "{name}\">\n"; + print "\n"; + print "\n"; + print "{fullname}\">\n"; + print "{codename}\">\n"; + print "\n"; + print "
feral budget generator: $record->{name}
your name:$new_fullname
your monetary contribution:€$new_amount
\n"; + print "\n"; + + &print_footer; + +} + + +############################################################################### +# compile budget: lay out the whole budget as it assembles + +sub compile_budget { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + my $sqld = qq( SELECT * FROM nonfinance LEFT JOIN agents on nonfinance.agent_id=agents.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id + LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id AND nonfinance.status='delivered' ORDER BY nonfinance.item); + my $sthd = $dbh->prepare($sqld); + $sthd->execute; + + my $sqlol = qq( SELECT * FROM nonfinance LEFT JOIN agents on nonfinance.agent_id=agents.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id + LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id AND nonfinance.status!='delivered' AND kind='labour' ORDER BY nonfinance.item); + my $sthol = $dbh->prepare($sqlol); + $sthol->execute; + + my $sqlor = qq( SELECT * FROM nonfinance LEFT JOIN agents on nonfinance.agent_id=agents.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id + LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id AND nonfinance.status!='delivered' AND kind='resources' ORDER BY nonfinance.item); + my $sthor = $dbh->prepare($sqlor); + $sthor->execute; + + my $sqldl = qq( SELECT * FROM nonfinance LEFT JOIN agents on nonfinance.agent_id=agents.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id + LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id AND nonfinance.status='delivered' AND kind='labour' ORDER BY nonfinance.item); + my $sthdl = $dbh->prepare($sqldl); + $sthdl->execute; + + my $sqldr = qq( SELECT * FROM nonfinance LEFT JOIN agents on nonfinance.agent_id=agents.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id + LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id AND nonfinance.status='delivered' AND kind='resources' ORDER BY nonfinance.item); + my $sthdr = $dbh->prepare($sqldr); + $sthdr->execute; + + + ## count potential deposits + my $sqla = qq( SELECT COUNT(fullname) AS qty FROM agents WHERE budget_id=$budget_id AND status!='staff'); + my $stha = $dbh->prepare($sqla); + $stha->execute; + + ## count deposits received + my $sqlar = qq( SELECT COUNT(fullname) AS qty FROM agents WHERE budget_id=$budget_id AND status='deposit'); + my $sthar = $dbh->prepare($sqlar); + $sthar->execute; + + my $sqlc = qq( SELECT COUNT(*) FROM nonfinance LEFT JOIN agents on nonfinance.agent_id=agent.id LEFT JOIN budgets ON nonfinance.budget_id=budgets.id + LEFT JOIN locations ON locations.structure=budgets.location WHERE nonfinance.budget_id=$budget_id); + my $sthc = $dbh->prepare($sqlc); + $sthc->execute; + + my $sqlf = qq( SELECT * FROM finance WHERE budget_id=$budget_id ORDER by amount); + my $sthf = $dbh->prepare($sqlf); + $sthf->execute; + + my $sqlb = qq( SELECT *, date_format(deliver_date,'%d-%m-%Y') AS end_date FROM budgets LEFT JOIN locations on budgets.location=locations.structure WHERE budgets.id=$budget_id); + my $sthb = $dbh->prepare($sqlb); + $sthb->execute; + + my $sqlfc = qq( SELECT COUNT(id) AS count FROM finance WHERE budget_id=$budget_id); + my $sthfc = $dbh->prepare($sqlfc); + $sthfc->execute; + + my $sqls = qq( SELECT SUM(amount) FROM finance WHERE budget_id=$budget_id); + my $sths = $dbh->prepare($sqls); + $sths->execute; + + my $sqlse = qq( SELECT SUM(cost) FROM expenditure WHERE budget_id=$budget_id); + my $sthse = $dbh->prepare($sqlse); + $sthse->execute; + + my $sqlr = qq( SELECT name, fullname, codename from finance LEFT JOIN agents ON finance.agent_id=agents.id + LEFT JOIN budgets ON finance.budget_id = budgets.id WHERE finance.budget_id="$budget_id" AND finance.agent_id="$agent_id"); + my $sthr = $dbh->prepare($sqlr); + $sthr->execute; + + my $sqlef = qq( SELECT budget_id, item, cost, currency, type FROM expenditure LEFT JOIN budgets on expenditure.budget_id=budgets.id WHERE expenditure.budget_id = '$budget_id' AND type='fee' ORDER BY expenditure.item); + my $sthef = $dbh->prepare($sqlef); + $sthef->execute; + + my $sqlem = qq( SELECT budget_id, item, cost, currency, type FROM expenditure LEFT JOIN budgets on expenditure.budget_id=budgets.id WHERE expenditure.budget_id = '$budget_id' AND type='materials' ORDER BY expenditure.item); + my $sthem = $dbh->prepare($sqlem); + $sthem->execute; + + my $sqlex = qq( SELECT budget_id, item, cost, currency, type FROM expenditure LEFT JOIN budgets on expenditure.budget_id=budgets.id WHERE expenditure.budget_id = '$budget_id' AND type='misc' ORDER BY expenditure.item); + my $sthex = $dbh->prepare($sqlex); + $sthex->execute; + + &print_header; + + print "\n"; + print "\n"; + print "\n"; + + print "
\n"; + print "
feral budget generator     | |     https://feraltrade.org/cgi-bin/budget/f20_budget.pl
\n"; + # print "
\n"; + + $sthb->execute; + while (my $recordb = $sthb->fetchrow_hashref) { + print "
\n"; + print "
$projectname    | | $recordb->{location}    "; + + print "   | | budget adjustments to $currentdayofmonth/$currentmonth/$currentyear
"; + + # print "   | | Budget"; + while (my $recordd = $sthd->fetchrow_hashref) { + $title = substr($recordd->{item}, 0, 30) ; + # print ": $title "; + } + # print "
"; + + print "\n"; + print "\n"; + + print "\n\n"; + } + + $sthr->execute; + while (my $recordr = $sthr->fetchrow_hashref) { + + print "\n"; + + print "\n"; + print "{name}\">\n"; + print "\n"; + print "\n"; + print "{fullname}\">\n"; + print "{codename}\">\n"; + print "\n"; + print "\n\n"; + } + + if ($agent_id eq "") { + print "\n"; + print "\n"; + print "{name}\">\n"; + print "\n"; + print "\n"; + print "\n"; + print "

\n\n"; + + } else { + print "\n"; + print "\n"; + print "{name}\">\n"; + print "\n"; + print "\n"; + + print "\n"; + print "

\n\n"; + } + + print "
\n"; + if ($agent_id ne "") { + while (my $recordfc = $sthfc->fetchrow_hashref) { + print " Contributing agents [$recordfc->{count}]. This budget will remain open for negotiations until $recordb->{end_date}.\n"; + print " Monetary items will be kept anonymous (although visible to the budget r/administrators) labour & resources will be tagged with the ID of the resourcer.\n"; + } + } + print "

\n"; + print "\n\n"; + + print "\n"; + + $dbh->disconnect; + + &print_footer; + +} + + +############################################################################ +# prepare expenditure + +sub prepare_expenditure { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + my $sql = qq( SELECT item, cost, currency, firstname, lastname, type FROM expenditure LEFT JOIN agents on expenditure.agent_id = agents.id WHERE expenditure.budget_id = $budget_id ORDER BY fullname); + my $sth = $dbh->prepare($sql); + $sth->execute; + + my $sqln = qq( SELECT name FROM budgets where id = $budget_id); + my $sthn = $dbh->prepare($sqln); + $sthn->execute; + + &print_header; + print "
\n"; + print "
"; + + print "\n"; + print "\n"; + + + print "\n"; + while (my $recordef = $sthef->fetchrow_hashref) { + my $cost = $recordef->{cost}; + $display_cost = sprintf "%.2f",$cost; + $display_cost =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma + print " \n"; + } + + print "\n"; + while (my $recordem = $sthem->fetchrow_hashref) { + my $cost = $recordem->{cost}; + $display_cost = sprintf "%.2f",$cost; + $display_cost =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma + print " \n"; + } + + print "\n"; + while (my $recordex = $sthex->fetchrow_hashref) { + my $cost = $recordex->{cost}; + $display_cost = sprintf "%.2f",$cost; + $display_cost =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma + print " \n"; + } + + + print "\n"; + print "\n"; + # print "\n"; + print "\n"; + while (my @sum = $sths->fetchrow_array()) { + $deposits = $recordar->{qty}*50; + $running = $sum[0]+$deposits; + $display_running = sprintf "%.2f",$running; + $display_running =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma + print "\n"; + } + } + + while (my @sumex = $sthse->fetchrow_array()) { + $runningex = $sumex[0]; + $surplus = $running - $runningex; + $display_runningex = sprintf "%.2f",$runningex; + $display_runningex =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma + $display_surplus = sprintf "%.2f",$surplus; + $display_surplus =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; ## add commma + print "\n"; + print "\n"; + } + + + print "
FINANCIAL
OUTGOINGS: / money requested or supplied
Fees
$recordef->{item} $recordef->{currency}$display_cost
Materials
$recordem->{item} $recordem->{currency}$display_cost
Miscellaneous
$recordex->{item} $recordex->{currency}$display_cost
 
INCOME: / donations, contributions, sums, funds
MONEY:
"; + while (my $recordf = $sthf->fetchrow_hashref) { + print "€$recordf->{amount}  "; + } + print "\n"; + + ## actual paid deposits + while (my $recordar = $sthar->fetchrow_hashref) { + print "
 
RUNNING total IN:€$display_running
RUNNING total OUT:€$display_runningex
BALANCE OF FINANCIAL TRADE:€$display_surplus
\
\n"; + + + print "\n"; + print "\n"; + + print "\n"; + $sthdl->execute; + while (my $record = $sthdl->fetchrow_hashref) { + $record->{item} =~ s/^([a-z])/\U$1/; ## capitalise first letter + my $first=$record->{firstname} ; + my $last=$record->{lastname} ; + $first_init = substr($first, 0, 1); + $last_init = substr($last, 0, 1); + $first_init =~ s/^([a-z])/\U$1/; ## capitalise first letter + $last_init =~ s/^([a-z])/\U$1/; ## capitalise first letter + print "\n"; + # print "\n"; + } + + print "\n"; + while (my $record = $sthdr->fetchrow_hashref) { + $record->{item} =~ s/^([a-z])/\U$1/; ## capitalise first letter + my $first=$record->{firstname} ; + my $last=$record->{lastname} ; + $first_init = substr($first, 0, 1); + $last_init = substr($last, 0, 1); + $first_init =~ s/^([a-z])/\U$1/; ## capitalise first letter + $last_init =~ s/^([a-z])/\U$1/; ## capitalise first letter + print "\n"; + } + + + print "\n"; + $sthol->execute; + while (my $record = $sthol->fetchrow_hashref) { + $record->{item} =~ s/^([a-z])/\U$1/; ## capitalise first letter + my $first=$record->{firstname} ; + my $last=$record->{lastname} ; + $first_init = substr($first, 0, 1); + $last_init = substr($last, 0, 1); + $first_init =~ s/^([a-z])/\U$1/; ## capitalise first letter + $last_init =~ s/^([a-z])/\U$1/; ## capitalise first letter + print "\n"; + } + + + print "\n"; + while (my $record = $sthor->fetchrow_hashref) { + $record->{item} =~ s/^([a-z])/\U$1/; ## capitalise first letter + my $first=$record->{firstname} ; + my $last=$record->{lastname} ; + $first_init = substr($first, 0, 1); + $last_init = substr($last, 0, 1); + $first_init =~ s/^([a-z])/\U$1/; ## capitalise first letter + $last_init =~ s/^([a-z])/\U$1/; ## capitalise first letter + print "\n"; + } + + print "
NONFINANCIAL
Human and nonhuman budget contributions: / labour and resources, deployed &/or offfered, latent, awaiting activation
Labour / deployed
$record->{item} [$first_init$last_init]
$record->{item} [$first_init$last_init]
Resources / deployed
$record->{item} [$first_init$last_init]
Labour / offered
$record->{item} [$first_init$last_init]
Resources / offered
$record->{item} [$first_init$last_init]
\n"; + print "
\n"; + + print "\n"; + + while (my $recordn = $sthn->fetchrow_hashref) { + print ""; + } + + print "\n"; + print "\n"; + print "\n"; + print "\n"; + + print "\n"; + + for ($i=1;$i<=23;$i++) { + while (my $record = $sth->fetchrow_hashref) { + + my $cost = $record->{cost}; + $dec_cost = sprintf "%.2f",$cost; ## 2 decimal places + + my $first=$record->{firstname} ; + my $last=$record->{lastname} ; + $first_init = substr($first, 0, 1); + $last_init = substr($last, 0, 1); + $first_init =~ s/^([a-z])/\U$1/; ## capitalise first letter + $last_init =~ s/^([a-z])/\U$1/; ## capitalise first letter + + print "\n"; + print "\n"; + print "\n"; + print "\n"; + + $i++ + } + print "\n"; + print "\n"; + print "\n"; + print "\n"; + } + print "\n"; + print "\n"; + print "\n"; +} + + +############################################################################ +# input expenditure + +sub input_expenditure { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + # clear previous entries + my $sql_del = (qq{DELETE FROM expenditure WHERE budget_id=$budget_id}); + my $sth_del = $dbh->prepare($sql_del); + $sth_del->execute; + + for ($i=1; $i<=25; $i++) { + if ($new_item{$i} ne '') { + my $sql = (qq{INSERT INTO expenditure (budget_id, item, cost, currency) VALUES ($budget_id, '$new_item{$i}', $cost{$i}, '$currency{$i}')}); + my $sth = $dbh->prepare($sql); + $sth->execute; + } + } + + # read back expenditure info + + my $sql2 = qq( SELECT budget_id, item, cost, currency FROM expenditure LEFT JOIN budgets on expenditure.budget_id=budgets.id WHERE expenditure.budget_id = '$budget_id' ORDER BY expenditure.id); + my $sth2 = $dbh->prepare($sql2); + $sth2->execute; + + &print_header; + + print "
\n"; + print "
feral budget generator
Expenditure: $recordn->{name}
agentitemcostkind
$i.[$first_init$last_init] {item}\" size=80 maxsize=100>
$i.


\n"; + print "
\n"; + print "\n"; + print ""; + + print "
feral budget generator
Expenditure
\n"; + print " \n"; + while (my $record2 = $sth2->fetchrow_hashref) { + my $cost = $record2->{cost}; + $dec_cost = sprintf "%.2f",$cost; ## 2 decimal places + + # print " \n"; + print " \n"; + } + print "\n"; + print "
item cost
$record2->{item} $record2->{currency}$record2->{cost}
$record2->{item} $dec_cost
\n"; + + print "\n"; + print "
\n"; + + my $sql = qq( SELECT * from finance LEFT JOIN agents ON finance.agent_id=agents.id + LEFT JOIN budgets ON finance.budget_id = budgets.id WHERE finance.budget_id="$budget_id" AND finance.agent_id="$agent_id"); + my $sth = $dbh->prepare($sql); + $sth->execute; + + $sth->execute; + while (my $record = $sth->fetchrow_hashref) { + + print "
\n"; + print "\n"; + print "{name}\">\n"; + print "\n"; + print "\n"; + print "{fullname}\">\n"; + print "{codename}\">\n"; + print "\n"; + print "\n"; + + print "\n"; + print "\n"; + print "{name}\">\n"; + print "\n"; + print "\n"; + print "{fullname}\">\n"; + print "{codename}\">\n"; + print "\n"; + print "
\n"; + print "\n"; + } + + # print "

add or ammend more expenditure items\n"; + # print "

got to view the budget as a whole\n"; + print "\n"; + print "\n"; + print "\n"; + + $dbh->disconnect; +} + + +############################################################################ +# prepare agents + +sub prepare_agents { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + my $sql = qq( SELECT * FROM agents WHERE budget_id = $budget_id ORDER BY lastname); + my $sth = $dbh->prepare($sql); + $sth->execute; + + my $sqlc = qq( SELECT COUNT(*) AS count FROM agents WHERE budget_id = $budget_id); + my $sthc = $dbh->prepare($sqlc); + $sthc->execute; + + my $sqln = qq( SELECT name FROM budgets where id = $budget_id); + my $sthn = $dbh->prepare($sqln); + $sthn->execute; + + &print_header; + print "
\n"; + print "\n"; + print "
\n"; + + print "\n"; + + while (my $recordn = $sthn->fetchrow_hashref) { + print ""; + } + + print "\n"; + + for ($i=1;$i<=50;$i++) { + while (my $record = $sth->fetchrow_hashref) { + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "{id}\">\n"; + print "{firstname}\">\n"; + print "{lastname}\">\n"; + print "{codename}\">\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + $i++ + } + } + + print "\n"; + print "\n"; + print "\n"; + print "\n"; + + while (my $recordc = $sthc->fetchrow_hashref) { + my $c = ($recordc->{count}); + for ($i=1+$c;$i<=50;$i++) { + print "\n"; + print "\n"; + print "\n"; + print "\n"; + # $i++ + } + } + print "\n"; + print "\n"; + print "\n"; +} + + +############################################################################ +# edit agent + +sub edit_agent { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + # read in agent data + + &print_header; + print "
\n"; + print "
feral budget generator
Agents: $recordn->{name}
firstnamelastnamecodename
$record->{firstname}$record->{lastname}$record->{codename}
$i.


\n"; + print "\n"; +} + +############################################################################### +# print_header subroutine + +sub print_header { + print < + + + + + feral budget generator + + + +END +} + +############################################################################### +# print_footer subroutine + +sub print_footer { + print < + +END +} + +############################################################################### +# adminfooter subroutine + +sub adminfooter { + + print "\n"; + print "\n"; + print "
\n"; + print "\n"; + print ""; + + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + + print "
feral budget generator
Edit agent
\n"; + + print "\n"; + print "
\n"; + + print "
\n"; + print "\n"; + print "{name}\">\n"; + print "\n"; + print "\n"; + print "{fullname}\">\n"; + print "{codename}\">\n"; + print "\n"; + print "\n"; + + print "\n"; + print "\n"; + print "\n"; + + $dbh->disconnect; +} + +############################################################################ +# update agent + +sub update_agent { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + my $sql = (qq{UPDATE agents set firstname='$new_firstname', lastname='$new_lastname', fullname='$new_firstname $new_lastname', codename='$new_codename' WHERE budget_id=$budget_id AND id=$edit_agent_id}); + my $sth = $dbh->prepare($sql); + $sth->execute; + + # read back agent info + + &print_header; + print "
\n"; + print "
\n"; + print "
\n"; + print "\n"; + + print "
feral budget generator
\n"; + print "
\n"; + + print "
\n"; + print "\n"; + print "{name}\">\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + + print "\n"; + print "\n"; + print "\n"; + + $dbh->disconnect; +} + + +############################################################################ +# input agents + +sub input_agents { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + for ($i=1; $i<=50; $i++) { + if ($new_firstname{$i} ne '') { + my $sql = (qq{INSERT INTO agents (budget_id, firstname, lastname, fullname, codename) VALUES ($budget_id, '$new_firstname{$i}', '$new_lastname{$i}', '$new_firstname{$i} $new_lastname{$i} ','$new_codename{$i}')}); + # my $sql = (qq{INSERT INTO agents (budget_id, firstname, lastname, codename) VALUES ($budget_id, '$new_firstname{i}', '$new_lastname{i}', '$new_codename{i}')}); + my $sth = $dbh->prepare($sql); + $sth->execute; + } + } + + # read back agent info + + &print_header; + print "
\n"; + print "
\n"; + print "
\n"; + print "\n"; + + + print "
feral budget generator
\n"; + print "
\n"; + + print "
\n"; + print "\n"; + print "{name}\">\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + + print "\n"; + print "\n"; + print "\n"; + + $dbh->disconnect; +} + +############################################################################ +# add form + +sub add_form { + + &print_header; + print "
\n"; + print " $projectname: add a budget \n"; + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id); + my $sth = $dbh->prepare($sql); + $sth->execute; + + print "

 

\n"; + print "\n"; + print "
\n"; + print ""; + while (my $record = $sth->fetchrow_hashref) { + print ""; + print ""; + print ""; + print ""; + } + print "\n"; + + $dbh->disconnect; + + print "\n"; + print "\n"; + print "\n"; + print "\n"; + #print "\n"; + #print "\n"; + print "\n"; + print "\n"; + print "
BudgetDate
"; + print "{id}\">$record->{name} $record->{date}
 
add a new budget
\n"; + print "
date
"; + + print "

\n"; + + print "
 
password

\n"; + + &print_footer; + + $dbh->disconnect; +} + + +############################################################################### +# add budget + +sub add_budget { + + #if ($password eq $admin_password) { + + ### test if workshop exists already in database + if ($new_name ne '') { + + $new_name_found='false'; + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + my $sql = qq( SELECT DISTINCT name FROM budgets); + my $sth = $dbh->prepare($sql); + $sth->execute; + + while (my $record = $sth->fetchrow_hashref) { + if ($record->{name} eq $new_name) { + $new_name_found='true'; + } + } + + if ($new_name_found eq 'false') { + + my $sql = (qq{INSERT INTO budgets (name) VALUES ('$new_name')}); + my $sth = $dbh->prepare($sql); + $sth->execute; + + my $sql2 = (qq{ SELECT * from budgets where name='$new_name'}); + my $sth2 = $dbh->prepare($sql2); + $sth2->execute; + + $dbh->disconnect; + + &print_header; + + while (my $record2 = $sth2->fetchrow_hashref) { + print "
\n"; + print "\n"; + print "\n"; + print "
budget added {id}\">$new_name
\n"; + } + &print_footer; + + } else { + &print_header; + print "duplicate budget entry
\n"; + &print_footer; + } + } else { + &print_header; + print "no budget entered
\n"; + &print_footer; + } + + #} else { + + #&print_header; + #print "

Wrong password !

\n"; + #&print_footer; + + # } +} + + +############################################################################### +# add budget information + +sub add_budget_information { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + my $sql = (qq{UPDATE budgets SET location='$new_location', deliver_date='$new_deliver_date', remarks='$new_remarks', + WHERE name='$new_name'}); + my $sth = $dbh->prepare($sql); + $sth->execute; + + $dbh->disconnect; + &print_header; + + print "

\n"; + print " $projectname: $new_name added "; + #print "$add_information \n"; + print "

view all budgets

\n"; + print "

\n"; + + &print_footer; +} + +############################################################################### +# edit select form: select which budget to edit + +sub edit_select_form { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id); + my $sth = $dbh->prepare($sql); + $sth->execute; + + &print_header; + + print "
\n"; + print " edit a budget
\n"; + print "\n"; + print "\n"; + print "\n"; + while (my $record = $sth->fetchrow_hashref) { + print " \n"; + print " \n"; + print "\n"; + print "
{id}\"$record->{name}\n"; + } + + print "
\n"; + + $dbh->disconnect; + + &print_footer; + +} + +############################################################################### +# edit form: edit selected budget + +sub edit_form { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + my $sql = qq( SELECT DISTINCT * FROM budgets WHERE id=$edit_id); + my $sth = $dbh->prepare($sql); + $sth->execute; + + &print_header; + + print "
\n"; + + print "

$projectname: edit budget

\n"; + # print "\"\"\n"; + + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + + while (my $record = $sth->fetchrow_hashref) { + + print "\n"; + print "\n"; + print "\n"; + + print "\n"; + print "\n"; + + print "\n"; + # print "\n"; + print "\n"; + print "\n"; + print "
 
{name}\"size=50 maxsize=100>
{location}\"size=50 maxsize=100> location
{url}\"size=100 maxsize=100> url
Remarks: When, where, who
password
\n"; + print "
\n"; + + } + &print_footer; +} + +############################################################################### +# present budget: present singlebudget + +sub present_budget { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + my $sql = qq( SELECT DISTINCT * FROM budgets WHERE id=$edit_id); + my $sth = $dbh->prepare($sql); + $sth->execute; + + &print_header; + + # print "
\n"; + + print "

$projectname: budget notes

\n"; + # print "\"\"\n"; + + print "\n"; + print "\n"; + + while (my $record = $sth->fetchrow_hashref) { + + $record->{remarks} =~ s/\n/\
/g; + + print "\n"; + print "\n"; + # print "\n"; + + print "\n"; + print "\n"; + # print "\n"; + + + # print "\n"; + print "\n"; + print "
$record->{name}, \n"; + print "$record->{location} 
{url}\">$record->{url}
Remarks: When, where, who
$record->{remarks}
password
\n"; + print "
\n"; + + } + &print_footer; +} + + +############################################################################### +# edit budget: edit budget results + +sub edit_budget { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + #if ($password eq $admin_password) { + + &print_header; + + ### update budgets table + + my $sql_update = (qq{UPDATE budgets SET name='$new_name', location='$new_location', url='$new_url', remarks='$new_remarks', deliver_date="$new_deliver_date" WHERE id='$edit_id'}); + my $sth_update = $dbh->prepare($sql_update); + $sth_update->execute; + + + ### display results + + my $sql = qq( SELECT * FROM budgets WHERE id = '$edit_id'); + my $sth = $dbh->prepare($sql); + $sth->execute; + + while (my $record = $sth->fetchrow_hashref) { + + print "
\n"; + # print "\"\"\n"; + print "\n"; + print "\n"; + print "\n"; + print "
updated
$record->{name}

"; + } + + $dbh->disconnect; + &print_footer; + +} + +############################################################################### +# delete form: select a budget to delete + +sub delete_form { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id); + my $sth = $dbh->prepare($sql); + $sth->execute; + + &print_header; + + print "
\n"; + print " delete a budget
\n"; + print "\n"; + print "\n"; + print "\n"; + + while (my $record = $sth->fetchrow_hashref) { + # print "{name}\">\n"; + print " \n"; + print " \n"; + print "\n"; + print "\n"; + print "
{id}\"$record->{name}\n"; + print "$record->{location}\n"; + } + + print "
password
\n"; + + $dbh->disconnect; + &print_footer; +} + +############################################################################### +# delete budget: budget delete results + +sub delete_budget { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + + my $sql = (qq{SELECT * FROM budgets WHERE id = '$delete_id'}); + my $sth = $dbh->prepare($sql); + $sth->execute; + + my $sql2 = (qq{DELETE FROM budgets WHERE id = '$delete_id'}); + my $sth2 = $dbh->prepare($sql2); + $sth2->execute; + + while (my $record = $sth->fetchrow_hashref) { + + &print_header; + + print "$record->{name} deleted\n"; + + } + + &print_footer; + $dbh->disconnect; + +} + +############################################################################### +# display budget: displays all budgets + +sub display_budgets { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id); + my $sth = $dbh->prepare($sql); + $sth->execute; + + &print_header; + + print "
\n"; + print "

$projectname: all budgets: edit mode

\n"; + + print "\n"; + print "\n"; + while (my $record = $sth->fetchrow_hashref) { + print "\n"; + print ""; + print ""; + print ""; + print ""; + # print ""; + print "\n"; + } + + $dbh->disconnect; + + print"
BudgetLocationDateURL
{id}\">$record->{name}$record->{location}$record->{deliver_date}{url}\">$record->{url}{id}.jpg\" width=\"100\"border=\"0\" title=\"edit $record->{name}\" alt=\"\">
\n"; + &print_footer; +} + + +############################################################################### +# list budgets: list all budgets, non-edit mode + +sub list_budgets { + + my $dbh = DBI->connect($db_conect,$db_user,$db_pass) + or die ("can't connect: $DBI::errstr"); + my $sql = qq( SELECT DISTINCT * FROM budgets ORDER BY id); + my $sth = $dbh->prepare($sql); + $sth->execute; + + &print_header; + + print "
\n"; + print "

$projectname: all budgets: read-only

\n"; + + print "\n"; + print "\n"; + while (my $record = $sth->fetchrow_hashref) { + print "\n"; + print ""; + print ""; + print ""; + print ""; + # print ""; + print "\n"; + } + + $dbh->disconnect; + + print"
BudgetLocationDateURL
{id}\">$record->{name}$record->{location}$record->{deliver_date}{url}\">$record->{url}{id}.jpg\" width=\"100\"border=\"0\" title=\"edit $record->{name}\" alt=\"\">
\n"; + &print_footer; +} + +############################################################################################## + +# select start date subroutine + +sub select_start_date { + + ### day + print "
\n"; + + ### month + print "\n"; + + ### year + print "

all budgets: edit

all budgets: list

add a budget \ \; \|\n"; + print "delete a budget \ \; \n"; + + print "\n"; + print "\n"; + print "\n"; + +}