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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # "About Me" Personal Information
1.1       www         3: #
1.50    ! albertel    4: # $Id: lonaboutme.pm,v 1.49 2006/08/04 20:41:32 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.47      albertel   51:     my (undef,undef,$cdom,$cnum,undef,$action)=split(/\//,$r->uri);
1.2       www        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
1.47      albertel   65:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                     66: 					    ['forceedit','forcestudent',
                     67: 					     'register']);
1.43      raeburn    68: 
                     69: # ----------------------------------------------- Available Portfolio file display 
1.47      albertel   70:     if (($target ne 'tex') && ($action eq 'portfolio')) {
1.43      raeburn    71:         &display_portfolio_header($r);
1.47      albertel   72:         &display_portfolio_files($r);
1.43      raeburn    73:         $r->print(&Apache::loncommon::end_page());
                     74:         return OK;
                     75:     }
                     76: 
1.2       www        77: # --------------------------------------------------------------- Force Student
                     78:     my $forcestudent='';
1.37      albertel   79:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.43      raeburn    80: 
                     81:     my $forceregister = '';
                     82:     if ($forcestudent eq '') {
                     83:         $forceregister = $env{'form.register'};
                     84:     }
1.2       www        85:        
                     86: # --------------------------------------- There is such a user, get environment
                     87:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.22      sakharuk   88:     if ($target ne 'tex') {
1.40      albertel   89: 	my $start_page = 
                     90: 	    &Apache::loncommon::start_page("Personal Information",undef,
                     91: 					   {'function'       => $forcestudent,
1.47      albertel   92:  					    'domain'         => $cdom,
1.40      albertel   93: 					    'force_register' =>
1.43      raeburn    94: 						            $forceregister,});
1.40      albertel   95: 	$r->print($start_page);
1.22      sakharuk   96: 	$r->print('<h1>'.&Apache::loncommon::plainname($cnum,$cdom).'</h1>');
                     97:     } else {
                     98: 	$r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
                     99:     }
1.6       www       100:     if ($courseenv{'nickname'}) {
                    101:        $r->print(
1.7       albertel  102:          '<h2>&quot;'.$courseenv{'nickname'}.
1.6       www       103:          '&quot;</h2>');
                    104:     }
1.22      sakharuk  105:     if ($target ne 'tex') {
                    106: 	$r->print('<h3>'.$Apache::lonnet::domaindescription{$cdom}.'</h3>'.
1.39      www       107: 		  '<p>'.&Apache::loncommon::messagewrapper('Send me a message',$cnum,$cdom).'</p>'.&Apache::lonrss::advertisefeeds($cnum,$cdom));
1.22      sakharuk  108:     } else {
                    109: 	$r->print('\textbf{'.$Apache::lonnet::domaindescription{$cdom}.'}\\\\');
                    110:     }
1.2       www       111:     my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
                    112:     my $allowed=0;
                    113: 
1.1       www       114: # does this user have privileges to post, etc?
1.2       www       115: 
1.37      albertel  116:        my $privleged=$allowed=(($env{'user.name'} eq $cnum) && 
                    117: 			       ($env{'user.domain'} eq $cdom));
1.23      sakharuk  118:        if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.2       www       119:  
                    120:        if ($allowed) {
1.43      raeburn   121:            my $query_string = &build_query_string({'forcestudent' => '1',});
1.32      albertel  122: 	   $r->print('<p><b>'.&mt('Privacy Note').':</b> '.
                    123: 		     &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.').
                    124: 		     '</p>'.
1.43      raeburn   125: 		     &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  126: 		     &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
                    127:        } elsif ($privleged && $target ne 'tex') {
1.43      raeburn   128:            my $query_string = &build_query_string({'forceedit' => '1',});
                    129: 	   $r->print('<p><a href="'.$r->uri.$query_string.'"><font size="+1">'.
1.32      albertel  130: 		     &mt('Edit').'</font></a></p>');
                    131:        }
1.37      albertel  132:       if (($env{'form.uploaddoc.filename'}) &&
                    133:           ($env{'form.storeupl'}) && ($allowed)) {
                    134:  	  if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
1.24      albertel  135: 	      if ($syllabus{'uploaded.photourl'}) {
                    136: 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
                    137: 	      }
                    138: 	      $syllabus{'uploaded.photourl'}=
                    139:                  &Apache::lonnet::userfileupload('uploaddoc',undef,'aboutme');
1.3       www       140:  	  }
                    141:           $syllabus{'uploaded.lastmodified'}=time;
                    142:           &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
                    143:        }
