<?php
# le rep des images
$current_dir = REP_IMG;
# domaine
$domaine=URL_DU_SITE;
$_PX_config['manager_path'] = $current_dir;
$rel_url_files=ereg_replace("http://","",URL_DU_SITE);
include_once (ADD_PATH_ADMIN.'lib_partage/lib.image.php');
function nav_pop_xmedia($var){
	if(empty($var)) $var='xmedia_edit.php';
	$list=array('xmedia_edit.php'=>DOCUMENTS_NEW,'xmedia_light.php'=>DOCUMENTS_TS); //,'xmedia_custom_img.php'=>CUSTOM_IMG);

	print '<table id="nav_xmedia">'
	 	.'<tr>';

	while ($r=each($list))
		if ($var==(ereg_replace("\..*",'',$r['key']))) print '<td align="center">'.'<a href="'.URL_ADMIN.'xmedia_full.php?nav='.ereg_replace("\..*",'',$r['key']).'" style="color: #000000; text-decoration: none;"'.'"><div>'.$r['value'].'</div></a>'.'</td>';
		else print '<td align="center">'.'<a href="'.URL_ADMIN.'xmedia_full.php?nav='.ereg_replace("\..*",'',$r['key']).'" style="color: #000000; text-decoration: none;"><div id="select_div">'.$r['value'].'</div></a>'.'</td>';

	print '</tr>'
		.'</table>';
}
function isFileSafe($file_name, $file_data =''){
    if (preg_match('/[^A-Za-z0-9\-\_\.]/', $file_name)) return false;
    if (!preg_match('/\.(png|jpg|jpeg|gif|bmp|psd|tif|aiff|asf|avi|bz2|css|doc|eps|gz|htm|mid|mov|mp3|mpg|ogg|pdf|ppt|ps|qt|ra|ram|rm|rtf|sdd|sdw|sit|sxi|sxw|swf|tgz|txt|wav|xls|xml|wmv|zip)$/i', $file_name)) return false;
    return true;
}
function isImage($file_name){
    if (preg_match('/\.(png|jpg|gif|jpeg)$/i',$file_name)) return true;
    return false;
}
function getParentDir($current_dir){
    if (preg_match('#(.*/)*([^/])+/$#i',$current_dir, $match)) return $match[1];
    return '';
}
function textField($id, $size, $max=0, $default='', $tabindex='', $html='') {
	$res = '<input type="text" size="'.$size
	   .'" name="'.$id.'" id="'.$id.'" ';
	$res .= ($max != 0) ? 'maxlength="'.$max.'" ' : '';
	$res .= ($tabindex != '') ? 'tabindex="'.$tabindex.'" ' : '';
	$res .= ($default != '') ?
	   'value="'.htmlspecialchars($default).'" ' : '';
	$res .= $html;
	$res .= ' />';
	return $res;
}
// function size_img // retourn contenu size. // $mode >> si true return array($siz)
function size_img($is_image,$is_file,$current_dir,$name,$mode=false){
    if ($is_image) {
        $siz = @getimagesize(ADD_PATH_ADMIN.$current_dir.$name);
	if ($siz !== false ) {
            ## HTML format
            $file_size = '<strong>'.SIZE_TXT.'</strong>: '.$siz[3];
        } elseif ($siz !== false) {
            ## wiki format
            $file_size = '<strong>'.SIZE_TXT.'</strong>: '.$siz[0].'x'.$siz[1];
        }
    } elseif ($is_file) {
        $file_size = '<strong>'.FILE_SIZE.'</strong>:'.' '.(filesize('../'.$current_dir.$name)/1000).' Ko';
    }
    if(!$mode) return $file_size;
    elseif(isset($siz)) return $siz;
}
function creat_img_mini($dir='', $file, $type='', $widht, $height){
	if (tep_not_null($type))  $thumb = ADD_PATH_ADMIN.REP_IMG.'thumb/'.md5(REP_IMG.$dir.$file.$type).'.jpg';
	else $thumb = ADD_PATH_ADMIN.REP_IMG.'thumb/'.md5(REP_IMG.$dir.$file).'.jpg';
	@unlink($thumb);
	if ( (!empty($widht)) AND (!empty($height)) ) $msg=cropImg(ADD_PATH_ADMIN.REP_IMG.$dir.$file, $thumb, $widht, $height);
	elseif ( !empty($height) )  $msg=cropImg(ADD_PATH_ADMIN.REP_IMG.$dir.$file, $thumb, '', $height);
	calibre_droit_file($thumb);
	return $thumb;
}

