source: extensions/ContactForm/include/contact_form.inc.php @ 19180

Last change on this file since 19180 was 19180, checked in by mistic100, 12 years ago

add button 'Send copy to my email'

File size: 3.0 KB
RevLine 
[17483]1<?php
2if (!defined('CONTACT_FORM_PATH')) die('Hacking attempt!');
3
4global $template, $user, $conf, $page, $pwg_loaded_plugins;
5
6if ( (!is_classic_user() and !$conf['ContactForm']['cf_allow_guest']) or !count(get_contact_emails()) )
7{
8  redirect(get_root_url());
9}
10
11// +-----------------------------------------------------------------------+
12// |                                send email                             |
13// +-----------------------------------------------------------------------+
14if (isset($_POST['send_mail']))
15{
16  $contact = array(
[17945]17    'author' =>  trim($_POST['author']),
18    'email' =>   trim($_POST['email']),
19    'group' =>   @$_POST['group'],
20    'subject' => trim($_POST['subject']),
21    'content' => $_POST['content'],
[19180]22    'send_copy' => isset($_POST['send_copy']),
[17483]23   );
24 
25  $comment_action = send_contact_form($contact, @$_POST['key']);
26
27  switch ($comment_action)
28  {
29    case 'validate':
[18331]30      $_SESSION['page_infos'][] = l10n('E-mail sent successfully');
31      if (!empty($conf['ContactForm']['cf_redirect_url']))
32      {
33        redirect($conf['ContactForm']['cf_redirect_url']);
34      }
35      else
36      {
37        redirect(CONTACT_FORM_PUBLIC);
38      }
[17483]39      break;
40    case 'moderate':
41    case 'reject':
42      break;
43    default:
[18331]44      trigger_error('Invalid action '.$comment_action, E_USER_WARNING);
[17483]45  }
46}
47
48// +-----------------------------------------------------------------------+
49// |                                template                               |
50// +-----------------------------------------------------------------------+
51if (is_classic_user())
52{
53  if (!isset($contact))
54  {
55    $contact = array(
56      'author' => $user['username'],
57      'email' => $user['email'],
[17945]58      'group' => null,
[17483]59      'subject' => l10n($conf['ContactForm']['cf_default_subject']),
60      'content' => null,
61      );
62  }
63  $contact['is_logged'] = true;
64}
65if ($conf['ContactForm']['cf_mandatory_mail'])
66{
67  $contact['mandatory_mail'] = true;
68}
69if ($conf['ContactForm']['cf_mandatory_name'])
70{
71  $contact['mandatory_name'] = true;
72}
73
74if (!empty($pwg_loaded_plugins['ExtendedDescription']))
75{
76  add_event_handler('render_contact_form', 'get_user_language_desc');
77}
78
[17945]79$query = '
80SELECT DISTINCT group_name
81  FROM '. CONTACT_FORM_TABLE .'
82  ORDER BY group_name
83;';
84$result = pwg_query($query);
85
86$groups = array();
87while ($data = pwg_db_fetch_assoc($result))
88{
89  $groups[ $data['group_name'] ] = !empty($data['group_name']) ? l10n($data['group_name']) : l10n('Default');
90}
91
92if (count($groups) > 1)
93{
94  $template->assign('GROUPS', $groups);
95}
96
[17483]97$template->assign(array(
98  'contact' => $contact,
[18315]99  'ContactForm_before' => trigger_event('render_contact_form', nl2br($conf['ContactForm_before'])),
100  'ContactForm_after' => trigger_event('render_contact_form', nl2br($conf['ContactForm_after'])),
[17483]101  'KEY' => get_ephemeral_key(3),
102  'CONTACT_FORM_PATH' => CONTACT_FORM_PATH,
103  'CONTACT_FORM_ABS_PATH'=> dirname(__FILE__).'/../',
104  'F_ACTION' => CONTACT_FORM_PUBLIC,
105  ));
106
[17945]107$template->set_filename('index', realpath(CONTACT_FORM_PATH . 'template/contact_form.tpl'));
[17483]108
109?>
Note: See TracBrowser for help on using the repository browser.