<?php

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

switch ($action) {
    case 'add':
        if ($paramMain['Add'] != 'Y') {
            $configObj->glLibraryObj->header_redirect('index.php?module=commonpdf');
        }
        $date_news = DEFAULT_DATEFORMAT;
        $configObj->glTplObj->set('date_news', $date_news);
        $commonpdfObj->pagename = 'index.php?module=commonpdf'; // Attribute of Page Name
        $commonpdfObj->countFunction = $commonpdfObj->CountRows();
        $configObj->glTplObj->set('pdfAddTab', true);
        $commonpdfObj->loadCount("CountRows");
        $commonpdfObj->varpostdata = $_REQUEST;

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

    case 'edit':

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

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

        if ($_REQUEST['h_save'] == 'T') {
            $commonpdfObj->varpostdata = $_REQUEST;
            if ($commonpdfObj->update_commonpdf()) {
                if ($_POST['btnsaveandc_x'] != '') {
                    $configObj->glLibraryObj->header_redirect($commonpdfObj->urlwithpara . '&action=' . $_REQUEST['action'] . '&eid=' . $_REQUEST['eid'] . '&msg=edit');
                } else if ($_POST['btnsaveande_x'] != '') {
                    $configObj->glLibraryObj->header_redirect($commonpdfObj->urlwithpara . '&msg=edit');
                }
            }
        } else {
            $row = $commonpdfObj->select_commonpdf($_REQUEST['eid']);
            $configObj->glTplObj->set('row', $row);
        }

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

    case 'delete':
        if ($configObj->isAjaxSet) {
            $commonpdfObj->delete_commonpdf();
        }
        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('pdfTab', true);
        $commonpdfObj->load_commonpdf();
}
?>
