da566387a9d90e7a999a02a6381a588d6c2ffb29
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

1) <?php
2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 1 year ago

5) Written by schokokeks.org Hosting, namely
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

6)   Bernd Wurst <bernd@schokokeks.org>
7)   Hanno Böck <hanno@schokokeks.org>
8) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 1 year ago

9) This code is published under a 0BSD license.
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

10) 
11) 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.
12) */
13) 
14) require_once('session/start.php');
15) require_once('inc/icons.php');
16) require_once('inc/jquery.php');
17) javascript('more_storage.js');
18) 
19) require_once('invoice.php');
20) 
21) require_role(ROLE_CUSTOMER);
22) 
23) $_SESSION['more_storage_section'] = 'invoice_current';
24) if (isset($_GET['section'])) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

25)     $_SESSION['more_storage_section'] = $_GET['section'];
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

26) }
27) $section = $_SESSION['more_storage_section'];
28) 
29) title('Zusätzlichen Speicherplatz buchen');
30) 
31) $upcoming = upcoming_items();
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

32) $hosting = null;
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

33) foreach ($upcoming as $item) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

34)     if ($item['quelle'] == 'hosting') {
35)         $hosting = $item;
36)         break;
37)     }
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

38) }
39) if (!$hosting) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

40)     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.");
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

41) }
42) if ($hosting['brutto'] == 0) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

43)     system_failure("Ihr Konto wird mit Nettopreisen abgerechnet. Bitte wenden Sie sich an den Support.");
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

44) }
45) 
46) $customerquota = get_customerquota();
47) 
48) $count = 1024;
Bernd Wurst Erlaube auch einen Get-Para...

Bernd Wurst authored 7 years ago

49) if (isset($_REQUEST['count']) && (int) $_REQUEST['count'] > 0) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

50)     $count = (int) $_REQUEST['count'];
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

51) }
52) 
Hanno Böck avoid syntax deprecated in...

Hanno Böck authored 1 year ago

53) output("<p>Ihr aktuell zugeteilter Speicherplatz (ggf. inklusive Mitbenutzer) beträgt <strong>{$customerquota} MB</strong>. Sie können weiteren Speicherplatz hinzubuchen.</p>");
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

54) 
55) $checked = '';
56) if ($count == 1024) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

57)     $checked = 'checked="checked" ';
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

58) }
59) $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>';
60) if ($count == 2048) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

61)     $checked = 'checked="checked" ';
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

62) } else {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

63)     $checked = '';
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

64) }
65) $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>';
66) if ($count == 5120) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

67)     $checked = 'checked="checked" ';
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

68) } else {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

69)     $checked = '';
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

70) }
71) $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>';
72) 
73) $form .= '<input type="submit" value="Wählen" /></p>';
74) output(html_form("more_storage_selection", "more_storage", "", $form));
75) 
76) $new_item = $hosting;
77) unset($new_item['quelle']);
78) unset($new_item['id']);
79) $gb = $count/1024;
80) $new_item['beschreibung'] = 'Erweiterung Speicherplatz um '.$gb.' GB (Auftrag vom '.date('d.m.Y').')';
81) $new_item['betrag'] = $gb;
82) 
83) $startdate = $new_item['startdatum'];
84) $diff = date_diff(date_create("now"), date_create($startdate), true);
85) DEBUG('date_diff(now, '.$startdate.') => '.$diff->format('%y Year %m Month %d Day'));
86) $months = $diff->format("%m");
87) 
88) $stub_startdate = date_create($startdate);
89) date_sub($stub_startdate, date_interval_create_from_date_string($months.' months'));
90) $stub_enddate = date_create($startdate);
91) date_sub($stub_enddate, date_interval_create_from_date_string('1 day'));
92) 
93) $stub = $new_item;
94) $stub['startdatum'] = date_format($stub_startdate, 'Y-m-d');
95) $stub['enddatum'] = date_format($stub_enddate, 'Y-m-d');
96) $stub['anzahl'] = $months;
97) $stub['monate'] = $months;
98) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

99) $items = [];
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

100) $items[] = $stub;
101) $items[] = $new_item;
102) 
103) output('<p>Die Abrechnung erfolgt mit Ihrer nächsten turnusgemäßen Abrechnung und wird mit folgenden Rechnungsposten vorgemerkt.</p>');
104) output('<table><tr><th>Anzahl</th><th>Beschreibung</th><th>Zeitraum</th><th>Einzelpreis</th><th>Gesamtbetrag</th></tr>');
105) $counter = 0;
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

106) foreach ($items as $item) {
107)     $counter++;
108)     if ($counter == 1 && ($item['anzahl'] > 0)) {
109)         output("<tr><td colspan=\"5\" style=\"border: none;\"><em>Einmaliger Posten:</em></td></tr>");
110)     } elseif ($counter == 2) {
111)         output("<tr><td colspan=\"5\" style=\"border: none;\"><em>Künftiger regelmäßiger Posten:</em></td></tr>");
112)     }
113)     if ($item['anzahl'] == 0) {
114)         continue;
115)     }
116)     $desc = $item['startdatum'];
117)     if ($item['enddatum'] != null) {
118)         $desc = $item['startdatum'].' - '.$item['enddatum'];
119)     }
120)     $epreis = $item['betrag'];
121)     if ($item['brutto'] == 0) {
122)         $epreis = $epreis * (1 + ($item['mwst'] / 100));
123)     }
124)     $gesamt = round($epreis * $item['anzahl'], 2);
125)     $epreis = round($epreis, 2);
126)     $einheit = ($item['einheit'] ? $item['einheit'] : '');
127)     output("<tr><td>{$item['anzahl']} {$einheit}</td>");
128)     output("<td>{$item['beschreibung']}</td><td>{$desc}</td>");
129)     output("<td>{$epreis} €</td><td>{$gesamt} €</td></tr>\n");
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

130) }
131) output('</table>');
132) 
133) output('<p>Wir behalten uns vor, diese Rechnungsposten mit anderen sinngleichen Posten zusammen zu führen.</p>');
134) 
Bernd Wurst random_string() verwendet u...

Bernd Wurst authored 7 years ago

135) $handle = random_string(10);
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

136) 
137) $_SESSION['more_storage_handle'] = $handle;
138) $_SESSION['more_storage_items'] = $items;
139) $_SESSION['more_storage_count'] = $count;
140) 
141) $form = '';
142) 
143) if (have_module('systemuser')) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

144)     include('modules/systemuser/include/useraccounts.php');
145)     $useraccounts = list_useraccounts();
146) 
147)     if (count($useraccounts) == 1) {
148)         $form .= '<input type="hidden" name="more_storage_user" value="'.$useraccounts[0]['uid'].'" />';
149)     } else {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

150)         $choices = ['' => 'Nicht zuweisen'];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

151)         foreach ($useraccounts as $u) {
152)             $choices[$u['uid']] = "Benutzer ${u['username']} vergrößern";
153)         }
154)         $form .= '<p>Wie soll der zusätzliche Speicherplatz verwendet werden?</p><p>'.html_select('more_storage_user', $choices, $_SESSION['userinfo']['uid']).'</p>';