<?php 
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// 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.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Author of file: Baris Efe, webmaster@freedictionary.org
// ----------------------------------------------------------------------

// Lenght For WML Deck
$DIV_LENGHT=1500;

header("Content-Type: text/vnd.wap.wml");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
echo "<!DOCTYPE wml PUBLIC \"-//PHONE.COM//DTD WML 1.3//EN\" \"http://www.phone.com/dtd/wml13.dtd\">\n";
echo "<wml>\n";
echo "<card id='freedict' title=\"Dictionary\">\n";
echo "  <p>\n";
echo "  	Word:<input type=\"text\" name=\"Query\" value=\"\"/><br/>\n";

include ("pkg.dict.php");

// get non-extended info from the server
//$server = new DictServerInfo();

// if there was a query ...
if ($Query){
	$query = new DictQuery();
	$wap = new WapDict();
	
	// If strategy is * chage it to exact
	if ($Strategy=="*") $Strategy="exact";
	
	$arrOut = $wap->doQuery($Query, $Database, $Strategy, $DIV_LENGHT);
	//echo strlen($arrOut[0]);

	if (empty($nav)){
		$nextUrl="Dictionary.php?Query=$Query&amp;Form=DictionaryWap1&amp;Strategy=*&amp;Database=*&amp;nav=1";
		$navigationBar="<br/>\n<a href=\"$nextUrl\">Next</a><br/>";

		echo $navigationBar; // Up Navigation Bar
		echo $arrOut[0];
		echo $navigationBar; // Down Navigation Bar
	} else {
		$prevNav=$nav-1;
		$nextNav=$nav+1;
		$prevUrl="Dictionary.php?Query=$Query&amp;Form=DictionaryWap1&amp;Strategy=*&amp;Database=*&amp;nav=$prevNav";
		$nextUrl="Dictionary.php?Query=$Query&amp;Form=DictionaryWap1&amp;Strategy=*&amp;Database=*&amp;nav=$nextNav";
		if ($nav==sizeof($arrOut)) {
			$navigationBar="<br/>\n<a href=\"$prevUrl\">Prev</a><br/>";
		} else {
			$navigationBar="<br/>\n<a href=\"$prevUrl\">Prev</a> - <a href=\"$nextUrl\">Next</a><br/>";
		}
		
		echo $navigationBar; // Up Navigation Bar
		echo $arrOut[$nav];
		echo $navigationBar; // Down Navigation Bar
	}
} 
?>
        <do type="accept" label="Search">
            <go href="Dictionary.php" method="get">
                <postfield name="Query" value="$Query"/>
                <postfield name="Form" value="DictionaryWap1"/>
                <postfield name="Strategy" value="*"/>
                <postfield name="Database" value="*"/>
            </go>
        </do>
   </p>
    </card>
</wml>
