From 324f3c4279ee0d1ff24e297535f5a62cc777ace1 Mon Sep 17 00:00:00 2001 From: rub Date: Sat, 1 Apr 2006 01:14:57 +0000 Subject: [NBM] Step 7: Add functionalities subscribe/unsubscribe: o reduce length of check_key o fix bugs o send mail on subscribe/unsubscribe o add and used $conf parameters o review keyword of languages o improve selection/check o can subscribe/unsubscribe with a link include on mail o fix bug mass_update collate git-svn-id: http://piwigo.org/svn/trunk@1116 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/include/functions.php | 2 +- .../include/functions_notification_by_mail.inc.php | 368 +++++++++++++++++++-- admin/notification_by_mail.php | 290 ++++++---------- include/config_default.inc.php | 18 + install/db/18-database.php | 92 ++++++ install/phpwebgallery_structure.sql | 2 +- language/en_UK.iso-8859-1/admin.lang.php | 45 ++- language/en_UK.iso-8859-1/common.lang.php | 1 + language/fr_FR.iso-8859-1/admin.lang.php | 47 ++- language/fr_FR.iso-8859-1/common.lang.php | 1 + nbm.php | 88 +++++ template/yoga/admin/notification_by_mail.tpl | 2 +- 12 files changed, 699 insertions(+), 257 deletions(-) create mode 100644 install/db/18-database.php create mode 100644 nbm.php diff --git a/admin/include/functions.php b/admin/include/functions.php index 7168e79d9..dc477f6d1 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -762,7 +762,7 @@ SHOW FULL COLUMNS FROM '.$tablename.' { $column.= " default '".$row['Default']."'"; } - if (isset($row['Collation'])) + if (isset($row['Collation']) and $row['Collation'] != 'NULL') { $column.= " collate '".$row['Collation']."'"; } diff --git a/admin/include/functions_notification_by_mail.inc.php b/admin/include/functions_notification_by_mail.inc.php index 31753c7de..d19085685 100644 --- a/admin/include/functions_notification_by_mail.inc.php +++ b/admin/include/functions_notification_by_mail.inc.php @@ -26,6 +26,9 @@ // | USA. | // +-----------------------------------------------------------------------+ +/* nbm_global_var */ +$env_nbm = array(); + /* * Search an available check_key * @@ -37,7 +40,7 @@ function find_available_check_key() { while (true) { - $key = generate_key(128); + $key = generate_key(16); $query = ' select count(*) @@ -65,6 +68,250 @@ function quote_check_key_list($check_key_list = array()) return array_map(create_function('$s', 'return \'\\\'\'.$s.\'\\\'\';'), $check_key_list); } +/* + * Execute all main queries to get list of user + * + * Type are the type of list 'subscribe', 'send' + * + * return array of users + */ +function get_user_notifications($action, $check_key_list = array(), $enabled_filter_value = '') +{ + global $conf; + + $data_users = array(); + + if (in_array($action, array('subscribe', 'send'))) + { + $quoted_check_key_list = quote_check_key_list($check_key_list); + if (count($quoted_check_key_list) != 0 ) + { + $query_and_check_key = ' and + check_key in ('.implode(",", $quoted_check_key_list).') '; + } + else + { + $query_and_check_key = ''; + } + + $query = ' +select + N.user_id, + N.check_key, + U.'.$conf['user_fields']['username'].' as username, + U.'.$conf['user_fields']['email'].' as mail_address, + N.enabled, + N.last_send +from + '.USER_MAIL_NOTIFICATION_TABLE.' as N, + '.USERS_TABLE.' as U +where + N.user_id = U.'.$conf['user_fields']['id']; + + if ($action == 'send') + { + // No mail empty and all users enabled + $query .= ' and + N.enabled = \'true\' and + U.'.$conf['user_fields']['email'].' is not null'; + } + + $query .= $query_and_check_key; + + if (isset($enabled_filter_value) and ($enabled_filter_value != '')) + { + $query .= ' and + N.enabled = \''.boolean_to_string($enabled_filter_value).'\''; + } + + $query .= ' +order by'; + + if ($action == 'send') + { + $query .= ' + last_send, username;'; + } + else + { + $query .= ' + username;'; + } + + $query .= ';'; + + $result = pwg_query($query); + if (!empty($result)) + { + while ($nbm_user = mysql_fetch_array($result)) + { + array_push($data_users, $nbm_user); + } + } + } + return $data_users; +} + +/* + * Begin of use nbm environment + * Prepare and save current environment and initialize data in order to send mail + * + * Return none + */ +function begin_users_env_nbm($is_to_send_mail = false) +{ + global $user, $lang, $lang_info, $conf, $env_nbm; + + // Save $user, $lang_info and $lang arrays (include/user.inc.php has been executed) + $env_nbm['save_user'] = $user; + $env_nbm['save_lang_info'] = $lang_info; + $env_nbm['save_lang'] = $lang; + // Last Language + $env_nbm['last_language'] = $user['language']; + + $env_nbm['is_to_send_mail'] = $is_to_send_mail; + + if ($is_to_send_mail) + { + // Init mail configuration + $env_nbm['send_as_name'] = ((isset($conf['nbm_send_mail_as']) and !empty($conf['nbm_send_mail_as'])) ? $conf['nbm_send_mail_as'] : $conf['gallery_title']); + $env_nbm['send_as_mail_address'] = get_webmaster_mail_address(); + $env_nbm['send_as_mail_formated'] = format_email($env_nbm['send_as_name'], $env_nbm['send_as_mail_address']); + // Init mail counter + $env_nbm['error_on_mail_count'] = 0; + $env_nbm['sent_mail_count'] = 0; + // Save sendmail message info and error in the original language + $env_nbm['msg_info'] = l10n('nbm_msg_mail_sent_to'); + $env_nbm['msg_error'] = l10n('nbm_msg_error_sending_email_to'); + } +} + +/* + * End of use nbm environment + * Restore environment + * + * Return none + */ +function end_users_env_nbm() +{ + global $user, $lang, $lang_info, $env_nbm; + + // Restore $user, $lang_info and $lang arrays (include/user.inc.php has been executed) + $user = $env_nbm['save_user']; + $lang_info = $env_nbm['save_lang_info']; + $lang = $env_nbm['save_lang']; +} + +/* + * Set user_id on nbm enviromnent + * + * Return none + */ +function set_user_id_on_env_nbm($user_id) +{ + global $user, $lang, $lang_info, $env_nbm; + + $user = array(); + $user['id'] = $user_id; + $user = array_merge($user, getuserdata($user['id'], true)); + + if ($env_nbm['last_language'] != $user['language']) + { + $env_nbm['last_language'] = $user['language']; + + // Re-Init language arrays + $lang_info = array(); + $lang = array(); + + // language files + include(get_language_filepath('common.lang.php')); + // No test admin because script is checked admin (user selected no) + // Translations are in admin file too + include(get_language_filepath('admin.lang.php')); + } +} + +/* + * Inc Counter success + * + * Return none + */ +function inc_mail_sent_success($nbm_user) +{ + global $page, $env_nbm; + + $env_nbm['sent_mail_count'] += 1; + array_push($page['infos'], sprintf($env_nbm['msg_info'], $nbm_user['username'], $nbm_user['mail_address'])); +} + +/* + * Inc Counter failed + * + * Return none + */ +function inc_mail_sent_failed($nbm_user) +{ + global $page, $env_nbm; + + $env_nbm['error_on_mail_count'] += 1; + array_push($page['errors'], sprintf($env_nbm['msg_error'], $nbm_user['username'], $nbm_user['mail_address'])); +} + +/* + * Display Counter Info + * + * Return none + */ +function display_counter_info() +{ + global $page, $env_nbm; + + if ($env_nbm['error_on_mail_count'] != 0) + { + array_push($page['errors'], sprintf(l10n('nbm_msg_no_mail_to_send'), $env_nbm['error_on_mail_count'])); + if ($env_nbm['sent_mail_count'] != 0) + array_push($page['infos'], sprintf(l10n('nbm_msg_n_mails_sent'), $env_nbm['sent_mail_count'])); + } + else + { + if ($env_nbm['sent_mail_count'] == 0) + array_push($page['infos'], l10n('nbm_no_mail_to_send')); + else + array_push($page['infos'], sprintf(l10n('nbm_msg_n_mails_sent'), $env_nbm['sent_mail_count'])); + } +} + +function get_mail_content_subscribe_unsubcribe($nbm_user) +{ + global $page, $env_nbm; + + $content = "\n\n\n"; + + if ( isset($page['root_path']) ) + { + $save_root_path = $page['root_path']; + } + + $page['root_path'] = 'http://'.$_SERVER['HTTP_HOST'].cookie_path(); + + $content .= "___________________________________________________\n\n"; + $content .= sprintf(l10n('nbm_content_unsubscribe_link'), add_url_params(get_root_url().'/nbm.php', array('unsubscribe' => $nbm_user['check_key'])))."\n"; + $content .= sprintf(l10n('nbm_content_subscribe_link'), add_url_params(get_root_url().'/nbm.php', array('subscribe' => $nbm_user['check_key'])))."\n"; + $content .= sprintf(l10n('nbm_content_subscribe_unsubscribe_contact'), $env_nbm['send_as_mail_address'])."\n"; + $content .= "___________________________________________________\n\n\n\n"; + + if (isset($save_root_path)) + { + $page['root_path'] = $save_root_path; + } + else + { + unset($page['root_path']); + } + + return $content; +} + /* * Subscribe or unsubscribe notification by mail * @@ -73,70 +320,121 @@ function quote_check_key_list($check_key_list = array()) * * @return updated data count */ -function do_subscribe_unsubcribe_notification_by_mail($is_subscribe = false, $check_key_list = array()) +function do_subscribe_unsubcribe_notification_by_mail($is_admin_request, $is_subscribe = false, $check_key_list = array()) { - global $page; + global $conf, $page, $env_nbm, $conf; $updated_data_count = 0; + $error_on_updated_data_count = 0; + if ($is_subscribe) { $msg_info = l10n('nbm_user_change_enabled_true'); + $msg_error = l10n('nbm_user_not_change_enabled_true'); } else { $msg_info = l10n('nbm_user_change_enabled_false'); + $msg_error = l10n('nbm_user_not_change_enabled_false'); } if (count($check_key_list) != 0) { - $quoted_check_key_list = quote_check_key_list($check_key_list); + $updates = array(); + $enabled_value = boolean_to_string($is_subscribe); + $data_users = get_user_notifications('subscribe', $check_key_list, !$is_subscribe); - $query = ' -select - N.check_key, U.username, U.mail_address -from - '.USER_MAIL_NOTIFICATION_TABLE.' as N, - '.USERS_TABLE.' as U -where - N.user_id = U.id and - N.enabled = \''.boolean_to_string(!$is_subscribe).'\' and - check_key in ('.implode(",", $quoted_check_key_list).') -order by - username;'; + // Begin nbm users environment + begin_users_env_nbm(true); - $result = pwg_query($query); - if (!empty($result)) + foreach ($data_users as $nbm_user) { - $updates = array(); - $enabled_value = boolean_to_string($is_subscribe); + if (($env_nbm['error_on_mail_count'] + $env_nbm['sent_mail_count']) >= $conf['nbm_max_mails_send']) + { + // Stop fill list on 'send', if the quota is override + array_push($page['errors'], sprintf(l10n('nbm_nbm_break_send_mail'), $conf['nbm_max_mails_send'])); + break; + } + + $do_update = true; + if ($nbm_user['mail_address'] != '') + { + // set env nbm user + set_user_id_on_env_nbm($nbm_user['user_id']); + + $message = ''; + + $subject = '['.$conf['gallery_title'].']: '.($is_subscribe ? l10n('nbm_object_subcribe'): l10n('nbm_object_unsubcribe')); + $message .= sprintf(l10n('nbm_content_hello'), $nbm_user['username']).",\n\n"; + + if ($is_subscribe) + { + $message .= l10n($is_admin_request ? 'nbm_content_subscribe_by_admin' : 'nbm_content_subscribe_by_himself'); + } + else + { + $message .= l10n($is_admin_request ? 'nbm_content_unsubscribe_by_admin' : 'nbm_content_unsubscribe_by_himself'); + } + + $message .= "\n\n"; + $message .= l10n('nbm_content_byebye')."\n ".$env_nbm['send_as_name']."\n\n"; + + $message .= get_mail_content_subscribe_unsubcribe($nbm_user); + + if (pwg_mail(format_email($nbm_user['username'], $nbm_user['mail_address']), $env_nbm['send_as_mail_formated'], $subject, $message)) + { + inc_mail_sent_success($nbm_user); + } + else + { + inc_mail_sent_failed($nbm_user); + $do_update = false; + } + } - while ($row = mysql_fetch_array($result)) + if ($do_update) { array_push ( $updates, array ( - 'check_key' => $row['check_key'], + 'check_key' => $nbm_user['check_key'], 'enabled' => $enabled_value ) ); $updated_data_count += 1; - array_push($page['infos'], sprintf($msg_info, $row['username'], $row['mail_address'])); + array_push($page['infos'], sprintf($msg_info, $nbm_user['username'], $nbm_user['mail_address'])); + } + else + { + $error_on_updated_data_count += 1; + array_push($page['errors'], sprintf($msg_error, $nbm_user['username'], $nbm_user['mail_address'])); } - mass_updates( - USER_MAIL_NOTIFICATION_TABLE, - array( - 'primary' => array('check_key'), - 'update' => array('enabled') - ), - $updates - ); } + + // Restore nbm environment + end_users_env_nbm(); + + display_counter_info(); + + mass_updates( + USER_MAIL_NOTIFICATION_TABLE, + array( + 'primary' => array('check_key'), + 'update' => array('enabled') + ), + $updates + ); + } array_push($page['infos'], sprintf(l10n('nbm_user_change_enabled_updated_data_count'), $updated_data_count)); + if ($error_on_updated_data_count != 0) + { + array_push($page['errors'], sprintf(l10n('nbm_user_change_enabled_error_on_updated_data_count'), $error_on_updated_data_count)); + } return $updated_data_count; } @@ -148,9 +446,9 @@ order by * * @return updated data count */ -function unsubcribe_notification_by_mail($check_key_list = array()) +function unsubcribe_notification_by_mail($is_admin_request, $check_key_list = array()) { - return do_subscribe_unsubcribe_notification_by_mail(false, $check_key_list); + return do_subscribe_unsubcribe_notification_by_mail($is_admin_request, false, $check_key_list); } /* @@ -160,9 +458,9 @@ function unsubcribe_notification_by_mail($check_key_list = array()) * * @return updated data count */ -function subcribe_notification_by_mail($check_key_list = array()) +function subcribe_notification_by_mail($is_admin_request, $check_key_list = array()) { - return do_subscribe_unsubcribe_notification_by_mail(true, $check_key_list); + return do_subscribe_unsubcribe_notification_by_mail($is_admin_request, true, $check_key_list); } ?> \ No newline at end of file diff --git a/admin/notification_by_mail.php b/admin/notification_by_mail.php index fdeafbe60..85f583848 100644 --- a/admin/notification_by_mail.php +++ b/admin/notification_by_mail.php @@ -73,69 +73,6 @@ function get_tab_status($mode) return $result; } -/* - * Execute all main queries to get list of user - * - * Type are the type of list 'subscribe', 'send' - * - * return array of users - */ -function get_user_notifications($action, $check_key_list = array()) -{ - global $conf; - - $data_users = array(); - - if (in_array($action, array('subscribe', 'send'))) - { - $quoted_check_key_list = quote_check_key_list($check_key_list); - if (count($quoted_check_key_list) != 0 ) - { - $query_and_check_key = ' and - check_key in ('.implode(",", $quoted_check_key_list).') '; - } - else - { - $query_and_check_key = ''; - } - - $query = ' -select - N.user_id, - N.check_key, - U.'.$conf['user_fields']['username'].' as username, - U.'.$conf['user_fields']['email'].' as mail_address, - N.enabled, - N.last_send -from - '.USER_MAIL_NOTIFICATION_TABLE.' as N, - '.USERS_TABLE.' as U -where - N.user_id = U.'.$conf['user_fields']['id']; - - if ($action == 'send') - { - $query .= ' and - N.enabled = \'true\' and - U.'.$conf['user_fields']['email'].' is not null'.$query_and_check_key; - } - - $query .= ' -order by - username;'; - - $result = pwg_query($query); - if (!empty($result)) - { - while ($nbm_user = mysql_fetch_array($result)) - { - array_push($data_users, $nbm_user); - } - } - } - return $data_users; -} - /* * Inserting News users */ @@ -194,7 +131,7 @@ order by ) ); - array_push($page['infos'], sprintf(l10n('nbm_User %s [%s] added.'), $nbm_user['username'], $nbm_user['mail_address'])); + array_push($page['infos'], sprintf(l10n('nbm_user_x_added'), $nbm_user['username'], $nbm_user['mail_address'])); } // Insert new nbm_users @@ -202,7 +139,8 @@ order by // Update field enabled with specific function do_subscribe_unsubcribe_notification_by_mail ( - ($conf['default_value_user_mail_notification_enabled'] == true ? true : false), + true, + $conf['nbm_default_value_user_enabled'], $check_key_list ); } @@ -212,12 +150,12 @@ order by * Send mail for notification to all users * Return list of "treated/selected" users */ -function do_action_send_mail_notification($action = 'list', $check_key_list = array(), $customize_mail_content = '') +function do_action_send_mail_notification($action = 'list_to_send', $check_key_list = array(), $customize_mail_content = '') { - global $conf, $page, $user, $lang_info, $lang; + global $conf, $page, $user, $lang_info, $lang, $env_nbm; $return_list = array(); - if (in_array($action, array('list', 'send'))) + if (in_array($action, array('list_to_send', 'send'))) { list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); @@ -231,156 +169,133 @@ function do_action_send_mail_notification($action = 'list', $check_key_list = ar // disabled and null mail_address are not selected in the list $data_users = get_user_notifications('send', $check_key_list); - if (count($data_users) > 0) + // Check if exist news to list user or send mails + if (($conf['nbm_list_all_enabled_users_to_send'] == false) or ($is_action_send)) { - $error_on_mail_count = 0; - $sent_mail_count = 0; - // Save $user, $lang_info and $lang arrays (include/user.inc.php has been executed) - $sav_mailtousers_user = $user; - $sav_mailtousers_lang_info = $lang_info; - $sav_mailtousers_lang = $lang; - // Save message info and error in the original language - $msg_info = l10n('nbm_Mail sent to %s [%s].'); - $msg_error = l10n('nbm_Error when sending email to %s [%s].'); - // Last Language - $last_mailtousers_language = $user['language']; - - if ($is_action_send) - { - // Init mail configuration - $send_as_name = ((isset($conf['nbm_send_mail_as']) and !empty($conf['nbm_send_mail_as'])) ? $conf['nbm_send_mail_as'] : $conf['gallery_title']); - $send_as_mail_address = get_webmaster_mail_address(); - $send_as_mail_formated = format_email($send_as_name, $send_as_mail_address); - } - - foreach ($data_users as $nbm_user) + if (count($data_users) > 0) { - $user = array(); - $user['id'] = $nbm_user['user_id']; - $user = array_merge($user, getuserdata($user['id'], true)); + $datas = array(); - if ($last_mailtousers_language != $user['language']) - { - $last_mailtousers_language = $user['language']; - - // Re-Init language arrays - $lang_info = array(); - $lang = array(); + // Begin nbm users environment + begin_users_env_nbm($is_action_send); - // language files - include(get_language_filepath('common.lang.php')); - // No test admin because script is checked admin (user selected no) - // Translations are in admin file too - include(get_language_filepath('admin.lang.php')); - } - - if ($is_action_send) + foreach ($data_users as $nbm_user) { - $message = ''; - - if ($conf['nbm_send_detailed_content']) + if ((!$is_action_send) and (count($return_list) >= $conf['nbm_max_list_users_to_send'])) { - $news = news($nbm_user['last_send'], $dbnow); - $exist_data = count($news) > 0; + // Stop fill list on 'list_to_send', if the quota is override + array_push($page['infos'], sprintf(l10n('nbm_break_list_user'), $conf['nbm_max_list_users_to_send'])); + break; } - else + if (($is_action_send) and (count($return_list) >= $conf['nbm_max_mails_send'])) { - $exist_data = news_exists($nbm_user['last_send'], $dbnow); + // Stop fill list on 'send', if the quota is override + array_push($page['errors'], sprintf(l10n('nbm_nbm_break_send_mail'), $conf['nbm_max_mails_send'])); + break; } - if ($exist_data) - { - array_push($return_list, $nbm_user); + // set env nbm user + set_user_id_on_env_nbm($nbm_user['user_id']); - $subject = '['.$conf['gallery_title'].']: '.l10n('nbm_ContentObject'); - $message .= sprintf(l10n('nbm_ContentHello'), $nbm_user['username']).",\n\n"; - - if (!is_null($nbm_user['last_send'])) - $message .= sprintf(l10n('nbm_ContentNewElementsBetween'), $nbm_user['last_send'], $dbnow); - else - $message .= sprintf(l10n('nbm_ContentNewElements'), $dbnow); + if ($is_action_send) + { + $message = ''; if ($conf['nbm_send_detailed_content']) { - $message .= ":\n"; - - foreach ($news as $line) - { - $message .= ' o '.$line."\n"; - } - $message .= "\n"; + $news = news($nbm_user['last_send'], $dbnow); + $exist_data = count($news) > 0; } else { - $message .= ".\n"; + $exist_data = news_exists($nbm_user['last_send'], $dbnow); } - $message .= sprintf(l10n('nbm_ContentGoTo'), $conf['gallery_title'], $conf['gallery_url'])."\n\n"; - $message .= $customize_mail_content."\n\n"; - $message .= l10n('nbm_ContentByeBye')."\n ".$send_as_name."\n\n"; - $message .= "\n".sprintf(l10n('nbm_ContentUnsubscribe'), $send_as_mail_address)."\n\n"; - - if (pwg_mail(format_email($nbm_user['username'], $nbm_user['mail_address']), $send_as_mail_formated, $subject, $message)) + if ($exist_data) { - $sent_mail_count += 1; - array_push($page['infos'], sprintf($msg_info, $nbm_user['username'], $nbm_user['mail_address'])); + array_push($return_list, $nbm_user); - $data = array('user_id' => $user_notification['user_id'], - 'last_send' => $dbnow); - array_push($datas, $data); - } - else - { - $error_on_mail_count += 1; - array_push($page['errors'], sprintf($msg_error, $nbm_user['username'], $nbm_user['mail_address'])); + $subject = '['.$conf['gallery_title'].']: '.l10n('nbm_object_news'); + $message .= sprintf(l10n('nbm_content_hello'), $nbm_user['username']).",\n\n"; + + if (!is_null($nbm_user['last_send'])) + $message .= sprintf(l10n('nbm_content_new_elements_between'), $nbm_user['last_send'], $dbnow); + else + $message .= sprintf(l10n('nbm_content_new_elements'), $dbnow); + + if ($conf['nbm_send_detailed_content']) + { + $message .= ":\n"; + + foreach ($news as $line) + { + $message .= ' o '.$line."\n"; + } + $message .= "\n"; + } + else + { + $message .= ".\n"; + } + + $message .= sprintf(l10n('nbm_content_goto'), $conf['gallery_title'], $conf['gallery_url'])."\n\n"; + $message .= $customize_mail_content."\n\n"; + $message .= l10n('nbm_content_byebye')."\n ".$env_nbm['send_as_name']."\n\n"; + + $message .= get_mail_content_subscribe_unsubcribe($nbm_user); + + if (pwg_mail(format_email($nbm_user['username'], $nbm_user['mail_address']), $env_nbm['send_as_mail_formated'], $subject, $message)) + { + inc_mail_sent_success($nbm_user); + + $data = array('user_id' => $nbm_user['user_id'], + 'last_send' => $dbnow); + array_push($datas, $data); + } + else + { + inc_mail_sent_failed($nbm_user); + } } } - } - else - { - if (news_exists($nbm_user['last_send'], $dbnow)) + else { - array_push($return_list, $nbm_user); + if (news_exists($nbm_user['last_send'], $dbnow)) + { + array_push($return_list, $nbm_user); + } } } - } - - // Restore $user, $lang_info and $lang arrays (include/user.inc.php has been executed) - $user = $sav_mailtousers_user; - $lang_info = $sav_mailtousers_lang_info; - $lang = $sav_mailtousers_lang; - - if ($is_action_send) - { - mass_updates( - USER_MAIL_NOTIFICATION_TABLE, - array( - 'primary' => array('user_id'), - 'update' => array('last_send') - ), - $datas - ); + // Restore nbm environment + end_users_env_nbm(); - if ($error_on_mail_count != 0) + if ($is_action_send) { - array_push($page['errors'], sprintf(l10n('nbm_%d mails were not sent.'), $error_on_mail_count)); + mass_updates( + USER_MAIL_NOTIFICATION_TABLE, + array( + 'primary' => array('user_id'), + 'update' => array('last_send') + ), + $datas + ); + + display_counter_info(); } - else + } + else + { + if ($is_action_send) { - if ($sent_mail_count == 0) - array_push($page['infos'], l10n('nbm_No mail to send.')); - else - array_push($page['infos'], sprintf(l10n('nbm_%d mails were sent.'), $sent_mail_count)); + array_push($page['errors'], l10n('nbm_no_user_to send_notifications_by_mail')); } } } else { - if ($is_action_send) - { - array_push($page['errors'], l10n('nbm_No user to send notifications by mail.')); - } + // Quick List, don't check news + $return_list = $data_users; } } return $return_list; @@ -468,12 +383,12 @@ where { if (isset($_POST['falsify']) and isset($_POST['cat_true'])) { - unsubcribe_notification_by_mail($_POST['cat_true']); + unsubcribe_notification_by_mail(true, $_POST['cat_true']); } else if (isset($_POST['trueify']) and isset($_POST['cat_false'])) { - subcribe_notification_by_mail($_POST['cat_false']); + subcribe_notification_by_mail(true, $_POST['cat_false']); } break; } @@ -559,7 +474,10 @@ switch ($page['mode']) { $template->assign_block_vars( (get_boolean($nbm_user['enabled']) ? 'category_option_true' : 'category_option_false'), - array('SELECTED' => '', + array('SELECTED' => ( // Keep selected user where enabled are not changed when change has been notify + get_boolean($nbm_user['enabled']) ? (isset($_POST['falsify']) and isset($_POST['cat_true']) and in_array($nbm_user['check_key'], $_POST['cat_true'])) + : (isset($_POST['trueify']) and isset($_POST['cat_false']) and in_array($nbm_user['check_key'], $_POST['cat_false'])) + ) ? 'selected="selected"' : '', 'VALUE' => $nbm_user['check_key'], 'OPTION' => $nbm_user['username'].'['.$nbm_user['mail_address'].']' )); @@ -572,7 +490,7 @@ switch ($page['mode']) { $template->assign_block_vars($page['mode'], array()); - $data_users = do_action_send_mail_notification('list'); + $data_users = do_action_send_mail_notification('list_to_send'); if (count($data_users) == 0) { diff --git a/include/config_default.inc.php b/include/config_default.inc.php index b6427772e..3675f2ed6 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -438,4 +438,22 @@ $conf['picture_url_style'] = 'id'; // are active. $conf['php_extension_in_urls'] = true; +// +-----------------------------------------------------------------------+ +// | Notification by mail | +// +-----------------------------------------------------------------------+ + +// Default Value for nbm user +$conf['nbm_default_value_user_enabled'] = false; + +// Max user to show on list users to send notification +// Parameter not used if $conf['nbm_list_all_enabled_users_to_send'] is true +$conf['nbm_max_list_users_to_send'] = 100; + +// Search List user to send with quick (List all without check news) +// More quickly but less fun to use +$conf['nbm_list_all_enabled_users_to_send'] = false; + +// Max mails sended on one pass +$conf['nbm_max_mails_send'] = 35; + ?> diff --git a/install/db/18-database.php b/install/db/18-database.php new file mode 100644 index 000000000..13fb615bf --- /dev/null +++ b/install/db/18-database.php @@ -0,0 +1,92 @@ + $row['user_id'], + 'check_key' => find_available_check_key() + ) + ); +} + +mass_updates( + USER_MAIL_NOTIFICATION_TABLE, + array( + 'primary' => array('user_id'), + 'update' => array('check_key') + ), + $datas + ); + +echo "Alter table ".USER_MAIL_NOTIFICATION_TABLE; +$query = " +alter table ".USER_MAIL_NOTIFICATION_TABLE." + modify column `check_key` varchar(16) binary NOT NULL default '' +;"; +pwg_query($query); + + +// +-----------------------------------------------------------------------+ +// | End notification | +// +-----------------------------------------------------------------------+ + +echo +"\n" +.'Column '.USER_MAIL_NOTIFICATION_TABLE.'.check_key changed' +."\n" +; + +?> diff --git a/install/phpwebgallery_structure.sql b/install/phpwebgallery_structure.sql index f46babd5c..4c682d738 100644 --- a/install/phpwebgallery_structure.sql +++ b/install/phpwebgallery_structure.sql @@ -317,7 +317,7 @@ CREATE TABLE `phpwebgallery_user_infos` ( DROP TABLE IF EXISTS `phpwebgallery_user_mail_notification`; CREATE TABLE `phpwebgallery_user_mail_notification` ( `user_id` smallint(5) NOT NULL default '0', - `check_key` varchar(128) binary NOT NULL default '', + `check_key` varchar(16) binary NOT NULL default '', `enabled` enum('true','false') NOT NULL default 'false', `last_send` datetime default NULL, PRIMARY KEY (`user_id`), diff --git a/language/en_UK.iso-8859-1/admin.lang.php b/language/en_UK.iso-8859-1/admin.lang.php index b5ed27c4c..81b1aeb20 100644 --- a/language/en_UK.iso-8859-1/admin.lang.php +++ b/language/en_UK.iso-8859-1/admin.lang.php @@ -238,21 +238,31 @@ $lang['metadata_basic'] = 'basic'; $lang['metadata_exif'] = 'EXIF'; $lang['metadata_iptc'] = 'IPTC'; $lang['name'] = 'name'; -$lang['nbm_%d mails were not sent.'] = '%d mails were not sent.'; -$lang['nbm_%d mails were sent.'] = '%d mails were sent.'; -$lang['nbm_Error when sending email to %s [%s].'] = 'Error when sending email to %s [%s].'; -$lang['nbm_Mail sent to %s [%s].'] = 'Mail sent to %s [%s].'; -$lang['nbm_ContentObject'] = 'New elements added'; -$lang['nbm_ContentHello'] = 'Hello %s'; -$lang['nbm_ContentNewElementsBetween'] = 'New elements were added between %s and %s'; -$lang['nbm_ContentNewElements'] = 'New elements were added on %s'; -$lang['nbm_ContentGoTo'] = 'Go to %s %s.'; -$lang['nbm_ContentByeBye'] = 'See you soon'; -$lang['nbm_ContentUnsubscribe'] = 'To unsubscribe send a message to %s.'; -$lang['nbm_No mail to send.'] = 'No mail to send.'; -$lang['nbm_No user to send notifications by mail.'] = 'No user to send notifications by mail.'; -$lang['nbm_Send mail to users'] = 'Send mail to users'; -$lang['nbm_User %s [%s] added.'] = 'User %s [%s] added.'; +$lang['nbm_break_list_user'] = 'List of users to send mail is limited to %d. Others users are not listed.'; +$lang['nbm_nbm_break_send_mail'] = 'Sent mail is limited to %d send by pass. Others mails are skipped.'; +$lang['nbm_msg_no_mail_to_send'] = '%d mails were not sent.'; +$lang['nbm_msg_n_mails_sent'] = '%d mails were sent.'; +$lang['nbm_msg_error_sending_email_to'] = 'Error when sending email to %s [%s].'; +$lang['nbm_msg_mail_sent_to'] = 'Mail sent to %s [%s].'; +$lang['nbm_object_news'] = 'New elements added'; +$lang['nbm_object_subcribe'] = 'Subcribe of notification by mail'; +$lang['nbm_object_unsubcribe'] = 'Unsubcribe of notification by mail'; +$lang['nbm_content_hello'] = 'Hello %s'; +$lang['nbm_content_new_elements_between'] = 'New elements were added between %s and %s'; +$lang['nbm_content_new_elements'] = 'New elements were added on %s'; +$lang['nbm_content_goto'] = 'Go to %s %s.'; +$lang['nbm_content_subscribe_by_admin'] = 'You are subcribed by webmaster for the notification by mail'; +$lang['nbm_content_unsubscribe_by_admin'] = 'You are unsubcribed by webmaster for the notification by mail'; +$lang['nbm_content_subscribe_by_himself'] = 'You are subcribed for the notification by mail'; +$lang['nbm_content_unsubscribe_by_himself'] = 'You are unsubcribed for the notification by mail'; +$lang['nbm_content_byebye'] = 'See you soon'; +$lang['nbm_content_unsubscribe_link'] = 'To unsubscribe, click on %s .'; +$lang['nbm_content_subscribe_link'] = 'To subscribe, click on %s .'; +$lang['nbm_content_subscribe_unsubscribe_contact'] = 'On problems or questions, send a message to %s.'; +$lang['nbm_no_mail_to_send'] = 'No mail to send.'; +$lang['nbm_no_user_to send_notifications_by_mail'] = 'No user to send notifications by mail.'; +$lang['nbm_send_mail_to_users'] = 'Send mail to users'; +$lang['nbm_user_x_added'] = 'User %s [%s] added.'; $lang['nbm_item_notification'] = 'Notification'; $lang['nbm_param_mode'] = 'Parameter'; $lang['nbm_subscribe_mode'] = 'Subscribe'; @@ -264,7 +274,7 @@ $lang['nbm_info_send_mail_as'] = 'With blank value, gallery title will be used'; $lang['nbm_send_detailed_content'] = 'Send detailed content'; $lang['nbm_complementary_mail_content'] = 'Complementary mail content'; $lang['nbm_title_subscribe'] = 'Subscribe/unscribe users'; -$lang['nbm_warning_subscribe_unsubcribe'] = 'Warning, subscribe or unscribe send mails to users [Not Implemented]'; +$lang['nbm_warning_subscribe_unsubcribe'] = 'Warning, subscribe or unscribe send mails to users'; $lang['nbm_subscribe_col'] = 'Subscribed'; $lang['nbm_unsubscribe_col'] = 'Unsubcribed'; $lang['nbm_no_user_available_to_send_L1'] = 'No user are available in order to send mail.'; @@ -281,7 +291,10 @@ $lang['nbm_send_check_all'] = 'Check All'; $lang['nbm_send_uncheck_all'] = 'Uncheck All'; $lang['nbm_user_change_enabled_true'] = 'User %s [%s] added to subscribe list.'; $lang['nbm_user_change_enabled_false'] = 'User %s [%s] removed of subscribe list.'; +$lang['nbm_user_not_change_enabled_true'] = 'User %s [%s] not added to subscribe list.'; +$lang['nbm_user_not_change_enabled_false'] = 'User %s [%s] not removed of subscribe list.'; $lang['nbm_user_change_enabled_updated_data_count'] = '%d user(s) are updated.'; +$lang['nbm_user_change_enabled_error_on_updated_data_count'] = '%d user(s) are not updated.'; $lang['no_write_access'] = 'no write access'; $lang['order_by'] = 'order by'; $lang['path'] = 'path'; diff --git a/language/en_UK.iso-8859-1/common.lang.php b/language/en_UK.iso-8859-1/common.lang.php index f8dd99a22..abe3bc29b 100644 --- a/language/en_UK.iso-8859-1/common.lang.php +++ b/language/en_UK.iso-8859-1/common.lang.php @@ -105,6 +105,7 @@ $lang['Sort by'] = 'Sort by'; $lang['Sort order'] = 'Sort order'; $lang['The RSS notification feed provides notification on news from this website : new pictures, updated categories, new comments. Use a RSS feed reader.'] = 'The RSS notification feed provides notification on news from this website : new pictures, updated categories, new comments. Use a RSS feed reader.'; $lang['Unknown feed identifier'] = 'Unknown feed identifier'; +$lang['nbm_unknown_identifier'] = 'Unknown identifier'; $lang['User comments'] = 'User comments'; $lang['Username'] = 'Username'; $lang['Visits'] = 'Visits'; diff --git a/language/fr_FR.iso-8859-1/admin.lang.php b/language/fr_FR.iso-8859-1/admin.lang.php index 58d85a647..69a7c3523 100644 --- a/language/fr_FR.iso-8859-1/admin.lang.php +++ b/language/fr_FR.iso-8859-1/admin.lang.php @@ -238,21 +238,31 @@ $lang['metadata_basic'] = 'basique'; $lang['metadata_exif'] = 'EXIF'; $lang['metadata_iptc'] = 'IPTC'; $lang['name'] = 'nom'; -$lang['nbm_%d mails were not sent.'] = '%s mails n\'ont pas été envoyés.'; -$lang['nbm_%d mails were sent.'] = '%s mails ont été envoyés.'; -$lang['nbm_Error when sending email to %s [%s].'] = 'Erreur lors de l\'envoi du mail à %s [%s].'; -$lang['nbm_Mail sent to %s [%s].'] = 'Mail envoyé à %s [%s].'; -$lang['nbm_ContentObject'] = 'Nouveaux éléments ajoutés'; -$lang['nbm_ContentHello'] = 'Bonjour %s'; -$lang['nbm_ContentNewElementsBetween'] = 'Des nouveaux éléments ont été ajoutés entre le %s et le %s'; -$lang['nbm_ContentNewElements'] = 'Des nouveaux éléments ont été ajoutés le %s'; -$lang['nbm_ContentGoTo'] = 'Rendez-vous sur %s %s.'; -$lang['nbm_ContentByeBye'] = 'A bientôt'; -$lang['nbm_ContentUnsubscribe'] = 'Pour vous désinscrire, envoyer un mail à %s.'; -$lang['nbm_No mail to send.'] = 'Pas de mail à envoyer.'; -$lang['nbm_No user to send notifications by mail.'] = 'Pas d\'utilisateur pour envoyer des notifications par mails.'; -$lang['nbm_Send mail to users'] = 'Envoi de mail aux utilisateurs'; -$lang['nbm_User %s [%s] added.'] = 'Utilisateur %s [%s] ajouté.'; +$lang['nbm_break_list_user'] = 'La liste des utilisateurs pour l\'envoi est limitéé à %d. Les autres utilisateurs ne sont pas listés.'; +$lang['nbm_nbm_break_send_mail'] = 'Les mails envoyés sont limités à %d envois d\'une seule passe. Les autres envois de mail ont été ignorés.'; +$lang['nbm_msg_no_mail_to_send'] = '%s mails n\'ont pas été envoyés.'; +$lang['nbm_msg_n_mails_sent'] = '%s mails ont été envoyés.'; +$lang['nbm_msg_error_sending_email_to'] = 'Erreur lors de l\'envoi du mail à %s [%s].'; +$lang['nbm_msg_mail_sent_to'] = 'Mail envoyé à %s [%s].'; +$lang['nbm_object_news'] = 'Nouveaux éléments ajoutés'; +$lang['nbm_object_subcribe'] = 'Inscription à la notification par mail'; +$lang['nbm_object_unsubcribe'] = 'Désinscription à la notification par mail'; +$lang['nbm_content_hello'] = 'Bonjour %s'; +$lang['nbm_content_new_elements_between'] = 'Des nouveaux éléments ont été ajoutés entre le %s et le %s'; +$lang['nbm_content_new_elements'] = 'Des nouveaux éléments ont été ajoutés le %s'; +$lang['nbm_content_goto'] = 'Rendez-vous sur %s %s.'; +$lang['nbm_content_subscribe_by_admin'] = 'Vous venez d\'être inscrit par le webmestre du site pour revevoir la notification par mail.'; +$lang['nbm_content_unsubscribe_by_admin'] = 'Vous venez d\'être désinscrit par le webmestre du site pour revevoir la notification par mail.'; +$lang['nbm_content_subscribe_by_himself'] = 'Vous venez de vous inscrire pour revevoir la notification par mail.'; +$lang['nbm_content_unsubscribe_by_himself'] = 'Vous venez de vous désinscrire pour revevoir la notification par mail.'; +$lang['nbm_content_byebye'] = 'A bientôt'; +$lang['nbm_content_unsubscribe_link'] = 'Pour vous désinscrire, cliquez sur %s .'; +$lang['nbm_content_subscribe_link'] = 'Pour vous inscrire, cliquez sur %s .'; +$lang['nbm_content_subscribe_unsubscribe_contact'] = 'En cas de problèmes ou de questions, envoyer un mail à %s.'; +$lang['nbm_no_mail_to_send'] = 'Pas de mail à envoyer.'; +$lang['nbm_no_user_to send_notifications_by_mail'] = 'Pas d\'utilisateur pour envoyer des notifications par mails.'; +$lang['nbm_send_mail_to_users'] = 'Envoi de mail aux utilisateurs'; +$lang['nbm_user_x_added'] = 'Utilisateur %s [%s] ajouté.'; $lang['nbm_item_notification'] = 'Notification'; $lang['nbm_param_mode'] = 'Paramètrage'; $lang['nbm_subscribe_mode'] = 'Inscription'; @@ -264,7 +274,7 @@ $lang['nbm_info_send_mail_as'] = 'Sans valeur, le titre de la galerie sera utili $lang['nbm_send_detailed_content'] = 'Envoi d\'un contenu détaillé'; $lang['nbm_complementary_mail_content'] = 'Contenu complémentaire au mail'; $lang['nbm_title_subscribe'] = 'Inscrire/desinscrire les utilisateurs'; -$lang['nbm_warning_subscribe_unsubcribe'] = 'Attention, l\'inscription ou la desincription entraine l\'envoi de mails aux utilisateurs concernés [Fonction non implementée]'; +$lang['nbm_warning_subscribe_unsubcribe'] = 'Attention, l\'inscription ou la desincription entraine l\'envoi de mails aux utilisateurs concernés'; $lang['nbm_subscribe_col'] = 'Inscrits'; $lang['nbm_unsubscribe_col'] = 'Non Inscrits'; $lang['nbm_no_user_available_to_send_L1'] = 'Il n\'y a pas d\'utilisateur à notifier par mail.'; @@ -281,7 +291,10 @@ $lang['nbm_send_check_all'] = 'Tout cocher'; $lang['nbm_send_uncheck_all'] = 'Tout décocher'; $lang['nbm_user_change_enabled_true'] = 'L\'utilisateur %s [%s] a été ajouté à la liste des inscrits.'; $lang['nbm_user_change_enabled_false'] = 'L\'utilisateur %s [%s] a été supprimé de la liste des inscrits.'; -$lang['nbm_user_change_enabled_updated_data_count'] = '%d utilisateur(s) a(ont) été mis à jour.'; +$lang['nbm_user_not_change_enabled_true'] = 'L\'utilisateur %s [%s] n\'a pas été ajouté à la liste des inscrits.'; +$lang['nbm_user_not_change_enabled_false'] = 'L\'utilisateur %s [%s] n\'a pas été supprimé de la liste des inscrits.'; +$lang['nbm_user_change_enabled_updated_data_count'] = '%d utilisateurs ont été mis à jour.'; +$lang['nbm_user_change_enabled_error_on_updated_data_count'] = '%d utilisateurs n\'ont pas été mis à jour.'; $lang['no_write_access'] = 'pas d\'accès en écriture'; $lang['order_by'] = 'trier selon'; $lang['path'] = 'chemin'; diff --git a/language/fr_FR.iso-8859-1/common.lang.php b/language/fr_FR.iso-8859-1/common.lang.php index 13c2cb993..5a4ea1ac4 100644 --- a/language/fr_FR.iso-8859-1/common.lang.php +++ b/language/fr_FR.iso-8859-1/common.lang.php @@ -104,6 +104,7 @@ $lang['Sort by'] = 'Trier selon'; $lang['Sort order'] = 'Ordre de tri'; $lang['The RSS notification feed provides notification on news from this website : new pictures, updated categories, new comments. Use a RSS feed reader.'] = 'Le flux RSS notifie les événements de la galerie : nouvelles images, catégories mises à jour, nouveaux commentaires utilisateur. À utiliser avec un lecteur de flux RSS.'; $lang['Unknown feed identifier'] = 'Identifiant de flux inconnu'; +$lang['nbm_unknown_identifier'] = 'Identifiants inconnus'; $lang['User comments'] = 'Commentaires utilisateur'; $lang['Username'] = 'Nom d\'utilisateur'; $lang['Visits'] = 'Visites'; diff --git a/nbm.php b/nbm.php new file mode 100644 index 000000000..7aee31f8c --- /dev/null +++ b/nbm.php @@ -0,0 +1,88 @@ +'; + +if (count($page['errors']) != 0) +{ + echo "\n\nErrors:\n"; + foreach ($page['errors'] as $error) + { + echo $error."\n"; + } +} + +if (count($page['infos']) != 0) +{ + echo "\n\nInformations:\n"; + foreach ($page['infos'] as $info) + { + echo $info."\n"; + } +} + +echo ''; + + +?> \ No newline at end of file diff --git a/template/yoga/admin/notification_by_mail.tpl b/template/yoga/admin/notification_by_mail.tpl index c0c2424db..5809e9ec8 100644 --- a/template/yoga/admin/notification_by_mail.tpl +++ b/template/yoga/admin/notification_by_mail.tpl @@ -3,7 +3,7 @@ -

{lang:nbm_Send mail to users} [{U_TABSHEET_TITLE}]

+

{lang:nbm_send_mail_to_users} [{U_TABSHEET_TITLE}]

-- cgit v1.2.3