$env  = (isset($_GET['env'])) ? $_GET['env'] : 1;
// /**
//  * for the moment the logic is here, completely based on the work done in
//  * dotclear with extension to almost all the kind of files, but will need
//  * to move it into classes at some point.
//  */
$px_gd_version = gd_version();
$is_writable = false;
$is_dir = true;
$up_dir="../";
// set the current dir and mode from the session if info available
if (empty($_REQUEST['dir'])) {
	if (!empty($current_dir)) {
		## the current dir is coming from the session,
		## set the $env from it or set it to 1

		## we need to ensure a "correct" request URI to work with the lum class
		if ('.php' == substr($_SERVER['REQUEST_URI'], strlen($_SERVER['REQUEST_URI'])-4, 4))$_SERVER['REQUEST_URI'] .= '?';

		$_SERVER['REQUEST_URI'] = str_replace('?','?dir='.$current_dir.'&env='.$env.'&',$_SERVER['REQUEST_URI']);
	}
} else {
   	 $current_dir = $_REQUEST['dir'];
}

if (!empty($current_dir)) {
	    $current_dir = str_replace('\\','',$current_dir);
	    $current_dir = str_replace('..','',$current_dir);
	    $current_dir = preg_replace( '#(/)+#', '/', $current_dir);
	    $current_dir = preg_replace( '#^(/)+#', '', $current_dir);
	    $current_dir = preg_replace( '#(/)+$#', '', $current_dir);

	    if (!empty($current_dir)) $current_dir .= '/';
} else {
	    $current_dir = 'img/';
}

/* check rights */
if (is_dir($up_dir.'/'.$current_dir)) {
    if (is_writable($up_dir.'/'.$current_dir)) {
        $is_writable = true;
	$is_dir=true;
    } else {
	echo "<p class='erreur'>".ERROR_WRITE.THE_FOLDER.$rel_url_files.$current_dir.NOT_WRITE."</p>";
    }
} else {
	echo ERROR.THE_FOLDER." $current_dir ".DOES_NOT_EXIST;
    $is_dir = false;
}

/* modification of the file */
if (!empty($_GET['file'])) {
    $px_file = str_replace('..','',$_GET['file']);
    $px_file=eregi_replace("img/","",$px_file);
    $px_file = preg_replace( '#(/)+#', '/', $px_file);
    $px_file = preg_replace( '#^(/)+#', '', $px_file);

    if (!file_exists(ADD_PATH_ADMIN.REP_IMG.$px_file)) {
	echo ERROR.THE_REQUESTED_FILE_DOES_NOT_EXIST.$px_file;
    } else {
        if (!empty($_GET['del']) && $_GET['del'] == 1) {
            if (@unlink(ADD_PATH_ADMIN.REP_IMG.$px_file) === false) echo ERROR.IMPOSSIBLE_TO_DELETE_THE_FILE;
            else {
                @unlink(ADD_PATH_ADMIN.REP_IMG.'/thumb/'.md5($px_file.'xmedia_navi').'.jpg');
		echo FILE_DELETED_WITH_SUCCESS;
                header('Location: '.substr($_SERVER['REQUEST_URI'],0, strpos('?',$_SERVER['REQUEST_URI'])).'?dir='.rawurlencode($current_dir).'&mode='.$mode);
                exit();
            }
        } elseif(!empty($_GET['thumb']) && $_GET['thumb'] == 1) {
		creat_img_mini('', $px_file, 'xmedia_navi', 150, 100);
       }
    }
}

