Konfiguration des Autoresponders
bernd

bernd commited on 2012-02-25 15:16:45
Zeige 4 geänderte Dateien mit 217 Einfügungen und 13 Löschungen.


git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@2209 87cf0b9e-d624-0410-a070-f6ee81989793
... ...
@@ -23,6 +23,7 @@ else {
23 23
 }
24 24
 
25 25
 
26
+$is_autoresponder = is_array($account['autoresponder']);
26 27
 $is_forward = (count($account['forwards']) > 0);
27 28
 $is_mailbox = ($account['password'] != NULL  ||  $id == 0);
28 29
 $numforwards = max(count($account['forwards']), 1);
... ...
@@ -70,6 +71,16 @@ output("<script type=\"text/javascript\">
70 71
     parent = document.getElementById('forward_config');
71 72
     parent.appendChild(DIV);
72 73
   }
74
+
75
+  function toggleDisplay(checkbox_id, item_id) 
76
+  {
77
+    if (document.getElementById(checkbox_id).checked == true) {
78
+      document.getElementById(item_id).style.display = 'block';
79
+    } else {
80
+      document.getElementById(item_id).style.display = 'none';
81
+    }
82
+  }
83
+
73 84
 </script>
74 85
 ");
75 86
 
... ...
@@ -85,27 +96,108 @@ if ($is_mailbox and ($account['password'] != ''))
85 96
 } 
86 97
 
87 98
 $form .= "
88
-    <p><input type=\"checkbox\" id=\"mailbox\" name=\"mailbox\" value=\"yes\" ".($is_mailbox ? 'checked="checked" ' : '')." /><label for=\"mailbox\">&#160;<strong>In Mailbox speichern</strong></label></p>
89
-    <p style=\"margin-left: 2em;\" id=\"mailbox_options\">Passwort für Abruf:&#160;<input type=\"password\" id=\"password\" name=\"password\" value=\"{$password_value}\" />{$password_message}</p>";
99
+    <p><input onchange=\"toggleDisplay('mailbox', 'mailbox_options')\" type=\"checkbox\" id=\"mailbox\" name=\"mailbox\" value=\"yes\" ".($is_mailbox ? 'checked="checked" ' : '')." /><label for=\"mailbox\">&#160;<strong>In Mailbox speichern</strong></label></p>
100
+    <div style=\"margin-left: 2em;".($is_mailbox ? '' : ' display: none;')."\" id=\"mailbox_options\">
101
+    <p>Passwort für Abruf:&#160;<input type=\"password\" id=\"password\" name=\"password\" value=\"{$password_value}\" />{$password_message}</p>";
90 102
 
91
-$form.= "<p style=\"margin-left: 2em;\" class=\"spamfilter_options\">Unerwünschte E-Mails (Spam, Viren) in diesem Postfach ".html_select('spamfilter_action', array("none" => 'nicht filtern', "folder" => 'in Unterordner »Spam« ablegen', "tag" => 'markieren und zustellen', "delete" => 'nicht zustellen (löschen)'), $account['spamfilter'])."</p>";
103
+$form.= "<p class=\"spamfilter_options\">Unerwünschte E-Mails (Spam, Viren) in diesem Postfach ".html_select('spamfilter_action', array("none" => 'nicht filtern', "folder" => 'in Unterordner »Spam« ablegen', "tag" => 'markieren und zustellen', "delete" => 'nicht zustellen (löschen)'), $account['spamfilter'])."</p>";
92 104
 
93 105
 $quota = config('vmail_basequota');
94 106
 if ($is_mailbox and $account['quota']) {
95 107
   $quota = $account['quota'];
96 108
 }
97 109
 
