File:  [LON-CAPA] / loncom / interface / lonblockingstatus.pm
Revision 1.12: download - view: text, annotated - select for diffs
Tue Jan 15 18:24:15 2013 UTC (11 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_11_1, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0, HEAD
- Include module in call to &course_type().

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

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