Location: PHPKode > scripts > Application Framework Classes > application-framework-classes/tool.class.php
<?php
/* 
 *(c) 2003 christoph althammer hide@address.com  
 *         http://www.milpa.de
 *
 *         GNU GENERAL PUBLIC LICENSE
 *         die deutsche Übersetzung der GPL ist zu finden auf www.suse.org.
 *
 *   auth: c. althammer
 *   date: 2002-10-10
 *   lc  : 2002-10-17
 *   comm: certain tools & GUI Helpers
 *
 *
 */


class Comment 			extends GUI {};
class GUIWindowStatus 	extends GUI{};
class GUIBox 			extends GUI {};
class GUIBoxOpen 		extends GUI {};
class GUIBoxClose 		extends GUI {};
class GUIRedir 			extends GUI {};
class GUIAlert 			extends GUI {};
class GUIOpenNewWindow 	extends GUI {};
class GUICloseWindow	extends GUI {};

 
class GUI {
	
	function Comment($Comment=""){
		echo"\n\n\n<!-- AFW Comment -->\n";
		echo"<!-- $Comment -->\n";
		echo"<!-- End -->\n\n\n";
		return true;	
	}
	
	function GUIAlert($Msg=""){
		if (empty($Msg)) {
			new Debug("Error:empty GUI Message");
			return false;
			} else{
			new Debug("GUI Message:'$Msg'");
			echo"\n
				<SCRIPT LANGUAGE=\"JavaScript\"><!-- 
				alert('$Msg');				
				//-->
				</SCRIPT>";
			return true;			
			}			
	} 
	function GUIWindowStatus($Msg=""){
			//new Debug("GUIWindowStatus:'$Msg'");
			echo"\n
				<SCRIPT LANGUAGE=\"JavaScript\"><!-- 
				window.status='$Msg';				
				//-->
				</SCRIPT>";
			return true;		
			
	}	
	function GUIBox($ContentFile="",$Object=""){
		if (empty($ContentFile)) new Error("GUIBox called with empty Content");
		new Template("borderhead.templ.php",$Object);
		new Template($ContentFile,$Object);
		new Template("borderfoot.templ.php",$Object);
		return true;	
	}	
	
	function GUIBoxOpen($Object=760){
		new Debug("GUIBoxOpen called, waiting for Close");
		$GUIBoxWidth=$Object;
		new Template("boxopen.templ.php",$GUIBoxWidth);		
		return true;	
	}	
	
	function GUIBoxClose(){
		new Debug("GUIBoxClosed");
		new Template("boxclose.templ.php",$Object);
		return true;
		}
	
	function GUIRedir($Location=""){
		$Conf	= new Conf;
		if (empty($Location))	{
			new Error("GUIRedir aborted due to empty Param");
			return false;
			} else {?>
			<SCRIPT language="JavaScript">
			self.location.href='<?php echo"$Location";?>';
			</SCRIPT>
			<?php
			}
			
			/*
			if ($Conf->Debug==false) {?>
			<SCRIPT language="JavaScript">
			self.location.href='<?php echo"$Location";?>';
			</SCRIPT>
			<?php
			} else {
				new Debug("Redirect to '$Location' aborted due to DebugMode=true");
				new Debug("Application halted");
				die;
				}*/
		return true;
	}
	
	function GUIOpenNewWindow($Url=""){
		if (empty($Url)) new Error("GUIOpenNewWindow called mithout URL");
		new Debug("Open new Window '$Url'");
				
		?>
		<SCRIPT LANGUAGE="JAVASCRIPT">
		<!-- 
		pop_up('<?php echo$Url;?>');
		//-->
		</SCRIPT>
		<?php
		return true;
	}
	
	function GUICloseWindow(){
		new Debug("Close Window called");
				
		?>
		<SCRIPT LANGUAGE="JAVASCRIPT">
		<!-- 
		self.close();
		//-->
		</SCRIPT>
		<?php
		return true;
	}
	
	function GUIBack(){
		echo"<div align=\"right\"><a href=\"javascript:history.back();\"><<zurück</a></div>";
		return true;	
	}
	
