<?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).
 *
 *******************************************************************************
*/

	if (isset($_POST['action'])){
		$action = $_POST['action'];
	}
// print_r($_POST);
	if (!empty($action) && ($action == "save" || $action == "testMail" || $action == "resetColor")){
		ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '../../services');
		ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '../../services/lib');
		require_once ('business/ConfigMgr.php');
		$configMgr = new ConfigMgr();

		if ($action == "save"){
			// $_POST['cfg_mail_system'] = (isset($_POST['cfg_mail_system']) && ($_POST['cfg_mail_system'] == 1)) ? 1 : 0;
			$_POST['cfg_allow_duplicate_reservation'] = (isset($_POST['cfg_allow_duplicate_reservation']) && ($_POST['cfg_allow_duplicate_reservation'] == "on")) ? 1 : 0;
			$_POST['cfg_cal_start_current_month'] = (isset($_POST['cfg_cal_start_current_month']) && ($_POST['cfg_cal_start_current_month'] == "on")) ? 1 : 0;
			$_POST['cfg_cal_8days_week'] = (isset($_POST['cfg_cal_8days_week']) && ($_POST['cfg_cal_8days_week'] == "on")) ? 1 : 0;
			$_POST['cfg_cal_show_week_number'] = (isset($_POST['cfg_cal_show_week_number']) && ($_POST['cfg_cal_show_week_number'] == "on")) ? 1 : 0;
			$_POST['cfg_cal_show_nomonth_days'] = (isset($_POST['cfg_cal_show_nomonth_days']) && ($_POST['cfg_cal_show_nomonth_days'] == "on")) ? 1 : 0;
			$_POST['cfg_cal_show_reserv_option'] = (isset($_POST['cfg_cal_show_reserv_option']) && ($_POST['cfg_cal_show_reserv_option'] == "on")) ? 1 : 0;
			$_POST['cfg_db_backup_enabled'] = (isset($_POST['cfg_db_backup_enabled']) && ($_POST['cfg_db_backup_enabled'] == "on")) ? 1 : 0;
			$_POST['cfg_lease_keep_on_server'] = (isset($_POST['cfg_lease_keep_on_server']) && ($_POST['cfg_lease_keep_on_server'] == "on")) ? 1 : 0;
			$_POST['cfg_lease_create_2copy'] = (isset($_POST['cfg_lease_create_2copy']) && ($_POST['cfg_lease_create_2copy'] == "on")) ? 1 : 0;
			$_POST['cfg_log_enabled'] = (isset($_POST['cfg_log_enabled']) && ($_POST['cfg_log_enabled'] == "on")) ? 1 : 0;
			$_POST['cfg_allow_edit_paid_reserv'] = (isset($_POST['cfg_allow_edit_paid_reserv']) && ($_POST['cfg_allow_edit_paid_reserv'] == "on")) ? 1 : 0;

			foreach ($_POST as $key => $val) {
				$pos = stripos($key, "cfg_");
				if ($pos !== false) {
					$res = $configMgr->saveConfig(substr($key,4), $val);
				}
			}
			$msgType = "success";
			$msg = $tr->translate("msgSuccess");
		}
		$config = $configMgr->getConfigs();

		if ($action == "testMail"){
			include_once ('MailVo.php');
			$mail[] = new MailVo();
			$mail[0]->from = $config['renter_email'];
			$mail[0]->to = $session->userEmail;
			$mail[0]->subject = "Test Configuration";
			$mail[0]->content = "Test Configuration";
			include_once ('config/Mailer.php');
			$m = new Mailer($config);
			$r = $m->sendMail($mail);
			if (!$r) {
				$msgType = "error";
				$msg = $tr->translate("msgMailError");
			}else{
				$msgType = "success";
				$msg = $tr->translate("msgSuccess");
			}
		}
		if ($action == "resetColor") {
			$aa = array();
			$aa['cfg_color_cal_bgd'] = "EDEDED";
			$aa['cfg_color_cal_free_bgd'] = "D8E4BC";
			$aa['cfg_color_cal_free_txt'] = "000000";
			$aa['cfg_color_cal_option_bgd'] = "FABF8F";
			$aa['cfg_color_cal_option_txt'] = "000000";
			$aa['cfg_color_cal_booked_bgd'] = "DA9694";
			$aa['cfg_color_cal_booked_txt'] = "000000";
			$aa['cfg_color_season_na_bgd'] = "C3C3C3";
			$aa['cfg_color_season_na_txt'] = "000000";
			$aa['cfg_color_season_medium_bgd'] = "F7F3D5";
			$aa['cfg_color_season_medium_txt'] = "000000";
			$aa['cfg_color_season_high_bgd'] = "C1D7EB";
			$aa['cfg_color_season_high_txt'] = "000000";
			$aa['cfg_color_season_tophigh_bgd'] = "D0FEFE";
			$aa['cfg_color_season_tophigh_txt'] = "000000";
			foreach ($aa as $key => $val) {
				$pos = stripos($key, "cfg_");
				if ($pos !== false) {
					$res = $configMgr->saveConfig(substr($key,4), $val);
				}
			}
			$msgType = "success";
			$msg = $tr->translate("msgSuccess");
		}
	}

	require "../_container/container_top.php";
	require_once("config/Tagger.php");
	$tagger = new Tagger();

	if (!empty($action) && ($action == "save" || $action == "testMail" || $action == "resetColor")){
		echo '<div class="alert alert-'.$msgType . '">
			<strong>' . $msg . '</strong>
			</div>';
	}
	$currentTab = getPost('currentTab');

