File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.117: download - view: text, annotated - select for diffs
Fri Mar 27 04:59:30 2009 UTC (15 years, 2 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- "Slot reservation history " link in "Functions" area of Personal Information page when
   viewer is in course context and has "vgr" privilege in course.
- &slot_reservations_link() provides a link to /adm/slotrequest to display slot reservation history for a specified user.

    1: # The LearningOnline Network
    2: # Personal Information Page
    3: #
    4: # $Id: lonaboutme.pm,v 1.117 2009/03/27 04:59:30 raeburn 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 personal information page available').'}}\\\\\\\\');
  122:                 } else {
  123:                     $r->print(&Apache::loncommon::start_page("Personal Information Page"));
  124:                     $r->print('<h2>'.&mt('No user personal information 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 personal information page functionality for this specific user.').'</li>'.
  127:                               '<li>'.&mt('The domain has been configured to disable, by default, personal information 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'       => 'Personal Information',
  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 Portfolio').'</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: #------------Get rights
  199:  my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
  200:  my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
  201:     my $allowed=0;
  202:   my $privleged=$allowed=(($env{'user.name'} eq $cnum) && 
  203: 			       ($env{'user.domain'} eq $cdom));
  204:        if ($forcestudent or $target eq 'tex') { $allowed=0; } 
  205:  
  206: 
  207: # --------------------------------------- There is such a user, get environment
  208:   
  209:     if ($target ne 'tex') {
  210: 	my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
  211:         my $args = {'function' => $forcestudent,
  212:                     'domain'   => $cdom,
  213:                     'force_register' => $forceregister};
  214:         if ($env{'form.popup'}) {
  215:             $args->{'no_nav_bar'} = 1;
  216:         }
  217: 	$args->{'bread_crumbs'} = [{href=>"/adm/fhwfdev/$cnum/aboutme",text=>"Personal Information Page"}];
  218: 	my $start_page = 
  219: 	    &Apache::loncommon::start_page("Personal Data",$rss_link,$args);
  220: 	$r->print($start_page);
  221:         
  222:     }   
  223: 
  224: #Print Privacy Note
  225:        if ($allowed) {          
  226:            $r->print('<p class="LC_info">'
  227:                     .'<b>'.&mt('Privacy Note:').'</b> '
  228:                     .&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.')
  229:                     .'</p>'
  230:            );
  231: 	} 
  232: 
  233: #Print Help Text
  234: if  ($target ne 'tex') {
  235: 	if($allowed){
  236: 		$r->print(&Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')));
  237: 	}
  238: }
  239: 
  240: #----------------Print Functions
  241: 	if( $target ne 'tex'){
  242: 		 &Apache::lontemplate::print_start_page_functions($r);
  243:       		if($allowed){
  244: 			 my $query_string = &build_query_string({'forcestudent' => '1','popup' => $env{'form.popup'}});		
  245: 			&Apache::lontemplate::print_functions_content($r,'<a href="'.$r->uri.$query_string.'">'.&mt('Show Public View').'</a>'.&Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView'));
  246:     		}elsif($privleged){
  247: 			my $query_string = &build_query_string({'forceedit' => '1','popup' => $env{'form.popup'}});
  248: 			 &Apache::lontemplate::print_functions_content($r,'<a href="'.$r->uri.$query_string.'">'. &mt('Edit').'</a>');
  249: 		}
  250: 		&Apache::lontemplate::print_functions_content($r,&Apache::lontemplate::send_message($r,$cnum,$cdom));
  251: 
  252: 		if ($env{'request.course.id'} && &Apache::lonnet::allowed('srm',$env{'request.course.id'})	&& &in_course($cdom,$cnum)) {
  253: 			if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) || &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
  254: 					 $env{'request.course.sec'})) {
  255: 				&Apache::lontemplate::print_functions_content($r,&Apache::loncommon::track_student_link('View recent activity by this student',
  256: 			  	 	$cnum,$cdom).('&nbsp;'x2));
  257: 	    		}
  258:                         if (&Apache::lonnet::allowed('vgr', $env{'request.course.id'}) || 
  259:                             &Apache::lonnet::allowed('vgr', $env{'request.course.id'}.'/'.
  260:                                                      $env{'request.course.sec'})) {
  261:                             &Apache::lontemplate::print_functions_content($r,&Apache::loncommon::slot_reservations_link('Slot reservation history',
  262:                                         $cnum,$cdom).('&nbsp;'x2));
  263:                         }
  264: 	    		&Apache::lontemplate::print_functions_content($r,&Apache::loncommon::noteswrapper(&mt('Add Records'),$cnum,$cdom));
  265: 		}
  266: 	&Apache::lontemplate::print_end_page_functions($r);
  267: 	}  
  268: #------Print Headtitle
  269:  if ($target ne 'tex') {
  270: 	 $r->print('<div class="LC_ContentBoxSpecial">');
  271: 	$r->print('<h2 class="LC_hcell">'.&Apache::loncommon::plainname($cnum,$cdom).'</h2>');
  272: 	$r->print('<blockquote>');
  273: 	 if ($courseenv{'nickname'}) {
  274:       	 	$r->print('<h2>&quot;'.$courseenv{'nickname'}.'&quot;</h2>');
  275:     	}
  276: 	$r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>');
  277:  }
  278: else{
  279: 	$r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
  280: 	$r->print('\textbf{'.&Apache::lonnet::domain($cdom,'description').'}\\\\');	
  281: }
  282: # does this user have privileges to post, etc?
  283: 
  284:      
  285: 	my $query_string; 
  286: 	
  287:       if (($env{'form.uploaddoc.filename'}) &&
  288:           ($env{'form.storeupl'}) && ($allowed)) {
  289:  	  if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
  290: 	      if ($syllabus{'uploaded.photourl'}) {
  291: 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  292: 	      }
  293: 	      $syllabus{'uploaded.photourl'}=
  294:                  &Apache::lonnet::userphotoupload('uploaddoc','aboutme');
  295:  	  }
  296:           $syllabus{'uploaded.lastmodified'}=time;
  297:           &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
  298:        }
  299:     if ($allowed && $env{'form.delupl'}) {
  300: 	if ($syllabus{'uploaded.photourl'}) {
  301: 	    &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  302: 	    delete($syllabus{'uploaded.photourl'});
  303: 	    &Apache::lonnet::del('aboutme',['uploaded.photourl'],$cdom,$cnum);
  304: 	}
  305:     }
  306:        if (($allowed) && ($env{'form.storesyl'})) {
  307: 	   foreach my $syl_field (keys(%syllabusfields)) {
  308:                my $field=$env{'form.'.$syl_field};
  309:                $field=~s/\s+$//s;
  310:                $field=&Apache::lonfeedback::clear_out_html($field,
  311:                                                            $env{'user.adv'});
  312: 	       $syllabus{$syl_field}=$field;
  313:            }
  314:            $syllabus{'uploaded.lastmodified'}=time;
  315:            &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
  316:        }
  317: 
  318: my $lastmod;
  319: my $image; 
  320: # ---------------------------------------------------------------- Get syllabus
  321:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
  322:        $lastmod=$syllabus{'uploaded.lastmodified'};
  323:        $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
  324:  	$r->print('<br />'.&mt('Last updated').': '.$lastmod);
  325: 
  326: 
  327:        if ($syllabus{'uploaded.photourl'}) {
  328: 	   &Apache::lonnet::allowuploaded('/adm/aboutme',
  329: 					  $syllabus{'uploaded.photourl'});
  330: 	
  331:            #This call is to resize all "Personal Information" images in the LonCapa System. When its done, you can remove this line.
  332: 	   &Apache::lonnet::resizeImage(&Apache::lonnet::filelocation('',$syllabus{'uploaded.photourl'}));
  333: 	   #---End Resize---
  334: 
  335: 	   $image=qq{<img name="userPhoto" src="$syllabus{'uploaded.photourl'} " class="LC_AboutMe_Image" />};
  336: 	   
  337: 	   if ($target eq 'tex') {
  338: 	       $image=&Apache::lonxml::xmlparse($r,'tex',$image);
  339: 	   }
  340: 	
  341:        }
  342: 	
  343:        if ($allowed) {
  344:            $r->print(
  345: 	 '<form method="post" enctype="multipart/form-data">'.
  346:          '<h3>'.&mt('Upload a Photo').'</h3>'.
  347:          '<input type="file" name="uploaddoc" size="50" />'.
  348:          '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />'.
  349:          '<input type="hidden" name="popup" value="'.$env{'form.popup'}.'" />'.
  350: 	 '</form><form method="post"><input type="submit" name="delupl" value="'.&mt('Delete Photo').'" /> </form><p>
  351: ');
  352: 
  353:        }
  354: 
  355: 	if($allowed) {
  356: 		$r->print('<form method="post">');
  357: 	}
  358: 
  359: 	 if($target ne 'tex') #print Image
  360:      	 {	
  361: 		&Apache::lontemplate::start_ContentBox($r);			
  362: 		&Apache::lontemplate::end_ContentBox($r);
  363: 		$r->print($image);		
  364: 		
  365: 	}#End Print Image
  366: 
  367: 	#Print Content eg. Contactinfo aboutme,...	
  368: 	&Apache::lontemplate::print_aboutme_content_template($r,$allowed,$target,\%syllabusfields,\%syllabus);	
  369:         #End Print Content
  370: 
  371:        if($target ne 'tex')#Begin Print RSS and portfiles
  372:        {			
  373: 		&print_portfiles_link($r,$is_course);
  374: 		if(&Apache::lonrss::advertisefeeds($cnum,$cdom) ne ''){
  375: 			&Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_ContentBoxSpecial');
  376: 			$r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom));		
  377: 			&Apache::lontemplate::print_end_template($r);		
  378: 		}		
  379: 		
  380:        } #End  Print RSS and portfiles
  381: 
  382:        
  383:        if ($allowed) {
  384:            if ($env{'form.popup'}) {
  385:                $r->print('<input type="hidden" name="popup" value="'.
  386:                          $env{'form.popup'}.'" />');
  387:            }
  388: 	   $r->print('</form>');
  389:        }
  390:        if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
  391:     } else {
  392: 	# &Apache::lontemplate::send_message($r,$cnum,$cdom);
  393:        $r->print('<p>'.&mt('No personal information provided').'.</p>');
  394:     }
  395:     if($target ne 'tex'){
  396: 		#$r->print('</blockquote>');
  397:     		#$r->print('</div>');	
  398: 	}
  399: 
  400:     if ($env{'request.course.id'}
  401: 	&& &Apache::lonnet::allowed('srm',$env{'request.course.id'})
  402: 	&& &in_course($cdom,$cnum)) {
  403: 	if ($target ne 'tex') {	   
  404: 	   &Apache::lontemplate::print_start_template($r,&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course'),'LC_ContentBoxSpecial');
  405: 	   $r->print('<span class="LC_info">');
  406: 	   $r->print(&mt('Shared by course faculty and staff').&Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message"));
  407: 		$r->print('</span> <p>');	   
  408: &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
  409: 	   $r->print('</p>');
  410: 	   &Apache::lontemplate::print_end_template($r);
  411: 	    
  412: 	} else {
  413: 	    $r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
  414: 	    &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
  415: 	}
  416:     }
  417:     $r->print('</blockquote>');
  418:     $r->print('</div>');
  419:     if ($target ne 'tex') {
  420:         if ($env{'form.popup'}) {
  421:             $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a>');
  422:         }
  423: 	$r->print(&Apache::loncommon::end_page());
  424:     } else {
  425: 	$r->print('\end{document}');
  426:     }
  427: 
  428:   
  429: 	
  430:     return OK;
  431: }
  432: 
  433: sub in_course {
  434:     my ($udom,$uname,$cdom,$cnum,$type) = @_;
  435:     $type ||= 'any';
  436:     if (!defined($cdom) || !defined($cnum)) {
  437: 	my $cid  = $env{'request.course.id'};
  438: 	$cdom = $env{'course.'.$cid.'.domain'};
  439: 	$cnum = $env{'course.'.$cid.'.num'};
  440:     }
  441:     my %roles = &Apache::lonnet::dump('roles',$udom,$uname);
  442:     my @course_roles = grep(m{^/\Q$cdom\E/\Q$cnum\E[/_]}, keys(%roles));
  443:     return 0 if (!@course_roles);
  444:     return 1 if ($type eq 'any');
  445:     my $now = time();
  446:     foreach my $role (@course_roles) {
  447: 	my (undef,$role_end,$role_start)=split(/\_/,$roles{$role});
  448: 	my $status = 'active';
  449: 	if ($role_start > 0 && $now < $role_start) {
  450: 	    $status = 'future';
  451: 	}
  452: 	if ($role_end > 0 && $now > $role_end) {
  453: 	    $status = 'previous';
  454: 	}
  455: 	return 1 if ($status eq $type);
  456:     }
  457:     return 0;
  458: }
  459: 
  460: sub aboutme_info {
  461:     my ($r,$is_course) = @_;
  462:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
  463:     my $name;
  464:     if (!$is_course) {
  465:         $name = &Apache::loncommon::plainname($cnum,$cdom);
  466:     }
  467:     return ($cdom,$cnum,$name);
  468: }
  469: 
  470: sub print_portfiles_link {
  471:     my ($r,$is_course) = @_;
  472:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  473:     my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
  474:                                       $cdom,$cnum,$name);
  475:     my $query_string = &build_query_string();
  476:     my $output;
  477:     my %lt = &Apache::lonlocal::texthash(
  478:         'vpfi' => 'Viewable portfolio files',
  479:         'vgpf' => 'Viewable group portfolio files',
  480:         'difl' => 'Display file listing',
  481:     );                     
  482:     if ($filecounts->{'both'} > 0) {
  483: 	$output = '<div class="LC_ContentBoxSpecial"><h4 class="LC_hcell">';
  484: 	$output .= ($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
  485:         
  486: 	#$output = '<h4>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
  487:         $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
  488:                    $query_string.'">'.$lt{'difl'}.
  489:                    '</a><br /><br />';
  490:         if ($filecounts->{'both'} == 1) {
  491:             if ($is_course) {
  492:                 $output .= &mt('One group portfolio file is available.').'<ul>';
  493:             } else {
  494:                 $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
  495:             }
  496:         } else {
  497:             if ($is_course) {
  498:                 $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
  499:             } else {
  500:                 $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
  501:             }
  502:         }
  503:         if ($filecounts->{'withoutpass'}) {
  504: 	    $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
  505:         }
  506:         if ($filecounts->{'withpass'}) {
  507: 	    $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
  508:         }
  509:         $output .= '</ul>';
  510: 	$output .='</p>';
  511: 	$output .='</div>';
  512:     }
  513:     $r->print($output);
  514:     return;
  515: }
  516: 
  517: sub build_query_string {
  518:     my ($new_items) = @_;
  519:     my $query_string;
  520:     my @formelements = ('register'); 
  521:     my $new = 0;
  522:     if (ref($new_items) eq 'HASH') {
  523:         $new = 1;
  524:         if (!defined($new_items->{'forceedit'}) && 
  525:             !defined($new_items->{'forcestudent'})) {
  526:             push(@formelements,('forceedit','forcestudent'));
  527:         }
  528:     } else {
  529:         push(@formelements,('forceedit','forcestudent'));
  530:     }
  531:     foreach my $element (@formelements) {
  532:         if (exists($env{'form.'.$element})) {
  533:             if ((!$new) || (!defined($new_items->{$element}))) {
  534:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
  535:             }
  536:         }
  537:     }
  538:     if ($new) {
  539:         foreach my $key (keys(%{$new_items})) {
  540:             $query_string .= '&amp;'.$key.'='.$new_items->{$key};
  541:         }
  542:     }
  543:     $query_string =~ s/^\&amp;/\?/;
  544:     return $query_string;
  545: }
  546: 
  547: sub display_portfolio_header {
  548:     my ($r,$is_course) = @_;
  549:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  550:     my $query_string = &build_query_string();
  551:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  552:     my $forcestudent='';
  553:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
  554: 
  555:     my $output;
  556:     if ($is_course) {
  557:         $output = 
  558:             &Apache::loncommon::start_page('Viewable group portfolio files',undef,
  559:                                             {'function' => $forcestudent,
  560:                                              'domain'   => $cdom,});
  561:         $output .= '<h3>'.&mt('Group Portfolio files').'</h3>';
  562:     } else {
  563:         $output  =
  564:             &Apache::loncommon::start_page('Viewable portfolio files',undef,
  565:                                             {'function' => $forcestudent,
  566:                                              'domain'   => $cdom,});
  567:         if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
  568:             &Apache::lonhtmlcommon::add_breadcrumb
  569:                 ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
  570:                   text=>&mt('Personal Information Page - [_1]',$name),
  571:                   title=>&mt('Go to personal information page for [_1]', $name)},
  572: 		 {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
  573:                   text=>&mt('Viewable files - [_1]', $name),
  574:                   title=>&mt('Viewable portfolio files for [_1]', $name)}
  575:             );
  576:             $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
  577:         }
  578:         $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
  579:     }
  580:     $r->print($output);
  581:     return;
  582: }
  583: 
  584: sub display_portfolio_files {
  585:     my ($r,$is_course) = @_;
  586:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  587:     my %lt = &Apache::lonlocal::texthash(
  588:         'withoutpass' => 'passphrase not required',
  589:         'withpass'    => 'passphrase protected',
  590:         'both'        => 'all access types ',
  591:     );
  592: 
  593:     my $portaccess = 'withoutpass';
  594:     if (exists($env{'form.portaccess'})) {
  595:         $portaccess = $env{'form.portaccess'};
  596:     }
  597: 
  598:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
  599: 	.'" name="displaystatus" method="post">'.
  600: 	&mt('File access type: ').'<select name="portaccess">';
  601:     foreach my $type ('withoutpass','withpass','both') {
  602:         $output .= '<option value="'.$type.'" ';
  603:         if ($portaccess eq $type) {
  604:             $output .= 'selected="selected"';
  605:         }
  606:         $output .= '>'.$lt{$type}.'</option>';
  607:     }
  608:     $output .= '</select>'."\n".
  609:                '<input type="submit" name="portaccessbutton" value="'.
  610:                &mt('Update display').'" />';
  611:     $output .= '</form><br /><br />';
  612:     $r->print($output);
  613:     my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
  614:                                       $cdom,$cnum,$name);
  615:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
  616:         my $query_string = &build_query_string();
  617:         $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
  618:                   '/aboutme'.$query_string.'">');
  619:         if ($is_course) {
  620:             $r->print(&mt('Course Information page'));
  621:         } else {
  622:             $r->print(&mt('Information about [_1]',$name));
  623:         }
  624:         $r->print('</a>');
  625:     }
  626:     return;
  627: }
  628: 
  629: sub portfolio_files {
  630:     my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
  631:     my $filecounts = {
  632:                        withpass    => 0,
  633:                        withoutpass => 0,
  634:                        both        => 0,
  635:                      };
  636:     my $current_permissions =
  637: 	&Apache::lonnet::get_portfile_permissions($cdom,$cnum);
  638:     my %access_controls = 
  639: 	&Apache::lonnet::get_access_controls($current_permissions);
  640:     my $portaccess;
  641:     if ($mode eq 'showlink') {
  642:         $portaccess = 'both';
  643:     } else {
  644:         $portaccess = 'withoutpass';
  645:         if (exists($env{'form.portaccess'})) {
  646:             $portaccess = $env{'form.portaccess'};
  647:         }
  648:     }
  649: 
  650:     my $diroutput;
  651:     if ($is_course) {
  652:         my %files_by_group;
  653:         foreach my $filename (sort(keys(%access_controls))) {
  654:             my ($group,$path) = split('/',$filename,2);
  655:             $files_by_group{$group}{$path} = $access_controls{$filename}; 
  656:         }
  657:         foreach my $group (sort(keys(%files_by_group))) {
  658:             my %fileshash;
  659:             my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
  660:                                            $is_course,$filecounts,$mode,
  661:                                            $files_by_group{$group},
  662:                                            \%fileshash,$group);
  663:             if ($grpout) {
  664:                 $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
  665:             }
  666:         }
  667:     } else {
  668:         my %allfileshash;
  669:         $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
  670:                                       $filecounts,$mode,\%access_controls,
  671:                                       \%allfileshash);
  672:     }
  673:     if ($mode eq 'listfiles') {
  674:         if ($filecounts->{'both'}) {
  675:              $r->print($diroutput);
  676:         } else {
  677:             my $access_text;
  678:             if (ref($lt) eq 'HASH') {
  679:                 $access_text = $lt->{$portaccess};   
  680:             }
  681:             $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
  682:         }
  683:     }
  684:     return $filecounts;
  685: }
  686: 
  687: { 
  688:     my $count=0;
  689:     sub portfolio_table_start {
  690: 	$count=0;
  691: 	return '<table class="LC_aboutme_port">';
  692:     }
  693:     sub portfolio_row_start {
  694: 	$count++;
  695: 	my $class = ($count%2)?'LC_odd_row'
  696: 	                      :'LC_even_row';
  697: 	return '<tr class="'.$class.'">';
  698:     }
  699: }
  700: 
  701: sub build_hierarchy {
  702:     my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
  703:         $allfileshash,$group) = @_;
  704:     foreach my $filename (sort(keys(%{$access_info}))) {
  705:         my $access_status =
  706:            &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group,                                                 $$access_info{$filename});
  707:         if ($portaccess eq 'both') {
  708:             if (($access_status ne 'ok') &&
  709:                 ($access_status !~  /^[^:]+:guest_/)) {
  710:                 next;
  711:             }
  712:         } elsif ($portaccess eq 'withoutpass') {
  713:             if ($access_status ne 'ok') {
  714:                 next;
  715:             }
  716:         } elsif ($portaccess eq 'withpass') {
  717:             if ($access_status !~  /^[^:]+:guest_/) {
  718:                 next;
  719:             }
  720:         }
  721:         if ($mode eq 'listfiles') {
  722:             $filename =~ s/^\///;
  723:             my @pathitems = split('/',$filename);
  724:             my $lasthash = $allfileshash;
  725:             while (@pathitems > 1) {
  726:                 my $newlevel = shift(@pathitems);
  727:                 if (!exists($lasthash->{$newlevel})) {
  728:                     $lasthash->{$newlevel} = {};
  729:                 }
  730:                 $lasthash = $lasthash->{$newlevel};
  731:             }
  732:             $lasthash->{$pathitems[0]} = $filename;
  733:         }
  734:         if ($access_status eq 'ok') {
  735:             $filecounts->{'withoutpass'} ++;
  736:         } elsif ($access_status =~  /^[^:]+:guest_/) {
  737:             $filecounts->{'withpass'} ++;
  738:         }
  739:     }
  740:     $filecounts->{'both'} =  $filecounts->{'withoutpass'} +
  741:                               $filecounts->{'withpass'};
  742:     my $output;
  743:     if ($mode eq 'listfiles') {
  744:         if ($filecounts->{'both'} > 0) {
  745:             $output = &portfolio_table_start();
  746:             $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
  747:                                         $group);
  748:             $output .= '</table>';
  749:         }
  750:     }
  751:     return $output;
  752: }
  753: 
  754: sub parse_directory {
  755:     my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
  756:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  757:     $depth++;
  758:     my $output;
  759: 
  760:     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
  761:                                                                 $group);
  762:     my $getpropath = 1;
  763:     my %dirlist = map {
  764: 	    ((split('&',$_,2))[0],1)
  765: 	} &Apache::lonnet::dirlist($portfolio_root.$path,$cdom,$cnum,$getpropath);
  766:     foreach my $item (sort(keys(%{$currhash}))) {
  767:         $output .= &portfolio_row_start();
  768:         $output .= '<td style="padding-left: '.($depth*25).'px">';
  769:         if (ref($currhash->{$item}) eq 'HASH') {
  770:             my $title=&HTML::Entities::encode($item,'<>&"');
  771:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" />&nbsp;'.$title;
  772: 	    $output .= '</td><td></td></tr>';
  773:             $output .= &parse_directory($r,$depth,$currhash->{$item},
  774: 					$path.'/'.$item,$is_course,$group);
  775:         } else {
  776: 	    my $file_name; 
  777: 	    if ($currhash->{$item} =~ m|/([^/]+)$|) {
  778: 		$file_name = $1;
  779: 	    } else {
  780: 		$file_name = $currhash->{$item};
  781: 	    }
  782: 	    my $have_meta = exists($dirlist{$file_name.'.meta'});
  783:             my $url;
  784:             if ($is_course) {
  785:                 $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
  786:                        '/portfolio/'.$currhash->{$item};
  787:             } else { 
  788: 	        $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
  789: 		       $currhash->{$item};
  790:             }
  791:             my $showname;
  792: 	    if ($have_meta) {
  793: 		$showname = &Apache::lonnet::metadata($url,'title');
  794: 	    }
  795: 	    if ($showname eq '') {
  796: 		$showname = $file_name;
  797: 	    } else {
  798: 		$showname = $file_name.' ('.$showname.')';
  799: 	    }
  800: 
  801:             $showname=&HTML::Entities::encode($showname,'<>&"');
  802:             $output .= '<a href="'.$url.'">'.
  803: 		'<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
  804: 		'&nbsp;'.$showname.'</a>';
  805: 	    $output.='</td><td>';
  806: 	    if ($have_meta) {
  807: 		$output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Metadata').'" src="'.
  808: 		&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
  809: 		'" class="LC_icon" /></a>';
  810: 	    }
  811: 	    $output .= '</td></tr>';
  812:         }
  813:     }
  814:     return $output;
  815: }
  816: 
  817: sub aboutme_access {
  818:     my ($uname,$udom) = @_;
  819:     my $privcheck = $env{'request.course.id'};
  820:     my $sec;
  821:     if ($env{'request.course.sec'} ne '') {
  822:         $sec = $env{'request.course.sec'};
  823:         $privcheck .= '/'.$sec;
  824:     }
  825:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  826:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  827:     if (($cdom eq '') || ($cnum eq '')) {
  828:         my %coursehash = &coursedescription($env{'request.course.id'});
  829:         $cdom = $coursehash{'domain'};
  830:         $cnum = $coursehash{'cnum'};
  831:     }
  832:     if ((&Apache::lonnet::allowed('srm',$privcheck)) || 
  833:         (&Apache::lonnet::allowed('dff',$privcheck))) {
  834:         if (&in_course($uname,$udom,$cnum,$cdom)) {
  835:             return 1;
  836:         }
  837:     }
  838:     return;
  839: }
  840: 
  841: 1;
  842: __END__

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