forked from yves-lndm/Roundcube-Vacation-Autoreply-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vacation.php
197 lines (159 loc) · 7.12 KB
/
vacation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/*
* Vacation plugin that adds a new tab to the settings section
* to enable forward / out of office replies.
*
* @package plugins
* @uses rcube_plugin
* @author Jasper Slits <[email protected]>
* @version 1.9
* @license GPL
* @link https://sourceforge.net/projects/rcubevacation/
* @todo See README.TXT
*
* @moded 2016-12-09 by LNDM for RC 1.2.3
*/
// Load required dependencies
require 'lib/vacationdriver.class.php';
require 'lib/dotforward.class.php';
require 'lib/vacationfactory.class.php';
require 'lib/VacationConfig.class.php';
class vacation extends rcube_plugin {
public $task = 'settings';
private $v = "";
private $inicfg = "";
private $enableVacationTab = true;
private $vcObject;
public function init() {
$this->add_texts('localization/', array('vacation'));
$this->load_config();
$this->inicfg = $this->readIniConfig();
// Don't proceed if the current host does not support vacation
if (!$this->enableVacationTab) {
return false;
}
$this->v = VacationDriverFactory::Create($this->inicfg['driver']);
$this->v->setIniConfig($this->inicfg);
$this->register_action('plugin.vacation', array($this, 'vacation_init'));
$this->register_action('plugin.vacation-save', array($this, 'vacation_save'));
$this->register_handler('plugin.vacation_form', array($this, 'vacation_form'));
// The vacation_aliases method is defined in vacationdriver.class.php so use $this->v here
$this->register_action('plugin.vacation_aliases', array($this->v, 'vacation_aliases'));
$this->include_script('vacation.js');
$this->include_stylesheet('skins/default/vacation.css');
$this->rcmail = rcmail::get_instance();
$this->user = $this->rcmail->user;
$this->identity = $this->user->get_identity();
// forward settings are shared by ftp,sshftp and setuid driver.
$this->v->setDotForwardConfig($this->inicfg['driver'],$this->vcObject->getDotForwardCfg());
}
public function vacation_init() {
$this->add_texts('localization/', array('vacation'));
$rcmail = rcmail::get_instance();
$rcmail->output->set_pagetitle($this->gettext('autoresponder'));
//Load template
$rcmail->output->send('vacation.vacation');
}
public function vacation_save() {
$rcmail = rcmail::get_instance();
// Initialize the driver
$this->v->init();
if ($this->v->save()) {
// $this->v->getActionText() Dummy for now
$rcmail->output->show_message($this->gettext("success_changed"), 'confirmation');
} else {
$rcmail->output->show_message($this->gettext("failed"), 'error');
}
$this->vacation_init();
}
// Parse config.ini and get configuration for current host
private function readIniConfig() {
$this->vcObject = new VacationConfig();
$this->vcObject->setCurrentHost($_SESSION['imap_host']);
$config = $this->vcObject->getCurrentConfig();
if (false !== ($errorStr = $this->vcObject->hasError())) {
raise_error(array('code' => 601, 'type' => 'php', 'file' => __FILE__,
'message' => sprintf("Vacation plugin: %s", $errorStr)), true, true);
}
$this->enableVacationTab = $this->vcObject->hasVacationEnabled();
return $config;
}
public function vacation_form() {
$rcmail = rcmail::get_instance();
// Initialize the driver
$this->v->init();
$settings = $this->v->_get();
// Load default body & subject if present.
if (empty($settings['subject']) && $defaults = $this->v->loadDefaults()) {
$settings['subject'] = $defaults['subject'];
$settings['body'] = $defaults['body'];
}
$rcmail->output->set_env('product_name', $rcmail->config->get('product_name'));
// return the complete edit form as table
$out = '<fieldset><legend>' . $this->gettext('outofoffice') . ' ::: ' . $rcmail->user->data['username'] . '</legend>' . "\n";
// show autoresponder properties
// Auto-reply enabled
$field_id = 'vacation_enabled';
$input_autoresponderactive = new html_checkbox(array('name' => '_vacation_enabled', 'id' => $field_id, 'value' => 1));
$out .= sprintf("<p><label for=\"%s\">%s</label> %s</p>\n",
$field_id,
rep_specialchars_output($this->gettext('autoreply')),
$input_autoresponderactive->show($settings['enabled']));
// Subject
$field_id = 'vacation_subject';
$input_autorespondersubject = new html_inputfield(array('name' => '_vacation_subject', 'id' => $field_id, 'size' => 90));
$out .= sprintf("<p><label for=\"%s\">%s</label> %s</p>\n",
$field_id,
rep_specialchars_output($this->gettext('autoreplysubject')),
$input_autorespondersubject->show($settings['subject']));
// Out of office body
$field_id = 'vacation_body';
$input_autoresponderbody = new html_textarea(array('name' => '_vacation_body', 'id' => $field_id, 'cols' => 70, 'rows' => 15));
$out .= sprintf("<p><label style=\"vertical-align:top;\" for=\"%s\">%s</label> %s</p>\n",
$field_id,
rep_specialchars_output($this->gettext('autoreplymessage')),
$input_autoresponderbody->show($settings['body']));
/* We only use aliases for .forward and only if it's enabled in the config*/
if ($this->v->useAliases()) {
$size = 0;
// If there are no multiple identities, hide the button and add increase the size of the textfield
$hasMultipleIdentities = $this->v->vacation_aliases('buttoncheck');
if ($hasMultipleIdentities == '') $size = 15;
$field_id = 'vacation_aliases';
$input_autoresponderalias = new html_inputfield(array('name' => '_vacation_aliases', 'id' => $field_id, 'size' => 75+$size));
$out .= '<p>' . $this->gettext('separate_alias') . '</p>';
// Inputfield with button
$out .= sprintf('<p><label for="%s">%s</label> %s
', $field_id, rep_specialchars_output($this->gettext('aliases')),
$input_autoresponderalias->show($settings['aliases']));
if ($hasMultipleIdentities!='')
$out .= sprintf('<input type="button" id="aliaslink" class="button" value="%s"/>',
rep_specialchars_output($this->gettext('aliasesbutton')));
$out .= "</p>";
}
$out .= '</fieldset><br /><fieldset><legend>' . $this->gettext('forward') . '</legend>';
// Keep a local copy of the mail
$field_id = 'vacation_keepcopy';
$input_localcopy = new html_checkbox(array('name' => '_vacation_keepcopy', 'id' => $field_id, 'value' => 1));
$out .= sprintf("<p><label for=\"%s\">%s</label> %s</p>\n",
$field_id,
rep_specialchars_output($this->gettext('keepcopy')),
$input_localcopy->show($settings['keepcopy']));
// Information on the forward in a seperate fieldset.
if (! isset($this->inicfg['disable_forward']) || ( isset($this->inicfg['disable_forward']) && $this->inicfg['disable_forward']==false))
{
$out .= '<p>' . $this->gettext('separate_forward') . '</p>';
// Forward mail to another account
$field_id = 'vacation_forward';
$input_autoresponderforward = new html_inputfield(array('name' => '_vacation_forward', 'id' => $field_id, 'size' => 90));
$out .= sprintf("<p><label for=\"%s\">%s</label> %s</p>\n",
$field_id,
rep_specialchars_output($this->gettext('forwardingaddresses')),
$input_autoresponderforward->show($settings['forward']));
}
$out .= "</fieldset><br />\n";
$rcmail->output->add_gui_object('vacationform', 'vacation-form');
return $out;
}
}
?>