3 function contacts_init(&$a) {
4 require_once('include/group.php');
5 $a->page['aside'] .= group_side();
7 if($a->config['register_policy'] != REGISTER_CLOSED)
8 $a->page['aside'] .= '<div class="side-invite-link-wrapper" id="side-invite-link-wrapper" ><a href="invite" class="side-invite-link" id="side-invite-link">' . t("Invite Friends") . '</a></div>';
11 function contacts_post(&$a) {
17 $contact_id = intval($a->argv[1]);
21 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
23 intval($_SESSION['uid'])
26 if(! count($orig_record)) {
27 notice("Could not access contact record." . EOL);
28 goaway($a->get_baseurl() . '/contacts');
32 $profile_id = intval($_POST['profile-assign']);
34 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
36 intval($_SESSION['uid'])
39 notice("Cannot locate selected profile." . EOL);
43 $rating = intval($_POST['reputation']);
44 if($rating > 5 || $rating < 0)
47 $reason = notags(trim($_POST['reason']));
49 $r = q("UPDATE `contact` SET `profile-id` = %d, `rating` = %d, `reason` = '%s'
50 WHERE `id` = %d AND `uid` = %d LIMIT 1",
55 intval($_SESSION['uid'])
58 notice("Contact updated." . EOL);
60 notice("Failed to update contact record." . EOL);
67 function contacts_content(&$a) {
70 $_SESSION['sysmsg'] .= "Permission denied." . EOL;
76 $contact_id = intval($a->argv[1]);
82 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
84 intval($_SESSION['uid'])
87 if(! count($orig_record)) {
88 notice("Could not access contact record." . EOL);
89 goaway($a->get_baseurl() . '/contacts');
94 // $photo = str_replace('-4.jpg', '' , $r[0]['photo']);
95 // $photos = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d",
97 // intval($_SESSION['uid'])
100 if($cmd == 'block') {
101 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
102 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
105 intval($_SESSION['uid'])
108 $msg = "Contact has been " . (($blocked) ? '' : 'un') . "blocked." . EOL ;
111 goaway($a->get_baseurl() ."/contacts/$contact_id");
112 return; // NOTREACHED
116 $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
118 intval($_SESSION['uid']));
120 // if(count($photos)) {
121 // foreach($photos as $p) {
122 // q("DELETE FROM `photos` WHERE `id` = %d LIMIT 1",
127 if(intval($contact_id))
128 q("DELETE FROM `item` WHERE `contact-id` = %d LIMIT 1",
132 notice("Contact has been removed." . EOL );
133 goaway($a->get_baseurl() . '/contacts');
134 return; // NOTREACHED
138 if(($a->argc == 2) && intval($a->argv[1])) {
140 $contact_id = intval($a->argv[1]);
141 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
146 notice("Contact not found.");
150 require_once('view/contact_selectors.php');
152 $tpl = file_get_contents("view/contact_edit.tpl");
155 if(strlen($r[0]['issued-id'])) {
156 if(strlen($r[0]['dfrn-id'])) {
157 $direction = DIRECTION_BOTH;
158 $dir_icon = 'images/lrarrow.gif';
159 $alt_text = 'Mutual Friendship';
162 $direction = DIRECTION_IN;
163 $dir_icon = 'images/larrow.gif';
164 $alt_text = 'is a fan of yours';
168 $direction = DIRECTION_OUT;
169 $dir_icon = 'images/rarrow.gif';
170 $alt_text = 'you are a fan of';
173 $o .= replace_macros($tpl,array(
174 '$profile_select' => contact_profile_assign($r[0]['profile-id']),
175 '$contact_id' => $r[0]['id'],
176 '$block_text' => (($r[0]['blocked']) ? 'Unblock this contact' : 'Block this contact' ),
177 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">Currently blocked</div>' : ''),
178 '$rating' => contact_reputation($r[0]['rating']),
179 '$reason' => $r[0]['reason'],
180 '$groups' => '', // group_selector(),
181 '$photo' => $r[0]['photo'],
182 '$name' => $r[0]['name'],
183 '$dir_icon' => $dir_icon,
184 '$alt_text' => $alt_text,
185 '$url' => (($direction != DIRECTION_IN) ? "redir/{$r[0]['id']}" : $r[0]['url'] )
193 if(($a->argc == 2) && ($a->argv[1] == 'all'))
196 $sql_extra = " AND `blocked` = 0 ";
198 $tpl = file_get_contents("view/contacts-top.tpl");
199 $o .= replace_macros($tpl,array(
200 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
201 '$hide_text' => ((strlen($sql_extra)) ? 'Show Blocked Connections' : 'Hide Blocked Connections')
205 case DIRECTION_BOTH :
206 $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` != '' ";
209 $sql_extra2 = " AND `dfrn-id` = '' AND `issued-id` != '' ";
212 $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` = '' ";
220 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
221 intval($_SESSION['uid']));
225 $tpl = file_get_contents("view/contact_template.tpl");
231 if(strlen($rr['issued-id'])) {
232 if(strlen($rr['dfrn-id'])) {
233 $direction = DIRECTION_BOTH;
234 $dir_icon = 'images/lrarrow.gif';
235 $alt_text = 'Mutual Friendship';
238 $direction = DIRECTION_IN;
239 $dir_icon = 'images/larrow.gif';
240 $alt_text = 'is a fan of yours';
244 $direction = DIRECTION_OUT;
245 $dir_icon = 'images/rarrow.gif';
246 $alt_text = 'you are a fan of';
249 $o .= replace_macros($tpl, array(
251 '$alt_text' => $alt_text,
252 '$dir_icon' => $dir_icon,
253 '$thumb' => $rr['thumb'],
254 '$name' => $rr['name'],
255 '$url' => (($direction != DIRECTION_IN) ? "redir/{$rr['id']}" : $rr['url'] )