3 function contacts_init(&$a) {
4 require_once('include/group.php');
5 $a->page['aside'] .= group_side();
8 function contacts_post(&$a) {
14 $contact_id = intval($a->argv[1]);
18 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
20 intval($_SESSION['uid'])
23 if(! count($orig_record)) {
24 notice("Could not access contact record." . EOL);
25 goaway($a->get_baseurl() . '/contacts');
29 $profile_id = intval($_POST['profile-assign']);
31 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
33 intval($_SESSION['uid'])
36 notice("Cannot locate selected profile." . EOL);
40 $rating = intval($_POST['reputation']);
41 if($rating > 5 || $rating < 0)
44 $reason = notags(trim($_POST['reason']));
46 $r = q("UPDATE `contact` SET `profile-id` = %d, `rating` = %d, `reason` = '%s'
47 WHERE `id` = %d AND `uid` = %d LIMIT 1",
52 intval($_SESSION['uid'])
55 notice("Contact updated." . EOL);
57 notice("Failed to update contact record." . EOL);
64 function contacts_content(&$a) {
67 $_SESSION['sysmsg'] .= "Permission denied." . EOL;
73 $contact_id = intval($a->argv[1]);
79 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
81 intval($_SESSION['uid'])
84 if(! count($orig_record)) {
85 notice("Could not access contact record." . EOL);
86 goaway($a->get_baseurl() . '/contacts');
91 $photo = str_replace('-4.jpg', '' , $r[0]['photo']);
92 $photos = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d",
94 intval($_SESSION['uid'])
98 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
99 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
102 intval($_SESSION['uid'])
105 $msg = "Contact has been " . (($blocked) ? '' : 'un') . "blocked." . EOL ;
108 goaway($a->get_baseurl() ."/contacts/$contact_id");
109 return; // NOTREACHED
113 $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
115 intval($_SESSION['uid']));
117 foreach($photos as $p) {
118 q("DELETE FROM `photos` WHERE `id` = %d LIMIT 1",
122 if($intval($contact_id))
123 q("DELETE FROM `item` WHERE `contact-id` = %d LIMIT 1",
127 notice("Contact has been removed." . EOL );
128 goaway($a->get_baseurl() . '/contacts');
129 return; // NOTREACHED
133 if(($a->argc == 2) && intval($a->argv[1])) {
135 $contact_id = intval($a->argv[1]);
136 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
141 notice("Contact not found.");
145 require_once('view/contact_selectors.php');
147 $tpl = file_get_contents("view/contact_edit.tpl");
150 if(strlen($r[0]['issued-id'])) {
151 if(strlen($r[0]['dfrn-id'])) {
152 $direction = DIRECTION_BOTH;
153 $dir_icon = 'images/lrarrow.gif';
154 $alt_text = 'Mutual Friendship';
157 $direction = DIRECTION_IN;
158 $dir_icon = 'images/larrow.gif';
159 $alt_text = 'is a fan of yours';
163 $direction = DIRECTION_OUT;
164 $dir_icon = 'images/rarrow.gif';
165 $alt_text = 'you are a fan of';
168 $o .= replace_macros($tpl,array(
169 '$profile_select' => contact_profile_assign($r[0]['profile-id']),
170 '$contact_id' => $r[0]['id'],
171 '$block_text' => (($r[0]['blocked']) ? 'Unblock this contact' : 'Block this contact' ),
172 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">Currently blocked</div>' : ''),
173 '$rating' => contact_reputation($r[0]['rating']),
174 '$reason' => $r[0]['reason'],
175 '$groups' => '', // group_selector(),
176 '$photo' => $r[0]['photo'],
177 '$name' => $r[0]['name'],
178 '$dir_icon' => $dir_icon,
179 '$alt_text' => $alt_text,
180 '$url' => (($direction != DIRECTION_IN) ? "redir/{$r[0]['id']}" : $r[0]['url'] )
188 if(($a->argc == 2) && ($a->argv[1] == 'all'))
191 $sql_extra = " AND `blocked` = 0 ";
193 $tpl = file_get_contents("view/contacts-top.tpl");
194 $o .= replace_macros($tpl,array(
195 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
196 '$hide_text' => ((strlen($sql_extra)) ? 'Show Blocked Connections' : 'Hide Blocked Connections')
200 case DIRECTION_BOTH :
201 $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` != '' ";
204 $sql_extra2 = " AND `dfrn-id` = '' AND `issued-id` != '' ";
207 $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` = '' ";
215 $r = q("SELECT * FROM `contact` WHERE `uid` = %d $sql_extra $sql_extra2 ",
216 intval($_SESSION['uid']));
220 $tpl = file_get_contents("view/contact_template.tpl");
226 if(strlen($rr['issued-id'])) {
227 if(strlen($rr['dfrn-id'])) {
228 $direction = DIRECTION_BOTH;
229 $dir_icon = 'images/lrarrow.gif';
230 $alt_text = 'Mutual Friendship';
233 $direction = DIRECTION_IN;
234 $dir_icon = 'images/larrow.gif';
235 $alt_text = 'is a fan of yours';
239 $direction = DIRECTION_OUT;
240 $dir_icon = 'images/rarrow.gif';
241 $alt_text = 'you are a fan of';
244 $o .= replace_macros($tpl, array(
246 '$alt_text' => $alt_text,
247 '$dir_icon' => $dir_icon,
248 '$thumb' => $rr['thumb'],
249 '$name' => $rr['name'],
250 '$url' => (($direction != DIRECTION_IN) ? "redir/{$rr['id']}" : $rr['url'] )