<?php

defined('_VALID') or die('Restricted access');

include_once('class.videogallery.php');
$videoObj = new videogallery($configObj);
$action = $_REQUEST['action'];
$view = $_REQUEST['view'];
//echo $action;exit;
$videoObj->intitialize($view);

$configObj->glTplObj->change_path($configObj->currentModulePath . 'html/templates/');
$configObj->glTplObj->set('configObj', $configObj);
$configObj->glTplObj->set('videoObj', $videoObj);
$configObj->glTplObj->set('videoTab', true);

switch ($action) {
    case 'add':
        $videoObj->varpostdata = $_REQUEST;

        if ($_REQUEST['h_save'] == 'T') {

//            if ($videoObj->checkvalidurl($videoObj->varpostdata['var_youtubeurl'])) {
//                echo "invalid";
            if ($videoObj->checksameurl($videoObj->varpostdata['var_youtubeurl'])) {
//                echo "url_exist";
                header("Location: https://www.eclipze.ky/powerpanel/index.php?module=videogallery"); 
            } else {
                if ($videoObj->insert_video()) {
//                    echo "success";
                    header("Location: https://www.eclipze.ky/powerpanel/index.php?module=videogallery"); 
                }
            }
        }

        exit;
        break;

    case 'primary':


        $videoObj->varpostdata = $_REQUEST;
        $videoID = $videoObj->varpostdata['videoID'];
        if ($videoObj->set_primary($videoID)) {
            echo "1";
        } else {
            echo "0";
        }
        exit;
        break;

    case 'set_photo_displayorder':

        $videoObj->varpostdata = $_REQUEST;

        $photointglcode = $videoObj->varpostdata['photointglcode'];

        if ($videoObj->set_photo_displayorder($photointglcode)) {
            echo "1";
        } else {
            echo "0";
        }
        exit;
        break;

    case 'set_publish':

        $videoObj->varpostdata = $_REQUEST;
        $videoID = $videoObj->varpostdata['videoID'];
        $publish = $videoObj->varpostdata['publish'];

        if ($videoObj->set_publish($videoID, $publish)) {
            echo "1";
        } else {
            echo "0";
        }
        exit;
        break;

    case 'sharedata':
//        ob_clean();
//        echo "Sdad";exit;
        if ($_REQUEST['h_save'] == 'T') {
          
            $videoObj->varpostdata = $_REQUEST;
            echo $videoObj->shareonfacebook();
        } else {
            echo $videoObj->genrateshareOption();
        }
        exit;
        break;

    case 'delvideo':
        $videoObj->varpostdata = $_REQUEST;
        $videoID = $_REQUEST['videoID'];

        $videoObj->delete_video($videoID);

        echo "1";
        exit;
        break;

    case 'savealbumcaption':

        $videoObj->varpostdata = $_REQUEST;
        $videoID = $videoObj->varpostdata['videoID'];

        $photocaption = urldecode($videoObj->varpostdata['photocaption']);

        if ($videoObj->saveVideoTitle($videoID, $photocaption)) {
            echo "1";
        } else {
            echo "0";
        }
        exit;
        break;


    case 'videopopup':
        if (isset($_REQUEST['videoid'])) {
            echo $videoObj->video_display($_REQUEST['videoid']);
            exit();
        }

        break;

    case 'video_grid':

        $configObj->glTplObj->set('videoArry', $videoObj->load_videogallery());
        echo $configObj->glTplObj->process('video_listing.tpl.php');
        exit;
        break;

    default:

        $videoArry = $videoObj->load_videogallery();

        $configObj->glTplObj->set('videoArry', $videoArry);
        $configObj->glTplObj->set('frmaction', "index.php?module=videogallery&action=add");
        $configObj->glTplObj->set('BottomSubmitButtons', $configObj->glLibraryObj->GetSubmitButtons($cancelurl, 'bottom', '', '', $btnsaveandc));

        $configObj->adminContentPanel = $configObj->glTplObj->process('videogallery.tpl.php');

        break;
}
?>
