<?php

class trashmanager {

    var $pagename = 'index.php?module=trashmanager';
    var $int_glcode;
    var $chr_read;
    var $chr_star;
    var $chr_publish;
    var $int_displayorder;
    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 = 1;
    var $pagesize = DEFAULT_PAGESIZE;
    var $pagenumber = '1';
    var $lastinsertid;
    var $urlwithpara = '';
    var $urlwithpoutsearch = '';
    var $urlwithoutsort = '';
    var $urlwithoutpaging = '';
    var $configObj;
    var $tablename = '';
    var $displayfield1 = '';
    var $displayfield2 = '';
    var $displayfield3 = '';
    var $displayfieldtitle1 = '';
    var $displayfieldtitle2 = '';
    var $displayfieldtitle3 = '';
    var $view = '';
    var $tid = '';
    var $filterby = '0';
    var $urlwithoutfilter = '';
    var $chr_validthumb = '';
    var $display_limit_array = array(5, 10, 15, 20, 25, 30);
    var $varpostdata = array();

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

    function intitialize($view = '') {

        $this->searchby = (isset($_REQUEST['searchby'])) ? $_REQUEST['searchby'] : $this->searchby;
        $this->modval = ($_REQUEST['modval'] != '' || $_REQUEST['modval'] != '0') ? $_REQUEST['modval'] : '';
        $_REQUEST['searchtxt'] = ($_REQUEST['type'] == 'autosearch' || !empty($_REQUEST['auto'])) ? $_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->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;\">";
            }
        }
        $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 Generateurl() {

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

    function CountRows() {

        if ($this->displayfield2 != '') {

            if (trim($this->searchtxt) != '') {


                $whereclause .= ($this->searchby == '0') ? " and ((" . $this->displayfield1 . " like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%') or (" . $this->displayfield2 . " like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%') or (concat(" . $this->displayfield1 . ",' '," . $this->displayfield2 . ") like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'))  " : " and $this->searchby like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'";
            }
        } else {
            if (trim($this->searchtxt) != '') {
                $whereclause .= ($this->searchby == '0') ? " and ($this->displayfield1 like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%') " : " and $this->searchby like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'";
            }
        }
        if ($this->modval != '0' && $this->modval != '') {

            $whereclause1 .=" and FIND_IN_SET('" . $this->modval . "',fk_modules)";
        }
        $viewrequested = substr($_REQUEST['view'], -7);
        $newview = substr($_REQUEST['view'], 0, -7);

        if ($this->configObj->glSessionObj->value('chr_user') == 'A') {
            if ($_REQUEST['view'] == $newview . '-custom') {
                $whereclause.="and cd.var_adminuser!='Netclues' ";
            } else {
                $whereclause.="and var_adminuser!='Netclues' ";
            }

            $whereclause1.="and mp.var_adminuser!='Netclues' ";
        }
        $admin = '"' . ADMIN_NAME . '"';

        if ($this->configObj->glSessionObj->value('admin_id') != '1' && $this->configObj->glSessionObj->value('chr_user') != 'A') {
            if ($_REQUEST['view'] == $newview . '-custom') {
                $whereclause.="and cd.var_adminuser=" . $admin . " ";
            } else {
                $whereclause.="and var_adminuser=" . $admin . " ";
            }
            $whereclause1.="and mp.var_adminuser=" . $admin . " ";
        }

        if ($this->filterby != '0' && $this->filterby != '') {
            $filterarray = explode('-', $this->filterby);

            $whereclause .=" and $filterarray[0] = '$filterarray[1]'";
        }

        if ($_REQUEST['view'] == $newview . '-custom') {
            $sqlCountPages = ("select count(1) as total from " . DB_PREFIX . "custom_data as cd left join " . DB_PREFIX . "pages p on cd.fk_pages=p.int_glcode where cd.chr_delete='Y' and p.int_glcode=" . $newview . " $whereclause ");
        } else if ($_REQUEST['view'] == 'settings') {
            $sqlCountPages = "select count(1) as total from " . $this->tablename . " as e left join " . DB_PREFIX . "emailtype as et on e.fk_emailtype = et.int_glcode where chr_delete = 'Y' $whereclause ";
        } else if ($_REQUEST['view'] == 'users') {
            $sqlCountPages = "select count(1) as total from " . $this->tablename . " where chr_delete = 'Y' and chr_usertype IN('U','V') $whereclause ";
        } else if ($_REQUEST['view'] == 'staff') {
            $sqlCountPages = "select count(1) as total from " . $this->tablename . " where chr_delete = 'Y' and chr_usertype ='S' $whereclause ";
        } else {
            $sqlCountPages = "select count(1) as total from " . $this->tablename . " where chr_delete = 'Y' $whereclause ";
        }

        // echo   $sqlCountPages;
        $rs = $this->configObj->glDbObj->get_sql_row($sqlCountPages);

        return $rs['total'];
    }

    function dateconversion($date) {
        if ($date != '') {
            $datearray = explode('-', $date);
            $year = $datearray[0];
            $month = $datearray[1];
            $day = $datearray[2];
            return $day . '/' . $month . '/' . $year;
        } else {
            return '';
        }
    }

    function message($msg = '') {
        (string) $display_output = null;
        if ($msg != "") {
            $display_output .="<div class=\"dverrorcustom\"><div class=\"confirmation-div\"><strong>$msg</strong></div></div>";
        }
        return $display_output;
    }

    function restoreCMS($id, $rid = '', $lid = '') {
        $idArry = explode(',', $id);
        $this->remainId = '';
        $this->msgflg = 0;

        foreach ($idArry as $value) {

            $tablename = DB_PREFIX . "pages";
            $rsql2 = "SELECT fk_pages FROM " . DB_PREFIX . "pages
                WHERE chr_delete = 'Y' and int_glcode ='$value'";
            $parnt = $this->configObj->glDbObj->get_sql_row($rsql2);

            $sql = "SELECT count(0) as total FROM " . DB_PREFIX . "pages 
                WHERE chr_delete = 'Y' and int_glcode ='" . $parnt['fk_pages'] . "'";
            $parnt2 = $this->configObj->glDbObj->get_sql_row($sql);

            if ($parnt2['total'] == '0') {

                $this->msgflg = 0;
            } else {
                // Error msg

                $rsql = "SELECT var_pagename FROM " . DB_PREFIX . "pages
                WHERE chr_delete = 'Y' and int_glcode ='" . $parnt['fk_pages'] . "'";

                $rn = $this->configObj->glDbObj->get_sql_row($rsql);
                $this->remainId .= $rn['var_pagename'] . ',';
                $this->msgflg = 1;
            }

             $totalcount_l = '';
            $sql_l = "SELECT max(int_displayorder) as lid FROM " . DB_PREFIX . "pages where chr_delete='N' ";
            $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 = $value";
            $this->configObj->glDbObj->query($sql_update);
      
            
            
            }

        $this->remainId = substr($this->remainId, 0, -1);


        return $this->msgflg;
    }

    function restore() {
        if ($_REQUEST['view'] == 'pages') {
            $tablename = $_REQUEST['tablename'];
            $restoreids = $_REQUEST['rids'];
            $restorearray = explode(',', $restoreids);
            $totalrestorerecords = count($restorearray);

            $message = $this->restoreCMS($restoreids, $restoreids, $restorelistids);

            if ($message == 1) {
                $message = "Sorry! Please restore the menu(s) '" . $this->remainId . "'  first.";
            } else {

                $message = 'The records restored successfully';
            }//end of else

            $this->configObj->glTplObj->set('messagebox', '<div class="dverrorcustom">
                    <div class="confirmation-div"><strong>' . $message . '</strong></div></div>');
        }
        $tablename = $_REQUEST['tablename'];
        $restoreids = $_REQUEST['rids'];
        $restorearray = explode(',', $restoreids);
        $totalrestorerecords = count($restorearray);

        for ($i = 0; $i < $totalrestorerecords; $i++) {
            $sql = "Update " . $tablename . " set chr_delete='N' where int_glcode='$restorearray[$i]'";
            $this->configObj->glDbObj->query($sql);
        }

        $this->load_trashmanager();
    }

    function delete() {

        if ($_REQUEST['view'] == 'business') {
            $tablename = $_REQUEST['tablename'];
            $deleteids = $_REQUEST['dids'];
            $deletearray = explode(',', $deleteids);
            $totaldeleterecords = count($deletearray);

            for ($i = 0; $i < $totaldeleterecords; $i++) {
                $sql = "delete from " . $tablename . " where int_glcode='$deletearray[$i]'";
                $this->configObj->glDbObj->query($sql);


                //related category
                $sql = "delete from " . DB_PREFIX . "module_categories where fk_moduleglcode='$deletearray[$i]' and fk_modules=12";

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

                //related area
                $sql = "delete from " . DB_PREFIX . "module_area where fk_moduleglcode='$deletearray[$i]' and fk_modules=12";
                //s echo $sql;
                $this->configObj->glDbObj->query($sql);

                //related review
                $sql = "delete from " . DB_PREFIX . "module_review where fk_moduleglcode='$deletearray[$i]' and fk_modules=12";
                $this->configObj->glDbObj->query($sql);

                //related promotion for business
                $sql = "delete from " . DB_PREFIX . "module_promotions where fk_moduleglcode='$deletearray[$i]' and fk_modules=12";
                //s echo $sql;
                $this->configObj->glDbObj->query($sql);

                //related tag
                $sql = "delete from " . DB_PREFIX . "category_module_tag where fk_moduleglcode='$deletearray[$i]' and fk_modules=12";
                $this->configObj->glDbObj->query($sql);

                //for businesss
                $sql = "delete from " . DB_PREFIX . "business_related_module where fk_business='$deletearray[$i]' and fk_modules=12";
                $this->configObj->glDbObj->query($sql);

                //for article
                $sql = "delete from " . DB_PREFIX . "business_related_module  where fk_business='$deletearray[$i]' and fk_modules=11";
                $this->configObj->glDbObj->query($sql);

                //for Tour/Activity
                $sql = "delete from " . DB_PREFIX . "business_related_module  where fk_business='$deletearray[$i]' and fk_modules=15";
                $this->configObj->glDbObj->query($sql);

                //hightlight
                $sql = "delete from " . DB_PREFIX . "module_highlights  where fk_moduleglcode='$deletearray[$i]' and fk_modules=12";
                $this->configObj->glDbObj->query($sql);

                //smartrec
                $sql = "delete from " . DB_PREFIX . "module_smartrec  where fk_moduleglcode='$deletearray[$i]' and fk_modules=12";
                $this->configObj->glDbObj->query($sql);
            }
        } else if ($_REQUEST['view'] == 'promotion') {
            $tablename = $_REQUEST['tablename'];
            $deleteids = $_REQUEST['dids'];
            $deletearray = explode(',', $deleteids);
            $totaldeleterecords = count($deletearray);

            for ($i = 0; $i < $totaldeleterecords; $i++) {
                $sql = "delete from " . $tablename . " where int_glcode='$deletearray[$i]'";
                $this->configObj->glDbObj->query($sql);

                //related category
                $sql = "delete from " . DB_PREFIX . "module_categories where fk_moduleglcode='$deletearray[$i]' and fk_modules=16";
                $this->configObj->glDbObj->query($sql);

                //related tag
                $sql = "delete from " . DB_PREFIX . "category_module_tag where fk_moduleglcode='$deletearray[$i]' and fk_modules=16";
                $this->configObj->glDbObj->query($sql);

                //for activity
                $sql = "delete from " . DB_PREFIX . "promotion_related_module where fk_promotion ='$deletearray[$i]' and fk_modules=15";
                $this->configObj->glDbObj->query($sql);

                //for businesss
                $sql = "delete from " . DB_PREFIX . "promotion_related_module where fk_promotion ='$deletearray[$i]' and fk_modules=12";
                $this->configObj->glDbObj->query($sql);

                //for article
                $sql = "delete from " . DB_PREFIX . "promotion_related_module  where fk_promotion ='$deletearray[$i]' and fk_modules=11";
                $this->configObj->glDbObj->query($sql);
            }
        } else if ($_REQUEST['view'] == 'tag') {
            $tablename = $_REQUEST['tablename'];
            $deleteids = $_REQUEST['dids'];
            $deletearray = explode(',', $deleteids);
            $totaldeleterecords = count($deletearray);

            for ($i = 0; $i < $totaldeleterecords; $i++) {
                $sql = "delete from " . $tablename . " where int_glcode='$deletearray[$i]'";
                $this->configObj->glDbObj->query($sql);

                //related category
                $sql = "delete from " . DB_PREFIX . "category_tag where fk_tag=$deletearray[$i]";
                $this->configObj->glDbObj->query($sql);
            }
        } else {
            $tablename = $_REQUEST['tablename'];
            $deleteids = $_REQUEST['dids'];
            $deletearray = explode(',', $deleteids);
            $totaldeleterecords = count($deletearray);

            for ($i = 0; $i < $totaldeleterecords; $i++) {
                if ($_REQUEST['view'] == 'banners') {
                    $sql = "select var_image from " . DB_PREFIX . "banner where int_glcode=" . $deletearray[$i];
                    $row = $this->configObj->glDbObj->get_sql_row($sql);
                    $uploadfile = GLOBAL_MODULES_PATH . '/banners/html/uploads/images/' . $row['var_image'];

                    if (file_exists($uploadfile)) {
                        //echo $uploadfile;
                        unlink($uploadfile);
                    }
                    $uploadfile = GLOBAL_MODULES_PATH . '/banners/html/uploads/images/thumb_banners_' . $row['var_image'];
                    if (file_exists($uploadfile)) {
                        //echo $uploadfile;
                        unlink($uploadfile);
                    }
                    $uploadfile = GLOBAL_MODULES_PATH . '/banners/html/uploads/images/cropped_thumb_banners_' . $row['var_image'];
                    if (file_exists($uploadfile)) {
                        //echo $uploadfile;
                        unlink($uploadfile);
                    }
                }
                $sql = "delete from " . $tablename . " where int_glcode='$deletearray[$i]'";
                $this->configObj->glDbObj->query($sql);
            }
        }
        $this->load_trashmanager();
    }

    function getModulesCombo($position) {

        $view = $_REQUEST['view'];

        $type = ($position == "top") ? "MT" : "MB";
        $module = "select * from " . DB_PREFIX . "modules where chr_delete='N' and chr_publish='Y' and chr_filterflag='Y' order by  int_glcode asc";
        $rs1 = $this->configObj->glDbObj->query($module);
        $custmodule = "select * from " . DB_PREFIX . "pages where chr_custom='Y' and chr_delete='N' and chr_publish='Y' and chr_previewstatus='N' ";
        $rs2 = $this->configObj->glDbObj->query($custmodule);
        $noofcus = "select count(1) as total from " . DB_PREFIX . "pages where chr_custom='Y' and chr_delete='N' and chr_publish='Y'  and chr_previewstatus='N'  ";
        $count = $this->configObj->glDbObj->get_sql_row($noofcus);
        $display = "<div class=\"new-search-show-all\">";
        $display .="<select id=\"cmbmodules$position\" name=\"cmbmodules$position\" onchange=\"SendGridBindRequest('index.php?module=trashmanager&view=" . $_REQUEST['view'] . "','gridbody','$type') \" class=\"more-textarea\">";
        $display .="<optgroup label=\"Modules\">";
        while ($row = $this->configObj->glDbObj->fetch_array($rs1)) {
            $p = ($row['var_modulename'] == $view) ? 'selected' : '';
            $display.="<option value=" . $row['var_modulename'] . " " . $p . ">" . $row['chr_pro_modulename'] . "</option>";
        }
        if ($this->configObj->glSessionObj->value('admin_id') == '1') {
            if ($count['total'] > 0) {
                $display .="<optgroup label=\"Custom Modules\">";
            }
        }
        while ($custrow = $this->configObj->glDbObj->fetch_array($rs2)) {
            $p1 = ($custrow['int_glcode'] . '-custom' == $view) ? 'selected="selected"' : '';
            $display.="<option value=" . $custrow['int_glcode'] . '-custom' . " " . $p1 . ">" . $custrow['var_pagename'] . "</option>";
        }
        return $display.="</select></div>";
    }

    function load_trashmanager() {
        $fullview = $_REQUEST['view'];
        $viewrequested = substr($fullview, -7);
        $newview = substr($fullview, 0, -7);


        if ($_REQUEST['view'] == 'commonpdf') {
            $this->view = '';
            $searchArray = array("var_title" => "Title", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'pdf_mst';
            $this->displayfield1 = "var_title";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Title";
            $this->displayfieldtitle2 = "";
            $this->view = 'commonpdf';
            $view1 = 'Trash Manager - Common Files';
        }

        else if ($_REQUEST['view'] == 'newsletter') {
            $this->view = '';
            $searchArray = array("var_email" => "Email Id", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'newsletterleads';
            $this->displayfield1 = "var_email";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Email Id";
            $this->displayfieldtitle2 = "";
            $this->view = 'newsletter';
            $view1 = 'Trash Manager - Newsletter Leads';
        }   else if ($_REQUEST['view'] == 'appointment') {
            $this->view = '';
            $searchArray = array("var_name" => "Name", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'appointmentleads';
            $this->displayfield1 = "var_name";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Name";
            $this->displayfieldtitle2 = "";
            $this->view = 'appointment';
            $view1 = 'Trash Manager - Book an Appointment Leads';
        } else if ($_REQUEST['view'] == 'pagephoto') {
            $this->view = '';
            $searchArray = array("var_title" => "Title", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'pagephoto';
            $this->displayfield1 = "var_title";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Title";
            $this->displayfieldtitle2 = "";
            $this->view = 'pagephoto';
            $view1 = 'Trash Manager - Page Banner';
        } else if ($_REQUEST['view'] == 'news') {
            $this->view = '';
            $searchArray = array("var_title" => " News Title", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'news';
            $this->displayfield1 = "var_title";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "News Title";
            $this->displayfieldtitle2 = "";
            $this->view = 'news';
            $view1 = 'Trash Manager - News';
        } else if ($_REQUEST['view'] == 'comments') {
            $this->view = '';
            $searchArray = array("varcomment" => "Comment");
            $this->tablename = DB_PREFIX . 'comments';
            $this->displayfield1 = "varcomment";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Comment";
            $this->displayfieldtitle2 = "";
            $this->view = 'comments';
            $view1 = 'Trash Manager - Comments';
        } else if ($_REQUEST['view'] == 'photoalbum') {
            $this->view = '';
            $searchArray = array("var_title" => "Title", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'photoalbum';
            $this->displayfield1 = "var_title";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Title";
            $this->displayfieldtitle2 = "";
            $this->view = 'photoalbum';
            $view1 = 'Trash Manager - Photo Abums';
        } else if ($_REQUEST['view'] == 'product') {
            $this->view = '';
            $searchArray = array("var_title" => "Title", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'product';
            $this->displayfield1 = "var_title";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Title";
            $this->displayfieldtitle2 = "";
            $this->view = 'product';
            $view1 = 'Trash Manager - Products';
        } else if ($_REQUEST['view'] == 'services') {
            $this->view = '';
            $searchArray = array("var_title" => "Title", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'services';
            $this->displayfield1 = "var_title";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Title";
            $this->displayfieldtitle2 = "";
            $this->view = 'services';
            $view1 = 'Trash Manager - Services';
        } else if ($_REQUEST['view'] == 'productphotogallery') {
            $this->view = '';
            $searchArray = array("varphotocaption" => "Title", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'productphotogallery';
            $this->displayfield1 = "varphotocaption";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Title";
            $this->displayfieldtitle2 = "";
            $this->view = 'productphotogallery';
            $view1 = 'Trash Manager - Product Photogallery';
        } else if ($_REQUEST['view'] == 'careers') {
            $this->view = '';
            $searchArray = array("var_positions " => "Title", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'careers';
            $this->displayfield1 = "var_positions ";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Title";
            $this->displayfieldtitle2 = "";
            $this->view = 'careers';
            $view1 = 'Trash Manager - Careers';
        } else if ($_REQUEST['view'] == 'ourteam') {
            $this->view = '';
            $searchArray = array("var_name" => "Name", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'ourteam';
            $this->displayfield1 = "var_name";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Name";
            $this->displayfieldtitle2 = "";
            $this->view = 'ourteam';
            $view1 = 'Trash Manager - Our Team';
        } else if ($_REQUEST['view'] == 'special') {
            $this->view = '';
            $searchArray = array("var_title" => "Title", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'special';
            $this->displayfield1 = "var_title";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Name";
            $this->displayfieldtitle2 = "";
            $this->view = 'special';
            $view1 = 'Trash Manager - Special';
        } else if ($_REQUEST['view'] == 'package') {
            $this->view = '';
            $searchArray = array("var_title" => " Package Title", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'package';
            $this->displayfield1 = "var_title";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Package Title";
            $this->displayfieldtitle2 = "";
            $this->view = 'package';
            $view1 = 'Trash Manager - Packages';
        } else if ($_REQUEST['view'] == 'packagetype') {
            $this->view = '';
            $searchArray = array("var_title" => " Package Type Title", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'packagetype';
            $this->displayfield1 = "var_title";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Package Type Title";
            $this->displayfieldtitle2 = "";
            $this->view = 'packagetype';
            $view1 = 'Trash Manager - Package Type';
        } else if ($_REQUEST['view'] == 'pagephoto') {
            $this->view = '';
            $searchArray = array("var_title" => " Package Type Title", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'banner';
            $this->displayfield1 = "var_title";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Page Banner";
            $this->displayfieldtitle2 = "";
            $this->view = 'pagephoto';
            $view1 = 'Trash Manager - Page Banner';
        } else if ($_REQUEST['view'] == 'banner') {
            $this->view = '';
            $searchArray = array("var_title" => "Banner Title", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'banner';
            $this->displayfield1 = "var_title";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Page Banner";
            $this->displayfieldtitle2 = "";
            $this->view = 'banner';
            $view1 = 'Trash Manager - Page Banner';
        } else if ($_REQUEST['view'] == 'reviewapplication') {
            $this->view = '';
            $searchArray = array("var_firstname" => "First Name", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'app_form';
            $this->displayfield1 = "var_firstname";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Title";
            $this->displayfieldtitle2 = "";
            $this->view = 'reviewapplication';
            $view1 = 'Trash Manager - Review Application';
        } else if ($_REQUEST['view'] == 'videogallery') {
            $this->view = '';
            $searchArray = array("var_title" => " Video Title", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'videogallery';
            $this->displayfield1 = "var_title";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Video Title";
            $this->displayfieldtitle2 = "";
            $this->view = 'videogallery';
            $view1 = 'Trash Manager - Videogallery';
        } else if ($_REQUEST['view'] == 'groups') {
            $this->view = '';
            $searchArray = array("var_name" => "Name");
            $this->tablename = DB_PREFIX . 'groups';
            $this->displayfield1 = "var_name";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Name";
            $this->displayfieldtitle2 = "";
            $this->view = 'groups';
            $view1 = 'Trash Manager - Groups';
        } else if ($_REQUEST['view'] == 'service_category') {
            $this->view = '';
            $searchArray = array("var_title" => "Name");
            $this->tablename = DB_PREFIX . 'service_category';
            $this->displayfield1 = "var_title";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Name";
            $this->displayfieldtitle2 = "";
            $this->view = 'service_category';
            $view1 = 'Trash Manager - service_category';    
        } else {
            $this->view = '';
            $searchArray = array("var_pagename" => "Page name", "var_adminuser" => "User Name", "var_ipaddress" => "Ip Address");
            $this->tablename = DB_PREFIX . 'pages';
            $this->displayfield1 = "var_pagename";
            $this->displayfield2 = "";
            $this->displayfieldtitle1 = "Page Name";
            $this->displayfieldtitle2 = "";
            $this->view = 'pages';
            $view1 = 'Trash Manager - Pages';
        }
        $this->loadcount('CountRows');
        $result = $this->selectall_trash();
        $this->configObj->glTplObj->set('result', $result);
        $actionurl = 'index.php?module=trashmanager&view=' . $this->view;
        $parmas = $this->generateParam($view1, $actionurl, $searchArray, $this->tablename);
        $this->configObj->glTplObj->set('headerpanel', $this->configObj->glLibraryObj->generateHeaderPanel($parmas, 'no'));
        $this->configObj->glTplObj->set('pagingTop', $this->configObj->glLibraryObj->generatePagingPannel($parmas));
        $this->configObj->glTplObj->set('pagingBottom', $this->configObj->glLibraryObj->generatePagingPannel($this->generateParam($view1, $actionurl, $searchArray, $this->tablename, 'bottom')));
        $notemessagebox = $this->configObj->glLibraryObj->notemessage("Note : ", "Please take a note that the records which are 30 days older will be automatically deleted from the database and will not be available later on into the PowerPanel.");
        $this->configObj->glTplObj->set('notemessagebox', $notemessagebox);

        $tmpsetsortvar = 'setsortimg' . $this->orderby;
        $$finalsortvar = $tmpsetsortvar;

        $this->configObj->glTplObj->set($$finalsortvar, $this->sortvar);

        if ($_REQUEST['msg']) {
            if ($_REQUEST['msg'] == 'add') {
                $messagebox = $this->configObj->glLibraryObj->message("Congrats! The record is successfully saved!");
                $this->configObj->glTplObj->set('messagebox', $messagebox);
            } else if ($_REQUEST['msg'] == 'edit') {
                $messagebox = $this->configObj->glLibraryObj->message("Congrats! The record modified successfully!");
                $this->configObj->glTplObj->set('messagebox', $messagebox);
            }
        }
        if ($this->configObj->isAjaxSet) {
            echo $this->configObj->glTplObj->process('trashmanager.tpl.php');
            exit;
        } else {
            $this->configObj->adminContentPanel = $this->configObj->glTplObj->process('trashmanager.tpl.php');
        }
    }

    function selectall_trash() {
        $dtformat = DEFAULT_DATEFORMAT;
        $this->configObj->glDbObj->resetfields(); // Reset the object
        $this->configObj->glDbObj->setQueryType('select');    // Set the Table


        $fullview = $_REQUEST['view'];
        $viewrequested = substr($fullview, -7);
        $newview = substr($fullview, 0, -7);

        if ($_REQUEST['view'] == $newview . '-custom') {
            $this->configObj->glDbObj->setTable(" " . DB_PREFIX . "custom_data as cd join " . DB_PREFIX . "pages p on cd.fk_pages=p.int_glcode");
            $this->configObj->glDbObj->addColumn("cd.*,cd.dt_modifydate as modifydate,p.var_pagename");
        } else if ($_REQUEST['view'] == 'settings') {
            $this->configObj->glDbObj->setTable($this->tablename . " as e left join " . DB_PREFIX . "emailtype as et on e.fk_emailtype = et.int_glcode ");
            $this->configObj->glDbObj->addColumn("e.*,type,DATE_FORMAT(dt_modifydate, '" . $dtformat . "') as modifydate");
        } else {
            $this->configObj->glDbObj->setTable($this->tablename);
            $this->configObj->glDbObj->addColumn("*,dt_modifydate as modifydate");
        }

        $whereclause1 = "chr_delete = 'Y'";
        $whereclause2 = "p.chr_delete = 'Y'";
        if ($_REQUEST['view'] == $newview . '-custom') {
            $whereclause = "cd.chr_delete = 'Y' and p.int_glcode=" . $newview . "";
        } else {
            $whereclause = "chr_delete = 'Y'";
        }

        if ($this->modval != '0' && $this->modval != '') {
            $whereclause1 .=" and FIND_IN_SET('" . $this->modval . "',mp.fk_modules)";
        }

        if ($this->configObj->glSessionObj->value('chr_user') == 'A') {
            if ($_REQUEST['view'] == $newview . '-custom') {
                $whereclause.=" and cd.var_adminuser!='Netclues' ";
            } else {
                $whereclause.=" and var_adminuser!='Netclues' ";
            }

            $whereclause1.=" and var_adminuser!='Netclues' ";
        }
        $admin = '"' . ADMIN_NAME . '"';
        if ($this->configObj->glSessionObj->value('admin_id') != '1' && $this->configObj->glSessionObj->value('chr_user') != 'A') {
            if ($_REQUEST['view'] == $newview . '-custom') {
                $whereclause.=" and cd.var_adminuser=" . $admin . " ";
            } else {
                $whereclause.=" and var_adminuser=" . $admin . " ";
            }

            $whereclause1.=" and var_adminuser=" . $admin . " ";
        }

        if ($_REQUEST['view'] == 'users') {
            $whereclause .= "and chr_usertype IN ('U','V')";
        } else if ($_REQUEST['view'] == 'staff') {
            $whereclause .= "and chr_usertype='S'";
        }
        if ($this->displayfield2 != '') {
            if (trim($this->searchtxt) != '') {


                $whereclause .= ($this->searchby == '0') ? " and ((" . $this->displayfield1 . " like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%') or (" . $this->displayfield2 . " like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%') or (concat(" . $this->displayfield1 . ",' '," . $this->displayfield2 . ") like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'))  " : " and $this->searchby like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'";
                $whereclause1 .= ($this->searchby == '0') ? " and {$this->searchbyVal} like \"%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%\" " : " and p.$this->searchby  like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'";
            }
        } else {

            if (trim($this->searchtxt) != '') {

                $whereclause .= ($this->searchby == '0') ? " and {$this->searchbyVal} like \"%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%\" " : " and $this->searchby  like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'";
                $whereclause1 .= ($this->searchby == '0') ? " and {$this->searchbyVal} like \"%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%\" " : " and $this->searchby  like '%" . $this->configObj->glDbObj->addSlashes($this->searchtxt) . "%'";
                $whereclause2 .= ($this->searchby == '0') ? " and {$this->searchbyVal} 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]'";
        }
        if ($_REQUEST['view'] == $newview . '-custom') {
            $this->configObj->glDbObj->setWhere($whereclause);
        } else {
            $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' || !empty($_REQUEST['auto'])) {
            $orderby = (isset($_REQUEST['orderby'])) ? 'order by ' . $this->orderby . ' ' . $this->ordertype : 'order by int_glcode';

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


            if ($_REQUEST['view'] == 'settings') {
                $autoSearchQry = "select e.int_glcode ," . $this->displayfield1 . " as AutoVal FROM " . $this->tablename . " as e left join " . DB_PREFIX . "emailtype as et on e.fk_emailtype = et.int_glcode where $whereclause  $searchbyVal group by type $orderby";
            } else if ($_REQUEST['view'] == $newview . '-custom') {
                $autoSearchQry = "select cd.int_glcode ,{$this->searchbyVal} as AutoVal FROM " . $this->tablename . " as cd join " . DB_PREFIX . "pages p on cd.fk_pages=p.int_glcode where $whereclause  $searchbyVal group by {$this->searchbyVal} $orderby";
            } else {
                $autoSearchQry = "select int_glcode ,{$this->searchbyVal} as AutoVal FROM " . $this->tablename . " where $whereclause  $searchbyVal group by {$this->searchbyVal} $orderby";
            }
            $this->configObj->glLibraryObj->GetAutoSearch($autoSearchQry);
        }
        $rs = $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        return $rs;
    }

    function generateParam($view, $actionurl, $searchArray, $table, $position = 'top') {
        $filterstar = array();
        if ($position == 'top') {
            
        }
        $modulescombo = $this->getModulesCombo($position);
        $tid = $_REQUEST['view'];
        $this->configObj->glTplObj->set('tid', $tid);

        return array('pageurl' => $this->pagename,
            'heading' => $view,
            'listImage' => 'add-new-user-icon.png',
            'tablename' => $this->tablename,
            'position' => $position,
            'actionImage' => '',
            'actionImageHover' => '',
            '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,
            ),
            'modulescombo' => $modulescombo,
            'modcmb' => $modcmb
        );
    }

    function Bindmodule() {
        $selected_array = $_REQUEST['modval'];
        $module = "select * from " . DB_PREFIX . "modules where chr_delete='N' and chr_publish='Y' and chr_gallerymodule_flag='Y'";
        $rs1 = $this->configObj->glDbObj->query($module);
        $display = "<div class=\"new-search-show-all\">";
        $display .="<select name=\"module\" id=\"module\" class=\"more-textarea\"  onchange=\"SendGridBindRequest('$this->urlwithpara','gridbody','MVF')\">";
        $display .="<option value=\"0\">-- Filter By Module --</option>";
        while ($row = $this->configObj->glDbObj->fetch_array($rs1)) {
            $p = ($row['int_glcode'] == $selected_array) ? 'selected' : '';
            $display.="<option value=" . $row['int_glcode'] . " " . $p . ">" . $row['chr_pro_modulename'] . "</option>";
        }
        return $display.="</select></div>";
    }

    function loadCount($function) {
        $this->pagename = 'index.php?module=trashmanager' . '&view=' . $this->view;
        $this->intitialize();
        $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();
    }

}

?>