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

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

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