1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
<?php
/*
Connexion à la BDD
*/
require "config/db.cfg.php";
mysql_connect($adresse, $nom, $motdepasse);
mysql_select_db($database);
/*
Affichage d'une news en particulier
*/
if(isset($_GET['id'])) {
$id = intval(htmlentities($_GET['id']));
/*
Si l'id !=0, intval renvoie quelque chose de bon
*/
if($id != 0) {
$sql = 'SELECT * FROM news_' . lang . ' WHERE id='.$id.' ORDER by date DESC';
$req = mysql_query($sql) or die(mysql_error());
$data = mysql_fetch_assoc($req);
echo '<div class="news">';
echo '<h3><b>'.stripslashes($data['titre']).'</b></h3>';
echo '<p class="date_news">Écrit le : '. date("d/m/Y à G:i", strtotime($data['date'])) . ' par '. $data['auteur'].'</p>';
echo '<p>'.nl2br(stripslashes($data['description'])).'</p>';
echo '</div>';
/*
Affichage des commentaire
*/
$sql2 = mysql_query("SELECT COUNT(*) AS nb_comments FROM news_comments WHERE id_billet = ".$id);
$req2 = mysql_fetch_array($sql2);
$nb_comments = $req2['nb_comments'];
if ($nb_comments != 0){
?>
<br /><br /><br /><p>Commentaire</p><br /><?php
} else {}
/*
Récupération des commentaires
*/
$sql = "SELECT * FROM news_comments WHERE id_billet = ".$id. " ORDER by date_commentaire" ;
$req = mysql_query($sql) or die(mysql_error());
while ($donnees = mysql_fetch_assoc($req)) { ?>
<p>
<strong><?php echo htmlspecialchars($donnees['auteur']); ?></strong> le <?php echo $donnees['date_commentaire']; ?>
</p>
<p>
<?php echo nl2br(htmlspecialchars($donnees['commentaire'])); ?>
</p><?php
} ?>
<!--
Formulaire pour ajouter un commentaire
-->
Ajouter un commentaire :<br />
<form method="post" action="admin.php?action=creer">
Nom : <br/><input type="text" name="titre" /><br/>
Contenu :<br/><textarea name="contenu" class="mceEditor"></textarea><br/>
<input type="submit" value="envoyer"/>
</form>
<?php
mysql_close();
} /* La fin du if */
/*
id ==0, intval renvoie certainement qqch de faux
*/
else {
echo "Erreur";
}
}
/*
Listage des news
*/
else {
$limit_par_page = 5; /* Limite des news à afficher par page */
if(isset($_GET['page']))
{
$page = $_GET['page'];
$page = $page - 1;
}
else
{
$page = 0;
}
$from = $page * $limit_par_page;
$sql = "SELECT * FROM news_" . lang . " ORDER by date DESC LIMIT $from,$limit_par_page";
$req = mysql_query($sql) or die(mysql_error());
$resumeNbreCaracteres = 100;
$NbrCol = 2;
$NbreData = mysql_num_rows($req);
$NbrLigne = 0;
if ($NbreData != 0) {
$j = 1; ?>
<b>Actualités</b><br /><br />
<center>
<table class="news_2colonnes">
<?php
while($data = mysql_fetch_assoc($req)) {
if ($j%$NbrCol == 1) {
$NbrLigne++; ?>
<tr>
<?php
$fintr = 0;
} ?>
<td style="vertical-align:top; border :1px; solid #000;">
<div class="news_liste2">
<table style="border: none;">
<tr>
<td>
<b><?php echo stripslashes($data['titre']); ?></b>
</td>
<td style="text-align: right;">
<span style="cursor: default;" title="
<?php
if(isset($data['auteur'])) {
if ($data['auteur'] != '') {
echo "Publiée par ". stripslashes($data['auteur']) . " le ".date("d/m/Y", strtotime($data['date']));
}
}
else {}?>">
<?php echo date("d/m/Y", strtotime($data['date'])); ?>
</span>
</td>
</tr>
<tr>
<td style="text-align: justify;" colspan="2">
<?php
$newsContenuResume = texte_resume(stripslashes($data['description']), $resumeNbreCaracteres);
if ($data['image'] != "") { ?>
<div style="float: left; padding-right: 3px;">
<img src="<?php echo stripslashes($data['image']); ?>" alt="" width="40px" height="40px" style="vertical-align: middle; margin:0; padding: 0;" />
</div><?php
} else {}
echo "<span style=\"text-align: justify\">" . nl2br($newsContenuResume) . "</span>";
?> ...
</td>
</tr>
<tr>
<td>
<a href="<?php $url = ajouterParamLang("news.php?id=".$data['id'],"$paramNom", "$paramValeur"); echo $url; ?>">[<?php echo PAGE_INDEX_TEXT_NEWS_002; ?>]</a>
</td>
<td style="text-align: right;">
<?php
$sql2 = mysql_query("SELECT COUNT(*) AS nb_comments FROM news_comments WHERE id_billet = ".$data['id']);
$req2 = mysql_fetch_array($sql2);
$nb_comments = $req2['nb_comments'];
echo $nb_comments;
?> Commentaire<?php if ($nb_comments > 1){echo "s";} else {} ?>
</td>
</tr>
</table>
</div>
</td>
<?php
if ($j%$NbrCol == 0) { ?>
</tr>
<?php
$fintr = 1;
}
$j++;
} /* La fin du while */
mysql_free_result($req);
if ($fintr!=1) {
echo '</tr>';
} ?>
<tr>
<td></td>
<td>
<div style="text-align: right; padding-right: 3px;">
<?php
/*
Pagination
*/
if (!isset($_GET['id'])) {
$sql2 = mysql_query("SELECT COUNT(*) AS nb_msg FROM news_" .lang);
$donnees2 = mysql_fetch_array($sql2);
$nb_msg = $donnees2['nb_msg'];
$nb_pages = ceil($nb_msg / $limit_par_page);
if (empty($_GET["page"])) {
$num_page=1;
}
else {
$num_page = $_GET["page"];
}
echo "<br />Page : ";
for($page=1;$page<=$nb_pages;$page++) {
if ($nb_pages > 1) {
if ($num_page==1) {
echo " $page";
}
else {
echo " <a href='news.php?page=1' class='page'>1</a>";
}
$pagebefore = $num_page - 1;
if (($pagebefore >= 1) and ($pagebefore < ($nb_pages + 1) )) {
echo " <a href='news.php?page=$pagebefore' class='page'><</a>";
}
if (($num_page != 1) and ($num_page != $nb_pages) and ($num_page < ($nb_pages + 1) )) {
echo " $num_page</a>";
}
$pagenext = $num_page + 1;
if ($pagenext <= $nb_pages) {
echo " <a href='news.php?page=$pagenext' class='page'>></a>";
}
if ($num_page==$nb_pages) {
echo " $nb_pages</a>";
}
else {
echo " <a href='news.php?page=$nb_pages' class='page'>$nb_pages</a>";
}
break;
}
else {
if ($page==$num_page) {
echo "<a href='news.php?page=$page' class='apage'><b>$page</b></a>";
}
else {
echo "<a href='news.php?page=$page' class='page'>$page</a>";
}
}
}
mysql_close();
}
?>
</div>
</td>
</tr>
</table>
</center><?php
}
}
?> |
Partager