Zwischenversion
Bernd Wurst

Bernd Wurst commited on 2017-02-18 18:02:07
Zeige 7 geänderte Dateien mit 366 Einfügungen und 2 Löschungen.

... ...
@@ -70,7 +70,7 @@ function invoice_items($id)
70 70
 function upcoming_items()
71 71
 {
72 72
   $c = (int) $_SESSION['customerinfo']['customerno'];
73
-  $result = db_query("SELECT anzahl, beschreibung, startdatum, enddatum, betrag, einheit, brutto, mwst FROM kundendaten.upcoming_items WHERE kunde=? ORDER BY startdatum ASC", array($c));
73
+  $result = db_query("SELECT quelle, id, anzahl, beschreibung, startdatum, enddatum, betrag, einheit, brutto, mwst FROM kundendaten.upcoming_items WHERE kunde=? ORDER BY startdatum ASC", array($c));
74 74
   $ret = array();
75 75
   while($line = $result->fetch())
76 76
 	  array_push($ret, $line);
... ...
@@ -290,4 +290,67 @@ function find_iban($blz, $kto)
290 290
 }
291 291
 
292 292
 
293
+function get_customerquota()
294
+{
295
+  $cid = (int) $_SESSION['customerinfo']['customerno'];
296
+  $result = db_query("SELECT quota FROM system.customerquota WHERE cid=:cid", array(":cid" => $cid));
297
+  $data = $result->fetch();
298
+  return $data["quota"];
299
+}
300
+
301
+function save_more_storage($items, $storage) {
302
+  $cid = (int) $_SESSION['customerinfo']['customerno'];
303
+  
304
+  $queries = array();  
305
+
306
+  if ($storage < 1024 || $storage > 10240) {
307
+    input_error('Speicherplatz nicht im erwarteten Bereich');
308
+  }
309
+  $oldcustomerquota = get_customerquota();
310
+  if ($oldcustomerquota > 20480) {
311
+    # Über 20 GB soll die Automatik nichts machen
312
+    system_failure("Ihr Speicherplatz kann über diese Funktion nicht weiter erhöht werden. Bitte wenden Sie sich an die Administratoren.");
313
+  }
314
+  $result = db_query("SELECT quota FROM system.customerquota WHERE lastchange > CURDATE()");
315
+  if ($result->rowcount() > 0) {
316
+    system_failure("Ihr Speicherplatz wurde heute bereits verändert. Sie können dies nur einmal am Tag machen.");
317
+  }
318
+
319
+  $queries[] = array("UPDATE system.customerquota SET quota=quota+:storage WHERE cid=:cid", array(":storage" => $storage, ":cid" => $cid));
320
+
321
+  foreach ($items as $data) {
322
+    if ($data['anzahl'] == 0) {
323
+      continue;
324
+    }
325
+    $data['kunde'] = $cid;
326
+    $data['notizen'] = 'Bestellt via Webinterface';
327
+    if (!isset($data['anzahl']) ||
328
+        !isset($data['beschreibung']) ||
329
+        !isset($data['datum']) ||
330
+        !array_key_exists('kuendigungsdatum', $data) ||
331
+        !isset($data['betrag']) ||
332
+        !isset($data['monate'])) {
333
+      DEBUG($data);
334
+      input_error("Ungültige Daten");
335
+      return;
336
+    }
337
+ 
338
+    $param = array();
339
+    foreach ($data as $k => $v) {
340
+      $param[':'.$k] = $v;
341
+    }
342
+
343
+    $queries[] = array("INSERT INTO kundendaten.leistungen (kunde,periodisch,beschreibung,datum,kuendigungsdatum,betrag,brutto,monate,anzahl,notizen) VALUES ".
344
+                       "(:kunde,1,:beschreibung,:datum,:kuendigungsdatum,:betrag,:brutto,:monate,:anzahl,:notizen)", $param);
345
+  }
346
+
347
+  if (count($queries) < 2) {
348
+    system_failure("irgendwas stimmt jetzt nicht");
349
+  }
350
+  
351
+  foreach ($queries as $q) {
352
+    db_query($q[0], $q[1]);
353
+  }
354
+}
355
+
293 356
 ?>
