<?php

// reload session encase they've just upgraded
$Auth->reloadSession();

// require login
$Auth->requireUser(WEB_ROOT . '/login.' . SITE_CONFIG_PAGE_EXTENSION);

// setup order by options
$orderByOptions = array();
$orderByOptions['order_by_filename_asc'] = 'Filename ASC';
$orderByOptions['order_by_filename_desc'] = 'Filename DESC';
$orderByOptions['order_by_uploaded_date_asc'] = 'Uploaded Date ASC';
$orderByOptions['order_by_uploaded_date_desc'] = 'Uploaded Date DESC';
$orderByOptions['order_by_downloads_asc'] = 'Downloads ASC';
$orderByOptions['order_by_downloads_desc'] = 'Downloads DESC';
$orderByOptions['order_by_filesize_asc'] = 'Filesize ASC';
$orderByOptions['order_by_filesize_desc'] = 'Filesize DESC';
$orderByOptions['order_by_last_access_date_asc'] = 'Last Access Date ASC';
$orderByOptions['order_by_last_access_date_desc'] = 'Last Access Date DESC';

// Get users account lock status
$accountLocked = 0;
$lockStatus    = corefunctions::getUsersAccountLockStatus($Auth->id);
if(SITE_CONFIG_SECURITY_ACCOUNT_LOCK == 'yes' && $lockStatus == '1')
{
    $accountLocked = 1;
}
// handle screen messages
if (isset($_REQUEST['s']))
{
    $s = $_REQUEST['s'];
    $s = validation::safeOutputToScreen($s);
    notification::setSuccess($s);
}

// setup page
define("PAGE_NAME", t("account_home_page_name", "Account Home"));
define("PAGE_DESCRIPTION", t("account_home_meta_description", "Your Account Home"));
define("PAGE_KEYWORDS", t("account_home_meta_keywords", "account, home, file, your, interface, upload, download, site"));
define("FROM_ACCOUNT_HOME", true);
define("SELECTED_NAVIGATION_LINK", "your_files");

