Annotation of loncom/interface/lonnotify.pm, revision 1.1
1.1 ! raeburn 1: #
! 2: # Copyright Michigan State University Board of Trustees
! 3: #
! 4: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
! 5: #
! 6: # LON-CAPA is free software; you can redistribute it and/or modify
! 7: # it under the terms of the GNU General Public License as published by
! 8: # the Free Software Foundation; either version 2 of the License, or
! 9: # (at your option) any later version.
! 10: #
! 11: # LON-CAPA is distributed in the hope that it will be useful,
! 12: # but WITHOUT ANY WARRANTY; without even the implied warranty of
! 13: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 14: # GNU General Public License for more details.
! 15: #
! 16: # You should have received a copy of the GNU General Public License
! 17: # along with LON-CAPA; if not, write to the Free Software
! 18: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! 19: #
! 20: # /home/httpd/html/adm/gpl.txt
! 21: #
! 22: # http://www.lon-capa.org/
! 23: #
! 24:
! 25: package Apache::lonnotify;
! 26:
! 27: use strict;
! 28: use Apache::lonnet;
! 29: use Apache::loncommon;
! 30: use Apache::lonsupportreq;
! 31: use LONCAPA::Enrollment;
! 32: use Apache::Constants qw(:common :http);
! 33: use Apache::lonlocal;
! 34:
! 35: sub handler {
! 36: my ($r) = @_;
! 37: &Apache::loncommon::content_type($r,'text/html');
! 38: $r->send_http_header;
! 39:
! 40: if ($r->header_only) {
! 41: return OK;
! 42: }
! 43: # my $codedom = $env{'request.role.domain'};
! 44: my $cdom = 'northwood5';
! 45: unless (&Apache::lonnet::allowed('psa',$env{'request.role.domain'})) {
! 46: # Not allowed to broadcast e-mail system-wide
! 47: $env{'user.error.msg'}="/adm/notify:psa:0:0:Cannot broadcast e-mail systemwide";
! 48: return HTTP_NOT_ACCEPTABLE;
! 49: }
! 50:
! 51: my $command = $env{'form.command'};
! 52: &Apache::lonhtmlcommon::clear_breadcrumbs();
! 53: &Apache::lonhtmlcommon::add_breadcrumb
! 54: ({href=>'/adm/notify',
! 55: text=>"Broadcast e-mail"});
! 56: if ($command eq 'process') {
! 57: &print_request_receipt($r,$cdom);
! 58: } elsif ($command eq 'compose') {
! 59: &print_composition_form($r,$cdom);
! 60: } else {
! 61: &print_selection_form($r,$cdom);
! 62: }
! 63: return OK;
! 64: }
! 65:
! 66: sub print_selection_form {
! 67: my ($r,$cdom) = @_;
! 68: my %coursecodes = ();
! 69: my %codes = ();
! 70: my @codetitles = ();
! 71: my %cat_titles = ();
! 72: my %cat_order = ();
! 73: my %idlist = ();
! 74: my %idnums = ();
! 75: my %idlist_titles = ();
! 76: my $caller = 'global';
! 77: my $totcodes = 0;
! 78: my $format_reply;
! 79: my $jscript = '';
! 80: my $loaditems = qq|
! 81: function initialize_codes() {
! 82: return;
! 83: }
! 84: |;
! 85: $totcodes = &Apache::lonsupportreq::retrieve_instcodes(\%coursecodes,$cdom,$totcodes);
! 86: if ($totcodes > 0) {
! 87: $format_reply = &Apache::lonnet::auto_instcode_format($caller,$cdom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
! 88: if ($format_reply eq 'ok') {
! 89: my $numtypes = @codetitles;
! 90: &Apache::lonsupportreq::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
! 91: &Apache::lonsupportreq::javascript_code_selections($numtypes,\%cat_titles,\$jscript,\%idlist,\%idnums,\%idlist_titles,\@codetitles);
! 92: $loaditems = '';
! 93: }
! 94: }
! 95:
! 96: my $function = &Apache::loncommon::get_users_function();
! 97: my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
! 98: my $bodytag = &Apache::loncommon::bodytag('Broadcast e-mail to users');
! 99: my $html=&Apache::lonxml::xmlbegin();
! 100: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs
! 101: (undef,'Broadcast e-mail to users','Broadcast_system_email');
! 102: $r->print(<<ENDONE);
! 103: $html
! 104: <head>
! 105: <title>LON-CAPA Notification E-mail</title>
! 106: <script type"text/javascript">
! 107: $jscript
! 108: </script>
! 109: </head>
! 110: $bodytag
! 111: $breadcrumbs
! 112: <br />
! 113: <form method="post" name="logproblem">
! 114: <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
! 115: <tr>
! 116: <td>
! 117: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
! 118: <tr>
! 119: <td>
! 120: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
! 121: <tr>
! 122: <td>
! 123: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
! 124: <tr>
! 125: <td width="140" bgcolor="$tablecolor">
! 126: <table width="140" border="0" cellpadding="8" cellspacing="0">
! 127: <tr>
! 128: <td align="right"><b>Roles:</b>
! 129: </td>
! 130: </tr>
! 131: </table>
! 132: </td>
! 133: <td width="100%" valign="top">
! 134: <table width="100%" border="0" cellpadding="8" cellspacing="0">
! 135: <tr>
! 136: <td>
! 137: <select name="roles" multiple>
! 138: ENDONE
! 139: foreach ('cc','in','ta','ep','ad') {
! 140: my $plrole=&Apache::lonnet::plaintext($_);
! 141: $r->print(' <option value="'.$_.'">'.$plrole.'</option>');
! 142: }
! 143: $r->print(<<ENDTWO);
! 144: </select>
! 145: </td>
! 146: </tr>
! 147: </table>
! 148: </td>
! 149: </tr>
! 150: <tr>
! 151: <td width="140" bgcolor="$tablecolor">
! 152: <table width="140" border="0" cellpadding="8" cellspacing="0">
! 153: <tr>
! 154: <td align="right"><b>Courses:</b>
! 155: </td>
! 156: </tr>
! 157: </table>
! 158: </td>
! 159: <td width="100%" valign="top">
! 160: <table width="100%" border="0" cellpadding="8" cellspacing="0">
! 161: <tr>
! 162: <td>
! 163: ENDTWO
! 164: if ($totcodes > 0) {
! 165: my $numtitles = @codetitles;
! 166: if ($numtitles == 0) {
! 167: $r->print('No institutional course code categories found.<br />Can not select courses to receive e-mail.');
! 168: } else {
! 169: $r->print('<table><tr><td>'.$codetitles[0].'<br />'."\n".
! 170: '<select name="'.$codetitles[0].
! 171: '" onChange="courseSet('."'$codetitles[0]'".')">'."\n".
! 172: ' <option value="-1" />Select'."\n");
! 173: my @items = ();
! 174: my @longitems = ();
! 175: if ($idlist{$codetitles[0]} =~ /","/) {
! 176: @items = split/","/,$idlist{$codetitles[0]};
! 177: } else {
! 178: $items[0] = $idlist{$codetitles[0]};
! 179: }
! 180: if (defined($idlist_titles{$codetitles[0]})) {
! 181: if ($idlist_titles{$codetitles[0]} =~ /","/) {
! 182: @longitems = split/","/,$idlist_titles{$codetitles[0]};
! 183: } else {
! 184: $longitems[0] = $idlist_titles{$codetitles[0]};
! 185: }
! 186: for (my $i=0; $i<@longitems; $i++) {
! 187: if ($longitems[$i] eq '') {
! 188: $longitems[$i] = $items[$i];
! 189: }
! 190: }
! 191: } else {
! 192: @longitems = @items;
! 193: }
! 194: for (my $i=0; $i<@items; $i++) {
! 195: $r->print(' <option value="'.$items[$i].'">'.$longitems[$i].'</option>');
! 196: }
! 197: $r->print('</select></td>');
! 198: for (my $i=1; $i<$numtitles; $i++) {
! 199: $r->print('<td>'.$codetitles[$i].'<br />'."\n".
! 200: '<select name="'.$codetitles[$i].
! 201: '" onChange="courseSet('."'$codetitles[$i]'".')">'."\n".
! 202: '<option value="-1"><-Pick '.$codetitles[$i-1].'</option>'."\n".
! 203: '</select>'."\n".
! 204: '</td>'
! 205: );
! 206: }
! 207: $r->print('</tr></table>');
! 208: }
! 209: }
! 210: $r->print(<<END);
! 211: </td>
! 212: </tr>
! 213: </table>
! 214: </td>
! 215: </tr>
! 216: <tr>
! 217: <td width="140" bgcolor="$tablecolor">
! 218: <table width="140" border="0" cellpadding="8" cellspacing="0">
! 219: <tr>
! 220: <td align="right"><b>Submit:</b>
! 221: </td>
! 222: </tr>
! 223: </table>
! 224: </td>
! 225: <td width="100%" valign="top" align="right">
! 226: <br />
! 227: <input type="hidden" name="command" value="compose" />
! 228: <input type="submit" value="Compose Message"/>
! 229: <br /><br />
! 230: </td>
! 231: </tr>
! 232: </table>
! 233: </td>
! 234: </tr>
! 235: </table>
! 236: </td>
! 237: </tr>
! 238: </table>
! 239: </td>
! 240: </tr>
! 241: </table>
! 242: </form>
! 243: </body>
! 244: </html>
! 245: END
! 246: return;
! 247: }
! 248:
! 249: sub print_composition_form {
! 250: my ($r,$cdom) = @_;
! 251: my $function = &Apache::loncommon::get_users_function();
! 252: my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
! 253: my $bodytag = &Apache::loncommon::bodytag('Broadcast e-mail to users');
! 254: my $html=&Apache::lonxml::xmlbegin();
! 255: &Apache::lonhtmlcommon::add_breadcrumb
! 256: ({href=>'/adm/notify?command=compose',
! 257: text=>"Compose Message"});
! 258: my $jscript = <<"END";
! 259: function checkAll(field) {
! 260: if (field.length > 0) {
! 261: for (i = 0; i < field.length; i++) {
! 262: field[i].checked = true ;
! 263: }
! 264: } else {
! 265: field.checked = true
! 266: }
! 267: }
! 268:
! 269: function uncheckAll(field) {
! 270: if (field.length > 0) {
! 271: for (i = 0; i < field.length; i++) {
! 272: field[i].checked = false ;
! 273: } } else {
! 274: field.checked = false ;
! 275: }
! 276: }
! 277: END
! 278: my $breadcrumbs = (&Apache::lonhtmlcommon::breadcrumbs
! 279: (undef,'Broadcast e-mail to users','Broadcast_system_email'));
! 280:
! 281: $r->print(<<ENDONE);
! 282: $html
! 283: <head>
! 284: <title>LON-CAPA Notification E-mail</title>
! 285: <script type"text/javascript">
! 286: $jscript
! 287: </script>
! 288: </head>
! 289: $bodytag $breadcrumbs
! 290: <br />
! 291: ENDONE
! 292: my $instcode = '';
! 293: my @cats = ('Semester','Year','Department','Number');
! 294: foreach my $category (@cats) {
! 295: if (defined($env{'form.'.$category})) {
! 296: unless ($env{'form.'.$category} eq '-1') {
! 297: $instcode .= $env{'form.'.$category};
! 298: }
! 299: }
! 300: }
! 301: if ($instcode eq '') {
! 302: $instcode = '.';
! 303: }
! 304: my %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.');
! 305: my @roles = &Apache::loncommon::get_env_multiple('form.roles');
! 306: my %recipients = ();
! 307: foreach my $course_id (keys %courses) {
! 308: &get_active_users($course_id,\@roles,\%recipients);
! 309: }
! 310: if (%recipients) {
! 311: $r->print('<form name="compose" method="post">
! 312: <input type="hidden" command="process" />
! 313: <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
! 314: <tr>
! 315: <td>
! 316: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
! 317: <tr>
! 318: <td>
! 319: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
! 320: <tr>
! 321: <td>
! 322: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
! 323: <tr>
! 324: <td width="140" bgcolor="'.$tablecolor.'">
! 325: <table width="140" border="0" cellpadding="8" cellspacing="0">
! 326: <tr>
! 327: <td align="right"><b>Subject:</b>
! 328: </td>
! 329: </tr>
! 330: </table>
! 331: </td>
! 332: <td width="100%" valign="top">
! 333: <table width="100%" border="0" cellpadding="8" cellspacing="0">
! 334: <tr>
! 335: <td><input type="text" name="subject" size="30" />
! 336: </td>
! 337: </tr>
! 338: </table>
! 339: </td>
! 340: </tr>
! 341: <tr>
! 342: <td width="140" bgcolor="'.$tablecolor.'">
! 343: <table width="140" border="0" cellpadding="8" cellspacing="0">
! 344: <tr>
! 345: <td align="right">Message:</td>
! 346: </td>
! 347: </tr>
! 348: </table>
! 349: </td>
! 350: <td width="100%" valign="top">
! 351: <table width="100%" border="0" cellpadding="8" cellspacing="0">
! 352: <tr>
! 353: <td>
! 354: <textarea name="message" id="message"
! 355: cols="60" rows="10" wrap="hard"></textarea>
! 356: </td>
! 357: </tr>
! 358: </table>
! 359: </td>
! 360: </tr>
! 361: <tr>
! 362: <td width="140" bgcolor="'.$tablecolor.'">
! 363: <table width="140" border="0" cellpadding="8" cellspacing="0">
! 364: <tr>
! 365: <td align="right"><b>Recipients:</b>
! 366: </td>
! 367: </tr>
! 368: </table>
! 369: </td>
! 370: <td width="100%" valign="top">
! 371: <table width="100%" border="0" cellpadding="8" cellspacing="0">
! 372: <tr>
! 373: <td>
! 374: <input type="button" value="check all"
! 375: onclick="javascript:checkAll(document.compose.email)" />
! 376: <input type="button" value="uncheck all"
! 377: onclick="javascript:uncheckAll(document.compose.email)" /><br />
! 378: <table border="0">');
! 379: foreach my $username (sort keys %recipients) {
! 380: if ($recipients{$username} =~ /\@/) {
! 381: my $value=&Apache::lonnet::escape($username).':'.&Apache::lonnet::escape($recipients{$username});
! 382: $r->print('<tr><td><input type="checkbox" name="email" value="'.$value.'" checked="checked" /></td><td>'.$username.'</td><td>'.$recipients{$username}.'</td></tr>');
! 383: $numrecep ++;
! 384: }
! 385: }
! 386: $r->print('
! 387: </table>
! 388: </td>
! 389: </tr>
! 390: </table>
! 391: </td>
! 392: </tr>
! 393: <tr>
! 394: <td width="140" bgcolor="'.$tablecolor.'">
! 395: <table width="140" border="0" cellpadding="8" cellspacing="0">
! 396: <tr>
! 397: <td align="right"><b>Submit:</b>
! 398: </td>
! 399: </tr>
! 400: </table>
! 401: </td>
! 402: <td width="100%" valign="top" align="right">
! 403: <br />
! 404: <input type="hidden" name="command" value="compose" />
! 405: <input type="submit" name="sendemail" value="Send Message"/>
! 406: <br /><br />
! 407: </td>
! 408: </tr>
! 409: </table>
! 410: </td>
! 411: </tr>
! 412: </table>
! 413: </td>
! 414: </tr>
! 415: </table>
! 416: </td>
! 417: </tr>
! 418: </table>
! 419: </form>');
! 420: } else {
! 421: $r->print('No recipients identified');
! 422: }
! 423: $r->print('</body></html>');
! 424: return;
! 425: }
! 426:
! 427:
! 428: sub print_request_receipt {
! 429: my ($r,$dom) =@_;
! 430: my @recipients = &Apache::loncommon::get_env_multiple('recipients');
! 431: my $subject = $env{'form.subject'};
! 432: my $message = $env{'form.message'};
! 433: my $function = &Apache::loncommon::get_users_function();
! 434: my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
! 435: my $bodytag = &Apache::loncommon::bodytag('Broadcast e-mail to users');
! 436: my $html=&Apache::lonxml::xmlbegin();
! 437: my $jscript;
! 438: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs
! 439: (undef,'Broadcast e-mail to users','Broadcast_system_email');
! 440: $r->print(<<ENDONE);
! 441: $html
! 442: <head>
! 443: <title>LON-CAPA Notification E-mail</title>
! 444: <script type"text/javascript">
! 445: $jscript
! 446: </script>
! 447: </head>
! 448: $bodytag
! 449: $breadcrumbs
! 450: ENDONE
! 451: $r->print($subject.'<br /><br />');
! 452: $r->print($message.'<br /><br />');
! 453: foreach my $person (@recipients) {
! 454: my ($username,$email) = split/:/,$person;
! 455: $r->print('user: '.&Apache::lonnet::unescape($username).' email: '.&Apache::lonnet::unescape($email).'<br />');
! 456: }
! 457: return;
! 458: }
! 459:
! 460: sub get_active_users {
! 461: my ($course_id,$roles,$recipients) = @_;
! 462: if (@{$roles} > 0) {
! 463: my ($cdom,$cnum) = split/_/,$course_id;
! 464: my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$cdom,$cnum);
! 465: foreach my $person (@coursepersonnel) {
! 466: my ($role,$user) = ($person =~ /^([^:]*):(.+)$/);
! 467: if (($role) && (grep/^$role$/,@{$roles})) {
! 468: unless (exists($$recipients{$user})) {
! 469: my ($uname,$udom) = split/:/,$user;
! 470: if ($uname ne '' && $udom ne '') {
! 471: if (&LONCAPA::Enrollment::check_user_status($udom,$uname,$cdom,$cnum,$role) eq 'ok') {
! 472: my %userinfo = &Apache::lonnet::get('environment',['permanenetemail','notification','critnotification',],$udom,$uname);
! 473: my @emailtypes = ('permanentemail','critnotification','notification');
! 474: my $email = '';
! 475: foreach (@emailtypes) {
! 476: $email = $userinfo{$_};
! 477: if ($email =~ /\@/) {
! 478: last;
! 479: }
! 480: }
! 481: if ($email eq '') {
! 482: my $authinfo = &Apache::lonnet::queryauthenticate($uname,$udom);
! 483: my ($authtype,$autharg) = split/:/,$authinfo;
! 484: if (($authtype =~ /^krb/) && ($autharg =~ /^MSU/)) {
! 485: $email = $uname.'@msu.edu';
! 486: }
! 487: }
! 488: $$recipients{$user} = $email;
! 489: }
! 490: }
! 491: }
! 492: }
! 493: }
! 494: }
! 495: }
! 496:
! 497: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>