diff --git a/admin/donors.php b/admin/donors.php index 1d2c776..048e9da 100644 --- a/admin/donors.php +++ b/admin/donors.php @@ -43,10 +43,14 @@ switch($_GET['action']) { $q=mysql_query("INSERT INTO sponsors (year) VALUES ('".$config['FAIRYEAR']."')"); $id=mysql_insert_id(); echo json_encode(array("id"=>$id)); + save_activityinfo("Created donor/sponsor", $id, $_SESSION['users_uid'],"System"); + $createnew=true; } + else $createnew=false; if($id) { $exec="UPDATE sponsors SET ". + "donortype='".mysql_escape_string(stripslashes($_POST['donortype']))."', ". "organization='".mysql_escape_string(stripslashes($_POST['organization']))."', ". "address='".mysql_escape_string(stripslashes($_POST['address']))."', ". "address2='".mysql_escape_string(stripslashes($_POST['address2']))."', ". @@ -61,16 +65,17 @@ switch($_GET['action']) { "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']))."' ". + "waiveraccepted='".mysql_escape_string(stripslashes($_POST['waiveraccepted']))."' ". "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"); + if(!$createnew) { + save_activityinfo("Updated donor/sponsor details", $id, $_SESSION['users_uid'],"System"); + happy_("Donor/Sponsor Details saved"); + } } exit; break; @@ -319,7 +324,7 @@ function delete_contact(){ $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); + user_delete($uid,"sponsor"); happy_("Deleted contact %1", array($name)); //($comment , $donorId, $userId, $type, $campaign_id=null){ @@ -332,12 +337,13 @@ function addexisting_contact() { $sponsors_id=intval($_POST['id']); echo "Linking uid=$uid to sponsors_id=$sponsors_id
"; - $u=user_load_by_uid($uid); echo "uid $uid has users.id {$u['id']}"; + $u=user_load_by_uid($uid); $u['sponsors_id']=$sponsors_id; $u['types'][]="sponsor"; user_save($u); + save_activityinfo("Existing user (".$u['firstname']." ".$u['lastname'].") linked to donor/sponsor",$sponsors_id,$_SESSION['users_uid'],'System'); happy_("Added existing user to donor/sponsor"); @@ -454,6 +460,7 @@ function draw_contactsinfo_form($contact = null){ $query = mysql_query("SELECT *,MAX(year) FROM users LEFT JOIN users_sponsor ON users_sponsor.users_id=users.id WHERE sponsors_id='" . $sponsor_id . "' + AND types LIKE '%sponsor%' GROUP BY uid HAVING deleted='no' ORDER BY users_sponsor.primary DESC,lastname,firstname @@ -476,6 +483,8 @@ function draw_contactsinfo_form($contact = null){ echo "

New Contact"; echo "

\n"; echo "
\n"; + + //and do the blank one echo "
"; draw_contact_form($sponsor_id); echo "
\n"; @@ -488,11 +497,36 @@ function draw_contactsinfo_form($contact = null){ // draw a form in which to enter information about the various contacts function draw_contact_form($sponsor_id, $contact = null){ global $salutations; + global $config; + + //grab the sponsor details, so we can do diff things for individual vs organization + $q=mysql_query("SELECT * FROM sponsors WHERE id='$sponsor_id'"); + $sponsor=mysql_fetch_object($q); + if($contact != null){ $id = $contact["id"]; }else{ - $id = "new"; - } + $id = "new"; + if($sponsor->donortype=="individual") { + list($firstname,$lastname)=split(" ",$sponsor->organization,2); + $contact['firstname']=$firstname; + $contact['lastname']=$lastname; + $contact['email']=$sponsor->email; + $contact['phonehome']=$sponsor->phone; + } + else { + $contact['phonework']=$sponsor->phone; + } + + $contact['fax']=$sponsor->fax; + $contact['address']=$sponsor->address; + $contact['address2']=$sponsor->address2; + $contact['city']=$sponsor->city; + $contact['province']=$sponsor->province_code; + $contact['postalcode']=$sponsor->postalcode; + + } + echo "
\n"; echo "\n"; if($id == "new"){ @@ -519,14 +553,25 @@ function draw_contact_form($sponsor_id, $contact = null){ - + donortype=="organization") { + $d="disabled=\"disabled\""; + } + else $d=""; + ?> + + value = ""> - + type="text" name="firstname" value = ""> type="text" name="lastname" value = ""> + + + type="text" name="email" size="60" value = ""> + @@ -539,10 +584,16 @@ function draw_contact_form($sponsor_id, $contact = null){ - - - type="text" name="email" size="60" value = ""> - + + + + + + + + + + @@ -690,6 +741,7 @@ $(document).ready(function() { $("#organizationinfo_fundingselectiondate").datepicker({ dateFormat: 'yy-mm-dd'}); //, showOn: 'button', buttonText: "" }); + open_search(); }); @@ -720,6 +772,9 @@ function open_editor(id) { $("#organizationinfo_fundingselectiondate").val(""); $("#organizationinfo_notes").val(""); + $("#organizationinfo_save_button").attr('disabled','disabled'); + $("[name=donortype]").attr('checked',''); + } else { $('#editor_tabs').tabs('option', 'selected', 0); @@ -766,7 +821,9 @@ function update_organizationinfo() $("#organizationinfo_notes").val(json.notes); // For some reason, with checkboxes, these have to be arrays $("[name=waiveraccepted]").val([json.waiveraccepted]); - $("[name=taxreceiptrequired]").val([json.taxreceiptrequired]); + $("[name=donortype]").val([json.donortype]); + + donortypechange(); }); } @@ -782,6 +839,7 @@ function organizationinfo_save() { } else $("#debug").load("?action=organizationinfo_save", $("#organizationinfo").serializeArray()); + return false; } @@ -880,8 +938,27 @@ function togglefulldonationhistory() { } function campaignchange() { - } + +function donortypechange() { + if($("input[@name='donortype']:checked").val()=="organization") { + $("#organizationinfo_logo").attr("disabled",""); + $("#organizationinfo_donationpolicyurl").attr("disabled",""); + $("#organizationinfo_fundingselectiondate").attr("disabled",""); + $("#organizationinfo_proposalsubmissiondate").attr("disabled",""); + } + else if($("input[@name='donortype']:checked").val()=="individual") { + $("#organizationinfo_logo").attr("disabled","disabled"); + $("#organizationinfo_donationpolicyurl").attr("disabled","disabled"); + $("#organizationinfo_fundingselectiondate").attr("disabled","disabled"); + $("#organizationinfo_proposalsubmissiondate").attr("disabled","disabled"); + } + else { + } + $("#organizationinfo_save_button").attr('disabled',''); +} + + ";
@@ -919,8 +996,8 @@ echo "
"; @@ -938,8 +1015,9 @@ echo "
"; - - + + + "; ?>
- - + +
- + " onClick="return organizationinfo_save()" />
@@ -979,8 +1057,8 @@ echo "
";