Subversion Repositories cheapmusic

Rev

Rev 65 | Rev 121 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 65 Rev 113
Line 33... Line 33...
33
        }
33
        }
34
        $sGTINCode = trim($p_sGTINCode);
34
        $sGTINCode = trim($p_sGTINCode);
35
        $p_sGTINCode = null;
35
        $p_sGTINCode = null;
36
        $length = strlen($sGTINCode);
36
        $length = strlen($sGTINCode);
37
        if (($length > 11 && $length <= 14) || $length == 8) {
37
        if (($length > 11 && $length <= 14) || $length == 8) {
38
            $zerros = 18 - $length;
38
            $zeroes = 18 - $length;
39
            $length = null;
39
            $length = null;
40
            $fill = "";
40
            $fill = "";
41
            for ($i = 0;$i < $zerros;$i++) {
41
            for ($i = 0;$i < $zeroes;$i++) {
42
                $fill .= "0";
42
                $fill .= "0";
43
            }
43
            }
44
            $zerros = null;
44
            $zeroes = null;
45
            $i = null;
45
            $i = null;
46
            $sGTINCode = $fill . $sGTINCode;
46
            $sGTINCode = $fill . $sGTINCode;
47
            $fill = null;
47
            $fill = null;
48
            if (!clsLibGTIN::GTINCheckDigit($sGTINCode)) {
48
            if (!clsLibGTIN::GTINCheckDigit($sGTINCode)) {
49
                return false;
49
                return false;
Line 124... Line 124...
124
        else {
124
        else {
125
            $iCalculation = null;
125
            $iCalculation = null;
126
            $p_sGTINCode = null;
126
            $p_sGTINCode = null;
127
            return true;
127
            return true;
128
        }
128
        }
-
 
129
    }
-
 
130
 
-
 
131
    public static function GTINCalcCheckDigit($p_sGTINCode) {
-
 
132
        $p_sGTINCode .= '0';
-
 
133
        $sGTINCode = trim($p_sGTINCode);
-
 
134
        $length = strlen($sGTINCode);
-
 
135
        if (($length > 11 && $length <= 14) || $length == 8) {
-
 
136
            $zeroes = 18 - $length;
-
 
137
            $length = null;
-
 
138
            $fill = "";
-
 
139
            for ($i = 0;$i < $zeroes;$i++) {
-
 
140
                $fill .= "0";
-
 
141
            }
-
 
142
            $zeroes = null;
-
 
143
            $sGTINCode = $fill . $sGTINCode;
-
 
144
            $fill = null;
-
 
145
        }
-
 
146
        $iCalculation = 0;
-
 
147
        for ($i = 0;$i < (strlen($sGTINCode) - 1);$i++) {
-
 
148
            $iCalculation += $i % 2 ? $sGTINCode[$i] * 1 : $sGTINCode[$i] * 3;
-
 
149
        }
-
 
150
        $iDigit = substr(10 - (substr($iCalculation, -1)) , -1);
-
 
151
        $iCalculation = null;
-
 
152
        $p_sGTINCode = null;
-
 
153
        return $iDigit;
129
    }
154
    }
130
}
155
}
131
?>
156
?>