| 12
 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
 
 | <?php 
if ($_SESSION['right'] != "") {
 
	//on met le formulaire dans une fonction
	function form() {
 
		global $DBprfx,$DBConn,$setting,$send_var;
 
		if (!isset($send_var['article_title'])) $send_var['article_title'] = "";
		if (!isset($send_var['article_text'])) $send_var['article_text'] = "";
 
		?>
		<form action='admin.php?module=postarticle' method='POST' enctype='multipart/form-data' name='post_article'>
		<table border="0" class="texte1">
  		<tr>
  		  <td>Titre:</td>
  		  <td><input value="<?php echo $send_var['article_title']; ?>" type='text' name='titre'></td>
      </tr>
      <tr>
        <td>À paraitre dans l'édition:</td>
        <td>
			<select size='1' name='parent'>
			<option selected="selected" value=""></option><?php
 
			$sql = "SELECT * FROM " . $DBprfx . "edition";
			$edition = mysql_query($sql, $DBConn) or die(mysql_error());
			while ($array = mysql_fetch_array($edition)) {
				$edition_id = mysql_result($edition, $i, 'edition_ID');
				$edition_titre = mysql_result($edition, $i, 'edition_titre');
				$edition_validity = mysql_result($edition, $i, 'edition_validity');
 
				if ($setting['allow_post_on_active_ed'] == "true" or $edition_validity == 0) {
					if ($send_var['article_parent'] == $edition_id) {
						$selected = "selected='selected'";
					} else {
						$selected = "";
					}
					?>
					<option <?php echo $selected; ?> value='<?php echo $edition_id; ?>'><?php echo $edition_titre; ?></option>
					<?php
				}
 
			$i++;
			}
			?>
			</select>
    	  </td>
  		</tr>
		</table> 
 
		<br><div class="texte1">Texte:</div>
      	<!--Btn bb_code--> 
        <?php bb_code_btn("article_text"); ?>
 
		<textarea style="width:500px;height:300px" wrap="virtual" name="article_text"><?php echo $send_var['article_text']; ?></textarea>
        <br>
		<input type='submit' value="Envoyer" name='submit_post_article' />
        <input type="submit" value="Prévisualisation" name="preview" />
		</form><?php
 
 
	}
 
///////////
//PREVIEW//
///////////
 
	//Mode preview
	if (isset($_POST['preview'])) {
 
		$send_var['article_title'] = stripslashes($_POST['titre']);
		$send_var['article_title'] = preg_replace ('/\</is', '<', $send_var['article_title']); //on enlève le HTML.
		$send_var['article_parent'] = $_POST['parent'];
		$send_var['article_text'] = stripslashes($_POST['article_text']);
		$send_var['article_text'] = preg_replace ('/\</is', '<', $send_var['article_text']); //on enlève le HTML.
 
 
		?><strong>Prévisualisation:</strong><br />
        <table class="preview"><tr><td align="left"><?php
 
		//on formate le BBcode
		$article_texte_clean = bbcode_format(remove_html($send_var['article_text']));
 
		?><span class="article_title"><?php echo $send_var['article_title'] ?></span><br>
		  <span class="article_auteur">Par <?php echo get_username($_SESSION['user']) ?></span><br /><br>
		  <span class="article_texte"><?php echo $article_texte_clean; ?></span><?php
 
		?></td></tr></table>
        <br /><br /> 
 
		<?php form();
 
 
////////
//SEND//
////////
 
	//Si le formulaire est envoyé...
	} else if (isset($_POST['submit_post_article'])) {
 
		$send_var['article_title'] = $_POST['titre'];
		$send_var['article_title'] = preg_replace ('/\</is', '<', $send_var['article_title']); //on enlève le HTML.
		$send_var['article_parent'] = $_POST['parent'];
		$send_var['article_text'] = $_POST['article_text'];
		$send_var['article_text'] = preg_replace ('/\</is', '<', $send_var['article_text']); //on enlève le HTML.
 
		//On vérifie si l'article a un titre
		if ($send_var['article_title'] == "") { 
			?><span class="error">Veuillez préciser un titre</span><?php
			form();
 
		//on défini si l'Article est valide ou pas
		} else {
			if ($_SESSION['right'] == 1 or $_SESSION['right'] == 3) {
				$article_validity = "0";
			} else {
				$article_validity = "1";
			}
 
			//on insère dans MySQL
			$sql = 'INSERT INTO ' . $DBprfx . 'article (`article_ID`,`article_titre`,`article_auteur`,`article_parent`,`article_texte`,`article_validity`) 
					  VALUES (\'\','
					   . '\'' . addslashes($send_var['article_title']) . '\',' 
					   . '\'' . $_SESSION['user'] . '\',' 
					   . '\'' . $send_var['article_parent'] . '\',' 
					   . '\'' . addslashes($send_var['article_text']) . '\','
					   . '\'' . $article_validity . '\'
					   )';
 
 
			//echo $send_var['article_parent'];
			$insert = mysql_query($sql, $DBConn) or die(mysql_error());
 
			$last_ID = mysql_insert_id();
 
			$app_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
			$app_url = substr($app_url,0 ,-10);
			$app_url = $app_url."/admin.php?module=articles&do=read&ID=".$last_ID."&from=all";
 
			$date = date('Y-m-d H:i:s');
 
			//on envoie un message aux admins et editeur si demander par ceux-ci et si ce n'est pas un d'eux qui l'a envoyé.
			if ($_SESSION['right'] != 2 && $_SESSION['right'] != 4) {
 
				//Le order by n'est que pour trouver le premier admin
				$sqmail = "SELECT `ID`,`send_email`,`email`,`name` FROM " . $DBprfx . "user WHERE `right` = '2' UNION SELECT `ID`,`send_email`,`email`,`name`  FROM " . $DBprfx . "user WHERE `right` = '4' ORDER BY `ID` ASC";
 
				$mail_to = mysql_query($sqmail, $DBConn) or die(mysql_error());
				$ligne_mail = mysql_fetch_array($mail_to, MYSQL_ASSOC);
				$nb = mysql_num_rows($mail_to);
 
 
				$i = 0;
				while ($array = mysql_fetch_array($mail_to)) {
					$send_email = mysql_result($mail_to, $i, 'send_email');
					$name = mysql_result($mail_to, $i, 'name');
					$email = mysql_result($mail_to, $i, 'email');
 
					//$pomme .= "-";
					 if ($send_email == 1) {
 
 
 
						 $user = get_username($_SESSION['user']);
						 $Subject = "$user vient d'écrire un article pour ".$setting['journal_name'];
					   $EmailBody = "Bonjour $name,\n\n $user a écrit un article pour ".$setting['journal_name'].".\nVous pouvez le consulter à l'adresse suivante: $app_url \n\n Bonne journée\nEnvoyé le: $date";
 
						 mail($name." <".$email.">",$Subject, $EmailBody, "From: ".$setting['journal_name']." <".$ligne_mail['email'].">");
 
					}
 
					$i++;
				}			 
			}
 
			//affiche un message de succes
			?>
            <span class="succes">Votre article  à été créé avec succès!
            <?php
			if ($_SESSION['right'] == 1 or $_SESSION['right'] == 3) {
				?><br>Votre article doit être approuvé par un administrateur avant sa publication<?php
			}
			?></span><br /><br /><a class="retour" href="admin.php?module=articles" title="Retour">Retour</a><?php
		}
 
	} else {
 
		//on affiche le formulaire
		form();
 
 
	}
 
} else { 
	?><span class="error">Vous n'avez pas accès à ce module</span><?php
}
 
?> | 
Partager