<?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($_REQUEST['action']) && $_REQUEST['action'] == "custom_module") {
	$show_init_form = true;

	// Get domain
	$p_catdom_id = intval($_REQUEST['catdom_id']);
	$p_domain_id = $p_catdom_id;
	$q = "select * from domaincategories where catdom_id='$p_catdom_id';";
	$r = mysql_query($q) or die("<strong>$q</strong>".mysql_error());
	if($r && mysql_num_rows($r)>0) {
		$row = mysql_fetch_assoc($r);
		if(intval($row['parent_id'])>0) $p_domain_id = intval($row['parent_id']);
	}
	
	$module_use_defaults = 0;
	$module_bl_links = 1;
	$module_bl_show = 1;
	$module_bl_categs = array();
	$module_bl_title = "";
    $module_bl_description = "";
    $module_bl_robots = "";
    $module_bl_more_text = "See more listings";

	$current_catdom_module_id = $admin_catdom_module_id;

}

if($show_init_form) {
	
	//require_once("modules/contents/functions.php");
	//require_once("functions/root_display.php");
	//require_once("classes/tree_radio_class.php");
	
	//print_r($module_params);
	// Try to get any previously saved customization
	if(isset($module_params) && is_array($module_params)) {
		foreach ($module_params as $key=>$value) {
			${$key} = $value;
		}
	}
	?>
	<style type="text/css">
		#ws_categs ul {
			margin:0;padding:0;list-style:none;
		}
		
		#ws_categs ul li{
			margin:3px;
			border-bottom: 1px solid #cccccc;
		}
		
		#categs ul {
			margin:0;padding:0;list-style:none;
		}
		
		#categs ul li{
			margin:3px;
			border-bottom: 1px solid #cccccc;
		}
		
	</style>
	<div id="bl_middle" class="inline_container">
		<form method="post" name="ws_search_form" id="ws_search_form">
		<table cellpadding="0" cellspacing="0" border="0" width="100%">
			<tr>
				<th colspan="3" align="left">
					Webservices BL Categories Selection
				</th>
			</tr>
			<tr>
				<td nowrap class="itdh" width="20%">Categories Search</td>
				<td class="itd" width="80%">
					<input type="text" name="ws_categ_term" id="ws_categ_term" value="" style="width:100%;">
				</td>
				<td class="itd_lb" align="center">
					<input type="submit" id="search_yp_categs" value="Search" class="submit_button">
				</td>
			</tr>
			<tr>
				<td class="itd" colspan="3">
					<div id="ws_categs" style="height:250px; overflow-y:auto;">
						<ul id="ws_categs_ul"></ul>
					</div>
				</td>
			</tr>
		</table>
		</form>
		
		<form method="POST" action="custom_module_update.php" name="bl_middle_frm" id="bl_middle_frm">
		<table cellpadding="0" cellspacing="0" border="0" width="100%">
			<tr>
				<th colspan="2" align="left">
					Selected Categories
				</th>
			</tr>
			<tr>
				<td class="itd" colspan="3">
					<div id="categs" style="height:250px; overflow-y:auto;">
						<ul id="categs_ul">
						<?php
						if(count($module_bl_categs) > 0) {
							foreach ($module_bl_categs as $uid => $title) {
								echo '<li id="s_' . $uid . '"><input type="checkbox" id="' . $uid. '" name="module_bl_categs['.$uid.']" value="'.$title.'" checked="checked" class="yp_categs"> '.$title.'</li>';
							}
						}
						?>
						
						</ul>
					</div>
				</td>
			</tr>
			<tr>
				<td nowrap class="itdh">BL Listing Title</td>
				<td class="itd">
					<input type="text" name="module_bl_title" value="<?php echo $module_bl_title; ?>" style="width:100%;"/>
				</td>
			</tr>
            <tr>
                <td nowrap class="itdh">BL Listing More Listing Text</td>
                <td class="itd">
                    <input type="text" name="module_bl_more_text" value="<?php echo $module_bl_more_text; ?>" style="width:100%;"/>
                    <br><small>Example: "See more listings"</small>
                </td>
            </tr>
			<tr>
				<td nowrap class="itdh">BL Meta Description</td>
				<td class="itd">
					<textarea name="module_bl_description" rows="4"  style="width:100%;"><?php echo $module_bl_description; ?></textarea>
				</td>
			</tr>
			<tr>
				<td nowrap class="itdh">BL META ROBOTS</td>
				<td class="itd">
					<input type="text" name="module_bl_robots" value="<?php echo $module_bl_robots; ?>" style="width:100%;"/>
					If empty acts as: "index, follow". Possible values separated by comma: index, noindex, follow, nofollow (only 2 at a time)
				</td>
			</tr>
			<tr>
				<td nowrap class="itdh">Use defaults?</td>
				<td class="itd">
					<input type="radio" name="module_use_defaults" value="1" <?php echo ($module_use_defaults == 1) ? "checked" : ""; ?> style="vertical-align:middle;"/> Yes 
					<input type="radio" name="module_use_defaults" value="0" <?php echo ($module_use_defaults == 0) ? "checked" : ""; ?> style="vertical-align:middle;"/> No
				</td>
			</tr>
			<tr>
				<td nowrap class="itdh">Show website links?</td>
				<td class="itd">
					<input type="radio" name="module_bl_links" value="1" <?php echo (intval($module_bl_links) == 1) ? 'checked="checked"' : ""; ?> style="vertical-align:middle;"/> Yes 
					<input type="radio" name="module_bl_links" value="0" <?php echo (intval($module_bl_links) == 0) ? 'checked="checked"' : ""; ?> style="vertical-align:middle;"/> No
				</td>
			</tr>
			<tr>
				<td nowrap class="itdh">Display Module Content?</td>
				<td class="itd">
					<input type="radio" name="module_bl_show" value="1" <?php echo (intval($module_bl_show) == 1) ? 'checked="checked"' : ""; ?> style="vertical-align:middle;"/> Yes 
					<input type="radio" name="module_bl_show" value="0" <?php echo (intval($module_bl_show) == 0) ? 'checked="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>

    <script>
        var full_uri = '<?= $protocol . $_SERVER['HTTP_HOST'] ?>';
    </script>
    <script src="<?=$path . 'amodules/bl_middle/js/bl_middle_init.js'?>"></script>
	<?php
	//$optres['js'][] = $path . 'amodules/bl_middle/js/bl_middle_init.js';
 	$module_forms = array(
		"form_name" => "bl_middle_frm",
		"form_action" => "",
		"form_method" => "POST"
	);
}
else {
	// We are in the front-end
	// Initialize defaults
	$module_use_defaults = 0;
	$module_bl_links = 1;
	$module_bl_show = 1;
	$module_bl_categs = array();
	$module_bl_title = "";
    $module_bl_description = "";
    $module_bl_robots = "";
    $module_bl_more_text = "See more listings";
	
	// Try to get any customization done
	if(isset($module_params) && is_array($module_params)) {
		foreach ($module_params as $key=>$value) {
			${$key} = $value;
		}
	}
}
?>
