<?
/* 
   This file is part of the 'Science Fair In A Box' project
   SFIAB Website: http://www.sfiab.ca

   Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
   Copyright (C) 2008 James Grant <james@lightbox.org>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation, version 2.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/
?>
<?
require("../common.inc.php");
require_once("../user.inc.php");
user_auth_required('committee', 'admin');

switch($_GET['action']) {
	case 'organizationinfo_load':
		$id=intval($_GET['id']);
		$q=mysql_query("SELECT * FROM sponsors WHERE id='$id'");
		$ret=mysql_fetch_assoc($q);
		echo json_encode($ret);		
		exit;
		break;

	case 'organizationinfo_save':
		$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']))."', ".
			"address='".mysql_escape_string(stripslashes($_POST['address']))."', ".
			"city='".mysql_escape_string(stripslashes($_POST['city']))."', ".
			"province_code='".mysql_escape_string(stripslashes($_POST['province_code']))."', ".
			"postalcode='".mysql_escape_string(stripslashes($_POST['postalcode']))."', ".
			"phone='".mysql_escape_string(stripslashes($_POST['phone']))."', ".
			"tollfree='".mysql_escape_string(stripslashes($_POST['tollfree']))."', ".
			"fax='".mysql_escape_string(stripslashes($_POST['fax']))."', ".
			"email='".mysql_escape_string(stripslashes($_POST['email']))."', ".
			"website='".mysql_escape_string(stripslashes($_POST['website']))."', ".
			"notes='".mysql_escape_string(stripslashes($_POST['notes']))."', ".
			"donationpolicyurl='".mysql_escape_string(stripslashes($_POST['donationpolicyurl']))."', ".
			"fundingselectiondate='".mysql_escape_string(stripslashes($_POST['fundingselectiondate']))."', ".
			"waiveraccepted='".mysql_escape_string(stripslashes($_POST['waiveraccepted']))."', ".
			"taxreceiptrequired='".mysql_escape_string(stripslashes($_POST['taxreceiptrequired']))."' ".
			"WHERE id='$id'";
			mysql_query($exec);

			//FIXME accept the logo
			//"logo='".mysql_escape_string(stripslashes($_POST['logo']))."', ".
//($comment , $donorId, $userId, $type, $campaign_id=null){
			save_activityinfo("Updated organization info for {$_POST['organization']}", $id, $_SESSION['user_uid'],"System");
		}
		exit;
		break;
	case 'sponsorshipinfo_load':
		$id=intval($_GET['id']);
		$ret=array();
		echo json_encode($ret);		
		exit;
		break;
	
	case 'contactsinfo_load':
		// make sure a donor id has been selected
		if($_GET['id']){
			draw_contactsinfo_form();
	   	}
		exit;
		break;

	case 'contactsinfo_save':
		save_contact();
		exit;
		break;
	case 'contactsinfo_delete':
		delete_contact();
		exit;
		break;
	case 'activityinfo_load':
		// make sure a donor id has been selected
		if($_GET['id']){
			draw_activityinfo_form();
		}
		exit;
		break;
 	case 'activityinfo_save':
//($comment , $donorId, $userId, $type, $campaign_id=null){
		if(save_activityinfo(
                $_POST['comment'],
                $_GET['id'],
                $_SESSION['users_uid'],
                $_POST['type'],
                $_POST['fundraising_campaigns_id']
                )){
			happy_("Activity Logged");
		}else{
			error_("Unable to save activity log");
		}
		exit;
		break;
}

send_header("Donor/Sponsor Management",
		array('Committee Main' => 'committee_main.php',
			'Administration' => 'admin/index.php',
			'Fundraising' => 'admin/fundraising.php')
		);

//delete the contact who has been submitted in _POST
function delete_contact(){
	if(array_key_exists('userid', $_POST)){
		$uid = $_POST['userid'];
		$data = mysql_query("SELECT CONCAT_WS(' ', users.firstname, users.lastname) AS name FROM users WHERE id=" . $uid);
		$namedata = mysql_fetch_array($data);
		$name = trim($namedata['name']);
		user_delete($uid);
		happy_("Deleted contact %1", array($name));

//($comment , $donorId, $userId, $type, $campaign_id=null){
		save_activityinfo("Deleted contact \"$name\"",$_GET['id'],$_SESSION['users_uid'],'System' );
	}
}

// save the contact info
function save_contact(){
	global $config;
	//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 = "Contact created successfully";
			$successLog = "Added 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 = "Contact updated successfully";
			$successLog = "Updated contact ";

			$u = user_load($_POST['userid']);
			$id = intval($_POST['userid']);
		}

		$sponsor_id = $_POST['sponsor_id'];
		$p = ($_POST['primary']=='yes')?'yes':'no';
		if($p == 'no') {
			/* Make sure this sponsor ($sponsor_id) has a primary */
			$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'";
			$q = mysql_query($query);
			if(mysql_num_rows($q) == 0) {
				/* 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'
					WHERE sponsors_id='$sponsor_id' AND users_id != '$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.
        echo "setting primary $p";
		$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);
		$name = trim($u['firstname'] . ' ' . $u['lastname']);
//($comment , $donorId, $userId, $type, $campaign_id=null){
		save_activityinfo($successLog . '"' . $name . '"',$sponsor_id,$_SESSION['users_uid'],'System');
		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 group of forms for editing and creating new contacts
function draw_contactsinfo_form($contact = null){
	global $config;

	// 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=\"contactaccordion\" style=\"width: 740px;\">\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 users_sponsor.primary DESC,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";
	}

	// 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";

	// and finally end the accordion
	echo "</div>\n";

}

// draw a form in which to enter information about the various contacts
function draw_contact_form($sponsor_id, $contact = null){
	if($contact != null){
		$id = $contact["id"];
	}else{
			$id = "new";
	}
	echo "<form id=\"contact_" . $id . "\" method=\"post\" action=\"donors.php?action=contactsinfo_save\">\n";
	echo "<input type=\"hidden\" name=\"sponsor_id\" value=\"$sponsor_id\">\n";
	if($id == "new"){
		echo "<input type=\"hidden\" name=\"recordtype\" value=\"new\">\n";
	}else{
		echo "<input type=\"hidden\" name=\"recordtype\" value=\"existing\">\n";
		echo "<input type=\"hidden\" name=\"userid\" value=\"" . $id . "\">\n";
	}
?>
	<table class="tableedit">
		<tr>
			<td><?=i18n("Salutation"); ?></td>
			<td><input type="text" name="salutation" size="4" value = "<?=htmlspecialchars($contact['salutation'])?>"></td>
			<td><?=i18n("Position"); ?></td>
			<td><input type="text" name="position" value = "<?=htmlspecialchars($contact['position'])?>"></td>
		</tr>
		<tr>
			<td><?=i18n("First Name"); ?></td>
			<td><input type="text" name="firstname" value = "<?=htmlspecialchars($contact['firstname'])?>"></td>
			<td><?=i18n("Last Name"); ?></td>
			<td><input type="text" name="lastname" value = "<?=htmlspecialchars($contact['lastname'])?>"></td>
		</tr>
		<tr>
			<td><?=i18n("Phone (Work)"); ?></td>
			<td><input type="text" name="phonework" value = "<?=htmlspecialchars($contact['phonework'])?>"></td>
			<td><?=i18n("Phone (Cell)"); ?></td>
			<td><input type="text" name="phonecell" value = "<?=htmlspecialchars($contact['phonecell'])?>"></td>
		</tr>
		<tr>
			<td><?=i18n("Phone (Home)"); ?></td>
			<td><input type="text" name="phonehome" value = "<?=htmlspecialchars($contact['phonehome'])?>"></td>
			<td><?=i18n("Fax"); ?></td>
			<td><input type="text" name="fax" value = "<?=htmlspecialchars($contact['fax'])?>"></td>
		</tr>
		<tr>
			<td><?=i18n("Email"); ?></td>
			<td colspan="3"><input type="text" name="email" size="60" value = "<?=htmlspecialchars($contact['email'])?>"></td>
		</tr>
		<tr>
			<td><?=i18n("Notes"); ?></td>
			<td colspan="3"><textarea name="notes" cols="60" rows="4"><?=htmlspecialchars($contact['notes'])?></textarea></td>
		</tr>
		<tr>
			<td><?=i18n("Primary Contact")?></td>
			<td>
				<label><?=i18n("Yes")?><input type="radio" name="primary" value="yes" <?php if($contact['primary'] == 'yes') echo "CHECKED";?></label>
				<label><?=i18n("No")?><input type="radio" name="primary" value="no" <?php if($contact['primary'] != 'yes') echo "CHECKED";?>></label>
			</td>
<?php
			echo "<td align=\"center\"><input type=\"submit\" value=\"" . i18n("Save") . "\" onClick=\"return contactsinfo_save('" . $id . "')\" /></td>";
			echo "<td>";
			if($id != "new")
				echo "<input type=\"submit\" value=\"" . i18n("Remove") . "\" onClick=\"return contactsinfo_delete('" . $id . "')\" />";
			echo "</td>";
?>
		</tr>
	</table>
</form>
<?php
}


function draw_activityinfo_form(){
    global $config;
	$sponsorid = $_GET['id'];
// we'll start by drawing the table header
?>
	<form id="activityinfo">
	<table class="tableview" style="width:99%">
	<thead><tr>
		<th>Date</th>
		<th>User</th>
		<th>Contact Type</th>
		<th>Campaign</th>
		<th>Notes</th>
	</tr></thead>
	<tbody>

	<tr>
		<td align="center" ><input type="submit" value="<?=i18n("Add Log")?>" onClick="return activityinfo_save()" /></td>
		<td align="center"><?=$_SESSION['name']?></td>
		<td align="center">
        <?
            echo "<select name=\"type\">";
            echo "<option value=\"\">".i18n("Choose Type")."</option>\n";
            $logtypes=array("Campaign","Phone Call","Email","Personal Visit","Other");
            foreach($logtypes AS $lt) {
                echo "<option value=\"$lt\">".i18n($lt)."</option>\n";
            }
            echo "</select>\n";
        ?>
        </td>
		<td align="center">
        <?
            $q=mysql_query("SELECT * FROM fundraising_campaigns WHERE fiscalyear='{$config['FISCALYEAR']}' ORDER BY name");
            echo "<select name=\"fundraising_campaigns_id\">";
            echo "<option value=\"\">".i18n("Choose Campaign")."</option>\n";
            while($r=mysql_fetch_object($q)) {
                echo "<option value=\"$r->id\">$r->name</option>\n";
            }
            echo "</select>\n";
        ?>
        </td>
		<td><input type="text" name="comment" style="width: 99%;"/></td>
	</tr>

<?php
	$query = "SELECT CONCAT_WS('&nbsp;', users.firstname, users.lastname) AS name, fdl.dt, fdl.log, fdl.type,
            fundraising_campaigns.name AS campaignname
		  FROM fundraising_donor_logs AS fdl 
		  JOIN users ON fdl.users_id=users.id 
          LEFT JOIN fundraising_campaigns ON fdl.fundraising_campaigns_id=fundraising_campaigns.id
		  WHERE sponsors_id=" . $sponsorid. " ORDER BY dt DESC";
	//echo "<tr><td colspan=\"3\">" . $query . "</td></tr>";
	$q = mysql_query($query);
    echo mysql_error();
	if(mysql_num_rows($q)) {
		while($r = mysql_fetch_array($q)) {
			echo "<tr><td>" . $r["dt"] . "</td>";
			echo "<td>" . $r["name"] . "</td>";
			echo "<td>" . $r["type"] . "</td>";
			echo "<td>" . $r["campaignname"] . "</td>";
			echo "<td>" . $r["log"] . "</td>";
			echo "</tr>\n";
        }
	}else{
		echo "<tr><td colspan=\"5\" style=\"text-align:center\">" . i18n("No records") . "</td></tr>";
	}
?>

	</tbody></table>
	</form>
<?php
}

// Save an activity info log.  Returns true on success, false on failure.
function save_activityinfo($comment, $donorId, $userId, $type, $campaign_id=null){
	$returnval = false;

    if($campaign_id) $cid="'$campaign_id'"; else $cid="NULL";

    $query = "INSERT INTO fundraising_donor_logs (sponsors_id, dt, users_id, log, `type`, fundraising_campaigns_id) 
                VALUES ($donorId,
                    NOW(),
                    $userId,
                    '".mysql_real_escape_string($comment)."',
                    '".mysql_real_escape_string($type)."',
                    $cid)";

    if(mysql_query($query)){
        $returnval = true;
    }
	return $returnval;
}

?>
<script type="text/javascript">
/* Setup the popup window */
$(document).ready(function() {
/*`
	$("#open_editor").dialog({
		bgiframe: true, autoOpen: false,
		modal: true, resizable: false,
		draggable: false
	});
*/

	$("#editor_tabs").tabs({
		show: function(event, ui) {
			switch(ui.panel.id) {
				case 'editor_tab_organization':
					update_organizationinfo();
					break;
				case 'editor_tab_sponsorship':
					update_sponsorshipinfo();
					break;
				case 'editor_tab_contacts':
					update_contactsinfo();
					break;
				case 'editor_tab_activity':
					update_activityinfo();
				break;
			}
		},
		selected: 0,
	});

	$("#organizationinfo_fundingselectiondate").datepicker({ dateFormat: 'yy-mm-dd'});
    //, showOn: 'button', buttonText: "<?=i18n("calendar")?>" });

});


var sponsor_id=0;
function open_editor(id) {
	sponsor_id=id;
	$("#donor_editor").show();
	$("#searchbrowse").hide();
	$("#searchresults").hide();

	if(id==-1) {
		$('#editor_tabs').tabs('option', 'selected', 0);
		$('#editor_tabs').tabs('option', 'disabled', [1,2,3]);

		$("#organizationinfo_organization").val("");
		$("#organizationinfo_address").val("");
		$("#organizationinfo_address2").val("");
		$("#organizationinfo_city").val("");
		$("#organizationinfo_province_code").val("");
		$("#organizationinfo_postalcode").val("");
		$("#organizationinfo_phone").val("");
		$("#organizationinfo_tollfree").val("");
		$("#organizationinfo_fax").val("");
		$("#organizationinfo_email").val("");
		$("#organizationinfo_website").val("");
		$("#organizationinfo_donationpolicyurl").val("");
		$("#organizationinfo_fundingselectiondate").val("");
		$("#organizationinfo_notes").val("");

	}
	else {
		$('#editor_tabs').tabs('option', 'selected', 0);
		$('#editor_tabs').tabs('option', 'disabled', []);
	}

	update_organizationinfo();
	return false;
}

function open_search() {
	$("#donor_editor").hide();
	$("#searchbrowse").show();
	

}
function update_organizationinfo() 
{
	var id=sponsor_id;		
	if(!sponsor_id)
		return false;
	if(sponsor_id==-1) {
		$("#sponsor_id").val(-1);
		return false;
	}

	$.getJSON("<?=$_SERVER['PHP_SELF']?>?action=organizationinfo_load&id="+id,
	function(json){
		$("#sponsor_id").val(json.id);
		$("#organizationinfo_organization").val(json.organization);
		$("#organizationinfo_address").val(json.address);
		$("#organizationinfo_city").val(json.city);
		$("#organizationinfo_province_code").val(json.province_code);
		$("#organizationinfo_postalcodd").val(json.postalcode);
		$("#organizationinfo_phone").val(json.phone);
		$("#organizationinfo_tollfree").val(json.tollfree);
		$("#organizationinfo_fax").val(json.fax);
		$("#organizationinfo_email").val(json.email);
		$("#organizationinfo_website").val(json.website);
		$("#organizationinfo_donationpolicyurl").val(json.donationpolicyurl);
		$("#organizationinfo_fundingselectiondate").val(json.fundingselectiondate);
		$("#organizationinfo_notes").val(json.notes);
		// For some reason, with checkboxes, these have to be arrays
		$("[name=waiveraccepted]").val([json.waiveraccepted]);
		$("[name=taxreceiptrequired]").val([json.taxreceiptrequired]);
	});
}

function organizationinfo_save() {

	//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("<?$_SERVER['PHP_SELF']?>?action=organizationinfo_save", $("#organizationinfo").serializeArray(),
		function(json) {
			open_editor(json.id);
		},
		"json");
	}
	else
		$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=organizationinfo_save", $("#organizationinfo").serializeArray());
	return false;
}

