Location: PHPKode > projects > PHPmyCDMouse > phpmycdmouse_031/cddirbrowse.php
<?
/*
   Copyright (C) 2003  by Uwe Thiel, Germany

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
    USA.
*/

session_start();
require("./config.inc.php");
require($Header);
require("./functioninc/catpopup.js");
require("./functioninc/popupvar.js");
require("./functioninc/brows_lend_disp.php");
deletevars();
$Access = $_SESSION["Access"];

$FileOffset = intval($_GET["FileOffset"]);


$BrowseDir=$_GET["BrowseDir"];

if (($BrowseDir==NULL) || ($BrowseDir=="") || ($BrowseDir==" ")) $BrowseDir="/";

if (strlen($BrowseDir)>1) {
    $DirUptmp=explode("/", $BrowseDir);
    if (count($DirUptmp) >2) { array_pop($DirUptmp); $DirUp=implode("/", $DirUptmp); } else $DirUp="/";
 } else $DirUp="/";


	

		$ID = intval($_GET["ID"]);


				$GetCDCatname = new CD_DB();
				$GetCDCatnameSQL = "SELECT CDLabel, CDCategoryID, CategoryName FROM CD LEFT JOIN Category ON Category.CategoryID=CD.CDCategoryID WHERE CDID=$ID";
				$GetCDCatname->query($GetCDCatnameSQL);
				$GetCDCatname->next_record();
				$ParentID=0;
				$FileList = new CD_DB();
				$FileListSQL = "SELECT FileID, File.CDID AS CDID, CDLabel, CDsize, CDCreated, CDAddedDate, CDNumber, Description, NrFiles, NrSubDirs, Filename, Filetype, LinkTarget, FileDatetime, Filesize, SubDir, FileLabel FROM File, CD WHERE File.CDID=CD.CDID AND CD.CDID=$ID AND File.SubDir="."'".$BrowseDir."'" ." ORDER BY Filetype,SubDir,Filename LIMIT $FileOffset, $LinesPerPage";
				$FileList->query($FileListSQL);
				$RecordCount = new CD_DB();
				$RecordCountSQL = "SELECT COUNT(FileID) AS FileCount FROM File, CD WHERE File.CDID=CD.CDID AND CD.CDID=$ID AND File.SubDir="."'".$BrowseDir."'" ." ORDER BY Filename";
				$RecordCount->query($RecordCountSQL);
				$RecordCount->next_record();
