2017-03-14 11:01:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Informatica Eindproject D4p
|
|
|
|
* 6in3, Stedelijk Gymnasium Nijmegen
|
|
|
|
* Docent: Hans de Wolf
|
|
|
|
*
|
|
|
|
* ==================
|
|
|
|
*
|
|
|
|
* Daniel Boutros,
|
|
|
|
* Christiaan Goossens,
|
|
|
|
* Jelmer Hinssen
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Inforbank\Application\Helper;
|
|
|
|
|
|
|
|
class IBAN
|
|
|
|
{
|
|
|
|
private function wordToNumbers($word)
|
|
|
|
{
|
|
|
|
$newword = "";
|
|
|
|
$wordarray = str_split($word);
|
|
|
|
foreach ($wordarray as $v) {
|
2017-04-02 09:50:45 +00:00
|
|
|
if (ctype_alpha($v)) {
|
2017-03-30 13:49:27 +00:00
|
|
|
$newword .= ord(strtolower($v)) - 87;
|
2017-04-02 09:50:45 +00:00
|
|
|
} else {
|
2017-03-30 13:49:27 +00:00
|
|
|
$newword .= $v;
|
|
|
|
}
|
2017-03-14 11:01:41 +00:00
|
|
|
}
|
|
|
|
return $newword;
|
|
|
|
}
|
|
|
|
|
2017-04-02 09:50:45 +00:00
|
|
|
private function getCheckDigits($bignum)
|
|
|
|
{
|
2017-03-30 13:49:27 +00:00
|
|
|
//Modulo staartdeling
|
2017-03-14 11:01:41 +00:00
|
|
|
$modulo97 = (int)substr($bignum, 0, 6);
|
|
|
|
$modulo97 = $modulo97 % 97;
|
|
|
|
$modulo97 = (1000000 * $modulo97) + (int)substr($bignum, 6, 6);
|
|
|
|
$modulo97 = $modulo97 % 97;
|
|
|
|
$modulo97 = (1000000 * $modulo97) + (int)substr($bignum, 12, 6);
|
|
|
|
$modulo97 = $modulo97 % 97;
|
|
|
|
$modulo97 = (1000000 * $modulo97) + (int)substr($bignum, 18, 6);
|
|
|
|
$modulo97 = $modulo97 % 97;
|
|
|
|
$checkdigits = 98 - $modulo97;
|
|
|
|
if (strlen($checkdigits) < 2) {
|
|
|
|
$checkdigits = '0' . $checkdigits;
|
|
|
|
}
|
2017-03-30 13:49:27 +00:00
|
|
|
return $checkdigits;
|
|
|
|
}
|
2017-04-02 09:50:45 +00:00
|
|
|
|
|
|
|
public function isValidIBAN($iban)
|
|
|
|
{
|
2017-03-30 13:49:27 +00:00
|
|
|
$iban = str_replace(" ", "", $iban);
|
|
|
|
$landcode = substr($iban, 0, 2);
|
|
|
|
$controle = substr($iban, 2, 2);
|
|
|
|
$identificatie = substr($iban, 4);
|
|
|
|
$identificatie .= $landcode;
|
|
|
|
$identificatie .= "00";
|
|
|
|
$nummer = $this->wordToNumbers($identificatie);
|
|
|
|
return $controle == $this->getCheckDigits($nummer);
|
|
|
|
}
|
2017-04-02 09:50:45 +00:00
|
|
|
|
|
|
|
public function getRekeningNummer($iban)
|
|
|
|
{
|
2017-03-30 13:49:27 +00:00
|
|
|
return substr(str_replace(" ", "", $iban), 8);
|
|
|
|
}
|
2017-04-02 09:50:45 +00:00
|
|
|
|
|
|
|
public function getBank($iban)
|
|
|
|
{
|
2017-03-30 13:49:27 +00:00
|
|
|
return substr(str_replace(" ", "", $iban), 4, 4);
|
|
|
|
}
|
2017-04-02 09:50:45 +00:00
|
|
|
|
|
|
|
public function getLand($iban)
|
|
|
|
{
|
2017-03-30 13:49:27 +00:00
|
|
|
return substr(str_replace(" ", "", $iban), 0, 2);
|
|
|
|
}
|
2017-04-02 09:50:45 +00:00
|
|
|
|
2017-03-30 13:49:27 +00:00
|
|
|
public function getIBAN($rekeningnr)
|
|
|
|
{
|
|
|
|
$landcode = "NL"; // NL in vertaling
|
|
|
|
$landnumber = $this->wordToNumbers($landcode);
|
|
|
|
|
|
|
|
|
|
|
|
$bankcode = "INFO";
|
|
|
|
$banknumber = $this->wordToNumbers($bankcode);
|
|
|
|
|
|
|
|
$rekeningnr = str_pad($rekeningnr, 10, 0, STR_PAD_LEFT);
|
|
|
|
|
|
|
|
$bignum = $banknumber . $rekeningnr . $landnumber . "00";
|
|
|
|
$checkdigits = $this->getCheckDigits($bignum);
|
2017-03-14 11:01:41 +00:00
|
|
|
|
|
|
|
$rekeningnrarr = str_split($rekeningnr, 4);
|
|
|
|
return $landcode.$checkdigits." ".$bankcode." ".$rekeningnrarr[0]." ".$rekeningnrarr[1]." ".$rekeningnrarr[2];
|
|
|
|
}
|
|
|
|
}
|