<?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
	$ribbon_id = array();
	$ribbon_theme = "swiper";
    $ribbon_settings = [
        "slides_per_view" => 5,
        "effect" => null
    ];
	$current_catdom_module_id = $admin_catdom_module_id;
}

if($show_init_form) {

	//echo '<pre>$module_params = ', var_export($module_params, true), '</pre>';
    $themes = [
        "swiper" => "Swiper Default"
    ];

	// Try to get any previously saved customization
	if(isset($module_params) && is_array($module_params)) {
		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;
			}
		}


	}

	$ribbons = array();
	$q = "SELECT * FROM ribbons WHERE domain_id='$_parent_id' AND status='1' ORDER BY title ASC";
	$r = @mysql_query($q);
	if($r && mysql_num_rows($r) > 0) {
		while($row = mysql_fetch_assoc($r)) {
			$ribbons[$row['id']] = array_map('stripslashes', $row);
		}
	}
	?>

	<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="ribbon_frm" id="ribbon_frm">
			<table cellpadding="0" cellspacing="0" border="0" width="100%">
				<tr>
					<th colspan="2" align="left">
						Ribbon Customization
					</th>
				</tr>

				<tr>
					<td colspan="2">
						Select RIBBON to place on
						<b style="color: #ff0000;"><?=$categ_title;?></b> page
						<hr>
					</td>
				</tr>
                <tr>
                    <td class="itdh">Choose Style</td>
                    <td class="itd_lb" width="100%">
                        <select name="ribbon_theme" id="ribbon_theme">
                            <?php
                            foreach($themes as $theme_id=>$theme_name) {
                                $selected = '';
                                if($theme_id == $ribbon_theme) $selected = 'selected="selected"';
                                echo '<option value="'.$theme_id.'" ' . $selected . '>'.$theme_name.'</option>';
                            }
                            ?>
                        </select>
                    </td>
                </tr>

				<?php
				if(count($ribbons) > 0) {
					$group = '';
					foreach($ribbons as $id=>$ribbon_data) {

						$page_title = $ribbon_data['title'];
						$checked = '';
						$disabled = 'disabled="disabled"';
						if($ribbon_id == $id) {
							$checked = 'checked="checked"';
							$disabled = '';

						}
						?>
						<tr>
							<td class="itdh"><input type="radio" name="ribbon_id" value="<?=$id?>" <?=$checked?> class="xpck"></td>
							<td class="itd_lb" width="100%"><span><?=$page_title?></span></td>
						</tr>
						<?php
					}
				}
                else {
                    ?>
                    <tr>
                        <td class="itdh">&nbsp;</td>
                        <td class="itd_lb" width="100%"><span style="color:red;">There are no ribbons to choose from!!</span></td>
                    </tr>
                    <?php
                }
				?>

                <tr>
                    <td colspan="2" class="itdh">Ribbon Settings</td>
                </tr>

                <tr>
                    <td class="itdh">Slides Per View</td>
                    <td class="itd_lb"><input type="number" name="ribbon_settings[slides_per_view]" value="<?=$ribbon_settings['slides_per_view'];?>" style="width:160px;"> </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>

	<script type="text/javascript">

	</script>
	<?php

	$module_forms = array(
		"form_name" => "ribbon_frm",
		"form_action" => "",
		"form_method" => "POST"
	);
}
else {
	// We are in the front-end
	// Initialize defaults
    $ribbon_id = array();
    $ribbon_theme = "swiper";
    $ribbon_settings = [
        "slides_per_view" => 5,
        "effect" => null
    ];

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