96649f21ba18d07757afa9d98998f7a22c0d86a3
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

1) <?php
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

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 Added license tags for CC0,...

Bernd Wurst authored 12 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 6 years ago

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

Bernd Wurst authored 12 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) */
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

16) 
17) require_once('inc/base.php');
18) require_once('inc/security.php');
19) 
Bernd Wurst Erzeuge HTML als Eingabe fü...

Bernd Wurst authored 5 years ago

20) use_module('contacts');
21) require_once('contacts.php');
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

22) 
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

23) function my_invoices()
24) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

25)     $c = (int) $_SESSION['customerinfo']['customerno'];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

26)     $result = db_query("SELECT id,datum,betrag,bezahlt,abbuchung,sepamandat FROM kundendaten.ausgestellte_rechnungen WHERE kunde=? ORDER BY id DESC", [$c]);
27)     $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

28)     while ($line = $result->fetch()) {
29)         array_push($ret, $line);
30)     }
31)     return $ret;
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

32) }
33) 
34) 
35) function get_pdf($id)
36) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

37)     $c = (int) $_SESSION['customerinfo']['customerno'];
38)     $id = (int) $id;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

39)     $result = db_query("SELECT pdfdata FROM kundendaten.ausgestellte_rechnungen WHERE kunde=:c AND id=:id", [":c" => $c, ":id" => $id]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

40)     if ($result->rowCount() == 0) {
41)         system_failure('Ungültige Rechnungsnummer oder nicht eingeloggt');
42)     }
43)     return $result->fetch(PDO::FETCH_OBJ)->pdfdata;
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

44) }
45) 
46) 
Hanno codingstyle fixes

Hanno authored 5 years ago

47) function invoice_address($customer = null)
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

48) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

49)     $c = (int) $_SESSION['customerinfo']['customerno'];
Bernd Wurst Erzeuge HTML als Eingabe fü...

Bernd Wurst authored 5 years ago

50)     if ($customer != null && have_role(ROLE_SYSADMIN)) {
51)         $c = (int) $customer;
52)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

53)     $result = db_query("SELECT contact_kunde, contact_rechnung FROM kundendaten.kunden WHERE id=?", [$c]);
Bernd Wurst Erzeuge HTML als Eingabe fü...

Bernd Wurst authored 5 years ago

54)     $kontakte = $result->fetch();
55)     $kunde = get_contact($kontakte['contact_kunde'], $c);
56)     if ($kontakte['contact_rechnung']) {
57)         $rechnung = get_contact($kontakte['contact_rechnung'], $c);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

58)         foreach (['company', 'name', 'address', 'zip', 'city', 'country', 'email'] as $field) {
Bernd Wurst Erzeuge HTML als Eingabe fü...

Bernd Wurst authored 5 years ago

59)             if ($rechnung[$field]) {
60)                 $kunde[$field] = $rechnung[$field];
61)             }
62)         }
63)     }
64)     // Hier ist $kunde der bereinigte Rechnungskontakt
65)     return $kunde;
66) }
67) 
68) 
69) function invoice_details($id)
70) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

71)     $id = (int) $id;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

72)     $result = db_query("SELECT kunde,datum,betrag,bezahlt,sepamandat,abbuchung FROM kundendaten.ausgestellte_rechnungen WHERE id=:id", [":id" => $id]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

73)     if ($result->rowCount() == 0) {
74)         system_failure('Ungültige Rechnungsnummer oder nicht eingeloggt');
75)     }
Bernd Wurst Erzeuge HTML als Eingabe fü...

Bernd Wurst authored 5 years ago

76)     $data = $result->fetch();
77)     if (!have_role(ROLE_SYSADMIN) && $data['kunde'] != (int) $_SESSION['customerinfo']['customerno']) {
78)         system_failure('Ungültige Rechnungsnummer für diesen Login');
79)     }
80)     return $data;
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

81) }
82) 
83) function invoice_items($id)
84) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

85)     $id = (int) $id;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

86)     $result = db_query("SELECT id, beschreibung, datum, enddatum, betrag, einheit, brutto, mwst, anzahl FROM kundendaten.rechnungsposten WHERE rechnungsnummer=:id", [":id" => $id]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

87)     if ($result->rowCount() == 0) {
88)         system_failure('Ungültige Rechnungsnummer oder nicht eingeloggt');
89)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

