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