<?php
if (isset($tpl['status']))
{
	$status = __('status', true);
	switch ($tpl['status'])
	{
		case 2:
			pjUtil::printNotice(NULL, $status[2]);
			break;
	}
} else {
	if (isset($_GET['err']))
	{
		$titles = __('error_titles', true);
		$bodies = __('error_bodies', true);
		pjUtil::printNotice(@$titles[$_GET['err']], @$bodies[$_GET['err']]);
	}
	include_once PJ_VIEWS_PATH . 'pjLayouts/elements/optmenu.php';
	if (isset($tpl['arr']))
	{
		if (is_array($tpl['arr']))
		{
			$count = count($tpl['arr']);
			if ($count > 0)
			{
				?>
				<form id="frmUpdateOptions" action="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminOptions&amp;action=pjActionUpdate" method="post" class="form pj-form">
					<input type="hidden" name="options_update" value="1" />
					<input type="hidden" name="next_action" value="pjActionIndex" />
					<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'] != 1 || (int) $tpl['arr'][$i]['is_visible'] === 0) continue;
					$rowClass = NULL;
					$rowStyle = NULL;
					if (in_array($tpl['arr'][$i]['key'], array('o_smtp_host', 'o_smtp_port', 'o_smtp_user', 'o_smtp_pass')))
					{
						$rowClass = " boxSmtp";
						$rowStyle = "display: none";
						switch ($tpl['option_arr']['o_send_email'])
						{
							case 'smtp':
								$rowStyle = NULL;
								break;
						}
					}
					if (in_array($tpl['arr'][$i]['key'], array('o_facebook_app_id', 'o_facebook_app_secret')))
					{
						$rowClass = " boxFacebook";
						$rowStyle = "display: none";
						switch ($tpl['option_arr']['o_facebook_allow'])
						{
							case 'Yes':
								$rowStyle = NULL;
								break;
						}
					}
					if (in_array($tpl['arr'][$i]['key'], array('o_google_client_id', 'o_google_client_secret')))
					{
						$rowClass = " boxGoogle";
						$rowStyle = "display: none";
						switch ($tpl['option_arr']['o_google_allow'])
						{
							case 'Yes':
								$rowStyle = NULL;
								break;
						}
					}
					?>
					<tr class="pj-table-row-odd<?php echo $rowClass; ?>" style="<?php echo $rowStyle; ?>">
						<td>
							<?php
							if($tpl['arr'][$i]['key'] == 'o_thankyou_page')
							{
								?><span class="title-tooltip"><?php __('opt_' . $tpl['arr'][$i]['key']);?></span>&nbsp;<a href="#" class="pj-form-langbar-tip listing-tip" title="<?php __('lblThankYouPageTip'); ?>"></a><?php 
							}else if($tpl['arr'][$i]['key'] == 'o_protected_page'){
								?><span class="title-tooltip"><?php __('opt_' . $tpl['arr'][$i]['key']);?></span>&nbsp;<a href="#" class="pj-form-langbar-tip listing-tip" title="<?php __('lblProtectedPageTip'); ?>"></a><?php 
							}else if($tpl['arr'][$i]['key'] == 'o_login_page'){
								?><span class="title-tooltip"><?php __('opt_' . $tpl['arr'][$i]['key']);?></span>&nbsp;<a href="#" class="pj-form-langbar-tip listing-tip" title="<?php __('lblLoginPageTip'); ?>"></a><?php 
							}else{ 
								__('opt_' . $tpl['arr'][$i]['key']);
							} 
							?>
						</td>
						<td>
							<?php
							switch ($tpl['arr'][$i]['type'])
							{
								case 'string':
									if($tpl['arr'][$i]['key'] == 'o_thankyou_page' || $tpl['arr'][$i]['key'] == 'o_protected_page' || $tpl['arr'][$i]['key'] == 'o_login_page')
									{
										?>
										<span class="pj-form-field-custom pj-form-field-custom-before">
											<span class="pj-form-field-before"><abbr class="pj-form-field-icon-url"></abbr></span>
											<input type="text" name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field w400 required" value="<?php echo htmlspecialchars(stripslashes($tpl['arr'][$i]['value'])); ?>" />
										</span>
										<?php
									}else{
										?><input type="text" name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field <?php echo in_array($tpl['arr'][$i]['key'], array('o_listing_page', 'o_facebook_app_id','o_facebook_app_secret','o_google_client_id','o_google_client_secret'))  ? 'w400' : 'w200'; ?>" value="<?php echo htmlspecialchars(stripslashes($tpl['arr'][$i]['value'])); ?>" /><?php
									}
									break;
								case 'text':
									?><textarea name="value-<?php echo $tpl['arr'][$i]['type']; ?>-<?php echo $tpl['arr'][$i]['key']; ?>" class="pj-form-field" style="width: 400px; height: 80px;"><?php echo htmlspecialchars(stripslashes($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 htmlspecialchars(stripslashes($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 htmlspecialchars(stripslashes($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]);
									$enum_arr = __('enum_arr', true);
									if($tpl['arr'][$i]['key'] == 'o_week_start')
									{
										$enum_arr = __('days', true);
									}
									$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)
									{
										?><option value="<?php echo $default[0].'::'.$el; ?>"<?php echo $default[1] == $el ? ' selected="selected"' : NULL;?>><?php echo isset($enum_arr[$el]) ? $enum_arr[$el] : (array_key_exists($k, $enumLabels) ? stripslashes($enumLabels[$k]) : stripslashes($el)); ?></option><?php
									}
									?>
									</select>
									<?php
									break;
							}
							?>
						</td>
					</tr>
					<?php
					if($tpl['arr'][$i]['key'] == 'o_facebook_app_secret')
					{
						?>
						<tr class="pj-table-row-odd boxFacebook" style="<?php echo $tpl['option_arr']['o_facebook_allow'] == 'Yes' ? 'display:' : 'display:none'; ?>">
							<td><?php __('lblFacebookSiteURL');?></td>
							<td><?php echo PJ_INSTALL_URL . 'index.php?controller=pjFront&action=pjActionFacebookLogin'; ?></td>
						</tr>									
						<?php
					}
					if($tpl['arr'][$i]['key'] == 'o_google_client_secret')
					{
						?>
						<tr class="pj-table-row-odd boxGoogle" style="<?php echo $tpl['option_arr']['o_google_allow'] == 'Yes' ? 'display:' : 'display:none'; ?>">
							<td><?php __('lblGoogleSiteURL');?></td>
							<td><?php echo PJ_INSTALL_URL . 'index.php?controller=pjFront&action=pjActionGoogleLogin'; ?></td>
						</tr>									
						<?php
					}
				}
				?>
						</tbody>
					</table>
					
					<p><input type="submit" value="<?php __('btnSave'); ?>" class="pj-button" /></p>
				</form>
				
				<?php
			}
		}
	}
}
?>