<?php
$show_init_form = false;	/* To display or not the initialization form */

/* Try to see if the call is from administration panel */
if(isset($admin_catdom_module_id) && $admin_catdom_module_id>0 && isset($_GET['action']) && $_GET['action'] == "custom_module") {
	$show_init_form = true;
	// Initialize defaults
	$module_show_featured_title = 0;
	$module_show_featured_section = 1;
	$module_show_secondary_section = 1;
	$module_show_adv_title = 0;
	$module_show_adv_delim = 0;
	
	$module_secondary_title = "";
	$module_catdom_id_adv = 0;
	
	$module_vads_display = 1;
	
	$current_catdom_module_id = $admin_catdom_module_id;
}

if($show_init_form) {
	// Try to get any previously saved customization
	if(isset($module_params) && is_array($module_params)) {
		foreach ($module_params as $key=>$value) {
			${$key} = $value;
		}
	}
	
	$_categs = array();
	$_catdom_id = 0;
	$_parent_id = 0;
	
	if(!isset($admin_catdom_id)) {
	
		$q = "select * from left_content where catdom_module_id='$current_catdom_module_id';";
		//echo $q;
		$r = @mysql_query($q);
		if($r && mysql_num_rows($r)>0) {
			$row = mysql_fetch_assoc($r);
			
			$_catdom_id = intval($row['catdom_id']);
		}
	}
	else {
		$_catdom_id = $admin_catdom_id;
	}
	if($_catdom_id > 0) {
			$q = "select * from domaincategories where catdom_id='$_catdom_id';";
			//echo "<br/>$q";
			$r = @mysql_query($q);
			if($r && mysql_num_rows($r) == 1) {
				$row = mysql_fetch_assoc($r);
				$_parent_id = intval($row['parent_id']);
				
				
				
				if($_parent_id == 0) {
					$q = "select * from domaincategories where catdom_id='$_catdom_id' or parent_id='$_catdom_id' order by parent_id asc, order_seq asc;";
				}
				else {
					$q = "select * from domaincategories where catdom_id='$_parent_id' or parent_id='$_parent_id' order by parent_id asc, order_seq asc;";
				}
				//echo "<br/>$q";
				$r = @mysql_query($q);
				if($r && mysql_num_rows($r) > 0) {
					while ($row = mysql_fetch_assoc($r)) {
						$_categs[$row['catdom_id']] = intval($row['parent_id']) == 0 ? "_Homepage_" : stripslashes($row['title_el']);
					}
				}
			}
			
		
	}
	
	
	?>
	<div class="inline_container">
	<form method="POST" action="custom_module_update.php" name="adverts_middle_frm" id="adverts_middle_frm">
		<table cellpadding="0" cellspacing="0" border="0" width="100%">
			<tr>
				<th colspan="2" align="left">
					Vertical Adverts Customization
				</th>
			</tr>
			<tr>
				<td nowrap class="itdh">Display Method</td>
				<td class="itd">
					<input type="radio" name="module_vads_display" id="module_vads_display_on" value="1" <?php if($module_vads_display == 1) echo "checked"; ?> style="vertical-align:middle;"> Inline
					<input type="radio" name="module_vads_display" id="module_vads_display_off" value="0" <?php if($module_vads_display == 0) echo "checked"; ?> style="vertical-align:middle;"> Javascript
				</td>
			</tr>
			<tr>
				<td nowrap class="itdh">Show Adverts Bound To</td>
				<td class="itd">
					<select name="module_catdom_id_adv">
						<option value="0" selected="selected">None</option>
						<?php
						if(count($_categs) > 0) {
							foreach ($_categs as $cc_id=>$cc_name) {
								$selected = "";
								if(intval($cc_id) == intval($module_catdom_id_adv)) $selected='selected="selected"';
								echo '<option value="', $cc_id, '" ', $selected, '>', $cc_name, '</option>';
							}
						}
						?>
					</select>
				</td>
			</tr>
			<tr>
				<td nowrap class="itdh">Show Featured Adverts Section</td>
				<td class="itd">
					<input type="radio" name="module_show_featured_section" id="module_show_featured_section_on" value="1" <?php if($module_show_featured_section == 1) echo "checked"; ?> style="vertical-align:middle;"> Yes
					<input type="radio" name="module_show_featured_section" id="module_show_featured_section_off" value="0" <?php if($module_show_featured_section == 0) echo "checked"; ?> style="vertical-align:middle;"> No
				</td>
			</tr>
			<tr>
				<td nowrap class="itdh">Show Secondary Adverts Section</td>
				<td class="itd">
					<input type="radio" name="module_show_secondary_section" id="module_show_secondary_section_on" value="1" <?php if($module_show_secondary_section == 1) echo "checked"; ?> style="vertical-align:middle;"> Yes 
					<input type="radio" name="module_show_secondary_section" id="module_show_secondary_section_off" value="0" <?php if($module_show_secondary_section == 0) echo "checked"; ?> style="vertical-align:middle;"> No 
				</td>
			</tr>
			
			<tr>
				<td nowrap class="itdh">Use defaults?</td>
				<td class="itd">
					<input type="radio" name="use_defaults" value="1" style="vertical-align:middle;"/> Yes 
					<input type="radio" name="use_defaults" value="0" checked style="vertical-align:middle;"/> No
				</td>
			</tr>
			<tr>
				<td colspan="2" align="right" class="footer">
					<input type="reset" value="Reset" name="submit" class="submit_button"/>
					<input type="submit" value="Save" name="submit" class="submit_button"/>
					<input type="hidden" value="<?php echo $current_catdom_module_id; ?>" name="admin_catdom_module_id" id="admin_catdom_module_id"/>
				</td>
			</tr>
		</table>
	</form>
	</div>
	<?php
	
	$module_forms = array(
		"form_name" => "adverts_middle_frm",
		"form_action" => "",
		"form_method" => "POST"
	);
}
else {
	// We are in the front-end
	// Initialize defaults
	$module_show_featured_title = 0;
	$module_show_featured_section = 1;
	$module_show_secondary_section = 1;
	$module_show_adv_title = 0;
	$module_show_adv_delim = 0;
	
	$module_secondary_title = "";
	$module_catdom_id_adv = 0;
	
	$module_vads_display = 1;
	
	// Try to get any customization done
	if(isset($module_params) && is_array($module_params)) {
		foreach ($module_params as $key=>$value) {
			${$key} = $value;
		}
	}
}
?>
