<?php

//defined( '_VALID' ) or die( 'Restricted access' );

include_once('class.banner.php');
$banner = new banner($configObj);

$action = $_REQUEST['action'];
$configObj->glTplObj->change_path($configObj->currentModulePath . 'html/templates/');
$configObj->glTplObj->set('configObj', $configObj);
$configObj->glTplObj->set('banner', $banner);
//$configObj->glTplObj->set('bannerTab',true);
$configObj->glTplObj->set('bannerwidth', $banner->width);
$configObj->glTplObj->set('bannerheight', $banner->height);




switch ($action) {
    case 'add':

        $fk_modules = $banner->get_fk_modules($_REQUEST['module']);

        $configObj->glTplObj->set('fk_modules', $fk_modules);
        $banner->varpostdata = $_REQUEST;
        $configObj->glTplObj->set('addbannerTab', true);

        $banner->pagename = 'index.php?module=banner';  // Attribute of Page Name
        $banner->countFunction = $banner->CountRowsbanner();
        $banner->loadCount('var_title');



        $banner->Generateurl();
        if ($_REQUEST['h_save'] == 'T') {
            if ($banner->insert_banner()) {
                if ($_POST['btnsaveandc_x'] != '') {
                    $eid = $banner->lastinsertid;

                    $action = 'edit';


                    $configObj->glLibraryObj->header_redirect('index.php?module=banner&action=edit&msg=add&eid=' . $eid);
                } else if ($_POST['btnsaveande_x'] != '') {
                    $configObj->glLibraryObj->header_redirect('index.php?module=banner&msg=add');
                }
            }
        }

        if ($row['fk_pageid'] != "") {
            $stylei = "style='display:block'";
            $checkedi = "checked='checked'";
        } else {
            $stylei = "style='display:none'";
            $checkedi = "";
        }

        if ($row['var_link'] != "") {
            $stylee = "style='display:block'";
            $checkede = "checked='checked'";
        } else {
            $stylee = "style='display:none'";
            $checkede = "";
        }

        $configObj->glTplObj->set('stylei', $stylei);
        $configObj->glTplObj->set('stylee', $stylee);
        $configObj->glTplObj->set('checkedi', $checkedi);

        $configObj->glTplObj->set('pagetree', $banner->Bindpageshierarchy('fk_pages', '', '', 'add-new-user-textarea2', '1'));

        $configObj->glTplObj->set('BottomSubmitButtons', $configObj->glLibraryObj->GetSubmitButtons($banner->urlwithpara, 'bottom'));

        $configObj->adminContentPanel = $configObj->glTplObj->process('banner_add.tpl.php');


        break;

    case 'edit':


        $banner->pagename = 'index.php?module=banner';  // Attribute of Page Name
        $banner->countFunction = $banner->CountRowsbanner();
        $configObj->glTplObj->set('addbannerTab', true);
        $banner->loadCount('var_title');
        $configObj->glTplObj->set('frmaction', $banner->urlwithpara . '&action=' . $_REQUEST['action'] . '&eid=' . $_REQUEST['eid']);
        $configObj->glTplObj->set('BottomSubmitButtons', $configObj->glLibraryObj->GetSubmitButtons($banner->urlwithpara, 'bottom'));
        if ($_REQUEST['h_save'] == 'T') {
            $banner->varpostdata = $_REQUEST;

            if ($banner->update_banner()) {
                if ($_POST['btnsaveandc_x'] != '') {
                    $configObj->glLibraryObj->header_redirect($banner->urlwithpara . '&action=' . $_REQUEST['action'] . '&eid=' . $_REQUEST['eid'] . '&msg=edit');
                } else if ($_POST['btnsaveande_x'] != '') {
                    $configObj->glLibraryObj->header_redirect($banner->urlwithpara . '&msg=edit');
                }
            }
        }
        $fk_modules = $banner->get_fk_modules($_REQUEST['module']);
        $configObj->glTplObj->set('fk_modules', $fk_modules);
        $row = $banner->select_banner($_REQUEST['eid']);
        $configObj->glTplObj->set('row', $row);
        $configObj->glTplObj->set('catsdrp', $catsdrp);


        if ($_REQUEST['msg']) {
            if ($_REQUEST['msg'] == 'add') {
                $messagebox = $banner->configObj->glLibraryObj->message("The record has been successfully saved.");

                $banner->configObj->glTplObj->set('messagebox', $messagebox);
            } else if ($_REQUEST['msg'] == 'edit') {
                $messagebox = $banner->configObj->glLibraryObj->message("The record has been successfully edited and saved.");

                $banner->configObj->glTplObj->set('messagebox', $messagebox);
            }
        }

        if ($row['fk_pageid'] != "0") {
            $stylei = "style='display:block'";
            $checkedi = "checked='checked'";
        } else {
            $stylei = "style='display:none'";
            $checkedi = "";
        }

        if ($row['var_link'] != "") {
            $stylee = "style='display:block'";
            $checkede = "checked='checked'";
        } else {
            $stylee = "style='display:none'";
            $checkede = "";
        }


        $configObj->glTplObj->set('stylei', $stylei);
        $configObj->glTplObj->set('checkedi', $checkedi);

        $configObj->glTplObj->set('stylee', $stylee);
        $configObj->glTplObj->set('checkede', $checkede);

        $configObj->glTplObj->set('pagetree', $banner->Bindpageshierarchy('fk_pages', $row['fk_pageid'], '', 'add-new-user-textarea2', '4'));

        $configObj->adminContentPanel = $configObj->glTplObj->process('banner_add.tpl.php');


        break;

    case 'delete':

        if ($configObj->isAjaxSet) {
            $fk_modules = $banner->get_fk_modules($_REQUEST['module']);

            $banner->delete_banner($fk_modules);
        }

        break;


    default:
        $configObj->glTplObj->set('bannerTab', true);
        $banner->load_banner();

        break;
}
?>