1.37      albertel  144:     if ($allowed && $env{'form.delupl'}) {
1.32      albertel  145: 	if ($syllabus{'uploaded.photourl'}) {
                    146: 	    &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
                    147: 	    delete($syllabus{'uploaded.photourl'});
                    148: 	    &Apache::lonnet::del('aboutme',['uploaded.photourl'],$cdom,$cnum);
                    149: 	}
                    150:     }
1.37      albertel  151:        if (($allowed) && ($env{'form.storesyl'})) {
1.2       www       152: 	   foreach (keys %syllabusfields) {
1.37      albertel  153:                my $field=$env{'form.'.$_};
1.2       www       154:                $field=~s/\s+$//s;
1.11      www       155:                $field=&Apache::lonfeedback::clear_out_html($field,
1.37      albertel  156:                                                            $env{'user.adv'});
1.4       www       157: 	       $syllabus{$_}=$field;
1.2       www       158:            }
                    159:            $syllabus{'uploaded.lastmodified'}=time;
                    160:            &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
                    161:        }
                    162: 
                    163: # ---------------------------------------------------------------- Get syllabus
                    164:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.5       www       165:        my $lastmod=$syllabus{'uploaded.lastmodified'};
1.18      www       166:        $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
                    167:        $r->print(&mt('Last updated').': '.$lastmod);
