From f140ce05a072715b3509200ca0a51f10fb97a706 Mon Sep 17 00:00:00 2001 From: jacob Date: Fri, 2 Oct 2009 18:10:55 +0000 Subject: [PATCH] A rudimentary start on adding contacts --- admin/donors.php | 257 ++++++++++++++++++++++++----------------------- 1 file changed, 131 insertions(+), 126 deletions(-) diff --git a/admin/donors.php b/admin/donors.php index ce755b4..707642e 100644 --- a/admin/donors.php +++ b/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 -?> -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ ?> - -
- " onClick="return contactsinfo_save()" /> -
+// 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']; -
-<< ".i18n("Back to %1 Contacts",array($sponsors_organization))."\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 ""; - echo ""; - echo " "; - echo " "; - echo " "; - echo " "; - echo " "; - echo " "; - echo " "; - echo "\n"; - - while($r=mysql_fetch_object($q)) { - echo "\n"; - echo " \n"; - echo " \n"; - echo " "; - echo " \n"; - echo " \n"; - $p = i18n(($r->primary=='yes')?'Yes':'No'); - echo " \n"; - echo " \n"; - - - echo "\n"; - } - echo "
".i18n("Year")."".i18n("Name")."".i18n("Email")."".i18n("Phone (Work)")."".i18n("Phone (Cell)")."".i18n("Primary")."Actions
$r->year"; - if($r->salutation) echo $r->salutation." "; - echo "$r->firstname $r->lastname"; - if($r->email) { - list($eb,$ea)=split("@",$r->email); - echo $r->email; - } - else - echo " "; - - echo " $r->phonework$r->phonecell$p"; - //FIXME: should we just go to /user_personal.php here instead? - echo "id\">"; - echo " "; - echo "id\">"; - echo "
\n"; + if($_GET['action']=="edit") + { + echo "

".i18n("Edit %1 Contact",array($sponsors_organization))."

\n"; + $buttontext="Save Contact"; + $u=user_load(intval($_GET['edit'])); + } + else if($_GET['action']=="add") + { + echo "

".i18n("Add %1 Contact",array($sponsors_organization))."

\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 "
\n"; + echo "\n"; +// echo "\n"; +// if($_GET['action']=="edit") + // the value passed here should be dynamically changed depending on how this form was reached + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
".i18n("Salutation")."
".i18n("First Name")."
".i18n("Last Name")."
".i18n("Position")."
".i18n("Phone (Work)")."
".i18n("Phone (Cell)")."
".i18n("Phone (Home)")."
".i18n("Fax")."
".i18n("Email")."
".i18n("Notes")."
".i18n("Primary Contact")."
\n"; + echo "
\n"; + echo "
\n"; } ?> @@ -356,7 +361,7 @@ function update_contactsinfo() } function contactsinfo_save() { - $("#debug").load("?action=contactsinfo_save", $("#contactsinfo").serializeArray()); + $("#debug").load("?action=contactsinfo_save", $("#createcontact").serializeArray()); return false; }