function update_sponsorshipinfo() 
{
	var id=sponsor_id;		
	$.getJSON("<?=$_SERVER['PHP_SELF']?>?action=sponsorshipinfo_load&id="+id,
	function(json){
		$("#sponsor_id").val(json.id);
	});
}

function sponsorshipinfo_save() {
	$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=sponsorshipinfo_save", $("#sponsorshipinfo").serializeArray());
	return false;
}

function update_contactsinfo() 
{
	var id=sponsor_id;		
	$("#editor_tab_contacts").load("<?=$_SERVER['PHP_SELF']?>?action=contactsinfo_load&id="+id, null,
	function() {
		$("#contactaccordion").accordion();
	}
	);
}

function contactsinfo_save(uid) {
	var id=sponsor_id;		
	$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=contactsinfo_save&id="+id, $("#contact_" + uid).serializeArray(),
	function() {
		$("#contactaccordion").accordion();
		update_contactsinfo();
	});
	return false;
}

function contactsinfo_delete(uid) {
	var id=sponsor_id;		
	$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=contactsinfo_delete&id="+id, $("#contact_" + uid).serializeArray(),
	function() {
		$("#contactaccordion").accordion();
		update_contactsinfo();
	});
	return false;
}


function update_activityinfo() 
{
	var id=sponsor_id;		
	$("#editor_tab_activity").load("<?=$_SERVER['PHP_SELF']?>?action=activityinfo_load&id="+id);
	/*
	var id=sponsor_id;		
	$.getJSON("<?=$_SERVER['PHP_SELF']?>?action=activityinfo_load&id="+id,
	function(json){
		$("#sponsor_id").val(json.id);
	});
	*/
	return false;
}