90)     $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

91)     while ($line = $result->fetch()) {
92)         array_push($ret, $line);
93)     }
94)     return $ret;
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

95) }
96) 
97) 
98) function upcoming_items()
99) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

100)     $c = (int) $_SESSION['customerinfo']['customerno'];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

101)     $result = db_query("SELECT quelle, id, anzahl, beschreibung, startdatum, enddatum, betrag, einheit, brutto, mwst FROM kundendaten.upcoming_items WHERE kunde=? ORDER BY startdatum ASC", [$c]);
102)     $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

103)     while ($line = $result->fetch()) {
104)         array_push($ret, $line);
105)     }
106)     return $ret;
bernd Kunden können Ihre Rechnung...

bernd authored 16 years ago

107) }
108) 
109) 
Hanno rename generate_qrcode_imag...

Hanno authored 6 years ago

110) function generate_qrcode_image_invoice($id)
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

111) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

112)     $invoice = invoice_details($id);
113)     $customerno = $invoice['kunde'];
114)     $amount = 'EUR'.sprintf('%.2f', $invoice['betrag']);
115)     $datum = $invoice['datum'];
116)     $data = 'BCD
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

117) 001
118) 1
119) SCT
120) GENODES1VBK
121) schokokeks.org GbR
122) DE91602911200041512006
123) '.$amount.'
124) 
125) 
Bernd Wurst Beschreibung entfernt, mach...

Bernd Wurst authored 10 years ago

126) RE '.$id.' KD '.$customerno.' vom '.$datum;
Hanno remove whitespace in empty...

Hanno authored 6 years ago

127) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

128)     $descriptorspec = [
129)     0 => ["pipe", "r"],  // STDIN ist eine Pipe, von der das Child liest
130)     1 => ["pipe", "w"],  // STDOUT ist eine Pipe, in die das Child schreibt
131)     2 => ["pipe", "w"],
132)   ];
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

133) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

134)     $process = proc_open('qrencode -t PNG -o - -l M', $descriptorspec, $pipes);
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

135) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

136)     if (is_resource($process)) {
137)         // $pipes sieht nun so aus:
138)         // 0 => Schreibhandle, das auf das Child STDIN verbunden ist
139)         // 1 => Lesehandle, das auf das Child STDOUT verbunden ist
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

140) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

141)         fwrite($pipes[0], $data);
142)         fclose($pipes[0]);
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

143) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

144)         $pngdata = stream_get_contents($pipes[1]);
145)         fclose($pipes[1]);
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

146) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

147)         // Es ist wichtig, dass Sie alle Pipes schließen bevor Sie
148)         // proc_close aufrufen, um Deadlocks zu vermeiden
149)         $return_value = proc_close($process);
Hanno remove whitespace in empty...

Hanno authored 6 years ago

150) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

151)         return $pngdata;
152)     } else {
153)         warning('Es ist ein interner Fehler im Webinterface aufgetreten, aufgrund dessen kein QR-Code erstellt werden kann. Sollte dieser Fehler mehrfach auftreten, kontaktieren Sie bitte die Administratoren.');
154)     }
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

155) }
156) 
157) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

158) function get_lastschrift($rechnungsnummer)
159) {
160)     $rechnungsnummer = (int) $rechnungsnummer;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

161)     $result = db_query("SELECT rechnungsnummer, rechnungsdatum, sl.betrag, buchungsdatum, sl.status FROM kundendaten.sepalastschrift sl LEFT JOIN kundendaten.ausgestellte_rechnungen re ON (re.sepamandat=sl.mandatsreferenz) WHERE rechnungsnummer=?", [$rechnungsnummer]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

162)     if ($result->rowCount() == 0) {
163)         return null;
164)     }
165)     $item = $result->fetch();
166)     return $item;
Bernd Wurst Vorgemerkte Lastschriften a...

Bernd Wurst authored 10 years ago

167) }
168) 
169) function get_lastschriften($mandatsreferenz)
170) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

