diff options
Diffstat (limited to 'forum/utils/contacts.php')
-rw-r--r-- | forum/utils/contacts.php | 201 |
1 files changed, 159 insertions, 42 deletions
diff --git a/forum/utils/contacts.php b/forum/utils/contacts.php index cec6bd7..bd59d16 100644 --- a/forum/utils/contacts.php +++ b/forum/utils/contacts.php @@ -1,73 +1,159 @@ <?php include_once($UTIL_DIR . "/convert.php"); +include_once($UTIL_DIR . "/parser.php"); class Contact { public $cid; public $name; public $address; + public $city; + public $country; public $phone; public $phone2; public $email; + public $email2; public $url; + public $url2; + public $essential; + public $notes; public function write($fp) { - fwrite($fp, " <contact cid=\"" . htmlspecialchars($this->cid, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " name=\"" . htmlspecialchars($this->name, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " address=\"" . htmlspecialchars($this->address, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " phone=\"" . htmlspecialchars($this->phone, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " phone2=\"" . htmlspecialchars($this->phone2, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " email=\"" . htmlspecialchars($this->email, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " url=\"" . htmlspecialchars($this->url, ENT_QUOTES, "UTF-8") . "\">\n"); - fwrite($fp, " </contact>\n"); + fwrite($fp, " <contact cid=\"" . convert_xml($this->cid, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " name=\"" . convert_xml($this->name, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " address=\"" . convert_xml($this->address, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " city=\"" . convert_xml($this->city, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " country=\"" . convert_xml($this->country, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " phone=\"" . convert_xml($this->phone, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " phone2=\"" . convert_xml($this->phone2, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " email=\"" . convert_xml($this->email, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " email2=\"" . convert_xml($this->email2, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " url=\"" . convert_xml($this->url, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " url2=\"" . convert_xml($this->url2, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " essential=\"" . convert_xml($this->essential, ENT_QUOTES, "UTF-8") . "\">"); + fwrite($fp, convert_xml($this->notes, ENT_QUOTES, "UTF-8")); + fwrite($fp, "</contact>\n"); } public function show() { echo "<p>\n"; - echo "\tcid: " . $this->cid . "<br/>"; + // echo "\tcid: " . $this->cid . "<br/>"; echo "\tname: " . $this->name . "<br/>"; echo "\taddress: " . $this->address . "<br/>"; + echo "\tcity: " . $this->city . "<br/>"; + echo "\tcountry: " . $this->country . "<br/>"; echo "\tphone: " . $this->phone . "<br/>"; - if($this->phone2) echo "\tphone2: " . $this->phone2 . "<br/>"; + echo "\tphone2: " . $this->phone2 . "<br/>"; echo "\temail: <a href=\"mailto:" . $this->email . "\">" . $this->email . "</a><br/>"; + echo "\temail2: <a href=\"mailto:" . $this->email2 . "\">" . $this->email2 . "</a><br/>"; echo "\turl: <a href=\"" . $this->url . "\">" . $this->url . "</a><br/>"; + echo "\turl2: <a href=\"" . $this->url2 . "\">" . $this->url2 . "</a><br/>"; + echo "\tnotes: " . parse($this->notes) . "<br/>"; + echo "\t<a href=\"?mode=addressbook&action=editcontact&cid=" . $this->cid . "\">Edit</a>\n"; echo "</p>\n"; } public function showshort() { - echo "<div class\"contact\"><a href=\"?mode=addressbook&cid=" . $this->cid . "\">" . $this->name . "</a></div>"; + echo "<div class=\"contact\"><a href=\"?mode=addressbook&cid=" . $this->cid . "\">" . $this->name . "</a></div>"; } - function Contact($cid, - $name, - $address, - $phone, - $phone2, - $email, - $url) + function Contact($cid, $name, $address, $city, $country, $phone, $phone2, $email, $email2, $url, $url2, $essential, $notes) { $this->cid = $cid; $this->name = $name; $this->address = $address; + $this->city = $city; + $this->country = $country; $this->phone = $phone; $this->phone2 = $phone2; $this->email = $email; + $this->email2 = $email2; $this->url = $url; + $this->url2 = $url2; + $this->essential = $essential; + $this->notes = $notes; + } +} + +class ContactGroup { + public $gid; + public $name; + private $contacts = array(); + + public function getContact($cid) + { + return $this->contacts[$cid]; + } + + public function write($fp) { + fwrite($fp, " <contactgroup gid=\"" . convert_xml($this->gid, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " name=\"" . convert_xml($this->name, ENT_QUOTES, "UTF-8") . "\">\n"); + + foreach($this->contacts as $contact) { + $contact->write($fp); + } + + fwrite($fp, " </contactgroup>\n"); + } + + public function getMaxCID() + { + $maxcid = 1; + foreach($this->contacts as $contact) { + if($maxcid < $contact->cid) $maxcid = $contact->cid; + } + return $maxcid; + } + + public function add($contact) { + $key = $contact->cid; + $this->contacts[$key] = $contact; + } + + public function show() + { + echo " <div class=\"contactgroup\">\n"; + echo " <div class=\"title\">" . $this->name . "</div>\n"; + echo " <div class=\"contacts\">\n"; + foreach($this->contacts as $contact) { + $contact->showshort(); + } + echo " </div>\n"; + echo " </div>\n"; + } + + public function showshort() + { + echo " <div class=\"contactgroup\">\n"; + echo " <div class=\"title\"><a href=\"?mode=addressbook&gid=" . $this->gid . "\">" . $this->name . "</a></div>\n"; + echo " <div class=\"contacts\">\n"; + foreach($this->contacts as $contact) { + if($contact->essential) $contact->showshort(); + } + echo " </div>\n"; + echo " </div>\n"; + } + + function ContactGroup($gid, + $name) + { + $this->gid = $gid; + $this->name = $name; } } class Contacts { private $file; - private $contacts = array(); + private $contactgroups = array(); public function show() { echo "<div class=\"contactlist\">\n"; - foreach($this->contacts as $contact) { - $contact->showshort(); + foreach($this->contactgroups as $contactgroup) { + $contactgroup->showshort(); } echo "</div>\n"; } @@ -75,20 +161,38 @@ class Contacts { public function getNextCID() { $nextcid = 1; - foreach($this->contacts as $contact) { - if($nextcid < $contact->cid) $nextcid = $contact->cid; + foreach($this->contactgroups as $contactgroup) { + $cid = $contactgroup->getMaxCID(); + if($nextcid < $cid) $nextcid = $cid; } - return $nextcid; + return $nextcid + 1; + } + + public function getNextGID() + { + $nextgid = 1; + foreach($this->contactgroups as $contactgroup) { + if($nextgid < $contactgroup->gid) $nextgid = $contactgroup->gid; + } + return $nextgid + 1; } public function getContact($cid) { - return $this->contacts[$cid]; + foreach($this->contactgroups as $contactgroup) { + if($contactgroup->getContact($cid)) return $contactgroup->getContact($cid); + } + return false; } - public function add($contact) { - $key = $contact->cid; - $this->contacts[$key] = $contact; + public function getContactGroup($gid) + { + return $this->contactgroups[$gid]; + } + + public function add($contactgroup) { + $key = $contactgroup->gid; + $this->contactgroups[$key] = $contactgroup; } public function write() @@ -101,8 +205,8 @@ class Contacts { fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); fwrite($fp, "<contacts>\n"); - foreach($this->contacts as $contact) { - $contact->write($fp); + foreach($this->contactgroups as $contactgroup) { + $contactgroup->write($fp); } fwrite($fp, "</contacts>\n"); @@ -113,19 +217,32 @@ class Contacts { { $dom = new DomDocument; - $dom->preserveWhiteSpace = FALSE; + $dom->preserveWhiteSpace = TRUE; $dom->load($this->file); - $params = $dom->getElementsByTagName('contact'); - - foreach ($params as $param) { - $contact = new Contact($param->getAttribute('cid'), - $param->getAttribute('name'), - $param->getAttribute('address'), - $param->getAttribute('phone'), - $param->getAttribute('phone2'), - $param->getAttribute('email'), - $param->getAttribute('url')); - $this->add($contact); + $contactgroups = $dom->getElementsByTagName('contactgroup'); + + foreach ($contactgroups as $cg) { + $contactgroup = new ContactGroup($cg->getAttribute('gid'), + $cg->getAttribute('name')); + + $contacts = $cg->getElementsByTagName('contact'); + foreach ($contacts as $c) { + $contact = new Contact($c->getAttribute('cid'), + $c->getAttribute('name'), + $c->getAttribute('address'), + $c->getAttribute('city'), + $c->getAttribute('country'), + $c->getAttribute('phone'), + $c->getAttribute('phone2'), + $c->getAttribute('email'), + $c->getAttribute('email2'), + $c->getAttribute('url'), + $c->getAttribute('url2'), + $c->getAttribute('essential'), + $c->textContent); + $contactgroup->add($contact); + } + $this->add($contactgroup); } } |