File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.70.4.4: download - view: text, annotated - select for diffs
Mon Nov 1 13:35:42 2010 UTC (13 years, 7 months ago) by raeburn
Branches: version_2_9_X
CVS tags: version_2_9_1
Diff to branchpoint 1.70: preferred, unified
- Backport 1.147.

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

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