<?php

defined('_VALID') or die(RESTRICTED_ACCESS);
include_once('class.packagetype.php');
$ppackagetypeObj = new packagetype($configObj);
$action = $_REQUEST['action'];
$configObj->glTplObj->change_path($configObj->currentModulePath . 'html/templates/');
$configObj->glTplObj->set('configObj', $configObj);
$configObj->glTplObj->set('ppackagetypeObj', $ppackagetypeObj);
$paramMain = $configObj->AllmoduleAccess[$configObj->ModuleName];
$configObj->glTplObj->set('paramMain', $paramMain);


switch ($action) {
    case 'add':


        $configObj->glTplObj->set('packagetypeaddTab', true);
        if ($paramMain['Add'] != 'Y') {
            $configObj->glLibraryObj->header_redirect('index.php?module=packagetype');
        }
        $date_news = DEFAULT_DATEFORMAT;
        $configObj->glTplObj->set('date_news', $date_news);
        $ppackagetypeObj->pagename = 'index.php?module=packagetype'; // Attribute of Page Name
        $ppackagetypeObj->countFunction = $ppackagetypeObj->CountRows();
        $ppackagetypeObj->loadCount("CountRows");
        $ppackagetypeObj->varpostdata = $_REQUEST;

        $configObj->glTplObj->set('frmpackagetype', $ppackagetypeObj->pagename . '&action=' . $_REQUEST['action']);
        if ($_REQUEST['h_save'] == 'T') {
            if ($ppackagetypeObj->insert_packagetype()) {
                if ($_POST['btnsaveandc_x'] != '') {
                    $eid = $ppackagetypeObj->lastinsertid;
                    $configObj->glLibraryObj->header_redirect('index.php?module=packagetype&action=edit&msg=add&eid=' . $ppackagetypeObj->lastinsertid);
                } else if ($_POST['btnsaveande_x'] != '') {
                    $configObj->glLibraryObj->header_redirect('index.php?module=packagetype&msg=add');
                }
            }
        } else {
            $configObj->glTplObj->set('BottomSubmitButtons', $configObj->glLibraryObj->GetSubmitButtons($ppackagetypeObj->urlwithpara, 'bottom', '', ''));
            $configObj->adminContentPanel = $configObj->glTplObj->process('packagetype_add.tpl.php');
        }
        break;

    case 'edit':

        if ($paramMain['Edit'] != 'Y') {
            $configObj->glLibraryObj->header_redirect('index.php?module=packagetype');
        }
        $date_news = DEFAULT_DATEFORMAT;
        $configObj->glTplObj->set('date_news', $date_news);
        $ppackagetypeObj->loadCount('CountRows');
        $configObj->glTplObj->set('packagetypeaddTab', true);

        $configObj->glTplObj->set('frmpackagetype', $ppackagetypeObj->urlwithpara . '&action=' . $_REQUEST['action'] . '&eid=' . $_REQUEST['eid']);
        $configObj->glTplObj->set('BottomSubmitButtons', $configObj->glLibraryObj->GetSubmitButtons($ppackagetypeObj->urlwithpara, 'bottom'));

        if ($_REQUEST['h_save'] == 'T') {
            $ppackagetypeObj->varpostdata = $_REQUEST;
            if ($ppackagetypeObj->update_packagetype()) {
                if ($_POST['btnsaveandc_x'] != '') {
                    $configObj->glLibraryObj->header_redirect($ppackagetypeObj->urlwithpara . '&action=' . $_REQUEST['action'] . '&eid=' . $_REQUEST['eid'] . '&msg=edit');
                } else if ($_POST['btnsaveande_x'] != '') {
                    $configObj->glLibraryObj->header_redirect($ppackagetypeObj->urlwithpara . '&msg=edit');
                }
            }
        } else {
            $row = $ppackagetypeObj->select_packagetype($_REQUEST['eid']);

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

        if ($_REQUEST['msg']) {
            if ($_REQUEST['msg'] == 'add') {
                $messagebox = $ppackagetypeObj->configObj->glLibraryObj->message("Congrats! The record is successfully saved.");
                $ppackagetypeObj->configObj->glTplObj->set('messagebox', $messagebox);
            } else if ($_REQUEST['msg'] == 'edit') {
                $messagebox = $ppackagetypeObj->configObj->glLibraryObj->message("Congrats! The record is successfully edited and saved.");
                $ppackagetypeObj->configObj->glTplObj->set('messagebox', $messagebox);
            }
        }
        $configObj->adminContentPanel = $configObj->glTplObj->process('packagetype_add.tpl.php');
        break;

    case 'delete':
        if ($configObj->isAjaxSet) {
            $ppackagetypeObj->delete_packagetype();
        }
        break;

    case 'history':

        if ($paramMain['History'] == 'Y') {

            include_once('../libraries/class.history.php');
            $id = $_REQUEST['id'];
            $tablename = DB_PREFIX . "packagetype";
            $configObj->glTplObj->set('packagetypeViewTab', true);
            $historyObj = new history($configObj, 15, $tablename, $id, $chr_custom = 'N', $path);

            if ($configObj->isAjaxSet && $_REQUEST['type'] == 'delete') {
                $historyObj->delete_history();
            }

            if ($configObj->isAjaxSet && isset($_REQUEST['recordid']) && $_REQUEST['history_action'] == 'delete') {
                $historyObj->delete_add_history_record();
                $ppackagetypeObj->configObj->glTplObj->set('newAddedHistory', $historyObj->new_added_history());
                $_REQUEST['orderby'] = $ppackagetypeObj->orderby;
                $_REQUEST['ordertype'] = $ppackagetypeObj->ordertype;
                $pagesObj->loadpage();

                exit();
            } else {
                $ppackagetypeObj->loadCount('CountRows');

                if (!$configObj->isAjaxSet) {
                    $historyObj->backbuttonurl = str_replace("&h", "&", $blogObj->hurlwithpara);
                }
                $historyObj->load_history();
            }
        } else {
            $configObj->glLibraryObj->header_redirect('index.php?module=packagetype');
        }
        break;

    case 'sametitle' :

        if ($_REQUEST['id'] != '') {
            $eid = " and int_glcode!='" . $_REQUEST['id'] . "'";
        }
        $sql = "select count(1) as total from " . DB_PREFIX . "packagetype where var_title='" . $_REQUEST['title'] . "' and chr_delete='N' $eid";
        $rs = $configObj->glDbObj->get_sql_row($sql);
        echo $rs['total'];
        exit;
        break;

    case 'updatepublish':
        $id = $_REQUEST['id'];
        $configObj->glLibraryObj->updatefieldinmultiple();
        echo 1;
        exit;


    default:

        if ($_REQUEST['task'] == 'downlaod') {
            $configObj->glLibraryObj->download_files(SITE_PATH . '/powerpanel/' . $configObj->currentModulePath . 'html/uploads/pdfs/');
        }
        $configObj->glTplObj->set('packagetypeTab', true);
        $ppackagetypeObj->load_packagetype();
}
?>
