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 "