Annotation of loncom/interface/lonaboutme.pm, revision 1.45

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

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