HEX
Server: Apache
System: Linux 162-240-236-42.bluehost.com 3.10.0-1160.114.2.el7.x86_64 #1 SMP Wed Mar 20 15:54:52 UTC 2024 x86_64
User: bt667 (1004)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /home/bt667/www/wp-content/plugins/wp_mvplayer/admin/class-admin-wpmvp.php
<?php
/**
 * The admin-specific functionality of the plugin.
 *
 * Defines the plugin name, version, and two examples hooks for how to
 * enqueue the admin-specific stylesheet and JavaScript.
 *
 * @package    WPMVP
 * @subpackage WPMVP/admin
 * @author     Rohit Sharma
 */

class WPMVP_Admin {
    private $plugin_name,$version,$helper;
    public function __construct( $WPMVP, $version ) {
        $this->plugin_name = $WPMVP;
        $this->version = $version;
        $this->helper = new MVP_Importer_Helper();
        add_action( 'admin_enqueue_scripts',array($this,  'mvp_admin_scripts' ));
        add_action( 'wp_enqueue_scripts',array($this,  'mvp_frontend_scripts' ));
        add_action( 'wp_ajax_admin_listing_tabs_ajax', array( $this,'mvp_listing_tabs_admin_ajax_handler' ));
        add_action( 'wp_ajax_nopriv_admin_listing_tabs_ajax', array( $this,'mvp_listing_tabs_admin_ajax_handler' ));       
        add_action( 'wp_ajax_admin_playlist_tabs_ajax', array( $this,'mvp_listing_playlist_tabs_admin_ajax_handler' ));
        add_action( 'wp_ajax_nopriv_admin_playlist_tabs_ajax', array( $this,'mvp_listing_playlist_tabs_admin_ajax_handler' ));
        add_action( 'wp_ajax_nopriv_delete_images_listing',  array( $this,'delete_images_listing_ajax_handler' ));   

        add_action( 'wp_ajax_delete_images_listing',  array( $this,'delete_images_listing_ajax_handler' ));

        add_action( 'wp_ajax_nopriv_delete_playlist_images_listing',  array( $this,'delete_playlist_images_listing_ajax_handler' ));       

        add_action( 'wp_ajax_delete_playlist_images_listing',  array( $this,'delete_playlist_images_listing_ajax_handler' ));

        add_action( 'wp_ajax_nopriv_SoftwareLicenseManagerChecked', array( $this,'SoftwareLicenseManagerCheckedhandler' ));

        add_action( 'wp_ajax_SoftwareLicenseManagerChecked',  array( $this,'SoftwareLicenseManagerCheckedhandler' ));

    }

    public function SoftwareLicenseManagerCheckedhandler(){

        $license_data_options = $this->helper->mvp_license_status($_POST['license_key']);

        if(isset($license_data_options)){
            $date_expiry = strtotime($license_data_options->date_expiry);
            $today = strtotime(date("Y-m-d"));

            if($license_data_options->result=='success'){
                $option_name = 'mvp_player_license_option';
                // Expiry code

                if($license_data_options->date_expiry == "lifetime"){
                    $msg = 1;
                    $license_data = array(
                        'status'=>__('Active','mvp'),
                        'license_key'=>$_POST['license_key']
                    );
                }else{
                    if($today > $date_expiry){
                        $msg = 0;                        
                        $license_data = array(                            
                            'status'=>__('Your License have been expiry. <br/> Kindly, renew your License then try again','mvp'),                            
                            'license_key'=>$_POST['license_key']
                        );
                    }else{
                        $msg = 1;
                        $license_data = array(
                            'status'=> __('Active','mvp'),
                            'license_key'=>$_POST['license_key']
                        );
                    }
                }
            }else{
                $msg =0;
                $license_data = array(
                    'status'=> __('Please provide correct License','mvp'),
                    'license_key'=>$_POST['license_key']
                );

            }

        }else{

            $msg =0;
            $license_data = array(
                'status'=>__('Please provide correct License','mvp'),
                'license_key'=>$_POST['license_key']
            );
        }

        if ( get_option( $option_name ) !== false ) {
            update_option( $option_name, $license_data );
        }else{
            $deprecated = null;
            $autoload = 'no';
            add_option( $option_name, $license_data, $deprecated, $autoload );
        }

        $response   =   array(
            'data' => $license_data['license_key'],
            'success' => $msg,
            'message' => $license_data['status']
        );

        echo json_encode( $response ); exit;
    }

    public function delete_playlist_images_listing_ajax_handler(){
        global $wpdb;
        $playlist_table = $wpdb->prefix . "playlist_video";
        $id =$_POST['v_id'];

        if(isset($id) && !empty($id)){
            $wpdb->query($wpdb->prepare("UPDATE $playlist_table SET ImageLogo='' WHERE id=%d",$id));
        }
    }

    public function delete_images_listing_ajax_handler(){
        global $wpdb;
        $video_table = $wpdb->prefix . "mvplayer_video";
        $id =$_POST['v_id'];

        if(isset($id) && !empty($id)){
            $wpdb->query($wpdb->prepare("UPDATE $video_table SET ImageLogo='' WHERE id=%d",$id));
        }
    }

    public function mvp_admin_scripts(){
		// Setting Script
        $scripts_ver = '4.69';
		wp_enqueue_script( 'mvp-admin-sweet-alert-js','https://cdn.jsdelivr.net/npm/sweetalert2@10/dist/sweetalert2.min.js');
        wp_enqueue_style( 'mvp-admin-sweet-alert-css', 'https://cdn.jsdelivr.net/npm/sweetalert2@10/dist/sweetalert2.min.css');
        wp_enqueue_style( 'mvp-admin-custom-css', MV_PLAYER_URL.'css/mvp_admin.css?time'.time(), array(),$scripts_ver , false);
        wp_enqueue_script( 'mvp-admin-tiny-mce-script', get_stylesheet_directory_uri() . '/custom_script.js', array( 'jquery', 'tiny_mce' ) );
        wp_enqueue_style(MV_PLAYER_SLUG."admin-font-awesome-css",MV_PLAYER_URL."font-awesome/css/font-awesome.min.css");
        wp_enqueue_script( 'mvp-admin-custom-js', MV_PLAYER_URL.'js/admin_backend.js?time='.time(), array(), $scripts_ver, false);
        $mvp_admin_custom_array =  array(
                                        'ajaxurl' => admin_url('admin-ajax.php'),                                        
                                        'license_key' => __( 'Please fill License key', 'mvp'),
                                        'already_activated' => __( 'Already Activated!', 'mvp'),                                        
                                        'license_activated_till' => __( 'License Activated Till', 'mvp'),                                                                                
                                        'please_wait' => __( 'Please Wait', 'mvp'  ),
                                        'config_auto' => __( 'Config Autoresponder List', 'mvp'  ),
                                        'no_listing' => __( 'No Listing Found', 'mvp'  ),
                                        'no_listing_exists' => __( 'No Listing exists for this string. Please search again!', 'mvp'  ),                                                                                
                                        'video_settings_saved' => __( 'Video Settings have been saved successfully!', 'mvp'  ),    
                                        'auto_settings_saved' => __( 'Autoresponder Settings have been saved successfully!', 'mvp'  ),    
                                        'opt_settings_saved' => __( 'Opt-In Settings have been saved successfully!', 'mvp'  ),               
                                        'button_settings_saved' => __( 'Buttons Settings have been saved successfully!', 'mvp'  ),  
                                        'skins_settings_saved' => __( 'Skins Settings have been saved successfully!', 'mvp'  ), 
                                        'affiliate_settings_saved' => __( 'Affiliate Marketing Settings have been saved successfully!', 'mvp'  ),   
                                        'add_social_lock' => __( 'Please enter seconds if you want to add social lock in between the video', 'mvp'  ),                                           
                                        'add_optin_popup' => __( 'Please enter seconds if you want to add optin popup in between the video', 'mvp'  ),                                                                                   
                                        'add_content_revealer' => __( 'Please enter seconds if you want to add content revealer in between the video', 'mvp'  ),  
                                        'add_call_action' => __( "Please enter seconds if you want to add call to action button in between the video", 'mvp'  ),                                          
                                        'add_affiliate_marketing' => __( "Please enter seconds if you want to add affiliate marketing popup in between the video", 'mvp'  ),                                                                                 
                                    );

		wp_localize_script( 'mvp-admin-custom-js', 'mvp_admin_custom_ajax_object', $mvp_admin_custom_array);
    }

    public function mvp_frontend_scripts(){
		// Setting Script
        $scripts_ver = '4.69';
		wp_enqueue_style( 'mvp-frontend-custom-css', MV_PLAYER_URL.'css/mvp_admin.css?time'.time(), array(),$scripts_ver , false);
        wp_enqueue_script( 'mvp-frontend-custom-alert-js',MV_PLAYER_URL.'js/custom_frontend.js', array('jquery'), $scripts_ver, false);    
        wp_enqueue_script( 'mvp-frontend-tiny-mce-script', get_stylesheet_directory_uri() . '/custom_script.js', array( 'jquery', 'tiny_mce' ) );
    }
    