98
-$form .= "<p style=\"margin-left: 2em;\" class=\"quota_options\">Größe des Postfachs: <input type=\"text\" id=\"quota\" name=\"quota\" value=\"{$quota}\" /> MB<br /><span style=\"font-size: 80%\"><em>Hinweis: Die Differenz zwischen dem hier gesetzten Wert und dem Sockelbetrag von ".config('vmail_basequota')." MB wird vom Speicherplatz Ihres Benutzer-Kontos abgezogen.</em></span></p>";
110
+$form .= "<p class=\"quota_options\">Größe des Postfachs: <input type=\"text\" id=\"quota\" name=\"quota\" value=\"{$quota}\" /> MB<br /><span style=\"font-size: 80%\"><em>Hinweis: Die Differenz zwischen dem hier gesetzten Wert und dem Sockelbetrag von ".config('vmail_basequota')." MB wird vom Speicherplatz Ihres Benutzer-Kontos abgezogen.</em></span></p>";
99 111
 
100 112
 $quota_notify = ($account['quota_threshold'] >= 0) ? ' checked="checked" ' : '';
101 113
 $quota_threshold = ($account['quota_threshold'] >= 0) ? $account['quota_threshold'] : '';
102
-$form .= "<p style=\"margin-left: 2em;\" class=\"quota_options\"><input type=\"checkbox\" id=\"quota_notify\" name=\"quota_notify\" value=\"1\" {$quota_notify} /><label for=\"quota_notify\">Benachrichtigung wenn weniger als</label> <input type=\"text\" name=\"quota_threshold\" id=\"quota_threshold\" value=\"{$quota_threshold}\" /> MB Speicherplatz zur Verfügung stehen.</p>";
114
+$form .= "<p class=\"quota_options\"><input type=\"checkbox\" id=\"quota_notify\" name=\"quota_notify\" value=\"1\" {$quota_notify} /><label for=\"quota_notify\">Benachrichtigung wenn weniger als</label> <input type=\"text\" name=\"quota_threshold\" id=\"quota_threshold\" value=\"{$quota_threshold}\" /> MB Speicherplatz zur Verfügung stehen.</p>";
115
+
116
+$form .= "</div>";
117
+
118
+
119
+
120
+
121
+$form .= "<p><input onchange=\"toggleDisplay('autoresponder', 'autoresponder_config')\" type=\"checkbox\" id=\"autoresponder\" name=\"autoresponder\" value=\"yes\" ".($is_autoresponder ? 'checked="checked" ' : '')." /><label for=\"autoresponder\">&#160;<strong>Automatische Antwort versenden</strong></label></p>";
122
+
123
+$form .= "<div style=\"margin-left: 2em;".($is_autoresponder ? '' : ' display: none;')."\" id=\"autoresponder_config\">";
124
+
125
+$ar = $account['autoresponder'];
126
+if (! $ar) {
127
+  $ar = empty_autoresponder_config();
128
+}
129
+
130
+if ($ar['valid_until'] != NULL && $ar['valid_until'] < date('Y-m-d')) {
131
+  // Daten sind Restbestand von einem früheren Einsatz des Autoresponders
132
+  $ar['valid_from'] = NULL;
133
+  $ar['valid_until'] = NULL;
134
+}
135
+$valid_from_now_checked = ($ar['valid_from'] <= date('Y-m-d H:i:s') || $ar['valid_from'] == NULL) ? ' checked="checked"' : '';
136
+$valid_from_future_checked = ($ar['valid_from'] > date('Y-m-d H:i:s')) ? ' checked="checked"' : '';
137
+$startdate = $ar['valid_from'];
138
+if (! $startdate) {
139
+  $startdate = date('Y-m-d', time() + 1*24*60*60);
140
+}
141
+$form .= "<p><input type=\"radio\" name=\"ar_valid_from\" value=\"now\" id=\"ar_valid_from_now\"{$valid_from_now_checked} /> <label for=\"ar_valid_from_now\">Ab sofort</label><br />".
142
+  "<input type=\"radio\" name=\"ar_valid_from\" value=\"future\" id=\"ar_valid_from_future\"{$valid_from_future_checked} /> <label for=\"ar_valid_from_future\">Erst ab dem </label>".
143
+  html_datepicker("ar_valid_from", strtotime($startdate))."</p>";
144
+
145
+$valid_until_infinity_checked = ($ar['valid_until'] == NULL) ? ' checked="checked"' : '';
146
+$valid_until_date_checked = ($ar['valid_until'] != NULL) ? ' checked="checked"' : '';
147
+$enddate = $ar['valid_until'];
148
+if (! $enddate) {
149
+  $enddate = date('Y-m-d', time() + 7*24*60*60);
150
+}
151
+$form .= "<h4>Deaktivierung</h4>";
152
+$form .= "<p><input type=\"radio\" name=\"ar_valid_until\" value=\"infinity\" id=\"ar_valid_until_infinity\"{$valid_until_infinity_checked} /> <label for=\"ar_valid_until_infinity\">Unbefristet</label><br />".
153
+  "<input type=\"radio\" name=\"ar_valid_until\" value=\"date\" id=\"ar_valid_until_date\"{$valid_until_date_checked} /> <label for=\"ar_valid_until_date\">Keine Antworten mehr versenden ab dem </label>".
154
+  html_datepicker("ar_valid_until", strtotime($enddate))."</p>";
155
+
156
+
157
+$subject = $ar['subject'];
158
+if ($subject == NULL)
159
+  $subject = '';
160
+$ar_subject_default_checked = ($subject == NULL) ? ' checked="checked"' : '';
161
+$ar_subject_custom_checked = ($subject) ? ' checked="checked"' : '';
162
+$form .= "<h4>Betreffzeile der automatischen Antwort</h4>".
163
+  "<p><input type=\"radio\" name=\"ar_subject\" value=\"default\" id=\"ar_subject_default\"{$ar_subject_default_checked} /> ".
164
+  "<label for=\"ar_subject_default\">Automatisch (Re: <em>&lt;Betreff der Originalnachricht&gt;</em>)</label><br />".
165
+  "<input type=\"radio\" name=\"ar_subject\" value=\"custom\" id=\"ar_subject_custom\"{$ar_subject_custom_checked} /> ".
166
+  "<label for=\"ar_subject_custom\">Anderer Betreff:</label> <input type=\"text\" name=\"ar_subject_value\" id=\"ar_subject_value\" value=\"{$subject}\"/></p>";
167
+
168
+$message = $ar['message'];
169
+$form .= "<h4>Inhalt der automatischen Antwort</h4>".
170
+  "<p><textarea cols=\"80\" rows=\"10\" name=\"ar_message\" id=\"ar_message\">".$ar['message']."</textarea></p>";
171
+$quote = $ar['quote'];
172
+if (! $quote) 
173
+  $quote = 'none';
174
+$form .= "<p><label for=\"ar_quote\">Originalnachricht des Absenders </label>".
175
+  html_select('ar_quote', array("none" => 'nicht in Antwort einschließen', 
176
+                                "inline" => 'zitieren (max. 50 Zeilen)', 
177
+                                "attach" => 'vollständig als Anhang beifügen'), $quote)."</p>";
178
+
179
+
180
+$ar_from_default_checked = ($ar['fromname'] == NULL) ? ' checked="checked"' : '';
181
+$ar_from_custom_checked = ($ar['fromname'] != NULL) ? ' checked="checked"' : '';
182
+$fromname = $ar['fromname'];
183
+$form .= "<h4>Absender der automatischen Antwort</h4>".
184
+  "<p><input type=\"radio\" name=\"ar_from\" value=\"default\" id=\"ar_from_default\"{$ar_from_default_checked} /> <label for=\"ar_from_default\">Nur E-Mail-Adresse</label><br />".
185
+  "<input type=\"radio\" name=\"ar_from\" value=\"custom\" id=\"ar_from_custom\"{$ar_from_custom_checked} /> <label for=\"ar_from_custom\">Mit Name: </label> ".
186
+  "<input type=\"text\" name=\"ar_fromname\" id=\"ar_fromname\" value=\"{$fromname}\"/></p>";
103 187
 
