From 1dad6505ebef9af1d719ae0ab9b95bddb2b4e206 Mon Sep 17 00:00:00 2001 From: dave Date: Thu, 13 Dec 2007 21:50:31 +0000 Subject: [PATCH] - Select the first contact for each sponsor as the primary - Prevent the user from setting zero, or more than one, primary contact. - Add a primary column to the contacts table, so they can see the automatic set/unset operations on the primary contact. --- admin/award_contacts.php | 26 ++++++++++++++++++++++++-- db/db.update.81.php | 11 +++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 db/db.update.81.php 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"); + } +} +?> +