File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.122: download - view: text, annotated - select for diffs
Fri Apr 3 10:46:13 2009 UTC (15 years, 3 months ago) by amueller
Branches: MAIN
CVS tags: HEAD
If you didn't have uploaded a picture the delete button doesn't appear

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

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