1.3       www       168:        if ($syllabus{'uploaded.photourl'}) {
1.24      albertel  169: 	   &Apache::lonnet::allowuploaded('/adm/aboutme',
                    170: 					  $syllabus{'uploaded.photourl'});
1.33      matthew   171: 	   my $image=
                    172:                qq{<img src="$syllabus{'uploaded.photourl'}" align="right" />};
1.27      albertel  173: 	   if ($target eq 'tex') {
                    174: 	       $image=&Apache::lonxml::xmlparse($r,'tex',$image);
1.26      sakharuk  175: 	   }
1.27      albertel  176: 	   $r->print($image);
1.3       www       177:        }
1.23      sakharuk  178:        if ($allowed) {
1.3       www       179:            $r->print(
1.32      albertel  180: 	 '<form method="post">
                    181:                <input type="submit" name="delupl" value="Delete Photo" />
                    182:           </form>'.
1.3       www       183: 	 '<form method="post" enctype="multipart/form-data">'.
1.18      www       184:          '<h3>'.&mt('Upload a Photo').'</h3>'.
1.3       www       185:          '<input type="file" name="uploaddoc" size="50">'.
                    186:          '<input type="submit" name="storeupl" value="Upload">'.
                    187: 	 '</form><form method="post">');
1.32      albertel  188: 
1.2       www       189:        }
                    190:        foreach (sort keys %syllabusfields) {
                    191:           if (($syllabus{$_}) || ($allowed)) {
                    192:               my $message=$syllabus{$_};
1.38      albertel  193: 	      &Apache::lonfeedback::newline_to_br(\$message);
1.2       www       194:               $message
                    195:              =~s/(http\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.29      www       196: 	      if ($allowed) {
                    197: 		  $message=&Apache::lonspeller::markeduptext($message);
                    198: 	      }
1.2       www       199: 	      $message=&Apache::lontexconvert::msgtexconverted($message);
1.22      sakharuk  200: 	      if ($target ne 'tex') {
                    201: 		  $r->print('<h3>'.$syllabusfields{$_}.'</h3><blockquote>'.
                    202:                             $message.'</blockquote>');
                    203: 	      } else {
                    204: 		     $r->print('\\\\\textbf{'.$syllabusfields{$_}.'}\\\\'.
1.25      sakharuk  205: 			       &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
1.22      sakharuk  206: 	      }
1.23      sakharuk  207:               if ($allowed) {
1.2       www       208:                  $r->print('<br /><textarea cols="80" rows="6" name="'.$_.'">'.
                    209: 			   $syllabus{$_}.
1.17      www       210:            '</textarea><input type="submit" name="storesyl" value="'.
                    211: 			   &mt('Store').'" />');
1.2       www       212: 	      }
                    213: 	  }
                    214:        }
1.23      sakharuk  215:        if ($allowed) {
1.2       www       216: 	   $r->print('</form>');
                    217:        }
1.46      albertel  218:        if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
1.2       www       219:     } else {
1.17      www       220:        $r->print('<p>'.&mt('No personal information provided').'.</p>');
1.8       www       221:     }
1.43      raeburn   222: 
                    223:     if ($target ne 'tex') {
                    224:         &print_portfiles_link($r);
                    225:     }
                    226: 
1.37      albertel  227:     if ($env{'request.course.id'}) {
                    228: 	if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})) {
1.22      sakharuk  229: 	    if ($target ne 'tex') {
1.30      sakharuk  230: 		$r->print('<a name="coursecomment" />');
1.22      sakharuk  231: 		$r->print('<hr /><h3>'.
                    232:                           &mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'</h3>'.
                    233:                           &mt('Shared by course faculty and staff').
                    234:                           &Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message").
1.19      www       235: '<br />');
1.41      albertel  236:                 &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
1.31      matthew   237:                 $r->print('<hr />');
                    238:                 if (&Apache::lonnet::allowed('vsa',
1.37      albertel  239:                                              $env{'request.course.id'}) ||
1.31      matthew   240:                     &Apache::lonnet::allowed('vsa',
1.37      albertel  241:                                              $env{'request.course.id'}.'/'.
                    242:                                              $env{'request.course.sec'})) {
1.35      matthew   243:                     $r->print(&Apache::loncommon::track_student_link
                    244:                               ('View recent activity by this student',
                    245:                                $cnum,$cdom).('&nbsp;'x2));
1.31      matthew   246:                 }
                    247:                 $r->print(&Apache::loncommon::noteswrapper('Add Records',$cnum,$cdom));
1.22      sakharuk  248: 	    } else {
                    249: 		$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  250: 		&Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
1.22      sakharuk  251: 	    }
1.8       www       252:         }
1.1       www       253:     }
1.40      albertel  254:     if ($target ne 'tex') {
                    255: 	$r->print(&Apache::loncommon::end_page());
                    256:     } else {
                    257: 	$r->print('\end{document}');
                    258:     }
