<?php

class service_category {

    var $pagename = 'index.php?module=service_category';
    var $int_glcode;
    var $chr_read;
    var $chr_star;
    var $chr_publish;
    var $intdisplayorder;
    var $chr_delete = 'Y';
    var $dt_createdate;
    var $dt_modifydate;
    var $oldint_displayorder;
    var $numofrows;
    var $numofpages;
    var $orderby = 'int_displayorder';
    var $ordertype = 'asc';
    var $searchby = '0';
    var $searchtxt;
    var $start = '0';
    var $pagesize = DEFAULT_PAGESIZE;
    var $pagenumber = '1';
    var $lastinsertid;
    var $urlwithpara = '';
    var $urlwithpoutsearch = '';
    var $urlwithoutsort = '';
    var $urlwithoutpaging = '';
    var $configObj;
    var $filterby = '0';
    var $urlwithoutfilter = '';
    var $display_limit_array = array(5, 10, 15, 30);
    var $varpostdata = array();

    function service_category($configObj) {
      //  $this->sortvar = '<img alt="sorting" src="' . GLOBAL_ADMIN_IMAGES_PATH . 'arrow-up.png" style="vertical-align:middle;">';
        $this->configObj = $configObj;
    }

    function intitialize() {
        $this->searchby = (isset($_REQUEST['searchby'])) ? $_REQUEST['searchby'] : $this->searchby;
        $_REQUEST['searchtxt'] = ($_REQUEST['type'] == 'autosearch') ? $_REQUEST['term'] : $_REQUEST['searchtxt'];
        $this->searchbyVal = (isset($_REQUEST['searchbyVal'])) ? $_REQUEST['searchbyVal'] : $this->searchbyVal;
        $this->searchtxt = (isset($_REQUEST['searchtxt'])) ? urldecode($_REQUEST['searchtxt']) : '';
        $this->searchtxtjs = (isset($_REQUEST['searchtxt'])) ? urlencode($_REQUEST['searchtxt']) : '';
        $this->orderby = (isset($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : $this->orderby;
        $this->ordertype = (isset($_REQUEST['ordertype'])) ? $_REQUEST['ordertype'] : $this->ordertype;
        $this->filterby = (isset($_REQUEST['filterby'])) ? $_REQUEST['filterby'] : $this->filterby;
        $this->accessories = (isset($_REQUEST['accessories'])) ? $_REQUEST['accessories'] : $this->accessories;

        if (isset($_REQUEST['sorting'])) {
            if ($this->ordertype == "asc") {   // This is for sort image
                $this->ordertype = "desc";
                $this->sortvar = "<img alt=\"sorting\" src=\"" . GLOBAL_ADMIN_IMAGES_PATH . "arrow-down.png\" style=\"vertical-align:middle;\">";
            } else if ($this->ordertype == "desc") {   // This is for sort image
                $this->ordertype = "asc";
                $this->sortvar = "<img alt=\"sorting\" src=\"" . GLOBAL_ADMIN_IMAGES_PATH . "arrow-up.png\" style=\"vertical-align:middle;\">";
            }
        } else {
        }
        $this->pagesize = (isset($_REQUEST['pagesize'])) ? $_REQUEST['pagesize'] : $this->pagesize;
        $this->pagenumber = (isset($_REQUEST['pagenumber'])) ? $_REQUEST['pagenumber'] : $this->pagenumber;
        $this->start = ($this->pagenumber - 1 ) * $this->pagesize;
    }

   

    function select_service_category($id) {
        $string = DEFAULT_DATEFORMAT;
        $this->configObj->glDbObj->resetfields(); // Reset the object
        $this->configObj->glDbObj->setQueryType('select');    // Set the Table
        $tablename = DB_PREFIX . "service_category";
        $this->configObj->glDbObj->setTable($tablename);
        $this->configObj->glDbObj->addColumn("*");
        $this->configObj->glDbObj->setWhere('int_glcode =' . $id);
        $row = $this->configObj->glDbObj->get_sql_row($this->configObj->glDbObj->buildQuery());
        return $row;
    }

    function CountRows() {
        $this->intitialize();
        if (trim($this->searchtxt) != '') {
            $whereclause .= ($this->searchby == '0') ? " and (var_title like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%') " : " and $this->searchby like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'";
        }
        if ($this->filterby != '0' && $this->filterby != '') {
            $filterarray = explode('-', $this->filterby);
            $whereclause .=" and $filterarray[0] = '$filterarray[1]'";
        }
        
        $sqlCountPages = "select count(1) as total from " . DB_PREFIX . "service_category where chr_delete = 'N'  $whereclause ";
        $rs = $this->configObj->glDbObj->get_sql_row($sqlCountPages);
        $this->numofrows = $rs['total'];
        return $rs['total'];
    }
    
     function catnews($id) {
        $sql = "select var_title from " . DB_PREFIX . "service_category where int_glcode=" . $id;
        $result = $this->configObj->glDbObj->get_sql_row($sql);
        return $result['var_title'];
    }

    
    function selectall_service_category() {
        
        $this->configObj->glDbObj->resetfields(); // Reset the object
        $this->configObj->glDbObj->setQueryType('select');    // Set the Table
        $tablename = DB_PREFIX . "service_category";
        $this->configObj->glDbObj->setTable($tablename);
        $this->configObj->glDbObj->addColumn('*');        

        $whereclause = "chr_delete = 'N'";
        if ($this->filterby != '0' && $this->filterby != '') {
            $filterarray = explode('-', $this->filterby);
            $whereclause .=" and $filterarray[0] = '$filterarray[1]'";
        }
        if($this->accessories!='0' && $this->accessories!='')
        {
            $whereclause .=" and accessory_type='".$this->accessories."'";
        }
        if (trim($this->searchtxt) != '') {
            $whereclause .= ($this->searchby == '0') ? " and (var_title like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%') " : " and $this->searchby like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'";
        }
        $this->configObj->glDbObj->setWhere($whereclause);
        $this->configObj->glDbObj->setOrderBy($this->orderby . ' ' . $this->ordertype);
        $this->configObj->glDbObj->setLimit($this->start . ', ' . $this->pagesize);

        if ($_REQUEST['type'] == 'autosearch') {
            $orderby = (isset($_REQUEST['orderby'])) ? 'order by ' . $this->orderby . ' ' . $this->ordertype : 'order by int_displayorder';

            $searchbyVal = (!empty($this->searchbyVal)) ? " chr_delete = 'N' and {$this->configObj->glDbObj->addSlashes($this->searchbyVal)} like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%' " : "$whereclause";

            if ($this->searchbyVal == '0') {
                $this->searchbyVal = "var_title";
            }
            if ($this->searchbyVal == 'var_title') {
                $this->searchbyVal = "var_title";
            }
            
            if ($this->filterby != '0' && $this->filterby != '') {
                $filterarray = explode('-', $this->filterby);
                $whereclauseauto = " and $filterarray[0] = '$filterarray[1]'";
            }
            
            $searchbyVal1 = "{$this->searchbyVal} like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%' and chr_delete = 'N'";
            $autoSearchQry = "select int_glcode ," . $this->searchbyVal . " as AutoVal FROM " . $tablename . " where  $searchbyVal1 $whereclauseauto group by " . $this->searchbyVal . " $orderby";
            $this->configObj->glLibraryObj->GetAutoSearch($autoSearchQry);
        }
        $rs = $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());

        return $rs;
    }

    // **********************
    // INSERT
    // **********************

    function insert_service_category() {
        
        $this->configObj->glLibraryObj->updatedisplay_order('service_category', $this->varpostdata['int_displayorder']);
        
        if ($_FILES['var_image']['name'] != '') {

            //for removing space in name
            $file_extension = $this->configObj->glLibraryObj->file_extension($_FILES['var_image']['name']);
            $photo = basename($_FILES['var_image']['name']);
            $photofile = str_replace(' ', '-', $photo);
            $phototitle = explode('.', $photofile);
            $var_title = $phototitle[0];
            $_FILES['var_image']['name'] = $photofile;
            if ($_REQUEST['fk_recid'] == 1) {
                $image_width = HOME_BANNER_WIDTH;
                $image_height = HOME_BANNER_HEIGHT;
            } else {
                $image_width = INNERBANNER_WIDTH;
                $image_height = INNERBANNER_HEIGHT;
            }
            $var_thumb = $this->upload_image('var_image', $image_width, $image_height, 'thumb_', $sess, $image_width, $image_height, 'thumb_');
            $this->imagename = $var_thumb;
        }
        if ($this->varpostdata['h_save'] == 'T') {            

            $this->int_glcode = ""; // clear key for autoincrement
            $this->configObj->glDbObj->resetfields();
            $tablename = DB_PREFIX . 'service_category';
            $this->configObj->glDbObj->setTable($tablename);
            $this->configObj->glDbObj->setQueryType('insert');

            // Set the Columns
            $this->configObj->glDbObj->addColumn('var_title');
            $this->configObj->glDbObj->addColumn('var_alias');  
            $this->configObj->glDbObj->addColumn('var_image');
            $this->configObj->glDbObj->addColumn('var_description');
            $this->configObj->glDbObj->addColumn('var_general_info');
            $this->configObj->glDbObj->addColumn('var_metatitle');
            $this->configObj->glDbObj->addColumn('var_metakeyword');
            $this->configObj->glDbObj->addColumn('var_metadescription');
            
            $this->configObj->glDbObj->addColumn('int_displayorder');
            $this->configObj->glDbObj->addColumn('dt_createdate');
            $this->configObj->glDbObj->addColumn('dt_modifydate');
            $this->configObj->glDbObj->addColumn('chr_delete');
            $this->configObj->glDbObj->addColumn('chr_publish');
            $this->configObj->glDbObj->addColumn('chr_read');
            

            $this->configObj->glDbObj->addValue($this->varpostdata['var_title']);
            $this->configObj->glDbObj->addValue($this->varpostdata['var_alias']);
           $this->configObj->glDbObj->addValue($this->imagename);
          
            if($this->varpostdata['var_desc'] == 'Y'){
             $this->configObj->glDbObj->addValue($this->varpostdata['text_fulltext']);   
            } else {
                $this->configObj->glDbObj->addValue('');  
            }     
            if($this->varpostdata['var_h_info'] == 'Y') { 
                $this->configObj->glDbObj->addValue($this->varpostdata['var_general_info']);
            } else {
                $this->configObj->glDbObj->addValue('');
            }
            $this->configObj->glDbObj->addValue($this->varpostdata['var_metatitle']);
            $this->configObj->glDbObj->addValue($this->varpostdata['var_metakeyword']);
            $this->configObj->glDbObj->addValue($this->varpostdata['var_metadescription']);
            
            
            $this->configObj->glDbObj->addValue($this->varpostdata['int_displayorder']);
            $this->configObj->glDbObj->addValue('NOW()');
            $this->configObj->glDbObj->addValue('NOW()');
            $this->configObj->glDbObj->addValue('N');
            $this->configObj->glDbObj->addValue($this->varpostdata['chr_publish']); 
            $this->configObj->glDbObj->addValue('Y');
            
            $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
            $this->lastinsertid = mysql_insert_id();
            $this->configObj->glLibraryObj->set_display_order_sequence(DB_PREFIX . 'service_category');
            $this->configObj->glLibraryObj->insertinlogmanager('97', DB_PREFIX . 'service_category', 'var_title', $this->lastinsertid, 'I');

            return true;
        }
    }
  
    function update_service_category() {
         if ($this->varpostdata['int_displayorder'] != $this->varpostdata['old_displayorder']) {
            $this->update_display_order($this->varpostdata['eid'], $this->varpostdata['int_displayorder'], $this->varpostdata['old_displayorder']);
        }
        
        if ($_FILES['var_image']['name'] != '') {

            //for removing space in name
            $file_extension = $this->configObj->glLibraryObj->file_extension($_FILES['var_image']['name']);
            $pdf = basename($_FILES['var_image']['name']);
            $pdffile = str_replace(' ', '-', $pdf);
            $pdfdata = explode('.', $pdffile);
            $var_title = $pdfdata[0];

            $_FILES['var_image']['name'] = $pdffile;
            $this->imagename = $_FILES['var_image']['name'];
            if ($_REQUEST['fk_recid'] == 1) {
                $image_width = HOME_BANNER_WIDTH;
                $image_height = HOME_BANNER_HEIGHT;
            } else {
                $image_width = INNERBANNER_WIDTH;
                $image_height = INNERBANNER_HEIGHT;
            }

            $var_thumb = $this->upload_image('var_image', $image_width, $image_height, 'thumb_', $sess, $image_width, $image_height, 'thumb_');
            $this->imagename = $var_thumb;
        }
        $this->configObj->glDbObj->resetfields();
        $this->configObj->glDbObj->setQueryType('update');
        $tablename = DB_PREFIX . 'service_category';
        $this->configObj->glDbObj->setTable($tablename);

        // Set the Columns
        
        $this->configObj->glDbObj->addColumn('var_title'); 
        $this->configObj->glDbObj->addColumn('var_alias'); 
        $this->configObj->glDbObj->addColumn('var_image'); 
        $this->configObj->glDbObj->addColumn('var_description');
        $this->configObj->glDbObj->addColumn('var_general_info');
        if ($this->configObj->glSessionObj->value('admin_id') == '1' || DISPLAY_ALL_SEO == 'Y') { 
            $this->configObj->glDbObj->addColumn('var_metatitle');
            $this->configObj->glDbObj->addColumn('var_metakeyword');
            $this->configObj->glDbObj->addColumn('var_metadescription');
        }
        $this->configObj->glDbObj->addColumn('int_displayorder');
        $this->configObj->glDbObj->addColumn('dt_modifydate');
        $this->configObj->glDbObj->addColumn('chr_publish');
        $this->configObj->glDbObj->addColumn('chr_read');
             

        // Set the Values
        $this->configObj->glDbObj->addValue($this->varpostdata['var_title']); 
        $this->configObj->glDbObj->addValue($this->varpostdata['var_alias']);
        $this->configObj->glDbObj->addValue($this->imagename);
        if($this->varpostdata['var_desc'] == 'Y'){
            $this->configObj->glDbObj->addValue($this->varpostdata['text_fulltext']);   
        } else {
            $this->configObj->glDbObj->addValue('');  
        }
        if($this->varpostdata['var_h_info'] == 'Y') { 
            $this->configObj->glDbObj->addValue($this->varpostdata['var_general_info']);
        } else {
            $this->configObj->glDbObj->addValue('');
        }
        if ($this->configObj->glSessionObj->value('admin_id') == '1' || DISPLAY_ALL_SEO == 'Y') { 
            $this->configObj->glDbObj->addValue($this->varpostdata['var_metatitle']);
            $this->configObj->glDbObj->addValue($this->varpostdata['var_metakeyword']);
            $this->configObj->glDbObj->addValue($this->varpostdata['var_metadescription']);
        }
        $this->configObj->glDbObj->addValue($this->varpostdata['int_displayorder']);
        $this->configObj->glDbObj->addValue('NOW()');
        $this->configObj->glDbObj->addValue($this->varpostdata['chr_publish']);
        $this->configObj->glDbObj->addValue('Y');
       
        
        $this->configObj->glDbObj->setWhere('int_glcode=' . $this->varpostdata['eid']);
        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        $this->lastinsertid = $this->varpostdata['eid'];
        $this->configObj->glLibraryObj->set_display_order_sequence(DB_PREFIX . 'service_category');
        $this->configObj->glLibraryObj->insertinlogmanager('97', DB_PREFIX . 'service_category', 'var_title', $this->lastinsertid, 'U');
        return true;
    }
    
    function upload_image($filefield, $thumb_width, $thumb_height, $prefix, $sess, $large_width, $large_height, $prefix2 = '') {
        $file_photo = basename($_FILES[$filefield]['name']);

        $imagename = $sess . $file_photo;
        $uploaddir = '../upimages/pagephoto/images/';
        $file_photo = $sess . basename($_FILES[$filefield]['name']);
        $file = $uploaddir . $file_photo;

        $tmp = $_FILES[$filefield]['tmp_name'];
        $uploadedfile = $_FILES[$filefield]['tmp_name'];

        // Create an Image from it so we can do the resize
        $image_info = getimagesize($uploadedfile);

        switch ($image_info['mime']) {
            case 'image/gif':
                $img_create = 'ImageCreateFromGIF';
                break;
            case 'image/jpeg':
                $img_create = 'ImageCreateFromJPEG';
                break;
            case 'image/png':
                $img_create = 'ImageCreateFromPNG';
                break;
            case 'image/bmp':
                $img_create = 'ImageCreateFromBMP';
                break;
        }
        $photoexe = explode('.', $imagename);
        $photoexename = $photoexe[count($photoexe) - 1];

        if ($photoexename == 'bmp') {

            $src = $this->configObj->glLibraryObj->imagecreatefrombmp($uploadedfile);
        } else {
            $src = @$img_create($uploadedfile);
        }
        list($width, $height) = getimagesize($uploadedfile);

        $newwidth = $width;
        $newheight = $height;

        $tmp = imagecreatetruecolor($newwidth, $newheight);
//      ============================== this code use for transparent image white background ============================
        $background_color = imagecolorallocate($tmp, 255, 255, 255);
        imagefill($tmp, 0, 0, $background_color);
//        ================================================================================================================
        imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
        imagejpeg($tmp, $file, 90);

        imagedestroy($src);
        imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request  // has completed.

        $source1 = $uploaddir . $file_photo;

        //$sess = time();
        $thumbfilename = $prefix . $sess . $file_photo;

        $target1 = $uploaddir . $prefix . $file_photo;

        $target2 = $uploaddir . $prefix2 . $file_photo;

        if ($large_width > 0) {


            $returnthumbmsg1 = $this->configObj->glLibraryObj->generate_thumb($source1, $thumb_width, false, false, $target1, false, null, $thumb_width, $thumb_height);
        }
        if ($large_width > 0) {
            $returnthumbmsg2 = $this->configObj->glLibraryObj->generate_thumb($source1, $thumb_width, false, false, $target2, false, null, $large_width, $large_height);
        }
        if ($returnthumbmsg1 == 'INVALID' || $returnthumbmsg2 == 'INVALID') {
            $this->chr_validthumb = 'N';
            $this->chr_validthumbdetail = 'N';
        } else {
            $this->chr_validthumb = 'Y';
            $this->chr_validthumbdetail = 'Y';
        }
        return $imagename;
    }

    function Generateurl() {
        $this->hurlwithpara = $this->pagename . '&' . 'hpagesize=' . $this->pagesize . '&hnumofrows=' . $this->numofrows . '&horderby=' . $this->orderby . '&hordertype=' . $this->ordertype . '&hsearchby=' . $this->searchby . '&hsearchtxt=' . $this->searchtxtjs . '&hpagenumber=' . $this->pagenumber . '&hfilterby=' . $this->filterby . '&history=T'.'&accessory_type='.$this->accessories;
        $this->urlwithpara = $this->pagename . '&' . 'pagesize=' . $this->pagesize . '&numofrows=' . $this->numofrows . '&orderby=' . $this->orderby . '&ordertype=' . $this->ordertype . '&searchby=' . $this->searchby . '&searchtxt=' . $this->searchtxtjs . '&pagenumber=' . $this->pagenumber . '&filterby=' . $this->filterby .'&history=T'.'&accessory_type='.$this->accessories;
        $this->urlwithpoutsearch = $this->pagename . '&' . 'pagesize=' . $this->pagesize . '&orderby=' . $this->orderby . '&ordertype=' . $this->ordertype . '&filterby=' . $this->filterby.'&history=T'.'&accessory_type='.$this->accessories;
        $this->urlwithoutsort = $this->pagename . '&' . 'pagesize=' . $this->pagesize . '&numofrows=' . $this->numofrows . '&searchby=' . $this->searchby . '&searchtxt=' . $this->searchtxtjs . '&pagenumber=' . $this->pagenumber . '&ordertype=' . $this->ordertype . '&filterby=' . $this->filterby.'&history=T'.'&accessory_type='.$this->accessories;
        $this->urlwithoutpaging = $this->pagename . '&orderby=' . $this->orderby . '&ordertype=' . $this->ordertype . '&searchby=' . $this->searchby . '&searchtxt=' . $this->searchtxtjs . '&filterby=' . $this->filterby.'&history=T'.'&accessory_type='.$this->accessories;
        $this->urlwithoutfilter = $this->pagename . '&' . 'pagesize=' . $this->pagesize . '&orderby=' . $this->orderby . '&ordertype=' . $this->ordertype . '&searchby=' . $this->searchby . '&searchtxt=' . $this->searchtxtjs.'&history=T'.'&accessory_type='.$this->accessories;
        $this->configObj->AutoSearchUrl = $this->urlwithpara . "&type=autosearch&searchbyVal=" . $this->searchbyVal.'&accessory_type='.$this->accessories;
    }

    function org_generateParam($view = 'service_category', $actionurl = 'index.php?module=service_category&action=add', $searchArray = array("var_title" => "service_category"), $table = 'fc_service_category', $position = 'top') {
        $filterPos = ($position == 'top') ? 'FT' : 'FB';
        
        if ($this->configObj->glSessionObj->value('admin_id') == '1') {
            $filterstar = array(
                'filterurl' => $this->urlwithoutfilter,
                'filterposition' => $filterPos,
                'filterby' => $this->filterby
            );
        } else {
            $filterstar = array();
        }
        return array('pageurl' => $this->pagename,
            'heading' => $view,
            'listImage' => 'add-new-user-icon.png',
            'tablename' => $table,
            'position' => $position,
            'actionImage' => 'add-new-button-blue.gif',
            'actionImageHover' => 'add-new-button-blue-hover.gif',
            'actionUrl' => $actionurl,
            'search' => array('searchArray' => $searchArray,
                'searchBy' => $this->searchby,
                'searchText' => $this->searchtxt,
                'searchUrl' => $this->urlwithpoutsearch
            ),
            'filter' => $filterstar,
            'paging' => array('pagenumber' => $this->pagenumber,
                'noofpages' => $this->noofpages,
                'numofrows' => $this->numofrows,
                'pagingurl' => $this->urlwithpara
            ),
            'display' => array('displayurl' => $this->urlwithoutpaging,
                'pagesize' => $this->pagesize,
                'limitarray' => $this->display_limit_array,
                
            ),
            'accessories' => $accessories,
        );
    }

    function update_display_order($ids, $values, $oldvalues) {
        $tablename = "service_category";

        for ($i = 0; $i < count($ids); $i++) {
            // Updation Of the Display Order
            if ($values[$i] != $oldvalues[$i]) {
                $this->configObj->glDbObj->resetfields();

                $this->configObj->glDbObj->setQueryType('select');

                $this->configObj->glDbObj->setTable(DB_PREFIX . "service_category");

                $this->configObj->glDbObj->addColumn('count(1) as total');

                $this->configObj->glDbObj->setWhere("int_displayorder=" . $values[$i] . " and chr_delete = 'N' $updatewhereclause");

                $rs = $this->configObj->glDbObj->get_sql_row($this->configObj->glDbObj->buildQuery());

                if ($rs['total'] > 0) {
                    if ($values[$i] > $oldvalues[$i]) {
                        $this->configObj->glDbObj->resetfields();

                        $this->configObj->glDbObj->setTable(DB_PREFIX . "service_category");

                        $this->configObj->glDbObj->setQueryType('update');

                        $this->configObj->glDbObj->addColumn('int_displayorder');

                        $this->configObj->glDbObj->UnsetQuotes();

                        $this->configObj->glDbObj->addValue('int_displayorder - 1');

                        $this->configObj->glDbObj->SetQuotes();

                        $this->configObj->glDbObj->setWhere('int_displayorder > ' . $oldvalues[$i] . ' and  int_displayorder <= ' . $values[$i] . '' . $updatewhereclause);

                        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
                    } else {
                        $this->configObj->glDbObj->resetfields();

                        $this->configObj->glDbObj->setTable(DB_PREFIX . "service_category");

                        $this->configObj->glDbObj->setQueryType('update');

                        $this->configObj->glDbObj->addColumn('int_displayorder');

                        $this->configObj->glDbObj->UnsetQuotes();

                        $this->configObj->glDbObj->addValue('int_displayorder + 1');

                        $this->configObj->glDbObj->SetQuotes();

                        $this->configObj->glDbObj->setWhere('int_displayorder >= ' . $values[$i] . ' and  int_displayorder < ' . $oldvalues[$i] . '' . $updatewhereclause);

                        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
                    }
                }
                $this->configObj->glDbObj->resetfields();

                $this->configObj->glDbObj->setTable(DB_PREFIX . "service_category");

                $this->configObj->glDbObj->setQueryType('update');

                $this->configObj->glDbObj->addColumn('int_displayorder');

                $this->configObj->glDbObj->addValue($values[$i]);

                $this->configObj->glDbObj->setWhere('int_glcode=' . $ids[$i] . '' . $updatewhereclause);

                $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());

                }
        }
    }

  

