root/broadcast/lib.php

Revision 254, 3.8 kB (checked in by kevin, 9 months ago)

Broadcast plugin, a major revision of Tim Hawes's newsletter plugin

Line 
1 <?php
2 function broadcast_pagesetup()
3 {
4     global $CFG, $PAGE;
5     
6     include($CFG->dirroot . "mod/broadcast/broadcast.config.php");
7
8     if (defined("context") && (context == "admin") && isloggedin() && isadmin($_SESSION['userid']))
9     {
10         // Add to the submenu
11         $num = count($PAGE->menu_sub) + 1;
12
13         $PAGE->menu_sub[$num]['name'] = "admin:broadcast";
14         $PAGE->menu_sub[$num]['html'] = '<a href="'.$CFG->wwwroot . 'mod/broadcast/broadcast_start.php">'.__gettext("Broadcast").'</a>';
15     }
16     
17     // a big if that says that the broadcast link appears on community profiles is the user is an admin or community owner
18     
19     $pg_owner = page_owner();
20     
21     if (isloggedin() && defined("context") && (context == "profile") &&
22         user_info('user_type',$pg_owner) == 'community' &&
23         (isadmin($_SESSION['userid']) || ($broadcast_allow_owners && user_info('owner',$pg_owner) == $_SESSION['userid']))) {
24             
25         $body = '<p><a href="'.$CFG->wwwroot.'mod/broadcast/broadcast_start.php?cid='.$pg_owner.'" />';
26         $body .= __gettext("Send a message to this community").'</a></p>';
27         $body = templates_draw(array(
28                     'context' => 'sidebarholder',
29                     'title' => __gettext("Broadcast"),
30                     'body' => $body,
31                     ));
32                 
33         sidebar_add(30, 'sidebar-myblock', $body, true, "new block");
34     }
35 }
36
37 /*function broadcast_init()
38 {
39     
40     global $function, $CFG;
41     include('broadcast.config.php');
42
43
44 } // end function init*/
45     
46     
47 function broadcast_get_all_users($profile_field,$profile_value) {
48     
49     global $CFG;
50     
51     if ($profile_field && $profile_value) {
52         
53         $thesql= <<< END
54 SELECT u.*, uf.value AS email_flag
55 FROM
56 ( {$CFG->prefix}users u
57    INNER JOIN {$CFG->prefix}profile_data p
58    ON (u.ident = p.owner)
59 )
60 LEFT JOIN {$CFG->prefix}user_flags uf
61 ON (u.ident = uf.user_id AND uf.flag = 'emailnotifications')
62 WHERE u.user_type = "person"
63 AND u.active="yes"
64 AND p.name = '$profile_field'
65 AND (p.value = '$profile_value'
66     OR '$profile_value' IN (SELECT tag FROM {$CFG->prefix}tags WHERE ref = p.ident)
67 )
68 ORDER BY u.ident ASC
69 END;
70     } else {
71
72     $thesql= <<< END
73 SELECT u.*, uf.value AS email_flag
74 FROM {$CFG->prefix}users u
75 LEFT JOIN {$CFG->prefix}user_flags uf
76 ON (u.ident = uf.user_id AND uf.flag = 'emailnotifications')
77 WHERE u.user_type = "person"
78 AND u.active="yes"
79 ORDER BY u.ident ASC
80 END;
81     }
82     $recipients=get_records_sql($thesql);
83     return $recipients;
84 }
85                     
86 function broadcast_get_community_users($community,$profile_field,$profile_value) {
87     
88     global $CFG;
89     
90     if ($profile_field && $profile_value) {
91         $thesql= <<<END
92 SELECT DISTINCT u.ident,u.username,u.name, u.email, uf.value AS email_flag FROM
93 (
94     (
95         {$CFG->prefix}friends f
96         INNER JOIN {$CFG->prefix}users u
97         ON (u.ident = f.owner)
98     ) INNER JOIN {$CFG->prefix}profile_data p
99       ON (u.ident = p.owner)
100 ) LEFT JOIN {$CFG->prefix}user_flags uf
101   ON (u.ident = uf.user_id AND uf.flag = 'emailnotifications')
102 WHERE f.friend = {$community->ident}
103 AND u.active= 'yes'
104 AND u.user_type = 'person'
105 AND p.name = '$profile_field'
106 AND (p.value = '$profile_value'
107     OR '$profile_value' IN (SELECT tag FROM {$CFG->prefix}tags WHERE ref = p.ident)
108 )
109 END;
110     } else {
111                     
112       $thesql = <<<END
113 SELECT DISTINCT u.ident,u.username,u.name, u.email, uf.value AS email_flag FROM
114 ( {$CFG->prefix}friends f
115   INNER JOIN {$CFG->prefix}users u ON (u.ident = f.owner)
116 )
117 LEFT JOIN {$CFG->prefix}user_flags uf
118 ON (u.ident = uf.user_id AND uf.flag = 'emailnotifications')
119 WHERE f.friend = $community->ident
120 AND u.active = 'yes'
121 AND u.user_type = 'person'
122 END;
123     }
124     
125     $recipients=get_records_sql($thesql);   
126     
127     return $recipients;
128 }
129
130 ?>
131
Note: See TracBrowser for help on using the browser.