<?php

function insert_get_member_series_count($var)
{
        global $conn;
        $query="SELECT count(*) as total FROM videos_series WHERE USERID=$var[USERID]";
        $executequery=$conn->execute($query);
        $results = $executequery->fields[total];
		echo "$results";
}

function insert_get_subscribed_status_series($var)
{
        global $conn;
        $query="SELECT * FROM videos_series_subscribers WHERE SID=$var[SID] AND USERID='$_SESSION[USERID]'";
        $executequery=$conn->execute($query);
		$results = $executequery->getrows();
        $resultscount = count($results);
		if ($resultscount >= 1)
			return "true";
		else
			return "false";
}

function insert_get_name_from_seriesid($var)
{
        global $conn;
        $query="SELECT name FROM videos_series WHERE SID=$var[SID]";
        $executequery=$conn->execute($query);
        $getsid = $executequery->fields[name];
		echo "$getsid";
}

function insert_get_videos_in_series_list($a)
{
        global $conn;
        $query = "SELECT VIDEOID,title FROM videos WHERE SID='$a[SID]' AND public='1' AND active='1'order by VIDEOID desc limit 4";
        $executequery=$conn->execute($query);
        $results=$executequery->getrows();
        return $results;
}

function insert_get_series_created_date($a)
{
	global $conn;
	$query="SELECT date_created FROM videos_series WHERE SID='$a[sid]'";
	$executequery=$conn->execute($query);
	$list=explode('-',$executequery->fields[date_created]);
	print_r($list[2]);print_r('-');
	print_r($list[1]);print_r('-');
	print_r($list[0]);
}

function insert_get_videos_in_series($a)
{
	global $conn;
	$query="SELECT count(*) AS total FROM videos WHERE SID='$a[SID]' AND public='1' AND active='1'";
	$executequery=$conn->execute($query);
	$return=$executequery->fields[total];
	return $return;
}

function insert_get_series_spotlight($a)
{
    global $config,$conn;
	$query = "select * from videos_series where featured='1' order by rand()"; 
	$results = $conn->execute($query);
	$returnthis = $results->getrows();
	return $returnthis;
}

function does_series_exist($a)
{
	global $conn;
    global $config;
    $query="SELECT name FROM videos_series WHERE SID='".mysql_real_escape_string($a)."'";
    $executequery=$conn->execute($query);
    if ($executequery->recordcount()>0)
        return true;
    else
		return false;
}

function insert_return_member_series_count($var)
{
        global $conn;
        $query="SELECT count(*) as total FROM videos_series WHERE USERID='".mysql_real_escape_string($var[USERID])."'";
        $executequery=$conn->execute($query);
        $results = $executequery->fields[total];
		return $results;
}

function insert_get_member_videoseries($var)
{
    global $config,$conn;
	$query = "select * from videos_series WHERE USERID='".mysql_real_escape_string($var[USERID])."' order by name asc"; 
	$results = $conn->execute($query);
	$returnthis = $results->getrows();
	return $returnthis;
}


?>