File:  [LON-CAPA] / loncom / interface / lonblockingstatus.pm
Revision 1.14.2.3: download - view: text, annotated - select for diffs
Mon Sep 28 00:27:48 2020 UTC (3 years, 8 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  Backport 1.17

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

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