session_set_cookie_params(SESSION_TIME); session_start(); $idutente = null; if(isset($_SESSION['idutente'])) { $idutente = $_SESSION['idutente']; } #### FUNZIONI ## function login($username,$password) { global $idutente, $db; $query = "select id,nome,cognome,email from utentiweb where username='$username' and password='".md5($password)."' and attivo=1 limit 0,1"; $stmt = $db->prepare($query); $stmt->execute(); if($stmt->rowCount() > 0) { $nomecol = $stmt->fetch(); $_SESSION['idutente'] = $idutente = $nomecol[0]; $_SESSION['nome'] = $nomecol[1]; $_SESSION['cognome'] = $nomecol[2]; $_SESSION['email'] = $nomecol[3]; $login = true; } else $login = false; return $login; } function logout() { global $idutente; $idutente = null; $_SESSION['idutente'] = null; } ## END FUNZIONI ## ?> ## FUNZIONI ## function formattaStringaDb($str) { return utf8_decode(rawurldecode(stripslashes($str))); } function formattaStringaToDb($str) { return utf8_encode(addslashes($str)); } function get_include_contents($filename) { global $lang,$idutente,$idordine,$user,$login,$cart,$articolo; if (is_file($filename)) { ob_start(); include $filename; $contents = ob_get_contents(); ob_end_clean(); return $contents; } return false; } function generatePassword ($length=8) { $password = ""; $possible = "0123456789bcdfghjkmnpqrstvwxyz"; $i = 0; while ($i < $length) { $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); if (!strstr($password, $char)) { $password .= $char; $i++; } } return $password; } function getIva() { global $db; $query = "select valore from settaggi where nome='iva' limit 1;"; $stmt = $db->prepare($query); $stmt->execute(); $nomecol = $stmt->fetch(); return $nomecol['valore']; } function ControlloCodiceFiscale($cf) { if( $cf == '' ) return false; if( strlen($cf) != 16 ) return false; $cf = strtoupper($cf); if( ! ereg("^[A-Z0-9]+$", $cf) ){ return false; } $s = 0; for( $i = 1; $i <= 13; $i += 2 ){ $c = $cf[$i]; if( '0' <= $c && $c <= '9' ) $s += ord($c) - ord('0'); else $s += ord($c) - ord('A'); } for( $i = 0; $i <= 14; $i += 2 ){ $c = $cf[$i]; switch( $c ){ case '0': $s += 1; break; case '1': $s += 0; break; case '2': $s += 5; break; case '3': $s += 7; break; case '4': $s += 9; break; case '5': $s += 13; break; case '6': $s += 15; break; case '7': $s += 17; break; case '8': $s += 19; break; case '9': $s += 21; break; case 'A': $s += 1; break; case 'B': $s += 0; break; case 'C': $s += 5; break; case 'D': $s += 7; break; case 'E': $s += 9; break; case 'F': $s += 13; break; case 'G': $s += 15; break; case 'H': $s += 17; break; case 'I': $s += 19; break; case 'J': $s += 21; break; case 'K': $s += 2; break; case 'L': $s += 4; break; case 'M': $s += 18; break; case 'N': $s += 20; break; case 'O': $s += 11; break; case 'P': $s += 3; break; case 'Q': $s += 6; break; case 'R': $s += 8; break; case 'S': $s += 12; break; case 'T': $s += 14; break; case 'U': $s += 16; break; case 'V': $s += 10; break; case 'W': $s += 22; break; case 'X': $s += 25; break; case 'Y': $s += 24; break; case 'Z': $s += 23; break; } } if( chr($s%26 + ord('A')) != $cf[15] ) return false; return true; } function ControlloPIVA($pi){ if( $pi == '' ) return false; if( strlen($pi) != 11 ) return false; if( ! ereg("^[0-9]+$", $pi) ) return false; $s = 0; for( $i = 0; $i <= 9; $i += 2 ) $s += ord($pi[$i]) - ord('0'); for( $i = 1; $i <= 9; $i += 2 ){ $c = 2*( ord($pi[$i]) - ord('0') ); if( $c > 9 ) $c = $c - 9; $s += $c; } if( ( 10 - $s%10 )%10 != ord($pi[10]) - ord('0') ) return false; return true; } function TagliaStringa($stringa, $max_char){ $stringa = strip_tags($stringa); if(strlen($stringa)>$max_char){ $stringa_tagliata=substr($stringa, 0,$max_char); $last_space=strrpos($stringa_tagliata," "); $stringa_ok=substr($stringa_tagliata, 0,$last_space); return $stringa_ok.'...'; }else{ return $stringa; } } function codeLang($lang) { switch($lang) { case "ita": $res = 1; break; case "eng": $res = 2; break; case "fra": $res = 3; break; case "ger": $res = 5; break; case "spa": $res = 4; break; } return $res; } ###### ?>