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

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

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