1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Mail |
5
|
|
|
* @author Iurii Makukh |
6
|
|
|
* @copyright Copyright (c) 2017, Iurii Makukh |
7
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+ |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace gplcart\modules\mail\controllers; |
11
|
|
|
|
12
|
|
|
use gplcart\core\controllers\backend\Controller; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Handles incoming requests and outputs data related to Mail module |
16
|
|
|
*/ |
17
|
|
|
class Settings extends Controller |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Route page callback to display the module settings page |
22
|
|
|
*/ |
23
|
|
|
public function editSettings() |
24
|
|
|
{ |
25
|
|
|
$this->setTitleEditSettings(); |
26
|
|
|
$this->setBreadcrumbEditSettings(); |
27
|
|
|
|
28
|
|
|
$this->setData('settings', $this->module->getSettings('mail')); |
29
|
|
|
|
30
|
|
|
$this->submitSettings(); |
31
|
|
|
$this->setDataEditSettings(); |
32
|
|
|
$this->outputEditSettings(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Prepare data before passing to templates |
37
|
|
|
*/ |
38
|
|
|
protected function setDataEditSettings() |
39
|
|
|
{ |
40
|
|
|
$smtp_host = $this->getData('settings.host'); |
41
|
|
|
|
42
|
|
|
if (is_array($smtp_host)) { |
43
|
|
|
$this->setData('settings.host', implode(PHP_EOL, (array) $smtp_host)); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Set title on the module settings page |
49
|
|
|
*/ |
50
|
|
|
protected function setTitleEditSettings() |
51
|
|
|
{ |
52
|
|
|
$title = $this->text('Edit %name settings', array('%name' => $this->text('Mail'))); |
53
|
|
|
$this->setTitle($title); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Set breadcrumbs on the module settings page |
58
|
|
|
*/ |
59
|
|
|
protected function setBreadcrumbEditSettings() |
60
|
|
|
{ |
61
|
|
|
$breadcrumbs = array(); |
62
|
|
|
|
63
|
|
|
$breadcrumbs[] = array( |
64
|
|
|
'text' => $this->text('Dashboard'), |
65
|
|
|
'url' => $this->url('admin') |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$breadcrumbs[] = array( |
69
|
|
|
'text' => $this->text('Modules'), |
70
|
|
|
'url' => $this->url('admin/module/list') |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$this->setBreadcrumbs($breadcrumbs); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Saves the submitted settings |
78
|
|
|
*/ |
79
|
|
|
protected function submitSettings() |
80
|
|
|
{ |
81
|
|
|
if ($this->isPosted('save') && $this->validateSettings()) { |
82
|
|
|
$this->updateSettings(); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Validate submitted module settings |
88
|
|
|
*/ |
89
|
|
|
protected function validateSettings() |
90
|
|
|
{ |
91
|
|
|
$this->setSubmitted('settings'); |
92
|
|
|
|
93
|
|
|
$this->validateElement('port', 'numeric'); |
94
|
|
|
$this->validateElement('host', 'required'); |
95
|
|
|
$this->validateElement('user', 'required'); |
96
|
|
|
$this->validateElement('password', 'required'); |
97
|
|
|
|
98
|
|
|
$this->setSubmittedBool('auth'); |
99
|
|
|
$this->setSubmittedArray('host'); |
100
|
|
|
|
101
|
|
|
return !$this->hasErrors(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Update module settings |
106
|
|
|
*/ |
107
|
|
|
protected function updateSettings() |
108
|
|
|
{ |
109
|
|
|
$this->controlAccess('module_edit'); |
110
|
|
|
$this->module->setSettings('mail', $this->getSubmitted()); |
111
|
|
|
$this->redirect('', $this->text('Settings have been updated'), 'success'); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Render and output the module settings page |
116
|
|
|
*/ |
117
|
|
|
protected function outputEditSettings() |
118
|
|
|
{ |
119
|
|
|
$this->output('mail|settings'); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
} |
123
|
|
|
|