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

Last change on this file since 18581 was 18331, checked in by mistic100, 12 years ago
  • add redirect url option
  • remove test code
  • fix fatal error at first installation
File size: 3.0 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      $_SESSION['page_infos'][] = l10n('E-mail sent successfully');
30      if (!empty($conf['ContactForm']['cf_redirect_url']))
31      {
32        redirect($conf['ContactForm']['cf_redirect_url']);
33      }
34      else
35      {
36        redirect(CONTACT_FORM_PUBLIC);
37      }
38      break;
39    case 'moderate':
40    case 'reject':
41      break;
42    default:
43      trigger_error('Invalid action '.$comment_action, E_USER_WARNING);
44  }
45}
46
47// +-----------------------------------------------------------------------+
48// |                                template                               |
49// +-----------------------------------------------------------------------+
50if (is_classic_user())
51{
52  if (!isset($contact))
53  {
54    $contact = array(
55      'author' => $user['username'],
56      'email' => $user['email'],
57      'group' => null,
58      'subject' => l10n($conf['ContactForm']['cf_default_subject']),
59      'content' => null,
60      );
61  }
62  $contact['is_logged'] = true;
63}
64if ($conf['ContactForm']['cf_mandatory_mail'])
65{
66  $contact['mandatory_mail'] = true;
67}
68if ($conf['ContactForm']['cf_mandatory_name'])
69{
70  $contact['mandatory_name'] = true;
71}
72
73if (!empty($pwg_loaded_plugins['ExtendedDescription']))
74{
75  add_event_handler('render_contact_form', 'get_user_language_desc');
76}
77
78$query = '
79SELECT DISTINCT group_name
80  FROM '. CONTACT_FORM_TABLE .'
81  ORDER BY group_name
82;';
83$result = pwg_query($query);
84
85$groups = array();
86while ($data = pwg_db_fetch_assoc($result))
87{
88  $groups[ $data['group_name'] ] = !empty($data['group_name']) ? l10n($data['group_name']) : l10n('Default');
89}
90
91if (count($groups) > 1)
92{
93  $template->assign('GROUPS', $groups);
94}
95
96$template->assign(array(
97  'contact' => $contact,
98  'ContactForm_before' => trigger_event('render_contact_form', nl2br($conf['ContactForm_before'])),
99  'ContactForm_after' => trigger_event('render_contact_form', nl2br($conf['ContactForm_after'])),
100  'KEY' => get_ephemeral_key(3),
101  'CONTACT_FORM_PATH' => CONTACT_FORM_PATH,
102  'CONTACT_FORM_ABS_PATH'=> dirname(__FILE__).'/../',
103  'F_ACTION' => CONTACT_FORM_PUBLIC,
104  ));
105
106$template->set_filename('index', realpath(CONTACT_FORM_PATH . 'template/contact_form.tpl'));
107
108?>
Note: See TracBrowser for help on using the repository browser.