... ...
@@ -0,0 +1,8 @@
1
+$(function() {
2
+  $(".buttonset input[type=submit]").remove();
3
+  $(".buttonset").buttonset();
4
+  
5
+  $(".buttonset input").click( function() {
6
+    $(this).closest("form").submit();
7
+    });
8
+  });
... ...
@@ -0,0 +1,168 @@
1
+<?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2014 by schokokeks.org Hosting, namely
6
+  Bernd Wurst <bernd@schokokeks.org>
7
+  Hanno Böck <hanno@schokokeks.org>
8
+
9
+To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10
+
11
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12
+http://creativecommons.org/publicdomain/zero/1.0/
13
+
14
+Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15
+*/
16
+
17
+require_once('session/start.php');
18
+require_once('inc/icons.php');
19
+require_once('inc/jquery.php');
20
+javascript('more_storage.js');
21
+
22
+require_once('invoice.php');
23
+
24
+require_role(ROLE_CUSTOMER);
25
+
26
+$_SESSION['more_storage_section'] = 'invoice_current';
27
+if (isset($_GET['section'])) {
28
+  $_SESSION['more_storage_section'] = $_GET['section'];
29
+}
30
+$section = $_SESSION['more_storage_section'];
31
+
32
+title('Zusätzlichen Speicherplatz buchen');
33
+
34
+$upcoming = upcoming_items();
35
+$hosting = NULL;
36
+foreach ($upcoming as $item) {
37
+  if ($item['quelle'] == 'hosting') {
38
+    $hosting = $item;
39
+    break;
40
+  }
41
+}
42
+if (!$hosting) {
43
+  system_failure("Die Abrechnung für das normale Hosting konnte nicht ermittelt werden. Daher können Sie diese Funktion leider nicht benutzen. Wenden Sie sich bitte an die Administratoren um mehr Speicherplatz zu bestellen.");
44
+}
45
+if ($hosting['brutto'] == 0) {
46
+  system_failure("Ihr Konto wird mit Nettopreisen abgerechnet. Bitte wenden Sie sich an den Support.");
47
+}
48
+
49
+$customerquota = get_customerquota();
50
+
51
+$count = 1024;
52
+if (isset($_POST['count']) && (int) $_POST['count'] > 0) {
53
+  $count = (int) $_POST['count'];
54
+}
55
+
56
+output("<p>Ihr aktuell zugeteilter Speicherplatz (ggf. inklusive Mitbenutzer) beträgt <strong>${customerquota} MB</strong>. Sie können weiteren Speicherplatz hinzubuchen.</p>");
57
+
58
+$checked = '';
59
+if ($count == 1024) {
60
+  $checked = 'checked="checked" ';
61
+}
62
+$form = '<p class="buttonset"><input '.$checked.'type="radio" name="count" value="1024" id="count-1" /><label for="count-1">Zusätzlich <strong>1 GB</strong>, insgesamt also '.($customerquota+1024).' MB</label>';
63
+if ($count == 2048) {
64
+  $checked = 'checked="checked" ';
65
+} else {
66
+  $checked = '';
67
+}
68
+$form .= '<input '.$checked.'type="radio" name="count" value="2048" id="count-2" /><label for="count-2">Zusätzlich <strong>2 GB</strong>, insgesamt also '.($customerquota+2048).' MB</label>';
69
+if ($count == 5120) {
70
+  $checked = 'checked="checked" ';
71
+} else {
72
+  $checked = '';
73
+}
74
+$form .= '<input '.$checked.'type="radio" name="count" value="5120" id="count-5" /><label for="count-5">Zusätzlich <strong>5 GB</strong>, insgesamt also '.($customerquota+5120).' MB</label>';
75
+
76
+$form .= '<input type="submit" value="Wählen" /></p>';
77
+output(html_form("more_storage_selection", "more_storage", "", $form));
78
+
79
+$new_item = $hosting;
80
+unset($new_item['quelle']);
81
+unset($new_item['id']);
82
+$gb = $count/1024;
83
+$new_item['beschreibung'] = 'Erweiterung Speicherplatz um '.$gb.' GB (Auftrag vom '.date('d.m.Y').')';
84
+$new_item['betrag'] = $gb;
85
+
86
+$startdate = $new_item['startdatum'];
87
+$diff = date_diff(date_create("now"), date_create($startdate), true);
88
+DEBUG('date_diff(now, '.$startdate.') => '.$diff->format('%y Year %m Month %d Day'));
89
+$months = $diff->format("%m");
90
+
91
+$stub_startdate = date_create($startdate);
92
+date_sub($stub_startdate, date_interval_create_from_date_string($months.' months'));
93
+$stub_enddate = date_create($startdate);
94
+date_sub($stub_enddate, date_interval_create_from_date_string('1 day'));
95
+
96
+$stub = $new_item;
97
+$stub['startdatum'] = date_format($stub_startdate, 'Y-m-d');
98
+$stub['enddatum'] = date_format($stub_enddate, 'Y-m-d');
99
+$stub['anzahl'] = $months;
100
+$stub['monate'] = $months;
101
+
102
+$items = array();
103
+$items[] = $stub;
104
+$items[] = $new_item;
105
+
106
+output('<p>Die Abrechnung erfolgt mit Ihrer nächsten turnusgemäßen Abrechnung und wird mit folgenden Rechnungsposten vorgemerkt.</p>');
107
+output('<table><tr><th>Anzahl</th><th>Beschreibung</th><th>Zeitraum</th><th>Einzelpreis</th><th>Gesamtbetrag</th></tr>');
108
+$counter = 0;
109
+foreach($items AS $item)
110
+{
111
+  $counter++;
112
+  if ($counter == 1 && ($item['anzahl'] > 0)) {
113
+    output("<tr><td colspan=\"5\" style=\"border: none;\"><em>Einmaliger Posten:</em></td></tr>");
114
+  }
115
+  elseif ($counter == 2) {
116
+    output("<tr><td colspan=\"5\" style=\"border: none;\"><em>Künftiger regelmäßiger Posten:</em></td></tr>");
117
+  }
118
+  if ($item['anzahl'] == 0) {
119
+    continue;
120
+  }
121
+	$desc = $item['startdatum'];
122
+	if ($item['enddatum'] != NULL)
123
+		$desc = $item['startdatum'].' - '.$item['enddatum'];
124
+	$epreis = $item['betrag'];
125
+	if ($item['brutto'] == 0)
126
+		$epreis = $epreis * (1 + ($item['mwst'] / 100));
127
+	$gesamt = round($epreis * $item['anzahl'], 2);
128
+	$epreis = round($epreis, 2);
129
+  $einheit = ($item['einheit'] ? $item['einheit'] : '');
130
+	output("<tr><td>{$item['anzahl']} {$einheit}</td>");
131
+  output("<td>{$item['beschreibung']}</td><td>{$desc}</td>");
132
+	output("<td>{$epreis} €</td><td>{$gesamt} €</td></tr>\n");
133
+}
134
+output('</table>');
135
+
136
+output('<p>Wir behalten uns vor, diese Rechnungsposten mit anderen sinngleichen Posten zusammen zu führen.</p>');
137
+
138
+$handle = bin2hex(random_bytes(10));
139
+
140
+$_SESSION['more_storage_handle'] = $handle;
141
+$_SESSION['more_storage_items'] = $items;
142
+$_SESSION['more_storage_count'] = $count;
143
+
144
+$form = '';
145
+
146
+if (have_module('systemuser')) {
147
+  include('modules/systemuser/include/useraccounts.php');
148
+  $useraccounts = list_useraccounts();
149
+
150
+  if (count($useraccounts) == 1) {
151
+    $form .= '<input type="hidden" name="more_storage_user" value="'.$useraccounts[0]['uid'].'" />';
152
+  } else {
153
+    $choices = array('' => 'Nicht zuweisen');
154
+    foreach ($useraccounts as $u) {
155
+      $choices[$u['uid']] = "Benutzer ${u['username']} vergrößern";
156
+    }
157
+    $form .= '<p>Wie soll der zusätzliche Speicherplatz verwendet werden?</p><p>'.html_select('more_storage_user', $choices, $_SESSION['userinfo']['uid']).'</p>';
158
+  }
159
+}
160
+
161
+$form .= '<p>
162
+<input type="hidden" name="more_storage_handle" value="'.$handle.'" />
163
+<input type="submit" value="Jetzt zahlungspflichtig bestellen" /><p>';
164
+
165
+
166
+output(html_form("more_storage", "more_storage_save", "action=more_storage", $form));
167
+
168
+?>
... ...
@@ -0,0 +1,109 @@
1
+<?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2014 by schokokeks.org Hosting, namely
6
+  Bernd Wurst <bernd@schokokeks.org>
7
+  Hanno Böck <hanno@schokokeks.org>
8
+
9
+To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10
+
11
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12
+http://creativecommons.org/publicdomain/zero/1.0/
13
+
14
+Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15
+*/
16
+
17
+require_once('session/start.php');
18
+
19
+require_once('invoice.php');
20
+
21
+require_role(ROLE_CUSTOMER);
22
+
23
+$section = $_SESSION['more_storage_section'];
24
+
25
+title('Zusätzlichen Speicherplatz buchen');
26
+
27
+
28
+check_form_token('more_storage');
29
+
30
+$valid = false;
31
+if (isset($_POST['more_storage_handle']) && isset($_SESSION['more_storage_handle']) &&
32
+  $_POST['more_storage_handle'] == $_SESSION['more_storage_handle']) {
33
+  $valid = true;
34
+}
35
+if (!$valid) {
36
+  system_failure("Ungültige Session");
37
+}
38
+
39
+if (!isset($_SESSION['more_storage_items']) || !isset($_SESSION['more_storage_count'])) {
40
+  system_failure('Keine Daten');
41
+}
42
+
43
+$items = $_SESSION['more_storage_items'];
44
+$count = $_SESSION['more_storage_count'];
45
+
46
+if (count($items) < 2) {
47
+  system_failure("Ungültige Daten");
48
+}
49
+
50
+$stub = $items[0];
51
+if ($stub['anzahl'] == 0) {
52
+  $stub = NULL;
53
+}
54
+$regular = $items[1];
55
+
56
+$clean_items = array();
57
+
58
+if ($stub) {
59
+  $i = array();
60
+  $i['beschreibung'] = $stub['beschreibung'];
61
+  $i['datum'] = $stub['startdatum'];
62
+  $i['kuendigungsdatum'] = $stub['enddatum'];
63
+  $i['betrag'] = $stub['betrag'];
64
+  $i['brutto'] = $stub['brutto'];
65
+  $i['monate'] = $stub['anzahl'];
66
+  $i['anzahl'] = $stub['anzahl'];
67
+  $clean_items[] = $i;
68
+}
69
+
70
+$i = array();
71
+$i['beschreibung'] = $regular['beschreibung'];
72
+$i['datum'] = $regular['startdatum'];
73
+$i['kuendigungsdatum'] = NULL;
74
+$i['betrag'] = $regular['betrag'];
75
+$i['brutto'] = $regular['brutto'];
76
+$i['monate'] = $regular['anzahl'];
77
+$i['anzahl'] = $regular['anzahl'];
78
+$clean_items[] = $i;
79
+
80
+save_more_storage($clean_items, $count);
81
+
82
+if (have_module('systemuser')) {
83
+  require('modules/systemuser/include/useraccounts.php');
84
+  $useraccounts = list_useraccounts();
85
+  if (isset($_POST['more_storage_user'])) {
86
+    foreach ($useraccounts as $u) {
87
+      if ($u['uid'] == $_POST['more_storage_user']) {
88
+        $account = get_account_details($u['uid']);
89
+        $account['quota'] = $account['quota'] + $count;
90
+        set_account_details($account);
91
+      }
92
+    }
93
+  }
94
+  unset($_SESSION['more_storage_user']);
95
+}
96
+
97
+
98
+unset($_SESSION['more_storage_handle']);
99
+unset($_SESSION['more_storage_items']);
100
+unset($_SESSION['more_storage_count']);
101
+
102
+if (isset($_SESSION['more_storage_section'])) {
103
+  DEBUG('Weiterleitung zu: '.$prefix.'go/'.str_replace('_', '/', $_SESSION['more_storage_section']));
104
+  redirect($prefix.'go/'.str_replace('_', '/', $_SESSION['more_storage_section']));
105
+} else {
106
+  redirect($prefix.'go/invoice/current');
107
+}
108
+
109
+?>
... ...
@@ -74,6 +75,15 @@ else
74 75
     output("</td></tr>\n");
