<?php
/**
 * appRain CMF
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Team. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 *
 * Official Website
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/docs
 */
 ?>
<input id="file_upload"  name="file_upload" type="text" />
<?php App::Helper('Toolbar')->setTitle($this->__("File Manager"))->setBtnFilemanagerSrcBox($srcstr)->setBtnCustomHTML('')->Render(array('code'=>'filemanager_top')); ?>

<script type="text/javascript">
    jQuery(document).ready(function() {
        jQuery('#file_upload').uploadify({
          'uploader'  : siteInfo.baseUrl + '/addons/uploadify/uploadify.swf',
          'script'    : '<?php echo $this->baseUrl('/common/batchupload');?>',
          'cancelImg' : siteInfo.baseUrl + '/addons/uploadify/cancel.png',
          'multi'     : true,
          'auto'      : true,
          'onAllComplete' 	: function(event,data)
                              {
                                alert(data.filesUploaded + ' files uploaded successfully!');
                                window.location = "";
                              }
          });
    });
</script>

<?php
    if( !empty($file_list['data']))
    {
        foreach( $file_list['data'] as $key => $val )
        {
            $file_path = $this->get_config("filemanager_path") . "/{$val['name']}";

            if( App::Load("Helper/Utility")->is_image( $val['name'] ))
            {
                $img_path = $this->get_config("filemanager_path") . "/{$val['name']}";
            }
            else
            {
                $img_path = $this->basedir("/images/admin/file.gif");
            }

            if( App::Load("Helper/Utility")->is_image( $val['name'] ))
            {
                $optimizepath = App::Load("Helper/Html")->inputTag("file",$this->baseurl('/common/get_image/' . base64_encode( $file_path) . '/50/fix'),array("style"=>"width: 150px; padding: 5px; border: 1px solid #CECECE"));
            }
            else
            {
                $optimizepath = App::Load("Helper/Html")->inputTag("file",$this->baseurl('/common/download/' . base64_encode( $file_path)),array("style"=>"width: 150px; padding: 5px; border: 1px solid #CECECE"));
            }

            App::Module('DataGrid')->addRow(
                App::Load("Helper/Html")->linkTag($this->baseurl('/common/download/' . base64_encode( $file_path)),App::Load("Helper/Html")->imgDTag($img_path,"/50/fix")),
                App::Load("Helper/Html")->inputTag("filename",$val['name'],array("style"=>"width: 150px; padding: 5px; border: 1px solid #CECECE")),
                App::Load("Helper/Html")->inputTag("filepath",$this->baseurl("/{$file_path}"),array("style"=>"width: 150px; padding: 5px; border: 1px solid #CECECE")),
                $optimizepath,
                App::Load("Helper/Html")->linkTag($this->baseurl('/admin/filemanager/delete/' . base64_encode( $val['name'])),App::Load("Helper/Html")->imgTag($this->baseurl('/images/admin/remove.gif')),array('class'=>'confirm-link'))
            );
        }
        App::Module('DataGrid')->setHeader(array('Download','File Name', 'Direct Link', 'Optimized Link','Options'))
                               ->setFooter($file_list['paging_str'])
                               ->Render();
    }
    else
    {
        echo $this->callElement('default/tools/message', array('caption' =>'Message','type' => 'message', 'message' => 'No fime information found.'));
    }
?>

<?php echo App::Helper('Toolbar')->setBtnBack()->Render(array('code'=>'filemanager_bottom'));?>
