<?php
$backup_fail = false;
$cerr = "Error creating address book ";
$contacts = array();
$handle = opendir($bookdir);
$skip = array(".","..","index.php","backups","thumbs.db","desktop.ini",".DS_Store","_notes");
while($file = readdir($handle)) {
if (!in_array($file,$skip)) { array_push($contacts,$file); }}
if (count($contacts) == 0) { $backup_fail = true; }
else {
$content = "";
foreach ($contacts as $b) {
include($bookdir.$b);
$content .= $uniqueid."+++";
$content .= file_get_contents($bookdir.$b)."***"; }
$content = str_replace(">***2",">===2",$content);
$content = str_replace("***","",$content);
$backups = $bookdir."backups/";
if (!file_exists($backups)) { @mkdir($backups,0777) or die($cerr."backup directory"); }
if (!file_exists($backups."index.php")) { touch($backups."index.php") or die($cerr."backup index"); }
if (file_get_contents($backups."index.php") == "") {
file_put_contents($backups."index.php","<"."?php header('Location: ../index.php'); ?".">"); }
if (!file_exists($backups.".htaccess")) { touch($backups.".htaccess") or die($cerr."backup .htaccess"); }
if (file_get_contents($backups.".htaccess") == "") {
file_put_contents($backups.".htaccess","Allow from All"); }
$date = date("YmdHis");
$file = $backups."backup_".$date.".zip";
touch($file);
$content = $foo->encode($content,$default_key);
file_put_contents($file,$content); }
header("Location: ./contacts.php");
?>