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