<?
// include_once "admin/file_browser.php";


function dispAdminVideos () {

if ($_SESSION["user_right"] < $GLOBALS["EPTV"] )
{
	return("T'es ouf");
}

	get_time();


$result_prod = getVideosByType("eptvprod");
$result_bonus = getVideosByType("eptvbonus");
$result_adm = getVideosByType("eptv.adm");

	

$str = '
		
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
		<td bgcolor="#000000">
		<table width="100%" border="0" cellspacing="1" cellpadding="2">
			<tr>
			<td>
				<b>
				<font color="#ffffff">
				&nbsp a l l &nbsp v i d e o s
				</font>
				</b> 
			</td>
			</tr>
			<tr>
			   <td width=150>
				<FORM name="new_video" method="post" action="index.php?section=AdminHome&section_admin=AdminAddVideos&vid_id='.$vid_id.'">
				<INPUT class="button" TYPE="submit" NAME="action" VALUE="  NOUVELLE VIDEO  "><BR> </TD>
				</FORM>
			   </td>
			   <td>
				<FORM name="new_video" method="post" action="index.php?section=AdminHome&section_admin=AdminVideosSolos&vid_id='.$vid_id.'">
				<INPUT class="button" TYPE="submit" NAME="action" VALUE="LISTE VIDEOS SOLOS"><BR> </TD>
				</FORM>
			   </td>

			</tr>
		</table>
		</td>
		</tr>
	</table>
	<BR>';







	if (mysql_num_rows($result_prod)) {
		$str .= dispAdminVideosByType($result_prod, "&nbsp;e p t v &nbsp; p r o d u c t i o n");	
	}
	
	if (mysql_num_rows($result_bonus)) {
		$str .= dispAdminVideosByType($result_bonus, "&nbsp;e p t v &nbsp b o n u s");
	}

	if (mysql_num_rows($result_adm)) {
		$str .= dispAdminVideosByType($result_adm, "&nbsp;e p t v . a d m");
	}

return $str;

}




function dispAdminVideosByType($result, $video_type) {
 
	$str = '		
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
		<td bgcolor="#000000">
		<table width="100%" border="0" cellspacing="1" cellpadding="2">
			<tr>
			<td>
				<b>
				<font color="#ffffff">
				'.$video_type.'
				</font>
				</b> 
			</td>
			</tr>
			
			<tr>
			<td bgcolor="#d3d3df">
			<table cellpadding="0" cellspacing="0" width="100%">
				<tr>
				<td>
				<table width="100%" border="0" cellspacing="0" cellpadding="4">

		';

		while ($video = mysql_fetch_array($result)) {
 
			$vid_id = $video["video_id"];

			$str .= dispWhenTendu($video["video_tendu"]);

			$str .= '
		
				<a href="
					'.$video["video_path"].'
					" class="texte_link">
					'.$video["video_name"].'
				</TD><TD>';
			if ($video["video_path_daily"]) {
			$str .= '<a href=\'http://www.eptv.fr/dailymotion.php?q='.$video["video_path_daily"].'\' onclick="return popitup(this, \'EPTV\')" ><img src=\'http://www.dailymotion.com/favicon.ico\' height=15></a>';
			}	
			$str .= '</TD>
				<TD>
					'.$video["video_date"].'
				</TD>
				<TD align=center>
					'.$video["video_size"].' Mo
				</TD>
			';

				if ($video["video_user_id"] == $_SESSION["user_id"] || $_SESSION["user_right"] == $GLOBALS["ROOT"]){
					$str .= '
						<TD width=10% align=right>
							<FORM name="update_video" method="post" action="index.php?section=AdminHome&section_admin=AdminModifVideos&vid_id='.$vid_id.'">
							<INPUT class="small_button" TYPE="submit" NAME="action" VALUE=" MODIF "> 
							</FORM>
						</TD>
						<TD width=10% align=right>
							<FORM name="supp_video" method="post" action="index.php?section=AdminHome&section_admin=AdminDelVideos&vid_id='.$vid_id.'">
							<INPUT class="small_button" TYPE="submit" NAME="action" VALUE=" SUPP ">
							</FORM>	
						</TD>
					';
				}


			$str .= '</TR>';
		}

$str .= '
					</table>
					</td>
					</tr>
				</table>
				</td>
				</tr>
			</table>
			</td>
			</tr>
		</table>
		<br>
	';

	return ($str);

}


