<?php
if (isset($_POST['login_username'])) { $user = $_POST['login_username']; }
else { $user = $_COOKIE['wmusername']; }
$bookdir = "../data/".$user."/";
$pend = "!</div></div></body></html>";
$cerr = "Error creating address book ";
if (!file_exists($bookdir)) { @mkdir($bookdir,0777) or die($cerr."contacts directory".$pend); }
if (!file_exists($bookdir."index.php")) {
touch($bookdir."index.php") or die($cerr."contacts index".$pend); }
if (file_get_contents($bookdir."index.php") == "") {
file_put_contents($bookdir."index.php","<"."?php header('Location: ../index.php'); ?".">"); }
if (!file_exists($bookdir."groups.php")) {
touch($bookdir."groups.php") or die($cerr."groups index".$pend);
$content = "<"."?php\r";
$content .= "$"."group_names = array();\r";
$content .= "$"."group_files = array();\r";
$content .= "?".">";
file_put_contents($bookdir."groups.php",$content); }
function isFriend($name,$address) {
$bookdir = "../data/".$_COOKIE['wmusername']."/";
$found = "";
$contacts = array();
$handle = opendir($bookdir);
$skip = array(".","..","index.php","backups","groups.php","security.php","thumbs.db","desktop.ini",".DS_Store","_notes");
while($file = readdir($handle)) { if (!in_array($file,$skip)) { array_push($contacts,$file); }}
if (count($contacts) > 0) {
for ($k=0; $k<count($contacts); $k++) {
include($bookdir.$contacts[$k]);
if ($address != "") {
if (($emailhome == $address) || ($emailwork == $address)) {
$found = $uniqueid;
$k = count($contacts); }}}}
$name_array = explode(" ",$name);
switch(count($name_array)) {
case "1":
$isemail = explode("@",$name);
if (count($isemail) == 1) { $f = $name; }
else { $f = "0"; }
$m = "0";
$l = "0"; break;
case "2":
$f = $name_array[0];
$m = "0";
$l = $name_array[1]; break;
default:
$f = $name_array[0];
$m = $name_array[1];
$l = end($name_array); }
if ($f == "") { $f = "0"; }
if ($found == "") { return "<a onfocus='this.blur();' style='font-weight: normal;' href='contacts.php?new=".$address."&f=".$f."&m=".$m."&l=".$l."'>ADD</a>"; }
else { return "<a onfocus='this.blur();' style='font-weight: normal;' href='contacts.php?view=".$found."'>VIEW</a>"; }
}
?>