function activityinfo_save() {
	var id=sponsor_id;		
	$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=activityinfo_save&id="+id, $("#activityinfo").serializeArray(),
	function(){
		update_activityinfo();
	});
	return false;
}

function donorsearch() {
	$("#searchresults").show();
	$("#searchresults").load("donors_search.php", $("#searchform").serializeArray());
		return false;
}

</script>
<?

 
	if($_GET['action']=="delete" && $_GET['delete'])
	{
		//dont allow any deleting until we figure out what we need to do, infact, i think we never should hard delete
		//this should only soft-delete so things like awards from previous years are still all linked correctly.
	//	mysql_query("DELETE FROM sponsors WHERE id='".$_GET['delete']."'");
//		echo happy("Sponsors cannot be deleted");
	}

		echo "<table cellspacing=2 width=740 border=0><tr>";
echo "<td>";
		echo "<a href=\"#\" onclick=\"open_editor(-1)\">Add New Donor(s)/Sponsor(s)</a>\n";
echo "</td>";
echo "<td>";
		echo "<a href=\"#\" onclick=\"open_search()\">View/Modify Donor(s)/Sponsor(s)</a>\n";
echo "</td>";
echo "</tr></table>";
echo "<hr />";
?>

<div id="donor_editor" title="Donor/Sponsor Editor" style="display: none; width: 770px;">
	<div id="editor_tabs">
		<ul>
			<li><a href="#editor_tab_organization"><span><?=i18n('Donor/Sponsor Details')?></span></a></li>
			<li><a href="#editor_tab_sponsorship"><span><?=i18n('Donations/Sponsorships')?></span></a></li>
			<li><a href="#editor_tab_contacts"><span><?=i18n('Contacts')?></span></a></li>
			<li><a href="#editor_tab_activity"><span><?=i18n('Activity Log')?></span></a></li>
		</ul>

		<div id="editor_tab_organization">
			<form enctype="multipart/form-data" id="organizationinfo">
			<input type="hidden" name="sponsor_id" id="sponsor_id" value="0">
			<table class="tableedit" border=0>
			<tr><td><?=i18n("Donor Type")?></td><td colspan="5">
				<input id="donortype_individual" type="radio" name="donortype" value="individual" /><label for="donortype_individual"><?=i18n("Individual")?></label>
				<input id="donortype_organization" type="radio" name="donortype" value="organization" checked="checked"/><label for="donortype_organization"><?=i18n("Organization")?></label>
			</td></tr>
			<tr><td><?=i18n("Name")?></td><td colspan="5"><input class="translatable" type="text" id="organizationinfo_organization" name="organization" size="60" maxlength="128" /></td></tr>
			<tr><td><?=i18n("Address 1")?></td><td colspan="5"><input id="organizationinfo_address" type="text" name="address" size="60" maxlength="64" /></td></tr>
			<tr><td><?=i18n("Address 2")?></td><td colspan="5"><input id="organizationinfo_address2" type="text" name="address2" size="60" maxlength="64" /></td></tr>
			<tr><td><?=i18n("City")?></td><td><input id="organizationinfo_city" type="text" name="city" size="16" maxlength="32" /></td>
			<td><?=i18n($config['provincestate'])?></td><td>
				<? emit_province_selector("province_code","","id=\"organizationinfo_province_code\""); ?>
			</td>
			<td><?=i18n($config['postalzip'])?></td><td><input id="organizationinfo_postalcode" type="text" name="postalcode" size="8" maxlength="7" /></td></tr>
			<tr><td><?=i18n("Phone")?></td><td><input type="text" id="organizationinfo_phone" name="phone" size="16" maxlength="32" /></td>
			<td><?=i18n("Toll Free")?></td><td><input type="text" id="organizationinfo_tollfree" name="tollfree" size="16" maxlength="32" /></td>
			<td><?=i18n("Fax")?></td><td><input type="text" id="organizationinfo_fax" name="fax" size="16" maxlength="32" /></td></tr>
			<tr><td><?=i18n("Email")?></td><td colspan="5"><input type="text" id="organizationinfo_email" name="email" size="60" maxlength="128" /></td>
            </tr>
			<tr><td><?=i18n("Website")?></td><td colspan="5"><input type="text" id="organizationinfo_website" name="website" size="60" maxlength="128" /></td>
            </tr>
			<tr><td><?=i18n("Donation Policy")?></td><td colspan="5"><input id="organizationinfo_donationpolicyurl" type="file" name="donationpolicyurl" size="30" maxlength="128" /></td></tr>
            <tr><td><?=i18n("Logo")?></td><td colspan="5"><input type="file" name="logo" size="30" /></td></tr>
			<tr><td><?=i18n("Funding Selection Date")?></td><td colspan="5"><input id="organizationinfo_fundingselectiondate" type="text" name="fundingselectiondate" size="10" maxlength="10" /></td>
            </tr>
