1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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($action == "addgroup" && $gid) {
$contactgroup = new ContactGroup($gid, $name);
$contacts->add($contactgroup);
$contacts->write();
$gid = 0;
}
elseif($action == "addcontact" && $gid && $cid) {
$contact = new Contact($cid,
$name,
$address,
$city,
$country,
$phone,
$phone2,
$email,
$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&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();
}
elseif($cid) {
$contact = $contacts->getContact($cid);
$contact->show();
}
elseif($gid) {
$contactgroup = $contacts->getContactGroup($gid);
$contactgroup->show();
form($contacts->getNextCID(),
"?mode=addressbook&action=addcontact&gid=".$gid,
"Add contact");
} else {
$contacts->show();
if($current_user->uid == 0) {
?>
<form method="post" action="?mode=addressbook&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
}
}
?>
|