aboutsummaryrefslogtreecommitdiffstats
path: root/admin/notification_by_mail.php
diff options
context:
space:
mode:
Diffstat (limited to 'admin/notification_by_mail.php')
-rw-r--r--admin/notification_by_mail.php290
1 files changed, 104 insertions, 186 deletions
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
@@ -74,69 +74,6 @@ function get_tab_status($mode)
}
/*
- * 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
*/
function insert_new_data_user_mail_notification()
@@ -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)
{