Ignore:
Timestamp:
Apr 13, 2006, 12:49:42 AM (18 years ago)
Author:
rub
Message:

Issue ID 330:

o Change NBM configuration in order to avoid lose treatment action when occurred timeout
o Add news redirect/repost functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/notification_by_mail.php

    r1116 r1156  
    4848
    4949// +-----------------------------------------------------------------------+
     50// | Initialization                                                        |
     51// +-----------------------------------------------------------------------+
     52$base_url = get_root_url().'admin.php';
     53
     54// +-----------------------------------------------------------------------+
    5055// | functions                                                             |
    5156// +-----------------------------------------------------------------------+
     57
     58/*
     59 * Do background treatmetn in order to finish to send mails
     60 *
     61 * @param $post_keyname: key of check_key post array
     62 * @param check_key_treated:array of check_key treated
     63 * @return none
     64 */
     65function do_background_treatment($post_keyname, $check_key_treated = array())
     66{
     67  global $env_nbm, $base_url;
     68
     69  if ($env_nbm['is_sendmail_timeout'])
     70  {
     71    if (isset($_POST[$post_keyname]))
     72    {
     73      $post_count = count($_POST[$post_keyname]);
     74      $treated_count = count($check_key_treated);
     75      if ($treated_count != 0)
     76      {
     77        $time_refresh = ceil((get_moment() - $env_nbm['start_time']) * $post_count / $treated_count);
     78      }
     79      else
     80      {
     81        $time_refresh = 10;
     82      }
     83      $_POST[$post_keyname] = array_diff($_POST[$post_keyname], $check_key_treated);
     84      re_post_http($base_url.get_query_string_diff(array()), sprintf(l10n('nbm_background_treatment_redirect'), $time_refresh) , $time_refresh);
     85    }
     86  }
     87
     88}
    5289
    5390/*
     
    79116function insert_new_data_user_mail_notification()
    80117{
    81   global $conf, $page;
     118  global $conf, $page, $env_nbm;
    82119
    83120  // Set null mail_address empty
     
    138175    mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts);
    139176    // Update field enabled with specific function
    140     do_subscribe_unsubcribe_notification_by_mail
     177    $check_key_treated = do_subscribe_unsubcribe_notification_by_mail
    141178    (
    142179      true,
     
    144181      $check_key_list
    145182    );
     183
     184     // On timeout simulate like tabsheet send
     185    if ($env_nbm['is_sendmail_timeout'])
     186    {
     187      if ($conf['nbm_default_value_user_enabled'])
     188      {
     189        $_POST['trueify'] = 'trueify';
     190        $_POST['cat_false'] = $check_key_list;
     191        do_background_treatment('cat_false', $check_key_treated);
     192      }
     193      else
     194      {
     195        $_POST['falsify'] = 'falsify';
     196        $_POST['cat_true'] = $check_key_list;
     197        do_background_treatment('cat_true', $check_key_treated);
     198      }
     199    }
    146200  }
    147201}
     
    149203/*
    150204 * Send mail for notification to all users
    151  * Return list of "treated/selected" users
     205 * Return list of "selected" users for 'list_to_send'
     206 * Return list of "treated" check_key for 'send'
    152207 */
    153208function do_action_send_mail_notification($action = 'list_to_send', $check_key_list = array(), $customize_mail_content = '')
     
    177232        $datas = array();
    178233
     234        // Prepare message after change language
     235        if ($is_action_send)
     236        {
     237          $msg_break_timeout = l10n('nbm_nbm_break_timeout_send_mail');
     238        }
     239        else
     240        {
     241          $msg_break_timeout = l10n('nbm_break_timeout_list_user');
     242        }
     243
    179244        // Begin nbm users environment
    180245        begin_users_env_nbm($is_action_send);
     
    182247        foreach ($data_users as $nbm_user)
    183248        {
    184           if ((!$is_action_send) and (count($return_list) >= $conf['nbm_max_list_users_to_send']))
     249          if ((!$is_action_send) and check_sendmail_timeout())
    185250          {
    186251            // Stop fill list on 'list_to_send', if the quota is override
    187             array_push($page['infos'], sprintf(l10n('nbm_break_list_user'), $conf['nbm_max_list_users_to_send']));
     252            array_push($page['infos'], $msg_break_timeout);
    188253            break;
    189254          }
    190           if (($is_action_send) and (count($return_list) >= $conf['nbm_max_mails_send']))
     255          if (($is_action_send) and check_sendmail_timeout())
    191256          {
    192257            // Stop fill list on 'send', if the quota is override
    193             array_push($page['errors'], sprintf(l10n('nbm_nbm_break_send_mail'), $conf['nbm_max_mails_send']));
     258            array_push($page['errors'], $msg_break_timeout);
    194259            break;
    195260          }
     
    200265          if ($is_action_send)
    201266          {
     267            // Fill return list of "treated" check_key for 'send'
     268            array_push($return_list, $nbm_user['check_key']);
    202269            $message = '';
    203270
     
    214281            if ($exist_data)
    215282            {
    216               array_push($return_list, $nbm_user);
    217 
    218283              $subject = '['.$conf['gallery_title'].']: '.l10n('nbm_object_news');
    219284              $message .= sprintf(l10n('nbm_content_hello'), $nbm_user['username']).",\n\n";
     
    263328            if (news_exists($nbm_user['last_send'], $dbnow))
    264329            {
     330              // Fill return list of "selected" users for 'list_to_send'
    265331              array_push($return_list, $nbm_user);
    266332            }
     
    296362    {
    297363      // Quick List, don't check news
     364      // Fill return list of "selected" users for 'list_to_send'
    298365      $return_list = $data_users;
    299366    }
    300367  }
     368
     369  // Return list of "selected" users for 'list_to_send'
     370  // Return list of "treated" check_key for 'send'
    301371  return $return_list;
    302372}
     
    384454    if (isset($_POST['falsify']) and isset($_POST['cat_true']))
    385455    {
    386       unsubcribe_notification_by_mail(true, $_POST['cat_true']);
     456      $check_key_treated = unsubcribe_notification_by_mail(true, $_POST['cat_true']);
     457      do_background_treatment('cat_true', $check_key_treated);
    387458    }
    388459    else
    389460    if (isset($_POST['trueify']) and isset($_POST['cat_false']))
    390461    {
    391       subcribe_notification_by_mail(true, $_POST['cat_false']);
     462      $check_key_treated = subcribe_notification_by_mail(true, $_POST['cat_false']);
     463      do_background_treatment('cat_false', $check_key_treated);
    392464    }
    393465    break;
     
    398470    if (isset($_POST['send_submit']) and isset($_POST['send_selection']) and isset($_POST['send_customize_mail_content']))
    399471    {
    400       do_action_send_mail_notification('send', $_POST['send_selection'], $_POST['send_customize_mail_content']);
     472      $check_key_treated = do_action_send_mail_notification('send', $_POST['send_selection'], $_POST['send_customize_mail_content']);
     473      do_background_treatment('send_selection', $check_key_treated);
    401474    }
    402475  }
     
    415488);
    416489
    417 $base_url = get_root_url().'admin.php';
    418 
    419490$template->assign_vars
    420491(
     
    422493  (
    423494    'U_TABSHEET_TITLE' => l10n('nbm_'.$page['mode'].'_mode'),
    424     'U_HELP' => add_url_params(get_root_url().'/popuphelp.php', array('page' => 'notification_by_mail')),
     495    'U_HELP' => add_url_params(get_root_url().'popuphelp.php', array('page' => 'notification_by_mail')),
    425496    'F_ACTION'=> $base_url.get_query_string_diff(array())
    426497  )
Note: See TracChangeset for help on using the changeset viewer.