<?php
 
include("../includes/site_config.php");
include('../session_handler.inc');
include('../error.php');
include('../imagesizer.php');
include('../message.php');
include('../includes/functions.php');
include('paginate.php');
include('../lib/lib.Functions.php');
$option_manager = new OptionManager();
$CONST_MAIL=$option_manager->GetValue('mail');
//include('../ajax.js');



$option_manager = new OptionManager();
$vidcount=$option_manager->GetValue('video_count');
$youcount=$option_manager->GetValue('youtube_count'); 
 

include_once __INCLUDE_CLASS_PATH."/class.Video.php";

$video = new Video();

include_once __INCLUDE_CLASS_PATH."/class.DB.php";

$db = new DB();


include("../includes/tab_functions.js");
$mode=$_GET['mode'];

$chkPrivateyou='N';

if($_REQUEST['chkPrivateyou']=='Y'){

 $chkPrivateyou='Y' ;
}
if($_REQUEST['chkPrivateyou']=='N'){

 $chkPrivateyou='N' ;
}
##############
# Deleting Youtube Video
###########

if(isset($_REQUEST['chkRemoveyou'])){

mysql_query("DELETE from youtube WHERE you_id = '".form_get('chkRemoveyou')."'");

}

#####

if(isset($_REQUEST['youApp'])){

mysql_query("Update youtube set approved='1' WHERE you_id = '".form_get('youApp')."'");

}



$block = ereg("MSIE",$_SERVER['HTTP_USER_AGENT'])?'block':'table-row';

$mode=$_GET['mode'];

$you_count =$db->get_var("SELECT count(*) FROM youtube WHERE you_userid=$Sess_UserId");

if(isset($_REQUEST['Submit_you'])){
if ($you_count < $youcount && !isset($_REQUEST['chkRemoveyou']) && $_REQUEST['tube']!='') {




 $upd= "insert into youtube(you_userid, you_private, youtube_code, you_time) values('$Sess_UserId','$chkPrivateyou' ,'".form_get('tube')."', now()) ";
mysql_query($upd);
$db->query("UPDATE adverts SET adv_approved = '0' WHERE adv_userid = '$Sess_UserId'");
		}
	

/*else{

$upd= "update youtube set you_private='$chkPrivateyou', youtube_code='".$_REQUEST['tube']."'  Where you_userid='$Sess_UserId'";
mysql_query($upd);

$db->query("UPDATE adverts SET adv_approved = '0' WHERE adv_userid = '$Sess_UserId'");
}*/
}
$ret=mysql_query("select * from youtube where approved='0'");
$noyou=mysql_num_rows($ret);
//$ret_you=mysql_fetch_object($ret);

$you_count =$db->get_var("SELECT count(*) FROM youtube WHERE you_userid=$Sess_UserId");

###############@@@@@@@
# End of Youtube Code
######################

$Sess_UserId = $_SESSION['Sess_UserId'];
$Sess_UserName = $_SESSION['Sess_UserName'];

# select advert data

$result = mysql_query("SELECT * FROM adverts WHERE adv_userid=$Sess_UserId",$link);

$TOTAL = mysql_num_rows($result);

# if nothing is returned then show error otherwise get data

if ($TOTAL < 1) {

    $error_message=PRGPICADMIN_ERROR1;

    error_page($error_message,GENERAL_USER_ERROR);

}

if ($mode=='amend') {



        if ($Sess_UserName == '$Sess_UserName') {

            restrict_demo();

        }
$vidname=form_get('vidname');
$_SESSION['vidname'] = $vidname;
    //$chkRemovevid=formGet('chkRemovevid');
 $chkRemovevid=form_get('chkRemovevid');

   // $chkPrivatevid=formGet('chkPrivatevid');
 $vidApp=form_get('vidApp');


    //if (count($chkRemovevid)) {
if (isset($chkRemovevid)) {
       // foreach ( $chkRemovevid as $key=>$value) {
	   
$quePic=mysql_fetch_object(mysql_query("SELECT * from videos LEFT JOIN members on(vid_userid=mem_userid) where vid_id='$chkRemovevid'"));

            $video->InitById($chkRemovevid);

            $video->DeleteVid();
			
send_mail ("$quePic->mem_email", "$CONST_MAIL", "$CONST_COMPANY ".VID_UNAPR, MAIL_UNAPPROVEDVID,$type,"ON");
        //}

    }





   

    // end video

    $video->ClearPrivate($Sess_UserId);
if ($vidApp) {
    //if (count($chkPrivatevid)) {

        //foreach ( $chkPrivatevid as $key=>$value) {

            $video->InitById($vidApp);

            $video->ApproveVid();
			
			
$quePic=mysql_fetch_object(mysql_query("SELECT * from videos LEFT JOIN members on(vid_userid=mem_userid) where vid_id='$vidApp'"));
send_mail ("$quePic->mem_email", "$CONST_MAIL", "$CONST_COMPANY ".VID_APR, MAIL_APPROVEDVID,$type,"ON");

//$src=$_REQUEST['sr'];

    }

	//include("generate_profile.php");

}



