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

1.1       droeschl    1: # The LearningOnline Network with CAPA
                      2: # displays the blocking status table
                      3: #
1.19    ! raeburn     4: # $Id: lonblockingstatus.pm,v 1.18 2020/09/29 19:29:51 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.17      raeburn    46:     my (%activities,$activity,$origurl,$origsymb);
1.19    ! raeburn    47:     map { $activities{$_} = 1; } ('boards','chat','com','blogs','about','groups','port','printout','docs','grades','passwd','search');
1.1       droeschl   48: 
1.8       raeburn    49:     # determine what kind of blocking we want details for
1.17      raeburn    50:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['activity','url','symb']);
1.8       raeburn    51:     $activity = $env{'form.activity'};
                     52: 
                     53:     my $title = 'Communication Blocking Status Information';
                     54: 
1.16      raeburn    55:     if (($activity eq 'docs') || ($activity eq 'printout') ||
                     56:         ($activity eq 'grades') || ($activity eq 'passwd') ||
                     57:         ($activity eq 'search')) {
1.8       raeburn    58:         $title = 'Blocking Status Information';
1.16      raeburn    59:         if ($activity eq 'docs') {
                     60:             $origurl = $env{'form.url'};
1.17      raeburn    61:             $origsymb = $env{'form.symb'};
1.16      raeburn    62:         }
1.8       raeburn    63:     }
                     64:     $r->print(&Apache::loncommon::start_page($title,undef,
                     65:                                             {'only_body' => 1}));
                     66: 
                     67:     if (($activity eq '') || (!$activities{$activity})) {
1.17      raeburn    68:         $r->print('<p class="LC_error">'.&mt('Error: unknown activity type blocked').'</p>');
                     69:     } elsif (($activity eq 'docs') && ($origurl eq '') && ($origsymb eq '')) {
                     70:         $r->print('<p class="LC_error">'.&mt('Error: could not determine what content was blocked from access').'</p>');
1.8       raeburn    71:     } else {
1.17      raeburn    72:         $r->print(&blockpage($activity,$origurl,$origsymb));
1.8       raeburn    73:     }
1.18      raeburn    74: 
1.8       raeburn    75:     $r->print(&Apache::loncommon::end_page());
1.6       droeschl   76: 
1.1       droeschl   77:     return OK;
                     78: }
