| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
require_once("../../includes.php"); |
|---|
| 5 |
include($CFG->dirroot . "mod/broadcast/broadcast.config.php"); |
|---|
| 6 |
$function['admin:broadcast:body'][] = $CFG->dirroot . "mod/tinymce/tinymce_js.php"; |
|---|
| 7 |
|
|---|
| 8 |
global $CFG, $template, $PAGE; |
|---|
| 9 |
$template['css'] .= file_get_contents($CFG->dirroot . "mod/broadcast/css"); |
|---|
| 10 |
|
|---|
| 11 |
define("context", "broadcast"); |
|---|
| 12 |
|
|---|
| 13 |
$cid = optional_param('cid',''); |
|---|
| 14 |
$action = optional_param('action',''); |
|---|
| 15 |
|
|---|
| 16 |
templates_page_setup(); |
|---|
| 17 |
|
|---|
| 18 |
$title = __gettext("Broadcast"); |
|---|
| 19 |
|
|---|
| 20 |
$body = ""; |
|---|
| 21 |
$output = ""; |
|---|
| 22 |
$error = false; |
|---|
| 23 |
|
|---|
| 24 |
if (isloggedin()) { |
|---|
| 25 |
if ($action == 'submit' && $cid) { |
|---|
| 26 |
$profile_field = optional_param('profile_field',''); |
|---|
| 27 |
$profile_value = optional_param('profile_value',''); |
|---|
| 28 |
if (isadmin($_SESSION['userid']) ) { |
|---|
| 29 |
|
|---|
| 30 |
$show_recipients = optional_param('show_recipients',0,PARAM_INT); |
|---|
| 31 |
} else { |
|---|
| 32 |
$show_recipients = 0; |
|---|
| 33 |
} |
|---|
| 34 |
$body .= '<form action="'.$CFG->wwwroot.'mod/broadcast/broadcast_send.php" method ="post">'."\n"; |
|---|
| 35 |
$body .= '<input type="hidden" name="cid" value="' . $cid . '">'."\n"; |
|---|
| 36 |
$body .= '<input type="hidden" name="profile_field" value="' . $profile_field . '">'."\n"; |
|---|
| 37 |
$body .= '<input type="hidden" name="profile_value" value="' . $profile_value . '">'."\n"; |
|---|
| 38 |
|
|---|
| 39 |
if ($cid != '*') { |
|---|
| 40 |
$community = get_record('users','ident',intval($cid),'user_type','community'); |
|---|
| 41 |
if ($community) { |
|---|
| 42 |
if (isadmin($_SESSION['userid']) || ($broadcast_allow_owners && $community->owner == $_SESSION['userid'])) { |
|---|
| 43 |
|
|---|
| 44 |
if ($show_recipients) { |
|---|
| 45 |
$recipients = broadcast_get_community_users($community,$profile_field,$profile_value); |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
$title = __gettext("Broadcast to").' "'.user_info('name',intval($cid)).'"'; |
|---|
| 49 |
|
|---|
| 50 |
} else { |
|---|
| 51 |
$error = true; |
|---|
| 52 |
$body = __gettext("You are not allowed to contact this community."); |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
} else { |
|---|
| 56 |
$error = true; |
|---|
| 57 |
$body = __gettext("The community you specified does not exist."); |
|---|
| 58 |
} |
|---|
| 59 |
} else if ($cid=="*" && isadmin($_SESSION['userid'])) { |
|---|
| 60 |
|
|---|
| 61 |
if ($show_recipients) { |
|---|
| 62 |
$recipients = broadcast_get_all_users($profile_field,$profile_value); |
|---|
| 63 |
} |
|---|
| 64 |
} else { |
|---|
| 65 |
$error = true; |
|---|
| 66 |
$body = __gettext("You must be a site administrator to view this page."); |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
if (!$error) { |
|---|
| 70 |
if ($show_recipients) { |
|---|
| 71 |
$emailed_users = ''; |
|---|
| 72 |
$activity_users = ''; |
|---|
| 73 |
if ($recipients) { |
|---|
| 74 |
foreach($recipients as $recipient) { |
|---|
| 75 |
|
|---|
| 76 |
if (!empty($recipient->email_flag) && $recipient->email_flag == 1) { |
|---|
| 77 |
$emailed_users.= $recipient->name . ", "; |
|---|
| 78 |
} else { |
|---|
| 79 |
$activity_users.= $recipient->name . ", "; |
|---|
| 80 |
} |
|---|
| 81 |
} |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
if ($emailed_users) { |
|---|
| 86 |
$emailed_users = substr($emailed_users,0,-2); |
|---|
| 87 |
} else { |
|---|
| 88 |
$emailed_users = '<b>None</b>'; |
|---|
| 89 |
} |
|---|
| 90 |
if ($activity_users) { |
|---|
| 91 |
$activity_users = substr($activity_users,0,-2); |
|---|
| 92 |
} else { |
|---|
| 93 |
$activity_users = '<b>None</b>'; |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
$output = __gettext('Using email notification').': '.$emailed_users.'<br /><br />'; |
|---|
| 97 |
$output .= __gettext('Using web-only notification').': '.$activity_users; |
|---|
| 98 |
|
|---|
| 99 |
$body .= templates_draw(array ('context' => 'databoxvertical','name' => __gettext('Send to') . ':','contents' => $output)); |
|---|
| 100 |
|
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
$body.= templates_draw(array ('context' => 'databoxvertical','name' => __gettext('Message Subject') . ':','contents' => display_input_field(array ("message_subject","","text")))); |
|---|
| 104 |
$body.= templates_draw(array ( 'context' => 'databoxvertical', 'name' => __gettext('Message Body') . ':', 'contents' => display_input_field(array ( "message_text", "", "weblogtext" ) ))); |
|---|
| 105 |
$body.="<input type=\"submit\" name=\"submit\" VALUE=\"" . __gettext("Send") . "\"></form><br><br><br>"; |
|---|
| 106 |
run('admin:broadcast:body',array(array("message_text"))); |
|---|
| 107 |
} |
|---|
| 108 |
} else { |
|---|
| 109 |
|
|---|
| 110 |
$profile_field_select = broadcast_get_profile_field_select(); |
|---|
| 111 |
$body .= '<form action="'.$CFG->wwwroot.'mod/broadcast/broadcast_start.php" method="post" >'."\n"; |
|---|
| 112 |
$body .= '<input type="hidden" name="action" value="submit">'."\n"; |
|---|
| 113 |
if ($cid) { |
|---|
| 114 |
$title = __gettext("Broadcast to").' "'.user_info('name',intval($cid)).'"'; |
|---|
| 115 |
$body .= '<input type="hidden" name="cid" value="'.$cid.'">'."\n"; |
|---|
| 116 |
} else { |
|---|
| 117 |
$thesql='SELECT * FROM ' . $CFG->prefix . 'users u |
|---|
| 118 |
WHERE u.user_type = "community" AND u.active="yes" ORDER by u.ident'; |
|---|
| 119 |
$output = "<select name=\"cid\" id=\"cid\">"; |
|---|
| 120 |
$output .= "<option value=\"0\" selected=selected> </option>"; |
|---|
| 121 |
$output .= "<option value=\"*\">ALL USERS</option>"; |
|---|
| 122 |
$communities = get_records_sql($thesql); |
|---|
| 123 |
foreach($communities as $community) { |
|---|
| 124 |
$output.="<option value=\"" . $community->ident . "\">" . $community->name . "</option>"; |
|---|
| 125 |
} |
|---|
| 126 |
$output.="</select> "; |
|---|
| 127 |
$body .= templates_draw(array ('context' => 'databoxvertical','name' => __gettext('Select community to broadcast to') . ': ','contents' => $output)); |
|---|
| 128 |
} |
|---|
| 129 |
if ($profile_field_select) { |
|---|
| 130 |
|
|---|
| 131 |
$output .= '<div class="fieldname">'; |
|---|
| 132 |
$output .= '<h3>'.."</h3>\n"; |
|---|
| 133 |
$output .= '</div>'."\n"; */ |
|---|
| 134 |
$output = $profile_field_select; |
|---|
| 135 |
$output .= " ".__gettext("to")." "; |
|---|
| 136 |
$output .= '<input type="text" name="profile_value" value="">'."\n"; |
|---|
| 137 |
$body .= templates_draw(array ('context' => 'databoxvertical','name' => __gettext("Optionally restrict the mailing to people who have set the profile field") . ': ','contents' => $output)); |
|---|
| 138 |
} |
|---|
| 139 |
if (isadmin($_SESSION['userid'])) { |
|---|
| 140 |
|
|---|
| 141 |
$output .= '<h3>'.__gettext("Show recipients")."</h3>"; |
|---|
| 142 |
$output .= '</div>'."\n";*/ |
|---|
| 143 |
$output = '<input type="radio" name="show_recipients" value="0" checked> '.__gettext('No'); |
|---|
| 144 |
$output .= '<input type="radio" name="show_recipients" value="1"> '.__gettext('Yes')."\n"; |
|---|
| 145 |
$body .= templates_draw(array ('context' => 'databoxvertical','name' => __gettext("Show recipients") . ': ','contents' => $output)); |
|---|
| 146 |
} |
|---|
| 147 |
$body.= '<input type="submit" value="'.__gettext("Continue...").'">'; |
|---|
| 148 |
$body .= '</form>'."\n"; |
|---|
| 149 |
} |
|---|
| 150 |
} else { |
|---|
| 151 |
$body .= __gettext("You must be logged in to view this page."); |
|---|
| 152 |
} |
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
$body = templates_draw(array( |
|---|
| 157 |
'context' => 'contentholder', |
|---|
| 158 |
'title' => $title, |
|---|
| 159 |
'body' => $body |
|---|
| 160 |
) |
|---|
| 161 |
); |
|---|
| 162 |
|
|---|
| 163 |
echo templates_page_draw( array( |
|---|
| 164 |
$title, $body |
|---|
| 165 |
) |
|---|
| 166 |
); |
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
function broadcast_get_profile_field_select() { |
|---|
| 171 |
|
|---|
| 172 |
global $CFG, $data; |
|---|
| 173 |
|
|---|
| 174 |
$select = '<select name="profile_field">'."\n"; |
|---|
| 175 |
$select .= '<option value=""></option>'; |
|---|
| 176 |
include_once($CFG->dirroot.'mod/profile/profile.config.php'); |
|---|
| 177 |
if (isset($data['profile:details'])) { |
|---|
| 178 |
foreach($data['profile:details'] as $pd) { |
|---|
| 179 |
if (empty($pd->user_type) || $pd->user_type == 'person') { |
|---|
| 180 |
$select .= "<option value=\"{$pd->internal_name}\">{$pd->name}</option>\n"; |
|---|
| 181 |
} |
|---|
| 182 |
} |
|---|
| 183 |
} |
|---|
| 184 |
$select .= "</select>\n"; |
|---|
| 185 |
|
|---|
| 186 |
return $select; |
|---|
| 187 |
} |
|---|
| 188 |
|
|---|
| 189 |
?> |
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|