<?php

class videogallery {

    var $pagename = 'index.php?module=photogallery'; // Attribute of Page Name
    var $int_glcode;   // KEY ATTR. WITH AUTOINCREMENT
    var $chr_read;
    var $chr_star;
    var $chr_publish;
    var $int_displayorder;   // (normal Attribute)
    var $chr_delete = 'Y';   // (normal Attribute)
    var $dt_createdate;   // (normal Attribute)
    var $dt_modifydate;   // (normal Attribute)
    var $oldint_displayorder; // Attribute of Old Displayorder
    var $numofrows; // Attribute of Num Of Rows In Result
    var $numofpages; // Attribute of Num Of Pages In Result
    /////var $orderby = 'intdisplayorder' ; // Attribute of Deafult Order By
    var $orderby = 'int_displayorder'; //'dt_startdate'; // Attribute of Deafult Order By
    var $ordertype = 'asc'; // Attribute of Deafult Order By
    var $searchby = '0'; // Attribute of Search By
    var $searchtxt; // Attribute of Search Text
    var $start = 1; // Attribute of Start For Paging
    var $pagesize = DEFAULT_PAGESIZE; // Attribute of Pagesize For Paging
    var $pagenumber = '1'; // Attribute of Page Number For Paging
    var $lastinsertid; // Attribute of Last Inserid
    var $urlwithpara = ''; // Attribute of URL With parameters
    var $urlwithpoutsearch = ''; // Attribute of URL With parameters without searh
    var $urlwithoutsort = ''; // Attribute of URL With parameters without sort
    var $urlwithoutpaging = ''; // Attribute of URL With parameters without paging
    var $configObj;
    // var $sortvar = '<img alt="sorting" src="'.GLOBAL_ADMIN_IMAGES_PATH.'/arrow-up.png" style="vertical-align:middle;">'; // This is for sort image
    var $filterby = '0';
    var $urlwithoutfilter = '';
    var $display_limit_array = array(5, 10, 15, 30);
    var $varpostdata = array();
    var $thumb_width = TRADESHOW_THUMB_WIDTH;
    var $thumb_height = TRADESHOW_THUMB_HEIGHT;