<?
/*
			<tr><td><?=i18n("Waiver Accepted")?></td><td>
			<input type="radio" id="organizationinfo_waiveraccepted_no" name="waiveraccepted" value="no"><label for="organizationinfo_waiveraccepted_no"><?=i18n("No")?></label> &nbsp;&nbsp;
			<input type="radio" id="organizationinfo_waiveraccepted_yes" name="waiveraccepted" value="yes"><label for="organizationinfo_waiveraccepted_yes"><?=i18n("Yes")?></label> &nbsp;&nbsp;
			</td>

			<td><?=i18n("Tax Receipt Requested")?></td><td>
			<input type="radio" id="organizationinfo_taxreceiptrequired_no" name="taxreceiptrequired" value="no"><label for="organizationinfo_taxreceiptrequired_no"><?=i18n("No")?></label> &nbsp;&nbsp;
			<input type="radio" id="organizationinfo_taxreceiptrequired_yes" name="taxreceiptrequired" value="yes"><label for="organizationinfo_taxreceiptrequired_yes"><?=i18n("Yes")?></label> &nbsp;&nbsp;
			</td>

			<td><?=i18n("Marketing Receipt Requested")?></td><td colspan="3">
			<input type="radio" id="organizationinfo_marketingreceiptrequired_no" name="marketingreceiptrequired" value="no"><label for="organizationinfo_marketingreceiptrequired_no"><?=i18n("No")?></label> &nbsp;&nbsp;
			<input type="radio" id="organizationinfo_marketingreceiptrequired_yes" name="marketingreceiptrequired" value="yes"><label for="organizationinfo_marketingreceiptrequired_yes"><?=i18n("Yes")?></label> &nbsp;&nbsp;
			</td></tr>
            */
