forked from science-ation/science-ation
- 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.
This commit is contained in:
parent
dcfcd358fc
commit
1dad6505eb
@ -63,15 +63,34 @@
|
|||||||
|
|
||||||
if($_POST['save']=="edit" || $_POST['save']=="add")
|
if($_POST['save']=="edit" || $_POST['save']=="add")
|
||||||
{
|
{
|
||||||
|
$p = ($_POST['primary']=='yes')?'yes':'no';
|
||||||
|
|
||||||
if($_POST['save']=="add")
|
if($_POST['save']=="add")
|
||||||
{
|
{
|
||||||
$q=mysql_query("INSERT INTO award_contacts (award_sponsors_id,year) VALUES ('$award_sponsors_id','".$config['FAIRYEAR']."')");
|
$q=mysql_query("INSERT INTO award_contacts (award_sponsors_id,year) VALUES ('$award_sponsors_id','".$config['FAIRYEAR']."')");
|
||||||
$id=mysql_insert_id();
|
$id=mysql_insert_id();
|
||||||
}
|
}
|
||||||
else
|
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 ".
|
$exec="UPDATE award_contacts SET ".
|
||||||
"salutation='".mysql_escape_string(stripslashes($_POST['salutation']))."', ".
|
"salutation='".mysql_escape_string(stripslashes($_POST['salutation']))."', ".
|
||||||
"firstname='".mysql_escape_string(stripslashes($_POST['firstname']))."', ".
|
"firstname='".mysql_escape_string(stripslashes($_POST['firstname']))."', ".
|
||||||
@ -163,6 +182,7 @@
|
|||||||
echo " <th>".i18n("Email")."</th>";
|
echo " <th>".i18n("Email")."</th>";
|
||||||
echo " <th>".i18n("Phone (Work)")."</th>";
|
echo " <th>".i18n("Phone (Work)")."</th>";
|
||||||
echo " <th>".i18n("Phone (Cell)")."</th>";
|
echo " <th>".i18n("Phone (Cell)")."</th>";
|
||||||
|
echo " <th>".i18n("Primary")."</th>";
|
||||||
echo " <th>Actions</th>";
|
echo " <th>Actions</th>";
|
||||||
echo "</tr>\n";
|
echo "</tr>\n";
|
||||||
|
|
||||||
@ -185,6 +205,8 @@
|
|||||||
echo "</td>";
|
echo "</td>";
|
||||||
echo " <td>$r->phonework</td>\n";
|
echo " <td>$r->phonework</td>\n";
|
||||||
echo " <td>$r->phonecell</td>\n";
|
echo " <td>$r->phonecell</td>\n";
|
||||||
|
$p = i18n(($r->primary=='yes')?'Yes':'');
|
||||||
|
echo " <td>$p</td>\n";
|
||||||
echo " <td align=\"center\">";
|
echo " <td align=\"center\">";
|
||||||
echo "<a href=\"award_contacts.php?award_sponsors_id=$award_sponsors_id&action=edit&edit=$r->id\"><img border=\"0\" src=\"".$config['SFIABDIRECTORY']."/images/16/edit.".$config['icon_extension']."\"></a>";
|
echo "<a href=\"award_contacts.php?award_sponsors_id=$award_sponsors_id&action=edit&edit=$r->id\"><img border=\"0\" src=\"".$config['SFIABDIRECTORY']."/images/16/edit.".$config['icon_extension']."\"></a>";
|
||||||
echo " ";
|
echo " ";
|
||||||
|
11
db/db.update.81.php
Normal file
11
db/db.update.81.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?
|
||||||
|
function db_update_81_post()
|
||||||
|
{
|
||||||
|
$q = mysql_query("SELECT DISTINCT award_sponsors_id FROM award_contacts");
|
||||||
|
while($i = mysql_fetch_object($q)) {
|
||||||
|
$asid = $i->award_sponsors_id;
|
||||||
|
mysql_query("UPDATE award_contacts SET `primary`='yes' WHERE award_sponsors_id='$asid' LIMIT 1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user