<?php
/* $Id: searchmore.php 16 2006-06-08 08:31:06Z hodaka $
 *  ------------------------------------------------------------------------ *
 *                XOOPS - PHP Content Management System                      *
 *                    Copyright (c) 2000 XOOPS.org                           *
 *                       <http://www.xoops.org/>                             *
 *  ------------------------------------------------------------------------ *
 *                      MyAddress - XOOPS addressbook                        *
 *                        <http://www.kuri3.net/>                            *
 *              Copyright (c) 2004 by hodaka <hodaka@kuri3.net>              *
 * ------------------------------------------------------------------------- *
 * 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; either version 2 of the License, or         *
 * (at your option) any later version.                                       *
 *                                                                           *
 * You may not change or alter any portion of this comment or credits        *
 * of supporting developers from this source code or any supporting          *
 * source code which is considered copyrighted (c) material of the           *
 * original comment or credit authors.                                       *
 *                                                                           *
 * 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; if not, write to the Free Software               *
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *
 */

include( "header.php" );

// reject no perm modified on v1.23
if( empty($xoopsModuleConfig['myaddress_guestperm']) && !is_object($xoopsUser) ) {
	redirect_header( XOOPS_URL."/user.php" , 2 , _MD_MYADDRESS_YOUMUSTREG );
	exit();
} elseif( !haveGroupPerm() ) {
	redirect_header( XOOPS_URL."/index.php", 2, _MD_MYADDRESS_YOUHAVENOPERM );
	exit();
}

$zipkey = isset($_GET['zip']) ? $_GET['zip'] : "";
$adrs1 = (isset($_SESSION) && isset($_SESSION['adrs1'])) ? $_SESSION['adrs1'] : "";
$adrs2 = (isset($_SESSION) && isset($_SESSION['adrs2'])) ? $_SESSION['adrs2'] : "";
$form = isset($_GET['form']) ? $_GET['form'] : "address";

xoops_header(false);

echo "
<SCRIPT LANGUAGE=\"JavaScript\">
<!--
function insertAddress(form) {
	for(i=0 ; i<form.length-1 ; i++)	{
		if(form.zipcode[i].checked) {";
if ( $form == "address" ) {
echo "
			opener.document.address.myzipcode.value = form.zipcode[i].value;
			opener.document.address.myaddress1.value = form.address1[i].value;
			opener.document.address.myaddress2.value = form.address2[i].value;";
} else {
echo "
			opener.document.company.czipcode.value = form.zipcode[i].value;
			opener.document.company.caddress1.value = form.address1[i].value;
			opener.document.company.caddress2.value = form.address2[i].value;";
}
echo "
			opener.focus();
			window.close();
		}
	}
}
//-->
</SCRIPT>\n";

echo "
</HEAD>
<BODY>\n";

// search zipcode table again
if ( $zipkey != ""  ) {
	$ziparray = zip_to_address( $zipkey );
} elseif ( $adrs1 != "" || $adrs2 != "" ) {
	$ziparray = address_to_zip( $adrs1, $adrs2 );
} else {
	exit;
}

echo "<FORM NAME='addressForm'>
<DIV ALIGN='RIGHT'><INPUT VALUE='"._CLOSE."' TYPE='button' onclick='javascript:window.close();' /></DIV>\n";

	echo "<CENTER><H2>"._MD_MYADDRESS_PLURAL."</H2></CENTER>\n";

if ( !isset( $ziparray ) || count( $ziparray ) == 0 ) {
	echo "<B><FONT COLOR='red'>["._MD_MYADDRESS_NOFOUND."]</FONT></B>\n";
} else {
	foreach( $ziparray as $zip) {
		$strzip = strval( $zip['zipcode'] );
		$strzip = substr( $strzip, 0, 3 ) . "-" . substr( $strzip, 3, 4 );
		echo "<P><INPUT TYPE='radio' name='zipcode' VALUE='".$strzip."' />".$strzip." ".$zip['pref']." ".$zip['address2'];
		echo "<INPUT TYPE='HIDDEN' NAME='address1' VALUE='".$zip['pref']."' />";
		echo "<INPUT TYPE='HIDDEN' NAME='address2' VALUE='". $zip['address2'] ."' />\n";
	}
}

echo "<CENTER><P><INPUT TYPE='button' VALUE= '"._SEND."' onClick='insertAddress(this.form)' />";

echo "&nbsp;&nbsp;<INPUT TYPE='button' VALUE= '"._CLOSE."' onClick='javascript:window.close();' /></P></CENTER></FORM>\n";
echo "</BODY></HTML>\n";
?>
