<?php
if($_GET['controller'] == 'pjAdminOptions')
{
	pjUtil::printNotice(__('infoOwnersNotificaionsTitle', true), __('infoOwnersNotificaionsDesc', true));
}else{
	pjUtil::printNotice(__('infoOwnersNotificaions2Title', true), __('infoOwnersNotificaions2Desc', true));
} 
?>
<div class="multilang"></div>
<br/><br/>

<fieldset class="fieldset white">
	<legend><?php __('lblLegendBookingsEmails');?></legend>
	<table class="pj-table" cellpadding="0" cellspacing="0" style="width: 100%">
		<thead>
			<tr>
				<th><?php __('lblOption'); ?></th>
				<th><?php __('lblValue'); ?></th>
			</tr>
		</thead>
		<tbody>
			<?php
			for ($i = 0; $i < $count; $i++)
			{
				if ($tpl['arr'][$i]['tab_id'] == 5 && (int) $tpl['arr'][$i]['is_visible'] === 1 && (strpos($tpl['arr'][$i]['key'], 'email') > -1))
				{
				
					$rowClass = NULL;
					$rowStyle = NULL;
					if (in_array($tpl['arr'][$i]['key'], array('o_owner_email_confirmation_subject', 'o_owner_email_confirmation_message')))
					{
						$rowClass = " boxOwnerConfirmation";
						$rowStyle = "display: none";
						switch ($tpl['option_arr']['o_owner_email_confirmation'])
						{
							case '1':
								$rowStyle = NULL;
								break;
						}
					}
					if (in_array($tpl['arr'][$i]['key'], array('o_owner_email_payment_subject', 'o_owner_email_payment_message')))
					{
						$rowClass = " boxOwnerPayment";
						$rowStyle = "display: none";
						switch ($tpl['option_arr']['o_owner_email_payment'])
						{
							case '1':
								$rowStyle = NULL;
								break;
						}
					}
					if (in_array($tpl['arr'][$i]['key'], array('o_owner_email_cancel_subject', 'o_owner_email_cancel_message')))
					{
						$rowClass = " boxOwnerCancel";
						$rowStyle = "display: none";
						switch ($tpl['option_arr']['o_owner_email_cancel'])
						{
							case '1':
								$rowStyle = NULL;
								break;
						}
					}
					?>
					<tr class="pj-table-row-odd<?php echo $rowClass; ?>" style="<?php echo $rowStyle; ?>">
						<td width="35%" valign="top">
							<span class="block bold"><?php __('opt_' . $tpl['arr'][$i]['key']); ?></span>
							<?php
							if(in_array($tpl['arr'][$i]['key'], array('o_owner_email_confirmation_message','o_owner_email_payment_message','o_owner_email_cancel_message')))
							{ 
								?><span class="fs10"><?php echo nl2br(__('lblBookingTokens', true)); ?></span><?php 
							}else{
								?><span class="fs10"><?php __('opt_' . $tpl['arr'][$i]['key'] . '_text'); ?></span><?php
							}								
							?>
						</td>
						<td valign="top">
							<?php
							switch ($tpl['arr'][$i]['type'])
							{
								case 'string':
									if(in_array($tpl['arr'][$i]['key'], array('o_owner_email_confirmation_subject','o_owner_email_payment_subject','o_owner_email_cancel_subject')))
									{
									?>
										<?php
											foreach ($tpl['lp_arr'] as $v)
											{
												?>
												<p class="pj-multilang-wrap" data-index="<?php echo $v['id']; ?>" style="display: <?php echo (int) $v['is_default'] === 0 ? 'none' : NULL; ?>">
													<span class="inline_block">
														<input type="text" name="i18n[<?php echo $v['id']; ?>][<?php echo $tpl['arr'][$i]['key'] ?>]" class="pj-form-field w400" value="<?php echo pjSanitize::html(@$tpl['arr']['i18n'][$v['id']][$tpl['arr'][$i]['key']]); ?>" />
														<span class="pj-multilang-input"><img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $v['file']; ?>" alt="" /></span>
													</span>
												</p>
												<?php
											}
										?>
									<?php
									}
									else { ?>
										<input type="text" name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field w400" value="<?php echo pjSanitize::html($tpl['arr'][$i]['value']); ?>" />
									<?php }
									break;
								case 'text':
									
									if(in_array($tpl['arr'][$i]['key'], array('o_owner_email_cancel_message', 'o_owner_email_confirmation_message', 'o_owner_email_payment_message')))
									{
									?>
										<?php
											foreach ($tpl['lp_arr'] as $v)
											{
												?>
												<p class="pj-multilang-wrap" data-index="<?php echo $v['id']; ?>" style="display: <?php echo (int) $v['is_default'] === 0 ? 'none' : NULL; ?>">
													<span class="inline_block">
														<textarea name="i18n[<?php echo $v['id']; ?>][<?php echo $tpl['arr'][$i]['key'] ?>]" class="pj-form-field" style="width: 400px; height: 400px;"><?php echo pjSanitize::html(@$tpl['arr']['i18n'][$v['id']][$tpl['arr'][$i]['key']]); ?></textarea>
														<span class="pj-multilang-input"><img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $v['file']; ?>" alt="" /></span>
													</span>
												</p>
												<?php
											}
										?>
										
									<?php
									}
									else { ?>
										<textarea name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field" style="width: 460px; height: 400px;"><?php echo pjSanitize::html($tpl['arr'][$i]['value']); ?></textarea>
									<?php }
											
									break;
								case 'int':
								    ?><input type="text" name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field field-int w60" value="<?php echo pjSanitize::html($tpl['arr'][$i]['value']); ?>" /><?php
									break;
								case 'float':
								    ?><input type="text" name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field field-float w60" value="<?php echo pjSanitize::html($tpl['arr'][$i]['value']); ?>" /><?php
									break;
								case 'enum':
									?><select name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field">
									<?php
									$default = explode("::", $tpl['arr'][$i]['value']);
									$enum = explode("|", $default[0]);
									
									$enumLabels = array();
									if (!empty($tpl['arr'][$i]['label']) && strpos($tpl['arr'][$i]['label'], "|") !== false)
									{
										$enumLabels = explode("|", $tpl['arr'][$i]['label']);
									}
									
									foreach ($enum as $k => $el)
									{
										if ($default[1] == $el)
										{
											?><option value="<?php echo $default[0].'::'.$el; ?>" selected="selected"><?php echo array_key_exists($k, $enumLabels) ? stripslashes($enumLabels[$k]) : stripslashes($el); ?></option><?php
										} else {
											?><option value="<?php echo $default[0].'::'.$el; ?>"><?php echo array_key_exists($k, $enumLabels) ? stripslashes($enumLabels[$k]) : stripslashes($el); ?></option><?php
										}
									}
									?>
									</select>
									<?php
									break;
							}
							?>
						</td>
					</tr>
					<?php
				}
			}
			?>
		</tbody>
	</table>