171)     $result = db_query("SELECT rechnungsnummer, rechnungsdatum, betrag, buchungsdatum, status FROM kundendaten.sepalastschrift WHERE mandatsreferenz=? ORDER BY buchungsdatum DESC", [$mandatsreferenz]);
172)     $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

173)     while ($item = $result->fetch()) {
174)         $ret[] = $item;
175)     }
176)     return $ret;
Bernd Wurst Vorgemerkte Lastschriften a...

Bernd Wurst authored 10 years ago

177) }
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

178) 
Bernd Wurst Erzeuge HTML als Eingabe fü...

Bernd Wurst authored 5 years ago

179) 
Hanno codingstyle fixes

Hanno authored 5 years ago

180) function get_sepamandat($id)
Bernd Wurst Erzeuge HTML als Eingabe fü...

Bernd Wurst authored 5 years ago

181) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

182)     $result = db_query("SELECT id, kunde, mandatsreferenz, glaeubiger_id, erteilt, medium, gueltig_ab, gueltig_bis, erstlastschrift, kontoinhaber, adresse, iban, bic, bankname FROM kundendaten.sepamandat WHERE id=? OR mandatsreferenz=?", [$id, $id]);
Bernd Wurst Erzeuge HTML als Eingabe fü...

Bernd Wurst authored 5 years ago

183)     return $result->fetch();
Hanno codingstyle fixes

Hanno authored 5 years ago

184) }
Bernd Wurst Erzeuge HTML als Eingabe fü...

Bernd Wurst authored 5 years ago

185) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

186) function get_sepamandate()
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

187) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

188)     $cid = (int) $_SESSION['customerinfo']['customerno'];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

189)     $result = db_query("SELECT id, mandatsreferenz, glaeubiger_id, erteilt, medium, gueltig_ab, gueltig_bis, erstlastschrift, kontoinhaber, adresse, iban, bic, bankname FROM kundendaten.sepamandat WHERE kunde=?", [$cid]);
190)     $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

191)     while ($entry = $result->fetch()) {
192)         array_push($ret, $entry);
193)     }
194)     return $ret;
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

195) }
196) 
197) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

198) function yesterday($date)
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

199) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

200)     $result = db_query("SELECT ? - INTERVAL 1 DAY", [$date]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

201)     return $result->fetch()[0];
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

202) }
203) 
204) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

205) function invalidate_sepamandat($id, $date)
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

206) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

207)     $args = [":cid" => (int) $_SESSION['customerinfo']['customerno'],
Bernd Wurst Weitere Prepared-Statement-...

Bernd Wurst authored 10 years ago

208)                 ":id" => (int) $id,
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

209)                 ":date" => $date, ];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

210)     db_query("UPDATE kundendaten.sepamandat SET gueltig_bis=:date WHERE id=:id AND kunde=:cid", $args);
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

211) }
212) 
213) 
214) function sepamandat($name, $adresse, $iban, $bankname, $bic, $gueltig_ab)
215) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

216)     $cid = (int) $_SESSION['customerinfo']['customerno'];
217) 
218)     $first_date = date('Y-m-d');
219)     $invoices = my_invoices();
220)     foreach ($invoices as $i) {
221)         if ($i['bezahlt'] == 0 && $i['datum'] < $first_date) {
222)             $first_date = $i['datum'];
223)         }
224)     }
225)     if ($gueltig_ab < date('Y-m-d') && $gueltig_ab != $first_date) {
226)         system_failure('Das Mandat kann nicht rückwirkend erteilt werden. Bitte geben Sie ein Datum in der Zukunft an.');
Bernd Wurst Speichere Gläubiger-ID mit...

Bernd Wurst authored 10 years ago

227)     }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

228)     $alte_mandate = get_sepamandate();
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

229)     $referenzen = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

230)     foreach ($alte_mandate as $mandat) {
231)         if ($mandat['gueltig_bis'] == null || $mandat['gueltig_bis'] >= $gueltig_ab) {
232)             DEBUG('Altes Mandat wird für ungültig erklärt.');
233)             DEBUG($mandat);
234)             invalidate_sepamandat($mandat['id'], yesterday($gueltig_ab));
235)         }
236)         array_push($referenzen, $mandat['mandatsreferenz']);
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

237)     }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

