<?php

function dispAdminNews () {

$MAX_ADMIN_NEWS = 1000;


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

$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 l l &nbsp n e w s
				</font>
				</b>
			</td>
			</tr>

			<FORM name="new_news" method="post" action="index.php?html=AdminHome&section_admin=AdminAddNews">
   			<TR>
  			<TD><INPUT class="button" TYPE="submit" NAME="action" VALUE="  NOUVELLE NEWS  "><BR> </TD>
			</TR>
 			</FORM>

			<tr>
			<td bgcolor="#303030">
			<table cellpadding="0" cellspacing="0" width="100%">
				<tr>
				<td>
				<table width="100%" border="0" cellspacing="0" cellpadding="4">


				';
$str .=dispAdminAllNews($MAX_ADMIN_NEWS);

$str .= '
				</TR>
				</table>
				</td>
				</tr>
			</table>
			</td>
			</tr>
		</table>
		</td>
		</tr>
	</table>

	';

return $str;
}


function dispAdminAllNews($MAX_NEWS){

	$str = '';

	if ($_SESSION["user_right"] >= $GLOBALS["PRIV_GUEST"] ) {
		$result = getLastNews(2);
	}
	else if ($_SESSION["user_right"] >= $GLOBALS["GUEST"] ) {
		$result = getLastNews(1);
	}
	else {
		$result = getLastNews(0);
	}

	if (mysql_num_rows($result)){
		for ($cpt = 0; $cpt < $MAX_NEWS && $cpt < mysql_numrows($result); $cpt++) {
			$news = mysql_fetch_array($result);

			$news_id = $news["news_id"];
// DISP NEWS TITLE BY TENDU

			$str .= dispAdminWhenTendu($news["news_tendu"]);

			$str .= '
				<b>
				'.$news["news_title"].'
				</b>
				</TD>

				</TR>';

// DISP NEWS CONTENT BY TENDU
			$str .= dispAdminWhenTendu($news["news_tendu"]);


			$str .= '

				<font class="texte_date">
				<small> &nbsp;
				'.$news["news_date"].'
				<br> </font>
				</small>
				<font class="texte_normal">
				<small>
				'.$news["news_comment"].'
				</font>
				</small>
				<br>';


			$result_member = getOneUserByID($news["news_user_id"]);
			$member = mysql_fetch_array($result_member);

			$str .= '<br>Post&eacute; par:
				'.$member["user_pseudo"].'
				</td>';

			if ($news["news_user_id"] == $_SESSION["user_id"] || $_SESSION["user_right"] == $GLOBALS["ROOT"]){
				$str .= '
					<TD width="20%" align="right">
 					 	<FORM name="update_news" method="post" action="index.php?html=AdminHome&section_admin=AdminModifNews&news_id='.$news_id.'">
 					 	<INPUT class="button" TYPE="submit" NAME="action" VALUE="  MODIFIER  ">
  						</FORM>

 						<FORM name="supp_news" method="post" action="index.php?html=AdminHome&section_admin=AdminDelNews&news_id='.$news_id.'">
 						<INPUT class="button" TYPE="submit" NAME="action" VALUE="  SUPPRIMER  ">
						</FORM>
					</TD>
				';
			}

			$str .= '

			</TR>




 			<TR><TD>
  			 <hr width="90%">
			</TD></TR>


		';
		}
	}

	return ($str);
}





function	dispAdminAddNews() {


 $date = get_date();

 $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 n e w s &nbsp t o &nbsp d a t a b a s e
			</font>
			</b>
		</td>
		</tr>
	<tr>
	<td bgcolor="#303030">
	<table cellpadding="0" cellspacing="0" width="100%">
		<tr>
		    <form name="saisie" method="post" action="index.php?html=AdminHome&section_admin=AddNews&news_id='.$news_id.'">
		    <TABLE CELLSPACING="0" CELLPADDING="10" BORDER="0">

			    <TR><TD> Titre de la News: </TD>
			    <TD> <INPUT TYPE="text" NAME="news_get_title" VALUE="" SIZE="50" MAXLENGTH="52"> </TD>
			    </TR>

			    <TR><TD> Date : </TD>
			    <TD> <INPUT TYPE="text" NAME="news_get_date" VALUE="'.$date.'" SIZE="8" MAXLENGTH="10"> </TD>
			    </TR>

			    <TR><TD>Commentaire: </TD>
			    <TD>
			    <TEXTAREA rows="3" cols="38" name="news_get_comment" ONFOCUS=""></textarea>
			    </TD>
			    </TR>

			    <TR><TD>Groupe News</TD>
			    <TD>
			    <TABLE CELLSPACING"0" CELLPADDING="1" BORDER="0">
				<TR> <TD>
				    <select name="news_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> </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	dispAdminModifNews() {



 $news_id =$_GET['news_id'];

 $result = getOneNews($news_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 n e w s
			</font>
			</b>
		</td>
		</tr>
	<tr>
	<td bgcolor="#303030">
	<table cellpadding="0" cellspacing="0" width="100%">
		<tr>
	';

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

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

 		   <TR><TD> News Title: </TD>
		    <TD> <INPUT TYPE="text" NAME="news_get_uptitle" VALUE="'.$news["news_title"].'" SIZE="50" MAXLENGTH="52"> </TD>
		    </TR>

		    <TR><TD> Date: </TD>
		    <TD> <INPUT TYPE="text" NAME="news_get_date" VALUE="'.$news["news_date"].'" SIZE="8" MAXLENGTH="10"> </TD>
		    </TR>

		    <TR><TD>Commentaire: </TD>
		    <TD>
		    <TEXTAREA rows="3" cols="38" name="news_get_comment" ONFOCUS="">'.$news["news_comment"].'</textarea>
		    </TD>
		    </TR>

		    <TR><TD>Groupe News</TD>
		    <TD>
		    <TABLE CELLSPACING"0" CELLPADDING="1" BORDER="0">
		    <TR> <TD>
		    <select name="news">
		    <option value="0">Public</option>
		    <option value="1">Tendu</option>
		    <option value="2">Priv&eacute;e</option>
		    </TD></TR>

		    </TABLE>
		    </TD>
		    </TR>';

			$result_member = getOneUserByID($news["news_user_id"]);
			$member = mysql_fetch_array($result_member);

			$str .= '<TR>
					<TD>Post&eacute;e par:</TD>
					<TD>'.$member["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	dispAdminDelNews() {

$news_id =$_GET['news_id'];

$result = getOneNews($news_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 n e w s
			</font>
			</b>
		</td>
		</tr>
	<tr>
	<td bgcolor="#303030">
	<table cellpadding="0" cellspacing="0" width="100%">
		<tr>
	';

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

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

		    <TR><TD> Titre de la News: </TD>
		    <TD>'.$news["news_title"].'</TD>
		    </TR>

		    <TR><TD> Date: </TD>
		    <TD> '.$news["news_date"].' à  '.$news["news_time"] .' </TD>
		    </TR>

		    <TR><TD>Commentaire: </TD>
		    <TD>
		    '.$news["news_comment"].'
		    </TD>
		    </TR>

		    <TR><TD>Groupe News: </TD>
		    <TD>';

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


		$result_member = getOneUserByID($news["news_user_id"]);
		$member = mysql_fetch_array($result_member);

		$str .= '<TR>
				<TD>Post&eacute; par:</TD>
				<TD>'.$member["user_pseudo"].'</TD>
			</TR>

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

return ($str);
}


?>