1.6       droeschl   79: 
                     80: sub blockpage {
1.17      raeburn    81:     my ($activity,$origurl,$origsymb) = @_;
1.6       droeschl   82: 
                     83:     # in case of a portfolio block we need to determine the owner of the files
                     84:     # we're trying to look at. This information is passed via query string.
                     85:     my ($uname, $udom);
                     86: 
1.19    ! raeburn    87:     if (($activity eq 'port') || ($activity eq 'about') ||
1.13      raeburn    88:         (($activity eq 'passwd') && ($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))) {
1.8       raeburn    89:         &Apache::loncommon::get_unprocessed_cgi(
1.6       droeschl   90:             $ENV{'QUERY_STRING'}, ['udom', 'uname'] );
                     91: 
                     92:         ($uname, $udom) = ($env{'form.uname'}, $env{'form.udom'});
1.8       raeburn    93:         if (($uname !~ /^$match_username$/) || ($udom !~ /^$match_domain$/)) {
1.13      raeburn    94:             if ($activity eq 'port') {
                     95:                 return '<span class="LC_error">'.
                     96:                        &mt('Information about the owner of the portfolio files you were trying to view was missing or invalid.').
                     97:                        '</span><br />'.
1.18      raeburn    98:                        &mt('Without valid owner information, the reason why access is blocked can not be determined');
1.19    ! raeburn    99:             } elsif ($activity eq 'about') {
        !           100:                 return '<span class="LC_error">'.
        !           101:                        &mt('The username and/or domain for the User Information page you were trying to view was missing or invalid.').
        !           102:                        '</span><br />'.
        !           103:                        &mt('Without valid information, the reason why access is blocked can not be determined');
1.13      raeburn   104:             } else {
                    105:                 return '<span class="LC_error">'.
                    106:                        &mt('Information about the username and/or domain for which you were trying to reset a password was missing or invalid.').
                    107:                        '</span><br />'.
                    108:                        &mt('Without valid information, the reason why access is blocked can not be determined');
                    109:             }
1.8       raeburn   110:         }
1.6       droeschl  111:     }
                    112: 
1.17      raeburn   113:     # retrieve start/end of possible active blocking
                    114:     my (%setters,$startblock,$endblock,$triggerblock);
1.6       droeschl  115: 
1.17      raeburn   116:     if ($activity eq 'docs') {
                    117:         my ($cdom,$cnum);
                    118:         if ($env{'request.course.id'}) {
                    119:             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    120:             $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    121:         }
                    122:         my $cancheck;
                    123:         if (($cdom ne '') && ($cnum ne '')) {
                    124:             if ($origsymb =~ m{^uploaded/($match_domain)/($match_courseid)/}) {
                    125:                 my ($crsdom,$crsnum) = ($1,$2);
                    126:                 if (($cdom eq $crsdom) && ($cnum eq $crsnum)) {
                    127:                     $cancheck = 1;
                    128:                 }
                    129:             } else {
                    130:                 $cancheck = 1;
                    131:             }
                    132:         }
                    133:         if ($cancheck) {
                    134:             ($startblock,$endblock,$triggerblock) =
                    135:                 &Apache::loncommon::blockcheck(\%setters,$activity,$cnum,$cdom,$origurl,1,$origsymb,'blockingstatus');
                    136:         } else {
                    137:             return '<p class="LC_info">'.&mt('Could not determine why access is blocked.').'</p>';
                    138:         }
                    139:     } else {
1.18      raeburn   140:         ($startblock,$endblock,$triggerblock) =
1.17      raeburn   141:             &Apache::loncommon::blockcheck(\%setters,$activity,$uname,$udom,$origurl,undef,$origsymb,'blockingstatus');
                    142:     }
1.6       droeschl  143: 
                    144:     # nothing to do if there's no active blocking
1.18      raeburn   145:     unless ($startblock && $endblock) {
1.17      raeburn   146:         if ($activity eq 'docs') {
                    147:             return '<p class="LC_info">'.&mt('Content no longer blocked from access').'</p>';
                    148:         }
                    149:         return '<p class="LC_info">'.&mt('Access no longer blocked for this activity').'</p>';
                    150:     }
1.6       droeschl  151: 
                    152:     # lookup $activity -> description
                    153:                    #possible activity          #corresponding description
1.8       raeburn   154:     my %descs = (
                    155:                    boards     => 'Discussion posts in this course',
                    156:                    chat       => 'Chat Room',
1.14      raeburn   157:                    com        => 'This message',
1.8       raeburn   158:                    blogs      => 'Blogs',
1.19    ! raeburn   159:                    about      => 'User information pages',
1.8       raeburn   160:                    groups     => 'Groups in this course',
1.18      raeburn   161:                    printout   => 'Printout generation',
1.8       raeburn   162:                    docs       => 'Course Content',
1.13      raeburn   163:                    passwd     => 'Changing of passwords',
1.15      raeburn   164:                    grades     => 'Course Gradebook',
1.16      raeburn   165:                    search     => 'Content Search',
1.8       raeburn   166:                 );
                    167: 
                    168:     if ($activity eq 'groups' || $activity eq 'boards') {
1.12      raeburn   169:         if (&Apache::loncommon::course_type() eq 'Community') {
1.15      raeburn   170:             $descs{'boards'} = 'Discussion posts in this community';
                    171:             $descs{'groups'} = 'Groups in this community';
                    172:             $descs{'docs'} = 'Community Content';
1.16      raeburn   173:             $descs{'grades'} = 'Community Gradebook';
1.8       raeburn   174:         }
                    175:     }
                    176: 
                    177:     my $description = $descs{$activity};
                    178:     if ($activity eq 'port') {
                    179:         $description = &get_portfolio_category($uname,$udom,\%setters);
                    180:     }
                    181:     if ($description eq '') {
                    182:         $description = 'Communication';
                    183:     }
1.6       droeschl  184: 
                    185:     my $showstart = Apache::lonlocal::locallocaltime($startblock);
                    186:     my $showend   = Apache::lonlocal::locallocaltime($endblock);
                    187: 
                    188:     my $output;
1.16      raeburn   189: 
1.8       raeburn   190:     if ( ref($description) ne 'ARRAY' ) {
1.6       droeschl  191:         #default: $description is one of the above descriptions
1.8       raeburn   192:         if ($activity eq 'docs') {
1.18      raeburn   193:             $output=&mt( 'Access to the content page you are attempting to'
1.8       raeburn   194:                          . ' view will be unavailable between [_1] and [_2] because'
1.10      raeburn   195:                          . ' access to selected '.$description.' is being blocked.'
1.8       raeburn   196:                          ,$showstart, $showend);
1.16      raeburn   197:         } elsif (($activity eq 'printout') || ($activity eq 'passwd') ||
1.19    ! raeburn   198:                  ($activity eq 'grades') || ($activity eq 'search') ||
        !           199:                  ($activity eq 'about')) {
1.11      raeburn   200:             $output = mt( $description
                    201:                           . ' will be unavailable between [_1] and [_2] because'
                    202:                           . ' this functionality is being blocked.'
                    203:                           ,$showstart, $showend);
1.8       raeburn   204:         } else {
                    205:             $output = mt( $description
                    206:                           . ' will be inaccessible between [_1] and [_2] because'
                    207:                           . ' communication is being blocked.'
1.18      raeburn   208:                           ,$showstart, $showend);
1.8       raeburn   209:         }
1.6       droeschl  210:     } else {
                    211:         # @$description is is the array returned from get_portfolio_category()
                    212:         # and contains the description (e.g. "Portfolio files belonging to [_1]"
                    213:         # and the value for [_1]
                    214:         $output = mt( $$description[0]
                    215:                       . ' will be inaccessible between [_2] and [_3] because'
                    216:                       . ' communication is being blocked.'
1.18      raeburn   217:                      ,$$description[1], $showstart, $showend);
1.6       droeschl  218:     }
                    219: 
                    220:     $output = "<p class=\"LC_info\">$output</p>";
                    221: 
1.18      raeburn   222:     # show a table containing details, except if user is trying to look
1.6       droeschl  223:     # at a different user's portfolio files
                    224:     if (   $activity ne 'port'                        # no portfolio
                    225:         || (   $uname eq $env{'user.name'}            # or own portfolio
                    226:             && $udom  eq $env{'user.domain'} ) 
                    227:         || Apache::lonnet::is_course($udom, $uname) ) # or portfolio of a course
                    228:     {
1.8       raeburn   229:         $output .= &build_block_table(\%setters);
1.4       kalberla  230:     }
1.6       droeschl  231: 
1.5       kalberla  232:     return $output;
                    233: }
                    234: 
                    235: sub build_block_table {
1.8       raeburn   236:     my ($setters) = @_;
1.5       kalberla  237:     my %lt = &Apache::lonlocal::texthash(
1.11      raeburn   238:         'cacb' => 'Currently active communication/content blocks',
1.5       kalberla  239:         'cour' => 'Course',
                    240:         'dura' => 'Duration',
                    241:         'blse' => 'Block set by'
                    242:     );
                    243:     my $output;
1.6       droeschl  244:     $output  = Apache::loncommon::start_data_table()
                    245:              . Apache::loncommon::data_table_caption($lt{'cacb'})
                    246:              . Apache::loncommon::start_data_table_header_row()
                    247:              . "<th>$lt{'cour'}</th> <th>$lt{'dura'}</th> <th>$lt{'blse'}</th>"
                    248:              . Apache::loncommon::end_data_table_header_row();
                    249: 
1.5       kalberla  250:     foreach my $course (keys(%{$setters})) {
                    251:         my %courseinfo=&Apache::lonnet::coursedescription($course);
                    252:         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
                    253:             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
                    254:             my $fullname = Apache::loncommon::plainname($uname,$udom);
                    255:             if (defined($env{'user.name'}) && defined($env{'user.domain'})
                    256:                 && $env{'user.name'} ne 'public'
1.6       droeschl  257:                 && $env{'user.domain'} ne 'public') 
                    258:             {
1.5       kalberla  259:                 $fullname = Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
                    260:             }
1.11      raeburn   261:             my $triggertype = $$setters{$course}{triggers}[$i];
1.8       raeburn   262:             if ($triggertype) {
1.18      raeburn   263:                 $fullname .= &mt(' (triggered by you when starting timer)');
1.8       raeburn   264:             }
1.5       kalberla  265:             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
                    266:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
                    267:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
1.6       droeschl  268:             my $duration = mt('[_1] to [_2]', $openblock, $closeblock);
                    269:             $output .= Apache::loncommon::start_data_table_row()
                    270:                      . "<td>$courseinfo{'description'}</td>"
                    271:                      . "<td>$duration</td>"
                    272:                      . "<td>$fullname</td>"
                    273:                      . Apache::loncommon::end_data_table_row();
1.5       kalberla  274:         }
                    275:     }
                    276:     $output .= Apache::loncommon::end_data_table();
