<?php

class special {

    var $pagename = 'index.php?module=special';
    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 $categorytype = '';
    var $filterby = '0';
    var $urlwithoutfilter = '';
    var $startdate = '';
    var $display_limit_array = array(5, 10, 15, 30);
    var $varpostdata = array();

    function special($configObj) {
        $this->checkAliasTable = array(
            DB_PREFIX . "special" => "var_alias",);
        //  $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;
        $this->searchby = (isset($_REQUEST['searchby'])) ? $_REQUEST['searchby'] : $this->searchby;
        $this->startdate = (isset($_REQUEST['startdate'])) ? $_REQUEST['startdate'] : $this->startdate;
        $_REQUEST['searchtxt'] = ($_REQUEST['type'] == 'autosearch') ? $_REQUEST['term'] : $_REQUEST['searchtxt'];
        $this->searchbyVal = (isset($_REQUEST['searchbyVal'])) ? $_REQUEST['searchbyVal'] : $this->searchbyVal;
        $this->searchtxt = (isset($_REQUEST['searchtxt'])) ? $_REQUEST['searchtxt'] : '';
        $this->searchtxtjs = (isset($_REQUEST['searchtxt'])) ? $_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->start = ($this->pagenumber - 1 ) * $this->pagesize;
    }

    function select_special($id) {
        $dtformat = DEFAULT_DATEFORMAT;
        $this->configObj->glDbObj->resetfields(); // Reset the object
        $this->configObj->glDbObj->setQueryType('select');    // Set the Table
        $this->configObj->glDbObj->setTable(DB_PREFIX . 'special');
        $this->configObj->glDbObj->addColumn("*,date_format(dt_startdate,'" . $dtformat . "') as dt_startdate, DATE_FORMAT(dt_expiredate, '" . DEFAULT_DATEFORMAT . "') as dt_expiredate");
        $this->configObj->glDbObj->setWhere("int_glcode =" . $id);
        $row = $this->configObj->glDbObj->get_sql_row($this->configObj->glDbObj->buildQuery());
        return $row;
    }

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

    function CountAssignedPosition($sql) {
        $this->configObj->glDbObj->resetfields(); // Reset the object
        $rs = $this->configObj->glDbObj->get_sql_row($sql);
        return $rs['total'];
    }

    /*
     * Facebook and Twitter Start
     */

    function getfacabookaccount() {
        $sql = "select * from " . DB_PREFIX . "facebook where chr_delete='N' and chr_publish='Y'";
        $rec = $this->configObj->glDbObj->query($sql);
        return $rec;
    }

    function gettwitteraccount() {
        $sql = "select * from " . DB_PREFIX . "twitter where chr_delete='N' and chr_publish='Y'";
        $rec = $this->configObj->glDbObj->query($sql);
        return $rec;
    }

    function getspecialcustomdata() {
        $sql = "SELECT var_title,var_description FROM " . DB_PREFIX . "special WHERE chr_delete='N' AND int_glcode='" . $_REQUEST['eid'] . "'";
        $result = $this->configObj->glDbObj->get_sql_row($sql);
        return $result;
    }

    function genrateshareOption() {

        $this->configObj->glTplObj->set('twitterresult', $this->gettwitteraccount());
        $this->configObj->glTplObj->set('result', $this->getfacabookaccount());
        $this->configObj->glTplObj->set('specialdata', $this->getspecialcustomdata());
        return $this->configObj->glTplObj->process('shareoption.tpl.php');
    }

    function getlogdetail($fb_tw_id, $articleid, $type = "F") {
        $sql = "select *,DATE_FORMAT(dt_createdate ,'" . DEFAULT_DATEFORMAT . "') as dt_createdate from " . DB_PREFIX . "sharelog where chr_type ='{$type}' and fk_facebook_twitter ={$fb_tw_id}  and fk_article={$articleid} and fk_module=83  order by dt_createdate desc limit 0,1";
        $rec = $this->configObj->glDbObj->query($sql);
        return $rec;
    }

    function get_Post_data($id) {
        $sql = "SELECT * FROM " . DB_PREFIX . "special WHERE chr_delete='N' AND int_glcode='" . $id . "'";

        $result = $this->configObj->glDbObj->get_sql_row($sql);

        $imagename = $result['var_image'];
        $corePath = "upimages/special/images/";
        $imagepath = '../' . $corePath;
        $imagename = "thumb_" . $imagename;

        $image = $imagepath . $imagename;

        $imagelink = $corePath . $imagename;
        //echo !file_exists($image);

        if ($imagename != "") {
            $image = (!file_exists($image)) ? "" : $image;
        } else {
            $image = "";
        }
        //echo $image;
        if (!empty($image)) {
            $image = SITE_PATH . $imagelink;
            $paramArr['data']['picture'] = $image;
        }
        if (SITE_SEO == 'Y') {
            $speciallink = SITE_PATH . $result["var_alias"];
        } else {
            $speciallink = SITE_PATH . "special" . $id;
        }

        $paramArr['int_glcode'] = $id;
        $paramArr['data']['name'] = $this->varpostdata['var_title'];
        $paramArr["data"]["actions"] = array("name" => "Sent from Netclues PowerPanel", "link" => "http://www.netclues.ky");
        $paramArr['data']['link'] = $speciallink;
        if ($this->varpostdata['var_description'] != '') {
            $paramArr['data']['description'] = $this->varpostdata['var_description'];
        }
        // $paramArr['description'] = "hello";

        return $paramArr;
    }

