fe8d7c2025e33349ab1e51c0e906ec3ee69dcff2
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) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 1 year ago

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

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

bernd authored 16 years ago

13) 
14) require_once('inc/base.php');
15) require_once('inc/security.php');
16) 
Bernd Wurst Erzeuge HTML als Eingabe fü...

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

20) function my_invoices()
21) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

29) }
30) 
31) 
32) function get_pdf($id)
33) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

36)     $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 5 years ago

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

bernd authored 16 years ago

41) }
42) 
43) 
Hanno codingstyle fixes

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Hanno Böck authored 2 years ago

50)     $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

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

Hanno Böck authored 2 years ago

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

Bernd Wurst authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

69)     $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 5 years ago

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

Bernd Wurst authored 5 years ago

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

bernd authored 16 years ago

78) }
79) 
80) function invoice_items($id)
81) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

83)     $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 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

92) }
93) 
94) 
95) function upcoming_items()
96) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

98)     $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]);
99)     $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 16 years ago

104) }
105) 
106) 
Hanno rename generate_qrcode_imag...

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

109)     $invoice = invoice_details($id);
110)     $customerno = $invoice['kunde'];
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

111)     $amount = 'EUR' . sprintf('%.2f', $invoice['betrag']);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

112)     $datum = $invoice['datum'];
113)     $data = 'BCD
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

114) 001
115) 1
116) SCT
117) GENODES1VBK
118) schokokeks.org GbR
119) DE91602911200041512006
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

120) ' . $amount . '
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

121) 
122) 
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

125)     $descriptorspec = [
Hanno Böck Neue codingstyle-rule array...

Hanno Böck authored 1 month ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

131)     $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

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

148)         return $pngdata;
149)     } else {
150)         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.');
151)     }
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

152) }
153) 
154) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

155) function get_lastschrift($rechnungsnummer)
156) {
157)     $rechnungsnummer = (int) $rechnungsnummer;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

158)     $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 5 years ago

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

Bernd Wurst authored 10 years ago

164) }
165) 
166) function get_lastschriften($mandatsreferenz)
167) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 5 years ago

176) 
Hanno codingstyle fixes

Hanno authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Hanno Böck authored 2 years ago

179)     $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

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

Hanno authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

186)     $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]);
187)     $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

192) }
193) 
194) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

199) }
200) 
201) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno Böck authored 2 years ago

204)     $args = [":cid" => (int) $_SESSION['customerinfo']['customerno'],
Hanno Böck Neue codingstyle-rule array...

Hanno Böck authored 1 month ago

205)         ":id" => (int) $id,
206)         ":date" => $date, ];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

207)     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

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

Hanno authored 5 years ago

213)     $cid = (int) $_SESSION['customerinfo']['customerno'];
214) 
215)     $first_date = date('Y-m-d');
216)     $invoices = my_invoices();
217)     foreach ($invoices as $i) {
218)         if ($i['bezahlt'] == 0 && $i['datum'] < $first_date) {
219)             $first_date = $i['datum'];
220)         }
221)     }
222)     if ($gueltig_ab < date('Y-m-d') && $gueltig_ab != $first_date) {
223)         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

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

237)     while (in_array($referenz, $referenzen)) {
238)         $counter++;
239)         $referenz = sprintf('K%04d-M%03d', $cid, $counter);
240)     }
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

241)     DEBUG('Nächste freie Mandatsreferenz: ' . $referenz);
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

247)         "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

248)         [":referenz" => $referenz, ":glaeubiger_id" => $glaeubiger_id, ":cid" => $cid,
Hanno Böck Neue codingstyle-rule array...

Hanno Böck authored 1 month ago

249)             ":today" => $today, ":gueltig_ab" => $gueltig_ab, ":name" => $name, ":adresse" => $adresse,
250)             ":iban" => $iban, ":bic" => $bic, ":bankname" => $bankname, ]
Hanno Fix codingstyle

Hanno authored 4 years ago

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

Bernd Wurst authored 2 years ago

252)     db_query(
253)         "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

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

Bernd Wurst authored 2 years ago

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

Bernd Wurst authored 10 years ago

256) }
257) 
258) 
Bernd Wurst QR-Codes für Überweisung be...

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

262)     if (strlen($iban) != 22 || substr($iban, 0, 2) != 'DE') {
263)         // Geht nur bei deutschen IBANs
264)         echo 'Fehler!';
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

265)         echo '$iban = ' . $iban;
266)         echo 'strlen($iban): ' . strlen($iban);
267)         echo 'substr($iban, 0, 2): ' . substr($iban, 0, 2);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

268)         return null;
269)     }
270)     $blz = substr($iban, 4, 8);
271)     // FIXME: Liste der BLZs muss vorhanden sein!
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

272)     $bankinfofile = dirname(__FILE__) . '/bankinfo.txt';
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

273)     $f = file($bankinfofile);
274)     $match = '';
275)     foreach ($f as $line) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

276)         if (substr($line, 0, 9) == $blz . '1') {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

277)             $match = $line;
278)             break;
279)         }
Bernd Wurst Vervollständige Bankname un...

Bernd Wurst authored 10 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

285) }
286) 
287) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

293) }
294) 
295) 
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

296) function get_customerquota()
297) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 7 years ago

302) }
303) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

309) 
310)     if ($storage < 1024 || $storage > 10240) {
311)         input_error('Speicherplatz nicht im erwarteten Bereich');
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

318)     $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 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 7 years ago

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

Hanno authored 5 years ago

337)             DEBUG($data);
338)             input_error("Ungültige Daten");
339)             return;
340)         }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

343)         foreach ($data as $k => $v) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

344)             $param[':' . $k] = $v;
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

345)         }
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

346) 
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

347)         $queries[] = ["INSERT INTO kundendaten.leistungen (kunde,periodisch,beschreibung,datum,kuendigungsdatum,betrag,brutto,monate,anzahl,notizen) VALUES " .
Hanno Böck Neue codingstyle-rule array...

Hanno Böck authored 1 month ago

348)                    "(:kunde,1,:beschreibung,:datum,:kuendigungsdatum,:betrag,:brutto,:monate,:anzahl,:notizen)", $param, ];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

349)     }
Bernd Wurst Zwischenversion

Bernd Wurst authored 7 years ago

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

Hanno authored 5 years ago

351)     if (count($queries) < 2) {
352)         system_failure("irgendwas stimmt jetzt nicht");
353)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

355)     foreach ($queries as $q) {
356)         db_query($q[0], $q[1]);
357)     }
Bernd Wurst set admin address as sender...

Bernd Wurst authored 2 years ago

358)     $name = $_SESSION['customerinfo']['company'];
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

359)     if (!$name && $_SESSION['customerinfo']['name']) {
Bernd Wurst set admin address as sender...

Bernd Wurst authored 2 years ago

360)         $name = $_SESSION['customerinfo']['name'];
361)     }
Hanno Böck codingstyle, spaces between...

Hanno Böck authored 8 months ago

362)     $allstorage = $oldcustomerquota + $storage;
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

363)     $emailaddr = $_SESSION['customerinfo']['email'];
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

364)     $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

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