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

Last change on this file since 17945 was 17945, checked in by mistic100, 12 years ago
  • stores emails in database (/!\ update only from published version, not from trunk)
  • allow emails to be categorized
File size: 2.8 KB
Line 
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(
17    'author' =>  trim($_POST['author']),
18    'email' =>   trim($_POST['email']),
19    'group' =>   @$_POST['group'],
20    'subject' => trim($_POST['subject']),
21    'content' => $_POST['content'],
22   );
23 
24  $comment_action = send_contact_form($contact, @$_POST['key']);
25
26  switch ($comment_action)
27  {
28    case 'validate':
29      array_push($page['infos'], l10n('E-mail sent successfully'));
30      unset($contact);
31      break;
32    case 'moderate':
33    case 'reject':
34      break;
35    default:
36      trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
37  }
38}
39
40// +-----------------------------------------------------------------------+
41// |                                template                               |
42// +-----------------------------------------------------------------------+
43if (is_classic_user())
44{
45  if (!isset($contact))
46  {
47    $contact = array(
48      'author' => $user['username'],
49      'email' => $user['email'],
50      'group' => null,
51      'subject' => l10n($conf['ContactForm']['cf_default_subject']),
52      'content' => null,
53      );
54  }
55  $contact['is_logged'] = true;
56}
57if ($conf['ContactForm']['cf_mandatory_mail'])
58{
59  $contact['mandatory_mail'] = true;
60}
61if ($conf['ContactForm']['cf_mandatory_name'])
62{
63  $contact['mandatory_name'] = true;
64}
65
66if (!empty($pwg_loaded_plugins['ExtendedDescription']))
67{
68  add_event_handler('render_contact_form', 'get_user_language_desc');
69}
70
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
89$template->assign(array(
90  'contact' => $contact,
91  'ContactForm_before' => trigger_event('render_contact_form', $conf['ContactForm_before']),
92  'ContactForm_after' => trigger_event('render_contact_form', $conf['ContactForm_after']),
93  'KEY' => get_ephemeral_key(3),
94  'CONTACT_FORM_PATH' => CONTACT_FORM_PATH,
95  'CONTACT_FORM_ABS_PATH'=> dirname(__FILE__).'/../',
96  'F_ACTION' => CONTACT_FORM_PUBLIC,
97  ));
98
99$template->set_filename('index', realpath(CONTACT_FORM_PATH . 'template/contact_form.tpl'));
100
101?>
Note: See TracBrowser for help on using the repository browser.