File: fork.php - Tab length: 1 2 4 8 - Lines: on off - No wrap: on off<?php
/*
** Parties de code � adapter � yN :
** - Appels � mysql_connect et mysql_select_db � ajouter (lignes 106 et 107)
** - Fonctions showCadre (ligne 11) et showError (ligne 47) � remplacer
** - Nom des tables et des champs dans les requ�tes SQL
** --- topics.forum : ID du forum d'appartenance du topic
** --- topics.id : ID du topic
** --- topics.posts : nombre de post dans le topic
** --- topics.title : titre du topic
** --- posts.num : num�ro du post dans le topic (de 0 � N - 1 pour un topic de N posts)
** --- posts.topic : ID du topic auquel appartient le post
** --- last_post.num : num�ro du dernier post lu dans le topic
** --- last_post.topic : ID du topic auquel appartient le post
** - Indexes de la variable $topic (adapter aux noms des champs de la table topics)
*/
?>
<?php function showCadre ($title, $text) { ?>
<?xml version="1.0" encoding="windows-1252"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<meta name="Author" content="yAro" />
<meta name="Description" content="Vous cherchez des forums, un endroit pour discuter ? C'est ici ! Actualit�, blogs, bd, cin�, programmation, jeux vid�o, consoles, calculettes TI, �tudes ... y'a too :) Attention ... addictif ! :D" />
<meta name="Keywords" content="forum,discussion,forums,board,chat,gratuit,free,actualite,news,rss,blogs,blog,journal,chat,discuter,ti89,ti,calculette,console,cuisine,recettes,pocket,gba,gp32,zodiac,n-gage,lynx,nintendo,sega,sony,psp,playstation,atari,aide,informatique,d�panage,jeux,r�tro,retrogaming,videolud�lisme,petite,annonce,petites,annonces,citations,annuaire,selection,multimedia,images,video,musique,dvd,mp3,cin�ma,bd,livres,manga,liens,favoris,hors,sujet,divers,t�l�,tv,real,humour,blagues,newbie,portables,logiciel,windows,web,irc,ressources,webmasters,services,adulte" />
<meta name="Identifier-URL" content="http://www.yaronet.com" />
<meta name="Reply-to" content="webmaster@yaronet.com" />
<meta name="revisit-after" content="15 days" />
<meta name="robots" content="index, follow" />
<title><?php echo $title; ?></title>
<link type='text/css' rel='stylesheet' href='http://www.yaronet.com/v31/defaut/styles.css' />
<link type='text/css' rel='stylesheet' href='http://www.yaronet.com/v31/gfx/global.css' />
<script language="JavaScript" type="text/javascript" src="http://www.yaronet.com/v31/defaut/styles.js"></script>
<script language="JavaScript" type="text/javascript" src="http://www.yaronet.com/xcite.js"></script>
<script language="JavaScript" type="text/javascript" src="http://www.yaronet.com/v31/gfx/js/scripts2.js"></script>
</head>
<body>
<a name='haut'></a>
<div id='bulle' style='position:absolute; visibility: hidden; z-index:3;'></div>
<div id='mylinks' style='top:0;left:0;position:absolute;z-index:1;visibility: hidden; display:inline;'></div>
<script language='JavaScript' type="text/javascript" src='http://www.yaronet.com/bulle.js'></script>
<img src='http://www.yaronet.com/v31/defaut/null.gif' height='10' alt='' />
<div class='cadre'>
<h1>» <?php echo $title; ?></h1>
<br />
<?php echo $text; ?>
</div>
</body>
</html>
<?php } ?>
<?php function showError ($msg, $url = '') { ?>
<?xml version="1.0" encoding="windows-1252"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<meta name="Author" content="yAro" />
<meta name="Description" content="Vous cherchez des forums, un endroit pour discuter ? C'est ici ! Actualit�, blogs, bd, cin�, programmation, jeux vid�o, consoles, calculettes TI, �tudes ... y'a too :) Attention ... addictif ! :D" />
<meta name="Keywords" content="forum,discussion,forums,board,chat,gratuit,free,actualite,news,rss,blogs,blog,journal,chat,discuter,ti89,ti,calculette,console,cuisine,recettes,pocket,gba,gp32,zodiac,n-gage,lynx,nintendo,sega,sony,psp,playstation,atari,aide,informatique,d�panage,jeux,r�tro,retrogaming,videolud�lisme,petite,annonce,petites,annonces,citations,annuaire,selection,multimedia,images,video,musique,dvd,mp3,cin�ma,bd,livres,manga,liens,favoris,hors,sujet,divers,t�l�,tv,real,humour,blagues,newbie,portables,logiciel,windows,web,irc,ressources,webmasters,services,adulte" />
<meta name="Identifier-URL" content="http://www.yaronet.com" />
<meta name="Reply-to" content="webmaster@yaronet.com" />
<meta name="revisit-after" content="15 days" />
<meta name="robots" content="index, follow" />
<link type='text/css' rel='stylesheet' href='http://www.yaronet.com/v31/defaut/styles.css' />
<script language="JavaScript" type="text/javascript" src="http://www.yaronet.com/v31/defaut/styles.js"></script>
<title>Error</title>
</head>
<body>
<a name='haut'></a>
<div id='bulle' style='position:absolute; visibility: hidden; z-index:3;'></div>
<div id='mylinks' style='top:0;left:0;position:absolute;z-index:1;visibility: hidden; display:inline;'></div>
<script language='JavaScript' type='text/javascript' src='http://www.yaronet.com/bulle.js'></script>
<img src='http://www.yaronet.com/v31/defaut/null.gif' height='10' alt='' />
<div class='error'>
<h1><!\ Erreur</h1>
<br />
<br />
<?php echo $msg; ?><br />
<br />
<a href='<?php echo $url; ?>'>
<img src='http://www.yaronet.com/v31/defaut/okw.gif' alt='OK' title='OK' />
</a>
</div>
<br />
</body>
</html>
<?php } ?>
<?php
if (!is_numeric ($_GET['s']) || !is_numeric ($_GET['p1']))
{
header ('Location: index.php');
exit (0);
}
/*
mysql_connect (...);
mysql_select_db (...);
*/
if (!($handle = mysql_query ('SELECT forum, id, posts, title FROM topics WHERE id = \'' . $_GET['s'] . '\''))
|| !($topic = mysql_fetch_assoc ($handle)))
showError ('Le sujet n�' . $_GET['s'] . ' n\'a pas �t� trouv�.');
else if ($_GET['p1'] < 0 || $_GET['p1'] >= $topic['posts'])
showError ('Le num�ro du premier post � extraire est invalide.');
else if (!is_numeric ($_POST['p2']))
{
$options = '';
for ($i = min ($topic['posts'], $_GET['p1'] + 20); $i > $_GET['p1']; --$i)
$options = '<option value="' . ($i - 1) . '">' . ($i - 1) . '</option>' . $options;
showCadre ('S�parer un sujet', '
<form action="?s=' . $_GET['s'] . '&p1=' . $_GET['p1'] . '" method="post">
<b>Topic � s�parer :</b> ' . htmlentities ($topic['title']) . '<br />
<br />
<b>Premier post :</b> ./' . $_GET['p1'] . '<br />
<br />
<b>Dernier post :</b> ./<select name="p2">' . $options . '</select><br />
<br />
<b>Nouveau titre : </b> <input maxlength="100" name="title" size="50" type="text" value="' . htmlentities ('Fork de "' . $topic['title'] . '"') . '" /><br />
<br />
<input type="submit" value="S�parer le topic" />
</form>');
}
else if ($_POST['p2'] < $_GET['p1'] || $_POST['p2'] >= $topic['posts'])
showError ('Le num�ro du dernier post � extraire est invalide.');
else
{
$p1 = $_GET['p1'];
$p2 = $_POST['p2'];
// Cr�e le nouveau topic
mysql_query ('INSERT INTO topics (forum, title) VALUES (\'' . $topic['forum'] . '\', \'' . mysql_real_escape_string ($_POST['title']) . '\'') or die;
$id = mysql_insert_id ();
// Affecte les posts fork�s au nouveau topic
mysql_query ('UPDATE posts SET topic = \'' . $id . '\' WHERE topic = \'' . $topic['id'] . '\' AND num >= \'' . $p1 . '\' AND NUM <= \'' . $p2 . '\'');
// Corrige la num�rotation des posts dans le nouveau topic
mysql_query ('UPDATE posts SET num = (num - ' . $p1 . ') WHERE topic = \'' . $id . '\'');
// Corrige la num�rotation des posts dans l'ancien topic
mysql_query ('UPDATE posts SET num = (num - ' . ($p2 - $p1 + 1) . ') WHERE topic = \'' . $topic['id'] . '\' AND num > \'' . $p2 . '\'');
// Corrige les infos sur le dernier post lu dans l'ancien topic
mysql_query ('UPDATE last_post SET num = (num - ' . ($p2 - $p1 + 1) . ') WHERE topic = \'' . $topic['id'] . '\' AND num > \'' . $p2 . '\'');
// FIXME: Post de Boo dans l'ancien topic pour pr�venir du fork et fournir un lien vers le nouveau topic ?
showCadre ('OK !', '
Topic s�par� !
<div style="text-align: center;">
<a href="javascript:window.close();">
<img title="OK" alt="OK" src="http://www.yaronet.com/v31/defaut/okw.gif"/>
</a>
</div>');
}
?>