1.4       kalberla  277: }
1.1       droeschl  278: 
1.6       droeschl  279: sub get_portfolio_category {
                    280:     my ($uname, $udom, $setters) = @_;
                    281: 
                    282:     if ($uname eq $env{'user.name'} && $udom eq $env{'user.domain'}) {
                    283:         # user's portolfio files
                    284: 
                    285:         return 'Your portfolio files';
                    286: 
                    287:     } elsif (Apache::lonnet::is_course($udom, $uname)) {
                    288:         # group portfolio files
                    289: 
                    290:         my $coursedesc;
                    291: 
                    292:         foreach my $course (keys(%{$setters})) {
                    293:             my %courseinfo = Apache::lonnet::coursedescription($course);
                    294:             $coursedesc    = $courseinfo{'description'};
                    295:         }
                    296: 
                    297:         return ["Group portfolio in the course '[_1]'", $coursedesc];
                    298:         
                    299:     } else {
                    300:         # different user's portfolio files
                    301:         
                    302:         my $plainname = Apache::loncommon::plainname($uname, $udom);
                    303: 
                    304:         unless (   $env{'user.name'}   eq 'public' 
                    305:                 && $env{'user.domain'} eq 'public' ) 
                    306:         {
                    307:             $plainname = Apache::loncommon::aboutmewrapper(
                    308:                             $plainname, $uname, $udom);
                    309:         }
                    310: 
                    311:         return ['Portfolio files belonging to [_1]', $plainname];
                    312:     }
                    313: }
                    314: 
1.1       droeschl  315: 1;
                    316: __END__

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