summaryrefslogtreecommitdiff
path: root/forum/utils/addressbook.php
diff options
context:
space:
mode:
authordeva <deva>2008-10-26 12:29:38 +0000
committerdeva <deva>2008-10-26 12:29:38 +0000
commit4bc99c18ecbbb7bb7d0fac4592fcc63e3c568798 (patch)
tree5b0523c6111ec9ed061d30f13917318d18c19322 /forum/utils/addressbook.php
parent007967b96763a0f5a0165f34af28005fa65bcf01 (diff)
We now have a functional but very ugly addressbook.
Diffstat (limited to 'forum/utils/addressbook.php')
-rw-r--r--forum/utils/addressbook.php134
1 files changed, 115 insertions, 19 deletions
diff --git a/forum/utils/addressbook.php b/forum/utils/addressbook.php
index 43477dd..29b0fb0 100644
--- a/forum/utils/addressbook.php
+++ b/forum/utils/addressbook.php
@@ -1,41 +1,137 @@
<?php
include_once($UTIL_DIR . "/contacts.php");
+function form($cid,
+ $posturl,
+ $buttontext,
+ $name = "",
+ $address = "",
+ $city = "",
+ $country = "",
+ $phone = "",
+ $phone2 = "",
+ $email = "",
+ $email2 = "",
+ $url = "",
+ $url2 = "",
+ $essential = "",
+ $notes = "")
+{
+?>
+<form method="post" action="<?php echo $posturl; ?>">
+ <input type="hidden" name="cid" value="<?php echo $cid;?>">
+ Name: <input name="name" value="<?php echo $name;?>"><br/>
+ Address: <input name="address" value="<?php echo $address;?>"><br/>
+ City: <input name="city" value="<?php echo $city;?>"><br/>
+ Country: <input name="country" value="<?php echo $country;?>"><br/>
+ Phone: <input name="phone" value="<?php echo $phone;?>"><br/>
+ Phone2: <input name="phone2" value="<?php echo $phone2;?>"><br/>
+ Email: <input name="email" value="<?php echo $email;?>"><br/>
+ Email2: <input name="email2" value="<?php echo $email2;?>"><br/>
+ URL: <input name="url" value="<?php echo $url;?>"><br/>
+ URL2: <input name="url2" value="<?php echo $url2;?>"><br/>
+ Essential: <input type="checkbox" name="essential" <?php if($essential == "on") echo " checked";?>><br/>
+ Notes:<br/>
+ <textarea name="notes" cols="60" rows="10"><?php echo $notes;?></textarea><br/>
+ <button type="submit"><?php echo $buttontext; ?></button>
+</form>
+<?php
+}
+
+
$contacts = new Contacts($DATA_DIR . "/contacts.xml");
-if($cid && $name) {
- // Edit
- $contact = new Contact($cid,
- $name,
- $address,
- $phone,
- $phone2,
- $email,
- $url);
- $contacts->add($contact);
+if($action == "addgroup" && $gid) {
+ $contactgroup = new ContactGroup($gid, $name);
+ $contacts->add($contactgroup);
$contacts->write();
-} elseif($name) {
- // Add
- $cid = $contacts->getNextCID();
+ $gid = 0;
+}
+
+elseif($action == "addcontact" && $gid && $cid) {
$contact = new Contact($cid,
$name,
$address,
+ $city,
+ $country,
$phone,
$phone2,
$email,
- $url);
- $contacts->add($contact);
+ $email2,
+ $url,
+ $url2,
+ $essential,
+ $notes);
+ $contactgroup = $contacts->getContactGroup($gid);
+ $contactgroup->add($contact);
+ $contacts->write();
+ $cid = 0;
+}
+
+elseif($action =="editcontact" && $cid) {
+ $contact = $contacts->getContact($cid);
+ form($contact->cid,
+ "?mode=addressbook&amp;action=updatecontact".$gid,
+ "Update contact",
+ $contact->name,
+ $contact->address,
+ $contact->city,
+ $contact->country,
+ $contact->phone,
+ $contact->phone2,
+ $contact->email,
+ $contact->email2,
+ $contact->url,
+ $contact->url2,
+ $contact->essential,
+ $contact->notes);
+}
+
+elseif($action == "updatecontact" && $cid) {
+ $contact = $contacts->getContact($cid);
+
+ $contact->name = $name;
+ $contact->address = $address;
+ $contact->city = $city;
+ $contact->country = $country;
+ $contact->phone = $phone;
+ $contact->phone2 = $phone2;
+ $contact->email = $email;
+ $contact->email2 = $email2;
+ $contact->url = $url;
+ $contact->url2 = $url2;
+ $contact->essential = $essential;
+ $contact->notes = $notes;
+
$contacts->write();
+
+ $contact->show();
}
-if($cid) {
+elseif($cid) {
$contact = $contacts->getContact($cid);
$contact->show();
-} else {
- $contacts->show();
+}
+
+elseif($gid) {
+ $contactgroup = $contacts->getContactGroup($gid);
+ $contactgroup->show();
- // TODO: Editorbox for adding new contact
+ form($contacts->getNextCID(),
+ "?mode=addressbook&amp;action=addcontact&amp;gid=".$gid,
+ "Add contact");
+} else {
+ $contacts->show();
+ if($current_user->uid == 0) {
+?>
+<form method="post" action="?mode=addressbook&amp;action=addgroup">
+ <input type="hidden" name="gid" value="<?php echo $contacts->getNextGID();?>">
+ Name: <input name="name" value="">
+ <button type="submit">Add group</button>
+</form>
+<?php
+ }
}
?> \ No newline at end of file