modules/invoice/save.php
92f2aa62
 <?php
 /*
 This file belongs to the Webinterface of schokokeks.org Hosting
 
cf54502a
 Written 2008-2018 by schokokeks.org Hosting, namely
92f2aa62
   Bernd Wurst <bernd@schokokeks.org>
   Hanno Böck <hanno@schokokeks.org>
 
 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.
 
2626dd47
 You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
92f2aa62
 http://creativecommons.org/publicdomain/zero/1.0/
 
 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.
 */
 
 require_role(ROLE_CUSTOMER);
 
 require('invoice.php');
 require_once("inc/debug.php");
d47d0b77
 require_once("inc/security.php");
92f2aa62
 global $debugmode;
 
 $section = 'invoice_current';
 
 
2626dd47
 if ($_GET['action'] == 'new') {
     check_form_token('sepamandat_neu');
9086c9ad
 
2626dd47
     $gueltig_ab = $_REQUEST['gueltig_ab'];
     if ($gueltig_ab == 'datum') {
         $gueltig_ab = $_REQUEST['gueltig_ab_datum_year'].'-'.$_REQUEST['gueltig_ab_datum_month'].'-'.$_REQUEST['gueltig_ab_datum_day'];
     }
     if (! check_date($gueltig_ab)) {
         system_failure('Konnte das Datum nicht auslesen');
     }
     DEBUG('Gültig ab: '.$gueltig_ab);
92f2aa62
 
2626dd47
     if (empty($_REQUEST['kontoinhaber'])) {
         system_failure('Bitte geben Sie den Kontoinhaber so an, wie dies bei Ihrer Bank hinterlegt ist.');
     }
     $name = $_REQUEST['kontoinhaber'];
     DEBUG('Kontoinhaber:'.$name);
92f2aa62
 
2626dd47
     if (empty($_REQUEST['adresse'])) {
         system_failure('Bitte geben Sie die Adresse des Kontoinhabers an.');
     }
     $adresse = $_REQUEST['adresse'];
     DEBUG('Adresse: '.$adresse);
92f2aa62
 
2626dd47
     if (empty($_REQUEST['iban'])) {
         system_failure('Es wurde keine IBAN angegeben.');
     }
fc1849c2
     $iban = str_replace(' ', '', strtoupper($_REQUEST['iban']));
2626dd47
     if (! verify_iban($iban)) {
         system_failure("Die IBAN scheint nicht korrekt zu sein!");
     }
     DEBUG('IBAN: '.$iban);
92f2aa62
 
2626dd47
     $bankname = $_REQUEST['bankname'];
     if (empty($_REQUEST['bankname'])) {
         system_failure('Bitte geben Sie den Namen der Bank an.');
     }
     DEBUG('Bank: '.$bankname);
92f2aa62
 
2626dd47
     $bic = null;
     if (empty($_REQUEST['bic'])) {
         if (substr($iban, 0, 2) == 'DE') {
             $bic=null;
         } else {
             system_failure('Sie haben keinen BIC angegeben. Für Konten außerhalb Deutschlands ist ein BIC weiterhin erforderlich.');
         }
92f2aa62
     } else {
2626dd47
         $bic = $_REQUEST['bic'];
92f2aa62
     }
2626dd47
     DEBUG('BIC: '.$bic);
92f2aa62
 
9086c9ad
 
2626dd47
     sepamandat($name, $adresse, $iban, $bankname, $bic, $gueltig_ab);
9086c9ad
 
2626dd47
     redirect($prefix.'go/invoice/current');
92f2aa62
 }