1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // | Copyright (C) 2006-2007 Ruben ARNAUD - team@phpwebgallery.net | |
---|
7 | // +-----------------------------------------------------------------------+ |
---|
8 | // | file : $Id: notification_by_mail.php 1900 2007-03-12 22:33:53Z rub $ |
---|
9 | // | last update : $Date: 2007-03-12 22:33:53 +0000 (Mon, 12 Mar 2007) $ |
---|
10 | // | last modifier : $Author: rub $ |
---|
11 | // | revision : $Revision: 1900 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | |
---|
28 | // +-----------------------------------------------------------------------+ |
---|
29 | // | include | |
---|
30 | // +-----------------------------------------------------------------------+ |
---|
31 | |
---|
32 | if (!defined('PHPWG_ROOT_PATH')) |
---|
33 | { |
---|
34 | die ("Hacking attempt!"); |
---|
35 | } |
---|
36 | |
---|
37 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
38 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_notification_by_mail.inc.php'); |
---|
39 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_tabsheet.inc.php'); |
---|
40 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
41 | include_once(PHPWG_ROOT_PATH.'include/functions_notification.inc.php'); |
---|
42 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
43 | |
---|
44 | // +-----------------------------------------------------------------------+ |
---|
45 | // | Check Access and exit when user status is not ok | |
---|
46 | // +-----------------------------------------------------------------------+ |
---|
47 | check_status(ACCESS_ADMINISTRATOR); |
---|
48 | |
---|
49 | // +-----------------------------------------------------------------------+ |
---|
50 | // | Initialization | |
---|
51 | // +-----------------------------------------------------------------------+ |
---|
52 | $base_url = get_root_url().'admin.php'; |
---|
53 | $must_repost = false; |
---|
54 | |
---|
55 | // +-----------------------------------------------------------------------+ |
---|
56 | // | functions | |
---|
57 | // +-----------------------------------------------------------------------+ |
---|
58 | |
---|
59 | /* |
---|
60 | * Do timeout treatment in order to finish to send mails |
---|
61 | * |
---|
62 | * @param $post_keyname: key of check_key post array |
---|
63 | * @param check_key_treated: array of check_key treated |
---|
64 | * @return none |
---|
65 | */ |
---|
66 | function do_timeout_treatment($post_keyname, $check_key_treated = array()) |
---|
67 | { |
---|
68 | global $env_nbm, $base_url, $page, $must_repost; |
---|
69 | |
---|
70 | if ($env_nbm['is_sendmail_timeout']) |
---|
71 | { |
---|
72 | if (isset($_POST[$post_keyname])) |
---|
73 | { |
---|
74 | $post_count = count($_POST[$post_keyname]); |
---|
75 | $treated_count = count($check_key_treated); |
---|
76 | if ($treated_count != 0) |
---|
77 | { |
---|
78 | $time_refresh = ceil((get_moment() - $env_nbm['start_time']) * $post_count / $treated_count); |
---|
79 | } |
---|
80 | else |
---|
81 | { |
---|
82 | $time_refresh = 0; |
---|
83 | } |
---|
84 | $_POST[$post_keyname] = array_diff($_POST[$post_keyname], $check_key_treated); |
---|
85 | |
---|
86 | $must_repost = true; |
---|
87 | array_push($page['errors'], |
---|
88 | l10n_dec('nbm_background_treatment_redirect_second', |
---|
89 | 'nbm_background_treatment_redirect_seconds', |
---|
90 | $time_refresh)); |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | } |
---|
95 | |
---|
96 | /* |
---|
97 | * Get the authorized_status for each tab |
---|
98 | * return corresponding status |
---|
99 | */ |
---|
100 | function get_tab_status($mode) |
---|
101 | { |
---|
102 | $result = ACCESS_WEBMASTER; |
---|
103 | switch ($mode) |
---|
104 | { |
---|
105 | case 'param': |
---|
106 | case 'subscribe': |
---|
107 | $result = ACCESS_WEBMASTER; |
---|
108 | break; |
---|
109 | case 'send': |
---|
110 | $result = ACCESS_ADMINISTRATOR; |
---|
111 | break; |
---|
112 | default: |
---|
113 | $result = ACCESS_WEBMASTER; |
---|
114 | break; |
---|
115 | } |
---|
116 | return $result; |
---|
117 | } |
---|
118 | |
---|
119 | /* |
---|
120 | * Inserting News users |
---|
121 | */ |
---|
122 | function insert_new_data_user_mail_notification() |
---|
123 | { |
---|
124 | global $conf, $page, $env_nbm; |
---|
125 | |
---|
126 | // Set null mail_address empty |
---|
127 | $query = ' |
---|
128 | update |
---|
129 | '.USERS_TABLE.' |
---|
130 | set |
---|
131 | '.$conf['user_fields']['email'].' = null |
---|
132 | where |
---|
133 | trim('.$conf['user_fields']['email'].') = \'\';'; |
---|
134 | pwg_query($query); |
---|
135 | |
---|
136 | // null mail_address are not selected in the list |
---|
137 | $query = ' |
---|
138 | select |
---|
139 | u.'.$conf['user_fields']['id'].' as user_id, |
---|
140 | u.'.$conf['user_fields']['username'].' as username, |
---|
141 | u.'.$conf['user_fields']['email'].' as mail_address |
---|
142 | from |
---|
143 | '.USERS_TABLE.' as u left join '.USER_MAIL_NOTIFICATION_TABLE.' as m on u.'.$conf['user_fields']['id'].' = m.user_id |
---|
144 | where |
---|
145 | u.'.$conf['user_fields']['email'].' is not null and |
---|
146 | m.user_id is null |
---|
147 | order by |
---|
148 | user_id;'; |
---|
149 | |
---|
150 | $result = pwg_query($query); |
---|
151 | |
---|
152 | if (mysql_num_rows($result) > 0) |
---|
153 | { |
---|
154 | $inserts = array(); |
---|
155 | $check_key_list = array(); |
---|
156 | |
---|
157 | while ($nbm_user = mysql_fetch_array($result)) |
---|
158 | { |
---|
159 | // Calculate key |
---|
160 | $nbm_user['check_key'] = find_available_check_key(); |
---|
161 | |
---|
162 | // Save key |
---|
163 | array_push($check_key_list, $nbm_user['check_key']); |
---|
164 | |
---|
165 | // Insert new nbm_users |
---|
166 | array_push |
---|
167 | ( |
---|
168 | $inserts, |
---|
169 | array |
---|
170 | ( |
---|
171 | 'user_id' => $nbm_user['user_id'], |
---|
172 | 'check_key' => $nbm_user['check_key'], |
---|
173 | 'enabled' => 'false' // By default if false, set to true with specific functions |
---|
174 | ) |
---|
175 | ); |
---|
176 | |
---|
177 | array_push |
---|
178 | ( |
---|
179 | $page['infos'], |
---|
180 | sprintf( |
---|
181 | l10n('nbm_user_x_added'), |
---|
182 | $nbm_user['username'], |
---|
183 | get_email_address_as_display_text($nbm_user['mail_address']) |
---|
184 | ) |
---|
185 | ); |
---|
186 | } |
---|
187 | |
---|
188 | // Insert new nbm_users |
---|
189 | mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts); |
---|
190 | // Update field enabled with specific function |
---|
191 | $check_key_treated = do_subscribe_unsubscribe_notification_by_mail |
---|
192 | ( |
---|
193 | true, |
---|
194 | $conf['nbm_default_value_user_enabled'], |
---|
195 | $check_key_list |
---|
196 | ); |
---|
197 | |
---|
198 | // On timeout simulate like tabsheet send |
---|
199 | if ($env_nbm['is_sendmail_timeout']) |
---|
200 | { |
---|
201 | $quoted_check_key_list = quote_check_key_list(array_diff($check_key_list, $check_key_treated)); |
---|
202 | if (count($quoted_check_key_list) != 0 ) |
---|
203 | { |
---|
204 | $query = 'delete from '.USER_MAIL_NOTIFICATION_TABLE.' where check_key in ('.implode(",", $quoted_check_key_list).');'; |
---|
205 | $result = pwg_query($query); |
---|
206 | |
---|
207 | redirect($base_url.get_query_string_diff(array()), l10n('nbm_redirect_msg')); |
---|
208 | } |
---|
209 | } |
---|
210 | } |
---|
211 | } |
---|
212 | |
---|
213 | /* |
---|
214 | * Send mail for notification to all users |
---|
215 | * Return list of "selected" users for 'list_to_send' |
---|
216 | * Return list of "treated" check_key for 'send' |
---|
217 | */ |
---|
218 | function do_action_send_mail_notification($action = 'list_to_send', $check_key_list = array(), $customize_mail_content = '') |
---|
219 | { |
---|
220 | global $conf, $page, $user, $lang_info, $lang, $env_nbm; |
---|
221 | $return_list = array(); |
---|
222 | |
---|
223 | if (in_array($action, array('list_to_send', 'send'))) |
---|
224 | { |
---|
225 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
226 | |
---|
227 | $is_action_send = ($action == 'send'); |
---|
228 | |
---|
229 | // disabled and null mail_address are not selected in the list |
---|
230 | $data_users = get_user_notifications('send', $check_key_list); |
---|
231 | |
---|
232 | // List all if it's define on options or on timeout |
---|
233 | $is_list_all_without_test = ($env_nbm['is_sendmail_timeout'] or $conf['nbm_list_all_enabled_users_to_send']); |
---|
234 | |
---|
235 | // Check if exist news to list user or send mails |
---|
236 | if ((!$is_list_all_without_test) or ($is_action_send)) |
---|
237 | { |
---|
238 | if (count($data_users) > 0) |
---|
239 | { |
---|
240 | $datas = array(); |
---|
241 | |
---|
242 | if (!isset($customize_mail_content)) |
---|
243 | { |
---|
244 | $customize_mail_content = $conf['nbm_complementary_mail_content']; |
---|
245 | } |
---|
246 | |
---|
247 | if ($conf['nbm_send_html_mail'] and !(strpos($customize_mail_content, '<') === 0)) |
---|
248 | { |
---|
249 | // On HTML mail, detects if the content are HTML format. |
---|
250 | // If it's plain text format, convert content to readable HTML |
---|
251 | $customize_mail_content = nl2br(htmlentities($customize_mail_content)); |
---|
252 | } |
---|
253 | |
---|
254 | // Prepare message after change language |
---|
255 | if ($is_action_send) |
---|
256 | { |
---|
257 | $msg_break_timeout = l10n('nbm_break_timeout_send_mail'); |
---|
258 | } |
---|
259 | else |
---|
260 | { |
---|
261 | $msg_break_timeout = l10n('nbm_break_timeout_list_user'); |
---|
262 | } |
---|
263 | |
---|
264 | // Begin nbm users environment |
---|
265 | begin_users_env_nbm($is_action_send); |
---|
266 | |
---|
267 | foreach ($data_users as $nbm_user) |
---|
268 | { |
---|
269 | if ((!$is_action_send) and check_sendmail_timeout()) |
---|
270 | { |
---|
271 | // Stop fill list on 'list_to_send', if the quota is override |
---|
272 | array_push($page['infos'], $msg_break_timeout); |
---|
273 | break; |
---|
274 | } |
---|
275 | if (($is_action_send) and check_sendmail_timeout()) |
---|
276 | { |
---|
277 | // Stop fill list on 'send', if the quota is override |
---|
278 | array_push($page['errors'], $msg_break_timeout); |
---|
279 | break; |
---|
280 | } |
---|
281 | |
---|
282 | // set env nbm user |
---|
283 | set_user_on_env_nbm($nbm_user, $is_action_send); |
---|
284 | |
---|
285 | if ($is_action_send) |
---|
286 | { |
---|
287 | set_make_full_url(); |
---|
288 | // Fill return list of "treated" check_key for 'send' |
---|
289 | array_push($return_list, $nbm_user['check_key']); |
---|
290 | |
---|
291 | if ($conf['nbm_send_detailed_content']) |
---|
292 | { |
---|
293 | $news = news($nbm_user['last_send'], $dbnow, false, $conf['nbm_send_html_mail']); |
---|
294 | $exist_data = count($news) > 0; |
---|
295 | } |
---|
296 | else |
---|
297 | { |
---|
298 | $exist_data = news_exists($nbm_user['last_send'], $dbnow); |
---|
299 | } |
---|
300 | |
---|
301 | if ($exist_data) |
---|
302 | { |
---|
303 | $subject = '['.$conf['gallery_title'].']: '.l10n('nbm_object_news'); |
---|
304 | |
---|
305 | // Assign current var for nbm mail |
---|
306 | assign_vars_nbm_mail_content($nbm_user); |
---|
307 | |
---|
308 | $end_punct = ($conf['nbm_send_detailed_content'] ? ':' : '.'); |
---|
309 | |
---|
310 | if (!is_null($nbm_user['last_send'])) |
---|
311 | { |
---|
312 | $env_nbm['mail_template']->assign_block_vars |
---|
313 | ( |
---|
314 | 'content_new_elements_between', |
---|
315 | array |
---|
316 | ( |
---|
317 | 'DATE_BETWEEN_1' => $nbm_user['last_send'], |
---|
318 | 'DATE_BETWEEN_2' => $dbnow, |
---|
319 | 'END_PUNCT' => $end_punct |
---|
320 | ) |
---|
321 | ); |
---|
322 | } |
---|
323 | else |
---|
324 | { |
---|
325 | $env_nbm['mail_template']->assign_block_vars |
---|
326 | ( |
---|
327 | 'content_new_elements_single', |
---|
328 | array |
---|
329 | ( |
---|
330 | 'DATE_SINGLE' => $dbnow, |
---|
331 | 'END_PUNCT' => $end_punct |
---|
332 | ) |
---|
333 | ); |
---|
334 | } |
---|
335 | |
---|
336 | if ($conf['nbm_send_detailed_content']) |
---|
337 | { |
---|
338 | foreach ($news as $data) |
---|
339 | { |
---|
340 | $env_nbm['mail_template']->assign_block_vars |
---|
341 | ( |
---|
342 | 'global_new_line.new_line', array('DATA' => $data) |
---|
343 | ); |
---|
344 | } |
---|
345 | } |
---|
346 | |
---|
347 | if (!empty($customize_mail_content)) |
---|
348 | { |
---|
349 | $env_nbm['mail_template']->assign_block_vars |
---|
350 | ( |
---|
351 | 'custom', array('CUSTOMIZE_MAIL_CONTENT' => $customize_mail_content) |
---|
352 | ); |
---|
353 | } |
---|
354 | |
---|
355 | if ($conf['nbm_send_html_mail'] and $conf['nbm_send_recent_post_dates']) |
---|
356 | { |
---|
357 | $recent_post_dates = get_recent_post_dates_array( |
---|
358 | $conf['recent_post_dates']['NBM']); |
---|
359 | foreach ($recent_post_dates as $date_detail) |
---|
360 | { |
---|
361 | $env_nbm['mail_template']->assign_block_vars |
---|
362 | ( |
---|
363 | 'recent_post.recent_post_block', |
---|
364 | array |
---|
365 | ( |
---|
366 | 'TITLE' => get_title_recent_post_date($date_detail), |
---|
367 | 'HTML_DATA' => get_html_description_recent_post_date($date_detail) |
---|
368 | ) |
---|
369 | ); |
---|
370 | } |
---|
371 | } |
---|
372 | |
---|
373 | $env_nbm['mail_template']->assign_block_vars |
---|
374 | ( |
---|
375 | 'goto', |
---|
376 | array |
---|
377 | ( |
---|
378 | 'GALLERY_TITLE' => $conf['gallery_title'], |
---|
379 | 'GALLERY_URL' => $conf['gallery_url'] |
---|
380 | ) |
---|
381 | ); |
---|
382 | |
---|
383 | $env_nbm['mail_template']->assign_block_vars |
---|
384 | ( |
---|
385 | 'byebye', array('SEND_AS_NAME' => $env_nbm['send_as_name']) |
---|
386 | ); |
---|
387 | |
---|
388 | if (pwg_mail |
---|
389 | ( |
---|
390 | format_email($nbm_user['username'], $nbm_user['mail_address']), |
---|
391 | array |
---|
392 | ( |
---|
393 | 'from' => $env_nbm['send_as_mail_formated'], |
---|
394 | 'subject' => $subject, |
---|
395 | 'email_format' => $env_nbm['email_format'], |
---|
396 | 'content' => $env_nbm['mail_template']->parse('notification_by_mail', true), |
---|
397 | 'content_format' => $env_nbm['email_format'], |
---|
398 | 'template' => $nbm_user['template'], |
---|
399 | 'theme' => $nbm_user['theme'] |
---|
400 | ) |
---|
401 | )) |
---|
402 | { |
---|
403 | inc_mail_sent_success($nbm_user); |
---|
404 | |
---|
405 | $data = array('user_id' => $nbm_user['user_id'], |
---|
406 | 'last_send' => $dbnow); |
---|
407 | array_push($datas, $data); |
---|
408 | } |
---|
409 | else |
---|
410 | { |
---|
411 | inc_mail_sent_failed($nbm_user); |
---|
412 | } |
---|
413 | |
---|
414 | unset_make_full_url(); |
---|
415 | } |
---|
416 | } |
---|
417 | else |
---|
418 | { |
---|
419 | if (news_exists($nbm_user['last_send'], $dbnow)) |
---|
420 | { |
---|
421 | // Fill return list of "selected" users for 'list_to_send' |
---|
422 | array_push($return_list, $nbm_user); |
---|
423 | } |
---|
424 | } |
---|
425 | |
---|
426 | // unset env nbm user |
---|
427 | unset_user_on_env_nbm(); |
---|
428 | } |
---|
429 | |
---|
430 | // Restore nbm environment |
---|
431 | end_users_env_nbm(); |
---|
432 | |
---|
433 | if ($is_action_send) |
---|
434 | { |
---|
435 | mass_updates( |
---|
436 | USER_MAIL_NOTIFICATION_TABLE, |
---|
437 | array( |
---|
438 | 'primary' => array('user_id'), |
---|
439 | 'update' => array('last_send') |
---|
440 | ), |
---|
441 | $datas |
---|
442 | ); |
---|
443 | |
---|
444 | display_counter_info(); |
---|
445 | } |
---|
446 | } |
---|
447 | else |
---|
448 | { |
---|
449 | if ($is_action_send) |
---|
450 | { |
---|
451 | array_push($page['errors'], l10n('nbm_no_user_to send_notifications_by_mail')); |
---|
452 | } |
---|
453 | } |
---|
454 | } |
---|
455 | else |
---|
456 | { |
---|
457 | // Quick List, don't check news |
---|
458 | // Fill return list of "selected" users for 'list_to_send' |
---|
459 | $return_list = $data_users; |
---|
460 | } |
---|
461 | } |
---|
462 | |
---|
463 | // Return list of "selected" users for 'list_to_send' |
---|
464 | // Return list of "treated" check_key for 'send' |
---|
465 | return $return_list; |
---|
466 | } |
---|
467 | |
---|
468 | // +-----------------------------------------------------------------------+ |
---|
469 | // | Main | |
---|
470 | // +-----------------------------------------------------------------------+ |
---|
471 | if (!isset($_GET['mode'])) |
---|
472 | { |
---|
473 | $page['mode'] = 'send'; |
---|
474 | } |
---|
475 | else |
---|
476 | { |
---|
477 | $page['mode'] = $_GET['mode']; |
---|
478 | } |
---|
479 | |
---|
480 | // +-----------------------------------------------------------------------+ |
---|
481 | // | Check Access and exit when user status is not ok | |
---|
482 | // +-----------------------------------------------------------------------+ |
---|
483 | check_status(get_tab_status($page['mode'])); |
---|
484 | |
---|
485 | // +-----------------------------------------------------------------------+ |
---|
486 | // | Insert new users with mails | |
---|
487 | // +-----------------------------------------------------------------------+ |
---|
488 | if (!isset($_POST) or (count($_POST) ==0)) |
---|
489 | { |
---|
490 | // No insert data in post mode |
---|
491 | insert_new_data_user_mail_notification(); |
---|
492 | } |
---|
493 | |
---|
494 | // +-----------------------------------------------------------------------+ |
---|
495 | // | Treatment of tab post | |
---|
496 | // +-----------------------------------------------------------------------+ |
---|
497 | switch ($page['mode']) |
---|
498 | { |
---|
499 | case 'param' : |
---|
500 | { |
---|
501 | if (isset($_POST['param_submit']) and !is_adviser()) |
---|
502 | { |
---|
503 | $updated_param_count = 0; |
---|
504 | // Update param |
---|
505 | $result = pwg_query('select param, value from '.CONFIG_TABLE.' where param like \'nbm\\_%\''); |
---|
506 | while ($nbm_user = mysql_fetch_array($result)) |
---|
507 | { |
---|
508 | if (isset($_POST[$nbm_user['param']])) |
---|
509 | { |
---|
510 | $value = $_POST[$nbm_user['param']]; |
---|
511 | |
---|
512 | $query = ' |
---|
513 | update |
---|
514 | '.CONFIG_TABLE.' |
---|
515 | set |
---|
516 | value = \''. str_replace("\'", "''", $value).'\' |
---|
517 | where |
---|
518 | param = \''.$nbm_user['param'].'\';'; |
---|
519 | pwg_query($query); |
---|
520 | $updated_param_count += 1; |
---|
521 | } |
---|
522 | } |
---|
523 | |
---|
524 | array_push($page['infos'], |
---|
525 | l10n_dec('nbm_updated_param_count', 'nbm_updated_params_count', |
---|
526 | $updated_param_count)); |
---|
527 | |
---|
528 | // Reload conf with new values |
---|
529 | load_conf_from_db('param like \'nbm\\_%\''); |
---|
530 | } |
---|
531 | } |
---|
532 | case 'subscribe' : |
---|
533 | { |
---|
534 | if (!is_adviser()) |
---|
535 | { |
---|
536 | if (isset($_POST['falsify']) and isset($_POST['cat_true'])) |
---|
537 | { |
---|
538 | $check_key_treated = unsubscribe_notification_by_mail(true, $_POST['cat_true']); |
---|
539 | do_timeout_treatment('cat_true', $check_key_treated); |
---|
540 | } |
---|
541 | else |
---|
542 | if (isset($_POST['trueify']) and isset($_POST['cat_false'])) |
---|
543 | { |
---|
544 | $check_key_treated = subscribe_notification_by_mail(true, $_POST['cat_false']); |
---|
545 | do_timeout_treatment('cat_false', $check_key_treated); |
---|
546 | } |
---|
547 | } |
---|
548 | break; |
---|
549 | } |
---|
550 | |
---|
551 | case 'send' : |
---|
552 | { |
---|
553 | if (isset($_POST['send_submit']) and isset($_POST['send_selection']) and isset($_POST['send_customize_mail_content']) and !is_adviser()) |
---|
554 | { |
---|
555 | $check_key_treated = do_action_send_mail_notification('send', $_POST['send_selection'], stripslashes($_POST['send_customize_mail_content'])); |
---|
556 | do_timeout_treatment('send_selection', $check_key_treated); |
---|
557 | } |
---|
558 | } |
---|
559 | } |
---|
560 | |
---|
561 | // +-----------------------------------------------------------------------+ |
---|
562 | // | template initialization | |
---|
563 | // +-----------------------------------------------------------------------+ |
---|
564 | $template->set_filenames |
---|
565 | ( |
---|
566 | array |
---|
567 | ( |
---|
568 | 'double_select' => 'admin/double_select.tpl', |
---|
569 | 'notification_by_mail'=>'admin/notification_by_mail.tpl' |
---|
570 | ) |
---|
571 | ); |
---|
572 | |
---|
573 | $template->assign_vars |
---|
574 | ( |
---|
575 | array |
---|
576 | ( |
---|
577 | 'U_HELP' => add_url_params(get_root_url().'popuphelp.php', array('page' => 'notification_by_mail')), |
---|
578 | 'F_ACTION'=> $base_url.get_query_string_diff(array()) |
---|
579 | ) |
---|
580 | ); |
---|
581 | |
---|
582 | if (is_autorize_status(ACCESS_WEBMASTER)) |
---|
583 | { |
---|
584 | // TabSheet initialization |
---|
585 | $page['tabsheet'] = array |
---|
586 | ( |
---|
587 | 'param' => array |
---|
588 | ( |
---|
589 | 'caption' => l10n('nbm_param_mode'), |
---|
590 | 'url' => add_url_params($base_url.get_query_string_diff(array('mode', 'select')), |
---|
591 | array('mode' => 'param')) |
---|
592 | ), |
---|
593 | 'subscribe' => array |
---|
594 | ( |
---|
595 | 'caption' => l10n('nbm_subscribe_mode'), |
---|
596 | 'url' => add_url_params($base_url.get_query_string_diff(array('mode', 'select')), array('mode' => 'subscribe')), |
---|
597 | ), |
---|
598 | 'send' => array |
---|
599 | ( |
---|
600 | 'caption' => l10n('nbm_send_mode'), |
---|
601 | 'url' => add_url_params($base_url.get_query_string_diff(array('mode', 'select')), array('mode' => 'send')) |
---|
602 | ) |
---|
603 | ); |
---|
604 | |
---|
605 | $page['tabsheet'][$page['mode']]['selected'] = true; |
---|
606 | |
---|
607 | // Assign tabsheet to template |
---|
608 | template_assign_tabsheet(); |
---|
609 | } |
---|
610 | |
---|
611 | if ($must_repost) |
---|
612 | { |
---|
613 | // Get name of submit button |
---|
614 | $repost_submit_name = ''; |
---|
615 | if (isset($_POST['falsify'])) |
---|
616 | { |
---|
617 | $repost_submit_name = 'falsify'; |
---|
618 | } |
---|
619 | elseif (isset($_POST['trueify'])) |
---|
620 | { |
---|
621 | $repost_submit_name = 'trueify'; |
---|
622 | } |
---|
623 | elseif (isset($_POST['send_submit'])) |
---|
624 | { |
---|
625 | $repost_submit_name = 'send_submit'; |
---|
626 | } |
---|
627 | |
---|
628 | $template->assign_block_vars |
---|
629 | ( |
---|
630 | 'repost', |
---|
631 | array |
---|
632 | ( |
---|
633 | 'REPOST_SUBMIT_NAME' => $repost_submit_name |
---|
634 | ) |
---|
635 | ); |
---|
636 | } |
---|
637 | |
---|
638 | switch ($page['mode']) |
---|
639 | { |
---|
640 | case 'param' : |
---|
641 | { |
---|
642 | $template->assign_block_vars( |
---|
643 | $page['mode'], |
---|
644 | array( |
---|
645 | 'SEND_HTML_MAIL_YES' => ($conf['nbm_send_html_mail'] ? 'checked="checked"' : ''), |
---|
646 | 'SEND_HTML_MAIL_NO' => (!$conf['nbm_send_html_mail'] ? 'checked="checked"' : ''), |
---|
647 | 'SEND_MAIL_AS' => $conf['nbm_send_mail_as'], |
---|
648 | 'SEND_DETAILED_CONTENT_YES' => ($conf['nbm_send_detailed_content'] ? 'checked="checked"' : ''), |
---|
649 | 'SEND_DETAILED_CONTENT_NO' => (!$conf['nbm_send_detailed_content'] ? 'checked="checked"' : ''), |
---|
650 | 'COMPLEMENTARY_MAIL_CONTENT' => $conf['nbm_complementary_mail_content'], |
---|
651 | 'SEND_RECENT_POST_DATES_YES' => ($conf['nbm_send_recent_post_dates'] ? 'checked="checked"' : ''), |
---|
652 | 'SEND_RECENT_POST_DATES_NO' => (!$conf['nbm_send_recent_post_dates'] ? 'checked="checked"' : '') |
---|
653 | )); |
---|
654 | break; |
---|
655 | } |
---|
656 | |
---|
657 | case 'subscribe' : |
---|
658 | { |
---|
659 | $template->assign_block_vars( |
---|
660 | $page['mode'], |
---|
661 | array( |
---|
662 | )); |
---|
663 | |
---|
664 | $template->assign_vars( |
---|
665 | array( |
---|
666 | 'L_CAT_OPTIONS_TRUE' => l10n('nbm_subscribe_col'), |
---|
667 | 'L_CAT_OPTIONS_FALSE' => l10n('nbm_unsubscribe_col') |
---|
668 | ) |
---|
669 | ); |
---|
670 | |
---|
671 | $data_users = get_user_notifications('subscribe'); |
---|
672 | foreach ($data_users as $nbm_user) |
---|
673 | { |
---|
674 | $template->assign_block_vars( |
---|
675 | (get_boolean($nbm_user['enabled']) ? 'category_option_true' : 'category_option_false'), |
---|
676 | array('SELECTED' => ( // Keep selected user where enabled are not changed when change has been notify |
---|
677 | get_boolean($nbm_user['enabled']) ? (isset($_POST['falsify']) and isset($_POST['cat_true']) and in_array($nbm_user['check_key'], $_POST['cat_true'])) |
---|
678 | : (isset($_POST['trueify']) and isset($_POST['cat_false']) and in_array($nbm_user['check_key'], $_POST['cat_false'])) |
---|
679 | ) ? 'selected="selected"' : '', |
---|
680 | 'VALUE' => $nbm_user['check_key'], |
---|
681 | 'OPTION' => $nbm_user['username'].'['.get_email_address_as_display_text($nbm_user['mail_address']).']' |
---|
682 | )); |
---|
683 | } |
---|
684 | |
---|
685 | break; |
---|
686 | } |
---|
687 | |
---|
688 | case 'send' : |
---|
689 | { |
---|
690 | $template->assign_block_vars($page['mode'], array()); |
---|
691 | |
---|
692 | $data_users = do_action_send_mail_notification('list_to_send'); |
---|
693 | |
---|
694 | if (count($data_users) == 0) |
---|
695 | { |
---|
696 | $template->assign_block_vars($page['mode'].'.send_empty', array()); |
---|
697 | } |
---|
698 | else |
---|
699 | { |
---|
700 | $template->assign_block_vars( |
---|
701 | $page['mode'].'.send_data', |
---|
702 | array( |
---|
703 | 'CUSTOMIZE_MAIL_CONTENT' => isset($_POST['send_customize_mail_content']) ? stripslashes($_POST['send_customize_mail_content']) : $conf['nbm_complementary_mail_content'] |
---|
704 | )); |
---|
705 | |
---|
706 | foreach ($data_users as $num => $nbm_user) |
---|
707 | { |
---|
708 | if ( |
---|
709 | (!$must_repost) or // Not timeout, normal treatment |
---|
710 | (($must_repost) and in_array($nbm_user['check_key'], $_POST['send_selection'])) // Must be repost, show only user to send |
---|
711 | ) |
---|
712 | { |
---|
713 | $template->assign_block_vars( |
---|
714 | $page['mode'].'.send_data.user_send_mail', |
---|
715 | array( |
---|
716 | 'CLASS' => ($num % 2 == 1) ? 'nbm_user2' : 'nbm_user1', |
---|
717 | 'ID' => $nbm_user['check_key'], |
---|
718 | 'CHECKED' => ( // not check if not selected, on init select<all |
---|
719 | isset($_POST['send_selection']) and // not init |
---|
720 | !in_array($nbm_user['check_key'], $_POST['send_selection']) // not selected |
---|
721 | ) ? '' : 'checked="checked"', |
---|
722 | 'USERNAME'=> $nbm_user['username'], |
---|
723 | 'EMAIL' => get_email_address_as_display_text($nbm_user['mail_address']), |
---|
724 | 'LAST_SEND'=> $nbm_user['last_send'] |
---|
725 | )); |
---|
726 | } |
---|
727 | } |
---|
728 | } |
---|
729 | |
---|
730 | break; |
---|
731 | } |
---|
732 | } |
---|
733 | |
---|
734 | // +-----------------------------------------------------------------------+ |
---|
735 | // | Sending html code | |
---|
736 | // +-----------------------------------------------------------------------+ |
---|
737 | $template->assign_var_from_handle('DOUBLE_SELECT', 'double_select'); |
---|
738 | $template->assign_var_from_handle('ADMIN_CONTENT', 'notification_by_mail'); |
---|
739 | |
---|
740 | ?> |
---|