    function load_service_category() {

        if ($_REQUEST['task'] == 'orderupdate') {
            $updateids = $_REQUEST['uids'];
            $updatevalues = $_REQUEST['uvals'];
            $updateoldvalues = $_REQUEST['uoldvals'];
            $upidsarray = explode(',', $updateids);
            $upvalsarray = explode(',', $updatevalues);
            $upoldvalsarray = explode(',', $updateoldvalues);
            $this->update_display_order($upidsarray, $upvalsarray, $upoldvalsarray,'service_category');
            $tablename = "" . DB_PREFIX . 'service_category';
            $this->configObj->glLibraryObj->set_display_order_sequence($tablename);
        }

        $this->loadCount('CountRows');
        $this->configObj->glTplObj->set('speakercategoryTab', true);
        $this->configObj->glTplObj->set('numofrows', $this->CountRows());
        
        $result = $this->selectall_service_category();
        $this->configObj->glTplObj->set('result', $result);

        $this->Generateurl();
        $view = 'Manage Service Categories';
        $actionurl = 'index.php?module=service_category&action=add';
        $searchArray = array("var_title" => "service_category");
        $table = DB_PREFIX . "service_category";
        $parmas = $this->org_generateParam($view, $actionurl, $searchArray, $table);
        $this->configObj->glTplObj->set('headerpanel', $this->configObj->glLibraryObj->generateHeaderPanel($parmas));
        $this->configObj->glTplObj->set('pagingTop', $this->configObj->glLibraryObj->generatePagingPannel($parmas));
        $this->configObj->glTplObj->set('pagingBottom', $this->configObj->glLibraryObj->generatePagingPannel($this->org_generateParam($view, $actionurl, $searchArray, $table, 'bottom')));

        // Set the sorting image
        $tmpsetsortvar = 'setsortimg' . $this->orderby;
        $$finalsortvar = $tmpsetsortvar;
        $this->configObj->glTplObj->set($$finalsortvar, $this->sortvar);

        // End of Set the sorting image

        if ($_REQUEST['msg']) {
            if ($_REQUEST['msg'] == 'add') {
                $messagebox = $this->configObj->glLibraryObj->message("Congrats! The record has been successfully saved.");
                $this->configObj->glTplObj->set('messagebox', $messagebox);
            } else if ($_REQUEST['msg'] == 'edit') {
                $messagebox = $this->configObj->glLibraryObj->message("Congrats! The record has been successfully edited.");
                $this->configObj->glTplObj->set('messagebox', $messagebox);
            }
        }

        $notemessagebox = $this->configObj->glLibraryObj->notemessage("Note: ", "Adding service categories are incremental, once you add a new service categories it will display as first service categories and previous service categories will move down in the order.");
        $this->configObj->glTplObj->set('notemessagebox', $notemessagebox);

        if ($this->configObj->isAjaxSet) {
            echo $this->configObj->glTplObj->process('service_category.tpl.php');
            exit;
        } else {
            $this->configObj->adminContentPanel = $this->configObj->glTplObj->process('service_category.tpl.php');
        }
    }

