Detect exact email address matches regardless of the name that goes with it, and dont let them submit

This commit is contained in:
james 2009-10-09 15:04:45 +00:00
parent 5aa7cf541a
commit 1f244c8375

View File

@ -125,29 +125,54 @@ switch($_GET['action']) {
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)) {
if($_POST['email'])
$q=mysql_query("SELECT *,MAX(year) FROM users WHERE email='".trim($_POST['email'])."' GROUP BY uid HAVING deleted='no'");
if($r=mysql_fetch_object($q)) {
echo i18n("There is an exact email address match for %1",array($_POST['email']));
echo "<ul>";
echo "<li><a href=\"#\" onclick=\"useexistingcontact($r->uid)\">$r->firstname $r->lastname $r->email $r->phonehome</a></li>\n";
}
echo "</ul>";
echo "</ul>";
?>
<script type="text/javascript">
$("#contactnewsave").attr("disabled","disabled");
</script>
<?
}
else {
echo i18n("There are %1 existing users that match, please enter more details",array($num));
?>
<script type="text/javascript">
$("#contactnewsave").attr("disabled","");
</script>
<?
$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;
@ -337,6 +362,7 @@ function draw_contact_form($sponsor_id, $contact = null){
if($id == "new"){
echo "<input type=\"hidden\" name=\"recordtype\" value=\"new\">\n";
$newcontactsearch="onkeypress=\"return newcontactsearch()\"";
$newcontactsave="id=\"contactnewsave\"";
}else{
echo "<input type=\"hidden\" name=\"recordtype\" value=\"existing\">\n";
echo "<input type=\"hidden\" name=\"userid\" value=\"" . $id . "\">\n";
@ -392,7 +418,7 @@ function draw_contact_form($sponsor_id, $contact = null){
<label><?=i18n("No")?><input type="radio" name="primary" value="no" <?php if($contact['primary'] != 'yes') echo "CHECKED";?>></label>
</td>
<?php
echo "<td align=\"center\"><input type=\"submit\" value=\"" . i18n("Save") . "\" onClick=\"return contactsinfo_save('" . $id . "')\" /></td>";
echo "<td align=\"center\"><input $newcontactsave type=\"submit\" value=\"" . i18n("Save") . "\" onClick=\"return contactsinfo_save('" . $id . "')\" /></td>";
echo "<td>";
if($id != "new")
echo "<input type=\"submit\" value=\"" . i18n("Remove") . "\" onClick=\"return contactsinfo_delete('" . $id . "')\" />";