<?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
// ----------------------------------------------------------------------

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

if (isUP()) {
	if (isUPGui()) {
		echo UPGui();
	} else {
		echo UPText();
	}
}else if(isNokia()) {
	echo Nokia();
}else if(isMozilla()) {
	echo Mozilla();
} else {
	echo Nokia();
};
?>
</wml>

<?
/////////////////////////////////////////////////////////////////////
function UPGui()
{
?>
	<card id="freedict" title="Dictionary">
		<p>
			Word:<input type="text" name="Query" value=""/>
			<br/>
			<do type="button" label="Search">
				<go href="Dictionary.php">
					<postfield name="Query" value="$Query"/>
					<postfield name="Form" value="DictionaryWap1"/>
					<postfield name="Strategy" value="*"/>
					<postfield name="Database" value="*"/>
				</go>
			</do>
		</p>
	</card>
<?
}
/////////////////////////////////////////////////////////////////////
function UPText()
{
?>
	<card id="freedict" title="Dctionary">
		<p>
			Word:<input type="text" name="Query" value=""/>
			<br/>
			<do type="accept" label="Search">
				<go href="Dictionary.php" method="post">
					<postfield name="Query" value="$Query"/>
					<postfield name="Form" value="DictionaryWap1"/>
					<postfield name="Strategy" value="*"/>
					<postfield name="Database" value="*"/>
				</go>
			</do>
		</p>
	</card>
<?
}
/////////////////////////////////////////////////////////////////////
function Nokia()
{
?>
	<card id="freedict" title="Dctionary">
		<p>
			Word:<input type="text" name="Query" value=""/>
			<br/>
			<do type="accept" label="Search">
				<go href="Dictionary.php" method="post">
					<postfield name="Query" value="$Query"/>
					<postfield name="Form" value="DictionaryWap1"/>
					<postfield name="Strategy" value="*"/>
					<postfield name="Database" value="*"/>
				</go>
			</do>
		</p>
	</card>
<?
}
/////////////////////////////////////////////////////////////////////
function Mozilla()
{
	echo "You should look this page on mobile";
}
/////////////////////////////////////////////////////////////////////
// Functions for detecting browser type
function isNokia() {
  global $HTTP_USER_AGENT;
	return (strpos(strtolower($HTTP_USER_AGENT),"nokia") ===false) ? false : true;
}

function isMozilla() {
  global $HTTP_USER_AGENT;
	return (strpos(strtolower($HTTP_USER_AGENT),"mozilla") ===false) ? false : true;
}

function isUPGui() {
  global $HTTP_USER_AGENT;
	return ((strpos(strtolower($HTTP_USER_AGENT),"gui") ===false) || isNokia())? false : true;
}

function isUP() {
  global $HTTP_USER_AGENT;
	return ((strpos(strtolower($HTTP_USER_AGENT),"up") ===false) || isNokia())? false : true;
}
/////////////////////////////////////////////////////////////////////
?>