<?php
// load file
$file = null;
if (isset($_REQUEST['_page_url']))
{
    // figure out the delete hash
    $loggedInHash = '';
    foreach ($_REQUEST AS $k => $item)
    {
        if (strlen($k) == 32)
        {
            $loggedInHash = $k;
        }
    }

    // only keep the initial part if there's a forward slash
    $shortUrl = current(explode("/", str_replace("~i", "", $_REQUEST['_page_url'])));
    $file = file::loadByShortUrl($shortUrl);

    // check whether we can display the delete/password options
    $showAll = false;
    if ($file->deleteHash == $loggedInHash)
    {
        $showAll = true;
    }

    // double check the owner for logged in user
    if (($showAll == false) && ($file))
    {
        if (($file->userId != NULL) && ($file->userId == $Auth->id))
        {
            $showAll = true;
        }
    }
}
$user = userPeer::loadUserById($Auth->id);

// load file details
if (!$file)
{
    /* if no file found, redirect to home page */
    coreFunctions::redirect(WEB_ROOT . "/index." . SITE_CONFIG_PAGE_EXTENSION);
}

// only show this page if active file
if ($file->statusId != 1)
{
    // redirect to file in order to show error
    coreFunctions::redirect($file->getFullShortUrl());
}

// check file permissions, allow owners, non user uploads and admin/mods
if($file->userId != null)
{
	if((($file->userId != $Auth->id) && ($Auth->level_id < 10)))
	{
		// if this is a private file
		if(coreFunctions::getOverallPublicStatus($file->userId, $file->folderId, $file->id) == false)
		{
			$errorMsg = t("error_file_is_not_publicly_shared", "File is not publicly available.");
			coreFunctions::redirect(coreFunctions::getCoreSitePath() . "/error." . SITE_CONFIG_PAGE_EXTENSION . "?e=" . urlencode($errorMsg));
		}
	}
}

// setup page
define("PAGE_NAME", t("share_file_title", "File Information"));
define("PAGE_DESCRIPTION", t("file_information_description", "Information about") . ' ' . $file->originalFilename);
define("PAGE_KEYWORDS", strtolower($file->originalFilename) . t("file_information_meta_keywords", ", share, information, file, upload, download, site"));
define("TITLE_DESCRIPTION_LEFT", t("file_information_left_description", "Information about") . ' ' . $file->originalFilename);
define("TITLE_DESCRIPTION_RIGHT", t("share_files_title_page_description_right", ""));

// include header
require_once(SITE_TEMPLATES_PATH . '/partial/_header.inc.php');
?>
<div class="download">
  <div class="row">
    <div class="file-info">
	  <div class="icon">
	    <img src="<?php echo $file->getLargeIconPath(); ?>" width="100" alt="<?php echo strtolower($file->extension); ?>"/>
	  </div>
	  <div class="name">
	    <h4><?php echo wordwrap(validation::safeOutputToScreen($file->originalFilename), 28, ' ', true); ?> <small><?php echo coreFunctions::formatSize($file->fileSize); ?></small></h4>
	  </div>
	  <div class="share">
	    <!-- Go to www.addthis.com/dashboard to customize your tools --> <div class="addthis_inline_share_toolbox"></div>
	  </div>
	  <div class="download1">
	    <a href="<?php echo validation::safeOutputToScreen($file->getFullShortUrl()); ?>" target="_blank" class="btn btn-block btn-download"><?php echo UCWords(t('hg_download_info', 'Download')); ?> <i class="la la-arrow-right"></i></a>
	  </div>
	</div>
  </div>
</div>
<?php if ((SITE_CONFIG_FORCE_FILES_PRIVATE == 'no') && ($file->isPublic == 1) && ($user->isPublic == 1) && coreFunctions::getUserFoldersPublicStatus($file->folderId) == true): ?>
<div class="col-md-12">
  <div class="form-horizontal">
    <div class="form-group">
      <label class="col-sm-2 control-label"><?php echo t('html_code', 'HTML Code'); ?></label>
      ` <div class="col-sm-9">
          <input type="text" onclick="this.select()" readonly='' class="form-control" value='<?php echo $file->getHtmlLinkCode(); ?>'>
        </div>
    </div>
	<div class="form-group">
      <label class="col-sm-2 control-label"><?php echo UCWords(t('hg_forum_code', 'Forum code')); ?></label>
      ` <div class="col-sm-9">
          <input type="text" onclick="this.select()" readonly="" class="form-control" value="<?php echo $file->getForumLinkCode(); ?>">
        </div>
    </div>
	<div class="form-group">
      <label class="col-sm-2 control-label"><?php echo UCWords(t('hg_statistics', 'Statistics link')); ?></label>
      ` <div class="col-sm-9">
          <input type="text" onclick="this.select()" readonly="" class="form-control" value="<?php echo $file->getStatisticsUrl(); ?>">
        </div>
    </div>
  </div>
</div>
<?php endif; ?>
<div class="clearfix" style="margin: 100px 0;"></div>
<?php
// include footer
require_once(SITE_TEMPLATES_PATH . '/partial/_footer.inc.php');
?>
