Annotation of loncom/interface/lonblockingstatus.pm, revision 1.14.2.2.2.1

1.1       droeschl    1: # The LearningOnline Network with CAPA
                      2: # displays the blocking status table
                      3: #
1.14.2.2.2.1! raeburn     4: # $Id: lonblockingstatus.pm,v 1.14.2.2 2020/09/08 03:57:48 raeburn Exp $
1.1       droeschl    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: #
                     29: package Apache::lonblockingstatus;
                     30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common);
                     33: use Apache::loncommon();
1.3       kalberla   34: use Apache::lonnet;
                     35: use Apache::lonlocal;
1.8       raeburn    36: use LONCAPA qw(:DEFAULT :match);
1.1       droeschl   37: 
                     38: sub handler {
                     39:     my $r = shift;
1.8       raeburn    40:     &Apache::loncommon::no_cache($r);
                     41:     &Apache::loncommon::content_type($r,'text/html');
1.6       droeschl   42: 
1.1       droeschl   43:     $r->send_http_header;
                     44:     return OK if $r->header_only;
                     45: 
1.8       raeburn    46:     my (%activities,$activity,$origurl);
1.14.2.2.2.1! raeburn    47:     map { $activities{$_} = 1; } ('boards','chat','com','blogs','groups','port','printout','docs','grades','passwd');
1.1       droeschl   48: 
1.8       raeburn    49:     # determine what kind of blocking we want details for
                     50:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['activity','url']);
                     51:     $activity = $env{'form.activity'};
                     52: 
                     53:     my $title = 'Communication Blocking Status Information';
                     54: 
1.14.2.1  raeburn    55:     if (($activity eq 'docs') || ($activity eq 'printout') ||
1.14.2.2.2.1! raeburn    56:         ($activity eq 'grades') || ($activity eq 'passwd')) {
1.8       raeburn    57:         $title = 'Blocking Status Information';
1.14.2.1  raeburn    58:         if ($activity eq 'docs') {
                     59:             $origurl = $env{'form.url'};
                     60:         }
1.8       raeburn    61:     }
                     62:     $r->print(&Apache::loncommon::start_page($title,undef,
                     63:                                             {'only_body' => 1}));
                     64: 
                     65:     if (($activity eq '') || (!$activities{$activity})) {
                     66:         $r->print('<span class="LC_error">'.&mt('Error: unknown activity type blocked').'</span>');
                     67:     } else {
                     68:         $r->print(&blockpage($activity,$origurl));
                     69:     }
1.6       droeschl   70:     
1.8       raeburn    71:     $r->print(&Apache::loncommon::end_page());
1.6       droeschl   72: 
1.1       droeschl   73:     return OK;
                     74: }
