<?php

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

switch ($action) {

    case 'add':

        $configObj->glTplObj->set('servicesAddTab', true);
        if ($paramMain['Add'] != 'Y') {
            $configObj->glLibraryObj->header_redirect('index.php?module=services');
        }
        if ($_REQUEST['h_save'] == 'T') {
            $servicesObj->varpostdata = $_REQUEST;

            if ($servicesObj->insert_services()) {
                if ($_POST['btnsaveandc_x'] != '') {
                    $eid = $servicesObj->lastinsertid;
                    $configObj->glLibraryObj->header_redirect('index.php?module=services&action=edit&msg=add&eid=' . $eid);
                } else if ($_POST['btnsaveande_x'] != '') {
                    $configObj->glLibraryObj->header_redirect('index.php?module=services&msg=add');
                } else if ($_POST['btnsaveandnew_x'] != '') {
                    $configObj->glLibraryObj->header_redirect('index.php?module=services&action=add&msg=add');
                } else if ($_POST['btnsaveandcopy_x'] != '') {
                    $configObj->glLibraryObj->header_redirect('index.php?module=services&action=edit&msg=add&mode=copy&eid=' . $newsObj->lastinsertid);
                }
            }
        } else {
            
            if ($_REQUEST['msg'] == 'add') {
                $messagebox = $servicesObj->configObj->glLibraryObj->message("The data has been successfully saved.");
                $servicesObj->configObj->glTplObj->set('messagebox', $messagebox);
            } else if ($_REQUEST['msg'] == 'edit') {
                $messagebox = $servicesObj->configObj->glLibraryObj->message("The data has been successfully edited and saved.");
                $servicesObj->configObj->glTplObj->set('messagebox', $messagebox);
            }
            $servicesObj->Generateurl();
            $configObj->glTplObj->set('fk_tml_modules', 26);
            $configObj->glTplObj->set('BottomSubmitButtons', $configObj->glLibraryObj->GetSubmitButtons($servicesObj->urlwithpara, 'bottom'));
            $configObj->glTplObj->set('title',$servicesObj->combo());
            $configObj->adminContentPanel = $configObj->glTplObj->process('add_services.tpl.php');
        }
        break;

    case 'edit':

        $configObj->glTplObj->set('servicesAddTab', true);
        if ($paramMain['Edit'] != 'Y') {
            $configObj->glLibraryObj->header_redirect('index.php?module=services');
        }
        $servicesObj->Generateurl();
        $configObj->glTplObj->set('BottomSubmitButtons', $configObj->glLibraryObj->GetSubmitButtons($servicesObj->urlwithpara, 'bottom'));
      
        if ($_REQUEST['h_save'] == 'T') {
          // if (isset($_REQUEST['eid']) && $_REQUEST['eid'] != '') {  
            $servicesObj->varpostdata = $_REQUEST;

            if ($servicesObj->update_services()) {

                if ($_POST['btnsaveandc_x'] != '') {
                    $configObj->glLibraryObj->header_redirect($servicesObj->urlwithpara . '&action=' . $_REQUEST['action'] . '&eid=' . $_REQUEST['eid'] . '&msg=edit');
                } else if ($_POST['btnsaveande_x'] != '') {
                    $configObj->glLibraryObj->header_redirect($servicesObj->urlwithpara . '&msg=edit');
                } else if ($_POST['btnsaveandnew_x'] != '') {

                    $configObj->glLibraryObj->header_redirect($servicesObj->urlwithpara . '&action=add&msg=edit');
                } else if ($_POST['btnsaveandcopy_x'] != '') {
                    $configObj->glLibraryObj->header_redirect($servicesObj->urlwithpara . '&action=edit&msg=edit&mode=copy&eid=' . $_REQUEST['eid']);
                }
            }
        } else {
           //  echo "4444";exit;
            if ($_REQUEST['msg']) {
                if ($_REQUEST['msg'] == 'add') {
                    $messagebox = $servicesObj->configObj->glLibraryObj->message("The record has been successfully saved.");
                    $servicesObj->configObj->glTplObj->set('messagebox', $messagebox);
                } else if ($_REQUEST['msg'] == 'edit') {
                    $messagebox = $servicesObj->configObj->glLibraryObj->message("The record has been successfully edited and saved.");
                    $servicesObj->configObj->glTplObj->set('messagebox', $messagebox);
                }
            }
            if ($_REQUEST['mode'] == 'copy') {
                $action = 'add';
                $configObj->glTplObj->set('action', $action);
            } else {
                $action = $_REQUEST['action'];
            }
            $row = $servicesObj->select_services($_REQUEST['eid']);
            $configObj->glTplObj->set('row', $row);
            $newsaction = $servicesObj->urlwithpara . '&action=' . $action . '&eid=' . $_REQUEST['eid'];
            $configObj->glTplObj->set('newsaction', $newsaction);
            $configObj->glTplObj->set('fk_tml_modules', 26);
            $row = $servicesObj->select_services($_REQUEST['eid']);
            $configObj->glTplObj->set('title',$servicesObj->combo($row['fk_category']));
            $configObj->adminContentPanel = $configObj->glTplObj->process('add_services.tpl.php');
        }
        break;

    case 'delete':
        if ($configObj->isAjaxSet) {
            $servicesObj->is_servicesused();
        }
        break;
        
   case 'updatepublish':
        $id = $_REQUEST['id'];
        $configObj->glLibraryObj->updatefieldinmultiple();
        echo 1;
        exit;     
        
    default:

        $servicesObj->load_services();
        break;
}
?>