<?php
/* setup page */
define("PAGE_NAME", t("file_password_page_name", "File Password"));
define("PAGE_DESCRIPTION", t("file_password_meta_description", "Enter file password"));
define("PAGE_KEYWORDS", t("file_password_meta_keywords", "file, password, account, short, url, user"));
define("TITLE_DESCRIPTION_LEFT", t("file_password_title_page_description_left", "A password is required to access this file, please enter it below."));
define("TITLE_DESCRIPTION_RIGHT", t("file_password_title_page_description_right", ""));

/* check password */
$file = file::loadByShortUrl($_REQUEST['file']);
if ((int) $_REQUEST['submitme'])
{
    // validation
    $filePassword = trim($_REQUEST['filePassword']);
    if (!strlen($filePassword))
    {
        notification::setError(t("please_enter_the_file_password", "Please enter the file password."));
    }

    // create the account
    if (!notification::isErrors())
    {
        if ($file)
        {
            // check password
            if (md5($filePassword) == $file->accessPassword)
            {
                $_SESSION['allowAccess' . $file->id] = true;
                coreFunctions::redirect(file::getFileUrl($file->id));
            }
            else
            {
                notification::setError(t("file_password_is_invalid", "File password is invalid."));
            }
        }
    }
}
// include header
require_once(SITE_TEMPLATES_PATH . '/partial/_header.inc.php');
?>
<?php
if (notification::isErrors())
{
    echo notification::outputErrors();
}
elseif (notification::isSuccess())
{
    echo notification::outputSuccess();
}
?>
<div class="col-md-3">
    <form method="post" action="<?php echo WEB_ROOT; ?>/file_password.<?php echo SITE_CONFIG_PAGE_EXTENSION; ?>">
        <div class="input-group"><span class="input-group-addon"><i class="fa fa-chevron-right"></i></span>
            <input name="filePassword" class="form-control" tabindex="1" placeholder="<?php echo t("password", "password"); ?>" type="password"/>
        </div>

        <div class="input-group form-buttons"> <span class="input-group-btn">
                <button class="btn btn-default" tabindex="99" type='submit' value="<?php echo t("access_file", "access file"); ?>" name='submit' id="submitf" style="width:100%;height:60px;"><i class="fa fa-check"></i> SEND</button>
            </span> 
            <input type="hidden" value="1" name="submitme"/>
            <input type="hidden" value="<?php echo validation::safeOutputToScreen($_REQUEST['file']); ?>" name="file"/>
        </div>
    </form>
</div>
<?php
// include footer
require_once(SITE_TEMPLATES_PATH . '/partial/_footer.inc.php');
?>
