diff --git a/admin/award_contacts.php b/admin/award_contacts.php index 37c3246..ec7646f 100644 --- a/admin/award_contacts.php +++ b/admin/award_contacts.php @@ -63,15 +63,34 @@ if($_POST['save']=="edit" || $_POST['save']=="add") { + $p = ($_POST['primary']=='yes')?'yes':'no'; + if($_POST['save']=="add") { $q=mysql_query("INSERT INTO award_contacts (award_sponsors_id,year) VALUES ('$award_sponsors_id','".$config['FAIRYEAR']."')"); $id=mysql_insert_id(); } else - $id=$_POST['id']; + $id=intval($_POST['id']); + + if($p == 'no') { + /* Make sure this sponsor ($award_sponsors_id) has a primary */ + $q = mysql_query("SELECT id FROM award_contacts WHERE + award_sponsors_id='$award_sponsors_id' + AND year={$config['FAIRYEAR']} + AND `primary`='yes' + AND id!='$id'"); + if(mysql_num_rows($q) == 0) { + /* This must be the primary */ + $p = 'yes'; + } + } else { + /* Unset all other primaries */ + mysql_query("UPDATE award_contacts SET `primary`='no' + WHERE award_sponsors_id='$award_sponsors_id' + AND year={$config['FAIRYEAR']}"); + } - $p = ($_POST['primary']=='yes')?'yes':'no'; $exec="UPDATE award_contacts SET ". "salutation='".mysql_escape_string(stripslashes($_POST['salutation']))."', ". "firstname='".mysql_escape_string(stripslashes($_POST['firstname']))."', ". @@ -163,6 +182,7 @@ echo "