<?php
defined('_VALID') or die('Restricted access');
include_once('class.special.php');
$specialObj = new special($configObj);
$action = $_REQUEST['action'];
$configObj->glTplObj->change_path($configObj->currentModulePath . 'html/templates/');
$configObj->glTplObj->set('configObj', $configObj);
$configObj->glTplObj->set('specialObj', $specialObj);
$specialObj->intitialize();
$paramMain = $configObj->AllmoduleAccess[$configObj->ModuleName];
$configObj->glTplObj->set('paramMain', $paramMain);

switch ($action){
    case 'add':
        if ($paramMain['Add'] != 'Y') {
            $configObj->glLibraryObj->header_redirect('index.php?module=special');
        }
        $configObj->glTplObj->set('specialaddTab', true);
        if ($_REQUEST['h_save'] == 'T') {
            $specialObj->varpostdata = $_REQUEST;
            if ($specialObj->insert_special()) {
                if ($_POST['btnsaveandc_x'] != '') {
                    $eid = $specialObj->lastinsertid;
                    $configObj->glLibraryObj->header_redirect('index.php?module=special&action=edit&msg=add&eid=' . $eid);
                } else if ($_POST['btnsaveande_x'] != '') {
                    $configObj->glLibraryObj->header_redirect('index.php?module=special&msg=add');
                } else if ($_POST['btnsaveandnew_x'] != '') {
                    $configObj->glLibraryObj->header_redirect('index.php?module=special&action=add&msg=add');
                } else if ($_POST['btnsaveandcopy_x'] != '') {
                    $configObj->glLibraryObj->header_redirect('index.php?module=special&action=edit&msg=add&mode=copy&eid=' . $specialObj->lastinsertid);
                }
            }
        } else {
            if ($_REQUEST['msg'] == 'add') {
                $messagebox = $specialObj->configObj->glLibraryObj->message("The data has been successfully saved.");
                $specialObj->configObj->glTplObj->set('messagebox', $messagebox);
            } else if ($_REQUEST['msg'] == 'edit') {
                $messagebox = $specialObj->configObj->glLibraryObj->message("The data has been successfully edited and saved.");
                $specialObj->configObj->glTplObj->set('messagebox', $messagebox);
            }
            $specialaction = $specialObj->pagename . '&action=' . $action;
            $configObj->glTplObj->set('specialaction', $specialaction);
            $specialObj->Generateurl();
            $configObj->glTplObj->set('BottomSubmitButtons', $configObj->glLibraryObj->GetSubmitButtons($specialObj->urlwithpara, 'bottom'));
            $configObj->adminContentPanel = $configObj->glTplObj->process('special_add.tpl.php');
        }
        break;
        
        case 'sharedata':

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

    case 'edit':
        if($paramMain['Edit'] != 'Y'){
            $configObj->glLibraryObj->header_redirect('index.php?module=special');
        }
        $configObj->glTplObj->set('specialaddTab', true);
        $specialObj->Generateurl();
        $configObj->glTplObj->set('BottomSubmitButtons', $configObj->glLibraryObj->GetSubmitButtons($specialObj->urlwithpara, 'bottom'));
        if ($_REQUEST['h_save'] == 'T') {
            $specialObj->varpostdata = $_REQUEST;
            if ($specialObj->update_special()) {
                if ($_POST['btnsaveandc_x'] != '') {
                    $configObj->glLibraryObj->header_redirect($specialObj->urlwithpara . '&action=' . $_REQUEST['action'] . '&eid=' . $_REQUEST['eid'] . '&msg=edit');
                } else if ($_POST['btnsaveande_x'] != '') {
                    $configObj->glLibraryObj->header_redirect($specialObj->urlwithpara . '&msg=edit');
                } else if ($_POST['btnsaveandnew_x'] != '') {
                    $configObj->glLibraryObj->header_redirect($specialObj->urlwithpara . '&action=add&msg=edit');
                } else if ($_POST['btnsaveandcopy_x'] != '') {
                    $configObj->glLibraryObj->header_redirect($specialObj->urlwithpara . '&action=edit&msg=edit&mode=copy&eid=' . $_REQUEST['eid']);
                }
            }
        } else {
            if ($_REQUEST['msg']) {
                if ($_REQUEST['msg'] == 'add') {
                    $messagebox = $specialObj->configObj->glLibraryObj->message("The record has been successfully saved.");
                    $specialObj->configObj->glTplObj->set('messagebox', $messagebox);
                } else if ($_REQUEST['msg'] == 'edit') {
                    $messagebox = $specialObj->configObj->glLibraryObj->message("The record has been successfully edited and saved.");
                    $specialObj->configObj->glTplObj->set('messagebox', $messagebox);
                }
            }
            if ($_REQUEST['mode'] == 'copy') {
                $action = 'add';
                $configObj->glTplObj->set('action', $action);
            } else {
                $action = $_REQUEST['action'];
            }
            $specialaction = $specialObj->urlwithpara . '&action=' . $action . '&eid=' . $_REQUEST['eid'];
            $configObj->glTplObj->set('specialaction', $specialaction);
            $row = $specialObj->select_special($_REQUEST['eid']);
            $configObj->glTplObj->set('row', $row);
            $configObj->adminContentPanel = $configObj->glTplObj->process('special_add.tpl.php');
        }
        break;

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

    case 'delbrochureimg':
        $specialObj->delbrochureimg();
        ob_clean();
        break;


    case 'delbrochure':
        $specialObj->delbrochure();
        ob_clean();
        break;
    
    case 'delbrochureimg1':

        $specialObj->delbrochureimg1();
        ob_clean();
        break;
    
    case 'deletedocument':
        $id = $_GET['sid'];
        $file = $_GET['file'];
        $specialObj->deletedocument($id,$file);
        ob_clean();
        break;
    
    case 'updatepublish':
        $id = $_REQUEST['id'];
        $configObj->glLibraryObj->updatefieldinmultiple();
        echo 1;
        exit;

    default:
        $configObj->glTplObj->set('specialTab', true);
        $specialObj->load_special();
        break;
}
?>
