Contenido 4.4.5 hat wohl Probleme mit verschachtelten array-Klammern.
Geht nicht:
Geht:
Ich habe den Code auch noch ein bisschen überarbeitet; man kan nun die notwendigen Parameter am Anfang des Outputs angeben (wobei eine Konfiguration natürlich schöner wäre, aber aud schnelle...).
Für das Glossar muss eine Oberkategorie erzeugt werden. Darunter muss man weitere Kategorien anlegen, die dann die Artikel enthalten. Bei diesen Kategorien kann es sich z.B. um eine Kategorie für jeden Anfangsbuchstaben handeln oder um Gruppieren, z.B. Essen, Getränke, ....
Beispiel:
- News <- Oberkategorie
-- Kategorie A <- Kategorie pro Anfangsbuchstabe
---- Artikel Alle meine Entchen
---- Artikel Am Ende ist am Anfang
---- Artikel Allmählich gehen mir die Beispiele aus
- Glossar
Glossar enthält den Artikel mit diesem Modul... (Vorgabe Darthbach).
$parentcatid ist die idcat der
Oberkategorie. $cmstypeid ist die interne ID des Content-Typs, 2 ist z.B. CMS_HTML. $numberofcmstype ist die Nummer, die im Textmodul hinter dem Contenttyp steht, z.B. 1 bei CMS_HTML[1].
Code: Alles auswählen
<?php
$parentcatid = 21;
$cmstypeid = 2;
$numberofcmstype = 1;
echo "<!-- Modul: Glossarliste -->\n";
function klein($text) {
$text = urldecode($text);
$text = strip_tags($text, "");
// $text = str_replace(" ", "_", $text);
$text = str_replace(":", "_", $text);
$text = str_replace("(", "_", $text);
$text = str_replace(")", "_", $text);
$text = str_replace("[", "_", $text);
$text = str_replace("]", "_", $text);
$text = str_replace("'", "_", $text);
$text = str_replace('"', '_', $text);
$text = strtolower($text);
$text = str_replace("ä", "ae", $text);
$text = str_replace("ö", "oe", $text);
$text = str_replace("ü", "ue", $text);
$text = str_replace("ß", "ss", $text);
return $text;
}
function unterkategorien($kategorie) {
global $cfg, $unterkat;
$unterkat[] = $kategorie;
$db = new DB_Contenido;
$sql = "SELECT idcat FROM {$cfg['tab']['cat']} WHERE parentid = '".$kategorie."' ORDER BY idcat ASC;";
$db->query($sql);
while ($db->next_record()) {
unterkategorien($db->f("idcat"));
}
}
$db = new DB_Contenido;
$db2 = new DB_Contenido;
$breiterand = 5;
$breitekomplett = 200 - 2 * $breiterand;
$liste = array("0-9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "@");
foreach ($liste as $buchstabe) {
$gesamt[$buchstabe] = "";
}
$unterkat = array();
unterkategorien($parentcatid);
// liest die anzahl betroffener artikel aus der datenbank
$sql = "SELECT count(*) AS anzahl FROM ".$cfg['tab']['cat']." AS a LEFT JOIN ".$cfg['tab']['cat_art']." AS b ON a.idcat = b.idcat LEFT JOIN ".$cfg['tab']['art_lang']." AS c ON b.idart = c.idart LEFT JOIN ".$cfg['tab']['content']." AS d ON c.idartlang = d.idartlang LEFT JOIN ".$cfg['tab']['cat_lang']." AS e ON a.idcat = e.idcat WHERE a.parentid IN (".implode(", ", $unterkat).") AND d.idtype = '".$cmstypeid."' AND d.typeid = '".$numberofcmstype."' AND d.value != '';";
$db->query($sql);
$db->next_record();
$anzahl_artikel = $db->f("anzahl");
if ($anzahl_artikel > 0) {
$sql = "SELECT d.value, b.idart, b.idcat, e.name FROM ".$cfg['tab']['cat']." AS a LEFT JOIN ".$cfg['tab']['cat_art']." AS b ON a.idcat = b.idcat LEFT JOIN ".$cfg['tab']['art_lang']." AS c ON b.idart = c.idart LEFT JOIN ".$cfg['tab']['content']." AS d ON c.idartlang = d.idartlang LEFT JOIN ".$cfg['tab']['cat_lang']." AS e ON a.idcat = e.idcat WHERE a.parentid IN (".implode(", ", $unterkat).") AND d.idtype = '".$cmstypeid."' AND d.typeid = '".$numberofcmstype."' AND d.value != '';";
$db->query($sql);
while ($db->next_record()) {
$suche = klein($db->f("value"));
$suchindex = substr($suche, 0, 1);
$titel = urldecode($db->f("value"));
$artikel = $db->f("idart");
$kategorie = $db->f("idcat");
$abteilung = $db->f("name");
$gefunden = false;
foreach ($liste as $value) {
$wert = ord($suchindex);
if (($wert > 47) && ($wert < 57))
$suchindex = "0-9";
if ($value == $suchindex) {
$gefunden = true;
break;
}
}
if ($gefunden) {
$gesamt[$suchindex][] = array('suche' => $suche, 'titel' => $titel, 'kategorie' => $kategorie, 'artikel' => $artikel, 'abteilung' => $abteilung);
} else {
$gesamt['@'][] = array('suche' => $suche, 'titel' => $titel, 'kategorie' => $kategorie, 'artikel' => $artikel, 'abteilung' => $abteilung);
}
}
echo ' <tr><td align="right" colspan="3" class="liste">';
for ($i = 0; $i < 14; $i++) {
$text = strtoupper($liste[$i]);
if (is_array($gesamt[ $liste[$i] ])) {
$text = '<a href="#'.$text.'" class="liste">'.$text.'</a>';
}
echo $text.' ';
}
echo '</td></tr>
<tr><td align="right" colspan="3" class="liste">';
for ($i = 14; $i < 28; $i++) {
$text = strtoupper($liste[$i]);
if (is_array($gesamt[ $liste[$i] ])) {
$text = '<a href="#'.$text.'" class="liste">'.$text.'</a>';
}
echo $text.' ';
}
echo '</td></tr>
<tr><td colspan="3" class="text">Dieses Glossar enthält '.$anzahl_artikel.' Artikel.</td></tr>
';
foreach ($liste as $buchstabe) {
if (is_array($gesamt[$buchstabe])) {
sort($gesamt[$buchstabe]);
$text = strtoupper($buchstabe);
echo ' <tr><td colspan="3" width="'.$textspalteplus.'"><img src="images/dotclear.gif" width="'.$textspalteplus.'" height="20" alt=""></td></tr>
<tr>
<td valign="top" width="'.$breiterand.'"> </td>
<td valign="top" width="'.$breitekomplett.'" valign="top"><a name="'.$text.'"></a>'.$text.'</td>
<td valign="top" width="'.$breiterand.'"> </td>
</tr>
';
foreach ($gesamt[$buchstabe] as $eintrag) {
$link = $sess->url("front_content.php?idcat=".$eintrag['kategorie']."&idart=".$eintrag['artikel'].$sessionid);
echo ' <tr>
<td valign="top" width="'.$breiterand.'"> </td>
<td valign="top" width="'.$breitekomplett.'" valign="top"><a href="'.$link.'" class="liste_headlinelink">'.$eintrag['titel'].'</a> ('.$eintrag['abteilung'].')</td>
<td valign="top" width="'.$breiterand.'"> </td>
</tr>
';
}
echo ' <tr>
<td valign="top" width="'.$breiterand.'"> </td>
<td valign="top" width="'.$breitekomplett.'"> </td>
<td valign="top" width="'.$breiterand.'"> </td>
</tr>
';
}
}
} else {
echo ' <tr>
<td valign="top" width="'.$breiterand.'"> </td>
<td valign="top" align="center" width="'.$breitekomplett.'">Dieses Glossar enthält leider noch keine Artikel.</td>
<td valign="top" width="'.$breiterand.'"> </td>
</tr>
<tr>
<td valign="top" width="'.$breiterand.'"> </td>
<td valign="top" width="'.$breitekomplett.'"> </td>
<td valign="top" width="'.$breiterand.'"> </td>
</tr>
';
}
unset ($breiterand);
unset ($breitekomplett);
?>
Viel Spass beim Anpassen.
Gruß
HerrB