2008-10-22 21:46:31 +00:00
< ?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website : http :// www . sfiab . ca
2008-10-23 21:32:31 +00:00
Copyright ( C ) 2008 James Grant < james @ lightbox . org >
2008-10-22 21:46:31 +00:00
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation , version 2.
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; see the file COPYING . If not , write to
the Free Software Foundation , Inc . , 59 Temple Place - Suite 330 ,
Boston , MA 02111 - 1307 , USA .
*/
?>
< ?
require ( " ../common.inc.php " );
require ( " ../tableeditor.class.php " );
require_once ( " ../user.inc.php " );
user_auth_required ( 'committee' , 'admin' );
2008-10-23 21:32:31 +00:00
if ( $_POST [ 'action' ] == " sponsorshipedit " || $_POST [ 'action' ] == " sponsorshipadd " ) {
$sponsors_id = intval ( $_POST [ 'sponsors_id' ]);
$sponsorships_id = intval ( $_POST [ 'sponsorships_id' ]);
$fundraising_type = mysql_real_escape_string ( $_POST [ 'fundraising_type' ]);
$value = intval ( $_POST [ 'value' ]);
$status = mysql_real_escape_string ( $_POST [ 'status' ]);
$probability = mysql_real_escape_string ( $_POST [ 'probability' ]);
if ( $status == " confirmed " || $status == " received " ) $probability = " 100 " ;
if ( $probability == 100 && $status == " pending " ) $status = " confirmed " ;
}
if ( $_POST [ 'action' ] == " sponsorshipedit " ) {
if ( $sponsorships_id && $sponsors_id && $fundraising_type && $value ) {
mysql_query ( " UPDATE sponsorships SET sponsors_id=' $sponsors_id ', fundraising_type=' $fundraising_type ', value=' $value ', status=' $status ', probability=' $probability ' WHERE id=' $sponsorships_id ' " );
if ( mysql_error ())
message_push ( error ( mysql_error ()));
else
message_push ( happy ( i18n ( " Saved sponsorship changes " )));
}
else
message_push ( error ( i18n ( " Required fields were missing, please try again " )));
}
if ( $_POST [ 'action' ] == " sponsorshipadd " ) {
if ( $sponsors_id && $fundraising_type && $value ) {
mysql_query ( " INSERT INTO sponsorships (sponsors_id,fundraising_type,value,status,probability,year) VALUES (' $sponsors_id ',' $fundraising_type ',' $value ',' $status ',' $probability ',' { $config [ 'FAIRYEAR' ] } ') " );
message_push ( happy ( i18n ( " Added new sponsorship " )));
}
else
message_push ( error ( i18n ( " Required fields were missing, please try again " )));
if ( mysql_error ())
message_push ( error ( mysql_error ()));
}
2008-10-22 21:46:31 +00:00
send_header ( " Fundraising " ,
array ( 'Committee Main' => 'committee_main.php' ,
'Administration' => 'admin/index.php' ),
" fundraising "
);
2008-10-23 21:32:31 +00:00
require_once ( " ../ajax.inc.php " );
?>
< div class = " SFIABDialog " id = " SFIABDialog " style = " position: absolute; visibility: hidden; " >
< div class = " SFIABDialogInner " id = " SFIABDialogInner " ></ div >
</ div >
< script type = " text/javascript " >
function SFIABDialogSubmit () {
//we let it submit the form, which reloads the page
return true ;
}
function SFIABDialogCancel () {
var d = document . getElementById ( 'SFIABDialog' );
var di = document . getElementById ( 'SFIABDialogInner' );
d . style . visibility = " hidden " ;
di . style . visibility = " hidden " ;
return false ;
}
var SFIABDialogGrowWidth = 0 ;
var SFIABDialogGrowHeight = 0 ;
var SFIABDialogFinalWidth = 100 ;
var SFIABDialogFinalHeight = 100 ;
var SFIABDialogGrowWidthStep = 0 ;
var SFIABDialogGrowHeightStep = 0 ;
var SFIABDialogGrowTime = 200 ; //1 second
var SFIABDialogGrowSteps = 10 ;
function SFIABDialog ( e , url , width , height ) {
var posx = 0 ;
var posy = 0 ;
//get this going while we do the other stuff
SFIABDialogFill ( url );
if ( ! e ) var e = window . event ;
if ( e . pageX || e . pageY ) {
posx = e . pageX ;
posy = e . pageY ;
}
else if ( e . clientX || e . clientY ) {
posx = e . clientX + document . body . scrollLeft + document . documentElement . scrollLeft ;
posy = e . clientY + document . body . scrollTop + document . documentElement . scrollTop ;
}
var d = document . getElementById ( 'SFIABDialog' );
var di = document . getElementById ( 'SFIABDialogInner' );
d . style . top = posy + 'px' ;
d . style . left = posx + 'px' ;
d . style . visibility = 'visible' ;
di . style . visibility = 'hidden' ;
SFIABDialogGrowWidth = 1 ;
SFIABDialogGrowHeight = 1 ;
SFIABDialogFinalWidth = width ;
SFIABDialogFinalHeight = height ;
d . style . width = SFIABDialogGrowWidth + " px " ;
d . style . height = SFIABDialogGrowHeight + " px " ;
SFIABDialogGrowWidthStep = Math . round ( width / SFIABDialogGrowSteps );
SFIABDialogGrowHeightStep = Math . round ( height / SFIABDialogGrowSteps );
setTimeout ( 'growDialog()' , Math . round ( SFIABDialogGrowTime / SFIABDialogGrowSteps ));
}
function growDialog () {
SFIABDialogGrowWidth += SFIABDialogGrowWidthStep ;
SFIABDialogGrowHeight += SFIABDialogGrowHeightStep ;
if ( SFIABDialogGrowWidth > SFIABDialogFinalWidth )
SFIABDialogGrowWidth = SFIABDialogFinalWidth ;
if ( SFIABDialogGrowHeight > SFIABDialogFinalHeight )
SFIABDialogGrowHeight = SFIABDialogFinalHeight ;
var d = document . getElementById ( 'SFIABDialog' );
d . style . width = SFIABDialogGrowWidth + " px " ;
d . style . height = SFIABDialogGrowHeight + " px " ;
if ( SFIABDialogGrowWidth < SFIABDialogFinalWidth || SFIABDialogGrowHeight < SFIABDialogFinalHeight )
setTimeout ( 'growDialog()' , Math . round ( SFIABDialogGrowTime / SFIABDialogGrowSteps ));
else {
var di = document . getElementById ( 'SFIABDialogInner' );
di . style . visibility = " visible " ;
}
}
function SFIABDialogFill ( url ) {
var d = document . getElementById ( 'SFIABDialogInner' );
d . innerHTML = " " ;
http . open ( " GET " , url , true );
http . onreadystatechange = SFIABDialogFillResponse ;
http . send ( null );
}
function SFIABDialogFillResponse () {
try {
if ( http . readyState == 4 ) {
var d = document . getElementById ( 'SFIABDialogInner' );
var objhtml = http . responseText ;
d . innerHTML = objhtml ;
}
}
catch ( e ) {
}
}
</ script >
< ?
2008-10-22 21:46:31 +00:00
//first, insert any defaults
$q = mysql_query ( " SELECT * FROM fundraising WHERE year=' " . $config [ 'FAIRYEAR' ] . " ' " );
if ( ! mysql_num_rows ( $q )) {
$q = mysql_query ( " SELECT * FROM fundraising WHERE year='-1' " );
while ( $r = mysql_fetch_object ( $q )) {
mysql_query ( " INSERT INTO fundraising (`type`,`name`,`system`,`goal`,`year`) VALUES (' $r->type ',' " . mysql_real_escape_string ( $r -> name ) . " ',' $r->system ',' $r->goal ',' " . $config [ 'FAIRYEAR' ] . " ') " );
}
}
//this table is eventually going to be massive, and probably not in a tableview format, it'll show goals as well as all ongoing fund pledges, probabilities, etc as well as over/under, etc, all prettily colour coded.. basically a good overview of the total fundraising status of the fair.
$q = mysql_query ( " SELECT * FROM fundraising WHERE year=' { $config [ 'FAIRYEAR' ] } ' ORDER BY system,type " );
2008-10-23 21:32:31 +00:00
echo " <table class= \" fundraisingtable \" > " ;
/*
2008-10-22 21:46:31 +00:00
echo " <tr> " ;
2008-10-23 21:32:31 +00:00
echo " <th colspan= \" 2 \" > " . i18n ( " Fund " ) . " </th> \n " ;
2008-10-22 21:46:31 +00:00
echo " <th> " . i18n ( " Goal " ) . " </th> \n " ;
echo " </tr> \n " ;
2008-10-23 21:32:31 +00:00
*/
2008-10-22 21:46:31 +00:00
while ( $r = mysql_fetch_object ( $q )) {
echo " <tr> " ;
2008-10-23 21:32:31 +00:00
echo " <th colspan= \" 6 \" > " . i18n ( $r -> name ) . " </th> \n " ;
echo " <th style= \" text-align: right \" > " . format_money ( $r -> goal ) . " </th> \n " ;
echo " </tr> \n " ;
if ( $r -> type == " general " )
$orsql .= " OR fundraising_type IS NULL " ;
$typetotal = 0 ;
$sq = mysql_query ( " SELECT sponsorships.id, sponsors.organization, sponsorships.value, sponsorships.status, sponsorships.probability
FROM sponsorships
JOIN sponsors ON sponsorships . sponsors_id = sponsors . id
WHERE ( sponsorships . fundraising_type = '$r->type' $orsql )
AND sponsorships . year = '{$config[' FAIRYEAR ']}' " );
while ( $sr = mysql_fetch_object ( $sq )) {
echo " <tr id= \" sponsorships_ $sr->id\ " class = \ " fundraising { $sr -> status } \" ><td width= \" 30 \" ><a onclick= \" return SFIABDialog(event,'sponsorship.php?id= $sr->id &fundraising_type= $r->type ',300,200) \" href= \" # \" >edit</a></td><td> $sr->organization </td> \n " ;
echo " <td> $sr->status </td> " ;
echo " <td> " ;
if ( $sr -> status == " pending " )
{
echo " $sr->probability % " ;
echo " </td> " ;
echo " <td> " . format_money ( $sr -> value ) . " </td> " ;
}
else
echo " </td><td></td> \n " ;
$probval = $sr -> probability / 100 * $sr -> value ;
echo " <td style= \" text-align: right \" > " . format_money ( $probval ) . " </td> " ;
echo " <td></td> \n " ;
echo " </tr> \n " ;
$typetotal += $probval ;
}
echo " <tr> " ;
echo " <td><a onclick= \" return SFIABDialog(event,'sponsorship.php?fundraising_type= $r->type ',300,200) \" href= \" # \" >add</a></td> " ;
echo " <td colspan= \" 4 \" style= \" text-align: right; font-weight: bold; \" > " . i18n ( " %1 Total " , array ( $r -> name ), array ( " Fundraising type total, eg) Award Sponsorship Total " )) . " </td> \n " ;
echo " <td style= \" font-weight: bold; text-align: right; \" > " . format_money ( $typetotal ) . " </td> \n " ;
$typediff = $typetotal - $r -> goal ;
echo " <td style= \" font-weight: bold; text-align: right; \" > " . format_money ( $typediff ) . " </td> \n " ;
echo " </tr> \n " ;
2008-10-22 21:46:31 +00:00
$totalgoal += $r -> goal ;
2008-10-23 21:32:31 +00:00
$totaldiff += $typediff ;
echo " <tr><td colspan= \" 7 \" > </td></tr> \n " ;
2008-10-22 21:46:31 +00:00
}
2008-10-23 21:32:31 +00:00
echo " <tr><td colspan= \" 6 \" style= \" font-weight: bold; text-align: right; \" > " . i18n ( " Total Net Position " ) . " </td><td style= \" text-align: right; font-weight: bold; \" > " . format_money ( $totaldiff ) . " </td></tr> \n " ;
2008-10-22 21:46:31 +00:00
echo " </table> \n " ;
echo " <a href= \" fundraising_types.php \" > " . i18n ( " Edit fund types and goals " ) . " </a> \n " ;
send_footer ();
?>