Skip to content

Commit

Permalink
Issue ID 330:
Browse files Browse the repository at this point in the history
  o Remove "background treatment"
  o Add button "Continue treatment"


git-svn-id: http://piwigo.org/svn/trunk@1177 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rub committed Apr 14, 2006
1 parent 1857027 commit aa49352
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 107 deletions.
8 changes: 4 additions & 4 deletions admin/include/functions_notification_by_mail.inc.php
Expand Up @@ -338,7 +338,7 @@ 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 check_key lisr treated
* @return check_key list treated
*/
function do_subscribe_unsubcribe_notification_by_mail($is_admin_request, $is_subscribe = false, $check_key_list = array())
{
Expand Down Expand Up @@ -366,7 +366,7 @@ function do_subscribe_unsubcribe_notification_by_mail($is_admin_request, $is_sub
$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');
$msg_break_timeout = l10n('nbm_break_timeout_send_mail');

// Begin nbm users environment
begin_users_env_nbm(true);
Expand Down Expand Up @@ -471,7 +471,7 @@ function do_subscribe_unsubcribe_notification_by_mail($is_admin_request, $is_sub
*
* check_key list where action will be done
*
* @return check_key lisr treated
* @return check_key list treated
*/
function unsubcribe_notification_by_mail($is_admin_request, $check_key_list = array())
{
Expand All @@ -483,7 +483,7 @@ function unsubcribe_notification_by_mail($is_admin_request, $check_key_list = ar
*
* check_key list where action will be done
*
* @return check_key lisr treated
* @return check_key list treated
*/
function subcribe_notification_by_mail($is_admin_request, $check_key_list = array())
{
Expand Down
79 changes: 51 additions & 28 deletions admin/notification_by_mail.php
Expand Up @@ -50,21 +50,22 @@
// | Initialization |
// +-----------------------------------------------------------------------+
$base_url = get_root_url().'admin.php';
$must_repost = false;

// +-----------------------------------------------------------------------+
// | functions |
// +-----------------------------------------------------------------------+

/*
* Do background treatmetn in order to finish to send mails
* Do timeout treatment 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
* @param check_key_treated: array of check_key treated
* @return none
*/
function do_background_treatment($post_keyname, $check_key_treated = array())
function do_timeout_treatment($post_keyname, $check_key_treated = array())
{
global $env_nbm, $base_url;
global $env_nbm, $base_url, $page, $must_repost;

if ($env_nbm['is_sendmail_timeout'])
{
Expand All @@ -78,10 +79,12 @@ function do_background_treatment($post_keyname, $check_key_treated = array())
}
else
{
$time_refresh = 10;
$time_refresh = 0;
}
$_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);

$must_repost = true;
array_push($page['errors'], sprintf(l10n('nbm_background_treatment_redirect'), $time_refresh));
}
}

Expand Down Expand Up @@ -117,18 +120,6 @@ function insert_new_data_user_mail_notification()
{
global $conf, $page, $env_nbm;

// Treatment of simulate post
if (isset($_POST['insert_new_user_nbm']))
{
$check_key_treated = do_subscribe_unsubcribe_notification_by_mail
(
true,
$conf['nbm_default_value_user_enabled'],
$_POST['insert_new_user_nbm']
);
do_background_treatment('insert_new_user_nbm', $check_key_treated);
}

// Set null mail_address empty
$query = '
update
Expand Down Expand Up @@ -196,11 +187,13 @@ function insert_new_data_user_mail_notification()
// On timeout simulate like tabsheet send
if ($env_nbm['is_sendmail_timeout'])
{
if ($conf['nbm_default_value_user_enabled'])
$quoted_check_key_list = quote_check_key_list(array_diff($check_key_list, $check_key_treated));
if (count($quoted_check_key_list) != 0 )
{
// Simulate Post
$_POST['insert_new_user_nbm'] = $check_key_list;
do_background_treatment('insert_new_user_nbm', $check_key_treated);
$query = 'delete from '.USER_MAIL_NOTIFICATION_TABLE.' where check_key in ('.implode(",", $quoted_check_key_list).');';
$result = pwg_query($query);

redirect($base_url.get_query_string_diff(array()));
}
}
}
Expand Down Expand Up @@ -230,8 +223,11 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
// disabled and null mail_address are not selected in the list
$data_users = get_user_notifications('send', $check_key_list);

// List all if it's define on options or on timeout
$is_list_all_without_test = ($env_nbm['is_sendmail_timeout'] or $conf['nbm_list_all_enabled_users_to_send']);

// Check if exist news to list user or send mails
if (($conf['nbm_list_all_enabled_users_to_send'] == false) or ($is_action_send))
if ((!$is_list_all_without_test == false) or ($is_action_send))
{
if (count($data_users) > 0)
{
Expand All @@ -240,7 +236,7 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
// Prepare message after change language
if ($is_action_send)
{
$msg_break_timeout = l10n('nbm_nbm_break_timeout_send_mail');
$msg_break_timeout = l10n('nbm_break_timeout_send_mail');
}
else
{
Expand Down Expand Up @@ -460,13 +456,13 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
if (isset($_POST['falsify']) and isset($_POST['cat_true']))
{
$check_key_treated = unsubcribe_notification_by_mail(true, $_POST['cat_true']);
do_background_treatment('cat_true', $check_key_treated);
do_timeout_treatment('cat_true', $check_key_treated);
}
else
if (isset($_POST['trueify']) and isset($_POST['cat_false']))
{
$check_key_treated = subcribe_notification_by_mail(true, $_POST['cat_false']);
do_background_treatment('cat_false', $check_key_treated);
do_timeout_treatment('cat_false', $check_key_treated);
}
break;
}
Expand All @@ -476,7 +472,7 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
if (isset($_POST['send_submit']) and isset($_POST['send_selection']) and isset($_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);
do_timeout_treatment('send_selection', $check_key_treated);
}
}
}
Expand Down Expand Up @@ -517,6 +513,33 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
);
}

if ($must_repost)
{
// Get name of submit button
$repost_submit_name = '';
if (isset($_POST['falsify']))
{
$repost_submit_name = 'falsify';
}
elseif (isset($_POST['trueify']))
{
$repost_submit_name = 'trueify';
}
elseif (isset($_POST['send_submit']))
{
$repost_submit_name = 'send_submit';
}

$template->assign_block_vars
(
'repost',
array
(
'REPOST_SUBMIT_NAME' => $repost_submit_name
)
);
}

switch ($page['mode'])
{
case 'param' :
Expand Down Expand Up @@ -589,7 +612,7 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
'ID' => $nbm_user['check_key'],
'CHECKED' => ( // not check if not selected, on init select<all
isset($_POST['send_selection']) and // not init
!in_array($nbm_user['check_key'], $_POST['send_selection']) // not selected
!in_array($nbm_user['check_key'], $_POST['send_selection']) // not selected
) ? '' : 'checked="checked"',
'USERNAME'=> $nbm_user['username'],
'EMAIL' => $nbm_user['mail_address'],
Expand Down
71 changes: 0 additions & 71 deletions include/functions.inc.php
Expand Up @@ -871,75 +871,4 @@ 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
}

?>
5 changes: 3 additions & 2 deletions language/en_UK.iso-8859-1/admin.lang.php
Expand Up @@ -253,7 +253,8 @@
$lang['metadata_exif'] = 'EXIF';
$lang['metadata_iptc'] = 'IPTC';
$lang['name'] = 'name';
$lang['nbm_background_treatment_redirect'] = 'Execution time is out, treatment continue on background.'."\n".'Re-display on %d secondes...';
$lang['nbm_background_treatment_redirect'] = 'Execution time is out, treatment must be continue [Estmated time: %d secondes].';
$lang['nbm_repost_submit'] = 'Continue processing treatment';
$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';
Expand All @@ -278,7 +279,7 @@
$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_timeout_send_mail'] = 'Time to send mail is limited. Others mails are skipped or sent on background.';
$lang['nbm_break_timeout_send_mail'] = 'Time to send mail is limited. Others mails are skipped.';
$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';
Expand Down
5 changes: 3 additions & 2 deletions language/fr_FR.iso-8859-1/admin.lang.php
Expand Up @@ -256,7 +256,8 @@
$lang['metadata_exif'] = 'EXIF';
$lang['metadata_iptc'] = 'IPTC';
$lang['name'] = 'nom';
$lang['nbm_background_treatment_redirect'] = 'Le temps d\'éxécution étant dépassé, le traitement continue en arrière plan.'."\n".'Ré-affichage dans %d secondes...';
$lang['nbm_background_treatment_redirect'] = 'Le temps d\'éxécution étant dépassé, le traitement doit continuer [Temps estimé: %d secondes].';
$lang['nbm_repost_submit'] = 'Continuer le traitement en cours...';
$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';
Expand All @@ -281,7 +282,7 @@
$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_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_break_timeout_send_mail'] = 'Le temps d\'envoi des mails est limité. Les autres envois de mail ont été ignorés.';
$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.';
Expand Down
10 changes: 10 additions & 0 deletions template/yoga/admin/notification_by_mail.tpl
Expand Up @@ -16,6 +16,15 @@
</div>

<form method="post" name="notification_by_mail" id="notification_by_mail" action="{F_ACTION}">
<!-- BEGIN repost -->
<fieldset>
<div class="errors">
<p>
<input type="submit" value="{lang:nbm_repost_submit}" name="{REPOST_SUBMIT_NAME}" {TAG_INPUT_ENABLED}/>
</p>
</div>
</fieldset>
<!-- END repost -->

<!-- BEGIN param -->
<fieldset>
Expand Down Expand Up @@ -62,6 +71,7 @@
<center>
{lang:nbm_no_user_available_to_send_L1}<br>
{lang:nbm_no_user_available_to_send_L2}<br>
<br>
</center>
<!-- END send_empty -->
<!-- BEGIN send_data -->
Expand Down

0 comments on commit aa49352

Please sign in to comment.