forked from science-ation/science-ation
Implement live search for adding existing users to a contact
This commit is contained in:
parent
ff9d802b6e
commit
0015d2bcd7
@ -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)")."<br />";
|
||||
echo "<ul>";
|
||||
while($r=mysql_fetch_object($q)) {
|
||||
echo "<li><a href=\"#\" onclick=\"useexistingcontact($r->uid)\">$r->firstname $r->lastname $r->email $r->phonehome</a></li>\n";
|
||||
}
|
||||
echo "</ul>";
|
||||
}
|
||||
else {
|
||||
echo i18n("There are %1 existing users that match, please enter more details",array($num));
|
||||
}
|
||||
echo "<br />";
|
||||
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 <br />";
|
||||
|
||||
$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 "<h3><a href=\"#\">New Contact";
|
||||
echo "</a></h3>\n";
|
||||
echo "<div>\n";
|
||||
echo "<div id=\"newcontactsearch\"></div>";
|
||||
draw_contact_form($sponsor_id);
|
||||
echo "</div>\n";
|
||||
|
||||
@ -284,6 +336,7 @@ function draw_contact_form($sponsor_id, $contact = null){
|
||||
echo "<input type=\"hidden\" name=\"sponsor_id\" value=\"$sponsor_id\">\n";
|
||||
if($id == "new"){
|
||||
echo "<input type=\"hidden\" name=\"recordtype\" value=\"new\">\n";
|
||||
$newcontactsearch="onkeypress=\"return newcontactsearch()\"";
|
||||
}else{
|
||||
echo "<input type=\"hidden\" name=\"recordtype\" value=\"existing\">\n";
|
||||
echo "<input type=\"hidden\" name=\"userid\" value=\"" . $id . "\">\n";
|
||||
@ -308,9 +361,9 @@ function draw_contact_form($sponsor_id, $contact = null){
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?=i18n("First Name"); ?></td>
|
||||
<td><input type="text" name="firstname" value = "<?=htmlspecialchars($contact['firstname'])?>"></td>
|
||||
<td><input <?=$newcontactsearch?> type="text" name="firstname" value = "<?=htmlspecialchars($contact['firstname'])?>"></td>
|
||||
<td><?=i18n("Last Name"); ?></td>
|
||||
<td><input type="text" name="lastname" value = "<?=htmlspecialchars($contact['lastname'])?>"></td>
|
||||
<td><input <?=$newcontactsearch?> type="text" name="lastname" value = "<?=htmlspecialchars($contact['lastname'])?>"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?=i18n("Phone (Work)"); ?></td>
|
||||
@ -326,7 +379,7 @@ function draw_contact_form($sponsor_id, $contact = null){
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?=i18n("Email"); ?></td>
|
||||
<td colspan="3"><input type="text" name="email" size="60" value = "<?=htmlspecialchars($contact['email'])?>"></td>
|
||||
<td colspan="3"><input <?=$newcontactsearch?> type="text" name="email" size="60" value = "<?=htmlspecialchars($contact['email'])?>"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?=i18n("Notes"); ?></td>
|
||||
@ -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("<?=$_SERVER['PHP_SELF']?>?action=newcontactsearch",$("#contact_new").serializeArray());
|
||||
}
|
||||
|
||||
function useexistingcontact(uid) {
|
||||
var id=sponsor_id;
|
||||
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=contactsinfo_addexisting",{id: id, uid: uid} ,function() { update_contactsinfo(); });
|
||||
}
|
||||
</script>
|
||||
<?
|
||||
|
||||
|
@ -213,10 +213,67 @@ switch($_GET['action']){
|
||||
case "manage_tab_prospects":
|
||||
$campaign_id=intval($_GET['id']);
|
||||
$q=mysql_query("SELECT * FROM fundraising_campaigns WHERE id='$campaign_id' AND fiscalyear='{$config['FISCALYEAR']}'");
|
||||
?>
|
||||
<h4>Choose Prospects</h4>
|
||||
<form id="prospectform">
|
||||
<table>
|
||||
<tr><td style="width: 130px;"><?=i18n("Type")?>:</td><td>
|
||||
<label><input type="radio" name="donortype" value="organization" onchange="donortypechange()" ><?=i18n("Organization")?></label><br />
|
||||
<label><input type="radio" name="donortype" value="individual" onchange="donortypechange()" ><?=i18n("Individual")?></label><br />
|
||||
</td></tr>
|
||||
</table>
|
||||
<div id="prospect_common" style="display: none;">
|
||||
<hr />
|
||||
<table>
|
||||
<tr><td style="width: 130px;"><?=i18n("Donation History")?>:</td><td>
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="donationhistory[]" value="never"><?=i18n("Never donated/sponsored")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="donationhistory[]" value="past"><?=i18n("Donated/sponsored in the past")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="donationhistory[]" value="lastyear"><?=i18n("Donated/sponsored last year")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="donationhistory[]" value="thisyear"><?=i18n("Donated/sponsored this year")?></label><br />
|
||||
</td></tr>
|
||||
<tr><td><?=i18n("Donation Level")?>:</td><td>
|
||||
<?
|
||||
$q=mysql_query("SELECT * FROM fundraising_donor_levels WHERE fiscalyear='{$config['FISCALYEAR']}' ORDER BY min");
|
||||
while($r=mysql_fetch_object($q)) {
|
||||
echo "<label><input onchange=\"return prospect_search()\" type=\"checkbox\" name=\"donationlevel[]\" value=\"$r->level\" >".i18n($r->level)." (".format_money($r->min,false)." - ".format_money($r->max,false).")</label><br />\n";
|
||||
}
|
||||
?>
|
||||
</td></tr>
|
||||
<tr><td><?=i18n("Email Address")?>:</td><td>
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="emailaddress[]" value="available"><?=i18n("Available")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="emailaddress[]" value="notavailable"><?=i18n("Not Available")?></label><br />
|
||||
</td></tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
if($r=mysql_fetch_object($q)) {
|
||||
<div id="prospect_individual" style="display: none;">
|
||||
<table>
|
||||
<tr><td style="width: 130px;"><?=i18n("Role")?>:</td><td>
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="judge"><?=i18n("Judge")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="teacher"><?=i18n("Teacher")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="sciencehead"><?=i18n("School Science Head")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="principal"><?=i18n("School Principal")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="parent"><?=i18n("Parent/Guardian")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="mentor"><?=i18n("Mentor")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="committee"><?=i18n("Committee")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="volunteer"><?=i18n("Volunteer")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="students"><?=i18n("Students")?></label><br />
|
||||
</td></tr></table>
|
||||
</div>
|
||||
|
||||
}
|
||||
<div id="prospect_organization" style="display: none;">
|
||||
<table>
|
||||
<tr><td style="width: 130px;"><?=i18n("Role")?>:</td><td>
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="contacttype[]" value="primary"><?=i18n("Primary contacts")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="contacttype[]" value="secondary"><?=i18n("Secondary contacts")?></label><br />
|
||||
</td></tr></table>
|
||||
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
<div id="prospectsearchresults"></div>
|
||||
</form>
|
||||
<?
|
||||
exit;
|
||||
break;
|
||||
|
||||
@ -359,6 +416,30 @@ function update_tab_prospects() {
|
||||
function update_tab_communications() {
|
||||
$("#campaign_tab_communications").load("<?$_SERVER['PHP_SELF']?>?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;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<?
|
||||
|
Loading…
Reference in New Issue
Block a user