<?php
/* setup includes */
require_once('includes/master.inc.php');

/* setup page */
define("PAGE_NAME", t("index_page_name"));
define("PAGE_DESCRIPTION", t("index_meta_description"));
define("PAGE_KEYWORDS", t("index_meta_keywords"));

/* check for url request on redirect and remove if needbe */
if ($_REQUEST['url'])
{
    redirect(WEB_ROOT . "/");
}

/* validate any submission */
require_once('_indexAction.inc.php');

/* header section */
require_once('_header.php');

/* index JS */
require_once('_indexJS.inc.php');
?>

<div class="searchBoxWrapper">

<?php
$longUrl = $_REQUEST['longUrl'];

if (isErrors())
{
    echo outputErrors();
}
?>

    <?php
    if ((int) $_REQUEST['success'] == 1)
    {
        $shortUrlObj = shortUrl::loadById((int) $_REQUEST['u']);
        $shortUrl = $shortUrlObj->compileShortUrl();
        //$longUrl = $shortUrlObj->fullUrl;

        /* output result */
        ?>

        <!-- short url result -->
        <div class="shortUrlResult" style="height: 40px; margin-bottom: 10px;">
            <div class="shortUrlResultTick">
                <img src="<?php echo SITE_IMAGE_PATH; ?>/success_tick.png" width="43" height="32" alt="success"/>
            </div>
            <div>
                <a href="<?php echo $shortUrl; ?>" target="_blank"><?php echo htmlentities($shortUrl); ?></a>
            </div>
			<div class="clear"><!-- --></div>
		</div>
		
		<?php if(isset($_REQUEST['p'])): ?>
		<div class="shortUrlResult" style="margin-bottom: 10px; padding: 0px;">
			<div class="previewUrlText" style="padding: 14px; float: left; text-align: left;">
				Original Url:<br/><font style="color: #777;"><?php echo htmlentities($shortUrlObj->fullUrl); ?></font>
			</div>
			<div class="clear"><!-- --></div>
		</div>
		<?php endif; ?>
		
		<div class="shortUrlResult" style="padding-top: 0px;">
			<div class="qrcode" style="float: right;">
				<img src="<?php echo htmlentities($shortUrl); ?>~q" alt="qr code" width="111" height="111"/>
			</div>
			
			<?php
                if (SITE_CONFIG_ENABLE_STATS == "yes")
                {
					echo '<div style="float: left; padding-top: 18px; padding-left: 14px; padding-bottom: 4px;">';
                    echo t("url_statistics", "Url Statistics").": <a href='" . htmlentities($shortUrl) . "~s' target='_blank'>" . htmlentities($shortUrlObj->shortUrlPart) . "~s</a>";
					echo '</div>';
                }
                ?>

            <div class="shareButtons" style="float: left; width: 400px; overflow:hidden; padding-left: 14px; padding-top: 14px; padding-bottom: 10px;">
				<!-- AddThis Button BEGIN -->
				<div class="addthis_toolbox addthis_default_style addthis_32x32_style">
				<a class="addthis_button_preferred_1" addthis:url="<?php echo htmlentities($shortUrl); ?>"></a>
				<a class="addthis_button_preferred_2" addthis:url="<?php echo htmlentities($shortUrl); ?>"></a>
				<a class="addthis_button_preferred_3" addthis:url="<?php echo htmlentities($shortUrl); ?>"></a>
				<a class="addthis_button_preferred_4" addthis:url="<?php echo htmlentities($shortUrl); ?>"></a>
				<a class="addthis_button_preferred_5" addthis:url="<?php echo htmlentities($shortUrl); ?>"></a>
				<a class="addthis_button_preferred_6" addthis:url="<?php echo htmlentities($shortUrl); ?>"></a>
				<a class="addthis_button_preferred_7" addthis:url="<?php echo htmlentities($shortUrl); ?>"></a>
				<a class="addthis_button_compact" addthis:url="<?php echo htmlentities($shortUrl); ?>"></a>
				<a class="addthis_counter addthis_bubble_style" addthis:url="<?php echo htmlentities($shortUrl); ?>"></a>
				</div>
				<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4f44f44768bcd979"></script>
				<!-- AddThis Button END -->
			</div>
			<div class="clear"><!-- --></div>
        </div>
        <div class="clear"><!-- --></div>

    <?php
}
?>

    <!-- main search box -->
    <form method="POST" action="index.<?php echo SITE_CONFIG_PAGE_EXTENSION; ?>" autocomplete="off">
        <div class="searchBox">
            <div class="searchContainer">
                <div class="searchTerms">
                    <div class="searchTermsA">
                        <a href="#>" onClick="showTerms(); return false;">
                            <img src="<?php echo SITE_IMAGE_PATH; ?>/homepage_title_1a.png" width="110" height="20" alt="<?php echo t("agree_terms"); ?>">
                        </a>
                    </div>
                    <div class="searchTermsB" id="searchTermsB">
                        <input name="agreeTerms" id="agreeTerms" type="checkbox" value="1"/>
                    </div>
                </div>
                <div class="searchIntroText">
                    <label for="longUrl">
                        <img src="<?php echo SITE_IMAGE_PATH; ?>/homepage_title_1.png" width="246" height="26" alt="<?php echo t("enter_your_long_url"); ?>">
                    </label>
                </div>

                <div class="searchInputArea" style="background: url(<?php echo SITE_IMAGE_PATH; ?>/search_box.gif) no-repeat;">
                    <div class="searchInput">
                        <input name="longUrl" id="longUrl" type="text" value="<?php echo htmlentities($longUrl); ?>" title="<?php echo t("enter_your_long_url"); ?>" class="homepageInput"/>
                        <input name="submitted" type="hidden" value="1"/>
                        <input name="submit" type="submit" value="" class="homepageSubmit" style="width:58px;"/>
                    </div>
                </div>
            </div>
        </div>

        <!-- additional options -->
        <div class="additionalBox" id="additionalBox">
            <div class="additionalContainer" id="additionalContainer">
                <div class="additionalDownArrow" id="additionalDownArrow" onClick="showHideAdditionalOptions();">
                    <img id="additionalImageIcon" src="<?php echo SITE_IMAGE_PATH; ?>/downArrow.png" width="24" height="11"/>
                </div>
                <div class="additionalIntroText" id="additionalIntroText" onClick="showHideAdditionalOptions();">
                    <img src="<?php echo SITE_IMAGE_PATH; ?>/homepage_title_2.png"/>
                </div>

                <div class="additionalOptions" id="additionalOptions">
                    <div class="customUrl">
                        <div>
                            <label for="customUrl"><?php echo t("custom_url"); ?></label>
                        </div>
                        <div>
                            <input class="uiStyle" name="customUrl" id="customUrl" type="input" title="<?php echo t("set_a_custom_url"); ?>" value="<?php echo htmlentities($_REQUEST['customUrl']); ?>"/>
                        </div>