    function shareonfacebook() {
        $status = 0;

        if (!empty($this->varpostdata['fb']) || !empty($this->varpostdata['tw'])) {
            $eidArray = explode(",", $this->varpostdata['eid']);

            foreach ($eidArray as $eidvalue) {
                $param = $this->get_Post_data($eidvalue);
                if (!empty($this->varpostdata['fb'])) {

                    foreach ($this->varpostdata['fb'] as $value) {
                        // print_r($value);
                        $pageDetail = $this->getfbpagedetail($value);

                        $param["APP_ID"] = $pageDetail['var_application_id'];
                        $param["APP_SECRET"] = $pageDetail['var_seceret_key'];
                        $param["PAGE_ID"] = $pageDetail['var_page_id'];
                        $param["access_token"] = $pageDetail['var_oauth_token'];

                        if ($this->configObj->glLibraryObj->shareOnFacebook($param) == 1) {
                            $status = 1;
                            $this->addfbsharelog($pageDetail, $param, "F");
                        }
                    }
                }
                if (!empty($this->varpostdata['tw'])) {
                    $eidArray = explode(",", $this->varpostdata['eid']);

                    $trid = $eidArray[0];
//                    $albumalias = $this->get_album_alias($trid);
                    foreach ($this->varpostdata['tw'] as $value) {
                        $pageDetail = $this->gettwpagedetail($value);

                        $param['CONSUMER_KEY'] = $pageDetail['var_consumer_key'];
                        $param['CONSUMER_SECRET'] = $pageDetail['var_consumer_secret'];
                        $param['OUATH_TOKEN'] = $pageDetail['var_ouath_token'];
                        $param['OUATH_TOKEN_SECRET'] = $pageDetail['var_ouath_token_secret'];
                        $param['status'] = $param['name'];
                        $param['media'] = $param['picture'];
                        $titledata = strlen($param['data']['name']) > 50 ? substr($param['data']['name'], 0, 50) . "..." : $param['data']['name'];
                        $data = strlen($param['data']['description']) > 70 ? substr($param['data']['description'], 0, 70) . "..." : $param['data']['description'];
                        $param['data']['name'] = $titledata;
                        $param['data']['name'] .= "\n" . $data;


                        $param['data']['name'] .= "\n" . SITE_PATH;
//                        $param['data']['name'].=$param['media'];
                        if ($this->configObj->glLibraryObj->shareOnTwitter($param) == 1) {
                            $status = 1;
                            $this->addfbsharelog($pageDetail, $param, "T");
                        }
                    }
                }
            }
        }
        // print_r($_REQUEST);
        return $status;
    }

    function getfbpagedetail($id) {
        $sql = "select * from " . DB_PREFIX . "facebook where chr_delete='N' and chr_publish='Y' and int_glcode={$id}";
        $rec = $this->configObj->glDbObj->get_sql_row($sql);
        return $rec;
    }

    function gettwpagedetail($id) {
        $sql = "select * from " . DB_PREFIX . "twitter where chr_delete='N' and chr_publish='Y' and int_glcode={$id}";
        $rec = $this->configObj->glDbObj->get_sql_row($sql);
        return $rec;
    }

    function addfbsharelog($pageParam, $articleParam, $type) {
        $param = array(
            "fk_facebook_twitter" => $pageParam['int_glcode'],
            "fk_article" => $articleParam['int_glcode'],
            "chr_type" => $type,
            "dt_createdate" => "now()",
            "dt_modifydate" => "now()",
            "fk_module" => "83"
        );

        $this->configObj->glLibraryObj->insertIntoDB(DB_PREFIX . "sharelog", $param);
        $this->insertfacebooklogdata();
    }

    function insertfacebooklogdata() {
        $sql = "insert into " . DB_PREFIX . "facebooklog (fk_sharelogglcode,var_title,var_description,var_ipaddress,var_name) values ('" . mysql_insert_id() . "','" . mysql_real_escape_string($this->varpostdata['var_title']) . "','" . mysql_real_escape_string($this->varpostdata['var_short_description']) . "','" . $_SERVER['REMOTE_ADDR'] . "','" . ADMIN_NAME . "')";
        $this->configObj->glDbObj->query($sql);
    }

