spatiere master
spatiere

--- a/js/cnp.html
+++ b/js/cnp.html
@@ -1,31 +1,31 @@
 <html>
 <head>
 <script type="text/javascript">
-    function verificaCNP ($cnp) {
-        if ( $cnp.length != 13 ) {
-            return false;
-        }
-        
-        var $s = $cnp[0]*2+$cnp[1]*7+$cnp[2]*9+$cnp[3]*1+$cnp[4]*4+$cnp[5]*6+$cnp[6]*3+$cnp[7]*5+$cnp[8]*8+$cnp[9]*2+$cnp[10]*7+$cnp[11]*9;
-        var $rest = $s%11;
-        if ( $rest >= 10 ) {$rest=1};
-        if ( $cnp[12] == $rest ) {
-            return true;
-        } else {
-            return false;
-        }
-    }
+	function verificaCNP ($cnp) {
+		if ( $cnp.length != 13 ) {
+			return false;
+		}
+
+		var $s = $cnp[0]*2+$cnp[1]*7+$cnp[2]*9+$cnp[3]*1+$cnp[4]*4+$cnp[5]*6+$cnp[6]*3+$cnp[7]*5+$cnp[8]*8+$cnp[9]*2+$cnp[10]*7+$cnp[11]*9;
+		var $rest = $s%11;
+		if ( $rest >= 10 ) {$rest=1};
+		if ( $cnp[12] == $rest ) {
+			return true;
+		} else {
+			return false;
+		}
+	}
 </script>
 </head>
 <body>
 
 <script type="text/javascript">
-    var $cnp = "2851210278792";
-    if ( verificaCNP ( $cnp ) ) {
-        alert ($cnp+" e valid");
-    } else {
-        alert ($cnp+" e invalid");
-    }
+	var $cnp = "2851210278792";
+	if ( verificaCNP ( $cnp ) ) {
+		alert ($cnp+" e valid");
+	} else {
+		alert ($cnp+" e invalid");
+	}
 </script>
 </body>
 </html>

--- a/php/cnp.php
+++ b/php/cnp.php
@@ -1,7 +1,6 @@
 <?php
 
 /*
-
 Validare de CNP
 
 1) se calculeaza suma
@@ -12,31 +11,29 @@
 - rest<10 at c(13)=rest
 sau
 - rest=10 at c(13)=1
+*/
 
+function verificaCNP ($cnp) {
+	if ( strlen ($cnp) != 13 ) {
+		return false;
+	}
 
-*/
+	$s = $cnp{0}*2+$cnp{1}*7+$cnp{2}*9+$cnp{3}*1+$cnp{4}*4+$cnp{5}*6+$cnp{6}*3+$cnp{7}*5+$cnp{8}*8+$cnp{9}*2+$cnp{10}*7+$cnp{11}*9;
+	$rest = $s%11;
+	if ( $rest >= 10 ) $rest=1;
+	if ( $cnp{12} == $rest ) {
+		return true;
+	} else {
+		return false;
+	}
+}
 
 $cnp = "2851210278792";
 
 if ( verificaCNP ( $cnp ) ) {
-    echo $cnp." e valid";
+	echo $cnp." e valid";
 } else {
-    echo $cnp." e invalid";
-}
-
-function verificaCNP ($cnp) {
-    if ( strlen ($cnp) != 13 ) {
-        return false;
-    }
-    
-    $s = $cnp{0}*2+$cnp{1}*7+$cnp{2}*9+$cnp{3}*1+$cnp{4}*4+$cnp{5}*6+$cnp{6}*3+$cnp{7}*5+$cnp{8}*8+$cnp{9}*2+$cnp{10}*7+$cnp{11}*9;
-    $rest = $s%11;
-    if ( $rest >= 10 ) $rest=1;
-    if ( $cnp{12} == $rest ) {
-        return true;
-    } else {
-        return false;
-    }
+	echo $cnp." e invalid";
 }
 
 ?>

--- a/php/cui.php
+++ b/php/cui.php
@@ -1,30 +1,30 @@
-<?php 
+<?php
+
+function verificaCui ($cif) {
+	if ( !is_numeric ($cif) ) return false;
+	if ( strlen ($cif)>10 ) return false;
+	$cifra_control = substr ($cif, -1);
+	$cif = substr ($cif, 0, -1);
+	while (strlen ($cif)!=9) {
+		$cif = '0'.$cif;
+	}
+	$suma = $cif[0] * 7 + $cif[1] * 5 + $cif[2] * 3 + $cif[3] * 2 + $cif[4] * 1 + $cif[5] * 7 + $cif[6] * 5 + $cif[7] * 3 + $cif[8] * 2;
+	$suma = $suma*10;
+	$rest = fmod ($suma, 11);
+	if ( $rest == 10 ) $rest = 0;
+	if ( $rest == $cifra_control ) {
+		return true;
+	} else {
+		return false;
+	}
+}
 
 $cui = "2864518";
 
 if ( verificaCui ( $cui ) ) {
-    echo $cui." e valid";
+	echo $cui." e valid";
 } else {
-    echo $cui." e invalid";
-}
-
-function verificaCui ($cif) {
-    if (!is_numeric($cif)) return false;
-    if ( strlen($cif)>10 ) return false;
-    $cifra_control=substr($cif, -1);
-    $cif=substr($cif, 0, -1);
-    while (strlen($cif)!=9){
-        $cif='0'.$cif;
-    }
-    $suma=$cif[0] * 7 + $cif[1] * 5 + $cif[2] * 3 + $cif[3] * 2 + $cif[4] * 1 + $cif[5] * 7 + $cif[6] * 5 + $cif[7] * 3 + $cif[8] * 2;
-    $suma=$suma*10;
-    $rest=fmod($suma, 11);
-    if ( $rest==10 ) $rest=0;
-    if ( $rest == $cifra_control ) {
-        return true;
-    } else {
-        return false;
-    }
+	echo $cui." e invalid";
 }
 
 ?>

comments