File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.160: download - view: text, annotated - select for diffs
Sat Jan 2 21:07:36 2021 UTC (3 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_11_3_msu, HEAD
- Blocking of user actions in a course during an exam can include access to
  "About Me" pages belonging to users in the course (course personnel with
  evb priv are exempt).

    1: # The LearningOnline Network
    2: # Personal Information Page
    3: #
    4: # $Id: lonaboutme.pm,v 1.160 2021/01/02 21:07:36 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: =pod
   30: 
   31: =head1 NAME
   32: 
   33: pache::lonaboutme
   34: 
   35: =head1 SYNOPSIS
   36: 
   37: (empty)
   38: 
   39: This is part of the LearningOnline Network with CAPA project
   40: described at http://www.lon-capa.org.
   41: 
   42: =head1 OVERVIEW
   43: 
   44: (empty)
   45: 
   46: 
   47: =head1 SUBROUTINES
   48: 
   49: =over
   50: 
   51: =item handler()
   52: 
   53: =item aboutme_info()
   54: 
   55: =item print_portfiles_link()
   56: 
   57: =item build_query_string()
   58: 
   59: =item display_portfolio_header()
   60: 
   61: =item display_portfolio_files()
   62: 
   63: =item portfolio_files()
   64: 
   65: =item build_hierarchy()
   66: 
   67: =item parse_directory()
   68: 
   69: =back
   70: 
   71: =cut
   72: 
   73: 
   74: package Apache::lonaboutme;
   75: 
   76: use strict;
   77: use Apache::Constants qw(:common);
   78: use Apache::loncommon;
   79: use Apache::lonnet;
   80: use Apache::lontexconvert;
   81: use Apache::lonhtmlgateway;
   82: use Apache::lonrss();
   83: use Apache::lonlocal;
   84: use Apache::lonmsgdisplay();
   85: use Apache::lontemplate;
   86: use Apache::longroup;
   87: use HTML::Entities();
   88: use Image::Magick;
   89: 
   90: sub handler {
   91:     my $r = shift;
   92:     &Apache::loncommon::content_type($r,'text/html');
   93:     $r->send_http_header;
   94:     return OK if $r->header_only;
   95:     my $target=$env{'form.grade_target'};
   96: # ------------------------------------------------------------ Print the screen
   97:     if ($target eq 'tex') {
   98:         $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
   99:     }
  100:     my (undef,undef,$cdom,$cnum,undef,$action)=split(/\//,$r->uri);
  101:     my $is_course;
  102: # Is this even a user?
  103:     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
  104:         &Apache::loncommon::simple_error_page($r,'No info',
  105:             'No user information available');
  106:         return OK;
  107:     } else {
  108:         $is_course = &Apache::lonnet::is_course($cdom,$cnum);
  109:     }
  110: 
  111:     my $candisplay = 1;
  112:     if (!$is_course) {
  113:         if ($action ne 'portfolio') {
  114:             $candisplay = &Apache::lonnet::usertools_access($cnum,$cdom,'aboutme');
  115:             if ((!$candisplay) && ($env{'request.course.id'})) {
  116:                 $candisplay = &aboutme_access($cnum,$cdom);
  117:             }
  118:             if (!$candisplay) {
  119:                 if ($target eq 'tex') {
  120:                     $r->print('\noindent{\large\textbf{'.&mt('No user personal information page available').'}}\\\\\\\\');
  121:                 } else {
  122:                     $r->print(&Apache::loncommon::start_page("Personal Information Page"));
  123:                     $r->print('<p class="_LC_info">'.&mt('No user personal information page available') .'</p>'.
  124:                         &mt('This is a result of one of the following:').'<ul>'.
  125:                         '<li>'.&mt('The administrator of this domain has disabled personal information page functionality for this specific user.').'</li>'.
  126:                         '<li>'.&mt('The domain has been configured to disable, by default, personal information page functionality for all users in the domain.').'</li>'.
  127:                         '</ul>');
  128:                     $r->print(&Apache::loncommon::end_page());
  129:                 }
  130:                 return OK;
  131:             }
  132:         }
  133:     }
  134: 
  135: # --------------------------------------------------------- The syllabus fields
  136:     my %syllabusfields=&Apache::lonlocal::texthash(
  137:        'aaa_contactinfo'   => 'Contact Information',
  138:        'bbb_aboutme'       => 'Personal Information',
  139:        'ccc_webreferences' => 'Web References');
  140: 
  141: # ------------------------------------------------------------ Get Query String
  142:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  143:                         ['forceedit','forcestudent','todocs',
  144:                          'register','popup','folderpath','title']);
  145: # ----------------------------------------------- Available Portfolio file display
  146:     if (($target ne 'tex') && ($action eq 'portfolio')) {
  147:         &display_portfolio_header($r,$is_course);
  148:         if ((!$is_course) && (!&Apache::lonnet::usertools_access($cnum,$cdom,'portfolio'))) {
  149:             $r->print('<h2>'.&mt('No user portfolio available') .'</h2>'.
  150:                 &mt('This is a result of one of the following:').'<ul>'.
  151:                 '<li>'.&mt('The administrator of this domain has disabled portfolio functionality for this specific user.').'</li>'.
  152:                 '<li>'.&mt('The domain has been configured to disable, by default, portfolio functionality for all users in the domain.').'</li>'.
  153:                 '</ul>');
  154:         } else {
  155:             my ($blocked,$blocktext) =
  156:                 &Apache::loncommon::blocking_status('port',$cnum,$cdom);
  157:             if (!$blocked) {
  158:                 &display_portfolio_files($r,$is_course);
  159:             } else {
  160:                 $r->print($blocktext);
  161:             }
  162:         }
  163:         $r->print(&Apache::loncommon::end_page());
  164:         return OK;
  165:     }
  166: 
  167:     if ($is_course) {
  168:         if ($target ne 'tex') {
  169:             my $args = {'function'       => undef,
  170:                         'domain'         => $cdom};
  171:             if ($env{'form.register'}) {
  172:                 $args->{'force_register'} = $env{'form.register'};
  173:             } else {
  174:                 my %coursedescription = 
  175:                     &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
  176:                 my $cdescr = $coursedescription{'description'};
  177:                 my $brcrum = [{href=>"/adm/$cdom/$cnum/aboutme",
  178:                                text=>&mt('Course Information - [_1]',$cdescr),
  179:                                no_mt=>1}
  180:                              ];
  181:                 $args->{'bread_crumbs'} = $brcrum;
  182:             }
  183:             my $start_page = &Apache::loncommon::start_page(
  184:                                  "Course Information",undef,$args);
  185:             $r->print($start_page);
  186:             $r->print('<h2>'.&mt('Group Portfolio').'</h2>');
  187:             &print_portfiles_link($r,$is_course);
  188:             $r->print(&Apache::loncommon::end_page());
  189:         }
  190:         return OK;
  191:     }
  192: 
  193: #------------Get rights
  194:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
  195:     my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
  196:     my ($allowed,$coursedomain,$coursenum);
  197:     if ($env{'request.course.id'}) {
  198:         $coursedomain = $env{'course.'.$env{'request.course.id'}.'.domain'};
  199:         $coursenum = $env{'course.'.$env{'request.course.id'}.'.num'};
  200:     }
  201:     my ($cfile) = 
  202:         &Apache::lonnet::can_edit_resource($env{'request.noversionuri'},
  203:                                            $coursenum,$coursedomain,
  204:                                            $env{'request.noversionuri'},
  205:                                            $env{'request.symb'});
  206:     if ($cfile ne '') {
  207:         $allowed = 1;
  208:     }
  209: 
  210:     if (!$env{'form.forceedit'} or $target eq 'tex') { $allowed=0; }
  211: 
  212: # --------------------------------------- There is such a user, get environment
  213: 
  214:     if ($target ne 'tex') {
  215:         my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
  216:         my $args = {'function' => undef,
  217:                     'domain'   => $cdom,
  218:                     'force_register' => $env{'form.register'},
  219:                    };
  220:         if ($env{'form.popup'}) { # Don't show breadcrumbs in popup window 
  221:             $args->{'no_nav_bar'} = 1;
  222:         } elsif (!$env{'form.register'}) { #Don't show breadcrumbs twice, when this page is part of course content and you call it
  223:             if (($env{'request.course.id'}) &&
  224:                  ($env{'form.folderpath'} =~ /^supplemental/)) {
  225:                 my $crstype = &Apache::loncommon::course_type();
  226:                 my $title = $env{'form.title'};
  227:                 if ($title eq '') {
  228:                     $title = &mt('Personal Information Page');
  229:                 }
  230:                 my $brcrum =
  231:                     &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
  232:                 if (ref($brcrum) eq 'ARRAY') {
  233:                     $args->{'bread_crumbs'} = $brcrum;
  234:                 }
  235:             } else {
  236:                 $args->{'bread_crumbs'} = [{href=>"/adm/$cdom/$cnum/aboutme",
  237:                                             text=>"Personal Information Page"}];
  238:             }
  239:         }
  240:         my $start_page = &Apache::loncommon::start_page('Personal Information Page',$rss_link,$args);
  241:         $r->print($start_page);
  242:    }
  243:    my ($blocked,$blocktext) =
  244:        &Apache::loncommon::blocking_status('about',$cnum,$cdom);
  245:    if ($blocked) {
  246:        if ($target eq 'tex') {
  247:            $r->print('\noindent{\large\textbf{'.&mt('No user personal information page available').'}}\\\\\\\\');
  248:        } else {
  249:            $r->print($blocktext);
  250:        }
  251:        $r->print(&Apache::loncommon::end_page());
  252:        return OK;
  253:    }
  254: 
  255: #----------------Print Privacy note (edit mode) or last modified date. 
  256: 
  257:     if ($target ne 'tex') {
  258:         #Print Privacy Note
  259:         if ($allowed) {
  260:             $r->print('<div class="LC_info">'
  261:                 .'<b>'.&mt('Privacy Note:').'</b> '
  262:                 .&mt('The information you submit can be viewed by anybody who is logged into LON-CAPA. Do not provide information that you are not ready to share publicly.')
  263:                 .'</div>'
  264:             );
  265:         } elsif ($syllabus{'uploaded.lastmodified'}) {
  266:         #Print last modified
  267:             my $lastmod=$syllabus{'uploaded.lastmodified'};
  268:             $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
  269:             $r->print('<div class="LC_info">');
  270:             $r->print(&mt('Last updated').': '.$lastmod . '');
  271:             $r->print('</div>');
  272:         }
  273:     }
  274: 
  275: #------Print Headtitle
  276:      if ($target ne 'tex') {
  277:          $r->print('<div class="LC_Box">'.
  278:                    '<h2 class="LC_hcell">'.&Apache::loncommon::plainname($cnum,$cdom).'</h2>');
  279:          if ($allowed) {
  280:              $r->print('<div style="margin: 0; float:left;">');
  281:              if ($courseenv{'nickname'}) {
  282:                  $r->print('<h2>&quot;'.$courseenv{'nickname'}.'&quot;</h2>');
  283:              }
  284:              $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3></div>');
  285:              #Print Help Text
  286:              $r->print('<div style="margin: 0; float:right;">'.
  287:                        &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).
  288:                        '</div><br clear="all" />');
  289:          } else {
  290:              if ($courseenv{'nickname'}) {
  291:                  $r->print('<h2>&quot;'.$courseenv{'nickname'}.'&quot;</h2>');
  292:              }
  293:              $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>');
  294:          }
  295:      } else {
  296:         $r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
  297:         $r->print('\textbf{'.&Apache::lonnet::domain($cdom,'description').'}\\\\');
  298:     }
  299: # does this user have privileges to post, etc?
  300: 
  301: 
  302:     my $query_string;
  303: 
  304:     if (($env{'form.uploaddoc.filename'}) &&
  305:           ($env{'form.storeupl'}) && ($allowed)) {
  306:         if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
  307:             if ($syllabus{'uploaded.photourl'}) {
  308:                 &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  309:             }
  310:             $syllabus{'uploaded.photourl'}=
  311:                 &Apache::lonnet::userfileupload('uploaddoc',undef,'aboutme',
  312:                     undef,undef,undef,undef,undef,undef,undef,'400','500');
  313:          }
  314:         $syllabus{'uploaded.lastmodified'}=time;
  315:         &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
  316:     }
  317:     if ($allowed && $env{'form.delupl'}) {
  318:         if ($syllabus{'uploaded.photourl'}) {
  319:             &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  320:             delete($syllabus{'uploaded.photourl'});
  321:             &Apache::lonnet::del('aboutme',['uploaded.photourl'],$cdom,$cnum);
  322:         }
  323:     }
  324:     if (($allowed) && ($env{'form.storesyl'})) {
  325:         foreach my $syl_field (keys(%syllabusfields)) {
  326:             my $field=$env{'form.'.$syl_field};
  327:             chomp($field);
  328:             my $gateway = Apache::lonhtmlgateway->new();
  329:             $field = $gateway->process_incoming_html($field,1);
  330:             $syllabus{$syl_field}=$field;
  331:         }
  332:         $syllabus{'uploaded.lastmodified'}=time;
  333:         &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
  334:     }
  335: 
  336:     my $image;
  337: # ---------------------------------------------------------------- Get syllabus
  338:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
  339:         if ($syllabus{'uploaded.photourl'}) {
  340:             &Apache::lonnet::allowuploaded('/adm/aboutme',$syllabus{'uploaded.photourl'});
  341: 
  342:             $image=qq|<img name="userPhoto" src="$syllabus{'uploaded.photourl'} " class="LC_AboutMe_Image" alt="Photo of the user" />|;
  343: 
  344:             if ($target eq 'tex') {
  345:                 $image=&Apache::lonxml::xmlparse($r,'tex',$image);
  346:             }
  347:         }
  348: 
  349:         if ($allowed) {
  350:             $r->print(
  351:                 '<form name="UploadPhoto" method="post" enctype="multipart/form-data" action="">'.
  352:                 '<h3>'.&mt('Upload a Photo').'</h3>'.
  353:                 '<p class="LC_info">'.
  354:                 &mt('LON-CAPA will automatically scale your uploaded file so the image will not exceed a width of 400px and a height of 500px.').'</p>'.
  355:                 '<input type="file" name="uploaddoc" size="50" />'.
  356:                 '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />'.
  357:                 '<input type="hidden" name="popup" value="'.$env{'form.popup'}.'" />'.
  358:                 '</form>');
  359:             if ($syllabus{'uploaded.photourl'}) {
  360:                 $r->print('<form name="delPhoto" method="post" action="" ><input type="submit" name="delupl" value="'.&mt('Delete Photo').'" /> </form>')
  361:             }
  362:             $r->print('<p></p>');
  363:         }
  364: 
  365:         if($allowed) {
  366:             $r->print('<form name="lonaboutmeFields" method="post" action="" >');
  367:         }
  368: 
  369:         if ($target ne 'tex') { #print Image
  370:             $r->print($image.'<div class="LC_clear_float_footer"></div>');
  371: 
  372:         } #End Print Image
  373: 
  374:        #Print Content eg. Contactinfo aboutme,...
  375:         &Apache::lontemplate::print_aboutme_content_template($r,$allowed,$target,\%syllabusfields,\%syllabus);
  376:        #End Print Content
  377: 
  378:         if ($target ne 'tex') { #Begin Print RSS and portfiles
  379:             &print_portfiles_link($r,$is_course);
  380:             if (&Apache::lonrss::advertisefeeds($cnum,$cdom) ne '') {
  381:                 &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box');
  382:                 $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom));
  383:                 &Apache::lontemplate::print_end_template($r);
  384:             }
  385: 
  386:         } #End  Print RSS and portfiles
  387: 
  388: 
  389:         if ($allowed) {
  390:             if ($env{'form.popup'}) {
  391:                 $r->print('<input type="hidden" name="popup" value="'.
  392:                     $env{'form.popup'}.'" />');
  393:             }
  394:             $r->print('</form>');
  395:         }
  396:         if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
  397:     } else {
  398:         $r->print('<p class="LC_info">'.&mt('No personal information provided').'.</p>');
  399:     }
  400: 
  401:     if ($env{'request.course.id'}
  402:         && &Apache::lonnet::allowed('srm',$env{'request.course.id'})
  403:         && &Apache::lonnet::in_course($cdom,$cnum,$coursedomain,$coursenum,undef,1)) {
  404:         if ($target ne 'tex') {
  405:             $r->print('<a name="coursecomment" />');
  406:             &Apache::lontemplate::print_start_template($r,&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course'),'LC_Box');
  407:             $r->print('<span class="LC_info">');
  408:             $r->print(&mt('Shared by course faculty and staff').&Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message"));
  409:             $r->print('</span>');
  410:             &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
  411:             &Apache::lontemplate::print_end_template($r);
  412: 
  413:         } else {
  414:             $r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
  415:             &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom,$target);
  416:         }
  417:     }
  418:     if ($target ne 'tex') {
  419:         $r->print('</div>');
  420:         if ($env{'form.popup'}) {
  421:             $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
  422:         }
  423:         $r->print(&Apache::loncommon::end_page());
  424:     } else {
  425:         $r->print('\end{document}');
  426:     }
  427: 
  428: 
  429: 
  430:     return OK;
  431: }
  432: 
  433: sub aboutme_info {
  434:     my ($r,$is_course) = @_;
  435:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
  436:     my $name;
  437:     if (!$is_course) {
  438:         $name = &Apache::loncommon::plainname($cnum,$cdom);
  439:     }
  440:     return ($cdom,$cnum,$name);
  441: }
  442: 
  443: sub print_portfiles_link {
  444:     my ($r,$is_course) = @_;
  445:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  446:     my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
  447:                                       $cdom,$cnum,$name);
  448:     my $query_string = &build_query_string();
  449:     my $output;
  450:     my %lt = &Apache::lonlocal::texthash(
  451:         'vpfi' => 'Viewable portfolio files',
  452:         'vgpf' => 'Viewable group portfolio files',
  453:         'difl' => 'Display file listing',
  454:     );
  455:     if ($filecounts->{'both'} > 0) {
  456:         $output = '<div class="LC_Box"><h4 class="LC_hcell">';
  457:         $output .= ($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
  458: 
  459:        #$output = '<h4>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
  460:         $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
  461:             $query_string.'">'.$lt{'difl'}.
  462:             '</a><br /><br />';
  463:         if ($filecounts->{'both'} == 1) {
  464:             if ($is_course) {
  465:                 $output .= &mt('One group portfolio file is available.').'<ul>';
  466:             } else {
  467:                 $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
  468:             }
  469:         } else {
  470:             if ($is_course) {
  471:                 $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
  472:             } else {
  473:                 $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
  474:             }
  475:         }
  476:         if ($filecounts->{'withoutpass'}) {
  477:             $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
  478:         }
  479:         if ($filecounts->{'withpass'}) {
  480:             $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
  481:         }
  482:         $output .= '</ul>';
  483:         $output .= '</div>';
  484:     } elsif ($is_course) {
  485:         $output .= '<div class="LC_info">'.&mt('There are currently no publicly accessible or password protected group portfolio files.').'</div>'; 
  486:     }
  487:     $r->print($output);
  488:     return;
  489: }
  490: 
  491: sub build_query_string {
  492:     my ($new_items) = @_;
  493:     my $query_string;
  494:     my @formelements = ('register');
  495:     my $new = 0;
  496:     if (ref($new_items) eq 'HASH') {
  497:         $new = 1;
  498:         if (!defined($new_items->{'forceedit'}) &&
  499:             !defined($new_items->{'forcestudent'})) {
  500:             push(@formelements,('forceedit','forcestudent'));
  501:         }
  502:     } else {
  503:         push(@formelements,('forceedit','forcestudent'));
  504:     }
  505:     foreach my $element (@formelements) {
  506:         if (exists($env{'form.'.$element})) {
  507:             if ((!$new) || (!defined($new_items->{$element}))) {
  508:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
  509:             }
  510:         }
  511:     }
  512:     if ($new) {
  513:         foreach my $key (keys(%{$new_items})) {
  514:             $query_string .= '&amp;'.$key.'='.$new_items->{$key};
  515:         }
  516:     }
  517:     $query_string =~ s/^\&amp;/\?/;
  518:     return $query_string;
  519: }
  520: 
  521: sub display_portfolio_header {
  522:     my ($r,$is_course) = @_;
  523:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  524:     my $query_string = &build_query_string();
  525:     my $args = {'domain' => $cdom};
  526:     if ($env{'form.forcestudent'}) {
  527:         $args->{'function'} = 'student';
  528:     }
  529:     my $output;
  530:     if ($is_course) {
  531:         if (($env{'request.course.id'} eq $cdom.'_'.$cnum) && 
  532:             ($env{'form.register'})) {
  533:             $args->{force_register} = $env{'form.register'};
  534:         } else {
  535:             my %coursedescription = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
  536:             my $cdescr = $coursedescription{'description'}; 
  537:             my $brcrum = [{href=>"/adm/$cdom/$cnum/aboutme".$query_string,
  538:                            text=>&mt('Course Information - [_1]',$cdescr),
  539:                            no_mt=>1},
  540:                           {href=>"/adm/$cdom/$cnum/aboutme/portfolio".$query_string,
  541:                            text=>'Viewable group portfolio files'}
  542:                          ];
  543:             $args->{bread_crumbs} = $brcrum;
  544:         }
  545:         $output = &Apache::loncommon::start_page('Viewable group portfolio files',undef,$args).
  546:                   '<h3>'.&mt('Group Portfolio files').'</h3>';
  547:     } else {
  548:         if ($env{'request.course.id'} && $env{'form.register'}) {
  549:             $args->{force_register} = $env{'form.register'};
  550:         } else {
  551:             my $brcrum = [{href  => "/adm/$cdom/$cnum/aboutme".$query_string,
  552:                           text  => &mt('Personal Information Page - [_1]',$name),
  553:                           title => &mt('Go to personal information page for [_1]',$name),
  554:                           no_mt => 1},
  555:                          {href  => "/adm/$cdom/$cnum/aboutme/portfolio".$query_string,
  556:                           text  => &mt('Viewable files'),
  557:                           title => &mt('Viewable portfolio files for [_1]',$name),
  558:                           no_mt => 1}
  559:                          ];
  560:             $args->{bread_crumbs} = $brcrum;
  561:         } 
  562:         $output  = 
  563:             &Apache::loncommon::start_page('Viewable portfolio files',
  564:                                            undef,$args).
  565:             '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
  566:     }
  567:     $r->print($output);
  568:     return;
  569: }
  570: 
  571: sub display_portfolio_files {
  572:     my ($r,$is_course) = @_;
  573:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  574:     my %lt = &Apache::lonlocal::texthash(
  575:         'withoutpass' => 'passphrase not required',
  576:         'withpass'    => 'passphrase protected',
  577:         'both'        => 'all access types ',
  578:     );
  579: 
  580:     my $portaccess = 'withoutpass';
  581:     if (exists($env{'form.portaccess'})) {
  582:         $portaccess = $env{'form.portaccess'};
  583:     }
  584: 
  585:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
  586:         .'" name="displaystatus" method="post">'.
  587:         &mt('File access type: ').'<select name="portaccess">';
  588:     foreach my $type ('withoutpass','withpass','both') {
  589:         $output .= '<option value="'.$type.'" ';
  590:         if ($portaccess eq $type) {
  591:             $output .= 'selected="selected"';
  592:         }
  593:         $output .= '>'.$lt{$type}.'</option>';
  594:     }
  595:     $output .= '</select>'."\n";
  596:     if ($env{'form.register'}) {
  597:         $output .= '<input type="hidden" name="register" value="'.$env{'form.register'}.'" />'."\n";
  598:     }
  599:     $output .= '<input type="submit" name="portaccessbutton" value="'.
  600:                &mt('Update display').'" />'.
  601:                '</form><br /><br />';
  602:     $r->print($output);
  603:     my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
  604:                                       $cdom,$cnum,$name);
  605:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
  606:         if ($env{'request.course.id'} && $env{'form.register'}) {
  607:             my $query_string = &build_query_string();
  608:             $r->print('<br /><a href="/adm/'.$cdom.'/'.$cnum.
  609:                       '/aboutme'.$query_string.'">');
  610:             if ($is_course) {
  611:                 $r->print(&mt('Course Information page'));
  612:             } else {
  613:                 $r->print(&mt('Information about [_1]',$name));
  614:             }
  615:             $r->print('</a>');
  616:         }
  617:     }
  618:     return;
  619: }
  620: 
  621: sub portfolio_files {
  622:     my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
  623:     my $filecounts = {
  624:                        withpass    => 0,
  625:                        withoutpass => 0,
  626:                        both        => 0,
  627:                      };
  628:     my $current_permissions =
  629:     &Apache::lonnet::get_portfile_permissions($cdom,$cnum);
  630:     my %access_controls =
  631:     &Apache::lonnet::get_access_controls($current_permissions);
  632:     my $portaccess;
  633:     if ($mode eq 'showlink') {
  634:         $portaccess = 'both';
  635:     } else {
  636:         $portaccess = 'withoutpass';
  637:         if (exists($env{'form.portaccess'})) {
  638:             $portaccess = $env{'form.portaccess'};
  639:         }
  640:     }
  641: 
  642:     my $diroutput;
  643:     if ($is_course) {
  644:         my %files_by_group;
  645:         my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
  646:         foreach my $filename (sort(keys(%access_controls))) {
  647:             my ($group,$path) = split('/',$filename,2);
  648:             if (exists($curr_groups{$group})) {
  649:                 $files_by_group{$group}{$path} = $access_controls{$filename};
  650:             }
  651:         }
  652:         foreach my $group (sort(keys(%files_by_group))) {
  653:             my %fileshash;
  654:             my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
  655:                                            $is_course,$filecounts,$mode,
  656:                                            $files_by_group{$group},
  657:                                            \%fileshash,$group);
  658:             if ($grpout) {
  659:                 $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
  660:             }
  661:         }
  662:     } else {
  663:         my %allfileshash;
  664:         $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
  665:                                       $filecounts,$mode,\%access_controls,
  666:                                       \%allfileshash);
  667:     }
  668:     if ($mode eq 'listfiles') {
  669:         if ($filecounts->{'both'}) {
  670:              $r->print($diroutput);
  671:         } else {
  672:             my $access_text;
  673:             if (ref($lt) eq 'HASH') {
  674:                 $access_text = $lt->{$portaccess};
  675:             }
  676:             $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
  677:         }
  678:     }
  679:     return $filecounts;
  680: }
  681: 
  682: sub build_hierarchy {
  683:     my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
  684:         $allfileshash,$group) = @_;
  685:     my $clientip = &Apache::lonnet::get_requestor_ip($r);
  686:     foreach my $filename (sort(keys(%{$access_info}))) {
  687:         my $access_status =
  688:            &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group,$clientip,
  689:                                                  $access_info->{$filename});
  690:         if ($portaccess eq 'both') {
  691:             if (($access_status ne 'ok') &&
  692:                 ($access_status !~  /^[^:]+:guest_/)) {
  693:                 next;
  694:             }
  695:         } elsif ($portaccess eq 'withoutpass') {
  696:             if ($access_status ne 'ok') {
  697:                 next;
  698:             }
  699:         } elsif ($portaccess eq 'withpass') {
  700:             if ($access_status !~  /^[^:]+:guest_/) {
  701:                 next;
  702:             }
  703:         }
  704:         if ($mode eq 'listfiles') {
  705:             $filename =~ s/^\///;
  706:             my @pathitems = split('/',$filename);
  707:             my $lasthash = $allfileshash;
  708:             while (@pathitems > 1) {
  709:                 my $newlevel = shift(@pathitems);
  710:                 if (!exists($lasthash->{$newlevel})) {
  711:                     $lasthash->{$newlevel} = {};
  712:                 }
  713:                 $lasthash = $lasthash->{$newlevel};
  714:             }
  715:             $lasthash->{$pathitems[0]} = $filename;
  716:         }
  717:         if ($access_status eq 'ok') {
  718:             $filecounts->{'withoutpass'} ++;
  719:         } elsif ($access_status =~  /^[^:]+:guest_/) {
  720:             $filecounts->{'withpass'} ++;
  721:         }
  722:     }
  723:     $filecounts->{'both'} =  $filecounts->{'withoutpass'} +
  724:                               $filecounts->{'withpass'};
  725:     my $output;
  726:     if ($mode eq 'listfiles') {
  727:         if ($filecounts->{'both'} > 0) {
  728:             $output = &Apache::loncommon::start_data_table();
  729:             $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
  730:                                         $group);
  731:             $output .= &Apache::loncommon::end_data_table();
  732:         }
  733:     }
  734:     return $output;
  735: }
  736: 
  737: sub parse_directory {
  738:     my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
  739:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  740:     $depth++;
  741:     my $output;
  742: 
  743:     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
  744:                                                                 $group);
  745:     my $getpropath = 1;
  746:     my ($listref,$listerror) =
  747:         &Apache::lonnet::dirlist($portfolio_root.$path,$cdom,$cnum,$getpropath);
  748:     my %dirlist;
  749:     if (ref($listref) eq 'ARRAY') {
  750:         %dirlist = map { ((split('&',$_,2))[0],1) } @{$listref};
  751:     }
  752:     foreach my $item (sort(keys(%{$currhash}))) {
  753:         $output .= &Apache::loncommon::start_data_table_row();
  754:         $output .= '<td style="padding-left: '.($depth*25).'px">';
  755:         if (ref($currhash->{$item}) eq 'HASH') {
  756:             my $title=&HTML::Entities::encode($item,'<>&"');
  757:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" />&nbsp;'.$title;
  758:             $output .= '</td><td>&nbsp;</td>'
  759:                       .&Apache::loncommon::end_data_table_row();
  760:             $output .= &parse_directory($r,$depth,$currhash->{$item},
  761:                     $path.'/'.$item,$is_course,$group);
  762:         } else {
  763:             my $file_name;
  764:             if ($currhash->{$item} =~ m|/([^/]+)$|) {
  765:                 $file_name = $1;
  766:             } else {
  767:                 $file_name = $currhash->{$item};
  768:             }
  769:             my $have_meta = exists($dirlist{$file_name.'.meta'});
  770:             my $url;
  771:             if ($is_course) {
  772:                 $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
  773:                     '/portfolio/'.$currhash->{$item};
  774:             } else {
  775:                 $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.$currhash->{$item};
  776:             }
  777:             my $showname;
  778:             if ($have_meta) {
  779:                 $showname = &Apache::lonnet::metadata($url,'title');
  780:             }
  781:             if ($showname eq '') {
  782:                 $showname = $file_name;
  783:             } else {
  784:                 $showname = $file_name.' ('.$showname.')';
  785:             }
  786: 
  787:             $showname=&HTML::Entities::encode($showname,'<>&"');
  788:             $output .= '<a href="'.$url.'">'.
  789:                 '<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
  790:                 '&nbsp;'.$showname.'</a>';
  791:             $output.='</td><td>';
  792:             if ($have_meta) {
  793:                 $output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Metadata').'" src="'.
  794:                     &Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.png').
  795:                     '" class="LC_icon" /></a>';
  796:             }
  797:             $output .= '</td>'
  798:                 .&Apache::loncommon::end_data_table_row();
  799:         }
  800:     } 
  801:     return $output;
  802: }
  803: 
  804: sub aboutme_access {
  805:     my ($uname,$udom) = @_;
  806:     my $privcheck = $env{'request.course.id'};
  807:     my $sec;
  808:     if ($env{'request.course.sec'} ne '') {
  809:         $sec = $env{'request.course.sec'};
  810:         $privcheck .= '/'.$sec;
  811:     }
  812:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  813:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  814:     if (($cdom eq '') || ($cnum eq '')) {
  815:         my %coursehash = &Apache::lonnet::coursedescription($env{'request.course.id'});
  816:         $cdom = $coursehash{'domain'};
  817:         $cnum = $coursehash{'cnum'};
  818:     }
  819:     if ((&Apache::lonnet::allowed('srm',$privcheck)) ||
  820:         (&Apache::lonnet::allowed('dff',$privcheck))) {
  821:         if (&Apache::lonnet::in_course($uname,$udom,$cnum,$cdom,undef,1)) {
  822:             return 1;
  823:         }
  824:     }
  825:     return;
  826: }
  827: 
  828: 1;
  829: __END__

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