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

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

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