Do a lot of database re-working, renaming and reorganization

Database now refers to everything by donor/donation .. and apparently just as i complete this, carolyn has decided to go to both donor/sponsor instead of just donor.. ugh..
This commit is contained in:
james 2009-10-02 16:46:13 +00:00
parent 55751e5da8
commit 01fde584be
14 changed files with 88 additions and 78 deletions

View File

@ -28,7 +28,7 @@
user_auth_required('committee', 'admin');
include ("fundraising_sponsorship_handler.inc.php");
include ("fundraising_types_handler.inc.php");
include ("fundraising_goals_handler.inc.php");
include ("fundraising_main.inc.php");
send_header("Donations",

View File

@ -103,7 +103,7 @@
break;
}
send_header("Donor Management",
send_header("Donor/Sponsor Management",
array('Committee Main' => 'committee_main.php',
'Administration' => 'admin/index.php',
'Fundraising' => 'admin/fundraising.php')
@ -394,20 +394,20 @@ function donorsearch() {
echo "<table cellspacing=2 width=740 border=0><tr>";
echo "<td>";
echo "<a href=\"#\" onclick=\"open_editor(-1)\">Add New Donor(s)</a>\n";
echo "<a href=\"#\" onclick=\"open_editor(-1)\">Add New Donor(s)/Sponsor(s)</a>\n";
echo "</td>";
echo "<td>";
echo "<a href=\"#\" onclick=\"open_search()\">View/Modify Donor(s)</a>\n";
echo "<a href=\"#\" onclick=\"open_search()\">View/Modify Donor(s)/Sponsor(s)</a>\n";
echo "</td>";
echo "</tr></table>";
echo "<hr />";
?>
<div id="donor_editor" title="Donor Editor" style="display: none">
<div id="donor_editor" title="Donor/Sponsor Editor" style="display: none">
<div id="editor_tabs">
<ul>
<li><a href="#editor_tab_organization"><span><?=i18n('Donor Details')?></span></a></li>
<li><a href="#editor_tab_sponsorship"><span><?=i18n('Donations')?></span></a></li>
<li><a href="#editor_tab_organization"><span><?=i18n('Donor/Sponsor Details')?></span></a></li>
<li><a href="#editor_tab_sponsorship"><span><?=i18n('Donations/Sponsorships')?></span></a></li>
<li><a href="#editor_tab_contacts"><span><?=i18n('Contacts')?></span></a></li>
<li><a href="#editor_tab_activity"><span><?=i18n('Activity Log')?></span></a></li>
</ul>

View File

@ -61,7 +61,7 @@
$numr=mysql_fetch_object($numq);
$numawards=$numr->num;
$numq=mysql_query("SELECT COUNT(id) AS num FROM sponsorships WHERE year='".$config['FAIRYEAR']."' AND sponsors_id='$r->id'");
$numq=mysql_query("SELECT COUNT(id) AS num FROM fundraising_donations WHERE fiscalyear='".$config['FISCALYEAR']."' AND sponsors_id='$r->id'");
$numr=mysql_fetch_object($numq);
$numsponsorships=$numr->num;

View File

@ -2,13 +2,13 @@
if($_POST['action']=="funddelete" && $_POST['delete']) {
//first lookup all the sponsorships inside the fund
$id=intval($_POST['delete']);
$q=mysql_query("SELECT * FROM fundraising WHERE id='$id' AND year='".$config['FAIRYEAR']."'");
$q=mysql_query("SELECT * FROM fundraising_goals WHERE id='$id' AND year='".$config['FISCALYEAR']."'");
$f=mysql_fetch_object($q);
//hold yer horses, no deleting system funds!
if($f) {
if($f->system=="no") {
mysql_query("DELETE FROM sponsorships WHERE fundraising_type='".mysql_real_escape_string($f->type)."' AND year='".$config['FAIRYEAR']."'");
mysql_query("DELETE FROM fundraising WHERE id='$id'");
mysql_query("DELETE FROM fundraising_donations WHERE fundraising_goal='".mysql_real_escape_string($f->type)."' AND fiscalyear='".$config['FISCALYEAR']."'");
mysql_query("DELETE FROM fundraising_goals WHERE id='$id'");
if(mysql_affected_rows())
happy_("Successfully removed fund %1",array($f->name));
}
@ -21,23 +21,23 @@ if($_POST['action']=="funddelete" && $_POST['delete']) {
if($_POST['action']=="fundedit" || $_POST['action']=="fundadd") {
$fundraising_id=intval($_POST['fundraising_id']);
if($fundraising_id) {
$q=mysql_query("SELECT * FROM fundraising WHERE id='$fundraising_id'");
$q=mysql_query("SELECT * FROM fundraising_goals WHERE id='$fundraising_id'");
$f=mysql_fetch_object($q);
$system=$f->system;
}
$name=mysql_real_escape_string($_POST['name']);
$type=mysql_real_escape_string($_POST['type']);
$goal=mysql_real_escape_string($_POST['goal']);
$description=mysql_real_escape_string($_POST['description']);
$goal=intval($_POST['goal']);
$budget=intval($_POST['budget']);
}
if($_POST['action']=="fundedit") {
if( ($system=="yes" && $goal) || ($system=="no" && $goal && $type && $name) ) {
if( ($system=="yes" && $budget) || ($system=="no" && $budget && $goal && $name) ) {
if($system=="yes") {
mysql_query("UPDATE fundraising SET goal='$goal', description='$description' WHERE id='$fundraising_id'");
mysql_query("UPDATE fundraising SET budget='$budget', description='$description' WHERE id='$fundraising_id'");
}
else {
mysql_query("UPDATE fundraising SET goal='$goal', description='$description', type='$type', name='$name' WHERE id='$fundraising_id'");
mysql_query("UPDATE fundraising SET budget='$budget', description='$description', goal='$goal', name='$name' WHERE id='$fundraising_id'");
}
if(mysql_error())
error_("MySQL Error: %1",array(mysql_error()));
@ -52,7 +52,7 @@ if($_POST['action']=="fundedit") {
}
if($_POST['action']=="fundadd") {
if( $goal && $type && $name) {
mysql_query("INSERT INTO fundraising (type,name,description,system,goal,year) VALUES ('$type','$name','$description','no','$goal','{$config['FAIRYEAR']}')");
mysql_query("INSERT INTO fundraising_goals (goal,name,description,system,budget,fiscalyear) VALUES ('$goal','$name','$description','no','$budget','{$config['FISCALYEAR']}')");
happy_("Added new fund");
}
else

View File

@ -2,7 +2,7 @@
if($_GET['action']=="fundraisingmain") {
//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 DESC,type");
$q=mysql_query("SELECT * FROM fundraising_goals WHERE fiscalyear='{$config['FISCALYEAR']}' ORDER BY system DESC,goal");
echo "<table class=\"fundraisingtable\">";
while($r=mysql_fetch_object($q)) {
@ -16,7 +16,7 @@ if($_GET['action']=="fundraisingmain") {
echo "</th>\n";
echo "<th colspan=\"5\">".i18n($r->name)."</th>\n";
echo "<th style=\"text-align: right\"><nobr>".format_money($r->goal)."</nobr></th>\n";
echo "<th style=\"text-align: right\"><nobr>".format_money($r->budget)."</nobr></th>\n";
echo "</tr>\n";
if($r->type=="general")
@ -25,19 +25,19 @@ if($_GET['action']=="fundraisingmain") {
$typetotal=0;
$typeprobtotal=0;
$sq=mysql_query("
SELECT sponsorships.id, sponsors.organization AS name, 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']}'
SELECT fundraising_donations.id, sponsors.organization AS name, fundraising_donations.value, fundraising_donations.status, fundraising_donations.probability
FROM fundraising_donations
JOIN sponsors ON fundraising_donations.sponsors_id=sponsors.id
WHERE (fundraising_donations.fundraising_goal='$r->goal' $orsql)
AND fundraising_donations.fiscalyear='{$config['FISCALYEAR']}'
UNION
SELECT sponsorships.id, CONCAT(users.firstname,' ',users.lastname) AS name, sponsorships.value, sponsorships.status, sponsorships.probability
FROM sponsorships
JOIN users ON sponsorships.users_uid=users.uid
WHERE (sponsorships.fundraising_type='$r->type' $orsql)
AND sponsorships.year='{$config['FAIRYEAR']}'
SELECT fundraising_donations.id, CONCAT(users.firstname,' ',users.lastname) AS name, fundraising_donations.value, fundraising_donations.status, fundraising_donations.probability
FROM fundraising_donations
JOIN users ON fundraising_donations.users_uid=users.uid
WHERE (fundraising_donations.fundraising_goal='$r->goal' $orsql)
AND fundraising_donations.fiscalyear='{$config['FISCALYEAR']}'
ORDER BY status DESC, probability DESC, name
");

View File

@ -28,7 +28,7 @@
if($_GET['id']) {
$id=intval($_GET['id']);
$q=mysql_query("SELECT sponsorships.*, sponsors.organization FROM sponsorships,sponsors WHERE sponsorships.id='$id' AND sponsorships.sponsors_id=sponsors.id");
$q=mysql_query("SELECT fundraising_donations.*, sponsors.organization FROM fundraising_donations,sponsors WHERE fundraising_donations.id='$id' AND fundraising_donations.sponsors_id=sponsors.id");
$sponsorship=mysql_fetch_object($q);
$formaction="sponsorshipedit";
}
@ -55,7 +55,7 @@ function typechange() {
<?
echo "<form id=\"fundraisingsponsorship\">";
echo "<input type=\"hidden\" name=\"action\" value=\"$formaction\">";
echo "<input type=\"hidden\" name=\"sponsorships_id\" value=\"$id\">";
echo "<input type=\"hidden\" name=\"fundraising_donations_id\" value=\"$id\">";
echo "<table cellspacing=0 cellpadding=0 class=\"tableedit\">";
if($formaction=="sponsorshipadd") {

View File

@ -1,6 +1,6 @@
<?
if($_POST['action']=="sponsorshipdelete") {
mysql_query("DELETE FROM sponsorships WHERE id='".intval($_POST['delete'])."'");
mysql_query("DELETE FROM fundraising_donations WHERE id='".intval($_POST['delete'])."'");
if(mysql_affected_rows())
happy_("Successfully removed sponsorship");
exit;
@ -8,7 +8,7 @@ if($_POST['action']=="sponsorshipdelete") {
if($_POST['action']=="sponsorshipedit" || $_POST['action']=="sponsorshipadd") {
$sponsors_id=intval($_POST['sponsors_id']);
$sponsorships_id=intval($_POST['sponsorships_id']);
$fundraising_donations_id=intval($_POST['fundraising_donations_id']);
$fundraising_type=mysql_real_escape_string($_POST['fundraising_type']);
$value=mysql_real_escape_string($_POST['value']);
@ -21,8 +21,8 @@ if($_POST['action']=="sponsorshipedit" || $_POST['action']=="sponsorshipadd") {
if($_POST['action']=="sponsorshipedit") {
if($sponsorships_id && $fundraising_type && $value) {
$q=mysql_query("SELECT * FROM sponsorships WHERE id='$sponsorships_id'");
if($fundraising_donations_id && $fundraising_type && $value) {
$q=mysql_query("SELECT * FROM fundraising_donations WHERE id='$fundraising_donations_id'");
$current=mysql_fetch_object($q);
unset($log);
@ -40,10 +40,10 @@ if($_POST['action']=="sponsorshipedit") {
$log[]="Changed sponsorship probability from $current->probability to $probability";
if(count($log)) {
mysql_query("UPDATE sponsorships SET fundraising_type='$fundraising_type', value='$value', status='$status', probability='$probability' WHERE id='$sponsorships_id'");
mysql_query("UPDATE fundraising_donations SET fundraising_type='$fundraising_type', value='$value', status='$status', probability='$probability' WHERE id='$fundraising_donations_id'");
foreach($log AS $l) {
mysql_query("INSERT INTO sponsors_logs (sponsors_id,dt,users_id,log) VALUES (
mysql_query("INSERT INTO fundraising_donor_logs (sponsors_id,dt,users_id,log) VALUES (
'$current->sponsors_id',
NOW(),
'".$_SESSION['users_id']."',
@ -65,8 +65,8 @@ if($_POST['action']=="sponsorshipedit") {
}
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']}')");
mysql_query("INSERT INTO sponsors_logs (sponsors_id,dt,users_id,log) VALUES (
mysql_query("INSERT INTO fundraising_donations (sponsors_id,fundraising_type,value,status,probability,fiscalyear) VALUES ('$sponsors_id','$fundraising_type','$value','$status','$probability','{$config['FISCALYEAR']}')");
mysql_query("INSERT INTO fundraising_donor_logs (sponsors_id,dt,users_id,log) VALUES (
'$sponsors_id',
NOW(),
'".$_SESSION['users_id']."',

View File

@ -26,16 +26,16 @@
require_once("../user.inc.php");
//first, insert any defaults
$q=mysql_query("SELECT * FROM sponsorships_levels WHERE year='".$config['FAIRYEAR']."'");
$q=mysql_query("SELECT * FROM fundraising_donor_levels WHERE year='".$config['FISCALYEAR']."'");
if(!mysql_num_rows($q)) {
$q=mysql_query("SELECT * FROM sponsorships_levels WHERE year='-1'");
$q=mysql_query("SELECT * FROM fundraising_donor_levels WHERE year='-1'");
while($r=mysql_fetch_object($q)) {
mysql_query("INSERT INTO sponsorships_levels (`level`,`min`,`max`,`description`,`year`) VALUES (
mysql_query("INSERT INTO fundraising_donor_levels (`level`,`min`,`max`,`description`,`year`) VALUES (
'".mysql_real_escape_string($r->level)."',
'".mysql_real_escape_string($r->min)."',
'".mysql_real_escape_string($r->max)."',
'".mysql_real_escape_string($r->description)."',
'".$config['FAIRYEAR']."')");
'".$config['FISCALYEAR']."')");
}
}
@ -47,7 +47,7 @@
"internal_document_management"
);
$editor=new TableEditor("sponsorships_levels",
$editor=new TableEditor("fundraising_donor_levels",
array("level"=>"Level Name",
"min"=>"Minimum Amount",
"max"=>"Maximum Amount",
@ -58,13 +58,13 @@
"max"=>"Maximum Amount",
"description"=>"Description / Benefits",
)
,array("year"=>$config['FAIRYEAR'])
,array("year"=>$config['FISCALYEAR'])
);
$editor->setPrimaryKey("id");
$editor->setDefaultSortField("max");
$editor->setRecordType("Level");
$editor->filterList('year',$config['FAIRYEAR']);
$editor->filterList('year',$config['FISCALYEAR']);
$editor->execute();
send_footer();

View File

@ -461,7 +461,7 @@ if(is_array($nav)) {
echo "<li><h4 style=\"text-align: center;\">".i18n("Fundraising")."</h4></li>\n";
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/admin/fundraising.php\">".i18n("Fundraising Dashboard").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/admin/fundraising_campaigns.php\">".i18n("Manage Campaigns").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/admin/donors.php\">".i18n("Manage Donors").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/admin/donors.php\">".i18n("Manage Donors/Sponsors").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/admin/reports.php?area=fundraising\">".i18n("Fundraising Reports").'</a></li>';
echo "</ul><br />\n";
break;

View File

@ -170,23 +170,6 @@
'".mysql_real_escape_string($r->ord)."',
'".mysql_real_escape_string($newfairyear)."')");
echo i18n("Rolling fundraising goals")." <br />";
roll($currentfairyear, $newfairyear, "fundraising",
array("type","name","description","system","goal"));
echo i18n("Rolling sponsorship levels")." <br />";
roll($currentfairyear, $newfairyear, "sponsorships_levels",
array("level","min","max","description"));
echo i18n("Rolling sponsorships")." <br />";
roll($currentfairyear, $newfairyear, "sponsorships",
array("sponsors_id","fundraising_type","value")); //no need to roll status or probability, because we're about to reset them..
mysql_query("UPDATE sponsorships SET status='pending', probability=25 WHERE year='$newfairyear'");
$q=mysql_query("SELECT * FROM sponsorships WHERE year='$newfairyear'");
while($r=mysql_fetch_object($q)) {
mysql_query("INSERT INTO sponsors_logs (sponsors_id,dt,users_id,log) VALUES ('$r->sponsors_id',NOW(),'{$_SESSION['auth_user_id']}','Fair year rollover - reset status=pending, probability=25\%')");
}
echo i18n("Rolling awards")."<br />";
//awards
$q=mysql_query("SELECT * FROM award_awards WHERE year='$currentfairyear'");

22
config/rolloverfiscal.php Normal file
View File

@ -0,0 +1,22 @@
<?
//FIXME: I just ripped these out of the fair year rollover since they are no longer tied to the fair year, they are now tied to the FISCAL year, we'll need to implement a new fiscal year rollover mechanism similar to the fairyear rollover
//FIXME: The table names are also wrong since i've now renamed htem all, will fix when the fiscal rollover is implemented
echo i18n("Rolling fundraising goals")." <br />";
roll($currentfairyear, $newfairyear, "fundraising",
array("type","name","description","system","goal"));
echo i18n("Rolling sponsorship levels")." <br />";
roll($currentfairyear, $newfairyear, "sponsorships_levels",
array("level","min","max","description"));
echo i18n("Rolling sponsorships")." <br />";
roll($currentfairyear, $newfairyear, "sponsorships",
array("sponsors_id","fundraising_type","value")); //no need to roll status or probability, because we're about to reset them..
mysql_query("UPDATE sponsorships SET status='pending', probability=25 WHERE year='$newfairyear'");
$q=mysql_query("SELECT * FROM sponsorships WHERE year='$newfairyear'");
while($r=mysql_fetch_object($q)) {
mysql_query("INSERT INTO sponsors_logs (sponsors_id,dt,users_id,log) VALUES ('$r->sponsors_id',NOW(),'{$_SESSION['auth_user_id']}','Fair year rollover - reset status=pending, probability=25\%')");
}
?>

View File

@ -1 +1 @@
141
142

View File

@ -109,6 +109,7 @@ if($_POST['action']=="save")
{
echo "Creating configuration settings...";
mysql_query("INSERT INTO config (var,val,category,ord,year) VALUES ('FAIRYEAR','".$_POST['fairyear']."','Special','0','0')");
mysql_query("INSERT INTO config (var,val,category,ord,year) VALUES ('FISCALYEAR','".$_POST['fiscalyear']."','Special','0','0')");
mysql_query("INSERT INTO config (var,val,category,ord,year) VALUES ('SFIABDIRECTORY','".$_POST['sfiabdirectory']."','Special','','0')");
$year = intval($_POST['fairyear']);
@ -176,6 +177,9 @@ $month=date("m");
if($month>4) $fairyearsuggest=date("Y")+1;
else $fairyearsuggest=date("Y");
if($month>6) $fiscalyearsuggest=date("Y")+1;
else $fiscalyearsuggest=date("Y");
$directorysuggest=substr($_SERVER['REQUEST_URI'],0,-13);
echo "<h3>Options</h3>";
echo "<form method=\"post\" action=\"install3.php\">";
@ -184,6 +188,7 @@ echo "<input type=\"hidden\" name=\"action\" value=\"save\" />";
echo "<table>";
echo "<tr><td>Fair Name</td><td><input size=\"25\" type=\"text\" name=\"fairname\" value=\"\"></td><td>The name of the fair you are installing SFIAB to run</td></tr>";
echo "<tr><td>Fair Year</td><td><input size=\"8\" type=\"text\" name=\"fairyear\" value=\"$fairyearsuggest\"></td><td>The year of the fair you are installing SFIAB to run</td></tr>";
echo "<tr><td>Fiscal Year</td><td><input size=\"8\" type=\"text\" name=\"fiscalyear\" value=\"$fiscalyearsuggest\"></td><td>The current fiscal year (for fundraising/accounting purposes)</td></tr>";
echo "<tr><td>Directory</td><td><input size=\"25\" type=\"text\" name=\"sfiabdirectory\" value=\"$directorysuggest\"></td><td>The directory of this SFIAB installation as seen by the web browser</td></tr>";
echo "</table>";

View File

@ -49,17 +49,17 @@
echo "</table>\n";
echo "<h2>Your Sponsorships</h2>\n";
$sq=mysql_query("SELECT sponsorships.id,
$sq=mysql_query("SELECT fundraising_donations.id,
sponsors.organization,
sponsorships.value,
sponsorships.status,
sponsorships.probability,
fundraising_donations.value,
fundraising_donations.status,
fundraising_donations.probability,
fundraising.name
FROM sponsorships
JOIN sponsors ON sponsorships.sponsors_id=sponsors.id
JOIN fundraising ON sponsorships.fundraising_type=fundraising.type
AND sponsorships.year='{$config['FAIRYEAR']}'
AND fundraising.year='{$config['FAIRYEAR']}'
FROM fundraising_donations
JOIN sponsors ON fundraising_donations.sponsors_id=sponsors.id
JOIN fundraising_goals ON fundraising_donations.fundraising_goal=fundraising_goal.goal
AND fundraising_donations.fiscalyear='{$config['FISCALYEAR']}'
AND fundraising_goals.fiscalyear='{$config['FISCALYEAR']}'
AND sponsors.id='".$u['sponsors_id']."'
ORDER BY status DESC, probability DESC, organization");
echo mysql_error();
@ -73,7 +73,7 @@
echo "</tr>\n";
$total=0;
while($sr=mysql_fetch_object($sq)) {
echo "<tr id=\"sponsorships_$sr->id\" class=\"fundraising{$sr->status}\">";
echo "<tr id=\"donations_$sr->id\" class=\"fundraising{$sr->status}\">";
echo "<td>$sr->name</td>\n";
echo "<td>$sr->status</td>";
echo "<td style=\"text-align: right\">".format_money($sr->value)."</td>";
@ -93,8 +93,8 @@
echo "<br />\n";
echo "<br />\n";
echo "<h2>Sponsorship Levels</h2>\n";
$q=mysql_query("SELECT * FROM sponsorships_levels WHERE year='".$config['FAIRYEAR']."' ORDER BY max DESC");
echo "<h2>Donor Levels</h2>\n";
$q=mysql_query("SELECT * FROM fundraising_donor_levels WHERE year='".$config['FISCALYEAR']."' ORDER BY max DESC");
echo "<table class=\"tableview\">";
echo "<th></th><th>".i18n("Level")."</th>";
echo "<th>".i18n("Description / Benefits")."</th>\n";