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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # "About Me" Personal Information
1.1       www         3: #
1.53    ! raeburn     4: # $Id: lonaboutme.pm,v 1.52 2006/08/16 19:40:46 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.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 {
        !           284:             $output .= &mt('A total of [quant,_1,portfolio file] owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
        !           285:         }
1.43      raeburn   286:         if ($filecounts->{'withoutpass'}) {
1.53    ! raeburn   287:             if ($filecounts->{'withoutpass'} == 1) {
        !           288:                 $output .= '<li>'.&mt('[quant,_1,file] is publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
        !           289:             } else {
        !           290:                 $output .= '<li>'.&mt('[quant,_1,file] are publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
        !           291:             }
1.43      raeburn   292:         }
                    293:         if ($filecounts->{'withpass'}) {
1.53    ! raeburn   294:             if ($filecounts->{'withpass'} == 1) {
        !           295:                 $output .= '<li>'.&mt('[quant,_1,file] requires a passphrase for access.',$filecounts->{'withpass'}).'</li>';
        !           296:             } else {
        !           297:                 $output .= '<li>'.&mt('[quant,_1,file] require a passphrase for access.',$filecounts->{'withpass'}).'</li>'; 
        !           298:             }
1.43      raeburn   299:         }
                    300:         $output .= '</ul>';
                    301:     }
                    302:     $r->print($output);
                    303:     return;
                    304: }
                    305: 
                    306: sub build_query_string {
                    307:     my ($new_items) = @_;
                    308:     my $query_string;
                    309:     my @formelements = ('register'); 
1.47      albertel  310:     my $new = 0;
1.43      raeburn   311:     if (ref($new_items) eq 'HASH') {
1.47      albertel  312:         $new = 1;
1.43      raeburn   313:         if (!defined($new_items->{'forceedit'}) && 
                    314:             !defined($new_items->{'forcestudent'})) {
                    315:             push(@formelements,('forceedit','forcestudent'));
                    316:         }
                    317:     } else {
                    318:         push(@formelements,('forceedit','forcestudent'));
                    319:     }
                    320:     foreach my $element (@formelements) {
                    321:         if (exists($env{'form.'.$element})) {
1.47      albertel  322:             if ((!$new) || (!defined($new_items->{$element}))) {
1.43      raeburn   323:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
                    324:             }
                    325:         }
                    326:     }
1.47      albertel  327:     if ($new) {
1.43      raeburn   328:         foreach my $key (keys(%{$new_items})) {
                    329:             $query_string .= '&amp;'.$key.'='.$new_items->{$key};
                    330:         }
                    331:     }
                    332:     $query_string =~ s/^\&amp;/\?/;
                    333:     return $query_string;
                    334: }
                    335: 
                    336: sub display_portfolio_header {
                    337:     my ($r) = @_;
                    338:     my ($cdom,$cnum,$name) = &aboutme_info($r);
                    339:     my $query_string = &build_query_string();
                    340:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    341:     my $forcestudent='';
                    342:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.53    ! raeburn   343:     my $output = 
1.43      raeburn   344:         &Apache::loncommon::start_page('Viewable portfolio files',undef,
                    345:                                             {'function' => $forcestudent, 
                    346:                                              'domain'   => $cdom,});
1.53    ! raeburn   347:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
        !           348:         &Apache::lonhtmlcommon::add_breadcrumb
        !           349:             ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
        !           350:               text=>"Personal information - $name",
        !           351:               title=>"Go to personal information page for $name"},
        !           352:              {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
        !           353:               text=>"Viewable files - $name",
        !           354:               title=>"Viewable portfolio files for $name"}
        !           355:         );
        !           356:         $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
        !           357:     }