// include header
require_once(SITE_TEMPLATES_PATH . '/partial/_header_file_manager.inc.php');
?>
<?php
// file manager javascript
require_once(SITE_TEMPLATES_PATH . '/partial/_account_home_javascript.inc.php');
?>
<script>
$('#file-menu').addClass('active');
</script>
	<div class="row section">
	  <div class="col-md-12 entry">
		<h2><?php echo t("hg_file_manager" , "File Manager")?></h2>
      </div>
	  <div class="clearfix"></div>
	  <div class="fileSectionM">
		<div class="folders">
		  <div class="sep"><?php echo t("hg_folders" , "Folders")?></div>
		  <div id="folderTreeview"></div>
		</div>
		<div class="files ">
		  <div class="actions text-right">
		    <button class="btn btn-primary btn-upload pull-left" type="button" onClick="uploadFiles(); return false;"><i class="la la-upload"></i> <?php echo t("hg_upload", "Upload")?></button>
			<div class="btn-group">
			  <button type="button" class="btn btn-default btn-files dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
			    <?php echo t("hg_add" , "Add New")?>
			  </button>
			  <ul class="dropdown-menu dropdown-menu-right">
			    <li><a href="#" onClick="uploadFiles(); return false;"><i class="la la-upload"></i> <?php echo t("hg_file" , "File")?></a></li>
			    <li><a href="#" onClick="showAddFolderForm(); return false;"><i class="la la-folder"></i> <?php echo t("hg_folder" , "Folder")?></a></li>
			  </ul>
			</div>
			<div class="btn-group hidden-xs">
			  <button type="button" id="filterButton" class="btn btn-default btn-files dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
			    <?php echo t("hg_sort" , "Sort by")?>
			  </button>
			  <ul class="dropdown-menu dropdown-menu-right">
                <?php
                foreach ($orderByOptions AS $k => $orderByOption)
                {
                    echo '<li><a href="#" onClick="updateSorting(\'' . validation::safeOutputToScreen($k) . '\', \'' . validation::safeOutputToScreen(t($k, $orderByOption)) . '\', this); return false;">' . validation::safeOutputToScreen(t($k, $orderByOption)) . '</a></li>';
                }
                ?>
			  </ul>
			  <input name="filterOrderBy" id="filterOrderBy" value="order_by_filename_asc" type="hidden"/>
			</div>
			<div class="btn-group hidden-xs">
			  <button type="button" id="perPageButton" class="btn btn-default btn-files dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
			    <?php echo t("hg_per_page" , "Per page")?> <?php echo $defaultPerPage; ?>
			  </button>
			  <ul class="dropdown-menu dropdown-menu-right">
			    <?php
                foreach ($perPageOptions AS $perPageOption)
                {
                    //if ($perPageOption == $defaultPerPage)
                    echo '<li><a href="#" onClick="updatePerPage(\'' . validation::safeOutputToScreen($perPageOption) . '\', \'' . validation::safeOutputToScreen($perPageOption) . '\', this); return false;">' . validation::safeOutputToScreen($perPageOption) . '</a></li>';
                }
                ?>
			  </ul>
			  <input name="perPageElement" id="perPageElement" value="100" type="hidden"/>
			</div>
			<div class="btn-group hidden-xs" role="group" aria-label="...">
              <button class="btn btn-default btn-files btn-view " type="button" onClick="toggleViewType(); return false;" id="viewTypeText"><i class="la la-th-list"></i></button>
            </div>
		  </div>
		  <div class="file-manager-container">
		    <div id="fileManagerContainer">
			  <div class="breadcrumbs-container">
                <ul id="folderBreadcrumbs" class="breadcrumb bc-3 pull-left hidden-xs">
                  <li>
                    <a href="#">
                      <?php echo t('your_uploads', 'Your Uploads'); ?>
                    </a>
                  </li>
                </ul>
				<ul class="breadcrumb bc-3 pull-left visible-xs">
                  <li id="-1" rel="home" class="jstree-open">
                    <a href="#" onclick="$('#folderTreeview').jstree('select_node', $('#-1'));">
                      <?php echo t('your_uploads', 'Your Uploads'); ?>
                    </a>
                  </li>
                </ul>
              </div>
			  <div id="fileManagerWrapper" class="fileManagerWrapper">
                <div id="fileManager" class="fileManager fileManagerIcon">
				  <div class="loader"><?php echo t("hg_loading" , "Loading...")?></div>
				</div>
                  <input id="nodeId" type="hidden" value="-1"/>
                <div id="pagination" class="col-md-12 responsiveAlign"></div>
                <div class="clear"></div>
			  </div>
			</div>
		  </div>
		</div>
		<div class="files-info" style="display: none;">
		  <div class="actions">
            <span id="statusText"></span>
		  </div>
		  <div class="contains">
		    <button type="button" class="btn btn-default btn-block btn-files btn-del" onClick="deleteFiles(); return false;">
			  <i class="la la-trash"></i>  <span class="hidden-xs"><?php echo t("hg_delete" , "Delete")?></span>
			</button>
			<button type="button" class="btn btn-default btn-block btn-files" onClick="viewFileLinks(); return false;">
			  <i class="la la-link"></i>  <span class="hidden-xs"><?php echo t("hg_links" , "Links")?></span>
			</button>
			<button type="button" class="btn btn-default btn-block btn-files" onClick="duplicateFiles(); return false;">
			  <i class="la la-files-o"></i>  <span class="hidden-xs"><?php echo t("hg_duplicate" , "Duplicate")?></span>
			</button>
		  </div>
		</div>
	  </div>
	</div>


<div id="filePopupContentWrapper" style="display: none;">
    <div id="filePopupContent" class="filePopupContent"></div>
</div>

<div id="filePopupContentWrapperNotice" style="display: none;">
    <div id="filePopupContentNotice" class="filePopupContentNotice"></div>
</div>

<!-- filter modal -->
<div class="modal fade" id="filterModal">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title"><?php echo t('filter_your_files', 'Filter Your Files'); ?></h4>
            </div>

            <div class="modal-body">

                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="filterText" class="control-label"><?php echo t('filter', 'Filter'); ?></label>
                            <input type="text" class="form-control" name="filterText" id="filterText" placeholder="<?php echo t('file_manager_freetext_search', 'Freetext search...'); ?>" value="<?php echo isset($filterText) ? validation::safeOutputToScreen($filterText) : ''; ?>">
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <label class="control-label">&nbsp;</label>
                            <div class="radio">
                                <label>
                                    <input type="radio" value="" id="filterFolderId" name="folderId" CHECKED><?php echo t('file_manager_current_folder', 'Current Folder'); ?>
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <label class="control-label">&nbsp;</label>
                            <div class="radio">
                                <label>
                                    <input type="radio" value="all" id="filterFolderAll" name="folderId"><?php echo t('file_manager_all_files', 'All Files'); ?>
                                </label>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-12">
                        <div class="form-group">
                            <label for="filterUploadedDateRange" class="control-label"><?php echo t('upload_date', 'Upload Date'); ?></label>
                            <div class="daterange daterange-inline" data-format="MMMM D, YYYY" data-start-date="<?php echo date("F j, Y", strtotime('-30 day')); ?>" data-end-date="<?php echo date("F j, Y"); ?>" data-callback="">
                                <i class="entypo-calendar"></i>
                                <span><?php echo t('file_manager_select_range', 'Select range...'); ?></span>
                            </div>
                            <input type="hidden" name="filterUploadedDateRange" id="filterUploadedDateRange" value=""/>
                        </div>
                    </div>
                </div>

            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo t('close', 'Close'); ?></button>
                <button type="button" class="btn btn-default" onClick="clearSearchFilters();
                        return false;" data-dismiss="modal"><?php echo t('clear_filter', 'Clear Filter'); ?></button>
                <button type="button" class="btn btn-info" onClick="doFilter(true);
                                        return false;" data-dismiss="modal"><?php echo t('apply_filter', 'Apply Filter'); ?> <i class="entypo-check"></i></button>
            </div>
        </div>
    </div>
