File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.125: download - view: text, annotated - select for diffs
Wed Apr 15 10:49:30 2009 UTC (15 years, 1 month ago) by bisitz
Branches: MAIN
CVS tags: HEAD
No content changes - removed loads of annoying trailing blanks and tabs in script code

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

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