2009-10-01 21:03:56 +00:00
< ?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website : http :// www . sfiab . ca
Copyright ( C ) 2009 James Grant < james @ lightbox . org >
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_once ( " ../user.inc.php " );
user_auth_required ( 'committee' , 'admin' );
2009-10-07 19:43:58 +00:00
2009-10-06 21:32:13 +00:00
switch ( $_GET [ 'action' ]){
case " campaigninfo_save " :
save_campaign_info ();
exit ;
break ;
2009-10-07 19:43:58 +00:00
2009-10-07 21:22:23 +00:00
case " modify " :
2009-10-07 19:43:58 +00:00
echo " <div id= \" campaignaccordion \" style= \" width: 780px; \" > \n " ;
$q = mysql_query ( " SELECT * FROM fundraising_campaigns WHERE fiscalyear=' { $config [ 'FISCALYEAR' ] } ' ORDER BY name " );
while ( $r = mysql_fetch_object ( $q )) {
echo " <h3><a href= \" # \" > " . htmlspecialchars ( $r -> name ) . " </a></h3> \n " ;
echo " <div id= \" campaign_ { $r -> id } \" > \n " ;
echo " <form id= \" campaigninfo_ { $r -> id } \" method= \" post \" action= \" { $_SERVER [ 'PHP_SELF' ] } \" onsubmit= \" return campaigninfo_save( $r->id ) \" > \n " ;
echo " <input type= \" hidden \" name= \" campaign_id \" value= \" { $r -> id } \" /> \n " ;
echo " <table> \n " ;
display_campaign_form ( $r );
?>
< tr >< td colspan = " 6 " style = " text-align: center; " >
< br />
< input type = " submit " value = " <?=i18n( " Save Campaign " )?> " ></ td >
</ tr >
</ table >
</ form >
</ div >
< ?
}
?>
< h3 >< a href = " # " >< ? = i18n ( " Create New Campaign " ) ?> </a></h3>
< div id = " campaign_new " >
< form id = " campaigninfo_new " method = " post " action = " <?= $_SERVER['PHP_SELF'] ?> " onsubmit = " return campaigninfo_save(-1) " >
< input type = " hidden " name = " campaign_id " value = " -1 " />
< table >
< ?
display_campaign_form ();
?>
< tr >< td colspan = " 6 " style = " text-align: center; " >
< br />
< input type = " submit " value = " <?=i18n( " Create Campaign " )?> " ></ td >
</ tr >
</ table >
</ form >
</ div >
</ div >
< ?
exit ;
break ;
2009-10-07 21:22:23 +00:00
case " managelist " :
echo i18n ( " Select a campaign " );
?>
< table class = " tableview " >
< tr >
< th >< ? = i18n ( " Name " ) ?> </th>
< th >< ? = i18n ( " Type " ) ?> </th>
< th >< ? = i18n ( " Start Date " ) ?> </th>
< th >< ? = i18n ( " End Date " ) ?> </th>
< th >< ? = i18n ( " Goal " ) ?> </th>
< th >< ? = i18n ( " Target( $ ) " ) ?> </th>
< th >< ? = i18n ( " Received " ) ?> </th>
< th >< ? = i18n ( " % to Budget " ) ?> </th>
</ tr >
< ?
$q = mysql_query ( " SELECT * FROM fundraising_campaigns WHERE fiscalyear=' { $config [ 'FISCALYEAR' ] } ' " );
while ( $r = mysql_fetch_object ( $q )) {
$goalq = mysql_query ( " SELECT * FROM fundraising_goals WHERE goal=' { $r -> fundraising_goal } ' AND fiscalyear=' { $config [ 'FISCALYEAR' ] } ' " );
$goalr = mysql_fetch_object ( $goalq );
$recq = mysql_query ( " SELECT SUM(value) AS received FROM fundraising_donations WHERE fundraising_campaigns_id=' $r->id ' AND fiscalyear=' { $config [ 'FISCALYEAR' ] } ' AND status='received' " );
echo mysql_error ();
$recr = mysql_fetch_object ( $recq );
$received = $recr -> received ;
if ( $r -> budget )
$percent = round ( $received / $r -> target * 100 , 1 );
else
$percent = 0 ;
$col = colour_to_percent ( $percent );
echo " <tr style= \" cursor:pointer; \" onclick= \" return managecampaign( $r->id ) \" > \n " ;
echo " <td> $r->name </td> \n " ;
echo " <td> $r->type </td> \n " ;
echo " <td> " . format_date ( $r -> startdate ) . " </td> \n " ;
echo " <td> " . format_date ( $r -> enddate ) . " </td> " ;
echo " <td> $goalr->name </td> " ;
echo " <td style= \" text-align: right; \" > " . format_money ( $r -> target , false ) . " </td> \n " ;
echo " <td style= \" text-align: right; \" > " . format_money ( $received , false ) . " </td> \n " ;
echo " <td style= \" text-align: center; background-color: $col ; \" > { $percent } %</td> \n " ;
echo " </tr> \n " ;
}
?>
</ table >
< br />
< ?
exit ;
break ;
2009-10-07 21:44:32 +00:00
2009-10-07 21:22:23 +00:00
case " manage " :
if ( ! $_GET [ 'id' ]) {
error_ ( " Missing campaign to manage " );
exit ;
}
$id = intval ( $_GET [ 'id' ]);
$q = mysql_query ( " SELECT * FROM fundraising_campaigns WHERE id=' $id ' " );
$campaign = mysql_fetch_object ( $q );
echo " <h3> $campaign->name </h3> \n " ;
?>
< div id = " campaign_tabs " >
< ul >
< li >< a href = " #campaign_tab_overview " >< span >< ? = i18n ( 'Overview' ) ?> </span></a></li>
< li >< a href = " #campaign_tab_donations " >< span >< ? = i18n ( 'Donations/Sponsorships' ) ?> </span></a></li>
< li >< a href = " #campaign_tab_prospects " >< span >< ? = i18n ( 'Prospects' ) ?> </span></a></li>
< li >< a href = " #campaign_tab_communications " >< span >< ? = i18n ( 'Communications' ) ?> </span></a></li>
</ ul >
< div id = " campaign_tab_overview " >
overview tab
</ div >
< div id = " campaign_tab_donations " >
donations tab
</ div >
< div id = " campaign_tab_prospects " >
prospects tab
</ div >
< div id = " campaign_tab_communications " >
communications tab
</ div >
</ div >
< ?
exit ;
break ;
2009-10-07 21:44:32 +00:00
case " manage_tab_overview " :
$campaign_id = intval ( $_GET [ 'id' ]);
$q = mysql_query ( " SELECT * FROM fundraising_campaigns WHERE id=' $campaign_id ' AND fiscalyear=' { $config [ 'FISCALYEAR' ] } ' " );
if ( $r = mysql_fetch_object ( $q )) {
$goalq = mysql_query ( " SELECT * FROM fundraising_goals WHERE goal=' { $r -> fundraising_goal } ' AND fiscalyear=' { $config [ 'FISCALYEAR' ] } ' " );
$goalr = mysql_fetch_object ( $goalq );
$recq = mysql_query ( " SELECT SUM(value) AS received FROM fundraising_donations WHERE fundraising_campaigns_id=' $r->id ' AND fiscalyear=' { $config [ 'FISCALYEAR' ] } ' AND status='received' " );
echo mysql_error ();
$recr = mysql_fetch_object ( $recq );
$received = $recr -> received ;
if ( $r -> budget )
$percent = round ( $received / $r -> target * 100 , 1 );
else
$percent = 0 ;
$col = colour_to_percent ( $percent );
echo " <table cellspacing= \" 3 \" cellpadding= \" 3 \" > " ;
echo " <tr> \n " ;
echo " <td>Type</td><td> $r->type </td></tr> \n " ;
echo " <td>Start Date</td><td> " . format_date ( $r -> startdate ) . " </td> \n " ;
echo " </tr> \n " ;
echo " <td>Follow-Up Date</td><td> " . format_date ( $r -> enddate ) . " </td> " ;
echo " </tr> \n " ;
echo " <td>Default Goal</td><td> $goalr->name </td> " ;
echo " </tr> \n " ;
echo " <td>Target</td><td> " . format_money ( $r -> target , false ) . " </td> \n " ;
echo " </tr> \n " ;
echo " <td>Received</td><td> " . format_money ( $received , false ) . " </td> \n " ;
echo " </tr> \n " ;
echo " <td>% to Budget</td><td style= \" color: $col ; \" > { $percent } %</td> \n " ;
echo " </tr> \n " ;
echo " </table> \n " ;
}
exit ;
break ;
2009-10-06 21:32:13 +00:00
}
function save_campaign_info (){
2009-10-07 19:43:58 +00:00
global $config ;
if ( ! $_POST [ 'name' ]){
error_ ( " Campaign Name is required " );
return ;
}
if ( ! $_POST [ 'startdate' ]) $startdate = date ( " Y-m-d " ); else $startdate = $_POST [ 'startdate' ];
if ( ! $_GET [ 'id' ]) {
$query = " INSERT INTO fundraising_campaigns (name,fiscalyear) VALUES (
'".mysql_real_escape_string($_POST[' name '])."' , '{$config[' FISCALYEAR ']}' ) " ;
mysql_query ( $query );
2009-10-06 21:32:13 +00:00
$id = mysql_insert_id ();
2009-10-07 19:43:58 +00:00
happy_ ( " Campaign Created " );
2009-10-06 21:32:13 +00:00
} else {
2009-10-07 19:43:58 +00:00
$id = $_GET [ " id " ];
happy_ ( " Campaign Saved " );
}
mysql_query ( " UPDATE fundraising_campaigns SET
name = '".mysql_real_escape_string($_POST[' name '])."' ,
`type` = '".mysql_real_escape_string($_POST[' type '])."' ,
startdate = '".mysql_real_escape_string($startdate)."' ,
followupdate = '".mysql_real_escape_string($_POST[' followupdate '])."' ,
enddate = '".mysql_real_escape_string($_POST[' enddate '])."' ,
target = '".mysql_real_escape_string($_POST[' target '])."' ,
fundraising_goal = '".mysql_real_escape_string($_POST[' fundraising_goal '])."'
WHERE id = '$id' " );
2009-10-06 21:32:13 +00:00
}
send_header ( " Campaign Management " ,
2009-10-01 21:03:56 +00:00
array ( 'Committee Main' => 'committee_main.php' ,
'Administration' => 'admin/index.php' ,
'Fundraising' => 'admin/fundraising.php' ),
" fundraising "
);
?>
2009-10-06 21:32:13 +00:00
2009-10-01 21:03:56 +00:00
< script type = " text/javascript " >
$ ( document ) . ready ( function () {
2009-10-07 21:22:23 +00:00
managecampaigns ();
2009-10-01 21:03:56 +00:00
});
2009-10-06 21:32:13 +00:00
2009-10-07 21:22:23 +00:00
function modifycampaigns () {
$ ( " #campaigndiv " ) . show ();
$ ( " #campaigndiv " ) . load ( " <? $_SERVER['PHP_SELF'] ?>?action=modify " , null , function () { modifycampaignsfinish ();});
}
function managecampaigns () {
$ ( " #campaigndiv " ) . show ();
$ ( " #campaigndiv " ) . load ( " <? $_SERVER['PHP_SELF'] ?>?action=managelist " , null , function () { managecampaignsfinish ();});
}
2009-10-07 21:44:32 +00:00
var currentcampaignid ;
2009-10-07 21:22:23 +00:00
function managecampaign ( id ) {
$ ( " #campaigndiv " ) . show ();
$ ( " #campaigndiv " ) . load ( " <? $_SERVER['PHP_SELF'] ?>?action=manage&id= " + id , null , function () { managecampaignfinish ();});
2009-10-07 21:44:32 +00:00
currentcampaignid = id ;
2009-10-07 19:43:58 +00:00
}
2009-10-07 21:22:23 +00:00
function modifycampaignsfinish (){
2009-10-07 19:43:58 +00:00
$ ( " #campaignaccordion " ) . accordion ();
2009-10-06 21:32:13 +00:00
// create the date pickers for our form
2009-10-07 19:43:58 +00:00
$ ( " .date " ) . datepicker ({
2009-10-06 21:32:13 +00:00
dateFormat : 'yy-mm-dd'
});
}
2009-10-07 21:22:23 +00:00
function managecampaignsfinish () {
}
function managecampaignfinish () {
$ ( " #campaign_tabs " ) . tabs ({
show : function ( event , ui ) {
switch ( ui . panel . id ) {
case 'campaign_tab_overview' :
2009-10-07 21:44:32 +00:00
update_tab_overview ();
2009-10-07 21:22:23 +00:00
break ;
case 'campaign_tab_donations' :
// update_sponsorshipinfo();
break ;
case 'campaign_tab_prospects' :
// update_contactsinfo();
break ;
case 'campaign_tab_communications' :
// update_activityinfo();
break ;
}
},
selected : 0 ,
});
}
2009-10-07 19:43:58 +00:00
function campaigninfo_save ( id ) {
2009-10-06 21:32:13 +00:00
//if we're creating we need to do the post, and get the id it returns, so we can re-open the popup window with that id
2009-10-07 19:43:58 +00:00
if ( id ==- 1 ) {
2009-10-07 21:22:23 +00:00
$ ( " #debug " ) . load ( " <? $_SERVER['PHP_SELF'] ?>?action=campaigninfo_save " , $ ( " #campaigninfo_new " ) . serializeArray (), function () { modifycampaigns (); });
2009-10-06 21:32:13 +00:00
} else {
2009-10-07 21:22:23 +00:00
$ ( " #debug " ) . load ( " <? $_SERVER['PHP_SELF'] ?>?action=campaigninfo_save&id= " + id , $ ( " #campaigninfo_ " + id ) . serializeArray (), function () { modifycampaigns (); });
2009-10-06 21:32:13 +00:00
}
return false ;
}
2009-10-07 21:44:32 +00:00
function update_tab_overview () {
$ ( " #campaign_tab_overview " ) . load ( " <? $_SERVER['PHP_SELF'] ?>?action=manage_tab_overview&id= " + currentcampaignid );
}
2009-10-01 21:03:56 +00:00
</ script >
2009-10-06 21:32:13 +00:00
2009-10-07 19:43:58 +00:00
< ?
function display_campaign_form ( $r = null ) {
global $config ;
?>
2009-10-06 21:32:13 +00:00
< tr >
2009-10-07 19:43:58 +00:00
< td >< ? = i18n ( " Name " ) ?> </td>
< td colspan = " 3 " >< input size = " 40 " type = " text " name = " name " value = " <?= $r->name ?> " ></ td >
< td >< ? = i18n ( " Type " ) ?> </td><td><input type="text" name="type" value="<?=$r->type?>"></td>
</ tr >
< ?
if ( $r -> startdate ) $sd = $r -> startdate ;
else $sd = date ( " Y-m-d " );
?>
< tr >
< td >< ? = i18n ( " Start Date " ) ?> </td><td><input type="text" name="startdate" class="date" value="<?=$sd?>" /></td>
< td >< ? = i18n ( " Follow-Up Date " ) ?> </td><td><input type="text" name="followupdate" class="date" value="<?=$r->followupdate?>" /></td>
< td >< ? = i18n ( " End Date " ) ?> </td><td><input type="text" name="enddate" class="date" value="<?=$r->enddate?>" /></td>
</ tr >
< tr >
< td >< ? = i18n ( " Target " ) ?> </td><td>$<input type="text" id="target" name="target" size="10" value="<?=$r->target?>" /></td>
< td >< ? = i18n ( " Default Goal " ) ?> </td><td colspan="3">
< ?
$fgq = mysql_query ( " SELECT * FROM fundraising_goals WHERE fiscalyear=' { $config [ 'FISCALYEAR' ] } ' ORDER BY name " );
echo " <select name= \" fundraising_goal \" > " ;
echo " <option value= \" \" > " . i18n ( " Choose Default Goal " ) . " </option> \n " ;
while ( $fgr = mysql_fetch_object ( $fgq )) {
if ( $r -> fundraising_goal == $fgr -> goal ) $sel = " selected= \" selected \" " ; else $sel = " " ;
echo " <option $sel value= \" $fgr->goal\ " > " .i18n( $fgr->name ). " </ option > \n " ;
}
echo " </select> \n " ;
?>
</ td >
</ tr >
< ?
}
?>
2009-10-07 21:22:23 +00:00
< table cellspacing = 2 width = 740 border = 0 >
< tr >< td >
< a href = " # " onclick = " modifycampaigns() " > Create / Modify Campaigns </ a >
</ td >< td >
< a href = " # " onclick = " managecampaigns() " > Campaign Management </ a >
</ td ></ tr ></ table >
< hr />
2009-10-06 21:32:13 +00:00
2009-10-07 21:22:23 +00:00
< div id = " campaigndiv " style = " width: 780px; display: none; " >
2009-10-01 21:03:56 +00:00
</ div >
2009-10-07 19:43:58 +00:00
2009-10-01 21:03:56 +00:00
< ?
send_footer ();
?>