1.43      raeburn   358:     $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
                    359:     $r->print($output);
                    360:     return;
                    361: }
                    362: 
                    363: sub display_portfolio_files {
1.47      albertel  364:     my ($r) = @_;
1.45      albertel  365:     my ($cdom,$cnum,$name) = &aboutme_info($r);
1.47      albertel  366:     my %lt = ( withoutpass => 'passphrase not required',
                    367: 	       withpass    => 'passphrase protected',
                    368: 	       both        => 'all access types ',);
                    369:     %lt = &Apache::lonlocal::texthash(%lt);
                    370: 
1.43      raeburn   371:     my $portaccess = 'withoutpass';
                    372:     if (exists($env{'form.portaccess'})) {
                    373:         $portaccess = $env{'form.portaccess'};
                    374:     }
1.47      albertel  375: 
1.45      albertel  376:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
                    377: 	.'" name="displaystatus" method="post">'.
                    378: 	&mt('File access type: ').'<select name="portaccess">';
1.43      raeburn   379:     foreach my $type ('withoutpass','withpass','both') {
                    380:         $output .= '<option value="'.$type.'" ';
                    381:         if ($portaccess eq $type) {
                    382:             $output .= 'selected="selected"';
                    383:         }
1.53    ! raeburn   384:         $output .= '>'.$lt{$type}.'</option>';
1.43      raeburn   385:     }
                    386:     $output .= '</select>'."\n".
                    387:                '<input type="submit" name="portaccessbutton" value="'.
1.47      albertel  388:                &mt('Update display').'" />';
1.43      raeburn   389:     $output .= '</form><br /><br />';
                    390:     $r->print($output);
1.47      albertel  391:     my $filecounts = &portfolio_files($r,'listfiles',\%lt);
1.53    ! raeburn   392:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
        !           393:         my $query_string = &build_query_string();
        !           394:         $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
        !           395:                   '/aboutme'.$query_string.'">'.
        !           396:                   &mt('Information about [_1]',$name).'</a>');
        !           397:     }
1.43      raeburn   398:     return;
                    399: }
                    400: 
                    401: sub portfolio_files {
                    402:     my ($r,$mode,$lt) = @_;
                    403:     my ($cdom,$cnum,$name) = &aboutme_info($r);
                    404:     my $filecounts = {
                    405:                        withpass    => 0,
                    406:                        withoutpass => 0,
                    407:                        both        => 0,
                    408:                      };
                    409:     my $current_permissions =
1.44      albertel  410: 	&Apache::lonnet::get_portfile_permissions($cdom,$cnum);
1.43      raeburn   411:     my %access_controls = 
1.44      albertel  412: 	&Apache::lonnet::get_access_controls($current_permissions);
1.43      raeburn   413:     my %allfileshash;
                    414:     my $portaccess;
                    415:     if ($mode eq 'showlink') {
                    416:         $portaccess = 'both';
                    417:     } else {
                    418:         $portaccess = 'withoutpass';
                    419:         if (exists($env{'form.portaccess'})) {
                    420:             $portaccess = $env{'form.portaccess'};
                    421:         }
                    422:     }
                    423: 
                    424:     foreach my $filename (keys(%access_controls)) {
                    425:         my $access_status = 
1.44      albertel  426:             &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,undef,
                    427: 						  $access_controls{$filename});
1.43      raeburn   428:         if ($portaccess eq 'both') {
                    429:             if (($access_status ne 'ok') &&
                    430:                 ($access_status !~  /^[^:]+:guest_/)) {
                    431:                 next;
                    432:             }
                    433:         } elsif ($portaccess eq 'withoutpass') {
                    434:             if ($access_status ne 'ok') {
                    435:                 next;
                    436:             }
                    437:         } elsif ($portaccess eq 'withpass') {
                    438:             if ($access_status !~  /^[^:]+:guest_/) {
                    439:                 next;
                    440:             }
                    441:         }
                    442:         if ($mode eq 'listfiles') {
                    443:             $filename =~ s/^\///;
                    444:             my @pathitems = split('/',$filename);
                    445:             my $lasthash = \%allfileshash;
                    446:             while (@pathitems > 1) {
                    447:                 my $newlevel = shift(@pathitems);
                    448:                 if (!exists($lasthash->{$newlevel})) {
                    449:                     $lasthash->{$newlevel} = {};
                    450:                 }
                    451:                 $lasthash = $lasthash->{$newlevel};
                    452:             }
                    453:             $lasthash->{$pathitems[0]} = $filename;
                    454:         }
                    455:         if ($access_status eq 'ok') {
                    456:             $filecounts->{'withoutpass'} ++;
                    457:         } elsif ($access_status =~  /^[^:]+:guest_/) {
                    458:             $filecounts->{'withpass'} ++;
                    459:         }
                    460:     }
                    461:     $filecounts->{'both'} =  $filecounts->{'withoutpass'} +
                    462:                               $filecounts->{'withpass'};
                    463:     if ($mode eq 'listfiles') {
                    464:         my $output;
                    465:         if (keys(%allfileshash) > 0) {
1.45      albertel  466:             $output = &portfolio_table_start();
1.49      albertel  467:             $output .= &parse_directory($r,0,\%allfileshash,'');
1.43      raeburn   468:             $output .= '</table>';
                    469:         } else {
                    470:             my $access_text;
                    471:             if (ref($lt) eq 'HASH') {
                    472:                 $access_text = $lt->{$portaccess};   
                    473:             }
                    474:             $output .= &mt('There are no available files of the specified access type: [_1]',$access_text);
                    475:         }
                    476:         $r->print($output);
                    477:     }
                    478:     return $filecounts;
                    479: }
                    480: 
