<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mVc.eMailer.pl</title>
	<atom:link href="http://mvc.emailer.pl/feed" rel="self" type="application/rss+xml" />
	<link>http://mvc.emailer.pl</link>
	<description>Model - Widok - Kontroler w praktyce</description>
	<lastBuildDate>Mon, 27 Sep 2010 14:41:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Walidacja REGON dla MySQL</title>
		<link>http://mvc.emailer.pl/bazy-danych/walidacja-regon-dla-mysql</link>
		<comments>http://mvc.emailer.pl/bazy-danych/walidacja-regon-dla-mysql#comments</comments>
		<pubDate>Fri, 27 Aug 2010 10:56:51 +0000</pubDate>
		<dc:creator>Radosław Piątek</dc:creator>
				<category><![CDATA[Bazy danych]]></category>

		<guid isPermaLink="false">http://mvc.emailer.pl/?p=51</guid>
		<description><![CDATA[CREATE FUNCTION `valid_regon`(`regon` varchar(255)) RETURNS int(1) READS SQL DATA BEGIN DECLARE cs integer DEFAULT 0; DECLARE m integer DEFAULT 0; DECLARE i integer DEFAULT 0; IF (char_length(regon) = 7) THEN simple_loop: LOOP SET i=i+1; if i in (1) then SET m = 2; elseif i in (2) then SET m = 3; elseif i in [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush:sql">

CREATE FUNCTION `valid_regon`(`regon` varchar(255)) RETURNS int(1)
    READS SQL DATA
BEGIN

DECLARE cs integer DEFAULT 0;
DECLARE m integer  DEFAULT 0;
DECLARE i integer DEFAULT 0;

IF (char_length(regon) = 7) THEN

       simple_loop: LOOP
         SET i=i+1;
                        if i in (1) then
                                SET m = 2;
                        elseif i in (2) then
                                SET m = 3;
                        elseif i in (3) then
                                SET m = 4;
                        elseif i in (4) then
                                SET m = 5;
                        elseif i in (5) then
                                SET m = 6;
                        elseif i in (6) then
                                SET m = 7;
                        end if;
			SET cs = cs + (m * substr(regon,i,1));

         IF i=6 THEN
            LEAVE simple_loop;
         END IF;
       END LOOP simple_loop;

                SET cs = cs % 11;
                if ( cs = substr(regon,7,1) ) then
                        return 1;
                else
                        return 0;
                end if;

ELSEIF (char_length(regon) = 9) THEN

       simple_loop: LOOP
         SET i=i+1;
                        if i in (3) then
                                SET m = 2;
                        elseif i in (4) then
                                SET m = 3;
                        elseif i in (5) then
                                SET m = 4;
                        elseif i in (6) then
                                SET m = 5;
                        elseif i in (7) then
                                SET m = 6;
                        elseif i in (8) then
                                SET m = 7;
                        elseif i in (1) then
                                SET m = 8;
                        elseif i in (2) then
                                SET m = 9;
                        end if;
			SET cs = cs + (m * substr(regon,i,1));

         IF i=8 THEN
            LEAVE simple_loop;
         END IF;
       END LOOP simple_loop;

                SET cs = cs % 11;
                if ( cs = substr(regon,9,1) ) then
                        return 1;
                else
                        return 0;
                end if;	

ELSEIF (char_length(regon) = 14) THEN

       simple_loop: LOOP
         SET i=i+1;
                        if i in (1,11) then
                                SET m = 2;
                        elseif i in (8) then
                                SET m = 3;
                        elseif i in (2,12) then
                                SET m = 4;
                        elseif i in (4) then
                                SET m = 5;
                        elseif i in (9) then
                                SET m = 6;
                        elseif i in (7) then
                                SET m = 7;
                        elseif i in (3,13) then
                                SET m = 8;
                        elseif i in (6) then
                                SET m = 9;
                        elseif i in (5) then
                                SET m = 0;
                        end if;
			SET cs = cs + (m * substr(regon,i,1));

         IF i=13 THEN
            LEAVE simple_loop;
         END IF;
       END LOOP simple_loop;

                SET cs = cs % 11;
                if ( cs = substr(regon,14,1) ) then
                        return 1;
                else
                        return 0;
                end if;
ELSE
	return -1;
END IF;

END
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mvc.emailer.pl/bazy-danych/walidacja-regon-dla-mysql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Walidacja PESEL dla MySQL</title>
		<link>http://mvc.emailer.pl/bazy-danych/walidacja-pesel-dla-mysql</link>
		<comments>http://mvc.emailer.pl/bazy-danych/walidacja-pesel-dla-mysql#comments</comments>
		<pubDate>Fri, 27 Aug 2010 10:55:29 +0000</pubDate>
		<dc:creator>Radosław Piątek</dc:creator>
				<category><![CDATA[Bazy danych]]></category>

		<guid isPermaLink="false">http://mvc.emailer.pl/?p=48</guid>
		<description><![CDATA[CREATE FUNCTION `valid_pesel`(`pesel` varchar(255)) RETURNS int(1) READS SQL DATA BEGIN DECLARE cs integer DEFAULT 0; DECLARE m integer DEFAULT 0; DECLARE i integer DEFAULT 0; IF (char_length(pesel) = 11) THEN simple_loop: LOOP SET i=i+1; if i in (1,5,9) then SET m = 1; elseif i in (2,6,10) then SET m = 3; elseif i in [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush:sql">

CREATE FUNCTION `valid_pesel`(`pesel` varchar(255)) RETURNS int(1)
    READS SQL DATA
BEGIN

DECLARE cs integer DEFAULT 0;
DECLARE m integer  DEFAULT 0;
DECLARE i integer DEFAULT 0;

IF (char_length(pesel) = 11) THEN

       simple_loop: LOOP
         SET i=i+1;
                        if i in (1,5,9) then
                                SET m = 1;
                        elseif i in (2,6,10) then
                                SET m = 3;
                        elseif i in (3,7) then
                                SET m = 7;
                        elseif i in (4,8) then
                                SET m = 9;
                        end if;
			SET cs = cs + (m * substr(pesel,i,1));

         IF i=10 THEN
            LEAVE simple_loop;
         END IF;
       END LOOP simple_loop;

                SET cs = cs % 10;

                if (cs > 0) then
                        SET cs = 10 - cs;
                end if;

                if ( cs = substr(pesel,11,1) ) then
                        return 1;
                else
                        return 0;
                end if;

ELSE
	return -1;
END IF;

END
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mvc.emailer.pl/bazy-danych/walidacja-pesel-dla-mysql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Walidacja NIP dla MySQL</title>
		<link>http://mvc.emailer.pl/bazy-danych/walidacja-nip-dla-mysql</link>
		<comments>http://mvc.emailer.pl/bazy-danych/walidacja-nip-dla-mysql#comments</comments>
		<pubDate>Fri, 27 Aug 2010 10:54:20 +0000</pubDate>
		<dc:creator>Radosław Piątek</dc:creator>
				<category><![CDATA[Bazy danych]]></category>

		<guid isPermaLink="false">http://mvc.emailer.pl/?p=46</guid>
		<description><![CDATA[CREATE FUNCTION `valid_nip`(`nip` varchar(255)) RETURNS int(1) READS SQL DATA BEGIN DECLARE cs integer DEFAULT 0; DECLARE m integer DEFAULT 0; DECLARE i integer DEFAULT 0; IF (char_length(nip) = 10) THEN simple_loop: LOOP SET i=i+1; if i in (4) then SET m = 2; elseif i in (5) then SET m = 3; elseif i in [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush:sql">
CREATE FUNCTION `valid_nip`(`nip` varchar(255)) RETURNS int(1)
    READS SQL DATA
BEGIN

DECLARE cs integer DEFAULT 0;
DECLARE m integer  DEFAULT 0;
DECLARE i integer DEFAULT 0;

IF (char_length(nip) = 10) THEN

       simple_loop: LOOP
         SET i=i+1;
                        if i in (4) then
                                SET m = 2;
                        elseif i in (5) then
                                SET m = 3;
                        elseif i in (6) then
                               SET m = 4;
                        elseif i in (2,7) then
                                SET m = 5;
                        elseif i in (1,8) then
                               SET m = 6;
                        elseif i in (3,9) then
                                SET m = 7;
                        end if;
			SET cs = cs + (m * substr(nip,i,1));

         IF i=9 THEN
            LEAVE simple_loop;
         END IF;
       END LOOP simple_loop;

                SET cs = cs % 11;
                if ( cs = substr(nip,10,1) ) then
                        return 1;
                else
                        return 0;
                end if;

ELSE
	return -1;
END IF;

END</pre>
]]></content:encoded>
			<wfw:commentRss>http://mvc.emailer.pl/bazy-danych/walidacja-nip-dla-mysql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Walidacja PESEL dla MSSQL</title>
		<link>http://mvc.emailer.pl/bazy-danych/walidacja-pesel-dla-mssql</link>
		<comments>http://mvc.emailer.pl/bazy-danych/walidacja-pesel-dla-mssql#comments</comments>
		<pubDate>Fri, 27 Aug 2010 10:46:44 +0000</pubDate>
		<dc:creator>Radosław Piątek</dc:creator>
				<category><![CDATA[Bazy danych]]></category>

		<guid isPermaLink="false">http://mvc.emailer.pl/?p=34</guid>
		<description><![CDATA[CREATE FUNCTION valid_pesel( @pesel nvarchar(255) ) RETURNS INTEGER AS BEGIN DECLARE @cs int DECLARE @m int DECLARE @i int DECLARE @res int SET @pesel = cast(@pesel as nvarchar) SET @cs = 0 SET @m = 0 SET @i = 1 IF LEN(@pesel) = 11 begin WHILE (@i 0) SET @cs = 10 - @cs IF [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush:sql">

CREATE FUNCTION valid_pesel( @pesel nvarchar(255) ) RETURNS INTEGER
AS
BEGIN
	DECLARE @cs int
	DECLARE @m int
	DECLARE @i int
	DECLARE @res int
	SET @pesel = cast(@pesel as nvarchar)
	SET @cs = 0
	SET @m = 0
	SET @i = 1
	IF LEN(@pesel) = 11
		begin
			WHILE (@i <= 10)
			BEGIN
                  if @i in (1,5,9) SET @m = 1
                  else if @i in (2,6,10) SET @m = 3
                  else if @i in (3,7) SET @m = 7
                  else if @i in (4,8) SET @m = 9
				  SET @cs = @cs + (@m * SUBSTRING(@pesel,@i,1))
				  SET @i = (@i + 1)
			END
			SET @cs = @cs % 10
            if (@cs > 0) SET @cs = 10 - @cs
			IF ( @cs = SUBSTRING(@pesel,11,1) )
				SET @res = 1
			ELSE
				SET @res = 0
		END
	ELSE
		BEGIN
			SET @res = -1
		END
	RETURN @res
END
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mvc.emailer.pl/bazy-danych/walidacja-pesel-dla-mssql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Walidacja REGON dla MSSQL</title>
		<link>http://mvc.emailer.pl/bazy-danych/walidacja-regon-dla-mssql</link>
		<comments>http://mvc.emailer.pl/bazy-danych/walidacja-regon-dla-mssql#comments</comments>
		<pubDate>Fri, 27 Aug 2010 10:46:01 +0000</pubDate>
		<dc:creator>Radosław Piątek</dc:creator>
				<category><![CDATA[Bazy danych]]></category>

		<guid isPermaLink="false">http://mvc.emailer.pl/?p=32</guid>
		<description><![CDATA[CREATE FUNCTION valid_regon( @regon nvarchar(255) ) RETURNS INTEGER AS BEGIN DECLARE @cs int DECLARE @m int DECLARE @i int DECLARE @res int SET @regon = cast(@regon as nvarchar) SET @cs = 0 SET @m = 0 SET @i = 1 IF LEN(@regon) = 7 BEGIN WHILE (@i &#60;= 6) BEGIN IF @i IN (1) SET [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush:sql">CREATE FUNCTION valid_regon( @regon nvarchar(255) ) RETURNS INTEGER
AS
BEGIN
	DECLARE @cs int
	DECLARE @m int
	DECLARE @i int
	DECLARE @res int
	SET @regon = cast(@regon as nvarchar)
	SET @cs = 0
	SET @m = 0
	SET @i = 1
	IF LEN(@regon) = 7
		BEGIN
			WHILE (@i &lt;= 6)
			BEGIN
                  IF @i IN (1) SET @m = 2
                  ELSE IN @i in (2) SET @m = 3
                  ELSE IN @i in (3) SET @m = 4
                  ELSE IN @i in (4) SET @m = 5
                  ELSE IN @i in (5) SET @m = 6
                  ELSE IN @i in (6) SET @m = 7
				  SET @cs = @cs + (@m * SUBSTRING(@regon,@i,1))
				  SET @i = (@i + 1)
			END
			SET @cs = @cs % 11
			IF ( @cs = SUBSTRING(@regon,7,1) )
				SET @res = 1
			ELSE
				SET @res = 0
		END
	ELSE IF LEN(@regon) = 9
		BEGIN
			WHILE (@i &lt;= <img src='http://mvc.emailer.pl/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' />
			BEGIN
                  IF @i IN (3) SET @m = 2
                  ELSE IF @i IN (4) SET @m = 3
                  ELSE IF @i IN (5) SET @m = 4
                  ELSE IF @i IN (6) SET @m = 5
                  ELSE IF @i IN (7) SET @m = 6
                  ELSE IF @i IN (8) SET @m = 7
                  ELSE IF @i IN (1) SET @m = 8
                  ELSE IF @i IN (2) SET @m = 9
				  SET @cs = @cs + (@m * SUBSTRING(@regon,@i,1))
				  SET @i = (@i + 1)
			END
			SET @cs = @cs % 11
			IF ( @cs = SUBSTRING(@regon,9,1) )
				SET @res = 1
			ELSE
				SET @res = 0
		END
	ELSE IF LEN(@regon) = 14
		BEGIN
			WHILE (@i &lt;= 13)
			BEGIN
                  IF @i IN (1,11) SET @m = 2
                  ELSE IF @i IN (8) SET @m = 3
                  ELSE IF @i IN (2,12) SET @m = 4
                  ELSE IF @i IN (4) SET @m = 5
                  ELSE IF @i IN (9) SET @m = 6
                  ELSE IF @i IN (7) SET @m = 7
                  ELSE IF @i IN (3,13) SET @m = 8
                  ELSE IF @i IN (6) SET @m = 9
                  ELSE IF @i IN (5) SET @m = 0
				  SET @cs = @cs + (@m * SUBSTRING(@regon,@i,1))
				  SET @i = (@i + 1)
			END
			SET @cs = @cs % 11
			IF ( @cs = SUBSTRING(@regon,14,1) )
				SET @res = 1
			ELSE
				SET @res = 0
		END
	ELSE
		BEGIN
			SET @res = -1
		END
	RETURN @res
END</pre>
]]></content:encoded>
			<wfw:commentRss>http://mvc.emailer.pl/bazy-danych/walidacja-regon-dla-mssql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Walidacja NIP dla MSSQL</title>
		<link>http://mvc.emailer.pl/bazy-danych/walidacja-nip-dla-mssql</link>
		<comments>http://mvc.emailer.pl/bazy-danych/walidacja-nip-dla-mssql#comments</comments>
		<pubDate>Fri, 27 Aug 2010 10:45:08 +0000</pubDate>
		<dc:creator>Radosław Piątek</dc:creator>
				<category><![CDATA[Bazy danych]]></category>

		<guid isPermaLink="false">http://mvc.emailer.pl/?p=30</guid>
		<description><![CDATA[CREATE FUNCTION valid_nip( @nip nvarchar(255) ) RETURNS INTEGER AS BEGIN DECLARE @cs int DECLARE @m int DECLARE @i int DECLARE @res int SET @nip = cast(@nip as nvarchar) SET @cs = 0 SET @m = 0 SET @i = 1 IF LEN(@nip) = 10 begin WHILE (@i &#38;lt;= 9) BEGIN if @i in (4) SET [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush:sql">CREATE FUNCTION valid_nip( @nip nvarchar(255) ) RETURNS INTEGER
AS
BEGIN
 DECLARE @cs int
 DECLARE @m int
 DECLARE @i int
 DECLARE @res int
 SET @nip = cast(@nip as nvarchar)
 SET @cs = 0
 SET @m = 0
 SET @i = 1
 IF LEN(@nip) = 10
 begin
 WHILE (@i &amp;lt;= 9)
 BEGIN
 if @i in (4) SET @m = 2
 else if @i in (5) SET @m = 3
 else if @i in (6) SET @m = 4
 else if @i in (2,7) SET @m = 5
 else if @i in (1,8) SET @m = 6
 else if @i in (3,9) SET @m = 7
 SET @cs = @cs + (@m * SUBSTRING(@nip,@i,1))
 SET @i = (@i + 1)
 END
 SET @cs = @cs % 11
 IF ( @cs = SUBSTRING(@nip,10,1) )
 SET @res = 1
 ELSE
 SET @res = 0
 END
 ELSE
 BEGIN
 SET @res = -1
 END
 RETURN @res
END</pre>
]]></content:encoded>
			<wfw:commentRss>http://mvc.emailer.pl/bazy-danych/walidacja-nip-dla-mssql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Walidacja NIP dla Zend Framework</title>
		<link>http://mvc.emailer.pl/zend-framework/walidacja-nip</link>
		<comments>http://mvc.emailer.pl/zend-framework/walidacja-nip#comments</comments>
		<pubDate>Wed, 21 Apr 2010 18:20:00 +0000</pubDate>
		<dc:creator>Radosław Piątek</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://mvc.emailer.pl/?p=1</guid>
		<description><![CDATA[Walidator nipu: tutaj wgrywamy pliczek o nazwie Nip.php do katalogu /zend/Validate/ Kod validatora: /** * Zend Framework * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * [...]]]></description>
			<content:encoded><![CDATA[<p>Walidator nipu:<br />
tutaj wgrywamy pliczek o nazwie Nip.php do katalogu /zend/Validate/<br />
Kod validatora:</p>
<pre class="brush:php">
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Validate
 * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id$
 */ 

/**
 * @see Zend_Validate_Abstract
 */
require_once 'Zend/Validate/Abstract.php'; 

/**
 * @category   Zend
 * @package    Zend_Validate
 * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Validate_Nip extends Zend_Validate_Abstract
{
    /**
     * Validation failure message key for when the value is not of valid length
     */
    const LENGTH   = 'numLength';

    /**
     * Validation failure message key for when the value fails the mod  checksum
     */
    const CHECKSUM = 'numChecksum';

     /**
     * Digits filter for input
     *
     * @var Zend_Filter_Digits
     */
    protected static $_filter = null;

    /**
     * @var array
     */
    protected $_messageTemplates = array(
        self::LENGTH   => "'%value%' must contain 10 digits",
        self::CHECKSUM => "Luhn algorithm (mod-11 checksum) failed on '%value%'"
    ); 

    /**
     * Defined by Zend_Validate_Interface
     *
     * Returns true if and only if $value contains a valid Eividencial namber message
     *
     * @param  string $value
     * @return boolean
     */
    public function isValid($value)
    {

        $this->_setValue($value);

        if (null === self::$_filter) {
            /**
             * @see Zend_Filter_Digits
             */
            require_once 'Zend/Filter/Digits.php';
            self::$_filter = new Zend_Filter_Digits();
        }

        $valueFiltered = self::$_filter->filter($value);

        $length = strlen($valueFiltered);

        if ($length != 10) {
            $this->_error(self::LENGTH);
            return false;
        }

        $mod = 11;
        $sum = 0;
        $weights = array (6, 5, 7, 2, 3, 4, 5, 6, 7);    

        preg_match_all("/\d/", $valueFiltered, $digits) ;

        $valueFilteredArray = $digits[0];        

        foreach ( $valueFilteredArray as $digit )
        {
            $weight = current($weights);
            $sum += $digit * $weight;
            next($weights);
        }

        if ( ( ($sum % $mod == 10) ? 0 : $sum % $mod) != $valueFilteredArray[$length - 1] )
        {
            $this->_error(self::CHECKSUM, $valueFiltered);
            return false;
        }

        return true;
    }
}
</pre>
<p>Wywołanie: </p>
<pre class="brush:php">
        $validator = new Zend_Validate_Nip();
        if (!$validator->isValid('000-00-00-00')) {
            $messages = $validator->getMessages();
            echo current($messages);
        }
</pre>
<p>oczywiscie wlasne komunikaty : stale: numLength, numChecksum przy budowaniu formularzy np. :</p>
<pre class="brush:php">
        $element->setValidators(
                array(
                    array('Nip', true, array(
                        'messages' => array(
                        'numLength' => "'%value%' must contain 10 digits",
                        'numChecksum' => "Luhn algorithm (mod-11 checksum) failed on  %value%'"
                    )))
                ));
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mvc.emailer.pl/zend-framework/walidacja-nip/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Walidacja ISBN dla Zend Framework</title>
		<link>http://mvc.emailer.pl/zend-framework/walidacja-isbn</link>
		<comments>http://mvc.emailer.pl/zend-framework/walidacja-isbn#comments</comments>
		<pubDate>Mon, 23 Nov 2009 10:59:30 +0000</pubDate>
		<dc:creator>Radosław Piątek</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://mvc.emailer.pl/?p=16</guid>
		<description><![CDATA[/** * Zend Framework * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd * If you did not receive a copy of the license and [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush:php">
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Validate
 * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id$
 */ 

/**
 * @see Zend_Validate_Abstract
 */
require_once 'Zend/Validate/Abstract.php'; 

/**
 * Zend_Validate_StringLength
 */

require_once 'Zend/Validate/StringLength.php';

/**
 * Zend_Validate_Digits
 */
require_once 'Zend/Validate/Digits.php';

/**
 * @category   Zend
 * @package    Zend_Validate
 * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Validate_Isbn extends Zend_Validate_Abstract
{
    /**
     * Sets ISBN-10 format
     */
    const ISBN10 = 10;
    const LENGTH10   = 'numLength10';
    const CHECKSUM10 = 'numChecksum10';    

    /**
     * Sets ISBN-13 format
     */
    const ISBN13 = 13;
    const LENGTH13   = 'numLength13';
    const CHECKSUM13 = 'numChecksum13';    

    /**
     * Sets Other Const
     */
    const INVALID_SET = 'invSet';
    const INVALID_CHARACTERS = 'invCharacters';
    const UNKNOWN_VERSION = 'unknownVersion';
    const ISEMPTY = 'isEmpty';
    /**
     * @var array
     */ 

    protected $_messageTemplates = array(
        self::INVALID_SET    => "'%value%' - invalid isbn version set",
        self::ISEMPTY   => "no isbn versions allowed",
        self::UNKNOWN_VERSION   => "unknown ISBN version given",
        self::INVALID_CHARACTERS   => "'%value%' contains invalid characters",
        self::LENGTH10   => "'%value%' must contain 10 digits",
        self::LENGTH13   => "'%value%' must contain 13 digits",
        self::CHECKSUM10 => "Luhn algorithm (mod-11 checksum) failed on '%value%'",
        self::CHECKSUM13 => "Luhn algorithm (mod-11 checksum) failed on '%value%'",
    );

    /**
     * @acces protected
     * @var   integer
     */
    protected $_allowVersionArr = array(
                                        self::ISBN13=>1,
                                        self::ISBN10=>1
                                        );

    /**
     * Sets the allow version.
     *
     * @access public
     * @param  integer $version
     * @return bool
     */
    public function allowVersion($version)
    {
        if (($version != self::ISBN10) &#038;&#038; ($version != self::ISBN13)) {
            $this->_error(self::UNKNOWN_VERSION);
            return false;
        }
        $this->_allowVersionArr[$version] = 1;
        return true;
    }

    /**
     * Sets the allow version.
     *
     * @access public
     * @param  integer $version
     * @return bool
     */
    public function disallowVersion($version)
    {
        if (($version != self::ISBN10) &#038;&#038; ($version != self::ISBN13)) {
            $this->_error(self::UNKNOWN_VERSION);
            return false;
        }
        $this->_allowVersionArr[$version] = 0;
        return true;
    }

    /**
     * Returns true if the given value is a valid ISBN-10 or ISBN-13.
     *
     * @access public
     * @param  string $value
     * @return bool
     */
    public function isValid($value)
    {
        if (array_sum($this->_allowVersionArr) == 0) {
            $this->_error(self::ISEMPTY);
            return false;
        }

        $valueString = (string) $value;
        $return = true;

        // all isbn numbers can start with "ISBN"
        if (substr($valueString,0,4) == 'ISBN') {
            $valueString = substr($valueString, 4);
        }

        // " " and "-" are allowed separators in all isbn numbers
        $valueString = str_replace(array(' ', '-'), '', $valueString);

        // all other chars must be digits
        $digits = new Zend_Validate_Digits();

        if (!$digits->isValid($valueString)) {
            $this->_error(self::INVALID_CHARACTERS, $value);
            $return = false;
        }

        $length = strlen($valueString);

        if ($return === true &#038;&#038; $this->_allowVersionArr[self::ISBN10] &#038;&#038; $length == 10) {
            $return = $this->_validateIsbn10($valueString);
        } elseif ($return === true &#038;&#038; $this->_allowVersionArr[self::ISBN13] &#038;&#038; $length == 13) {
            $return = $this->_validateIsbn13($valueString);
        } else {
            $this->_error(self::INVALID_SET, $value);
            return false;
        }

    }

    /**
     * Validates ISBN-10
     *
     * @access protected
     * @param  string $value
     * @return bool
     */
    protected function _validateIsbn10($value)
    {
        $stringLength = new Zend_Validate_StringLength(10, 10);

        if (!$stringLength->isValid($value)) {
            $this->_error(self::LENGTH10, $value);
            return false;
        }

        $remainder = $value[9];
        $checksum  = 0;

        for ($i=10, $a=0; $i>1; $i--, $a++)
        {
            $digit     = (int) $value[$a];
            $checksum += $digit * $i;
        }

        $valide = ((11 - ($checksum % 11)) == $remainder);

        if (!$valide) {
            $this->_error(self::CHECKSUM10, $value);
        }

        return $valide;
    }

    /**
     * Validates ISBN-13
     *
     * @access protected
     * @param  string $value
     * @return bool
     */
    protected function _validateIsbn13($value)
    {
        $stringLength = new Zend_Validate_StringLength(13, 13);
        if (!$stringLength->isValid($value)) {
            $this->_error(self::LENGTH13, $value);
            return false;
        }

        $remainder = $value[12];
        $checksum  = 0;

        for ($i=0; $i<12; $i++)
        {
            $multi     = (($i % 2) == 1) ? 1 : 3;
            $digit     = (int) $value[$i];
            $checksum += $digit * $multi;
        }

        $valide = ((10 - ($checksum % 10)) == $remainder);

        if (!$valide) {
            $this->_error(self::CHECKSUM13, $value);
        }

        return $valide;
    }

}
</pre>
<pre class="brush:php">
        $validator4 = new Zend_Validate_Isbn();
        if (!$validator4->isValid('0000000000')) {
            $messages4 = $validator4->getMessages();
            echo current($messages4);
        }
</pre>
<pre class="brush:php">
        $element->setValidators(
                array(
                    array('Isbn', true, array(
                        'messages' => array(
                        'numLength' => "'%value%' must contain either 10 or 13 digits",
                        'numChecksum' => "Luhn algorithm (mod-10 checksum) failed on '%value%'"
                    )))
                ));
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mvc.emailer.pl/zend-framework/walidacja-isbn/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Walidacja REGON dla Zend Framework</title>
		<link>http://mvc.emailer.pl/zend-framework/walidacja-regon</link>
		<comments>http://mvc.emailer.pl/zend-framework/walidacja-regon#comments</comments>
		<pubDate>Mon, 23 Nov 2009 10:59:08 +0000</pubDate>
		<dc:creator>Radosław Piątek</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://mvc.emailer.pl/?p=14</guid>
		<description><![CDATA[/** * Zend Framework * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd * If you did not receive a copy of the license and [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush:php">
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Validate
 * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id$
 */ 

/**
 * @see Zend_Validate_Abstract
 */
require_once 'Zend/Validate/Abstract.php'; 

/**
 * @category   Zend
 * @package    Zend_Validate
 * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Validate_Regon extends Zend_Validate_Abstract
{
    /**
     * Validation failure message key for when the value is not of valid length
     */
    const LENGTH   = 'numLength';

    /**
     * Validation failure message key for when the value fails the mod  checksum
     */
    const CHECKSUM = 'numChecksum';

     /**
     * Digits filter for input
     *
     * @var Zend_Filter_Digits
     */
    protected static $_filter = null;

    /**
     * @var array
     */
    protected $_messageTemplates = array(
        self::LENGTH   => "'%value%' must contain either 7, 9 or 14 digits",
        self::CHECKSUM => "Luhn algorithm (mod-11 checksum) failed on '%value%'"
    ); 

    /**
     * Defined by Zend_Validate_Interface
     *
     * Returns true if and only if $value contains a valid Eividencial namber message
     *
     * @param  string $value
     * @return boolean
     */
    public function isValid($value)
    {

        $this->_setValue($value);

        if (null === self::$_filter) {
            /**
             * @see Zend_Filter_Digits
             */
            require_once 'Zend/Filter/Digits.php';
            self::$_filter = new Zend_Filter_Digits();
        }

        $valueFiltered = self::$_filter->filter($value);

        $length = strlen($valueFiltered);

        if ($length != 7 &#038;&#038; $length != 9 &#038;&#038; $length != 14) {
            $this->_error(self::LENGTH);
            return false;
        }

        $mod = 11;
        $sum = 0;
        $weights[7] = array (2, 3, 4, 5, 6, 7);
        $weights[9] = array (8, 9, 2, 3, 4, 5, 6, 7);
        $weights[14] = array (2, 4, 8, 5, 0, 9, 7, 3, 6, 1, 2, 4, 8);

        preg_match_all("/\d/", $valueFiltered, $digits) ;

        $valueFilteredArray = $digits[0];        

        $weights = $weights[$length];
        foreach ( $valueFilteredArray as $digit )
        {
            $weight = current($weights);
            $sum += $digit * $weight;
            next($weights);
        }

        if ( ( ($sum % $mod == 10) ? 0 : $sum % $mod) != $valueFilteredArray[$length - 1] )
        {
            $this->_error(self::CHECKSUM, $valueFiltered);
            return false;
        }

        return true;
    }
}
</pre>
<pre class="brush:php">
        $validator3 = new Zend_Validate_Regon();
        if (!$validator3->isValid('0000000')) {
            $messages3 = $validator3->getMessages();
            echo current($messages3);
        }
</pre>
<pre class="brush:php">
        $element->setValidators(
                array(
                    array('Regon', true, array(
                        'messages' => array(
                        'numLength' => "'%value%' must contain either 7, 9 or 14 digits",
                        'numChecksum' => "Luhn algorithm (mod-11 checksum) failed on '%value%'"
                    )))
                ));
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mvc.emailer.pl/zend-framework/walidacja-regon/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Walidacja PESEL dla Zend Framework</title>
		<link>http://mvc.emailer.pl/zend-framework/walidacja-pesel</link>
		<comments>http://mvc.emailer.pl/zend-framework/walidacja-pesel#comments</comments>
		<pubDate>Mon, 23 Nov 2009 10:58:27 +0000</pubDate>
		<dc:creator>Radosław Piątek</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://mvc.emailer.pl/?p=12</guid>
		<description><![CDATA[/** * Zend Framework * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd * If you did not receive a copy of the license and [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush:php">
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Validate
 * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id$
 */ 

/**
 * @see Zend_Validate_Abstract
 */
require_once 'Zend/Validate/Abstract.php'; 

/**
 * @category   Zend
 * @package    Zend_Validate
 * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Validate_Pesel extends Zend_Validate_Abstract
{
    /**
     * Validation failure message key for when the value is not of valid length
     */
    const LENGTH   = 'numLength';

    /**
     * Validation failure message key for when the value fails the mod  checksum
     */
    const CHECKSUM = 'numChecksum';

     /**
     * Digits filter for input
     *
     * @var Zend_Filter_Digits
     */
    protected static $_filter = null;

    /**
     * @var array
     */
    protected $_messageTemplates = array(
        self::LENGTH   => "'%value%' must contain 11 digits",
        self::CHECKSUM => "Luhn algorithm (mod-10 checksum) failed on '%value%'"
    ); 

    /**
     * Defined by Zend_Validate_Interface
     *
     * Returns true if and only if $value contains a valid Eividencial namber message
     *
     * @param  string $value
     * @return boolean
     */
    public function isValid($value)
    {

        $this->_setValue($value);

        if (null === self::$_filter) {
            /**
             * @see Zend_Filter_Digits
             */
            require_once 'Zend/Filter/Digits.php';
            self::$_filter = new Zend_Filter_Digits();
        }

        $valueFiltered = self::$_filter->filter($value);

        $length = strlen($valueFiltered);

        if ($length != 11) {
            $this->_error(self::LENGTH);
            return false;
        }

        $mod = 10;
        $sum = 0;
        $weights = array (1, 3, 7, 9, 1, 3, 7, 9, 1, 3);    

        preg_match_all("/\d/", $valueFiltered, $digits) ;

        $valueFilteredArray = $digits[0];        

        foreach ( $valueFilteredArray as $digit )
        {
            $weight = current($weights);
            $sum += $digit * $weight;
            next($weights);
        }

        if ( (((10 - ($sum % $mod) == 10) ? 0 : 10) - ($sum % $mod)) != $valueFilteredArray[$length - 1] )
        {
            $this->_error(self::CHECKSUM, $valueFiltered);
            return false;
        }

        return true;
    }
}
</pre>
<pre class="brush:php">
        $validator2 = new Zend_Validate_Pesel();
        if (!$validator2->isValid('00000000000')) {
            $messages2 = $validator2->getMessages();
            echo current($messages2);
        }
</pre>
<pre class="brush:php">
        $element->setValidators(
                array(
                    array('Pesel', true, array(
                        'messages' => array(
                        'numLength' => "'%value%' must contain 10 digits",
                        'numChecksum' => "Luhn algorithm (mod-11 checksum) failed on '%value%'"
                    )))
                ));
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mvc.emailer.pl/zend-framework/walidacja-pesel/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

