<?php
// param simple to print only the path
// param no_archive: to not print archive
// param sort: to sort
include_once('tiki-setup.php');
$nbe = 0;
$nbo = 0;
if (empty($_REQUEST['sort']))
	$_REQUEST['sort']='galleryId';
$query = "select * from tiki_files order by ".$_REQUEST['sort']." desc";
$result = $tikilib->query($query);
$path = $tikilib->get_preference('fgal_use_dir', '');
echo "<table>";
if (!isset($simple)) {
	echo "<tr><td>GalleryId</td><td>fileId</td><td>Name</td><td>User</td><td>Path</td></tr>";
}
while ($res = $result->fetchRow()) {
	if (!file_exists($path.$res['path'])) {
		if ($res['archiveId']) {
			if (isset($_REQUEST['no_archive']))
				continue;
		}
		echo "<tr>";
		$gal_info = $tikilib->get_file_gallery($res['galleryId']);
		if (isset($_REQUEST['simple'])) {
			echo "<td>".$res['path'].'</td>';
		} else {
			if ($gal_info['show_name'] == 'f')
				$res['name']=$res['filename'];
			echo "<td><a href=\"https://intranet.spanlink.com/tiki/tiki-list_file_gallery.php?galleryId=".$res['galleryId']."\">".$res['galleryId']."</a></td><td>".$res['fileId']."</td><td>".htmlentities($res['name'])."</td><td>".$res['lastModifUser']."</td><td>".$res['path']."</td>";
		}
		++$nbe;
		if ($res['archiveId']) {
			echo "<td>ARCHIVE</td>";
		} else {
			echo "<td></td>";
		}
		echo "</tr>\n";
	} else {
//		echo "OK -ID ".$res['fileId']."<br />";
		++$nbo;
	}
}
echo "Errors:$nbe, OK:$nbo<br />";
?>