function find_reccur_file($rep_def)
{

   $rep = opendir($rep_def);

   while( $file = readdir($rep))
   {
	if($file !='..' && $file !='.' && $file !='')
       	{
		if (is_dir($rep_def.$file))
		{
			$tab_temp = find_reccur_file($rep_def.$file.'/');
			$tab = array_merge($tab, $tab_temp);

		}
		else if (is_file($rep_def.$file))
		{
			$tab[] = $rep_def.$file;
		}
	}

   }

closedir($rep);
return $tab;
}






function dispAdminVideosSolos () {

   $rep_def = "videos/";

   if ($_SESSION["user_right"] < $GLOBALS["REPORTER"] )
   {
	return("T'es ouf");
   }


   // Files on BDD

   $result = getAllVideos();

   while ($video = mysql_fetch_array($result)) {
	$tab_path_bdd[] = $video["video_path"];
   }


   // Files on Serveur

   $tab_path_local = find_reccur_file($rep_def);



   for ($cpt_local = 0; $tab_path_local[$cpt_local]; $cpt_local++)
   {
	for ($cpt_bdd = 0; $tab_path_bdd[$cpt_bdd] && $tab_path_bdd[$cpt_bdd] != $tab_path_local[$cpt_local]; $cpt_bdd++)
	{
		;
	}
	if (!$tab_path_bdd[$cpt_bdd])
	{
		$tab_solo[] = $tab_path_local[$cpt_local];
	}

   }




   $str = '
		
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
		<td bgcolor="#000000">
		<table width="100%" border="0" cellspacing="1" cellpadding="2">
			<tr>
			<td>
				<b>
				<font color="#ffffff">
				&nbsp v i d e o s &nbsp; s o l o s
				</font>
				</b> 
			</td>
			</tr>
						
			<tr>
			<td bgcolor="#d3d3df">
			<table cellpadding="0" cellspacing="0" width="100%">
				<tr>
				<td>
				<table width="100%" border="0" cellspacing="0" cellpadding="4">
				';


				for ($i = 0; $tab_solo[$i]; $i++)
				{
				
			$str .= '

				<TR>

				<TD width = 380>
					'.$tab_solo[$i].'
			 	</TD>

				<TD  align=left>
					<FORM name="update_video" method="post" action="index.php?section=AdminHome&section_admin=AdminAddVideos&vid_path='.$tab_solo[$i].'">
					<INPUT class="small_button" TYPE="submit" NAME="action" VALUE=" Ajouter "> 
					</FORM>
				</TD>

				</TR>
			';

				}

			$str .= '

				</table>
				</td>
				</tr>
			</table>
			</td>
			</tr>
		</table>
		</td>
		</tr>
	</table>
	
   ';




   return $str;

}