1.6       droeschl   75: 
                     76: 
                     77: sub blockpage {
1.8       raeburn    78:     my ($activity,$origurl) = @_;
1.6       droeschl   79: 
                     80:     # in case of a portfolio block we need to determine the owner of the files
                     81:     # we're trying to look at. This information is passed via query string.
                     82:     my ($uname, $udom);
                     83: 
1.13      raeburn    84:     if (($activity eq 'port') || 
                     85:         (($activity eq 'passwd') && ($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))) {
1.8       raeburn    86:         &Apache::loncommon::get_unprocessed_cgi(
1.6       droeschl   87:             $ENV{'QUERY_STRING'}, ['udom', 'uname'] );
                     88: 
                     89:         ($uname, $udom) = ($env{'form.uname'}, $env{'form.udom'});
1.8       raeburn    90:         if (($uname !~ /^$match_username$/) || ($udom !~ /^$match_domain$/)) {
1.13      raeburn    91:             if ($activity eq 'port') {
                     92:                 return '<span class="LC_error">'.
                     93:                        &mt('Information about the owner of the portfolio files you were trying to view was missing or invalid.').
                     94:                        '</span><br />'.
                     95:                        &mt('Without valid owner information, the reason why access is blocked can not be determined'); 
                     96:             } else {
                     97:                 return '<span class="LC_error">'.
                     98:                        &mt('Information about the username and/or domain for which you were trying to reset a password was missing or invalid.').
                     99:                        '</span><br />'.
                    100:                        &mt('Without valid information, the reason why access is blocked can not be determined');
                    101:             }
1.8       raeburn   102:         }
1.6       droeschl  103:     }
                    104: 
                    105: 
                    106:     # retrieve start/end of possible active blocking
1.4       kalberla  107:     my %setters;
1.8       raeburn   108:     my ($startblock,$endblock,$triggerblock) = 
1.9       raeburn   109:         &Apache::loncommon::blockcheck(\%setters,$activity,$uname,$udom,$origurl);
1.6       droeschl  110: 
                    111:     # nothing to do if there's no active blocking
                    112:     unless ($startblock && $endblock) { return ''; }
                    113: 
                    114:     # lookup $activity -> description
                    115:                    #possible activity          #corresponding description
1.8       raeburn   116:     my %descs = (
                    117:                    boards     => 'Discussion posts in this course',
                    118:                    chat       => 'Chat Room',
1.14      raeburn   119:                    com        => 'This message',
1.8       raeburn   120:                    blogs      => 'Blogs',
                    121:                    groups     => 'Groups in this course',
1.11      raeburn   122:                    printout   => 'Printout generation', 
1.8       raeburn   123:                    docs       => 'Course Content',
1.13      raeburn   124:                    passwd     => 'Changing of passwords',
1.14.2.2.2.1! raeburn   125:                    grades     => 'Course Gradebook',
1.8       raeburn   126:                 );
                    127: 
                    128:     if ($activity eq 'groups' || $activity eq 'boards') {
1.12      raeburn   129:         if (&Apache::loncommon::course_type() eq 'Community') {
1.14.2.2  raeburn   130:             $descs{'boards'} = 'Discussion posts in this community';
                    131:             $descs{'groups'} = 'Groups in this community';
1.14.2.2.2.1! raeburn   132:             $descs{'docs'} = 'Community Content';
        !           133:             $descs{'grades'} = 'Community Gradebook';
1.8       raeburn   134:         }
                    135:     }
                    136: 
                    137:     my $description = $descs{$activity};
                    138:     if ($activity eq 'port') {
                    139:         $description = &get_portfolio_category($uname,$udom,\%setters);
                    140:     }
                    141:     if ($description eq '') {
                    142:         $description = 'Communication';
                    143:     }
1.6       droeschl  144: 
                    145:     my $showstart = Apache::lonlocal::locallocaltime($startblock);
                    146:     my $showend   = Apache::lonlocal::locallocaltime($endblock);
                    147: 
                    148:     my $output;
                    149:     
1.8       raeburn   150:     if ( ref($description) ne 'ARRAY' ) {
1.6       droeschl  151:         #default: $description is one of the above descriptions
1.8       raeburn   152:         if ($activity eq 'docs') {
1.9       raeburn   153:             $output=&mt( 'Access to the content page you are attempting to' 
1.8       raeburn   154:                          . ' view will be unavailable between [_1] and [_2] because'
1.10      raeburn   155:                          . ' access to selected '.$description.' is being blocked.'
1.8       raeburn   156:                          ,$showstart, $showend);
1.14.2.2.2.1! raeburn   157:         } elsif (($activity eq 'printout') || ($activity eq 'passwd') || ($activity eq 'grades')) {
1.11      raeburn   158:             $output = mt( $description
                    159:                           . ' will be unavailable between [_1] and [_2] because'
                    160:                           . ' this functionality is being blocked.'
                    161:                           ,$showstart, $showend);
1.8       raeburn   162:         } else {
                    163:             $output = mt( $description
                    164:                           . ' will be inaccessible between [_1] and [_2] because'
                    165:                           . ' communication is being blocked.'
                    166:                           ,$showstart, $showend);  
                    167:         }
1.6       droeschl  168:     } else {
                    169:         # @$description is is the array returned from get_portfolio_category()
                    170:         # and contains the description (e.g. "Portfolio files belonging to [_1]"
                    171:         # and the value for [_1]
                    172:         $output = mt( $$description[0]
                    173:                       . ' will be inaccessible between [_2] and [_3] because'
                    174:                       . ' communication is being blocked.'
                    175:                      ,$$description[1], $showstart, $showend)  
                    176:     }
                    177: 
                    178:     $output = "<p class=\"LC_info\">$output</p>";
                    179: 
                    180:     # show a table containing details, except if user is trying to look 
                    181:     # at a different user's portfolio files
                    182:     if (   $activity ne 'port'                        # no portfolio
                    183:         || (   $uname eq $env{'user.name'}            # or own portfolio
                    184:             && $udom  eq $env{'user.domain'} ) 
                    185:         || Apache::lonnet::is_course($udom, $uname) ) # or portfolio of a course
                    186:     {
1.8       raeburn   187:         $output .= &build_block_table(\%setters);
1.4       kalberla  188:     }
1.6       droeschl  189: 
1.5       kalberla  190:     return $output;
                    191: }
                    192: 
                    193: sub build_block_table {
1.8       raeburn   194:     my ($setters) = @_;
1.5       kalberla  195:     my %lt = &Apache::lonlocal::texthash(
1.11      raeburn   196:         'cacb' => 'Currently active communication/content blocks',
1.5       kalberla  197:         'cour' => 'Course',
                    198:         'dura' => 'Duration',
                    199:         'blse' => 'Block set by'
                    200:     );
                    201:     my $output;
1.6       droeschl  202:     $output  = Apache::loncommon::start_data_table()
                    203:              . Apache::loncommon::data_table_caption($lt{'cacb'})
                    204:              . Apache::loncommon::start_data_table_header_row()
                    205:              . "<th>$lt{'cour'}</th> <th>$lt{'dura'}</th> <th>$lt{'blse'}</th>"
                    206:              . Apache::loncommon::end_data_table_header_row();
                    207: 
1.5       kalberla  208:     foreach my $course (keys(%{$setters})) {
                    209:         my %courseinfo=&Apache::lonnet::coursedescription($course);
                    210:         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
                    211:             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
                    212:             my $fullname = Apache::loncommon::plainname($uname,$udom);
                    213:             if (defined($env{'user.name'}) && defined($env{'user.domain'})
                    214:                 && $env{'user.name'} ne 'public'
1.6       droeschl  215:                 && $env{'user.domain'} ne 'public') 
                    216:             {
1.5       kalberla  217:                 $fullname = Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
                    218:             }
1.11      raeburn   219:             my $triggertype = $$setters{$course}{triggers}[$i];
1.8       raeburn   220:             if ($triggertype) {
                    221:                 $fullname .= &mt(' (triggered by you when starting timer)'); 
                    222:             }
1.5       kalberla  223:             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
                    224:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
                    225:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
1.6       droeschl  226:             my $duration = mt('[_1] to [_2]', $openblock, $closeblock);
                    227:             $output .= Apache::loncommon::start_data_table_row()
                    228:                      . "<td>$courseinfo{'description'}</td>"
                    229:                      . "<td>$duration</td>"
                    230:                      . "<td>$fullname</td>"
                    231:                      . Apache::loncommon::end_data_table_row();
1.5       kalberla  232:         }
                    233:     }
                    234:     $output .= Apache::loncommon::end_data_table();
