7f815276981e366df7e6f3b6ccb92ebeca624fb3
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

1) <?php
2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
Bernd Wurst Copyright year update

Bernd Wurst authored 6 years ago

5) Written 2008-2018 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) 
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) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

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'])) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Bernd Wurst authored 7 years ago

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

Hanno authored 5 years ago

35) $hosting = null;
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

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

Hanno authored 5 years ago

37)     if ($item['quelle'] == 'hosting') {
38)         $hosting = $item;
39)         break;
40)     }
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 7 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 7 years ago

47) }
48) 
49) $customerquota = get_customerquota();
50) 
51) $count = 1024;
Bernd Wurst Erlaube auch einen Get-Para...

Bernd Wurst authored 7 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 7 years ago

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) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Bernd Wurst authored 7 years ago

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) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Bernd Wurst authored 7 years ago

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

Hanno authored 5 years ago

66)     $checked = '';
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

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) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Bernd Wurst authored 7 years ago

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

Hanno authored 5 years ago

72)     $checked = '';
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

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;
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 7 years ago

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')) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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>';