238)     $counter = 1;
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

239)     $referenz = sprintf('K%04d-M%03d', $cid, $counter);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

240)     while (in_array($referenz, $referenzen)) {
241)         $counter++;
242)         $referenz = sprintf('K%04d-M%03d', $cid, $counter);
243)     }
244)     DEBUG('Nächste freie Mandatsreferenz: '. $referenz);
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

245) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

246)     $glaeubiger_id = config('glaeubiger_id');
Bernd Wurst Speichere Gläubiger-ID mit...

Bernd Wurst authored 10 years ago

247) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

248)     $today = date('Y-m-d');
249)     db_query(
Hanno Update codingstyle accordin...

Hanno authored 5 years ago

250)         "INSERT INTO kundendaten.sepamandat (mandatsreferenz, glaeubiger_id, kunde, erteilt, medium, gueltig_ab, kontoinhaber, adresse, iban, bic, bankname) VALUES (:referenz, :glaeubiger_id, :cid, :today, 'online', :gueltig_ab, :name, :adresse, :iban, :bic, :bankname)",
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

251)         [":referenz" => $referenz, ":glaeubiger_id" => $glaeubiger_id, ":cid" => $cid,
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

252)                 ":today" => $today, ":gueltig_ab" => $gueltig_ab, ":name" => $name, ":adresse" => $adresse,
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

253)                 ":iban" => $iban, ":bic" => $bic, ":bankname" => $bankname, ]
Hanno Fix codingstyle

Hanno authored 4 years ago

254)     );
Bernd Wurst invoice: only update invoic...

Bernd Wurst authored 3 years ago

255)     db_query(
256)         "UPDATE kundendaten.ausgestellte_rechnungen SET abbuchung=1 WHERE kunde = :cid AND datum >= :gueltig_ab and bezahlt=0",
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

257)         [":cid" => $cid, ":gueltig_ab" => $gueltig_ab]
Bernd Wurst invoice: only update invoic...

Bernd Wurst authored 3 years ago

258)     );
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

259) }
260) 
261) 
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

262) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

263) function get_bank_info($iban)
Bernd Wurst Vervollständige Bankname un...

Bernd Wurst authored 10 years ago

264) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

265)     if (strlen($iban) != 22 || substr($iban, 0, 2) != 'DE') {
266)         // Geht nur bei deutschen IBANs
267)         echo 'Fehler!';
268)         echo '$iban = '.$iban;
269)         echo 'strlen($iban): '.strlen($iban);
270)         echo 'substr($iban, 0, 2): '.substr($iban, 0, 2);
271)         return null;
272)     }
273)     $blz = substr($iban, 4, 8);
274)     // FIXME: Liste der BLZs muss vorhanden sein!
275)     $bankinfofile = dirname(__FILE__).'/bankinfo.txt';
276)     $f = file($bankinfofile);
277)     $match = '';
278)     foreach ($f as $line) {
279)         if (substr($line, 0, 9) == $blz.'1') {
280)             $match = $line;
281)             break;
282)         }
Bernd Wurst Vervollständige Bankname un...

Bernd Wurst authored 10 years ago

283)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

284)     $bank = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

285)     $bank['name'] = iconv('latin1', 'utf8', chop(substr($match, 9, 58)));
286)     $bank['bic'] = chop(substr($match, 139, 11));
287)     return $bank;
Bernd Wurst Vervollständige Bankname un...

Bernd Wurst authored 10 years ago

288) }
289) 
290) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

291) function find_iban($blz, $kto)
Bernd Wurst Ermögliche das Berechnen de...

Bernd Wurst authored 10 years ago

292) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

293)     $iban = sprintf('DE00%08s%010s', $blz, $kto);
294)     $iban = iban_set_checksum($iban);
295)     return $iban;
Bernd Wurst Ermögliche das Berechnen de...

Bernd Wurst authored 10 years ago

296) }
297) 
298) 
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

299) function get_customerquota()
300) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

301)     $cid = (int) $_SESSION['customerinfo']['customerno'];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

302)     $result = db_query("SELECT quota FROM system.customerquota WHERE cid=:cid", [":cid" => $cid]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

303)     $data = $result->fetch();
304)     return $data["quota"];
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

