Changeset 1904 for trunk/include


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

Fix bad default value for language on table user_info
Improve mail send (Undisclosed-recipients, switch language, ...)
Improve send an email to group members (Use Bcc, template, multi-language, ...) (But need more improvements)

Location:
trunk/include
Files:
2 edited

Legend:

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

    r1901 r1904  
    210210}
    211211
    212 /**
     212/*
     213 * Switch language to param language
     214 * All entries are push on language stack
     215 *
     216 * @param string language
     217 */
     218function 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 */
     271function 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  }
     294}
     295
     296/*
     297 * send en email to user's group
     298 *
     299  * @param:
     300 *   - group_id: mail are sent to group with this Id
     301 *   - email_format: mail format
     302 *   - key_subject:  TODO Include translations
     303 *   - tpl_shortname: short template name without extension
     304 *   - assign_vars: array used to assign_vars to mail template
     305 *   - language_selected: send mail only to user with this selected language
     306*/
     307function pwg_mail_group(
     308  $group_id, $email_format, $key_subject,
     309  $tpl_shortname, $assign_vars = array(), $language_selected = '')
     310{
     311  global $conf;
     312
     313  $query = '
     314SELECT
     315  distinct language, template
     316FROM
     317  '.USER_GROUP_TABLE.' as ug
     318  INNER JOIN '.USERS_TABLE.' as u  ON '.$conf['user_fields']['id'].' = ug.user_id
     319  INNER JOIN '.USER_INFOS_TABLE.' as ui  ON ui.user_id = ug.user_id
     320WHERE
     321        '.$conf['user_fields']['email'].' IS NOT NULL
     322    AND group_id = '.$group_id;
     323
     324  if (!empty($language_selected))
     325  {
     326    $query .= '
     327    AND language = \''.$language_selected.'\'';
     328  }
     329
     330    $query .= '
     331;';
     332
     333  $result = pwg_query($query);
     334
     335  if (mysql_num_rows($result) > 0)
     336  {
     337    $list = array();
     338    while ($row = mysql_fetch_array($result))
     339    {
     340      list($row['template'], $row['theme']) = explode('/', $row['template']);
     341      $list[] = $row;
     342    }
     343  }
     344
     345
     346  foreach ($list as $elem)
     347  {
     348    $query = '
     349SELECT
     350  u.'.$conf['user_fields']['username'].' as username,
     351  u.'.$conf['user_fields']['email'].' as mail_address
     352FROM
     353  '.USER_GROUP_TABLE.' as ug
     354  INNER JOIN '.USERS_TABLE.' as u  ON '.$conf['user_fields']['id'].' = ug.user_id
     355  INNER JOIN '.USER_INFOS_TABLE.' as ui  ON ui.user_id = ug.user_id
     356WHERE
     357        '.$conf['user_fields']['email'].' IS NOT NULL
     358    AND group_id = '.$group_id.'
     359    AND language = \''.$elem['language'].'\'
     360;';
     361
     362    $result = pwg_query($query);
     363
     364    if (mysql_num_rows($result) > 0)
     365    {
     366      $Bcc = array();
     367      while ($row = mysql_fetch_array($result))
     368      {
     369        if (!empty($row['mail_address']))
     370        {
     371          array_push($Bcc, format_email($row['username'], $row['mail_address']));
     372        }
     373      }
     374
     375      switch_lang_to($elem['language']);
     376
     377      $mail_template = get_mail_template($email_format, $elem);
     378      $mail_template->set_filename($tpl_shortname, $tpl_shortname.'.tpl');
     379      $mail_template->assign_vars($assign_vars);
     380
     381      pwg_mail
     382      (
     383        '',
     384        array
     385        (
     386          'subject' => $key_subject,
     387          'email_format' => $email_format,
     388          'content' => $mail_template->parse($tpl_shortname, true),
     389          'content_format' => $email_format,
     390          'template' => $elem['template'],
     391          'theme' => $elem['theme']
     392        )
     393      );
     394
     395      switch_lang_back();
     396    }
     397  }
     398}
     399
     400
     401/*
    213402 * sends an email, using PhpWebGallery specific informations
    214403 *
     
    246435  }
    247436
    248   $to = format_email('', $to);
     437  if (!empty($to))
     438  {
     439    $to = format_email('', $to);
     440  }
    249441
    250442  if (empty($args['from']))
     
    288480  $headers = 'From: '.$args['from']."\n";
    289481  $headers.= 'Reply-To: '.$args['from']."\n";
     482  if (empty($to))
     483  {
     484    $headers.= 'To: undisclosed-recipients: ;'."\n";
     485  }
    290486
    291487  if (!empty($args['Cc']))
  • trunk/include/functions_user.inc.php

    r1900 r1904  
    805805 * availability of the file
    806806 *
    807  * in descending order of preference: user language, default language,
     807 * in descending order of preference:
     808 *   param language, user language, default language
    808809 * PhpWebGallery default language.
    809810 *
    810811 * @param string filename
    811812 * @param string dirname
     813 * @param string language
    812814 * @return string filepath
    813815 */
    814 function get_language_filepath($filename, $dirname = '')
     816function get_language_filepath($filename, $dirname = '', $language = '')
    815817{
    816818  global $user, $conf;
     
    823825
    824826  $directories = array();
    825   if ( isset($user['language']) )
     827  if ( !empty($language) )
     828  {
     829    $directories[] = $dirname.$language;
     830  }
     831
    826832  {
    827833    $directories[] = $dirname.$user['language'];
Note: See TracChangeset for help on using the changeset viewer.