<?php

class pages {

    var $int_glcode;
    var $fk_pages;
    var $var_pagename;
    var $var_alias;
    var $text_fulltext;
    var $var_metatitle;
    var $var_metakeyword;
    var $var_metadescription;
    var $int_displayorder;
    var $chr_access = 'P';
    var $chr_publish = 'Y';   // (normal Attribute)
    var $chr_delete = 'N';   // (normal Attribute)
    var $dt_createdate;   // (normal Attribute)
    var $dt_modifydate;   // (normal Attribute)
    var $chr_star;
    var $chr_read;   // (normal Attribute)
    var $oldint_displayorder; // Attribute of Old Displayorder
    var $pagename = 'index.php?module=pages'; // Attribute of Page Name
    var $numofrows; // Attribute of Num Of Rows In Result
    var $numofpages; // Attribute of Num Of Pagues In Result
    var $orderby = 'int_displayorder'; // Attribute of Deafult Order By
    var $ordertype = 'asc'; // Attribute of Deafult Order By
    var $searchby = '0'; // Attribute of Search By
    var $searchtxt; // Attribute of Search Text
    var $start = 1; // Attribute of Start For Paging
    var $pagesize = DEFAULT_PAGESIZE; // Attribute of Pagesize For Paging
    var $pagenumber = '1';
    var $lastinsertid;
    var $urlwithpara = '';
    var $urlwithpoutsearch = '';
    var $urlwithoutsort = '';
    var $urlwithoutpaging = '';
    var $filterby = '0';
    var $urlwithoutfilter = '';
    var $display_limit_array = array('5', '10', '20', '30');
    var $fk_module = '1';