104 188
 
105
-$form .= "<p><input type=\"checkbox\" id=\"forward\" name=\"forward\" value=\"yes\" ".($is_forward ? 'checked="checked" ' : '')." /><label for=\"forward\">&#160;<strong>Weiterleitung an andere E-Mail-Adressen</strong></label></p>";
106 189
 
107 190
 
108
-$form .= "<div style=\"margin-left: 2em;\" id=\"forward_config\">";
191
+$form .= '</div>';
192
+
193
+
194
+
195
+
196
+
197
+$form .= "<p><input onchange=\"toggleDisplay('forward', 'forward_config')\" type=\"checkbox\" id=\"forward\" name=\"forward\" value=\"yes\" ".($is_forward ? 'checked="checked" ' : '')." /><label for=\"forward\">&#160;<strong>Weiterleitung an andere E-Mail-Adressen</strong></label></p>";
198
+
199
+
200
+$form .= "<div style=\"margin-left: 2em;".($is_forward ? '' : ' display: none;')."\" id=\"forward_config\">";
109 201
 
110 202
 if ($is_forward)
111 203
 {
... ...
@@ -126,10 +218,10 @@ else
126 218
     </div>\n";
127 219
 }
128 220
 
129
-$form .= '</div>';
221
+$form .= '<p>[ <a href="#" onclick="moreForward();">mehr Empfänger</a> ]</p>
222
+</div>';
130 223
 