    /*
     * Facebook and Twitter End
     */

    function catnews($id) {
        $sql = "select var_title from " . DB_PREFIX . "special where int_glcode=" . $id;
        $result = $this->configObj->glDbObj->get_sql_row($sql);
        return $result['var_title'];
    }

    function selectall_special() {
        //echo $this->startdate;
        $dtformat = DEFAULT_DATEFORMAT;
        $this->configObj->glDbObj->resetfields(); // Reset the object
        $this->configObj->glDbObj->setQueryType('select');    // Set the Table
        $tablename = DB_PREFIX . "special ";
        $this->configObj->glDbObj->setTable($tablename);
        $this->configObj->glDbObj->addColumn("*,date_format(dt_startdate,'" . $dtformat . "') as dt_startdate, DATE_FORMAT(dt_expiredate, '" . DEFAULT_DATEFORMAT . "') as dt_expiredate");
        $whereclause = " chr_delete = 'N' ";

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

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

            if ($this->startdate != '0' && $this->startdate != '') {
                $whereclause .= " and DATE_FORMAT(dt_startdate, '%Y') = '$this->startdate'";
            }
            if ($this->searchbyVal == 'var_title') {
                $this->searchbyVal = "var_title";
            }
            $searchbyVal = (!empty($this->searchbyVal)) ? " $whereclause " : $whereclause;
            $autoSearchQry = "select int_glcode ," . $this->searchbyVal . " as AutoVal FROM " . $tablename . " where $searchbyVal group by " . $this->searchbyVal . " $orderby";
            $this->configObj->glLibraryObj->GetAutoSearch($autoSearchQry);
        }
        $this->configObj->glDbObj->buildQuery();
        $rs = $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        return $rs;
    }

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

    function updatedisplay_order() {
        $this->configObj->glDbObj->resetfields();
        $this->configObj->glDbObj->setQueryType('update');
        $this->configObj->glDbObj->setTable(DB_PREFIX . 'special');
        $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']);
        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
    }

    function upload_image($filefield, $thumb_width, $thumb_height, $prefix, $sess, $thumb_width2, $thumb_height2, $prefix2 = '') {

        $file_photo = basename($_FILES[$filefield]['name']);
        $imagename = $sess . $file_photo;

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

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

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

        switch ($image_info['mime']) {
            case 'image/gif':
                $img_create = 'ImageCreateFromGIF';
                break;
            case 'image/jpeg':
                $img_create = 'ImageCreateFromJPEG';
                break;
            case 'image/png':
                $img_create = 'ImageCreateFromPNG';
                break;
            case 'image/bmp':
                $img_create = 'ImageCreateFromBMP';
                break;
        }

        $photoexe = explode('.', $imagename);
        $photoexename = $photoexe[count($photoexe) - 1];

        if ($photoexename == 'bmp') {

            $src = $this->configObj->glLibraryObj->imagecreatefrombmp($uploadedfile);
        } else {

            $src = @$img_create($uploadedfile);
        }

        list($width, $height) = getimagesize($uploadedfile);

        if ($width >= height && $width >= 1000) {
            $newwidth = 950;
            $newheight = intval(($newwidth * $height) / $width);
        } else if ($height >= width && $height >= 750) {
            $newheight = 700;
            $newwidth = intval(($newheight * $width) / $height);
        } else {
            $newwidth = $width;
            $newheight = $height;
        }


        $tmp = imagecreatetruecolor($newwidth, $newheight);
        $background_color = imagecolorallocate($tmp, 255, 255, 255);
        imagefill($tmp, 0, 0, $background_color);
        imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

        imagejpeg($tmp, $file, 90);

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

        $source1 = $uploaddir . $file_photo;

        //$sess = time();
        $thumbfilename = $prefix . $sess . $file_photo;
        $target1 = $uploaddir . $prefix . $file_photo;
        $target2 = $uploaddir . $prefix2 . $file_photo;
        $thumbstatus = $this->configObj->glLibraryObj->generate_thumb($source1, $thumb_width, false, false, $target1, false, null, $thumb_width, $thumb_height);
        if ($thumbstatus == 'invalid filesize') {
            $errstatus .= ":" . "invalid1";
        }
        if ($thumb_width2 > 0) {
            $thumbstatus = $this->configObj->glLibraryObj->generate_thumb($source1, $thumb_width2, false, false, $target2, false, null, $thumb_width2, $thumb_height2);

            if ($thumbstatus == 'invalid filesize') {
                $errstatus .= ":" . "invalid2";
            }
        }
        if ($returnthumbmsg1 == 'INVALID' || $returnthumbmsg2 == 'INVALID') {
            $this->chr_validthumb = 'N';
        } else {
            $this->chr_validthumb = 'Y';
        }
        return $imagename;
    }

