]> git.mxchange.org Git - friendica.git/blob - mod/notifications.php
add nicknames to contact records (going forward and retroactive)
[friendica.git] / mod / notifications.php
1 <?php
2
3 function notifications_post(&$a) {
4
5         if(! local_user()) {
6                 goaway($a->get_baseurl());
7         }
8         
9         $request_id = (($a->argc > 1) ? $a->argv[1] : 0);
10         
11         if($request_id === "all")
12                 return;
13
14         if($request_id) {
15
16                 $r = q("SELECT `id` FROM `intro` 
17                         WHERE `request-id` = %d 
18                         AND `uid` = %d LIMIT 1",
19                                 intval($request_id),
20                                 intval(local_user())
21                 );
22         
23                 if(count($r)) {
24                         $intro_id = $r[0]['id'];
25                 }
26                 else {
27                         notice( t('Invalid request identifier.') . EOL);
28                         return;
29                 }
30                 if($_POST['submit'] == t('Discard')) {
31                         $r = q("DELETE FROM `intro` WHERE `id` = %d LIMIT 1", 
32                                 intval($intro_id)
33                         );      
34                         $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", 
35                                 intval($request_id),
36                                 intval(local_user())
37                         );
38                         return;
39                 }
40                 if($_POST['submit'] == t('Ignore')) {
41                         $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d LIMIT 1",
42                                 intval($intro_id));
43                         return;
44                 }
45         }
46 }
47
48
49
50
51
52 function notifications_content(&$a) {
53
54         if(! local_user()) {
55                 notice( t('Permission denied.') . EOL);
56                 goaway($a->get_baseurl());
57         }
58
59         $o = '';
60         $o .= '<script> $(document).ready(function() { $(\'#nav-notify-link\').addClass(\'nav-selected\'); });</script>';
61
62         if(($a->argc > 1) && ($a->argv[1] == 'all'))
63                 $sql_extra = '';
64         else
65                 $sql_extra = " AND `ignore` = 0 ";
66
67
68         $tpl = load_view_file('view/intros-top.tpl');
69         $o .= replace_macros($tpl,array(
70                 '$hide_url' => ((strlen($sql_extra)) ? 'notifications/all' : 'notifications' ),
71                 '$hide_text' => ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests'))
72         )); 
73
74         $r = q("SELECT `intro`.`id` AS `intro-id`, `intro`.*, `contact`.* 
75                 FROM `intro` LEFT JOIN `contact` ON `intro`.`contact-id` = `contact`.`id`
76                 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
77                         intval($_SESSION['uid']));
78
79         if(($r !== false) && (count($r))) {
80
81
82                 $tpl = load_view_file("view/intros.tpl");
83
84                 foreach($r as $rr) {
85
86                         $o .= replace_macros($tpl,array(
87                                 '$intro_id' => $rr['intro-id'],
88                                 '$dfrn-id' => $rr['issued-id'],
89                                 '$uid' => $_SESSION['uid'],
90                                 '$contact-id' => $rr['contact-id'],
91                                 '$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/default-profile.jpg"),
92                                 '$fullname' => $rr['name'],
93                                 '$knowyou' => (($rr['knowyou']) ? t('yes') : t('no')),
94                                 '$url' => $rr['url'],
95                                 '$note' => $rr['note']
96                         ));
97                 }
98         }
99         else
100                 notice( t('No notifications.') . EOL);
101
102         return $o;
103 }