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 " ".i18n("Email").""; echo " ".i18n("Phone (Work)").""; echo " ".i18n("Phone (Cell)").""; + echo " ".i18n("Primary").""; echo " Actions"; echo "\n"; @@ -185,6 +205,8 @@ echo ""; echo " $r->phonework\n"; echo " $r->phonecell\n"; + $p = i18n(($r->primary=='yes')?'Yes':''); + echo " $p\n"; echo " "; echo "id\">"; echo " "; diff --git a/db/db.update.81.php b/db/db.update.81.php new file mode 100644 index 0000000..192d18e --- /dev/null +++ b/db/db.update.81.php @@ -0,0 +1,11 @@ +award_sponsors_id; + mysql_query("UPDATE award_contacts SET `primary`='yes' WHERE award_sponsors_id='$asid' LIMIT 1"); + } +} +?> +