<?php
/**
 * Created by PhpStorm.
 * User: IOAN
 * Date: 12/3/2015
 * Time: 10:55 AM
 */
$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
	$interlinks = [
		"theme" => "default",
		"title" => null,
        "show_title" => 0
	];
	$current_catdom_module_id = $admin_catdom_module_id;
}

if($show_init_form) {

	//echo '<pre>$module_params = ', var_export($module_params, true), '</pre>';

	// Try to get any previously saved customization
	if(isset($module_params) && is_array($module_params)) {
	    //echo '<pre>', var_export($module_params, true), '</pre>';
		foreach ($module_params as $key=>$value) {
			${$key} = $value;
		}
	}

	$_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;
	}
	$categ_title = '';
	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']);


			$categ_title = stripslashes($row['title_en']);


			if($_parent_id == 0) {
				$_parent_id = $_catdom_id;
			}
		}


	}


	?>

	<style type="text/css">
		.inline_container input:disabled, .inline_container select:disabled, .inline_container textarea:disabled {
			background-color: #efefef;
			border-color: #ccc;
			border-style: solid;
			border-width: 1px;
			color: #ccc;
			font-size: 11px;
			margin: 1px 0;
		}
	</style>

	<div class="inline_container">
		<form method="POST" action="custom_module_update.php" name="interlinks_frm" id="interlinks_frm">
			<table cellpadding="0" cellspacing="0" border="0" width="100%">
				<tr>
					<th colspan="3" align="left">
						Insterlinks Modules Customization
					</th>
				</tr>

                <tr>
                    <th colspan="2" class="itdh">Module Display Settings</th>
                </tr>

                <tr>
                    <td class="itdh">Theme</td>
                    <td class="itd_lb">Default<input type="hidden" name="interlinks[theme]" value="default" style="width:160px;"> </td>
                </tr>
                <tr>
                    <td class="itdh">Title</td>
                    <td class="itd_lb"><input type="text" name="interlinks[title]" value="<?=trim($interlinks['title'])?>" style="width:100%;"> </td>
                </tr>
				<tr>
                    <td class="itdh">Show Module Title</td>
                    <td class="itd_lb">
						<select name="interlinks[show_title]">
							<option value="1" <?php echo (intval($interlinks['show_title']) == 1 ? 'selected="selected"' : '');?>>Yes, show!</option>
							<option value="0" <?php echo (intval($interlinks['show_title']) == 0 ? 'selected="selected"' : '');?>>No, do not show!</option>
						</select>
					</td>
                </tr>

				<tr>
					<td nowrap class="itdh">Use defaults?</td>
					<td class="itd" colspan="2">
						<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="3" 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" => "interlinks_frm",
		"form_action" => "",
		"form_method" => "POST"
	);
}
else {
	// We are in the front-end
	// Initialize defaults
	$interlinks = [
        "theme" => "default",
        "title" => null,
        "show_title" => 0
	];

	// Try to get any customization done
	if(isset($module_params) && is_array($module_params)) {
		foreach ($module_params as $key=>$value) {
			${$key} = $value;
		}
	}
}
?>
