BeCastWebEngine/inc/panel.class.php

351 lines
9.8 KiB
PHP

<?php
/**
* Project: BeCast Webengine - simple site engine
* File: /inc/panel.class.php
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @link http://www.becast.at
* @copyright 2009-2025 becast.at
* @author Bernhard Jaud <bernhard at becast dot at>
* @package BcWe core
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id$
*/
$module["panel"]["name"]="Panel Class";
$module["panel"]["ver"]="0.3.8";
class panel {
var string $sidebar="";
var string $page="";
var string $bodyext="";
var string $title="";
var string $content="";
var string $meta="";
var string $form="";
var string $foot="";
var string $head="";
var string $menu_items ="";
function page($additional_title="",$meta=""){
global $config,$db,$core;
return '<!DOCTYPE html>
<html lang="de">
<head>
<title>'.$config['sitetitle'].'</title>
<link rel="stylesheet" type="text/css" href="admin.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
'.$this->meta.'
</head>
<body '.$this->bodyext.'>
<div id="container">
'.$this->menu().'
<div id="content">
'.$this->page.'
</div>
<div id="footer">
&copy; 2016 - 2025 Becast.at | mySQL Queries: '.$db->querys().'
<br/>
Powered by
<a href="http://www.becast.at">BeCast WebEngine</a>
'.$core->ver_major.'.'.$core->ver_minor.".".$core->ver_rev.' - '.$core->ver_codename.'
</div>
</div>
'.$this->foot.'
</body>
</html>';
}
function parse_page(){
$this->page.="<h2>".$this->title."</h2>
<p>".$this->content."</p>";
$this->title="";
$this->content="";
echo $this->page();
exit();
}
function menu_item($panel,$text, $img=""): void
{
global $config, $userdata, $userinfo, $session, $meta;
if($panel=="group_only"){
$this->menu_items.="<li><strong>".$text."</strong></li>";
}elseif($panel=="admin_home"){
$this->menu_items.="<li><a href=\"".$config["path"]."/admin/index.php\"><img src=\"".$config["path"]."/admin/images/icons/".$img.".png\" alt='".$img."'> ".$text."</a></li>";
}elseif($panel=="page_home"){
$this->menu_items.="<li><a href=\"".$config["path"]."/index.php\"><img src=\"".$config["path"]."/admin/images/icons/".$img.".png\" alt='".$img."'> ".$text."</a></li>";
}else{
if($img!=""){
$this->menu_items.="<li><a href=\"".$config["path"]."/admin/index.php?panel=".$panel."\"><img src=\"".$config["path"]."/admin/images/icons/".$img.".png\" alt='".$img."'> ".$text."</a></li>";
}else{
$this->menu_items.="<li><a href=\"".$config["path"]."/admin/index.php?panel=".$panel."\">".$text."</a></li>";
}
}
}
function admin_message($title,$message,$redirect=FALSE,$panel="",$time="4"): void
{
global $config,$session,$lang;
$session->page_begin("Admin Message", True);
if($panel!="" && $redirect){
$this->content=$message."<br /><a href=\"".$config["path"]."/admin/index.php?panel=".$panel."\">".$lang->_('CLICKREDIRECT')."</a>";
}elseif($panel!="" && !$redirect){
$this->content=$message."<br /><a href=\"".$config["path"]."/admin/index.php?panel=".$panel."\">".$lang->_('CLICKCONTINUE')."</a>";
}else{
$this->content=$message;
}
if($redirect && $panel!="")
$this->meta.="<meta http-equiv=\"refresh\" content=\"".$time."; URL=".$config["path"]."/admin/index.php?panel=".$panel."\" />";
$this->title=$title;
$this->parse_page();
}
function menu(): string
{
return '<div id="menu">
<ul>'.$this->menu_items.'</ul></div>';
}
function form ($args = array(),$return=FALSE,$extra=""){
$method = $args["method"] ?? 'POST';
$action = $args["action"] ?? $_SERVER['PHP_SELF'];
$form = '<form action="' .$action. '" method="' .$method. '"' .$extra. '>';
if(!$return){
$this->content .= $form;
}else{
return $form;
}
}
function formClose ($return=FALSE)
{
$form = '</form>';
if(!$return){
$this->content .= $form;
}else{
return $form;
}
}
function button ($text = '', $name='', $extra='', $return=FALSE)
{
$fld = '<input type="button" name="'.$name.'" value="'.$text.'" ' .$extra. ' />';
if(!$return){
$this->content .= $fld;
}else{
return $fld;
}
}
function radio ($args=array(),$extra="",$return=FALSE)
{
$name = $args["name"] ?? 'radiobutton';
$value = $args["value"];
if($value!=""){
$extra .= ' value="'.$value.'"';
}
$fld=$this->radioOrCheck ("radio",$name,$extra,$return);
if($return){
return $fld;
}
}
function checkbox ($args=array(),$extra="",$return=FALSE)
{
$name = $args["name"] ? $args["name"] : 'checkbox';
$value = $args["value"];
if($value!=""){
$extra .= ' value="'.$value.'"';
}
$fld=$this->radioOrCheck ("checkbox",$name,$extra,$return);
if($return){
return $fld;
}
}
/* private */
function radioOrCheck ($type,$name="",$extra="",$return=FALSE)
{
$fld = '<input type="'.$type.'" name="'.$name.'" ' .$extra. ' />';
if(!$return){
$this->content .= $fld;
}else{
return $fld;
}
}
function field ($args=array(),$extra="",$return=FALSE)
{
$typ = $args["typ"] ?? 'text';
$name = $args["name"] ?? 'textfield';
$value = $args["value"] ?? '';
$fld = '<input type="' .$typ. '" name="' .$name. '" value="' .$value. '"' .$extra. ' />'; // html: form field
if(!$return){
$this->content .= $fld;
}else{
return $fld;
}
}
function submit ($args=array(),$extra="",$return=FALSE)
{
$name = $args["name"] ?? 'submit';
$fld = '<input type="submit" name="'.$name.'" ' .$extra. ' />'; // html: form submit button
if(!$return){
$this->content .= $fld;
}else{
return $fld;
}
}
function get_option($option,$name,$value="") {
global $lang;
if($option=="yesno"){
$checked["yes"]="";
$checked["no"]="";
if($value==1||$value==True||$value=="yes"){
$checked["yes"]='checked="checked"';
}else{
$checked["no"]='checked="checked"';
}
$yn=$this->radio(array("name"=>$name,"value"=>"1"),$checked["yes"],TRUE);
$yn.="Ja";
$yn.=$this->radio(array("name"=>$name,"value"=>"0"),$checked["no"],TRUE);
$yn.="Nein";
return $yn;
}
if($option=="onoff"){
$checked["on"]="";
$checked["off"]="";
if($value==1||$value==True||$value=="on"){
$checked["on"]='checked="checked"';
}else{
$checked["off"]='checked="checked"';
}
$yn=$this->radio(array("name"=>$name,"value"=>"1"),$checked["on"],TRUE);
$yn.="An";
$yn.=$this->radio(array("name"=>$name,"value"=>"0"),$checked["off"],TRUE);
$yn.="Aus";
return $yn;
}
if($option=="text"){
$text=$this->field(array("name"=>$name,"typ"=>"text","value"=>$value),"",TRUE);
return $text;
}
if(str_contains($option, "wysiwyg")){
$string=str_replace("wysiwyg(","",substr($option, 0, -1));
$sarr=explode(";",$string);
foreach($sarr as $str){
$substr=explode("|",$str);
$a_name[]=$substr[0];
$value[]=$substr[1];
}
if(is_array($sarr)){
$text=$this->textarea(array("name"=>$name,"value"=>$value, $a_name[0]=>$value[0],$a_name[1]=>$value[1]),"class=\"mceEditor\"",TRUE);
}else{
$text=$this->textarea(array("name"=>$name,"value"=>$value),"class=\"mceEditor\"",TRUE);
}
return $text;
}
if(str_contains($option, "textarea")){
$string=str_replace("textarea(","",substr($option, 0, -1));
$sarr=explode(";",$string);
if(count($sarr)>1) {
foreach ($sarr as $str) {
$substr = explode("|", $str);
$a_name[] = $substr[0];
$value[] = $substr[1];
}
$text=$this->textarea(array("name"=>$name,"value"=>$value, $a_name[0]=>$value[0],$a_name[1]=>$value[1]),"",TRUE);
}else{
$text=$this->textarea(array("name"=>$name,"value"=>$value),"",TRUE);
}
return $text;
}
if($option=="language"){
$values = array();
$langs=$lang->getlanguages();
foreach($langs as $lang){
$values[$lang['name']]=$lang['short'];
}
return $this->select($values,$value,$name,"",TRUE);
}
if(str_contains($option, "select")){
$string=str_replace("select(","",substr($option, 0, -1));
$sarr=explode(";",$string);
$values=array();
if(count($sarr)>1) {
foreach ($sarr as $str) {
$substr = explode("|", $str);
$values[$substr[0]] = $substr[1];
}
}
return $this->select($values,$value,$name,"",TRUE);
}
}
/*
$args[value] used for default text (as in "field" function)
*/
function textarea ($args = array(),$extra="",$return=FALSE)
{
$name = $args["name"] ?? 'field';
$rows = $args["rows"] ?? '3';
$cols = $args["cols"] ?? '30';
$text = $args["value"] ?? '';
$fld = '<textarea name="' .$name. '" rows="' .$rows. '" cols="' .$cols. '"' .$extra. '>' .$text. '</textarea>';
if(!$return){
$this->content .= $fld;
}else{
return $fld;
}
}
/*
$values = array containing values (key = processing value, data = displaying value)
*/
function select ($values=array(),$selected="",$name="",$extra="",$return=FALSE)
{
$fld='<select name="'.$name.'" '.$extra.'>';
foreach($values as $name=>$val){
if($val==$selected){
$fld.='<option value="'.$val.'" selected="selected">'.$name.'</option>';
}else{
$fld.='<option value="'.$val.'">'.$name.'</option>';
}
}
$fld.="</select>";
if(!$return){
$this->content .= $fld;
}else{
return $fld;
}
}
}
?>