<?php
/*******************************************************************************
 *                    _ _ _ _
 *                   / _ _  /
 *            _ _   / /__/ /_ _   ____ _ _   _ _ _    __
 *           / _ ` /   _ _// _ ` / __// _ ` / _ \\ \ / /
 *          / _ _// /\ \  / _ _/ \_ \/ _ _// / \/ \ ` /
 *          \_ , /_/  \_\ \_ ,  /__ /\_ , /_/      \_/
 *
 *******************************************************************************
 *    Application:  eReserv
 *    Version:      6
 *    Author:       David Di Certo
 *    Website:      http://www.cogites.com
 *    Email:        contact@cogites.com
 *    Copyright:    2013 - David Di Certo
 *******************************************************************************
 *    == FR ==      La revente et la redistribution de l'application sont
 *                  strictement interdites.
 *
 *                  Vous êtes tenu d'avoir pris connaissance des
 *                  Conditions Générales de Vente disponibles sur Cogites.com
 *                  (y compris pour la version Free).
 *
 *    == EN ==      Resale and redistribution of the application are
 *                  Strictly prohibited.
 *
 *                  You are required to have read the Terms and Conditions
 *                  available on Cogites.com (including the Free version).
 *
 *******************************************************************************
*/

	require "../_container/container_top.php";
	require_once ('business/TenancyMgr.php');
	$tenancyMgr = new TenancyMgr();

	$selectTenancy = getPost('selectTenancy');
	$arrTenancy = $tenancyMgr->getTenancys();

	function url_origin($s, $use_forwarded_host=false) {
		$ssl = (!empty($s['HTTPS']) && $s['HTTPS'] == 'on') ? true:false;
		$sp = strtolower($s['SERVER_PROTOCOL']);
		$protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : '');
		$port = $s['SERVER_PORT'];
		$port = ((!$ssl && $port=='80') || ($ssl && $port=='443')) ? '' : ':'.$port;
		$host = ($use_forwarded_host && isset($s['HTTP_X_FORWARDED_HOST'])) ? $s['HTTP_X_FORWARDED_HOST'] : (isset($s['HTTP_HOST']) ? $s['HTTP_HOST'] : null);
		$host = isset($host) ? $host : $s['SERVER_NAME'] . $port;
		return $protocol . '://' . $host;
	}
	function full_url($s, $use_forwarded_host=false) {
		return url_origin($s, $use_forwarded_host) . $s['REQUEST_URI'];
	}
	function short_url($s, $use_forwarded_host=false) {
		return url_origin($s, $use_forwarded_host) ;
	}

	$absolute_url = short_url($_SERVER);

?>

	<div>
		<ul class="breadcrumb">
			<li><a href="./"><?php echo $tr->translate("menuHome"); ?></a> <span class="divider">/</span></li>
			<li class="active"><?php echo $tr->translate("menuCode"); ?></li>
		</ul>
	</div>
	<div class="sortable row-fluid">
		<a data-rel="tooltip" title="<?php echo $tr->translate('AddReserv'); ?>" class="well span2 top-block btn-action" href="#" name="newReservation" id="newReservation" _page="reservationDetail.php" _action="Add">
			<i class="icon-red icon-user"></i>
			<div><?php echo $tr->translate("AddReserv"); ?></div>
			<div></div>
		</a>
		<a data-rel="tooltip" title="<?php echo $tr->translate("AddPayment"); ?>" class="well span2 top-block btn-action" href="#" name="newPayment" id="newPayment" _page="paymentDetail.php" _action="Add">
			<i class="icon-cog"></i>
			<div><?php echo $tr->translate("AddPayment"); ?></div>
			<div></div>
		</a>
	</div>

	<div class="row-fluid sortable">
		<div class="box span12">
			<div class="box-header well" data-original-title>
				<h2><i class="icon-picture"></i> <?php echo $tr->translate("Filter"); ?></h2>
			</div>
			<div class="box-content">
			<?php if (!$selectTenancy) { ?>
				<div class="alert alert-error">
				<strong><?php echo $tr->translate("msgCodeSelectTenancy"); ?></strong>
				</div>
			<?php } ?>
				<form class="form-horizontal" method="post" name="codeForm" id="codeForm" action="code.php">
					<select id="selectTenancy" name="selectTenancy" data-rel="chosen" class="filter-action">
						<option value=""></option>
						<?php $id = 0; foreach ($arrTenancy as $tenancy) {
							echo "<option value='" . $tenancy->tenancy_id . "'";
							if ($selectTenancy == $tenancy->tenancy_id) {echo " selected"; $id = $tenancy->tenancy_id;}
							echo ">" . $tenancy->name . "</option>";
						} ?>
					</select>
				</form>
			</div>
		</div><!--/span-->
	</div><!--/row-->
    
	<div class="row-fluid sortable">
		<div class="box span6">
			<div class="box-header well" data-original-title>
				<h2><i class="icon-picture"></i> <?php echo $tr->translate("thCodeCalendar"); ?></h2>
			</div>
			<div class="box-content">
				<textarea class="span12" rows="5" name="inputCodeCal"><a href="#" onclick="window.open('<?php echo $absolute_url . CONTEXT_ROOT; ?>/user/calendar.php?id=<?php echo $id;?>','_blank','toolbar=0, location=0, status=0, scrollbars=1, resizable=0, menubar=0, width=1000, height=1000, left=10, top=10');"><?php echo $tr->translate("thCodeCalendarName"); ?></a></textarea>
				<input id="btnCodeCal" name="btnCodeCal" type="button" class="btn btn-primary" value="<?php echo $tr->translate("thCodePreview"); ?>" onclick="window.open('<?php echo $absolute_url . CONTEXT_ROOT; ?>/user/calendar.php?id=<?php echo $id;?>','_blank','toolbar=0, location=0, status=0, scrollbars=1, resizable=0, menubar=0, width=1000, height=1000, left=10, top=10');">
			</div>
		</div><!--/span-->
		<?php if (file_exists("../user/userform.php")) { ?>
		<div class="box span6">
			<div class="box-header well" data-original-title>
				<h2><i class="icon-picture"></i> <?php echo $tr->translate("thCodeUserform"); ?></h2>
			</div>
			<div class="box-content">
				<textarea class="span12" rows="5" name="inputCodeForm"><a href="#" onclick="window.open('<?php echo $absolute_url . CONTEXT_ROOT; ?>/user/userform.php?id=<?php echo $id;?>','_blank','toolbar=0, location=0, status=0, scrollbars=1, resizable=0, menubar=0, width=1000, height=1000, left=10, top=10');"><?php echo $tr->translate("thCodeCalendarName"); ?></a></textarea>
				<input id="btnCodeForm" name="btnCodeForm" type="button" class="btn btn-primary" value="<?php echo $tr->translate("thCodePreview"); ?>" onclick="window.open('<?php echo $absolute_url . CONTEXT_ROOT; ?>/user/userform.php?id=<?php echo $id;?>','_blank','toolbar=0, location=0, status=0, scrollbars=1, resizable=0, menubar=0, width=1000, height=1000, left=10, top=10');">
			</div>
		</div><!--/span-->
		<?php } ?>
	</div><!--/row-->
    
<?php require "../_container/container_bottom.php"; ?>
<script>
$("textarea").focus(function() {
    var $this = $(this);
    $this.select();

    // Work around Chrome's little problem
    $this.mouseup(function() {
        // Prevent further mouseup intervention
        $this.unbind("mouseup");
        return false;
    });
});
</script>