<?

$list = new iconlist($_GET['tabid']);

if ($_GET['q']) {
	$sys['criteria'] = $_GET['q'];
} else {
	$sys['criteria'] = $_POST['q'];
}


if (strlen(trim($sys['criteria'])) == 0) {
	//header("Location: ".glueURL(array("path"=>$str->safeJS($str->forURL($sys['path'])),"user"=>$str->safeJS($str->forURL($sys['user'])),"msg"=>"search"))."");
	//exit();
}




$sys['criteria'] = $str->fromHTML($sys['criteria']);



if ($sys['fromRoot']) {
	$sys['fullPath'] = $permissions['path'];
} else {
	$sys['fullPath'] = gluePath($permissions['path'], $sys['path']);
}


$searchpath = $sys['fullPath'];
$find = $sys['criteria'];


//get dir listing
$dirlist = $fm->getDirList($searchpath, array());

$dirlist = str_replace($searchpath, "", $dirlist);


//add * at the begining
if (substr($find, 0, 1) != "*") {
	$find = "*".$find;
}
//add * at the end
if (substr($find, -1) != "*") {
	$find .= "*";
}

//debug($dirlist);


//arrange data for icon listing
for ($i = 0 ; $i < sizeof($dirlist) ; $i++) {

	if (!in_array(basename($dirlist[$i]), $ignoreFiles) && my_fnmatch($find,strtolower(basename($dirlist[$i]))) == true && (strstr($dirlist[$i], $thumbsDirName) == false)){
		
			$fullPath = gluePath($searchpath, $dirlist[$i]);
			$dirname = $fm->dirname($dirlist[$i]);

			$data['name'] = $fm->basename($dirlist[$i]);
			$data['lcname'] = strtolower($data['name']);
			$data['input_value'] = $dirlist[$i];
			$data['mdate'] = filemtime($fullPath);

			//deleted from
			$data['filetypedescription'] = gluePath($sys['path'],"/",$dirname);
			
		if (is_dir($fullPath)) {
			$data['isdir'] = true;
			$data['size'] = $settings->config['compute_folder_size']?$fm->getDirSize($fullpath):0;
			$data['ext'] = "";
			$data['icon_img'] = "images/icons/filetypes/big/folder.gif";
			$data['thumb_img'] = "images/icons/filetypes/big/folder.gif";
			$data['list_img'] = "images/icons/filetypes/small/folder.gif";
			$data['filetype'] = "folder";
			$data['ondblclick'] = "";
		} else {
			$data['isdir'] = false;
			$data['size'] = filesize($fullPath);
			$extension = $fm->getExtension($data['name']);
			$data['ext'] = $extension;
			$fileinfo = $fm->fileTypeInfo($extension);
			//$data['filetypedescription'] = $fileinfo['description'];

			$data['icon_img'] = gluePath("images/icons/filetypes/big/",$fileinfo['icon']);
			$iconfolder = "images/icons/filetypes/big/";
			$data['thumb_img'] =  $img->icon($fullPath, 1, 1, gluePath($sys['path'],$dirname));
			$data['bigthumb'] = ((strstr($data['thumb_img'], '?'))?true:false);
			$data['list_img'] = gluePath("images/icons/filetypes/small/",$fileinfo['icon']);

			$data['filetype'] = $img_prefix.$fileinfo['type'];
			$data['ondblclick'] = "";
		}
		$list->setIcon($data);
	}

}

?>
<script>
tb = parent.AfianHandler['allTabs']['<?echo $_GET['tabid'];?>'];
if (tb != undefined) {
tb.removeAll();
}

<?
if (sizeof($list->icons) > 0) {

for ($i = 0 ; $i < sizeof($list->icons) ; $i++) {
	$list->drawIcon($list->icons[$i]);
}
?>

if (tb != undefined) {
tb.sortItems('name', 'desc');
tb.buildItems();
if (tb.active) {
tb.showItems();
}
}
<?}?>
if (tb != undefined) {
parent.cancelTimeOut(tb.id);
tb.countSelected = 0;
tb.hideHourGlass();
tb.browsed = true;
}
</script>