</fieldset>

<fieldset class="fieldset white">
	<legend><?php __('lblLegendBookingsSMS');?></legend>
	<table class="pj-table" cellpadding="0" cellspacing="0" style="width: 100%">
		<thead>
			<tr>
				<th><?php __('lblOption'); ?></th>
				<th><?php __('lblValue'); ?></th>
			</tr>
		</thead>
		<tbody>
			<?php
			for ($i = 0; $i < $count; $i++)
			{
				if ($tpl['arr'][$i]['tab_id'] == 5 && (int) $tpl['arr'][$i]['is_visible'] === 1 && (strpos($tpl['arr'][$i]['key'], 'sms') > -1))
				{
					$rowClass = NULL;
					$rowStyle = NULL;
					
					?>
					<tr class="pj-table-row-odd<?php echo $rowClass; ?>" style="<?php echo $rowStyle; ?>">
						<td width="35%" valign="top">
							<span class="block bold"><?php __('opt_' . $tpl['arr'][$i]['key']); ?></span>
							<span class="fs10"><?php echo nl2br(__('lblBookingSMSTokens', true)); ?></span>
						</td>
						<td valign="top">
							<?php
							switch ($tpl['arr'][$i]['type'])
							{
								case 'string':
									?>
										<input type="text" name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field w400" value="<?php echo pjSanitize::html($tpl['arr'][$i]['value']); ?>" />
									<?php 
									break;
								case 'text':
									if(in_array($tpl['arr'][$i]['key'], array('o_owner_sms_confirmation_message', 'o_owner_sms_payment_message')))
									{
										foreach ($tpl['lp_arr'] as $v)
										{
											?>
											<p class="pj-multilang-wrap" data-index="<?php echo $v['id']; ?>" style="display: <?php echo (int) $v['is_default'] === 0 ? 'none' : NULL; ?>">
												<span class="inline_block">
													<textarea name="i18n[<?php echo $v['id']; ?>][<?php echo $tpl['arr'][$i]['key'] ?>]" class="pj-form-field" style="width: 400px; height: 200px;"><?php echo pjSanitize::html(@$tpl['arr']['i18n'][$v['id']][$tpl['arr'][$i]['key']]); ?></textarea>
													<span class="pj-multilang-input"><img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $v['file']; ?>" alt="" /></span>
												</span>
											</p>
											<?php
										}
									}else { 
										?>
										<textarea name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field" style="width: 460px; height: 400px;"><?php echo pjSanitize::html($tpl['arr'][$i]['value']); ?></textarea>
										<?php 
									}	
									break;
								case 'int':
								    ?><input type="text" name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field field-int w60" value="<?php echo pjSanitize::html($tpl['arr'][$i]['value']); ?>" /><?php
									break;
								case 'float':
								    ?><input type="text" name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field field-float w60" value="<?php echo pjSanitize::html($tpl['arr'][$i]['value']); ?>" /><?php
									break;
								case 'enum':
									?><select name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field">
									<?php
									$default = explode("::", $tpl['arr'][$i]['value']);
									$enum = explode("|", $default[0]);
									
									$enumLabels = array();
									if (!empty($tpl['arr'][$i]['label']) && strpos($tpl['arr'][$i]['label'], "|") !== false)
									{
										$enumLabels = explode("|", $tpl['arr'][$i]['label']);
									}
									
									foreach ($enum as $k => $el)
									{
										if ($default[1] == $el)
										{
											?><option value="<?php echo $default[0].'::'.$el; ?>" selected="selected"><?php echo array_key_exists($k, $enumLabels) ? stripslashes($enumLabels[$k]) : stripslashes($el); ?></option><?php
										} else {
											?><option value="<?php echo $default[0].'::'.$el; ?>"><?php echo array_key_exists($k, $enumLabels) ? stripslashes($enumLabels[$k]) : stripslashes($el); ?></option><?php
										}
									}
									?>
									</select>
									<?php
									break;
							}
							?>
						</td>
					</tr>
					<?php
				}
			}
			?>
		</tbody>
	</table>
