File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.53: download - view: text, annotated - select for diffs
Fri Aug 18 13:49:34 2006 UTC (17 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_2_X, version_2_2_2, version_2_2_1, version_2_2_0, HEAD
Information about link to portfolio listing updated.  &get_portfolio_root() accepts domain and name arguments so catalog information is available in listing of viewable files. Some single/plural noun verb agreements.

    1: # The LearningOnline Network
    2: # "About Me" Personal Information
    3: #
    4: # $Id: lonaboutme.pm,v 1.53 2006/08/18 13:49:34 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: package Apache::lonaboutme;
   30: 
   31: use strict;
   32: use Apache::Constants qw(:common);
   33: use Apache::loncommon;
   34: use Apache::lonnet;
   35: use Apache::lontexconvert;
   36: use Apache::lonfeedback;
   37: use Apache::lonrss();
   38: use Apache::lonlocal;
   39: use Apache::lonmsgdisplay();
   40: use HTML::Entities();
   41: 
   42: sub handler {
   43:     my $r = shift;
   44:     &Apache::loncommon::content_type($r,'text/html');
   45:     $r->send_http_header;
   46:     return OK if $r->header_only;
   47:     my $target=$env{'form.grade_target'};
   48: # ------------------------------------------------------------ Print the screen
   49:     if ($target eq 'tex') {
   50: 	$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
   51:     }
   52:     my (undef,undef,$cdom,$cnum,undef,$action)=split(/\//,$r->uri);
   53: # Is this even a user?
   54:     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
   55: 	&Apache::loncommon::simple_error_page($r,'No info',
   56: 					      'No user information available');
   57:         return OK;
   58:     }
   59: # --------------------------------------------------------- The syllabus fields
   60:     my %syllabusfields=&Apache::lonlocal::texthash(
   61:        'aaa_contactinfo'   => 'Contact Information',
   62:        'bbb_aboutme'       => 'About Me',
   63:        'ccc_webreferences' => 'Web References');
   64: 
   65: # ------------------------------------------------------------ Get Query String
   66:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
   67: 					    ['forceedit','forcestudent',
   68: 					     'register']);
   69: 
   70: # ----------------------------------------------- Available Portfolio file display 
   71:     if (($target ne 'tex') && ($action eq 'portfolio')) {
   72:         &display_portfolio_header($r);
   73:         &display_portfolio_files($r);
   74:         $r->print(&Apache::loncommon::end_page());
   75:         return OK;
   76:     }
   77: 
   78: # --------------------------------------------------------------- Force Student
   79:     my $forcestudent='';
   80:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
   81: 
   82:     my $forceregister = '';
   83:     if ($forcestudent eq '') {
   84:         $forceregister = $env{'form.register'};
   85:     }
   86:        
   87: # --------------------------------------- There is such a user, get environment
   88:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
   89:     if ($target ne 'tex') {
   90: 	my $start_page = 
   91: 	    &Apache::loncommon::start_page("Personal Information",undef,
   92: 					   {'function'       => $forcestudent,
   93:  					    'domain'         => $cdom,
   94: 					    'force_register' =>
   95: 						            $forceregister,});
   96: 	$r->print($start_page);
   97: 	$r->print('<h1>'.&Apache::loncommon::plainname($cnum,$cdom).'</h1>');
   98:     } else {
   99: 	$r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
  100:     }
  101:     if ($courseenv{'nickname'}) {
  102:        $r->print(
  103:          '<h2>&quot;'.$courseenv{'nickname'}.
  104:          '&quot;</h2>');
  105:     }
  106:     if ($target ne 'tex') {
  107: 	$r->print('<h3>'.$Apache::lonnet::domaindescription{$cdom}.'</h3>'.
  108: 		  '<p>'.&Apache::loncommon::messagewrapper('Send me a message',$cnum,$cdom).'</p>'.&Apache::lonrss::advertisefeeds($cnum,$cdom));
  109:     } else {
  110: 	$r->print('\textbf{'.$Apache::lonnet::domaindescription{$cdom}.'}\\\\');
  111:     }
  112:     my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
  113:     my $allowed=0;
  114: 
  115: # does this user have privileges to post, etc?
  116: 
  117:        my $privleged=$allowed=(($env{'user.name'} eq $cnum) && 
  118: 			       ($env{'user.domain'} eq $cdom));
  119:        if ($forcestudent or $target eq 'tex') { $allowed=0; }
  120:  
  121:        if ($allowed) {
  122:            my $query_string = &build_query_string({'forcestudent' => '1',});
  123: 	   $r->print('<p><b>'.&mt('Privacy Note').':</b> '.
  124: 		     &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.').
  125: 		     '</p>'.
  126: 		     &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'</p><p><a href="'.$r->uri.$query_string.'">Show Public View</a>'.
  127: 		     &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
  128:        } elsif ($privleged && $target ne 'tex') {
  129:            my $query_string = &build_query_string({'forceedit' => '1',});
  130: 	   $r->print('<p><a href="'.$r->uri.$query_string.'"><font size="+1">'.
  131: 		     &mt('Edit').'</font></a></p>');
  132:        }
  133:       if (($env{'form.uploaddoc.filename'}) &&
  134:           ($env{'form.storeupl'}) && ($allowed)) {
  135:  	  if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
  136: 	      if ($syllabus{'uploaded.photourl'}) {
  137: 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  138: 	      }
  139: 	      $syllabus{'uploaded.photourl'}=
  140:                  &Apache::lonnet::userfileupload('uploaddoc',undef,'aboutme');
  141:  	  }
  142:           $syllabus{'uploaded.lastmodified'}=time;
  143:           &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
  144:        }
  145:     if ($allowed && $env{'form.delupl'}) {
  146: 	if ($syllabus{'uploaded.photourl'}) {
  147: 	    &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  148: 	    delete($syllabus{'uploaded.photourl'});
  149: 	    &Apache::lonnet::del('aboutme',['uploaded.photourl'],$cdom,$cnum);
  150: 	}
  151:     }
  152:        if (($allowed) && ($env{'form.storesyl'})) {
  153: 	   foreach (keys %syllabusfields) {
  154:                my $field=$env{'form.'.$_};
  155:                $field=~s/\s+$//s;
  156:                $field=&Apache::lonfeedback::clear_out_html($field,
  157:                                                            $env{'user.adv'});
  158: 	       $syllabus{$_}=$field;
  159:            }
  160:            $syllabus{'uploaded.lastmodified'}=time;
  161:            &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
  162:        }
  163: 
  164: # ---------------------------------------------------------------- Get syllabus
  165:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
  166:        my $lastmod=$syllabus{'uploaded.lastmodified'};
  167:        $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
  168:        $r->print(&mt('Last updated').': '.$lastmod);
  169:        if ($syllabus{'uploaded.photourl'}) {
  170: 	   &Apache::lonnet::allowuploaded('/adm/aboutme',
  171: 					  $syllabus{'uploaded.photourl'});
  172: 	   my $image=
  173:                qq{<img src="$syllabus{'uploaded.photourl'}" align="right" />};
  174: 	   if ($target eq 'tex') {
  175: 	       $image=&Apache::lonxml::xmlparse($r,'tex',$image);
  176: 	   }
  177: 	   $r->print($image);
  178:        }
  179:        if ($allowed) {
  180:            $r->print(
  181: 	 '<form method="post">
  182:                <input type="submit" name="delupl" value="Delete Photo" />
  183:           </form>'.
  184: 	 '<form method="post" enctype="multipart/form-data">'.
  185:          '<h3>'.&mt('Upload a Photo').'</h3>'.
  186:          '<input type="file" name="uploaddoc" size="50">'.
  187:          '<input type="submit" name="storeupl" value="Upload">'.
  188: 	 '</form><form method="post">');
  189: 
  190:        }
  191:        foreach (sort keys %syllabusfields) {
  192:           if (($syllabus{$_}) || ($allowed)) {
  193:               my $message=$syllabus{$_};
  194: 	      &Apache::lonfeedback::newline_to_br(\$message);
  195:               $message
  196:              =~s/(http\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
  197: 	      if ($allowed) {
  198: 		  $message=&Apache::lonspeller::markeduptext($message);
  199: 	      }
  200: 	      $message=&Apache::lontexconvert::msgtexconverted($message);
  201: 	      if ($target ne 'tex') {
  202: 		  $r->print('<h3>'.$syllabusfields{$_}.'</h3><blockquote>'.
  203:                             $message.'</blockquote>');
  204: 	      } else {
  205: 		     $r->print('\\\\\textbf{'.$syllabusfields{$_}.'}\\\\'.
  206: 			       &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
  207: 	      }
  208:               if ($allowed) {
  209:                  $r->print('<br /><textarea cols="80" rows="6" name="'.$_.'">'.
  210: 			   &HTML::Entities::encode($syllabus{$_},'"&<>').
  211:            '</textarea><input type="submit" name="storesyl" value="'.
  212: 			   &mt('Store').'" />');
  213: 	      }
  214: 	  }
  215:        }
  216:        if ($allowed) {
  217: 	   $r->print('</form>');
  218:        }
  219:        if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
  220:     } else {
  221:        $r->print('<p>'.&mt('No personal information provided').'.</p>');
  222:     }
  223: 
  224:     if ($target ne 'tex') {
  225:         &print_portfiles_link($r);
  226:     }
  227: 
  228:     if ($env{'request.course.id'}) {
  229: 	if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})) {
  230: 	    if ($target ne 'tex') {
  231: 		$r->print('<a name="coursecomment" />');
  232: 		$r->print('<hr /><h3>'.
  233:                           &mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'</h3>'.
  234:                           &mt('Shared by course faculty and staff').
  235:                           &Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message").
  236: '<br />');
  237:                 &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
  238:                 $r->print('<hr />');
  239:                 if (&Apache::lonnet::allowed('vsa',
  240:                                              $env{'request.course.id'}) ||
  241:                     &Apache::lonnet::allowed('vsa',
  242:                                              $env{'request.course.id'}.'/'.
  243:                                              $env{'request.course.sec'})) {
  244:                     $r->print(&Apache::loncommon::track_student_link
  245:                               ('View recent activity by this student',
  246:                                $cnum,$cdom).('&nbsp;'x2));
  247:                 }
  248:                 $r->print(&Apache::loncommon::noteswrapper('Add Records',$cnum,$cdom));
  249: 	    } else {
  250: 		$r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
  251: 		&Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
  252: 	    }
  253:         }
  254:     }
  255:     if ($target ne 'tex') {
  256: 	$r->print(&Apache::loncommon::end_page());
  257:     } else {
  258: 	$r->print('\end{document}');
  259:     }
  260:     return OK;
  261: }
  262: 
  263: sub aboutme_info {
  264:     my ($r) = @_;
  265:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
  266:     my $name = &Apache::loncommon::plainname($cnum,$cdom);
  267:     return ($cdom,$cnum,$name);
  268: }
  269: 
  270: sub print_portfiles_link {
  271:     my ($r) = @_;
  272:     my ($cdom,$cnum,$name) = &aboutme_info($r);
  273:     my $filecounts = &portfolio_files($r,'showlink');
  274:     my $query_string = &build_query_string();
  275:     my $output;
  276:     if ($filecounts->{'both'} > 0) {
  277:         $output = &mt('<h3>Viewable portfolio files</h3>');
  278:         $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
  279:                    $query_string.'">'.&mt('Display file listing').
  280:                    '</a><br /><br />';
  281:         if ($filecounts->{'both'} == 1) {
  282:             $output .= &mt('One portfolio file owned by [_2] is available.',$filecounts->{'both'},$name).'<ul>';
  283:         } else {
  284:             $output .= &mt('A total of [quant,_1,portfolio file] owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
  285:         }
  286:         if ($filecounts->{'withoutpass'}) {
  287:             if ($filecounts->{'withoutpass'} == 1) {
  288:                 $output .= '<li>'.&mt('[quant,_1,file] is publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
  289:             } else {
  290:                 $output .= '<li>'.&mt('[quant,_1,file] are publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
  291:             }
  292:         }
  293:         if ($filecounts->{'withpass'}) {
  294:             if ($filecounts->{'withpass'} == 1) {
  295:                 $output .= '<li>'.&mt('[quant,_1,file] requires a passphrase for access.',$filecounts->{'withpass'}).'</li>';
  296:             } else {
  297:                 $output .= '<li>'.&mt('[quant,_1,file] require a passphrase for access.',$filecounts->{'withpass'}).'</li>'; 
  298:             }
  299:         }
  300:         $output .= '</ul>';
  301:     }
  302:     $r->print($output);
  303:     return;
  304: }
  305: 
  306: sub build_query_string {
  307:     my ($new_items) = @_;
  308:     my $query_string;
  309:     my @formelements = ('register'); 
  310:     my $new = 0;
  311:     if (ref($new_items) eq 'HASH') {
  312:         $new = 1;
  313:         if (!defined($new_items->{'forceedit'}) && 
  314:             !defined($new_items->{'forcestudent'})) {
  315:             push(@formelements,('forceedit','forcestudent'));
  316:         }
  317:     } else {
  318:         push(@formelements,('forceedit','forcestudent'));
  319:     }
  320:     foreach my $element (@formelements) {
  321:         if (exists($env{'form.'.$element})) {
  322:             if ((!$new) || (!defined($new_items->{$element}))) {
  323:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
  324:             }
  325:         }
  326:     }
  327:     if ($new) {
  328:         foreach my $key (keys(%{$new_items})) {
  329:             $query_string .= '&amp;'.$key.'='.$new_items->{$key};
  330:         }
  331:     }
  332:     $query_string =~ s/^\&amp;/\?/;
  333:     return $query_string;
  334: }
  335: 
  336: sub display_portfolio_header {
  337:     my ($r) = @_;
  338:     my ($cdom,$cnum,$name) = &aboutme_info($r);
  339:     my $query_string = &build_query_string();
  340:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  341:     my $forcestudent='';
  342:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
  343:     my $output = 
  344:         &Apache::loncommon::start_page('Viewable portfolio files',undef,
  345:                                             {'function' => $forcestudent, 
  346:                                              'domain'   => $cdom,});
  347:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
  348:         &Apache::lonhtmlcommon::add_breadcrumb
  349:             ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
  350:               text=>"Personal information - $name",
  351:               title=>"Go to personal information page for $name"},
  352:              {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
  353:               text=>"Viewable files - $name",
  354:               title=>"Viewable portfolio files for $name"}
  355:         );
  356:         $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
  357:     }
  358:     $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
  359:     $r->print($output);
  360:     return;
  361: }
  362: 
  363: sub display_portfolio_files {
  364:     my ($r) = @_;
  365:     my ($cdom,$cnum,$name) = &aboutme_info($r);
  366:     my %lt = ( withoutpass => 'passphrase not required',
  367: 	       withpass    => 'passphrase protected',
  368: 	       both        => 'all access types ',);
  369:     %lt = &Apache::lonlocal::texthash(%lt);
  370: 
  371:     my $portaccess = 'withoutpass';
  372:     if (exists($env{'form.portaccess'})) {
  373:         $portaccess = $env{'form.portaccess'};
  374:     }
  375: 
  376:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
  377: 	.'" name="displaystatus" method="post">'.
  378: 	&mt('File access type: ').'<select name="portaccess">';
  379:     foreach my $type ('withoutpass','withpass','both') {
  380:         $output .= '<option value="'.$type.'" ';
  381:         if ($portaccess eq $type) {
  382:             $output .= 'selected="selected"';
  383:         }
  384:         $output .= '>'.$lt{$type}.'</option>';
  385:     }
  386:     $output .= '</select>'."\n".
  387:                '<input type="submit" name="portaccessbutton" value="'.
  388:                &mt('Update display').'" />';
  389:     $output .= '</form><br /><br />';
  390:     $r->print($output);
  391:     my $filecounts = &portfolio_files($r,'listfiles',\%lt);
  392:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
  393:         my $query_string = &build_query_string();
  394:         $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
  395:                   '/aboutme'.$query_string.'">'.
  396:                   &mt('Information about [_1]',$name).'</a>');
  397:     }
  398:     return;
  399: }
  400: 
  401: sub portfolio_files {
  402:     my ($r,$mode,$lt) = @_;
  403:     my ($cdom,$cnum,$name) = &aboutme_info($r);
  404:     my $filecounts = {
  405:                        withpass    => 0,
  406:                        withoutpass => 0,
  407:                        both        => 0,
  408:                      };
  409:     my $current_permissions =
  410: 	&Apache::lonnet::get_portfile_permissions($cdom,$cnum);
  411:     my %access_controls = 
  412: 	&Apache::lonnet::get_access_controls($current_permissions);
  413:     my %allfileshash;
  414:     my $portaccess;
  415:     if ($mode eq 'showlink') {
  416:         $portaccess = 'both';
  417:     } else {
  418:         $portaccess = 'withoutpass';
  419:         if (exists($env{'form.portaccess'})) {
  420:             $portaccess = $env{'form.portaccess'};
  421:         }
  422:     }
  423: 
  424:     foreach my $filename (keys(%access_controls)) {
  425:         my $access_status = 
  426:             &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,undef,
  427: 						  $access_controls{$filename});
  428:         if ($portaccess eq 'both') {
  429:             if (($access_status ne 'ok') &&
  430:                 ($access_status !~  /^[^:]+:guest_/)) {
  431:                 next;
  432:             }
  433:         } elsif ($portaccess eq 'withoutpass') {
  434:             if ($access_status ne 'ok') {
  435:                 next;
  436:             }
  437:         } elsif ($portaccess eq 'withpass') {
  438:             if ($access_status !~  /^[^:]+:guest_/) {
  439:                 next;
  440:             }
  441:         }
  442:         if ($mode eq 'listfiles') {
  443:             $filename =~ s/^\///;
  444:             my @pathitems = split('/',$filename);
  445:             my $lasthash = \%allfileshash;
  446:             while (@pathitems > 1) {
  447:                 my $newlevel = shift(@pathitems);
  448:                 if (!exists($lasthash->{$newlevel})) {
  449:                     $lasthash->{$newlevel} = {};
  450:                 }
  451:                 $lasthash = $lasthash->{$newlevel};
  452:             }
  453:             $lasthash->{$pathitems[0]} = $filename;
  454:         }
  455:         if ($access_status eq 'ok') {
  456:             $filecounts->{'withoutpass'} ++;
  457:         } elsif ($access_status =~  /^[^:]+:guest_/) {
  458:             $filecounts->{'withpass'} ++;
  459:         }
  460:     }
  461:     $filecounts->{'both'} =  $filecounts->{'withoutpass'} +
  462:                               $filecounts->{'withpass'};
  463:     if ($mode eq 'listfiles') {
  464:         my $output;
  465:         if (keys(%allfileshash) > 0) {
  466:             $output = &portfolio_table_start();
  467:             $output .= &parse_directory($r,0,\%allfileshash,'');
  468:             $output .= '</table>';
  469:         } else {
  470:             my $access_text;
  471:             if (ref($lt) eq 'HASH') {
  472:                 $access_text = $lt->{$portaccess};   
  473:             }
  474:             $output .= &mt('There are no available files of the specified access type: [_1]',$access_text);
  475:         }
  476:         $r->print($output);
  477:     }
  478:     return $filecounts;
  479: }
  480: 
  481: { 
  482:     my $count=0;
  483:     sub portfolio_table_start {
  484: 	$count=0;
  485: 	return '<table class="LC_aboutme_port">';
  486:     }
  487:     sub portfolio_row_start {
  488: 	$count++;
  489: 	my $class = ($count%2)?'LC_odd_row'
  490: 	                      :'LC_even_row';
  491: 	return '<tr class="'.$class.'">';
  492:     }
  493: }
  494: 
  495: sub parse_directory {
  496:     my ($r,$depth,$currhash,$path) = @_;
  497:     my ($cdom,$cnum,$name) = &aboutme_info($r);
  498:     $depth++;
  499:     my $output;
  500: 
  501:     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum);
  502:     my %dirlist = map {
  503: 	    ((split('&',$_,2))[0],1)
  504: 	} &Apache::lonnet::dirlist($path,$cdom,$cnum,$portfolio_root);
  505:     foreach my $item (sort(keys(%{$currhash}))) {
  506:         $output .= &portfolio_row_start();
  507:         $output .= '<td style="padding-left: '.($depth*25).'px">';
  508:         if (ref($currhash->{$item}) eq 'HASH') {
  509:             my $title=&HTML::Entities::encode($item,'<>&"');
  510:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" />&nbsp;'.$title;
  511: 	    $output .= '</td><td></td></tr>';
  512:             $output .= &parse_directory($r,$depth,$currhash->{$item},
  513: 					$path.'/'.$item);
  514:         } else {
  515: 	   
  516: 
  517: 	    my $file_name; 
  518: 	    if ($currhash->{$item} =~ m|/([^/]+)$|) {
  519: 		$file_name = $1;
  520: 	    } else {
  521: 		$file_name = $currhash->{$item};
  522: 	    }
  523: 	    my $have_meta = exists($dirlist{$file_name.'.meta'});
  524: 	    my $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
  525: 		$currhash->{$item};
  526: 
  527:             my $showname;
  528: 	    if ($have_meta) {
  529: 		$showname = &Apache::lonnet::metadata($url,'title');
  530: 	    }
  531: 	    if ($showname eq '') {
  532: 		$showname = $file_name;
  533: 	    } else {
  534: 		$showname = $file_name.' ('.$showname.')';
  535: 	    }
  536: 
  537:             $showname=&HTML::Entities::encode($showname,'<>&"');
  538:             $output .= '<a href="'.$url.'">'.
  539: 		'<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
  540: 		'&nbsp;'.$showname.'</a>';
  541: 	    $output.='</td><td>';
  542: 	    if ($have_meta) {
  543: 		$output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Catalog Information').'" src="'.
  544: 		&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
  545: 		'" class="LC_icon" /></a>';
  546: 	    }
  547: 	    $output .= '</td></tr>';
  548:         }
  549:     }
  550:     return $output;
  551: }
  552: 
  553: 1;
  554: __END__

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