?>
		
	<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("menuSettings"); ?></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 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>
		</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("thTagList"); ?></h2>
				<div class="box-icon">
					<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-down"></i></a>
				</div>
			</div>
			<div class="box-content" style="display:none;">
				<div class="tabbable">
					<ul class="nav nav-tabs">
						<?php $arrTags = Tagger::getTagList(); foreach ($arrTags as $tag) { ?>
							<li class="<?php if (reset($arrTags) == $tag) echo "active"; ?>"><a href="#tag_<?php echo $tag; ?>" data-toggle="tab"><?php echo $tr->translate('tagName_'.$tag); ?></a></li>
						<?php } ?>
					</ul>
					<div class="tab-content">
					<?php $arrTags = Tagger::getTagList(); foreach ($arrTags as $tag) { ?>
						<div class="tab-pane <?php if (reset($arrTags) == $tag) echo "active"; ?>" id="tag_<?php echo $tag; ?>">
							<table id="tableConfigTagList" name="tableConfigTagList" class="table table-bordered table-striped table-condensed">
								<thead>
									<tr>
										<th style="width:55px;"><?php echo $tr->translate("thTagName"); ?></th>
										<th><?php echo $tr->translate("thTagDescription"); ?></th>
									</tr>
								</thead>
								<tbody>
								<?php foreach(Tagger::getTag($tag) as $tagName){ ?>
									<tr><td><code><?php echo htmlentities($tagName); ?></code></td>
										<td><?php echo $tr->translate($tagName); ?></td></tr>
								<?php } ?>
								</tbody>
							</table>
						</div>
					<?php } ?>
					</div>
				</div>
			</div>
		</div><!--/span-->
	</div><!--/row-->
	<div class="row-fluid sortable">	
		<div class="box span12">
			<div class="box-header well" data-original-title>
				<h2><i class="icon-cogs"></i> <?php echo $tr->translate("thSettings"); ?></h2>
			</div>
			<div class="box-content">

			<form class="form-horizontal" method="post" name="configForm" id="configForm" action="config.php">
				<input type="hidden" name="action" id="action" value="" />
				<input type="hidden" name="currentTab" id="currentTab" value="<?php echo $currentTab; ?>>" />
				<div class="tabbable">
					<ul class="nav nav-tabs" id="optionTab">
						<li class="<?php if (($currentTab == "config_1") || ($currentTab == "")) echo "active"; ?>" id="config_1" name="config_1"><a href="#1a" data-toggle="tab"><?php echo $tr->translate("cfgName_1"); ?></a></li>
						<li class="<?php if ($currentTab == "config_2") echo "active"; ?>" id="config_2" name="config_2"><a href="#2a" data-toggle="tab"><?php echo $tr->translate("cfgName_2"); ?></a></li>
						<li class="<?php if ($currentTab == "config_9") echo "active"; ?>" id="config_9" name="config_9"><a href="#9a" data-toggle="tab"><?php echo $tr->translate("cfgName_9"); ?></a></li>
						<li class="<?php if ($currentTab == "config_11") echo "active"; ?>" id="config_11" name="config_11"><a href="#11a" data-toggle="tab"><?php echo $tr->translate("cfgName_11"); ?></a></li>
						<li class="<?php if ($currentTab == "config_4") echo "active"; ?>" id="config_4" name="config_4"><a href="#4a" data-toggle="tab"><?php echo $tr->translate("cfgName_4"); ?></a></li>
						<li class="<?php if ($currentTab == "config_5") echo "active"; ?>" id="config_5" name="config_5"><a href="#5a" data-toggle="tab"><?php echo $tr->translate("cfgName_5"); ?></a></li>
						<li class="<?php if ($currentTab == "config_6") echo "active"; ?>" id="config_6" name="config_6"><a href="#6a" data-toggle="tab"><?php echo $tr->translate("cfgName_6"); ?></a></li>
						<li class="<?php if ($currentTab == "config_7") echo "active"; ?>" id="config_7" name="config_7"><a href="#7a" data-toggle="tab"><?php echo $tr->translate("cfgName_7"); ?></a></li>
					</ul>
					<div class="tab-content" style="min-height: 150px;">
						<div class="tab-pane <?php if (($currentTab == "config_1") || ($currentTab == "")) echo "active"; ?>" id="1a">
							<div class="control-group">
								<label class="control-label" for="cfg_language"><?php echo $tr->translate("cfgVal_language"); ?></label>
								<div class="controls input-medium">
									<select name="cfg_language" id="cfg_language" data-rel="chosen">
										<?php $arrValue = array("en_US"=>"English (US)","fr_FR"=>"Français","it_IT"=>"Italian","de_DE"=>"German","es_ES"=>"Spanish","nl_NL"=>"Dutch"); foreach ($arrValue as $key => $val) { ?>
											<option value="<?php echo $key;?>" <?php if ($config['language'] == $key) echo " selected"; ?>><?php echo $val;?></option>
										<?php } ?>
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_date_format"><?php echo $tr->translate("cfgVal_date_format"); ?></label>
								<div class="controls input-medium">
									<select name="cfg_date_format" id="cfg_date_format" data-rel="chosen">
										<?php $arrValue = array("d.m.Y", "d/m/Y", "d-m-Y", "Y-m-d"); foreach ($arrValue as $val) { ?>
											<option value="<?php echo $val;?>" <?php if ($config['date_format'] == $val) echo " selected"; ?>><?php echo $val;?></option>
										<?php } ?>
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_date_format"><?php echo $tr->translate("cfgVal_currency_symbol"); ?></label>
								<div class="controls input-medium">
									<select name="cfg_currency_symbol" id="cfg_currency_symbol" data-rel="chosen">
										<?php $arrValue = array("€","$","£","CHF","R$"); foreach ($arrValue as $val) { ?>
											<option value="<?php echo $val;?>" <?php if ($config['currency_symbol'] == $val) echo " selected"; ?>><?php echo $val;?></option>
										<?php } ?>
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_tracking_payment"><?php echo $tr->translate("cfgVal_tracking_payment"); ?></label>
								<div class="controls input-medium">
									<select name="cfg_tracking_payment" id="cfg_tracking_payment" data-rel="chosen">
										<option></option>
										<?php $arrValue = $tr->translate("cfgVal_payment_default"); foreach ($arrValue as $val) { ?>
											<option value="<?php echo $val;?>" <?php if ($config['tracking_payment'] == $val) echo " selected"; ?>><?php echo $val;?></option>
										<?php } ?>
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_max_list_page"><?php echo $tr->translate("cfgVal_max_list_page"); ?></label>
								<div class="controls">
									<div class="input-prepend">
										<a href="#"><span class="add-on icon-minus-sign qtyminus" data-field="cfg_max_list_page"></span></a><input type="text" class="input-mini" id="cfg_max_list_page" name="cfg_max_list_page" value="<?php echo $config['max_list_page']; ?>"><a href="#"><span class="add-on icon-plus-sign qtyplus" data-field="cfg_max_list_page"></span></a>
									</div>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_allow_duplicate_reservation"><?php echo $tr->translate("cfgVal_allow_duplicate_reservation"); ?></label>
								<div class="controls">
									<div class="input-prepend">
										<input type="checkbox" id="cfg_allow_duplicate_reservation" name="cfg_allow_duplicate_reservation" <?php if($config['allow_duplicate_reservation'] == 1) echo " checked"; ?>>
									</div>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_allow_edit_paid_reserv"><?php echo $tr->translate("cfgVal_allow_edit_paid_reserv"); ?></label>
								<div class="controls">
									<div class="input-prepend">
										<input type="checkbox" id="cfg_allow_edit_paid_reserv" name="cfg_allow_edit_paid_reserv" <?php if($config['allow_edit_paid_reserv'] == 1) echo " checked"; ?>>
									</div>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_lease_reminder_delay"><?php echo $tr->translate("cfgVal_lease_reminder_delay"); ?></label>
								<div class="controls">
									<div class="input-prepend">
										<a href="#"><span class="add-on icon-minus-sign qtyminus" data-field="cfg_lease_reminder_delay"></span></a><input type="text" class="input-mini" id="cfg_lease_reminder_delay" name="cfg_lease_reminder_delay" value="<?php echo $config['lease_reminder_delay']; ?>"><a href="#"><span class="add-on icon-plus-sign qtyplus" data-field="cfg_lease_reminder_delay"></span></a>
									</div>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_balance_reminder_delay"><?php echo $tr->translate("cfgVal_balance_reminder_delay"); ?></label>
								<div class="controls">
									<div class="input-prepend">
										<a href="#"><span class="add-on icon-minus-sign qtyminus" data-field="cfg_balance_reminder_delay"></span></a><input type="text" class="input-mini" id="cfg_balance_reminder_delay" name="cfg_balance_reminder_delay" value="<?php echo $config['balance_reminder_delay']; ?>"><a href="#"><span class="add-on icon-plus-sign qtyplus" data-field="cfg_balance_reminder_delay"></span></a>
									</div>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_tenant_reference"><?php echo $tr->translate("cfgVal_tenant_reference"); ?></label>
								<div class="controls">
									<label class="">
										<input id="" name="cfg_tenant_reference" type="cfg_tenant_reference" class="tags span6" value="<?php echo $config['tenant_reference']; ?>">
									</label>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_reserv_reference"><?php echo $tr->translate("cfgVal_reserv_reference"); ?></label>
								<div class="controls">
									<label class="">
										<input id="" name="cfg_reserv_reference" type="cfg_reserv_reference" class="tags span6" value="<?php echo $config['reserv_reference']; ?>">
									</label>
								</div>
							</div>
						</div>

						<div class="tab-pane <?php if ($currentTab == "config_9") echo "active"; ?>" id="9a">
							<div class="control-group">
								<label class="control-label" for="cfg_cal_first_weekday"><?php echo $tr->translate("cfgVal_cal_first_weekday"); ?></label>
								<div class="controls input-medium">
									<select name="cfg_cal_first_weekday" id="cfg_cal_first_weekday" data-rel="chosen">
										<?php $arrValue = $tr->translate("cfgVal_cal_first_weekday_names"); foreach ($arrValue as $key => $val) { ?>
											<option value="<?php echo $key;?>" <?php if ($config['cal_first_weekday'] == $key) echo " selected"; ?>><?php echo $val;?></option>
										<?php } ?>
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_cal_start_current_month"><?php echo $tr->translate("cfgVal_cal_start_current_month"); ?></label>
								<div class="controls">
									<label class="">
										<input type="checkbox" name="cfg_cal_start_current_month" id="cfg_cal_start_current_month" <?php if($config['cal_start_current_month'] == 1) echo " checked"; ?>>
									</label>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_cal_show_week_number"><?php echo $tr->translate("cfgVal_cal_show_week_number"); ?></label>
								<div class="controls">
									<label class="">
										<input type="checkbox" name="cfg_cal_show_week_number" id="cfg_cal_show_week_number" <?php if($config['cal_show_week_number'] == 1) echo " checked"; ?>>
									</label>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_cal_8days_week"><?php echo $tr->translate("cfgVal_cal_8days_week"); ?></label>
								<div class="controls">
									<label class="">
										<input type="checkbox" name="cfg_cal_8days_week" id="cfg_cal_8days_week" <?php if($config['cal_8days_week'] == 1) echo " checked"; ?>>
									</label>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_cal_show_nomonth_days"><?php echo $tr->translate("cfgVal_cal_show_nomonth_days"); ?></label>
								<div class="controls">
									<label class="">
										<input type="checkbox" name="cfg_cal_show_nomonth_days" id="cfg_cal_show_nomonth_days" <?php if($config['cal_show_nomonth_days'] == 1) echo " checked"; ?>>
									</label>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_cal_show_reserv_option"><?php echo $tr->translate("cfgVal_cal_show_reserv_option"); ?></label>
								<div class="controls">
									<label class="">
										<input type="checkbox" name="cfg_cal_show_reserv_option" id="cfg_cal_show_reserv_option" <?php if($config['cal_show_reserv_option'] == 1) echo " checked"; ?>>
									</label>
								</div>
							</div>
						</div>

						<div class="tab-pane <?php if ($currentTab == "config_11") echo "active"; ?>" id="11a">
							<label class="control-label" for="cfg_color_cal_bgd"><?php echo $tr->translate("cfgVal_color_cal_bgd"); ?></label>
							<div class="control-group">
								<div class="controls">
									<div class="control-group">
										<div class="input-append">
											<div><span class="add-on"><i>#</i></span><input name="cfg_color_cal_bgd" id="cfg_color_cal_bgd" style="border: 0;border-right:20px solid #<?php echo ($config['color_cal_bgd']) ? $config['color_cal_bgd'] : "000000"; ?>;" type="text" class="input-small colorpicker" value="<?php echo ($config['color_cal_bgd']) ? $config['color_cal_bgd'] : "000000"; ?>"> <?php echo $tr->translate("BackgroundColor"); ?></div>
										</div>						
									</div>
								</div>
							</div>
							<label class="control-label" for="cfg_color_cal_free"><?php echo $tr->translate("cfgVal_color_cal_free"); ?></label>
							<div class="control-group">
								<div class="controls">
									<div class="control-group">
										<div class="input-append">
											<div><span class="add-on"><i>#</i></span><input name="cfg_color_cal_free_bgd" id="cfg_color_cal_free_bgd" style="border: 0;border-right:20px solid #<?php echo ($config['color_cal_free_bgd']) ? $config['color_cal_free_bgd'] : "000000"; ?>;" type="text" class="input-small colorpicker" value="<?php echo ($config['color_cal_free_bgd']) ? $config['color_cal_free_bgd'] : "000000"; ?>"> <?php echo $tr->translate("BackgroundColor"); ?></div>
											<div><span class="add-on"><i>#</i></span><input name="cfg_color_cal_free_txt" id="cfg_color_cal_free_txt" style="border: 0;border-right:20px solid #<?php echo ($config['color_cal_free_txt']) ? $config['color_cal_free_txt'] : "000000"; ?>;" type="text" class="input-small colorpicker" value="<?php echo ($config['color_cal_free_txt']) ? $config['color_cal_free_txt'] : "000000"; ?>"> <?php echo $tr->translate("TextColor"); ?></div>
										</div>						
									</div>
								</div>
							</div>
							<label class="control-label" for="cfg_color_cal_option"><?php echo $tr->translate("cfgVal_color_cal_option"); ?></label>
							<div class="control-group">
								<div class="controls">
									<div class="control-group">
										<div class="input-append">
											<div><span class="add-on"><i>#</i></span><input name="cfg_color_cal_option_bgd" id="cfg_color_cal_option_bgd" style="border: 0;border-right:20px solid #<?php echo ($config['color_cal_option_bgd']) ? $config['color_cal_option_bgd'] : "000000"; ?>;" type="text" class="input-small colorpicker" value="<?php echo ($config['color_cal_option_bgd']) ? $config['color_cal_option_bgd'] : "000000"; ?>"> <?php echo $tr->translate("BackgroundColor"); ?></div>
											<div><span class="add-on"><i>#</i></span><input name="cfg_color_cal_option_txt" id="cfg_color_cal_option_txt" style="border: 0;border-right:20px solid #<?php echo ($config['color_cal_option_txt']) ? $config['color_cal_option_txt'] : "000000"; ?>;" type="text" class="input-small colorpicker" value="<?php echo ($config['color_cal_option_txt']) ? $config['color_cal_option_txt'] : "000000"; ?>"> <?php echo $tr->translate("TextColor"); ?></div>
										</div>						
									</div>
								</div>
							</div>
							<label class="control-label" for="cfg_color_cal_booked"><?php echo $tr->translate("cfgVal_color_cal_booked"); ?></label>
							<div class="control-group">
								<div class="controls">
									<div class="control-group">
										<div class="input-append">
											<div><span class="add-on"><i>#</i></span><input name="cfg_color_cal_booked_bgd" id="cfg_color_cal_booked_bgd" style="border: 0;border-right:20px solid #<?php echo ($config['color_cal_booked_bgd']) ? $config['color_cal_booked_bgd'] : "000000"; ?>;" type="text" class="input-small colorpicker" value="<?php echo ($config['color_cal_booked_bgd']) ? $config['color_cal_booked_bgd'] : "000000"; ?>"> <?php echo $tr->translate("BackgroundColor"); ?></div>
											<div><span class="add-on"><i>#</i></span><input name="cfg_color_cal_booked_txt" id="cfg_color_cal_booked_txt" style="border: 0;border-right:20px solid #<?php echo ($config['color_cal_booked_txt']) ? $config['color_cal_booked_txt'] : "000000"; ?>;" type="text" class="input-small colorpicker" value="<?php echo ($config['color_cal_booked_txt']) ? $config['color_cal_booked_txt'] : "000000"; ?>"> <?php echo $tr->translate("TextColor"); ?></div>
										</div>						
									</div>
								</div>
							</div>

							<label class="control-label" for="cfg_color_season_na"><?php echo $tr->translate("cfgVal_color_season_na"); ?></label>
							<div class="control-group">
								<div class="controls">
									<div class="control-group">
										<div class="input-append">
											<div><span class="add-on"><i>#</i></span><input name="cfg_color_season_na_bgd" id="cfg_color_season_na_bgd" style="border: 0;border-right:20px solid #<?php echo ($config['color_season_na_bgd']) ? $config['color_season_na_bgd'] : "000000"; ?>;" type="text" class="input-small colorpicker" value="<?php echo ($config['color_season_na_bgd']) ? $config['color_season_na_bgd'] : "000000"; ?>"> <?php echo $tr->translate("BackgroundColor"); ?></div>
											<div><span class="add-on"><i>#</i></span><input name="cfg_color_season_na_txt" id="cfg_color_season_na_txt" style="border: 0;border-right:20px solid #<?php echo ($config['color_season_na_txt']) ? $config['color_season_na_txt'] : "000000"; ?>;" type="text" class="input-small colorpicker" value="<?php echo ($config['color_season_na_txt']) ? $config['color_season_na_txt'] : "000000"; ?>"> <?php echo $tr->translate("TextColor"); ?></div>
										</div>						
									</div>
								</div>
							</div>
							<label class="control-label" for="cfg_color_season_medium"><?php echo $tr->translate("cfgVal_color_season_medium"); ?></label>
							<div class="control-group">
								<div class="controls">
									<div class="control-group">
										<div class="input-append">
											<div><span class="add-on"><i>#</i></span><input name="cfg_color_season_medium_bgd" id="cfg_color_season_medium_bgd" style="border: 0;border-right:20px solid #<?php echo ($config['color_season_medium_bgd']) ? $config['color_season_medium_bgd'] : "000000"; ?>;" type="text" class="input-small colorpicker" value="<?php echo ($config['color_season_medium_bgd']) ? $config['color_season_medium_bgd'] : "000000"; ?>"> <?php echo $tr->translate("BackgroundColor"); ?></div>
											<div><span class="add-on"><i>#</i></span><input name="cfg_color_season_medium_txt" id="cfg_color_season_medium_txt" style="border: 0;border-right:20px solid #<?php echo ($config['color_season_medium_txt']) ? $config['color_season_medium_txt'] : "000000"; ?>;" type="text" class="input-small colorpicker" value="<?php echo ($config['color_season_medium_txt']) ? $config['color_season_medium_txt'] : "000000"; ?>"> <?php echo $tr->translate("TextColor"); ?></div>
										</div>						
									</div>
								</div>
							</div>
							<label class="control-label" for="cfg_color_season_high"><?php echo $tr->translate("cfgVal_color_season_high"); ?></label>
							<div class="control-group">
								<div class="controls">
									<div class="control-group">
										<div class="input-append">
											<div><span class="add-on"><i>#</i></span><input name="cfg_color_season_high_bgd" id="cfg_color_season_high_bgd" style="border: 0;border-right:20px solid #<?php echo ($config['color_season_high_bgd']) ? $config['color_season_high_bgd'] : "000000"; ?>;" type="text" class="input-small colorpicker"value="<?php echo ($config['color_season_high_bgd']) ? $config['color_season_high_bgd'] : "000000"; ?>"> <?php echo $tr->translate("BackgroundColor"); ?></div>
											<div><span class="add-on"><i>#</i></span><input name="cfg_color_season_high_txt" id="cfg_color_season_high_txt" style="border: 0;border-right:20px solid #<?php echo ($config['color_season_high_txt']) ? $config['color_season_high_txt'] : "000000"; ?>;" type="text" class="input-small colorpicker"value="<?php echo ($config['color_season_high_txt']) ? $config['color_season_high_txt'] : "000000"; ?>"> <?php echo $tr->translate("TextColor"); ?></div>
										</div>						
									</div>
								</div>
							</div>
							<label class="control-label" for="cfg_color_season_tophigh"><?php echo $tr->translate("cfgVal_color_season_tophigh"); ?></label>
							<div class="control-group">
								<div class="controls">
									<div class="control-group">
										<div class="input-append">
											<div><span class="add-on"><i>#</i></span><input name="cfg_color_season_tophigh_bgd" id="cfg_color_season_tophigh_bgd" style="border: 0;border-right:20px solid #<?php echo ($config['color_season_tophigh_bgd']) ? $config['color_season_tophigh_bgd'] : "000000"; ?>;" type="text" class="input-small colorpicker" value="<?php echo ($config['color_season_tophigh_bgd']) ? $config['color_season_tophigh_bgd'] : "000000"; ?>"> <?php echo $tr->translate("BackgroundColor"); ?></div>
											<div><span class="add-on"><i>#</i></span><input name="cfg_color_season_tophigh_txt" id="cfg_color_season_tophigh_txt" style="border: 0;border-right:20px solid #<?php echo ($config['color_season_tophigh_txt']) ? $config['color_season_tophigh_txt'] : "000000"; ?>;" type="text" class="input-small colorpicker" value="<?php echo ($config['color_season_tophigh_txt']) ? $config['color_season_tophigh_txt'] : "000000"; ?>"> <?php echo $tr->translate("TextColor"); ?></div>
										</div>						
									</div>
								</div>
							</div>
							<div class="control-group">
								<div class="controls">
									<button type="button" name="resetColor" id="resetColor" class="btn btn-mini btn-success"><?php echo $tr->translate("btnConfigResetColor"); ?></button>
								</div>
							</div>
						</div>

						<div class="tab-pane <?php if ($currentTab == "config_2") echo "active"; ?>" id="2a">
							<div class="control-group">
								<label class="control-label" for="cfg_mail_system"><?php echo $tr->translate("cfgVal_mail_system"); ?></label>
								<div class="controls">
									<label class="radio">
										<input type="radio" name="cfg_mail_system" id="cfg_mail_system3" value="2" <?php if($config['mail_system'] == 2) echo " checked"; ?>>
											<?php echo $tr->translate("cfgVal_mail_system_php"); ?>
									</label>
									<div style="clear:both"></div>
									<label class="radio">
										<input type="radio" name="cfg_mail_system" id="cfg_mail_system1" value="0" <?php if($config['mail_system'] == 0) echo " checked"; ?>>
											<?php echo $tr->translate("cfgVal_mail_system_internal"); ?>
									</label>
									<div style="clear:both"></div>
								</div>
							</div>
							<div class="control-group">
								<div class="controls">
									<button type="button" name="testMail" id="testMail" class="btn btn-mini btn-success"><?php echo $tr->translate("btnConfigSendTestMail"); ?></button>
								</div>
							</div>
						</div>

						<div class="tab-pane <?php if ($currentTab == "config_4") echo "active"; ?>" id="4a">
							<div class="control-group">
								<label class="control-label" for="cfg_log_enabled"><?php echo $tr->translate("cfgVal_log_enabled"); ?></label>
								<div class="controls">
									<input type="checkbox" id="cfg_log_enabled" name="cfg_log_enabled" <?php if($config['log_enabled'] == 1) echo " checked"; ?>>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_delete_log_older_than"><?php echo $tr->translate("cfgVal_delete_log_older_than"); ?></label>
								<div class="controls">
									<div class="input-prepend">
										<a href="#"><span class="add-on icon-minus-sign qtyminus" data-field="cfg_delete_log_older_than"></span></a><input class="input-mini" type="text" id="cfg_delete_log_older_than" name="cfg_delete_log_older_than" value="<?php echo $config['delete_log_older_than']; ?>"></span><a href="#"><span class="add-on icon-plus-sign qtyplus" data-field="cfg_delete_log_older_than"></span></a>
									</div>
								</div>
							</div>
						</div>
						<div class="tab-pane <?php if ($currentTab == "config_5") echo "active"; ?>" id="5a">
							<div class="control-group">
								<label class="control-label" for="cfg_lease_keep_on_server"><?php echo $tr->translate("cfgVal_lease_keep_on_server"); ?></label>
								<div class="controls">
									<input type="checkbox" id="cfg_lease_keep_on_server" name="cfg_lease_keep_on_server" <?php if($config['lease_keep_on_server'] == 1) echo " checked"; ?>>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_lease_filename"><?php echo $tr->translate("cfgVal_lease_filename"); ?></label>
								<div class="controls">
									<div class="input-prepend">
										<input class="input-xxlarge" type="text" id="cfg_lease_filename" name="cfg_lease_filename" value="<?php echo $config['lease_filename']; ?>"><span class="add-on"><i>.pdf</i></span>
									</div>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_lease_create_2copy"><?php echo $tr->translate("cfgVal_lease_create_2copy"); ?></label>
								<div class="controls">
									<input type="checkbox" id="cfg_lease_create_2copy" name="cfg_lease_create_2copy" <?php if($config['lease_create_2copy'] == 1) echo " checked"; ?>>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_lease_dateline"><?php echo $tr->translate("cfgVal_lease_dateline"); ?></label>
								<div class="controls">
									<div class="input-prepend">
										<a href="#"><span class="add-on icon-minus-sign qtyminus" data-field="cfg_lease_dateline"></span></a><input class="input-mini" type="text" id="cfg_lease_dateline" name="cfg_lease_dateline" value="<?php echo $config['lease_dateline']; ?>"></span><a href="#"><span class="add-on icon-plus-sign qtyplus" data-field="cfg_lease_dateline"></span></a>
									</div>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_balance_dateline"><?php echo $tr->translate("cfgVal_balance_dateline"); ?></label>
								<div class="controls">
									<div class="input-prepend">
										<a href="#"><span class="add-on icon-minus-sign qtyminus" data-field="cfg_balance_dateline"></span></a><input class="input-mini" type="text" id="cfg_balance_dateline" name="cfg_balance_dateline" value="<?php echo $config['balance_dateline']; ?>"></span><a href="#"><span class="add-on icon-plus-sign qtyplus" data-field="cfg_balance_dateline"></span></a>
									</div>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_lease_deposit_percent"><?php echo $tr->translate("cfgVal_lease_deposit_percent"); ?></label>
								<div class="controls">
									<div class="input-prepend">
										<a href="#"><span class="add-on icon-minus-sign qtyminus" data-field="cfg_lease_deposit_percent"></span></a><input type="text" class="input-mini" id="cfg_lease_deposit_percent" name="cfg_lease_deposit_percent" value="<?php echo $config['lease_deposit_percent']; ?>"><span class="add-on"><i>%</i></span><a href="#"><span class="add-on icon-plus-sign qtyplus" data-field="cfg_lease_deposit_percent"></span></a>
									</div>
								</div>
							</div>
						</div>
						<div class="tab-pane <?php if ($currentTab == "config_6") echo "active"; ?>" id="6a">
							<div class="control-group">
								<label class="control-label" for="cfg_db_backup_enabled"><?php echo $tr->translate("cfgVal_db_backup_enabled"); ?></label>
								<div class="controls">
									<input type="checkbox" id="cfg_db_backup_enabled" name="cfg_db_backup_enabled" <?php if($config['db_backup_enabled'] == 1) echo " checked"; ?>>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_delete_backup_older_than"><?php echo $tr->translate("cfgVal_delete_backup_older_than"); ?></label>
								<div class="controls">
									<div class="input-prepend">
										<a href="#"><span class="add-on icon-minus-sign qtyminus" data-field="cfg_delete_backup_older_than"></span></a><input class="input-mini" type="text" id="cfg_delete_backup_older_than" name="cfg_delete_backup_older_than" value="<?php echo $config['delete_backup_older_than']; ?>"></span><a href="#"><span class="add-on icon-plus-sign qtyplus" data-field="cfg_delete_backup_older_than"></span></a>
									</div>
								</div>
							</div>
						</div>
						<div class="tab-pane <?php if ($currentTab == "config_7") echo "active"; ?>" id="7a">
							<div class="control-group">
								<label class="control-label" for="cfg_renter_title"><?php echo $tr->translate("cfgVal_renter_title"); ?></label>
								<div class="controls">
									<select class="input-medium" name="cfg_renter_title" id="cfg_renter_title">
										<option value=""></option>
										<?php $arrTitle = $tr->translate("thUserformTitles");
											foreach($arrTitle as $title) { ?>
												<option value="<?php echo $title; ?>" <?php if ($title == $config['renter_title']) echo " selected"; ?>><?php echo $title; ?></option>
										<?php } ?>
									</select>
								</div> 
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_renter_lastname"><?php echo $tr->translate("cfgVal_renter_lastname"); ?></label>
								<div class="controls">
									<input class="span3" type="text" id="cfg_renter_lastname" name="cfg_renter_lastname" value="<?php echo $config['renter_lastname']; ?>">
								</div>
							</div>

							<div class="control-group">
								<label class="control-label" for="cfg_renter_name"><?php echo $tr->translate("cfgVal_renter_name"); ?></label>
								<div class="controls">
									<input class="span3" type="text" id="cfg_renter_name" name="cfg_renter_name" value="<?php echo $config['renter_name']; ?>">
								</div>
							</div>    

							<div class="control-group">
								<label class="control-label" for="cfg_renter_address"><?php echo $tr->translate("cfgVal_renter_address"); ?></label>
								<div class="controls">
									<input class="span3" type="text" id="cfg_renter_address" name="cfg_renter_address" value="<?php echo $config['renter_address']; ?>">
								</div>
							</div>

							<div class="control-group">
								<label class="control-label" for="cfg_renter_zipcode"><?php echo $tr->translate("cfgVal_renter_zipcode"); ?></label>
								<div class="controls">
									<input class="span3" type="text" id="cfg_renter_zipcode" name="cfg_renter_zipcode" value="<?php echo $config['renter_zipcode']; ?>">
								</div>
							</div>

							<div class="control-group">
								<label class="control-label" for="cfg_renter_city"><?php echo $tr->translate("cfgVal_renter_city"); ?></label>
								<div class="controls">
									<input class="span3" type="text" id="cfg_renter_city" name="cfg_renter_city" value="<?php echo $config['renter_city']; ?>">
								</div>
							</div>

							<div class="control-group">
								<label class="control-label" for="cfg_renter_country"><?php echo $tr->translate("cfgVal_renter_country"); ?></label>
								<div class="controls">
									<input class="span3" type="text" id="cfg_renter_country" name="cfg_renter_country" value="<?php echo $config['renter_country']; ?>">
								</div>
							</div>

							<div class="control-group">
								<label class="control-label" for="cfg_renter_phone"><?php echo $tr->translate("cfgVal_renter_phone"); ?> *</label>
								<div class="controls">
									<input class="span3" type="text" id="cfg_renter_phone" name="cfg_renter_phone" value="<?php echo $config['renter_phone']; ?>">
								</div>
							</div>

							<div class="control-group">
								<label class="control-label" for="cfg_renter_mobile"><?php echo $tr->translate("cfgVal_renter_mobile"); ?> *</label>
								<div class="controls">
									<input class="span3" type="text" id="cfg_renter_mobile" name="cfg_renter_mobile" value="<?php echo $config['renter_mobile']; ?>">
								</div>
							</div> 

							<div class="control-group">
								<label class="control-label" for="cfg_renter_email"><?php echo $tr->translate("cfgVal_renter_email"); ?></label>
								<div class="controls">
									<input class="span3" type="text" id="cfg_renter_email" name="cfg_renter_email" value="<?php echo $config['renter_email']; ?>">
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="cfg_renter_url"><?php echo $tr->translate("cfgVal_renter_url"); ?></label>
								<div class="controls">
									<input class="span3" type="text" id="cfg_renter_url" name="cfg_renter_url" value="<?php echo $config['renter_url']; ?>">
								</div>
							</div>
							<p>* <?php echo $tr->translate("cfgVal_renter_message"); ?></p>
							<p class="hidden"> <span class="label label-info">Astuce</span>   Les éléments saisis dans ce formulaire seront repris dans <a href="lease.php">les contrats </a>et les <a href="mailing.php"> email envoyés aux locataires</a>.</p>
						</div>
					</div>
					<div class="form-actions">
						<button type="button" name="save" id="save" class="btn btn-primary"><?php echo $tr->translate("btnConfigSave"); ?></button>
					</div>
					</div>
				</div>
            </div>
			</form>
			</div>	
		</div><!--/span-->
		
	</div><!--/row-->
	<div class="row-fluid sortable" id="editReservation">
	</div><!--/row--> 