<?php //'private' (0=public) - leave for later functionality  ?>
                        <input id="shortUrlType" name="shortUrlType" value="1" type="hidden"/>
                    </div>

                    <div class="shortUrlPassword">
                        <div>
                            <label for="shortUrlPassword"><?php echo t("index_password"); ?></label>
                        </div>
                        <div>
                            <input class="uiStyle" name="shortUrlPassword" id="shortUrlPassword" type="password" title="<?php echo t("set_the_password_to_access_link"); ?>" value="<?php echo htmlentities($_REQUEST['shortUrlPassword']); ?>"/>
                        </div>
                    </div>

                    <div class="clear"><!-- --></div>

                    <div class="shortUrlExpiryDate">
                        <div>
                            <label for="shortUrlExpiryDate"><?php echo t("expiry_date"); ?></label>
                        </div>
                        <div>
                            <input class="uiStyle" name="shortUrlExpiryDate" id="shortUrlExpiryDate" type="text" title="<?php echo t("set_an_expiry_date_for_url"); ?>" value="<?php echo htmlentities($_REQUEST['shortUrlExpiryDate']); ?>"/>
                        </div>
                    </div>

                    <div class="shortUrlUses">
                        <div>
                            <label for="shortUrlUses"><?php echo t("url_total_uses"); ?></label>
                        </div>
                        <div>
                            <select id="shortUrlUses" name="shortUrlUses" title="<?php echo t("total_uses_before_url_expires"); ?>">
<?php
$options = array(0 => t("unlimited"), 1 => "1", 2 => "2", 3 => "3", 5 => "5", 10 => "10", 20 => "20", 50 => "50", 100 => "100", 500 => "500", 1000 => "1000");
foreach ($options AS $k => $option)
{
    echo '<option value="' . (string) $k . '"';
    if ($k == (int) $_REQUEST['shortUrlUses'])
    {
        echo ' SELECTED';
    }
    echo '>' . $option . '</option>';
}
?>
                            </select>
                        </div>
                    </div>

                    <div class="clear"><!-- --></div>

                </div>
            </div>
        </div>

        <input type="hidden" id="additionalOptState" name="additionalOptState" value="<?php echo (int) $_REQUEST['additionalOptState']; ?>"/>
    </form>

    <!-- JS bookmarks -->
    <div class="bookmarkItems">
        <div class="subBoomarkItem">
            <a href="#" onClick="bookmarksite('<?php echo str_replace("'", "", SITE_CONFIG_SITE_NAME); ?>', '<?php echo WEB_ROOT; ?>'); return false;"><img height="20" width="20" alt="<?php echo t("add_to_bookmarks"); ?>" src="<?php echo SITE_IMAGE_PATH; ?>/star_icon.png"/></a>
        </div>
        <div class="subBoomarkItem">
            <a href="javascript:void(location.href='<?php echo WEB_ROOT; ?>/index.<?php echo SITE_CONFIG_PAGE_EXTENSION; ?>?agreeTerms=1&submitted=1&longUrl='+encodeURIComponent(location.href.replace('http://','')));" onClick="alert(t('toolbar_quicklink_alert')); return false;"><img height="20" width="20" alt="<?php echo t("create_short_url"); ?>" src="<?php echo SITE_IMAGE_PATH; ?>/plus_icon.png"/></a>
        </div>
        <div class="subBoomarkItem">
            <a href="javascript:void(location.href='<?php echo WEB_ROOT; ?>/index.<?php echo SITE_CONFIG_PAGE_EXTENSION; ?>?agreeTerms=1&submitted=1&postToTwitter=1&longUrl='+encodeURIComponent(location.href.replace('http://','')));" onClick="alert(t('twitter_quicklink_alert')); return false;"><img height="20" width="20" alt="<?php echo t("post_on_twitter"); ?>" src="<?php echo SITE_IMAGE_PATH; ?>/twitter_icon.png"/></a>
        </div>
        <div class="clear"><!-- --></div>
    </div>

</div>

<?php
require_once('_footer.php');
?>