/* Upload of the file */
if ($is_writable && !empty($_FILES['up_file'])) {
    $tmp_file = $_FILES['up_file']['tmp_name'];
    $file_name = $_FILES['up_file']['name'];

    if (version_compare(phpversion(),'4.2.0','>=')) {
        $upd_error = $_FILES['up_file']['error'];
    } else {
        $upd_error = 0;
    }

    if ($upd_error != 0) {
        switch ($upd_error) {
        case 1:
        case 2:
	echo ERROR.THE_SIZE_OF_THE_FILE_EXCESS_THE_MAXIMUM_SIZE;
           break;
        case 3:
	echo ERROR.THE_FILE_NOT_FULLY_TRANFERED;
            break;
        case 4:
		echo ERROR.NO_FILE;
           break;
        }
    } elseif(!file_exists($tmp_file)) {
	echo ERROR.NO_FILE;
    } elseif(filesize($tmp_file) > MAX_UPLOAD_SIZE) {
	echo ERROR.THE_SIZE_OF_THE_FILE_EXCESS_THE_MAXIMUM_SIZE;
    } else {
        $file_name = preg_replace( '#(\s+)#', '_', $file_name);
        if(!isFileSafe($file_name)) {
	echo ERROR.INVALID_TYPE_OR_NAME_FILE;

        } else {
		$cu=eregi_replace(REP_IMG,"",$current_dir);
            if (copy($tmp_file,ADD_PATH_ADMIN.REP_IMG.$cu.$file_name)) {
		tep_file(ADD_PATH_ADMIN.REP_IMG.$cu.$file_name);
		if (!isset($widht)) $widht='';
		if (!isset($height)) $height='';
		creat_img_mini($cu, $file_name, 'xmedia_navi', $widht, $height);
            } else {
		echo ERROR_OCCURED_DURING_THE_TRANSFER;
            }
        }
    }
}


/*------------------------   Repertoire -------------------------------  */

/* Create a subfolder */
if ($is_writable && !empty($_POST['create'])
    ) {
    if (!empty($_POST['new_folder'])) {
        $new_dir = trim($_POST['new_folder']);
        if (preg_match('/[^A-Za-z0-9\-\_]/', $new_dir) or ($new_dir == 'thumb')) echo ERROR.INVALID_FOLDER_NAME;
        else {
            if ( tep_mkdir($up_dir.'/'.$current_dir.$new_dir)) {
               header('Location: '.$_PHP_SELF.'?dir='.$current_dir.$new_dir.'&mode='.$mode);
                exit();
            } else echo ERROR.IMPOSSIBLE_CREATE_THE_FOLDER;
        }
    }
}

/* Delete a subfolder */
if ($is_writable && !empty($_REQUEST['delfolder']) ) {

    $can_delete = true;
    $can_delete = (strlen($current_dir) != 0) ? true : false;

    if ($is_dir && $can_delete) {
        $D = dir($up_dir.'/'.$current_dir);
        while(false !== ($entry = $D->read())) {
            if ($entry != '.' && $entry != '..' && $entry != '.htaccess' && $entry != '.htpasswd') {
                 $can_delete = false;
                 break;
            }
        }
        $D->close();
    }

    if ($can_delete) {
        if (file_exists($up_dir.'/'.$current_dir.'.htaccess'))
            @unlink($up_dir.'/'.$current_dir.'.htaccess');
        if (file_exists($up_dir.'/'.$current_dir.'.htpasswd'))
            @unlink($up_dir.'/'.$current_dir.'.htpasswd');

        if (!rmdir($up_dir.'/'.$current_dir)) echo ERROR.IMPOSSIBLE_TO_DELETE_THE_FOLDER;
        else {
	echo SUCCES_DELETE_THIS_FOLDER;
            $dir = getParentDir($current_dir);
            if (empty($dir)) $dir = 'img/';
            header('Location: '.$_PHP_SELF.'?dir='.$dir.'&mode='.$mode);
            exit();
        }
    }
}

