From ed72fb394487a909f6e4d6fbf83b4f05f53738ca Mon Sep 17 00:00:00 2001 From: james Date: Thu, 17 Sep 2009 20:03:56 +0000 Subject: [PATCH] Add ability to create new sponsors usign the popup editor - basically it posts a sponsor_id=-1 and which causes it to insert a new record, then do the normal save, then it closes and re-opens the editor with the id that is returned by the save post via json --- admin/sponsors.php | 158 +++++++++++---------------------------------- 1 file changed, 36 insertions(+), 122 deletions(-) diff --git a/admin/sponsors.php b/admin/sponsors.php index 4bc7bc1..fada89e 100644 --- a/admin/sponsors.php +++ b/admin/sponsors.php @@ -35,7 +35,13 @@ break; case 'organizationinfo_save': - $id=$_POST['sponsor_id']; + $id=intval($_POST['sponsor_id']); + if($id==-1) { + $q=mysql_query("INSERT INTO sponsors (year) VALUES ('".$config['FAIRYEAR']."')"); + $id=mysql_insert_id(); + echo json_encode(array("id"=>$id)); + } + if($id) { $exec="UPDATE sponsors SET ". "organization='".mysql_escape_string(stripslashes($_POST['organization']))."', ". @@ -59,7 +65,6 @@ //FIXME accept the logo //"logo='".mysql_escape_string(stripslashes($_POST['logo']))."', ". - happy_("Organization Info Saved"); } exit; break; @@ -126,8 +131,15 @@ function popup_editor(id) $('#popup_editor').dialog('option', 'height', h); $("#popup_editor").dialog('open'); - $('#editor_tabs').tabs('option', 'disabled', []); - $('#editor_tabs').tabs('option', 'selected', 0); + if(id==-1) { + $('#editor_tabs').tabs('option', 'selected', 0); + $('#editor_tabs').tabs('option', 'disabled', [1,2,3]); + + } + else { + $('#editor_tabs').tabs('option', 'selected', 0); + $('#editor_tabs').tabs('option', 'disabled', []); + } update_organizationinfo(); return false; @@ -136,7 +148,12 @@ function popup_editor(id) function update_organizationinfo() { var id=sponsor_id; - if(!sponsor_id) return false; + if(!sponsor_id) + return false; + if(sponsor_id==-1) { + $("#sponsor_id").val(-1); + return false; + } $.getJSON("?action=organizationinfo_load&id="+id, function(json){ @@ -161,7 +178,18 @@ function update_organizationinfo() } function organizationinfo_save() { - $("#debug").load("?action=organizationinfo_save", $("#organizationinfo").serializeArray()); + + //if we're creating we need to do the post, and get the id it returns, so we can re-open the popup window with that id + if($("#sponsor_id").val()==-1) { + $.post("?action=organizationinfo_save", $("#organizationinfo").serializeArray(), + function(json) { + $("#popup_editor").dialog('close'); + popup_editor(json.id); + }, + "json"); + } + else + $("#debug").load("?action=organizationinfo_save", $("#organizationinfo").serializeArray()); return false; } @@ -269,43 +297,6 @@ function activityinfo_save() { << ".i18n("Back to Award Sponsors")."\n"; - if($_GET['action']=="edit") - { - echo "

".i18n("Edit Award Sponsor")."

\n"; - $buttontext="Save Sponsor"; - $q=mysql_query("SELECT * FROM sponsors WHERE id='".$_GET['edit']."'"); - $r=mysql_fetch_object($q); - } - else if($_GET['action']=="add") - { - echo "

".i18n("Add New Award Sponsor")."

\n"; - $buttontext="Add Sponsor"; - } - $buttontext=i18n($buttontext); - - echo "
\n"; - echo "\n"; - - if($_GET['action']=="edit") - 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 "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - - echo "
".i18n("Organization Name")."organization)."\" size=\"60\" maxlength=\"128\" />
".i18n("Address")."address)."\" size=\"60\" maxlength=\"64\" />
".i18n("City")."city)."\" size=\"32\" maxlength=\"32\" />
".i18n($config['provincestate']).""; - emit_province_selector("province_code",$r->province_code); - echo "
".i18n($config['postalzip'])."postalcode\" size=\"8\" maxlength=\"7\" />
".i18n("Phone")."phone)."\" size=\"16\" maxlength=\"32\" />
".i18n("Toll Free")."tollfree)."\" size=\"16\" maxlength=\"32\" />
".i18n("Fax")."fax)."\" size=\"16\" maxlength=\"32\" />
".i18n("Email")."email)."\" size=\"60\" maxlength=\"128\" />
".i18n("Website")."website)."\" size=\"60\" maxlength=\"128\" />
".i18n("Donation Policy URL")."donationpolicyurl)."\" size=\"60\" maxlength=\"128\" />
".i18n("Funding Selection Date").""; - emit_date_selector("fundingselectiondate",$r->fundingselectiondate); - echo "
".i18n("Logo")."
".i18n("Waiver Accepted").""; - if($r->waiveraccepted=="no") $ch="checked=\"checked\""; else $ch=""; - echo "".i18n("No")."   "; - if($r->waiveraccepted=="yes") $ch="checked=\"checked\""; else $ch=""; - echo "".i18n("Yes")."   "; - echo "
".i18n("Tax Receipt Required").""; - if($r->taxreceiptrequired=="no") $ch="checked=\"checked\""; else $ch=""; - echo "".i18n("No")."   "; - if($r->taxreceiptrequired=="yes") $ch="checked=\"checked\""; else $ch=""; - echo "".i18n("Yes")."   "; - echo "
".i18n("Notes")."
\n"; - echo "
\n"; - - - - } - else - { - echo "Add New Sponsor\n"; + echo "Add New Sponsor\n"; echo "
"; echo ""; echo ""; @@ -388,7 +313,7 @@ function activityinfo_save() { echo " "; echo " "; echo " "; - echo " "; +// echo " "; echo "\n"; //$q=mysql_query("SELECT * FROM award_sponsors WHERE year='".$config['FAIRYEAR']."' ORDER BY organization"); @@ -429,22 +354,11 @@ function activityinfo_save() { echo "$numcontacts  "; echo "id\">\"view\""; echo ""; - echo " \n"; echo "\n"; } echo "
# of Sponsorships# of Awards# of ContactsActionAction
"; - echo "id\">"; - /* cannot delete sponsors, we need to be able to link to them from other years, etc... this could be turned back on as a soft delete eventually - echo " "; - echo "id\">"; -*/ - - echo "
\n"; - - } - send_footer(); ?>