1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use cmsemail\email; |
4
|
|
|
|
5
|
|
|
if (!defined('BASEPATH')) { |
6
|
|
|
exit('No direct script access allowed'); |
7
|
|
|
} |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Image CMS |
11
|
|
|
* |
12
|
|
|
* Feedback module |
13
|
|
|
*/ |
14
|
|
|
class Feedback extends MY_Controller |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
public $username_max_len = 30; |
18
|
|
|
|
19
|
|
|
public $message_max_len = 600; |
20
|
|
|
|
21
|
|
|
public $theme_max_len = 150; |
22
|
|
|
|
23
|
|
|
public $admin_mail = 'admin@localhost'; |
24
|
|
|
|
25
|
|
|
public $message = ''; |
26
|
|
|
|
27
|
|
|
protected $formErrors = []; |
28
|
|
|
|
29
|
|
|
public function __construct() { |
30
|
|
|
parent::__construct(); |
31
|
|
|
$this->load->module('core'); |
32
|
|
|
$this->load_settings(); |
33
|
|
|
|
34
|
|
|
$this->formErrors = [ |
35
|
|
|
'required' => lang('Field is required'), |
36
|
|
|
'min_length' => lang('Length is less than the minimum'), |
37
|
|
|
'valid_email' => lang('Email is not valid'), |
38
|
|
|
'max_length' => lang('Length greater than the maximum'), |
39
|
|
|
]; |
40
|
|
|
$lang = new MY_Lang(); |
41
|
|
|
$lang->load('feedback'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function autoload() { |
45
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function captcha_check($code) { |
49
|
|
|
if (!$this->dx_auth->captcha_check($code)) { |
|
|
|
|
50
|
|
|
return FALSE; |
51
|
|
|
} else { |
52
|
|
|
return TRUE; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
View Code Duplication |
public function recaptcha_check() { |
57
|
|
|
$result = $this->dx_auth->is_recaptcha_match(); |
58
|
|
|
if (!$result) { |
59
|
|
|
$this->form_validation->set_message('recaptcha_check', lang('Improper protection code', 'feedback')); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $result; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
// Index function |
66
|
|
|
|
67
|
|
|
public function index() { |
68
|
|
|
$this->template->registerMeta('ROBOTS', 'NOINDEX, NOFOLLOW'); |
69
|
|
|
|
70
|
|
|
$this->core->set_meta_tags(lang('Feedback', 'feedback')); |
71
|
|
|
|
72
|
|
|
$this->load->library('form_validation'); |
73
|
|
|
|
74
|
|
|
// Create captcha |
75
|
|
|
$this->dx_auth->captcha(); |
76
|
|
|
$tpl_data['cap_image'] = $this->dx_auth->get_captcha_image(); |
|
|
|
|
77
|
|
|
|
78
|
|
|
$this->template->add_array($tpl_data); |
79
|
|
|
|
80
|
|
|
if (count($this->input->post()) > 0) { |
81
|
|
|
$this->form_validation->set_rules('name', lang('Your name', 'feedback'), 'trim|required|min_length[3]|max_length[' . $this->username_max_len . ']|xss_clean'); |
82
|
|
|
$this->form_validation->set_rules('email', lang('Email', 'feedback'), 'trim|required|valid_email|xss_clean'); |
83
|
|
|
$this->form_validation->set_rules('theme', lang('Subject', 'feedback'), 'trim|max_length[' . $this->theme_max_len . ']|xss_clean'); |
84
|
|
|
$this->form_validation->set_rules('message', lang('Message', 'feedback'), 'trim|required|max_length[' . $this->message_max_len . ']|xss_clean'); |
85
|
|
|
|
86
|
|
View Code Duplication |
if ($this->dx_auth->use_recaptcha) { |
87
|
|
|
$this->form_validation->set_rules('recaptcha_response_field', lang('Protection code', 'feedback'), 'trim|xss_clean|required|callback_recaptcha_check'); |
88
|
|
|
} else { |
89
|
|
|
$this->form_validation->set_rules('captcha', lang('Protection code', 'feedback'), 'trim|required|xss_clean|callback_captcha_check'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if ($this->form_validation->run($this) == FALSE) { // there are errors |
93
|
|
|
$this->form_validation->set_error_delimiters('', ''); |
94
|
|
|
CMSFactory\assetManager::create()->setData('validation', $this->form_validation); |
95
|
|
|
form_error(); |
96
|
|
|
} else { // form is validate |
97
|
|
|
|
98
|
|
|
$feedback_variables = [ |
99
|
|
|
'Theme' => $this->input->post('theme'), |
100
|
|
|
'userName' => $this->input->post('name'), |
101
|
|
|
'userEmail' => $this->input->post('email'), |
102
|
|
|
'userMessage' => $this->input->post('message'), |
103
|
|
|
]; |
104
|
|
|
email::getInstance()->sendEmail($this->input->post('email'), 'feedback', $feedback_variables); |
105
|
|
|
CMSFactory\assetManager::create()->appendData('message_sent', TRUE); |
|
|
|
|
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
CMSFactory\assetManager::create()->render('feedback'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
private function load_settings() { |
114
|
|
|
$this->db->limit(1); |
115
|
|
|
$this->db->where('name', 'feedback'); |
116
|
|
|
$query = $this->db->get('components')->row_array(); |
117
|
|
|
|
118
|
|
|
$settings = unserialize($query['settings']); |
119
|
|
|
|
120
|
|
|
if (is_int($settings['message_max_len'])) { |
121
|
|
|
$this->message_max_len = $settings['message_max_len']; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
if ($settings['email']) { |
125
|
|
|
$this->admin_mail = $settings['email']; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/* End of file sample_module.php */ |