305) }
306) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

307) function save_more_storage($items, $storage)
308) {
309)     $cid = (int) $_SESSION['customerinfo']['customerno'];
Hanno remove whitespace in empty...

Hanno authored 6 years ago

310) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

311)     $queries = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

312) 
313)     if ($storage < 1024 || $storage > 10240) {
314)         input_error('Speicherplatz nicht im erwarteten Bereich');
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

315)     }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

316)     $oldcustomerquota = get_customerquota();
317)     if ($oldcustomerquota > 102400) {
318)         # Über 100 GB soll die Automatik nichts machen
319)         system_failure("Ihr Speicherplatz kann über diese Funktion nicht weiter erhöht werden. Bitte wenden Sie sich an die Administratoren.");
320)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

321)     $result = db_query("SELECT quota FROM system.customerquota WHERE cid=:cid AND lastchange > CURDATE()", [":cid" => $cid]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

322)     if ($result->rowcount() > 0) {
323)         system_failure("Ihr Speicherplatz wurde heute bereits verändert. Sie können dies nur einmal am Tag machen.");
324)     }
325) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

326)     $queries[] = ["UPDATE system.customerquota SET quota=quota+:storage WHERE cid=:cid", [":storage" => $storage, ":cid" => $cid]];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

327) 
328)     foreach ($items as $data) {
329)         if ($data['anzahl'] == 0) {
330)             continue;
331)         }
332)         $data['kunde'] = $cid;
333)         $data['notizen'] = 'Bestellt via Webinterface';
334)         if (!isset($data['anzahl']) ||
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

335)         !isset($data['beschreibung']) ||
336)         !isset($data['datum']) ||
337)         !array_key_exists('kuendigungsdatum', $data) ||
338)         !isset($data['betrag']) ||
339)         !isset($data['monate'])) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

340)             DEBUG($data);
341)             input_error("Ungültige Daten");
342)             return;
343)         }
Hanno remove whitespace in empty...

Hanno authored 6 years ago

344) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

345)         $param = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

346)         foreach ($data as $k => $v) {
347)             $param[':'.$k] = $v;
348)         }
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

349) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

350)         $queries[] = ["INSERT INTO kundendaten.leistungen (kunde,periodisch,beschreibung,datum,kuendigungsdatum,betrag,brutto,monate,anzahl,notizen) VALUES ".
351)                        "(:kunde,1,:beschreibung,:datum,:kuendigungsdatum,:betrag,:brutto,:monate,:anzahl,:notizen)", $param, ];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

352)     }
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

353) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

354)     if (count($queries) < 2) {
355)         system_failure("irgendwas stimmt jetzt nicht");
356)     }
Hanno remove whitespace in empty...

Hanno authored 6 years ago

357) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

358)     foreach ($queries as $q) {
359)         db_query($q[0], $q[1]);
360)     }
Bernd Wurst set admin address as sender...

Bernd Wurst authored 3 years ago

361)     $name = $_SESSION['customerinfo']['company'];
362)     if (! $name && $_SESSION['customerinfo']['name']) {
363)         $name = $_SESSION['customerinfo']['name'];
364)     }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

365)     $allstorage = $oldcustomerquota+$storage;
366)     $emailaddr = $_SESSION['customerinfo']['email'];
Bernd Wurst set admin address as sender...

Bernd Wurst authored 3 years ago

367)     $message = "Hallo,\n\nsoeben wurde im Webinterface von ".config('company_name')." eine Bestellung über zusätzlichen Speicherplatz ausgeführt.\nSollten Sie diese Bestellung nicht getätigt haben, antworten Sie bitte auf diese E-Mail um unseren Support zu erreichen.\n\nBei dieser Bestellung wurden {$storage} MB zusätzlicher Speicherplatz bestellt. Ihnen stehen ab sofort insgesamt {$allstorage} MB zur Verfügung.\n\nIhre Kundennummer: {$_SESSION['customerinfo']['customerno']} ({$name})\n";
Bernd Wurst fix encoding mail headers a...

Bernd Wurst authored 4 years ago

368)     send_mail($emailaddr, 'Auftragsbestätigung: Mehr Speicherplatz bei schokokeks.org', $message);