Changeset 1116 for trunk/admin


Ignore:
Timestamp:
Apr 1, 2006, 3:14:57 AM (19 years ago)
Author:
rub
Message:

[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

Location:
trunk/admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r1111 r1116  
    763763          $column.= " default '".$row['Default']."'";
    764764        }
    765         if (isset($row['Collation']))
     765        if (isset($row['Collation']) and $row['Collation'] != 'NULL')
    766766        {
    767767          $column.= " collate '".$row['Collation']."'";
  • trunk/admin/include/functions_notification_by_mail.inc.php

    r1105 r1116  
    2727// +-----------------------------------------------------------------------+
    2828
     29/* nbm_global_var */
     30$env_nbm = array();
     31
    2932/*
    3033 * Search an available check_key
     
    3841  while (true)
    3942  {
    40     $key = generate_key(128);
     43    $key = generate_key(16);
    4144    $query = '
    4245select
     
    6770
    6871/*
    69  * Subscribe or unsubscribe notification by mail
    70  *
    71  * is_subscribe define if action=subscribe or unsubscribe
    72  * check_key list where action will be done
    73  *
    74  * @return updated data count
    75  */
    76 function do_subscribe_unsubcribe_notification_by_mail($is_subscribe = false, $check_key_list = array())
    77 {
    78   global $page;
    79 
    80   $updated_data_count = 0;
    81   if ($is_subscribe)
    82   {
    83     $msg_info = l10n('nbm_user_change_enabled_true');
    84   }
    85   else
    86   {
    87     $msg_info = l10n('nbm_user_change_enabled_false');
    88   }
    89 
    90   if (count($check_key_list) != 0)
     72 * Execute all main queries to get list of user
     73 *
     74 * Type are the type of list 'subscribe', 'send'
     75 *
     76 * return array of users
     77 */
     78function get_user_notifications($action, $check_key_list = array(), $enabled_filter_value = '')
     79{
     80  global $conf;
     81
     82  $data_users = array();
     83
     84  if (in_array($action, array('subscribe', 'send')))
    9185  {
    9286    $quoted_check_key_list = quote_check_key_list($check_key_list);
     87    if (count($quoted_check_key_list) != 0 )
     88    {
     89      $query_and_check_key = ' and
     90    check_key in ('.implode(",", $quoted_check_key_list).') ';
     91    }
     92    else
     93    {
     94      $query_and_check_key = '';
     95    }
    9396
    9497    $query = '
    9598select
    96   N.check_key, U.username, U.mail_address
     99  N.user_id,
     100  N.check_key,
     101  U.'.$conf['user_fields']['username'].' as username,
     102  U.'.$conf['user_fields']['email'].' as mail_address,
     103  N.enabled,
     104  N.last_send
    97105from
    98106  '.USER_MAIL_NOTIFICATION_TABLE.' as N,
    99107  '.USERS_TABLE.' as U
    100108where
    101   N.user_id =  U.id and
    102   N.enabled = \''.boolean_to_string(!$is_subscribe).'\' and
    103   check_key in ('.implode(",", $quoted_check_key_list).')
    104 order by
     109  N.user_id =  U.'.$conf['user_fields']['id'];
     110 
     111    if ($action == 'send')
     112    {
     113      // No mail empty and all users enabled
     114      $query .= ' and
     115  N.enabled = \'true\' and
     116  U.'.$conf['user_fields']['email'].' is not null';
     117    }
     118
     119    $query .= $query_and_check_key;
     120
     121    if (isset($enabled_filter_value) and ($enabled_filter_value != ''))
     122    {
     123      $query .= ' and
     124        N.enabled = \''.boolean_to_string($enabled_filter_value).'\'';
     125    }
     126
     127    $query .= '
     128order by';
     129
     130    if ($action == 'send')
     131    {
     132      $query .= '
     133  last_send, username;';
     134    }
     135    else
     136    {
     137      $query .= '
    105138  username;';
     139    }
     140
     141    $query .= ';';
    106142
    107143    $result = pwg_query($query);
    108144    if (!empty($result))
    109145    {
    110       $updates = array();
    111       $enabled_value = boolean_to_string($is_subscribe);
    112 
    113       while ($row = mysql_fetch_array($result))
     146      while ($nbm_user = mysql_fetch_array($result))
     147      {
     148        array_push($data_users, $nbm_user);
     149      }
     150    }
     151  }
     152  return $data_users;
     153}
     154
     155/*
     156 * Begin of use nbm environment
     157 * Prepare and save current environment and initialize data in order to send mail
     158 *
     159 * Return none
     160 */
     161function begin_users_env_nbm($is_to_send_mail = false)
     162{
     163  global $user, $lang, $lang_info, $conf, $env_nbm;
     164
     165  // Save $user, $lang_info and $lang arrays (include/user.inc.php has been executed)
     166  $env_nbm['save_user'] = $user;
     167  $env_nbm['save_lang_info'] = $lang_info;
     168  $env_nbm['save_lang'] = $lang;
     169  // Last Language
     170  $env_nbm['last_language'] = $user['language'];
     171
     172  $env_nbm['is_to_send_mail'] = $is_to_send_mail;
     173
     174  if ($is_to_send_mail)
     175  {
     176    // Init mail configuration
     177    $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']);
     178    $env_nbm['send_as_mail_address'] = get_webmaster_mail_address();
     179    $env_nbm['send_as_mail_formated'] = format_email($env_nbm['send_as_name'], $env_nbm['send_as_mail_address']);
     180    // Init mail counter
     181    $env_nbm['error_on_mail_count'] = 0;
     182    $env_nbm['sent_mail_count'] = 0;
     183    // Save sendmail message info and error in the original language
     184    $env_nbm['msg_info'] = l10n('nbm_msg_mail_sent_to');
     185    $env_nbm['msg_error'] = l10n('nbm_msg_error_sending_email_to');
     186  }
     187}
     188
     189/*
     190 * End of use nbm environment
     191 * Restore environment
     192 *
     193 * Return none
     194 */
     195function end_users_env_nbm()
     196{
     197  global $user, $lang, $lang_info, $env_nbm;
     198
     199  // Restore $user, $lang_info and $lang arrays (include/user.inc.php has been executed)
     200  $user = $env_nbm['save_user'];
     201  $lang_info = $env_nbm['save_lang_info'];
     202  $lang = $env_nbm['save_lang'];
     203}
     204
     205/*
     206 * Set user_id on nbm enviromnent
     207 *
     208 * Return none
     209 */
     210function set_user_id_on_env_nbm($user_id)
     211{
     212  global $user, $lang, $lang_info, $env_nbm;
     213
     214  $user = array();
     215  $user['id'] = $user_id;
     216  $user = array_merge($user, getuserdata($user['id'], true));
     217
     218  if ($env_nbm['last_language'] != $user['language'])
     219  {
     220    $env_nbm['last_language'] = $user['language'];
     221
     222    // Re-Init language arrays
     223    $lang_info = array();
     224    $lang  = array();
     225
     226    // language files
     227    include(get_language_filepath('common.lang.php'));
     228    // No test admin because script is checked admin (user selected no)
     229    // Translations are in admin file too
     230    include(get_language_filepath('admin.lang.php'));
     231  }
     232}
     233
     234/*
     235 * Inc Counter success
     236 *
     237 * Return none
     238 */
     239function inc_mail_sent_success($nbm_user)
     240{
     241  global $page, $env_nbm;
     242
     243  $env_nbm['sent_mail_count'] += 1;
     244  array_push($page['infos'], sprintf($env_nbm['msg_info'], $nbm_user['username'], $nbm_user['mail_address']));
     245}
     246
     247/*
     248 * Inc Counter failed
     249 *
     250 * Return none
     251 */
     252function inc_mail_sent_failed($nbm_user)
     253{
     254  global $page, $env_nbm;
     255
     256  $env_nbm['error_on_mail_count'] += 1;
     257  array_push($page['errors'], sprintf($env_nbm['msg_error'], $nbm_user['username'], $nbm_user['mail_address']));
     258}
     259
     260/*
     261 * Display Counter Info
     262 *
     263 * Return none
     264 */
     265function display_counter_info()
     266{
     267  global $page, $env_nbm;
     268
     269  if ($env_nbm['error_on_mail_count'] != 0)
     270  {
     271    array_push($page['errors'], sprintf(l10n('nbm_msg_no_mail_to_send'), $env_nbm['error_on_mail_count']));
     272    if ($env_nbm['sent_mail_count'] != 0)
     273      array_push($page['infos'], sprintf(l10n('nbm_msg_n_mails_sent'), $env_nbm['sent_mail_count']));
     274  }
     275  else
     276  {
     277    if ($env_nbm['sent_mail_count'] == 0)
     278      array_push($page['infos'], l10n('nbm_no_mail_to_send'));
     279    else
     280      array_push($page['infos'], sprintf(l10n('nbm_msg_n_mails_sent'), $env_nbm['sent_mail_count']));
     281  }
     282}
     283
     284function get_mail_content_subscribe_unsubcribe($nbm_user)
     285{
     286  global $page, $env_nbm;
     287 
     288  $content = "\n\n\n";
     289 
     290  if ( isset($page['root_path']) )
     291  {
     292    $save_root_path = $page['root_path'];
     293  }
     294
     295  $page['root_path'] = 'http://'.$_SERVER['HTTP_HOST'].cookie_path();
     296 
     297  $content .= "___________________________________________________\n\n";
     298  $content .= sprintf(l10n('nbm_content_unsubscribe_link'), add_url_params(get_root_url().'/nbm.php', array('unsubscribe' => $nbm_user['check_key'])))."\n";
     299  $content .= sprintf(l10n('nbm_content_subscribe_link'), add_url_params(get_root_url().'/nbm.php', array('subscribe' => $nbm_user['check_key'])))."\n";
     300  $content .= sprintf(l10n('nbm_content_subscribe_unsubscribe_contact'), $env_nbm['send_as_mail_address'])."\n";
     301  $content .= "___________________________________________________\n\n\n\n";
     302
     303  if (isset($save_root_path))
     304  {
     305    $page['root_path'] = $save_root_path;
     306  }
     307  else
     308  {
     309    unset($page['root_path']);
     310  }
     311
     312  return $content;
     313}
     314
     315/*
     316 * Subscribe or unsubscribe notification by mail
     317 *
     318 * is_subscribe define if action=subscribe or unsubscribe
     319 * check_key list where action will be done
     320 *
     321 * @return updated data count
     322 */
     323function do_subscribe_unsubcribe_notification_by_mail($is_admin_request, $is_subscribe = false, $check_key_list = array())
     324{
     325  global $conf, $page, $env_nbm, $conf;
     326
     327  $updated_data_count = 0;
     328  $error_on_updated_data_count = 0;
     329
     330  if ($is_subscribe)
     331  {
     332    $msg_info = l10n('nbm_user_change_enabled_true');
     333    $msg_error = l10n('nbm_user_not_change_enabled_true');
     334  }
     335  else
     336  {
     337    $msg_info = l10n('nbm_user_change_enabled_false');
     338    $msg_error = l10n('nbm_user_not_change_enabled_false');
     339  }
     340
     341  if (count($check_key_list) != 0)
     342  {
     343    $updates = array();
     344    $enabled_value = boolean_to_string($is_subscribe);
     345    $data_users = get_user_notifications('subscribe', $check_key_list, !$is_subscribe);
     346
     347    // Begin nbm users environment
     348    begin_users_env_nbm(true);
     349
     350    foreach ($data_users as $nbm_user)
     351    {
     352      if (($env_nbm['error_on_mail_count'] + $env_nbm['sent_mail_count']) >= $conf['nbm_max_mails_send'])
     353      {
     354        // Stop fill list on 'send', if the quota is override
     355        array_push($page['errors'], sprintf(l10n('nbm_nbm_break_send_mail'), $conf['nbm_max_mails_send']));
     356        break;
     357      }
     358
     359      $do_update = true;
     360      if ($nbm_user['mail_address'] != '')
     361      {
     362        // set env nbm user
     363        set_user_id_on_env_nbm($nbm_user['user_id']);
     364
     365        $message = '';
     366
     367        $subject = '['.$conf['gallery_title'].']: '.($is_subscribe ? l10n('nbm_object_subcribe'): l10n('nbm_object_unsubcribe'));
     368        $message .= sprintf(l10n('nbm_content_hello'), $nbm_user['username']).",\n\n";
     369
     370        if ($is_subscribe)
     371        {
     372          $message .= l10n($is_admin_request ? 'nbm_content_subscribe_by_admin' : 'nbm_content_subscribe_by_himself');
     373        }
     374        else
     375        {
     376          $message .= l10n($is_admin_request ? 'nbm_content_unsubscribe_by_admin' : 'nbm_content_unsubscribe_by_himself');
     377        }
     378
     379        $message .= "\n\n";
     380        $message .= l10n('nbm_content_byebye')."\n   ".$env_nbm['send_as_name']."\n\n";
     381
     382        $message .= get_mail_content_subscribe_unsubcribe($nbm_user);
     383
     384        if (pwg_mail(format_email($nbm_user['username'], $nbm_user['mail_address']), $env_nbm['send_as_mail_formated'], $subject, $message))
     385        {
     386          inc_mail_sent_success($nbm_user);
     387        }
     388        else
     389        {
     390          inc_mail_sent_failed($nbm_user);
     391          $do_update = false;
     392        }
     393      }
     394
     395      if ($do_update)
    114396      {
    115397        array_push
     
    118400          array
    119401          (
    120             'check_key' => $row['check_key'],
     402            'check_key' => $nbm_user['check_key'],
    121403            'enabled' => $enabled_value
    122404          )
    123405        );
    124406        $updated_data_count += 1;
    125         array_push($page['infos'], sprintf($msg_info, $row['username'], $row['mail_address']));
     407        array_push($page['infos'], sprintf($msg_info, $nbm_user['username'], $nbm_user['mail_address']));
    126408      }
    127 
    128       mass_updates(
    129         USER_MAIL_NOTIFICATION_TABLE,
    130         array(
    131           'primary' => array('check_key'),
    132           'update' => array('enabled')
    133         ),
    134         $updates
    135       );
    136     }
     409      else
     410      {
     411        $error_on_updated_data_count += 1;
     412        array_push($page['errors'], sprintf($msg_error, $nbm_user['username'], $nbm_user['mail_address']));
     413      }
     414
     415    }
     416
     417    // Restore nbm environment
     418    end_users_env_nbm();
     419
     420    display_counter_info();
     421
     422    mass_updates(
     423      USER_MAIL_NOTIFICATION_TABLE,
     424      array(
     425        'primary' => array('check_key'),
     426        'update' => array('enabled')
     427      ),
     428      $updates
     429    );
     430
    137431  }
    138432
    139433  array_push($page['infos'], sprintf(l10n('nbm_user_change_enabled_updated_data_count'), $updated_data_count));
     434  if ($error_on_updated_data_count != 0)
     435  {
     436    array_push($page['errors'], sprintf(l10n('nbm_user_change_enabled_error_on_updated_data_count'), $error_on_updated_data_count));
     437  }
    140438
    141439  return $updated_data_count;
     
    149447 * @return updated data count
    150448 */
    151 function unsubcribe_notification_by_mail($check_key_list = array())
    152 {
    153   return do_subscribe_unsubcribe_notification_by_mail(false, $check_key_list);
     449function unsubcribe_notification_by_mail($is_admin_request, $check_key_list = array())
     450{
     451  return do_subscribe_unsubcribe_notification_by_mail($is_admin_request, false, $check_key_list);
    154452}
    155453
     
    161459 * @return updated data count
    162460 */
    163 function subcribe_notification_by_mail($check_key_list = array())
    164 {
    165   return do_subscribe_unsubcribe_notification_by_mail(true, $check_key_list);
     461function subcribe_notification_by_mail($is_admin_request, $check_key_list = array())
     462{
     463  return do_subscribe_unsubcribe_notification_by_mail($is_admin_request, true, $check_key_list);
    166464}
    167465
  • trunk/admin/notification_by_mail.php

    r1115 r1116  
    7575
    7676/*
    77  * Execute all main queries to get list of user
    78  *
    79  * Type are the type of list 'subscribe', 'send'
    80  *
    81  * return array of users
    82  */
    83 function get_user_notifications($action, $check_key_list = array())
    84 {
    85   global $conf;
    86 
    87   $data_users = array();
    88 
    89   if (in_array($action, array('subscribe', 'send')))
    90   {
    91     $quoted_check_key_list = quote_check_key_list($check_key_list);
    92     if (count($quoted_check_key_list) != 0 )
    93     {
    94       $query_and_check_key = ' and
    95     check_key in ('.implode(",", $quoted_check_key_list).') ';
    96     }
    97     else
    98     {
    99       $query_and_check_key = '';
    100     }
    101 
    102     $query = '
    103 select
    104   N.user_id,
    105   N.check_key,
    106   U.'.$conf['user_fields']['username'].' as username,
    107   U.'.$conf['user_fields']['email'].' as mail_address,
    108   N.enabled,
    109   N.last_send
    110 from
    111   '.USER_MAIL_NOTIFICATION_TABLE.' as N,
    112   '.USERS_TABLE.' as U
    113 where
    114   N.user_id =  U.'.$conf['user_fields']['id'];
    115  
    116     if ($action == 'send')
    117     {
    118       $query .= ' and
    119   N.enabled = \'true\' and
    120   U.'.$conf['user_fields']['email'].' is not null'.$query_and_check_key;
    121     }
    122 
    123     $query .= '
    124 order by
    125   username;';
    126 
    127     $result = pwg_query($query);
    128     if (!empty($result))
    129     {
    130       while ($nbm_user = mysql_fetch_array($result))
    131       {
    132         array_push($data_users, $nbm_user);
    133       }
    134     }
    135   }
    136   return $data_users;
    137 }
    138 
    139 /*
    14077 * Inserting News users
    14178 */
     
    195132      );
    196133
    197       array_push($page['infos'], sprintf(l10n('nbm_User %s [%s] added.'), $nbm_user['username'], $nbm_user['mail_address']));
     134      array_push($page['infos'], sprintf(l10n('nbm_user_x_added'), $nbm_user['username'], $nbm_user['mail_address']));
    198135    }
    199136
     
    203140    do_subscribe_unsubcribe_notification_by_mail
    204141    (
    205       ($conf['default_value_user_mail_notification_enabled'] == true ? true : false),
     142      true,
     143      $conf['nbm_default_value_user_enabled'],
    206144      $check_key_list
    207145    );
     
    213151 * Return list of "treated/selected" users
    214152 */
    215 function do_action_send_mail_notification($action = 'list', $check_key_list = array(), $customize_mail_content = '')
    216 {
    217   global $conf, $page, $user, $lang_info, $lang;
     153function do_action_send_mail_notification($action = 'list_to_send', $check_key_list = array(), $customize_mail_content = '')
     154{
     155  global $conf, $page, $user, $lang_info, $lang, $env_nbm;
    218156  $return_list = array();
    219157 
    220   if (in_array($action, array('list', 'send')))
     158  if (in_array($action, array('list_to_send', 'send')))
    221159  {
    222160    list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
     
    232170    $data_users = get_user_notifications('send', $check_key_list);
    233171
    234     if (count($data_users) > 0)
    235     {
    236       $error_on_mail_count = 0;
    237       $sent_mail_count = 0;
    238       // Save $user, $lang_info and $lang arrays (include/user.inc.php has been executed)
    239       $sav_mailtousers_user = $user;
    240       $sav_mailtousers_lang_info = $lang_info;
    241       $sav_mailtousers_lang = $lang;
    242       // Save message info and error in the original language
    243       $msg_info = l10n('nbm_Mail sent to %s [%s].');
    244       $msg_error = l10n('nbm_Error when sending email to %s [%s].');
    245       // Last Language
    246       $last_mailtousers_language = $user['language'];
    247 
    248       if ($is_action_send)
     172    // Check if exist news to list user or send mails
     173    if (($conf['nbm_list_all_enabled_users_to_send'] == false) or ($is_action_send))
     174    {
     175      if (count($data_users) > 0)
    249176      {
    250         // Init mail configuration
    251         $send_as_name = ((isset($conf['nbm_send_mail_as']) and !empty($conf['nbm_send_mail_as'])) ? $conf['nbm_send_mail_as'] : $conf['gallery_title']);
    252         $send_as_mail_address = get_webmaster_mail_address();
    253         $send_as_mail_formated = format_email($send_as_name, $send_as_mail_address);
    254       }
    255 
    256       foreach ($data_users as $nbm_user)
    257       {
    258         $user = array();
    259         $user['id'] = $nbm_user['user_id'];
    260         $user = array_merge($user, getuserdata($user['id'], true));
    261 
    262         if ($last_mailtousers_language != $user['language'])
     177        $datas = array();
     178
     179        // Begin nbm users environment
     180        begin_users_env_nbm($is_action_send);
     181
     182        foreach ($data_users as $nbm_user)
    263183        {
    264           $last_mailtousers_language = $user['language'];
    265 
    266           // Re-Init language arrays
    267           $lang_info = array();
    268           $lang  = array();
    269 
    270           // language files
    271           include(get_language_filepath('common.lang.php'));
    272           // No test admin because script is checked admin (user selected no)
    273           // Translations are in admin file too
    274           include(get_language_filepath('admin.lang.php'));
    275         }
    276 
    277         if ($is_action_send)
    278         {
    279           $message = '';
    280 
    281           if ($conf['nbm_send_detailed_content'])
     184          if ((!$is_action_send) and (count($return_list) >= $conf['nbm_max_list_users_to_send']))
    282185          {
    283              $news = news($nbm_user['last_send'], $dbnow);
    284              $exist_data = count($news) > 0;
     186            // 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']));
     188            break;
     189          }
     190          if (($is_action_send) and (count($return_list) >= $conf['nbm_max_mails_send']))
     191          {
     192            // 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']));
     194            break;
     195          }
     196
     197          // set env nbm user
     198          set_user_id_on_env_nbm($nbm_user['user_id']);
     199
     200          if ($is_action_send)
     201          {
     202            $message = '';
     203
     204            if ($conf['nbm_send_detailed_content'])
     205            {
     206               $news = news($nbm_user['last_send'], $dbnow);
     207               $exist_data = count($news) > 0;
     208            }
     209            else
     210            {
     211              $exist_data = news_exists($nbm_user['last_send'], $dbnow);
     212            }
     213
     214            if ($exist_data)
     215            {
     216              array_push($return_list, $nbm_user);
     217
     218              $subject = '['.$conf['gallery_title'].']: '.l10n('nbm_object_news');
     219              $message .= sprintf(l10n('nbm_content_hello'), $nbm_user['username']).",\n\n";
     220
     221              if (!is_null($nbm_user['last_send']))
     222                $message .= sprintf(l10n('nbm_content_new_elements_between'), $nbm_user['last_send'], $dbnow);
     223              else
     224                $message .= sprintf(l10n('nbm_content_new_elements'), $dbnow);
     225
     226              if ($conf['nbm_send_detailed_content'])
     227              {
     228                $message .= ":\n";
     229
     230                foreach ($news as $line)
     231                {
     232                  $message .= '  o '.$line."\n";
     233                }
     234                $message .= "\n";
     235              }
     236              else
     237              {
     238                $message .= ".\n";
     239              }
     240
     241              $message .= sprintf(l10n('nbm_content_goto'), $conf['gallery_title'], $conf['gallery_url'])."\n\n";
     242              $message .= $customize_mail_content."\n\n";
     243              $message .= l10n('nbm_content_byebye')."\n   ".$env_nbm['send_as_name']."\n\n";
     244
     245              $message .= get_mail_content_subscribe_unsubcribe($nbm_user);
     246
     247              if (pwg_mail(format_email($nbm_user['username'], $nbm_user['mail_address']), $env_nbm['send_as_mail_formated'], $subject, $message))
     248              {
     249                inc_mail_sent_success($nbm_user);
     250
     251                $data = array('user_id' => $nbm_user['user_id'],
     252                              'last_send' => $dbnow);
     253                array_push($datas, $data);
     254              }
     255              else
     256              {
     257                inc_mail_sent_failed($nbm_user);
     258              }
     259            }
    285260          }
    286261          else
    287262          {
    288             $exist_data = news_exists($nbm_user['last_send'], $dbnow);
    289           }
    290 
    291           if ($exist_data)
    292           {
    293             array_push($return_list, $nbm_user);
    294 
    295             $subject = '['.$conf['gallery_title'].']: '.l10n('nbm_ContentObject');
    296             $message .= sprintf(l10n('nbm_ContentHello'), $nbm_user['username']).",\n\n";
    297 
    298             if (!is_null($nbm_user['last_send']))
    299               $message .= sprintf(l10n('nbm_ContentNewElementsBetween'), $nbm_user['last_send'], $dbnow);
    300             else
    301               $message .= sprintf(l10n('nbm_ContentNewElements'), $dbnow);
    302 
    303             if ($conf['nbm_send_detailed_content'])
     263            if (news_exists($nbm_user['last_send'], $dbnow))
    304264            {
    305               $message .= ":\n";
    306 
    307               foreach ($news as $line)
    308               {
    309                 $message .= '  o '.$line."\n";
    310               }
    311               $message .= "\n";
    312             }
    313             else
    314             {
    315               $message .= ".\n";
    316             }
    317 
    318             $message .= sprintf(l10n('nbm_ContentGoTo'), $conf['gallery_title'], $conf['gallery_url'])."\n\n";
    319             $message .= $customize_mail_content."\n\n";
    320             $message .= l10n('nbm_ContentByeBye')."\n   ".$send_as_name."\n\n";
    321             $message .= "\n".sprintf(l10n('nbm_ContentUnsubscribe'), $send_as_mail_address)."\n\n";
    322 
    323             if (pwg_mail(format_email($nbm_user['username'], $nbm_user['mail_address']), $send_as_mail_formated, $subject, $message))
    324             {
    325               $sent_mail_count += 1;
    326               array_push($page['infos'], sprintf($msg_info, $nbm_user['username'], $nbm_user['mail_address']));
    327 
    328               $data = array('user_id' => $user_notification['user_id'],
    329                             'last_send' => $dbnow);
    330               array_push($datas, $data);
    331             }
    332             else
    333             {
    334               $error_on_mail_count += 1;
    335               array_push($page['errors'], sprintf($msg_error, $nbm_user['username'], $nbm_user['mail_address']));
     265              array_push($return_list, $nbm_user);
    336266            }
    337267          }
    338268        }
    339         else
     269
     270        // Restore nbm environment
     271        end_users_env_nbm();
     272
     273        if ($is_action_send)
    340274        {
    341           if (news_exists($nbm_user['last_send'], $dbnow))
    342           {
    343             array_push($return_list, $nbm_user);
    344           }
     275          mass_updates(
     276            USER_MAIL_NOTIFICATION_TABLE,
     277            array(
     278              'primary' => array('user_id'),
     279              'update' => array('last_send')
     280             ),
     281             $datas
     282             );
     283
     284          display_counter_info();
    345285        }
    346286      }
    347 
    348       // Restore $user, $lang_info and $lang arrays (include/user.inc.php has been executed)
    349       $user = $sav_mailtousers_user;
    350       $lang_info = $sav_mailtousers_lang_info;
    351       $lang = $sav_mailtousers_lang;
    352 
    353       if ($is_action_send)
     287      else
    354288      {
    355         mass_updates(
    356           USER_MAIL_NOTIFICATION_TABLE,
    357           array(
    358             'primary' => array('user_id'),
    359             'update' => array('last_send')
    360            ),
    361            $datas
    362            );
    363 
    364 
    365         if ($error_on_mail_count != 0)
     289        if ($is_action_send)
    366290        {
    367           array_push($page['errors'], sprintf(l10n('nbm_%d mails were not sent.'), $error_on_mail_count));
    368         }
    369         else
    370         {
    371           if ($sent_mail_count == 0)
    372             array_push($page['infos'], l10n('nbm_No mail to send.'));
    373           else
    374             array_push($page['infos'], sprintf(l10n('nbm_%d mails were sent.'), $sent_mail_count));
     291          array_push($page['errors'], l10n('nbm_no_user_to send_notifications_by_mail'));
    375292        }
    376293      }
     
    378295    else
    379296    {
    380       if ($is_action_send)
    381       {
    382         array_push($page['errors'], l10n('nbm_No user to send notifications by mail.'));
    383       }
     297      // Quick List, don't check news
     298      $return_list = $data_users;
    384299    }
    385300  }
     
    469384    if (isset($_POST['falsify']) and isset($_POST['cat_true']))
    470385    {
    471       unsubcribe_notification_by_mail($_POST['cat_true']);
     386      unsubcribe_notification_by_mail(true, $_POST['cat_true']);
    472387    }
    473388    else
    474389    if (isset($_POST['trueify']) and isset($_POST['cat_false']))
    475390    {
    476       subcribe_notification_by_mail($_POST['cat_false']);
     391      subcribe_notification_by_mail(true, $_POST['cat_false']);
    477392    }
    478393    break;
     
    560475      $template->assign_block_vars(
    561476        (get_boolean($nbm_user['enabled']) ? 'category_option_true' : 'category_option_false'),
    562         array('SELECTED' => '',
     477        array('SELECTED' => ( // Keep selected user where enabled are not changed when change has been notify
     478                              get_boolean($nbm_user['enabled']) ? (isset($_POST['falsify']) and isset($_POST['cat_true']) and in_array($nbm_user['check_key'], $_POST['cat_true']))
     479                                                                : (isset($_POST['trueify']) and isset($_POST['cat_false']) and in_array($nbm_user['check_key'], $_POST['cat_false']))
     480                            ) ? 'selected="selected"' : '',
    563481              'VALUE' => $nbm_user['check_key'],
    564482              'OPTION' => $nbm_user['username'].'['.$nbm_user['mail_address'].']'
     
    573491    $template->assign_block_vars($page['mode'], array());
    574492
    575     $data_users = do_action_send_mail_notification('list');
     493    $data_users = do_action_send_mail_notification('list_to_send');
    576494
    577495    if  (count($data_users) == 0)
Note: See TracChangeset for help on using the changeset viewer.