File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.63: download - view: text, annotated - select for diffs
Wed May 23 21:44:11 2007 UTC (17 years ago) by albertel
Branches: MAIN
CVS tags: version_2_4_X, version_2_4_2, version_2_4_1, version_2_4_0, HEAD
- only display the srm section if its a member of the course

    1: # The LearningOnline Network
    2: # "About Me" Personal Information
    3: #
    4: # $Id: lonaboutme.pm,v 1.63 2007/05/23 21:44:11 albertel Exp $
    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;
   35: use Apache::lontexconvert;
   36: use Apache::lonfeedback;
   37: use Apache::lonrss();
   38: use Apache::lonlocal;
   39: use Apache::lonmsgdisplay();
   40: use HTML::Entities();
   41: 
   42: sub handler {
   43:     my $r = shift;
   44:     &Apache::loncommon::content_type($r,'text/html');
   45:     $r->send_http_header;
   46:     return OK if $r->header_only;
   47:     my $target=$env{'form.grade_target'};
   48: # ------------------------------------------------------------ Print the screen
   49:     if ($target eq 'tex') {
   50: 	$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
   51:     }
   52:     my (undef,undef,$cdom,$cnum,undef,$action)=split(/\//,$r->uri);
   53:     my $is_course;
   54: # Is this even a user?
   55:     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
   56: 	&Apache::loncommon::simple_error_page($r,'No info',
   57: 					      'No user information available');
   58:         return OK;
   59:     } else {
   60:         $is_course = &Apache::lonnet::is_course($cdom,$cnum);
   61:     }
   62: 
   63: # --------------------------------------------------------- The syllabus fields
   64:     my %syllabusfields=&Apache::lonlocal::texthash(
   65:        'aaa_contactinfo'   => 'Contact Information',
   66:        'bbb_aboutme'       => 'About Me',
   67:        'ccc_webreferences' => 'Web References');
   68: 
   69: # ------------------------------------------------------------ Get Query String
   70:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
   71: 					    ['forceedit','forcestudent',
   72: 					     'register']);
   73: 
   74: # ----------------------------------------------- Available Portfolio file display 
   75:     if (($target ne 'tex') && ($action eq 'portfolio')) {
   76:         &display_portfolio_header($r,$is_course);
   77:         my ($blocked,$blocktext) = 
   78:            &Apache::loncommon::blocking_status('port',$cnum,$cdom);
   79:         if (!$blocked) {
   80:             &display_portfolio_files($r,$is_course);
   81:         } else {
   82:             $r->print($blocktext);
   83:         }
   84:         $r->print(&Apache::loncommon::end_page());
   85:         return OK;
   86:     }
   87: 
   88:     if ($is_course) {
   89:         if ($target ne 'tex') {
   90:             my $start_page =
   91:                 &Apache::loncommon::start_page(
   92:                     "Course Information",
   93:                      undef,
   94:                      {'function' => $env{'forcestudent'},
   95:                       'domain'   => $cdom,
   96:                       'force_register' => $env{'forceregister'},});
   97:             $r->print($start_page);
   98:             $r->print('<h2>'.&mt('Group files').'</h2>');
   99:             &print_portfiles_link($r,$is_course);
  100:             $r->print(&Apache::loncommon::end_page());
  101:         }
  102:         return OK;
  103:     }
  104: 
  105: # --------------------------------------------------------------- Force Student
  106:     my $forcestudent='';
  107:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
  108: 
  109:     my $forceregister = '';
  110:     if ($forcestudent eq '') {
  111:         $forceregister = $env{'form.register'};
  112:     }
  113:        
  114: # --------------------------------------- There is such a user, get environment
  115:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
  116:     if ($target ne 'tex') {
  117: 	my $start_page = 
  118: 	    &Apache::loncommon::start_page("Personal Information",undef,
  119: 					   {'function'       => $forcestudent,
  120:  					    'domain'         => $cdom,
  121: 					    'force_register' =>
  122: 						            $forceregister,});
  123: 	$r->print($start_page);
  124: 	$r->print('<h1>'.&Apache::loncommon::plainname($cnum,$cdom).'</h1>');
  125:     } else {
  126: 	$r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
  127:     }
  128:     if ($courseenv{'nickname'}) {
  129:        $r->print(
  130:          '<h2>&quot;'.$courseenv{'nickname'}.
  131:          '&quot;</h2>');
  132:     }
  133:     if ($target ne 'tex') {
  134: 	$r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>'.
  135: 		  '<p>'.&Apache::loncommon::messagewrapper('Send me a message',$cnum,$cdom).'</p>'.&Apache::lonrss::advertisefeeds($cnum,$cdom));
  136:     } else {
  137: 	$r->print('\textbf{'.&Apache::lonnet::domain($cdom,'description').'}\\\\');
  138:     }
  139:     my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
  140:     my $allowed=0;
  141: 
  142: # does this user have privileges to post, etc?
  143: 
  144:        my $privleged=$allowed=(($env{'user.name'} eq $cnum) && 
  145: 			       ($env{'user.domain'} eq $cdom));
  146:        if ($forcestudent or $target eq 'tex') { $allowed=0; }
  147:  
  148:        if ($allowed) {
  149:            my $query_string = &build_query_string({'forcestudent' => '1',});
  150: 	   $r->print('<p><b>'.&mt('Privacy Note').':</b> '.
  151: 		     &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.').
  152: 		     '</p>'.
  153: 		     &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>'.
  154: 		     &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
  155:        } elsif ($privleged && $target ne 'tex') {
  156:            my $query_string = &build_query_string({'forceedit' => '1',});
  157: 	   $r->print('<p><a href="'.$r->uri.$query_string.'"><font size="+1">'.
  158: 		     &mt('Edit').'</font></a></p>');
  159:        }
  160:       if (($env{'form.uploaddoc.filename'}) &&
  161:           ($env{'form.storeupl'}) && ($allowed)) {
  162:  	  if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
  163: 	      if ($syllabus{'uploaded.photourl'}) {
  164: 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  165: 	      }
  166: 	      $syllabus{'uploaded.photourl'}=
  167:                  &Apache::lonnet::userfileupload('uploaddoc',undef,'aboutme');
  168:  	  }
  169:           $syllabus{'uploaded.lastmodified'}=time;
  170:           &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
  171:        }
  172:     if ($allowed && $env{'form.delupl'}) {
  173: 	if ($syllabus{'uploaded.photourl'}) {
  174: 	    &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  175: 	    delete($syllabus{'uploaded.photourl'});
  176: 	    &Apache::lonnet::del('aboutme',['uploaded.photourl'],$cdom,$cnum);
  177: 	}
  178:     }
  179:        if (($allowed) && ($env{'form.storesyl'})) {
  180: 	   foreach my $syl_field (keys(%syllabusfields)) {
  181:                my $field=$env{'form.'.$syl_field};
  182:                $field=~s/\s+$//s;
  183:                $field=&Apache::lonfeedback::clear_out_html($field,
  184:                                                            $env{'user.adv'});
  185: 	       $syllabus{$syl_field}=$field;
  186:            }
  187:            $syllabus{'uploaded.lastmodified'}=time;
  188:            &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
  189:        }
  190: 
  191: # ---------------------------------------------------------------- Get syllabus
  192:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
  193:        my $lastmod=$syllabus{'uploaded.lastmodified'};
  194:        $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
  195:        $r->print(&mt('Last updated').': '.$lastmod);
  196:        if ($syllabus{'uploaded.photourl'}) {
  197: 	   &Apache::lonnet::allowuploaded('/adm/aboutme',
  198: 					  $syllabus{'uploaded.photourl'});
  199: 	   my $image=
  200:                qq{<img src="$syllabus{'uploaded.photourl'}" align="right" />};
  201: 	   if ($target eq 'tex') {
  202: 	       $image=&Apache::lonxml::xmlparse($r,'tex',$image);
  203: 	   }
  204: 	   $r->print($image);
  205:        }
  206:        if ($allowed) {
  207:            $r->print(
  208: 	 '<form method="post">
  209:                <input type="submit" name="delupl" value="Delete Photo" />
  210:           </form>'.
  211: 	 '<form method="post" enctype="multipart/form-data">'.
  212:          '<h3>'.&mt('Upload a Photo').'</h3>'.
  213:          '<input type="file" name="uploaddoc" size="50">'.
  214:          '<input type="submit" name="storeupl" value="Upload">'.
  215: 	 '</form><form method="post">');
  216: 
  217:        }
  218:        foreach my $field (sort(keys(%syllabusfields))) {
  219:           if (($syllabus{$field}) || ($allowed)) {
  220:               my $message=$syllabus{$field};
  221: 	      &Apache::lonfeedback::newline_to_br(\$message);
  222:               $message
  223:              =~s/(http\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
  224: 	      if ($allowed) {
  225: 		  $message=&Apache::lonspeller::markeduptext($message);
  226: 	      }
  227: 	      $message=&Apache::lontexconvert::msgtexconverted($message);
  228: 	      if ($target ne 'tex') {
  229: 		  $r->print('<h3>'.$syllabusfields{$field}.'</h3><blockquote>'.
  230:                             $message.'</blockquote>');
  231: 	      } else {
  232: 		     $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
  233: 			       &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
  234: 	      }
  235:               if ($allowed) {
  236:                  $r->print('<br /><textarea cols="80" rows="6" name="'.$field.'">'.
  237: 			   &HTML::Entities::encode($syllabus{$field},'"&<>').
  238:            '</textarea><input type="submit" name="storesyl" value="'.
  239: 			   &mt('Save').'" />');
  240: 	      }
  241: 	  }
  242:        }
  243:        if ($allowed) {
  244: 	   $r->print('</form>');
  245:        }
  246:        if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
  247:     } else {
  248:        $r->print('<p>'.&mt('No personal information provided').'.</p>');
  249:     }
  250: 
  251:     if ($target ne 'tex') {
  252:         &print_portfiles_link($r,$is_course);
  253:     }
  254: 
  255:     if ($env{'request.course.id'}
  256: 	&& &Apache::lonnet::allowed('srm',$env{'request.course.id'})
  257: 	&& &in_course($cdom,$cnum)) {
  258: 	if ($target ne 'tex') {
  259: 	    $r->print('<a name="coursecomment" />');
  260: 	    $r->print('<hr /><h3>'.
  261: 		      &mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'</h3>'.
  262: 		      &mt('Shared by course faculty and staff').
  263: 		      &Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message").
  264: 		      '<br />');
  265: 	    &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
  266: 	    $r->print('<hr />');
  267: 	    if (&Apache::lonnet::allowed('vsa',
  268: 					 $env{'request.course.id'}) ||
  269: 		&Apache::lonnet::allowed('vsa',
  270: 					 $env{'request.course.id'}.'/'.
  271: 					 $env{'request.course.sec'})) {
  272: 		$r->print(&Apache::loncommon::track_student_link
  273: 			  ('View recent activity by this student',
  274: 			   $cnum,$cdom).('&nbsp;'x2));
  275: 	    }
  276: 	    $r->print(&Apache::loncommon::noteswrapper('Add Records',$cnum,$cdom));
  277: 	} else {
  278: 	    $r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
  279: 	    &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
  280: 	}
  281:     }
  282:     if ($target ne 'tex') {
  283: 	$r->print(&Apache::loncommon::end_page());
  284:     } else {
  285: 	$r->print('\end{document}');
  286:     }
  287:     return OK;
  288: }
  289: 
  290: sub in_course {
  291:     my ($udom,$uname,$cdom,$cnum,$type) = @_;
  292:     $type ||= 'any';
  293:     if (!defined($cdom) || !defined($cnum)) {
  294: 	my $cid  = $env{'request.course.id'};
  295: 	$cdom = $env{'course.'.$cid.'.domain'};
  296: 	$cnum = $env{'course.'.$cid.'.num'};
  297:     }
  298:     my %roles = &Apache::lonnet::dump('roles',$udom,$uname);
  299:     my @course_roles = grep(m{^/\Q$cdom\E/\Q$cnum\E[/_]}, keys(%roles));
  300:     return 0 if (!@course_roles);
  301:     return 1 if ($type eq 'any');
  302:     my $now = time();
  303:     foreach my $role (@course_roles) {
  304: 	my (undef,$role_end,$role_start)=split(/\_/,$roles{$role});
  305: 	my $status = 'active';
  306: 	if ($role_start > 0 && $now < $role_start) {
  307: 	    $status = 'future';
  308: 	}
  309: 	if ($role_end > 0 && $now > $role_end) {
  310: 	    $status = 'previous';
  311: 	}
  312: 	return 1 if ($status eq $type);
  313:     }
  314:     return 0;
  315: }
  316: 
  317: sub aboutme_info {
  318:     my ($r,$is_course) = @_;
  319:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
  320:     my $name;
  321:     if (!$is_course) {
  322:         $name = &Apache::loncommon::plainname($cnum,$cdom);
  323:     }
  324:     return ($cdom,$cnum,$name);
  325: }
  326: 
  327: sub print_portfiles_link {
  328:     my ($r,$is_course) = @_;
  329:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  330:     my $filecounts = &portfolio_files($r,'showlink',undef,$is_course);
  331:     my $query_string = &build_query_string();
  332:     my $output;
  333:     my %lt = &Apache::lonlocal::texthash(
  334:                          vpfi => 'Viewable portfolio files',
  335:                          vgpf => 'Viewable group portfolio files',
  336:                          difl => 'Display file listing',
  337:              );                     
  338:     if ($filecounts->{'both'} > 0) {
  339:         $output = '<h3>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h3>';
  340:         $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
  341:                    $query_string.'">'.$lt{'difl'}.
  342:                    '</a><br /><br />';
  343:         if ($filecounts->{'both'} == 1) {
  344:             if ($is_course) {
  345:                 $output .= &mt('One group portfolio file is available.').'<ul>';
  346:             } else {
  347:                 $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
  348:             }
  349:         } else {
  350:             if ($is_course) {
  351:                 $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
  352:             } else {
  353:                 $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
  354:             }
  355:         }
  356:         if ($filecounts->{'withoutpass'}) {
  357: 	    $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
  358:         }
  359:         if ($filecounts->{'withpass'}) {
  360: 	    $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
  361:         }
  362:         $output .= '</ul>';
  363:     }
  364:     $r->print($output);
  365:     return;
  366: }
  367: 
  368: sub build_query_string {
  369:     my ($new_items) = @_;
  370:     my $query_string;
  371:     my @formelements = ('register'); 
  372:     my $new = 0;
  373:     if (ref($new_items) eq 'HASH') {
  374:         $new = 1;
  375:         if (!defined($new_items->{'forceedit'}) && 
  376:             !defined($new_items->{'forcestudent'})) {
  377:             push(@formelements,('forceedit','forcestudent'));
  378:         }
  379:     } else {
  380:         push(@formelements,('forceedit','forcestudent'));
  381:     }
  382:     foreach my $element (@formelements) {
  383:         if (exists($env{'form.'.$element})) {
  384:             if ((!$new) || (!defined($new_items->{$element}))) {
  385:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
  386:             }
  387:         }
  388:     }
  389:     if ($new) {
  390:         foreach my $key (keys(%{$new_items})) {
  391:             $query_string .= '&amp;'.$key.'='.$new_items->{$key};
  392:         }
  393:     }
  394:     $query_string =~ s/^\&amp;/\?/;
  395:     return $query_string;
  396: }
  397: 
  398: sub display_portfolio_header {
  399:     my ($r,$is_course) = @_;
  400:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  401:     my $query_string = &build_query_string();
  402:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  403:     my $forcestudent='';
  404:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
  405: 
  406:     my $output;
  407:     if ($is_course) {
  408:         $output = 
  409:             &Apache::loncommon::start_page('Viewable group portfolio files',undef,
  410:                                             {'function' => $forcestudent,
  411:                                              'domain'   => $cdom,});
  412:         $output .= '<h3>'.&mt('Group Portfolio files').'</h3>';
  413:     } else {
  414:         $output  =
  415:             &Apache::loncommon::start_page('Viewable portfolio files',undef,
  416:                                             {'function' => $forcestudent,
  417:                                              'domain'   => $cdom,});
  418:         if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
  419:             &Apache::lonhtmlcommon::add_breadcrumb
  420:                 ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
  421:                   text=>"Personal information - $name",
  422:                   title=>"Go to personal information page for $name"},                 {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
  423:                   text=>"Viewable files - $name",
  424:                   title=>"Viewable portfolio files for $name"}
  425:             );
  426:             $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
  427:         }
  428:         $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
  429:     }
  430:     $r->print($output);
  431:     return;
  432: }
  433: 
  434: sub display_portfolio_files {
  435:     my ($r,$is_course) = @_;
  436:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  437:     my %lt = ( withoutpass => 'passphrase not required',
  438: 	       withpass    => 'passphrase protected',
  439: 	       both        => 'all access types ',);
  440:     %lt = &Apache::lonlocal::texthash(%lt);
  441: 
  442:     my $portaccess = 'withoutpass';
  443:     if (exists($env{'form.portaccess'})) {
  444:         $portaccess = $env{'form.portaccess'};
  445:     }
  446: 
  447:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
  448: 	.'" name="displaystatus" method="post">'.
  449: 	&mt('File access type: ').'<select name="portaccess">';
  450:     foreach my $type ('withoutpass','withpass','both') {
  451:         $output .= '<option value="'.$type.'" ';
  452:         if ($portaccess eq $type) {
  453:             $output .= 'selected="selected"';
  454:         }
  455:         $output .= '>'.$lt{$type}.'</option>';
  456:     }
  457:     $output .= '</select>'."\n".
  458:                '<input type="submit" name="portaccessbutton" value="'.
  459:                &mt('Update display').'" />';
  460:     $output .= '</form><br /><br />';
  461:     $r->print($output);
  462:     my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course);
  463:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
  464:         my $query_string = &build_query_string();
  465:         $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
  466:                   '/aboutme'.$query_string.'">');
  467:         if ($is_course) {
  468:             $r->print(&mt('Course Information page'));
  469:         } else {
  470:             $r->print(&mt('Information about [_1]',$name));
  471:         }
  472:         $r->print('</a>');
  473:     }
  474:     return;
  475: }
  476: 
  477: sub portfolio_files {
  478:     my ($r,$mode,$lt,$is_course) = @_;
  479:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  480:     my $filecounts = {
  481:                        withpass    => 0,
  482:                        withoutpass => 0,
  483:                        both        => 0,
  484:                      };
  485:     my $current_permissions =
  486: 	&Apache::lonnet::get_portfile_permissions($cdom,$cnum);
  487:     my %access_controls = 
  488: 	&Apache::lonnet::get_access_controls($current_permissions);
  489:     my $portaccess;
  490:     if ($mode eq 'showlink') {
  491:         $portaccess = 'both';
  492:     } else {
  493:         $portaccess = 'withoutpass';
  494:         if (exists($env{'form.portaccess'})) {
  495:             $portaccess = $env{'form.portaccess'};
  496:         }
  497:     }
  498: 
  499:     my $diroutput;
  500:     if ($is_course) {
  501:         my %files_by_group;
  502:         foreach my $filename (sort(keys(%access_controls))) {
  503:             my ($group,$path) = split('/',$filename,2);
  504:             $files_by_group{$group}{$path} = $access_controls{$filename}; 
  505:         }
  506:         foreach my $group (sort(keys(%files_by_group))) {
  507:             my %fileshash;
  508:             my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
  509:                                            $is_course,$filecounts,$mode,
  510:                                            $files_by_group{$group},
  511:                                            \%fileshash,$group);
  512:             if ($grpout) {
  513:                 $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
  514:             }
  515:         }
  516:     } else {
  517:         my %allfileshash;
  518:         $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
  519:                                       $filecounts,$mode,\%access_controls,
  520:                                       \%allfileshash);
  521:     }
  522:     if ($mode eq 'listfiles') {
  523:         if ($filecounts->{'both'}) {
  524:              $r->print($diroutput);
  525:         } else {
  526:             my $access_text;
  527:             if (ref($lt) eq 'HASH') {
  528:                 $access_text = $lt->{$portaccess};   
  529:             }
  530:             $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
  531:         }
  532:     }
  533:     return $filecounts;
  534: }
  535: 
  536: { 
  537:     my $count=0;
  538:     sub portfolio_table_start {
  539: 	$count=0;
  540: 	return '<table class="LC_aboutme_port">';
  541:     }
  542:     sub portfolio_row_start {
  543: 	$count++;
  544: 	my $class = ($count%2)?'LC_odd_row'
  545: 	                      :'LC_even_row';
  546: 	return '<tr class="'.$class.'">';
  547:     }
  548: }
  549: 
  550: sub build_hierarchy {
  551:     my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
  552:         $allfileshash,$group) = @_;
  553:     foreach my $filename (sort(keys(%{$access_info}))) {
  554:         my $access_status =
  555:            &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group,                                                 $$access_info{$filename});
  556:         if ($portaccess eq 'both') {
  557:             if (($access_status ne 'ok') &&
  558:                 ($access_status !~  /^[^:]+:guest_/)) {
  559:                 next;
  560:             }
  561:         } elsif ($portaccess eq 'withoutpass') {
  562:             if ($access_status ne 'ok') {
  563:                 next;
  564:             }
  565:         } elsif ($portaccess eq 'withpass') {
  566:             if ($access_status !~  /^[^:]+:guest_/) {
  567:                 next;
  568:             }
  569:         }
  570:         if ($mode eq 'listfiles') {
  571:             $filename =~ s/^\///;
  572:             my @pathitems = split('/',$filename);
  573:             my $lasthash = $allfileshash;
  574:             while (@pathitems > 1) {
  575:                 my $newlevel = shift(@pathitems);
  576:                 if (!exists($lasthash->{$newlevel})) {
  577:                     $lasthash->{$newlevel} = {};
  578:                 }
  579:                 $lasthash = $lasthash->{$newlevel};
  580:             }
  581:             $lasthash->{$pathitems[0]} = $filename;
  582:         }
  583:         if ($access_status eq 'ok') {
  584:             $filecounts->{'withoutpass'} ++;
  585:         } elsif ($access_status =~  /^[^:]+:guest_/) {
  586:             $filecounts->{'withpass'} ++;
  587:         }
  588:     }
  589:     $filecounts->{'both'} =  $filecounts->{'withoutpass'} +
  590:                               $filecounts->{'withpass'};
  591:     my $output;
  592:     if ($mode eq 'listfiles') {
  593:         if ($filecounts->{'both'} > 0) {
  594:             $output = &portfolio_table_start();
  595:             $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
  596:                                         $group);
  597:             $output .= '</table>';
  598:         }
  599:     }
  600:     return $output;
  601: }
  602: 
  603: sub parse_directory {
  604:     my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
  605:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  606:     $depth++;
  607:     my $output;
  608: 
  609:     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
  610:                                                                 $group);
  611:     my %dirlist = map {
  612: 	    ((split('&',$_,2))[0],1)
  613: 	} &Apache::lonnet::dirlist($path,$cdom,$cnum,$portfolio_root);
  614:     foreach my $item (sort(keys(%{$currhash}))) {
  615:         $output .= &portfolio_row_start();
  616:         $output .= '<td style="padding-left: '.($depth*25).'px">';
  617:         if (ref($currhash->{$item}) eq 'HASH') {
  618:             my $title=&HTML::Entities::encode($item,'<>&"');
  619:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" />&nbsp;'.$title;
  620: 	    $output .= '</td><td></td></tr>';
  621:             $output .= &parse_directory($r,$depth,$currhash->{$item},
  622: 					$path.'/'.$item,$is_course,$group);
  623:         } else {
  624: 	    my $file_name; 
  625: 	    if ($currhash->{$item} =~ m|/([^/]+)$|) {
  626: 		$file_name = $1;
  627: 	    } else {
  628: 		$file_name = $currhash->{$item};
  629: 	    }
  630: 	    my $have_meta = exists($dirlist{$file_name.'.meta'});
  631:             my $url;
  632:             if ($is_course) {
  633:                 $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
  634:                        '/portfolio/'.$currhash->{$item};
  635:             } else { 
  636: 	        $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
  637: 		       $currhash->{$item};
  638:             }
  639:             my $showname;
  640: 	    if ($have_meta) {
  641: 		$showname = &Apache::lonnet::metadata($url,'title');
  642: 	    }
  643: 	    if ($showname eq '') {
  644: 		$showname = $file_name;
  645: 	    } else {
  646: 		$showname = $file_name.' ('.$showname.')';
  647: 	    }
  648: 
  649:             $showname=&HTML::Entities::encode($showname,'<>&"');
  650:             $output .= '<a href="'.$url.'">'.
  651: 		'<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
  652: 		'&nbsp;'.$showname.'</a>';
  653: 	    $output.='</td><td>';
  654: 	    if ($have_meta) {
  655: 		$output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Catalog Information').'" src="'.
  656: 		&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
  657: 		'" class="LC_icon" /></a>';
  658: 	    }
  659: 	    $output .= '</td></tr>';
  660:         }
  661:     }
  662:     return $output;
  663: }
  664: 
  665: 1;
  666: __END__

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