1.45      albertel  481: { 
                    482:     my $count=0;
                    483:     sub portfolio_table_start {
                    484: 	$count=0;
                    485: 	return '<table class="LC_aboutme_port">';
                    486:     }
                    487:     sub portfolio_row_start {
                    488: 	$count++;
                    489: 	my $class = ($count%2)?'LC_odd_row'
                    490: 	                      :'LC_even_row';
                    491: 	return '<tr class="'.$class.'">';
                    492:     }
                    493: }
                    494: 
1.43      raeburn   495: sub parse_directory {
1.49      albertel  496:     my ($r,$depth,$currhash,$path) = @_;
1.43      raeburn   497:     my ($cdom,$cnum,$name) = &aboutme_info($r);
1.45      albertel  498:     $depth++;
                    499:     my $output;
1.49      albertel  500: 
1.53    ! raeburn   501:     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum);
1.49      albertel  502:     my %dirlist = map {
                    503: 	    ((split('&',$_,2))[0],1)
                    504: 	} &Apache::lonnet::dirlist($path,$cdom,$cnum,$portfolio_root);
1.43      raeburn   505:     foreach my $item (sort(keys(%{$currhash}))) {
1.45      albertel  506:         $output .= &portfolio_row_start();
                    507:         $output .= '<td style="padding-left: '.($depth*25).'px">';
1.43      raeburn   508:         if (ref($currhash->{$item}) eq 'HASH') {
1.45      albertel  509:             my $title=&HTML::Entities::encode($item,'<>&"');
                    510:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" />&nbsp;'.$title;
1.47      albertel  511: 	    $output .= '</td><td></td></tr>';
1.49      albertel  512:             $output .= &parse_directory($r,$depth,$currhash->{$item},
                    513: 					$path.'/'.$item);
1.43      raeburn   514:         } else {
1.50      albertel  515: 	   
                    516: 
                    517: 	    my $file_name; 
                    518: 	    if ($currhash->{$item} =~ m|/([^/]+)$|) {
                    519: 		$file_name = $1;
                    520: 	    } else {
                    521: 		$file_name = $currhash->{$item};
                    522: 	    }
                    523: 	    my $have_meta = exists($dirlist{$file_name.'.meta'});
                    524: 	    my $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
                    525: 		$currhash->{$item};
                    526: 
1.43      raeburn   527:             my $showname;
1.50      albertel  528: 	    if ($have_meta) {
                    529: 		$showname = &Apache::lonnet::metadata($url,'title');
                    530: 	    }
                    531: 	    if ($showname eq '') {
                    532: 		$showname = $file_name;
                    533: 	    } else {
                    534: 		$showname = $file_name.' ('.$showname.')';
                    535: 	    }
                    536: 
1.45      albertel  537:             $showname=&HTML::Entities::encode($showname,'<>&"');
1.49      albertel  538:             $output .= '<a href="'.$url.'">'.
                    539: 		'<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
                    540: 		'&nbsp;'.$showname.'</a>';
                    541: 	    $output.='</td><td>';
1.50      albertel  542: 	    if ($have_meta) {
1.49      albertel  543: 		$output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Catalog Information').'" src="'.
1.47      albertel  544: 		&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
1.49      albertel  545: 		'" class="LC_icon" /></a>';
                    546: 	    }
1.45      albertel  547: 	    $output .= '</td></tr>';
1.43      raeburn   548:         }
                    549:     }
1.45      albertel  550:     return $output;
1.43      raeburn   551: }
1.1       www       552: 
                    553: 1;
                    554: __END__

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