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 // if(count($photos)) {
118 // foreach($photos as $p) {
119 // q("DELETE FROM `photos` WHERE `id` = %d LIMIT 1",
124 if(intval($contact_id))
125 q("DELETE FROM `item` WHERE `contact-id` = %d LIMIT 1",
129 notice("Contact has been removed." . EOL );
130 goaway($a->get_baseurl() . '/contacts');
131 return; // NOTREACHED
135 if(($a->argc == 2) && intval($a->argv[1])) {
137 $contact_id = intval($a->argv[1]);
138 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
143 notice("Contact not found.");
147 require_once('view/contact_selectors.php');
149 $tpl = file_get_contents("view/contact_edit.tpl");
152 if(strlen($r[0]['issued-id'])) {
153 if(strlen($r[0]['dfrn-id'])) {
154 $direction = DIRECTION_BOTH;
155 $dir_icon = 'images/lrarrow.gif';
156 $alt_text = 'Mutual Friendship';
159 $direction = DIRECTION_IN;
160 $dir_icon = 'images/larrow.gif';
161 $alt_text = 'is a fan of yours';
165 $direction = DIRECTION_OUT;
166 $dir_icon = 'images/rarrow.gif';
167 $alt_text = 'you are a fan of';
170 $o .= replace_macros($tpl,array(
171 '$profile_select' => contact_profile_assign($r[0]['profile-id']),
172 '$contact_id' => $r[0]['id'],
173 '$block_text' => (($r[0]['blocked']) ? 'Unblock this contact' : 'Block this contact' ),
174 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">Currently blocked</div>' : ''),
175 '$rating' => contact_reputation($r[0]['rating']),
176 '$reason' => $r[0]['reason'],
177 '$groups' => '', // group_selector(),
178 '$photo' => $r[0]['photo'],
179 '$name' => $r[0]['name'],
180 '$dir_icon' => $dir_icon,
181 '$alt_text' => $alt_text,
182 '$url' => (($direction != DIRECTION_IN) ? "redir/{$r[0]['id']}" : $r[0]['url'] )
190 if(($a->argc == 2) && ($a->argv[1] == 'all'))
193 $sql_extra = " AND `blocked` = 0 ";
195 $tpl = file_get_contents("view/contacts-top.tpl");
196 $o .= replace_macros($tpl,array(
197 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
198 '$hide_text' => ((strlen($sql_extra)) ? 'Show Blocked Connections' : 'Hide Blocked Connections')
202 case DIRECTION_BOTH :
203 $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` != '' ";
206 $sql_extra2 = " AND `dfrn-id` = '' AND `issued-id` != '' ";
209 $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` = '' ";
217 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
218 intval($_SESSION['uid']));
222 $tpl = file_get_contents("view/contact_template.tpl");
228 if(strlen($rr['issued-id'])) {
229 if(strlen($rr['dfrn-id'])) {
230 $direction = DIRECTION_BOTH;
231 $dir_icon = 'images/lrarrow.gif';
232 $alt_text = 'Mutual Friendship';
235 $direction = DIRECTION_IN;
236 $dir_icon = 'images/larrow.gif';
237 $alt_text = 'is a fan of yours';
241 $direction = DIRECTION_OUT;
242 $dir_icon = 'images/rarrow.gif';
243 $alt_text = 'you are a fan of';
246 $o .= replace_macros($tpl, array(
248 '$alt_text' => $alt_text,
249 '$dir_icon' => $dir_icon,
250 '$thumb' => $rr['thumb'],
251 '$name' => $rr['name'],
252 '$url' => (($direction != DIRECTION_IN) ? "redir/{$rr['id']}" : $rr['url'] )