source: test_server/mail.php@ 651

Last change on this file since 651 was 651, checked in by aleg, 15 years ago

Změněná cesta k GM a Char logům pro realmy 4 a 7.

File size: 17.0 KB
Line 
1<?php
2
3
4require_once("header.php");
5valid_login($action_permission['update']);
6
7//###########################################################################
8// print mail form
9function print_mail_form()
10{
11 global $lang_mail, $output;
12
13 $to = (isset($_GET['to'])) ? $_GET['to'] : NULL;
14 $type = (isset($_GET['type'])) ? $_GET['type'] :"email";
15
16 $output .= "
17 <center>
18 <form action=\"mail.php?action=send_mail\" method=\"post\" name=\"form\">
19 <fieldset style=\"width: 770px;\">
20 <legend>{$lang_mail['mail_type']}</legend>
21 <br />
22 <table class=\"top_hidden\" style=\"width: 720px;\">
23 <tr>
24 <td align=\"left\">{$lang_mail['recipient']}: <input type=\"text\" name=\"to\" size=\"32\" value=\"$to\" maxlength=\"225\" /></td>
25 <td align=\"left\">{$lang_mail['subject']}: <input type=\"text\" name=\"subject\" size=\"32\" maxlength=\"50\" /></td>
26 <td width=\"1\" align=\"right\">
27 <select name=\"type\">";
28 if ($type == "email")
29 $output .= "
30 <option value=\"email\">{$lang_mail['email']}</option>
31 <option value=\"ingame_mail\">{$lang_mail['ingame_mail']}</option>";
32 else
33 $output .= "
34 <option value=\"ingame_mail\">{$lang_mail['ingame_mail']}</option>
35 <option value=\"email\">{$lang_mail['email']}</option>";
36 $output .= "
37 </select>
38 </td>
39 </tr>
40 <tr><td colspan=\"3\"><hr /></td></tr>
41 <tr>
42 <td colspan=\"3\">
43 {$lang_mail['dont_use_both_groupsend_and_to']}
44 </td>
45 </tr>
46 <tr>
47 <td colspan=\"3\">{$lang_mail['group_send']}:
48 <select name=\"group_send\">
49 <optgroup label=\"{$lang_mail['both']}\">
50 <option value=\"gm_level\">{$lang_mail['gm_level']}</option>
51 </optgroup>
52 <optgroup label=\"{$lang_mail['email']}\">
53 <option value=\"locked\">{$lang_mail['locked_accouns']}</option>
54 <option value=\"banned\">{$lang_mail['banned_accounts']}</option>
55 </optgroup>
56 <optgroup label=\"{$lang_mail['ingame_mail']}\">
57 <option value=\"char_level\">{$lang_mail['char_level']}</option>
58 <option value=\"online\">{$lang_mail['online']}</option>
59 </optgroup>
60 </select>
61 <select name=\"group_sign\">
62 <option value=\"=\">=</option>
63 <option value=\"&lt;\">&lt;</option>
64 <option value=\">\">&gt;</option>
65 <option value=\"!=\">!=</option>
66 </select>
67 <input type=\"text\" name=\"group_value\" size=\"20\" maxlength=\"40\" />
68 </td>
69 </tr>
70 <tr><td colspan=\"3\"><hr /></td></tr>
71 <tr>
72 <td colspan=\"3\" align=\"left\">
73 {$lang_mail['attachments']}:
74 </td>
75 </tr>
76 <tr>
77 <td colspan=\"3\" align=\"right\">
78 {$lang_mail['money']} : <input type=\"text\" name=\"money\" value=\"0\" size=\"10\" maxlength=\"10\" />
79 {$lang_mail['item']} : <input type=\"text\" name=\"att_item\" value=\"0\" size=\"10\" maxlength=\"10\" />
80 {$lang_mail['stack']} : <input type=\"text\" name=\"att_stack\" value=\"0\" size=\"10\" maxlength=\"10\" />
81 </td>
82 </tr>
83 <tr>
84 <td colspan=\"3\">
85 </td>
86 </tr>
87 </table>
88 </fieldset>
89 <fieldset style=\"width: 770px;\">
90 <legend>{$lang_mail['mail_body']}</legend>
91 <br /><textarea name=\"body\" rows=\"14\" cols=\"92\"></textarea><br />
92 <br />
93 <table>
94 <tr>
95 <td>";
96 makebutton($lang_mail['send'], "javascript:do_submit()",130);
97 $output .= "
98 </td>
99 </tr>
100 </table>
101 </fieldset>
102 <br />
103 </form>
104 </center>
105";
106}
107
108
109//#############################################################################
110// Send the actual mail(s)
111function send_mail()
112{
113 global $lang_global, $output, $realm_db, $characters_db, $realm_id, $user_name, $from_mail, $mailer_type, $smtp_cfg;
114
115 if ( empty($_POST['body']) || empty($_POST['subject']) || empty($_POST['type']) || empty($_POST['group_sign']) || empty($_POST['group_send']) )
116 {
117 redirect("mail.php?error=1");
118 }
119
120 $sqlr = new SQL;
121 $sqlr->connect($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name']);
122 $sqlc = new SQL;
123 $sqlc->connect($characters_db[$realm_id]['addr'], $characters_db[$realm_id]['user'], $characters_db[$realm_id]['pass'], $characters_db[$realm_id]['name']);
124
125 $body = explode("\n",$_POST['body']);
126 $subject = $sqlc->quote_smart($_POST['subject']);
127
128 if(isset($_POST['to'])&&($_POST['to'] != ''))
129 $to = $sqlc->quote_smart($_POST['to']);
130 else
131 {
132 $to = 0;
133 if(!isset($_POST['group_value'])||$_POST['group_value'] === '')
134 {
135 redirect("mail.php?error=1");
136 }
137 else
138 {
139 $group_value = $sqlc->quote_smart($_POST['group_value']);
140 $group_sign = $sqlc->quote_smart($_POST['group_sign']);
141 $group_send = $sqlc->quote_smart($_POST['group_send']);
142 }
143 }
144
145 $type = addslashes($_POST['type']);
146 $att_gold = $sqlc->quote_smart($_POST['money']);
147 $att_item = $sqlc->quote_smart($_POST['att_item']);
148 $att_stack = $sqlc->quote_smart($_POST['att_stack']);
149
150 switch ($type)
151 {
152 case "email":
153
154 require_once("libs/mailer/class.phpmailer.php");
155 $mail = new PHPMailer();
156 $mail->Mailer = $mailer_type;
157 if ($mailer_type == "smtp")
158 {
159 $mail->Host = $smtp_cfg['host'];
160 $mail->Port = $smtp_cfg['port'];
161 if($smtp_cfg['user'] != '')
162 {
163 $mail->SMTPAuth = true;
164 $mail->Username = $smtp_cfg['user'];
165 $mail->Password = $smtp_cfg['pass'];
166 }
167 }
168
169 $value = NULL;
170 for($i=0;$i<(count($body));$i++)
171 $value .= $body[$i]."\r\n";
172 $body=$value;
173
174 $mail->From = $from_mail;
175 $mail->FromName = $user_name;
176 $mail->Subject = $subject;
177 $mail->IsHTML(true);
178
179 $body = str_replace("\n", "<br />", $body);
180 $body = str_replace("\r", " ", $body);
181 $body = str_replace(array("\r\n", "\n", "\r"), '<br />', $body);
182 $body = preg_replace( "/([^\/=\"\]])((http|ftp)+(s)?:\/\/[^<>\s]+)/i", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $body);
183 $body = preg_replace('/([^\/=\"\]])(www\.)(\S+)/', '\\1<a href="http://\\2\\3" target="_blank">\\2\\3</a>', $body);
184
185 $mail->Body = $body;
186 $mail->WordWrap = 50;
187
188 if($to)
189 {
190 //single Recipient
191 $mail->AddAddress($to);
192 if(!$mail->Send())
193 {
194 $mail->ClearAddresses();
195 redirect("mail.php?error=3&mail_err=".$mail->ErrorInfo);
196 }
197 else
198 {
199 $mail->ClearAddresses();
200 redirect("mail.php?error=2");
201 }
202 }
203 elseif (isset($group_value))
204 {
205 //group send
206 $email_array = array();
207 switch ($group_send)
208 {
209 case "gm_level":
210 $result = $sqlr->query("SELECT email FROM account WHERE gmlevel $group_sign '$group_value'");
211 while($user = $sql->fetch_row($result))
212 {
213 if($user[0] != "") array_push($email_array, $user[0]);
214 }
215 break;
216 case "locked":
217 $result = $sql->query("SELECT email FROM account WHERE locked $group_sign '$group_value'");
218 while($user = $sql->fetch_row($result))
219 {
220 if($user[0] != "")
221 array_push($email_array, $user[0]);
222 }
223 break;
224 case "banned":
225 $que = $sqlr->query("SELECT id FROM account_banned");
226 while ($banned = $sql->fetch_row($que))
227 {
228 $result = $sqlr->query("SELECT email FROM account WHERE id = '$banned[0]'");
229 if($sqlr->result($result, 0, 'email'))
230 array_push($email_array, $sql->result($result, 0, 'email'));
231 }
232 break;
233 default:
234 redirect("mail.php?error=5");
235 break;
236 }
237 foreach ($email_array as $mail_addr)
238 {
239 $mail->AddAddress($mail_addr);
240 if(!$mail->Send())
241 {
242 $mail->ClearAddresses();
243 redirect("mail.php?error=3&mail_err=".$mail->ErrorInfo);
244 }
245 else
246 {
247 $mail->ClearAddresses();
248 }
249 }
250 redirect("mail.php?error=2");
251 }
252 else
253 redirect("mail.php?error=1");
254 break;
255 case "ingame_mail":
256 $value = NULL;
257 for($i=0;$i<(count($body));$i++)
258 $value .= $body[$i]." ";
259 $body=$value;
260 $body = str_replace("\r", " ", $body);
261
262 if($to)
263 {
264 //single Recipient
265 $result = $sqlc->query("SELECT name FROM characters WHERE name = '$to'");
266 if ($sqlc->num_rows($result) == 1)
267 {
268 $receiver = $sqlc->result($result, 0, 'name');
269 $mails = array();
270 array_push($mails, array($receiver, $subject, $body, $att_gold, $att_item, $att_stack));
271 send_ingame_mail($realm_id, $mails);
272 }
273 else
274 {
275 redirect("mail.php?error=4");
276 }
277 redirect("mail.php?error=2");
278 break;
279 }
280 elseif(isset($group_value))
281 {
282 //group send
283 $char_array = array();
284 switch ($group_send)
285 {
286 case "gm_level":
287 $result = $sqlr->query("SELECT id FROM account WHERE gmlevel $group_sign '$group_value'");
288 while($acc = $sqlc->fetch_row($result))
289 {
290 $result_2 = $sqlc->query("SELECT name FROM `characters` WHERE account = '$acc[0]'");
291 while($char = $sqlc->fetch_row($result_2))
292 array_push($char_array, $char[0]);
293 }
294 break;
295 case "online":
296 $result = $sqlc->query("SELECT name FROM `characters` WHERE online $group_sign '$group_value'");
297 while($user = $sqlc->fetch_row($result))
298 array_push($char_array, $user[0]);
299 break;
300 case "char_level":
301 $result = $sqlc->query("SELECT name FROM `characters` WHERE SUBSTRING_INDEX(SUBSTRING_INDEX(`data`, ' ', 35), ' ', -1) $group_sign '$group_value'");
302 while($user = $sqlc->fetch_row($result))
303 array_push($char_array, $user[0]);
304 break;
305 default:
306 redirect("mail.php?error=5");
307 }
308 $mails = array();
309 foreach ($char_array as $receiver)
310 {
311 array_push($mails, array($receiver, $subject, $body, $att_gold, $att_item, $att_stack));
312 }
313 send_ingame_mail($realm_id, $mails);
314 redirect("mail.php?error=2");
315 }
316 break;
317 default:
318 redirect("mail.php?error=1");
319 }
320
321}
322
323
324//##########################################################################################
325//SEND INGAME MAIL BY TELNET
326//
327// Xiong Guoy
328// 2009-08-08
329function send_ingame_mail($realm_id, $massmails)
330{
331 require_once 'libs/telnet_lib.php';
332 global $server, $lang_telnet;
333 $telnet = new telnet_lib();
334
335 //$massmails array format
336 //($to, $subject, $body, $gold = 0, $item = 0, $stack = 1)
337
338 $result = $telnet->Connect($server[$realm_id]['addr'], $server[$realm_id]['telnet_port'], $server[$realm_id]['telnet_user'], $server[$realm_id]['telnet_pass']);
339
340 if (0 == $result)
341 {
342 $mess_str = '';
343 $result = '';
344 foreach($massmails as $mails)
345 {
346 if ($mails[3] && $mails[4])
347 {
348 $mess_str1 = "send money ".$mails[0]." \"".$mails[1]."\" \"".$mails[2]."\" ".$mails[3]."";
349 $telnet->DoCommand($mess_str1, $result1);
350
351 $mess_str .= $mess_str1."<br >";
352 $result .= $result1."";
353
354 $mess_str1 = "send item ".$mails[0]." \"".$mails[1]."\" \"".$mails[2]."\" ".$mails[4].(($mails[5] > 1) ? "[:count".$mails[5]."]" : " ");
355 $telnet->DoCommand($mess_str1, $result1);
356
357 $mess_str .= $mess_str1."<br >";
358 $result .= $result1."";
359 }
360 elseif ($mails[3])
361 {
362 $mess_str1 = "send money ".$mails[0]." \"".$mails[1]."\" \"".$mails[2]."\" ".$mails[3]."";
363 $telnet->DoCommand($mess_str1, $result1);
364
365 $mess_str .= $mess_str1."<br >";
366 $result .= $result1."";
367 }
368 elseif ($mails[4])
369 {
370 $mess_str1 = "send item ".$mails[0]." \"".$mails[1]."\" \"".$mails[2]."\" ".$mails[4].(($mails[5] > 1) ? "[:count".$mails[5]."]" : " ");
371 $telnet->DoCommand($mess_str1, $result1);
372
373 $mess_str .= $mess_str1."<br >";
374 $result .= $result1."";
375 }
376 else
377 {
378 $mess_str1 = "send mail ".$mails[0]." \"".$mails[1]."\" \"".$mails[2]."\"";
379 $telnet->DoCommand($mess_str1, $result1);
380
381 $mess_str .= $mess_str1."<br >";
382 $result .= $result1."";
383 }
384 }
385 $result = str_replace("mangos>","",$result);
386 $result = str_replace(array("\r\n", "\n", "\r"), '<br />', $result);
387 $mess_str .= "<br /><br />".$result;
388 $telnet->Disconnect();
389 }
390 elseif (1 == $result)
391 $mess_str = $lang_telnet['unable'];
392 elseif (2 == $result)
393 $mess_str = $lang_telnet['unknown_host'];
394 elseif (3 == $result)
395 $mess_str = $lang_telnet['login_failed'];
396 elseif (4 == $result)
397 $mess_str = $lang_telnet['not_supported'];
398
399 redirect("mail.php?action=result&error=6&mess=$mess_str");
400
401}
402
403
404//########################################################################################################################
405// InGame Mail Result
406//########################################################################################################################
407//
408// Xiong Guoy
409// 2009-08-08
410// report page for send_ingame_mail
411function result()
412{
413 global $lang_global, $output;
414 $mess = (isset($_GET['mess'])) ? $_GET['mess'] : NULL;
415 $output .= '
416 <center>
417 <br />
418 <table width="400" class="flat">
419 <tr>
420 <td align="left">
421 <br />'.$mess.'<br />';
422 unset($mess);
423 $output .= '
424 </td>
425 </tr>
426 </table>
427 <br />
428 <table width="400" class="hidden">
429 <tr>
430 <td align="center">';
431 makebutton($lang_global['back'], 'javascript:window.history.back()', 130);
432 $output .= '
433 </td>
434 </tr>
435 </table>
436 <br />
437 </center>';
438
439}
440
441
442//########################################################################################################################
443// MAIN
444//########################################################################################################################
445$err = (isset($_GET['error'])) ? $_GET['error'] : NULL;
446
447$output .= "
448 <div class=\"top\">";
449
450$lang_mail = lang_mail();
451$lang_telnet = lang_telnet();
452
453switch ($err)
454{
455 case 1:
456 $output .= "
457 <h1><font class=\"error\">{$lang_global['empty_fields']}</font></h1>";
458 break;
459 case 2:
460 $output .= "
461 <h1><font class=\"error\">{$lang_mail['mail_sent']}</font></h1>";
462 break;
463 case 3:
464 $mail_err = (isset($_GET['mail_err'])) ? $_GET['mail_err'] : NULL;
465 $output .= "
466 <h1><font class=\"error\">{$lang_mail['mail_err']}: $mail_err</font></h1>";
467 break;
468 case 4:
469 $output .= "
470 <h1><font class=\"error\">{$lang_mail['no_recipient_found']}</font></h1>
471 {$lang_mail['use_name_or_email']}";
472 break;
473 case 5:
474 $output .= "
475 <h1><font class=\"error\">{$lang_mail['option_unavailable']}</font></h1>
476 {$lang_mail['use_currect_option']}";
477 break;
478 case 6:
479 $output .= "
480 <h1><font class=\"error\">{$lang_mail['result']}</font></h1>";
481 break;
482 default: //no error
483 $output .= "
484 <h1>{$lang_mail['send_mail']}</h1>";
485}
486unset($err);
487
488$output .= "
489 </div>";
490
491$action = (isset($_GET['action'])) ? $_GET['action'] : NULL;
492
493switch ($action)
494{
495 case "send_mail":
496 send_mail();
497 break;
498 case "result":
499 result();
500 break;
501 default:
502 print_mail_form();
503}
504
505unset($action);
506unset($action_permission);
507unset($lang_telnet);
508unset($lang_mail);
509
510require_once("footer.php");
511
512?>
Note: See TracBrowser for help on using the repository browser.