131
-$form .= '<p style="margin-left: 2em;">[ <a href="#" onclick="moreForward();">mehr Empfänger</a> ]</p>
132
-  <p><input type="submit" value="Speichern" />&#160;&#160;&#160;&#160;'.internal_link('vmail', 'Abbrechen').'</p>';
224
+$form .= '<p><input type="submit" value="Speichern" />&#160;&#160;&#160;&#160;'.internal_link('vmail', 'Abbrechen').'</p>';
133 225
 
134 226
 output(html_form('vmail_edit_mailbox', 'save', 'action=edit'.($id != 0 ? '&id='.$id : ''), $form));
135 227
 
... ...
@@ -17,18 +17,36 @@ function empty_account()
17 17
 		'spamexpire' => 7,
18 18
     'quota' => config('vmail_basequota'),
19 19
     'quota_threshold' => 20,
20
-		'forwards' => array()
20
+		'forwards' => array(),
21
+		'autoresponder' => NULL
21 22
 		);
22 23
 	return $account;
23 24
 
24 25
 }
25 26
 
27
+function empty_autoresponder_config()
28
+{
29
+  $ar = array(
30
+    'valid_from' => date( 'Y-m-d H:i:s' ),
31
+    'valid_until' => NULL,
32
+    'fromname' => NULL,
33
+    'fromaddr' => NULL,
34
+    'subject' => NULL,
35
+    'message' => 'Danke für Ihre E-Mail.
36
+Ich bin aktuell nicht im Büro und werde Ihre Nachricht erst nach meiner Rückkehr beantworten.
37
+Ihre E-Mail wird nicht weitergeleitet.',
38
+    'quote' => NULL
39
+    );
40
+  return $ar;
41
+}
42
+
43
+
26 44
 function get_account_details($id, $checkuid = true)
27 45
 {
28 46
 	$id = (int) $id;
29 47
 	$uid = (int) $_SESSION['userinfo']['uid'];
30 48
 	$uid_check = ($checkuid ? "useraccount='{$uid}' AND " : "");
31
-	$result = db_query("SELECT id, local, domain, password, spamfilter, forwards, server, quota, quota_used, quota_threshold from mail.v_vmail_accounts WHERE {$uid_check}id={$id} LIMIT 1");
49
+	$result = db_query("SELECT id, local, domain, password, spamfilter, forwards, autoresponder, server, quota, COALESCE(quota_used, 0) AS quota_used, quota_threshold from mail.v_vmail_accounts WHERE {$uid_check}id={$id} LIMIT 1");
32 50
 	if (mysql_num_rows($result) == 0)
33 51
 		system_failure('Ungültige ID oder kein eigener Account');
34 52
 	$acc = empty_account();
... ...
@@ -44,6 +62,14 @@ function get_account_details($id, $checkuid = true)
44 62
 	    array_push($acc['forwards'], array("id" => $item['id'], 'spamfilter' => $item['spamfilter'], 'destination' => $item['destination']));
45 63
 	  }
46 64
 	}
