File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.106: download - view: text, annotated - select for diffs
Thu Feb 26 16:17:30 2009 UTC (15 years, 4 months ago) by schafran
Branches: MAIN
CVS tags: HEAD
Box title is now the main title of the next page and the link text or the former page title will be set to the subtitle in the near future.
Group: consistent wording

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

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