?>
			<tr><td><?=i18n("Notes")?></td><td colspan="5"><textarea id="organizationinfo_notes" name="notes" rows="4" cols="60"></textarea></td></tr>
			</table>
			<input type="submit" value="Save" onClick="return organizationinfo_save()" />
			</form>
		</div>
		<div id="editor_tab_sponsorship">
		sponsorship
		</div>
		<div id="editor_tab_contacts">
		</div>
		<div id="editor_tab_activity">
		activity
		</div>
	</div>
</div>


<div id="searchbrowse" style="display: none;">
<form id="searchform" method="post" action="donors.php" onsubmit="return donorsearch()">
<?=i18n("Search")?>: <input type="text" name="search" />
<input id="donortype_individual" type="checkbox" name="donortype[]" value="individual" checked="checked" /><label for="donortype_individual"><?=i18n("Individual")?></label>
<input id="donortype_organization" type="checkbox" name="donortype[]" value="organization" checked="checked"/><label for="donortype_organization"><?=i18n("Organization")?></label>
<input type="submit" value="<?=i18n("Browse")?>" />
</form>
</div>
<div id="searchresults">
</div>
<?

if($_GET['action']=="add") {
?>
<script type="text/javascript">
$(document).ready(function() {
	open_editor(-1);
});
</script>
<?
}

send_footer();

?>
