Location: PHPKode > scripts > MyPhonebook > myphonebook/myphonebook-1.0.1/process.php
<?php


if (get_magic_quotes_gpc()) {



$name = strip_tags($_POST['name']);
$fname = strip_tags($_POST['fname']);
$company = strip_tags($_POST['company']);
$address = strip_tags($_POST['address']);
$city = strip_tags($_POST['city']);
$state = strip_tags($_POST['state']);
$plz = strip_tags($_POST['plz']);
$country = strip_tags($_POST['country']);
$phone = $_POST['phone'];
$mobile =$_POST['mobile'];
$fax = $_POST['fax'];
$officephone = $_POST['officephone'];
$email = $_POST['email'];
$website = htmlentities($_POST['website']);
$annotations = htmlentities($_POST['annotations']);

} else {

$name = strip_tags(str_replace("'","",($_POST['name'])));
$fname = strip_tags(str_replace("'","",($_POST['fname'])));
$company = strip_tags(str_replace("'","",($_POST['company'])));
$address = strip_tags(str_replace("'","",($_POST['address'])));
$city = strip_tags(str_replace("'","",($_POST['city'])));
$state = strip_tags(str_replace("'","",($_POST['state'])));
$plz = strip_tags($_POST['plz']);
$country = strip_tags(str_replace("'","",($_POST['country'])));
$phone = $_POST['phone'];
$mobile =$_POST['mobile'];
$fax = $_POST['fax'];
$officephone = $_POST['officephone'];
$email = $_POST['email'];
$website = htmlentities(str_replace("'","",($_POST['website'])));
$annotations = htmlentities(str_replace("'","",($_POST['annotations'])));

}

if (preg_match('([^\+-.0-9])',$phone)) {
echo "Please enter a valid phone number";
echo "<br>";
echo "<a href=\"index.php\" target=\"_parent\">Go Back</a>";
exit;

}

if (preg_match('([^\+-.0-9])',$fax)) {
echo "Please enter a valid mobile number";
echo "<br>";
echo "<a href=\"index.php\" target=\"_parent\">Go Back</a>";
exit;

}

if (preg_match('([^\+-.0-9])',$mobile)) {
echo "Please enter a valid fax number";
echo "<br>";
echo "<a href=\"index.php\" target=\"_parent\">Go Back</a>";
exit;

}

if (preg_match('([^\+-.0-9])',$officephone)) {
echo "Please enter a valid office phone number";
echo "<br>";
echo "<a href=\"index.php\" target=\"_parent\">Go Back</a>";
exit;

}

if (preg_match('([^\-0-9a-zA-Z])',$plz)) {
echo "Please enter a valid Postal ( ZIP ) Code";
echo "<br>";
echo "<a href=\"index.php\" target=\"_parent\">Go Back</a>";
exit;

}

if ($email) {

if (! preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i',$email)) {

echo "Please enter a valid email address";
echo "<br>";
echo "<a href=\"index.php\" target=\"_parent\">Go Back</a>";
exit;

}
}

//variabel fichier définéiren

$data = 'data/';
$data2 = 'data2/';
$applic ='.php';
$userfile = $data . trim($name) . trim($fname) . $applic;
$userfile2 = $data2 . trim($name) . trim($fname) . $applic;
$user2 = '2';
$user3 = '3';
$userfile3 = trim($name) . trim($fname) .$user2 . $applic;
$userfile4 = trim($name) . trim($fname) .$user3 . $applic;
$includes = trim($name) . trim($fname) . $applic;




//Check op eidel Felder

