File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.93: download - view: text, annotated - select for diffs
Fri Feb 13 17:26:55 2009 UTC (15 years, 3 months ago) by neumanie
Branches: MAIN
CVS tags: HEAD
Change the desgin of aboutme,simple page,syllabus. Add/change css class's in loncommon.pm.

    1: # The LearningOnline Network
    2: # "About Me" Personal Information
    3: #
    4: # $Id: lonaboutme.pm,v 1.93 2009/02/13 17:26:55 neumanie 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: =pod
   30: 
   31: =head1 NAME
   32: 
   33: pache::lonaboutme
   34: 
   35: =head1 SYNOPSIS
   36: 
   37: (empty)
   38: 
   39: This is part of the LearningOnline Network with CAPA project
   40: described at http://www.lon-capa.org.
   41: 
   42: =head1 OVERVIEW
   43: 
   44: (empty)
   45: 
   46: 
   47: =head1 SUBROUTINES
   48: 
   49: =over
   50: 
   51: =item handler()
   52: 
   53: =item in_course()
   54: 
   55: =item aboutme_info()
   56: 
   57: =item print_portfiles_link()
   58: 
   59: =item build_query_string()
   60: 
   61: =item display_portfolio_header()
   62: 
   63: =item display_portfolio_files()
   64: 
   65: =item portfolio_files()
   66: 
   67: =item build_hierarchy()
   68: 
   69: =item parse_directory()
   70: 
   71: =back
   72: 
   73: =cut
   74: 
   75: 
   76: package Apache::lonaboutme;
   77: 
   78: use strict;
   79: use Apache::Constants qw(:common);
   80: use Apache::loncommon;
   81: use Apache::lonnet;
   82: use Apache::lontexconvert;
   83: use Apache::lonfeedback;
   84: use Apache::lonrss();
   85: use Apache::lonlocal;
   86: use Apache::lonmsgdisplay();
   87: use Apache::lontemplate;
   88: use HTML::Entities();
   89: use Image::Magick;
   90: 
   91: sub handler {
   92:     my $r = shift;
   93:     &Apache::loncommon::content_type($r,'text/html');
   94:     $r->send_http_header;
   95:     return OK if $r->header_only;
   96:     my $target=$env{'form.grade_target'};
   97: # ------------------------------------------------------------ Print the screen
   98:     if ($target eq 'tex') {
   99: 	$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
  100:     }
  101:     my (undef,undef,$cdom,$cnum,undef,$action)=split(/\//,$r->uri);
  102:     my $is_course;
  103: # Is this even a user?
  104:     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
  105: 	&Apache::loncommon::simple_error_page($r,'No info',
  106: 					      'No user information available');
  107:         return OK;
  108:     } else {
  109:         $is_course = &Apache::lonnet::is_course($cdom,$cnum);
  110:     }
  111: 
  112:     my $candisplay = 1;
  113:     if (!$is_course) {
  114:         if ($action ne 'portfolio') {
  115:             $candisplay = &Apache::lonnet::usertools_access($cnum,$cdom,'aboutme');
  116:             if ((!$candisplay) && ($env{'request.course.id'})) {
  117:                 $candisplay = &aboutme_access($cnum,$cdom);
  118:             }
  119:             if (!$candisplay) {
  120:                 if ($target eq 'tex') {
  121:                     $r->print('\noindent{\large\textbf{'.&mt('No user home page available').'}}\\\\\\\\');
  122:                 } else {
  123:                     $r->print(&Apache::loncommon::start_page("Personal Information"));
  124:                     $r->print('<h2>'.&mt('No user home page available') .'</h2>'.
  125:                               &mt('This is a result of one of the following:').'<ul>'.
  126:                               '<li>'.&mt('The administrator of this domain has disabled home page functionality for this specific user.').'</li>'.
  127:                               '<li>'.&mt('The domain has been configured to disable, by default, home page functionality for all users in the domain.').'</li>'.
  128:                               '</ul>');
  129:                     $r->print(&Apache::loncommon::end_page());
  130:                 }
  131:                 return OK;
  132:             }
  133:         }
  134:     }
  135: 
  136: # --------------------------------------------------------- The syllabus fields
  137:     my %syllabusfields=&Apache::lonlocal::texthash(
  138:        'aaa_contactinfo'   => 'Contact Information',
  139:        'bbb_aboutme'       => 'About Me',
  140:        'ccc_webreferences' => 'Web References');
  141: 
  142: # ------------------------------------------------------------ Get Query String
  143:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  144: 					    ['forceedit','forcestudent',
  145: 					     'register','popup']);
  146: 
  147: # ----------------------------------------------- Available Portfolio file display 
  148:     if (($target ne 'tex') && ($action eq 'portfolio')) {
  149:         &display_portfolio_header($r,$is_course);
  150:         if ((!$is_course) && (!&Apache::lonnet::usertools_access($cnum,$cdom,'portfolio'))) {
  151:             $r->print('<h2>'.&mt('No user portfolio available') .'</h2>'.
  152:                       &mt('This is a result of one of the following:').'<ul>'.
  153:                       '<li>'.&mt('The administrator of this domain has disabled portfolio functionality for this specific user.').'</li>'.
  154:                       '<li>'.&mt('The domain has been configured to disable, by default, portfolio functionality for all users in the domain.').'</li>'.
  155:                       '</ul>');
  156:         } else {
  157:             my ($blocked,$blocktext) = 
  158:                 &Apache::loncommon::blocking_status('port',$cnum,$cdom);
  159:             if (!$blocked) {
  160:                 &display_portfolio_files($r,$is_course);
  161:             } else {
  162:                 $r->print($blocktext);
  163:             }
  164:         }
  165:         $r->print(&Apache::loncommon::end_page());
  166:         return OK;
  167:     }
  168: 
  169:     if ($is_course) {
  170:         if ($target ne 'tex') {
  171: 	    my $brcrum = [{href=>"/adm/navmaps",text=>"Navigate Course Contents"},
  172: 			  {href=>"/adm/aboutme",text=>"Course Information"}];
  173:             my $start_page =
  174:                 &Apache::loncommon::start_page(
  175:                     "Course Information",
  176:                      undef,
  177:                      {'function' => $env{'forcestudent'},
  178:                       'domain'   => $cdom,
  179:                       'force_register' => $env{'forceregister'},
  180:                       'bread_crumbs' => $brcrum});
  181:             $r->print($start_page);
  182:             $r->print('<h2>'.&mt('Group files').'</h2>');
  183:             &print_portfiles_link($r,$is_course);
  184:             $r->print(&Apache::loncommon::end_page());
  185:         }
  186:         return OK;
  187:     }
  188: 
  189: # --------------------------------------------------------------- Force Student
  190:     my $forcestudent='';
  191:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
  192: 
  193:     my $forceregister = '';
  194:     if ($forcestudent eq '') {
  195:         $forceregister = $env{'form.register'};
  196:     }
  197:        
  198: # --------------------------------------- There is such a user, get environment
  199:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
  200:     if ($target ne 'tex') {
  201: 	my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
  202:         my $args = {'function' => $forcestudent,
  203:                     'domain'   => $cdom,
  204:                     'force_register' => $forceregister};
  205:         if ($env{'form.popup'}) {
  206:             $args->{'no_nav_bar'} = 1;
  207:         }
  208: 	$args->{'bread_crumbs'} = [{href=>"/adm/fhwfdev/$cnum/aboutme",text=>"Personal Information"}];
  209: 	my $start_page = 
  210: 	    &Apache::loncommon::start_page("Personal Information",$rss_link,$args);
  211: 	$r->print($start_page);
  212: 	$r->print('<h2>'.&Apache::loncommon::plainname($cnum,$cdom).'</h2>');
  213:     } else {
  214: 	$r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
  215:     }
  216:     if ($courseenv{'nickname'}) {
  217:        $r->print(
  218:          '<h2>&quot;'.$courseenv{'nickname'}.
  219:          '&quot;</h2>');
  220:     }
  221:     if ($target ne 'tex') {
  222: 	$r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>');#OLD SendMessage POS
  223:     } else {
  224: 	$r->print('\textbf{'.&Apache::lonnet::domain($cdom,'description').'}\\\\');
  225:     }
  226:     my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
  227:     my $allowed=0;
  228: 
  229: # does this user have privileges to post, etc?
  230: 
  231:        my $privleged=$allowed=(($env{'user.name'} eq $cnum) && 
  232: 			       ($env{'user.domain'} eq $cdom));
  233:        if ($forcestudent or $target eq 'tex') { $allowed=0; }
  234: 	my $query_string; 
  235:        if ($allowed) {
  236:            $query_string = &build_query_string({'forcestudent' => '1','popup' => $env{'form.popup'}});
  237: 	   $r->print('<p><b>'.&mt('Privacy Note').':</b> '.
  238: 		     &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.').
  239: 		     '</p><p><a href="'.$r->uri.$query_string.'">'.&mt('Show Public View').'</a>'.
  240:                      &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>'.
  241: 		     &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).'</p>');
  242:        } elsif ($privleged && $target ne 'tex') {
  243:            $query_string = &build_query_string({'forceedit' => '1','popup' => $env{'form.popup'}});
  244: 	   $r->print('<p><a href="'.$r->uri.$query_string.'">'.
  245: 		     &mt('Edit').'</a></p>');
  246:        }
  247:       if (($env{'form.uploaddoc.filename'}) &&
  248:           ($env{'form.storeupl'}) && ($allowed)) {
  249:  	  if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
  250: 	      if ($syllabus{'uploaded.photourl'}) {
  251: 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  252: 	      }
  253: 	      $syllabus{'uploaded.photourl'}=
  254:                  &Apache::lonnet::userphotoupload('uploaddoc','aboutme');
  255:  	  }
  256:           $syllabus{'uploaded.lastmodified'}=time;
  257:           &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
  258:        }
  259:     if ($allowed && $env{'form.delupl'}) {
  260: 	if ($syllabus{'uploaded.photourl'}) {
  261: 	    &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  262: 	    delete($syllabus{'uploaded.photourl'});
  263: 	    &Apache::lonnet::del('aboutme',['uploaded.photourl'],$cdom,$cnum);
  264: 	}
  265:     }
  266:        if (($allowed) && ($env{'form.storesyl'})) {
  267: 	   foreach my $syl_field (keys(%syllabusfields)) {
  268:                my $field=$env{'form.'.$syl_field};
  269:                $field=~s/\s+$//s;
  270:                $field=&Apache::lonfeedback::clear_out_html($field,
  271:                                                            $env{'user.adv'});
  272: 	       $syllabus{$syl_field}=$field;
  273:            }
  274:            $syllabus{'uploaded.lastmodified'}=time;
  275:            &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
  276:        }
  277: 
  278: my $lastmod;
  279: my $image; 
  280: # ---------------------------------------------------------------- Get syllabus
  281:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
  282:        $lastmod=$syllabus{'uploaded.lastmodified'};
  283:        $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
  284:  	$r->print('<br />'.&mt('Last updated').': '.$lastmod);
  285:        if ($syllabus{'uploaded.photourl'}) {
  286: 	   &Apache::lonnet::allowuploaded('/adm/aboutme',
  287: 					  $syllabus{'uploaded.photourl'});
  288: 	
  289:            #This call is to resize all "about me" images in the LonCapa System. When its done, you can remove this line.
  290: 	   &Apache::lonnet::resizeImage(&Apache::lonnet::filelocation('',$syllabus{'uploaded.photourl'}));
  291: 	   #---End Resize---
  292: 
  293: 	   $image=qq{<img name="userPhoto" src="$syllabus{'uploaded.photourl'} " style="float:left;margin-right:10px;" />};
  294: 	   
  295: 	   if ($target eq 'tex') {
  296: 	       $image=&Apache::lonxml::xmlparse($r,'tex',$image);
  297: 	   }
  298: 	
  299:        }
  300:        if ($allowed) {
  301:            $r->print(
  302: 	 '<form method="post" enctype="multipart/form-data">'.
  303:          '<h3>'.&mt('Upload a Photo').'</h3>'.
  304:          '<input type="file" name="uploaddoc" size="50" />'.
  305:          '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />'.
  306:          '<input type="hidden" name="popup" value="'.$env{'form.popup'}.'" />'.
  307: 	 '</form><form method="post"><input type="submit" name="delupl" value="'.&mt('Delete Photo').'" /> </form><p>
  308: ');
  309: 
  310:        }
  311: 
  312: 	if($allowed) {
  313: 		$r->print('<form method="post">');
  314: 	}
  315: 
  316: 	 if($target ne 'tex') #print Image
  317:      	 {	
  318: 		&Apache::lontemplate::start_ContentBox($r);		
  319: 		&Apache::lontemplate::send_message($r,$cnum,$cdom);
  320: 		&Apache::lontemplate::end_ContentBox($r);
  321: 		$r->print($image);		
  322: 		
  323: 	}#End Print Image
  324: 
  325: 	#Print Content eg. Contactinfo aboutme,...	
  326: 	&Apache::lontemplate::print_aboutme_content_template($r,$allowed,$target,\%syllabusfields,\%syllabus);	
  327:         #End Print Content
  328: 
  329:        if($target ne 'tex')#Begin Print RSS and portfiles
  330:        {	
  331: 				
  332: 		&print_portfiles_link($r,$is_course);
  333: 		if(&Apache::lonrss::advertisefeeds($cnum,$cdom) ne ''){
  334: 			$r->print('<div class="LC_ContentBoxSpecial">');
  335: 			$r->print('<h4 class="LC_hcell">'.'RSS Feeds and Blogs'.'</h4>');
  336: 			$r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom));
  337: 			$r->print('</div>');
  338: 		}		
  339: 		
  340: 		if($allowed){
  341: 			$r->print('<p><a href="'.$r->uri.$query_string.'">'.&mt('Show Public View').'</a>'.
  342:                         	&Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
  343: 		}
  344:        }#End  Print RSS and portfiles
  345:        if ($allowed) {
  346:            if ($env{'form.popup'}) {
  347:                $r->print('<input type="hidden" name="popup" value="'.
  348:                          $env{'form.popup'}.'" />');
  349:            }
  350: 	   $r->print('</form>');
  351:        }
  352:        if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
  353:     } else {
  354: 	 &Apache::lontemplate::send_message($r,$cnum,$cdom);
  355:        $r->print('<p>'.&mt('No personal information provided').'.</p>');
  356:     }
  357:     
  358: 
  359:     if ($env{'request.course.id'}
  360: 	&& &Apache::lonnet::allowed('srm',$env{'request.course.id'})
  361: 	&& &in_course($cdom,$cnum)) {
  362: 	if ($target ne 'tex') {
  363: 	    $r->print('<a name="coursecomment" />');
  364: 	    $r->print('<hr /><h3>'.
  365: 		      &mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'</h3>'.
  366: 		      &mt('Shared by course faculty and staff').
  367: 		      &Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message").
  368: 		      '<br />');
  369: 	    &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
  370: 	    $r->print('<hr />');
  371: 	    if (&Apache::lonnet::allowed('vsa',
  372: 					 $env{'request.course.id'}) ||
  373: 		&Apache::lonnet::allowed('vsa',
  374: 					 $env{'request.course.id'}.'/'.
  375: 					 $env{'request.course.sec'})) {
  376: 		$r->print(&Apache::loncommon::track_student_link
  377: 			  ('View recent activity by this student',
  378: 			   $cnum,$cdom).('&nbsp;'x2));
  379: 	    }
  380: 	    $r->print(&Apache::loncommon::noteswrapper(&mt('Add Records'),$cnum,$cdom));
  381: 	} else {
  382: 	    $r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
  383: 	    &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
  384: 	}
  385:     }
  386:     if ($target ne 'tex') {
  387:         if ($env{'form.popup'}) {
  388:             $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a>');
  389:         }
  390: 	$r->print(&Apache::loncommon::end_page());
  391:     } else {
  392: 	$r->print('\end{document}');
  393:     }
  394: 
  395:   
  396: 	
  397:     return OK;
  398: }
  399: 
  400: sub in_course {
  401:     my ($udom,$uname,$cdom,$cnum,$type) = @_;
  402:     $type ||= 'any';
  403:     if (!defined($cdom) || !defined($cnum)) {
  404: 	my $cid  = $env{'request.course.id'};
  405: 	$cdom = $env{'course.'.$cid.'.domain'};
  406: 	$cnum = $env{'course.'.$cid.'.num'};
  407:     }
  408:     my %roles = &Apache::lonnet::dump('roles',$udom,$uname);
  409:     my @course_roles = grep(m{^/\Q$cdom\E/\Q$cnum\E[/_]}, keys(%roles));
  410:     return 0 if (!@course_roles);
  411:     return 1 if ($type eq 'any');
  412:     my $now = time();
  413:     foreach my $role (@course_roles) {
  414: 	my (undef,$role_end,$role_start)=split(/\_/,$roles{$role});
  415: 	my $status = 'active';
  416: 	if ($role_start > 0 && $now < $role_start) {
  417: 	    $status = 'future';
  418: 	}
  419: 	if ($role_end > 0 && $now > $role_end) {
  420: 	    $status = 'previous';
  421: 	}
  422: 	return 1 if ($status eq $type);
  423:     }
  424:     return 0;
  425: }
  426: 
  427: sub aboutme_info {
  428:     my ($r,$is_course) = @_;
  429:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
  430:     my $name;
  431:     if (!$is_course) {
  432:         $name = &Apache::loncommon::plainname($cnum,$cdom);
  433:     }
  434:     return ($cdom,$cnum,$name);
  435: }
  436: 
  437: sub print_portfiles_link {
  438:     my ($r,$is_course) = @_;
  439:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  440:     my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
  441:                                       $cdom,$cnum,$name);
  442:     my $query_string = &build_query_string();
  443:     my $output;
  444:     my %lt = &Apache::lonlocal::texthash(
  445:                          vpfi => 'Viewable portfolio files',
  446:                          vgpf => 'Viewable group portfolio files',
  447:                          difl => 'Display file listing',
  448:              );                     
  449:     if ($filecounts->{'both'} > 0) {
  450: 	$output = '<div class="LC_ContentBoxSpecial"><h4 class="LC_hcell">';
  451: 	$output .= ($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
  452:         
  453: 	#$output = '<h4>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
  454:         $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
  455:                    $query_string.'">'.$lt{'difl'}.
  456:                    '</a><br /><br />';
  457:         if ($filecounts->{'both'} == 1) {
  458:             if ($is_course) {
  459:                 $output .= &mt('One group portfolio file is available.').'<ul>';
  460:             } else {
  461:                 $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
  462:             }
  463:         } else {
  464:             if ($is_course) {
  465:                 $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
  466:             } else {
  467:                 $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
  468:             }
  469:         }
  470:         if ($filecounts->{'withoutpass'}) {
  471: 	    $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
  472:         }
  473:         if ($filecounts->{'withpass'}) {
  474: 	    $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
  475:         }
  476:         $output .= '</ul>';
  477: 	$output .='</p>';
  478: 	$output .='</div>';
  479:     }
  480:     $r->print($output);
  481:     return;
  482: }
  483: 
  484: sub build_query_string {
  485:     my ($new_items) = @_;
  486:     my $query_string;
  487:     my @formelements = ('register'); 
  488:     my $new = 0;
  489:     if (ref($new_items) eq 'HASH') {
  490:         $new = 1;
  491:         if (!defined($new_items->{'forceedit'}) && 
  492:             !defined($new_items->{'forcestudent'})) {
  493:             push(@formelements,('forceedit','forcestudent'));
  494:         }
  495:     } else {
  496:         push(@formelements,('forceedit','forcestudent'));
  497:     }
  498:     foreach my $element (@formelements) {
  499:         if (exists($env{'form.'.$element})) {
  500:             if ((!$new) || (!defined($new_items->{$element}))) {
  501:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
  502:             }
  503:         }
  504:     }
  505:     if ($new) {
  506:         foreach my $key (keys(%{$new_items})) {
  507:             $query_string .= '&amp;'.$key.'='.$new_items->{$key};
  508:         }
  509:     }
  510:     $query_string =~ s/^\&amp;/\?/;
  511:     return $query_string;
  512: }
  513: 
  514: sub display_portfolio_header {
  515:     my ($r,$is_course) = @_;
  516:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  517:     my $query_string = &build_query_string();
  518:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  519:     my $forcestudent='';
  520:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
  521: 
  522:     my $output;
  523:     if ($is_course) {
  524:         $output = 
  525:             &Apache::loncommon::start_page('Viewable group portfolio files',undef,
  526:                                             {'function' => $forcestudent,
  527:                                              'domain'   => $cdom,});
  528:         $output .= '<h3>'.&mt('Group Portfolio files').'</h3>';
  529:     } else {
  530:         $output  =
  531:             &Apache::loncommon::start_page('Viewable portfolio files',undef,
  532:                                             {'function' => $forcestudent,
  533:                                              'domain'   => $cdom,});
  534:         if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
  535:             &Apache::lonhtmlcommon::add_breadcrumb
  536:                 ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
  537:                   text=>"Personal information - $name",
  538:                   title=>"Go to personal information page for $name"},                 {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
  539:                   text=>"Viewable files - $name",
  540:                   title=>"Viewable portfolio files for $name"}
  541:             );
  542:             $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
  543:         }
  544:         $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
  545:     }
  546:     $r->print($output);
  547:     return;
  548: }
  549: 
  550: sub display_portfolio_files {
  551:     my ($r,$is_course) = @_;
  552:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  553:     my %lt = ( withoutpass => 'passphrase not required',
  554: 	       withpass    => 'passphrase protected',
  555: 	       both        => 'all access types ',);
  556:     %lt = &Apache::lonlocal::texthash(%lt);
  557: 
  558:     my $portaccess = 'withoutpass';
  559:     if (exists($env{'form.portaccess'})) {
  560:         $portaccess = $env{'form.portaccess'};
  561:     }
  562: 
  563:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
  564: 	.'" name="displaystatus" method="post">'.
  565: 	&mt('File access type: ').'<select name="portaccess">';
  566:     foreach my $type ('withoutpass','withpass','both') {
  567:         $output .= '<option value="'.$type.'" ';
  568:         if ($portaccess eq $type) {
  569:             $output .= 'selected="selected"';
  570:         }
  571:         $output .= '>'.$lt{$type}.'</option>';
  572:     }
  573:     $output .= '</select>'."\n".
  574:                '<input type="submit" name="portaccessbutton" value="'.
  575:                &mt('Update display').'" />';
  576:     $output .= '</form><br /><br />';
  577:     $r->print($output);
  578:     my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
  579:                                       $cdom,$cnum,$name);
  580:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
  581:         my $query_string = &build_query_string();
  582:         $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
  583:                   '/aboutme'.$query_string.'">');
  584:         if ($is_course) {
  585:             $r->print(&mt('Course Information page'));
  586:         } else {
  587:             $r->print(&mt('Information about [_1]',$name));
  588:         }
  589:         $r->print('</a>');
  590:     }
  591:     return;
  592: }
  593: 
  594: sub portfolio_files {
  595:     my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
  596:     my $filecounts = {
  597:                        withpass    => 0,
  598:                        withoutpass => 0,
  599:                        both        => 0,
  600:                      };
  601:     my $current_permissions =
  602: 	&Apache::lonnet::get_portfile_permissions($cdom,$cnum);
  603:     my %access_controls = 
  604: 	&Apache::lonnet::get_access_controls($current_permissions);
  605:     my $portaccess;
  606:     if ($mode eq 'showlink') {
  607:         $portaccess = 'both';
  608:     } else {
  609:         $portaccess = 'withoutpass';
  610:         if (exists($env{'form.portaccess'})) {
  611:             $portaccess = $env{'form.portaccess'};
  612:         }
  613:     }
  614: 
  615:     my $diroutput;
  616:     if ($is_course) {
  617:         my %files_by_group;
  618:         foreach my $filename (sort(keys(%access_controls))) {
  619:             my ($group,$path) = split('/',$filename,2);
  620:             $files_by_group{$group}{$path} = $access_controls{$filename}; 
  621:         }
  622:         foreach my $group (sort(keys(%files_by_group))) {
  623:             my %fileshash;
  624:             my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
  625:                                            $is_course,$filecounts,$mode,
  626:                                            $files_by_group{$group},
  627:                                            \%fileshash,$group);
  628:             if ($grpout) {
  629:                 $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
  630:             }
  631:         }
  632:     } else {
  633:         my %allfileshash;
  634:         $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
  635:                                       $filecounts,$mode,\%access_controls,
  636:                                       \%allfileshash);
  637:     }
  638:     if ($mode eq 'listfiles') {
  639:         if ($filecounts->{'both'}) {
  640:              $r->print($diroutput);
  641:         } else {
  642:             my $access_text;
  643:             if (ref($lt) eq 'HASH') {
  644:                 $access_text = $lt->{$portaccess};   
  645:             }
  646:             $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
  647:         }
  648:     }
  649:     return $filecounts;
  650: }
  651: 
  652: { 
  653:     my $count=0;
  654:     sub portfolio_table_start {
  655: 	$count=0;
  656: 	return '<table class="LC_aboutme_port">';
  657:     }
  658:     sub portfolio_row_start {
  659: 	$count++;
  660: 	my $class = ($count%2)?'LC_odd_row'
  661: 	                      :'LC_even_row';
  662: 	return '<tr class="'.$class.'">';
  663:     }
  664: }
  665: 
  666: sub build_hierarchy {
  667:     my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
  668:         $allfileshash,$group) = @_;
  669:     foreach my $filename (sort(keys(%{$access_info}))) {
  670:         my $access_status =
  671:            &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group,                                                 $$access_info{$filename});
  672:         if ($portaccess eq 'both') {
  673:             if (($access_status ne 'ok') &&
  674:                 ($access_status !~  /^[^:]+:guest_/)) {
  675:                 next;
  676:             }
  677:         } elsif ($portaccess eq 'withoutpass') {
  678:             if ($access_status ne 'ok') {
  679:                 next;
  680:             }
  681:         } elsif ($portaccess eq 'withpass') {
  682:             if ($access_status !~  /^[^:]+:guest_/) {
  683:                 next;
  684:             }
  685:         }
  686:         if ($mode eq 'listfiles') {
  687:             $filename =~ s/^\///;
  688:             my @pathitems = split('/',$filename);
  689:             my $lasthash = $allfileshash;
  690:             while (@pathitems > 1) {
  691:                 my $newlevel = shift(@pathitems);
  692:                 if (!exists($lasthash->{$newlevel})) {
  693:                     $lasthash->{$newlevel} = {};
  694:                 }
  695:                 $lasthash = $lasthash->{$newlevel};
  696:             }
  697:             $lasthash->{$pathitems[0]} = $filename;
  698:         }
  699:         if ($access_status eq 'ok') {
  700:             $filecounts->{'withoutpass'} ++;
  701:         } elsif ($access_status =~  /^[^:]+:guest_/) {
  702:             $filecounts->{'withpass'} ++;
  703:         }
  704:     }
  705:     $filecounts->{'both'} =  $filecounts->{'withoutpass'} +
  706:                               $filecounts->{'withpass'};
  707:     my $output;
  708:     if ($mode eq 'listfiles') {
  709:         if ($filecounts->{'both'} > 0) {
  710:             $output = &portfolio_table_start();
  711:             $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
  712:                                         $group);
  713:             $output .= '</table>';
  714:         }
  715:     }
  716:     return $output;
  717: }
  718: 
  719: sub parse_directory {
  720:     my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
  721:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  722:     $depth++;
  723:     my $output;
  724: 
  725:     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
  726:                                                                 $group);
  727:     my $getpropath = 1;
  728:     my %dirlist = map {
  729: 	    ((split('&',$_,2))[0],1)
  730: 	} &Apache::lonnet::dirlist($portfolio_root.$path,$cdom,$cnum,$getpropath);
  731:     foreach my $item (sort(keys(%{$currhash}))) {
  732:         $output .= &portfolio_row_start();
  733:         $output .= '<td style="padding-left: '.($depth*25).'px">';
  734:         if (ref($currhash->{$item}) eq 'HASH') {
  735:             my $title=&HTML::Entities::encode($item,'<>&"');
  736:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" />&nbsp;'.$title;
  737: 	    $output .= '</td><td></td></tr>';
  738:             $output .= &parse_directory($r,$depth,$currhash->{$item},
  739: 					$path.'/'.$item,$is_course,$group);
  740:         } else {
  741: 	    my $file_name; 
  742: 	    if ($currhash->{$item} =~ m|/([^/]+)$|) {
  743: 		$file_name = $1;
  744: 	    } else {
  745: 		$file_name = $currhash->{$item};
  746: 	    }
  747: 	    my $have_meta = exists($dirlist{$file_name.'.meta'});
  748:             my $url;
  749:             if ($is_course) {
  750:                 $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
  751:                        '/portfolio/'.$currhash->{$item};
  752:             } else { 
  753: 	        $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
  754: 		       $currhash->{$item};
  755:             }
  756:             my $showname;
  757: 	    if ($have_meta) {
  758: 		$showname = &Apache::lonnet::metadata($url,'title');
  759: 	    }
  760: 	    if ($showname eq '') {
  761: 		$showname = $file_name;
  762: 	    } else {
  763: 		$showname = $file_name.' ('.$showname.')';
  764: 	    }
  765: 
  766:             $showname=&HTML::Entities::encode($showname,'<>&"');
  767:             $output .= '<a href="'.$url.'">'.
  768: 		'<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
  769: 		'&nbsp;'.$showname.'</a>';
  770: 	    $output.='</td><td>';
  771: 	    if ($have_meta) {
  772: 		$output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Metadata').'" src="'.
  773: 		&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
  774: 		'" class="LC_icon" /></a>';
  775: 	    }
  776: 	    $output .= '</td></tr>';
  777:         }
  778:     }
  779:     return $output;
  780: }
  781: 
  782: sub aboutme_access {
  783:     my ($uname,$udom) = @_;
  784:     my $privcheck = $env{'request.course.id'};
  785:     my $sec;
  786:     if ($env{'request.course.sec'} ne '') {
  787:         $sec = $env{'request.course.sec'};
  788:         $privcheck .= '/'.$sec;
  789:     }
  790:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  791:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  792:     if (($cdom eq '') || ($cnum eq '')) {
  793:         my %coursehash = &coursedescription($env{'request.course.id'});
  794:         $cdom = $coursehash{'domain'};
  795:         $cnum = $coursehash{'cnum'};
  796:     }
  797:     if ((&Apache::lonnet::allowed('srm',$privcheck)) || 
  798:         (&Apache::lonnet::allowed('dff',$privcheck))) {
  799:         if (&in_course($uname,$udom,$cnum,$cdom)) {
  800:             return 1;
  801:         }
  802:     }
  803:     return;
  804: }
  805: 
  806: 1;
  807: __END__

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