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