Ignore:
Timestamp:
09/16/12 17:20:39 (7 years ago)
Author:
mistic100
Message:
  • stores emails in database (/!\ update only from published version, not from trunk)
  • allow emails to be categorized
File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/ContactForm/include/functions.inc.php

    r17662 r17945  
    8686      'name' => $row['username'], 
    8787      'email' => $row['email'], 
    88       'active' => true, 
     88      'active' => 'true', 
    8989      )); 
    9090  } 
    9191   
    92   $conf['ContactForm']['cf_admin_mails'] = $emails; 
     92  mass_inserts( 
     93    CONTACT_FORM_TABLE, 
     94    array('name','email','active'), 
     95    $email 
     96    ); 
     97   
    9398  $conf['ContactForm']['cf_must_initialize'] = false; 
    9499  conf_update_param('ContactForm', serialize($conf['ContactForm'])); 
     
    107112    $conf_mail = get_mail_configuration(); 
    108113  } 
     114   
     115  $query = ' 
     116SELECT DISTINCT group_name 
     117  FROM '. CONTACT_FORM_TABLE .' 
     118  ORDER BY group_name 
     119;'; 
     120  $groups = array_from_query($query, 'group_name'); 
    109121   
    110122  $comm = array_merge($comm, 
     
    159171  } 
    160172   
     173  // check group 
     174  if ( count($groups) > 1 and $comm['group'] == -1 ) 
     175  { 
     176    $comm['group'] = true; 
     177    array_push($page['errors'], l10n('Please choose a category')); 
     178    $comment_action='reject'; 
     179  } 
     180   
    161181  // check content 
    162182  if (empty($comm['content'])) 
     
    186206   
    187207  // get admin emails 
    188   $emails = get_contact_emails(); 
     208  $emails = get_contact_emails($comm['group']); 
    189209  if (!count($emails)) 
    190210  { 
     
    281301/** 
    282302 * get contact emails 
    283  */ 
    284 function get_contact_emails() 
     303 * @param mixed group: 
     304 *    - bool true:    all emails 
     305 *    - empty string: emails without group 
     306 *    - string:       emails with the specified group 
     307 */ 
     308function get_contact_emails($group=true) 
    285309{ 
    286310  global $conf; 
     
    288312  include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); 
    289313   
     314  $where = '1=1'; 
     315  if ($group!==true) 
     316  { 
     317    if (empty($group)) 
     318    { 
     319      $where = 'group_name IS NULL'; 
     320    } 
     321    else 
     322    { 
     323      $where = 'group_name="'.$group.'"'; 
     324    } 
     325  } 
     326   
     327  $query = ' 
     328SELECT * 
     329  FROM '. CONTACT_FORM_TABLE .' 
     330  WHERE  
     331    '.$where.' 
     332    AND active = "true" 
     333  ORDER BY name ASC 
     334'; 
     335  $result = pwg_query($query); 
     336   
    290337  $emails = array(); 
    291   foreach ($conf['ContactForm']['cf_admin_mails'] as $data) 
    292   { 
    293     if ($data['active']) 
    294     { 
    295       array_push($emails, format_email($data['name'], $data['email'])); 
    296     } 
     338  while ($data = pwg_db_fetch_assoc($result)) 
     339  { 
     340    array_push($emails, format_email($data['name'], $data['email'])); 
    297341  } 
    298342   
Note: See TracChangeset for help on using the changeset viewer.