<?php
	session_start();
	include('database.php');
	DB_connexion(); 
	
	ini_set( 'display_errors', '0');
	error_reporting( 0 );
	
	/*if(!isset($_SESSION['logged']) )
	{		header ('Location: interdiction.php');
	}
	if($_SESSION['logged']== "no")
	{	header ('Location: interdiction.php');
	}*/
	
	if( isset($_POST['titre_topic']) && !empty($_POST['titre_topic']) && isset($_POST['categorie_topic']) && !empty($_POST['categorie_topic']) && isset($_POST['editeur']) && !empty($_POST['editeur'])  ) 
		{

		$titre_topic = mysql_real_escape_string($_POST['titre_topic']); 
		$categorie_topic = mysql_real_escape_string($_POST['categorie_topic']); 
		$editeur = mysql_real_escape_string($_POST['editeur']);
		$user = $_SESSION['user_id']; 
			   
		$sql = "INSERT INTO topics(topic_id, topic_subject, topic_content, topic_date, topic_cat, topic_by)
		VALUES('','$titre_topic','$editeur',NOW(),'$categorie_topic','$user')"; 		
			   
		$result = mysql_query($sql);
		
/*************************** en phase de test : 1 avril 2013 ************/		
			   
			    $element = mysql_insert_id();
			   
				$editeur = mysql_real_escape_string($_POST['editeur']);
		
				$sql = "INSERT INTO posts(post_content, post_date, post_topic, post_by) 
				VALUES ('$editeur' ,
				NOW(),
				" . mysql_real_escape_string($element) . ",
				" . $_SESSION['user_id'] . ")";

				$result = mysql_query($sql);
    	
	}
	
	
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<meta name="Description" content="Site perso,cours,ouvrages" />
<meta name="Keywords" content="WEBSITE perso " />
<meta name="Distribution" content="Global" />
<meta name="Robots" content="" />
<meta http-equiv="Content-Language" content="fr" />
<meta name="rating" content="general" />
<meta name="author" content="Patrice DELPY" />
<meta name="copyright" content="Copyright 2013" />
<meta name="generator" content="Patoche" />
<title>Patoche WEBSITE - 2013 - Template du site - en cours de développemment ...</title>
<!---------------------------------------------------------->	
<?php
		include('include_css_template_commun.php');
		include('include_css.php');
		include('css_tools_skill.php');
		include('include_javascript.php');

?> 

<style type="text/css">
			 
</style>

<script type="text/javascript">
function call_update()
{
	 ajax_routine(); 
	 setTimeout("call_update()", 1000); //appelle la fonction 1 fois par  seconde
}
</script>

<!---------------------------------------------------------->	
</head>

<body>
<!---------------------------------------------------------->	
	<div class="main"> <!-- main -->
<!---------------------------------------------------------->	

          <div class="header">
                <div class="balise_titre">Patoche</div>
                <div class="balise_citation">
                &quot;Etre conscient que l'on est ignorant est un grand pas vers le savoir&quot;
                </div>
          </div> 
 
          <div class="banniere"></div>  

<!---------------------------------------------------------->
<?php
/*	include("include_barre_login.php");
	echo '<div id="box_icon">';
	include("debug_connexion_membre.php");
	echo '</div>';
	include("include_menu.php");*/
	
	echo '<div id="box_infos">';
			include("include_menu.php");
			
			echo '<div id="box_icon2">';
			include("connexion_membre.php");
			echo	'</div>';
			
			echo '<div id="box_icon3">';
			include("include_barre_login.php");
			echo	'</div>';

	echo	'</div>';
	$_SESSION['page_active'] = basename (__FILE__ );
?>
		

<!---------------------------------------------------------->	
            <div class="contenu"> <!-- contenu -->
<!---------------------------------------------------------->	

		<div class="barre_vide"></div>

		<div id="navigation_horizontale">
			<ul class="menu_forum">
			<li class="forum_tag"><a href="forum.php" title="aller à la section">Forum</a></li>
			<li class="categorie_tag"><a href="ajouter_categorie.php" title="aller à la section">Ajouter catégorie</a></li>
			<li class="topic_tag_selected"><a href="ajouter_topic.php" title="aller à la section">Ajouter topic</a></li>
			</ul>
		</div>
		
		<div id="form_ajout_topic">
			
			<form method="post" enctype="multipart/form-data" id="form" action="ajouter_topic.php" onsubmit="return valider_ajouter_categorie(this)">
			 
				<h1>Nouveau topic (sujet)</h1>
				
				<input type="hidden" name="valide_form" id="valide_form" value="" />
				
				<div>
					<label for="titre">Titre</label>
					<input id="titre_topic" name="titre_topic" type="text"  size = "90" value = ""  />
					<span id="statut_titre"></span>
				</div>
				
				<div>
				<label for="titre">Catégorie</label>
				<select name="categorie_topic">
<?php		
				$sql = "SELECT	cat_id,	cat_name, cat_description FROM categories";
				$result = mysql_query($sql);

				echo '<option value=""></option>'; /* premier champ vide*/  
				
				while($row = mysql_fetch_assoc($result))
					{
						echo '<option value="' . $row['cat_id'] . '">' . $row['cat_name'] . '</option>';
					}
?>
				</select>		
				<span id="statut_selection"></span>
				</div>
				
				
				
				<div>
					<label for="description">Description</label> 
					<textarea rows="4" cols="20" id="categorie_description" name="categorie_description"  style="resize: none;" ><?php echo $champ_message; ?></textarea> 
				    <span id="statut_description"></span>
				</div>
				
				<div>
					<input id="send" name="send" type="submit" value="Ajouter"  />
				</div>
				
				</form>
			</div>	

<!---------------------------------------------------------->	
<?php			
    include('include_pied_page.php');
	include('include_publicite.php');
?>
<!---------------------------------------------------------->	
			</div>  <!-- contenu -->
<!---------------------------------------------------------->	
	</div>   <!-- main -->
<!---------------------------------------------------------->	

	<script type="text/javascript">
		call_update()
	</script>

</body>
</html>
