<?php

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

$configObj->glLibraryObj->settings();
$paramMain = $configObj->AllmoduleAccess[$configObj->ModuleName];
$configObj->glTplObj->set('paramMain', $paramMain);

switch ($action) {
    case 'add':
        $configObj->glTplObj->set('packageaddTab', true);
        if ($paramMain['Add'] != 'Y') {
            $configObj->glLibraryObj->header_redirect('index.php?module=package');
        }
        $configObj->glTplObj->set('date_package', $date_package);
        $packageObj->pagename = 'index.php?module=package'; // Attribute of Page Name
        $packageObj->countFunction = $packageObj->CountRows();
        $packageObj->loadCount("CountRows");
        $packageObj->varpostdata = $_REQUEST;
        $configObj->glTplObj->set('frmpackage', $packageObj->pagename . '&action=' . $_REQUEST['action']);
        $configObj->glTplObj->set('packageaddTab', true);
        if ($_REQUEST['h_save'] == 'T') {
            if ($packageObj->insert_package()) {
                if ($_POST['btnsaveandc_x'] != '') {
                    $eid = $packageObj->lastinsertid;
                    $configObj->glLibraryObj->header_redirect('index.php?module=package&action=edit&msg=add&eid=' . $eid);
                } else if ($_POST['btnsaveande_x'] != '') {
                    $configObj->glLibraryObj->header_redirect('index.php?module=package&msg=add');
                }
            }
        } else {
            $configObj->glTplObj->set('BottomSubmitButtons', $configObj->glLibraryObj->GetSubmitButtons($packageObj->urlwithpara, 'bottom'));

            $configObj->glTplObj->set('cattype', $packageObj->Bindcategorieshierarchy());

            $configObj->adminContentPanel = $configObj->glTplObj->process('package_add.tpl.php');
        }
        break;

    case 'sharedata':

        if ($_REQUEST['h_save'] == 'T') {
            $packageObj->varpostdata = $_REQUEST;
            echo $packageObj->shareonfacebook();
        } else {
            echo $packageObj->genrateshareOption();
        }
        exit;
        break;

    case 'edit':
        if ($paramMain['Edit'] != 'Y') {
            $configObj->glLibraryObj->header_redirect('index.php?module=package');
        }
        $configObj->glTplObj->set('date_package', $date_package);
        $packageObj->loadCount('CountRows');
        $configObj->glTplObj->set('frmpackage', $packageObj->urlwithpara . '&action=' . $_REQUEST['action'] . '&eid=' . $_REQUEST['eid']);
        $configObj->glTplObj->set('BottomSubmitButtons', $configObj->glLibraryObj->GetSubmitButtons($packageObj->urlwithpara, 'bottom'));
        $configObj->glTplObj->set('packageaddTab', true);
        if ($_REQUEST['h_save'] == 'T') {
            $packageObj->varpostdata = $_REQUEST;

            if ($packageObj->update_package()) {
                if ($_POST['btnsaveandc_x'] != '') {
                    $configObj->glLibraryObj->header_redirect($packageObj->urlwithpara . '&action=' . $_REQUEST['action'] . '&eid=' . $_REQUEST['eid'] . '&msg=edit');
                } else if ($_POST['btnsaveande_x'] != '') {
                    $configObj->glLibraryObj->header_redirect($packageObj->urlwithpara . '&msg=edit');
                }
            }
        } else {
            $row = $packageObj->select_package($_REQUEST['eid']);
            $configObj->glTplObj->set('row', $row);
            $configObj->glTplObj->set('cattype', $packageObj->Bindcategorieshierarchy($row['fk_packagetype']));
        }

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

    case 'delete':

        if ($configObj->isAjaxSet) {
            $packageObj->delete_package();
        }

        break;

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


    default:
        $configObj->glTplObj->set('packageTab', true);
        $packageObj->load_package();
}
?>
