<?php $this->loadCss('/admin/media/css/filemanager.css'); ?>
<?php $this->loadJavascript('/admin/media/js/utils.js'); ?>
<?php $this->loadJavascript('/admin/media/js/prototype.js'); ?>
<?php $this->loadJavascript('/admin/media/js/scriptaculous/global.js'); ?>
<?php $this->loadJavascript('/admin/media/js/scriptaculous/scriptaculous.js'); ?>
<?php $this->loadJavascript('/admin/media/js/scriptaculous/effects.js'); ?>
<?php $this->loadJavascript('/admin/media/js/tinymce/tiny_mce_popup.js'); ?>

<script type="text/javascript">
<!--
function init() {
    var allLinks = document.getElementsByTagName("link");
    allLinks[0].removeAttribute("href");
}
/*
old method
*/
function setFilenameAndClose(file) {
    var win = tinyMCE.getWindowArg("window");
    // insert information now
    win.document.getElementById(tinyMCE.getWindowArg("input")).value = baseUrl + file;

    // show preview
    win.showPreviewImage(win.document.getElementById(tinyMCE.getWindowArg("input")).value, false);

    // for image browsers: update image dimensions
    if (win.getImageData) {
        win.getImageData();
    }
    win.tinyMCE.setWindowArg('editor_id','mce_editor_0');
    // close popup window
    tinyMCEPopup.close();
}

var FileBrowserDialogue = {
    init : function () {
        // Here goes your code for setting your custom things onLoad.
    },
    setFilenameAndClose : function (file) {
        //var URL = document.my_form.my_field.value;
        var win = tinyMCEPopup.getWindowArg("window");

        // insert information now
        win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = baseUrl + file;

        // for image browsers: update image dimensions
        if (win.ImageDialog && win.ImageDialog.getImageData) win.ImageDialog.getImageData();
        if (win.ImageDialog && win.ImageDialog.showPreviewImage) win.ImageDialog.showPreviewImage(file);

        // close popup window
        tinyMCEPopup.close();
    }
}

-->
</script>
<div id="filemanager">
	<?php echo $form->start(); ?>
   <fieldset id="upload">
      <legend><?php echo translateAdmin('Carregar ficheiro');?></legend>

      <label><?php echo translateAdmin('Ficheiro');?>: </label>
      <?php echo $form->ficheiro; ?>
      <?php echo $form->submit; ?>
      <?php if ($form->ficheiro->getErrorMessage()): ?><div class="error"><?php echo $form->ficheiro->getErrorMessage(); ?></div><?php endif; ?>
   </fieldset>
   <?php echo $form->end(); ?>

   <fieldset id="dirs">
      <legend><?php echo translateAdmin('Pastas');?></legend>
      <div class="block">
         <?php if ($parent != ''): ?>
         <div><a href="<?php echo $this->link('/filemanager/browse/section/image/', 'path=' . $parent); ?>" class="folder_link">..</a></div>
         <?php endif; ?>
         <?php foreach ($dirs as $dir): ?>
         <?php if (strpos($dir, '.') !== 0 ): ?>
         <div><a href="<?php echo $this->link('/filemanager/browse/section/image/', 'path=' . $path . ($path != '/' ? '/' : '') .$dir); ?>" class="folder_link"><?php echo $dir ?></a> <a href="<?php echo $this->link('/filemanager/deletefolder/section/image/', 'path=' . $path . ($path != '/' ? '/' : '') .$dir); ?>" onclick="javascript:return confirm('<?php echo translateAdmin('Tem a certeza que deseja remover a pasta seleccionada?');?>');">[<?php echo translateAdmin('remover');?>]</a></div>
         <?php endif; ?>
         <?php endforeach; ?>
      </div>
   </fieldset>

   <fieldset id="files">
      <legend><?php echo $relative_path; ?></legend>
      <div class="block">
         <?php foreach ($files as $file): ?>
         <?php
         	$ext = explode(".", $file['name']);
         	$ext = end($ext);?>
         <div class="image">
         	<table align="center" width="100%">
         		<tr>
         		<td colspan="2" width="100%" align="center" valign="middle" height="100px">
         			<a href="#" onclick="FileBrowserDialogue.setFilenameAndClose('<?php echo $base_path . $relative_path . '/' . $file['name']; ?>');">
	            <?php if (file_exists($full_path . '/.thumbnails/' . $file['name'])): ?>
	            <img src="<?php echo $baseUrl . $base_path . $relative_path . '/.thumbnails/' . $file['name']; ?>" alt="<?php echo $file['name']; ?>" title="<?php echo $file['name']; ?>" border="0" />
	            <?php else: ?>
	            <?php if (file_exists(WWW_PATH.'/admin/media/images/icons/32/'.$ext.'.gif')): ?>
	                <img src="<?php echo $baseUrl . '/admin/media/images/icons/32/'. $ext .'.gif'; ?>" alt="<?php echo $file['name']; ?>" title="<?php echo $file['name']; ?>" border="0" width="40px" height="40px"/>
	                <?php else:?>
	                <img src="<?php echo $baseUrl . '/admin/media/images/icons/32/default.icon.gif'; ?>" alt="<?php echo $file['name']; ?>" title="<?php echo $file['name']; ?>" border="0"  width="40px" height="40px"/>
	            <?php endif; ?>
	            <?php endif; ?>
	            </a>
         		</td>
         		</tr>
            	<tr>
            		<td width="50%" align="left">
            		<a href="<?php echo $this->link('/filemanager/deletefiles/section/image/', 'path=' . $path . '&file=' . $file['name']); ?>" onclick="javascript:return confirm('<?php echo translateAdmin('Tem a certeza que deseja remover a imagem seleccionada?');?>');" class="deletelink" title="<?php echo translateAdmin('Remover');?>">&nbsp;&nbsp;&nbsp;</a>
            		</td>
            	</tr>
         	 </table>
         </div>
            <?php endforeach; ?>

      </div>
   </fieldset>
	      <?php echo $form_pasta->start(); ?>
   <fieldset id="uploadPasta">
      <legend><?php echo translateAdmin('Criar Pasta');?></legend>

      <label><?php echo translateAdmin('Pasta');?>: </label>
      <?php echo $form_pasta->pasta; ?>
      <?php echo $form_pasta->submit; ?>
      <?php if ($form_pasta->pasta->getErrorMessage()): ?><div class="error"><?php echo $form_pasta->pasta->getErrorMessage(); ?></div><?php endif; ?>
   </fieldset>
   <?php echo $form_pasta->end(); ?>
</div>