function dispAdminAddVideos () {

   $date = get_date();
   $vid_path = "";

   if (isset($_GET['vid_path']))
   {
	$vid_path = $_GET['vid_path'];
   }


 $str = '		
<table width="80%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	<td bgcolor="#000000">
	<table width="100%" border="0" cellspacing="1" cellpadding="2">
		<tr>
		<td>
			<b>
			<font color="#ffffff">
			&nbsp a d d &nbsp v i d e o &nbsp t o &nbsp d a t a b a s e
			</font>
			</b> 
		</td>
		</tr>					
	<tr>
	<td bgcolor="#d3d3df">
	<table cellpadding="0" cellspacing="0" width="100%">
		<tr>	
		    <form name="saisie" method="post" action="index.php?section=AdminHome&section_admin=AddVideo&vid_id='.$vid_id.'">
		    <TABLE CELLSPACING="0" CELLPADDING="10" BORDER="0">


 			    <TR>
			    <TD> Path de la Vid&eacute;o: </TD>
			    <TD>
		';

			if (isset($_REQUEST['file']))
			{
				$str .= '<INPUT TYPE="text" NAME="video_get_path" VALUE="'.$_REQUEST['file'].'" SIZE="50" MAXLENGTH="150">';
			}
			else
			{
				$str .= '<INPUT TYPE="text" NAME="video_get_path" VALUE="'.$vid_path.'" SIZE="50" MAXLENGTH="150">';
			}


		$str .= "
<a href=\"#\" onClick=\"window.open('admin/file_browser.php','_blank','toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0,copyhistory=0,menuBar=0,width=600,height=300');\"> Browser... </a>";

		$str .= '
			    <TR><TD> Path Dailymotion: </TD>
			    <TD> <INPUT TYPE="text" NAME="video_path_daily" VALUE="'.$video_path_daily.'" SIZE="50"> </TD>
			    </TR>
			    
			    <TR>
			    <TD> Nom de la Vid&eacute;o: </TD>
			    <TD> <INPUT TYPE="text" NAME="video_get_name" VALUE="" SIZE="50" MAXLENGTH="52"> </TD>
			    </TR>
    
			';
 

		
$str .='
			    </TD>
			    </TR>
   	 
			    <TR><TD> Date de d&eacute;pot: </TD>
			    <TD> <INPUT TYPE="text" NAME="video_get_date" VALUE="'.$date.'" SIZE="8" MAXLENGTH="10"> </TD>
			    </TR>
    
			    <TR><TD>Cat&eacute;gorie</TD>
			    <TD>
			    <TABLE CELLSPACING"0" CELLPADDING="1" BORDER="0">
			   	 <TR> <TD>
				    <select name="video_type">
				    <option value="eptvprod">EPTv Production</option>
				    <option value="eptv.adm">EPTv.Adm</option>
				    <option value="eptvbonus">EPTv Bonus</option>
				    </TD></TR>
			    </TABLE>
			    </TD>
			    </TR>

			    <TR><TD>Commentaire: </TD>
			    <TD>
			    <TEXTAREA rows="3" cols="38" name="video_comment" ONFOCUS=""></textarea>
			    </TD>
			    </TR>
    
			    <TR><TD>Groupe Vid&eacute;o</TD>
			    <TD>
			    <TABLE CELLSPACING"0" CELLPADDING="1" BORDER="0">
				<TR> <TD>
				    <select name="video_tendu">
				    <option value=0>Public</option>
				    <option value=1>Tendu</option>
				    <option value=2>Priv&eacute;e</option>
				</TD></TR>
			    </TABLE>
			    </TD>
			    </TR>

			    <TR>
				    <TD>News</TD>
				    <TD>
				    <INPUT TYPE="checkbox" NAME="auto_www_news" VALUE = 1 checked> Poster une news automatique sur le site. (nom de la vid&eacute;o + date + commentaire + groupe)
				    </TD>
			    </TR>

			    <TR>
				    <TD> </TD>
				    <TD> <INPUT class="button" TYPE="submit" NAME="action" VALUE="  UPLOADER  "> </TD>
			    </TR>
			    <TR>
			 	   <TD> </TD>
				   <TD> <INPUT class="button" TYPE="reset" NAME="action" VALUE=" RESET "> </TD>
			    </TR>
		    </TABLE>
		</FORM>
		</TR>
	</TABLE>
	</TD>
	</TR>
</TABLE>
';


return $str;
}


