summaryrefslogtreecommitdiff
path: root/beta_old1/app/sendmail.php
blob: e62a4a572d11c3de28cfa7fe5e361757b2877c4c (plain)
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
<?php
require('include/ludo/session_verify.inc.php');
require_once('include/ludo/html_elements.inc.php');
require_once('include/connect.inc.php');



generate_html_doctype_and_head("Envoi de courriel");
echo "<body>\n";
generate_html_divs_menu();
?>
	<div id="sous_menu">
		<p class="arbre">
		&gt; <a href="index.php">Accueil</a>
		&gt; <a href="index.php">R&eacute;unions</a>
		&gt; Envoi de courriel
		</p>
	</div>
<?php generate_html_div_help();
if( isset($_POST['idR']) )
{
	$idR=addslashes($_POST['idR']);
}
else
{
?>
	<div id="errmsg">
		Erreur lors de l'�mission de l'email : Param�tre manquant ou �rron�
	</div></body></html>
<?php
	exit();
}

if( isset($_POST['envoi']) )
{
	include 'include/ludo/config.inc.php';
	
	if ( !isset($_POST['msgObject']) || !isset($_POST['msgText']) || !is_array($_POST['dataParticipants']) )
	{
		$errmsg = "Erreur lors de l'�mission de l'email : Param�tre manquant ou �rron�";
	}
	else
	{
		if ( !isset($CONFIG['automatedMail']) )
		{
			$errmsg = "Erreur lors de l'�mission de l'email : Erreur de configuration par l'administrateur";
		}
		else
		{
			// Potentiellement dangereux...
			$query='SELECT nomP, prenomP, courrielP FROM Personne WHERE idP=\'' . implode("' OR idP='", $_POST['dataParticipants']) . "'";
			//~ echo " DEBUG : QUERY : $query\n";
			$result = mysql_query($query);
			if ( ! $result )
			{
				$errmsg = "Erreur lors de l'�mission de l'email : Erreur de base de donn�es";
			}
			else
			{
				$to=array();
				while ( list($nomP, $prenomP, $courrielP) = mysql_fetch_row($result) )
				{
					$to[]="$nomP $prenomP <$courrielP>";
				}
				$to=implode(', ',$to);
				
				
				if ( ! mail ( $to, urldecode($_POST['msgObject']), wordwrap(urldecode($_POST['msgText']),70), 'From: ' . $CONFIG['automatedMail'] . "\r\n" )	)
				{
					$errmsg = "Erreur lors de l'�mission de l'email : Erreur inconnue";
				}
			}
		}
	}

	if ( isset($errmsg) )
	{
		echo '<div id="errmsg">' . $errmsg .'</div></body></html>';
	}
	else
	{
		echo '<div id="contenu">Le courriel � bien �t� envoy�<br />';
		echo '<a href="details_reunion.php?idR=' . $idR . '">Retour au d�tail de la r�union</a></div></body></html>';
	}
	exit();
}


$result = mysql_query("SELECT idL FROM Reunion WHERE idR='$idR'");
if (mysql_num_rows($result)===1)
{
	list($idL) = mysql_fetch_array($result);
}
else
{
	$errmsg="";
}


	if ( isset($errmsg) )
	{
		echo '<div id="errmsg">' . $errmsg .'</div></body></html>';
		exit();
	}

?>

	<div id="contenu">
		<form id="formmail" action="sendmail.php" method="post" onsubmit="return dataListe('participants','dataParticipants');">
			<table>
				<tbody>
					<tr>
						<td>Contacts disponibles</td>
						<td>&nbsp;</td>
						<td>Destinataires</td>
					</tr>
					<tr>
						<td>
							<select name="contactDispo" size="10" id="contactDispo">
<?php
	$personnes = array();
	$req = 'SELECT P.idP , P.courrielP , P.nomP , P.prenomP FROM Personne P, Appartenir A WHERE P.idP=A.idP AND A.idL=' . $idL;
	$result = mysql_query($req) ;
	
	if (mysql_num_rows($result)>0)
	{
		for($i=0;$i<mysql_num_rows($result);$i++)
		{
			list($idP, $courrielP, $nomP, $prenomP) = mysql_fetch_array($result);
			$personnes[$idP]=array($courrielP, $nomP, $prenomP);
			echo '<option value="'.$idP.'"  ondblclick="addPers(this.form);">';
			echo $nomP . " " . $prenomP;
			echo "</option>\n";
		}
	}

?>
							</select>
						</td>
						<td>
							<input name="AjouterParticipant" id="AjouterParticipant" value="Ajouter" onclick="addPers(this.form);" type="button" />
							<br />
							<br />
							<input name="supprimerParticipant" id="supprimerParticipant" value="Retirer" onclick="removePers(this.form);" type="button" />
						</td>
						<td>
							<select name="participants" size="10" id="participants">
<?php
	foreach( $personnes as $idP=>$p)
	{
		if ( isset($_POST['mail_idP' . $idP] ) )
		{
			echo '<option value="'.$idP.'">';
			echo $p[1] . " " . $p[2];
			echo "</option>\n";
		}
	}
?>
							</select>
						</td>
					</tr>
				</tbody>
			</table>
			<div>
				Modèle :&nbsp;
<?php
	echo '<select name="modelsList" id="modelsList" onchange="loadlist(\'include/ludo/mail_textarea.php?idR=';
	echo $idR . "&amp;model=','modelsList','divMsg');\">\n";
?>
					<option value="empty">Vierge</option>
					<option value="cree">Nouvelle Réunion</option>
					<option value="modif">Réunion modifiée</option>
					<option value="annul">Réunion annulée</option>
					<option value="fixee">Réunion fixée</option>
				</select>
			</div>
			<div>
				Objet :&nbsp;<input name="msgObject" type="text" size="40" value="AWOR : Courriel de notification" />
			</div>
			<div id='divMsg'>
<?php include 'include/ludo/mail_textarea.php'; ?>
			</div>
			<div>
				<?php
					echo '<input name="idR" type="hidden" value="' . $idR . '" />' . "\n";
				?>
				<input name="envoi" type="hidden" value="1" />
				<input type="submit" value="Envoyer" />
			</div>
		</form>
	</div>
<?php generate_html_div_footer(); ?>
	<div id="msg"></div>
</body>
</html>