1.1       www       259:     return OK;
1.43      raeburn   260: }
                    261: 
                    262: sub aboutme_info {
                    263:     my ($r) = @_;
                    264:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
                    265:     my $name = &Apache::loncommon::plainname($cnum,$cdom);
                    266:     return ($cdom,$cnum,$name);
                    267: }
                    268: 
                    269: sub print_portfiles_link {
                    270:     my ($r) = @_;
                    271:     my ($cdom,$cnum,$name) = &aboutme_info($r);
                    272:     my $filecounts = &portfolio_files($r,'showlink');
1.47      albertel  273:     my $query_string = &build_query_string();
1.43      raeburn   274:     my $output;
                    275:     if ($filecounts->{'both'} > 0) {
                    276:         $output = &mt('<h3>Viewable portfolio files</h3>');
1.47      albertel  277:         $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
1.43      raeburn   278:                    $query_string.'">'.&mt('Display file listing').
                    279:                    '</a><br /><br />';
1.45      albertel  280:         $output .= &mt('A total of [quant,_1,portfolio file] owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
1.43      raeburn   281:         if ($filecounts->{'withoutpass'}) {
1.45      albertel  282:             $output .= '<li>'.&mt('[quant,_1,file] are publicly accessible.',$filecounts->{'withoutpass'}).'</li>';   
1.43      raeburn   283:         }
                    284:         if ($filecounts->{'withpass'}) {
1.45      albertel  285:             $output .= '<li>'.&mt('[quant,_1,file] require a passphrase for access.',$filecounts->{'withpass'}).'</li>';
1.43      raeburn   286:         }
                    287:         $output .= '</ul>';
                    288:     }
                    289:     $r->print($output);
                    290:     return;
                    291: }
                    292: 
                    293: sub build_query_string {
                    294:     my ($new_items) = @_;
                    295:     my $query_string;
                    296:     my @formelements = ('register'); 
1.47      albertel  297:     my $new = 0;
1.43      raeburn   298:     if (ref($new_items) eq 'HASH') {
1.47      albertel  299:         $new = 1;
1.43      raeburn   300:         if (!defined($new_items->{'forceedit'}) && 
                    301:             !defined($new_items->{'forcestudent'})) {
                    302:             push(@formelements,('forceedit','forcestudent'));
                    303:         }
                    304:     } else {
                    305:         push(@formelements,('forceedit','forcestudent'));
                    306:     }
                    307:     foreach my $element (@formelements) {
                    308:         if (exists($env{'form.'.$element})) {
1.47      albertel  309:             if ((!$new) || (!defined($new_items->{$element}))) {
1.43      raeburn   310:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
                    311:             }
                    312:         }
                    313:     }
1.47      albertel  314:     if ($new) {
1.43      raeburn   315:         foreach my $key (keys(%{$new_items})) {
                    316:             $query_string .= '&amp;'.$key.'='.$new_items->{$key};
                    317:         }
                    318:     }
                    319:     $query_string =~ s/^\&amp;/\?/;
                    320:     return $query_string;
                    321: }
                    322: 
                    323: sub display_portfolio_header {
                    324:     my ($r) = @_;
                    325:     my ($cdom,$cnum,$name) = &aboutme_info($r);
                    326:     my $query_string = &build_query_string();
                    327:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    328:     my $forcestudent='';
                    329:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
                    330:     my $output =
                    331:         &Apache::loncommon::start_page('Viewable portfolio files',undef,
                    332:                                             {'function' => $forcestudent, 
                    333:                                              'domain'   => $cdom,});
                    334:     &Apache::lonhtmlcommon::add_breadcrumb
                    335:         ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
                    336:           text=>"Personal information - $name",
                    337:           title=>"Go to personal information page for $name"},
1.47      albertel  338:          {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
1.43      raeburn   339:           text=>"Viewable files - $name",
                    340:           title=>"Viewable portfolio files for $name"}
                    341: );
                    342:     $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
                    343:     $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
                    344:     $r->print($output);
                    345:     return;
                    346: }
                    347: 
                    348: sub display_portfolio_files {
1.47      albertel  349:     my ($r) = @_;
1.45      albertel  350:     my ($cdom,$cnum,$name) = &aboutme_info($r);
1.47      albertel  351:     my %lt = ( withoutpass => 'passphrase not required',
                    352: 	       withpass    => 'passphrase protected',
                    353: 	       both        => 'all access types ',);
                    354:     %lt = &Apache::lonlocal::texthash(%lt);
                    355: 
1.43      raeburn   356:     my $portaccess = 'withoutpass';
                    357:     if (exists($env{'form.portaccess'})) {
                    358:         $portaccess = $env{'form.portaccess'};
                    359:     }
1.47      albertel  360: 
1.45      albertel  361:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
                    362: 	.'" name="displaystatus" method="post">'.
                    363: 	&mt('File access type: ').'<select name="portaccess">';
1.43      raeburn   364:     foreach my $type ('withoutpass','withpass','both') {
                    365:         $output .= '<option value="'.$type.'" ';
                    366:         if ($portaccess eq $type) {
                    367:             $output .= 'selected="selected"';
                    368:         }
1.47      albertel  369:         $output .= '>'.&mt($type).'</option>';
1.43      raeburn   370:     }
                    371:     $output .= '</select>'."\n".
                    372:                '<input type="submit" name="portaccessbutton" value="'.
1.47      albertel  373:                &mt('Update display').'" />';
1.43      raeburn   374:     $output .= '</form><br /><br />';
                    375:     $r->print($output);
1.47      albertel  376:     my $filecounts = &portfolio_files($r,'listfiles',\%lt);
1.43      raeburn   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();
1.49      albertel  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.49      albertel  479:     my ($r,$depth,$currhash,$path) = @_;
1.43      raeburn   480:     my ($cdom,$cnum,$name) = &aboutme_info($r);
1.45      albertel  481:     $depth++;
                    482:     my $output;
1.49      albertel  483: 
                    484:     my $portfolio_root =  &Apache::portfolio::get_portfolio_root($cdom,$cnum); 
                    485:     my %dirlist = map {
                    486: 	    ((split('&',$_,2))[0],1)
                    487: 	} &Apache::lonnet::dirlist($path,$cdom,$cnum,$portfolio_root);
1.43      raeburn   488:     foreach my $item (sort(keys(%{$currhash}))) {
1.45      albertel  489:         $output .= &portfolio_row_start();
                    490:         $output .= '<td style="padding-left: '.($depth*25).'px">';
1.43      raeburn   491:         if (ref($currhash->{$item}) eq 'HASH') {
1.45      albertel  492:             my $title=&HTML::Entities::encode($item,'<>&"');
                    493:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" />&nbsp;'.$title;
1.47      albertel  494: 	    $output .= '</td><td></td></tr>';
1.49      albertel  495:             $output .= &parse_directory($r,$depth,$currhash->{$item},
                    496: 					$path.'/'.$item);
1.43      raeburn   497:         } else {
1.50    ! albertel  498: 	   
        !           499: 
        !           500: 	    my $file_name; 
        !           501: 	    if ($currhash->{$item} =~ m|/([^/]+)$|) {
        !           502: 		$file_name = $1;
        !           503: 	    } else {
        !           504: 		$file_name = $currhash->{$item};
        !           505: 	    }
        !           506: 	    my $have_meta = exists($dirlist{$file_name.'.meta'});
        !           507: 	    my $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
        !           508: 		$currhash->{$item};
        !           509: 
1.43      raeburn   510:             my $showname;
1.50    ! albertel  511: 	    if ($have_meta) {
        !           512: 		$showname = &Apache::lonnet::metadata($url,'title');
        !           513: 	    }
        !           514: 	    if ($showname eq '') {
        !           515: 		$showname = $file_name;
        !           516: 	    } else {
        !           517: 		$showname = $file_name.' ('.$showname.')';
        !           518: 	    }
        !           519: 
1.45      albertel  520:             $showname=&HTML::Entities::encode($showname,'<>&"');
1.49      albertel  521:             $output .= '<a href="'.$url.'">'.
                    522: 		'<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
                    523: 		'&nbsp;'.$showname.'</a>';
                    524: 	    $output.='</td><td>';
                    525: 	    &Apache::lonnet::logthis("sh $showname");
1.50    ! albertel  526: 	    if ($have_meta) {
1.49      albertel  527: 		$output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Catalog Information').'" src="'.
1.47      albertel  528: 		&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
1.49      albertel  529: 		'" class="LC_icon" /></a>';
                    530: 	    }
1.45      albertel  531: 	    $output .= '</td></tr>';
1.43      raeburn   532:         }
                    533:     }
1.45      albertel  534:     return $output;
1.43      raeburn   535: }
1.1       www       536: 
                    537: 1;
                    538: __END__

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