</fieldset>

<?php
if($controller->isAdmin() && $_GET['controller'] == 'pjAdminOptions')
{
	?>
	<fieldset class="fieldset white">
		<legend><?php __('lblLegendAccountEmails');?></legend>
		<table class="pj-table" cellpadding="0" cellspacing="0" style="width: 100%">
			<thead>
				<tr>
					<th><?php __('lblOption'); ?></th>
					<th><?php __('lblValue'); ?></th>
				</tr>
			</thead>
			<tbody>
				<?php
				for ($i = 0; $i < $count; $i++)
				{
					if ($tpl['arr'][$i]['tab_id'] == 6 && (int) $tpl['arr'][$i]['is_visible'] === 1 && (strpos($tpl['arr'][$i]['key'], 'email') > -1))
					{
					
						$rowClass = NULL;
						$rowStyle = NULL;
						if (in_array($tpl['arr'][$i]['key'], array('o_email_registration_subject', 'o_email_registration_message')))
						{
							$rowClass = " boxOwnerRegistration";
							$rowStyle = "display: none";
							switch ($tpl['option_arr']['o_email_registration'])
							{
								case '1':
									$rowStyle = NULL;
									break;
							}
						}
						if (in_array($tpl['arr'][$i]['key'], array('o_email_submission_subject', 'o_email_submission_message')))
						{
							$rowClass = " boxOwnerSubmission";
							$rowStyle = "display: none";
							switch ($tpl['option_arr']['o_email_submission'])
							{
								case '1':
									$rowStyle = NULL;
									break;
							}
						}
						$opt_text = __('opt_' . $tpl['arr'][$i]['key'] . '_text', true);
						?>
						<tr class="pj-table-row-odd<?php echo $rowClass; ?>" style="<?php echo $rowStyle; ?>">
							<td width="35%" valign="top">
								<span class="block bold"><?php __('opt_' . $tpl['arr'][$i]['key']); ?></span>
								<?php if (!empty($opt_text)) { ?>
									<span class="fs10"><?php echo nl2br($opt_text); ?></span>
								<?php } ?>
							</td>
							<td valign="top">
								<?php
								switch ($tpl['arr'][$i]['type'])
								{
									case 'string':
										if(in_array($tpl['arr'][$i]['key'], array('o_email_registration_subject','o_email_submission_subject','o_email_forgot_subject')))
										{
										?>
											<?php
												foreach ($tpl['lp_arr'] as $v)
												{
													?>
													<p class="pj-multilang-wrap" data-index="<?php echo $v['id']; ?>" style="display: <?php echo (int) $v['is_default'] === 0 ? 'none' : NULL; ?>">
														<span class="inline_block">
															<input type="text" name="i18n[<?php echo $v['id']; ?>][<?php echo $tpl['arr'][$i]['key'] ?>]" class="pj-form-field w400" value="<?php echo pjSanitize::html(@$tpl['arr']['i18n'][$v['id']][$tpl['arr'][$i]['key']]); ?>" />
															<span class="pj-multilang-input"><img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $v['file']; ?>" alt="" /></span>
														</span>
													</p>
													<?php
												}
											?>
										<?php
										}
										else { ?>
											<input type="text" name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field w400" value="<?php echo pjSanitize::html($tpl['arr'][$i]['value']); ?>" />
										<?php }
										break;
									case 'text':
										
										if(in_array($tpl['arr'][$i]['key'], array('o_email_registration_message','o_email_submission_message','o_email_forgot_message')))
										{
										?>
											<?php
												foreach ($tpl['lp_arr'] as $v)
												{
													?>
													<p class="pj-multilang-wrap" data-index="<?php echo $v['id']; ?>" style="display: <?php echo (int) $v['is_default'] === 0 ? 'none' : NULL; ?>">
														<span class="inline_block">
															<textarea name="i18n[<?php echo $v['id']; ?>][<?php echo $tpl['arr'][$i]['key'] ?>]" class="pj-form-field" style="width: 400px; height: 200px;"><?php echo pjSanitize::html(@$tpl['arr']['i18n'][$v['id']][$tpl['arr'][$i]['key']]); ?></textarea>
															<span class="pj-multilang-input"><img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $v['file']; ?>" alt="" /></span>
														</span>
													</p>
													<?php
												}
											?>
											
										<?php
										}
										else { ?>
											<textarea name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field" style="width: 460px; height: 400px;"><?php echo pjSanitize::html($tpl['arr'][$i]['value']); ?></textarea>
										<?php }
												
										break;
									case 'int':
									    ?><input type="text" name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field field-int w60" value="<?php echo pjSanitize::html($tpl['arr'][$i]['value']); ?>" /><?php
										break;
									case 'float':
									    ?><input type="text" name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field field-float w60" value="<?php echo pjSanitize::html($tpl['arr'][$i]['value']); ?>" /><?php
										break;
									case 'enum':
										?><select name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field">
										<?php
										$default = explode("::", $tpl['arr'][$i]['value']);
										$enum = explode("|", $default[0]);
										
										$enumLabels = array();
										if (!empty($tpl['arr'][$i]['label']) && strpos($tpl['arr'][$i]['label'], "|") !== false)
										{
											$enumLabels = explode("|", $tpl['arr'][$i]['label']);
										}
										
										foreach ($enum as $k => $el)
										{
											if ($default[1] == $el)
											{
												?><option value="<?php echo $default[0].'::'.$el; ?>" selected="selected"><?php echo array_key_exists($k, $enumLabels) ? stripslashes($enumLabels[$k]) : stripslashes($el); ?></option><?php
											} else {
												?><option value="<?php echo $default[0].'::'.$el; ?>"><?php echo array_key_exists($k, $enumLabels) ? stripslashes($enumLabels[$k]) : stripslashes($el); ?></option><?php
											}
										}
										?>
										</select>
										<?php
										break;
								}
								?>
							</td>
						</tr>
						<?php
					}
				}
				?>
			</tbody>
		</table>
	</fieldset>
	
	<fieldset class="fieldset white">
		<legend><?php __('lblLegendAccountSMS');?></legend>
		<table class="pj-table" cellpadding="0" cellspacing="0" style="width: 100%">
			<thead>
				<tr>
					<th><?php __('lblOption'); ?></th>
					<th><?php __('lblValue'); ?></th>
				</tr>
			</thead>
			<tbody>
				<?php
				for ($i = 0; $i < $count; $i++)
				{
					if ($tpl['arr'][$i]['tab_id'] == 6 && (int) $tpl['arr'][$i]['is_visible'] === 1 && (strpos($tpl['arr'][$i]['key'], 'sms') > -1))
					{
						$rowClass = NULL;
						$rowStyle = NULL;
						if (in_array($tpl['arr'][$i]['key'], array('o_sms_registration_message')))
						{
							$rowClass = " boxOwnerSMSRegistration";
							$rowStyle = "display: none";
							switch ($tpl['option_arr']['o_sms_registration'])
							{
								case '1':
									$rowStyle = NULL;
									break;
							}
						}
						if (in_array($tpl['arr'][$i]['key'], array('o_sms_submission_message')))
						{
							$rowClass = " boxOwnerSMSSubmission";
							$rowStyle = "display: none";
							switch ($tpl['option_arr']['o_sms_submission'])
							{
								case '1':
									$rowStyle = NULL;
									break;
							}
						}
						$opt_text = __('opt_' . $tpl['arr'][$i]['key'] . '_text', true);
						?>
						<tr class="pj-table-row-odd<?php echo $rowClass; ?>" style="<?php echo $rowStyle; ?>">
							<td width="35%" valign="top">
								<span class="block bold"><?php __('opt_' . $tpl['arr'][$i]['key']); ?></span>
								<?php if (!empty($opt_text)) { ?>
									<span class="fs10"><?php echo nl2br($opt_text); ?></span>
								<?php } ?>
							</td>
							<td valign="top">
								<?php
								switch ($tpl['arr'][$i]['type'])
								{
									case 'string':
										?>
											<input type="text" name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field w400" value="<?php echo pjSanitize::html($tpl['arr'][$i]['value']); ?>" />
										<?php 
										break;
									case 'text':
										if(in_array($tpl['arr'][$i]['key'], array('o_sms_registration_message', 'o_sms_submission_message')))
										{
											foreach ($tpl['lp_arr'] as $v)
											{
												?>
												<p class="pj-multilang-wrap" data-index="<?php echo $v['id']; ?>" style="display: <?php echo (int) $v['is_default'] === 0 ? 'none' : NULL; ?>">
													<span class="inline_block">
														<textarea name="i18n[<?php echo $v['id']; ?>][<?php echo $tpl['arr'][$i]['key'] ?>]" class="pj-form-field" style="width: 400px; height: 200px;"><?php echo pjSanitize::html(@$tpl['arr']['i18n'][$v['id']][$tpl['arr'][$i]['key']]); ?></textarea>
														<span class="pj-multilang-input"><img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $v['file']; ?>" alt="" /></span>
													</span>
												</p>
												<?php
											}
										}else { 
											?>
											<textarea name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field" style="width: 460px; height: 400px;"><?php echo pjSanitize::html($tpl['arr'][$i]['value']); ?></textarea>
											<?php 
										}	
										break;
									case 'int':
									    ?><input type="text" name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field field-int w60" value="<?php echo pjSanitize::html($tpl['arr'][$i]['value']); ?>" /><?php
										break;
									case 'float':
									    ?><input type="text" name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field field-float w60" value="<?php echo pjSanitize::html($tpl['arr'][$i]['value']); ?>" /><?php
										break;
									case 'enum':
										?><select name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field">
										<?php
										$default = explode("::", $tpl['arr'][$i]['value']);
										$enum = explode("|", $default[0]);
										
										$enumLabels = array();
										if (!empty($tpl['arr'][$i]['label']) && strpos($tpl['arr'][$i]['label'], "|") !== false)
										{
											$enumLabels = explode("|", $tpl['arr'][$i]['label']);
										}
										
										foreach ($enum as $k => $el)
										{
											if ($default[1] == $el)
											{
												?><option value="<?php echo $default[0].'::'.$el; ?>" selected="selected"><?php echo array_key_exists($k, $enumLabels) ? stripslashes($enumLabels[$k]) : stripslashes($el); ?></option><?php
											} else {
												?><option value="<?php echo $default[0].'::'.$el; ?>"><?php echo array_key_exists($k, $enumLabels) ? stripslashes($enumLabels[$k]) : stripslashes($el); ?></option><?php
											}
										}
										?>
										</select>
										<?php
										break;
								}
								?>
							</td>
						</tr>
						<?php
					}
				}
				?>
			</tbody>
		</table>
	</fieldset>
	<?php
} 
?>

<p><input type="submit" value="<?php __('btnSave'); ?>" class="pj-button" /></p>