    public function mvp_listing_tabs_admin_ajax_handler(){
        global $wpdb;
        $playlist_videobuttons_table = $wpdb->prefix . "playlist_videobuttons";
        $video_table = $wpdb->prefix . "mvplayer_video";
        $videobuttons_table = $wpdb->prefix . "mvplayer_videobuttons";
        $autoresponder = 1;      

        if(!empty($_POST['row_id'])){
            $status = 'update';
            $id = $_POST['row_id'];
            $data =  $wpdb->get_row("SELECT * FROM $video_table where id= $id");

            if($data){
                $v_id                       = $id;
                $current_id                 = $id;
                $v_Title                    = $data->Title;
                $v_Video                    = $data->Video;
                $v_VideoSource              = $data->VideoSource;
                $v_ImageLogo                = $data->ImageLogo;
                $v_VideoWidth               = $data->VideoWidth;
                $v_VideoHeight              = $data->VideoHeight;
                $v_AutoPlay                 = $data->AutoPlay;
                $v_AllowPause               = $data->AllowPause;
                $v_AllowScroll              = $data->AllowScroll;
                $v_VideoControls            = $data->VideoControls;
                $v_VideoAlign               = $data->VideoAlign;
                $v_ShowContentLoc           = $data->ShowContentLocation;
                $v_ShowContentDur           = $data->ShowContentDuration;
                $v_Content                  = $data->VideoContent;
                $v_SocialBtnLoc             = $data->SocialButtonLocation;
                $v_SocialLockDuration       = $data->SocialLockDuration;
                $v_SocialEnable             = $data->SocialEnable;
                $v_SocialTitle              = $data->SocialTitle;
                $v_SocialText               = $data->SocialText;
                $v_DefaultTweet             = $data->DefaultTweet;
                $v_HeadlineMsg              = $data->HeadlineMsg;
                $v_ShareUrl                 = $data->ShareUrl;
                $v_CustomUrl                = $data->CustomUrl;
                $v_OptinBox                 = $data->OptinBox;
                $v_OptinLocation            = $data->OptinLocation;
                $v_OptinMidTime             = $data->OptinMidTime;
                $v_OptinHeadline            = $data->OptinHeadline;
                $v_OptinText                = $data->OptinText;
                $v_OptinSubmitText          = $data->OptinSubmitText;
                $v_ThankyouMessage          = $data->ThankyouMessage;
                $v_OptinAllowSkip           = $data->OptinAllowSkip;
                $v_Popup                    = $data->Popup;
                $v_PopupContent             = $data->PopupContent;
                $v_PopupLink                = $data->PopupLink;
                $v_PopupLocation            = $data->PopupLocation;
                $v_PopupMidTime             = $data->PopupMidTime;
                $v_VideoMailingList         = $data->VideoMailingList;
                $custom_formcode            = $data->custom_formcode;
                $v_MailChimpApiKey          = $data->MailChimpApiKey;
                $v_MailChimpListId          = $data->MailChimpListId;
                $v_GetResponseApiKey        = $data->GetResponseApiKey;
                $v_GetResponseCampaignId    = $data->GetResponseCampaignId;
                $v_AWeberListID             = $data->AWeberListID;
                $v_AWeberAccessTokens       = $data->AWeberAccessTokens;
                $v_ConstCntctUserName       = $data->ConstCntctUserName;
                $v_ConstCntctAPIKey         = $data->ConstCntctAPIKey;
                $v_ConstCntctSecret         = $data->ConstCntctSecret;
                $v_ConstCntctListID         = $data->ConstCntctListID;
                $v_SendlaneApiKey           = $data->SendlaneApiKey;
                $v_SendlaneApiHashKey       = $data->SendlaneApiHashKey;
                $v_SendlaneApiUrl           = $data->SendlaneApiUrl;
                $v_SendlaneSubDomain        = $data->SendlaneSubDomain;
                $v_SendlaneListID           = $data->SendlaneListID;
                $v_PlayerSkin               = $data->PlayerSkin;
                $v_cta_enable               = $data->cta_enable;
                $v_ctabtn_dur               = $data->ctabtn_dur;
                $v_cta_bg_color             = $data->cta_bg_color;
                $v_cta_text_color           = $data->cta_text_color;
                $v_cta_btn_text             = $data->cta_btn_text;
                $v_cta_btn_border           = $data->cta_btn_border;
                $v_cta_btn_radius           = $data->cta_btn_radius;
                $v_cta_btn_border_color     = $data->cta_btn_border_color;
                $v_cta_btn_height           = $data->cta_btn_height;
                $v_cta_btn_width            = $data->cta_btn_width;
                $v_ctabtn_allow_skip        = $data->ctabtn_allow_skip;
                $v_cta_share_url            = $data->cta_share_url;
                $v_cta_custom_url           = $data->cta_custom_url;
            }else{
                $v_id                       = '';
                $v_Title                    = '';
                $v_Video                    = '';
                $v_VideoSource              = '';
                $v_ImageLogo                = '';
                $v_VideoWidth               = '';
                $v_VideoHeight              = '';
                $v_AutoPlay                 = '';
                $v_AllowPause               = '';
                $v_AllowScroll              = '';
                $v_VideoControls            = '';
                $v_VideoAlign               = '';
                $v_ShowRelatedVideos        = '';
                $v_AllRelatedVideos         = '';
                $v_ShowContentLoc           = '';
                $v_ShowContentDur           = '';
                $v_Content                  = '';
                $v_SocialBtnLoc             = '';
                $v_SocialLockDuration       = '';
                $v_SocialEnable             = '';
                $v_SocialTitle              = '';
                $v_SocialText               = '';
                $v_DefaultTweet             = '';
                $v_HeadlineMsg              = '';
                $v_OptinBox                 = '';
                $v_OptinLocation            = '';
                $v_OptinMidTime             = '';
                $v_OptinHeadline            = '';
                $v_OptinText                = '';
                $v_OptinSubmitText          = '';
                $v_ThankyouMessage          = '';
                $v_OptinAllowSkip           = '';
                $v_Popup                    = '';
                $v_PopupContent             = '';
                $v_PopupLink                = '';
                $v_PopupLocation            = '';
                $v_PopupMidTime             = '';
                $v_VideoMailingList         = '';
                $custom_formcode            = '';
                $v_MailChimpApiKey          = '';
                $v_MailChimpListId          = '';
                $v_GetResponseApiKey        = '';
                $v_GetResponseCampaignId    = '';
                $v_AWeberListID             = '';
                $v_AWeberAccessTokens       = '';
                $v_ConstCntctUserName       = '';
                $v_ConstCntctAPIKey         = '';
                $v_ConstCntctSecret         = '';
                $v_ConstCntctListID         = '';
                $v_SendlaneApiKey           = '';
                $v_SendlaneApiHashKey       = '';
                $v_SendlaneApiUrl           = '';
                $v_SendlaneSubDomain        = '';
                $v_SendlaneListID           = '';
                $v_PlayerSkin               = '';
                $v_cta_enable               = '';
                $v_ctabtn_location          = '';
                $v_ctabtn_dur               = '';
                $v_cta_bg_color             = '';
                $v_cta_text_color           = '';
                $v_cta_btn_text             = '';
                $v_cta_btn_border           = '';
                $v_cta_btn_radius           = '';
                $v_cta_btn_border_color     = '';
                $v_cta_btn_height           = '';
                $v_cta_btn_width            = '';
                $v_ctabtn_allow_skip        = '';
                $v_cta_share_url            = '';
                $v_cta_custom_url           = '';
            }

            if(isset($_POST['save_action'])) {
                if($_POST['save_action'] == 'tab-1-content') {
                    $title = sanitize_text_field($_POST['title']);
                    $videowidth = sanitize_text_field($_POST['videowidth']);
                    $videoheight = sanitize_text_field($_POST['videoheight']);
                    $autoplay = sanitize_text_field($_POST['autoplay']);
                    $allowpause = sanitize_text_field($_POST['allowpause']);
                    $allowscroll = sanitize_text_field($_POST['allowscroll']);
                    $video_source = sanitize_text_field($_POST['video_source']);

                    // if($video_source == "vimeo_video"){
                    //     $videocontrols = "show";
                    // }else{
                        $videocontrols = sanitize_text_field($_POST['videocontrols']);

                        if($videocontrols == "hide"){
                            $autoplay = 'yes';
                        }
                    // }

                    $video_align = sanitize_text_field($_POST['video_align']);
                    $video_content = $_POST['video_content'];
                    $socialtitle = sanitize_text_field($_POST['socialtitle']);
                    $socialtext = sanitize_text_field($_POST['socialtext']);
                    $content_location = sanitize_text_field($_POST['content_location']);
                    $showcontent_dur = sanitize_text_field($_POST['showcontent_dur']);
                    $socialbtn_location = sanitize_text_field($_POST['socialbtn_location']);
                    $sociallock_dur = sanitize_text_field($_POST['sociallock_dur']);
                    $social_enable = sanitize_text_field($_POST['social_enable']);
                    $SocialLockAllowSkip = sanitize_text_field($_POST['social_allow_skip']);
                    $defaulttweet = sanitize_text_field($_POST['defaulttweet']);
                    $headline_msg = sanitize_text_field($_POST['headline_msg']);
                    $share_url = sanitize_text_field($_POST['share_url']);
                    $custom_url = sanitize_text_field($_POST['custom_url']);
                    $id = sanitize_text_field($_POST['row_id']);
                    $filename = sanitize_text_field($_POST['filename']);
                    $filename2 = sanitize_text_field($_POST['filename2']);
                    $filename3 = sanitize_text_field($_POST['filename3']);
                    $allow_skip = sanitize_text_field($_POST['social_allow_skip']);
                    $cta_enable = sanitize_text_field($_POST['cta_enable']);
                    $ctabtn_location = sanitize_text_field($_POST['ctabtn_location']);
                    $ctabtn_dur = sanitize_text_field($_POST['ctabtn_dur']);
                    $cta_bg_color = sanitize_text_field($_POST['cta_bg_color']);
                    $cta_text_color = sanitize_text_field($_POST['cta_text_color']);
                    $cta_btn_text = sanitize_text_field($_POST['cta_btn_text']);
                    $cta_btn_border = sanitize_text_field($_POST['cta_btn_border']);
                    $cta_btn_radius = sanitize_text_field($_POST['cta_btn_radius']);
                    $cta_btn_border_color = sanitize_text_field($_POST['cta_btn_border_color']);
                    $cta_btn_height = sanitize_text_field($_POST['cta_btn_height']);
                    $cta_btn_width = sanitize_text_field($_POST['cta_btn_width']);
                    $ctabtn_allow_skip = sanitize_text_field($_POST['ctabtn_allow_skip']);
                    $cta_share_url = sanitize_text_field($_POST['cta_share_url']);
                    $cta_custom_url = $_POST['cta_custom_url'];

                    if($filename || $filename2 || $filename3 && $videowidth && $videoheight){
                        if($video_source=='mp4_video'){
                            $videourl=$filename;
                        }else if($video_source=='youtube_video'){
                            $videourl=$filename2;
                        }else if($video_source=='vimeo_video'){
                            $videourl=$filename3;
                        }

                        if($_FILES["imagelogo"]["name"]){
                            $uploads = wp_upload_bits($_FILES["imagelogo"]["name"], null, file_get_contents($_FILES["imagelogo"]["tmp_name"]));
                            $img_name=$uploads['url'];
                        }
                        else{
                            $img_name = $data->ImageLogo;
                        }

                        if($social_enable=='no'){
                            $socialbtn_location='';$sociallock_dur='';$defaulttweet='';$headline_msg='';$share_url='';$custom_url='';$SocialLockAllowSkip = '';
                        }

                        if($cta_enable=='no'){
                            $ctabtn_location='';$ctabtn_dur='';$cta_bg_color='';$cta_text_color='';$cta_btn_text='';$cta_btn_border='';$cta_btn_radius='';$cta_btn_border_color='';$cta_btn_height='';$cta_btn_width='';$ctabtn_allow_skip='';$cta_share_url='';$cta_custom_url='';
                        }

                        if($share_url=='page_post' || $share_url=='main_blog'){
                            $custom_url='';
                        }

                        if($cta_share_url=='page_post' || $cta_share_url=='main_blog'){
                            $cta_custom_url='';
                        }

                        if($content_location=='beginning' || $content_location=='end'){
                            $showcontent_dur='';
                        }

                        if($socialbtn_location=='beginning' || $socialbtn_location=='end'){
                            $sociallock_dur='';
                        }

                        if($ctabtn_location=='beginning' || $ctabtn_location=='end'){
                            $ctabtn_dur='';
                        }

                        $video_content = str_replace('\\','',$video_content);                                                                        
                        $wpdb->query($wpdb->prepare("UPDATE $video_table  SET Title='%s',Video='%s',VideoSource='%s',ImageLogo='%s',VideoWidth='%s',VideoHeight='%s',AutoPlay='%s',AllowPause='%s',AllowScroll='%s',VideoControls='%s',VideoAlign='%s',ShowContentLocation='%s',ShowContentDuration='%s',VideoContent='%s',SocialButtonLocation='%s',SocialLockDuration='%s',SocialEnable='%s',SocialTitle='%s',SocialText='%s',DefaultTweet='%s',HeadlineMsg='%s',ShareUrl='%s',CustomUrl='%s',SocialLockAllowSkip='%s', cta_enable='%s', ctabtn_location='%s',ctabtn_dur='%s',cta_bg_color='%s',cta_text_color='%s',cta_btn_text='%s',cta_btn_border='%s',cta_btn_radius='%s',cta_btn_border_color='%s',cta_btn_height='%s',cta_btn_width='%s',ctabtn_allow_skip='%s',cta_share_url='%s',cta_custom_url='%s' where id='%d'",$title,$videourl,$video_source,$img_name,$videowidth,$videoheight,$autoplay,$allowpause,$allowscroll,$videocontrols,$video_align,$content_location,$showcontent_dur,$video_content,$socialbtn_location,$sociallock_dur,$social_enable,$socialtitle,$socialtext,$defaulttweet,$headline_msg,$share_url,$custom_url,$SocialLockAllowSkip,$cta_enable,$ctabtn_location,$ctabtn_dur,$cta_bg_color,$cta_text_color,$cta_btn_text,$cta_btn_border,$cta_btn_radius,$cta_btn_border_color,$cta_btn_height,$cta_btn_width,$ctabtn_allow_skip,$cta_share_url,$cta_custom_url,$id));                                                
                    }
                }

                if($_POST['save_action'] == 'tab-4-content') {
                    $VideoId = $id;     
                    
                    if(isset($_POST['allbuttons_label']) || $_POST['allbuttons_label'] != ""){
                        $Label = $_POST['allbuttons_label'];
                        $Icon = $_POST['allbuttons_icon'];
                        $Type = $_POST['allbuttons_type'];
                        $IframeUrl = $_POST['allbuttons_iframe'];
                        $MapLocation = $_POST['allbuttons_mapaddrs'];
                        $HtmlCode = stripslashes_deep( $_POST['allbuttons_htmlcode'] ) ;
                        $PostCategory = $_POST['allbuttons_postcat'];
                        $PostNo = $_POST['allbuttons_postno'];
                        $Page = $_POST['allbuttons_page'];
                        $RelatedVideoUrls = $_POST['allbuttons_related_video_url'];
                        $RelatedVideoThumbs = $_POST['allbuttons_related_video_thumb'];
                        $length = count($Label);
                        $ids ='';
                        $wpdb->delete( $videobuttons_table, array('VideoId' =>$VideoId));

                        for($i=0;$i<$length;$i++){
                            $wpdb->insert( $videobuttons_table, array('Label' =>$Label[$i]));
                            $ids = $wpdb->insert_id;
                            $data = array(
                                'VideoId' => $VideoId,'Icon' =>$Icon[$i],'Type' =>$Type[$i],
                                'IframeUrl' =>$IframeUrl[$i],'MapLocation' =>$MapLocation[$i],
                                'HtmlCode' =>$HtmlCode[$i],'PostCategory' =>$PostCategory[$i],
                                'PostNo' =>$PostNo[$i],'Page' =>$Page[$i],
                                'RelatedVideoUrls' =>$RelatedVideoUrls[$i],
                                'RelatedVideoThumbs' =>$RelatedVideoThumbs[$i]
                            );

                            $where =array('id' => $ids); 
                            $wpdb->update( $videobuttons_table, $data ,$where);                            
                        }  
                    }else{
                        $wpdb->delete( $videobuttons_table, array('VideoId' =>$VideoId));
                    }
                }

                if($_POST['save_action'] == 'tab-2-content') {
                    $mailchimpapikey = sanitize_text_field($_POST['mailchimpapikey']);
                    $mailchimplistid = sanitize_text_field($_POST['mailchimplistid']);
                    $getresponseapikey = sanitize_text_field($_POST['getresponseapikey']);
                    $getresponsecampaignid = sanitize_text_field($_POST['getresponsecampaignid']);
                    $AWeberListID = sanitize_text_field($_POST['AWeberListID']);
                    $sendlaneapikey = sanitize_text_field($_POST['sendlaneapikey']);
                    $sendlaneapihashkey = sanitize_text_field($_POST['sendlaneapihashkey']);
                    $sendlaneapiurl = sanitize_text_field($_POST['sendlaneapiurl']);
                    $sendlanesubdomain = sanitize_text_field($_POST['sendlanesubdomain']);
                    $sendlanelistid = sanitize_text_field($_POST['sendlanelistid']);
                    $custom_formcode = sanitize_text_field($_POST['custom_formcode']);
                    $id = sanitize_text_field($_POST['row_id']);

                    $wpdb->query($wpdb->prepare("UPDATE $video_table  SET custom_formcode='%s', MailChimpApiKey='%s',MailChimpListId='%s',GetResponseApiKey='%s',GetResponseCampaignId='%s', AWeberListID='%s', ConstCntctUserName='%s',ConstCntctAPIKey='%s',ConstCntctSecret='%s',ConstCntctListID='%s',SendlaneApiKey='%s',SendlaneApiHashKey='%s',SendlaneApiUrl='%s',SendlaneSubDomain='%s',SendlaneListID='%s' where id='%d'",$custom_formcode,@$mailchimpapikey,@$mailchimplistid,@$getresponseapikey,@$getresponsecampaignid,@$AWeberListID,@$constcntctusername,@$constcntctapikey,@$constcntctsecret,@$constcntctlistid,@$sendlaneapikey,@$sendlaneapihashkey,@$sendlaneapiurl,@$sendlanesubdomain,@$sendlanelistid,$id));
                }

                if($_POST['save_action'] == 'tab-3-content'){
                    $inc_optin = sanitize_text_field($_POST['inc_optin']);
                    $videomailinglist = sanitize_text_field($_POST['videomailinglist']);
                    $optin_location = sanitize_text_field($_POST['optin_location']);
                    $optin_mid_time = sanitize_text_field($_POST['optin_mid_time']);
                    $optin_headline = sanitize_text_field($_POST['optin_headline']);
                    $optin_text = sanitize_text_field($_POST['optin_text']);
                    $optin_submit_text = sanitize_text_field($_POST['optin_submit_text']);
                    $thankyou_message = sanitize_text_field($_POST['thankyou_message']);
                    $allow_skip = sanitize_text_field($_POST['allow_skip']);
                    $id = sanitize_text_field($_POST['row_id']);

                    if($optin_location=='beginning' || $optin_location=='end'){
                        $optin_mid_time='';
                    }

                    if($_POST['videomailinglist']=='mailchimp'){
                        $autoresponder = 1;

                        if($data->MailChimpApiKey  == '' || $data->MailChimpListId == ''){
                            $autoresponder = 0;
                        }
                    }elseif($_POST['videomailinglist']=='getresponse'){
                        $autoresponder = 1;

                        if($data->GetResponseApiKey  == '' || $data->GetResponseCampaignId == ''){
                            $autoresponder = 0;
                        }
                    }elseif($_POST['videomailinglist']=='aweber'){
                        $autoresponder = 1;

                        if($data->AWeberListID == ''){
                            $autoresponder = 0;
                        }
                    }elseif($_POST['videomailinglist']=='sendlane'){
                        $autoresponder = 1;

                        if($data->SendlaneApiKey  == '' || $data->SendlaneApiHashKey == '' || $data->SendlaneListID == ''){
                            $autoresponder = 0;
                        }
                    }

                    // die('here: '.$autoresponder);

                    if($autoresponder == 1){
                        $wpdb->query($wpdb->prepare("UPDATE $video_table SET OptinBox='%s', OptinLocation='%s', OptinMidTime='%s', OptinHeadline='%s', OptinText='%s', OptinSubmitText='%s', ThankyouMessage='%s', OptinAllowSkip='%s', VideoMailingList='%s' WHERE id='%d'", $inc_optin, $optin_location, $optin_mid_time, $optin_headline, $optin_text, $optin_submit_text, $thankyou_message, $allow_skip, $videomailinglist, $id));
                    }
                }

                if($_POST['save_action'] == 'tab-5-content'){
                    $player_skin = sanitize_text_field($_POST['player_skin']);
                    $id = sanitize_text_field($_POST['row_id']);
                    $wpdb->query($wpdb->prepare("UPDATE $video_table SET PlayerSkin='%s' where id='%d'",$player_skin,$id));
                }

                if($_POST['save_action'] == 'tab-6-content'){
                    $inc_popup = sanitize_text_field($_POST['inc_popup']);
                    $popup_content = $_POST['popup_content'];
                    $popup_link = sanitize_text_field($_POST['popup_link']);
                    $popup_location = sanitize_text_field($_POST['popup_location']);
                    $popup_mid_time = sanitize_text_field($_POST['popup_mid_time']);
                    $id = sanitize_text_field($_POST['row_id']);

                    if($inc_popup=='no'){
                        $popup_location='';$popup_mid_time='';$popup_content='';$popup_link='';
                    }

                    if($popup_location=='beginning' || $popup_location=='end'){
                        $popup_mid_time='';
                    }
                    
                    $wpdb->query($wpdb->prepare("UPDATE $video_table SET Popup='%s',PopupContent='%s',PopupLink='%s',PopupLocation='%s',PopupMidTime='%s' where id='%d'",$inc_popup,$popup_content,$popup_link,$popup_location,$popup_mid_time,$id));
                }
            }

        }else {
            if($_POST['save_action'] == 'tab-1-content') {
                $title = sanitize_text_field($_POST['title']);
                $videowidth = sanitize_text_field($_POST['videowidth']);
                $videoheight = sanitize_text_field($_POST['videoheight']);
                $autoplay = sanitize_text_field($_POST['autoplay']);
                $allowpause = sanitize_text_field($_POST['allowpause']);
                $allowscroll = sanitize_text_field($_POST['allowscroll']);
                $video_source = sanitize_text_field($_POST['video_source']);

                if($video_source == "vimeo_video"){
                    $videocontrols = "show";
                }else{
                    $videocontrols = sanitize_text_field($_POST['videocontrols']);
                }

                $video_align = sanitize_text_field($_POST['video_align']);
                $video_content = $_POST['video_content'];
                $socialtitle = sanitize_text_field($_POST['socialtitle']);
                $socialtext = sanitize_text_field($_POST['socialtext']);
                $content_location = sanitize_text_field($_POST['content_location']);
                $showcontent_dur = sanitize_text_field($_POST['showcontent_dur']);
                $socialbtn_location = sanitize_text_field($_POST['socialbtn_location']);
                $social_enable = sanitize_text_field($_POST['social_enable']);
                $defaulttweet = sanitize_text_field($_POST['defaulttweet']);
                $headline_msg = sanitize_text_field($_POST['headline_msg']);
                $share_url = sanitize_text_field($_POST['share_url']);
                $custom_url = sanitize_text_field($_POST['custom_url']);
                $id = sanitize_text_field($_POST['row_id']);
                $filename = sanitize_text_field($_POST['filename']);
                $filename2 = sanitize_text_field($_POST['filename2']);
                $filename3 = sanitize_text_field($_POST['filename3']);
                $allow_skip = sanitize_text_field($_POST['social_allow_skip']);              
                $cta_enable = sanitize_text_field($_POST['cta_enable']);
                $ctabtn_location = sanitize_text_field($_POST['ctabtn_location']);
                $sociallock_dur = sanitize_text_field($_POST['sociallock_dur']);
                $ctabtn_dur = sanitize_text_field($_POST['ctabtn_dur']);
                $cta_bg_color = sanitize_text_field($_POST['cta_bg_color']);
                $cta_text_color = sanitize_text_field($_POST['cta_text_color']);
                $cta_btn_text = sanitize_text_field($_POST['cta_btn_text']);
                $cta_btn_border = sanitize_text_field($_POST['cta_btn_border']);
                $cta_btn_radius = sanitize_text_field($_POST['cta_btn_radius']);
                $cta_btn_border_color = sanitize_text_field($_POST['cta_btn_border_color']);
                $cta_btn_height = sanitize_text_field($_POST['cta_btn_height']);
                $cta_btn_width = sanitize_text_field($_POST['cta_btn_width']);
                $ctabtn_allow_skip = sanitize_text_field($_POST['ctabtn_allow_skip']);
                $cta_share_url = sanitize_text_field($_POST['cta_share_url']);
                $cta_custom_url = sanitize_text_field($_POST['cta_custom_url']);

                if($filename || $filename2 || $filename3 && $videowidth && $videoheight){
                    if($video_source=='mp4_video'){
                        $videourl=$filename;
                    }else if($video_source=='youtube_video'){
                        $videourl=$filename2;
                    }else if($video_source=='vimeo_video'){
                        $videourl=$filename3;
                    }

                    if($_FILES["imagelogo"]["name"]){
                        $uploads = wp_upload_bits($_FILES["imagelogo"]["name"], null, file_get_contents($_FILES["imagelogo"]["tmp_name"]));
                        $img_name=$uploads['url'];
                    }else{
                        $img_name = $data->ImageLogo;
                    }

                    if($social_enable=='no'){
                        $socialbtn_location='';$sociallock_dur='';$defaulttweet='';$headline_msg='';$share_url='';$custom_url='';
                    }

                    if($cta_enable=='no'){
                        $ctabtn_location='';$ctabtn_dur='';$cta_bg_color='';$cta_text_color='';$cta_btn_text='';$cta_btn_border='';$cta_btn_radius='';$cta_btn_border_color='';$cta_btn_height='';$cta_btn_width='';$ctabtn_allow_skip='';$cta_share_url='';$cta_custom_url='';
                    }

                    if($share_url=='page_post' || $share_url=='main_blog'){
                        $custom_url='';
                    }

                    if($cta_share_url=='page_post' || $cta_share_url=='main_blog'){
                        $cta_custom_url='';
                    }

                    if($content_location=='beginning' || $content_location=='end'){
                        $showcontent_dur='';
                    }

                    if($socialbtn_location=='beginning' || $socialbtn_location=='end'){
                        $sociallock_dur='';
                    }

                    if($ctabtn_location=='beginning' || $ctabtn_location=='end'){
                        $ctabtn_dur='';
                    }

                    $video_content = str_replace('\\','',$video_content);
                    
                    $wpdb->insert( $video_table, array(
                                                    'Title' => $title,'Video' =>$videourl,
                                                    'VideoSource' =>$video_source,'ImageLogo'=>$img_name,
                                                    'VideoWidth'=>$videowidth,'VideoHeight'=>$videoheight,
                                                    'AutoPlay'=>$autoplay,'AllowPause'=>$allowpause,
                                                    'AllowScroll'=>$allowscroll,'VideoControls'=>$videocontrols,
                                                    'VideoAlign'=>$video_align,'ShowContentLocation'=>$content_location,
                                                    'ShowContentDuration'=>$showcontent_dur,'VideoContent'=>$video_content,
                                                    'SocialButtonLocation'=>$socialbtn_location,'SocialLockDuration'=>$sociallock_dur,
                                                    'SocialEnable'=>$social_enable,'SocialTitle'=>$socialtitle,
                                                    'SocialText'=>$socialtext,'DefaultTweet'=>$defaulttweet,
                                                    'HeadlineMsg'=>$headline_msg,'ShareUrl'=>$share_url,
                                                    'PlayerSkin'=>"none",'SocialLockAllowSkip'=>$allow_skip,
                                                    'CustomUrl'=>$custom_url,"cta_enable"=>$cta_enable,
                                                    "ctabtn_location"=>$ctabtn_location,"ctabtn_dur"=>$ctabtn_dur,
                                                    "cta_bg_color"=>$cta_bg_color,"cta_text_color"=>$cta_text_color,
                                                    "cta_btn_text"=>$cta_btn_text,"cta_btn_border"=>$cta_btn_border,
                                                    "cta_btn_radius"=>$cta_btn_radius,"cta_btn_border_color"=>$cta_btn_border_color,
                                                    "cta_btn_height"=>$cta_btn_height,"cta_btn_width"=>$cta_btn_width,
                                                    "ctabtn_allow_skip"=>$ctabtn_allow_skip,"cta_share_url"=>$cta_share_url,
                                                    "cta_custom_url"=>$cta_custom_url
                                                ));

                    $current_id = $wpdb->insert_id;
                }
            }

            if($_POST['save_action'] == 'tab-2-content') {
                $mailchimpapikey = sanitize_text_field($_POST['mailchimpapikey']);
                $mailchimplistid = sanitize_text_field($_POST['mailchimplistid']);
                $getresponseapikey = sanitize_text_field($_POST['getresponseapikey']);
                $getresponsecampaignid = sanitize_text_field($_POST['getresponsecampaignid']);
                $AWeberListID = sanitize_text_field($_POST['AWeberListID']);
                $sendlaneapikey = sanitize_text_field($_POST['sendlaneapikey']);
                $sendlaneapihashkey = sanitize_text_field($_POST['sendlaneapihashkey']);
                $sendlaneapiurl = sanitize_text_field($_POST['sendlaneapiurl']);
                $sendlanesubdomain = sanitize_text_field($_POST['sendlanesubdomain']);
                $sendlanelistid = sanitize_text_field($_POST['sendlanelistid']);
                $custom_formcode = sanitize_text_field($_POST['custom_formcode']);

                $wpdb->insert( $video_table, array(
                                                'custom_formcode'=>@$custom_formcode,'MailChimpApiKey'=>@$mailchimpapikey,
                                                'MailChimpListId'=>@$mailchimplistid,'GetResponseApiKey'=>@$getresponseapikey,
                                                'GetResponseCampaignId'=>@$getresponsecampaignid,'AWeberListID'=>@$AWeberListID,
                                                'ConstCntctUserName'=>@$constcntctusername,'ConstCntctAPIKey'=>@$constcntctapikey,
                                                'ConstCntctSecret'=>@$constcntctsecret,'ConstCntctListID'=>@$constcntctlistid
                ));

                $current_id = $wpdb->insert_id;
            }

            if($_POST['save_action'] == 'tab-3-content') {
                $inc_optin = sanitize_text_field($_POST['inc_optin']);
                $videomailinglist = sanitize_text_field($_POST['videomailinglist']);
                $optin_location = sanitize_text_field($_POST['optin_location']);
                $optin_mid_time = sanitize_text_field($_POST['optin_mid_time']);
                $optin_headline = sanitize_text_field($_POST['optin_headline']);
                $optin_text = sanitize_text_field($_POST['optin_text']);
                $optin_submit_text = sanitize_text_field($_POST['optin_submit_text']);
                $thankyou_message = sanitize_text_field($_POST['thankyou_message']);
                $allow_skip = sanitize_text_field($_POST['allow_skip']);
                $id = sanitize_text_field($_POST['row_id']);

                if($optin_location=='beginning' || $optin_location=='end'){
                    $optin_mid_time='';
                }

                $wpdb->insert( $video_table, array(
                                                'OptinBox'=>$inc_optin,'OptinLocation'=>$optin_location,
                                                'OptinMidTime'=>$optin_mid_time,'OptinHeadline'=>$optin_headline,
                                                'OptinText'=>$optin_text,'OptinSubmitText'=>$optin_submit_text,
                                                'ThankyouMessage'=>$thankyou_message,'OptinAllowSkip'=>$allow_skip,
                                                'VideoMailingList'=>$videomailinglist
                ));

                $current_id = $wpdb->insert_id;
            }

            if($_POST['save_action'] == 'tab-5-content') {
                $player_skin = sanitize_text_field($_POST['player_skin']);
                $wpdb->insert( $video_table, array(
                    'PlayerSkin'=>$player_skin
                ));

                $current_id = $wpdb->insert_id;
            }

            if($_POST['save_action'] == 'tab-6-content') {
                $inc_popup = sanitize_text_field($_POST['inc_popup']);
                $popup_content = sanitize_text_field($_POST['popup_content']);
                $popup_link = sanitize_text_field($_POST['popup_link']);
                $popup_location = sanitize_text_field($_POST['popup_location']);
                $popup_mid_time = sanitize_text_field($_POST['popup_mid_time']);
                $id = sanitize_text_field($_POST['row_id']);

                if($inc_popup=='no'){
                    $popup_location='';$popup_mid_time='';$popup_content='';$popup_link='';
                }

                if($popup_location=='beginning' || $popup_location=='end'){
                    $popup_mid_time='';
                }

                $wpdb->insert( $video_table, array(
                                                'Popup'=>$inc_popup,'PopupLocation'=>$popup_location,
                                                'PopupMidTime'=>$popup_mid_time,'PopupContent'=>$popup_content,
                                                'PopupLink'=>$popup_link
                ));

                $current_id = $wpdb->insert_id;
            }

            $status = 'insert';

        }

        if($autoresponder==0){
            $response   =   array(  
                                'success' => 0,
                                'message' => __('Config Autoresponder List','mvp'),
                                'status' => $status,
                                'redirect_url' => ''
                            );
        }else{
            $response   =   array(
                'success' => 1,
                'message' => __('Listing Saved Successfully!','mvp'),
                'status' => $status,
                'redirect_url' => get_permalink().'?page=mv_player_add_video&id='.$current_id
            );
        }     

        echo json_encode( $response ); exit;
    }

