hier das neuste elaborat aus unserem haus für die version 4.6.2. es handelt sich dabei um eine geteilte navigation.
hier der code (erkärungen dazu weiter unten):
Code: Alles auswählen
<?php
/**
* $Revision: 1.22 $
* $Source: D:/cvs/cvsrepo/test/PPI_Nade/module/mainNavigation/output.php,v $
* $Date: 2005/11/28 10:20:39 $
*/
/**
* navigation
* @author Andreas Kummer
* @copyright Copyright © 2005 w3concepts AG
*/
if (!class_exists('navigation')) {
class navigation {
/**
* Konstruktor der Klasse.
* @param Integer Primärschlüssel der Startkategorie.
*/
function navigation($startId) {
global $client, $lang, $idcat;
$this->startId = $startId;
$this->client = $client;
$this->lang = $lang;
$this->idcat = $idcat;
$this->before = '';
$this->beforeEach = '';
$this->between = '';
$this->after = '';
$this->db = new DB_Contenido();
$this->setStartIds();
$this->getNavigation();
}
/**
* Auslesen der Navigationsstruktur aus der Datenbank.
*/
function getNavigation() {
global $cfg;
if ($this->startId != $this->id[0]) {
/*
* Wenn die StartId nicht identisch ist mit der höchsten Ebene der
* aktuell selektierten Kategorie, dann liegt die gewählte Kategorie
* folgerichtig ausserhalb des für die Navigation gewählten Baumes.
* In diesem Fall ist nur die Hauptnavigation einzublenden.
*/
$this->id[0] = $this->startId;
for ($i = 1; $i <= 3; $i++) {
$this->id[$i] = -1;
}
}
$this->db->query("" .
"SELECT " .
" a.idcat, " .
" a.parentid, " .
" a.preid, " .
" a.postid, " .
" a.parentid, " .
" b.visible, " .
" b.name, " .
" b.idlang " .
" FROM {$cfg['tab']['cat']} AS a " .
"LEFT JOIN {$cfg['tab']['cat_lang']} AS b ON a.idcat = b.idcat " .
"WHERE " .
" a.idclient = {$this->client} " .
" AND (" .
" a.parentid = {$this->id[0]} " .
" OR a.parentid = {$this->id[1]} " .
" OR a.parentid = {$this->id[2]} " .
" OR a.parentid = {$this->id[3]} " .
" ) " .
"");
$this->navigationTree = array();
$this->firstId[0] = 0;
$this->firstId[1] = 0;
$this->firstId[2] = 0;
$this->firstId[3] = 0;
while ($this->db->next_record()) {
for ($i = 0; $i <= 3; $i++) {
if (($this->firstId[$i] == 0 && $this->db->f('parentid') == $this->id[$i] && $this->db->f('preid') == 0 && $this->db->f('idlang') == $this->lang) || ($this->firstId[$i] == 0 && $this->db->f('parentid') == $this->id[$i] && $this->db->f('preid') == 0 && $this->db->f('idlang') == null)) {
$this->firstId[$i] = $this->db->f('idcat');
}
}
$this->navigationTree[$this->db->f('parentid')][$this->db->f('idcat')] = array('preid'=>$this->db->f('preid'), 'postid'=>$this->db->f('postid'), 'visible'=>$this->db->f('visible'), 'name'=>$this->db->f('name'), 'idlang'=>$this->db->f('idlang'));
}
}
/**
* Ausgabe der Navigation an die Standardausgabe.
* @param String Navigationstyp
*/
function showNavigation($type, $next = -1) {
static $first;
static $output = false;
if ($next == 0) {
return false;
}
if ($next == -1) {
echo $this->before;
$next = $this->firstId[$type];
$first = true;
}
$parentId = $this->id[$type];
$link = 'front_content.php?idcat='.$next;
if ($this->navigationTree[$parentId][$next]['visible'] == 1 && $this->navigationTree[$parentId][$next]['idlang'] == $this->lang) {
if (!$first) {
echo $this->between;
}
if ($this->isSelected($next)) {
echo $this->beforeSelected;
} else {
echo $this->beforeEach;
}
echo '<a href="'.$link.'">'.$this->navigationTree[$parentId][$next]['name'].'</a>';
$first = false;
$output = true;
} elseif (!$output && $this->navigationTree[$parentId][$next]['postid'] == 0) {
/*
* Die Navigation enthält nichts.
*/
echo ' ';
}
$this->showNavigation($type, $this->navigationTree[$parentId][$next]['postid']);
}
/**
* Ausgabe vor der Navigation
* @param String Ausgabe vor der Navigation.
*/
function before($text) {
$this->before = $text;
}
/**
* Ausgabe vor jedem Eintrag
* @param String Ausgabe vor jedem Eintrag.
*/
function beforeEach($text) {
$this->beforeEach = $text;
}
/**
* Ausgabe vor jedem selektierten Menueintrag
* @param String Ausgabe vor jedem selektierten Menueintrag.
*/
function beforeSelected($text) {
$this->beforeSelected = $text;
}
/**
* Ausgabe zwischen zwei Hauptmenupunkten
* @param String Ausgabe zwischen zwei Hauptmenupunkten.
*/
function between($text) {
$this->between = $text;
}
/**
* Ausgabe nach der Navigation
* @param String Ausgabe nach der Navigation.
*/
function after($text) {
$this->after = $text;
}
/**
* Gibt das Level der Kategorie zurück.
* @param Integer Primärschlüssel der Kategorie.
* @return Integer Level der spezifizierten Kategorie.
*/
function getLevel($idcat) {
global $cfg;
if (empty($idcat)) {
return 0;
}
$this->db->query("" .
"SELECT level FROM {$cfg['tab']['cat_tree']} " .
"WHERE " .
" idcat = $idcat" .
"");
if ($this->db->next_record()) {
return $this->db->f('level');
} else {
return 0;
}
}
/**
* Gib die Tiefe relativ zum Hauptmenu an.
* @param Integer Primärschlüssel der Kategorie
* @return Integer Level relativ zum Hauptmenu
*/
function getNetLevel($idcat) {
return $this->getLevel($idcat) - $this->getLevel($this->startId);
}
/**
* Ermittlung des jeweils ersten Kategorieeintrages jeder Ebene. Die
* Speicherung dieser Daten erfolgt in das Klassenattribut id.
*/
function setStartIds() {
$id = $this->idcat;
$level = $this->getNetLevel($id);
$this->id[$level] = $id;
while ($level > 0) {
$this->id[$level-1] = $this->getParentId($id);
$id = $this->id[$level-1];
$level = $this->getNetLevel($id);
}
if (empty($this->id)) {
$this->id[0] = $this->startId;
}
for ($i = 1; $i <= 3; $i++) {
if (empty($this->id[$i])) {
$this->id[$i] = -1;
}
}
ksort($this->id);
}
/**
* Ermittlung des Elternelementes der Kategorie mit dem Primärschlüssel
* idcat
* @param Integer Primärschlüssel des Kindelementes, dessen Elternelement
* ermittelt werden soll.
* @return Integer Primärschlüssel des Elternelementes.
*/
function getParentId($idcat) {
global $cfg;
$this->db->query("" .
"SELECT parentid FROM {$cfg['tab']['cat']} " .
"WHERE " .
" idcat = $idcat " .
"");
if ($this->db->next_record()) {
return $this->db->f('parentid');
} else {
return 0;
}
}
/**
* Anzeige, ob eine Navigationsebene Elemente enthält oder nicht.
* @param Integer Navigationsstufe.
* @return Boolean True, wenn die Navigationsstufe leer ist (keine Elemente
* enhält). Sonst false.
*/
function navigationEmpty($level) {
if ($this->firstId[$level] == 0) {
return true;
}
return false;
}
/**
* Anzeige, ob eine Kategorie selektiert ist oder nicht. Eine Kategorie gilt
* als selektiert, wenn sie die aktuelle Kategorie ist oder ein direktes
* oder indirektes Elternelement der aktuellen Kategorie.
* @param Integer Primärschlüssel der Kategorie, deren Status gefragt ist.
* @return Boolean True, wenn die gefragte Kategorie mit der aktuellen
* Kategorie übereinstimmt oder ein direktes oder indirektes Elternelement
* der aktuellen Kategorie darstellt.
*/
function isSelected($idcat) {
return in_array($idcat, $this->id);
}
}
}
$navigation = new navigation("CMS_VALUE[0]");
$navigation->between('<img src="/cms/images/templateImages/spacer.png" width="10" height="1"/>');
$navigation->beforeEach('<img src="/cms/images/templateImages/spacer.png" width="10" height="1"/>');
$navigation->beforeSelected('<img src="/cms/images/templateImages/pfeilWeiss.png"/>');
$navigation->showNavigation(0);
?>
Code: Alles auswählen
$navigation->showNavigation(0);
die werte für beforeEach, beforeSelected und between könne jeweils vor dem aufruf der showNavigation wieder geändert werden.
hope this is usefull!
regards,
andreas
ps: und man braucht für den input natürlich noch die klasse chooseTree:
Code: Alles auswählen
?><?
/**
* $Revision: 1.7 $
* $Source: D:/cvs/cvsrepo/test/PPI_Nade/module/articleList/input.php,v $
* $Date: 2005/11/25 17:41:12 $
*/
/**
* chooseTree
* @author Andreas Kummer
* @copyright Copyright © 2005 w3concepts AG
*/
if (!class_exists('chooseTree')) {
class chooseTree {
function chooseTree($selected, $index) {
global $lang, $client;
$this->selected = $selected;
$this->index = $index;
$this->lang = $lang;
$this->client = $client;
$this->db = new DB_Contenido();
$this->queryStructure();
$this->outputInterface();
}
function queryStructure() {
global $cfg;
$this->db->query("" .
"SELECT " .
" a.idcat, " .
" a.level, " .
" c.name " .
"FROM {$cfg['tab']['cat_tree']} AS a, " .
"{$cfg['tab']['cat']} AS b, " .
"{$cfg['tab']['cat_lang']} AS c " .
"WHERE " .
" a.idcat = b.idcat " .
" AND b.idcat = c.idcat " .
" AND c.idlang = '{$this->lang}' " .
" AND b.idclient = '{$this->client}' " .
" AND c.visible=1 " .
"ORDER BY " .
" a.idtree" .
"");
$this->structure = array();
while ($this->db->next_record()) {
$this->structure[$this->db->f('idcat')] = array('level'=>$this->db->f('level'), 'name'=>$this->db->f('name'));
}
}
function outputInterface() {
/*
* Tabellenanfang ausgeben
*/
echo "<table cellspacing=\"0\" cellpadding=\"10\" border=\"0\">";
/*
* Zeilenanfang ausgeben
*/
echo "<tr><td>Baum wählen:</td><td>";
/*
* Select-Feld ausgeben
*/
echo $this->getSelect($this->structure, $this->index);
/*
* Zeilenende ausgeben
*/
echo "</td></tr>";
/*
* Tabellenende ausgeben
*/
echo "</table>";
}
function getSelect($structure, $name) {
$returnValue = '<select size="1" name="'.$name.'" class="text_medium">'."\n";
foreach ($structure as $idcat => $item) {
if ($idcat == $this->selected) {
$selected = ' selected = "selected"';
} else {
$selected = '';
}
$spaces = "|";
for ($i = 0; $i < $item['level']; $i ++) {
$spaces = $spaces . "--";
}
$spaces .= ">";
$returnValue .= '<option value="'.$idcat.'"'.$selected.'>'.$spaces.$item['name'].'</option>';
}
$returnValue .= '</select>'."\n";
return $returnValue;
}
}
}
$chooseTree = new chooseTree("CMS_VALUE[0]", "CMS_VAR[0]");