<?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_23 implements IPruefziffer
{
  public static function check($pKtoNr, $pBlz, $pGewichtung = array(), $pPruefZifferStelle = 6)
  {
    if (empty($pGewichtung)) {
      $gewichtung = array(0, 0, 0, 0, 2, 3, 4, 5, 6, 7);
    } else {
      $gewichtung = $pGewichtung;
    }

    $ktoNr = str_pad($pKtoNr, 10, '0', STR_PAD_LEFT);
    $strZahl = strrev($ktoNr);

    $ary = PruefZiffHelpers::gewichten($strZahl, $gewichtung);
    $summe = array_sum($ary);

    $rest = $summe % 11;
    $pruefZiffer = 0;
    switch ($rest) {
      case 0:
        $pruefZiffer = 0;
        
      case 1:
        if ($ktoNr[5] == $ktoNr[6]) {
          return true;
        } else {
          return false;
        }
        
      default:
        $pruefZiffer = 11 - $rest;
    }

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