//    ========================================special image=======================================

    function upload_image1($filefield, $thumb_width, $thumb_height, $prefix, $sess, $thumb_width2, $thumb_height2, $prefix2 = '') {

        $file_photo = basename($_FILES[$filefield]['name']);
        $imagename = $sess . $file_photo;

        $uploaddir = '../upimages/special/special_images/';
        $file_photo = $sess . basename($_FILES[$filefield]['name']);
        $file = $uploaddir . $file_photo;
        $tmp = $_FILES[$filefield]['tmp_name'];

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

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

        switch ($image_info['mime']) {
            case 'image/gif':
                $img_create = 'ImageCreateFromGIF';
                break;
            case 'image/jpeg':
                $img_create = 'ImageCreateFromJPEG';
                break;
            case 'image/png':
                $img_create = 'ImageCreateFromPNG';
                break;
            case 'image/bmp':
                $img_create = 'ImageCreateFromBMP';
                break;
        }

        $photoexe = explode('.', $imagename);
        $photoexename = $photoexe[count($photoexe) - 1];

        if ($photoexename == 'bmp') {

            $src = $this->configObj->glLibraryObj->imagecreatefrombmp($uploadedfile);
        } else {

            $src = @$img_create($uploadedfile);
        }

        list($width, $height) = getimagesize($uploadedfile);

        if ($width >= height && $width >= 1000) {
            $newwidth = 950;
            $newheight = intval(($newwidth * $height) / $width);
        } else if ($height >= width && $height >= 750) {
            $newheight = 700;
            $newwidth = intval(($newheight * $width) / $height);
        } else {
            $newwidth = $width;
            $newheight = $height;
        }


        $tmp = imagecreatetruecolor($newwidth, $newheight);
        $background_color = imagecolorallocate($tmp, 255, 255, 255);
        imagefill($tmp, 0, 0, $background_color);
        imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

        imagejpeg($tmp, $file, 90);

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

        $source1 = $uploaddir . $file_photo;

        //$sess = time();
        $thumbfilename = $prefix . $sess . $file_photo;
        $target1 = $uploaddir . $prefix . $file_photo;
        $target2 = $uploaddir . $prefix2 . $file_photo;
        $thumbstatus = $this->configObj->glLibraryObj->generate_thumb($source1, $thumb_width, false, false, $target1, false, null, $thumb_width, $thumb_height);
        if ($thumbstatus == 'invalid filesize') {
            $errstatus .= ":" . "invalid1";
        }
        if ($thumb_width2 > 0) {
            $thumbstatus = $this->configObj->glLibraryObj->generate_thumb($source1, $thumb_width2, false, false, $target2, false, null, $thumb_width2, $thumb_height2);

            if ($thumbstatus == 'invalid filesize') {
                $errstatus .= ":" . "invalid2";
            }
        }
        if ($returnthumbmsg1 == 'INVALID' || $returnthumbmsg2 == 'INVALID') {
            $this->chr_validthumb = 'N';
        } else {
            $this->chr_validthumb = 'Y';
        }
        return $imagename;
    }

    function insert_special() {
        $this->configObj->glLibraryObj->updatedisplay_order('special', $this->varpostdata['int_displayorder']);
        $file_extension = $this->configObj->glLibraryObj->file_extension($_FILES['var_pdffile']['name']);
        $pdf = basename($_FILES['var_pdffile']['name']);
        $pdffile = str_replace(' ', '-', $pdf);
        $pdfdata = explode('.', $pdffile);
        $vartitle = $pdfdata[0];
        $pdffile = str_replace(' ', '-', $pdf);
        $pdfdata1 = explode('.', $pdffile);
        $p = count($pdfdata1);
        unset($pdfdata1[$p - 1]);
        $filename = implode('.', $pdfdata1);
        if ($pdf != "") {
            $uploaddir = '../upimages/special/pdf/';

            $sess = time();
            $pdf = basename($_FILES['var_pdffile']['name']);
            $pdffile = str_replace(' ', '-', $pdf);
            $pdffile = str_replace('%20', '-', $pdf);
            $new_pdfname = $sess . $pdffile;
            //echo $uploaddir ;exit;
            $file = $uploaddir . $new_pdfname;
            $tmp = $_FILES['var_pdffile']['tmp_name'];
            if (move_uploaded_file($tmp, $file)) {

                $pdffile = $new_pdfname;
            } else {
                echo "error " . $_FILES['var_pdffile']['error'] . " --- " . $tmp . " %%% " . $file;
            }
        }

        if ($_FILES['var_image']['name'] != '') {
            $var_photo = $this->upload_image('var_image', 620, 270, 'thumb_', $sess, 620, 270, 'thumb_');
//            $var_photo = $this->upload_image('var_image', SPECIAL_THUMB_WIDTH1, SPECIAL_THUMB_HEIGHT1, 'thumb_', $sess, SPECIAL_THUMB_WIDTH1, SPECIAL_THUMB_HEIGHT1, 'thumb_');
            $var_photo = $this->upload_image('var_image', SPECIAL_DETAIL_THUMB_WIDTH, SPECIAL_DETAIL_THUMB_HEIGHT, 'detail_thumb_', $sess, SPECIAL_DETAIL_THUMB_WIDTH, SPECIAL_DETAIL_THUMB_HEIGHT, 'detail_thumb_');
        }


        if (isset($this->varpostdata['dt_expiredate_no'])) {
            $end_date = 'N/A';
        } else {
            if (DEFAULT_DATEFORMAT == '%d/%m/%Y') {
                $end_date = $this->configObj->glLibraryObj->dtConvertDMYtoYMD($this->varpostdata['dt_expirydate']);
            }
            if (DEFAULT_DATEFORMAT == '%m/%d/%Y') {
                $end_date = $this->configObj->glLibraryObj->dtConvertMDYtoYMD($this->varpostdata['dt_expirydate']);
            }
            if (DEFAULT_DATEFORMAT == '%Y/%m/%d') {
                $end_date = $this->varpostdata['dt_expirydate'];
            }
            if (DEFAULT_DATEFORMAT == '%Y/%d/%m') {
                $end_date = $this->configObj->glLibraryObj->dtConvertYDMtoYMD($this->varpostdata['dt_expirydate']);
            }
        }
        $this->updatedisplay_order();

        $this->configObj->glDbObj->resetfields();
        $this->configObj->glDbObj->setQueryType('insert');
        $this->configObj->glDbObj->setTable(DB_PREFIX . 'special');

        // Set the Columns

        $this->configObj->glDbObj->addColumn('var_title');
        $this->configObj->glDbObj->addColumn('var_alias');

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

        $this->configObj->glDbObj->addColumn('var_pdffile');
        $this->configObj->glDbObj->addColumn('var_filename');
        $this->configObj->glDbObj->addColumn('var_image');

//        $this->configObj->glDbObj->addColumn('var_price');
        $this->configObj->glDbObj->addColumn('dt_startdate');
        $this->configObj->glDbObj->addColumn('dt_expiredate_no');
        $this->configObj->glDbObj->addColumn('dt_expiredate');


        $this->configObj->glDbObj->addColumn('var_homepagecaption');
        $this->configObj->glDbObj->addColumn('var_homepagetitle');
        $this->configObj->glDbObj->addColumn('var_homepagedescription');


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

        $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_publish');
        $this->configObj->glDbObj->addColumn('chr_delete');
        $this->configObj->glDbObj->addColumn('dt_createdate');
        $this->configObj->glDbObj->addColumn('dt_modifydate');
        $this->configObj->glDbObj->addColumn('chr_read');

        // Set the Values

        $this->configObj->glDbObj->addValue($this->varpostdata['var_title']);

        $this->configObj->glDbObj->addValue($this->varpostdata['var_alias']);

        $this->configObj->glDbObj->addValue($this->varpostdata['var_description']);
        $this->configObj->glDbObj->addValue($pdffile);
        $this->configObj->glDbObj->addValue($filename);
        $this->configObj->glDbObj->addValue($var_photo);

//        $this->configObj->glDbObj->addValue($this->varpostdata['var_price']);
        $this->configObj->glDbObj->addValue($this->configObj->glLibraryObj->date_convert($this->varpostdata['dt_startdate']));
        $p = ($this->varpostdata['dt_expiredate_no'] == "Y") ? 'Y' : 'N';
        $this->configObj->glDbObj->addValue($p);
        $this->configObj->glDbObj->addValue($this->configObj->glLibraryObj->date_convert($this->varpostdata['dt_expirydate']));

        $this->configObj->glDbObj->addValue($this->varpostdata['var_homepagecaption']);
        $this->configObj->glDbObj->addValue($this->varpostdata['var_homepagetitle']);
        $this->configObj->glDbObj->addValue($this->varpostdata['var_homepagedescription']);


        $this->configObj->glDbObj->addValue($this->varpostdata['var_home_page_description']);
        $this->configObj->glDbObj->addValue(trim($this->varpostdata['var_metatitle']));
        $this->configObj->glDbObj->addValue(trim($this->varpostdata['var_metakeyword']));
        $this->configObj->glDbObj->addValue(trim($this->varpostdata['var_metadescription']));
        $this->configObj->glDbObj->addValue($this->varpostdata['int_displayorder']);
        $this->configObj->glDbObj->addValue($this->varpostdata['chr_publish']);
        $this->configObj->glDbObj->addValue('N');
        $this->configObj->glDbObj->addValue('NOW()');
        $this->configObj->glDbObj->addValue('NOW()');
        $this->configObj->glDbObj->addValue('N');
        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());

        $this->lastinsertid = mysql_insert_id();
        $this->configObj->glLibraryObj->set_display_order_sequence(DB_PREFIX . 'special');
        $this->configObj->glLibraryObj->insertinlogmanager('83', DB_PREFIX . 'special', 'var_title', $this->lastinsertid, 'I');
        return true;
    }

    // **********************
    // UPDATE
    // **********************

    function update_special() {

        if ($this->varpostdata['int_displayorder'] != $this->varpostdata['old_displayorder']) {
            $tablename = DB_PREFIX . 'special';

            $this->configObj->glDbObj->resetfields();
            $this->configObj->glDbObj->setQueryType('select');
            $this->configObj->glDbObj->setTable(DB_PREFIX . 'special');
            $this->configObj->glDbObj->addColumn('count(1) as total');
            $this->configObj->glDbObj->setWhere("int_displayorder=" . $this->varpostdata['int_displayorder'] . " and chr_delete = 'N' ");
            //echo $this->configObj->glDbObj->buildQuery();
            $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'] . '');
                    $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
                } else {
                    $this->configObj->glDbObj->resetfields();
                    $this->configObj->glDbObj->setTable(DB_PREFIX . 'special');
                    $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  int_displayorder < ' . $this->varpostdata['old_displayorder'] . '');
                    $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
                }
            }
        }
        if ($this->varpostdata['int_displayorder'] != $this->varpostdata['old_displayorder']) {
            $this->update_display_order($this->varpostdata['eid'], $this->varpostdata['int_displayorder'], $this->varpostdata['old_displayorder']);
        }

        $file_extension = $this->configObj->glLibraryObj->file_extension($_FILES['var_pdffile']['name']);
        $pdf = basename($_FILES['var_pdffile']['name']);

        if ($pdf != "") {

            $pdffile = str_replace(' ', '-', $pdf);
            $pdfdata = explode('.', $pdffile);
            $vartitle = $pdfdata[0];
            $pdfdata1 = explode('.', $pdffile);
            $p = count($pdfdata1);
            unset($pdfdata1[$p - 1]);
            $filename = implode('.', $pdfdata1);

            $uploaddir = '../upimages/special/pdf/';
            $sess = time();
            $pdf = basename($_FILES['var_pdffile']['name']);
            $pdffile = str_replace(' ', '-', $pdf);
            $new_pdfname = $sess . $pdffile;
            //echo $uploaddir ;exit;

            $file = $uploaddir . $new_pdfname;
            $tmp = $_FILES['var_pdffile']['tmp_name'];
            if (move_uploaded_file($tmp, $file)) {
                //echo 'successful';exit;
                $pdffile = $new_pdfname;
            } else {
                echo "error " . $_FILES['var_pdffile']['error'] . " --- " . $tmp . " %%% " . $file;
            }
        } else {
            $pdffile = $_REQUEST['hidvar_pdffile'];
            $filename = $_REQUEST['hidvar_filename'];
        }

        if ($_FILES['var_image']['name'] != '') {
            $thumb_width = SPECIAL_THUMB_WIDTH1;
            $thumb_height = SPECIAL_THUMB_HEIGHT1;
            $thumb_width1 = SPECIAL_DETAIL_THUMB_WIDTH;
            $thumb_height1 = SPECIAL_DETAIL_THUMB_HEIGHT;
            $file_sphoto1 = basename($_FILES['var_image']['name']);
            if ($file_sphoto1 != '') {
                $sess = time();
//                $var_photo = $this->upload_image('var_image', $thumb_width, $thumb_height, 'thumb_', $sess, $thumb_width, $thumb_height, 'thumb_');
                $var_photo = $this->upload_image('var_image', 620, 270, 'thumb_', $sess, 620, 270, 'thumb_');
                $var_photo = $this->upload_image('var_image', $thumb_width1, $thumb_height1, 'detail_thumb_', $sess, $thumb_width1, $thumb_height1, 'detail_thumb_');

                $temparr = explode(':', $var_photo);
                if ($temparr[1] == 'invalid1') {
                    $var_photo = $temparr[2];
                    $chr_validphoto = 'N';
                } else {
                    $var_photo = $temparr[0];
                    $chr_validphoto = 'Y';
                }
            } else {
                $chr_validphoto = 'N';
            }
        } else {
            $var_photo = $_REQUEST['hidvar_image'];
        }


        $this->configObj->glDbObj->resetfields();
        $this->configObj->glDbObj->setQueryType('update');
        $this->configObj->glDbObj->setTable(DB_PREFIX . 'special');

        // Set the Columns

        $this->configObj->glDbObj->addColumn('var_title');
        $this->configObj->glDbObj->addColumn('var_alias');

        $this->configObj->glDbObj->addColumn('var_description');
        $this->configObj->glDbObj->addColumn('var_pdffile');
        $this->configObj->glDbObj->addColumn('var_filename');
        $this->configObj->glDbObj->addColumn('var_image');

