aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--admin/include/functions_notification_by_mail.inc.php41
-rw-r--r--admin/notification_by_mail.php101
-rw-r--r--include/config_default.inc.php7
-rw-r--r--include/functions.inc.php88
-rw-r--r--include/page_header.php3
-rw-r--r--language/en_UK.iso-8859-1/admin.lang.php5
-rw-r--r--language/en_UK.iso-8859-1/common.lang.php1
-rw-r--r--language/fr_FR.iso-8859-1/admin.lang.php5
-rw-r--r--language/fr_FR.iso-8859-1/common.lang.php1
-rw-r--r--template/yoga/redirect.tpl2
10 files changed, 218 insertions, 36 deletions
diff --git a/admin/include/functions_notification_by_mail.inc.php b/admin/include/functions_notification_by_mail.inc.php
index d19085685..bfaaf8cb0 100644
--- a/admin/include/functions_notification_by_mail.inc.php
+++ b/admin/include/functions_notification_by_mail.inc.php
@@ -27,7 +27,13 @@
// +-----------------------------------------------------------------------+
/* nbm_global_var */
-$env_nbm = array();
+$env_nbm = array
+ (
+ 'start_time' => get_moment(),
+ 'sendmail_timeout' => (intval(ini_get('max_execution_time')) * $conf['nbm_max_treatment_timeout_percent']),
+ 'is_sendmail_timeout' => false
+ );
+
/*
* Search an available check_key
@@ -57,6 +63,20 @@ where
}
}
+/*
+ * Check sendmail timeout state
+ *
+ * @return true, if it's timeout
+ */
+function check_sendmail_timeout()
+{
+ global $env_nbm;
+
+ $env_nbm['is_sendmail_timeout'] = ((get_moment() - $env_nbm['start_time']) > $env_nbm['sendmail_timeout']);
+
+ return $env_nbm['is_sendmail_timeout'];
+}
+
/*
* Add quote to all elements of check_key_list
@@ -318,12 +338,13 @@ function get_mail_content_subscribe_unsubcribe($nbm_user)
* is_subscribe define if action=subscribe or unsubscribe
* check_key list where action will be done
*
- * @return updated data count
+ * @return check_key lisr treated
*/
function do_subscribe_unsubcribe_notification_by_mail($is_admin_request, $is_subscribe = false, $check_key_list = array())
{
global $conf, $page, $env_nbm, $conf;
+ $check_key_treated = array();
$updated_data_count = 0;
$error_on_updated_data_count = 0;
@@ -344,18 +365,24 @@ function do_subscribe_unsubcribe_notification_by_mail($is_admin_request, $is_sub
$enabled_value = boolean_to_string($is_subscribe);
$data_users = get_user_notifications('subscribe', $check_key_list, !$is_subscribe);
+ // Prepare message after change language
+ $msg_break_timeout = l10n('nbm_nbm_break_timeout_send_mail');
+
// Begin nbm users environment
begin_users_env_nbm(true);
foreach ($data_users as $nbm_user)
{
- if (($env_nbm['error_on_mail_count'] + $env_nbm['sent_mail_count']) >= $conf['nbm_max_mails_send'])
+ if (check_sendmail_timeout())
{
// 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']));
+ array_push($page['errors'], $msg_break_timeout);
break;
}
+ // Fill return list
+ array_push($check_key_treated, $nbm_user['check_key']);
+
$do_update = true;
if ($nbm_user['mail_address'] != '')
{
@@ -436,7 +463,7 @@ function do_subscribe_unsubcribe_notification_by_mail($is_admin_request, $is_sub
array_push($page['errors'], sprintf(l10n('nbm_user_change_enabled_error_on_updated_data_count'), $error_on_updated_data_count));
}
- return $updated_data_count;
+ return $check_key_treated;
}
/*
@@ -444,7 +471,7 @@ function do_subscribe_unsubcribe_notification_by_mail($is_admin_request, $is_sub
*
* check_key list where action will be done
*
- * @return updated data count
+ * @return check_key lisr treated
*/
function unsubcribe_notification_by_mail($is_admin_request, $check_key_list = array())
{
@@ -456,7 +483,7 @@ function unsubcribe_notification_by_mail($is_admin_request, $check_key_list = ar
*
* check_key list where action will be done
*
- * @return updated data count
+ * @return check_key lisr treated
*/
function subcribe_notification_by_mail($is_admin_request, $check_key_list = array())
{
diff --git a/admin/notification_by_mail.php b/admin/notification_by_mail.php
index 85f583848..9d700b45b 100644
--- a/admin/notification_by_mail.php
+++ b/admin/notification_by_mail.php
@@ -47,10 +47,47 @@ include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
check_status(ACCESS_ADMINISTRATOR);
// +-----------------------------------------------------------------------+
+// | Initialization |
+// +-----------------------------------------------------------------------+
+$base_url = get_root_url().'admin.php';
+
+// +-----------------------------------------------------------------------+
// | functions |
// +-----------------------------------------------------------------------+
/*
+ * Do background treatmetn in order to finish to send mails
+ *
+ * @param $post_keyname: key of check_key post array
+ * @param check_key_treated:array of check_key treated
+ * @return none
+ */
+function do_background_treatment($post_keyname, $check_key_treated = array())
+{
+ global $env_nbm, $base_url;
+
+ if ($env_nbm['is_sendmail_timeout'])
+ {
+ if (isset($_POST[$post_keyname]))
+ {
+ $post_count = count($_POST[$post_keyname]);
+ $treated_count = count($check_key_treated);
+ if ($treated_count != 0)
+ {
+ $time_refresh = ceil((get_moment() - $env_nbm['start_time']) * $post_count / $treated_count);
+ }
+ else
+ {
+ $time_refresh = 10;
+ }
+ $_POST[$post_keyname] = array_diff($_POST[$post_keyname], $check_key_treated);
+ re_post_http($base_url.get_query_string_diff(array()), sprintf(l10n('nbm_background_treatment_redirect'), $time_refresh) , $time_refresh);
+ }
+ }
+
+}
+
+/*
* Get the authorized_status for each tab
* return corresponding status
*/
@@ -78,7 +115,7 @@ function get_tab_status($mode)
*/
function insert_new_data_user_mail_notification()
{
- global $conf, $page;
+ global $conf, $page, $env_nbm;
// Set null mail_address empty
$query = '
@@ -137,18 +174,36 @@ order by
// Insert new nbm_users
mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts);
// Update field enabled with specific function
- do_subscribe_unsubcribe_notification_by_mail
+ $check_key_treated = do_subscribe_unsubcribe_notification_by_mail
(
true,
$conf['nbm_default_value_user_enabled'],
$check_key_list
);
+
+ // On timeout simulate like tabsheet send
+ if ($env_nbm['is_sendmail_timeout'])
+ {
+ if ($conf['nbm_default_value_user_enabled'])
+ {
+ $_POST['trueify'] = 'trueify';
+ $_POST['cat_false'] = $check_key_list;
+ do_background_treatment('cat_false', $check_key_treated);
+ }
+ else
+ {
+ $_POST['falsify'] = 'falsify';
+ $_POST['cat_true'] = $check_key_list;
+ do_background_treatment('cat_true', $check_key_treated);
+ }
+ }
}
}
/*
* Send mail for notification to all users
- * Return list of "treated/selected" users
+ * Return list of "selected" users for 'list_to_send'
+ * Return list of "treated" check_key for 'send'
*/
function do_action_send_mail_notification($action = 'list_to_send', $check_key_list = array(), $customize_mail_content = '')
{
@@ -176,21 +231,31 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
{
$datas = array();
+ // Prepare message after change language
+ if ($is_action_send)
+ {
+ $msg_break_timeout = l10n('nbm_nbm_break_timeout_send_mail');
+ }
+ else
+ {
+ $msg_break_timeout = l10n('nbm_break_timeout_list_user');
+ }
+
// Begin nbm users environment
begin_users_env_nbm($is_action_send);
foreach ($data_users as $nbm_user)
{
- if ((!$is_action_send) and (count($return_list) >= $conf['nbm_max_list_users_to_send']))
+ if ((!$is_action_send) and check_sendmail_timeout())
{
// 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']));
+ array_push($page['infos'], $msg_break_timeout);
break;
}
- if (($is_action_send) and (count($return_list) >= $conf['nbm_max_mails_send']))
+ if (($is_action_send) and check_sendmail_timeout())
{
// 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']));
+ array_push($page['errors'], $msg_break_timeout);
break;
}
@@ -199,6 +264,8 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
if ($is_action_send)
{
+ // Fill return list of "treated" check_key for 'send'
+ array_push($return_list, $nbm_user['check_key']);
$message = '';
if ($conf['nbm_send_detailed_content'])
@@ -213,8 +280,6 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
if ($exist_data)
{
- array_push($return_list, $nbm_user);
-
$subject = '['.$conf['gallery_title'].']: '.l10n('nbm_object_news');
$message .= sprintf(l10n('nbm_content_hello'), $nbm_user['username']).",\n\n";
@@ -262,6 +327,7 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
{
if (news_exists($nbm_user['last_send'], $dbnow))
{
+ // Fill return list of "selected" users for 'list_to_send'
array_push($return_list, $nbm_user);
}
}
@@ -295,9 +361,13 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
else
{
// Quick List, don't check news
+ // Fill return list of "selected" users for 'list_to_send'
$return_list = $data_users;
}
}
+
+ // Return list of "selected" users for 'list_to_send'
+ // Return list of "treated" check_key for 'send'
return $return_list;
}
@@ -383,12 +453,14 @@ where
{
if (isset($_POST['falsify']) and isset($_POST['cat_true']))
{
- unsubcribe_notification_by_mail(true, $_POST['cat_true']);
+ $check_key_treated = unsubcribe_notification_by_mail(true, $_POST['cat_true']);
+ do_background_treatment('cat_true', $check_key_treated);
}
else
if (isset($_POST['trueify']) and isset($_POST['cat_false']))
{
- subcribe_notification_by_mail(true, $_POST['cat_false']);
+ $check_key_treated = subcribe_notification_by_mail(true, $_POST['cat_false']);
+ do_background_treatment('cat_false', $check_key_treated);
}
break;
}
@@ -397,7 +469,8 @@ where
{
if (isset($_POST['send_submit']) and isset($_POST['send_selection']) and isset($_POST['send_customize_mail_content']))
{
- do_action_send_mail_notification('send', $_POST['send_selection'], $_POST['send_customize_mail_content']);
+ $check_key_treated = do_action_send_mail_notification('send', $_POST['send_selection'], $_POST['send_customize_mail_content']);
+ do_background_treatment('send_selection', $check_key_treated);
}
}
}
@@ -414,14 +487,12 @@ $template->set_filenames
)
);
-$base_url = get_root_url().'admin.php';
-
$template->assign_vars
(
array
(
'U_TABSHEET_TITLE' => l10n('nbm_'.$page['mode'].'_mode'),
- 'U_HELP' => add_url_params(get_root_url().'/popuphelp.php', array('page' => 'notification_by_mail')),
+ 'U_HELP' => add_url_params(get_root_url().'popuphelp.php', array('page' => 'notification_by_mail')),
'F_ACTION'=> $base_url.get_query_string_diff(array())
)
);
diff --git a/include/config_default.inc.php b/include/config_default.inc.php
index ee55461bf..e441de35a 100644
--- a/include/config_default.inc.php
+++ b/include/config_default.inc.php
@@ -470,14 +470,11 @@ $conf['tags_levels'] = 5;
// 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;
+$conf['nbm_max_treatment_timeout_percent'] = 0.8;
+
?>
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 5a1245c4b..2b53b5c26 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -518,15 +518,25 @@ function pwg_debug( $string )
* (presence of an exit() instruction.
*
* @param string $url
+ * @param string $title_msg
+ * @param integer $refreh_time
* @return void
*/
-function redirect( $url )
+function redirect( $url , $msg = '', $refreh_time = 0)
{
global $user, $template, $lang_info, $conf, $lang, $t2, $page, $debug;
- // $refresh, $url_link and $title are required for creating an automated
+ // $redirect_msg, $refresh, $url_link and $title are required for creating an automated
// refresh page in header.tpl
- $refresh = 0;
+ if (!isset($msg) or ($msg == ''))
+ {
+ $redirect_msg = l10n('redirect_msg');
+ }
+ else
+ {
+ $redirect_msg = $msg;
+ }
+ $refresh = $refreh_time;
$url_link = $url;
$title = 'redirection';
@@ -859,4 +869,76 @@ function get_available_upgrade_ids()
return $available_upgrade_ids;
}
+
+/**
+ * Adaptation of _HTTPRequestToString (http://fr.php.net/urlencode)
+ *
+ *
+ * @return array request to string
+ */
+function http_request_to_string($arr_request, $var_name, $separator='&') {
+ $ret = "";
+ if (is_array($arr_request)) {
+ foreach ($arr_request as $key => $value) {
+ if (is_array($value)) {
+ if ($var_name) {
+ $ret .= http_request_to_string($value, "{$var_name}[{$key}]", $separator);
+ } else {
+ $ret .= http_request_to_string($value, "{$key}", $separator);
+ }
+ } else {
+ if ($var_name) {
+ $ret .= "{$var_name}[{$key}]=".urlencode($value)."&";
+ } else {
+ $ret .= "{$key}=".urlencode($value)."&";
+ }
+ }
+ }
+ }
+ if (!$var_name) {
+ $ret = substr($ret,0,-1);
+ }
+ return $ret;
+}
+
+/**
+ * Post request HTTP on backgroung and redirec to selected url
+ *
+ * Note : once this function called, the execution doesn't go further
+ * (presence of an exit() instruction.
+ *
+ * @param string $url_redirect
+ * @param string $redirect_message
+ * @param integer $redirect_refreh_time
+ * @return void
+ */
+function re_post_http($url_redirect, $redirect_message, $redirect_refreh_time)
+{
+ global $conf;
+
+ $data_post = http_request_to_string($_POST, '');
+
+ $message_post = "POST ".$_SERVER['PHP_SELF'].html_entity_decode(get_query_string_diff(array()))." HTTP/1.1\r\n";
+
+ foreach (array_flip(array_diff(array_flip(apache_request_headers()), array('Content-Type', 'Content-Length'))) as $header_name => $header_value)
+ {
+ $message_post .= $header_name.": ".$header_value."\r\n";
+ }
+
+
+// $message_post .= "Host: ".$_SERVER['HTTP_HOST']."\r\n";
+// $message_post .= "Cookie: ".$conf['session_name']."=".$_COOKIE[$conf['session_name']]."\r\n";
+ $message_post .= "Content-Type: application/x-www-form-urlencoded\r\n";
+ $message_post .= "Content-Length: ".strlen($data_post)."\r\n";
+ $message_post .= "\r\n";
+ $message_post .= $data_post."\r\n";
+
+ $fd = fsockopen($_SERVER['HTTP_HOST'], $_SERVER['SERVER_PORT']);
+ fputs($fd, $message_post);
+ fclose($fd);
+
+ redirect($url_redirect, $redirect_message, $redirect_refreh_time);
+ //exit(); done by redirect
+}
+
?>
diff --git a/include/page_header.php b/include/page_header.php
index f9b130c3c..f1f10cf56 100644
--- a/include/page_header.php
+++ b/include/page_header.php
@@ -57,10 +57,11 @@ $template->assign_vars(
));
// refresh
-if ( isset( $refresh ) and intval($refresh) >= 0 and isset( $url_link ) )
+if ( isset( $refresh ) and intval($refresh) >= 0 and isset( $url_link ) and isset( $redirect_msg ) )
{
$template->assign_vars(
array(
+ 'U_REDIRECT_MSG' => $redirect_msg,
'REFRESH_TIME' => $refresh,
'U_REFRESH' => $url_link
));
diff --git a/language/en_UK.iso-8859-1/admin.lang.php b/language/en_UK.iso-8859-1/admin.lang.php
index 465aed5a2..36e26a148 100644
--- a/language/en_UK.iso-8859-1/admin.lang.php
+++ b/language/en_UK.iso-8859-1/admin.lang.php
@@ -253,7 +253,8 @@ $lang['metadata_basic'] = 'basic';
$lang['metadata_exif'] = 'EXIF';
$lang['metadata_iptc'] = 'IPTC';
$lang['name'] = 'name';
-$lang['nbm_break_list_user'] = 'List of users to send mail is limited to %d. Others users are not listed.';
+$lang['nbm_background_treatment_redirect'] = 'Execution time is out, treatment continue on background. Re-display on %d secondes...';
+$lang['nbm_break_timeout_list_user'] = 'Prepared time for list of users to send mail is limited. Others users are not listed.';
$lang['nbm_col_check_user_send_mail'] = 'To send ?';
$lang['nbm_col_last_send'] = 'Last send';
$lang['nbm_col_mail'] = 'email';
@@ -277,7 +278,7 @@ $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_msg_n_mails_sent'] = '%d mails were sent.';
$lang['nbm_msg_no_mail_to_send'] = '%d mails were not sent.';
-$lang['nbm_nbm_break_send_mail'] = 'Sent mail is limited to %d send by pass. Others mails are skipped.';
+$lang['nbm_nbm_break_timeout_send_mail'] = 'Time to send mail is limited. Others mails are skipped or sent on background.';
$lang['nbm_no_mail_to_send'] = 'No mail to send.';
$lang['nbm_no_user_available_to_send_L1'] = 'No user are available in order to send mail.';
$lang['nbm_no_user_available_to_send_L2'] = 'A user is available, if there are new elements to notify';
diff --git a/language/en_UK.iso-8859-1/common.lang.php b/language/en_UK.iso-8859-1/common.lang.php
index d11d4d945..8a96b9981 100644
--- a/language/en_UK.iso-8859-1/common.lang.php
+++ b/language/en_UK.iso-8859-1/common.lang.php
@@ -343,4 +343,5 @@ $lang['upload_username'] = 'Username';
$lang['useful when password forgotten'] = 'useful when password forgotten';
$lang['w_month'] = 'Month';
$lang['yes'] = 'Yes';
+$lang['redirect_msg'] = 'Redirection...';
?>
diff --git a/language/fr_FR.iso-8859-1/admin.lang.php b/language/fr_FR.iso-8859-1/admin.lang.php
index 72426f5dd..d7752576e 100644
--- a/language/fr_FR.iso-8859-1/admin.lang.php
+++ b/language/fr_FR.iso-8859-1/admin.lang.php
@@ -256,7 +256,8 @@ $lang['metadata_basic'] = 'basique';
$lang['metadata_exif'] = 'EXIF';
$lang['metadata_iptc'] = 'IPTC';
$lang['name'] = 'nom';
-$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_background_treatment_redirect'] = 'Le temps d\'éxécution étant dépassé, le traitement continue en arrière plan. Ré-affichage dans %d secondes...';
+$lang['nbm_break_timeout_list_user'] = 'Le temps de préparation de la liste des utilisateurs pour l\'envoi est limité. Les autres utilisateurs ne sont pas listés.';
$lang['nbm_col_check_user_send_mail'] = 'A envoyer ?';
$lang['nbm_col_last_send'] = 'Dernier envoi';
$lang['nbm_col_mail'] = 'email';
@@ -280,7 +281,7 @@ $lang['nbm_msg_error_sending_email_to'] = 'Erreur lors de l\'envoi du mail à %s
$lang['nbm_msg_mail_sent_to'] = 'Mail envoyé à %s [%s].';
$lang['nbm_msg_n_mails_sent'] = '%s mails ont été envoyés.';
$lang['nbm_msg_no_mail_to_send'] = '%s mails n\'ont pas été envoyé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_nbm_break_timeout_send_mail'] = 'Le temps d\'envoi des mails est limité. Les autres envois de mail ont été ignorés ou vont être envoyés en arrière plan.';
$lang['nbm_no_mail_to_send'] = 'Pas de mail à envoyer.';
$lang['nbm_no_user_available_to_send_L1'] = 'Il n\'y a pas d\'utilisateur à notifier par mail.';
$lang['nbm_no_user_available_to_send_L2'] = 'Un utilisateur est à notifier si de nouveaux éléments sont disponibles pour cet utilisateur.';
diff --git a/language/fr_FR.iso-8859-1/common.lang.php b/language/fr_FR.iso-8859-1/common.lang.php
index df9e3be66..aaa3eb1a0 100644
--- a/language/fr_FR.iso-8859-1/common.lang.php
+++ b/language/fr_FR.iso-8859-1/common.lang.php
@@ -343,4 +343,5 @@ $lang['upload_username'] = 'Nom d\'utilisateur';
$lang['useful when password forgotten'] = 'utile en cas d\'oubli de mot de passe';
$lang['w_month'] = 'Mois';
$lang['yes'] = 'Oui';
+$lang['redirect_msg'] = 'Redirection...';
?> \ No newline at end of file
diff --git a/template/yoga/redirect.tpl b/template/yoga/redirect.tpl
index 6d85d3afc..446f187a3 100644
--- a/template/yoga/redirect.tpl
+++ b/template/yoga/redirect.tpl
@@ -1,2 +1,2 @@
-<p>Redirection...</p>
+<p>{U_REDIRECT_MSG}</p>
<p><a href="{U_REFRESH}">{lang:click_to_redirect}</a></p>