//local
/*$dbServer = "localhost";
$dbUser = "root";
$dbPass = "";
$dbName = "skyselect_cz";
$db_prefix = "";
*/
// web
$dbServer = "localhost";
$dbUser = "elenergouser";
$dbPass = "RthDDw3456";
$dbName = "elenergocz";
$db_prefix = "";
$cfg["base_url"] = "index.php";
//if (!isset($page)) { $page = 2; }
$cfg["admin_url"] = "admin.php";
$cfg["done_url"] = "doit.php";
?>
class CMenu
{
var $id, $table, $partable, $ParentArray, $root, $action;
function CMenu( $p_id, $admin = 1 )
{
#6.12.2006
global $q, $DB, $action, $cfg, $userAuth, $l;
$this->rights = array ( 1=>'číst', 'editovat', 'přidávat', 'úplný přístup' );
$this->id = $p_id;
$this->DB = $DB;
$this->q = $q;
$this->action = $action;
$this->cfg = $cfg;
$this->userAuth = $userAuth;
$this->l = $l;
if ($admin == 1) {
$sSQL = "SELECT ID, PARENT_ID, TEXT FROM menu WHere JAZYK = '$l' order by PORADI, PARENT_ID, ID";
} else {
$sSQL = "SELECT ID, PARENT_ID, TEXT FROM menu WHere UKAZAT = 1 and JAZYK = '$l' order by PORADI, PARENT_ID, ID";
}
$q = new query($DB, $sSQL);
while( $rec = $q->getrow())
{
$this->table[$rec["PARENT_ID"]][$rec["ID"]]=$rec["TEXT"];
$this->partable[$rec["ID"]][$rec["PARENT_ID"]]=$rec["TEXT"];
if ( $rec["ID"] == $p_id ) {
$this->parent = $rec["PARENT_ID"] ;
$this->nadpis = $rec["TEXT"] ;
}
}
$this->ParentArray = split(",", substr($this->getParentArray($this->id), 0, strlen($this->getParentArray($this->id))-1));
sort($this->ParentArray);
reset($this->ParentArray);
$this->root = current($this->ParentArray);
$sSQL = "Select * from jazyky";
$q->query($DB, $sSQL);
while( $rec = $q->getrow()) {
$this->jazyk['popis'][]=$rec['popis'];
$this->jazyk['kod'][]=$rec['kod'];
}
} //end of function
function show() {
global $page;
require_once('libs/blok.lib.php');
$sSQL = "Select * from menu where ID = ".$page;
$q1 = new query($this->DB, $sSQL);
$rec = $q1->getrow();
echo "
".$rec["TEXT"]." ";
$sSQL = "Select * from bloky Where PAGE_ID = ".$page;
$q1 = new query($this->DB, $sSQL);
$result = "";
while ( $rec = $q1->getrow()) {
$cbloky = new CBlok($rec["ID"]);
$result .= $cbloky->show();
}
echo $result;
}
function showAdmin() {
#8.12.2006
global $col, $dir, $page, $l;
$sSQL = "Select * from menu Where JAZYK='".$this->l."' and PARENT_ID = ".$this->id;
if (empty($col)) {$col=1;}//echo $sSQL;
if (isset($col)) {
switch($col) {
case 1: $sSQL .= " order by PORADI"; break;
case 2: $sSQL .= " order by AUTOR";break;
case 3: $sSQL .= " order by ZMENA";break;
}
}
if (isset($dir) && isset($col)) {
$sSQL .= ( $dir == 'up' ) ? " desc" : " asc";
}
/* $result = "";
$result.= "
";*/
$result = "Cesta: cfg["admin_url"]."\"> root » ".$this->getPath()."
";
//if ($this->id == 0) {
$result.= "přidat: cfg["admin_url"]."&page=$this->id&pageaction=addnew\">Stránku
";
//}
$result.= "";
$result.= "";
$this->q->query($this->DB, $sSQL);
while( $rec = $this->q->getrow() )
{
$result.= "";
//$result.= "cfg["admin_url"]."&page=".$rec["ID"]."&pageaction=edit\" >";
$result.= " cfg["admin_url"]."&page=".$rec["ID"]."\" >";
$result.= $rec["TEXT"];
$result.= " ";
$result.= "cfg["admin_url"]."&page=".$rec["ID"]."&pageaction=addnew\" >vytvořit podřízenou st. | ";
$result.= "cfg["admin_url"]."&page=".$rec["ID"]."&pageaction=edit\">upravit | ";
$result.= "cfg["admin_url"]."&page=".$rec["ID"]."&pageaction=prop\">vlastnosti | ";
$result.= "cfg["admin_url"]."&page=".$rec["ID"]."&pageaction=tree&autor=".$this->userAuth->id."\">přemístit | ";
$result.= "cfg["done_url"]."&page=".$rec["ID"]."&pageaction=copy&autor=".$this->userAuth->id."\">kopírovat | ";
$result.= "cfg["admin_url"]."&page=".$rec["ID"]."&pageaction=del&parent=".$this->id."\"> ";
if ($rec["PORADI"] > $this->getMinMax($this->id, 'min', $this->l) ) {
$result .= "cfg["admin_url"]."&page=$page&pageaction=updown&item=".$rec["ID"]."&kam=up\">▲ ";
}
if ($rec["PORADI"] < $this->getMinMax($this->id, 'max', $this->l) ) {
$result .= "cfg["admin_url"]."&page=$page&pageaction=updown&item=".$rec["ID"]."&kam=down\">▼ "; }
$result.= "".$this->userAuth->getName($rec["AUTOR"])." ";
$result.= "".substr($rec["DATUMCAS"], 6,2).".".substr($rec["DATUMCAS"], 4,2).".".substr($rec["DATUMCAS"], 0,4)." ".substr($rec["DATUMCAS"], 8,2).":".substr($rec["DATUMCAS"], 10,2).":".substr($rec["DATUMCAS"], 12,2)." ";
$result.= " ";
}
$result.= "
";
return $result;
} // end of function showAdmin()
function getPath() {
$result = $this->buildparent($this->id,$this->table,$this->partable);
return $result;
}
function getPubPath( $p_id ) {
$result = $this->buildparentPub($p_id,$this->table,$this->partable);
return substr($result, 0, strlen($result) - 14);
}
function buildparent($catid,$table,$partable)
{
if ($catid!=0 && isset($this->partable[$catid]))
{
$list=$partable[$catid];
$result=each($list);
if ($catid != $this->id):
$output = " » ";
$output .= $result[1]." ";
else:
$output = $result[1];
endif;
$output = $this->buildparent($result[0],$table,$partable).$output;
}
return (IsSet($output)) ? $output : "";
}
function buildparentPub($catid,$table,$partable)
{
if ($catid!=0 && isset($this->partable[$catid]))
{
$list=$partable[$catid];
$result=each($list);
if ($catid != $this->id):
//$output = "";
$output .= $result[1];
$output .= " ";
else:
$output = $result[1];
endif;
$output = $this->buildparentPub($result[0],$table,$partable).$output." » " ;
}
return (IsSet($output)) ? $output : "";
}
function addPage() {
global $f_nazev, $f_popis;
$result = "Cesta: cfg["admin_url"]."\"> root » ".$this->getPath()."
";
$result .= "
";
return $result;
}
function properties() {
global $f_nazev;
$result = "Cesta: cfg["admin_url"]."\"> root » ".$this->getPath()."
";
$result .= "
cfg["done_url"]."&page=".$this->id."\" method=\"post\" enctype=\"multipart/form-data\">";
$result.= " id."\">";
$result.= "
";
$result .= " cfg["done_url"]."\" method=\"post\" enctype=\"multipart/form-data\">";
$result .= " id."\">";
$result .= " ";
$result .= "Název stránky: nadpis."\">";
$result .= "Popis: ";
$result .= " ";
$result .= " ";
$result .= "
cfg["done_url"]."&page=".$this->id."&pageaction=newpravo\" method=\"post\" enctype=\"multipart/form-data\">";
$result.= " id."\">";
$result.= "uživatel: ";
$sSQL = "Select * from users";
$this->q->query($this->DB, $sSQL);
$result.= "-- vybrat -- ";
while( $rec = $this->q->getrow()) {
$result.= "".$rec['prijmeni'].", ".$rec['jmeno']." (".$rec['username'].") ";
}
$result.= " nebo ";
$result.= "skupina: ";
$sSQL = "Select * from usergroup";
$this->q->query($this->DB, $sSQL);
$result.= "-- všichni -- ";
while( $rec = $this->q->getrow()) {
$result.= "".$rec['nazev']." ";
}
$result.= " nebo ";
$result.= "právo: ";
while (list($key, $val) = each ($this->rights)) {
$result.= "$val ";
}
$result.= " ";
$result .= " ";
$result .= " ";
$result .= " ";
$result .= $this->getRightList();
return $result;
}
function getRightList() {
$sSQL = "Select * from users";
$q = new query($this->DB, $sSQL);
$users[0] = 'All'; $groups[0] = 'All';
while( $rec = $q->getrow())
$users[$rec["id"]] = $rec["username"];
$sSQL = "Select * from usergroup";
$q = new query($this->DB, $sSQL);
while( $rec = $q->getrow())
$groups[$rec["id"]] = $rec["nazev"];
$sSQL = "Select * from page_rights Where PAGE_ID = ".$this->id;
$this->q->query($this->DB, $sSQL);
$result = "";
return $result;
}
function delete() {
global $parent;
$result = "Cesta: cfg["admin_url"]."\"> root » ".$this->getPath()."
";
$result =
$result .= "
cfg["done_url"]."&page=".$this->id."&pageaction=newblok\" method=\"post\" enctype=\"multipart/form-data\">";
$result.= "
";
$result .= "";
$result .= " cfg["done_url"]."\" method=\"post\" enctype=\"multipart/form-data\">";
$result .= " id."\">";
$result .= " ";
$result .= " ";
$result .= " l."\">";
$result .= "Smazat stránku?
";
$result .= " ";
$result .= " ";
$result .= " ";
return $result;
header( "location: ".$this->cfg["done_url"]."&page=".$this->id."&pageaction=del&parent=$parent" );
} //end of function delete()
function editObsah() {
global $blok;
require_once('libs/blok.lib.php');
$result = "Cesta: cfg["admin_url"]."\"> root » ".$this->getPath()."
";
$result.= "
";
if (isset($blok)) {
$b = new CBlok($blok);
$result.= "
";
$result .= $b->edit();
} else {
$result .= "
cfg["done_url"]."?l=".$this->l."&page=".$this->id."&pageaction=newblok\" method=\"post\" enctype=\"multipart/form-data\">";
$result.= "";
$result .= "";
$result .= " ";
$sSQL = "Select * from bloky Where PAGE_ID = ".$this->id;
//echo $sSQL ;
$q1 = new query($this->DB, $sSQL);
while ( $rec = $q1->getrow()) {
$cbloky = new CBlok($rec["ID"]);
$result .= $cbloky->showAdmin();
}
}
return $result;
} //end of function edit()
function copy() {
global $autor;
$sSQL = "Insert into menu (TEXT, PARENT_ID, JAZYK, AUTOR) values ('Kopie - ".$this->nadpis."', ".$this->parent.", '".$this->l."', $autor)";
$this->q->query($this->DB, $sSQL);
$sSQL = "Select LAST_INSERT_ID() as tmp;";
$this->q->query($this->DB, $sSQL);
$rec = $this->q->getrow();
$url_param = "&page=".$rec["tmp"];
}
function getMaxParent( $catid )
{
if ($catid!=0 && isset($this->partable[$catid]))
{
$list=$this->partable[$catid];
$result=each($list);
//$output="$result[1] / ";
$output = ( $this->getMaxParent($result[0]) != 0 ) ? $this->getMaxParent($result[0]) : $result[0];
}
else
{
$output = 0;
}
return $output;
}
function maketree($rootcatid = 0, $maxlevel = 0)
{
$result = "Cesta: cfg["admin_url"]."\"> root » ".$this->getPath()."
";
$result .= "
";
$result .= "".$this->makeTree2( $rootcatid, $this->table, 0, $maxlevel)."
";
return $result;
}
function makeTree2($parcat,$table,$level,$maxlevel){
$list=$table[$parcat];
asort($list); // here we do the sorting
while(list($key,$val)=each($list)){
// do the indent
if ($level=="0"){
$output="";
}else{
$width=($level+1)*24;
$output=" ";
};
// the resulting HTML - feel free to change it
// $level is optional
$result = (!IsSet($result)) ? "" : $result;
$result .= "$output ";
$result .= "";
if ((isset($table[$key])) AND (($maxlevel>$level+1) OR ($maxlevel=="0"))) {
$result .= " ";
} else {
$result .= " ";
}
$result .= " ";
$result .= "$val ( l."&pageaction=move&parent=$key&page=".$this->id."\">přesunout sem )\n
";
if ((isset($table[$key])) AND (($maxlevel>$level+1) OR ($maxlevel=="0"))){
$result.= $this->makeTree2($key,$table,$level+1,$maxlevel);
};
};
return $result;
}
function move() {
global $parent;
$sSQL = "Update menu Set PARENT_ID = ".$parent." Where ID = ".$this->id;
$this->q->query($this->DB, $sSQL);
}
function addRight($p_id, $p_typ, $p_right) {
$sSQL = "Insert into page_rights (PAGE_ID, USER_GROUP_ID, TYP, PRAVO) values (".$this->id.", ".$p_id.", '".$p_typ."', ".$p_right.")";
$this->q->query($this->DB, $sSQL);
}
function delRight( $p_id ) {
$sSQL = "Delete from page_rights Where ID = $p_id";
$this->q->query($this->DB, $sSQL);
}
function getParentArray( $catid )
{
if ($catid!=0 && isset($this->partable[$catid]))
{
$list=$this->partable[$catid];
$result=each($list);
$output="$catid,";
$output=$this->getParentArray($result[0]).$output;
}
return (IsSet($output)) ? $output : "";
}
function getMinMax( $parent, $co, $lang ){
$sSQL = "Select $co(PORADI) cislo from menu Where PARENT_ID = $parent and JAZYK = '".$lang."'";
$q = new query($this->DB, $sSQL);
$rec = $q->getrow();
return $rec["cislo"];
}
function moveUp( $item )
{
$sSQL = "Select * from menu Where ID = $item";
$q = new query($this->DB, $sSQL);
$rec = $q->getrow();
$poradi = $rec["PORADI"];
$parent = $rec["PARENT_ID"];
$sSQL = "Select ID, PORADI from menu Where PARENT_ID = ".$parent." and PORADI < ".$poradi." order by PORADI desc limit 0,1";
//echo $sSQL;
$q->query($this->DB, $sSQL);
$rec = $q->getrow();
$tmp_id = $rec["ID"];
$tmp_poradi = $rec["PORADI"];
$sSQL = "Update menu set PORADI = ".$tmp_poradi." Where ID = ".$item ;
$q->query($this->DB, $sSQL);
$sSQL = "Update menu set PORADI = ".$poradi." Where ID = ".$tmp_id;
$q->query($this->DB, $sSQL);
}
function moveDown($item)
{
$sSQL = "Select * from menu Where ID = $item";
//echo $sSQL;;
$q = new query($this->DB, $sSQL);
$rec = $q->getrow();
$poradi = $rec["PORADI"];
$parent = $rec["PARENT_ID"];
$sSQL = "Select ID, PORADI from menu Where PARENT_ID = ".$parent." and PORADI > ".$poradi." order by PORADI limit 0,1";
//echo $sSQL;
$q->query($this->DB, $sSQL);
$rec = $q->getrow();
$tmp_id = $rec["ID"];
$tmp_poradi = $rec["PORADI"];
$sSQL = "Update menu set PORADI = ".$tmp_poradi." Where ID = ".$item;
$q->query($this->DB, $sSQL);
$sSQL = "Update menu set PORADI = ".$poradi." Where ID = ".$tmp_id;
$q->query($this->DB, $sSQL);
}
function listOfLang() {
$result = "
";
$result.= "přidat: cfg["admin_url"]."&page=$this->id&pageaction=addlang\">Jazkyk
";
$sSQL = "Select * from jazyky";
$q = new query($this->DB, $sSQL);
while($rec = $q->getrow()) {
$result.= $rec["popis"];
}
return $result;
}
function addLang() {
global $f_kod, $f_popis;
$result = "
";
if (!empty($f_kod) && !empty($f_popis)) {
$result.= $this->listOfLang();
} else {
$result .= "
cfg["done_url"]."&page=".$this->id."&pageaction=newlang\" method=\"post\" enctype=\"multipart/form-data\">";
$result .= " cfg["done_url"]."\" method=\"post\" enctype=\"multipart/form-data\">";
$result .= " id."\">";
$result .= " ";
$result .= "Kód: ";
$result .= "Popis: ";
$result .= " ";
$result .= " ";
}
return $result;
}
}
?>
class CELENERGOMenu extends Cmenu {
function CJOKAMenu($p_id, $admin=1 )
{
global $q, $DB, $action, $cfg, $userAuth;
return $this->CMenu($p_id, $admin);
}
function path() {
return $this->getPubPath($this->id);
}
function mainMenu() {
$sSQL = "Select * from menu Where JAZYK='".$this->l."' and PARENT_ID = 0";
$sSQL .= " order by PORADI";
$this->q->query($this->DB, $sSQL);
$result.= "";
return $result;
}
function leftMenu($p_id) {
// echo $p_id;
//$result .= $this->makebranch(0,$this->table,0,0);
$result = (empty($p_id) || $p_id == 1) ? "" : $this->maketree($p_id, 1);
return $result;
}
function maketree($rootcatid, $maxlevel)
{
//$result = "";
return $result;
}
function makebranch($parcat,$table,$level,$maxlevel)
{
global $mylevel;
//echo $level;
if (( IsSet($table[0]) && $level==0) || ( IsSet($table[$parcat]) && $level!=0) /* && $parcat != 0 */):
//$list = ($level!=0) ? $table[$parcat] : $table[0];
$list = ($level!=0) ? $table[$parcat] : $table[($this->getMaxParent( $this->id ) == 0) ? $this->id : $this->getMaxParent( $this->id )];
//$list = $table[$parcat] $this->getMaxParent( $this->id );
//asort($list); // here we do the sorting
$pocitadlo = 1;
while( isset($list) && list($key,$val) = each($list) )
{
$result = (!IsSet($result)) ? "" : $result;
$tmp = 2-$level;
$result.= "id && isset($this->table[$this->id])) || $this->getMaxParent( $this->id ) == $key ) {
$result.= "class=\"minus\"";
}
//if (!is_array($val) && $level > 0) {$result.= "class=\"none\"";}
if (!isset($this->table[$key])) {$result.= "class=\"none\"";}
$result.=">0) {$result .= "class=\"under\"";}
//$result.= $this->styl[($level!=0) ? $parcat : 0][$key];
$result.= ">$val ";
//$result.= " 0 ) ? "menu_sub" : "menu_main";
//$result.= "\">$val \n";
if ($pocitadlo < 4 ) $pocitadlo++;
if (
( isset($table[$key]) && (($maxlevel>$level+1) || ($maxlevel=="0")))
||
( in_array( $key, $this->ParentArray ) && isset($table[$key])
||
$parcat == $key
)
)
{
$result .= "".$this->makebranch($key,$table,$level+1,$maxlevel)." ";
}
} //endwhile
return $result;
else:
return false;
endif;
}
}
Došlo k chybě při spojení s databází! Opakujte, prosím, akci později.