    public function mvp_listing_playlist_tabs_admin_ajax_handler(){
        global $wpdb;

        $videobuttons_table = $wpdb->prefix . "mvplayer_videobuttons";
        $playlist_video_table = $wpdb->prefix . "playlist_video";        

        if(!empty($_POST['row_id'])){
            $status = 'update';
            $id = $_POST['row_id'];
            $Playlist_Id = $_POST['row_id'];
            $data =  $wpdb->get_row("SELECT * FROM $playlist_video_table where id= $id");

            if($data){
                $v_id                       = $id;
                $current_id                 = $id;
                $v_Title                    = $data->Title;
                $v_Video                    = $data->Video;
                $v_VideoSource              = $data->VideoSource;
                $v_ImageLogo                = $data->ImageLogo;
                $v_VideoWidth               = $data->VideoWidth;
                $v_VideoHeight              = $data->VideoHeight;
                $v_AutoPlay                 = $data->AutoPlay;
                $v_AllowPause               = $data->AllowPause;
                $v_VideoControls            = $data->VideoControls;
                $v_VideoAlign               = $data->VideoAlign;
                $v_ShowContentLoc           = $data->ShowContentLocation;
                $v_ShowContentDur           = $data->ShowContentDuration;
                $v_Content                  = $data->VideoContent;
                $v_SocialBtnLoc             = $data->SocialButtonLocation;
                $v_SocialLockDuration       = $data->SocialLockDuration;
                $v_SocialEnable             = $data->SocialEnable;
                $v_SocialTitle              = $data->SocialTitle;
                $v_SocialText               = $data->SocialText;
                $v_DefaultTweet             = $data->DefaultTweet;
                $v_HeadlineMsg              = $data->HeadlineMsg;
                $v_ShareUrl                 = $data->ShareUrl;
                $v_CustomUrl                = $data->CustomUrl;
                $v_OptinBox                 = $data->OptinBox;
                $v_OptinLocation            = $data->OptinLocation;
                $v_OptinMidTime             = $data->OptinMidTime;
                $v_OptinHeadline            = $data->OptinHeadline;
                $v_OptinText                = $data->OptinText;
                $v_OptinSubmitText          = $data->OptinSubmitText;
                $v_ThankyouMessage          = $data->ThankyouMessage;
                $v_OptinAllowSkip           = $data->OptinAllowSkip;
                $v_Popup                    = $data->Popup;
                $v_PopupContent             = $data->PopupContent;
                $v_PopupLink                = $data->PopupLink;
                $v_PopupLocation            = $data->PopupLocation;
                $v_PopupMidTime             = $data->PopupMidTime;
                $v_VideoMailingList         = $data->VideoMailingList;
                $custom_formcode            = $data->custom_formcode;
                $v_MailChimpApiKey          = $data->MailChimpApiKey;
                $v_MailChimpListId          = $data->MailChimpListId;
                $v_GetResponseApiKey        = $data->GetResponseApiKey;
                $v_GetResponseCampaignId    = $data->GetResponseCampaignId;
                $v_AWeberListID             = $data->AWeberListID;
                $v_AWeberAccessTokens       = $data->AWeberAccessTokens;
                $v_ConstCntctUserName       = $data->ConstCntctUserName;
                $v_ConstCntctAPIKey         = $data->ConstCntctAPIKey;
                $v_ConstCntctSecret         = $data->ConstCntctSecret;
                $v_ConstCntctListID         = $data->ConstCntctListID;
                $v_SendlaneApiKey           = $data->SendlaneApiKey;
                $v_SendlaneApiHashKey       = $data->SendlaneApiHashKey;
                $v_SendlaneApiUrl           = $data->SendlaneApiUrl;
                $v_SendlaneSubDomain        = $data->SendlaneSubDomain;
                $v_SendlaneListID           = $data->SendlaneListID;
                $v_PlayerSkin               = $data->PlayerSkin;
            }else{
                $v_id                       = '';
                $v_Title                    = '';
                $v_Video                    = '';
                $v_VideoSource              = '';
                $v_ImageLogo                = '';
                $v_VideoWidth               = '';
                $v_VideoHeight              = '';
                $v_AutoPlay                 = '';
                $v_AllowPause               = '';
                $v_VideoControls            = '';
                $v_VideoAlign               = '';
                $v_ShowRelatedVideos        = '';
                $v_AllRelatedVideos         = '';
                $v_ShowContentLoc           = '';
                $v_ShowContentDur           = '';
                $v_Content                  = '';
                $v_SocialBtnLoc             = '';
                $v_SocialLockDuration       = '';
                $v_SocialEnable             = '';
                $v_SocialTitle              = '';
                $v_SocialText               = '';
                $v_DefaultTweet             = '';
                $v_HeadlineMsg              = '';
                $v_OptinBox                 = '';
                $v_OptinLocation            = '';
                $v_OptinMidTime             = '';
                $v_OptinHeadline            = '';
                $v_OptinText                = '';
                $v_OptinSubmitText          = '';
                $v_ThankyouMessage          = '';
                $v_OptinAllowSkip           = '';
                $v_Popup                    = '';
                $v_PopupContent             = '';
                $v_PopupLink                = '';
                $v_PopupLocation            = '';
                $v_PopupMidTime             = '';
                $v_VideoMailingList         = '';
                $custom_formcode            = '';
                $v_MailChimpApiKey          = '';
                $v_MailChimpListId          = '';
                $v_GetResponseApiKey        = '';
                $v_GetResponseCampaignId    = '';
                $v_AWeberListID             = '';
                $v_AWeberAccessTokens       = '';
                $v_ConstCntctUserName       = '';
                $v_ConstCntctAPIKey         = '';
                $v_ConstCntctSecret         = '';
                $v_ConstCntctListID         = '';                
                $v_SendlaneApiKey           = '';
                $v_SendlaneApiHashKey       = '';
                $v_SendlaneApiUrl           = '';
                $v_SendlaneSubDomain        = '';
                $v_SendlaneListID           = '';
                $v_PlayerSkin               = '';
            }

            if(isset($_POST['save_action'])) {

                if($_POST['save_action'] == 'tab-1-content') {
                    $title = sanitize_text_field($_POST['title']);
                    $category_groups = $_POST['category-group'];
                    $video_option = $_POST['video_option'];
                    $videowidth = sanitize_text_field($_POST['videowidth']);
                    $videoheight = sanitize_text_field($_POST['videoheight']);
                    $autoplay = sanitize_text_field($_POST['autoplay']);
                    $allowpause = sanitize_text_field($_POST['allowpause']);
                    $videocontrols = sanitize_text_field($_POST['videocontrols']);
                    $video_align = sanitize_text_field($_POST['video_align']);
                    $video_content = $_POST['video_content'];
                    $socialtitle = sanitize_text_field($_POST['socialtitle']);
                    $socialtext = sanitize_text_field($_POST['socialtext']);
                    $content_location = sanitize_text_field($_POST['content_location']);
                    $showcontent_dur = sanitize_text_field($_POST['showcontent_dur']);
                    $socialbtn_location = sanitize_text_field($_POST['socialbtn_location']);
                    $sociallock_dur = sanitize_text_field($_POST['sociallock_dur']);
                    $social_enable = sanitize_text_field($_POST['social_enable']);
                    $defaulttweet = sanitize_text_field($_POST['defaulttweet']);
                    $headline_msg = sanitize_text_field($_POST['headline_msg']);
                    $share_url = sanitize_text_field($_POST['share_url']);
                    $custom_url = sanitize_text_field($_POST['custom_url']);
                    $allow_skip = sanitize_text_field($_POST['social_allow_skip']);

                    foreach ($category_groups as $category_group) {
                        $filename = $category_group['filename'];
                        $filename2 = $category_group['filename2'];
                        $filename3 = $category_group['filename3'];
                    } 

                    $video_files  = array();
                    $video_source = sanitize_text_field($_POST['video_source']);

                    if($filename || $filename2 || $filename3 && $videowidth && $videoheight){
                        $category_groups_json = json_encode($category_groups);    
                        $k = 0;

                        foreach ($category_groups as $key => $value) {
                            if($value['filename']){
                                $filename = $value['filename']; 
                            }else if($value['filename2']){
                                $filename = $value['filename2'];
                            }else{
                                $filename = $value['filename3']; 
                            }                          

                            $video_files[ $k ][ 'video_source' ] = $value['video_source'];
                            $video_files[ $k ][ 'filename' ] = $filename;                 
                            $k++;
                        }

                        $video_source = $value['video_source'];

                        if( $video_source=='mp4_video' ){
                            $videourl=$filename;
                        }else if( $video_source=='youtube_video' ){
                            $videourl=$filename2;
                        }else if( $video_source=='vimeo_video' ){
                            $videourl=$filename3;
                        }                 

                        if($_FILES["imagelogo"]["name"]){
                            $uploads = wp_upload_bits($_FILES["imagelogo"]["name"], null, file_get_contents($_FILES["imagelogo"]["tmp_name"]));
                            $img_name=$uploads['url'];
                        }else{
                            $img_name = $data->ImageLogo;
                        }

                        if($social_enable=='no'){
                            $socialbtn_location='';$sociallock_dur='';$defaulttweet='';$headline_msg='';$share_url='';$custom_url='';
                        }

                        if($share_url=='page_post' || $share_url=='main_blog'){
                            $custom_url='';
                        }

                        if($content_location=='beginning' || $content_location=='end'){
                            $showcontent_dur='';
                        }

                        if($socialbtn_location=='beginning' || $socialbtn_location=='end'){
                            $sociallock_dur='';
                        }
                        
                        $video_content = str_replace('\\','',$video_content);
                        $wpdb->query($wpdb->prepare("UPDATE $playlist_video_table SET Playlist_Id='%s',Title='%s',Video='%s',VideoSource='%s',ImageLogo='%s',VideoWidth='%s',VideoHeight='%s',AutoPlay='%s',AllowPause='%s',VideoControls='%s',VideoAlign='%s',ShowContentLocation='%s',ShowContentDuration='%s',VideoContent='%s',SocialButtonLocation='%s',SocialLockDuration='%s',SocialEnable='%s',SocialTitle='%s',SocialText='%s',DefaultTweet='%s',HeadlineMsg='%s',ShareUrl='%s',CustomUrl='%s',SocialLockAllowSkip='%s' where id='%d'",$Playlist_Id,$title,$category_groups_json,$video_source,$img_name,$videowidth,$videoheight,$autoplay,$allowpause,$videocontrols,$video_align,$content_location,$showcontent_dur,$video_content,$socialbtn_location,$sociallock_dur,$social_enable,$socialtitle,$socialtext,$defaulttweet,$headline_msg,$share_url,$custom_url,$allow_skip,$id));                                                
                    }
                }

                if($_POST['save_action'] == 'tab-4-content') {               
                    $VideoId = $id;

                    if(isset($_POST['allbuttons_label']) || $_POST['allbuttons_label'] != ""){
                        $Label = $_POST['allbuttons_label'];
                        $Icon = $_POST['allbuttons_icon'];
                        $Type = $_POST['allbuttons_type'];
                        $IframeUrl = $_POST['allbuttons_iframe'];
                        $MapLocation = $_POST['allbuttons_mapaddrs'];
                        $HtmlCode = $_POST['allbuttons_htmlcode'];
                        $PostCategory = $_POST['allbuttons_postcat'];
                        $PostNo = $_POST['allbuttons_postno'];
                        $Page = $_POST['allbuttons_page'];
                        $RelatedVideoUrls = $_POST['allbuttons_related_video_url'];
                        $RelatedVideoThumbs = $_POST['allbuttons_related_video_thumb'];
                        $length = count($Label);
                        $ids ='';
                        $wpdb->delete( $videobuttons_table, array('PlaylistId' =>$VideoId));

                        for($i=0;$i<$length;$i++){                         
                            $wpdb->insert( $videobuttons_table, array('Label' =>$Label[$i]));
                            $ids = $wpdb->insert_id;
                            $data = array(
                                'PlaylistId' => $VideoId,'Icon' =>$Icon[$i],
                                'Type' =>$Type[$i],'IframeUrl' =>$IframeUrl[$i],
                                'MapLocation' =>$MapLocation[$i],'HtmlCode' =>$HtmlCode[$i],
                                'PostCategory' =>$PostCategory[$i],'PostNo' =>$PostNo[$i],
                                'Page' =>$Page[$i],'RelatedVideoUrls' =>$RelatedVideoUrls[$i],
                                'RelatedVideoThumbs' =>$RelatedVideoThumbs[$i]
                            );                          

                            $where =array('id' => $ids); 
                            $wpdb->update( $videobuttons_table, $data ,$where);
                        }  
                    }else{
                        $wpdb->delete( $videobuttons_table, array('PlaylistId' =>$VideoId));
                    }
                }

                if($_POST['save_action'] == 'tab-2-content') {
                    $mailchimpapikey = sanitize_text_field($_POST['mailchimpapikey']);
                    $mailchimplistid = sanitize_text_field($_POST['mailchimplistid']);
                    $getresponseapikey = sanitize_text_field($_POST['getresponseapikey']);
                    $getresponsecampaignid = sanitize_text_field($_POST['getresponsecampaignid']);
                    $AWeberListID = sanitize_text_field($_POST['AWeberListID']);
                    $sendlaneapikey = sanitize_text_field($_POST['sendlaneapikey']);
                    $sendlaneapihashkey = sanitize_text_field($_POST['sendlaneapihashkey']);
                    $sendlaneapiurl = sanitize_text_field($_POST['sendlaneapiurl']);
                    $sendlanesubdomain = sanitize_text_field($_POST['sendlanesubdomain']);
                    $sendlanelistid = sanitize_text_field($_POST['sendlanelistid']);
                    $custom_formcode = sanitize_text_field($_POST['custom_formcode']);
                    $id = sanitize_text_field($_POST['row_id']);

                    //  Update Playlist Detais  
                    $wpdb->query($wpdb->prepare("UPDATE $playlist_video_table  SET Playlist_Id='%s', custom_formcode='%s', MailChimpApiKey='%s',MailChimpListId='%s',GetResponseApiKey='%s',GetResponseCampaignId='%s', AWeberListID='%s', ConstCntctUserName='%s',ConstCntctAPIKey='%s',ConstCntctSecret='%s',ConstCntctListID='%s',SendlaneApiKey='%s',SendlaneApiHashKey='%s',SendlaneApiUrl='%s',SendlaneSubDomain='%s',SendlaneListID='%s' where id='%d'",$Playlist_Id,$custom_formcode,$mailchimpapikey,$mailchimplistid,$getresponseapikey,$getresponsecampaignid,$AWeberListID,$constcntctusername,$constcntctapikey,$constcntctsecret,$constcntctlistid,$sendlaneapikey,@$sendlaneapihashkey,@$sendlaneapiurl,@$sendlanesubdomain,@$sendlanelistid,$id));
                }

                if($_POST['save_action'] == 'tab-3-content'){
                    $inc_optin = sanitize_text_field($_POST['inc_optin']);
                    $videomailinglist = sanitize_text_field($_POST['videomailinglist']);
                    $optin_location = sanitize_text_field($_POST['optin_location']);
                    $optin_mid_time = sanitize_text_field($_POST['optin_mid_time']);
                    $optin_headline = sanitize_text_field($_POST['optin_headline']);
                    $optin_text = sanitize_text_field($_POST['optin_text']);
                    $optin_submit_text = sanitize_text_field($_POST['optin_submit_text']);
                    $thankyou_message = sanitize_text_field($_POST['thankyou_message']);
                    $allow_skip = sanitize_text_field($_POST['allow_skip']);
                    $id = sanitize_text_field($_POST['row_id']);

                    if($optin_location=='beginning' || $optin_location=='end'){
                        $optin_mid_time='';
                    }

                    //  Update Playlist Detail
                    $wpdb->query($wpdb->prepare("UPDATE $playlist_video_table SET Playlist_Id='%s',OptinBox='%s',OptinLocation='%s',OptinMidTime='%s',OptinHeadline='%s', OptinText='%s',OptinSubmitText='%s',ThankyouMessage='%s',OptinAllowSkip='%s', VideoMailingList='%s'where id='%d'",$Playlist_Id,$inc_optin,$optin_location,$optin_mid_time,$optin_headline,$optin_text,$optin_submit_text,$thankyou_message,$allow_skip,$videomailinglist,$id));
                }

                if($_POST['save_action'] == 'tab-5-content'){
                    $player_skin = sanitize_text_field($_POST['player_skin']);
                    $id = sanitize_text_field($_POST['row_id']);
                    $wpdb->query($wpdb->prepare("UPDATE $playlist_video_table SET PlayerSkin='%s' where id='%d'",$player_skin,$id));
                }

                if($_POST['save_action'] == 'tab-6-content'){
                    $inc_popup = sanitize_text_field($_POST['inc_popup']);
                    $popup_content = $_POST['popup_content'];
                    $popup_link = sanitize_text_field($_POST['popup_link']);
                    $popup_location = sanitize_text_field($_POST['popup_location']);
                    $popup_mid_time = sanitize_text_field($_POST['popup_mid_time']);
                    $id = sanitize_text_field($_POST['row_id']);

                    if($inc_popup=='no'){
                        $popup_location='';$popup_mid_time='';$popup_content='';$popup_link='';
                    }

                    if($popup_location=='beginning' || $popup_location=='end'){
                        $popup_mid_time='';
                    }

                    //  Update Playlist Detail
                    $wpdb->query($wpdb->prepare("UPDATE $playlist_video_table SET Playlist_Id='%s',Popup='%s',PopupContent='%s',PopupLink='%s',PopupLocation='%s',PopupMidTime='%s' where id='%d'",$Playlist_Id,$inc_popup,$popup_content,$popup_link,$popup_location,$popup_mid_time,$id));                    
                }
            }
        }else{

            $Playlist_Id = $_GET['row_id'];

            if($_POST['save_action'] == 'tab-1-content') {
                $title = sanitize_text_field($_POST['title']);
                $category_groups = $_POST['category-group'];
                $video_option = $_POST['video_option'];
                $videowidth = sanitize_text_field($_POST['videowidth']);
                $videoheight = sanitize_text_field($_POST['videoheight']);
                $autoplay = sanitize_text_field($_POST['autoplay']);
                $allowpause = sanitize_text_field($_POST['allowpause']);
                $videocontrols = sanitize_text_field($_POST['videocontrols']);
                $video_align = sanitize_text_field($_POST['video_align']);
                $video_content = $_POST['video_content'];
                $socialtitle = sanitize_text_field($_POST['socialtitle']);
                $socialtext = sanitize_text_field($_POST['socialtext']);
                $content_location = sanitize_text_field($_POST['content_location']);
                $showcontent_dur = sanitize_text_field($_POST['showcontent_dur']);
                $socialbtn_location = sanitize_text_field($_POST['socialbtn_location']);
                $sociallock_dur = sanitize_text_field($_POST['sociallock_dur']);
                $social_enable = sanitize_text_field($_POST['social_enable']);
                $defaulttweet = sanitize_text_field($_POST['defaulttweet']);
                $headline_msg = sanitize_text_field($_POST['headline_msg']);
                $share_url = sanitize_text_field($_POST['share_url']);
                $custom_url = sanitize_text_field($_POST['custom_url']);
                $allow_skip = sanitize_text_field($_POST['social_allow_skip']);

                foreach ($category_groups as $category_group) {
                    $filename = $category_group['filename'];
                    $filename2 = $category_group['filename2'];
                    $filename3 = $category_group['filename3'];
                }

                $video_source = sanitize_text_field($_POST['video_source']);              

                if($filename || $filename2 || $filename3 && $videowidth && $videoheight){
                    $category_groups_json = json_encode($category_groups);                   

                    foreach ($category_groups as $value) {
                        $filename = $value['filename'];
                        $filename2 = $value['filename2'];
                        $filename3 = $value['filename3'];
                    }

                    $video_source = $value['video_source'];

                    if( $video_source=='mp4_video' ){
                        $videourl=$filename;
                    }else if( $video_source=='youtube_video' ){
                        $videourl=$filename2;
                    }else if( $video_source=='vimeo_video' ){
                        $videourl=$filename3;
                    }                   

                    if($_FILES["imagelogo"]["name"]){
                        $uploads = wp_upload_bits($_FILES["imagelogo"]["name"], null, file_get_contents($_FILES["imagelogo"]["tmp_name"]));
                        $img_name=$uploads['url'];
                    }else{
                        $img_name = $data->ImageLogo;
                    }

                    if($social_enable=='no'){
                        $socialbtn_location='';$sociallock_dur='';$defaulttweet='';$headline_msg='';$share_url='';$custom_url='';
                    }

                    if($share_url=='page_post' || $share_url=='main_blog'){
                        $custom_url='';
                    }

                    if($content_location=='beginning' || $content_location=='end'){
                        $showcontent_dur='';
                    }

                    if($socialbtn_location=='beginning' || $socialbtn_location=='end'){
                        $sociallock_dur='';
                    }

                    $video_content = str_replace('\\','',$video_content);                   
                    $wpdb->insert( $playlist_video_table, array('Title' => $title,'Video' =>$category_groups_json,'VideoSource' =>$video_source,'ImageLogo'=>$img_name,
                    'VideoWidth'=>$videowidth,'VideoHeight'=>$videoheight,'AutoPlay'=>$autoplay,'AllowPause'=>$allowpause,'VideoControls'=>$videocontrols,'VideoAlign'=>$video_align,
                    'ShowContentLocation'=>$content_location,'ShowContentDuration'=>$showcontent_dur, 'VideoContent'=>$video_content,'SocialButtonLocation'=>$socialbtn_location, 'SocialLockDuration'=>$sociallock_dur,
                    'SocialEnable'=>$social_enable,'SocialTitle'=>$socialtitle,'SocialText'=>$socialtext,'DefaultTweet'=>$defaulttweet,'HeadlineMsg'=>$headline_msg,'ShareUrl'=>$share_url,'CustomUrl'=>$custom_url, 'SocialLockAllowSkip'=>$allow_skip));                  

                    $wpdb->query($wpdb->prepare("UPDATE $playlist_video_table  SET Playlist_Id='%d' where id='%d'",$wpdb->insert_id,$wpdb->insert_id));
                    $current_id = $wpdb->insert_id;                  
                }
            }          

            if($_POST['save_action'] == 'tab-2-content') {
                $mailchimpapikey = sanitize_text_field($_POST['mailchimpapikey']);
                $mailchimplistid = sanitize_text_field($_POST['mailchimplistid']);
                $getresponseapikey = sanitize_text_field($_POST['getresponseapikey']);
                $getresponsecampaignid = sanitize_text_field($_POST['getresponsecampaignid']);
                $AWeberListID = sanitize_text_field($_POST['AWeberListID']);
                $sendlaneapikey = sanitize_text_field($_POST['sendlaneapikey']);
                $sendlaneapihashkey = sanitize_text_field($_POST['sendlaneapihashkey']);
                $sendlaneapiurl = sanitize_text_field($_POST['sendlaneapiurl']);
                $sendlanesubdomain = sanitize_text_field($_POST['sendlanesubdomain']);
                $sendlanelistid = sanitize_text_field($_POST['sendlanelistid']);
                $custom_formcode = sanitize_text_field($_POST['custom_formcode']);
                
                $wpdb->insert( $playlist_video_table, array(
                                                        'custom_formcode'=>@$custom_formcode,'MailChimpApiKey'=>@$mailchimpapikey,
                                                        'MailChimpListId'=>@$mailchimplistid,'GetResponseApiKey'=>@$getresponseapikey,
                                                        'GetResponseCampaignId'=>@$getresponsecampaignid,'AWeberListID'=>@$AWeberListID,
                                                        'ConstCntctUserName'=>@$constcntctusername,'ConstCntctAPIKey'=>@$constcntctapikey,
                                                        'ConstCntctSecret'=>@$constcntctsecret,'ConstCntctListID'=>@$constcntctlistid
                ));

                $wpdb->query($wpdb->prepare("UPDATE $playlist_video_table  SET Playlist_Id='%d' where id='%d'",$wpdb->insert_id,$wpdb->insert_id));
                $current_id = $wpdb->insert_id;
            }         

            if($_POST['save_action'] == 'tab-3-content') {
                $inc_optin = sanitize_text_field($_POST['inc_optin']);
                $videomailinglist = sanitize_text_field($_POST['videomailinglist']);
                $optin_location = sanitize_text_field($_POST['optin_location']);
                $optin_mid_time = sanitize_text_field($_POST['optin_mid_time']);
                $optin_headline = sanitize_text_field($_POST['optin_headline']);
                $optin_text = sanitize_text_field($_POST['optin_text']);
                $optin_submit_text = sanitize_text_field($_POST['optin_submit_text']);
                $thankyou_message = sanitize_text_field($_POST['thankyou_message']);
                $allow_skip = sanitize_text_field($_POST['allow_skip']);
                $id = sanitize_text_field($_POST['row_id']);

                if($optin_location=='beginning' || $optin_location=='end'){
                    $optin_mid_time='';
                }

                $wpdb->insert( $playlist_video_table, array('Playlist_Id'=> $Playlist_Id,'OptinBox'=>$inc_optin,'OptinLocation'=>$optin_location,'OptinMidTime'=>$optin_mid_time,'OptinHeadline'=>$optin_headline,
                'OptinText'=>$optin_text,'OptinSubmitText'=>$optin_submit_text,'ThankyouMessage'=>$thankyou_message,'OptinAllowSkip'=>$allow_skip,'VideoMailingList'=>$videomailinglist));
                $wpdb->query($wpdb->prepare("UPDATE $playlist_video_table  SET Playlist_Id='%d' where id='%d'",$wpdb->insert_id,$wpdb->insert_id));
                $current_id = $wpdb->insert_id;
            }           

            if($_POST['save_action'] == 'tab-5-content') {
                $player_skin = sanitize_text_field($_POST['player_skin']);
                $wpdb->insert( $playlist_video_table, array('Playlist_Id'=> $Playlist_Id,'PlayerSkin'=>$player_skin));
                $wpdb->query($wpdb->prepare("UPDATE $playlist_video_table  SET Playlist_Id='%d' where id='%d'",$wpdb->insert_id,$wpdb->insert_id));
                $current_id = $wpdb->insert_id;
            }

            if($_POST['save_action'] == 'tab-6-content') {
                $inc_popup = sanitize_text_field($_POST['inc_popup']);
                $popup_content = $_POST['popup_content'];
                $popup_link = sanitize_text_field($_POST['popup_link']);
                $popup_location = sanitize_text_field($_POST['popup_location']);
                $popup_mid_time = sanitize_text_field($_POST['popup_mid_time']);
                $id = sanitize_text_field($_POST['row_id']);

                if($inc_popup=='no'){
                    $popup_location='';$popup_mid_time='';$popup_content='';$popup_link='';
                }

                if($popup_location=='beginning' || $popup_location=='end'){
                    $popup_mid_time='';
                }

                $wpdb->insert( $playlist_video_table, array(
                                                        'Playlist_Id'=> $Playlist_Id,'Popup'=>$inc_popup,
                                                        'PopupLocation'=>$popup_location,'PopupMidTime'=>$popup_mid_time,
                                                        'PopupContent'=>$popup_content,'PopupLink'=>$popup_link

                ));
                
                $wpdb->query($wpdb->prepare("UPDATE $playlist_video_table SET Playlist_Id='%d' where id='%d'",$wpdb->insert_id,$wpdb->insert_id));
                $current_id = $wpdb->insert_id;
            }

            $status = 'insert';
        }

        $response   =   array(
                            'success' => 1,
                            'message' => __('Playlist Settings have been saved successfully!','mvp'),
                            'status' => $status,
                            'redirect_url' => get_permalink().'?page=mv_player_add_playlist&Playlist_Id='.$current_id
                        );
        echo json_encode( $response ); exit;
    }
}

new WPMVP_Admin( __('MV Player Extension','mvp'),'1.0.0' );