2 function edit_contact(&$a,$contact_id) {
6 function contacts_post(&$a) {
12 $contact_id = intval($a->argv[1]);
17 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
19 intval($_SESSION['uid'])
22 if(! count($orig_record)) {
23 notice("Could not access contact record." . EOL);
24 goaway($a->get_baseurl() . '/contacts');
28 $profile_id = intval($_POST['profile-assign']);
30 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
32 intval($_SESSION['uid'])
35 notice("Cannot locate selected profile." . EOL);
39 $rating = intval($_POST['reputation']);
40 if($rating > 5 || $rating < 0)
43 $reason = notags(trim($_POST['reason']));
45 $r = q("UPDATE `contact` SET `profile-id` = %d, `rating` = %d, `reason` = '%s'
46 WHERE `id` = %d AND `uid` = %d LIMIT 1",
51 intval($_SESSION['uid'])
54 notice("Contact updated." . EOL);
56 notice("Failed to update contact record." . EOL);
71 function contacts_content(&$a) {
74 $_SESSION['sysmsg'] .= "Permission denied." . EOL;
82 $contact_id = intval($a->argv[1]);
88 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
90 intval($_SESSION['uid'])
93 if(! count($orig_record)) {
94 notice("Could not access contact record." . EOL);
95 goaway($a->get_baseurl() . '/contacts');
100 $photo = str_replace('-4.jpg', '' , $r[0]['photo']);
101 $photos = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d",
103 intval($_SESSION['uid'])
106 if($cmd == 'block') {
107 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
108 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
111 intval($_SESSION['uid'])
114 $msg = "Contact has been " . (($blocked) ? '' : 'un') . "blocked." . EOL ;
117 goaway($a->get_baseurl() ."/contacts/$contact_id");
118 return; // NOTREACHED
122 $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
124 intval($_SESSION['uid']));
126 foreach($photos as $p) {
127 q("DELETE FROM `photos` WHERE `id` = %d LIMIT 1",
131 if($intval($contact_id))
132 q("DELETE FROM `item` WHERE `contact-id` = %d LIMIT 1",
136 notice("Contact has been removed." . EOL );
137 goaway($a->get_baseurl() . '/contacts');
138 return; // NOTREACHED
142 if(($a->argc == 2) && intval($a->argv[1])) {
144 $contact_id = intval($a->argv[1]);
145 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
150 notice("Contact not found.");
154 require_once('view/contact_selectors.php');
156 $tpl = file_get_contents("view/contact_edit.tpl");
159 if(strlen($r[0]['issued-id'])) {
160 if(strlen($r[0]['dfrn-id'])) {
161 $direction = DIRECTION_BOTH;
162 $dir_icon = 'images/lrarrow.gif';
163 $alt_text = 'Mutual Friendship';
166 $direction = DIRECTION_IN;
167 $dir_icon = 'images/larrow.gif';
168 $alt_text = 'is a fan of yours';
172 $direction = DIRECTION_OUT;
173 $dir_icon = 'images/rarrow.gif';
174 $alt_text = 'you are a fan of';
177 $o .= replace_macros($tpl,array(
178 '$profile_select' => contact_profile_assign($r[0]['profile-id']),
179 '$contact_id' => $r[0]['id'],
180 '$block_text' => (($r[0]['blocked']) ? 'Unblock this contact' : 'Block this contact' ),
181 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">Currently blocked</div>' : ''),
182 '$rating' => contact_reputation($r[0]['rating']),
183 '$reason' => $r[0]['reason'],
184 '$groups' => '', // group_selector(),
185 '$photo' => $r[0]['photo'],
186 '$name' => $r[0]['name'],
187 '$dir_icon' => $dir_icon,
188 '$alt_text' => $alt_text
196 if(($a->argc == 2) && ($a->argv[1] == 'all'))
199 $sql_extra = " AND `blocked` = 0 ";
201 $tpl = file_get_contents("view/contacts-top.tpl");
202 $o .= replace_macros($tpl,array(
203 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
204 '$hide_text' => ((strlen($sql_extra)) ? 'Show Blocked Connections' : 'Hide Blocked Connections')
208 case DIRECTION_BOTH :
209 $sql_extra = " AND `dfrn-id` != '' AND `issued-id` != '' ";
212 $sql_extra = " AND `dfrn-id` = '' AND `issued-id` != '' ";
215 $sql_extra = " AND `dfrn-id` != '' AND `issued-id` = '' ";
223 $r = q("SELECT * FROM `contact` WHERE `uid` = %d $sql_extra",
224 intval($_SESSION['uid']));
228 $tpl = file_get_contents("view/contact_template.tpl");
234 if(strlen($rr['issued-id'])) {
235 if(strlen($rr['dfrn-id'])) {
236 $direction = DIRECTION_BOTH;
237 $dir_icon = 'images/lrarrow.gif';
238 $alt_text = 'Mutual Friendship';
241 $direction = DIRECTION_IN;
242 $dir_icon = 'images/larrow.gif';
243 $alt_text = 'is a fan of yours';
247 $direction = DIRECTION_OUT;
248 $dir_icon = 'images/rarrow.gif';
249 $alt_text = 'you are a fan of';
252 $o .= replace_macros($tpl, array(
254 '$alt_text' => $alt_text,
255 '$dir_icon' => $dir_icon,
256 '$thumb' => $rr['thumb'],
257 '$name' => $rr['name'],
258 '$url' => (($direction != DIRECTION_IN) ? "redir/{$rr['id']}" : $rr['url'] )