<?php
if (!defined('IS_DEDI')) die();
include_once($cfg_dedi['dedi_path'].'inc/inc.init_external.php');
include $cfg_dedi['dedi_path'] .'inc/fnc.type_common.php';
?>
<html><head>
 <?php echo '<meta http-equiv="content-type" content="text/html; charset='.$lang_charset.'">'."\n"; ?>
<title>Image Link</title>
<style type="text/css">
<!--
body {font-family:Verdana, Arial, sans-serif; font-size: 12px;}
-->
</style>
</head>
<body bgcolor="white">

<?php
/*
 * @Return array [$i]['id'] - idupload from table dedi_upload
 *               [$i]['dirname'] - full directory relative from $dedi_client['upl_path']
 *               [$i]['filename'] - filename
 *               [$i]['titel'] - title from filebrowser titelfield
 *               [$i]['name'] = contract of dirname, filename and (optionally if not empty) titel
 */
$allfiles = _type_get_files($filetypes , $folders, $subfolders);
if (is_array($allfiles)) {
	foreach($allfiles as $a) {
		$b = substr($a['dirname'],0,-1);
		$filetree[$b][$a['id']] = $a;
	}
}
unset($allfiles);
// --------------------------------------------------------------------------------
// Kopflinks
$arr_folders = split('/',$dir);
$prev_folder = '';
echo '<a href="'.$cfg_client['htmlpath'].$cfg_client['contentfile'] ."?popup=browseimage&view=edit&filetypes=$filetypes&folders=$folders&subfolders=$subfolders&".$sess->name.'='.$sess->id.'"><img hspace="2" src="'.$cfg_dedi['dedi_html_path'].'tpl/'.$cfg_dedi['skin'].'/img/but_folder.gif" alt="go to" border="0">media</a><br>',"\n";
if ($dir != '') {
	for ($i=0;$i<count($arr_folders); $i++){
		//echo "$i ..$arr_folders[$i]..$prev_folder $arr_folders[$i]<br>\n";
		for ($x=0;$x<=$i;$x++) echo "&nbsp;";
		if ($i==count($arr_folders)-1){echo '<img hspace="2" src="'.$cfg_dedi['dedi_html_path'].'tpl/'.$cfg_dedi['skin'].'/img/but_folder.gif" border="0" alt="showing..."><b>', $arr_folders[$i], "</b><br>\n";}
		else {echo '<a href="'.$cfg_client['htmlpath'].$cfg_client['contentfile'] ."?".$sess->name.'='.$sess->id."&popup=browseimage&view=edit&filetypes=$filetypes&folders=$folders&subfolders=$subfolders&dir=".urlencode(ereg_replace("^/","","$prev_folder/$arr_folders[$i]")).'"><img hspace="2" src="'.$cfg_dedi['dedi_html_path'].'tpl/'.$cfg_dedi['skin'].'/img/but_folder.gif" border="0" alt="go to">', $arr_folders[$i], "</a><br>\n";}
       		$prev_folder = "$prev_folder/$arr_folders[$i]";
	}
}

// Unterordner
$folderlst = _type_get_folders($folders,$subfolders);
if(is_array($folderlst)) {
	foreach ($folderlst as $folder) {
		$folder['dirname'] = substr($folder['dirname'],0,-1);
		if(preg_match("/^".str_replace('/','\/',$dir)."\/?[^\/]+$/i",$folder['dirname'])) {
			echo '&nbsp;&nbsp;<a href="'.$cfg_client['htmlpath'].$cfg_client['contentfile'] ."?".$sess->name.'='.$sess->id."&popup=browseimage&view=edit&filetypes=$filetypes&folders=$folders&subfolders=$subfolders&dir=".urlencode(ereg_replace("/+","/",$folder['dirname'])).'">';
			printf("<img hspace=\"2\" src=\"".$cfg_dedi['dedi_html_path'].'tpl/'.$cfg_dedi['skin']."/img/but_folder_off2.gif\" alt=\"expand\" border=\"0\">%s </a><br>\n",preg_replace("/^.*\/([^\/]+)$/","\\1",$folder['dirname']));
		}
	}
}

// Files anzeigen
if(is_array($filetree[$dir])) {
	foreach($filetree[$dir] as $file) {
		$ext = substr(strrchr($file['filename'],'.'),1);
		echo "&nbsp;&nbsp;&nbsp;<img hspace=\"2\" src=\"".$cfg_dedi['dedi_html_path'].'tpl/'.$cfg_dedi['skin']."/img/file_icons/$ext.gif\" alt=\"\" border=\"0\">\n";
		$path = $cfg_client['upl_htmlpath'].$file['dirname'].$file['filename'];
//		$previewPath = preg_replace('/\.(\w+)$/','_dedi_thumb.\\1',$path);
		echo "<span style='cursor:pointer; font-size:10px; text-decoration:underline; color:blue' onClick=\"top.document.forms[0].elements['ImgUrl'].value='$path';";
		if($file['pic_thumb_width'] > 0){ $wh = $file['pic_thumb_width'].",".$file['pic_thumb_height']; $tn = preg_replace('/\.(\w+)$/','_dedi_thumb.\\1',$path); }
		else { $wh = $file['pic_width'].",".$file['pic_height']; $tn = "";};
		echo "top.showPreview($wh,'$tn');\">".$file['filename']."</span><br>";
	}
}
?>
</body>
</html>