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

1.1       droeschl    1: # The LearningOnline Network with CAPA
                      2: # displays the blocking status table
                      3: #
1.7     ! bisitz      4: # $Id: lonblockingstatus.pm,v 1.6 2009/09/25 13:51:58 droeschl 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.1       droeschl   36: 
                     37: sub handler {
                     38:     my $r = shift;
                     39:     Apache::loncommon::no_cache($r);
                     40:     Apache::loncommon::content_type($r,'text/html');
1.6       droeschl   41: 
1.1       droeschl   42:     $r->send_http_header;
                     43:     return OK if $r->header_only;
                     44: 
1.6       droeschl   45:     $r->print( Apache::loncommon::start_page(
                     46:                   'Communication Blocking Status Information',
                     47:                   undef, {'only_body' => 1}));
1.1       droeschl   48: 
1.6       droeschl   49:     $r->print(blockpage());
                     50:     
1.1       droeschl   51:     $r->print(Apache::loncommon::end_page());
1.6       droeschl   52: 
1.1       droeschl   53:     return OK;
                     54: }
1.6       droeschl   55: 
                     56: 
                     57: sub blockpage {
                     58: 
                     59:     # determine what kind of blocking we want details for
                     60:     Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['activity']);
                     61:     my $activity = $env{'form.activity'};
                     62: 
                     63:     if ($activity !~ /^[a-z]+$/) { return 'Error'; }
                     64: 
                     65: 
                     66:     # in case of a portfolio block we need to determine the owner of the files
                     67:     # we're trying to look at. This information is passed via query string.
                     68:     my ($uname, $udom);
                     69: 
                     70:     if ($activity eq 'port') {
                     71:         Apache::loncommon::get_unprocessed_cgi(
                     72:             $ENV{'QUERY_STRING'}, ['udom', 'uname'] );
                     73: 
                     74:         ($uname, $udom) = ($env{'form.uname'}, $env{'form.udom'});
                     75:         #TODO sanitize input: $uname, $udom
                     76:     }
                     77: 
                     78: 
                     79:     # retrieve start/end of possible active blocking
1.4       kalberla   80:     my %setters;
1.6       droeschl   81:     my ($startblock, $endblock) = Apache::loncommon::blockcheck(
                     82:                                         \%setters, $activity, $uname, $udom);
                     83: 
                     84:     # nothing to do if there's no active blocking
                     85:     unless ($startblock && $endblock) { return ''; }
                     86: 
                     87:     # lookup $activity -> description
                     88:                    #possible activity          #corresponding description
                     89:     my $description = 
                     90:                    $activity eq 'boards'     ? 'Discussion posts in this course'
