diff --git a/admin/donors.php b/admin/donors.php index fe68070..cc5b608 100644 --- a/admin/donors.php +++ b/admin/donors.php @@ -97,6 +97,10 @@ switch($_GET['action']) { delete_contact(); exit; break; + case 'contactsinfo_addexisting': + addexisting_contact(); + exit; + break; case 'activityinfo_load': // make sure a donor id has been selected if($_GET['id']){ @@ -119,6 +123,35 @@ switch($_GET['action']) { } exit; break; + + case 'newcontactsearch': + $searchstr="1 "; + if($_POST['firstname']) + $searchstr.=" AND firstname LIKE '%".$_POST['firstname']."%'"; + if($_POST['lastname']) + $searchstr.=" AND lastname LIKE '%".$_POST['lastname']."%'"; + if($_POST['email']) + $searchstr.=" AND email LIKE '%".$_POST['email']."%'"; + + $q=mysql_query("SELECT *,MAX(year) FROM users WHERE $searchstr GROUP BY uid HAVING deleted='no'"); + $num=mysql_num_rows($q); + if($num==0) { + echo i18n("No existing users match, will create a new user"); + } + else if($num<15) { + echo i18n("Did you mean one of these existing users? (click to choose one)")."
"; + echo ""; + } + else { + echo i18n("There are %1 existing users that match, please enter more details",array($num)); + } + echo "
"; + exit; + break; } send_header("Donor/Sponsor Management", @@ -142,6 +175,22 @@ function delete_contact(){ } } +function addexisting_contact() { + $uid=intval($_POST['uid']); + $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['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"); + +} + // save the contact info function save_contact(){ global $config; @@ -188,7 +237,6 @@ function save_contact(){ // 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']; @@ -242,11 +290,14 @@ function draw_contactsinfo_form($contact = null){ // 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"); + $query = mysql_query("SELECT *,MAX(year) FROM users LEFT JOIN users_sponsor ON users_sponsor.users_id=users.id + WHERE + sponsors_id='" . $sponsor_id . "' + GROUP BY uid + HAVING deleted='no' + ORDER BY users_sponsor.primary DESC,lastname,firstname + "); + echo mysql_error(); while($contact = mysql_fetch_array($query)){ // draw a header for this user @@ -264,6 +315,7 @@ function draw_contactsinfo_form($contact = null){ echo "

New Contact"; echo "

\n"; echo "
\n"; + echo "
"; draw_contact_form($sponsor_id); echo "
\n"; @@ -284,6 +336,7 @@ function draw_contact_form($sponsor_id, $contact = null){ echo "\n"; if($id == "new"){ echo "\n"; + $newcontactsearch="onkeypress=\"return newcontactsearch()\""; }else{ echo "\n"; echo "\n"; @@ -308,9 +361,9 @@ function draw_contact_form($sponsor_id, $contact = null){ - + type="text" name="firstname" value = ""> - + type="text" name="lastname" value = ""> @@ -326,7 +379,7 @@ function draw_contact_form($sponsor_id, $contact = null){ - + type="text" name="email" size="60" value = ""> @@ -436,7 +489,6 @@ function save_activityinfo($comment, $donorId, $userId, $type, $campaign_id=null '".mysql_real_escape_string($comment)."', '".mysql_real_escape_string($type)."', $cid)"; - echo $query; mysql_query($query); echo mysql_error(); @@ -645,6 +697,21 @@ function donorsearch() { return false; } +var searchtimer; + +function newcontactsearch() { + clearTimeout(searchtimer); + searchtimer=setTimeout('donewcontactsearch()',300); + return true; +} +function donewcontactsearch() { + $("#newcontactsearch").load("?action=newcontactsearch",$("#contact_new").serializeArray()); +} + +function useexistingcontact(uid) { + var id=sponsor_id; + $("#debug").load("?action=contactsinfo_addexisting",{id: id, uid: uid} ,function() { update_contactsinfo(); }); +} +

Choose Prospects

+
+ + +
: +
+
+
+ - if($r=mysql_fetch_object($q)) { + - } + + +
+
+
+ ?action=manage_tab_communications&id="+currentcampaignid); } + +function donortypechange() { + if($("input[@name='donortype']:checked").val()=="organization") { + $("#prospect_common").show('slow'); + $("#prospect_organization").show('slow'); + $("#prospect_individual").hide('slow'); + } + else if($("input[@name='donortype']:checked").val()=="individual") { + $("#prospect_common").show('slow'); + $("#prospect_organization").hide('slow'); + $("#prospect_individual").show('slow'); + } + else { + $("#prospect_common").hide('slow'); + } + prospect_search(); +} + +function prospect_search() { + + $("#prospectsearchresults").load("fundraising_campaigns_prospecting.php",$("#prospectform").serializeArray()); + return false; +} +