forked from science-ation/science-ation
A rudimentary start on adding contacts
This commit is contained in:
parent
4f588a5859
commit
f140ce05a0
257
admin/donors.php
257
admin/donors.php
@ -78,27 +78,16 @@
|
||||
break;
|
||||
|
||||
case 'contactsinfo_load':
|
||||
draw_contactsinfo_form();
|
||||
if($_GET['id']){
|
||||
draw_contactsinfo_form();
|
||||
}
|
||||
exit;
|
||||
break;
|
||||
|
||||
case 'contactsinfo_save':
|
||||
$u = user_create('sponsor', $_POST['email']);
|
||||
|
||||
$u['salutation']=$_POST['salutation'];
|
||||
$u['firstname']=$_POST['firstname'];
|
||||
$u['lastname']=$_POST['lastname'];
|
||||
$u['position']=$_POST['position'];
|
||||
$u['phonework']=$_POST['phonework'];
|
||||
$u['phonecell']=$_POST['phonecell'];
|
||||
$u['phonehome']=$_POST['phonehome'];
|
||||
$u['fax']=$_POST['fax'];
|
||||
$u['email']=$_POST['email'];
|
||||
// $u['notes']=$_POST['notes'];
|
||||
// $u['sponsors_id']=$sponsors_id;
|
||||
user_save($u);
|
||||
// happy_("happy!");
|
||||
save_contact();
|
||||
|
||||
// draw_contactsinfo_form();
|
||||
exit;
|
||||
break;
|
||||
}
|
||||
@ -109,119 +98,135 @@
|
||||
'Fundraising' => 'admin/fundraising.php')
|
||||
);
|
||||
|
||||
function draw_contactsinfo_form(){
|
||||
// use a basic form for now and beautify later
|
||||
?>
|
||||
<form id="createcontact" method="post" action="donors.php">
|
||||
<table class="editor"><tr>
|
||||
<td><?=i18n("First Name") ?></td>
|
||||
<td><input type="text" name="firstname" /></td>
|
||||
<td><?=i18n("Last Name") ?></td>
|
||||
<td><input type="text" name="lastname" /></td>
|
||||
<td><?=i18n("Email") ?></td>
|
||||
<td><input type="text" name="email" /></td>
|
||||
</tr><tr>
|
||||
<td><?=i18n("Home Phone") ?></td>
|
||||
<td><input type="text" name="phonehome" /></td>
|
||||
<td><?=i18n("Work Phone") ?></td>
|
||||
<td><input type="text" name="phonework" /></td>
|
||||
<td><?=i18n("Cell Phone") ?></td>
|
||||
<td><input type="text" name="phonecell" /></td>
|
||||
</tr><tr>
|
||||
<td><?=i18n("Fax") ?></td>
|
||||
<td><input type="text" name="fax" /></td>
|
||||
<td><?=i18n("Position") ?></td>
|
||||
<td><input type="text" name="position" /></td>
|
||||
<td><?=i18n("Salutation") ?></td>
|
||||
<td><input type="text" name="salutation" /></td>
|
||||
<?php /*
|
||||
</tr><tr>
|
||||
<td><?=i18n("Username") ?></td>
|
||||
<td><input type="text" name="username" /></td>
|
||||
<td><?=i18n("Organization") ?></td>
|
||||
<td><input type="text" name="organization" /></td>
|
||||
<td><?=i18n("") ?></td>
|
||||
<td><input type="text" name="" /></td>
|
||||
</tr><tr>
|
||||
<td><?=i18n("") ?></td>
|
||||
<td><input type="text" name="" /></td>
|
||||
<td><?=i18n("") ?></td>
|
||||
<td><input type="text" name="" /></td>
|
||||
<td><?=i18n("") ?></td>
|
||||
<td><input type="text" name="" /></td>
|
||||
*/ ?>
|
||||
</tr><tr>
|
||||
<td colspan="6">
|
||||
<input type="submit" value="<?=i18n("Save") ?>" onClick="return contactsinfo_save()" />
|
||||
</tr></table>
|
||||
// save the contact info
|
||||
function save_contact(){
|
||||
//happy_("happy!");
|
||||
if(validate_contactdata()){
|
||||
// load or create the user, according to the situation
|
||||
if($_POST['recordtype'] == 'new'){
|
||||
// this is a new record being submitted. Create the user.
|
||||
$successMessage = i18n("Contact created successfully");
|
||||
$u = user_create("sponsor", $_POST['email']);
|
||||
$id = $u['id'];
|
||||
|
||||
</form>
|
||||
<?php
|
||||
}else if($_POST['recordtype'] == 'existing'){
|
||||
// this is an existing record being updated. Load the user.
|
||||
$successMessage = i18n("Contact updated successfully");
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// FIXME: userid not yet getting posted, so the rest of this if won't work.
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
exit(1);
|
||||
$u = user_load($_POST['userid']);
|
||||
$id = intval($_POST['userid']);
|
||||
}
|
||||
|
||||
$sponsor_id = $_GET['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
|
||||
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'");
|
||||
if(mysql_num_rows($q) == 0) {
|
||||
/* This must be the primary */
|
||||
$p = 'yes';
|
||||
}
|
||||
} else {
|
||||
/* Unset all other primaries */
|
||||
mysql_query("UPDATE users_sponsor SET `primary`='no'
|
||||
WHERE sponsors_id='$sponsor_id'");
|
||||
}
|
||||
|
||||
// we now know whether or not they're the primary user. Update them with that,
|
||||
// along with all of the user info that's been submitted.
|
||||
$u['primary']=$p;
|
||||
$u['salutation']=$_POST['salutation'];
|
||||
$u['firstname']=$_POST['firstname'];
|
||||
$u['lastname']=$_POST['lastname'];
|
||||
$u['position']=$_POST['position'];
|
||||
$u['phonework']=$_POST['phonework'];
|
||||
$u['phonecell']=$_POST['phonecell'];
|
||||
$u['phonehome']=$_POST['phonehome'];
|
||||
$u['fax']=$_POST['fax'];
|
||||
$u['email']=$_POST['email'];
|
||||
$u['notes']=$_POST['notes'];
|
||||
$u['sponsors_id']=$sponsor_id;
|
||||
user_save($u);
|
||||
|
||||
|
||||
happy_($successMessage);
|
||||
}else{
|
||||
// something's wrong with the user data submitted. Should flag the fields where
|
||||
// appropriate, but for now just pop up an error
|
||||
error_("Form not filled out");
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: dummy filler function for now. Should go through all of the fields
|
||||
// submitted and validate before hitting the database
|
||||
function validate_contactdata(){
|
||||
$returnval = true;
|
||||
if($_POST['recordtype'] != 'new' && $_POST['recordtype'] != 'existing'){
|
||||
$returnval = false;
|
||||
}
|
||||
return $returnval;
|
||||
}
|
||||
|
||||
// draw a form for entering contact info
|
||||
function draw_contactsinfo_form($contact = null){
|
||||
// echo "<a href=\"sponsor_contacts.php?sponsors_id=$sponsors_id\"><< ".i18n("Back to %1 Contacts",array($sponsors_organization))."</a>\n";
|
||||
/*
|
||||
$sponsors_id=intval($_GET['id']);
|
||||
$q=mysql_query("SELECT id,
|
||||
uid,
|
||||
year,
|
||||
firstname,
|
||||
lastname,
|
||||
deleted,
|
||||
salutation,
|
||||
email,
|
||||
phonework,
|
||||
phonecell,
|
||||
`primary`
|
||||
FROM users,users_sponsor
|
||||
WHERE
|
||||
`types` LIKE '%sponsor%'
|
||||
AND sponsors_id='$sponsors_id'
|
||||
AND users_sponsor.users_id=users.id
|
||||
AND users.deleted='no'
|
||||
ORDER BY year DESC");
|
||||
echo mysql_error();
|
||||
|
||||
echo "<table class=\"tableview\">";
|
||||
echo "<tr>";
|
||||
echo " <th>".i18n("Year")."</th>";
|
||||
echo " <th>".i18n("Name")."</th>";
|
||||
echo " <th>".i18n("Email")."</th>";
|
||||
echo " <th>".i18n("Phone (Work)")."</th>";
|
||||
echo " <th>".i18n("Phone (Cell)")."</th>";
|
||||
echo " <th>".i18n("Primary")."</th>";
|
||||
echo " <th>Actions</th>";
|
||||
echo "</tr>\n";
|
||||
|
||||
while($r=mysql_fetch_object($q)) {
|
||||
echo "<tr>\n";
|
||||
echo " <td>$r->year</td>\n";
|
||||
echo " <td>";
|
||||
if($r->salutation) echo $r->salutation." ";
|
||||
echo "$r->firstname $r->lastname</td>\n";
|
||||
echo " <td>";
|
||||
if($r->email) {
|
||||
list($eb,$ea)=split("@",$r->email);
|
||||
echo $r->email;
|
||||
}
|
||||
else
|
||||
echo " ";
|
||||
|
||||
echo " </td>";
|
||||
echo " <td>$r->phonework</td>\n";
|
||||
echo " <td>$r->phonecell</td>\n";
|
||||
$p = i18n(($r->primary=='yes')?'Yes':'No');
|
||||
echo " <td>$p</td>\n";
|
||||
echo " <td align=\"center\">";
|
||||
//FIXME: should we just go to /user_personal.php here instead?
|
||||
echo "<a href=\"sponsor_contacts.php?sponsors_id=$sponsors_id&action=edit&edit=$r->id\"><img border=\"0\" src=\"".$config['SFIABDIRECTORY']."/images/16/edit.".$config['icon_extension']."\"></a>";
|
||||
echo " ";
|
||||
echo "<a onclick=\"return confirmClick('Are you sure you want to remove this contact?')\" href=\"sponsor_contacts.php?sponsors_id=$sponsors_id&action=delete&delete=$r->id\"><img border=0 src=\"".$config['SFIABDIRECTORY']."/images/16/button_cancel.".$config['icon_extension']."\"></a>";
|
||||
echo " </td>\n";
|
||||
|
||||
|
||||
echo "</tr>\n";
|
||||
}
|
||||
echo "</table>\n";
|
||||
if($_GET['action']=="edit")
|
||||
{
|
||||
echo "<h3>".i18n("Edit %1 Contact",array($sponsors_organization))."</h3>\n";
|
||||
$buttontext="Save Contact";
|
||||
$u=user_load(intval($_GET['edit']));
|
||||
}
|
||||
else if($_GET['action']=="add")
|
||||
{
|
||||
echo "<h3>".i18n("Add %1 Contact",array($sponsors_organization))."</h3>\n";
|
||||
$buttontext="Add Contact";
|
||||
}
|
||||
$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");
|
||||
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 "<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";
|
||||
echo "<tr><td>".i18n("Last Name")."</td><td><input type=\"text\" name=\"lastname\" value=\"".htmlspecialchars($contact['lastname'])."\" size=\"32\" maxlength=\"32\" /></td></tr>\n";
|
||||
echo "<tr><td>".i18n("Position")."</td><td><input type=\"text\" name=\"position\" value=\"".htmlspecialchars($contact['position'])."\" size=\"60\" maxlength=\"64\" /></td></tr>\n";
|
||||
echo "<tr><td>".i18n("Phone (Work)")."</td><td><input type=\"text\" name=\"phonework\" value=\"".htmlspecialchars($contact['phonework'])."\" size=\"16\" maxlength=\"32\" /></td></tr>\n";
|
||||
echo "<tr><td>".i18n("Phone (Cell)")."</td><td><input type=\"text\" name=\"phonecell\" value=\"".htmlspecialchars($contact['phonecell'])."\" size=\"16\" maxlength=\"32\" /></td></tr>\n";
|
||||
echo "<tr><td>".i18n("Phone (Home)")."</td><td><input type=\"text\" name=\"phonehome\" value=\"".htmlspecialchars($contact['phonehome'])."\" size=\"16\" maxlength=\"32\" /></td></tr>\n";
|
||||
echo "<tr><td>".i18n("Fax")."</td><td><input type=\"text\" name=\"fax\" value=\"".htmlspecialchars($contact['fax'])."\" size=\"16\" maxlength=\"32\" /></td></tr>\n";
|
||||
echo "<tr><td>".i18n("Email")."</td><td><input type=\"text\" name=\"email\" value=\"".htmlspecialchars($contact['email'])."\" size=\"60\" maxlength=\"128\" /></td></tr>\n";
|
||||
echo "<tr><td>".i18n("Notes")."</td><td><textarea name=\"notes\" rows=\"8\" cols=\"60\">".htmlspecialchars($contact['notes'])."</textarea></td></tr>\n";
|
||||
echo "<tr><td>".i18n("Primary Contact")."</td><td><select name=\"primary\">";
|
||||
$sel = ($contact['primary'] == 'yes') ? 'selected="selected"': '';
|
||||
echo "<option value=\"yes\" $sel>".i18n('Yes')."</option>";
|
||||
$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 "</table>\n";
|
||||
echo "</form>\n";
|
||||
}
|
||||
|
||||
?>
|
||||
@ -356,7 +361,7 @@ function update_contactsinfo()
|
||||
}
|
||||
|
||||
function contactsinfo_save() {
|
||||
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=contactsinfo_save", $("#contactsinfo").serializeArray());
|
||||
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=contactsinfo_save", $("#createcontact").serializeArray());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user