VMail-User können ihre Einstellungen selbst vornehmen und bekommen eine individuelle Startseite mit den Einstellungen.
bernd

bernd commited on 2012-02-29 13:26:13
Zeige 9 geänderte Dateien mit 166 Einfügungen und 14 Löschungen.


git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@2214 87cf0b9e-d624-0410-a070-f6ee81989793
... ...
@@ -12,7 +12,7 @@ title("Passwort ändern");
12 12
 
13 13
 
14 14
 
15
-if ($_POST['password1'] != '')
15
+if (isset($_POST['password1']) && $_POST['password1'] != '')
16 16
 {
17 17
   $accname = $_SESSION['mailaccount'];
18 18
   check_form_token('email_chpass');
... ...
@@ -6,7 +6,7 @@ require_once('inc/security.php');
6 6
 require_once('vmail.php');
7 7
 
8 8
 $section = 'email_vmail';
9
-require_role(ROLE_SYSTEMUSER);
9
+require_role(array(ROLE_SYSTEMUSER, ROLE_VMAIL_ACCOUNT));
10 10
 
11 11
 $account = empty_account();
12 12
 $id = (isset($_GET['id']) ? (int) $_GET['id'] : 0);
... ...
@@ -14,13 +14,26 @@ $id = (isset($_GET['id']) ? (int) $_GET['id'] : 0);
14 14
 if ($id != 0)
15 15
   $account = get_account_details($id);
16 16
 
17
+$accountlogin = false;
18
+if ($_SESSION['role'] == ROLE_VMAIL_ACCOUNT) {
19
+  $id = get_vmail_id_by_emailaddr($_SESSION['mailaccount']);
20
+  $account = get_account_details($id, false);
21
+  $accountlogin = true;
22
+  $accountname = filter_input_general($_SESSION['mailaccount']);
23
+}
24
+
25
+
17 26
 DEBUG($account);
18 27
 if ($id == 0) {
19 28
   title("E-Mail-Adresse anlegen");
20 29
 }
21 30
 else {
31
+  if ($accountlogin) {
32
+    title("Einstellungen für {$accountname}");
33
+  } else {
22 34
     title("E-Mail-Adresse bearbeiten");
23 35
   }
36
+}
24 37
 
25 38
 
26 39
 $is_autoresponder = is_array($account['autoresponder']) && $account['autoresponder']['valid_from'] != NULL;
... ...
@@ -84,7 +97,12 @@ output("<script type=\"text/javascript\">
84 97
 </script>
85 98
 ");
86 99
 
87
-$form = "
100
+$form = '';
101
+
102
+if ($accountlogin) {
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>";
104
+} else {
105
+  $form .= "
88 106
     <p><strong>E-Mail-Adresse:</strong>&#160;<input type=\"text\" name=\"local\" id=\"local\" size=\"10\" value=\"{$account['local']}\" /><strong style=\"font-size: 1.5em;\">&#160;@&#160;</strong>".domainselect($account['domain'])."</p>";
89 107
 
90 108
   $password_message = '';
... ...
@@ -114,7 +131,7 @@ $quota_threshold = ($account['quota_threshold'] >= 0) ? $account['quota_threshol
114 131
   $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 132
 
116 133
   $form .= "</div>";
117
-
134
+}
118 135
 
119 136
 
120 137
 
... ...
@@ -41,11 +41,23 @@ Ihre E-Mail wird nicht weitergeleitet.',
41 41
 }
42 42
 
43 43
 
44
+function get_vmail_id_by_emailaddr($emailaddr) 
45
+{
46
+  $emailaddr = mysql_real_escape_string( $emailaddr );
47
+  $result = db_query("SELECT id FROM mail.v_vmail_accounts WHERE CONCAT(local, '@', domainname) = '{$emailaddr}'");
48
+  $entry = mysql_fetch_assoc($result);
49
+  return (int) $entry['id'];
50
+}
51
+
44 52
 function get_account_details($id, $checkuid = true)
45 53
 {
46 54
 	$id = (int) $id;
55
+  $uid_check = '';
56
+  DEBUG("checkuid: ".$checkuid);
57
+  if ($checkuid) {
47 58
     $uid = (int) $_SESSION['userinfo']['uid'];
48
-	$uid_check = ($checkuid ? "useraccount='{$uid}' AND " : "");
59
+    $uid_check = "useraccount='{$uid}' AND ";
60
+  }
49 61
   $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");
50 62
 	if (mysql_num_rows($result) == 0)
51 63
 		system_failure('Ungültige ID oder kein eigener Account');
... ...
@@ -160,12 +172,12 @@ function get_max_mailboxquota($server, $oldquota) {
160 172
 
161 173
 function save_vmail_account($account)
162 174
 {
163
-  $uid = (int) $_SESSION['userinfo']['uid'];
175
+  $accountlogin = ($_SESSION['role'] == ROLE_VMAIL_ACCOUNT);
164 176
   $id = $account['id'];
165 177
   if ($id != NULL)
166 178
   {
167 179
     $id = (int) $id;
168
-    $oldaccount = get_account_details($id);
180
+    $oldaccount = get_account_details($id, !$accountlogin);
169 181
     // Erzeugt einen system_error() wenn ID ungültig
170 182
   }
171 183
   // Ab hier ist $id sicher, entweder NULL oder eine gültige ID des aktuellen users
... ...
@@ -174,6 +186,16 @@ function save_vmail_account($account)
174 186
   if ($id === NULL) {
175 187
     $newaccount = true;
176 188
   }
189
+
190
+  if ($accountlogin) {
191
+    if ($account['domain'] != $oldaccount['domain'])
192
+      system_failure('Sie können die E-Mail-Adresse nicht ändern!');
193
+    if ($account['local'] != $oldaccount['local'])
194
+      system_failure('Sie können die E-Mail-Adresse nicht ändern!');
195
+    if ($account['quota'] != $oldaccount['quota'])
196
+      system_failure('Sie können Ihren eigenen Speicherplatz nicht verändern.');
197
+  } else {
198
+  
177 199
     $account['local'] = filter_input_username($account['local']);
178 200
     if ($account['local'] == '')
179 201
     {
... ...
@@ -200,6 +222,7 @@ function save_vmail_account($account)
200 222
       system_failure('Bitte wählen Sie eine Ihrer Domains aus!');
201 223
       return false;
202 224
     }
225
+  }
203 226
   
204 227
   $forwards = array();
205 228
   if (count($account['forwards']) > 0) 
... ...
@@ -214,6 +237,10 @@ function save_vmail_account($account)
214 237
     }
215 238
   }
216 239
 
240
+  if ($accountlogin) {
241
+    $password = NULL; 
242
+    $set_password = false;
243
+  } else {
217 244
     $password='NULL';
218 245
     if ($account['password'] != '')
219 246
     {
... ...
@@ -229,6 +256,7 @@ function save_vmail_account($account)
229 256
     $set_password = ($id == NULL || $password != 'NULL');
230 257
     if ($account['password'] === NULL)
231 258
       $set_password=true;
259
+  }  
232 260
 
233 261
   $spam = 'NULL';
234 262
   switch ($account['spamfilter'])
... ...
@@ -244,6 +272,7 @@ function save_vmail_account($account)
244 272
       break;
245 273
   }
246 274
   
275
+  if (!$accountlogin) {
247 276
     $free = config('vmail_basequota');
248 277
     if ($newaccount) {
249 278
       // Neues Postfach
... ...
@@ -259,6 +288,7 @@ function save_vmail_account($account)
259 288
     }
260 289
   
261 290
     $account['quota'] = $newquota;
291
+  }  
262 292
 
263 293
   if ($account['quota_threshold'] == -1) {
264 294
     $account['quota_threshold'] = 'NULL';
... ...
@@ -361,12 +391,15 @@ Wussten Sie schon, dass Sie auf mehrere Arten Ihre E-Mails abrufen können?
361 391
   }
362 392
 
363 393
   // Update Mail-Quota-Cache
394
+  if ($_SESSION['role'] == ROLE_SYSTEMUSER) {
395
+    $uid = (int) $_SESSION['userinfo']['uid'];
364 396
     $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");
365 397
     while ($line = mysql_fetch_assoc($result)) {
366 398
       if ($line['quota'] !== NULL) {
367 399
         db_query("REPLACE INTO mail.vmailquota (uid, server, quota, used) VALUES ('{$line['useraccount']}', '{$line['server']}', '{$line['quota']}', '{$line['used']}')");
368 400
       }
369 401
     }
402
+  }
370 403
 
371 404
   return true;
372 405
 }
... ...
@@ -8,6 +8,10 @@ require_once('include/hasaccount.php');
8 8
 if ($role & ROLE_SYSTEMUSER) {
9 9
   $menu["email_vmail"] = array("label" => "E-Mail", "file" => "vmail", "weight" => 3);
10 10
 }
11
+if ($role & ROLE_VMAIL_ACCOUNT)
12
+{
13
+  $menu['email_edit'] = array("label" => "Einstellungen", "file" => "edit", "weight" => 10);
14
+}
11 15
 if ($role & (ROLE_VMAIL_ACCOUNT | ROLE_MAILACCOUNT))
12 16
 {
13 17
   $menu['email_chpass'] = array("label" => "Passwort ändern", "file" => "chpass", "weight" => 15);
... ...
@@ -4,7 +4,7 @@ require_once('session/start.php');
4 4
 
5 5
 require_once('vmail.php');
6 6
 
7
-require_role(ROLE_SYSTEMUSER);
7
+require_role(array(ROLE_SYSTEMUSER, ROLE_VMAIL_ACCOUNT));
8 8
 
9 9
 require_once("inc/debug.php");
10 10
 global $debugmode;
... ...
@@ -13,6 +13,14 @@ global $debugmode;
13 13
 if ($_GET['action'] == 'edit')
14 14
 {
15 15
   check_form_token('vmail_edit_mailbox');
16
+  $accountlogin = ($_SESSION['role'] == ROLE_VMAIL_ACCOUNT);
17
+
18
+  if ($accountlogin) {
19
+    $id = get_vmail_id_by_emailaddr($_SESSION['mailaccount']);
20
+    $account = get_account_details($id, false);
21
+    // Leere das, sonst werden die vervielfacht
22
+    $account['forwards'] = array();
23
+  } else {
16 24
     $id = (int) $_GET['id'];
17 25
   
18 26
     $account = empty_account();
... ...
@@ -21,7 +29,6 @@ if ($_GET['action'] == 'edit')
21 29
       $account['id'] = $id;
22 30
     $account['local'] = $_POST['local'];
23 31
     $account['domain'] = (int) $_POST['domain'];
24
-  $account['spamfilter'] = $_POST['spamfilter_action'];
25 32
     $account['password'] = $_POST['password'];
26 33
     if (($account['password'] == '') && ($_POST['mailbox'] == 'yes'))
27 34
       system_failure("Sie haben ein leeres Passwort eingegeben!");
... ...
@@ -41,6 +48,8 @@ if ($_GET['action'] == 'edit')
41 48
       $account['quota_threshold'] = $_POST['quota_threshold'];
42 49
     }
43 50
 
51
+  }
52
+  $account['spamfilter'] = $_POST['spamfilter_action'];
44 53
 
45 54
 
46 55
   $ar = empty_autoresponder_config();
... ...
@@ -113,8 +122,12 @@ if ($_GET['action'] == 'edit')
113 122
   save_vmail_account($account);
114 123
 
115 124
   if (! ($debugmode || we_have_an_error()))
125
+    if ($accountlogin) {
126
+      header('Location: ../index/index');
127
+    } else {
116 128
       header('Location: vmail');
117 129
     }
130
+}
118 131
 elseif ($_GET['action'] == 'delete')
119 132
 {
120 133
   $title = "E-mail-Adresse löschen";
... ...
@@ -0,0 +1,70 @@
1
+<?php
2
+
3
+require_once('inc/base.php');
4
+require_once('inc/icons.php');
5
+require_once('inc/security.php');
6
+require_role(ROLE_VMAIL_ACCOUNT);
7
+
8
+require_once('include/vmail.php');
9
+
10
+$id = get_vmail_id_by_emailaddr($_SESSION['mailaccount']);
11
+$acc = get_account_details($id, false);
12
+$actions = array();
13
+DEBUG($acc);
14
+
15
+$content = '<h3>Aktueller Speicherplatzverbrauch</h3>';
16
+
17
+$percent = round(( $acc["quota_used"] / $acc["quota"] ) * 100 );
18
+$color = ( $percent > 95 ? 'red' : ($percent > 75 ? "yellow" : "green" ));
19
+$width = 2 * min($percent, 100);
20
+$content .= "<div><div style=\"margin: 2px 0; padding: 0; width: 200px; border: 1px solid black;\"><div style=\"font-size: 1px; background-color: {$color}; height: 10px; width: {$width}px; margin: 0; padding: 0;\">&#160;</div></div> {$acc['quota_used']} MB von {$acc['quota']} MB belegt</div>";
21
+
22
+$content .= '<h3>Einstellungen</h3>
23
+<p>Eingehende E-Mails für Ihre Adresse werden wie folgt verarbeitet:</p>';
24
+
25
+$spam = 'ohne Spamfilter';
26
+switch ($acc['spamfilter'])
27
+{
28
+  case 'folder':  $spam = 'Spam in Unterordner';
29
+    break;
30
+	case 'tag':	$spam = 'Spam markieren';
31
+		break;
32
+	case 'delete':	$spam = 'Spam nicht zustellen';
33
+  	break;
34
+}
35
+$content .= '<p>'.other_icon('go.png')." Ablegen in Ihrer Mailbox ({$spam})</p>";
36
+
37
+
38
+if ($acc['autoresponder']) {
39
+  $now = date( 'Y-m-d H:i:s' );
40
+  $valid_from = $acc['autoresponder']['valid_from'];
41
+  $valid_until = $acc['autoresponder']['valid_until'];
42
+  if ($valid_from == NULL) {
43
+    // Autoresponder abgeschaltet
44
+    //$content .= '<p>'.other_icon('go.png')." Es wird keine automatische Antwort versendet</p>"; 
45
+  } elseif ($valid_from > $now) {
46
+    $content .= '<p>'.other_icon('go.png')." Es wird ab dem {$valid_from} eine automatische Antwort versendet</p>"; 
47
+  } elseif ($valid_until == NULL) {
48
+    $content .= '<p>'.other_icon('go.png')." Es wird eine automatische Antwort versendet</p>"; 
49
+  } elseif ($valid_until > $now) {
50
+    $content .= '<p>'.other_icon('go.png')." Es wird eine automatische Antwort versendet, jedoch nicht mehr ab dem {$valid_until}</p>"; 
51
+  } elseif ($valid_until < $now) {
52
+    $content .= '<p>'.other_icon('go.png')." Es wird seit dem {$valid_until} keine automatische Antwort mehr versendet</p>"; 
53
+  }
54
+}
55
+
56
+foreach ($acc['forwards'] AS $fwd)
57
+{
58
+ 	$spam = 'ohne Spamfilter';
59
+  switch ($fwd['spamfilter'])
60
+	{
61
+	  case 'tag':	$spam = 'Spam markieren';
62
+			break;
63
+		case 'delete':	$spam = 'Spam nicht zustellen';
64
+			break;
65
+	}
66
+	$fwd['destination'] = filter_input_general($fwd['destination']);
67
+  $content .= '<p>'.other_icon('go.png')." Weiterleitung an <strong>{$fwd['destination']}</strong> ({$spam})</p>"; 
68
+}
69
+
70
+?>
... ...
@@ -60,6 +60,10 @@ if (have_module('email') && ($_SESSION['role'] & ROLE_MAILACCOUNT || $_SESSION['
60 60
   output("<div class=\"block\">".internal_link("../email/chpass", "<img src=\"{$prefix}images/pwchange.png\" alt=\"\" /> Passwort ändern ")."</div>");
61 61
 }
62 62
 
63
+if (have_module('email') && ($_SESSION['role'] & ROLE_VMAIL_ACCOUNT)) {
64
+  output("<div class=\"block\">".internal_link("../email/edit", "<img src=\"{$prefix}images/cog.png\" alt=\"\" /> E-Mail-Einstellungen ")."</div>");
65
+}
66
+
63 67
 if ($_SESSION['role'] & ROLE_CUSTOMER || $_SESSION['role'] & ROLE_SYSTEMUSER) {
64 68
   output("<div class=\"block\">".internal_link("chpass", "<img src=\"{$prefix}images/pwchange.png\" alt=\"\" /> Passwort ändern ")."</div>");
65 69
 }
... ...
@@ -93,4 +97,10 @@ if (have_module('jabber') && $_SESSION['role'] & ROLE_CUSTOMER) {
93 97
 
94 98
 output("</div>");
95 99
 
100
+if (have_module('email') && $_SESSION['role'] & ROLE_VMAIL_ACCOUNT) {
101
+  include('modules/email/vmailoverview.php');
102
+  output("<div class=\"vmailoverview\">".$content."</div>");
103
+}
104
+
105
+
96 106
 ?>
... ...
@@ -228,12 +228,16 @@ div.content {
228 228
 }
229 229
 /*        overflow: hidden; */
230 230
 
231
-div.overview {
231
+div.vmailoverview {
232
+}
233
+
234
+.overview {
232 235
   margin: 2em;
236
+  overflow: auto;
237
+  width: 100%;
233 238
   max-width: 50em;
234 239
 }
235
-
236
-div.overview div.block {
240
+.overview div.block {
237 241
   float: left;
238 242
   margin: 1em;
239 243
   padding: 1em;
... ...
@@ -244,7 +248,7 @@ div.overview div.block {
244 248
   background-color: #eee;
245 249
 }
246 250
 
247
-div.overview div.block img {
251
+.overview div.block img {
248 252
   display: block;
249 253
   margin: 0 auto;
250 254
   margin-bottom: 1em;
... ...
@@ -252,7 +256,7 @@ div.overview div.block img {
252 256
 }
253 257
 
254 258
 /*
255
-div.overview div.block a {
259
+.overview div.block a {
256 260
   color: #000;
257 261
 }
258 262
 */
259 263