forked from science-ation/science-ation
Updated to use an accordion style form for entering contacts. There is an issue with the wrong data being submitted from the form. Working on that next
This commit is contained in:
parent
1fa368293f
commit
ce9446d66a
@ -78,7 +78,9 @@
|
||||
break;
|
||||
|
||||
case 'contactsinfo_load':
|
||||
// make sure a donor id has been selected
|
||||
if($_GET['id']){
|
||||
// $sql = "SELECT
|
||||
draw_contactsinfo_form();
|
||||
}
|
||||
exit;
|
||||
@ -100,6 +102,7 @@
|
||||
|
||||
// save the contact info
|
||||
function save_contact(){
|
||||
global $config;
|
||||
//happy_("happy!");
|
||||
if(validate_contactdata()){
|
||||
// load or create the user, according to the situation
|
||||
@ -109,34 +112,38 @@ function save_contact(){
|
||||
$u = user_create("sponsor", $_POST['email']);
|
||||
$id = $u['id'];
|
||||
|
||||
|
||||
}else if($_POST['recordtype'] == 'existing'){
|
||||
// this is an existing record being updated. Load the user.
|
||||
$successMessage = i18n("Contact updated successfully");
|
||||
$successMessage = i18n("Contact updated successfully: " . $_POST['userid']);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// FIXME: userid not yet getting posted, so the rest of this if won't work.
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
happy_($successMessage);
|
||||
exit(1);
|
||||
$u = user_load($_POST['userid']);
|
||||
$id = intval($_POST['userid']);
|
||||
|
||||
}
|
||||
|
||||
$sponsor_id = $_GET['sponsor_id'];
|
||||
$sponsor_id = $_POST['sponsor_id'];
|
||||
$p = ($_POST['primary']=='yes')?'yes':'no';
|
||||
if($p == 'no') {
|
||||
/* Make sure this sponsor ($sponsor_id) has a primary */
|
||||
$q = mysql_query("SELECT users_id
|
||||
$query = "SELECT users_id
|
||||
FROM users_sponsor, users
|
||||
WHERE
|
||||
users_sponsor.users_id=users.id
|
||||
AND sponsors_id='$sponsor_id'
|
||||
AND `primary`='yes'
|
||||
AND year='".$config['FAIRYEAR']."'
|
||||
AND users_id!='$id'");
|
||||
AND users_id!='$id'";
|
||||
$q = mysql_query($query);
|
||||
if(mysql_num_rows($q) == 0) {
|
||||
/* This must be the primary */
|
||||
/* This has to be the primary since there isn't one already */
|
||||
$p = 'yes';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Unset all other primaries */
|
||||
mysql_query("UPDATE users_sponsor SET `primary`='no'
|
||||
@ -159,7 +166,6 @@ function save_contact(){
|
||||
$u['sponsors_id']=$sponsor_id;
|
||||
user_save($u);
|
||||
|
||||
|
||||
happy_($successMessage);
|
||||
}else{
|
||||
// something's wrong with the user data submitted. Should flag the fields where
|
||||
@ -175,11 +181,13 @@ function validate_contactdata(){
|
||||
if($_POST['recordtype'] != 'new' && $_POST['recordtype'] != 'existing'){
|
||||
$returnval = false;
|
||||
}
|
||||
|
||||
return $returnval;
|
||||
}
|
||||
|
||||
// draw a form for entering contact info
|
||||
// draw a group of forms for editing and creating new contacts
|
||||
function draw_contactsinfo_form($contact = null){
|
||||
global $config;
|
||||
// echo "<a href=\"sponsor_contacts.php?sponsors_id=$sponsors_id\"><< ".i18n("Back to %1 Contacts",array($sponsors_organization))."</a>\n";
|
||||
/*
|
||||
if($_GET['action']=="edit")
|
||||
@ -195,18 +203,55 @@ function draw_contactsinfo_form($contact = null){
|
||||
}
|
||||
$buttontext=i18n($buttontext);
|
||||
*/
|
||||
if($_GET['sponsors_id'])
|
||||
$sponsors_id=$_GET['sponsors_id'];
|
||||
else if($_POST['sponsors_id'])
|
||||
$sponsors_id=$_POST['sponsors_id'];
|
||||
$buttontext = i18n("Add Contact");
|
||||
// make sure we know what sponsor we're dealing with here
|
||||
if(!isset($sponsor_id)){
|
||||
if($_GET['id'])
|
||||
$sponsor_id=$_GET['id'];
|
||||
else if($_POST['id'])
|
||||
$sponsor_id=$_POST['id'];
|
||||
$buttontext = i18n("Add Contact");
|
||||
}
|
||||
|
||||
// start our accordion
|
||||
echo "<div id=\"levelaccordion\" style=\"width: 75%;\">\n";
|
||||
|
||||
// loop through each contact and draw a form with their data in it.
|
||||
$query = mysql_query("SELECT * FROM users LEFT JOIN users_sponsor ON users_sponsor.users_id=users.id
|
||||
WHERE year='" . $config['FAIRYEAR'] . "'
|
||||
AND sponsors_id='" . $sponsor_id . "'
|
||||
AND deleted='no'
|
||||
ORDER BY lastname,firstname");
|
||||
while($contact = mysql_fetch_array($query)){
|
||||
// draw a header for this user
|
||||
echo "<h3><a href=\"#\">";
|
||||
echo $contact["firstname"] . " " . $contact["lastname"];
|
||||
echo "</a></h3>\n";
|
||||
|
||||
// and draw the actual form
|
||||
echo "<div>\n";
|
||||
draw_contact_form($sponsor_id, $contact);
|
||||
echo "</div>\n";
|
||||
}
|
||||
// and then draw an empty form in which to enter a new user
|
||||
echo "<h3><a href=\"#\">New Contact";
|
||||
echo "</a></h3>\n";
|
||||
echo "<div>\n";
|
||||
draw_contact_form($sponsor_id);
|
||||
echo "</div>\n";
|
||||
|
||||
// end the accordion
|
||||
echo "</div>\n";
|
||||
|
||||
}
|
||||
|
||||
// draw a form in which to enter contact info
|
||||
//FIXME - this form needs to be pretty
|
||||
function draw_contact_form($sponsor_id, $contact = null){
|
||||
echo "<form id=\"createcontact\" method=\"post\" action=\"donors.php?action=contactsinfo_save\">\n";
|
||||
echo "<input type=\"hidden\" name=\"sponsor_id\" value=\"$sponsor_id\">\n";
|
||||
// echo "<input type=\"hidden\" name=\"save\" value=\"".$_GET['action']."\">\n";
|
||||
// if($_GET['action']=="edit")
|
||||
// the value passed here should be dynamically changed depending on how this form was reached
|
||||
echo "<input type=\"hidden\" name=\"recordtype\" value=\"new\">\n";
|
||||
echo "<input type=\"hidden\" name=\"sponsor_id\" value=\"".$_GET['id']."\">\n";
|
||||
echo "<input type=\"hidden\" name=\"recordtype\" value=\"existing\">\n";
|
||||
if($contact != null)
|
||||
echo "<input type=\"hidden\" name=\"userid\" value=\"" . $contact["id"] . "\">\n";
|
||||
echo "<table>\n";
|
||||
echo "<tr><td>".i18n("Salutation")."</td><td><input type=\"text\" name=\"salutation\" value=\"".htmlspecialchars($contact['salutation'])."\" size=\"4\" maxlength=\"8\" /></td></tr>\n";
|
||||
echo "<tr><td>".i18n("First Name")."</td><td><input type=\"text\" name=\"firstname\" value=\"".htmlspecialchars($contact['firstname'])."\" size=\"32\" maxlength=\"32\" /></td></tr>\n";
|
||||
@ -224,7 +269,7 @@ function draw_contactsinfo_form($contact = null){
|
||||
$sel = ($contact['primary'] == 'no') ? 'selected="selected"': '';
|
||||
echo "<option value=\"no\" $sel>".i18n('No')."</option>";
|
||||
echo "</select></td></tr>\n";
|
||||
echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"" . i18n("Save") . "\" onClick=\"return contactsinfo_save()\" />\n";
|
||||
echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"" . i18n("Save") . "\" onClick=\"return contactsinfo_save()\" /></td></tr>\n";
|
||||
echo "</table>\n";
|
||||
echo "</form>\n";
|
||||
}
|
||||
@ -357,7 +402,11 @@ function sponsorshipinfo_save() {
|
||||
function update_contactsinfo()
|
||||
{
|
||||
var id=sponsor_id;
|
||||
$("#editor_tab_contacts").load("<?=$_SERVER['PHP_SELF']?>?action=contactsinfo_load&id="+id);
|
||||
$("#editor_tab_contacts").load("<?=$_SERVER['PHP_SELF']?>?action=contactsinfo_load&id="+id, null,
|
||||
function() {
|
||||
$("#levelaccordion").accordion();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function contactsinfo_save() {
|
||||
|
Loading…
Reference in New Issue
Block a user