]> git.mxchange.org Git - friendica.git/blob - mod/contacts.php
38b49475ac890ce7dbe297cfd7f7cc42984a908e
[friendica.git] / mod / contacts.php
1 <?php
2 function edit_contact(&$a,$contact_id) {
3
4 }
5
6 function contacts_post(&$a) {
7
8         
9         if(! local_user())
10                 return;
11
12         $contact_id = intval($a->argv[1]);
13         if(! $contact_id)
14                 return;
15 dbg(2);
16 print_r($_POST);
17         $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
18                 intval($contact_id),
19                 intval($_SESSION['uid'])
20         );
21
22         if(! count($orig_record)) {
23                 notice("Could not access contact record." . EOL);
24                 goaway($a->get_baseurl() . '/contacts');
25                 return; // NOTREACHED
26         }
27
28         $profile_id = intval($_POST['profile-assign']);
29         if($profile_id) {
30                 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
31                         intval($profile_id),
32                         intval($_SESSION['uid'])
33                 );
34                 if(! count($r)) {
35                         notice("Cannot locate selected profile." . EOL);
36                         return;
37                 }
38         }
39         $rating = intval($_POST['reputation']);
40         if($rating > 5 || $rating < 0)
41                 $rating = 0;
42
43         $reason = notags(trim($_POST['reason']));
44
45         $r = q("UPDATE `contact` SET `profile-id` = %d, `rating` = %d, `reason` = '%s'
46                 WHERE `id` = %d AND `uid` = %d LIMIT 1",
47                 intval($profile_id),
48                 intval($rating),
49                 dbesc($reason),
50                 intval($contact_id),
51                 intval($_SESSION['uid'])
52         );
53         if($r)
54                 notice("Contact updated." . EOL);
55         else
56                 notice("Failed to update contact record." . EOL);
57         return;
58
59 }
60
61
62
63
64
65
66
67
68
69
70
71 function contacts_content(&$a) {
72
73         if(! local_user()) {
74                 $_SESSION['sysmsg'] .= "Permission denied." . EOL;
75                 return;
76         }
77
78
79
80         if($a->argc == 3) {
81
82                 $contact_id = intval($a->argv[1]);
83                 if(! $contact_id)
84                         return;
85
86                 $cmd = $a->argv[2];
87
88                 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
89                         intval($contact_id),
90                         intval($_SESSION['uid'])
91                 );
92
93                 if(! count($orig_record)) {
94                         notice("Could not access contact record." . EOL);
95                         goaway($a->get_baseurl() . '/contacts');
96                         return; // NOTREACHED
97                 }
98
99
100                 $photo = str_replace('-4.jpg', '' , $r[0]['photo']);
101                 $photos = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d",
102                                 dbesc($photo),
103                                 intval($_SESSION['uid'])
104                 );
105         
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",
109                                         intval($blocked),
110                                         intval($contact_id),
111                                         intval($_SESSION['uid'])
112                         );
113                         if($r) {
114                                 $msg = "Contact has been " . (($blocked) ? '' : 'un') . "blocked." . EOL ;
115                                 notice($msg);
116                         }
117                         goaway($a->get_baseurl() ."/contacts/$contact_id");
118                         return; // NOTREACHED
119                 }
120
121                 if($cmd == 'drop') {
122                         $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
123                                 intval($contact_id),
124                                 intval($_SESSION['uid']));
125                         if(count($photos)) {
126                                 foreach($photos as $p) {
127                                         q("DELETE FROM `photos` WHERE `id` = %d LIMIT 1",
128                                                 $p['id']);
129                                 }
130                         }
131                         if($intval($contact_id))
132                                 q("DELETE FROM `item` WHERE `contact-id` = %d LIMIT 1",
133                                         intval($contact_id)
134                                 );
135         
136                         notice("Contact has been removed." . EOL );
137                         goaway($a->get_baseurl() . '/contacts');
138                         return; // NOTREACHED
139                 }
140         }
141
142         if(($a->argc == 2) && intval($a->argv[1])) {
143
144                 $contact_id = intval($a->argv[1]);
145                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
146                         $_SESSION['uid'],
147                         intval($contact_id)
148                 );
149                 if(! count($r)) {
150                         notice("Contact not found.");
151                         return;
152                 }
153
154                 require_once('view/contact_selectors.php');
155
156                 $tpl = file_get_contents("view/contact_edit.tpl");
157
158                 $direction = '';
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';
164                         }
165                         else {
166                                 $direction = DIRECTION_IN;
167                                 $dir_icon = 'images/larrow.gif';
168                                 $alt_text = 'is a fan of yours';
169                         }
170                 }
171                 else {
172                         $direction = DIRECTION_OUT;
173                         $dir_icon = 'images/rarrow.gif';
174                         $alt_text = 'you are a fan of';
175                 }
176
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
189
190                 ));
191
192                 return $o;
193
194         }
195
196         if(($a->argc == 2) && ($a->argv[1] == 'all'))
197                 $sql_extra = '';
198         else
199                 $sql_extra = " AND `blocked` = 0 ";
200
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')
205         )); 
206
207         switch($sort_type) {
208                 case DIRECTION_BOTH :
209                         $sql_extra = " AND `dfrn-id` != '' AND `issued-id` != '' ";
210                         break;
211                 case DIRECTION_IN :
212                         $sql_extra = " AND `dfrn-id` = '' AND `issued-id` != '' ";
213                         break;
214                 case DIRECTION_OUT :
215                         $sql_extra = " AND `dfrn-id` != '' AND `issued-id` = '' ";
216                         break;
217                 case DIRECTION_ANY :
218                 default:
219                         $sql_extra = '';
220                         break;
221         }
222
223         $r = q("SELECT * FROM `contact` WHERE `uid` = %d $sql_extra",
224                 intval($_SESSION['uid']));
225
226         if(count($r)) {
227
228                 $tpl = file_get_contents("view/contact_template.tpl");
229
230                 foreach($r as $rr) {
231                         if($rr['self'])
232                                 continue;
233                         $direction = '';
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';
239                                 }
240                                 else {
241                                         $direction = DIRECTION_IN;
242                                         $dir_icon = 'images/larrow.gif';
243                                         $alt_text = 'is a fan of yours';
244                                 }
245                         }
246                         else {
247                                 $direction = DIRECTION_OUT;
248                                 $dir_icon = 'images/rarrow.gif';
249                                 $alt_text = 'you are a fan of';
250                         }
251
252                         $o .= replace_macros($tpl, array(
253                                 '$id' => $rr['id'],
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'] )
259                         ));
260                 }
261         }
262         return $o;
263 }