<?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("src").value = file;
    tinyMCEPopup.close();
}

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

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

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

tinyMCEPopup.onInit.add(FileBrowserDialogue.init, FileBrowserDialogue);

-->
</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/file/', '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/file/', 'path=' .  $path . ($path != '/' ? '/' : '') .$dir); ?>" class="folder_link"><?php echo $dir ?></a>  <a href="<?php echo $this->link('/filemanager/deletefolder/section/file/', '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 $path; ?><?//= $relative_path; ?></legend>
      <div class="block">
			<table align="left" cellpadding="2" cellspacing="2" width="420px">


			<?php foreach ($files as $file): ?>
         	<?php
         	$ext = explode(".", $file['name']);
         	$ext = end($ext);?>
             <tr>
             	<td width="40px" valign="top">
             	<a href="#" onclick="FileBrowserDialogue.setFilenameAndClose('<?php echo $base_path . $relative_path . '/' . $file['name']; ?>');">
                 <?php if (file_exists(WWW_PATH.'/admin/media/images/icons/'.$ext.'.gif')): ?>
                <img src="<?php echo $baseUrl . '/admin/media/images/icons/'. $ext .'.gif'; ?>" alt="<?php echo $file['name']; ?>" title="<?php echo $file['name']; ?>" border="0" />
                <?php else:?>
                <img src="<?php echo $baseUrl . '/admin/media/images/icons/default.icon.gif'; ?>" alt="<?php echo $file['name']; ?>" title="<?php echo $file['name']; ?>" border="0" />
                <?php endif; ?>
                </a>
             	</td>
             	<td valign="middle" width="330px">
             	<a href="#" onclick="FileBrowserDialogue.setFilenameAndClose('<?php echo $base_path . $relative_path . '/' . $file['name']; ?>');"><?php echo $file['name']?></a>
             	</td>
                <td align="right" valign="top" width="40px">
                <a href="<?php echo $this->link('/filemanager/deletefiles/section/file/', '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');?>"></a>
                </td>
                </tr>
         <?php endforeach; ?>
         </table>
      </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>