<?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';
	
	pjUtil::printNotice(__('infoFormTitle', true), __('infoFormBody', true));
	
	$rf_key_arr = $pf_key_arr = array();
	$rf_key_arr['o_rf_include_fname'] = $pf_key_arr['o_pf_include_fname'] = __('lblFirstName', true, false);
	$rf_key_arr['o_rf_include_lname'] = $pf_key_arr['o_pf_include_lname'] = __('lblLastName', true, false);
	$rf_key_arr['o_rf_include_email'] = $pf_key_arr['o_pf_include_email'] = __('lblEmail', true, false);
	$rf_key_arr['o_rf_include_password'] = $pf_key_arr['o_pf_include_password'] = __('lblPassword', true, false);
	$rf_key_arr['o_rf_include_phone'] = $pf_key_arr['o_pf_include_phone'] = __('lblPhone', true, false);
	$rf_key_arr['o_rf_include_website'] = $pf_key_arr['o_pf_include_website'] = __('lblWebsite', true, false);
	$rf_key_arr['o_rf_include_gender'] = $pf_key_arr['o_pf_include_gender'] = __('lblGender', true, false);
	$rf_key_arr['o_rf_include_age'] = $pf_key_arr['o_pf_include_age'] = __('lblAge', true, false);
	$rf_key_arr['o_rf_include_birthday'] = $pf_key_arr['o_pf_include_birthday'] = __('lblBirthday', true, false);
	$rf_key_arr['o_rf_include_address'] = $pf_key_arr['o_pf_include_address'] = __('lblAddress', true, false);
	$rf_key_arr['o_rf_include_city'] = $pf_key_arr['o_pf_include_city'] = __('lblCity', true, false);
	$rf_key_arr['o_rf_include_state'] = $pf_key_arr['o_pf_include_state'] = __('lblState', true, false);
	$rf_key_arr['o_rf_include_country'] = $pf_key_arr['o_pf_include_country'] = __('lblCountry', true, false);
	$rf_key_arr['o_rf_include_zip'] = $pf_key_arr['o_pf_include_zip'] = __('lblZip', true, false);
	$rf_key_arr['o_rf_include_company'] = $pf_key_arr['o_pf_include_company'] = __('lblCompanyName', true, false);
	$enum_arr = __('enum_arr', true);
	if (isset($tpl['arr']))
	{
		if (is_array($tpl['arr']))
		{
			$count = count($tpl['arr']);
			if ($count > 0)
			{
				?>
				<form action="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminOptions&amp;action=pjActionUpdate" method="post" class="form pj-form" id="frmForms">
					<input type="hidden" name="options_update" value="1" />
					<input type="hidden" name="next_action" value="pjActionForms" />
					<input type="hidden" name="tab_id" value="<?php echo isset($_GET['tab_id']) && !empty($_GET['tab_id']) ? $_GET['tab_id'] : 'tabs-1'; ?>" />
					
					<div id="tabs">
						<ul>
							<li><a href="#tabs-1"><?php __('lblRegistrationForm'); ?></a></li>
							<li><a href="#tabs-2"><?php __('lblProfileForm'); ?></a></li>
						</ul>
						<div id="tabs-1">
							<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'] != 3 || (int) $tpl['arr'][$i]['is_visible'] === 0) continue;
										
										?>
										<tr class="pj-table-row-odd">
											<td width="30%">
												<?php echo $rf_key_arr[$tpl['arr'][$i]['key']]; ?>
											</td>
											<td>
												<?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 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]);
														
														$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
									}
									?>
								</tbody>
							</table>
							
							<p><input type="submit" value="<?php __('btnSave'); ?>" class="pj-button" /></p>
						</div>
						<div id="tabs-2">
							<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'] != 4 || (int) $tpl['arr'][$i]['is_visible'] === 0) continue;
										
										?>
										<tr class="pj-table-row-odd">
											<td width="30%">
												<?php echo $pf_key_arr[$tpl['arr'][$i]['key']]; ?>
											</td>
											<td>
												<?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 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]);
														
														$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
									}
									?>
								</tbody>
							</table>
							
							<p><input type="submit" value="<?php __('btnSave'); ?>" class="pj-button" /></p>
						</div>
					</div>
				</form>
				<?php
			}
		} 
	}	
		
	if (isset($_GET['tab_id']) && !empty($_GET['tab_id']))
	{
		$tab_id = explode("-", $_GET['tab_id']);
		$tab_id = (int) $tab_id[1] - 1;
		$tab_id = $tab_id < 0 ? 0 : $tab_id;
		?>
		<script type="text/javascript">
		(function ($) {
			$(function () {
				$("#tabs").tabs("option", "selected", <?php echo $tab_id; ?>);
			});
		})(jQuery_1_8_2);
		</script>
		<?php
	}
}
?>