    function pages($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;

        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->sortvar = "<img alt=\"sorting\" src=\"" . GLOBAL_ADMIN_IMAGES_PATH . "arrow-up.png\" style=\"vertical-align:middle;\">";
        }
        $this->numofrows = $this->CountRows();
        $this->pagesize = (isset($_REQUEST['pagesize'])) ? $_REQUEST['pagesize'] : $this->pagesize;
        $this->pagenumber = (isset($_REQUEST['pagenumber'])) ? $_REQUEST['pagenumber'] : $this->pagenumber;
        $this->noofpages = intval($this->numofrows / $this->pagesize);
        $this->noofpages = (($this->numofrows % $this->pagesize) > 0) ? ($this->noofpages + 1) : ($this->noofpages);
        $this->start = ($this->pagenumber - 1 ) * $this->pagesize;
    }

    function CountRows() {
        if (trim($this->searchtxt) != '') {
            $whereclauseids .= ($this->searchby == '0') ? " and var_pagename like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'" : " and $this->searchby like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'";
            $sqlgetinds = "select int_glcode,fk_pages FROM " . DB_PREFIX . "pages where chr_delete='N' and chr_previewstatus='N' $whereclauseids";
            $rsmatchedpagesids = $this->configObj->glDbObj->query($sqlgetinds);
            $pages = array();
            while ($row = $this->configObj->glDbObj->fetch_array($rsmatchedpagesids)) {
                $pages[] = $row['int_glcode'];
                $pages[] = $row['fk_pages'];
            }
            if (count($pages) > 0) {
                $strinds = implode(',', $pages);
                $whereclause .= " and  int_glcode in ($strinds)";
            } else {
                $whereclause .= " and  int_glcode in (0)";
            }
        }
        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 . "pages  where chr_displaycontent='Y' and chr_delete='N' and chr_previewstatus='N' $whereclause ";
        $rs = $this->configObj->glDbObj->get_sql_row($sqlCountPages);
        return $rs['total'];
    }

    function select_pages($id) {
        $query = "select * from " . DB_PREFIX . "pages where int_glcode=" . $id;
        $row = $this->configObj->glDbObj->get_sql_row($query);
        return $row;
    }

    function selectall_commonpdf() {
        $this->configObj->glDbObj->resetfields(); // Reset the object
        $this->configObj->glDbObj->setQueryType('select');    // Set the Table
        $tablename = DB_PREFIX . "pdf_mst";
        $this->configObj->glDbObj->setTable($tablename);
        $this->configObj->glDbObj->addColumn('*');
        $this->configObj->glDbObj->setWhere(" chr_delete = 'N' and chr_publish='Y' order by int_displayorder");
        $rs = $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());

        return $rs;
    }

    function countall_commonpdf() {
        $this->configObj->glDbObj->resetfields(); // Reset the object
        $this->configObj->glDbObj->setQueryType('select');    // Set the Table
        $tablename = DB_PREFIX . "pdf_mst";
        $this->configObj->glDbObj->setTable($tablename);
        $this->configObj->glDbObj->addColumn('count(0) as total');
        $this->configObj->glDbObj->setWhere(" chr_delete = 'N' and chr_publish='Y' order by int_displayorder");
        $data = $this->configObj->glDbObj->get_sql_row($this->configObj->glDbObj->buildQuery());
        return $data['total'];
    }

    function selectall() {
        if (trim($this->searchtxt) != '') {
            $whereclauseids = "chr_delete = 'N' and chr_previewstatus='N'";
            $whereclauseids .= ($this->searchby == '0') ? " and var_pagename like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'  " : " and $this->searchby like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'"; //change by jshah 040211
            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 chr_previewstatus='N' and {$this->searchbyVal} like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%' " : " {$whereclauseids} ";
                if ($this->searchbyVal == '0' || $this->searchbyVal == '') {
                    $this->searchbyVal = "var_pagename";
                }
                if ($this->filterby != '0' && $this->filterby != '') {
                    $filterarray = explode('-', $this->filterby);
                    $searchbyVal .=" and p.$filterarray[0] = '$filterarray[1]'";
                }
                $autoSearchQry = "select int_glcode ,{$this->searchbyVal} as AutoVal  FROM " . DB_PREFIX . "pages where $searchbyVal group by var_pagename $orderby";
                $this->configObj->glLibraryObj->GetAutoSearch($autoSearchQry);
            }
            $sqlgetinds = "select int_glcode,fk_pages FROM " . DB_PREFIX . "pages where $whereclauseids";
            $rsmatchedpagesids = $this->configObj->glDbObj->query($sqlgetinds);
            $pages = array();
            while ($row = $this->configObj->glDbObj->fetch_array($rsmatchedpagesids)) {
                $pages[] = $row['int_glcode'];
                $pages[] = $row['fk_pages'];
                while ($row['fk_pages'] != '0') {
                    $sqlquery = "select int_glcode,fk_pages FROM " . DB_PREFIX . "pages where chr_delete='N' and chr_previewstatus='N' and int_glcode='" . $row['fk_pages'] . "'";
                    $row = $this->configObj->glDbObj->get_sql_row($sqlquery);
                    $pages[] = $row['fk_pages'];
                }
            }
            $pages = array_unique($pages);
            if (count($pages) > 0) {
                $strinds = implode(',', $pages);
                $whereclause .= " and p.int_glcode in ($strinds)";
            } else {
                $whereclause .= " and p.int_glcode in (0)";
            }
        }
        if ($this->filterby != '0' && $this->filterby != '') {
            $filterarray = explode('-', $this->filterby);
            $whereclause.=" and p.$filterarray[0] = '$filterarray[1]'";
        }
        $whereCond = $whereclause;
        $orderby = (isset($_REQUEST['orderby'])) ? 'order by ' . $this->orderby . ' ' . $this->ordertype : 'order by p.int_displayorder';
        $sqlSelectPages = "select  p.int_glcode as id,p.var_pagename as name,p.fk_pages,p.*,m.var_modulename,m.chr_powerpanel_module FROM " . DB_PREFIX . "pages p left join " . DB_PREFIX . "modules m ON p.var_pagetype = m.int_glcode where 1 and p.chr_displaycontent='Y' and  p.chr_delete='N' and p.chr_previewstatus='N' $whereclause $orderby";
        $rs = $this->configObj->glDbObj->query($sqlSelectPages);
        $children = array();
        $pitems = array();
        while ($row = $this->configObj->glDbObj->fetch_array($rs)) {
            $pitems[] = $row;
        }
        if ($pitems) {
            foreach ($pitems as $p) {
                $fk_dbprefix_pages = 'fk_pages';
                $pt = $p[$fk_dbprefix_pages];
                $list = @$children[$pt] ? $children[$pt] : array();
                array_push($list, $p);
                $children[$pt] = $list;
            }
        }
        $list = $this->treerecurse(0, '&nbsp;&nbsp;&nbsp;', array(), $children, 10, 0);
        $list = array_slice($list, $this->start, $this->pagesize);
        return $list;
    }

    function treerecurse($id, $indent, $list, $children, $maxlevel = PAGE_HIERARCHY_LEVEL, $level = 0, $type = 1) {
        if ($children[$id] && $level <= $maxlevel) {

            foreach ($children[$id] as $c) {
                $id = $c['id'];
                if ($type) {
                    $pre = '<sup>|_</sup>&nbsp;';
                    $spacer = '.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                } else {
                    $pre = '|_ ';
                    $spacer = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                }
                if ($c['fk_pages'] == 0) {
                    $txt = $c['name'];
                } else {
                    $txt = $pre . $c['name'];
                }
                $pt = $c['fk_pages'];
                $list[$id] = $c;
                $list[$id]['treename'] = "$indent$txt";
                $list[$id]['children'] = count($children[$id]);
                $list = $this->treerecurse($id, $indent . $spacer, $list, $children, $maxlevel, $level + 1, $type);
            }
        }
        return $list;
    }

    function count_fk_pages($parent_id) {
        $sql = "select count(0) as total from " . DB_PREFIX . "pages where chr_delete='N' and chr_publish='Y' and fk_pages=" . $parent_id;
        $rs = $this->configObj->glDbObj->get_sql_row($sql);
        $fk_total = $rs['total'];
        return $fk_total;
    }

    function Bindpageshierarchy($name, $selected_id, $class = 'listbox') {
        if ($this->configObj->glSessionObj->value('admin_id') == '1') {
            
        } else {
            $dipnopar = "disabled";
        }
        $sql = "SELECT int_glcode AS id, var_pagename AS name, fk_pages FROM " . DB_PREFIX . "pages
                WHERE chr_publish = 'Y'
                AND chr_delete = 'N' AND  chr_menu_display='Y' and chr_previewstatus='N' and chr_mainparent='N'
                ORDER BY int_displayorder";
        $rs = $this->configObj->glDbObj->query($sql);
        $children = array();
        $pitems = array();
        while ($row = $this->configObj->glDbObj->fetch_array($rs)) {
            $pitems[] = $row;
        }
        if ($pitems) {
            foreach ($pitems as $p) {
                $pt = $p['fk_pages'];
                $list = @$children[$pt] ? $children[$pt] : array();
                array_push($list, $p);
                $children[$pt] = $list;
            }
        }
        $list = $this->treerecurse(0, '&nbsp;&nbsp;&nbsp;', array(), $children, 10, 0, 0);
        $display_output = '<select name="' . $name . '" id="' . $name . '" ' . $classname . ' size="10" style="width: 356px;">';
        $display_output .="<option value=\"0\" " . (($selected_id == '0') ? $dipnopar : $dipnopar) . ">No parent</option>";
        $temp1 = "";
        $temp = "";
        foreach ($list as $item) {
            if ($item['id'] == $_REQUEST['eid'] || $item['fk_pages'] == $_REQUEST['eid']) {
                $disabled = " disabled='disabled' ";
                $temp1 = $item['id'];
            } else if ($item['fk_pages'] == $temp || $item['fk_pages'] == $temp1 || $tempfk == $item['fk_pages']) {
                $disabled = " disabled='disabled' ";
                $temp = $item['id'];
                $tempfk = $item['fk_pages'];
            } else {
                $disabled = "";
            }
            $display_output.="<option value=" . $item['id'] . " " . (($item['id'] == $selected_id) ? 'selected' : '') . " " . $disabled . ">" . $item['treename'] . "</option>";
        }
        return $display_output;
    }

    function selectall_cms() {
        $sqlSelectPages = "select ";
        if (SITE_SEO == 'Y') {
            $sqlSelectPages .="case when p.fk_customtype <>0 then p.var_alias
                    when p.var_pagetype = 0 then p.var_alias
                   else p.var_alias
                   end as link";
        } else {
            $sqlSelectPages .="case when p.fk_customtype <>0 then concat('index.php?module=',m.var_modulename,'&amp;PageId=',p.int_glcode)
                   when p.var_pagetype = 0 then concat( 'index.php?pageId=', p.int_glcode )
                   else concat( 'index.php?module=', var_modulename)
                   end as link";
        }
        $sqlSelectPages .=" ,p.int_glcode as id,p.var_pagename as name,p.fk_pages,p.* from " . DB_PREFIX . "pages p left join " . DB_PREFIX . "modules m on m.int_glcode=p.var_pagetype where p.chr_delete = 'N' and p.chr_publish = 'Y' and p.chr_displaycontent='Y' and p.chr_delete='N' and p.chr_previewstatus='N' ORDER BY p.int_displayorder ASC";
        $rs = $this->configObj->glDbObj->query($sqlSelectPages);
        $children = array();
        $pitems = array();
        while ($row = $this->configObj->glDbObj->fetch_array($rs)) {
            $pitems[] = $row;
        }
        if ($pitems) {
            foreach ($pitems as $p) {
                $fk_dbprefix_pages = 'fk_pages';
                $pt = $p[$fk_dbprefix_pages];
                $list = @$children[$pt] ? $children[$pt] : array();
                array_push($list, $p);
                $children[$pt] = $list;
            }
        }
        $list = $this->treerecurse(0, '&nbsp;&nbsp;&nbsp;', array(), $children, 10, 0);
        $list = array_slice($list, 0, 100);
        return $list;
    }

    function getparentcategoryid() {
        if (!empty($this->varpostdata['fk_pages'])) {
            if ($this->varpostdata['fk_pages'] != 0) {
                $id = $this->varpostdata['fk_pages'];
            } else {
                $id = 1;
            }
        } else {
            $id = 0;
        }
        if ($id == 0) {
            $root_id = 1;
        } else {
            $root_id = $id;
        }
        $this->root_id = $root_id;
        return $id;
    }

    function insert_lft_rft() {
        if ($this->varpostdata['fk_pages'] != 0) {
            $id = $this->varpostdata['fk_pages'];
        } else {
            $id = 1;
        }
        $sql_lft_rgt = 'select int_lft, int_rgt from ' . DB_PREFIX . 'pages where int_glcode =' . $id;
        $row_lft_rgt = $this->configObj->glDbObj->get_sql_row($sql_lft_rgt);
        $left = $row_lft_rgt['int_rgt'];
        $right = $left + 1;
        $update_lft = 'update ' . DB_PREFIX . 'pages set int_lft = int_lft+2 where int_lft >"' . $row_lft_rgt['int_rgt'] . '" ';
        $this->configObj->glDbObj->query($update_lft);
        $update_rgt = 'update ' . DB_PREFIX . 'pages set int_rgt=int_rgt+2 where int_rgt >="' . $row_lft_rgt['int_rgt'] . '" ';
        $this->configObj->glDbObj->query($update_rgt);
        $this->left = $left;
        $this->right = $right;
    }

    // use for update category;
    function update_lft_rft() {
        $id = $this->getparentcategoryid();
        $sql_1 = "select int_glcode,fk_pages,int_lft,int_rgt from " . DB_PREFIX . "pages where int_glcode=" . $this->varpostdata['eid'];
        $row_1 = $this->configObj->glDbObj->get_sql_row($sql_1);
        $val = (int) $row_1['int_rgt'] - $row_1['int_lft'] + 1;
        if ($row_1['fk_pages'] != $id) {
            $sql_2 = "select count(1) as total from " . DB_PREFIX . "pages where int_lft BETWEEN '" . $row_1['int_lft'] . "' AND '" . $row_1['int_rgt'] . "'";
            $row_2 = $this->configObj->glDbObj->get_sql_row($sql_2);
            $sql_3 = " UPDATE " . DB_PREFIX . "pages SET int_lft = int_lft * (-1), int_rgt = int_rgt * (-1) WHERE int_lft BETWEEN '" . $row_1['int_lft'] . "' AND '" . $row_1['int_rgt'] . "'";
            $this->configObj->glDbObj->query($sql_3);
            $sql_4 = "UPDATE " . DB_PREFIX . "pages SET int_lft = int_lft - " . $val . " WHERE int_lft >" . $row_1['int_rgt'];
            $this->configObj->glDbObj->query($sql_4);
            $sql_5 = "UPDATE " . DB_PREFIX . "pages SET int_rgt = int_rgt - " . $val . " WHERE int_rgt >" . $row_1['int_rgt'];
            $this->configObj->glDbObj->query($sql_5);
            $sql_6 = "SELECT int_glcode,fk_pages,int_lft,int_rgt FROM " . DB_PREFIX . "pages WHERE int_glcode = " . $this->root_id;
            $row_6 = $this->configObj->glDbObj->get_sql_row($sql_6);
            $new_lft = $row_6['int_rgt'];
            $new_rgt = $row_6['int_rgt'] + $val - 1;
            $offset = $new_lft - $row_1['int_lft'];
            $sql_7 = "UPDATE " . DB_PREFIX . "pages SET int_lft = int_lft + " . $val . " WHERE int_lft >" . $row_6['int_rgt'];
            $this->configObj->glDbObj->query($sql_7);
            $sql_8 = "UPDATE " . DB_PREFIX . "pages SET int_rgt = int_rgt + " . $val . " WHERE int_rgt >=" . $row_6['int_rgt'];
            $this->configObj->glDbObj->query($sql_8);
            $sql_9 = "UPDATE " . DB_PREFIX . "pages SET int_rgt = " . $offset . " - int_rgt , int_lft = " . $offset . " - int_lft WHERE int_lft < 0";
            $this->configObj->glDbObj->query($sql_9);
            $this->new_left = $new_lft;
            $this->new_rgt = $new_rgt;
        } else {
            $this->new_left = $row_1['int_lft'];
            $this->new_rgt = $row_1['int_rgt'];
        }
    }

    function getlastid() {
        $sql = "SELECT max(int_glcode) AS id FROM " . DB_PREFIX . "pages where chr_delete='N' and chr_publish='Y'";
        $rec = $this->configObj->glDbObj->get_sql_row($sql);
        $lid = $rec["id"];
        return $lid;
    }
    
    function update_pages() {
        $this->update_lft_rft();
        $tablename = DB_PREFIX . 'pages';
        $this->imagename = $_REQUEST['hidvar_image'];
        $maindir = '../upimages/banners/images/main/';
        $thumbdir = '../upimages/banners/images/thumb/';
        if ($_REQUEST['preview'] != 'yes') {
            $tablename = DB_PREFIX . 'pages';
            if ($this->varpostdata['paction'] == 'add') {
                $intgdisporder = $this->varpostdata['int_displayorder'];
                $this->configObj->glDbObj->resetfields();
                $this->configObj->glDbObj->setQueryType('select');
                $this->configObj->glDbObj->setTable($tablename);
                $this->configObj->glDbObj->addColumn('count(1) as total');
                $this->configObj->glDbObj->setWhere("int_displayorder=" . $intgdisporder . " and fk_pages='" . $this->varpostdata['fk_pages'] . "' and chr_delete = 'N' and chr_previewstatus='N' ");
                $rs = $this->configObj->glDbObj->get_sql_row($this->configObj->glDbObj->buildQuery());

                if ($rs['total'] > 0) {
                    $this->configObj->glDbObj->resetfields();
                    $this->configObj->glDbObj->setTable($tablename);
                    $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 >= ' . $this->varpostdata['int_displayorder'] . ' and fk_pages="' . $this->varpostdata['fk_pages'] . '" and chr_delete = "N" and chr_previewstatus="N"');
                    $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
                }
                
                if ($this->varpostdata['var_display_order']!= $this->varpostdata['old_footer_displayorder'] && $_REQUEST['displayordrchk'] == 'Y') {
                    $this->configObj->glDbObj->resetfields();
                    $this->configObj->glDbObj->setQueryType('select');
                    $this->configObj->glDbObj->setTable($tablename);
                    $this->configObj->glDbObj->addColumn('count(1) as total');
                    $this->configObj->glDbObj->setWhere("footer_display_order=" . $this->varpostdata['var_display_order'] . " and chr_delete = 'N' and fk_pages='" . $this->varpostdata['fk_pages'] . "'  and chr_previewstatus='N'");
                    $rs = $this->configObj->glDbObj->get_sql_row($this->configObj->glDbObj->buildQuery());
                    if ($rs['total'] > 0) {
                        if ($this->varpostdata['var_display_order'] > $this->varpostdata['old_footer_displayorder']) {
                            $this->configObj->glDbObj->resetfields();
                            $this->configObj->glDbObj->setTable($tablename);
                            $this->configObj->glDbObj->setQueryType('update');
                            $this->configObj->glDbObj->addColumn('footer_display_order');
                            $this->configObj->glDbObj->UnsetQuotes();
                            $this->configObj->glDbObj->addValue('footer_display_order - 1');
                            $this->configObj->glDbObj->SetQuotes();
                            $this->configObj->glDbObj->setWhere('footer_display_order > ' . $this->varpostdata['old_footer_displayorder'] . ' and footer_display_order <= ' . $this->varpostdata['var_display_order'] . ' and fk_pages="' . $this->varpostdata['fk_pages'] . '"  and chr_previewstatus="N"');
                            //echo $this->configObj->glDbObj->buildQuery();die;
                            $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
                        } else {
                            $this->configObj->glDbObj->resetfields();
                            $this->configObj->glDbObj->setTable($tablename);
                            $this->configObj->glDbObj->setQueryType('update');
                            $this->configObj->glDbObj->addColumn('footer_display_order');
                            $this->configObj->glDbObj->UnsetQuotes();
                            $this->configObj->glDbObj->addValue('footer_display_order + 1');
                            $this->configObj->glDbObj->SetQuotes();
                            $this->configObj->glDbObj->setWhere('footer_display_order >= ' . $this->varpostdata['var_display_order'] . ' and fk_pages="' . $this->varpostdata['fk_pages'] . '"  and  footer_display_order < ' . $this->varpostdata['old_footer_displayorder'] . ' and chr_previewstatus="N"');
                            // echo $this->configObj->glDbObj->buildQuery(); die;
                            $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
                            
                        }
                    }
                }
                
            } else {

                $this->configObj->glDbObj->resetfields();
                $this->configObj->glDbObj->setQueryType('select');
                $this->configObj->glDbObj->setTable($tablename);
                $this->configObj->glDbObj->addColumn('int_displayorder');
                $this->configObj->glDbObj->setWhere("int_glcode=" . $this->varpostdata['eid']);
                $old_displayorder = $this->configObj->glDbObj->get_sql_row($this->configObj->glDbObj->buildQuery());
                if ($this->varpostdata['int_displayorder'] != $old_displayorder['int_displayorder']) {
                    $this->configObj->glDbObj->resetfields();
                    $this->configObj->glDbObj->setQueryType('select');
                    $this->configObj->glDbObj->setTable($tablename);
                    $this->configObj->glDbObj->addColumn('count(1) as total');
                    $this->configObj->glDbObj->setWhere("int_displayorder=" . $this->varpostdata['int_displayorder'] . " and chr_delete = 'N' and fk_pages='" . $this->varpostdata['fk_pages'] . "'  and chr_previewstatus='N'");
                    $rs = $this->configObj->glDbObj->get_sql_row($this->configObj->glDbObj->buildQuery());
                    if ($rs['total'] > 0) {
                        if ($this->varpostdata['int_displayorder'] > $this->varpostdata['old_displayorder']) {
                            $this->configObj->glDbObj->resetfields();
                            $this->configObj->glDbObj->setTable($tablename);
                            $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 > ' . $this->varpostdata['old_displayorder'] . ' and int_displayorder <= ' . $this->varpostdata['int_displayorder'] . ' and fk_pages="' . $this->varpostdata['fk_pages'] . '"  and chr_previewstatus="N"');
                            $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
                        } else {
                            $this->configObj->glDbObj->resetfields();
                            $this->configObj->glDbObj->setTable($tablename);
                            $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 >= ' . $this->varpostdata['int_displayorder'] . ' and fk_pages="' . $this->varpostdata['fk_pages'] . '"  and  int_displayorder < ' . $this->varpostdata['old_displayorder'] . ' and chr_previewstatus="N"');
                            $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
                        }
                    }
                }
                
                if ($this->varpostdata['var_display_order'] != $this->varpostdata['old_footer_displayorder']) {
                    $this->configObj->glDbObj->resetfields();
                    $this->configObj->glDbObj->setQueryType('select');
                    $this->configObj->glDbObj->setTable($tablename);
                    $this->configObj->glDbObj->addColumn('count(1) as total');
                    $this->configObj->glDbObj->setWhere("footer_display_order=" . $this->varpostdata['var_display_order'] . " and chr_delete = 'N' and fk_pages='" . $this->varpostdata['fk_pages'] . "'  and chr_previewstatus='N'");
                    $rs = $this->configObj->glDbObj->get_sql_row($this->configObj->glDbObj->buildQuery());
                    if ($rs['total'] > 0) {
                        if ($this->varpostdata['var_display_order'] > $this->varpostdata['old_footer_displayorder']) {
//                            echo '<pre>';
//                            print_r($_REQUEST);
//                            echo '</pre>';
                            $hidden_displayorder = trim($_REQUEST['old_footer_displayorder']);
                            if($hidden_displayorder != "") {
                                $old_footer_id = $_REQUEST['old_footer_displayorder']; 
                            }  else {
                                $old_footer_id = '0';
                            }
                            $this->configObj->glDbObj->resetfields();
                            $this->configObj->glDbObj->setTable($tablename);
                            $this->configObj->glDbObj->setQueryType('update');
                            $this->configObj->glDbObj->addColumn('footer_display_order');
                            $this->configObj->glDbObj->UnsetQuotes();
                            $this->configObj->glDbObj->addValue('footer_display_order - 1');
                            $this->configObj->glDbObj->SetQuotes();
                            $this->configObj->glDbObj->setWhere('footer_display_order > ' .$old_footer_id . ' and footer_display_order <= ' . $this->varpostdata['var_display_order'] . ' and fk_pages="' . $this->varpostdata['fk_pages'] . '"  and chr_previewstatus="N"');
                            $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
                        } else {
                            $footer_id = '0';
                            if(!empty($this->varpostdata['var_display_order'])) {
                                $footer_id = $this->varpostdata['var_display_order']; 
                            }
                            $this->configObj->glDbObj->resetfields();
                            $this->configObj->glDbObj->setTable($tablename);
                            $this->configObj->glDbObj->setQueryType('update');
                            $this->configObj->glDbObj->addColumn('footer_display_order');
                            $this->configObj->glDbObj->UnsetQuotes();
                            $this->configObj->glDbObj->addValue('footer_display_order + 1');
                            $this->configObj->glDbObj->SetQuotes();
                            $this->configObj->glDbObj->setWhere('footer_display_order >= ' . $footer_id . ' and fk_pages="' . $this->varpostdata['fk_pages'] . '"  and  footer_display_order < ' . $this->varpostdata['old_footer_displayorder'] . ' and chr_previewstatus="N"');
                            // echo $this->configObj->glDbObj->buildQuery(); die;
                            $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
                            
                        }
                    }
                }
            }
        }
        if ($this->varpostdata['var_pagetype'] == 'Y' && $this->varpostdata['chr_fixmodule'] == 'Y') {
            $varlink = $this->varpostdata['var_prelink'];
        } else if ($this->varpostdata['var_pagetype'] == 'Y' && $this->varpostdata['chr_fixmodule'] == '') {
            $varlink = "index.php?module=custom";
        } else {
            $varlink = "";
        }
        if ($this->varpostdata['var_pagetype'] == 'Y' && $this->varpostdata['chr_fixmodule'] != 'Y') {
            $custommoduleglcode = '8';
            $fk_customtype = $this->varpostdata['fk_customtype'];
        } else if ($this->varpostdata['var_pagetype'] == 'Y' && $this->varpostdata['chr_fixmodule'] == 'Y') {
            $sqlPageType = "select var_pagetype from " . DB_PREFIX . "pages where int_glcode=" . $_REQUEST['eid'];
            $varPageTypeResult = $this->configObj->glDbObj->get_sql_row($sqlPageType);
            $varPageType = $varPageTypeResult['var_pagetype'];
            if ($varPageType != '0') {
                $custommoduleglcode = $varPageType;
            }
            $fk_customtype = $this->varpostdata['fk_customtype'];
        } else {
            $fk_customtype = "0";

            $sqlPageType = "select var_pagetype from " . DB_PREFIX . "pages where int_glcode=" . $_REQUEST['eid'];
            $varPageTypeResult = $this->configObj->glDbObj->get_sql_row($sqlPageType);
            $varPageType = $varPageTypeResult['var_pagetype'];
            if ($varPageType != '0') {
                $custommoduleglcode = $varPageType;
                //$custommoduleglcode="0";
            } else {
                $custommoduleglcode = "0";
            }
        }

        $this->thumb_width1 = 238;
        $this->thumb_height1 = 124;
        if ($_FILES["var_cmntimage"]["name"] != "") {
            $maindir = '../upimages/banners/images/main/';
            $thumbdir = '../upimages/banners/images/thumb/';

            $var_main_file = $this->configObj->glLibraryObj->generate_image('var_cmntimage', $maindir); // Main Upload and Resize
            $this->cmntimagename = $var_main_file;
            if (isset($var_main_file)) {
                if (empty($this->varpostdata['var_pagename'])) {
                    $temp = explode(".", $_FILES["var_cmntimage"]["name"]);
                    $this->varpostdata['var_pagename'] = $temp[0];
                }

                $file_photo = basename($var_main_file);
                $file = $maindir . $var_main_file;
                $tmp = $_FILES['var_cmntimage']['tmp_name'];
                $uploadedfile = $maindir . $file_photo;
                $var_thumb = $this->configObj->glLibraryObj->create_image($this->thumb_width1, $this->thumb_height1, 'thumb_comment_', $this->thumb_width1, $this->thumb_height1, $uploadedfile, '', $thumbdir);
            }
        } else {
            $this->cmntimagename = $_REQUEST['hidvar_cmntimage'];
        }
        //add column
        $this->configObj->glDbObj->resetfields();
        $this->configObj->glDbObj->setQueryType('update');
        $this->configObj->glDbObj->setTable(DB_PREFIX . 'pages');
        $this->configObj->glDbObj->addColumn('fk_pages');
        $this->configObj->glDbObj->addColumn('var_pagetype');
        $this->configObj->glDbObj->addColumn('fk_customtype');
        $this->configObj->glDbObj->addColumn('chr_custom');
        $this->configObj->glDbObj->addColumn('chr_fixmodule');
        $this->configObj->glDbObj->addColumn('var_pagename');
        $this->configObj->glDbObj->addColumn('var_alias');
        // $this->configObj->glDbObj->addColumn('var_quote_note');
        $this->configObj->glDbObj->addColumn('text_fulltext');
        $this->configObj->glDbObj->addColumn('var_general_info');
        $this->configObj->glDbObj->addColumn('var_cmntimage');
        $this->configObj->glDbObj->addColumn('var_metatitle');
        $this->configObj->glDbObj->addColumn('var_metakeyword');
        $this->configObj->glDbObj->addColumn('var_metadescription');
        $this->configObj->glDbObj->addColumn('int_displayorder');
        if($_REQUEST['isnetcluesadmin'] == 'Y') {
        $this->configObj->glDbObj->addColumn('chr_display_footer');
        $this->configObj->glDbObj->addColumn('footer_display_order');
        }
        $this->configObj->glDbObj->addColumn('int_lft');
        $this->configObj->glDbObj->addColumn('int_rgt');
        $this->configObj->glDbObj->addColumn('chr_publish');
        if ($this->varpostdata['paction'] != 'add') {
            $this->configObj->glDbObj->addColumn('chr_read');
            $this->configObj->glDbObj->addColumn('dt_modifydate');
        }
        $this->configObj->glDbObj->addColumn('var_viewalias');
        
        $foote_display = ($_REQUEST['displayordrchk'] == 'Y')? 'Y' : 'N';
        $footer_dispay_order = (!empty($_REQUEST['var_display_order']) && $foote_display == 'Y')? $_REQUEST['var_display_order'] : ' ';
        
        //add vlaue
        $this->configObj->glDbObj->addValue($this->varpostdata['fk_pages']);
        $this->configObj->glDbObj->addValue($custommoduleglcode);
        $this->configObj->glDbObj->addValue($fk_customtype);
        $this->configObj->glDbObj->addValue($this->varpostdata['var_pagetype']);
        if ($this->varpostdata['chr_fixmodule'] != '') {
            $this->configObj->glDbObj->addValue($this->varpostdata['chr_fixmodule']);
        } else {
            $this->configObj->glDbObj->addValue('N');
        }
        $this->configObj->glDbObj->addValue($this->varpostdata['var_pagename']);
        $this->configObj->glDbObj->addValue($this->configObj->glLibraryObj->convertspacetodesh($this->varpostdata['var_alias']));
        $this->configObj->glDbObj->addValue($this->varpostdata['text_fulltext']);
        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(trim($this->cmntimagename));
        $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']);
        if($_REQUEST['isnetcluesadmin'] == 'Y') {
        $this->configObj->glDbObj->addValue($foote_display);
        $this->configObj->glDbObj->addValue($footer_dispay_order);
        }
        $this->configObj->glDbObj->addValue($this->new_left);
        $this->configObj->glDbObj->addValue($this->new_rgt);
        $this->configObj->glDbObj->addValue($this->varpostdata['chr_publish']);
        if ($this->varpostdata['paction'] != 'add') {
            $this->configObj->glDbObj->addValue('Y');
            $this->configObj->glDbObj->addValue('NOW()');
        }
        $this->configObj->glDbObj->addValue($this->varpostdata['var_detail']);
        $this->updatedrecord = $this->varpostdata['eid'];
        $this->configObj->glDbObj->setWhere('int_glcode=' . $this->varpostdata['eid']);
//        echo $this->configObj->glDbObj->buildQuery(); die;
        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        $this->configObj->glLibraryObj->insertinlogmanager('1', DB_PREFIX . 'pages', 'var_pagename', $this->varpostdata['eid'], 'U');

        return true;
    }


    function insert_pages() {

        if ($this->varpostdata['h_save'] == 'T') {
            
            $sql_max_id = "select max(int_displayorder) AS id from " . DB_PREFIX . "pages where chr_delete='N' and chr_publish='Y' and int_glcode not in (1) ";
            $max = $this->configObj->glDbObj->get_sql_row($sql_max_id);
            $maxid = $max["id"];

            if ($this->varpostdata['int_displayorder'] > 1) {
                $sql_count = "select count(0) as total from " . DB_PREFIX . "pages where chr_delete='N' and chr_publish='Y' and int_displayorder=" . $this->varpostdata['int_displayorder'];
                $count = $this->configObj->glDbObj->get_sql_row($sql_count);
                $totalcount = $count["total"];
            }
            $this->configObj->glLibraryObj->updatedisplay_order_parent('pages', $this->varpostdata['int_displayorder'], 'fk_pages', $this->varpostdata['fk_pages']);
            
            if($_REQUEST['displayordrchk'] == 'Y') {
                
                if ($this->varpostdata['var_display_order'] > 1) {
                    $sql_count_f = "select count(0) as total from " . DB_PREFIX . "pages where chr_delete='N' and chr_publish='Y' and footer_display_order=" . $this->varpostdata['var_display_order'];
                    $count_res = $this->configObj->glDbObj->get_sql_row($sql_count_f);
                    $footer_totalcount = $count_res["total"]; 
                }
                $this->configObj->glLibraryObj->update_footer_display_order('pages', $this->varpostdata['var_display_order'], 'fk_pages', $this->varpostdata['fk_pages']);
            }
            
            $this->insert_lft_rft();
            if ($this->varpostdata['Image40_x'] == '') {

                if ($this->varpostdata['var_pagetype'] == 'Y' && $this->varpostdata['chr_fixmodule'] == 'Y') {
                    $varlink = $this->varpostdata['var_prelink'];
                } else if ($this->varpostdata['var_pagetype'] == 'Y' && $this->varpostdata['chr_fixmodule'] == '') {
                    $varlink = "index.php?module=custom";
                } else {
                    $varlink = "";
                }
            }
            if ($_FILES["var_cmntimage"]["name"] != "") {
                $this->thumb_width1 = 238;
                $this->thumb_height1 = 124;
                $maindir = '../upimages/banners/images/main/';
                $thumbdir = '../upimages/banners/images/thumb/';
                $var_main_file = $this->configObj->glLibraryObj->generate_image('var_cmntimage', $maindir); // Main Upload and Resize
                $this->cmntimagename = $var_main_file;
                if (isset($var_main_file)) {
                    if (empty($this->varpostdata['var_pagename'])) {
                        $temp = explode(".", $_FILES["var_cmntimage"]["name"]);
                        $this->varpostdata['var_pagename'] = $temp[0];
                    }
                    $file_photo = basename($var_main_file);
                    $file = $maindir . $var_main_file;
                    $tmp = $_FILES['var_cmntimage']['tmp_name'];
                    $uploadedfile = $maindir . $file_photo;
                    $var_thumb = $this->configObj->glLibraryObj->create_image($this->thumb_width1, $this->thumb_height1, 'thumb_comment_', $this->thumb_width1, $this->thumb_height1, $uploadedfile, '', $thumbdir);
                }
            } else {
                $this->cmntimagename = $_REQUEST['hidvar_cmntimage'];
            }
            $this->int_glcode = "";
            $this->configObj->glDbObj->resetfields();
            $this->configObj->glDbObj->setTable(DB_PREFIX . 'pages');
            $this->configObj->glDbObj->setQueryType('insert');
            $this->configObj->glDbObj->addColumn('fk_pages'); //Parent Page id
            $this->configObj->glDbObj->addColumn('var_pagename');
            $this->configObj->glDbObj->addColumn('var_alias');
            $this->configObj->glDbObj->addColumn('text_fulltext');
            $this->configObj->glDbObj->addColumn('var_general_info');
            $this->configObj->glDbObj->addColumn('var_cmntimage');
            $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('chr_display_footer');
            $this->configObj->glDbObj->addColumn('footer_display_order');
            $this->configObj->glDbObj->addColumn('int_lft');
            $this->configObj->glDbObj->addColumn('int_rgt');
            $this->configObj->glDbObj->addColumn('chr_publish');
            $this->configObj->glDbObj->addColumn('chr_access');
            $this->configObj->glDbObj->addColumn('chr_read');
            $this->configObj->glDbObj->addColumn('chr_star');
            $this->configObj->glDbObj->addColumn('chr_delete');
            $this->configObj->glDbObj->addColumn('dt_createdate');
            $this->configObj->glDbObj->addColumn('dt_modifydate');
            $this->configObj->glDbObj->addColumn('var_viewalias ');
            $this->configObj->glDbObj->addColumn('chr_previewstatus');

            //values add
            $this->configObj->glDbObj->addValue($this->varpostdata['fk_pages']); //Parent Page id           
            if ($this->varpostdata['var_pagetype'] == 'Y') {
                $sqlModule = "select fk_modules from " . DB_PREFIX . "custom WHERE int_glcode='" . trim($this->varpostdata['fk_customtype']) . "'";
                $modresult = $this->configObj->glDbObj->get_sql_row($sqlModule);
                $custommoduleglcode = $modresult['fk_modules'];
                $fk_customtype = $this->varpostdata['fk_customtype'];
            } else {
                $custommoduleglcode = "0";
                $fk_customtype = "0";
            }
            
            $foote_display = ($_REQUEST['displayordrchk'] == 'Y')? 'Y' : 'N';
            $footer_dispay_order = (!empty($_REQUEST['var_display_order']) && $foote_display == 'Y')? $_REQUEST['var_display_order'] : '';
            $this->configObj->glDbObj->addValue($this->varpostdata['var_pagename']);
            $this->configObj->glDbObj->addValue($this->configObj->glLibraryObj->convertspacetodesh($this->varpostdata['var_alias']));
            $this->configObj->glDbObj->addValue($this->varpostdata['text_fulltext']);
            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(trim($this->cmntimagename));
            $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($foote_display);
            $this->configObj->glDbObj->addValue($footer_dispay_order);
            
            $this->configObj->glDbObj->addValue($this->left);
            $this->configObj->glDbObj->addValue($this->right);
            $this->configObj->glDbObj->addValue($this->varpostdata['chr_publish']);
            $this->configObj->glDbObj->addValue('P');
            $this->configObj->glDbObj->addValue('N');
            $this->configObj->glDbObj->addValue('N');
            $this->configObj->glDbObj->addValue('N');
            $this->configObj->glDbObj->addValue('NOW()');
            $this->configObj->glDbObj->addValue('NOW()');
            $this->configObj->glDbObj->addValue($this->varpostdata['var_detail']);
            if ($this->varpostdata['Image40_x'] != '') {
                $this->configObj->glDbObj->addValue('Y');
            } else {
                $this->configObj->glDbObj->addValue('N');
            }
//            exit($this->configObj->glDbObj->buildQuery());
            $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());

            $this->lastinsertid = mysql_insert_id();


            if ($footer_totalcount == '0') {
                $sql_l = "SELECT int_glcode as lid FROM " . DB_PREFIX . "pages  where chr_delete='N' and chr_publish='Y' ORDER BY int_glcode DESC LIMIT 0,1";
                $count_l = $this->configObj->glDbObj->get_sql_row($sql_l);
                $totalcount_l = $count_l["lid"];
                $sql_update = "update " . DB_PREFIX . "pages set footer_display_order=$maxid+1 where int_glcode=$totalcount_l";
                $this->configObj->glDbObj->query($sql_update);
            }
            
            if ($totalcount == '0') {
                $sql_l = "SELECT int_glcode as lid FROM " . DB_PREFIX . "pages  where chr_delete='N' and chr_publish='Y'   ORDER BY int_glcode DESC LIMIT 0,1";
                $count_l = $this->configObj->glDbObj->get_sql_row($sql_l);
                $totalcount_l = $count_l["lid"];
                $sql_update = "update " . DB_PREFIX . "pages set int_displayorder=$maxid+1 where int_glcode=$totalcount_l";
                $this->configObj->glDbObj->query($sql_update);
            }
//            

            $this->configObj->glLibraryObj->insertinlogmanager('1', DB_PREFIX . 'pages', 'var_pagename', $this->lastinsertid, 'I');
            return true;
        }
    }

    //get page name
    function get_pagename($page_id) {
        if ($page_id != '0') {
            $sqlpagename = "Select int_glcode,fk_pages,var_pagename from " . DB_PREFIX . "pages where int_glcode='" . $page_id . "'";
            $pagenameresult = $this->configObj->glDbObj->get_sql_row($sqlpagename);
            $pagename = $pagenameresult['var_pagename'];
            if ($pagenameresult['fk_pages'] != '0') {
                $sqlpagename = "Select var_pagename from " . DB_PREFIX . "pages where int_glcode='" . $pagenameresult['fk_pages'] . "'";
                $pagenameresult = $this->configObj->glDbObj->get_sql_row($sqlpagename);
                $pagename .= " >> " . $pagenameresult['var_pagename'];
            }
            return $pagename;
        }
    }

    
    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->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;
        $this->urlwithpoutsearch = $this->pagename . '&' . 'pagesize=' . $this->pagesize . '&orderby=' . $this->orderby . '&ordertype=' . $this->ordertype . '&filterby=' . $this->filterby;
        $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;
        $this->urlwithoutpaging = $this->pagename . '&orderby=' . $this->orderby . '&ordertype=' . $this->ordertype . '&searchby=' . $this->searchby . '&searchtxt=' . $this->searchtxtjs . '&filterby=' . $this->filterby;
        $this->urlwithoutfilter = $this->pagename . '&' . 'pagesize=' . $this->pagesize . '&orderby=' . $this->orderby . '&ordertype=' . $this->ordertype . '&searchby=' . $this->searchby . '&searchtxt=' . $this->searchtxtjs . '&filterby=' . $this->filterby;
        $this->configObj->AutoSearchUrl = $this->urlwithpara . "&type=autosearch&searchbyVal=" . $this->searchbyVal;
    }

    function generateParam($position = 'top') {
        $filterPos = ($position == 'top') ? 'FT' : 'FB';
        if ($this->configObj->glSessionObj->value('admin_id') == '1') {
            $filterstar = array(
                'filterarray' => array('chr_read-Y' => 'Read Only',
                    'chr_read-N' => 'Unread Only',
                    'chr_star-Y' => 'Star Only',
                    'chr_star-N' => 'Unstar Only'
                ),
                'filterurl' => $this->urlwithoutfilter,
                'filterposition' => $filterPos,
                'filterby' => $this->filterby
            );
        } else {

            $filterstar = array();
        }
        return array('pageurl' => $this->pagename,
            'heading' => 'Manage Pages',
            'listImage' => 'listing-icon.png',
            'tablename' => DB_PREFIX . 'pages',
            'position' => $position,
            'actionImage' => 'add-new-button-blue.gif',
            'actionImageHover' => 'add-new-button-blue-hover.gif',
            'actionUrl' => 'index.php?module=pages&action=add',
            'search' => array('searchArray' => array("var_pagename" => "Page Name"),
                'searchBy' => $this->searchby,
                'searchText' => $this->searchtxt,
                //'searchUrl'    => $this->urlwithpoutsearch
                '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,
            )
        );
    }

    function update_display_order($int_glcode, $fk_pages, $neworder, $oldorder) {
        $tablename = DB_PREFIX . "pages";
// Updation Of the Display Order
//        echo $neworder;
//        echo '<br/>';
//        echo $oldorder;
//        echo '<br/>';
//        echo $neworder;
//        die;
        if ($neworder != $oldorder && $neworder != 0) {
            $this->configObj->glDbObj->resetfields();
            $this->configObj->glDbObj->setQueryType('select');
            $this->configObj->glDbObj->setTable($tablename);
            $this->configObj->glDbObj->addColumn('count(1) as total');
            $this->configObj->glDbObj->setWhere("fk_pages=" . $fk_pages . " and chr_delete = 'N'");
            // echo $this->configObj->glDbObj->buildQuery();
            $rs = $this->configObj->glDbObj->get_sql_row($this->configObj->glDbObj->buildQuery());

//                $this->configObj->glDbObj->resetfields();
//                $this->configObj->glDbObj->setTable($tablename);
//                $this->configObj->glDbObj->setQueryType('select');
//                $this->configObj->glDbObj->addColumn('$fk_pages');
//                $this->configObj->glDbObj->setWhere('int_glcode='.$ids[$i]);
//                echo "__".$this->configObj->glDbObj->buildQuery();
//                $temprow = $this->configObj->glDbObj->get_sql_row($this->configObj->glDbObj->buildQuery());

            $this->configObj->glDbObj->resetfields();
            $this->configObj->glDbObj->setTable($tablename);
            $this->configObj->glDbObj->setQueryType('update');
            $this->configObj->glDbObj->addColumn('int_displayorder');
            $this->configObj->glDbObj->UnsetQuotes();
            if ($neworder > $oldorder) {
                $this->configObj->glDbObj->addValue('int_displayorder - 1');
                $this->configObj->glDbObj->SetQuotes();
                $this->configObj->glDbObj->setWhere('int_displayorder > ' . $oldorder . ' and  int_displayorder <= ' . $neworder . ' and fk_pages = ' . $fk_pages);
            } else {
                $this->configObj->glDbObj->addValue('int_displayorder + 1');
                $this->configObj->glDbObj->SetQuotes();
                $this->configObj->glDbObj->setWhere('int_displayorder <= ' . $oldorder . ' and  int_displayorder >= ' . $neworder . ' and fk_pages = ' . $fk_pages);
            }

            $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
            //    echo $this->configObj->glDbObj->buildQuery();
            $this->configObj->glDbObj->resetfields();
            $this->configObj->glDbObj->setTable($tablename);
            $this->configObj->glDbObj->setQueryType('update');
            $this->configObj->glDbObj->addColumn('int_displayorder');
            $this->configObj->glDbObj->addValue($neworder);
            $this->configObj->glDbObj->setWhere('int_glcode=' . $int_glcode . '');
//            echo $this->configObj->glDbObj->buildQuery(); die;  
            $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        }

        // End of updation of Display Order
    }
    
    function update_footer_display_order($int_glcode, $fk_pages, $neworder, $oldorder) {
        $tablename = DB_PREFIX . "pages";
        // Updation Of the Display Order
        if ($neworder != $oldorder && $neworder != 0) {

            $this->configObj->glDbObj->resetfields();
            $this->configObj->glDbObj->setQueryType('select');
            $this->configObj->glDbObj->setTable($tablename);
            $this->configObj->glDbObj->addColumn('count(1) as total');
            $this->configObj->glDbObj->setWhere("fk_pages=" . $fk_pages . " and chr_delete = 'N'");
            // echo $this->configObj->glDbObj->buildQuery();
            $rs = $this->configObj->glDbObj->get_sql_row($this->configObj->glDbObj->buildQuery());

//                $this->configObj->glDbObj->resetfields();
//                $this->configObj->glDbObj->setTable($tablename);
//                $this->configObj->glDbObj->setQueryType('select');
//                $this->configObj->glDbObj->addColumn('$fk_pages');
//                $this->configObj->glDbObj->setWhere('int_glcode='.$ids[$i]);
//                echo "__".$this->configObj->glDbObj->buildQuery();
//                $temprow = $this->configObj->glDbObj->get_sql_row($this->configObj->glDbObj->buildQuery());

            $this->configObj->glDbObj->resetfields();
            $this->configObj->glDbObj->setTable($tablename);
            $this->configObj->glDbObj->setQueryType('update');
            $this->configObj->glDbObj->addColumn('footer_display_order');
            $this->configObj->glDbObj->UnsetQuotes();
            if ($neworder > $oldorder) {
                $this->configObj->glDbObj->addValue('footer_display_order - 1');
                $this->configObj->glDbObj->SetQuotes();
                $this->configObj->glDbObj->setWhere('footer_display_order > ' . $oldorder . ' and  footer_display_order <= ' . $neworder . ' and fk_pages = ' . $fk_pages);
            } else {
                $this->configObj->glDbObj->addValue('footer_display_order + 1');
                $this->configObj->glDbObj->SetQuotes();
                $this->configObj->glDbObj->setWhere('footer_display_order <= ' . $oldorder . ' and  footer_display_order >= ' . $neworder . ' and fk_pages = ' . $fk_pages);
            }

            $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
            //    echo $this->configObj->glDbObj->buildQuery();
            $this->configObj->glDbObj->resetfields();
            $this->configObj->glDbObj->setTable($tablename);
            $this->configObj->glDbObj->setQueryType('update');
            $this->configObj->glDbObj->addColumn('footer_display_order');
            $this->configObj->glDbObj->addValue($neworder);
            $this->configObj->glDbObj->setWhere('int_glcode=' . $int_glcode . '');
            $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        }

        // End of updation of Display Order
    }

    function update_display_order_parentwise($ids, $values, $oldvalues, $parenids) {
        $tablename = DB_PREFIX . "pages";
        
        for ($i = 0; $i < count($ids); $i++) {

            if ($values[$i] != $oldvalues[$i]) {
                $this->configObj->glDbObj->resetfields();
                $this->configObj->glDbObj->setQueryType('select');
                $this->configObj->glDbObj->setTable($tablename);
                $this->configObj->glDbObj->addColumn('count(1) as total');
                $this->configObj->glDbObj->setWhere("int_displayorder=" . $values[$i] . " and chr_delete = 'N' and fk_pages='" . $parenids[$i] . "'  and chr_previewstatus='N'");
                $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($tablename);
                        $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] . ' and fk_pages="' . $parenids[$i] . '"  and chr_previewstatus="N"');
                        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
                    } else {
                        $this->configObj->glDbObj->resetfields();
                        $this->configObj->glDbObj->setTable($tablename);
                        $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] . ' and fk_pages="' . $parenids[$i] . '"  and chr_previewstatus="N"');
                        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
                    }
                }
                $this->configObj->glDbObj->resetfields();
                $this->configObj->glDbObj->setTable($tablename);
                $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] . ' and fk_pages="' . $parenids[$i] . '"  and chr_previewstatus="N"');
                $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
            }
        }
    }

    function loadpage() {
        if ($_REQUEST['task'] == 'orderupdate') {
            $updateids = $_REQUEST['uids'];
            $updatevalues = $_REQUEST['uvals'];
            $updateoldvalues = $_REQUEST['uoldvals'];
            $parentids = $_REQUEST['cmnglcode'];
            $upidsarray = explode(',', $updateids);
            $upvalsarray = explode(',', $updatevalues);
            $upoldvalsarray = explode(',', $updateoldvalues);

            $parentidsarray = explode(',', $parentids);

            $this->update_display_order_parentwise($upidsarray, $upvalsarray, $upoldvalsarray, $parentidsarray);
        }
        $this->loadCount('CountRows');

        $this->configObj->glTplObj->set('records', $this->selectall());
        $this->configObj->glTplObj->set('setsortimg' . $this->orderby, $this->sortvar);
        $parmas = $this->generateParam();
        $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->generateParam('bottom')));
        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 and saved.");
                $this->configObj->glTplObj->set('messagebox', $messagebox);
            }
        }

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


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

    function delete_page($fk_modules) {//not yet used
        $tablename = DB_PREFIX . 'pages';
        $deleteids = $_REQUEST['dids'];

        $deletearray = explode(',', $deleteids);
//print_r($deletearray);exit;
        $totaldeletedrecords = count($deletearray);
        $is_assigned = 0;
        $delcount = 0;
        for ($i = 0; $i < $totaldeletedrecords; $i++) {
            $fkstring = '';
            $fkdstring = $this->getfkarray($deletearray[$i], $fkstring);
            $fkarray = explode(',', $fkdstring);

            if ($fkarray[0] != '') {
                foreach ($fkarray as $value) {
                    $sql_child = "Update " . DB_PREFIX . "pages set chr_delete='Y',dt_modifydate = NOW(), var_ipaddress='" . $_SERVER['REMOTE_ADDR'] . "',var_adminuser='" . ADMIN_NAME . "' where 	int_glcode='$value'";
                    $this->configObj->glDbObj->query($sql_child);
                    $this->configObj->glLibraryObj->insertinlogmanager($fk_modules, DB_PREFIX . 'pages', 'var_pagename', $value, 'D');
                }
            }




            $sql = "Update " . DB_PREFIX . "pages set chr_delete='Y',dt_modifydate = NOW(),var_ipaddress='" . $_SERVER['REMOTE_ADDR'] . "',var_adminuser='" . ADMIN_NAME . "' where int_glcode='$deletearray[$i]'";
            $this->configObj->glDbObj->query($sql);
            $delcount++;


//            $sql_l = "SELECT max(int_displayorder) as lid FROM " . DB_PREFIX . "pages  where chr_delete='N' and chr_publish='Y'  and int_glcode not in(1) ORDER BY int_glcode DESC LIMIT 0,1";
//            $count_l = $this->configObj->glDbObj->get_sql_row($sql_l);
//            $totalcount_l = $count_l["lid"];
            
            
//            $sql_update = "update " . DB_PREFIX . "pages set int_displayorder=$totalcount_l + 1 where int_glcode = $deletearray[$i]";
//            $this->configObj->glDbObj->query($sql_update);
//
//            $sql_update = "update " . DB_PREFIX . "pages set int_displayorder=int_displayorder - 1 where int_glcode < $deletearray[$i]";
//            $this->configObj->glDbObj->query($sql_update);


            
            
            $sql_l = "SELECT int_displayorder FROM " . DB_PREFIX . "pages  where int_glcode = $deletearray[$i] and int_glcode not in(1) ORDER BY int_glcode DESC LIMIT 0,1";
            $result = $this->configObj->glDbObj->get_sql_row($sql_l);
            $total_disp = $result["int_displayorder"];
//            echo $total_disp;
           
           
//           $sql_update = "update " . DB_PREFIX . "pages set int_displayorder=$total_disp + 1 where int_glcode = $deletearray[$i]";
//            $this->configObj->glDbObj->query($sql_update);

          $sql_update = "update " . DB_PREFIX . "pages set int_displayorder=int_displayorder - 1 where int_displayorder > $total_disp and int_glcode not in(1)";
            $this->configObj->glDbObj->query($sql_update);   


//             $sql_update2 = "update " . DB_PREFIX . "pages set int_displayorder=int_displayorder + 1 where int_glcode = $deletearray[$i] and int_glcode not in(1) and chr_delete='Y'";
//            $this->configObj->glDbObj->query($sql_update2);
          
            

            $this->configObj->glLibraryObj->insertinlogmanager('1', DB_PREFIX . 'pages', 'var_pagename', $deletearray[$i], 'D');
        }

        $this->loadpage();
    }

    function getfkarray($pageid, $fkstring) {
        $rstring = '';
        $sql = "select int_glcode,fk_pages from " . DB_PREFIX . "pages where fk_pages in(" . $pageid . ")";
        $res = $this->configObj->glDbObj->query($sql);
        $count = $this->configObj->glDbObj->num_rows($res);
        if ($count > 0) {
            while ($row = $this->configObj->glDbObj->fetch_array($res)) {
                if ($fkstring != '')
                    $fkstring.=',';
                if ($rstring != '')
                    $rstring.=',';
                $fkstring.=$row['int_glcode'];
                $rstring.=$row['int_glcode'];
            }
            return $this->getfkarray($rstring, $fkstring);
        }
        else {
            return $fkstring;
        }
    }

    function loadCount($function) {
        $this->intitialize();
        //$this->numofrows = (isset($_REQUEST['numofrows']))?$_REQUEST['numofrows']:$this->{$function}();
        $this->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();
    }

    function get_var_imagepath($eid, $fieldname, $tablename) {
        $sql = "select " . $fieldname . " from " . $tablename . " where int_glcode=$eid AND chr_delete='N'";
        $rs = $this->configObj->glDbObj->get_sql_row($sql);
        $var_imagepath = $rs[$fieldname];
        return $var_imagepath;
    }

    function get_cropstatus($eid, $fieldname, $tablename) {
        $sql = "select " . $fieldname . " from " . $tablename . " where int_glcode=$eid AND chr_delete='N'";
        $rs = $this->configObj->glDbObj->get_sql_row($sql);
        $cropstatus = $rs[$fieldname];
        return $cropstatus;
    }

    function getpagesubchildid($id = '2') {
        $sqlSelectMenus = "SELECT int_glcode AS id, fk_pages AS parent FROM " . DB_PREFIX . "pages  WHERE chr_delete = 'N' ORDER BY  fk_pages ASC";

        $result = $this->configObj->glDbObj->query($sqlSelectMenus);

        // Create a multidimensional array to conatin a list of items and parents
        $menuData = array('items' => array(), 'parents' => array());
        // Builds the array lists with data from the menu table
        $l = 0;
        while ($menuItem = $this->configObj->glDbObj->fetch_assoc($result)) {
            // Creates entry into items array with current menu item id ie. $menuData['items'][1]
            $menuData['items'][$menuItem['id']] = $menuItem;
            // Creates entry into parents array. Parents array contains a list of all items with children
            $menuData['parents'][$menuItem['parent']][] = $menuItem['id'];
        }
        $this->menuData = $menuData;
        $html .= $this->bulidallpagesubchildid($id, $menuData);

        return $html . $id;
    }

    function bulidallpagesubchildid($parent, $menuData) {
        if (isset($menuData['parents'][$parent])) {
            foreach ($menuData['parents'][$parent] as $itemId) {
                if (!isset($menuData['parents'][$itemId])) {
                    $html .= $menuData['items'][$itemId]['id'] . ",";
                }
                if (isset($menuData['parents'][$itemId])) {
                    $html .= $menuData['items'][$itemId]['id'] . ",";
                    $html .= $this->bulidallpagesubchildid($itemId, $menuData, $level + 1);
                }
            }
        }
        return $html;
    }

    function insertpagesquick($ParentId, $CatName) {


        $this->insert_lft_rft();

        //$this->configObj->glLibraryObj->updatedisplay_order('pages',$this->varpostdata['int_displayorder']);
        $this->configObj->glDbObj->resetfields();
        $this->configObj->glDbObj->setQueryType('select');
        $this->configObj->glDbObj->setTable(DB_PREFIX . 'pages');
        $this->configObj->glDbObj->addColumn('count(1) as total');
        $this->configObj->glDbObj->setWhere("int_displayorder=1 and chr_delete = 'N' and fk_pages='" . $this->varpostdata['fk_pages'] . "' ");
        //echo $this->configObj->glDbObj->buildQuery();exit;
        $rs = $this->configObj->glDbObj->get_sql_row($this->configObj->glDbObj->buildQuery());
        if ($rs['total'] > 0) {
            $this->configObj->glDbObj->resetfields();
            $this->configObj->glDbObj->setTable(DB_PREFIX . 'pages');
            $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 >=1 and chr_delete = "N" and fk_pages="' . $this->varpostdata['fk_pages'] . '"');
            // $this->buildQuery();
            $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        }


        $this->int_glcode = "";
        $this->configObj->glDbObj->resetfields();
        $this->configObj->glDbObj->setTable(DB_PREFIX . 'pages');
        $this->configObj->glDbObj->setQueryType('insert');
        //add column
        $this->configObj->glDbObj->addColumn('fk_pages');
        $this->configObj->glDbObj->addColumn('var_pagename');


        $this->configObj->glDbObj->addValue($ParentId);
        $this->configObj->glDbObj->addValue($CatName);


        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        $this->lastinsertid = mysql_insert_id();

        echo $this->Bindpageshierarchy('fk_pages_quick', $this->lastinsertid, 'add-new-user-textarea2', '4');
        exit;
    }

    function delete_image($sid, $file) {
        $sql = "Update " . DB_PREFIX . "pages set var_bannerimage='', dt_modifydate=NOW() where int_glcode='" . $sid . "'";
        $this->configObj->glDbObj->query($sql);
        return true;
    }

    function get_fk_modules($module) {
        $sql = "SELECT int_glcode FROM " . DB_PREFIX . "modules WHERE var_modulename='$module' and chr_publish='Y' and chr_delete='N'";
        $rs = $this->configObj->glDbObj->get_sql_row($sql);
        $fk_modules = 0;
        $fk_modules = $rs['int_glcode'];
        return $fk_modules;
    }

    function getparentarray() {
        $sql = "SELECT fk_pages from " . DB_PREFIX . "pages where chr_delete='N' and chr_publish='Y' group by fk_pages";
        $row = $this->configObj->glDbObj->query($sql);
        $parentArray = array();
        while ($parent = $this->configObj->glDbObj->fetch_array($row)) {
            $parentArray[] = $parent;
        }
        //print_r($parentArray);
        return $parentArray;
    }
    
    function getpagenameexist($intglcode) {
        $page = "select * from " . DB_PREFIX . "pages where (var_pagetype != '0' OR var_viewalias !='') and int_glcode = " . $intglcode . "";
        $row = $this->configObj->glDbObj->get_sql_row($page);
        return $row;
    }

    function getpagenameexist1($intglcode) {
        $page = "select count(1) as total from " . DB_PREFIX . "pages where chr_delete='N' and fk_pages = " . $intglcode . "";
        $row = $this->configObj->glDbObj->get_sql_row($page);
        return $row['total'];
    }

    function treerecurse_key($id, $indent, $list, $children, $maxlevel = PAGE_HIERARCHY_LEVEL, $level = 0, $type = 1) {
        if ($children[$id] && $level <= $maxlevel) {
            foreach ($children[$id] as $c) {
                echo "<pre/>";
                print_r($c);
                $id = $c['id'];

                if ($type) {
                    $pre = '<sup>|_</sup>&nbsp;';
                    $spacer = '.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                } else {
                    $pre = '|_ ';
                    $spacer = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                }
                if ($c['fk_categories'] == 0) {
                    $txt = $c['name'];
                } else {
                    $txt = $pre . $c['name'];
                }
                $pt = $c['fk_category'];
                $list[$id] = $c;
                $list[$id]['treename'] = "$indent$txt";
                $list[$id]['children'] = count($children[$id]);
                $list = $this->treerecurse_key($id, $indent . $spacer, $list, $children, $maxlevel, $level + 1, $type);
            }
        }
        return $list;
    }

}
?>

