<?php

// 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';

// 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");

// page OG info (for facebook)
if(defined("_INT_FILE_ID"))
{
	$file = file::loadById(_INT_FILE_ID);
	if($file)
	{
		define("PAGE_OG_TITLE", substr(UCWords(t('View', 'view')).' '.$file->originalFilename.' '.t('on', 'on').' '.SITE_CONFIG_SITE_NAME, 0, 150));
		define("PAGE_OG_SITE_NAME", SITE_CONFIG_SITE_NAME);
		
		// don't show thumbnail if the album is private or has a password
		if((int)$file->folderId)
		{
			// check for password
			$folderPassword = null;
			$folder = fileFolder::loadById($file->folderId);
			if($folder)
			{
				$folderPassword = $folder->accessPassword;
			}

			// check for privacy
			$public = true;
			if(((int)$folder->userId > 0) && ($folder->userId != $Auth->id))
			{
				if(coreFunctions::getOverallPublicStatus($folder->userId, $folder->id) == false)
				{
					$public = false;
				}
			}
			if(($public == true) && ($folderPassword != true))
			{
				define("PAGE_OG_IMAGE", file::getIconPreviewImageUrl((array) $file, false, 64, false, 280, 280, 'middle'));
			}
		}
	}
}

// redirect if user not logged in and not requesting a file
if(($Auth->loggedIn() == false) && ($file == false))
{
	coreFunctions::redirect(WEB_ROOT.'/login.'.SITE_CONFIG_PAGE_EXTENSION);
}

// page OG info (for facebook)
define("PAGE_OG_TITLE", t("folder_page_name", "Folder"));
define("PAGE_OG_SITE_NAME", SITE_CONFIG_SITE_NAME);
define("PAGE_OG_DESCRIPTION", PAGE_DESCRIPTION);

// include header
require_once(SITE_TEMPLATES_PATH . '/partial/_header.inc.php');

// file manager javascript
require_once(SITE_TEMPLATES_PATH . '/partial/_account_home_javascript.inc.php');
?>

<?php if(!defined("_INT_FILE_ID")): ?>
<script>
$( document ).ready(function() {
	loadImages('-1');
});
</script>
<?php endif; ?>

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