65
+  if ($acc['autoresponder'] > 0) {
66
+    $result = db_query("SELECT id, IF(valid_from IS NULL OR valid_from > NOW() OR valid_until < NOW(), 0, 1) AS active, valid_from, valid_until, fromname, fromaddr, subject, message, quote FROM mail.vmail_autoresponder WHERE account={$acc['id']}");
67
+    $item = mysql_fetch_assoc($result);
68
+    DEBUG($item);
69
+    $acc['autoresponder'] = $item;
70
+  } else {
71
+    $acc['autoresponder'] = NULL;
72
+  }
47 73
   if ($acc['quota_threshold'] === NULL) {
48 74
     $acc['quota_threshold'] = -1;
49 75
   }
... ...
@@ -188,6 +214,27 @@ function save_vmail_account($account)
188 214
     }
189 215
   }
190 216
 
217
+  if (is_array($account['autoresponder'])) {
218
+    $ar = $account['autoresponder'];
219
+    $valid_from = maybe_null($ar['valid_from']);
220
+    $valid_until = maybe_null($ar['valid_until']);
221
+    $fromname = maybe_null( mysql_real_escape_string($ar['fromname']) );
222
+    $fromaddr = NULL;
223
+    if ($ar['fromaddr']) {
224
+      $fromaddr = mysql_real_escape_string(check_emailaddr($ar['fromaddr']));
225
+    }
226
+    $fromaddr = maybe_null( $fromaddr );
227
+    $subject = maybe_null( mysql_real_escape_string($ar['subject']));
228
+    $message = mysql_real_escape_string($ar['message']);
229
+    $quote = "'inline'";
230
+    if ($ar['quote'] == 'attach')
231
+      $quote = "'attach'";
232
+    elseif ($ar['quote'] == NULL)
233
+      $quote = 'NULL';
234
+    db_query("REPLACE INTO mail.vmail_autoresponder (account, valid_from, valid_until, fromname, fromaddr, subject, message, quote) ".
235
+             "VALUES ({$account['id']}, {$valid_from}, {$valid_until}, {$fromname}, {$fromaddr}, {$subject}, '{$message}', {$quote})");
236
+  }
237
+    
191 238
   $password='NULL';
192 239
   if ($account['password'] != '')
193 240
   {
... ...
@@ -311,7 +358,7 @@ Wussten Sie schon, dass Sie auf mehrere Arten Ihre E-Mails abrufen können?
311 358
   }
312 359
 
313 360
   // Update Mail-Quota-Cache
