<?php
$dirCount = 0;
defineOnce("PROTOCOL_PATTERN", "[a-z]:/*");
function displayLink($link, $name) {
$docLink = & new DocLink($link, $name);
// Create the associated view
$view = & new DocLinkView($docLink);
$view->displayLinkOpenDl();
}
function displayDir($link, $name, $enable = true, $open = false) {
global $dirCount;
$dir = str_replace("%2F","/",urlencode($link));
$isOk = ($ptrrep = @dir(urldecode($link)));
if ($isOk) {
chdir($ptrrep->path);
displayDivStart("Doc");
loopDir($link."/", "./", false, $open, $name, $enable);
displayDivEnd();
} else {
displayDivStart("Doc");
echo $name."<br/>";
displaySpanStart("error");
displaySpanStart("smallCode");
echo getLang("not_able_access")." ";
echo " <span class=\"progCode\">$link</span> - ";
echo getLang("check_doc_url")." ";
echo "<a href=\"Projects.php\">".getLang("projects")."</a>"." ".getLang("section");
displaySpanEnd();
displaySpanEnd();
displayDivEnd();
}
}
function loopDir($homeDir, $dir, $even, $open, $name, $enable = true) {
global $dirCount;
$dirCount ++;
global ${"content_$dirCount"};
$content = "content_$dirCount";
displayDivStart("directory".($even?" even":""));
?>
<div class="docDirLink <?=$open?"Open":"Closed"?>" onclick="openClose('docDirLink', this);<?=visibleInvisible(array($content))?>;"><?=$name?></div>
<?php
if ($open) {
$visibility = XP_VISIBLE;
} else {
$visibility = XP_INVISIBLE;
}
displayVisibleInvisibleSectionStart($visibility, $content);
// Here display content
$currentDir = $homeDir.$dir;
$ptrrep = dir($currentDir);
chdir($ptrrep->path);
$nbFiles = 0;
while(false != ($file=$ptrrep->read())) {
if($file!= "." && $file!= "..") {
$fileList[$nbFiles] = $file;
$nbFiles++;
}
}
if (!empty($fileList))
sort($fileList);
for ($i=0; $i < $nbFiles; $i ++) {
$file = $fileList[$i];
if(!is_dir($file)) {
$newUrl = str_replace("+","%20", $currentDir.urlencode($file));
$docLink = & new DocLink($newUrl, $file);
// Create the associated view
$view = & new DocLinkView($docLink);
$view->enable = $enable;
//echo $homeDir." === ".$dir."<br/>";
$view->displayLinkOpenDl(true);
} else {
// Display sub-directory
loopDir($currentDir, "$file/", !$even, false, $file, $enable);
// Back to current directory
$ptrrep = dir("..");
chdir($ptrrep->path);
}
}
displayVisibleInvisibleSectionEnd($visibility, $content); // visibility
displayDivEnd(); // directoryColor
}
function displayNoLink($typeName) {
displayNone(getNoLinkGoToProjectText($typeName));
}
// *********************************************************************
// Class DocLinkView
// *********************************************************************
class DocLinkView extends XPItemView {
var $enable;
function DocLinkView(& $item) {
$this->XPItemView($item);
$this->enable = true;
}
function displayLinkOpenDl($inDir = false) {
displayDivStart("docLink");
?>
<span class="docLinkName" title="<?=$this->item->link?>"><?=$this->item->name?></span>
<?php
displaySpanStart("openDlLinks");
if ($this->item->link == "") {
echoSpan("smallComment", getLang("empty_url"));
} else {
$openUrl = "doNothing();";
$openOk = false;
$dlUrl = "doNothing();";
$dlOk = false;
if ($this->enable) {
if (!$inDir) {
// Is the file local? If it is, there is no way to open it in a frame
$canOpenLocal = @filesize($this->item->link);
if ($canOpenLocal) {
// local file => no way to open it
} else {
$openUrl = "url('".$GLOBALS["gThisPage"].".php?url=".$this->item->link."');";
$openOk = true;
}
}
if ($inDir || $canOpenLocal) {
$dlUrl = "url('Download.php?url=".$this->item->link."');";
$dlOk = true;
}
}
?>
<a class="docOpenLink<?=$openOk?"":" disabled"?>" href="javascript:<?=$openUrl?>" title="<?=getLang("open")?>"> </a>
<a class="docDlLink<?=$dlOk?"":" disabled"?>" href="javascript:<?=$dlUrl?>" title="<?=getLang("download")?>"> </a>
<?php
}
displaySpanEnd();
displayDivEnd();
}
}
?>