Ignore:
Timestamp:
Mar 16, 2007, 12:20:41 AM (17 years ago)
Author:
rub
Message:

Add new translation functions.inc.php
Translate subject of information mail.
Notification mails are sent on the default language.
No mail is sent to the author witch are not done actions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_mail.inc.php

    r1904 r1908  
    155155}
    156156
     157/*
     158 * Switch language to param language
     159 * All entries are push on language stack
     160 *
     161 * @param string language
     162 */
     163function switch_lang_to($language)
     164{
     165  global $switch_lang, $user, $lang, $lang_info;
     166
     167  if (count($switch_lang['stack']) == 0)
     168  {
     169    $prev_language = $user['language'];
     170  }
     171  else
     172  {
     173    $prev_language = end($switch_lang['stack']);
     174  }
     175
     176  $switch_lang['stack'][] = $language;
     177
     178  if ($prev_language != $language)
     179  {
     180    if (!isset($switch_lang['language'][$prev_language]))
     181    {
     182      $switch_lang[$prev_language]['lang_info'] = $lang_info;
     183      $switch_lang[$prev_language]['lang'] = $lang;
     184    }
     185
     186    if (!isset($switch_lang['language'][$language]))
     187    {
     188      // Re-Init language arrays
     189      $lang_info = array();
     190      $lang  = array();
     191
     192      // language files
     193      include(get_language_filepath('common.lang.php', '', $language));
     194      // No test admin because script is checked admin (user selected no)
     195      // Translations are in admin file too
     196      include(get_language_filepath('admin.lang.php', '', $language));
     197      trigger_action('loading_lang');
     198      @include(get_language_filepath('local.lang.php', '', $language));
     199
     200      $switch_lang[$language]['lang_info'] = $lang_info;
     201      $switch_lang[$language]['lang'] = $lang;
     202    }
     203    else
     204    {
     205      $lang_info = $switch_lang[$language]['lang_info'];
     206      $lang = $switch_lang[$language]['lang'];
     207    }
     208  }
     209}
     210
     211/*
     212 * Switch back language pushed with switch_lang_to function
     213 *
     214 * @param: none
     215 */
     216function switch_lang_back()
     217{
     218  global $switch_lang, $user, $lang, $lang_info;
     219
     220  $last_language = array_pop($switch_lang['stack']);
     221
     222  if (count($switch_lang['stack']) > 0)
     223  {
     224    $language = end($switch_lang['stack']);
     225  }
     226  else
     227  {
     228    $language = $user['language'];
     229  }
     230
     231  if ($last_language != $language)
     232  {
     233    if (!isset($switch_lang['language'][$language]))
     234    {
     235      $lang_info = $switch_lang[$language]['lang_info'];
     236      $lang = $switch_lang[$language]['lang'];
     237    }
     238  }
     239}
     240
    157241/**
    158242 * Returns email of all administrator
     
    160244 * @return string
    161245 */
    162 function get_administrators_email()
    163 {
    164   global $conf;
    165 
    166   $result = array();
     246/*
     247 * send en notification email to all administrators
     248 * if a administrator is doing action,
     249 * he's be removed to email list
     250 *
     251 * @param:
     252 *   - keyargs_subject: mail subject on l10n_args format
     253 *   - keyargs_content: mail content on l10n_args format
     254 *
     255 * @return boolean (Ok or not)
     256 */
     257function pwg_mail_notification_admins($keyargs_subject, $keyargs_content)
     258{
     259  global $conf, $user;
     260  $return = true;
     261
     262  $admins = array();
    167263
    168264  $query = '
     
    177273  I.status in (\'webmaster\',  \'admin\') and
    178274  I.adviser = \'false\' and
    179   '.$conf['user_fields']['email'].' is not null
     275  '.$conf['user_fields']['email'].' is not null and
     276  I.user_id <> '.$user['id'].'
    180277order by
    181278  username
     
    189286      if (!empty($admin['mail_address']))
    190287      {
    191         array_push($result, format_email($admin['username'], $admin['mail_address']));
     288        array_push($admins, format_email($admin['username'], $admin['mail_address']));
    192289      }
    193290    }
    194291  }
    195292
    196   return $result;
    197 }
    198 
    199 /* Return a standard block useful for admin mail */
    200 function get_block_mail_admin_info()
    201 {
    202   global $user;
    203 
    204   return
    205     "\n"
    206     .'Connected user: '.$user['username']."\n"
    207     .'IP: '.$_SERVER['REMOTE_ADDR']."\n"
    208     .'Browser: '.$_SERVER['HTTP_USER_AGENT']."\n"
    209     ."\n";
    210 }
    211 
    212 /*
    213  * Switch language to param language
    214  * All entries are push on language stack
    215  *
    216  * @param string language
    217  */
    218 function switch_lang_to($language)
    219 {
    220   global $switch_lang, $user, $lang, $lang_info;
    221 
    222   if (count($switch_lang['stack']) == 0)
    223   {
    224     $prev_language = $user['language'];
    225   }
    226   else
    227   {
    228     $prev_language = end($switch_lang['stack']);
    229   }
    230 
    231   $switch_lang['stack'][] = $language;
    232 
    233   if ($prev_language != $language)
    234   {
    235     if (!isset($switch_lang['language'][$prev_language]))
    236     {
    237       $switch_lang[$prev_language]['lang_info'] = $lang_info;
    238       $switch_lang[$prev_language]['lang'] = $lang;
    239     }
    240 
    241     if (!isset($switch_lang['language'][$language]))
    242     {
    243       // Re-Init language arrays
    244       $lang_info = array();
    245       $lang  = array();
    246 
    247       // language files
    248       include(get_language_filepath('common.lang.php', '', $language));
    249       // No test admin because script is checked admin (user selected no)
    250       // Translations are in admin file too
    251       include(get_language_filepath('admin.lang.php', '', $language));
    252       trigger_action('loading_lang');
    253       @include(get_language_filepath('local.lang.php', '', $language));
    254 
    255       $switch_lang[$language]['lang_info'] = $lang_info;
    256       $switch_lang[$language]['lang'] = $lang;
    257     }
    258     else
    259     {
    260       $lang_info = $switch_lang[$language]['lang_info'];
    261       $lang = $switch_lang[$language]['lang'];
    262     }
    263   }
    264 }
    265 
    266 /*
    267  * Switch back language pushed with switch_lang_to function
    268  *
    269  * @param: none
    270  */
    271 function switch_lang_back()
    272 {
    273   global $switch_lang, $user, $lang, $lang_info;
    274 
    275   $last_language = array_pop($switch_lang['stack']);
    276 
    277   if (count($switch_lang['stack']) > 0)
    278   {
    279     $language = end($switch_lang['stack']);
    280   }
    281   else
    282   {
    283     $language = $user['language'];
    284   }
    285 
    286   if ($last_language != $language)
    287   {
    288     if (!isset($switch_lang['language'][$language]))
    289     {
    290       $lang_info = $switch_lang[$language]['lang_info'];
    291       $lang = $switch_lang[$language]['lang'];
    292     }
    293   }
     293  $keyargs_content_admin_info = array
     294  (
     295    get_l10n_args('Connected user: %s', $user['username']),
     296    get_l10n_args('IP: %s', $_SERVER['REMOTE_ADDR']),
     297    get_l10n_args('Browser: %s', $_SERVER['HTTP_USER_AGENT'])
     298  );
     299
     300  switch_lang_to($conf['default_language']);
     301
     302  $return = pwg_mail
     303  (
     304    '',
     305    array
     306    (
     307      'Bcc' => $admins,
     308      'subject' => '['.$conf['gallery_title'].'] '.l10n_args($keyargs_subject),
     309      'content' =>
     310         l10n_args($keyargs_content)."\n\n"
     311        .l10n_args($keyargs_content_admin_info)."\n",
     312      'content_format' => 'text/plain'
     313    )
     314  ) and $return;
     315
     316  switch_lang_back();
     317
     318  return $return;
    294319}
    295320
     
    297322 * send en email to user's group
    298323 *
    299   * @param:
     324 * @param:
    300325 *   - group_id: mail are sent to group with this Id
    301326 *   - email_format: mail format
    302  *   - key_subject:  TODO Include translations
     327 *   - keyargs_subject: mail subject on l10n_args format
    303328 *   - tpl_shortname: short template name without extension
    304329 *   - assign_vars: array used to assign_vars to mail template
    305330 *   - language_selected: send mail only to user with this selected language
    306 */
     331 *
     332 * @return boolean (Ok or not)
     333 */
    307334function pwg_mail_group(
    308   $group_id, $email_format, $key_subject,
     335  $group_id, $email_format, $keyargs_subject,
    309336  $tpl_shortname, $assign_vars = array(), $language_selected = '')
    310337{
    311338  global $conf;
     339  $return = true;
    312340
    313341  $query = '
     
    342370    }
    343371  }
    344 
    345372
    346373  foreach ($list as $elem)
     
    376403
    377404      $mail_template = get_mail_template($email_format, $elem);
    378       $mail_template->set_filename($tpl_shortname, $tpl_shortname.'.tpl');
     405      $mail_template->set_filename($tpl_shortname,
     406        (IN_ADMIN ? 'admin/' : '').$tpl_shortname.'.tpl');
    379407      $mail_template->assign_vars($assign_vars);
    380408
    381       pwg_mail
     409      $return = pwg_mail
    382410      (
    383411        '',
    384412        array
    385413        (
    386           'subject' => $key_subject,
     414          'Bcc' => $Bcc,
     415          'subject' => l10n_args($keyargs_subject),
    387416          'email_format' => $email_format,
    388417          'content' => $mail_template->parse($tpl_shortname, true),
     
    391420          'theme' => $elem['theme']
    392421        )
    393       );
     422      ) and $return;
    394423
    395424      switch_lang_back();
    396425    }
    397426  }
     427
     428  return $return;
    398429}
    399430
     
    414445 *       o template: template to use [default $conf['default_template']]
    415446 *       o theme: template to use [default $conf['default_template']]
     447 *
     448 * @return boolean (Ok or not)
    416449 */
    417450function pwg_mail($to, $args = array())
Note: See TracChangeset for help on using the changeset viewer.