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

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

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