</div>

<!-- add/edit folder -->
<div id="addEditFolderModal" class="modal fade edit-folder-modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <?php echo t('loading_please_wait', 'Loading, please wait...'); ?>
        </div>
    </div>
</div>

<!-- edit file -->
<div id="editFileModal" class="modal fade edit-file-modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <?php echo t('loading_please_wait', 'Loading, please wait...'); ?>
        </div>
    </div>
</div>

<!-- share folder -->
<div id="shareFolderModal" class="modal fade edit-folder-modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <?php echo t('loading_please_wait', 'Loading, please wait...'); ?>
        </div>
    </div>
</div>

<!-- stats -->
<div id="statsModal" class="modal fade custom-width stats-modal">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <?php echo t('loading_please_wait', 'Loading, please wait...'); ?>
        </div>
    </div>
</div>

<!-- links -->
<div id="fileLinksModal" class="modal fade file-links-wrapper">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title"><?php echo t('file_urls', 'File Urls'); ?></h2>
            </div>

            <div class="modal-body">
                <samp>
                    <div id="popupContentUrls" class="link-section" onClick="selectAllText(this);
                            return false;"></div>
                    <div id="popupContentHTMLCode" class="link-section" style="display: none;" onClick="selectAllText(this);
                            return false;"></div>
                    <div id="popupContentBBCode" class="link-section" style="display: none;" onClick="selectAllText(this);
                            return false;"></div>
                </samp>
            </div>

            <div class="modal-footer">
                <div class="row">
                    <div class="col-md-8 text-left">
                        <div class="btn-group">
                            <button type="button" class="btn btn-info active" onClick="showLinkSection('popupContentUrls', this);
                                    return false;"><?php echo t('file_urls', 'File Urls'); ?></button>
                            <button type="button" class="btn btn-info" onClick="showLinkSection('popupContentHTMLCode', this);
                                    return false;"><?php echo t('urls_html_code', 'HTML Code'); ?></button>
                            <button type="button" class="btn btn-info" onClick="showLinkSection('popupContentBBCode', this);
                                    return false;"><?php echo t('urls_bbcode', 'Forum BBCode'); ?></button>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo t('close', 'Close'); ?></button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- download folder modal -->
<div id="downloadFolderModal" class="modal fade custom-width download-folder-modal">
    <div class="modal-dialog  modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title"><?php echo t('file_urls', 'File Urls'); ?></h2>
            </div>

            <div class="modal-body">
                <div class="loader"><?php echo t("hg_loading" , "Loading...")?></div>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo t('close', 'Close'); ?></button>
            </div>
        </div>
    </div>
</div>

<!-- view file details modal -->
<div id="fileDetailsModal" class="modal fade custom-width file-details-modal">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="loader"><?php echo t("hg_loading" , "Loading...")?></div>
        </div>
    </div>
</div>
<!-- view file details modal -->
<div id="fileLinks" class="modal fade custom-width file-details-modal">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="loader"><?php echo t("hg_loading" , "Loading...")?></div>
        </div>
    </div>
</div>
<!-- view file details modal -->
<div id="sendEmail" class="modal fade custom-width file-details-modal">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="loader"><?php echo t("hg_loading" , "Loading...")?></div>
        </div>
    </div>
</div>
<!-- uploader -->
<div id="fileUploadWrapper" class="modal fade file-upload-wrapper">
    <div class="modal-dialog">
        <div class="modal-content">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="la la-close"></i></button>
            <?php
            // uploader code
            require_once(SITE_TEMPLATES_PATH . '/partial/_uploader.inc.php');
            ?>
        </div>
    </div>
</div>
<!-- view video -->
<div id="video_preview" class="modal fade custom-width">

            <?php echo t('loading_please_wait', 'Loading, please wait...'); ?>

</div>
<!-- general notice modal -->
<div id="generalModal" class="modal fade custom-width general-modal">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-body"></div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo t('close', 'Close'); ?></button>
            </div>
        </div>
    </div>
</div>

<?php
// include footer
require_once(SITE_TEMPLATES_PATH . '/partial/_footer_file_manager.inc.php');
?>
