<?php
///////////////////////////////////////////////////////////////////////////////////////////
///Script PHP/MYSQL of management of classifieds ads developed by Script PAG
///Script PAG all rights reserved. Use under license. http://www.script-pag.com
///////////////////////////////////////////////////////////////////////////////////////////

############################################################

require_once __DIR__.'/../all_fns_adm.php';

$checked_price = '';
$checked_digital[] = array();
$checked_data[] = array();
$checked_check[] = array();
$cal = 0;
	
foreach($cache_search_price as $price)
{
	if($price['id_cat'] == $_POST['form_opts'])
	$checked_price = $price['id_cat_opt'];
}

foreach($cache_search_digital as $digital)
{
	if($digital['id_cat'] == $_POST['form_opts'])
	$checked_digital[] = $digital['id_cat_opt'];
}

foreach($cache_search_data as $data)
{
	if($data['id_cat'] == $_POST['form_opts'])
	$checked_data[] = $data['id_cat_opt'];
}

foreach($cache_search_check as $check)
{
	if($check['id_cat'] == $_POST['form_opts'])
	$checked_check[] = $check['id_cat_opt'];
}

if(is_array($cache_cat_opts))
{
	foreach($cache_cat_opts as $row)
	{
		$type_cat_opt = (int) $row['type_cat_opt'];
	 
		if($type_cat_opt == 4)
		{
			?>
			<div class="flex-container div-form">
				<label class="title" for="opts_price"><?php echo $language_adm['page_add_opts_price_none']; ?></label>
				<div class="label">
					<input type="radio" id="opts_price" name="opts_price" value="0" <?php echo 'checked'; ?> />
					<label for="opts_price"></label>
				</div>
			</div>
			<?php
				
			break;
		}
	}
}
if(is_array($cache_cat_opts))
{
	$i = 1;
	
	foreach($cache_cat_opts as $row)
	{
		$id_cat_opt = (int) $row['id_cat_opt'];
		$type_cat_opt = (int) $row['type_cat_opt'];
	 
		if($type_cat_opt == 4)
		{
			?>
			<div class="flex-container div-form">
				<label class="title" for="<?php echo $id_cat_opt; ?>"><?php echo $language_adm['page_add_opts_info4'] .' <b>'. $i .'</b>'; ?></label>
				<div class="label">
					<input type="radio" id="<?php echo $id_cat_opt; ?>" name="opts_price" value="<?php echo $id_cat_opt; ?>" <?php if(!empty($checked_price) && $checked_price == $id_cat_opt) echo 'checked'; ?> />
					<label for="<?php echo $id_cat_opt; ?>"></label>
				</div>
			</div>
			<?php
				
			$i++;
		}
	}
}
if(is_array($cache_cat_opts))
{
	foreach($cache_cat_opts as $row)
	{
		$id_cat_opt = (int) $row['id_cat_opt'];
		$type_cat_opt = (int) $row['type_cat_opt'];
		$comment = $row['comment'];
	 
		if($type_cat_opt == 1)
		{
			foreach($cache_lang as $v)
			{
				$code_lang = stripslashes(htmlspecialchars($v['code_lang'], ENT_QUOTES));
				$name_cat_opt_lang = (isset($row['name_cat_opt_'. $code_lang])) ? stripslashes(htmlspecialchars($row['name_cat_opt_'. $code_lang], ENT_QUOTES)) : '';
				$position = (int) $v['position'];
				$active = (int) $v['active'];
				
				if($position != 1)
				continue;
				
				if($active == 1 && !empty($name_cat_opt_lang))
				{
				?>
				<div class="flex-container div-form">
					<label class="title" for="<?php echo $id_cat_opt; ?>"><?php echo $language_adm['page_add_opts_info1'] .' <b>'. $name_cat_opt_lang .'</b>'; if(!empty($comment)) echo ' - '. $comment; ?></label>
					<div class="label">
						<input type="checkbox" id="<?php echo $id_cat_opt; ?>" name="opts_digital[]" value="<?php echo $id_cat_opt; ?>" <?php if(in_array($id_cat_opt, $checked_digital)) echo 'checked'; ?> />
						<label for="<?php echo $id_cat_opt; ?>"></label>
					</div>
				</div>
				<?php
				}
				
				if($position == 1)
				break;
			}
		}
	}
}
if(is_array($cache_cat_opts))
{
	foreach($cache_cat_opts as $row)
	{
		$id_cat_opt = (int) $row['id_cat_opt'];
		$child_cat_opt = (int) $row['child_cat_opt'];
		$type_cat_opt = (int) $row['type_cat_opt'];
		$comment = $row['comment'];
	 
		if($type_cat_opt == 2)
		{
			foreach($cache_lang as $v)
			{
				$code_lang = stripslashes(htmlspecialchars($v['code_lang'], ENT_QUOTES));
				$name_cat_opt_lang = (isset($row['name_cat_opt_'. $code_lang])) ? stripslashes(htmlspecialchars($row['name_cat_opt_'. $code_lang], ENT_QUOTES)) : '';
				$position = (int) $v['position'];
				$active = (int) $v['active'];
				
				if($position != 1)
				continue;
				
				if($active == 1 && !empty($name_cat_opt_lang) && $child_cat_opt == 0)
				{
				?>
				<div class="flex-container div-form">
					<label class="title" for="<?php echo $id_cat_opt; ?>"><?php echo $language_adm['page_add_opts_info2'] .' <b>'. $name_cat_opt_lang .'</b>'; if(!empty($comment)) echo ' - '. $comment; ?></label>
					<div class="label">
						<input type="checkbox" id="<?php echo $id_cat_opt; ?>" name="opts_data[]" value="<?php echo $id_cat_opt; ?>" <?php if(in_array($id_cat_opt, $checked_data)) echo 'checked'; ?> />
						<label for="<?php echo $id_cat_opt; ?>"></label>
					</div>
				</div>
				<?php
				}
				
				if($position == 1)
				break;
			}
		}
	}
}
if(is_array($cache_cat_opts))
{
	foreach($cache_cat_opts as $row)
	{
		$id_cat_opt = (int) $row['id_cat_opt'];
		$type_cat_opt = (int) $row['type_cat_opt'];
		$comment = $row['comment'];
	 
		if($type_cat_opt == 3)
		{
			foreach($cache_lang as $v)
			{
				$code_lang = stripslashes(htmlspecialchars($v['code_lang'], ENT_QUOTES));
				$name_cat_opt_lang = (isset($row['name_cat_opt_'. $code_lang])) ? stripslashes(htmlspecialchars($row['name_cat_opt_'. $code_lang], ENT_QUOTES)) : '';
				$position = (int) $v['position'];
				$active = (int) $v['active'];
				
				if($position != 1)
				continue;
				
				if($active == 1 && !empty($name_cat_opt_lang))
				{
				?>
				<div class="flex-container div-form">
					<label class="title" for="<?php echo $id_cat_opt; ?>"><?php echo $language_adm['page_add_opts_info3'] .' <b>'. $name_cat_opt_lang .'</b>'; if(!empty($comment)) echo ' - '. $comment; ?></label>
					<div class="label">
						<input type="checkbox" id="<?php echo $id_cat_opt; ?>" name="opts_checkbox[]" value="<?php echo $id_cat_opt; ?>" <?php if(in_array($id_cat_opt, $checked_check)) echo 'checked'; ?> />
						<label for="<?php echo $id_cat_opt; ?>"></label>
					</div>
				</div>
				<?php
				}
				
				if($position == 1)
				break;
			}
		}
	}
}