function dispAdminModifVideos () {
  
$vid_id =$_GET['vid_id'];

$result = getOneVideo($vid_id);

$str = '		
<table width="80%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	<td bgcolor="#000000">
	<table width="100%" border="0" cellspacing="1" cellpadding="2">
		<tr>
		<td>
			<b>
			<font color="#ffffff">
			&nbsp m o d i f y &nbsp v i d e o
			</font>
			</b> 
		</td>
		</tr>					
	<tr>
	<td bgcolor="#d3d3df">
	<table cellpadding="0" cellspacing="0" width="100%">
		<tr>	
	';

  if (mysql_num_rows($result)){
    $video = mysql_fetch_array($result);    
  }

  $str .= '
    <form name="saisie" method="post" action="index.php?section=AdminHome&section_admin=ModifVideo&vid_id='.$vid_id.'">
	    <TABLE CELLSPACING="0" CELLPADDING="10" BORDER="0">
	   

			    <TR>
			    <TD> Path de la Vid&eacute;o: </TD>
			    <TD>
		';

			if (isset($_REQUEST['file']))
			{
				$str .= '<INPUT TYPE="text" NAME="video_get_path" VALUE="'.$_REQUEST['file'].'" SIZE="50" MAXLENGTH="150">';
			}
			else
			{
				$str .= '<INPUT TYPE="text" NAME="video_get_path" VALUE="'.$video["video_path"].'" SIZE="50" MAXLENGTH="150">';
			}


		$str .= "
<a href=\"#\" onClick=\"window.open('admin/file_browser.php','_blank','toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0,copyhistory=0,menuBar=0,width=600,height=300');\"> Browser... </a>";
 
$str .= '
			    <TR><TD> Path Dailymotion: </TD>
			    <TD> <INPUT TYPE="text" NAME="video_path_daily" VALUE="'.$video["video_path_daily"].'" SIZE="50"> </TD>
			    </TR>

 		   <TR><TD> Nom de la Vid&eacute;o: </TD>
		    <TD> <INPUT TYPE="text" NAME="video_get_upname" VALUE="'.$video["video_name"].'" SIZE="50" MAXLENGTH="52"> </TD>
		    </TR>
    
		    <TR><TD> Date de d&eacute;pot: </TD>
		    <TD> <INPUT TYPE="text" NAME="video_get_date" VALUE="'.$video["video_date"].'" SIZE="8" MAXLENGTH="10"> </TD>
		    </TR>
    
		    <TR><TD>Cat&eacute;gorie</TD>
		    <TD>
		    <TABLE CELLSPACING"0" CELLPADDING="1" BORDER="0">
			    <TR> <TD>
			    <select name="video_get_type">
			    <option value="eptvprod" '.get_selected_option("eptvprod",$video["video_type"]).' >EPTv Production</option>
			    <option value="eptv.adm" '.get_selected_option("eptv.adm",$video["video_type"]).' >EPTv.Adm</option>
			    <option value="eptvbonus" '.get_selected_option("eptvbonus",$video["video_type"]).' >EPTv Bonus</option>
			    </TD></TR>
		    </TABLE>
		    </TD>
		    </TR>

		    <TR><TD>Commentaire: </TD>
		    <TD>
		    <TEXTAREA rows="3" cols="38" name="video_get_comment" ONFOCUS="">'.$video["video_comment"].'</textarea>
		    </TD>
		    </TR>
    
		    <TR><TD>Groupe Vid&eacute;o</TD>
		    <TD>
		    <TABLE CELLSPACING"0" CELLPADDING="1" BORDER="0">
			    <TR> <TD>
				    <select name="video_get_tendu">
				    <option value="0" '.get_selected_option(0, $video["video_tendu"]).' >Public</option>
				    <option value="1" '.get_selected_option(1, $video["video_tendu"]).' >Tendu</option>
				    <option value="2" '.get_selected_option(2, $video["video_tendu"]).' >Priv&eacute;e</option>
			    </TD></TR>
	    	    </TABLE>
	    	    </TD>
	    	    </TR>
	';


	$str .= '    
		    <TR><TD>Post&eacute;e par: </TD>
		    <TD>
		    ';

		$id_user = getOneUserById($video["video_user_id"]);

		if (mysql_num_rows($id_user)){
		    $id_user = mysql_fetch_array($id_user);    
		}

		$str .= $id_user["user_pseudo"].'</TD></TR>


	    <TR>
	    <TD> </TD>
	    <TD> <INPUT class="button" TYPE="submit" NAME="action" VALUE="  UPDATE  "> </TD>
	    </TR>
	    <TR>
	    <TD> </TD>
	    <TD> <INPUT class="button" TYPE="reset" NAME="action" VALUE=" RESET "> </TD>
	    </TR>
 
    	</TABLE>
	</FORM>
	</TR>
   </TABLE>
   </TD>
   </TR>
</TABLE>
 
';

return $str;
}