1.7     ! bisitz     91:                  : $activity eq 'chat'       ? 'Chat Room'
1.6       droeschl   92:                  : $activity eq 'msgdisplay' ? 'This message'
                     93:                  : $activity eq 'blogs'      ? 'Blogs'
                     94:                  : $activity eq 'groups'     ? 'Groups in this course'
                     95:                  : $activity eq 'port'       ? get_portfolio_category(
                     96:                                                   $uname, $udom, \%setters) 
                     97:                  :                             'Communication';
                     98: 
                     99:     my $showstart = Apache::lonlocal::locallocaltime($startblock);
                    100:     my $showend   = Apache::lonlocal::locallocaltime($endblock);
                    101: 
                    102:     my $output;
                    103:     
                    104:     if ( ref($description) ne 'ARRAY' ) { 
                    105:         #default: $description is one of the above descriptions
                    106:         $output = mt( $description
                    107:                       . ' will be inaccessible between [_1] and [_2] because'
                    108:                       . ' communication is being blocked.'
                    109:                      ,$showstart, $showend);  
                    110:     } else {
                    111:         # @$description is is the array returned from get_portfolio_category()
                    112:         # and contains the description (e.g. "Portfolio files belonging to [_1]"
                    113:         # and the value for [_1]
                    114:         $output = mt( $$description[0]
                    115:                       . ' will be inaccessible between [_2] and [_3] because'
                    116:                       . ' communication is being blocked.'
                    117:                      ,$$description[1], $showstart, $showend)  
                    118:     }
                    119: 
                    120:     $output = "<p class=\"LC_info\">$output</p>";
                    121: 
                    122:     # show a table containing details, except if user is trying to look 
                    123:     # at a different user's portfolio files
                    124:     if (   $activity ne 'port'                        # no portfolio
                    125:         || (   $uname eq $env{'user.name'}            # or own portfolio
                    126:             && $udom  eq $env{'user.domain'} ) 
                    127:         || Apache::lonnet::is_course($udom, $uname) ) # or portfolio of a course
                    128:     {
                    129:         $output .= build_block_table($startblock,$endblock,\%setters);
1.4       kalberla  130:     }
1.6       droeschl  131: 
1.5       kalberla  132:     return $output;
                    133: }
                    134: 
                    135: sub build_block_table {
                    136:     my ($startblock,$endblock,$setters) = @_;
                    137:     my %lt = &Apache::lonlocal::texthash(
                    138:         'cacb' => 'Currently active communication blocks',
                    139:         'cour' => 'Course',
                    140:         'dura' => 'Duration',
                    141:         'blse' => 'Block set by'
                    142:     );
                    143:     my $output;
1.6       droeschl  144:     $output  = Apache::loncommon::start_data_table()
                    145:              . Apache::loncommon::data_table_caption($lt{'cacb'})
                    146:              . Apache::loncommon::start_data_table_header_row()
                    147:              . "<th>$lt{'cour'}</th> <th>$lt{'dura'}</th> <th>$lt{'blse'}</th>"
                    148:              . Apache::loncommon::end_data_table_header_row();
                    149: 
1.5       kalberla  150:     foreach my $course (keys(%{$setters})) {
                    151:         my %courseinfo=&Apache::lonnet::coursedescription($course);
                    152:         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
                    153:             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
                    154:             my $fullname = Apache::loncommon::plainname($uname,$udom);
                    155:             if (defined($env{'user.name'}) && defined($env{'user.domain'})
                    156:                 && $env{'user.name'} ne 'public'
1.6       droeschl  157:                 && $env{'user.domain'} ne 'public') 
                    158:             {
1.5       kalberla  159:                 $fullname = Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
                    160:             }
                    161:             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
                    162:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
                    163:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
1.6       droeschl  164:             my $duration = mt('[_1] to [_2]', $openblock, $closeblock);
                    165:             $output .= Apache::loncommon::start_data_table_row()
                    166:                      . "<td>$courseinfo{'description'}</td>"
                    167:                      . "<td>$duration</td>"
                    168:                      . "<td>$fullname</td>"
                    169:                      . Apache::loncommon::end_data_table_row();
1.5       kalberla  170:         }
                    171:     }
                    172:     $output .= Apache::loncommon::end_data_table();
1.4       kalberla  173: }
1.1       droeschl  174: 
1.6       droeschl  175: sub get_portfolio_category {
                    176:     my ($uname, $udom, $setters) = @_;
                    177: 
                    178:     if ($uname eq $env{'user.name'} && $udom eq $env{'user.domain'}) {
                    179:         # user's portolfio files
                    180: 
                    181:         return 'Your portfolio files';
                    182: 
                    183:     } elsif (Apache::lonnet::is_course($udom, $uname)) {
                    184:         # group portfolio files
                    185: 
                    186:         my $coursedesc;
                    187: 
                    188:         foreach my $course (keys(%{$setters})) {
                    189:             my %courseinfo = Apache::lonnet::coursedescription($course);
                    190:             $coursedesc    = $courseinfo{'description'};
                    191:         }
                    192: 
                    193:         return ["Group portfolio in the course '[_1]'", $coursedesc];
                    194:         
                    195:     } else {
                    196:         # different user's portfolio files
                    197:         
                    198:         my $plainname = Apache::loncommon::plainname($uname, $udom);
                    199: 
                    200:         unless (   $env{'user.name'}   eq 'public' 
                    201:                 && $env{'user.domain'} eq 'public' ) 
                    202:         {
                    203:             $plainname = Apache::loncommon::aboutmewrapper(
                    204:                             $plainname, $uname, $udom);
                    205:         }
                    206: 
                    207:         return ['Portfolio files belonging to [_1]', $plainname];
                    208:     }
                    209: }
                    210: 
1.1       droeschl  211: 1;
                    212: __END__

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