function Finances()
{
global $llimit,$rowsonpage;
$Buffer = '
Date Received |
Type |
Amount ($) | '
#Comment |
.'Entry |
';
if ($llimit==-1)
{
# -1 defined as default:
# this means show the last record!
$QueryResult = mysql_query("select count(*) from finances");
$finances_count = mysql_fetch_array($QueryResult);
#$llimit=$finances_count[0]-$rowsonpage;
$llimit=intval($finances_count[0]/10)*10;
if ($llimit<0)
{
$llimit=0;
}
}
$prevTotal=0;
$uppertable=' Here we will list the names of all the donors to the Arabeyes project (unless they have asked to remain anonymous). We will also reflect the dollar amount of the sum of donations.
| ';
#echo $rowsonpage;
if ($rowsonpage==-1)
{
$sql="select * from finances order by date";
}
else
{
$QueryResult = mysql_query("select Amount,Type from finances order by date asc limit 0,".strval($llimit));
while($QueryRow = mysql_fetch_array($QueryResult))
{
$prevTotal = ($QueryRow[Type]=="Deposit")?$prevTotal+$QueryRow[Amount]: $prevTotal-$QueryRow[Amount];
}
$QueryResult = mysql_query("select count(*) from finances");
$QueryRow = mysql_fetch_array($QueryResult);
$lastrow = $QueryRow[0];
$previouslink="";
$nextlink="";
if ($llimit==0)
{
$previouslink="finance.php";
$previouslink="";
}
elseif ($llimit-$rowsonpage<=0)
{
$previouslink="finance.php?llimit=0&rowsonpage=".$rowsonpage;
$previouslink='Previous';
}
else
{
$previouslink="finance.php?llimit=".strval($llimit-$rowsonpage)."&rowsonpage=".$rowsonpage;
$previouslink='Previous';
}
if ($llimit+$rowsonpage>=$lastrow)
{
$nextlink="";
}
#elseif($llimit+2*$rowsonpage>=$lastrow)
# {
# $nextlink="finance.php?rowsonpage=".$rowsonpage;
# $nextlink=' Next';
# }
else
{
$nextlink="finance.php?llimit=".($llimit+$rowsonpage)."&rowsonpage=".$rowsonpage;
$nextlink=' Next';
}
$uppertable.=''.$previouslink.$nextlink.' |
|
[Balance from previous pages = ';
$uppertable=($prevTotal>=0)?$uppertable.'+$':$uppertable.'-$';
$uppertable.=sprintf("%.2f", abs($prevTotal)).'] |
| ';
$sql="select * from finances order by date limit ";
$sql.=$llimit.",".strval($rowsonpage);
}
#echo $sql;
$QueryResult = mysql_query($sql);
$Total = 0;
while($QueryRow = mysql_fetch_array($QueryResult))
{
$Total = ($QueryRow[Type]=="Deposit")?$Total+$QueryRow[Amount]: $Total-$QueryRow[Amount];
$Buffer = ($QueryRow[Type]=='Deposit')?$Buffer.'
':$Buffer.'
';
$Buffer .= ''.$QueryRow[date].' | ';
$Buffer .= ''.$QueryRow[Type].' | ';
$Buffer .= ''.sprintf("%.2f", $QueryRow[Amount]).' | ';
#$Buffer .= ''.$QueryRow[Comment].' | '; #originally, changed!!
if ($QueryRow[private] == 1)
$Buffer .= 'Anonymous | ';
else
{
$Buffer .= ''.$QueryRow[firstname].' '.$QueryRow[lastname].' | ';
if(isset($_SESSION[type]) && $_SESSION[type] == 'c')
{
$Buffer .= '  | ';
}
$Buffer .= '';
}
$Buffer .= '
';
$Buffer .= ' | '.$QueryRow[Comment].' |
'; #originally, changed!!
}
$Buffer .= '
|
';
$Buffer .= 'Balance in Account | '.strval(($Total+$prevTotal>=0)?'+$':'-$').sprintf("%.2f", abs($Total+$prevTotal)).' |
';
$uppertable.='[Balance on current page = ';
$uppertable=($Total>=0)?$uppertable.'+$':$uppertable.'-$';
$uppertable.=sprintf("%.2f", abs($Total)).'] |
|
[Balance total in account = ';
$uppertable=strval(($Total+$prevTotal>=0)?$uppertable.'+$':$uppertable.'-$').sprintf("%.2f", abs($Total+$prevTotal)).']] |
|
|
';
$Buffer = $uppertable.$Buffer;
return DisplaySection('Donations Records (since '.GetDonationsStartdate().')', $Buffer);
}
function addrow_finance($date,$type,$amount,$comment,$firstname,$lastname,$private)
{
global $llimit,$rowsonpage;
if(isset($_SESSION[type]) && $_SESSION[type] == 'c')
{
$sql="INSERT INTO finances ( ID , date , Type , Amount , Comment , firstname , lastname , private )
VALUES ('', '".$date."', '".$type."', '".$amount."', '".$comment."', '".$firstname."', '".$lastname."', '".$private."');";
#echo $sql;
$QueryResult = mysql_query($sql);
}
header("Location: finance.php?llimit=".$llimit."&rowsonpage=".$rowsonpage);
exit;
}
function modrow_finance($id,$date,$type,$amount,$comment,$firstname,$lastname,$private)
{
global $llimit,$rowsonpage;
if(isset($_SESSION[type]) && $_SESSION[type] == 'c')
{
$sql="Update finances set date=\"$date\", Type=\"$type\", Amount=\"$amount\" , Comment=\"$comment\" , firstname=\"$firstname\" , lastname=\"$lastname\" , private=\"$private\" where id=$id";
#echo $sql;
$QueryResult = mysql_query($sql);
}
header("Location: finance.php?llimit=".$llimit."&rowsonpage=".$rowsonpage);
exit;
}
function delrow_finance($id)
{
global $llimit,$rowsonpage;
if(isset($_SESSION[type]) && $_SESSION[type] == 'c')
{
$sql="delete from finances where ID=".$id;
$QueryResult = mysql_query($sql);
}
header("Location: finance.php?llimit=".$llimit."&rowsonpage=".$rowsonpage);
exit;
}
function showadd_finance()
{
$Buffer="";
if(isset($_SESSION[type]) && $_SESSION[type] == 'c')
{
$Buffer="";
}
return $Buffer;
}
function showmod_finance($id)
{
$Buffer="";
$sql="select * from finances where id=".$id.";";
$Buffer="haöö";
if(isset($_SESSION[type]) && $_SESSION[type] == 'c')
{
$QueryResult = mysql_query($sql);
if($QueryRow = mysql_fetch_array($QueryResult))
{
$Buffer="";
}
}
return $Buffer;
}
function show_financeoptions()
{
global $rowsonpage,$llimit;
$validrowspp=array(5,10,20,50,100,-1);
reset($validrowspp);
$Buffer="";
return $Buffer;
}