Bonjour,
Je viens de terminer la fonction d'envoi pour la messagerie interne de mon site. Le code est valid html, et visiblement la fonction fonctionne parfaitement.
Mais j'aimerais savoir si au niveau du codage il y a pas possibilité de le rendre plus propre.
Merci
Je viens de terminer la fonction d'envoi pour la messagerie interne de mon site. Le code est valid html, et visiblement la fonction fonctionne parfaitement.
Mais j'aimerais savoir si au niveau du codage il y a pas possibilité de le rendre plus propre.
Merci
Code:
<?php
function send() {// Envoyer un message.
global $mysql, $userrow, $controlrow;
include('class/bbcode.php');
$bbcode_inc = new texte();
$page ='<img src="images/bannieres/messagerie.jpg" width="580" height="82" alt="Votre messagerie"><br><br>
<div class="title1"><h1><b>Répondre à un message</b></h1></div><br>';
if(isset($_GET['id'])){
$messagequery = mysql_query(sprintf("SELECT message, subject, for1 FROM %s_messenger WHERE id='%d' LIMIT 1", $mysql->pref, mysql_real_escape_string($_GET['id'])));
$messagerow = mysql_fetch_assoc($messagequery);
if ($userrow['id'] != $messagerow['for1'] or mysql_num_rows($messagequery) == 0) { header("Location: ?do=messenger"); }
$subject = (strpos($messagerow['subject'], 'RE :') === false) ? 'RE : '.$messagerow['subject'] : $messagerow['subject'];
$history = '<br><br><div class="title1"><h1><b>Historique du message</b></h1></div><br>'.$bbcode_inc->ms_format($messagerow['message']);
$last = '\n\n-------------------------\n\n'.$messagerow['message'];
}else{
$history = $subject = $last = null;
}
if (isset($_POST['submit'])) {
$errors = 0;
$errorlist = "";
$playerquery = mysql_query(sprintf("SELECT id, charname, email, email_send FROM %s_users WHERE id='%d' LIMIT 1", $mysql->pref, mysql_real_escape_string($_POST['for1'])));
$playerrow = mysql_fetch_assoc($playerquery);
if (mysql_num_rows($playerquery) == 0) { $errors++; $errorlist .= "- Le destinataire est inconnu.<br>";
}else{
if (preg_match("/[\<>]/", $_POST['content'])==1) { $errors++; $errorlist .= "- Votre message contient des caractères interdits.<br>"; }
if (trim($_POST['subject']) == '') { $errors++; $errorlist .= "- Le sujet du message est exigé.<br>"; }
if (trim($_POST['content']) == '') { $errors++; $errorlist .= "- Le message est exigé.<br>"; }
if (preg_match("/[\<>]/", $_POST['subject'])==1) { $errors++; $errorlist .= "- Votre sujet contient des caractères interdits.<br>"; }
if ($_POST['for1'] == $userrow['id']) { $errors++; $errorlist .= "- Vous ne pouvez pas vous envoyer des messages.<br>"; }
}
if ($errors == 0) {
include('kernel/functions_com.php');
$insert_messenger = mysql_query(sprintf("INSERT INTO %s_messenger SET id='', date='%d', subject='%s', message='%s', for1='%d', from1='%d'",
$mysql->pref,
time(),
mysql_real_escape_string($_POST['subject']),
mysql_real_escape_string($_POST['content'].$last),
mysql_real_escape_string($_POST['for1']),
mysql_real_escape_string($userrow['id'])
));
$page .='Le message vient d\'être envoyé à <b>'.$playerrow['charname'].'</b> !<br><br>Maintenant vous pouvez :<br><br><a href="index.php">» retourner au jeu</a><br><a href="?do=messenger&action=send">» envoyer un autre message</a>';
if($playerrow['email_send'] == 1){
$content ="Bonjour,\n\nUn nouveau message privé intitulé \"".htmlentities(stripcslashes($_POST['subject']))."\", vient d'être posté par ".htmlentities(stripcslashes($userrow['charname']))." dans votre messagerie.\n\nPour y accéder rendez-vous à cette adresse : ".$controlrow['gameurl']."do=messenger .\n\nA bientot sur ".stripslashes($controlrow['gamename'])."!";
mymail($playerrow['email'], stripslashes($controlrow['gamename']).' : un message privé', $content);
}
} else {
$page .= 'Le message n\'a pas pu être envoyé, car les erreur(s) suivante(s) se sont produite(s) :<br><br><span class="alerte">'.$errorlist.'</span><br><br>Maintenant vous pouvez :<br><br><a href="javascript:history.go(-1)">» retourner et réessayer</a><br><a href="index.php">» retourner au jeu</a>';
}
}else{
if(isset($_POST['previsualiser'])) {
$preview = '<td>Prévisualisation :</td><td>'.$bbcode_inc->ms_format($_POST['content']);
$subject = $_POST['subject'];
}else{
$preview = '<td></td><td>';
$_POST = null;
}
$page .='<form enctype="multipart/form-data" action="" method="post" name="post">
<table width="580px" border="0" cellspacing="0" cellpadding="0">
<tr valign="top"><td style="width:110px">Destinataire :</td><td>
<select name="for1">';
$forquery = $mysql->query("SELECT id, charname, authlevel FROM ".$mysql->pref."_users ORDER BY authlevel DESC, charname ASC");
$level = -1;
while ($forrow = mysql_fetch_assoc($forquery))
{
$selectfor = (isset($_GET['for1']) AND $_GET['for1'] == $forrow['id']) ? 'selected="selected"' : null;
if($level!=$forrow['authlevel'])
{
$admin = ($forrow['authlevel'] == 2 ) ? '<optgroup label="Administrateurs">' : null;
$moderator = ($forrow['authlevel'] == 1) ? '</optgroup><optgroup label="Modérateurs">' : null;
$player = ($forrow['authlevel'] == 0) ? '</optgroup><optgroup label="Joueurs">' : null;
$level= $forrow['authlevel'];
}
else
{
$admin=$moderator=$player='';
}
$page .= $admin.$moderator.$player.'<option value="'.$forrow['id'].'" '.$selectfor.'>'.$forrow['charname'].'</option>';
}
mysql_free_result($forquery);
$page.='</optgroup></select><br><br></td></tr>
<tr valign="top"><td>Sujet :</td><td><input type="text" name="subject" size="30" maxlength="50" value="'.$subject.'"><br><br></td></tr>
<tr valign="top"><td style="width:110px">BBcode :</td><td><select class="taille2" onchange="bbfontstyle(\'[color=\' + this.form.couleur.options[this.form.couleur.selectedIndex].value + \']\', \'[/color]\');this.selectedIndex=0;" name="couleur"><option style="color: black;" value="#000000">Couleur</option><option style="color: red;" value="#FF0000">Rouge</option><option style="color: orange;" value="#FFA500">Orange</option><option style="color: yellow;" value="#FFFF00">Jaune</option><option style="color: green;" value="#008000">Vert</option><option style="color: violet;" value="#EE82EE">Violet</option><option style="color: blue;" value="#0000FF">Bleu</option><option style="color: indigo;" value="#4B0082">Indigo</option></select> <select onchange="bbfontstyle(\'[size=\' + this.form.taille.options[this.form.taille.selectedIndex].value + \']\', \'[/size]\')" name="taille"> <option value="9">Très petit</option> <option value="10">Petit</option> <option value=3 selected>Normal</option> <option value="14">Grand</option> <option value="20">Très grand</option></select><input onclick="bbstyle(0)" type="button" value="G" class="taille2" style="font-weight: bold;"> <input onclick="bbstyle(2)" type="button" value="I" class="taille2" style="font-style: italic;"> <input onclick="bbstyle(4)" type="button" value="U" class="taille2" style="text-decoration: underline;"> <input onclick="bbstyle(6)" type="button" value="Url" class="taille2"> <input onclick="bbstyle(8)" type="button" value="Image" class="taille2"></td></tr>
<tr valign="top"><td></td><td style="height:4px"></td></tr>
<tr valign="top"><td></td><td><a href="javascript:emoticon(\':D\')"><img src="images/smileys/sourire.gif" style="border:0" alt=""></a> <a href="javascript:emoticon(\';\)\')"><img src="images/smileys/clin.gif" style="border:0" alt=""></a> <a href="javascript:emoticon(\':\(\')"><img src="images/smileys/triste.gif" style="border:0" alt=""></a> <a href="javascript:emoticon(\':surpris:\')"><img src="images/smileys/yeuxrond.gif" style="border:0" alt=""></a> <a href="javascript:emoticon(\':o\')"><img src="images/smileys/etonne.gif" style="border:0" alt=""></a> <a href="javascript:emoticon(\':confus:\')"><img src="images/smileys/confus.gif" style="border:0" alt=""></a> <a href="javascript:emoticon(\':lol:\')"><img src="images/smileys/lol.gif" style="border:0" alt=""></a> <a href="javascript:emoticon(\':fire:\')"><img src="images/smileys/flame.gif" style="border:0" alt=""></a> <a href="javascript:emoticon(\':splif:\')"><img src="images/smileys/petard.gif" style="border:0" alt=""></a> <a href="javascript:emoticon(\':bigsmile:\')"><img src="images/smileys/green.gif" style="border:0" alt=""></a> <a href="javascript:emoticon(\':x\')"><img src="images/smileys/mad.gif" style="border:0" alt=""></a> <a href="javascript:emoticon(\':roll:\')"><img src="images/smileys/rolleyes.gif" style="border:0" alt=""></a> <a href="javascript:emoticon(\':bigcry:\')"><img src="images/smileys/crying.gif" style="border:0" alt=""></a> <a href="javascript:emoticon(\':colere:\')"><img src="images/smileys/colere.gif" style="border:0" alt=""></a> <a href="javascript:emoticon(\':P\')"><img src="images/smileys/razz.gif" style="border:0" alt=""></a> <a href="javascript:emoticon(\'8\)\')"><img src="images/smileys/lunettes.gif" style="border:0" alt=""></a> <a href="javascript:emoticon(\':\)\')"><img src="images/smileys/sourire2.gif" style="border:0" alt=""></a> <a href="javascript:emoticon(\':oops:\')"><img src="images/smileys/redface.gif" style="border:0" alt=""></a><br><br></td></tr>
<tr valign="top"><td>Message :</td><td><textarea name="content" rows="5" cols="54">'.$_POST['content'].'</textarea><br><br></td></tr>
<tr valign="top"><td></td><td><input type="submit" name="submit" value="Envoyer"> <input type="button" value="Retour" OnClick="javascript:location=\'index.php\'"> <input type="submit" name="previsualiser" value="Prévisualiser"><br><br></td></tr>
<tr valign="top">'.$preview.'</td></tr>
</table>
</form>
'.$history;
}
display($page, 'Envoyer un message');
}
?>