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


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

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

    case 'edit':
        
        if ($paramMain['Edit'] != 'Y') {
            $configObj->glLibraryObj->header_redirect('index.php?module=service_category');
        }
        $date_news = DEFAULT_DATEFORMAT;
        $configObj->glTplObj->set('date_news', $date_news);
        $pservice_categoryObj->loadCount('CountRows');
      $configObj->glTplObj->set('service_categoryaddTab', true);

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

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

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

    case 'delete':
        if ($configObj->isAjaxSet) {
            $pservice_categoryObj->delete_service_category();
        }
        break;
        
        case 'history':
			
                   if ($paramMain['History'] == 'Y') {
                      
            include_once('../libraries/class.history.php');
            $id = $_REQUEST['id'];
            $tablename = DB_PREFIX ."service_category";
            $configObj->glTplObj->set('service_categoryViewTab', 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();
                $pservice_categoryObj->configObj->glTplObj->set('newAddedHistory', $historyObj->new_added_history());
                $_REQUEST['orderby'] = $pservice_categoryObj->orderby;
                $_REQUEST['ordertype'] = $pservice_categoryObj->ordertype;
                $pagesObj->loadpage();

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

                if (!$configObj->isAjaxSet) {
                    $historyObj->backbuttonurl = str_replace("&h", "&", $blogObj->hurlwithpara);
                }
                $historyObj->load_history();
            }
        } else {
            $configObj->glLibraryObj->header_redirect('index.php?module=service_category');
        }
                break;
        
    case 'sametitle' :
        
        if($_REQUEST['id']!='')
        {
            $eid = " and int_glcode!='".$_REQUEST['id']."'";
        }
        $sql = "select count(1) as total from ".DB_PREFIX."service_category 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('service_categoryTab', true);
        $pservice_categoryObj->load_service_category();
}
?>
