PodglÄ…d pliku: / books_opac / includes / checksum.php
<?php
/*****************************************************
* System biblioteczny - Modul OPAC *
*****************************************************
* Wersja: 1.2 Stable *
* Data: 21.08.2010 (13:45) *
* Autor: Jacek Kowalski (http://jacekk.info) *
* *
* Strona WWW: http://dev.jacekk.net/books *
* *
* Utwor rozprowadzany na licencji *
* http://creativecommons.org/licenses/by-nc-sa/2.5/ *
*****************************************************/
class checksum {
static function EAN($kod) {
$kod = str_split($kod);
$now = 1;
foreach($kod as $v) {
if($now==1) {
$sum += $v;
$now = 3;
}
else
{
$sum += $v*3;
$now = 1;
}
}
return (10 - ($sum%10)) % 10;
}
static function ISBN($kod) {
$kod = str_split($kod);
foreach($kod as $k => $v) {
$sum += (10-$k)*$v;
}
$sum = (11 - ($sum % 11)) % 11;
if($sum == 10) {
$sum = 'X';
}
return $sum;
}
static function ISSN($kod) {
$kod = str_split($kod);
foreach($kod as $k => $v) {
$sum += (8-$k)*$v;
}
$sum = (11 - ($sum % 11)) % 11;
if($sum == 10) {
$sum = 'X';
}
return $sum;
}
}
?>
Browse Code © 2010 by Jacek Kowalski