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

Last change on this file since 26172 was 25872, checked in by mistic100, 11 years ago

update for 2.6

File size: 3.1 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 !$conf['ContactForm_ready'] )
7{
8  redirect(get_absolute_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    'send_copy' => isset($_POST['send_copy']),
23   );
24
25  $comment_action = send_contact_form($contact, @$_POST['key']);
26
27  switch ($comment_action)
28  {
29    case 'validate':
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      }
39      break;
40    case 'moderate':
41    case 'reject':
42      break;
43    default:
44      trigger_error('Invalid action '.$comment_action, E_USER_WARNING);
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'],
58      'group' => null,
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_extended_desc');
77}
78
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
97$template->assign(array(
98  'contact' => $contact,
99  'ContactForm_before' => trigger_event('render_contact_form', nl2br($conf['ContactForm_before'])),
100  'ContactForm_after' => trigger_event('render_contact_form', nl2br($conf['ContactForm_after'])),
101  'KEY' => get_ephemeral_key(3),
102  'CONTACT_FORM_PATH' => CONTACT_FORM_PATH,
103  'CONTACT_FORM_ABS_PATH'=> realpath(CONTACT_FORM_PATH).'/',
104  'F_ACTION' => CONTACT_FORM_PUBLIC,
105  ));
106
107$template->set_filename('contactform', realpath(CONTACT_FORM_PATH . 'template/contact_form.tpl'));
108$template->assign_var_from_handle('CONTENT', 'contactform');
Note: See TracBrowser for help on using the repository browser.