<?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_location = "null";
    $module_mode = null;

    $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;
        }
    }


    $cities_list = ['null' => "No location"];

    $q = "SELECT cinema_location FROM `im_cinemas` WHERE 1 GROUP BY cinema_location ORDER BY cinema_location ASC";
    $r = @mysql_query($q);
    if($r && mysql_num_rows($r) > 0) {
        while($row = mysql_fetch_assoc($r)) {
            $cities_list [$row['cinema_location']] = $row['cinema_location'];
        }
    }

    $modes = [
        'null' => 'Default',
        'playing' => 'Show Now playing movies'
    ];



    ?>

    <form method="POST" action="custom_module_update.php" name="cinema_frm" id="cinema_frm">
        <div class="inline_container">
            <table cellpadding="0" cellspacing="0" border="0" width="100%">
                <tr>
                    <th colspan="2" align="left">
                        Cinema Module Customization
                    </th>
                </tr>
                <tr>
                    <td nowrap class="itdh">Select Town</td>
                    <td class="itd">
                        <select name="module_location">
                            <?php
                            foreach($cities_list as $loc=>$label) {
                                $selected = "";
                                if($loc == $module_location) $selected = 'selected="selected"';
                                echo '<option value="' . $loc . '" ' . $selected . '>' . $label . '</option>';
                            }

                            ?>
                        </select>
                    </td>
                </tr>

                <tr>
                    <td nowrap class="itdh">Select Mode</td>
                    <td class="itd">
                        <select name="module_mode">
                            <?php
                            foreach($modes as $mode=>$label) {
                                $selected = "";
                                if($mode == $module_mode) $selected = 'selected="selected"';
                                echo '<option value="' . $mode . '" ' . $selected . '>' . $label . '</option>';
                            }

                            ?>
                        </select>
                    </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>
        </div>

    </form>
    <?php

    $module_forms = array(
        "form_name" => "cinema_frm",
        "form_action" => "",
        "form_method" => "POST"
    );
}
else {
    // We are in the front-end
    // Initialize defaults
    $module_location = "null";
    $module_mode = null;

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