<?php
$name = '';
$iddoc = '';
$number = '';
$customer = '';
$SQL = "SELECT * FROM customerdb WHERE ID > 0";
$query = mysqli_query($mysqli_conn, $SQL) or error($SQL);
if (mysqli_num_rows($query) > 0) {
$vcardname = "VCard.vcf";
$vcard = fopen($vcardname, "w") or die("Cannot Open file! Check permissions?");
while ($c = mysqli_fetch_array($query)) {
$customer = $c['ID'];
$CCustomer = new customer($customer);
if ($CCustomer->Exists()) {
$number = $CCustomer->getTelephone();
$email = $CCustomer->getEmail();
$name = $CCustomer->getName(false);
$Fname = $CCustomer->getFirstName();
$Lname = $CCustomer->getLastName();
$address1 = $CCustomer->getAddress1();
$address2 = $CCustomer->getAddress2();
$town = $CCustomer->getTown();
$postcode = $CCustomer->getPostcode();
$region = $CCustomer->getRegion();
fwrite($vcard, "BEGIN:VCARD\r\n");
fwrite($vcard, "VERSION:3.0\r\n");
fwrite($vcard, "FN:{$name} (C-{$customer})\r\n");
fwrite($vcard, "N:{$Lname};{$Fname} (C-{$customer});;\r\n");
fwrite($vcard, "TEL;TYPE=cell:{$number}\r\n");
fwrite($vcard, "EMAIL:{$email}\r\n");
fwrite($vcard, "ADR;TYPE=home:;;{$address1};{$town};{$region};{$postcode};\r\n");
fwrite($vcard, "END:VCARD\r\n");
}
}
if (file_exists($vcardname)) {
echo "<meta http-equiv=\"refresh\" target=\"_blank\" content=\"0;url=$vcardname\">";
}
}
?>