    function videogallery($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;
        $_REQUEST['searchtxt'] = ($_REQUEST['type'] == 'autosearch') ? $_REQUEST['term'] : $_REQUEST['searchtxt'];
        $this->searchbyVal = (isset($_REQUEST['searchbyVal'])) ? $_REQUEST['searchbyVal'] : $this->searchbyVal;
        $this->searchtxt = (isset($_REQUEST['searchtxt'])) ? $this->configObj->glLibraryObj->rem_special_chars($_REQUEST['searchtxt']) : '';
        $this->searchtxtjs = (isset($_REQUEST['searchtxt'])) ? $this->configObj->glLibraryObj->rem_special_chars_js($_REQUEST['searchtxt']) : '';

        $this->orderby = (isset($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : $this->orderby;
        $this->ordertype = (isset($_REQUEST['ordertype'])) ? $_REQUEST['ordertype'] : $this->ordertype;
        $this->filterby = (isset($_REQUEST['filterby'])) ? $_REQUEST['filterby'] : $this->filterby;

        if (isset($_REQUEST['sorting'])) {
            if ($this->ordertype == "asc") {   // This is for sort image
                $this->ordertype = "desc";

                $this->sortvar = "<img alt=\"sorting\" src=\"" . GLOBAL_ADMIN_IMAGES_PATH . "arrow-down.png\" style=\"vertical-align:middle;\">";
            } else if ($this->ordertype == "desc") {   // This is for sort image
                $this->ordertype = "asc";
                $this->sortvar = "<img alt=\"sorting\" src=\"" . GLOBAL_ADMIN_IMAGES_PATH . "arrow-up.png\" style=\"vertical-align:middle;\">";
            }
        }


        $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 load_videogallery() {
        $videoArry = array();

        $sql = "select * from  " . DB_PREFIX . "videogallery where chr_delete='N' order by int_displayorder";

        $rs = $this->configObj->glDbObj->query($sql);
        while ($row = $this->configObj->glDbObj->fetch_assoc($rs)) {
            $videoArry[] = $row;
        }

        return $videoArry;
    }

    //End Facebook and twitter share Code

    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);
                //  print_r($param);
                //  exit;
                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['data']["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'])) {
                    foreach ($this->varpostdata['tw'] as $value) {
                        $pageDetail = $this->gettwpagedetail($value);
                        // print_r($pageDetail);
                        //exit;
                        $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'];
                        $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" . $param['data']['link'];
                        if ($this->configObj->glLibraryObj->shareOnTwitter_news($param) == 1) {
                            $status = 1;
                            $this->addfbsharelog($pageDetail, $param, "T");
                        }
                    }
                }
            }
        }
        //print_r($_REQUEST);
        return $status;
    }

    function get_Post_data($id) {
        $sql = "SELECT int_glcode,var_title,var_youtubeurl,var_image FROM " . DB_PREFIX . "videogallery WHERE chr_delete='N' AND int_glcode='" . $id . "'";

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

        $imagename = $result['var_image'];
        $corePath = "upimages/videogallery/images/";
        $imagepath = '../' . $corePath;
        $imagename = $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;
        }

        preg_match("/v=([^&]+)/i", $result['var_youtubeurl'], $matches);

        $youtube_videoid = $matches[1];

        $paramArr['int_glcode'] = $id;
       
        $paramArr['data']['name'] = $this->varpostdata['var_video_title'];
        $paramArr['data']['caption'] = SITE_NAME;
	$paramArr["data"]["actions"] = array("name" => "Sent from Netclues PowerPanel", "link" => "http://www.netclues.ky");
	
        $paramArr['data']['link'] = "http://www.youtube.com/watch?v=" . $youtube_videoid;
        $paramArr['data']['source'] = "http://www.youtube.com/e/" . $youtube_videoid;
        $paramArr['data']['picture'] = "http://img.youtube.com/vi/" . $youtube_videoid . "/default.jpg";

        

        if ($this->varpostdata['var_video_description'] != '') {
            $paramArr['data']['description'] = $this->varpostdata['var_video_description'];
        }

        return $paramArr;
    }

    //End Facebook and twitter share Code


    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 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 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=78  order by dt_createdate desc limit 0,1";
        $rec = $this->configObj->glDbObj->query($sql);
        return $rec;
    }

    function getvideocustomdata() {
        $sql = "SELECT var_title,var_description FROM " . DB_PREFIX . "videogallery 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('videodata', $this->getvideocustomdata());
        return $this->configObj->glTplObj->process('shareoption.tpl.php');
    }

    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" => "78"
        );

        $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() . "','" . $this->varpostdata['var_video_title'] . "','" . $this->varpostdata['var_video_description'] . "','" . $_SERVER['REMOTE_ADDR'] . "','" . ADMIN_NAME . "')";
        $this->configObj->glDbObj->query($sql);
    }

    function checkvalidurl($url) {
        preg_match("/v=([^&]+)/i", $url, $matches);
        $id = $matches[1];
        if ($id == '') {
            return '1';
        } else {
            $headers = get_headers('http://gdata.youtube.com/feeds/api/videos/' . $id);
            if (!strpos($headers[0], '200')) {
                return '1';
            }
            $myFile = "http://gdata.youtube.com/feeds/api/videos/" . $id;
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $myFile);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $content = curl_exec($ch);
            curl_close($ch);
            if ($content == 'Invalid id') {
                return '1';
            } else {
                return '0';
            }
        }
    }

    function insert_video() {
        
        $sess = time();
        $this->thumbname = $this->getYoutubeThumb($this->varpostdata['var_youtubeurl'], $this->varpostdata['var_title'] . $sess, '../upimages/videogallery/images', '300', '200', '100');
       
        if (isset($_REQUEST['select4'])) {
            $tags = $this->configObj->glLibraryObj->getTagName($this->varpostdata['select4']);
            $tag_id = $this->configObj->glLibraryObj->saveTag($tags);
        }
        if (!empty($this->varpostdata['select4']) && isset($this->varpostdata['select4'])) {
            $this->tag = implode(",", $tag_id);
        } else {
            $this->tag = "";
        }

        $this->updatedisplay_order_video();

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

        // Set the Columns
        $this->configObj->glDbObj->addColumn('var_title');
        $this->configObj->glDbObj->addColumn('var_image');
        $this->configObj->glDbObj->addColumn('var_description');
        $this->configObj->glDbObj->addColumn('var_youtubeurl');
        $this->configObj->glDbObj->addColumn('chr_delete');
        $this->configObj->glDbObj->addColumn('chr_publish');
        $this->configObj->glDbObj->addColumn('dt_createdate');
        $this->configObj->glDbObj->addColumn('dt_modifydate');
        $this->configObj->glDbObj->addColumn('int_displayorder');

        $this->configObj->glDbObj->addValue(htmlspecialchars($this->varpostdata['var_title'], ENT_QUOTES));
        $this->configObj->glDbObj->addValue($this->thumbname);
        $this->configObj->glDbObj->addValue($this->varpostdata['var_description']);
        $this->configObj->glDbObj->addValue(htmlspecialchars($this->varpostdata['var_youtubeurl'], ENT_QUOTES));
        $this->configObj->glDbObj->addValue('N');
        $this->configObj->glDbObj->addValue('Y');
        $this->configObj->glDbObj->addValue('NOW()');
        $this->configObj->glDbObj->addValue('NOW()');
        $this->configObj->glDbObj->addValue($this->varpostdata['int_displayorder']);
//        echo $this->configObj->glDbObj->buildQuery();exit;
        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        $this->lastinsertid = mysql_insert_id();

        $resultarray['display_field']['Title'] = 'var_title';
        $resultarray['display_detail']['var_title'] = 'Title';
        $resultarray['display_detail']['var_youtubeurl'] = 'Video Link';

        $resultarray['display_detail']['int_displayorder'] = 'Display Order';
        $resultarray['display_detail']['chr_publish'] = 'Display';

        $array['history_id'] = time();
        $array['user_id'] = $_SESSION[DB_PREFIX . 'admin_id'];
        $array['action'] = 'I';
        $array['chr_read'] = 'N';
        $array['actiondate'] = date("Y/m/d H:i:s", time());
        $array['int_glcode'] = trim($this->lastinsertid);
        $array['var_title'] = $this->configObj->glDbObj->addSlashes($this->varpostdata['var_title']);
        $array['var_youtubeurl'] = $this->configObj->glDbObj->addSlashes($this->varpostdata['var_youtubeurl']);

        $array['int_displayorder'] = $this->configObj->glDbObj->addSlashes($this->varpostdata['int_displayorder']);
        if ($this->varpostdata['chr_publish'] == 'Y') {
            $fpublish = 'Yes';
        } else {
            $fpublish = 'No';
        }
        $array['chr_publish'] = $fpublish;
        $resultarray['records'][] = $array;
        $this->configObj->glLibraryObj->insertinlogmanager('78', DB_PREFIX . 'videogallery', 'var_title', $this->lastinsertid, 'I');
        return true;
    }

    function updatedisplay_order_video() {

        $this->varpostdata = $_REQUEST;
        $this->configObj->glDbObj->resetfields();
        $this->configObj->glDbObj->setQueryType('update');
        $this->configObj->glDbObj->setTable(DB_PREFIX . 'videogallery');

        $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 getYoutubeThumb($url, $dst_img, $dst_path, $dst_w, $dst_h, $dst_quality) {
//        $img_name = $dst_img;
//        $src_embed = $this->get_youtubevideo($url, $dst_w, $dst_h);
//        preg_match('~http://[^/]+/v/([^&/]+)~', $src_embed, $match);
//        $youtube_id = $match[1];
//        $YouTubeThumbURL = 'http://img.youtube.com/vi/';
//        $src_cpl = $YouTubeThumbURL . $youtube_id . '/0.jpg';
//        $dst_cpl = $dst_path . "/" . basename($dst_img);
//        echo $src_cpl;exit;
//        try {
//            if (!$src_cpl) {
//                throw new Exception("No such file or directory");
//            } else {
//                list($src_w, $src_h) = getimagesize($src_cpl);
//                $src_img = imagecreatefromjpeg($src_cpl);
//                // throw new TestException();
//            }
//        } catch (Exception $e) {
//            echo 'Message: ' . $e->getMessage();
//        }
//        //Get heights and width so the image keeps its ratio.
//        $x_ratio = $dst_w / $src_w;
//        $y_ratio = $dst_h / $src_h;
//
//        if ((($x_ratio > 1) || ($y_ratio > 1)) && ($x_ratio > $y_ratio)) {
//            //If one of the sizes of the image is smaller than the destination (normal: more height than width).
//            $dst_w = ceil($y_ratio * $src_w);
//            $dst_h = $dst_h;
//        } elseif ((($x_ratio > 1) || ($y_ratio > 1)) && ($y_ratio > $x_ratio)) {
//            //If one of the sizes of the image is smaller than the destination (landscape: more width than height).
//            $dst_w = $dst_w;
//            $dst_h = ceil($x_ratio * $src_h);
//        } elseif (($x_ratio * $src_h) < $dst_h) {
//            //if the image is landscape (more width than height).
//            $dst_h = ceil($x_ratio * $src_h);
//            $dst_w = $dst_w;
//        } elseif (($x_ratio * $src_h) > $dst_h) {
//            //if the image is normal (more height than width).
//            $dst_h = ceil($x_ratio * $src_h);
//            $dst_w = $dst_w;
//        } else {
//            //if the image is normal (more height than width).
//            $dst_w = ceil($y_ratio * $src_w);
//            $dst_h = $dst_h;
//        }
//        // Creating the resized image.
//        $dst_img = imagecreatetruecolor($dst_w, $dst_h);
//        imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
//        // Saving the resized image.
//
//
//        imagejpeg($dst_img, $dst_cpl, $dst_quality);
//        // Cleaning the memory.
//        imagedestroy($src_img);
//        imagedestroy($dst_img);
//        return $img_name;
//    }

     function getYoutubeThumb($url, $dst_img, $dst_path, $dst_w, $dst_h, $dst_quality) {
         
         header ("Content-type: image/jpeg");   
        $img_name = $dst_img;
        $src_embed = $this->get_youtubevideo($url, $dst_w, $dst_h);
        preg_match('~http://[^/]+/v/([^&/]+)~', $src_embed, $match);
        $youtube_id = $match[1];
        $YouTubeThumbURL = 'http://img.youtube.com/vi/';
         $src_cpl = $YouTubeThumbURL . $youtube_id . '/0.jpg';
        $dst_cpl = $dst_path . "/" . basename($dst_img);
        try {
            if (!$src_cpl) {
                throw new Exception("No such file or directory");
            } else { 
                list($src_w, $src_h) = getimagesize($src_cpl);
                $src_img = imagecreatefromjpeg($src_cpl); 
//                header('Content-Type: image/jpeg');
                // throw new TestException();
            }
        } catch (Exception $e) {
            echo 'Message: ' . $e->getMessage();
        }
        
        
        
        $old_x=imageSX($src_img);
    $old_y=imageSY($src_img);

    if ($old_x > $old_y) {
        $thumb_w=$dst_h;
        $thumb_h=$old_y*($dst_h/$old_x);
    }
    if ($old_x < $old_y) {
        $thumb_w=$old_x*($dst_w/$old_y);
        $thumb_h=$dst_h;
    }
    if ($old_x == $old_y) {
        $thumb_w=$dst_w;
        $thumb_h=$dst_h;
    }

    
        //Get heights and width so the image keeps its ratio.
             
        // Creating the resized image.
        $dst_img = imagecreatetruecolor($thumb_w*2,$thumb_h*2);
        
        imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w*2,$thumb_h*2,$old_x,$old_y);
        // Saving the resized image.
        header("Content-type: image/jpeg", true, 200);
        ob_start();
        imagejpeg($dst_img, $dst_cpl, 100);
        // Cleaning the memory.
        imagedestroy($src_img);
        imagedestroy($dst_img);
        return $img_name;
    }

    function get_youtubevideo($url, $height, $width) {
        preg_match("/v=([^&]+)/i", $url, $matches);

        $id = $matches[1];
        $YouTubeVideoURL = 'http://www.youtube.com/v/';
        $code = '<object width="' . $width . '" height="' . $height . '">';
        $code .= '<param name="movie" value="' . $YouTubeVideoURL . '{id}&hl=en_US&fs=1&" ></param>';
        $code .='<param name="allowFullScreen" value="true" ></param>';
        $code .='<param name="allowscriptaccess" value="always"></param>';
        $code .='<embed src="' . $YouTubeVideoURL . '{id}&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' . $width . '" height="' . $height . '">';
        $code .='</embed></object>';
        $code = str_replace('{id}', $id, $code);
        return $code;
    }

    function set_photo_displayorder($photointglcode) {

        if (!empty($photointglcode)) {

            $intglcodeArry = explode(",", $photointglcode);
            $i = 1;
            foreach ($intglcodeArry as $glcode) {

                $this->configObj->glDbObj->resetfields();
                $this->configObj->glDbObj->setQueryType('update');
                $tablename = DB_PREFIX . 'videogallery';
                $this->configObj->glDbObj->setTable($tablename);
                $this->configObj->glDbObj->addColumn('int_displayorder');
                $this->configObj->glDbObj->addColumn('dt_modifydate');


                $this->configObj->glDbObj->addvalue($i);
                $this->configObj->glDbObj->addValue('NOW()');
                $this->configObj->glDbObj->setWhere('int_glcode =' . $glcode);
                $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());

                $i++;
            }

            return true;
        }
    }

    function set_primary($videoID) {

        $this->configObj->glDbObj->resetfields();
        $this->configObj->glDbObj->setQueryType('update');
        $tablename = DB_PREFIX . 'videogallery';
        $this->configObj->glDbObj->setTable($tablename);
        $this->configObj->glDbObj->addColumn('var_primary');
        $this->configObj->glDbObj->addColumn('dt_modifydate');
        $this->configObj->glDbObj->addvalue('Y');
        $this->configObj->glDbObj->addValue('NOW()');
        $this->configObj->glDbObj->setWhere('int_glcode=' . $videoID);

        if ($this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery())) {
            $this->configObj->glDbObj->resetfields();
            $this->configObj->glDbObj->setQueryType('update');
            $tablename = DB_PREFIX . 'videogallery';
            $this->configObj->glDbObj->setTable($tablename);
            $this->configObj->glDbObj->addColumn('var_primary');
            $this->configObj->glDbObj->addColumn('dt_modifydate');
            $this->configObj->glDbObj->addvalue('N');
            $this->configObj->glDbObj->addValue('NOW()');
            $this->configObj->glDbObj->setWhere('int_glcode !=' . $videoID);
//            $this->configObj->glDbObj->buildQuery();
            $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());
        } else {
            return false;
        }
        return true;
    }

    function set_publish($videoID, $publish) {

        if ($publish == 'N') {
            $publish = 'Y';
        } else {
            $publish = 'N';
        }

        $this->configObj->glDbObj->resetfields();
        $this->configObj->glDbObj->setQueryType('update');
        $tablename = DB_PREFIX . 'videogallery';
        $this->configObj->glDbObj->setTable($tablename);
        $this->configObj->glDbObj->addColumn('chr_publish');
        $this->configObj->glDbObj->addColumn('dt_modifydate');


        $this->configObj->glDbObj->addvalue($publish);
        $this->configObj->glDbObj->addValue('NOW()');
        $this->configObj->glDbObj->setWhere('int_glcode =' . $videoID);
        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());

        return true;
    }

    function delete_video($videoID) {

        $sql = "SELECT var_image FROM " . DB_PREFIX . "videogallery WHERE int_glcode ='" . $videoID . "'";
        $rs = $this->configObj->glDbObj->query($sql);
        $row = $this->configObj->glDbObj->fetch_assoc($rs);

        if (!empty($row)) {

            $sql = "update " . DB_PREFIX . "videogallery set var_ipaddress='" . $_SERVER['REMOTE_ADDR'] . "',var_adminuser='" . ADMIN_NAME . "',chr_delete='Y' WHERE int_glcode ='" . $videoID . "'";
            $rs = $this->configObj->glDbObj->query($sql);
        }
        $this->configObj->glLibraryObj->insertinlogmanager('78', DB_PREFIX . 'videogallery', 'var_title', $videoID, 'D');

        return $rs;
    }

    function saveVideoTitle($videoID, $photocaption) {

        $this->configObj->glDbObj->resetfields();
        $this->configObj->glDbObj->setQueryType('update');
        $tablename = DB_PREFIX . 'videogallery';
        $this->configObj->glDbObj->setTable($tablename);
        $this->configObj->glDbObj->addColumn('var_title');
        $this->configObj->glDbObj->addColumn('dt_modifydate');


        $this->configObj->glDbObj->addvalue($photocaption);
        $this->configObj->glDbObj->addValue('NOW()');
        $this->configObj->glDbObj->setWhere('int_glcode =' . $videoID);
        $this->configObj->glDbObj->query($this->configObj->glDbObj->buildQuery());

        return true;
    }

    function get_video($videoID) {
        $videoArry = array();

        $sql = "select * from  " . DB_PREFIX . "videogallery where int_glcode = '" . $videoID . "' and chr_delete='N'";

        $rs = $this->configObj->glDbObj->query($sql);
        $row = $this->configObj->glDbObj->fetch_assoc($rs);
        $videoArry = $row;


        return $videoArry;
    }

    function video_display($id) {
        $video_data = $this->get_video($id);

        $youtube_url = $video_data['var_youtubeurl'];
        $embdcode = $this->get_youtubevideo($youtube_url, '400', '600');

        echo $embdcode;
    }

    function checksameurl($url) {

        $sql = "select count(1) as total from " . DB_PREFIX . "videogallery where var_youtubeurl='" . $url . "' and chr_delete='N'";
        $rs = $this->configObj->glDbObj->get_sql_row($sql);
        return $rs['total'];
    }

}

?>
