<?php
/**
 * Created by PhpStorm.
 * User: IOAN
 * Date: 9/1/2015
 * Time: 10:47 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
    $faq_cat_id = 0;
    $faq_title = "FAQ";

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

    $_faqs = array();

    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;
    }
    if($_catdom_id > 0) {
        $q = "select * from faq_cat where active='yes' order by name ASC;";
        $r = @mysql_query($q);
        if($r && mysql_num_rows($r) > 0) {
            while($row = mysql_fetch_assoc($r)) {
                $_faqs [$row['faq_cat_id']] = array_map('stripslashes', $row);
            }

        }


    }


    ?>
    <div class="inline_container">
        <form method="POST" action="custom_module_update.php" name="faq_frm" id="faq_frm">
            <table cellpadding="0" cellspacing="0" border="0" width="100%">
                <tr>
                    <th colspan="2" align="left">
                        FAQ Selection & Customization
                    </th>
                </tr>
                <tr>
                    <td nowrap class="itdh">Select FAQ</td>
                    <td class="itd">
                        <select name="faq_cat_id">
                            <option value="0" selected="selected">None</option>
                            <?php
                            if(count($_faqs) > 0) {
                                foreach ($_faqs as $faq_id=>$faq) {
                                    $selected = "";
                                    if(intval($faq_id) == intval($faq_cat_id)) $selected='selected="selected"';
                                    echo '<option value="', $faq_id, '" ', $selected, '>', $faq['name'], '</option>';
                                }
                            }
                            ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td nowrap class="itdh">Link Title</td>
                    <td class="itd">
                        <input type="text" name="faq_title" id="faq_title" value="<?=$faq_title;?>">
                    </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>
    <?php

    $module_forms = array(
        "form_name" => "faq_frm",
        "form_action" => "",
        "form_method" => "POST"
    );
}
else {
    // We are in the front-end
    // Initialize defaults
    $faq_cat_id = 0;
    $faq_title = "FAQ";

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