File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.113: download - view: text, annotated - select for diffs
Fri Mar 20 10:05:08 2009 UTC (15 years, 2 months ago) by bisitz
Branches: MAIN
CVS tags: HEAD
Standard texthash calls:
- Direct call
- Keys and values in (single) quotes
- Standard indent

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

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