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

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

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