75 76
   }
76 77
   output("</table><p><sup>*</sup>) Die Werte für den verbrauchten Speicherplatz werden periodisch eingelesen und hier erst verspätet angezeigt!</p>");
78
+  $customerquota = get_customer_quota();
79
+  $freequota = $customerquota['max'] - $customerquota['assigned'];
80
+  if ($freequota > 10) { // Gewisse Unschärfe
81
+    output('<p class="warning"><b>Hinweis:</b><br/>Ihnen steht mehr Speicherplatz zur Verfügung als Ihren Benutzeraccounts zugewiesen ist. Sie können den Speicherplatz der einzelnen Benutzerkonten noch erhöhen.</p>');
82
+  } else {
83
+    if (have_module('invoice')) {
84
+      addnew('../invoice/more_storage?section=systemuser_account', 'Mehr Speicherplatz bestellen');
85
+    }
86
+  }
77 87
 }
78 88
 
79 89
 
... ...
@@ -45,7 +45,7 @@ function primary_useraccount()
45 45
 
46 46
 function available_shells()
47 47
 {
48
-  $result = db_query("SELECT path, name FROM system.shells WHERE usable=1");
48
+  $result = db_query("SELECT path, name FROM system.shells WHERE usable=?", array(1));
49 49
   $ret = array();
50 50
   while ($s = $result->fetch())
51 51
   {
... ...
@@ -27,6 +27,7 @@ $acc = get_account_details($_SESSION['userinfo']['uid'], $_SESSION['userinfo']['
27 27
 $usedquota = get_used_quota($acc['uid']);
28 28
 $quota = array();
29 29
 $multiserver = count($usedquota) > 1;
30
+$need_more_storage = false;
30 31
 foreach ($usedquota as $q)
31 32
 {
32 33
       $mailbar = '';
... ...
@@ -40,6 +41,9 @@ foreach ($usedquota as $q)
40 41
       }  
41 42
 
42 43
       $percent = round(( ($q["systemquota_used"]+$q["mailquota"]) / $q["systemquota"] ) * 100 );
44
+      if ($percent > 90) {
45
+        $need_more_storage = true;
46
+      }
43 47
       $color = ( $percent > 99 ? 'red' : ($percent > 80 ? "yellow" : "green" ));
44 48
       $width = 2 * min($percent, 100) - $mailwidth;
45 49
      
... ...
@@ -62,6 +66,9 @@ output("<h5>Stammdaten</h5>
62 66
 ");
63 67
 output("</div>\n");
64 68
 output("<h5>Speicherplatz</h5><div style=\"margin-left: 2em;\">{$quotastring}</div>");
69
+if (have_module('invoice') && $need_more_storage) {
70
+   addnew('../invoice/more_storage?section='.$section, 'Mehr Speicherplatz bestellen');
71
+}
65 72
     
66 73
 output("<p>Die Werte für den verbrauchten Speicherplatz werden periodisch eingelesen und hier verzögert angezeigt!</p>");
67 74
 
68 75