//        $this->configObj->glDbObj->addColumn('var_price');
        $this->configObj->glDbObj->addColumn('dt_startdate');
        $this->configObj->glDbObj->addColumn('dt_expiredate_no');
        $this->configObj->glDbObj->addColumn('dt_expiredate');


        $this->configObj->glDbObj->addColumn('var_homepagecaption');
        $this->configObj->glDbObj->addColumn('var_homepagetitle');
        $this->configObj->glDbObj->addColumn('var_homepagedescription');


        $this->configObj->glDbObj->addColumn('var_home_page_description');
        $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_publish');
        $this->configObj->glDbObj->addColumn('chr_read');
        $this->configObj->glDbObj->addColumn('chr_delete');
        $this->configObj->glDbObj->addColumn('dt_modifydate');

        // Set the Values

        $this->configObj->glDbObj->addValue($this->varpostdata['var_title']);
        $this->configObj->glDbObj->addValue($this->varpostdata['var_alias']);

        $this->configObj->glDbObj->addValue($this->varpostdata['var_description']);
        $this->configObj->glDbObj->addValue($pdffile);
        $this->configObj->glDbObj->addValue($filename);
        $this->configObj->glDbObj->addValue($var_photo);

//        $this->configObj->glDbObj->addValue($this->varpostdata['var_price']);
        $this->configObj->glDbObj->addValue($this->configObj->glLibraryObj->date_convert($this->varpostdata['dt_startdate']));
        $p = ($this->varpostdata['dt_expiredate_no'] == "Y") ? 'Y' : 'N';
        $this->configObj->glDbObj->addValue($p);
        if ($p == 'Y') {
            $this->configObj->glDbObj->addValue($this->configObj->glLibraryObj->date_convert($this->varpostdata['0000-00-00']));
        } else {
            $this->configObj->glDbObj->addValue($this->configObj->glLibraryObj->date_convert($this->varpostdata['dt_expirydate']));
        }

        $this->configObj->glDbObj->addValue($this->varpostdata['var_homepagecaption']);
        $this->configObj->glDbObj->addValue($this->varpostdata['var_homepagetitle']);
        $this->configObj->glDbObj->addValue($this->varpostdata['var_homepagedescription']);

        $this->configObj->glDbObj->addValue($this->varpostdata['var_home_page_description']);
        $this->configObj->glDbObj->addValue(trim($this->varpostdata['var_metatitle']));
        $this->configObj->glDbObj->addValue(trim($this->varpostdata['var_metakeyword']));
        $this->configObj->glDbObj->addValue(trim($this->varpostdata['var_metadescription']));
        $this->configObj->glDbObj->addValue($this->varpostdata['int_displayorder']);
        $this->configObj->glDbObj->addValue($this->varpostdata['chr_publish']);
        $this->configObj->glDbObj->addValue('Y');
        $this->configObj->glDbObj->addValue('N');
        $this->configObj->glDbObj->addValue('NOW()');


        $this->configObj->glDbObj->setWhere('int_glcode=' . $this->varpostdata['eid']);
        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        $this->configObj->glLibraryObj->set_display_order_sequence(DB_PREFIX . 'special');
        $this->configObj->glLibraryObj->insertinlogmanager('83', DB_PREFIX . 'special', 'var_title', $this->varpostdata['eid'], 'U');
        return true;
    }

    function delbrochureimg() {
        $this->configObj->glDbObj->resetfields();
        $this->configObj->glDbObj->setQueryType('update');
        $this->configObj->glDbObj->setTable(DB_PREFIX . 'special');
        $this->configObj->glDbObj->addColumn('var_image');
        $this->configObj->glDbObj->addValue('');
        $this->configObj->glDbObj->setWhere('int_glcode = ' . $_REQUEST['sid'] . ' ');
        echo $this->configObj->glDbObj->buildQuery();
        exit;
        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        return true;
    }

    function delbrochureimg1() {
        $this->configObj->glDbObj->resetfields();
        $this->configObj->glDbObj->setQueryType('update');
        $this->configObj->glDbObj->setTable(DB_PREFIX . 'special');
        $this->configObj->glDbObj->addColumn('var_special_image');
        $this->configObj->glDbObj->addValue('');
        $this->configObj->glDbObj->setWhere('int_glcode = ' . $_REQUEST['ssid'] . ' ');
        echo $this->configObj->glDbObj->buildQuery();
        exit;
        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        return true;
    }

    function deletedocument($id, $file) {
        $this->configObj->glDbObj->resetfields();
        $this->configObj->glDbObj->setQueryType('update');
        $this->configObj->glDbObj->setTable(DB_PREFIX . 'special');
        $this->configObj->glDbObj->addColumn('var_pdffile');
        $this->configObj->glDbObj->addColumn('var_filename');
        $this->configObj->glDbObj->addValue('');
        $this->configObj->glDbObj->addValue('');
        $this->configObj->glDbObj->setWhere("int_glcode='$id'");
        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        return true;
    }

    function org_generateParam($view = 'special', $actionurl = 'index.php?module=special&action=add', $searchArray = array("var_title" => "Title"), $table = 'DB_PREFIX.special', $position = 'top') {
        $filterPos = ($position == 'top') ? 'FT' : 'FB';

        if ($this->configObj->glSessionObj->value('admin_id') == '1' || $this->configObj->glSessionObj->value('chr_user') == 'A') {
            $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' => $view,
            'listImage' => 'add-new-user-icon.png',
            'tablename' => $table,
            'position' => $position,
            'actionImage' => 'add-new-button-blue.gif',
            'actionImageHover' => 'add-new-button-blue-hover.gif',
            'actionUrl' => $actionurl,
            'search' => array('searchArray' => $searchArray,
                'searchBy' => $this->searchby,
                'searchText' => $this->searchtxtjs,
                '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,
            ),
            'cattypecombo' => $selecttopcat
        );
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    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 get_fk_pages_modules_positions($eid) {
        $sql = "SELECT fk_pages_modules_positions from " . DB_PREFIX . "special WHERE int_glcode = $eid";
        $rs = $this->configObj->glDbObj->get_sql_row($sql);
        $fk_pages_modules_positions = $rs['fk_pages_modules_positions'];
        return $fk_pages_modules_positions;
    }

    function is_specialused() {
        $deleteids = $_REQUEST['dids'];
        $deletearray = explode(',', $deleteids);
        $totaldeletedrecords = count($deletearray);
        $is_assigned = 0;
        $delcount = 0;
        for ($i = 0; $i < $totaldeletedrecords; $i++) {
            $sql = "Update " . DB_PREFIX . "special 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++;

            $this->configObj->glLibraryObj->insertinlogmanager('83', DB_PREFIX . 'special', 'var_title', $deletearray[$i], 'D');
        }
        $this->load_special();
    }

    function loadCount() {
        $this->numofrows = $this->countFunction;
        $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 load_special() {
        if ($_REQUEST['task'] == 'orderupdate') {
            $updateids = $_REQUEST['uids'];
            $updatevalues = $_REQUEST['uvals'];
            $updateoldvalues = $_REQUEST['uoldvals'];
            $upidsarray = explode(',', $updateids);
            $upvalsarray = explode(',', $updatevalues);
            $upoldvalsarray = explode(',', $updateoldvalues);
            $this->update_display_order($upidsarray, $upvalsarray, $upoldvalsarray, 'special');
            $tablename = "" . DB_PREFIX . 'special';
            $this->configObj->glLibraryObj->set_display_order_sequence($tablename);
        }
        $this->pagename = 'index.php?module=special'; // Attribute of Page Name
        $this->countFunction = $this->CountRows();
        $this->loadCount();
        $this->configObj->glTplObj->set('numofrows', $this->numofrows);
        $result = $this->selectall_special();
        $this->configObj->glTplObj->set('result', $result);


        $view = 'Manage Promotions';

        if ($_REQUEST['specialcategory'] != '') {
            $cat = "&specialcategory=" . $_REQUEST['specialcategory'];
        }
        $actionurl = 'index.php?module=special&action=add' . $cat;
        $searchArray = array("var_title" => "Title");

        $table = DB_PREFIX . 'special';
        $parmas = $this->org_generateParam($view, $actionurl, $searchArray, $table);

        $this->configObj->glTplObj->set('headerpanel', $this->configObj->glLibraryObj->generateHeaderPanel($parmas, 'yes'));
        $this->configObj->glTplObj->set('pagingTop', $this->configObj->glLibraryObj->generatePagingPannel($parmas));
        $this->configObj->glTplObj->set('pagingBottom', $this->configObj->glLibraryObj->generatePagingPannel($this->org_generateParam($view, $actionurl, $searchArray, $table, 'bottom')));

        // Set the sorting image
        $tmpsetsortvar = 'setsortimg' . $this->orderby;
        $$finalsortvar = $tmpsetsortvar;

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

        // End of Set the sorting image

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

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

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

}

?>