################################################################################################################################################################
if ($FileList->num_rows()>0) {

    $GetIcons= new CD_DB;
    $GetIconsSQL="SELECT UserIcons.ICONID AS ICONID, Iconname, Iconsize, Icontype, Image_bin, Description, Extensions.Ext FROM UserIcons LEFT JOIN  Extensions ON UserIcons.ICONID=Extensions.ICONID ORDER BY ICONID";
    $GetIcons->query($GetIconsSQL);
    if ($GetIcons->num_rows()>0) {
                         $Iconcount=1;
                         for ($i=0; $GetIcons->next_record(); $i++) {
                              $ICONID[$i]=$GetIcons->f("ICONID");
			      $Iconname[$i]=$GetIcons->f("Iconname");
			      $Iconsize[$i]=$GetIcons->f("Iconsize");
			      $Icontype[$i]=$GetIcons->f("Icontype");
			      $Description[$i]=$GetIcons->f("Description");
			      $Iconext[$i]=$GetIcons->f("Ext");
			      if (($i>0) && (($ICONID[$i-1])!=($ICONID[$i]))) $Iconcount++;

                 } #of for GetIcons->next_record
         } #of $GetIcons->num_rows()>0



 ##################################################################### this is the Filelist-Data-section
		$pgnumber = $FileOffset/$LinesPerPage;                             # actual pagenumber
                $pgnumbermax = intval($RecordCount->f("FileCount")/$LinesPerPage); # highest pagenumber
                $printdiropen=true;
                $Counter=0;
		while($FileList->next_record()) {

		if ($Counter==0) {       #### First print CD-Info at the top of the page (and only once)
                ?>
				<img border="0" src="logo/logomed.png"><br><br>
               <table cellpadding=3 width=100%>
               <tr><td colspan=6><h1>Browse directory structure</h1></td></tr>
	       <tr><td colspan=7 height=20px></td></tr>
	       <tr class="CDInfoLine2"><td colspan=3><h2><b>Info about this CD:</b></h2></td><td colspan=2 align=right><?if ($Access[ChangeCDinfo]) { ?><input type="button" name="changecdinfo" value="Change CD-Properties" onclick="catpopup('cdinfo.php?Action=Edit&CDID=<?=$ID?>')"><? } ?></td><td align=left><form action="browseinit.php?BrowseBy=CD&ID=<?=$ID?>" method="post"><input type="submit" name="filebrowsesubmit" value="Browse through Files"></form></td></tr>
	           <tr class="CDInfoLine0"><td><b>Inventary-Nr.:</b></td><td><? if ($FileList->f("CDNumber")=="" || $FileList->f("CDNumber")=="0") echo("Not set"); else echo($FileList->f("CDNumber"));?></td><td><b>Category:</b></td><td><? if ($GetCDCatname->f("CategoryName")=="" || $GetCDCatname->f("CategoryName")=="0") echo("Main Category"); else echo($GetCDCatname->f("CategoryName"));?></td><td><b>Name:</b></td><td><?=$FileList->f("CDLabel")?></td></tr>
               <tr class="CDInfoLine1"><td><b>AddedDate:</b></td><td><?=$FileList->f("CDAddedDate")?></td><td><b>Created:</b></td><td><?=$FileList->f("CDCreated")?></td><td><b>Description:</b></td><td><?if($FileList->f("Description")!="") echo $FileList->f("Description"); else echo "not set";?></td></tr>
               <tr class="CDInfoLine0"><td><b>Size (bytes):</b></td><td><?=number_format($FileList->f("CDsize"),0,$decpoint,$comma)?></td><td><b>#Files</b></td><td><?=number_format($FileList->f("NrFiles"),0,$decpoint,$comma)?></td><td><b>#SubDirs</b></td><td><?=number_format($FileList->f("NrSubDirs"),0,$decpoint,$comma)?></td></tr>
				<tr class="CDInfoLine2"><td ><h2><b>Lend state:</b></h2></td><td colspan="4" align=left><img width=32px,height=32px BORDER=0 src="showicon.php?type=<?echo brows_lend_disp($ID, icon);?>"></td><td>
				<? if (brows_lend_disp($ID, state)) { ##if this media has been lent
				?>
				<input type=button value="got back" name="modifylendbutton" onClick="popupvar('adrlendmodify.php?cdid=<?=$ID?>&dellend=true',760,500)">
                <?
				} ###of if(brows.....
				else {
				?>
				<input type=button value="lend out" name="modifylendbutton" onClick="popupvar('adresses.php?cdid=<?=$ID?>&addlend=true',760,500)">
                <?
				} ###else of if(brows.....

				?></td></tr>
			   <tr><td></td></tr>
               </table><br>
	       <b>Page <?=($FileOffset/$LinesPerPage+1)?> of <?=ceil($RecordCount->f("FileCount")/$LinesPerPage)?></b>
               <table width=100% CELLPADDING=2>
               <tr class="ListHeader"><td  width=45px><b>Type</b></td><td  ><b>Size</b></td><td  ><b>Date Time</b></td><td  ><b>Directory</b></td><td  ><b>File Name</b></td><td  ><b>File Label</b></td>
               </tr>

			<tr class="DirUpLine" onmouseover="this.className='MouseOverRow';" onmouseout="this.className='DirUpLine';" >

			<td colspan=6 height=36px width=32px><a href="<?=$_SERVER["PHP_SELF"]?>?ID=<?=$ID?>&BrowseDir=<?=$DirUp?>">Up one Directory-Level (to <?=" ".$DirUp?>)</a></td></tr>

	       <?
		} ###of if ($Counter==0) and End of CD-Info on top of page

		############################################################This is the Fileline Section
			$Param = "ID=$ID&BrowseDir=$BrowseDir";
			$Counter++;
			$exttmp=explode(".",$FileList->f("Filename"));
			if (count($exttmp)>1) $ext=strtolower($exttmp[count($exttmp)-1]); else $ext=""; ##   calculate extension for iconview


			$FilesizeTemp=number_format($FileList->f("Filesize"),0,$decpoint,$comma);

                        if ($printdiropen) {
                           $printdiropen=false; ?>
						   <tr class="DirOpenLine" onmouseover="this.className='MouseOverRow';" onmouseout="this.className='DirOpenLine';" >
                           <td align=left><img width=32px height=32px BORDER=0 src="showicon.php?type=diropen"></td><td colspan=6 align=left><?echo(" <b><i>(Current Directory: $BrowseDir)</i></b>");?></td></tr>
                           <?              } ?>
						   <tr class="FileLine<?echo(strval($Counter%2));?>" onmouseover="this.className='MouseOverRow';" onmouseout="this.className='FileLine<?echo(strval($Counter%2));?>';" >
                           <td height=36px align=right>
                           <? if($FileList->f("Filetype")=="d") {
                                    if (strlen($BrowseDir)>1) $LinkBrowseDir=$BrowseDir ."/". $FileList->f("Filename"); else $LinkBrowseDir=$BrowseDir . $FileList->f("Filename"); #Calculate Links for Directory-Navigation
                                    if ($FileList->f("LinkTarget")!="") $LinkBrowseDir=$FileList->f("LinkTarget");
                                       ?>
                                       <a href="<?=$_SERVER["PHP_SELF"]?>?ID=<?=$FileList->f("CDID")?>&BrowseDir=<?=$LinkBrowseDir?>"<?if ($FileList->f("LinkTarget")!="") echo(" title=\"LINK to ".$FileList->f("LinkTarget")."\"><img width=32px,height=32px BORDER=0 src=\"showicon.php?type=dirlink\">"); else echo (" title=\"descend to: ".$LinkBrowseDir."\"><img width=32px,height=32px BORDER=0 src=\"showicon.php?type=dir\">");?></a>
                                        <? }
                                    else { # now lets specify the File-Icons
                                       ?>
                                       <img width=32px height=32px BORDER=0 src="<? if ($FileList->f("LinkTarget")!="") echo ("showicon.php?type=filelink\" title=\"Link to: " .$FileList->f("LinkTarget")."\">"); else echo ("showicon.php?ext=$ext\">");?>
                                       <?
                                    } #of else

                                    ?></td><td align=right><?=$FilesizeTemp?></td><td><?=$FileList->f("FileDatetime")?></td><td><?=$FileList->f("SubDir")?></td><td><a title="List info about: <?=$FileList->f("Filename")?>" href="javascript:catpopup('fileinfo.php?FileID=<?=$FileList->f("FileID")?>')"><?=$FileList->f("Filename")?></a></td><td><?=$FileList->f("FileLabel")?></td>
                                    </tr>
                                    <?
                }  ##of while
########################################################################this is the Page-Linklist section
require("./pagenav.php");
?>
</table>
<?
	}

	if ($FileList->num_rows()==0) {
?>
<table width=100% CELLPADDING=2>
<tr class="ListHeader"><td  ><b>Type</b></td><td  ><b>Size</b></td><td  ><b>Date Time</b></td><td  ><b>Directory</b></td><td  ><b>File Name</b></td><td  ><b>File Label</b></td>
</tr>
<? if ($BrowseDir!="/") { ?>
		<tr class="DirUpLine"><td colspan=6><a href="<?=$_SERVER["PHP_SELF"]?>?ID=<?=$ID?>&BrowseDir=<?=$DirUp?>">Up one Directory-Level (to <?=" ".$DirUp?>)</a></td></tr>
                <tr><td colspan=6 align=left><br><div class="Alert">EMPTY DIRECTORY</div></td></tr>
<?      } else { ?>
<tr><td colspan=6 align=left><br><div class="Alert">No Records Found</div></td></tr>
<?             } ?>
</table>
<?
	}
?>
<?
require($Footer);
?>
Return current item: PHPmyCDMouse