if (strlen($fname=="" || $fname =="" || $name =="")) {

echo "Missing Field Data, First Name and Last Name are mandatory";
echo "<br>";
echo "<a href=\"index.php\" target=\"_parent\">Go Back</a>";
exit;

}else{



//fichier créieren a schreiwen
$entry = '<?php';
$entry1 = '$user[]= "';
$entry2 ="<tr><td> $name &nbsp </td><td>$fname &nbsp</td><td>$company &nbsp</td><td> $phone &nbsp </td><td> $mobile &nbsp </td><td> $fax &nbsp </td><td><a href='mailto:$email'>$email</a> &nbsp </td> <td> <a href='$userfile2' target='_blank'>Details</a> </td> <td> <a href='$userfile3' target='iframe'>Modify</a></td> <td> <a href='$userfile4' target='iframe'>Delete</a> </td></tr>";
$entry3 ='";';
$entry4 = '$name=' . "'$name'; \n";
$entry5 = '$fname=' . "'$fname'; \n";
$entry5b = '$company=' . "'$company'; \n";
$entry6 = '$address=' . "'$address'; \n";
$entry7 = '$city=' . "'$city'; \n";
$entry8 = '$state=' . "'$state'; \n";
$entry9 = '$plz=' . "'$plz'; \n";
$entry10 = '$phone=' . "'$phone'; \n";
$entry11 = '$mobile=' . "'$mobile'; \n";
$entry12 = '$fax=' . "'$fax'; \n";
$entry13 = '$officephone=' . "'$officephone'; \n";
$entry14 = '$email=' . "'$email'; \n";
$entry15 = '$website=' . "'$website'; \n";
$entry16 = '$annotations=' . "'$annotations'; \n";
$entry17 = '?>';



if (! file_exists($userfile)) {

$open2 = fopen('data/includes.php','ab');
fwrite($open2,"<?php include'$includes'; ?> \n");
fclose($open2);

}


if (file_exists($userfile)) {
$content = file_get_contents($userfile);

if (trim(strlen($content)) > 1 ) {
echo "This Contact already exists";
echo "<br>";
echo "<a href=\"index.php\" target=\"_parent\">Go Back</a>";
exit;

}
}


$open = fopen("$userfile",'wb');

fwrite($open,"$entry $entry1 $entry2 $entry3 \n $entry4 $entry5 $entry5b $entry6 $entry7 $entry8 $entry9 $entry10 $entry11 $entry12 $entry13 $entry14 $entry15 $entry16 $entry17");
fclose($open);



//HTML aschreiwen

$open3 = fopen("$userfile2",'wb');
fwrite($open3,"

<html>
<head><link rel='stylesheet' type='text/css' href='style.css'>
</head>
<body>
<table cellpadding=4 width=400><tr>
<td align= right>Name:</td><td>$name</td>
</tr><tr>
<td align= right>First Name:</td><td>$fname</td>
</tr><tr>
<td align= right>Company:</td><td>$company</td>
</tr><tr>
<td align= right>Address:</td><td>$address</td>
</tr><tr>
<td align= right>City:</td><td>$city</td>
</tr><tr>
<td align= right>State:</td><td>$state</td>
</tr><tr>
<td align= right>Zip Code:</td><td>$plz</td>
</tr><tr>
<td align= right>Phone:</td><td>$phone</td>
</tr><tr>
<td align= right>Mobile:</td><td>$mobile</td>
</tr><tr>
<td align= right>Fax:</td><td>$fax</td>
</tr><tr>
<td align= right>Phone Office:</td><td>$officephone</td>
</tr><tr>
<td align= right>Email:</td><td>$email</td>
</tr><tr>
<td align= right>Website:</td><td>$website</td>
</tr></table>
<table wdth=400 cellpading=4>
<tr>
<td>Annotations:<br>
$annotations</td></tr></table>
</body>
</html>");

fclose($open3);




//HTML Modificatioun Fichier schreiwen

$open4 = fopen("$userfile3",'wb');
fwrite($open4,"

<?php

include'$userfile';

print <<<FORM


<html>
<head>

<link rel='stylesheet' type='text/css' href='style.css'>

</head>

<body>


<div align='center'>

<h3>Modify Contact $name $fname</h3>

<form action='process2.php' method='POST'>


<table align='center'>
<tr>
<td>



<table cellpadding=3 align='left'>


<tr>
<td align='right'>Company:</td>
<td><input type='text' name='company' style='width:250px;' value='$company'></td>
</tr>


<tr>
<td align='right'>Address:</td>
<td><input type='text' name='address' value='$address' style='width:250px;'></td>
</tr>


<tr>
<td align='right'>City:</td>
<td><input type='text' name='city' value='$city' style='width:250px;'></td>
</tr>


<tr>
<td align='right'>State:</td>
<td><input type='text' name='state' value='$state' style='width:250px;'></td>
</tr>


<tr>
<td align='right'>Postal Code:</td>
<td><input type='text' name='plz' value='$plz' style='width:100px;'></td>
</tr>


<tr>
<td align='right'>Country:</td>
<td><input type='text' name='country' value='$country' style='width:250px;'></td>
</tr>



<tr>
<td align='right' style='visibility:hidden;'>Name:</td>
<td><input type='text' name='name' style='width:250px; visibility:hidden;' value='$name'></td>
</tr>

<tr>
<td align='right' style='visibility:hidden;'>First Name:</td>
<td><input type='text' name='fname' style='width:250px; visibility:hidden;' value='$fname'></td>
</tr>



</table>

</td>

<td valign='top'>




<table cellpadding=3 align='left'>
<tr>
<td align='right'>Phone:</td>
<td><input type='text' name='phone' value='$phone' style='width:250px;'></td>
</tr>


<tr>
<td align='right'>Fax:</td>
<td><input type='text' name='fax' value='$fax' style='width:250px;'></td>
</tr>

<tr>
<td align='right'>Mobile:</td>
<td><input type='text' name='mobile' value='$mobile' style='width:250px;'></td>
</tr>

<tr>
<td align='right'>Office Phone:</td>
<td><input type='text' name='officephone' value='$officephone' style='width:250px;'></td>
</tr>

<tr>
<td align='right'>Email Address:</td>
<td><input type='text' name='email' value='$email' style='width:250px;'></td>
</tr>

<tr>
<td align='right'>Website:</td>
<td><input type='text' name='website' value='$website' style='width:250px;'></td>
</tr>


</table>

</td></tr></table>

Annotations:<br>
<textarea cols='55' rows='7' name='annotations'>$annotations</textarea>
<br>
<input type='submit' value=' Register Data'> &nbsp; &nbsp; <input type='reset' value='Reset'></td></tr></table>
</form>
</body>
</html>







FORM;

?>");

fclose($open4);









//HTML Delete Fichier Géneréieren

$open5 = fopen("$userfile4",'wb');
fwrite($open5,"

<?php

include'$userfile';

print <<<FORM2


<html>
<head>

<link rel='stylesheet' type='text/css' href='style.css'>

</head>

<body>


<div align='center'>

<h3>Really Delete $name $fname</h3>

<form action='process3.php' method='POST'>
<input type='text' name='name' value='$name'style='visibility:hidden;'>
<input type='text' name='fname' value='$fname' style='visibility:hidden;'>
<div align='center'>
<input type='submit' value=' Delete Contact'>
</form>



FORM2;

?>");

fclose($open5);






}


?>



<script language="JavaScript">
parent.location.replace('index.php');
</script>

Return current item: MyPhonebook