<?php

function dispAdminMembers () {


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

	get_time();


	$result = getAllMembers();

	$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 e p t v &nbsp m e m b e r s
					</font>
					</b> 

				</td>
				</tr>
	';

	if ($_SESSION["user_right"] == $GLOBALS["ROOT"]) {
		$str .= '
			<tr>
			<td>
				<FORM name="new_user" method="post" action="index.php?section=AdminHome&section_admin=AdminAddMember">
				<INPUT class="button" TYPE="submit" NAME="action" VALUE="  NOUVEAU MEMBRE  "><BR> </TD>
				</FORM>
			</td>
			</tr>
		';
	}


	$str .= '	
		<tr>
		<td bgcolor="#d3d3df">
		<table cellpadding="0" cellspacing="0" width="100%">
			<tr>
			<td>
			<table width="100%" border="0" cellspacing="0" cellpadding="4">
		<TR>
		<td><b>Login</b></td>
		<td><b>Pseudo</b></td>
		<td><b>Statut</b></td>
		<td><b>Droit</b></td>
			
		</TR>
		<TR>
	';


	// FONCTION PORC POUR ORDONNER LES MEMBRES

	$cpt = 4;
	$cpt_member = 1;
	$cpt_ancien = 1;

	while ($member = mysql_fetch_array($result)) {

		if ($member["user_statut"] == "President") {
			$tab[1] = $member["user_id"];
		}
		else if ($member["user_statut"] == "Secretaire") {
			$tab[2] = $member["user_id"];
		}
		else if ($member["user_statut"] == "Tresorier") {
			$tab[3] = $member["user_id"];
		}
		else if ($member["user_statut"] == "Membre") {
			$tab_member[$cpt_member++] = $member["user_id"];
		}
		else if ($member["user_statut"] == "Ancien") {
			$tab_ancien[$cpt_ancien++] = $member["user_id"];
		}
	}


	if ($tab_ancien) {
		for ($cpt_ancien_temp = 1;  $cpt_ancien_temp < $cpt_ancien; $cpt_ancien_temp++)
		{
			$tab_member[$cpt_member++] = $tab_ancien[$cpt_ancien_temp];
		}
	}

	for ($cpt_member = 1;  $tab_member[$cpt_member]; $cpt_member++) {
		$tab[$cpt++] = $tab_member[$cpt_member];
	}


	for ($cpt = 1; $tab[$cpt] || (!$tab[$cpt] && $cpt < 4); $cpt++) {

		while ($tab[$cpt]) {

			$result = getOneUserByID($tab[$cpt]);
			$member = mysql_fetch_array($result);

			$element_id = $member["user_id"];	

			$str .= '
				<tr>
				<td>
					'.$member["user_login"].'
				</td>
				<td>
					<b>'.$member["user_pseudo"].'</b>
				</td>
				<td>';

			$str .= $member["user_statut"];

			if ($_SESSION["user_right"] >= $GLOBALS["EPISUB"]) {
				$str .= '
					</td>
					<td><small>
					'.get_right_name($member["user_right"]).'
					</small></td>
				';
			}
			if ($_SESSION["user_right"] == $GLOBALS["ROOT"] || $member["user_id"] == $_SESSION["user_id"]) {
				$str .= '
					<TD width=10% align=right>
					<FORM name="update_member" method="post" action="index.php?section=AdminHome&section_admin=AdminModifMember&element_id='.$element_id.'">
					<INPUT class="button" TYPE="submit" NAME="action" VALUE="  MODIFIER  "> 
					</FORM>
					</TD>
				';
			}

			if ($_SESSION["user_right"] == $GLOBALS["ROOT"]) {
				$str .= '
					<TD width=10% align=right>
					<FORM name="supp_member" method="post" action="index.php?section=AdminHome&section_admin=AdminDelMember&element_id='.$element_id.'">
					<INPUT class="button" TYPE="submit" NAME="action" VALUE="  SUPPRIMER  ">
					</FORM>
					</TD>
				';
			}

			$str .= '
				</tr>
			';
	
			$cpt++;
		}
	}

// FIN DE LA FONCTION PORC


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


return $str;


}