$aVideos = $video->GetListByVideoApp();


$resultvid = count($aVideos);

$area = 'member';
?>

<?php include("include/header.php"); ?>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);
  return false;
}
//-->

function toggle_youApp(str)
	{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="<?=$CONST_LINK_ROOT?>/media.php";
url=url+"?you="+str;


xmlHttp.onreadystatechange=RegionChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function RegionChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("you_div").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
// -->

</script>
<script type="text/javascript" src="wmvplayer/silverlight.js"></script>
<script type="text/javascript" src="wmvplayer/player.js"></script>

<?php include('approve_menu.php'); ?>

<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;Approve Videos</div></div>
<div class="clear"></div>
<div class="admin-page">
<table width="680" align="<?php print("$CONST_TABLE_ALIGN"); ?>" border="0" cellspacing="0" cellpadding="0">

 

  <tr>

    <td>
	

       <? if($resultvid<1){?>
	   <table width="100%"  border="0" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>" cellspacing="<?php print("$CONST_SUBTABLE_CELLSPACING"); ?>">
	   <tr><td>&nbsp;</td>
 <td  align="left"> <font color="#CC0000" size="+2">Nothing To Approve!</font></td>

 <td align="center"></td>

          </tr></table>

<? }?>

          <?php

   

        print("<br>");

        $indx=0;
		$i=0;
        while ($indx < $resultvid) {

            $indx++;

            $sql_array = array_shift($aVideos);

                $vid_private="";

                if($sql_array->vid_private=='Y') $vid_private="checked";

                $vid_info = $sql_array->getInfo('small');


				

if(($i%3)==0)
	{
	print "<br style=clear:both>";
}

                 print("<div style=float:left;><table border=0 align-left><tr>

                       <!-- <td align='left'>$indx</td>

                        <td><input type='file' name='fuploadvid' size='20' disabled class='inputf'></td>-->

                        <td align='center'>$sql_array->vid_name<br>
					
					

						
						
						
						
							<a href='$CONST_LINK_ROOT/includes/$vid_info->Path'>
						
					<script type='text/javascript' src='swfobject.js'></script>
<script type='text/javascript'>
var s1 = new SWFObject('player.swf','player','400','300','9');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addParam('flashvars','file=$CONST_LINK_ROOT/movies/$sql_array->vid_id.flv');
s1.write('preview');
</script>

						
						
						
						
							
						
					<embed src='$CONST_LINK_ROOT/flvplayer.swf?file=$CONST_LINK_ROOT/movies/$sql_array->vid_id.flv&autoStart=false' width='175' height='175' quality='high' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed>
					
					
						
 
<br><a href='$CONST_LINK_ROOT/admin/approve_videos.php?chkRemovevid=$sql_array->vid_id&mode=amend&type=av' ");?> onclick="javascript:return confirm('Are you sure you want to DELETE')">Delete</a>|
<? print("
<a href='$CONST_LINK_ROOT/admin/approve_videos.php?vidApp=$sql_array->vid_id&mode=amend&sr=$vid_info->Path&type=av'>Approve</a>

<input type='hidden' name='vid_exists[]' value=$sql_array->vid_id>

</td></tr></table></div>
  ");

  $i++;      }

//print "</td></tr><tr><td>";

       
?>

<input type='hidden' name='type' value='v'>
</td></tr></table></div><div class="admin-page-bottom"></div></div>
<br /><br />
<!---->
<!--Approved Video code starts here-->
<!---->
<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;<?=APPROVED_VIDS?></div></div>
<div class="clear"></div>
<div class="admin-page">
<table width="680" align="<?php print("$CONST_TABLE_ALIGN"); ?>" border="0" cellspacing="0" cellpadding="0">
<? //ini_set("display_errors", 1);

 $quer=  "
            SELECT 	*
                      FROM videos
           	                    WHERE approved = '1'
            			                    ORDER BY vid_id DESC
        ";
//$cCount=mysql_num_rows(mysql_query($quer));
$record_per_page='20';

$pager = new PS_Pagination($link,$quer,$record_per_page,5);

$rs = $pager->paginate();



?>
<tr>

    <td>
	<table width="100%"  border="0" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>" cellspacing="<?php print("$CONST_SUBTABLE_CELLSPACING"); ?>">
		<tr><td>&nbsp;</td>

      

          </tr></table>


          <?php

   

        print("<br>");

        $indx=0;
		$k=0;
		while($sql_app=mysql_fetch_object($rs)){
       // while ($indx < $resultvid) {

            $indx++;

            //$sql_app = array_shift($aVideos);

                $vid_private="";

                if($sql_app->vid_private=='Y') $vid_private="checked";

                //$vid_info = $sql_app->getInfo('small');


				

if(($k%3)==0)
	{
	print "<br style=clear:both>";
}

                 print("<div style=float:left;><table border=0 align-left><tr>

                       <!-- <td align='left'>$indx</td>

                        <td><input type='file' name='fuploadvid' size='20' disabled class='inputf'></td>-->

                        <td align='center'>$sql_app->vid_name<br>
					
					

						
						
						
						
							<a href='$CONST_LINK_ROOT/includes/$vid_info->Path'>
						
					<script type='text/javascript' src='swfobject.js'></script>
<script type='text/javascript'>
var s1 = new SWFObject('player.swf','player','400','300','9');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addParam('flashvars','file=$CONST_LINK_ROOT/movies/$sql_app->vid_id.flv');
s1.write('preview');
</script>

						
						
						
						
							
						
					<embed src='$CONST_LINK_ROOT/flvplayer.swf?file=$CONST_LINK_ROOT/movies/$sql_app->vid_id.flv&autoStart=false' width='175' height='175' quality='high' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed>
					
					
						
 
<br> ");?><? if($DEMO==false){?><a href='<?=$CONST_LINK_ROOT?>/admin/approve_videos.php?chkRemovevid=<?=$sql_app->vid_id?>&mode=amend&type=av' onclick="javascript:return confirm('Are you sure you want to DELETE')">Delete</a><? }?>
<? print("
<input type='hidden' name='vid_exists[]' value=$sql_app->vid_id>

</td></tr></table></div>
  ");

  $k++;      }

//print "</td></tr><tr><td>";

       
?>
<?php /*?><br style="clear:both" />
<input type='hidden' name='type' value='v'>

   
<?
	$i=0;
	echo "<br style=clear:both>";	
while($ret_you=mysql_fetch_object($ret)){ 
if(($i%5)==0)
	{
	print "<br style=clear:both>";
}?>
<table border="0" cellpadding="5" cellspacing="5" align="left"><tr>
<td  align="left"><input type="image" src="<?=$SKIN_IMAGE_PATH?>/you.png" border="0"  align="absmiddle" value='<?=$ret_you->you_id?>' onClick='toggle_youApp(this.value);' name='My Youtube' width='100'/><br><a onClick="javascript:return confirm('Are you sure you want to DELETE')" href="<?=$_SERVER['PHP_SELF']?>?chkRemoveyou=<?=$ret_you->you_id ?>&mode=amend&type=av">Delete</a>|<a href='<?=$_SERVER['PHP_SELF']?>?youApp=<?=$ret_you->you_id?>&mode=amend&type=av'>Approve</a></td></tr>	</table>


<?  $i++;}
?>

<br style="clear:both" />
<table border="0"><tr><td>
<div id='you_div'  align='center' style='font-size: 10px;font-weight: bold;color:#0066FF'> </div>
</td></tr></table><?php */?>
</td></tr>

<tr><td align="right"><? echo $pager->renderNext(); ?></td></tr>
</table></div><div class="admin-page-bottom"></div></div>
<!--Code ends here-->
 

<?php include("include/footer.php"); ?>