// function add_ ($destination_form,$current_dir){
function add_ ($destination_form,$current_dir,$is_dir,$up_dir,$px_gd_version,$env,$rel_url_files,$mode_pop){
?>
<div id="add_file" style="display:none;">
	<form enctype="multipart/form-data" action="<?php print URL_ADMIN ?>appel_fct.php?funct=include/lib/lib.xmedia.php&amp;act=upload&amp;sortie=&amp;vars=" method="post"  onsubmit="montre('ret_file_upload');montre('onload');add_link_nav2('ret_file_upload','#',''+document.getElementById('up_file').value+'', '')" target="myiframe">
	<fieldset><legend><?php   echo ADD_A_FILE_TO_THE_CURRENT_FOLDER ; ?></legend>
	<p><input type="radio" name="extract_zip" value="true" onclick="montre('extract_zip_name')"/><?php print EXTRACT_LEIZP ?><span id="extract_zip_name" style="display:none;"><nobr><input name="extract_zip_name"  type="text" /><?php print EXTRACT_LEIZP_NAME ?></nobr></span></p>
	<p><span class="nowrap">
			<label for="up_file"><?php  echo sprintf( CHOOSE_FILE, (MAX_UPLOAD_SIZE)/1000000 ); ?> </label>	<input name="up_file" id="up_file" type="file" value=""/><input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_UPLOAD_SIZE ?>" /><input type="hidden" name="mode" value="<?php echo $mode_pop; ?>" /><input type="hidden" name="env" value="<?php echo $env; ?>" /><input type="hidden" name="dir" value="<?php echo $current_dir; ?>" /><input id="bt_submit_up" class="submit" type="submit" value="<?php echo ADD_FILE; ?>" style="display:none"/>
	</span></p>
	</fieldset>
	</form>
	<script>/* Cache le bouton sii selection vide*/
		function surveille_bt_upload(){
		var up = document.getElementById('up_file');
		if (up == undefined) document.getElementById('bt_submit_up').style.display='none';
		if (up != undefined)  document.getElementById('bt_submit_up').style.display='inline';;
		}
	</script>
</div>
<div id="add_rep" style="display:none;">
	<form action='<?php print $destination_form ?>' method='POST'>
        <input type='hidden' name='dir' value='<?php echo $current_dir; ?>' />
        <input type='hidden' name='mode' value='<?php echo $mode_pop; ?>' />
        <p><span class="nowrap"><label for="new_folder" style="display:inline"><?php  echo CREATE_A_SUB_FOLDER; ?> </label><input type="text" maxlength="30" id="new_folder" name="new_folder" size="15"/><input name="create" type="submit" class="submit" value="<?php  echo CREATE; ?>" /></span></p>
        </form>
</div>
<iframe name="myiframe" id="myiframe" style="margin:0;padding:0;border:none;height:0;" onload="upload_ajax('vos_file','include/lib/lib.xmedia.php','media_',' \'<?php print $destination_form ?>\', \'<?php print $is_dir ?>\',\'<?php print $current_dir ?>\',\'<?php print $up_dir ?>\',\'<?php print gd_version() ?>\',\'<?php print $env ?>\',\'<?php print $rel_url_files ?>\',\'<?php print $mode_pop ?>\'  ');cache('onload');"></iframe>
<div id="ret_file_upload" style="display:none;">
 <!-- 	<a href="#" onclick="window.location.reload();"><?php print CLOSE ?></a> -->
	<a href="#" onclick="upload_ajax('vos_file','include/lib/lib.xmedia.php','media_','\'<?php print $destination_form ?>\', \'<?php print $is_dir ?>\',\'<?php print $current_dir ?>\',\'<?php print $up_dir ?>\',\'<?php print gd_version() ?>\',\'<?php print $env ?>\',\'<?php print $_PX_config ?>\',\'<?php print $rel_url_files ?>\',\'<?php print $mode_pop ?>\'  ')"><?php print CLOSE ?></a>
</div>
<?php
}
/* Cadre principal qui produit block doc */
function media_($destination_form,$is_dir,$current_dir,$up_dir,$px_gd_version,$env,$rel_url_files,$mode_pop=false){

	require_once (ADD_PATH_ADMIN.REP_LIB_PARTAGE .'class.lum.php');
	require_once (ADD_PATH_ADMIN.REP_LIB_PARTAGE.'lib.image.php');	/* appel force pour presen lors appel par ajax*/
// 	print '<style type="text/css"> @import url('.URL_DU_SITE.'admin/tempalte/'.THEME_ADMIN.'/css_content/xmeda.css)</style>';
	 print '<h2>'. YOUR_FILES.$mode_pop.'</h2>';
	 print '<div style="padding:5px;">';

	if($mode_pop !=false) define('MOD_POP','');
	/* Start populating the list of files and folders */
	$img_list = array();
	$rep_list = array();

	if ($is_dir) {
	    $D = dir($up_dir.'/'.$current_dir);
	    $i = 0;
	    $j = 0;
	    //Get the parent folder to go "up" one level.
		if (!eregi("^.?(".REP_IMG.").?$",$current_dir)) {
		$parent_dir = getParentDir($current_dir);
		if (empty($parent_dir)) $parent_dir = '/';
		$rep_list[$j]['url'] = $rel_url_files.'/'.$parent_dir;
		$rep_list[$j]['name'] = 'Parent folder';
		$rep_list[$j]['current_dir'] = $parent_dir;
		$rep_list[$j]['type'] = 'updir';
		$j++;
	    }
	    while(false !== ($entry = $D->read()))
	    {
		if($entry != '.' && $entry != '..' && $entry != '.htaccess' && $entry != '.htpasswd') {
		    if (!is_dir($up_dir.'/'.$current_dir.$entry)) {
			$img_list[$i]['url'] = $rel_url_files.'/'
			    .$current_dir.$entry;
			$img_list[$i]['name'] = $entry;
			$img_list[$i]['current_dir'] = $current_dir;
			$img_list[$i]['type'] = 'file';
			$i++;
		    } elseif ($entry != 'thumb') {
			$rep_list[$j]['url'] = $rel_url_files.'/'
			    .$current_dir.$entry;
			$rep_list[$j]['name'] = $entry;
			$rep_list[$j]['current_dir'] = $current_dir.$entry;
			$rep_list[$j]['type'] = 'dir';
			$j++;
		    }
		}
	    }
	    $D->close();
	}

	/* Line to display a file */
	function line_file($data,$i){
	    global $mode, $up_dir, $_PX_website_config, $m,$px_gd_version, $env, $destination_form;
	    // 4 kinds of entry: "up" folder, folder, image and normal file
	    // 2 modes: popup and normal
	    $is_dir = false;
	    $is_file = false;
	    $is_image = false;
	    $is_updir = false;
	    $url = $data['url'];
	    $name = $data['name'];
	    $current_dir = $data['current_dir'];

	    switch ($data['type']) {
	    case 'file':
		$is_image = isImage($name);
		$is_file = !$is_image;
		$ext = getFileExtension($name);
		break;
	    case 'dir':
		$is_dir = true;
		break;
	    case 'updir':
		$is_updir = true;
		break;
	    }
	    $res = ''; ## final string to be displayed.
	    ## contains the height/width of the image or the size of
	    ##  the file, nothing if an image and impossible to get the size
	    $create_thumb = ''; //link to create the thumbnail
	    $icons_dir = '/template/'.TEMPLATE_ADMIN.'/img/icons/';

	    if (_USER_PERSO__GRP<=2){
		if (!defined('MOD_POP')) $delete_link = '<a href="'.$destination_form.'?dir='.rawurlencode($current_dir).'&amp;file='.rawurlencode($current_dir.$name).'&amp;del=1&amp;mode='.$mode.'&amp;env='.$env.'" title="'.'Delete'.'" onclick="return window.confirm(\''. ALERT_DELETE_THIS_FOLDER.'\')"><img src="template/'.TEMPLATE_ADMIN.'/img/delete.png" alt="'.'Delete'.'" /></a>';
		elseif (defined('MOD_POP')) $delete_link = '<a href="'.$destination_form.'?nav=xmedia_light&dir='.rawurlencode($current_dir).'&amp;file='.rawurlencode($current_dir.$name).'&amp;del=1&amp;mode='.$mode.'&amp;env='.$env.'" title="'.'Delete'.'" class="lightwindow" onclick="return window.confirm(\''. ALERT_DELETE_THIS_FOLDER.'\'); init()"><img src="template/'.TEMPLATE_ADMIN.'/img/delete.png" alt="'.'Delete'.'" /></a>';
	    }else $delete_link='';
	## DEB MODULE TAGS
	    if ( (defined('PX_CONFIG_MODULE_TAGS'))AND (PX_CONFIG_MODULE_TAGS=='true') ) {
	     $delete_link.='<a href="#" onclick="'."{  montre('onload');".sprintf("upload_ajax('%1\$s','%2\$s','%3\$s','%4\$s');",'form_ajax_txt',ADD_PATH_ADMIN.CHEM_MODULES."tags/inc/lib/function.box_add_el_tag.inc","box_add_el_tag","\'".rawurlencode(str_replace(REP_IMG,'',$current_dir).$name)."\'")."cache_t('onload','150'); montre('backgd'); montre('form_ajax'); ".'}'.'">TAGS</a>';
	     }
	## FIN MODULE TAGS

	    if ($is_dir || $is_updir) {
		$slash = ($is_dir) ? '/' : '';
		if (!defined('MOD_POP')) $action_link = '<a href="'.$destination_form.'?dir='.$current_dir.$slash.'&amp;mode='.$mode.'">%s</a>';
		else $action_link = '<a href="'.$destination_form.'?nav=xmedia_light&dir='.$current_dir.$slash.'&amp;mode='.$mode.'">%s</a>';
	    } else {
		## call from the "normal" list of files page
		if (!defined('MOD_POP')) $action_link = '<a href="'.URL_DU_SITE.$current_dir.$name.'">%s</a>';
		else $action_link = '<a href="'.$destination_form.'?nav=xmedia_edit&dir='.$current_dir.$name.'&amp;mode='.$mode.'">%s</a>';
	    }
	    ## create the thumbnail link
	    if ($is_file || $is_image) {
		if (file_exists(ADD_PATH_ADMIN.REP_IMG.'thumb/'.md5($current_dir.$name.'xmedia_navi').'.jpg')) {
			$img = URL_DU_SITE.REP_IMG."thumb/".md5($current_dir.$name.'xmedia_navi').".jpg";
			## thumbnail exists
			if (!defined('MOD_POP')) $th="<a href=\"".URL_DU_SITE.$current_dir.$name."\"><img class=\"thumbnailicon\" src=\"".$img."\" alt=\"\" alt='thumbnail exists'/></a>";
			else $th="<a href=\"".$destination_form."?nav=xmedia_edit&amp;file=".$current_dir.$name."&amp;src=$img&amp;width=".$siz[0]."&amp;height=".$siz[1]."\"><img class=\"thumbnailicon\" src=\"".$img."\"  alt='thumbnail exists'/></a>";

		} elseif ($is_image && $px_gd_version ) {
			## image without thumbnail
			if (file_exists(CHEMIN_ABS.CHEMIN_ADMIN.$icons_dir.$ext.'-dist.png')) {
				$img = URL_ADMIN.$icons_dir.$ext.'-dist.png';
			} else {
				$img = URL_ADMIN.$icons_dir.'default-dist.png';
			}
			$i="<img class=\"thumbnailicon\" src=\"".$img."\" alt=\"\" />";
			if (!defined('MOD_POP')){
				$th="<a href=\"".URL_DU_SITE.$current_dir.$name."\"><img class=\"thumbnailicon\" src=\"".$img."\" alt=\"\" /></a>";
				$create_thumb = '<a href="'.$destination_form.'?dir='.rawurlencode($current_dir).'&amp;file='.rawurlencode($current_dir.$name).'&amp;thumb=1&amp;mode='.$mode.'&amp;env='.$env.'" title="'.CLIK_FOR_CREATE_THUMBAIL.'"><img src="'.URL_ADMIN.'template/'.TEMPLATE_ADMIN.'/img/ico_createthumb.png" alt="'.CLIK_FOR_CREATE_THUMBAIL.'" /></a> ';
			}else{
				$th="<a href=\"".$destination_form."?nav=xmedia_edit&amp;file=".$current_dir.$name."&amp;src=$img&amp;width=".$siz[0]."&amp;height=".$siz[1]."\"><img class=\"thumbnailicon\" src=\"".$img."\" alt=\"\" /></a>";
				$create_thumb = '<a href="'.$destination_form.'?nav=xmedia_light&amp;dir='.rawurlencode($current_dir).'&amp;file='.rawurlencode($current_dir.$name).'&amp;thumb=1&amp;mode='.$mode.'&amp;env='.$env.'" title="'.CLIK_FOR_CREATE_THUMBAIL.'"><img src="'.URL_ADMIN.'template/'.TEMPLATE_ADMIN.'/img/'.'ico_createthumb.png" alt="'.CLIK_FOR_CREATE_THUMBAIL.'" /></a>';
			}
		} else {
			    ## normal file
			    $ext = getFileExtension($name);
			    if (file_exists(CHEMIN_ABS.CHEMIN_ADMIN.$icons_dir.$ext.'-dist.png')) {
				$img = URL_ADMIN.$icons_dir.$ext.'-dist.png';
			} else {
				$img = URL_ADMIN.$icons_dir.'default-dist.png';
			    }
			    if (!defined('MOD_POP')) $th = "<a href=\"".URL_DU_SITE.$current_dir.$name."\"><img class=\"thumbnailicon\" src=\"$img\" alt=\"\" /></a>";
			    else $th = "<a href=\"".$destination_form."?nav=xmedia_edit&file=".$current_dir.$name."&amp;src=$img&amp;width=".@$siz[0]."&amp;height=".@$siz[1]."\"><img class=\"thumbnailicon\" src=\"$img\" alt=\"\" /></a>";
		}
		$res = '<div class="icon">'."\n".'<p class="legend action">'.$create_thumb.' '.$delete_link.'</p>'."\n".'<p class="icon">'.$th.'</p>'."\n".'<p class="legend">';
		if (!defined('MOD_POP')) $res .="<a href=\"".URL_DU_SITE.$current_dir.$name."\">$name</a>";
		else $res .="<a href=\"".URL_DU_SITE.$current_dir.$name."\">$name</a>";
		$res .='<br />'."\n".size_img($is_image,$is_file,$current_dir,$name,false).'</p>'."\n".'</div>'."\n";
	    } elseif ($is_dir || $is_updir) {
		$ico = ($is_dir) ? 'ico_folder.png' : 'ico_folder_up.png';
		$img = URL_ADMIN.'template/'.TEMPLATE_ADMIN.'/img/'.$ico;
		$th = sprintf($action_link,'<img class="thumbnailicon" src="'.$img.'" alt="" />');
		$res = '<div class="icon">'."\n".'<p class="icon">'.$th.'</p>'."\n".'<p class="legend">'.sprintf($action_link,$name).'</p>'."\n".'</div>'."\n";
	    }
	    return $res;
	}

	##  Display the files and folders
	$img_list = array_merge($rep_list, $img_list);
	$nbr_img=(defined('_USER_PERSO__NBR_BOX_XMEDIA'))?_USER_PERSO__NBR_BOX_XMEDIA:20;
	$objLum = new lum($env, 'line_file', $img_list, 0,$nbr_img );
// 	$objLum->htmlHeader = '<div class="spacer"> &nbsp; </div>';
// 	$objLum->htmlLineStart = '';
// 	$objLum->htmlColStart = '';
// 	$objLum->htmlColEnd = '';
// 	$objLum->htmlLineEnd = '';
// 	$objLum->htmlFooter = '<div class="spacer"> &nbsp; </div>';
// 	$objLum->htmlLinksStart = '<p class="small">';
// 	$objLum->htmlLinksEnd = '</p>';
// 	$objLum->htmlCurPgStart = '<strong>';
// 	$objLum->htmlCurPgEnd = '</strong>';
// 	$objLum->htmlPrev = '&laquo;'.PREVIOUS_PAGE;
// 	$objLum->htmlNext = '&raquo;'.NEXT_PAGE;
// 	$objLum->htmlPrevGrp = '...';
// 	$objLum->htmlNextGrp = '...';
// 	$objLum->htmlEmpty = '<div class="spacer"> &nbsp; </div><div class="icon"><p class="icon"><strong>'.NO_FILE_FOR_THE_MOMENT.'</strong></p></div><div class="spacer"> &nbsp; </div>';
// 	$objLum->htmlLinksLib = 'page(s):';
	if ($is_dir) {
	    $parent_dir = getParentDir($current_dir);
	    if (empty($parent_dir)) $parent_dir = '/';
	    echo '<p class="small">';
		if (!eregi("^.?(img)..?$",$current_dir)) {
	       if (!defined('MOD_POP')) echo '<a href="'.$destination_form.'?dir='.$parent_dir.'&amp;mode='.$mode.'" title="'.GO_ONE_FOLDER_UP.'"><img src="template/'.TEMPLATE_ADMIN.'/img/ico_folder_up_small.png" alt=" " /></a> ';
	       else  echo '<a href="'.$destination_form.'?nav=xmedia_light&dir='.$parent_dir.'&amp;mode='.$mode.'" title="'.GO_ONE_FOLDER_UP.'"><img src="template/'.TEMPLATE_ADMIN.'/img/ico_folder_up_small.png" alt=" " /></a> ';
	    }
	    printf(YOU_ARE_IN_THE_FOLDER.'<strong>%s</strong>',$current_dir).'</p>';
	   if (!defined('MOD_POP'))   echo $objLum->drawLinks($destination_form)."\n\n";
	   else echo $objLum->drawLinks($destination_form.'?nav=xmedia_light')."\n\n";
	    echo $objLum->drawPage()."\n\n";
	   if (!defined('MOD_POP'))   echo $objLum->drawLinks($destination_form)."\n\n";
	   else echo $objLum->drawLinks($destination_form.'?nav=xmedia_light')."\n\n";
	    echo '<p class="small">';
		if (!eregi("^.?(img)..?$",$current_dir)) {
		if (!defined('MOD_POP'))  echo '<a href="'.$destination_form.'?dir='.$parent_dir.'&amp;mode='.$mode.'" title="'.GO_ONE_FOLDER_UP.'"><img src="template/'.TEMPLATE_ADMIN.'/img/ico_folder_up_small.png" alt=" " /></a> ';
		else  echo '<a href="'.$destination_form.'?nav=xmedia_light&dir='.$parent_dir.'&amp;mode='.$mode.'" title="'.GO_ONE_FOLDER_UP.'"><img src="template/'.TEMPLATE_ADMIN.'/img/ico_folder_up_small.png" alt=" " /></a> ';
	    }
	    printf(YOU_ARE_IN_THE_FOLDER.'<strong>%s</strong>',$current_dir);
		if($current_dir !=REP_IMG){
		if (!defined('MOD_POP'))  echo ' <strong><a href="'.$destination_form.'?dir='.rawurlencode($current_dir).'&amp;delfolder=1&amp;mode='.$mode.'" '.'onclick="return window.confirm(\''.ALERT_DELETE_THIS_FOLDER.'\')" title="'.DELETE_THIS_FOLDER.'"><img src="template/'.TEMPLATE_ADMIN.'/img/delete.png" alt=" " /></a></strong>';
		else echo ' <strong><a href="'.$destination_form.'?nav=xmedia_light&dir='.rawurlencode($current_dir).'&amp;delfolder=1&amp;mode='.$mode.'" '.'onclick="return window.confirm(\''.ALERT_DELETE_THIS_FOLDER.'\')" title="'.DELETE_THIS_FOLDER.'"><img src="'.$icons_dir.'delete.png" alt=" " /></a></strong>';
	    }
	    echo '</p>';
	}
	 print '</div>'
 		.'<script>init();</script>';
}
?>