<?php
function array_merge_recursive_distinct ( array &$array1, array &$array2 )
{
	$merged = $array1;
	
	foreach ( $array2 as $key => &$value )
	{
		if ( is_array ( $value ) && isset ( $merged [$key] ) && is_array ( $merged [$key] ) )
		{
			$merged [$key] = array_merge_recursive_distinct ( $merged [$key], $value );
		}
		else
		{
			$merged [$key] = $value;
		}
	}
	
	return $merged;
}
$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
	$sm_title = "";
	$sm_class = "sm-page";
	$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)) {
		
		//echo '<pre>', var_export($module_params, true), '</pre>';
		
		foreach ($module_params as $key=>$value) {
			${$key} = $value;
		}
	}
	?>
	<div class="inline_container">
	<form method="POST" action="custom_module_update.php" name="sm_middle_frm" id="sm_middle_frm">
		<table cellpadding="0" cellspacing="0" border="0" width="100%">
			<tr>
				<th colspan="2" align="left">
					Social Media Customization
				</th>
			</tr>
			<tr>
				<td nowrap class="itdh">Social Media Title</td>
				<td class="itd" width="80%">
					<input type="text" name="sm_title" id="sm_title" value="<?php echo $sm_title; ?>" style="width:100%;" size="30">
				</td>
			</tr>
			<tr>
				<td nowrap class="itdh">CSS Class</td>
				<td class="itd" width="80%">
					<input type="text" name="sm_class" id="sm_class" value="<?php echo $sm_class; ?>" style="width:100%;" size="30">
				</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" => "sm_middle_frm",
		"form_action" => "",
		"form_method" => "POST"
	);
}
else {
	// We are in the front-end
	// Initialize defaults
	
	
	
	$sm_title = "";
	$sm_class = "sm-page";
	// Try to get any customization done
	if(isset($module_params) && is_array($module_params)) {
		
		//echo '<pre>', var_export($module_params, true), '</pre>';
		
		foreach ($module_params as $key=>$value) {
			${$key} = $value;
		}
	}
}
?>
