File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.157: download - view: text, annotated - select for diffs
Thu Jun 19 00:36:29 2014 UTC (9 years, 10 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_11_1, version_2_11_0, HEAD
- Compilation of files to list on "Group Portfolio" page excludes entries
  from permissions.db for course which are not for current groups.

    1: # The LearningOnline Network
    2: # Personal Information Page
    3: #
    4: # $Id: lonaboutme.pm,v 1.157 2014/06/19 00:36:29 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: 
  244: #----------------Print Privacy note (edit mode) or last modified date. 
  245: 
  246:     if ($target ne 'tex') {
  247:         #Print Privacy Note
  248:         if ($allowed) {
  249:             $r->print('<div class="LC_info">'
  250:                 .'<b>'.&mt('Privacy Note:').'</b> '
  251:                 .&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.')
  252:                 .'</div>'
  253:             );
  254:         } elsif ($syllabus{'uploaded.lastmodified'}) {
  255:         #Print last modified
  256:             my $lastmod=$syllabus{'uploaded.lastmodified'};
  257:             $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
  258:             $r->print('<div class="LC_info">');
  259:             $r->print(&mt('Last updated').': '.$lastmod . '');
  260:             $r->print('</div>');
  261:         }
  262:     }
  263: 
  264: #------Print Headtitle
  265:      if ($target ne 'tex') {
  266:          $r->print('<div class="LC_Box">'.
  267:                    '<h2 class="LC_hcell">'.&Apache::loncommon::plainname($cnum,$cdom).'</h2>');
  268:          if ($allowed) {
  269:              $r->print('<div style="margin: 0; float:left;">');
  270:              if ($courseenv{'nickname'}) {
  271:                  $r->print('<h2>&quot;'.$courseenv{'nickname'}.'&quot;</h2>');
  272:              }
  273:              $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3></div>');
  274:              #Print Help Text
  275:              $r->print('<div style="margin: 0; float:right;">'.
  276:                        &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).
  277:                        '</div><br clear="all" />');
  278:          } else {
  279:              if ($courseenv{'nickname'}) {
  280:                  $r->print('<h2>&quot;'.$courseenv{'nickname'}.'&quot;</h2>');
  281:              }
  282:              $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>');
  283:          }
  284:      } else {
  285:         $r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
  286:         $r->print('\textbf{'.&Apache::lonnet::domain($cdom,'description').'}\\\\');
  287:     }
  288: # does this user have privileges to post, etc?
  289: 
  290: 
  291:     my $query_string;
  292: 
  293:     if (($env{'form.uploaddoc.filename'}) &&
  294:           ($env{'form.storeupl'}) && ($allowed)) {
  295:         if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
  296:             if ($syllabus{'uploaded.photourl'}) {
  297:                 &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  298:             }
  299:             $syllabus{'uploaded.photourl'}=
  300:                 &Apache::lonnet::userfileupload('uploaddoc',undef,'aboutme',
  301:                     undef,undef,undef,undef,undef,undef,undef,'400','500');
  302:          }
  303:         $syllabus{'uploaded.lastmodified'}=time;
  304:         &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
  305:     }
  306:     if ($allowed && $env{'form.delupl'}) {
  307:         if ($syllabus{'uploaded.photourl'}) {
  308:             &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  309:             delete($syllabus{'uploaded.photourl'});
  310:             &Apache::lonnet::del('aboutme',['uploaded.photourl'],$cdom,$cnum);
  311:         }
  312:     }
  313:     if (($allowed) && ($env{'form.storesyl'})) {
  314:         foreach my $syl_field (keys(%syllabusfields)) {
  315:             my $field=$env{'form.'.$syl_field};
  316:             chomp($field);
  317:             my $gateway = Apache::lonhtmlgateway->new();
  318:             $field = $gateway->process_incoming_html($field,1);
  319:             $syllabus{$syl_field}=$field;
  320:         }
  321:         $syllabus{'uploaded.lastmodified'}=time;
  322:         &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
  323:     }
  324: 
  325:     my $image;
  326: # ---------------------------------------------------------------- Get syllabus
  327:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
  328:         if ($syllabus{'uploaded.photourl'}) {
  329:             &Apache::lonnet::allowuploaded('/adm/aboutme',$syllabus{'uploaded.photourl'});
  330: 
  331:             $image=qq|<img name="userPhoto" src="$syllabus{'uploaded.photourl'} " class="LC_AboutMe_Image" alt="Photo of the user" />|;
  332: 
  333:             if ($target eq 'tex') {
  334:                 $image=&Apache::lonxml::xmlparse($r,'tex',$image);
  335:             }
  336:         }
  337: 
  338:         if ($allowed) {
  339:             $r->print(
  340:                 '<form name="UploadPhoto" method="post" enctype="multipart/form-data" action="">'.
  341:                 '<h3>'.&mt('Upload a Photo').'</h3>'.
  342:                 '<p class="LC_info">'.
  343:                 &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>'.
  344:                 '<input type="file" name="uploaddoc" size="50" />'.
  345:                 '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />'.
  346:                 '<input type="hidden" name="popup" value="'.$env{'form.popup'}.'" />'.
  347:                 '</form>');
  348:             if ($syllabus{'uploaded.photourl'}) {
  349:                 $r->print('<form name="delPhoto" method="post" action="" ><input type="submit" name="delupl" value="'.&mt('Delete Photo').'" /> </form>')
  350:             }
  351:             $r->print('<p></p>');
  352:         }
  353: 
  354:         if($allowed) {
  355:             $r->print('<form name="lonaboutmeFields" method="post" action="" >');
  356:         }
  357: 
  358:         if ($target ne 'tex') { #print Image
  359:             $r->print($image.'<div class="LC_clear_float_footer"></div>');
  360: 
  361:         } #End Print Image
  362: 
  363:        #Print Content eg. Contactinfo aboutme,...
  364:         &Apache::lontemplate::print_aboutme_content_template($r,$allowed,$target,\%syllabusfields,\%syllabus);
  365:        #End Print Content
  366: 
  367:         if ($target ne 'tex') { #Begin Print RSS and portfiles
  368:             &print_portfiles_link($r,$is_course);
  369:             if (&Apache::lonrss::advertisefeeds($cnum,$cdom) ne '') {
  370:                 &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box');
  371:                 $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom));
  372:                 &Apache::lontemplate::print_end_template($r);
  373:             }
  374: 
  375:         } #End  Print RSS and portfiles
  376: 
  377: 
  378:         if ($allowed) {
  379:             if ($env{'form.popup'}) {
  380:                 $r->print('<input type="hidden" name="popup" value="'.
  381:                     $env{'form.popup'}.'" />');
  382:             }
  383:             $r->print('</form>');
  384:         }
  385:         if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
  386:     } else {
  387:         $r->print('<p class="LC_info">'.&mt('No personal information provided').'.</p>');
  388:     }
  389: 
  390:     if ($env{'request.course.id'}
  391:         && &Apache::lonnet::allowed('srm',$env{'request.course.id'})
  392:         && &Apache::lonnet::in_course($cdom,$cnum,$coursedomain,$coursenum,undef,1)) {
  393:         if ($target ne 'tex') {
  394:             $r->print('<a name="coursecomment" />');
  395:             &Apache::lontemplate::print_start_template($r,&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course'),'LC_Box');
  396:             $r->print('<span class="LC_info">');
  397:             $r->print(&mt('Shared by course faculty and staff').&Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message"));
  398:             $r->print('</span>');
  399:             &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
  400:             &Apache::lontemplate::print_end_template($r);
  401: 
  402:         } else {
  403:             $r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
  404:             &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom, 'tex');
  405:         }
  406:     }
  407:     if ($target ne 'tex') {
  408:         $r->print('</div>');
  409:         if ($env{'form.popup'}) {
  410:             $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
  411:         }
  412:         $r->print(&Apache::loncommon::end_page());
  413:     } else {
  414:         $r->print('\end{document}');
  415:     }
  416: 
  417: 
  418: 
  419:     return OK;
  420: }
  421: 
  422: sub aboutme_info {
  423:     my ($r,$is_course) = @_;
  424:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
  425:     my $name;
  426:     if (!$is_course) {
  427:         $name = &Apache::loncommon::plainname($cnum,$cdom);
  428:     }
  429:     return ($cdom,$cnum,$name);
  430: }
  431: 
  432: sub print_portfiles_link {
  433:     my ($r,$is_course) = @_;
  434:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  435:     my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
  436:                                       $cdom,$cnum,$name);
  437:     my $query_string = &build_query_string();
  438:     my $output;
  439:     my %lt = &Apache::lonlocal::texthash(
  440:         'vpfi' => 'Viewable portfolio files',
  441:         'vgpf' => 'Viewable group portfolio files',
  442:         'difl' => 'Display file listing',
  443:     );
  444:     if ($filecounts->{'both'} > 0) {
  445:         $output = '<div class="LC_Box"><h4 class="LC_hcell">';
  446:         $output .= ($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
  447: 
  448:        #$output = '<h4>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
  449:         $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
  450:             $query_string.'">'.$lt{'difl'}.
  451:             '</a><br /><br />';
  452:         if ($filecounts->{'both'} == 1) {
  453:             if ($is_course) {
  454:                 $output .= &mt('One group portfolio file is available.').'<ul>';
  455:             } else {
  456:                 $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
  457:             }
  458:         } else {
  459:             if ($is_course) {
  460:                 $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
  461:             } else {
  462:                 $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
  463:             }
  464:         }
  465:         if ($filecounts->{'withoutpass'}) {
  466:             $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
  467:         }
  468:         if ($filecounts->{'withpass'}) {
  469:             $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
  470:         }
  471:         $output .= '</ul>';
  472:         $output .= '</div>';
  473:     } elsif ($is_course) {
  474:         $output .= '<div class="LC_info">'.&mt('There are currently no publicly accessible or password protected group portfolio files.').'</div>'; 
  475:     }
  476:     $r->print($output);
  477:     return;
  478: }
  479: 
  480: sub build_query_string {
  481:     my ($new_items) = @_;
  482:     my $query_string;
  483:     my @formelements = ('register');
  484:     my $new = 0;
  485:     if (ref($new_items) eq 'HASH') {
  486:         $new = 1;
  487:         if (!defined($new_items->{'forceedit'}) &&
  488:             !defined($new_items->{'forcestudent'})) {
  489:             push(@formelements,('forceedit','forcestudent'));
  490:         }
  491:     } else {
  492:         push(@formelements,('forceedit','forcestudent'));
  493:     }
  494:     foreach my $element (@formelements) {
  495:         if (exists($env{'form.'.$element})) {
  496:             if ((!$new) || (!defined($new_items->{$element}))) {
  497:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
  498:             }
  499:         }
  500:     }
  501:     if ($new) {
  502:         foreach my $key (keys(%{$new_items})) {
  503:             $query_string .= '&amp;'.$key.'='.$new_items->{$key};
  504:         }
  505:     }
  506:     $query_string =~ s/^\&amp;/\?/;
  507:     return $query_string;
  508: }
  509: 
  510: sub display_portfolio_header {
  511:     my ($r,$is_course) = @_;
  512:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  513:     my $query_string = &build_query_string();
  514:     my $args = {'domain' => $cdom};
  515:     if ($env{'form.forcestudent'}) {
  516:         $args->{'function'} = 'student';
  517:     }
  518:     my $output;
  519:     if ($is_course) {
  520:         if (($env{'request.course.id'} eq $cdom.'_'.$cnum) && 
  521:             ($env{'form.register'})) {
  522:             $args->{force_register} = $env{'form.register'};
  523:         } else {
  524:             my %coursedescription = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
  525:             my $cdescr = $coursedescription{'description'}; 
  526:             my $brcrum = [{href=>"/adm/$cdom/$cnum/aboutme".$query_string,
  527:                            text=>&mt('Course Information - [_1]',$cdescr),
  528:                            no_mt=>1},
  529:                           {href=>"/adm/$cdom/$cnum/aboutme/portfolio".$query_string,
  530:                            text=>'Viewable group portfolio files'}
  531:                          ];
  532:             $args->{bread_crumbs} = $brcrum;
  533:         }
  534:         $output = &Apache::loncommon::start_page('Viewable group portfolio files',undef,$args).
  535:                   '<h3>'.&mt('Group Portfolio files').'</h3>';
  536:     } else {
  537:         if ($env{'request.course.id'} && $env{'form.register'}) {
  538:             $args->{force_register} = $env{'form.register'};
  539:         } else {
  540:             my $brcrum = [{href  => "/adm/$cdom/$cnum/aboutme".$query_string,
  541:                           text  => &mt('Personal Information Page - [_1]',$name),
  542:                           title => &mt('Go to personal information page for [_1]',$name),
  543:                           no_mt => 1},
  544:                          {href  => "/adm/$cdom/$cnum/aboutme/portfolio".$query_string,
  545:                           text  => &mt('Viewable files'),
  546:                           title => &mt('Viewable portfolio files for [_1]',$name),
  547:                           no_mt => 1}
  548:                          ];
  549:             $args->{bread_crumbs} = $brcrum;
  550:         } 
  551:         $output  = 
  552:             &Apache::loncommon::start_page('Viewable portfolio files',
  553:                                            undef,$args).
  554:             '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
  555:     }
  556:     $r->print($output);
  557:     return;
  558: }
  559: 
  560: sub display_portfolio_files {
  561:     my ($r,$is_course) = @_;
  562:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  563:     my %lt = &Apache::lonlocal::texthash(
  564:         'withoutpass' => 'passphrase not required',
  565:         'withpass'    => 'passphrase protected',
  566:         'both'        => 'all access types ',
  567:     );
  568: 
  569:     my $portaccess = 'withoutpass';
  570:     if (exists($env{'form.portaccess'})) {
  571:         $portaccess = $env{'form.portaccess'};
  572:     }
  573: 
  574:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
  575:         .'" name="displaystatus" method="post">'.
  576:         &mt('File access type: ').'<select name="portaccess">';
  577:     foreach my $type ('withoutpass','withpass','both') {
  578:         $output .= '<option value="'.$type.'" ';
  579:         if ($portaccess eq $type) {
  580:             $output .= 'selected="selected"';
  581:         }
  582:         $output .= '>'.$lt{$type}.'</option>';
  583:     }
  584:     $output .= '</select>'."\n";
  585:     if ($env{'form.register'}) {
  586:         $output .= '<input type="hidden" name="register" value="'.$env{'form.register'}.'" />'."\n";
  587:     }
  588:     $output .= '<input type="submit" name="portaccessbutton" value="'.
  589:                &mt('Update display').'" />'.
  590:                '</form><br /><br />';
  591:     $r->print($output);
  592:     my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
  593:                                       $cdom,$cnum,$name);
  594:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
  595:         if ($env{'request.course.id'} && $env{'form.register'}) {
  596:             my $query_string = &build_query_string();
  597:             $r->print('<br /><a href="/adm/'.$cdom.'/'.$cnum.
  598:                       '/aboutme'.$query_string.'">');
  599:             if ($is_course) {
  600:                 $r->print(&mt('Course Information page'));
  601:             } else {
  602:                 $r->print(&mt('Information about [_1]',$name));
  603:             }
  604:             $r->print('</a>');
  605:         }
  606:     }
  607:     return;
  608: }
  609: 
  610: sub portfolio_files {
  611:     my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
  612:     my $filecounts = {
  613:                        withpass    => 0,
  614:                        withoutpass => 0,
  615:                        both        => 0,
  616:                      };
  617:     my $current_permissions =
  618:     &Apache::lonnet::get_portfile_permissions($cdom,$cnum);
  619:     my %access_controls =
  620:     &Apache::lonnet::get_access_controls($current_permissions);
  621:     my $portaccess;
  622:     if ($mode eq 'showlink') {
  623:         $portaccess = 'both';
  624:     } else {
  625:         $portaccess = 'withoutpass';
  626:         if (exists($env{'form.portaccess'})) {
  627:             $portaccess = $env{'form.portaccess'};
  628:         }
  629:     }
  630: 
  631:     my $diroutput;
  632:     if ($is_course) {
  633:         my %files_by_group;
  634:         my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
  635:         foreach my $filename (sort(keys(%access_controls))) {
  636:             my ($group,$path) = split('/',$filename,2);
  637:             if (exists($curr_groups{$group})) {
  638:                 $files_by_group{$group}{$path} = $access_controls{$filename};
  639:             }
  640:         }
  641:         foreach my $group (sort(keys(%files_by_group))) {
  642:             my %fileshash;
  643:             my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
  644:                                            $is_course,$filecounts,$mode,
  645:                                            $files_by_group{$group},
  646:                                            \%fileshash,$group);
  647:             if ($grpout) {
  648:                 $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
  649:             }
  650:         }
  651:     } else {
  652:         my %allfileshash;
  653:         $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
  654:                                       $filecounts,$mode,\%access_controls,
  655:                                       \%allfileshash);
  656:     }
  657:     if ($mode eq 'listfiles') {
  658:         if ($filecounts->{'both'}) {
  659:              $r->print($diroutput);
  660:         } else {
  661:             my $access_text;
  662:             if (ref($lt) eq 'HASH') {
  663:                 $access_text = $lt->{$portaccess};
  664:             }
  665:             $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
  666:         }
  667:     }
  668:     return $filecounts;
  669: }
  670: 
  671: sub build_hierarchy {
  672:     my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
  673:         $allfileshash,$group) = @_;
  674:     foreach my $filename (sort(keys(%{$access_info}))) {
  675:         my $access_status =
  676:            &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group,$$access_info{$filename});
  677:         if ($portaccess eq 'both') {
  678:             if (($access_status ne 'ok') &&
  679:                 ($access_status !~  /^[^:]+:guest_/)) {
  680:                 next;
  681:             }
  682:         } elsif ($portaccess eq 'withoutpass') {
  683:             if ($access_status ne 'ok') {
  684:                 next;
  685:             }
  686:         } elsif ($portaccess eq 'withpass') {
  687:             if ($access_status !~  /^[^:]+:guest_/) {
  688:                 next;
  689:             }
  690:         }
  691:         if ($mode eq 'listfiles') {
  692:             $filename =~ s/^\///;
  693:             my @pathitems = split('/',$filename);
  694:             my $lasthash = $allfileshash;
  695:             while (@pathitems > 1) {
  696:                 my $newlevel = shift(@pathitems);
  697:                 if (!exists($lasthash->{$newlevel})) {
  698:                     $lasthash->{$newlevel} = {};
  699:                 }
  700:                 $lasthash = $lasthash->{$newlevel};
  701:             }
  702:             $lasthash->{$pathitems[0]} = $filename;
  703:         }
  704:         if ($access_status eq 'ok') {
  705:             $filecounts->{'withoutpass'} ++;
  706:         } elsif ($access_status =~  /^[^:]+:guest_/) {
  707:             $filecounts->{'withpass'} ++;
  708:         }
  709:     }
  710:     $filecounts->{'both'} =  $filecounts->{'withoutpass'} +
  711:                               $filecounts->{'withpass'};
  712:     my $output;
  713:     if ($mode eq 'listfiles') {
  714:         if ($filecounts->{'both'} > 0) {
  715:             $output = &Apache::loncommon::start_data_table();
  716:             $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
  717:                                         $group);
  718:             $output .= &Apache::loncommon::end_data_table();
  719:         }
  720:     }
  721:     return $output;
  722: }
  723: 
  724: sub parse_directory {
  725:     my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
  726:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  727:     $depth++;
  728:     my $output;
  729: 
  730:     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
  731:                                                                 $group);
  732:     my $getpropath = 1;
  733:     my ($listref,$listerror) =
  734:         &Apache::lonnet::dirlist($portfolio_root.$path,$cdom,$cnum,$getpropath);
  735:     my %dirlist;
  736:     if (ref($listref) eq 'ARRAY') {
  737:         %dirlist = map { ((split('&',$_,2))[0],1) } @{$listref};
  738:     }
  739:     foreach my $item (sort(keys(%{$currhash}))) {
  740:         $output .= &Apache::loncommon::start_data_table_row();
  741:         $output .= '<td style="padding-left: '.($depth*25).'px">';
  742:         if (ref($currhash->{$item}) eq 'HASH') {
  743:             my $title=&HTML::Entities::encode($item,'<>&"');
  744:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" />&nbsp;'.$title;
  745:             $output .= '</td><td>&nbsp;</td>'
  746:                       .&Apache::loncommon::end_data_table_row();
  747:             $output .= &parse_directory($r,$depth,$currhash->{$item},
  748:                     $path.'/'.$item,$is_course,$group);
  749:         } else {
  750:             my $file_name;
  751:             if ($currhash->{$item} =~ m|/([^/]+)$|) {
  752:                 $file_name = $1;
  753:             } else {
  754:                 $file_name = $currhash->{$item};
  755:             }
  756:             my $have_meta = exists($dirlist{$file_name.'.meta'});
  757:             my $url;
  758:             if ($is_course) {
  759:                 $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
  760:                     '/portfolio/'.$currhash->{$item};
  761:             } else {
  762:                 $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.$currhash->{$item};
  763:             }
  764:             my $showname;
  765:             if ($have_meta) {
  766:                 $showname = &Apache::lonnet::metadata($url,'title');
  767:             }
  768:             if ($showname eq '') {
  769:                 $showname = $file_name;
  770:             } else {
  771:                 $showname = $file_name.' ('.$showname.')';
  772:             }
  773: 
  774:             $showname=&HTML::Entities::encode($showname,'<>&"');
  775:             $output .= '<a href="'.$url.'">'.
  776:                 '<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
  777:                 '&nbsp;'.$showname.'</a>';
  778:             $output.='</td><td>';
  779:             if ($have_meta) {
  780:                 $output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Metadata').'" src="'.
  781:                     &Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.png').
  782:                     '" class="LC_icon" /></a>';
  783:             }
  784:             $output .= '</td>'
  785:                 .&Apache::loncommon::end_data_table_row();
  786:         }
  787:     } 
  788:     return $output;
  789: }
  790: 
  791: sub aboutme_access {
  792:     my ($uname,$udom) = @_;
  793:     my $privcheck = $env{'request.course.id'};
  794:     my $sec;
  795:     if ($env{'request.course.sec'} ne '') {
  796:         $sec = $env{'request.course.sec'};
  797:         $privcheck .= '/'.$sec;
  798:     }
  799:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  800:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  801:     if (($cdom eq '') || ($cnum eq '')) {
  802:         my %coursehash = &Apache::lonnet::coursedescription($env{'request.course.id'});
  803:         $cdom = $coursehash{'domain'};
  804:         $cnum = $coursehash{'cnum'};
  805:     }
  806:     if ((&Apache::lonnet::allowed('srm',$privcheck)) ||
  807:         (&Apache::lonnet::allowed('dff',$privcheck))) {
  808:         if (&Apache::lonnet::in_course($uname,$udom,$cnum,$cdom,undef,1)) {
  809:             return 1;
  810:         }
  811:     }
  812:     return;
  813: }
  814: 
  815: 1;
  816: __END__

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