1.4       kalberla  235: }
1.1       droeschl  236: 
1.6       droeschl  237: sub get_portfolio_category {
                    238:     my ($uname, $udom, $setters) = @_;
                    239: 
                    240:     if ($uname eq $env{'user.name'} && $udom eq $env{'user.domain'}) {
                    241:         # user's portolfio files
                    242: 
                    243:         return 'Your portfolio files';
                    244: 
                    245:     } elsif (Apache::lonnet::is_course($udom, $uname)) {
                    246:         # group portfolio files
                    247: 
                    248:         my $coursedesc;
                    249: 
                    250:         foreach my $course (keys(%{$setters})) {
                    251:             my %courseinfo = Apache::lonnet::coursedescription($course);
                    252:             $coursedesc    = $courseinfo{'description'};
                    253:         }
                    254: 
                    255:         return ["Group portfolio in the course '[_1]'", $coursedesc];
                    256:         
                    257:     } else {
                    258:         # different user's portfolio files
                    259:         
                    260:         my $plainname = Apache::loncommon::plainname($uname, $udom);
                    261: 
                    262:         unless (   $env{'user.name'}   eq 'public' 
                    263:                 && $env{'user.domain'} eq 'public' ) 
                    264:         {
                    265:             $plainname = Apache::loncommon::aboutmewrapper(
                    266:                             $plainname, $uname, $udom);
                    267:         }
                    268: 
                    269:         return ['Portfolio files belonging to [_1]', $plainname];
                    270:     }
                    271: }
                    272: 
1.1       droeschl  273: 1;
                    274: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>