314
-  $result = db_query("SELECT useraccount, server, SUM(quota-(SELECT value FROM misc.config WHERE `key`='vmail_basequota')) AS quota, SUM(GREATEST(quota_used-(SELECT value FROM misc.config WHERE `key`='vmail_basequota'), 0)) AS used FROM mail.v_vmail_accounts GROUP BY useraccount, server");
361
+  $result = db_query("SELECT useraccount, server, SUM(quota-(SELECT value FROM misc.config WHERE `key`='vmail_basequota')) AS quota, SUM(GREATEST(quota_used-(SELECT value FROM misc.config WHERE `key`='vmail_basequota'), 0)) AS used FROM mail.v_vmail_accounts WHERE useraccount=".$uid." GROUP BY useraccount, server");
315 362
   while ($line = mysql_fetch_assoc($result)) {
316 363
     if ($line['quota'] !== NULL) {
317 364
       db_query("REPLACE INTO mail.vmailquota (uid, server, quota, used) VALUES ('{$line['useraccount']}', '{$line['server']}', '{$line['quota']}', '{$line['used']}')");
... ...
@@ -41,6 +41,54 @@ if ($_GET['action'] == 'edit')
41 41
     $account['quota_threshold'] = $_POST['quota_threshold'];
42 42
   }
43 43
 
44
+
45
+
46
+  $ar = empty_autoresponder_config();
47
+  $valid_from_date = time();
48
+  $valid_until_date = NULL;
49
+  if (isset($_POST['ar_valid_from_day']) && isset($_POST['ar_valid_from_month']) && isset($_POST['ar_valid_from_year'])) {
50
+    $valid_from_date = strtotime($_POST['ar_valid_from_year'].'-'.$_POST['ar_valid_from_month'].'-'.$_POST['ar_valid_from_day']);
51
+  }
52
+  if (isset($_POST['ar_valid_until_day']) && isset($_POST['ar_valid_until_month']) && isset($_POST['ar_valid_until_year'])) {
53
+    $valid_until_date = strtotime($_POST['ar_valid_until_year'].'-'.$_POST['ar_valid_until_month'].'-'.$_POST['ar_valid_until_day']);
54
+  }
55
+  if (isset($_POST['ar_valid_from']) && ($_POST['ar_valid_from'] == 'now' || $valid_from_date < time())) {
56
+    $valid_from_date = time();
57
+  }
58
+  $ar['valid_from'] = date('Y-m-d', $valid_from_date);
59
+  $ar['valid_until'] = date('Y-m-d', $valid_until_date);
60
+  if (!isset($_POST['autoresponder']) || $_POST['autoresponder'] != 'yes') {
61
+    $ar['valid_from'] = NULL;
62
+  }
63
+  if (isset($_POST['ar_valid_until']) && ($_POST['ar_valid_until'] == 'infinity' || $valid_until_date < time())) {
64
+    $ar['valid_until'] = NULL;
65
+  }
66
+
67
+  if (isset($_POST['ar_subject']) && $_POST['ar_subject'] == 'custom' && isset($_POST['ar_subject_value']) && chop($_POST['ar_subject_value']) != '') {
68
+    $ar['subject'] = filter_input_general( chop($_POST['ar_subject_value']) );
69
+  }
70
+
71
+  if (isset($_POST['ar_message'])) {
72
+    $ar['message'] = filter_input_general( $_POST['ar_message'] );
73
+  }
74
+
75
+  if (isset($_POST['ar_quote'])) {
76
+    if ($_POST['ar_quote'] == 'inline') {
77
+      $ar['quote'] = 'inline';
78
+    }
79
+    if ($_POST['ar_quote'] == 'attach') {
80
+      $ar['quote'] = 'attach';
81
+    }
82
+  }
83
+
84
+  if (isset($_POST['ar_from']) && $_POST['ar_from'] == 'custom' && isset($_POST['ar_fromname'])) {
85
+    $ar['fromname'] = filter_input_general( $_POST['ar_fromname']);
86
+  }
87
+    
88
+  $account['autoresponder'] = $ar;
89
+
90
+
91
+
44 92
   if (isset($_POST['forward']) && $_POST['forward'] == 'yes')
45 93
   {
46 94
     $num = 1;
... ...
@@ -80,6 +80,23 @@ if (count($sorted_by_domains) > 0)
80 80
 	        }
81 81
 	        array_push($actions, "Ablegen in Mailbox ({$spam})<br />".$quotachart);
82 82
 	      }
83
+        if ($acc['autoresponder']) {
84
+            $now = date( 'Y-m-d H:i:s' );
85
+            $valid_from = $acc['autoresponder']['valid_from'];
86
+            $valid_until = $acc['autoresponder']['valid_until'];
87
+            if ($valid_from == NULL) {
88
+              // Autoresponder abgeschaltet
89
+              array_push($actions, "<strike>Automatische Antwort versenden</strike> (Abgeschaltet)");
90
+            } elseif ($valid_from > $now) {
91
+              array_push($actions, "<strike>Automatische Antwort versenden</strike> (Wird aktiviert am {$valid_from})");
92
+            } elseif ($valid_until == NULL) {
93
+              array_push($actions, "Automatische Antwort versenden (Unbefristet)");
94
+            } elseif ($valid_until > $now) {
95
+              array_push($actions, "Automatische Antwort versenden (Wird deaktiviert am {$valid_until})");
96
+            } elseif ($valid_until < $now) {
97
+              array_push($actions, "<strike>Automatische Antwort versenden</strike> (Automatisch abgeschaltet seit {$valid_until})");
98
+            }
99
+        }
83 100
 	      foreach ($acc['forwards'] AS $fwd)
84 101
 	      {
85 102
 	      	$spam = 'ohne Spamfilter';
86 103