function dispAdminDelVideos () {

  $vid_id =$_GET['vid_id'];

  $result = getOneVideo($vid_id);


$str = '		
<table width="80%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	<td bgcolor="#000000">
	<table width="100%" border="0" cellspacing="1" cellpadding="2">
		<tr>
		<td>
			<b>
			<font color="#ffffff">
			&nbsp d e l e t e &nbsp v i d e o
			</font>
			</b> 
		</td>
		</tr>					
	<tr>
	<td bgcolor="#d3d3df">
	<table cellpadding="0" cellspacing="0" width="100%">
		<tr>	
	';

	  if (mysql_num_rows($result)){
	    $video = mysql_fetch_array($result);    
	  }

	  $str .= '
	    <form name="saisie" method="post" action="index.php?section=AdminHome&section_admin=DelVideo&vid_id='.$vid_id.'">
	    <TABLE CELLSPACING="0" CELLPADDING="10" BORDER="0">
   
		    <TR><TD> Nom de la Vid&eacute;o: </TD>
		    <TD>'.$video["video_name"].'</TD>
		    </TR>
    
		    <TR>
		    <TD> Path de la Vid&eacute;o: </TD>
		    <TD>
       
		     ' .$video["video_path"].'
      
		    </TD>
		    </TR>
    
		    <TR><TD> Date de d&eacute;pot: </TD>
		    <TD> '.$video["video_date"].' à  '.$video["video_time"] .' </TD>
		    </TR>

		    <TR><TD>Cat&eacute;gorie: </TD>
		    <TD>
		    '.$video["video_type"].'   

		    </TD>
		    </TR>

		    <TR><TD>Commentaire: </TD>
		    <TD>
		    '.$video["video_comment"].'
		    </TD>
		    </TR>
    
		    <TR><TD>Groupe Vid&eacute;o: </TD>
		    <TD>';

		  if ($video["video_tendu"] == 0){
		    $str .= 'Public</TD></TR>';
		  }
		  else if ($video["video_tendu"] == 1){
		    $str .= 'Tendu</TD></TR>';
		  }
		  else if ($video["video_tendu"] == 2){
		    $str .= 'Priv&eacute;e</TD></TR>';
		  }

		$str .= '    
		    <TR><TD>Post&eacute;e par: </TD>
		    <TD>
		    ';

		$id_user = getOneUserById($video["video_user_id"]);

		if (mysql_num_rows($id_user)){
		    $id_user = mysql_fetch_array($id_user);    
		}

		$str .= $id_user["user_pseudo"].'</TD></TR>';

		$str .= '
		    <TR>
		    <TD> </TD>
		    <TD> <INPUT class="button" TYPE="submit" NAME="action" VALUE="  SUPPRIMER  "> </TD>
		    </TR>  
    	</TABLE>
	</FORM>
	</TR>
   </TABLE>
   </TD>
   </TR>
</TABLE>

';

return $str;
}


?>
