<?php
/* Einbinden oft benötigter Funktionen */
include_once($rel."libraries/BTPL_functions.inc.php");
/* Ableitung eines Optionen Objektes für Download Optionen */
$dlOption = new CBOption();
$dlOption->setModule("download");
$dlOption->getOptionList();
include($path["cb"].$cbDirLib."pageSplit.class.php");
if (!$offset) { $offset = 0; }
$limit = 10;
$limitString = $offset.", ".$limit;
/*
* Queries generieren
* abhängig vom Ausgangspunkt beim laden des Moduls (ist $id gesetzt oder nicht)
* müssen verschiedene Queries generiert werden. Wenn $id nicht gesetzt,
* dann alle Kategorien anzeigen, die download als zuständiges Modul
* angegeben haben
* File Queries werden nur generiert, wenn $id bekannt
*/
if (empty($id) || !ereg("(^[1-9]?[0-9]*$)", $id)) {
$catQuery = mysql_query("SELECT * FROM ".TABLE."_mm_folder WHERE module = 'download' ORDER BY name ASC");
$catQuerySet = true;
if(!$catQuery) {
$catQuerySet = false;
}
$fileQuerySet = false;
} else {
/* alle Unterrubriken */
$catQuery = mysql_query("SELECT * FROM ".TABLE."_mm_folder WHERE parentID = '$id' ORDER BY name ASC");
/* Alle Dateien der aktuellen Rubrik */
$fileQuery = mysql_query("SELECT * FROM ".TABLE."_mm_files AS file, ".TABLE."_user AS user WHERE user.userid = file.userid AND file.branchID = '$id' ORDER BY insertdate DESC, file.filename ASC LIMIT $limitString");
/*
* Seiten Blätter Feature
*/
$result = mysql_query("SELECT COUNT(fileID) AS counter FROM ".TABLE."_mm_files WHERE branchID = '$id'");
list($numrec) = mysql_fetch_row($result);
$numpage = intval($numrec/$limit);
// Es wird aufgerundete wenn Teilrest übrig bleibt.
if ($numrec%$limit) {
++$numpage;
}
/*
* Herausfinden des Pfades an Rubriken, nebenbei auslesen
* der aktuellen Rubrik
*/
$counter = 1;
$actualID = $id;
$rootParentFound = false;
do {
/* Daten der aktuellen Rubrik */
$branchPathQuery = mysql_fetch_object(mysql_query("SELECT name, branchID, module, parentID, branchName, description FROM ".TABLE."_mm_folder WHERE branchID = '$actualID'"));
if($counter == 1) {
$actualBranchRow = $branchPathQuery;
}
$pathToRootName[] = $branchPathQuery->name;
$pathToRootID[] = $branchPathQuery->branchID;
$pathToRootDesc[] = $branchPathQuery->decription;
$actualID = $branchPathQuery->parentID;
if($branchPathQuery->module == 'download') {
$rootParentFound = true;
}
if($branchPathQuery->parentID == '0' || $branchPathQuery->parentID == '') {
$rootParentFound = true;
}
++$counter;
} while($rootParentFound != true);
$pathToRootName = array_reverse($pathToRootName);
$pathToRootDesc = array_reverse($pathToRootDesc);
$pathToRootID = array_reverse($pathToRootID);
/* gibt es Unterrubriken? ja / nein */
$catQuerySet = true;
if(!$catQuery) {
$catQuerySet = false;
}
/* gibt es Dateien? ja / nein */
$fileQuerySet = true;
if(!$fileQuery) {
$fileQuerySet = false;
}
}
/*
* Unterrubrik Abfrage
* wenn Unterrubriken vorhanden, Abfrage und Speicherung in Array,
* danach Zuweisung an Template
*/
if($catQuerySet) {
$catSubSet = 0;
while($catRow = mysql_fetch_object($catQuery)) {
$catName[] = $catRow->name;
$catID[] = $catRow->branchID;
$catDesc[] = $catRow->description;
$catSubSet = 1;
}
$tpl->assign("catSubSet", $catSubSet);
$tpl->assign("catQuerySet", "1");
$tpl->assign("catData",
array ( "name" => $catName,
"id" => $catID,
"desc" => $catDesc
)
);
$tpl->assign("pathData",
array ( "name" => $pathToRootName,
"id" => $pathToRootID
)
);
}
/*
* Datei Abfrage
*/
if($fileQuerySet) {
/*
* Page Navigation initialisieren, Offsets herausfinden
*/
$navigation = new PageSplit($limit, $offset, $numpage);
$pn = array();
if($navigation->checkLastAvailable()) {
$pn['back'][set] = "1";
$pn['back'][offset] = $navigation->getLastPage();
} else {
$pn['back'][set] = "0";
}
if($navigation->checkNextAvailable()) {
$pn['fwd'][set] = "1";
$pn['fwd'][offset] = $navigation->getNextPage();
} else {
$pn['fwd'][set] = "0";
}
$pn['pages'][offsets] = array_values($navigation->pages);
$pn['pages'][number] = array_keys($navigation->pages);
/*
* assign page Navigation
*/
$tpl->assign("pageNavigation", $pn);
$tpl->assign("currentPage", $navigation->thisPage);
/* Speicherung des Pfades zum aktuellen Uploadverzeichnis */
$actualBranchPath = $path["cb"].$cbDirUploads."files/".$actualBranchRow->branchName."/";
/* Zuweisung der Daten des aktuellen Zweiges an das Template */
$tpl->assign("actualBranch",
array ( "name" => $actualBranchRow->name,
"id" => $actualBranchRow->branchID,
"branchName" => $actualBranchRow->branchName,
"parentID" => $actualBranchRow->parentID,
"desc" => $actualBranchRow->description,
"status" => $actualBranchRow->status
)
);
/*
* Abrage der einzelnen Dateien und Ermittlung der Metadaten wie
* Größe usw. Umwandlung des Datums in einen Timestamp. Verarbeitung
* der Daten
*/
$filesSet = 0;
while($fileRow = mysql_fetch_object($fileQuery)) {
$commentCount = mysql_fetch_object(mysql_query("SELECT COUNT(commentID) AS counter FROM ".TABLE."_comment WHERE type = 'download' AND entryID = '".$fileRow->fileID."'"));
$fileCommentCount[] = $commentCount->counter;
$fileID[] = $fileRow->fileID;
$fileType[] = $fileRow->typeID;
$fileUID[] = $fileRow->userid;
$fileUserName[] = $fileRow->name;
$fileName[] = $fileRow->filename;
$fileSize[] = fsize($actualBranchPath.$fileRow->filename);
$fileTitle[] = $fileRow->title;
$fileDesc[] = $fileRow->description;
$fileKeyWords[] = $fileRow->keywords;
$fileOptions[] = $fileRow->options;
$fileParam[] = $fileRow->parameter;
$fileDate[] = strtotime($fileRow->insertdate);
$filesSet = 1;
} // while
/* Zuweisung der Daten ans Template */
$tpl->assign("fileQuerySet", $filesSet);
$tpl->assign("fileData",
array ( "name" => $fileName,
"username" => $fileUserName,
"size" => $fileSize,
"fileID" => $fileID,
"typeID" => $fileType,
"userID" => $fileUID,
"keywords" => $fileKeyWords,
"title" => $fileTitle,
"options" => $fileOptions,
"param" => $fileParam,
"date" => $fileDate,
"desc" => $fileDesc,
"commentCount" => $fileCommentCount
)
);
}
/* Ausgabe des Templates */
$tpl->display("dl_overview.template");
?>