File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.76: download - view: text, annotated - select for diffs
Tue Dec 2 23:35:21 2008 UTC (15 years, 5 months ago) by harmsja
Branches: MAIN
CVS tags: HEAD
layout changes. maybe helpfull for redesign team.
change fieldset to div
make headlines smaller image in div

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

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