function	dispAdminAddMember() {

 $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 m e m b e r &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=AddMember&element_id='.$element_id.'">
		    <TABLE CELLSPACING="0" CELLPADDING="10" BORDER="0">
   
			    <TR><TD> Login: </TD>
			    <TD> <INPUT TYPE="text" NAME="member_get_login" VALUE="" SIZE="20" MAXLENGTH="20"> </TD>
			    </TR>
   	 
			    <TR><TD> Pseudo: </TD>
			    <TD> <INPUT TYPE="text" NAME="member_get_pseudo" VALUE="" SIZE="20" MAXLENGTH="20"> </TD>
			    </TR>

			    <TR><TD> Pass: </TD>
			    <TD> <INPUT TYPE="password" NAME="member_get_pass" VALUE="" SIZE="20" MAXLENGTH="20"> </TD>
			    </TR>

			    <TR><TD> Confirmation du Pass: </TD>
			    <TD> <INPUT TYPE="password" NAME="member_get_checkpass" VALUE="" SIZE="20" MAXLENGTH="20"> </TD>
			    </TR>

			    <TR><TD> Mail: </TD>
			    <TD> <INPUT TYPE="text" NAME="member_get_mail" VALUE="" SIZE="30" MAXLENGTH="30"> </TD>
			    </TR>


			    <TR><TD> Num&eacute;ro de t&eacute;l&eacute;phone: </TD>
			    <TD> <INPUT TYPE="text" NAME="member_get_tel" VALUE="" SIZE="10" MAXLENGTH="10"> </TD>
			    </TR>

			    <TR><TD> Date d entr&eacute;e: </TD>
			    <TD> <INPUT TYPE="text" NAME="member_get_date" VALUE="'.$date.'" SIZE="8" MAXLENGTH="10"> </TD>
			    </TR>
    
			    <TR><TD>Statut: </TD>
			    <TD>
			    <TABLE CELLSPACING"0" CELLPADDING="1" BORDER="0">
			   	 <TR> <TD>
				    <select name="member_get_statut">
				    <option value="Membre">Membre</option>
				    <option value="Ancien">Ancien</option>
		';

		//// SELECT IF DISPLAY EACH STATUT IF FREE

		$result_statut = getAnExistingStatut("President");
		$statut = mysql_fetch_array($result_statut);	
		
		if (!$statut) {
			 $str .=  '<option value="President">President</option>';
		}

		$result_statut = getAnExistingStatut("Secretaire");
		$statut = mysql_fetch_array($result_statut);

		if (!$statut) {
			 $str .=  '<option value="Secretaire">Secretaire</option>';
		}
		$result_statut = getAnExistingStatut("Tresorier");
		$statut = mysql_fetch_array($result_statut);

		if (!$statut) {
			 $str .=  '<option value="Tresorier">Tresorier</option>';
		}

		//// END SELECT

		$str .= '
				    </TD></TR>
			    </TABLE>
			    </TD>
			    </TR>

			    <TR><TD>Right: </TD>
			    <TD>
			    <TABLE CELLSPACING"0" CELLPADDING="1" BORDER="0">
			   	 <TR> <TD>
				    <select name="member_get_right">
				    <option value="7">Normal
				    <option value="8">Root
				    </TD></TR>
			    </TABLE>
			    </TD>
			    </TR>

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

    			    <TR><TD>Happy Comment: </TD>
			    <TD>
			    <TEXTAREA rows="3" cols="38" name="member_get_comment" ONFOCUS=""></textarea>
			    </TD>
			    </TR>

			    <TR>
				    <TD>Ajouter à la mailing</TD>
				    <TD>
				    <INPUT TYPE="checkbox" NAME="auto_mailing_member" VALUE = 1 checked> Oui
				    </TD>
			    </TR>


			    <TR>
				    <TD> </TD>
				    <TD> <INPUT class="button" TYPE="submit" NAME="action" VALUE="  INSCRIPTION  "> </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	dispAdminModifMember() {


$element_id =$_GET['element_id'];

$result = getOneUserById($element_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 m e m b e r
			</font>
			</b> 
		</td>
		</tr>					
	<tr>
	<td bgcolor="#d3d3df">
	<table cellpadding="0" cellspacing="0" width="100%">
		<tr>	
	';

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

  $str .= '
    <form name="saisie" method="post" action="index.php?section=AdminHome&section_admin=ModifMember&element_id='.$element_id.'">
	    <TABLE CELLSPACING="0" CELLPADDING="10" BORDER="0">
	   
 		   <TR><TD> Login: </TD>
		    <TD> <INPUT TYPE="text" NAME="member_get_login" VALUE="'.$user["user_login"].'" SIZE="20" MAXLENGTH="20"
			';
			if ($_SESSION["user_right"] != $GLOBALS["ROOT"]) {
				$str .= 'readonly';
			}
			
			$str .= '
			> </TD>
		    </TR>
    
		    <TR><TD> Pseudo: </TD>
		    <TD>  <INPUT TYPE="text" NAME="member_get_pseudo" VALUE="'.$user["user_pseudo"].'" SIZE="20" MAXLENGTH="20"> </TD>
	   	    </TR>	

		    </TR>
		    <TR><TD> Pass: </TD>
		    <TD> <INPUT TYPE="password" NAME="member_get_pass" VALUE="" SIZE="20" MAXLENGTH="20"> </TD>
		    </TR>

		    <TR><TD> Re Pass: </TD>
		    <TD> <INPUT TYPE="password" NAME="member_get_verifpass" VALUE="" SIZE="20" MAXLENGTH="20"> </TD>
		    </TR>

		    <TR><TD> Mail: </TD>
		    <TD> <INPUT TYPE="text" NAME="member_get_mail" VALUE="'.$user["user_mail"].'" SIZE="50" MAXLENGTH="50"> </TD>
		    </TR>

    		    <TR><TD> Tel: </TD>
		    <TD> <INPUT TYPE="text" NAME="member_get_tel" VALUE="'.$user["user_tel"].'" SIZE="10" MAXLENGTH="10"> </TD>
		    </TR>
		';

			
		if ($_SESSION["user_right"] == $GLOBALS["ROOT"]) {
			$str .= '
			    <TR><TD> Date: </TD>
			    <TD> <INPUT TYPE="text" NAME="member_get_date" VALUE="'.$user["user_date"].'" SIZE="8" MAXLENGTH="10"> </TD>
			    </TR>

			    <TR><TD>Statut: </TD>
			    <TD>
			    <TABLE CELLSPACING"0" CELLPADDING="1" BORDER="0">
			   	 <TR> <TD>
				    <select name="member_get_statut">
				    <option value="Membre" '.get_selected_option("Membre",$user["user_statut"]).' >Membre</option>
				    <option value="Ancien" '.get_selected_option("Ancien",$user["user_statut"]).' >Ancien</option>
			';

			//// SELECT IF DISPLAY EACH STATUT BY MEMBER

			$result_statut = getAnExistingStatut("President");
			$statut = mysql_fetch_array($result_statut);
	
			if (!$statut || $statut["user_statut"] == $user["user_statut"]) {
				 $str .=  '<option value="President" '.get_selected_option("President",$user["user_statut"]).' >President</option>';
			}

			$result_statut = getAnExistingStatut("Secretaire");
			$statut = mysql_fetch_array($result_statut);

			if (!$statut || $statut["user_statut"] == $user["user_statut"]) {
				 $str .=  '<option value="Secretaire" '.get_selected_option("Secretaire",$user["user_statut"]).' >Secretaire</option>';
			}

			$result_statut = getAnExistingStatut("Tresorier");
			$statut = mysql_fetch_array($result_statut);

			if (!$statut || $statut["user_statut"] == $user["user_statut"]) {
				 $str .=  '<option value="Tresorier" '.get_selected_option("Tresorier",$user["user_statut"]).' >Tresorier</option>';
			}

			//// END SELECT

			$str .= '
				    </TD></TR>
			    </TABLE>
			    </TD>
			    </TR>

		    <TR><TD>Right:</TD>
		    <TD>
		    <TABLE CELLSPACING"0" CELLPADDING="1" BORDER="0">
			    <TR> <TD>
			    <SELECT name="member_get_right">
			    <option value="1" '.get_selected_option(1,$user["user_right"]).'>Basic</option>
			    <option value="2" '.get_selected_option(2,$user["user_right"]).'>Guest</option>
			    <option value="4" '.get_selected_option(4,$user["user_right"]).'>Epi Register</option>
			    <option value="5" '.get_selected_option(5,$user["user_right"]).'>Reporter</option>
			    <option value="6" '.get_selected_option(6,$user["user_right"]).'>Private Guest</option>
			    <option value="7" '.get_selected_option(7,$user["user_right"]).'>EPTv Member</option>
			    <option value="8" '.get_selected_option(8,$user["user_right"]).'>EPTv Root</option>
			    </TD></TR>
		    </TABLE>
		    </TD>
		    </TR>
		';
		}


		$str .= '

		    <TR><TD>Signature: </TD>
		    <TD> <TEXTAREA rows="3" cols="38" name="member_get_signature" ONFOCUS="">'.$user["user_signature"].'</textarea> </TD>
		    </TR>
		';    



		if ($_SESSION["user_right"] == $GLOBALS["ROOT"]) {
			$str .= '
			    <TR><TD>Happy Comment: </TD>
			    <TD>
			    <TEXTAREA rows="3" cols="38" name="member_get_comment" ONFOCUS="">'.$user["user_comment"].'</textarea>
			    </TD>
			    </TR>
			';
		}

		$str .= '
 		    <TR>
		    	<TD>Ajouter à la mailing</TD>
			<TD>
			<INPUT TYPE="checkbox" NAME="auto_mailing_member" VALUE = 1 '.get_mailing_checkbox($user["user_mailing"]).'> Oui
			</TD>
		    </TR>
	    </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	dispAdminDelMember() {

  $element_id =$_GET['element_id'];

  $result = getOneUserById($element_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 m e m b e r
			</font>
			</b> 
		</td>
		</tr>					
	<tr>
	<td bgcolor="#d3d3df">
	<table cellpadding="0" cellspacing="0" width="100%">
		<tr>	
	';

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

	  $str .= '
	    <form name="saisie" method="post" action="index.php?section=AdminHome&section_admin=DelUser&element_id='.$element_id.'">
	    <TABLE CELLSPACING="0" CELLPADDING="10" BORDER="0">
   
		    <TR><TD> Login: </TD>
		    <TD>'.$user["user_login"].'</TD>
		    </TR>
    
		    <TR><TD> Pseudo: </TD>
		    <TD>
		     ' .$user["user_pseudo"].'
		    </TD>
		    </TR>

		    <TR><TD> Pass: </TD>
		    <TD>
		     ' .$user["user_pass"].'
		    </TD>
		    </TR>

		    <TR><TD> Mail: </TD>
		    <TD>
		     ' .$user["user_mail"].'
		    </TD>
		    </TR>

		    <TR><TD> Tel: </TD>
		    <TD>
		     ' .$user["user_tel"].'
		    </TD>
		    </TR>

		    <TR><TD> Date: </TD>
		    <TD>
		     ' .$user["user_date"].'
		    </TD>
		    </TR>

		    <TR><TD> Statut: </TD>
		    <TD>
		     ' .$user["user_statut"].'
		    </TD>
		    </TR>

		    <TR><TD> Right: </TD>
		    <TD>
		     '.get_right_name($user["user_right"]).' = ' .$user["user_right"].'
		    </TD>
		    </TR>

		    <TR><TD> Signature: </TD>
		    <TD>
		     ' .$user["user_signature"].'
		    </TD>
		    </TR>

		    <TR><TD> Comment: </TD>
		    <TD>
		     ' .$user["user_comment"].'
		    </TD>
		    </TR>

		    <TR><TD> Mailing EPtv: </TD>
		    <TD>
		     ';
		if ($user["user_mailing"] == 1)
			$str .= "Oui";
		else
			$str .= "Non";

		$str .= ' 
		    </TD>
		    </TR>


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

';

return $str;
}

?>