<?php
/**
* HTML functions of PHPGEN system.
*
* PHPGEN 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.
*
* PHPGEN 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 PHPGEN; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @copyright EasySoft R&D Team (C) 2006
* @author Chunsheng Wang <hide@address.com>
* @link http://www.phpgen.com
* @package Include
* @version $Id: FuncHtml.php,v 1.4 2006/08/15 14:36:35 wangcs Exp $
*/
/**
* create tags like <a href="">text</a>
*
* @author wwccss<hide@address.com>
* @param string $Text the link text.
* @param string $URL the link url.
* @param string $Target the target window
* @param booble $Echo show directly or false.
*/
function htmlLink($Text, $URL, $Target = "_self", $Echo = false)
{
$LinkString = '<A href="'.$URL.'" target="'.$Target.'">'.$Text.'</A>';
$LinkString .= "\n";
if($Echo)
{
echo $LinkString;
}
return $LinkString;
}
/**
* create tags like "<select><option></option></select>"
*
* @author wwccss<hide@address.com>
* @param array $ArrayData the array to create select tag from.
* @param string $SelectName the name of the select tag.
* @param string $Mode Normal|Reverse,if normal, show the key of the array in the select box, else show the value of the array in the select box.
* @param string $SelectItem the item(s) to be selected, can like item1,item2.
* @param string $Attrib other params such as multiple, size and style.
* @param booble $Echo show directly or false.
*/
function htmlSelect($ArrayData, $SelectName, $Mode = "Normal", $SelectItem = "", $Attrib = "", $Echo = false)
{
if(!is_array($ArrayData))
{
return false;
}
/* The begin. */
$SelectString = "\n <select name='$SelectName' ";
/* Set the id. */
if(eregi("\[",$SelectName))
{
$SelectName = explode("[",$SelectName);
$SelectString .= "id='$SelectName[0]' ";
}
else
{
$SelectString .= "id='$SelectName'";
}
/* The param. */
$SelectString .= " $Attrib >\n";
/* Explode the SelectItems. */
$SelectItem = explode(",", $SelectItem);
/* The option. */
foreach ($ArrayData as $Key=>$Value)
{
if($Mode == "Normal")
{
if(in_array($Value, $SelectItem))
{
$SelectString .= "<option value='$Value' selected='selected'>$Key</option>";
}
else
{
$SelectString .= "<option value='$Value'>$Key</option>";
}
}
elseif($Mode == "Reverse")
{
if(in_array($Key, $SelectItem))
{
$SelectString .= "<option value='$Key' selected='selected'>$Value</option>";
}
else
{
$SelectString .= "<option value='$Key'>$Value</option>";
}
}
$SelectString .= "\n";
}
/* The end. */
$SelectString .= "</select>\n";
if($Echo)
{
echo $SelectString;
}
return $SelectString;
}
/**
* create tags like "<radio></radio>"
*
* @author wwccss<hide@address.com>
* @param array $ArrayData the array to create radio tag from.
* @param string $RadioName the name of the radio tag.
* @param string $Mode Normal|Reverse,if normal, show the key of the array, else show the value of the array.
* @param string $DefaultChecked the value to checked by default.
* @param string $Attrib other attribs.
* @param booble $Echo show directly or false.
*/
function htmlRadio($ArrayData, $RadioName, $Mode = "Reverse", $DefaultChecked = "", $Attrib = "", $Echo = false)
{
if(!is_array($ArrayData))
{
return false;
}
foreach($ArrayData as $Key => $Value)
{
if($Mode == "Reverse")
{
$SwitchTMP = $Value;
$Value = $Key;
$Key = $SwitchTMP;
}
$RadioString .= "<input type='radio' name='$RadioName' value='$Value'";
$RadioString .= ($Value == $DefaultChecked) ? " checked ='checked'" : "";
$RadioString .= $Attrib;
$RadioString .= " />$Key\n";
}
return $RadioString;
}
/**
* create tags like "<checkbox></checkbox>"
*
* @author wwccss<hide@address.com>
* @param array $ArrayData the array to create radio tag from.
* @param string $RadioName the name of the radio tag.
* @param string $Mode Normal|Reverse,if normal, show the key of the array, else show the value of the array.
* @param string $DefaultChecked the value to checked by default.
* @param string $Attrib other attribs.
* @param booble $Echo show directly or false.
*/
function htmlCheckBox($ArrayData, $CheckBoxName, $Mode = "Reverse", $DefaultChecked = "", $Attrib = "", $Echo = false)
{
if(!is_array($ArrayData))
{
return false;
}
foreach($ArrayData as $Key => $Value)
{
if($Mode == "Reverse")
{
$SwitchTMP = $Value;
$Value = $Key;
$Key = $SwitchTMP;
}
$CheckBoxString .= "<input type='checkbox' name='$CheckBoxName" . "[]' value='$Value'";
$CheckBoxString .= ($Value == $DefaultChecked) ? " checked ='checked'" : "";
$CheckBoxString .= $Attrib;
$CheckBoxString .= " />$Key\n";
}
return $CheckBoxString;
}
function htmlText($Name, $Attrib = "", $Value = "")
{
return "<input type='text' name='$Name' id='$Name' value='$Value' $Attrib />";
}
function htmlPassword($Name, $Attrib = "")
{
return "<input type='password' name='$Name' id='$Name' $Attrib />";
}
function htmlTextarea($Name, $Attrib = "", $Value = "")
{
return "<textarea name='$Name' id='$Name' $Attrib>$Value</textarea>";
}
function htmlFile($Name, $Attrib = "")
{
return "<input type='file' name='$Name' id='$Name' $Attrib />";
}
?>
<?php
/**
* $Log: FuncHtml.php,v $
* Revision 1.4 2006/08/15 14:36:35 wangcs
* * Add copyright info.
*
* Revision 1.3 2006/04/22 03:54:54 wangcs
* * Change to PHPGEN.
*
* Revision 1.2 2006/02/01 08:22:09 wangcs
* no message
*
* Revision 1.1 2006/01/23 09:27:30 wangcs
* *** empty log message ***
*
*/
?>