- Timestamp:
- Mar 31, 2006, 12:49:49 AM (18 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/notification_by_mail.php
r1114 r1115 54 54 * Get the authorized_status for each tab 55 55 * return corresponding status 56 */56 */ 57 57 function get_tab_status($mode) 58 58 { … … 61 61 { 62 62 case 'param': 63 case 'subscribe' 63 case 'subscribe': 64 64 $result = ACCESS_WEBMASTER; 65 65 break; 66 case 'send' 66 case 'send': 67 67 $result = ACCESS_ADMINISTRATOR; 68 68 break; … … 74 74 } 75 75 76 function get_user_notifications($enabled_only=false, $valid_email_only=false) 76 /* 77 * Execute all main queries to get list of user 78 * 79 * Type are the type of list 'subscribe', 'send' 80 * 81 * return array of users 82 */ 83 function get_user_notifications($action, $check_key_list = array()) 77 84 { 78 85 global $conf; 79 $query = ' 80 SELECT 81 N.user_id, N.check_key, N.last_send, N.enabled, 82 U.'.$conf['user_fields']['username'].' AS username, U.'.$conf['user_fields']['email'].' AS mail_address 83 FROM 86 87 $data_users = array(); 88 89 if (in_array($action, array('subscribe', 'send'))) 90 { 91 $quoted_check_key_list = quote_check_key_list($check_key_list); 92 if (count($quoted_check_key_list) != 0 ) 93 { 94 $query_and_check_key = ' and 95 check_key in ('.implode(",", $quoted_check_key_list).') '; 96 } 97 else 98 { 99 $query_and_check_key = ''; 100 } 101 102 $query = ' 103 select 104 N.user_id, 105 N.check_key, 106 U.'.$conf['user_fields']['username'].' as username, 107 U.'.$conf['user_fields']['email'].' as mail_address, 108 N.enabled, 109 N.last_send 110 from 84 111 '.USER_MAIL_NOTIFICATION_TABLE.' as N, 85 112 '.USERS_TABLE.' as U 86 WHERE 87 N.user_id = U.'.$conf['user_fields']['id']; 88 if ($enabled_only) 89 { 113 where 114 N.user_id = U.'.$conf['user_fields']['id']; 115 116 if ($action == 'send') 117 { 118 $query .= ' and 119 N.enabled = \'true\' and 120 U.'.$conf['user_fields']['email'].' is not null'.$query_and_check_key; 121 } 122 90 123 $query .= ' 91 AND N.enabled = \'true\''; 92 } 93 94 if ($valid_email_only) 95 { 96 $query .= ' 97 AND U.'.$conf['user_fields']['email'].' IS NOT NULL'; 98 } 99 $query .= ' 100 ORDER BY username 101 ;'; 102 $users = array(); 103 $result = pwg_query($query); 104 while ($row = mysql_fetch_array($result)) 105 { 106 $row['enabled'] = ($row['enabled']=='true') ? true:false; 107 array_push($users, $row); 108 } 109 return $users; 110 } 111 112 function make_index_absolute_url($cat_id) 113 { 114 global $page, $conf; 115 if ( isset($page['root_path']) ) 116 { 117 $save_root_path = $page['root_path']; 118 } 119 $page['root_path'] = 'http://'.$_SERVER['HTTP_HOST'].cookie_path().'/'; 120 $url = make_index_url( array('category'=>$cat_id) ); 121 if (isset($save_root_path)) 122 { 123 $page['root_path'] = $save_root_path; 124 } 125 else 126 { 127 unset($page['root_path']); 128 } 129 return $url; 124 order by 125 username;'; 126 127 $result = pwg_query($query); 128 if (!empty($result)) 129 { 130 while ($nbm_user = mysql_fetch_array($result)) 131 { 132 array_push($data_users, $nbm_user); 133 } 134 } 135 } 136 return $data_users; 130 137 } 131 138 … … 142 149 '.USERS_TABLE.' 143 150 set 144 mail_address= null151 '.$conf['user_fields']['email'].' = null 145 152 where 146 trim( mail_address) = \'\';';153 trim('.$conf['user_fields']['email'].') = \'\';'; 147 154 pwg_query($query); 148 155 … … 150 157 $query = ' 151 158 select 152 u.id user_id, u.username, u.mail_address 159 u.'.$conf['user_fields']['id'].' as user_id, 160 u.'.$conf['user_fields']['username'].' as username, 161 u.'.$conf['user_fields']['email'].' as mail_address 153 162 from 154 '.USERS_TABLE.' as u left join '.USER_MAIL_NOTIFICATION_TABLE.' as m on u. id= m.user_id163 '.USERS_TABLE.' as u left join '.USER_MAIL_NOTIFICATION_TABLE.' as m on u.'.$conf['user_fields']['id'].' = m.user_id 155 164 where 156 u. mail_addressis not null and165 u.'.$conf['user_fields']['email'].' is not null and 157 166 m.user_id is null 158 167 order by 159 id;';168 user_id;'; 160 169 161 170 $result = pwg_query($query); … … 166 175 $check_key_list = array(); 167 176 168 while ($ row= mysql_fetch_array($result))177 while ($nbm_user = mysql_fetch_array($result)) 169 178 { 170 179 // Calculate key 171 $ row['check_key'] = find_available_check_key();180 $nbm_user['check_key'] = find_available_check_key(); 172 181 173 182 // Save key 174 array_push($check_key_list, $ row['check_key']);175 176 // Insert new rows183 array_push($check_key_list, $nbm_user['check_key']); 184 185 // Insert new nbm_users 177 186 array_push 178 187 ( 179 $inserts, 188 $inserts, 180 189 array 181 190 ( 182 'user_id' => $ row['user_id'],183 'check_key' => $ row['check_key'],191 'user_id' => $nbm_user['user_id'], 192 'check_key' => $nbm_user['check_key'], 184 193 'enabled' => 'false' // By default if false, set to true with specific functions 185 194 ) 186 195 ); 187 196 188 array_push($page['infos'], sprintf(l10n('nbm_User %s [%s] added.'), $ row['username'], $row['mail_address']));189 } 190 191 // Insert new rows197 array_push($page['infos'], sprintf(l10n('nbm_User %s [%s] added.'), $nbm_user['username'], $nbm_user['mail_address'])); 198 } 199 200 // Insert new nbm_users 192 201 mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts); 193 202 // Update field enabled with specific function … … 204 213 * Return list of "treated/selected" users 205 214 */ 206 function do_action_send_mail_notification($ check_key_list = array(), $customize_mail_content = '')215 function do_action_send_mail_notification($action = 'list', $check_key_list = array(), $customize_mail_content = '') 207 216 { 208 217 global $conf, $page, $user, $lang_info, $lang; 209 210 list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); 211 212 if (isset($customize_mail_content)) 213 { 214 $customize_mail_content = $conf['nbm_complementary_mail_content']; 215 } 216 217 $user_notifications = get_user_notifications(true,true); 218 219 $error_on_mail_count = 0; 220 $sent_mail_count = 0; 221 $datas = array(); 222 // Save $user, $lang_info and $lang arrays (include/user.inc.php has been executed) 223 $sav_mailtousers_user = $user; 224 $sav_mailtousers_lang_info = $lang_info; 225 $sav_mailtousers_lang = $lang; 226 // Save message info and error in the original language 227 $msg_info = l10n('nbm_Mail sent to %s [%s].'); 228 $msg_error = l10n('nbm_Error when sending email to %s [%s].'); 229 // Last Language 230 $last_mailtousers_language = $user['language']; 231 232 // Init mail configuration 233 $send_as_name = ((isset($conf['nbm_send_mail_as']) and !empty($conf['nbm_send_mail_as'])) ? $conf['nbm_send_mail_as'] : $conf['gallery_title']); 234 $send_as_mail_address = get_webmaster_mail_address(); 235 $send_as_mail_formated = format_email($send_as_name, $send_as_mail_address); 236 237 foreach ($user_notifications as $user_notification) 238 { 239 if (!in_array($user_notification['check_key'], $check_key_list)) 240 continue; 241 if (!$user_notification['enabled']) 242 continue; 243 $user = array(); 244 $user['id'] = $user_notification['user_id']; 245 $user = array_merge($user, getuserdata($user['id'], true)); 246 247 if ($last_mailtousers_language != $user['language']) 248 { 218 $return_list = array(); 219 220 if (in_array($action, array('list', 'send'))) 221 { 222 list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); 223 224 $is_action_send = ($action == 'send'); 225 226 if (isset($customize_mail_content)) 227 { 228 $customize_mail_content = $conf['nbm_complementary_mail_content']; 229 } 230 231 // disabled and null mail_address are not selected in the list 232 $data_users = get_user_notifications('send', $check_key_list); 233 234 if (count($data_users) > 0) 235 { 236 $error_on_mail_count = 0; 237 $sent_mail_count = 0; 238 // Save $user, $lang_info and $lang arrays (include/user.inc.php has been executed) 239 $sav_mailtousers_user = $user; 240 $sav_mailtousers_lang_info = $lang_info; 241 $sav_mailtousers_lang = $lang; 242 // Save message info and error in the original language 243 $msg_info = l10n('nbm_Mail sent to %s [%s].'); 244 $msg_error = l10n('nbm_Error when sending email to %s [%s].'); 245 // Last Language 249 246 $last_mailtousers_language = $user['language']; 250 247 251 // Re-Init language arrays 252 $lang_info = array(); 253 $lang = array(); 254 255 // language files 256 include(get_language_filepath('common.lang.php')); 257 // No test admin because script is checked admin (user selected no) 258 // Translations are in admin file too 259 include(get_language_filepath('admin.lang.php')); 260 } 261 262 $message = ''; 263 $news = news($user_notification['last_send'], $dbnow); 264 if (count($news) > 0) 265 { 266 $subject = '['.$conf['gallery_title'].']: '.l10n('nbm_ContentObject'); 267 $message .= sprintf(l10n('nbm_ContentHello'), $user_notification['username']).",\n\n"; 268 269 if (!is_null($user_notification['last_send'])) 270 $message .= sprintf(l10n('nbm_ContentNewElementsBetween'), $user_notification['last_send'], $dbnow); 271 else 272 $message .= sprintf(l10n('nbm_ContentNewElements'), $dbnow); 273 274 if ($conf['nbm_send_detailed_content']) 275 { 276 $message .= ":\n"; 277 foreach ($news as $line) 248 if ($is_action_send) 249 { 250 // Init mail configuration 251 $send_as_name = ((isset($conf['nbm_send_mail_as']) and !empty($conf['nbm_send_mail_as'])) ? $conf['nbm_send_mail_as'] : $conf['gallery_title']); 252 $send_as_mail_address = get_webmaster_mail_address(); 253 $send_as_mail_formated = format_email($send_as_name, $send_as_mail_address); 254 } 255 256 foreach ($data_users as $nbm_user) 257 { 258 $user = array(); 259 $user['id'] = $nbm_user['user_id']; 260 $user = array_merge($user, getuserdata($user['id'], true)); 261 262 if ($last_mailtousers_language != $user['language']) 278 263 { 279 $message .= ' o '.$line."\n"; 264 $last_mailtousers_language = $user['language']; 265 266 // Re-Init language arrays 267 $lang_info = array(); 268 $lang = array(); 269 270 // language files 271 include(get_language_filepath('common.lang.php')); 272 // No test admin because script is checked admin (user selected no) 273 // Translations are in admin file too 274 include(get_language_filepath('admin.lang.php')); 280 275 } 281 } 282 $message .= ".\n"; 283 284 $message .= sprintf(l10n('nbm_ContentGoTo'), $conf['gallery_title'], $conf['gallery_url'])."\n\n"; 285 $message .= $customize_mail_content."\n\n"; 286 $message .= l10n('nbm_ContentByeBye')."\n ".$send_as_name."\n\n"; 287 $message .= "\n".sprintf(l10n('nbm_ContentUnsubscribe'), $send_as_mail_address)."\n\n"; 288 if (pwg_mail(format_email($user_notification['username'], $user_notification['mail_address']), $send_as_mail_formated, $subject, $message)) 289 { 290 $sent_mail_count++; 291 array_push($page['infos'], sprintf($msg_info, $user_notification['username'], $user_notification['mail_address'])); 292 $data = array('user_id' => $user_notification['user_id'], 293 'last_send' => $dbnow); 294 array_push($datas, $data); 295 } 296 else 297 { 298 $error_on_mail_count++; 299 array_push($page['errors'], sprintf($msg_error, $user_notification['username'], $user_notification['mail_address'])); 300 } 301 } 302 } 303 304 // Restore $user, $lang_info and $lang arrays (include/user.inc.php has been executed) 305 $user = $sav_mailtousers_user; 306 $lang_info = $sav_mailtousers_lang_info; 307 $lang = $sav_mailtousers_lang; 308 309 mass_updates( 310 USER_MAIL_NOTIFICATION_TABLE, 311 array( 312 'primary' => array('user_id'), 313 'update' => array('last_send') 314 ), 315 $datas 316 ); 317 318 if ($error_on_mail_count != 0) 319 { 320 array_push($page['errors'], sprintf(l10n('nbm_%d mails were not sent.'), $error_on_mail_count)); 321 } 322 else 323 { 324 if ($sent_mail_count == 0) 325 array_push($page['infos'], l10n('nbm_No mail to send.')); 276 277 if ($is_action_send) 278 { 279 $message = ''; 280 281 if ($conf['nbm_send_detailed_content']) 282 { 283 $news = news($nbm_user['last_send'], $dbnow); 284 $exist_data = count($news) > 0; 285 } 286 else 287 { 288 $exist_data = news_exists($nbm_user['last_send'], $dbnow); 289 } 290 291 if ($exist_data) 292 { 293 array_push($return_list, $nbm_user); 294 295 $subject = '['.$conf['gallery_title'].']: '.l10n('nbm_ContentObject'); 296 $message .= sprintf(l10n('nbm_ContentHello'), $nbm_user['username']).",\n\n"; 297 298 if (!is_null($nbm_user['last_send'])) 299 $message .= sprintf(l10n('nbm_ContentNewElementsBetween'), $nbm_user['last_send'], $dbnow); 300 else 301 $message .= sprintf(l10n('nbm_ContentNewElements'), $dbnow); 302 303 if ($conf['nbm_send_detailed_content']) 304 { 305 $message .= ":\n"; 306 307 foreach ($news as $line) 308 { 309 $message .= ' o '.$line."\n"; 310 } 311 $message .= "\n"; 312 } 313 else 314 { 315 $message .= ".\n"; 316 } 317 318 $message .= sprintf(l10n('nbm_ContentGoTo'), $conf['gallery_title'], $conf['gallery_url'])."\n\n"; 319 $message .= $customize_mail_content."\n\n"; 320 $message .= l10n('nbm_ContentByeBye')."\n ".$send_as_name."\n\n"; 321 $message .= "\n".sprintf(l10n('nbm_ContentUnsubscribe'), $send_as_mail_address)."\n\n"; 322 323 if (pwg_mail(format_email($nbm_user['username'], $nbm_user['mail_address']), $send_as_mail_formated, $subject, $message)) 324 { 325 $sent_mail_count += 1; 326 array_push($page['infos'], sprintf($msg_info, $nbm_user['username'], $nbm_user['mail_address'])); 327 328 $data = array('user_id' => $user_notification['user_id'], 329 'last_send' => $dbnow); 330 array_push($datas, $data); 331 } 332 else 333 { 334 $error_on_mail_count += 1; 335 array_push($page['errors'], sprintf($msg_error, $nbm_user['username'], $nbm_user['mail_address'])); 336 } 337 } 338 } 339 else 340 { 341 if (news_exists($nbm_user['last_send'], $dbnow)) 342 { 343 array_push($return_list, $nbm_user); 344 } 345 } 346 } 347 348 // Restore $user, $lang_info and $lang arrays (include/user.inc.php has been executed) 349 $user = $sav_mailtousers_user; 350 $lang_info = $sav_mailtousers_lang_info; 351 $lang = $sav_mailtousers_lang; 352 353 if ($is_action_send) 354 { 355 mass_updates( 356 USER_MAIL_NOTIFICATION_TABLE, 357 array( 358 'primary' => array('user_id'), 359 'update' => array('last_send') 360 ), 361 $datas 362 ); 363 364 365 if ($error_on_mail_count != 0) 366 { 367 array_push($page['errors'], sprintf(l10n('nbm_%d mails were not sent.'), $error_on_mail_count)); 368 } 369 else 370 { 371 if ($sent_mail_count == 0) 372 array_push($page['infos'], l10n('nbm_No mail to send.')); 373 else 374 array_push($page['infos'], sprintf(l10n('nbm_%d mails were sent.'), $sent_mail_count)); 375 } 376 } 377 } 326 378 else 327 array_push($page['infos'], sprintf(l10n('nbm_%d mails were sent.'), $sent_mail_count)); 328 } 379 { 380 if ($is_action_send) 381 { 382 array_push($page['errors'], l10n('nbm_No user to send notifications by mail.')); 383 } 384 } 385 } 386 return $return_list; 329 387 } 330 388 … … 365 423 // Update param 366 424 $result = pwg_query('select param, value from '.CONFIG_TABLE.' where param like \'nbm\\_%\''); 367 while ($ row= mysql_fetch_array($result))425 while ($nbm_user = mysql_fetch_array($result)) 368 426 { 369 427 if (isset($_POST['param_submit'])) 370 428 { 371 if (isset($_POST[$ row['param']]))429 if (isset($_POST[$nbm_user['param']])) 372 430 { 373 $value = $_POST[$ row['param']];431 $value = $_POST[$nbm_user['param']]; 374 432 375 433 $query = ' 376 434 update 377 435 '.CONFIG_TABLE.' 378 set 436 set 379 437 value = \''. str_replace("\'", "''", $value).'\' 380 438 where 381 param = \''.$ row['param'].'\';';439 param = \''.$nbm_user['param'].'\';'; 382 440 pwg_query($query); 383 441 $updated_param_count += 1; … … 385 443 } 386 444 387 $conf[$ row['param']] = $row['value'];445 $conf[$nbm_user['param']] = $nbm_user['value']; 388 446 389 447 // if the parameter is present in $_POST array (if a form is submited), we 390 448 // override it with the submited value 391 if (isset($_POST[$ row['param']]))392 { 393 $conf[$ row['param']] = stripslashes($_POST[$row['param']]);449 if (isset($_POST[$nbm_user['param']])) 450 { 451 $conf[$nbm_user['param']] = stripslashes($_POST[$nbm_user['param']]); 394 452 } 395 453 396 454 // If the field is true or false, the variable is transformed into a 397 455 // boolean value. 398 if ($conf[$ row['param']] == 'true' or $conf[$row['param']] == 'false')399 { 400 $conf[$ row['param']] = get_boolean($conf[$row['param']]);401 } 402 } 403 456 if ($conf[$nbm_user['param']] == 'true' or $conf[$nbm_user['param']] == 'false') 457 { 458 $conf[$nbm_user['param']] = get_boolean($conf[$nbm_user['param']]); 459 } 460 } 461 404 462 if ($updated_param_count != 0) 405 463 { … … 425 483 if (isset($_POST['send_submit']) and isset($_POST['send_selection']) and isset($_POST['send_customize_mail_content'])) 426 484 { 427 do_action_send_mail_notification( $_POST['send_selection'], $_POST['send_customize_mail_content']);485 do_action_send_mail_notification('send', $_POST['send_selection'], $_POST['send_customize_mail_content']); 428 486 } 429 487 } … … 497 555 ); 498 556 499 $user_notifications = get_user_notifications(); 500 501 foreach( $user_notifications as $user_notification) 557 $data_users = get_user_notifications('subscribe'); 558 foreach ($data_users as $nbm_user) 502 559 { 503 560 $template->assign_block_vars( 504 $user_notification['enabled'] ? 'category_option_true' : 'category_option_false',561 (get_boolean($nbm_user['enabled']) ? 'category_option_true' : 'category_option_false'), 505 562 array('SELECTED' => '', 506 'VALUE' => $ user_notification['check_key'],507 'OPTION' => $ user_notification['username'].'['.$user_notification['mail_address'].']'563 'VALUE' => $nbm_user['check_key'], 564 'OPTION' => $nbm_user['username'].'['.$nbm_user['mail_address'].']' 508 565 )); 509 566 } 567 510 568 break; 511 569 } … … 515 573 $template->assign_block_vars($page['mode'], array()); 516 574 517 $data_ rows = get_user_notifications(true,true);518 519 if (count($data_ rows) == 0)575 $data_users = do_action_send_mail_notification('list'); 576 577 if (count($data_users) == 0) 520 578 { 521 579 $template->assign_block_vars($page['mode'].'.send_empty', array()); … … 528 586 'CUSTOMIZE_MAIL_CONTENT' => isset($_POST['send_customize_mail_content']) ? $_POST['send_customize_mail_content'] : $conf['nbm_complementary_mail_content'] 529 587 )); 530 foreach ($data_rows as $num => $local_user) 531 { 532 $checked = 'checked="checked"'; 533 if ( isset($_POST['send_submit']) and 534 ( !isset($_POST['send_selection']) or 535 !in_array($local_user['check_key'], $_POST['send_selection']) 536 ) 537 ) 538 { 539 $checked=''; 540 } 541 $template->assign_block_vars( 588 589 foreach ($data_users as $num => $nbm_user) 590 $template->assign_block_vars( 542 591 $page['mode'].'.send_data.user_send_mail', 543 592 array( 544 'CLASS' => ($num % 2 == 1) ? 'row2' : 'row1', 545 'ID' => $local_user['check_key'], 546 'CHECKED' => $checked, 547 'USERNAME'=> $local_user['username'], 548 'EMAIL' => $local_user['mail_address'], 549 'LAST_SEND'=> $local_user['last_send'] 593 'CLASS' => ($num % 2 == 1) ? 'nbm_user2' : 'nbm_user1', 594 'ID' => $nbm_user['check_key'], 595 'CHECKED' => ( // not check if not selected, on init select<all 596 isset($_POST['send_selection']) and // not init 597 !in_array($nbm_user['check_key'], $_POST['send_selection']) // not selected 598 ) ? '' : 'checked="checked"', 599 'USERNAME'=> $nbm_user['username'], 600 'EMAIL' => $nbm_user['mail_address'], 601 'LAST_SEND'=> $nbm_user['last_send'] 550 602 )); 551 }552 603 } 553 604 -
trunk/template/yoga/admin/notification_by_mail.tpl
r1114 r1115 8 8 <h3> 9 9 <p style="text-align:center;"> 10 <a href="{header_link.PARAM_MODE}">{lang:nbm_param_mode}</a> | 11 <a href="{header_link.SUBSCRIBE_MODE}">{lang:nbm_subscribe_mode}</a> | 10 <a href="{header_link.PARAM_MODE}">{lang:nbm_param_mode}</a> | 11 <a href="{header_link.SUBSCRIBE_MODE}">{lang:nbm_subscribe_mode}</a> | 12 12 <a href="{header_link.SEND_MODE}">{lang:nbm_send_mode}</a> 13 13 </p> … … 62 62 <center> 63 63 {lang:nbm_no_user_available_to_send_L1}<br> 64 {lang:nbm_no_user_available_to_send_L2} 64 {lang:nbm_no_user_available_to_send_L2}<br> 65 65 </center> 66 66 <!-- END send_empty --> … … 85 85 </table> 86 86 <p> 87 <input type="button" value="{lang:nbm_send_check_all}" onclick="SelectAll(document.getElementById('notification_by_mail'))"/> 88 / 89 <input type="button" value="{lang:nbm_send_uncheck_all}" onclick="DeselectAll(document.getElementById('notification_by_mail'))"/> 87 <a href="" onclick="SelectAll(document.getElementById('notification_by_mail')); return false;">{lang:nbm_send_check_all}</a> 88 / <a href="" onclick="DeselectAll(document.getElementById('notification_by_mail')); return false;">{lang:nbm_send_uncheck_all}</a> 90 89 </p> 91 90 </fieldset>
Note: See TracChangeset
for help on using the changeset viewer.