<?php require "../_container/container_bottom.php"; ?> 

<script>
$(document).ready(function() {
	$("input[name='cfg_mail_system']:checked").trigger("click");

	$('.colorpicker').click(function(e){
		// alert($(this).val());
	});

	$('.colorpicker').colpick({
		colorScheme:'light',
		layout:'full',
		submit:false,
		onBeforeShow:function(hsb,hex,rgb,el,bySetColor) {
			$(this).colpickSetColor($(this).val());
		},
		onChange:function(hsb,hex,rgb,el,bySetColor) {
			$(el).css('border-color','#'+hex);
			// Fill the text box just if the color was set using the picker, and not the colpickSetColor function.
			if(!bySetColor) $(el).val(hex);
		}
	}).keyup(function(){
		$(this).colpickSetColor(this.value);
	});
	$('#cfg_invoice_text1').maxlength({
		alwaysShow: true
	});
});


$('#testMail').click(function(e){
	$('#action').val("testMail");
	$('#currentTab').val($("ul#optionTab li.active").attr('id'));
	blockUI();
	configForm.submit();
});

$('#resetColor').click(function(e){
	$('#action').val("resetColor");
	$('#currentTab').val($("ul#optionTab li.active").attr('id'));
	blockUI();
	configForm.submit();
});

$('#save').click(function(e){
	e.preventDefault();
	$('#action').val("save");
	$('#currentTab').val($("ul#optionTab li.active").attr('id'));
	blockUI();
	configForm.submit();
});

</script>