<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
if(!isset($_SESSION)){
session_start();
}
//----------------------------- danbank daten honzugeben ------------------------------
$dbhost = 'localhost';
$dbuser = 'test';
$dbpass = '+++++';
$dbname = '++++++';
$mysqli = mysqli_connect($dbhost, $dbuser, $dbpass,$dbname);
require ('includes/application_top.php');
// create smarty elements
$smarty = new Smarty;
require (DIR_WS_INCLUDES.'header.php');
// include boxes
require (DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/source/boxes.php');
//use perso_check.php language file
require_once (DIR_WS_LANGUAGES.$_SESSION['language'].'/persocheck.php');
$breadcrumb->add('Personalausweis Check', xtc_href_link('perso_check.php', '', 'SSL'));
var_dump($_SESSION);
if(isset($_SESSION['customer_id']) AND isset($_SESSION['customer_email_address'])){
?>
Neuer Personalausweis:<br>
<form action="?check=1" method="post" >
IDD << <input value="L7LY61T641" type="text" size="10" maxlength="10" name="ida"><<<<<<<<<<<<<<<<<br>
<input value="8012104" type="text" size="7" maxlength="7" name="idb"> < <input value="2409238d"type="text" size="8" maxlength="8" name="idc"><<<<<<<<<<<input value="8" type="text" size="1" maxlength="1" name="idd"> <br>
<input type="submit" value="überprüfen">
</form>
<br><hr><br>
Alter Personalausweis:<br>
<form action="?check=1" method="post" >
<input type="text" size="11" maxlength="11" name="ida"><<
<input type="text" size="7" maxlength="7" name="idb"><
<input type="text" size="7" maxlength="7" name="idc"><<<<<
<input type="text" size="1" maxlength="1" name="idd"> <br>
<input type="submit" value="überprüfen">
</form>
<?php
}else{
die("Du mußt eingeloggtsein um die Personalausweis Daten anzugeben!!<br><a href='#'>Login Url angeben</a>");
}
//---------------------------------------------- Ab hier das perso script unverändert , bis aufdie üaar zeilen die hinzu kamen mit der datenabnk
function check_number($id, $checknumber) {
$p = 7;
$sum = 0;
for($i=0; $i < strlen($id); $i++) {
$char = $id{$i};
if($char >= '0' && $char <= '9')
$int = intval($char);
else
$int = ord($char)-55;
$sum += $int*$p;
if($p==1)
$p=7;
else if($p==3)
$p=1;
else if($p==7)
$p=3;
}
$last_number = substr(strval($sum), -1);
return $last_number == $checknumber;
}
//Gibt die Art (neu vs. alt) des Personalausweis zurück
function perso_type($id) {
$splits = explode(" ", strtoupper($id));
if(strlen($splits[0]) == 11 && strlen($splits[1]) == 7 && strlen($splits[2]) == 7 && strlen($splits[3]) == 1) {
return 'old';
} else if(strlen($splits[0]) == 10 && strlen($splits[1]) == 7 && strlen($splits[2]) == 8 && strlen($splits[3]) == 1) {
return 'new';
} else {
return 'unknown';
}
}
//Sind die Prüfziffern gültig
function perso_checksum($id) {
$splits = explode(" ", strtoupper($id));
$checksums = array();
$perso_type = perso_type($id);
if($perso_type == 'unknown') {
return false;
}
$checksums[] = array(substr($splits[0],0,9), substr($splits[0],9,1));
$checksums[] = array(substr($splits[1],0,6), substr($splits[1],6,1));
$checksums[] = array(substr($splits[2],0,6), substr($splits[2],6,1));
$checksums[] = array(substr($splits[0],0,10).substr($splits[1],0,7).substr($splits[2],0,7), $splits[3]);
//Überprüfung der Checksummen
foreach($checksums as $checksum) {
if(!check_number($checksum[0], $checksum[1])) {
return false;
}
}
return true;
}
//Ist der Perso noch gültig?
function perso_gueltig($id) {
$splits = explode(" ", $id);
$valid_until = mktime(0,0,0, substr($splits[2], 2, 2) , substr($splits[2], 4, 2) , "20".substr($splits[2], 0, 2));
//Ist der Perso noch gültig
if(time() > $valid_until)
return false;
return true;
}
//Informationen aus dem Perso beziehen
function perso_info($id) {
$splits = explode(" ", $id);
//$return: Ein Objekt mit den Daten aus der Ausweisnummer
$return = new stdClass();
$return->perso_type = perso_type($id);
$return->geb = new stdClass();
$return->geb->tag= $splits[1]{4} . $splits[1]{5}; //Geburtstag
$return->geb->monat = $splits[1]{2} . $splits[1]{3}; //Geburtsmonat
$return->geb->jahr = $splits[1]{0} . $splits[1]{1}; //Geburtsjahr
if($return->geb->jahr > intval(date("y"))) {
$return->geb->jahr = "19".$return->geb->jahr;
} else {
$return->geb->jahr = "20".$return->geb->jahr;
}
$alter = date("Y") - $return->geb->jahr;
//Hatte er schon Geburtstag?
if( (date("n") < $return->geb->monat) OR (date("n") == $return->geb->monat AND date("j") < $return->geb->tag) ) {
$alter--;
}
$return->alter = $alter;
if($alter >= 18) {
$return->volljaehrig = true;
} else {
$return->volljaehrig = false;
}
$return->ablauf = new stdClass();
$return->ablauf->tag = $splits[2]{4} . $splits[2]{5}; //Ausweis Ablauf Tag
$return->ablauf->monat = $splits[2]{2} . $splits[2]{3}; //Ausweis Ablauf Monat
$return->ablauf->jahr = "20".$splits[2]{0} . $splits[2]{1}; //Ausweis Ablauf Jahr
if($return->perso_type == 'old') {
$return->herkunft = $splits[0]{10};
} else {
$return->herkunft = $splits[2]{7};
}
//Ein Deutscher?
if(strtolower($return->herkunft) == "d") {
$return->deutscher = true;
} else {
$return->deutscher = false;
}
//Behördenkennzahl als Nummer
$return->behoerdenkennzahl = substr($splits[0], 0, 4);
return $return;
}
//Beispiel zur Verwendung
if(isset($_GET['check'])) {
$perso_id = $_POST['ida']." ".$_POST['idb']." ".$_POST['idc']." ".$_POST['idd'];
if(perso_checksum($perso_id)) {
echo "Personalausweisnummer korrekt!";
//------------------------------------------------------------------------------- Das kamhinzu -------------------------------
$id_der_eingelogt_ist = $mysqli->real_escape_string($_SESSION['customer_id']);
$email_der_eingelogt_ist = $mysqli->real_escape_string($_SESSION['customer_email_address']);
if(! $mysqli ) {
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully<br>';
$sql = "UPDATE customers SET customers_status='6' WHERE customers_id='$id_der_eingelogt_ist' AND customers_email_address='$email_der_eingelogt_ist'";
if (mysqli_query($mysqli, $sql)) {
echo 'status geändert auf 6 für Personalausweiß Gruppe<br>';
echo 'ID = '.htmlspecialchars($id_der_eingelogt_ist).'<br>';
echo 'Email = '.htmlspecialchars($email_der_eingelogt_ist);
} else {
echo "Error updating record: " . mysqli_error($conn);
}
//---------------------------------------------------------------------------------------------------------------------------------
if(!perso_gueltig($perso_id)) {
echo "<br> <b>Perso ist abgelaufen!</b>";
}
echo "<br><br> Daten der Ausweisnummer: <pre>";
$data = perso_info($perso_id);
print_r($data);
echo "</pre>";
} else {
echo "Personalausweisnummer falsch!<br><br>";
}
}
//---------------------------------------------------------------------------------------------------------------------------------
$smarty->assign('language', $_SESSION['language']);
$smarty->caching = 0;
$main_content = $smarty->fetch(CURRENT_TEMPLATE.'/module/perso_check.html');
$smarty->assign('main_content',$main_content);
$smarty->caching = 0;
if(!defined(RM)) $smarty->load_filter('output', 'note');
$smarty->display(CURRENT_TEMPLATE.'/index.html');
include ('includes/application_bottom.php');
?>