Ignore:
Timestamp:
Sep 16, 2012, 5:20:39 PM (12 years ago)
Author:
mistic100
Message:
  • stores emails in database (/!\ update only from published version, not from trunk)
  • allow emails to be categorized
Location:
extensions/ContactForm/include
Files:
3 edited

Legend:

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

    r17483 r17945  
    1515{
    1616  $contact = array(
    17     'author' => trim($_POST['author']),
    18     'email' => trim($_POST['email']),
    19     'subject' =>   trim($_POST['subject']),
    20     'content' =>   $_POST['content'],
     17    'author' =>  trim($_POST['author']),
     18    'email' =>   trim($_POST['email']),
     19    'group' =>   @$_POST['group'],
     20    'subject' => trim($_POST['subject']),
     21    'content' => $_POST['content'],
    2122   );
    2223 
     
    4748      'author' => $user['username'],
    4849      'email' => $user['email'],
     50      'group' => null,
    4951      'subject' => l10n($conf['ContactForm']['cf_default_subject']),
    5052      'content' => null,
     
    6769}
    6870
     71$query = '
     72SELECT DISTINCT group_name
     73  FROM '. CONTACT_FORM_TABLE .'
     74  ORDER BY group_name
     75;';
     76$result = pwg_query($query);
     77
     78$groups = array();
     79while ($data = pwg_db_fetch_assoc($result))
     80{
     81  $groups[ $data['group_name'] ] = !empty($data['group_name']) ? l10n($data['group_name']) : l10n('Default');
     82}
     83
     84if (count($groups) > 1)
     85{
     86  $template->assign('GROUPS', $groups);
     87}
     88
    6989$template->assign(array(
    7090  'contact' => $contact,
     
    7797  ));
    7898
    79 $template->set_filename('index', dirname(__FILE__).'/../template/contact_form.tpl');
     99$template->set_filename('index', realpath(CONTACT_FORM_PATH . 'template/contact_form.tpl'));
    80100
    81101?>
  • 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 
  • extensions/ContactForm/include/install.inc.php

    r17658 r17945  
    44function contact_form_install()
    55{
    6   global $conf;
     6  global $conf, $prefixeTable;
     7 
     8  // email table
     9  $query = '
     10CREATE TABLE IF NOT EXISTS `'. $prefixeTable .'contact_form` (
     11  `id` smallint(5) NOT NULL AUTO_INCREMENT,
     12  `name` varchar(128) NOT NULL,
     13  `email` varchar(128) NOT NULL,
     14  `active` enum("true","false") NOT NULL DEFAULT "true",
     15  `group_name` varchar(128) DEFAULT NULL,
     16  PRIMARY KEY (`id`),
     17  UNIQUE KEY `UNIQUE` (`email`,`group_name`)
     18) ENGINE=MyISAM DEFAULT CHARSET=utf8;';
     19  pwg_query($query);
    720
    821  // configuration
     
    1932      'cf_redirect_delay' => 5,
    2033      'cf_mail_type' => 'text/html',
    21       'cf_admin_mails' => array(),
    2234      ));
    2335   
     
    3749    if (!isset($new_conf['cf_must_initialize']))
    3850    {
     51      // new params
    3952      $new_conf['cf_must_initialize'] = false;
    4053      $new_conf['cf_default_subject'] = 'A comment on your site';
    4154      $new_conf['cf_mail_type'] = 'text/html';
    42       unset($new_conf['comment'], $new_conf['cf_redirect_delay'], $new_conf['cf_separator'], $new_conf['cf_separator_length']);
    4355     
     56      // move emails to database
     57      $email = array();
    4458      foreach ($new_conf['cf_admin_mails'] as $email => $data)
    4559      {
    46         $new_conf['cf_admin_mails'][] = array(
     60        array_push($emails, array(
    4761          'email' => $email,
    4862          'name' => $data['NAME'],
    49           'active' => $data['ACTIVE'],
    50           );
    51         unset($new_conf['cf_admin_mails'][ $email ]);
     63          'active' => boolean_to_string($data['ACTIVE']),
     64          ));
    5265      }
    5366     
     67      mass_inserts(
     68        $prefixeTable .'contact_form',
     69        array('name','email','active'),
     70        $emails
     71        );
     72     
     73      // old params
     74      unset(
     75        $new_conf['comment'], $new_conf['cf_redirect_delay'],
     76        $new_conf['cf_separator'], $new_conf['cf_separator_length'],
     77        $new_conf['cf_admin_mails']
     78        );
     79     
     80      // save config
    5481      $conf['ContactForm'] = serialize($new_conf);
    5582      $conf['ContactForm_before'] = stripslashes($conf['persoformtop']);
Note: See TracChangeset for help on using the changeset viewer.