	function GUISelector($SelectorName="",$ArrKeys="",$ArrValues="",$SelectedKey=0,$DefaultKey=0,$DefaultValue="",$Width=100,$REDIRECT=""){
		if (((!is_array($ArrKeys))|| (!is_array($ArrValues)))	/*||((empty($ArrKeys))|| (empty($ArrValues)))*/	){
			new Debug("FAILED Building Selector $SelectorName:$DefaultValue/$DefaultKey Width=$Width");		
			return false;
			}
		new Debug("Building Selector $SelectorName:$SelectedKey/$DefaultKey Width=$Width/ $REDIRECT");
		
		$Selector.='<select name="'.$SelectorName.'" style="width:'.$Width.'px" '.$REDIRECT.'>';
		// $Selector.= $this->GetGUISelectorOption();
        $Selector.= $this->GetGUISelectorOption($DefaultKey,$DefaultValue,$SelectedKey);
		reset($ArrKeys);
		reset($ArrValues);
		do {
			$Selector.= $this->GetGUISelectorOption(current($ArrKeys),current($ArrValues),$SelectedKey);
			next($ArrValues);		
		} while(next($ArrKeys));
		$Selector.= "</select>";
		return $Selector;
	}
	function GUIMultipleSelector($SelectorName="",$ArrKeys="",$ArrValues="",$ArrSelected="",$DefaultKey=0,$DefaultValue="Default",$Width=100,$REDIRECT=""){
		if (((!is_array($ArrKeys))|| (!is_array($ArrValues)))	/*||((empty($ArrKeys))|| (empty($ArrValues)))*/	){
			new Debug("FAILED Multiple Building Selector $SelectorName:$DefaultValue/$DefaultKey Width=$Width");		
			return false;
			}
		new Debug("Building Multiple Selector $SelectorName:$ArrSelected/$DefaultKey Width=$Width/ $REDIRECT");
		/*new Debug($ArrSelected);
		new Debug($ArrKeys);
		new Debug($ArrValues);*/
		
		$Selector.='<select size="10" name="'.$SelectorName.'" style="width:'.$Width.'px" '.$REDIRECT.'  multiple>';
		// $Selector.= $this->GetGUISelectorOption();
        $Selector.= $this->GetGUIMultipleSelectorOption($DefaultKey,$DefaultValue,$ArrSelected);
		reset($ArrKeys);
		reset($ArrValues);
		do {
			$Selector.= $this->GetGUIMultipleSelectorOption(current($ArrKeys),current($ArrValues),$ArrSelected);
			next($ArrValues);		
		} while(next($ArrKeys));
		$Selector.= "</select>";
		return $Selector;
	}
	 
	
	function GetGUIMultipleSelectorOption($Key="",$Val="",$Sel=""){
		reset($Sel);
		do {
			$AVal=current($Sel);
			//new Debug($AVal);
			if($Key == $AVal) {$Selected="selected";break;}
				else $Selected="";
				
		}	while (next($Sel));
		$Line	= "\n<option value=\"$Key\" $Selected>$Val</option>";
		return $Line;	
	}
	
	
	function GetGUISelectorOption($Key="",$Val="",$Sel=""){
		if($Key == $Sel) $Selected="selected";
			else $Selected="";
		$Line	= "\n<option value=\"$Key\" $Selected>$Val</option>";
		return $Line;	
	}
		
}/* end of class */


class GUIMsg extends GUI{
	function GUIMsg($Msg){
		$this->Comment("Send GUI Message");
		$Conf	= new Conf;
		if ($Conf->ShowAlerts==1) {
			$Flag = $this->GUIAlert($Msg);
			}
		$this->GUIWindowStatus($Msg);
		$this->Comment("End GUI Message");
		return $Flag;	
	}
}
class GUIClearWindowStatus extends GUI {
	function GUIClearWindowStatus(){
		$this->GUIWindowStatus();
		return true;
	}

}


class FormatVar {

function StampToDate($timestamp=""){
		if (empty($timestamp)) return false;
		$res	= strftime("%d.%m.%Y",$timestamp);
		return $res;
		}

function DateToStamp($datum=""){
		if (empty($datum)) return false;
		@$str 	= explode(".",$datum);
		$res = mktime(0,0,0,$str[1],$str[0],$str[2]);
		return $res;
		}

function check_valid_date($datum=""){
		$res 	= false;
		@$str 	= explode(".",$datum);
		$res 	= checkdate($str[1],$str[0],$str[2]);
		if (strlen($str[2])<4) $res=false;
		return $res;
		}
function check_valid_time($zeit=""){
		$res 	= true;
		@$str 	= explode(":",$zeit);
		if ($str[0]<0 || $str[0] >23 || $str[1]<0 || $str[1] >59 || empty($str[0]) || empty($str[1]) ) $res = false;
		return $res;
		}

function TextAfterPost($Text=""){
	$Text	= stripslashes ($Text);
	//$Text	= htmlentities($Text);
	return $Text;
	}
function TextFromDb($Text=""){
	$Text	= stripslashes ($Text);
	$Text	= htmlentities($Text);
	return $Text;
	}
function TextForOutput($Text=""){
	$Text	= stripslashes ($Text);
	$Text	= htmlentities($Text);
	$Text	= nl2br($Text);	
	return $Text;
	}
function TextForDb($Text=""){
	$Text	= addslashes ($Text);
	return $Text;
	}
function URLAfterPost($Url=""){
	$Url	= urldecode($Url);
	return $Url;
	}
function URLFromDb($Url=""){
	$Url	= urldecode($Url);
	return $Url;
	}		
function URLForDb($Url=""){
	$Url	= urlencode($Url);
	return $Url;
	}
function DateForDb($PDate=""){
	return $this->DateToStamp($PDate);
	}
function DateFromDb($PStamp=""){
	return $this->StampToDate($PStamp);
	}	
function CurrencyFromDb($Val=0){
	$Val	= sprintf("%0.2f",$Val);
	if ((float)$Val == 0) $Val = "";
	return $Val;
	}
}



?>
Return current item: Application Framework Classes