Copyright (C) 2008 James Grant 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. */ ?> $id)); } if($id) { $exec="UPDATE sponsors SET ". "organization='".mysql_escape_string(stripslashes($_POST['organization']))."', ". "address='".mysql_escape_string(stripslashes($_POST['address']))."', ". "address2='".mysql_escape_string(stripslashes($_POST['address2']))."', ". "city='".mysql_escape_string(stripslashes($_POST['city']))."', ". "province_code='".mysql_escape_string(stripslashes($_POST['province_code']))."', ". "postalcode='".mysql_escape_string(stripslashes($_POST['postalcode']))."', ". "phone='".mysql_escape_string(stripslashes($_POST['phone']))."', ". "tollfree='".mysql_escape_string(stripslashes($_POST['tollfree']))."', ". "fax='".mysql_escape_string(stripslashes($_POST['fax']))."', ". "email='".mysql_escape_string(stripslashes($_POST['email']))."', ". "website='".mysql_escape_string(stripslashes($_POST['website']))."', ". "notes='".mysql_escape_string(stripslashes($_POST['notes']))."', ". "donationpolicyurl='".mysql_escape_string(stripslashes($_POST['donationpolicyurl']))."', ". "fundingselectiondate='".mysql_escape_string(stripslashes($_POST['fundingselectiondate']))."', ". "waiveraccepted='".mysql_escape_string(stripslashes($_POST['waiveraccepted']))."', ". "taxreceiptrequired='".mysql_escape_string(stripslashes($_POST['taxreceiptrequired']))."' ". "WHERE id='$id'"; mysql_query($exec); //FIXME accept the logo //"logo='".mysql_escape_string(stripslashes($_POST['logo']))."', ". //($comment , $donorId, $userId, $type, $campaign_id=null){ save_activityinfo("Updated donor/sponsor details", $id, $_SESSION['users_uid'],"System"); happy_("Donor/Sponsor Details saved"); } exit; break; case 'sponsorshipinfo_load': $id=intval($_GET['id']); $ret=array(); echo json_encode($ret); exit; break; case 'contactsinfo_load': // make sure a donor id has been selected if($_GET['id']){ draw_contactsinfo_form(); } exit; break; case 'contactsinfo_save': save_contact(); exit; break; case 'contactsinfo_delete': delete_contact(); exit; break; case 'activityinfo_load': // make sure a donor id has been selected if($_GET['id']){ draw_activityinfo_form(); } exit; break; case 'activityinfo_save': //($comment , $donorId, $userId, $type, $campaign_id=null){ if(save_activityinfo( $_POST['comment'], $_GET['id'], $_SESSION['users_uid'], $_POST['type'], $_POST['fundraising_campaigns_id'] )){ happy_("Activity Logged"); }else{ error_("Unable to save activity log"); } exit; break; } send_header("Donor/Sponsor Management", array('Committee Main' => 'committee_main.php', 'Administration' => 'admin/index.php', 'Fundraising' => 'admin/fundraising.php') ); //delete the contact who has been submitted in _POST function delete_contact(){ if(array_key_exists('userid', $_POST)){ $uid = $_POST['userid']; $data = mysql_query("SELECT CONCAT_WS(' ', users.firstname, users.lastname) AS name FROM users WHERE id=" . $uid); $namedata = mysql_fetch_array($data); $name = trim($namedata['name']); user_delete($uid); happy_("Deleted contact %1", array($name)); //($comment , $donorId, $userId, $type, $campaign_id=null){ save_activityinfo("Deleted contact \"$name\"",$_GET['id'],$_SESSION['users_uid'],'System' ); } } // save the contact info function save_contact(){ global $config; //happy_("happy!"); if(validate_contactdata()){ // load or create the user, according to the situation if($_POST['recordtype'] == 'new'){ // this is a new record being submitted. Create the user. $successMessage = "Contact created successfully"; $successLog = "Added contact "; $u = user_create("sponsor", $_POST['email']); $id = $u['id']; }else if($_POST['recordtype'] == 'existing'){ // this is an existing record being updated. Load the user. $successMessage = "Contact updated successfully"; $successLog = "Updated contact "; $u = user_load($_POST['userid']); $id = intval($_POST['userid']); } $sponsor_id = $_POST['sponsor_id']; $p = ($_POST['primary']=='yes')?'yes':'no'; if($p == 'no') { /* Make sure this sponsor ($sponsor_id) has a primary */ $query = "SELECT users_id FROM users_sponsor, users WHERE users_sponsor.users_id=users.id AND sponsors_id='$sponsor_id' AND `primary`='yes' AND year='".$config['FAIRYEAR']."' AND users_id!='$id'"; $q = mysql_query($query); if(mysql_num_rows($q) == 0) { /* This has to be the primary since there isn't one already */ $p = 'yes'; } } else { /* Unset all other primaries */ mysql_query("UPDATE users_sponsor SET `primary`='no' WHERE sponsors_id='$sponsor_id' AND users_id != '$id'"); } // we now know whether or not they're the primary user. Update them with that, // along with all of the user info that's been submitted. echo "setting primary $p"; $u['primary']=$p; $u['salutation']=$_POST['salutation']; $u['firstname']=$_POST['firstname']; $u['lastname']=$_POST['lastname']; $u['position']=$_POST['position']; $u['phonework']=$_POST['phonework']; $u['phonecell']=$_POST['phonecell']; $u['phonehome']=$_POST['phonehome']; $u['fax']=$_POST['fax']; $u['email']=$_POST['email']; $u['notes']=$_POST['notes']; $u['sponsors_id']=$sponsor_id; user_save($u); $name = trim($u['firstname'] . ' ' . $u['lastname']); //($comment , $donorId, $userId, $type, $campaign_id=null){ save_activityinfo($successLog . '"' . $name . '"',$sponsor_id,$_SESSION['users_uid'],'System'); happy_($successMessage); }else{ // something's wrong with the user data submitted. Should flag the fields where // appropriate, but for now just pop up an error error_("Form not filled out"); } } // FIXME: dummy filler function for now. Should go through all of the fields // submitted and validate before hitting the database function validate_contactdata(){ $returnval = true; if($_POST['recordtype'] != 'new' && $_POST['recordtype'] != 'existing'){ $returnval = false; } return $returnval; } // draw a group of forms for editing and creating new contacts function draw_contactsinfo_form($contact = null){ global $config; // make sure we know what sponsor we're dealing with here if(!isset($sponsor_id)){ if($_GET['id']) $sponsor_id=$_GET['id']; else if($_POST['id']) $sponsor_id=$_POST['id']; $buttontext = i18n("Add Contact"); } // start our accordion echo "
\n"; // loop through each contact and draw a form with their data in it. $query = mysql_query("SELECT * FROM users LEFT JOIN users_sponsor ON users_sponsor.users_id=users.id WHERE year='" . $config['FAIRYEAR'] . "' AND sponsors_id='" . $sponsor_id . "' AND deleted='no' ORDER BY users_sponsor.primary DESC,lastname,firstname"); while($contact = mysql_fetch_array($query)){ // draw a header for this user echo "

"; echo $contact["firstname"] . " " . $contact["lastname"]; echo "

\n"; // and draw the actual form echo "
\n"; draw_contact_form($sponsor_id, $contact); echo "
\n"; } // draw an empty form in which to enter a new user echo "

New Contact"; echo "

\n"; echo "
\n"; draw_contact_form($sponsor_id); echo "
\n"; // and finally end the accordion echo "
\n"; } // draw a form in which to enter information about the various contacts function draw_contact_form($sponsor_id, $contact = null){ global $salutations; if($contact != null){ $id = $contact["id"]; }else{ $id = "new"; } echo "
\n"; echo "\n"; if($id == "new"){ echo "\n"; }else{ echo "\n"; echo "\n"; } ?> "; echo ""; ?>
"; if($id != "new") echo ""; echo "
"; $q = mysql_query($query); echo mysql_error(); if(mysql_num_rows($q)) { while($r = mysql_fetch_array($q)) { echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; } }else{ echo ""; } ?>
Date User Contact Type Campaign Notes
" onClick="return activityinfo_save()" /> "; echo "\n"; $logtypes=array("Campaign","Phone Call","Email","Personal Visit","Other"); foreach($logtypes AS $lt) { echo "\n"; } echo "\n"; ?> "; echo "\n"; while($r=mysql_fetch_object($q)) { echo "\n"; } echo "\n"; ?>
" . $query . "
" . $r["dt"] . "" . $r["name"] . "" . $r["type"] . "" . $r["campaignname"] . "" . $r["log"] . "
" . i18n("No records") . "
"; echo ""; echo "Add New Donor(s)/Sponsor(s)\n"; echo ""; echo ""; echo "View/Modify Donor(s)/Sponsor(s)\n"; echo ""; echo ""; echo "
"; ?>