<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */
class Pruefziffer_54 implements IPruefziffer
{
  public static function check($pKtoNr, $pBlz, $pGewichtung = array(), $pPruefZifferStelle = 9)
  {
    $gewichtung = array(0, 2, 3, 4, 5, 6, 7, 2, 0, 0);

    $ktoNr = str_pad($pKtoNr, 8, '0', STR_PAD_LEFT);
    if (strlen($ktoNr) == 8) {
      $ktoNr = str_pad($ktoNr, 10, '49', STR_PAD_LEFT);
    } elseif (substr($ktoNr, 0, 2) != '49') {
      return false;
    }
    $strZahl = strrev($ktoNr);

    $ary = PruefZiffHelpers::gewichten($strZahl, $gewichtung);
    $result = 11 - (array_sum($ary) % 11);

    return ($result == $ktoNr[$pPruefZifferStelle]);
  }
}