<?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;
    $current_catdom_module_id = $admin_catdom_module_id;

    $popb_effects = array(
        'fadein	' => 'Fadein',
        'slide' => 'Slide',
        'newspaper' => 'Newspaper',
        'fall' => 'Fall',
        'sidefall' => 'Sidefall',
        'blur' => 'Blur',
        'flip' => 'Flip',
        'sign' => 'Sign',
        'superscaled' => 'Superscaled',
        'slit' => 'Slit',
        'rotate' => 'Rotate',
        'letmein' => 'Letmein',
        'makeway' => 'Makeway',
        'slip' => 'Slip',
        'corner' => 'Corner',
        'slidetogether	' => 'Slide together',
        'scale' => 'Scale',
        'door' => 'Door',
        'push' => 'Push',
        'contentscale' => 'Content scale',
        'swell' => 'Swell new',
        'rotatedown' => 'Rotate down new',
        'flash' => 'Flash',

    );

    $recurrence = array(
        '0' => 'Once Per Session',
        '600' => 'Every 10 minutes',
        '1800' => 'Every 30 minutes',
    );


    $popb_banner = array(
        'title_en' => 'Advertisment',
        'alt_en' => 'Advertisment',
    );


    // Get all popup banners associated with this domain homepage
    // in order to see if there already is one setup for sitewide
    /*$can_be_sitewide = false;
    $q = "SELECT l.module_params, l.module_active, d.catdom_id, d.parent_id FROM left_content l, domaincategories d WHERE l.catdom_module_id='$current_catdom_module_id' AND l.catdom_id=d.catdom_id";
    $r = @mysql_query($q);
    if($r && mysql_num_rows($r) == 1) {
        $row = mysql_fetch_assoc($r);
        $parent_id = intval($row['parent_id']);
        $_module_params = unserialize(base64_decode($row['module_params']));
        if($parent_id == 0) {
            // Get other possibly existing popup banner
            $q = "SELECT * FROM left_content WHERE catdom_id='$parent_id' AND ";
        }
    }*/


    // Get Banner title
    $q = "SELECT b.* FROM banner b, left_content l WHERE l.catdom_module_id='$current_catdom_module_id' AND l.module_id=b.module_id";
    $r = @mysql_query($q);
    if($r && mysql_num_rows($r) == 1) {
        $row = mysql_fetch_assoc($r);
        $popb_banner ['title_en'] = stripslashes($row['title_en']);
        $popb_banner ['alt_en'] = stripslashes($row['alt_en']);

    }

    // Initialize defaults
    $popb_title = $popb_banner ['title_en'];
    $popb_alt = $popb_banner ['alt_en'];
    $popb_effect = 'newspaper';
    $popb_follow = 'follow';
    $popb_target = '_blank';
    $popb_recurrence = 0;
    $popb_sitewide = 0;

}

if($show_init_form) {
    // Try to get any previously saved customization
    //echo '<pre>$module_params = ', var_export($module_params, true), '</pre>';
    if(isset($module_params) && is_array($module_params)) {
        foreach ($module_params as $key=>$value) {
            ${$key} = $value;
        }
    }
    ?>
    <div style="margin:0;padding:0;height:540px;overflow-y:auto;">
        <div class="inline_container">
            <form method="POST" action="custom_module_update.php" name="popup-banner-form" id="popup-banner-form" role="form">
                <table cellpadding="0" cellspacing="0" border="0" width="100%">
                    <tr>
                        <th colspan="2" align="left">
                            <?=$popb_banner ['title_en'];?> | POPUP Banner Settings
                        </th>
                    </tr>
                    <tr>
                        <td nowrap class="itdh">POPUP Title</td>
                        <td class="itd">
                            <input type="text" name="popb_title" id="popb_title" value="<?php echo $popb_title;?>" maxlength="128" style="width:100%;"/>
                        </td>
                    </tr>
                    <tr>
                        <td nowrap class="itdh">POPUP Hover Text</td>
                        <td class="itd">
                            <input type="text" name="popb_alt" id="popb_alt" value="<?php echo $popb_alt;?>" maxlength="256" style="width:100%;"/>
                        </td>
                    </tr>
                    <tr>
                        <td nowrap class="itdh">POPUP Link Follow</td>
                        <td class="itd">
                            <input type="radio" name="popb_follow" value="follow" <?php echo $popb_follow == "follow" ? 'checked="checked"':'';?>> Follow
                            <input type="radio" name="popb_follow" value="no-follow" <?php echo $popb_follow == "no-follow" ? 'checked="checked"':'';?>> No-Follow
                        </td>
                    </tr>
                    <tr>
                        <td nowrap class="itdh">POPUP Link Target</td>
                        <td class="itd">
                            <input type="radio" name="popb_target" value="_blank" <?php echo $popb_target == "_blank" ? 'checked="checked"':'';?>> New Window
                            <input type="radio" name="popb_target" value="_self" <?php echo $popb_target == "_self" ? 'checked="checked"':'';?>> Same Window
                        </td>
                    </tr>
                    <tr>
                        <td nowrap class="itdh">POPUP Visibility</td>
                        <td class="itd">

                            <input type="radio" name="popb_sitewide" value="0" <?php echo $popb_sitewide == "0" ? 'checked="checked"':'';?>> Only Bound Page
                            <input type="radio" name="popb_sitewide" value="1" <?php echo $popb_sitewide == "1" ? 'checked="checked"':'';?>> SITE WIDE (any page)
                        </td>
                    </tr>
                    <tr>
                        <td nowrap class="itdh">POPUP Reccurence</td>
                        <td class="itd">
                            <select name="popb_recurrence" id="popb_recurrence">
                                <?php

                                foreach($recurrence as $rec_val => $rec_name) {
                                    $selected = '';
                                    if($popb_recurrence == $rec_val) $selected = 'selected="selected"';
                                    echo '<option value="', $rec_val, '" ', $selected, '>', $rec_name, '</option>';
                                }

                                ?>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td nowrap class="itdh">POPUP Effect</td>
                        <td class="itd">
                            <select name="popb_effect" id="popb_effect">
                                <?php

                                foreach($popb_effects as $effect_code => $effect_name) {
                                    $selected = '';
                                    if($popb_effect == $effect_code) $selected = 'selected="selected"';
                                    echo '<option value="', $effect_code, '" ', $selected, '>', $effect_name, '</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>
            </form>
        </div>
    </div>
    <?php

    $module_forms = array(
        "form_name" => "popup-banner-form",
        "form_action" => "",
        "form_method" => "POST"
    );
}
else {
    // We are in the front-end
    $popb_banner = array(
        'title_en' => 'Advertisment',
        'alt_en' => 'Advertisment',
    );
    // Initialize defaults
    $popb_title = $popb_banner ['title_en'];
    $popb_alt = $popb_banner ['alt_en'];
    $popb_effect = 'newspaper';
    $popb_follow = 'follow';
    $popb_target = '_blank';

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