    function loadCount($function) {
        $this->intitialize();
        $this->numofrows = (isset($_REQUEST['numofrows'])) ? $_REQUEST['numofrows'] : $this->{$function}();
        $this->noofpages = intval($this->numofrows / $this->pagesize);
        $this->noofpages = (($this->numofrows % $this->pagesize) > 0) ? ($this->noofpages + 1) : ($this->noofpages);
        $this->configObj->glTplObj->set('numofrows', $this->numofrows);
        $this->Generateurl();
    }

    //end of class


    function delete_service_category() {
        $deleteids = $_REQUEST['dids'];
        $deletearray = explode(',', $deleteids);
        $totaldeletedrecords = count($deletearray);
        $is_assigned = 0;
        $delcount = 0;
        $tablename = DB_PREFIX . 'service_category';
        for ($i = 0; $i < $totaldeletedrecords; $i++) {

            $sql = "Update " . DB_PREFIX . "service_category set chr_delete='Y', var_ipaddress='" . $_SERVER['REMOTE_ADDR'] . "',var_adminuser='" . ADMIN_NAME . "', dt_modifydate=NOW() where int_glcode='$deletearray[$i]'";
            $this->configObj->glDbObj->query($sql);
            $delcount++;
            
            $this->configObj->glLibraryObj->insertinlogmanager('97', $tablename, 'var_title', $deletearray[$i], 'D');
        }
        $this->load_service_category();
        exit;
    }
    
    function count_rec($id) {
        $total = "SELECT count(1) as total from ". DB_PREFIX ."services where chr_delete='N' and fk_category ='" . $id . "'";
        $rs = $this->configObj->glDbObj->get_sql_row($total);
        return $rs['total'];
    }
}

?>