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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # "About Me" Personal Information
1.1       www         3: #
1.44    ! albertel    4: # $Id: lonaboutme.pm,v 1.43 2006/08/02 03:05:10 raeburn 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 />';
                    284:         $output .= &mt('A total of [_1] portfolio files owned by [_2] are available for viewing.',$filecounts->{'both'},$name).'<ul>';
                    285:         if ($filecounts->{'withoutpass'}) {
                    286:             $output .= '<li>'.&mt('[_1] files are either publicly accessible, or directly available to you because of your current role, domain and/or username.',$filecounts->{'withoutpass'}).'</li>';   
                    287:         }
                    288:         if ($filecounts->{'withpass'}) {
                    289:             $output .= '<li>'.&mt('[_1] files will be available after you have entered a passphrase set for each specific file.',$filecounts->{'withpass'}).'</li>';
                    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) = @_;
                    354:     my ($cdom,$cnum,$name) = aboutme_info($r);
                    355:     my $portaccess = 'withoutpass';
                    356:     if (exists($env{'form.portaccess'})) {
                    357:         $portaccess = $env{'form.portaccess'};
                    358:     }
                    359:     my $output = '<form name="displaystatus" method="post">'.
                    360:                  &mt('File access type: ').'<select name="portaccess">';
                    361:     foreach my $type ('withoutpass','withpass','both') {
                    362:         $output .= '<option value="'.$type.'" ';
                    363:         if ($portaccess eq $type) {
                    364:             $output .= 'selected="selected"';
                    365:         }
                    366:         $output .= '>'.$lt->{$type}.'</option>';
                    367:     }
                    368:     $output .= '</select>'."\n".
                    369:                '<input type="submit" name="portaccessbutton" value="'.
                    370:                &mt('Update display').'">'.
                    371:                '<input type="hidden" name="action" value="'.
                    372:                $env{'form.action'}.'"/>';
                    373:     $output .= '</form><br /><br />';
                    374:     $r->print($output);
                    375:     my $filecounts = &portfolio_files($r,'listfiles',$lt);
                    376:     my $query_string = &build_query_string();
                    377:     $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
                    378:                '/aboutme'.$query_string.'">'.
                    379:                &mt('Information about [_1]',$name).'</a>');
                    380:     return;
                    381: }
                    382: 
                    383: sub portfolio_files {
                    384:     my ($r,$mode,$lt) = @_;
                    385:     my ($cdom,$cnum,$name) = &aboutme_info($r);
                    386:     my $filecounts = {
                    387:                        withpass    => 0,
                    388:                        withoutpass => 0,
                    389:                        both        => 0,
                    390:                      };
                    391:     my $current_permissions =
1.44    ! albertel  392: 	&Apache::lonnet::get_portfile_permissions($cdom,$cnum);
1.43      raeburn   393:     my %access_controls = 
1.44    ! albertel  394: 	&Apache::lonnet::get_access_controls($current_permissions);
1.43      raeburn   395:     my %allfileshash;
                    396:     my $portaccess;
                    397:     if ($mode eq 'showlink') {
                    398:         $portaccess = 'both';
                    399:     } else {
                    400:         $portaccess = 'withoutpass';
                    401:         if (exists($env{'form.portaccess'})) {
                    402:             $portaccess = $env{'form.portaccess'};
                    403:         }
                    404:     }
                    405: 
                    406:     foreach my $filename (keys(%access_controls)) {
                    407:         my $access_status = 
1.44    ! albertel  408:             &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,undef,
        !           409: 						  $access_controls{$filename});
1.43      raeburn   410:         if ($portaccess eq 'both') {
                    411:             if (($access_status ne 'ok') &&
                    412:                 ($access_status !~  /^[^:]+:guest_/)) {
                    413:                 next;
                    414:             }
                    415:         } elsif ($portaccess eq 'withoutpass') {
                    416:             if ($access_status ne 'ok') {
                    417:                 next;
                    418:             }
                    419:         } elsif ($portaccess eq 'withpass') {
                    420:             if ($access_status !~  /^[^:]+:guest_/) {
                    421:                 next;
                    422:             }
                    423:         }
                    424:         if ($mode eq 'listfiles') {
                    425:             $filename =~ s/^\///;
                    426:             my @pathitems = split('/',$filename);
                    427:             my $lasthash = \%allfileshash;
                    428:             while (@pathitems > 1) {
                    429:                 my $newlevel = shift(@pathitems);
                    430:                 if (!exists($lasthash->{$newlevel})) {
                    431:                     $lasthash->{$newlevel} = {};
                    432:                 }
                    433:                 $lasthash = $lasthash->{$newlevel};
                    434:             }
                    435:             $lasthash->{$pathitems[0]} = $filename;
                    436:         }
                    437:         if ($access_status eq 'ok') {
                    438:             $filecounts->{'withoutpass'} ++;
                    439:         } elsif ($access_status =~  /^[^:]+:guest_/) {
                    440:             $filecounts->{'withpass'} ++;
                    441:         }
                    442:     }
                    443:     $filecounts->{'both'} =  $filecounts->{'withoutpass'} +
                    444:                               $filecounts->{'withpass'};
                    445:     if ($mode eq 'listfiles') {
                    446:         my $output;
                    447:         if (keys(%allfileshash) > 0) {
                    448:             my $depth = 0;
                    449:             my $count = 0;
                    450:             $output = '<table border="0" cellpadding="2" cellspacing="0">';
                    451:             ($count,$output) = &parse_directory($r,$output,$depth,
                    452:                                                \%allfileshash,$count);
                    453:             $output .= '</table>';
                    454:         } else {
                    455:             my $access_text;
                    456:             if (ref($lt) eq 'HASH') {
                    457:                 $access_text = $lt->{$portaccess};   
                    458:             }
                    459:             $output .= &mt('There are no available files of the specified access type: [_1]',$access_text);
                    460:         }
                    461:         $r->print($output);
                    462:     }
                    463:     return $filecounts;
                    464: }
                    465: 
                    466: sub parse_directory {
                    467:     my ($r,$output,$depth,$currhash,$count) = @_;
                    468:     my ($cdom,$cnum,$name) = &aboutme_info($r);
                    469:     $depth ++;
                    470:     my @backgroundColors = ("#FFFFFF", "#F6F6F6");
                    471:     my $indent = '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/whitespace1.gif").'" width="25" height="1" alt="&nbsp;&nbsp;" border="0" />';
                    472:     $output .= $indent;
                    473:     foreach my $item (sort(keys(%{$currhash}))) {
                    474:         $count ++;
                    475:         my $backgroundcolor = $backgroundColors[$count%2]; 
                    476:         $output .= '<tr bgcolor="'.$backgroundcolor.'">';
                    477:         $output .= '<td>';
                    478:         for (my $i=0; $i<$depth; $i++) {
                    479:             $output .= $indent;
                    480:         }
                    481:         if (ref($currhash->{$item}) eq 'HASH') {
                    482:             my $title = $item;
                    483:             $title=~s/\"/\&quot;/g;
                    484:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.' border="0" />&nbsp;'.$title;
                    485:             ($count,$output) = &parse_directory($r,$output,$depth,
                    486:                                                 $currhash->{$item},$count);
                    487:         } else {
                    488:             my $showname;
                    489:             if ($currhash->{$item} =~ m|/([^/]+)$|) {
                    490:                 $showname = $1;
                    491:             } else {
                    492:                 $showname = $currhash->{$item};
                    493:             }
                    494:             $output .= '<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" />&nbsp;<a href="/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.$currhash->{$item}.'">'.$showname.'</a>';
                    495:         }
                    496:         $output .= '</td></tr>';
                    497:     }
                    498:     return ($count,$output);
                    499: }
1.1       www       500: 
                    501: 1;
                    502: __END__

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