ryxeo-glpi-git / inc / mailing.function.php @ b67d8923
Historique | Voir | Annoter | Télécharger (7,54 ko)
1 | b67d8923 | Eric Seigne | <?php
|
---|---|---|---|
2 | /*
|
||
3 | * @version $Id: mailing.function.php 7763 2009-01-06 18:44:50Z moyo $
|
||
4 | -------------------------------------------------------------------------
|
||
5 | GLPI - Gestionnaire Libre de Parc Informatique
|
||
6 | Copyright (C) 2003-2009 by the INDEPNET Development Team.
|
||
7 | |||
8 | http://indepnet.net/ http://glpi-project.org
|
||
9 | -------------------------------------------------------------------------
|
||
10 | |||
11 | LICENSE
|
||
12 | |||
13 | This file is part of GLPI.
|
||
14 | |||
15 | GLPI is free software; you can redistribute it and/or modify
|
||
16 | it under the terms of the GNU General Public License as published by
|
||
17 | the Free Software Foundation; either version 2 of the License, or
|
||
18 | (at your option) any later version.
|
||
19 | |||
20 | GLPI is distributed in the hope that it will be useful,
|
||
21 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
23 | GNU General Public License for more details.
|
||
24 | |||
25 | You should have received a copy of the GNU General Public License
|
||
26 | along with GLPI; if not, write to the Free Software
|
||
27 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
28 | --------------------------------------------------------------------------
|
||
29 | */
|
||
30 | |||
31 | // ----------------------------------------------------------------------
|
||
32 | // Original Author of file:
|
||
33 | // Purpose of file:
|
||
34 | // ----------------------------------------------------------------------
|
||
35 | |||
36 | if (!defined('GLPI_ROOT')){ |
||
37 | die("Sorry. You can't access directly to this file"); |
||
38 | } |
||
39 | |||
40 | function testMail(){ |
||
41 | global $CFG_GLPI,$LANG; |
||
42 | $mmail=new glpi_phpmailer(); |
||
43 | $mmail->From=$CFG_GLPI["admin_email"]; |
||
44 | $mmail->FromName=$CFG_GLPI["admin_email"]; |
||
45 | $mmail->AddAddress($CFG_GLPI["admin_email"], "GLPI"); |
||
46 | $mmail->Subject="[SUPPORT RYXEO] ".$LANG["mailing"][32]; |
||
47 | $mmail->Body=$LANG["mailing"][31]."\n-- \n".$CFG_GLPI["mailing_signature"]; |
||
48 | |||
49 | if(!$mmail->Send()){ |
||
50 | addMessageAfterRedirect($LANG["setup"][206]); |
||
51 | } else addMessageAfterRedirect($LANG["setup"][205]); |
||
52 | } |
||
53 | |||
54 | function showFormMailingType($type, $profiles) { |
||
55 | global $LANG, $DB; |
||
56 | |||
57 | $options=""; |
||
58 | // Get User mailing
|
||
59 | $query = "SELECT glpi_mailing.FK_item as item, glpi_mailing.ID as ID |
||
60 | FROM glpi_mailing
|
||
61 | WHERE glpi_mailing.type='$type' AND glpi_mailing.item_type='" . USER_MAILING_TYPE . "' |
||
62 | ORDER BY glpi_mailing.FK_item;";
|
||
63 | $result = $DB->query($query); |
||
64 | if ($DB->numrows($result)) |
||
65 | while ($data = $DB->fetch_assoc($result)) { |
||
66 | if (isset($profiles[USER_MAILING_TYPE."_".$data["item"]])) { |
||
67 | unset($profiles[USER_MAILING_TYPE."_".$data["item"]]); |
||
68 | } |
||
69 | switch ($data["item"]) { |
||
70 | case ADMIN_MAILING : |
||
71 | $name = $LANG["setup"][237]; |
||
72 | break;
|
||
73 | case ADMIN_ENTITY_MAILING : |
||
74 | $name = $LANG["setup"][237]." ".$LANG["entity"][0]; |
||
75 | break;
|
||
76 | case ASSIGN_MAILING : |
||
77 | $name = $LANG["setup"][239]; |
||
78 | break;
|
||
79 | case AUTHOR_MAILING : |
||
80 | $name = $LANG["job"][4]; |
||
81 | break;
|
||
82 | case USER_MAILING : |
||
83 | $name = $LANG["common"][34] . " " . $LANG["common"][1]; |
||
84 | break;
|
||
85 | case OLD_ASSIGN_MAILING : |
||
86 | $name = $LANG["setup"][236]; |
||
87 | break;
|
||
88 | case TECH_MAILING : |
||
89 | $name = $LANG["common"][10]; |
||
90 | break;
|
||
91 | case RECIPIENT_MAILING : |
||
92 | $name = $LANG["job"][3]; |
||
93 | break;
|
||
94 | case ASSIGN_ENT_MAILING : |
||
95 | $name = $LANG["financial"][26]; |
||
96 | break;
|
||
97 | case ASSIGN_GROUP_MAILING : |
||
98 | $name = $LANG["setup"][248]; |
||
99 | break;
|
||
100 | case SUPERVISOR_ASSIGN_GROUP_MAILING : |
||
101 | $name = $LANG["common"][64]." ".$LANG["setup"][248]; |
||
102 | break;
|
||
103 | case SUPERVISOR_AUTHOR_GROUP_MAILING : |
||
104 | $name = $LANG["common"][64]." ".$LANG["setup"][249]; |
||
105 | break;
|
||
106 | default :
|
||
107 | $name=" "; |
||
108 | break;
|
||
109 | } |
||
110 | $options.= "<option value='" . $data["ID"] . "'>" . $name . "</option>\n"; |
||
111 | } |
||
112 | // Get Profile mailing
|
||
113 | $query = "SELECT glpi_mailing.FK_item as item, glpi_mailing.ID as ID, glpi_profiles.name as prof |
||
114 | FROM glpi_mailing
|
||
115 | LEFT JOIN glpi_profiles ON (glpi_mailing.FK_item = glpi_profiles.ID)
|
||
116 | WHERE glpi_mailing.type='$type' AND glpi_mailing.item_type='" . PROFILE_MAILING_TYPE . "' |
||
117 | ORDER BY glpi_profiles.name;";
|
||
118 | $result = $DB->query($query); |
||
119 | if ($DB->numrows($result)) |
||
120 | while ($data = $DB->fetch_assoc($result)) { |
||
121 | $options.= "<option value='" . $data["ID"] . "'>" . $LANG["profiles"][22] . " " . $data["prof"] . "</option>\n"; |
||
122 | if (isset($profiles[PROFILE_MAILING_TYPE."_".$data["item"]])) { |
||
123 | unset($profiles[PROFILE_MAILING_TYPE."_".$data["item"]]); |
||
124 | } |
||
125 | } |
||
126 | |||
127 | // Get Group mailing
|
||
128 | $query = "SELECT glpi_mailing.FK_item as item, glpi_mailing.ID as ID, glpi_groups.name as name |
||
129 | FROM glpi_mailing
|
||
130 | LEFT JOIN glpi_groups ON (glpi_mailing.FK_item = glpi_groups.ID)
|
||
131 | WHERE glpi_mailing.type='$type' AND glpi_mailing.item_type='" . GROUP_MAILING_TYPE . "' |
||
132 | ORDER BY glpi_groups.name;";
|
||
133 | $result = $DB->query($query); |
||
134 | if ($DB->numrows($result)) |
||
135 | while ($data = $DB->fetch_assoc($result)) { |
||
136 | $options.= "<option value='" . $data["ID"] . "'>" . $LANG["common"][35] . " " . $data["name"] . "</option>\n"; |
||
137 | if (isset($profiles[GROUP_MAILING_TYPE."_".$data["item"]])) { |
||
138 | unset($profiles[GROUP_MAILING_TYPE."_".$data["item"]]); |
||
139 | } |
||
140 | } |
||
141 | |||
142 | echo "<td class='right'>"; |
||
143 | if (count($profiles)) { |
||
144 | echo "<select name='mailing_to_add_" . $type . "[]' multiple size='5'>"; |
||
145 | |||
146 | foreach ($profiles as $key => $val) { |
||
147 | list ($item_type, $item) = split("_", $key); |
||
148 | echo "<option value='$key'>" . $val . "</option>\n"; |
||
149 | } |
||
150 | echo "</select>"; |
||
151 | } |
||
152 | |||
153 | echo "</td><td class='center'>"; |
||
154 | if (count($profiles)) { |
||
155 | echo "<input type='submit' class=\"submit\" name='mailing_add_$type' value='" . $LANG["buttons"][8] . " >>'>"; |
||
156 | } |
||
157 | echo "<br /><br />"; |
||
158 | if (!empty($options)){ |
||
159 | echo "<input type='submit' class=\"submit\" name='mailing_delete_$type' value='<< " . $LANG["buttons"][6] . "'>"; |
||
160 | } |
||
161 | |||
162 | echo "</td><td>"; |
||
163 | if (!empty($options)){ |
||
164 | echo "<select name='mailing_to_delete_" . $type . "[]' multiple size='5'>"; |
||
165 | echo $options; |
||
166 | echo "</select>"; |
||
167 | } else {
|
||
168 | echo " "; |
||
169 | } |
||
170 | echo "</td>"; |
||
171 | |||
172 | } |
||
173 | |||
174 | function updateMailNotifications($input) { |
||
175 | global $DB; |
||
176 | $type = ""; |
||
177 | $action = ""; |
||
178 | |||
179 | foreach ($input as $key => $val) { |
||
180 | if (!ereg("mailing_to_", $key) && ereg("mailing_", $key)) { |
||
181 | if (preg_match("/mailing_([a-z]+)_([a-z]+)/", $key, $matches)) { |
||
182 | $type = $matches[2]; |
||
183 | $action = $matches[1]; |
||
184 | } |
||
185 | } |
||
186 | } |
||
187 | |||
188 | if (count($input["mailing_to_" . $action . "_" . $type]) > 0) { |
||
189 | foreach ($input["mailing_to_" . $action . "_" . $type] as $val) { |
||
190 | switch ($action) { |
||
191 | case "add" : |
||
192 | list ($item_type, $item) = split("_", $val); |
||
193 | $query = "INSERT INTO glpi_mailing (type,FK_item,item_type) VALUES ('$type','$item','$item_type')"; |
||
194 | $DB->query($query); |
||
195 | break;
|
||
196 | case "delete" : |
||
197 | $query = "DELETE FROM glpi_mailing WHERE ID='$val'"; |
||
198 | $DB->query($query); |
||
199 | break;
|
||
200 | } |
||
201 | } |
||
202 | } |
||
203 | |||
204 | } |
||
205 | |||
206 | |||
207 | /**
|
||
208 | * Determine if email is valid
|
||
209 | * @param $email email to check
|
||
210 | * @return boolean
|
||
211 | */
|
||
212 | function isValidEmail($email="") |
||
213 | { |
||
214 | if( !eregi( "^" . |
||
215 | "[a-zA-Z0-9]+([_\\.-][a-zA-Z0-9]+)*" . //user |
||
216 | "@" .
|
||
217 | "([a-zA-Z0-9]+([\.-][a-zA-Z0-9]+)*)+" . //domain |
||
218 | "\\.[a-zA-Z0-9]{2,}" . //sld, tld |
||
219 | "$", $email) |
||
220 | ) |
||
221 | { |
||
222 | //echo "Erreur: '$email' n'est pas une adresse mail valide!<br>";
|
||
223 | return false; |
||
224 | } |
||
225 | else return true; |
||
226 | } |
||
227 | |||
228 | function isAuthorMailingActivatedForHelpdesk(){ |
||
229 | global $DB,$CFG_GLPI; |
||
230 | |||
231 | if ($CFG_GLPI['mailing']){ |
||
232 | $query="SELECT COUNT(ID) FROM glpi_mailing WHERE type IN ('new','followup','update','finish') |
||
233 | AND item_type = '".USER_MAILING_TYPE."' AND FK_item = '".AUTHOR_MAILING."' ;"; |
||
234 | if ($result=$DB->query($query)){ |
||
235 | if ($DB->result($result,0,0)>0){ |
||
236 | return true; |
||
237 | } |
||
238 | } |
||
239 | } |
||
240 | return false; |
||
241 | } |
||
242 | |||
243 | ?> |