/**
  * This function is used to create a new playlist 
  * in add video page without refreshing the page
  * 
  * @param    string    $name 
  * @param    string    $media
  */
 public function hd_ajax_add_playlist($name, $media)
 {
     global $wpdb;
     /** Get name from param */
     $p_name = addslashes(trim($name));
     /** sanitize name and get slug name */
     $p_slugname = sanitize_title($name);
     $p_description = '';
     /** Query to get last palylist order from playlist table */
     $playlist_order = getAllPlaylistCount();
     /** Query to get playlist name from playlist table if the given name is exist */
     $playlistname1 = 'SELECT playlist_name FROM ' . $wpdb->prefix . 'hdflvvideoshare_playlist WHERE playlist_name="' . $p_name . '"';
     $planame1 = $wpdb->get_row($playlistname1);
     /** Check the playlist name is already exist */
     if (count($planame1) > 0) {
         /** Display error message category already exist */
         render_error(__('Failed, category name already exist', APPTHA_VGALLERY)) . $this->get_playlist_for_dbx($media);
         return;
     }
     /** If new playlist name is exist, then create new data */
     if (!empty($p_name)) {
         /** Set palylsit details as array */
         $videoData = array('playlist_name' => $p_name, 'playlist_desc' => $p_description, 'is_publish' => 1, 'playlist_order' => $playlist_order, 'playlist_slugname' => $p_slugname);
         /** Insert the new data array into playlist table */
         $insert_plist = $wpdb->insert($wpdb->prefix . 'hdflvvideoshare_playlist', $videoData);
         /** Check data is insert into database */
         if ($insert_plist != 0) {
             /** Display success message */
             $this->render_message(__('Category', APPTHA_VGALLERY) . ' ' . $name . ' ' . __('added successfully', APPTHA_VGALLERY)) . $this->get_playlist_for_dbx($media);
         }
     }
     /** Return to new videos page */
     return;
 }
 /**
  * Function for add/ update playlist data.
  */
 public function add_playlist()
 {
     global $wpdb;
     /** Check if sttus is exists */
     if (isset($this->_status)) {
         /** Call function to update stauts */
         $this->status_update($this->_playListId, $this->_status);
     }
     /** Check whether to add new playlist */
     if (isset($this->_addnewPlaylist)) {
         /** Get playlistname parameters from request URL */
         $playlistName = filter_input(INPUT_POST, 'playlistname');
         /** Sanitize playlist title */
         $playlist_slugname = sanitize_title($playlistName);
         /** Get ispublish parameters from request URL */
         $playlistPublish = filter_input(INPUT_POST, 'ispublish');
         /** Check given playlist name is exist in playlist table */
         $playlist_slug = $this->_wpdb->get_var('SELECT COUNT(playlist_slugname) FROM ' . $wpdb->prefix . 'hdflvvideoshare_playlist WHERE playlist_slugname LIKE "' . $playlist_slugname . '%"');
         /** Check playlist slug is already exist  */
         if ($playlist_slug > 0) {
             /** If exist then increase count with slug name */
             $playlist_slugname = $playlist_slugname . '-' . intval($playlist_slug + 1);
         }
         /** Store all parameters into single array */
         $playlsitData = array('playlist_name' => $playlistName, 'playlist_slugname' => $playlist_slugname, 'is_publish' => $playlistPublish);
         /**
          * Check whether playlist id is exist
          * If exist, then update records in db, 
          * else insert new record  
          */
         if ($this->_playListId) {
             $updateflag = $this->playlist_update($playlsitData, $this->_playListId);
             /** Redirect to playlist page after updating record */
             $this->redirectPlaylistPage($updateflag, 'update', '');
         } else {
             /** Ordering starts from 0, 
              * so count of playlist is order + 1 value  */
             $ordering = getAllPlaylistCount();
             $playlsitData['playlist_order'] = $ordering;
             /** Insert new playlist into db */
             $addflag = $this->insert_playlist($playlsitData);
             /** Redirect to playlist page once action is done  */
             $this->redirectPlaylistPage($addflag, 'add', '');
         }
     }
 }