File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.89: download - view: text, annotated - select for diffs
Wed Dec 17 14:51:11 2008 UTC (15 years, 5 months ago) by harmsja
Branches: MAIN
CVS tags: HEAD
renamed new style to LC_***

    1: # The LearningOnline Network
    2: # "About Me" Personal Information
    3: #
    4: # $Id: lonaboutme.pm,v 1.89 2008/12/17 14:51:11 harmsja 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: 
   90: sub handler {
   91:     my $r = shift;
   92:     &Apache::loncommon::content_type($r,'text/html');
   93:     $r->send_http_header;
   94:     return OK if $r->header_only;
   95:     my $target=$env{'form.grade_target'};
   96: # ------------------------------------------------------------ Print the screen
   97:     if ($target eq 'tex') {
   98: 	$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
   99:     }
  100:     my (undef,undef,$cdom,$cnum,undef,$action)=split(/\//,$r->uri);
  101:     my $is_course;
  102: # Is this even a user?
  103:     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
  104: 	&Apache::loncommon::simple_error_page($r,'No info',
  105: 					      'No user information available');
  106:         return OK;
  107:     } else {
  108:         $is_course = &Apache::lonnet::is_course($cdom,$cnum);
  109:     }
  110: 
  111:     my $candisplay = 1;
  112:     if (!$is_course) {
  113:         if ($action ne 'portfolio') {
  114:             $candisplay = &Apache::lonnet::usertools_access($cnum,$cdom,'aboutme');
  115:             if ((!$candisplay) && ($env{'request.course.id'})) {
  116:                 $candisplay = &aboutme_access($cnum,$cdom);
  117:             }
  118:             if (!$candisplay) {
  119:                 if ($target eq 'tex') {
  120:                     $r->print('\noindent{\large\textbf{'.&mt('No user home page available').'}}\\\\\\\\');
  121:                 } else {
  122:                     $r->print(&Apache::loncommon::start_page("Personal Information"));
  123:                     $r->print('<h2>'.&mt('No user home page available') .'</h2>'.
  124:                               &mt('This is a result of one of the following:').'<ul>'.
  125:                               '<li>'.&mt('The administrator of this domain has disabled home page functionality for this specific user.').'</li>'.
  126:                               '<li>'.&mt('The domain has been configured to disable, by default, home page functionality for all users in the domain.').'</li>'.
  127:                               '</ul>');
  128:                     $r->print(&Apache::loncommon::end_page());
  129:                 }
  130:                 return OK;
  131:             }
  132:         }
  133:     }
  134: 
  135: # --------------------------------------------------------- The syllabus fields
  136:     my %syllabusfields=&Apache::lonlocal::texthash(
  137:        'aaa_contactinfo'   => 'Contact Information',
  138:        'bbb_aboutme'       => 'About Me',
  139:        'ccc_webreferences' => 'Web References');
  140: 
  141: # ------------------------------------------------------------ Get Query String
  142:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  143: 					    ['forceedit','forcestudent',
  144: 					     'register','popup']);
  145: 
  146: # ----------------------------------------------- Available Portfolio file display 
  147:     if (($target ne 'tex') && ($action eq 'portfolio')) {
  148:         &display_portfolio_header($r,$is_course);
  149:         if ((!$is_course) && (!&Apache::lonnet::usertools_access($cnum,$cdom,'portfolio'))) {
  150:             $r->print('<h2>'.&mt('No user portfolio available') .'</h2>'.
  151:                       &mt('This is a result of one of the following:').'<ul>'.
  152:                       '<li>'.&mt('The administrator of this domain has disabled portfolio functionality for this specific user.').'</li>'.
  153:                       '<li>'.&mt('The domain has been configured to disable, by default, portfolio functionality for all users in the domain.').'</li>'.
  154:                       '</ul>');
  155:         } else {
  156:             my ($blocked,$blocktext) = 
  157:                 &Apache::loncommon::blocking_status('port',$cnum,$cdom);
  158:             if (!$blocked) {
  159:                 &display_portfolio_files($r,$is_course);
  160:             } else {
  161:                 $r->print($blocktext);
  162:             }
  163:         }
  164:         $r->print(&Apache::loncommon::end_page());
  165:         return OK;
  166:     }
  167: 
  168:     if ($is_course) {
  169:         if ($target ne 'tex') {
  170: 	    my $brcrum = [{href=>"/adm/navmaps",text=>"Navigate Course Contents"},
  171: 			  {href=>"/adm/aboutme",text=>"Course Information"}];
  172:             my $start_page =
  173:                 &Apache::loncommon::start_page(
  174:                     "Course Information",
  175:                      undef,
  176:                      {'function' => $env{'forcestudent'},
  177:                       'domain'   => $cdom,
  178:                       'force_register' => $env{'forceregister'},
  179:                       'bread_crumbs' => $brcrum});
  180:             $r->print($start_page);
  181:             $r->print('<h2>'.&mt('Group files').'</h2>');
  182:             &print_portfiles_link($r,$is_course);
  183:             $r->print(&Apache::loncommon::end_page());
  184:         }
  185:         return OK;
  186:     }
  187: 
  188: # --------------------------------------------------------------- Force Student
  189:     my $forcestudent='';
  190:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
  191: 
  192:     my $forceregister = '';
  193:     if ($forcestudent eq '') {
  194:         $forceregister = $env{'form.register'};
  195:     }
  196:        
  197: # --------------------------------------- There is such a user, get environment
  198:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
  199:     if ($target ne 'tex') {
  200: 	my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
  201:         my $args = {'function' => $forcestudent,
  202:                     'domain'   => $cdom,
  203:                     'force_register' => $forceregister};
  204:         if ($env{'form.popup'}) {
  205:             $args->{'no_nav_bar'} = 1;
  206:         }
  207: 	$args->{'bread_crumbs'} = [{href=>"/adm/fhwfdev/$cnum/aboutme",text=>"Personal Information"}];
  208: 	my $start_page = 
  209: 	    &Apache::loncommon::start_page("Personal Information",$rss_link,$args);
  210: 	$r->print($start_page);
  211: 	$r->print('<h2>'.&Apache::loncommon::plainname($cnum,$cdom).'</h2>');
  212:     } else {
  213: 	$r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
  214:     }
  215:     if ($courseenv{'nickname'}) {
  216:        $r->print(
  217:          '<h2>&quot;'.$courseenv{'nickname'}.
  218:          '&quot;</h2>');
  219:     }
  220:     if ($target ne 'tex') {
  221: 	$r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>');#OLD SendMessage POS
  222:     } else {
  223: 	$r->print('\textbf{'.&Apache::lonnet::domain($cdom,'description').'}\\\\');
  224:     }
  225:     my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
  226:     my $allowed=0;
  227: 
  228: # does this user have privileges to post, etc?
  229: 
  230:        my $privleged=$allowed=(($env{'user.name'} eq $cnum) && 
  231: 			       ($env{'user.domain'} eq $cdom));
  232:        if ($forcestudent or $target eq 'tex') { $allowed=0; }
  233: 	my $query_string; 
  234:        if ($allowed) {
  235:            $query_string = &build_query_string({'forcestudent' => '1','popup' => $env{'form.popup'}});
  236: 	   $r->print('<p><b>'.&mt('Privacy Note').':</b> '.
  237: 		     &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.').
  238: 		     '</p><p><a href="'.$r->uri.$query_string.'">'.&mt('Show Public View').'</a>'.
  239:                      &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>'.
  240: 		     &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).'</p>');
  241:        } elsif ($privleged && $target ne 'tex') {
  242:            $query_string = &build_query_string({'forceedit' => '1','popup' => $env{'form.popup'}});
  243: 	   $r->print('<p><a href="'.$r->uri.$query_string.'">'.
  244: 		     &mt('Edit').'</a></p>');
  245:        }
  246:       if (($env{'form.uploaddoc.filename'}) &&
  247:           ($env{'form.storeupl'}) && ($allowed)) {
  248:  	  if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
  249: 	      if ($syllabus{'uploaded.photourl'}) {
  250: 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  251: 	      }
  252: 	      $syllabus{'uploaded.photourl'}=
  253:                  &Apache::lonnet::userphotoupload('uploaddoc','aboutme');
  254:  	  }
  255:           $syllabus{'uploaded.lastmodified'}=time;
  256:           &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
  257:        }
  258:     if ($allowed && $env{'form.delupl'}) {
  259: 	if ($syllabus{'uploaded.photourl'}) {
  260: 	    &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  261: 	    delete($syllabus{'uploaded.photourl'});
  262: 	    &Apache::lonnet::del('aboutme',['uploaded.photourl'],$cdom,$cnum);
  263: 	}
  264:     }
  265:        if (($allowed) && ($env{'form.storesyl'})) {
  266: 	   foreach my $syl_field (keys(%syllabusfields)) {
  267:                my $field=$env{'form.'.$syl_field};
  268:                $field=~s/\s+$//s;
  269:                $field=&Apache::lonfeedback::clear_out_html($field,
  270:                                                            $env{'user.adv'});
  271: 	       $syllabus{$syl_field}=$field;
  272:            }
  273:            $syllabus{'uploaded.lastmodified'}=time;
  274:            &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
  275:        }
  276: 
  277: my $lastmod;
  278: my $image; 
  279: # ---------------------------------------------------------------- Get syllabus
  280:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
  281:        $lastmod=$syllabus{'uploaded.lastmodified'};
  282:        $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
  283: 	 $r->print('<br />'.&mt('Last updated').': '.$lastmod);
  284:        if ($syllabus{'uploaded.photourl'}) {
  285: 	   &Apache::lonnet::allowuploaded('/adm/aboutme',
  286: 					  $syllabus{'uploaded.photourl'});
  287: 	   $image=qq{<img name="userPhoto" src="$syllabus{'uploaded.photourl'}" />};
  288: 
  289: 	   if ($target eq 'tex') {
  290: 	       $image=&Apache::lonxml::xmlparse($r,'tex',$image);
  291: 	   }
  292: 	  # $r->print($image); #Print old Image
  293:        }
  294:        if ($allowed) {
  295:            $r->print(
  296: 	 '<form method="post" enctype="multipart/form-data">'.
  297:          '<h3>'.&mt('Upload a Photo').'</h3>'.
  298:          '<input type="file" name="uploaddoc" size="50" />'.
  299:          '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />'.
  300:          '<input type="hidden" name="popup" value="'.$env{'form.popup'}.'" />'.
  301: 	 '</form><form method="post"><input type="submit" name="delupl" value="'.&mt('Delete Photo').'" /> </form>
  302: ');
  303: 
  304:        }
  305: 
  306: 	if($allowed) {
  307: 		$r->print('<form method="post">');
  308: 	}
  309: 
  310: 	&Apache::lontemplate::start_columnSection($r);
  311: 	&Apache::lontemplate::print_content_template($r,$allowed,$target,\%syllabusfields,\%syllabus);
  312:        if($target ne 'tex')
  313:        {
  314: 		&Apache::lontemplate::start_ContentBox($r);
  315: 		$r->print($image);
  316: 		&Apache::lontemplate::send_message($r,$cnum,$cdom);
  317: 		&Apache::lontemplate::end_ContentBox($r);
  318: 		&Apache::lontemplate::end_columnSection($r);
  319: 
  320: 		&Apache::lontemplate::start_columnSection($r);
  321: 		&Apache::lontemplate::start_ContentBox($r);
  322: 		&print_portfiles_link($r,$is_course);
  323: 		if(&Apache::lonrss::advertisefeeds($cnum,$cdom) ne ''){
  324: 			$r->print('<div class="LC_ContentBoxSpecial">');
  325: 			$r->print('<h4 class="LC_hcell">'.'RSS Feeds and Blogs'.'</h4>');
  326: 			$r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom));
  327: 			$r->print('</div>');
  328: 		}
  329: 		&Apache::lontemplate::end_ContentBox($r);
  330: 		&Apache::lontemplate::end_columnSection($r);
  331: 		if($allowed){
  332: 			$r->print('<p><a href="'.$r->uri.$query_string.'">'.&mt('Show Public View').'</a>'.
  333:                         	&Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
  334: 		}
  335:        }
  336:        if ($allowed) {
  337:            if ($env{'form.popup'}) {
  338:                $r->print('<input type="hidden" name="popup" value="'.
  339:                          $env{'form.popup'}.'" />');
  340:            }
  341: 	   $r->print('</form>');
  342:        }
  343:        if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
  344:     } else {
  345: 	 &Apache::lontemplate::send_message($r,$cnum,$cdom);
  346:        $r->print('<p>'.&mt('No personal information provided').'.</p>');
  347:     }
  348: 
  349:     if ($target ne 'tex') {
  350:         # &print_portfiles_link($r,$is_course); #old Print files
  351: 
  352:     }
  353: 
  354:     if ($env{'request.course.id'}
  355: 	&& &Apache::lonnet::allowed('srm',$env{'request.course.id'})
  356: 	&& &in_course($cdom,$cnum)) {
  357: 	if ($target ne 'tex') {
  358: 	    $r->print('<a name="coursecomment" />');
  359: 	    $r->print('<hr /><h3>'.
  360: 		      &mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'</h3>'.
  361: 		      &mt('Shared by course faculty and staff').
  362: 		      &Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message").
  363: 		      '<br />');
  364: 	    &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
  365: 	    $r->print('<hr />');
  366: 	    if (&Apache::lonnet::allowed('vsa',
  367: 					 $env{'request.course.id'}) ||
  368: 		&Apache::lonnet::allowed('vsa',
  369: 					 $env{'request.course.id'}.'/'.
  370: 					 $env{'request.course.sec'})) {
  371: 		$r->print(&Apache::loncommon::track_student_link
  372: 			  ('View recent activity by this student',
  373: 			   $cnum,$cdom).('&nbsp;'x2));
  374: 	    }
  375: 	    $r->print(&Apache::loncommon::noteswrapper('Add Records',$cnum,$cdom));
  376: 	} else {
  377: 	    $r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
  378: 	    &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
  379: 	}
  380:     }
  381:     if ($target ne 'tex') {
  382:         if ($env{'form.popup'}) {
  383:             $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a>');
  384:         }
  385: 	$r->print(&Apache::loncommon::end_page());
  386:     } else {
  387: 	$r->print('\end{document}');
  388:     }
  389: 
  390:   
  391: 	
  392:     return OK;
  393: }
  394: 
  395: sub in_course {
  396:     my ($udom,$uname,$cdom,$cnum,$type) = @_;
  397:     $type ||= 'any';
  398:     if (!defined($cdom) || !defined($cnum)) {
  399: 	my $cid  = $env{'request.course.id'};
  400: 	$cdom = $env{'course.'.$cid.'.domain'};
  401: 	$cnum = $env{'course.'.$cid.'.num'};
  402:     }
  403:     my %roles = &Apache::lonnet::dump('roles',$udom,$uname);
  404:     my @course_roles = grep(m{^/\Q$cdom\E/\Q$cnum\E[/_]}, keys(%roles));
  405:     return 0 if (!@course_roles);
  406:     return 1 if ($type eq 'any');
  407:     my $now = time();
  408:     foreach my $role (@course_roles) {
  409: 	my (undef,$role_end,$role_start)=split(/\_/,$roles{$role});
  410: 	my $status = 'active';
  411: 	if ($role_start > 0 && $now < $role_start) {
  412: 	    $status = 'future';
  413: 	}
  414: 	if ($role_end > 0 && $now > $role_end) {
  415: 	    $status = 'previous';
  416: 	}
  417: 	return 1 if ($status eq $type);
  418:     }
  419:     return 0;
  420: }
  421: 
  422: sub aboutme_info {
  423:     my ($r,$is_course) = @_;
  424:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
  425:     my $name;
  426:     if (!$is_course) {
  427:         $name = &Apache::loncommon::plainname($cnum,$cdom);
  428:     }
  429:     return ($cdom,$cnum,$name);
  430: }
  431: 
  432: sub print_portfiles_link {
  433:     my ($r,$is_course) = @_;
  434:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  435:     my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
  436:                                       $cdom,$cnum,$name);
  437:     my $query_string = &build_query_string();
  438:     my $output;
  439:     my %lt = &Apache::lonlocal::texthash(
  440:                          vpfi => 'Viewable portfolio files',
  441:                          vgpf => 'Viewable group portfolio files',
  442:                          difl => 'Display file listing',
  443:              );                     
  444:     if ($filecounts->{'both'} > 0) {
  445: 	$output = '<div class="LC_ContentBoxSpecial"><h4 class="LC_hcell">';
  446: 	$output .= ($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
  447:         
  448: 	#$output = '<h4>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
  449:         $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
  450:                    $query_string.'">'.$lt{'difl'}.
  451:                    '</a><br /><br />';
  452:         if ($filecounts->{'both'} == 1) {
  453:             if ($is_course) {
  454:                 $output .= &mt('One group portfolio file is available.').'<ul>';
  455:             } else {
  456:                 $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
  457:             }
  458:         } else {
  459:             if ($is_course) {
  460:                 $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
  461:             } else {
  462:                 $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
  463:             }
  464:         }
  465:         if ($filecounts->{'withoutpass'}) {
  466: 	    $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
  467:         }
  468:         if ($filecounts->{'withpass'}) {
  469: 	    $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
  470:         }
  471:         $output .= '</ul>';
  472: 	$output .='</p>';
  473: 	$output .='</div>';
  474:     }
  475:     $r->print($output);
  476:     return;
  477: }
  478: 
  479: sub build_query_string {
  480:     my ($new_items) = @_;
  481:     my $query_string;
  482:     my @formelements = ('register'); 
  483:     my $new = 0;
  484:     if (ref($new_items) eq 'HASH') {
  485:         $new = 1;
  486:         if (!defined($new_items->{'forceedit'}) && 
  487:             !defined($new_items->{'forcestudent'})) {
  488:             push(@formelements,('forceedit','forcestudent'));
  489:         }
  490:     } else {
  491:         push(@formelements,('forceedit','forcestudent'));
  492:     }
  493:     foreach my $element (@formelements) {
  494:         if (exists($env{'form.'.$element})) {
  495:             if ((!$new) || (!defined($new_items->{$element}))) {
  496:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
  497:             }
  498:         }
  499:     }
  500:     if ($new) {
  501:         foreach my $key (keys(%{$new_items})) {
  502:             $query_string .= '&amp;'.$key.'='.$new_items->{$key};
  503:         }
  504:     }
  505:     $query_string =~ s/^\&amp;/\?/;
  506:     return $query_string;
  507: }
  508: 
  509: sub display_portfolio_header {
  510:     my ($r,$is_course) = @_;
  511:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  512:     my $query_string = &build_query_string();
  513:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  514:     my $forcestudent='';
  515:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
  516: 
  517:     my $output;
  518:     if ($is_course) {
  519:         $output = 
  520:             &Apache::loncommon::start_page('Viewable group portfolio files',undef,
  521:                                             {'function' => $forcestudent,
  522:                                              'domain'   => $cdom,});
  523:         $output .= '<h3>'.&mt('Group Portfolio files').'</h3>';
  524:     } else {
  525:         $output  =
  526:             &Apache::loncommon::start_page('Viewable portfolio files',undef,
  527:                                             {'function' => $forcestudent,
  528:                                              'domain'   => $cdom,});
  529:         if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
  530:             &Apache::lonhtmlcommon::add_breadcrumb
  531:                 ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
  532:                   text=>"Personal information - $name",
  533:                   title=>"Go to personal information page for $name"},                 {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
  534:                   text=>"Viewable files - $name",
  535:                   title=>"Viewable portfolio files for $name"}
  536:             );
  537:             $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
  538:         }
  539:         $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
  540:     }
  541:     $r->print($output);
  542:     return;
  543: }
  544: 
  545: sub display_portfolio_files {
  546:     my ($r,$is_course) = @_;
  547:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  548:     my %lt = ( withoutpass => 'passphrase not required',
  549: 	       withpass    => 'passphrase protected',
  550: 	       both        => 'all access types ',);
  551:     %lt = &Apache::lonlocal::texthash(%lt);
  552: 
  553:     my $portaccess = 'withoutpass';
  554:     if (exists($env{'form.portaccess'})) {
  555:         $portaccess = $env{'form.portaccess'};
  556:     }
  557: 
  558:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
  559: 	.'" name="displaystatus" method="post">'.
  560: 	&mt('File access type: ').'<select name="portaccess">';
  561:     foreach my $type ('withoutpass','withpass','both') {
  562:         $output .= '<option value="'.$type.'" ';
  563:         if ($portaccess eq $type) {
  564:             $output .= 'selected="selected"';
  565:         }
  566:         $output .= '>'.$lt{$type}.'</option>';
  567:     }
  568:     $output .= '</select>'."\n".
  569:                '<input type="submit" name="portaccessbutton" value="'.
  570:                &mt('Update display').'" />';
  571:     $output .= '</form><br /><br />';
  572:     $r->print($output);
  573:     my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
  574:                                       $cdom,$cnum,$name);
  575:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
  576:         my $query_string = &build_query_string();
  577:         $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
  578:                   '/aboutme'.$query_string.'">');
  579:         if ($is_course) {
  580:             $r->print(&mt('Course Information page'));
  581:         } else {
  582:             $r->print(&mt('Information about [_1]',$name));
  583:         }
  584:         $r->print('</a>');
  585:     }
  586:     return;
  587: }
  588: 
  589: sub portfolio_files {
  590:     my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
  591:     my $filecounts = {
  592:                        withpass    => 0,
  593:                        withoutpass => 0,
  594:                        both        => 0,
  595:                      };
  596:     my $current_permissions =
  597: 	&Apache::lonnet::get_portfile_permissions($cdom,$cnum);
  598:     my %access_controls = 
  599: 	&Apache::lonnet::get_access_controls($current_permissions);
  600:     my $portaccess;
  601:     if ($mode eq 'showlink') {
  602:         $portaccess = 'both';
  603:     } else {
  604:         $portaccess = 'withoutpass';
  605:         if (exists($env{'form.portaccess'})) {
  606:             $portaccess = $env{'form.portaccess'};
  607:         }
  608:     }
  609: 
  610:     my $diroutput;
  611:     if ($is_course) {
  612:         my %files_by_group;
  613:         foreach my $filename (sort(keys(%access_controls))) {
  614:             my ($group,$path) = split('/',$filename,2);
  615:             $files_by_group{$group}{$path} = $access_controls{$filename}; 
  616:         }
  617:         foreach my $group (sort(keys(%files_by_group))) {
  618:             my %fileshash;
  619:             my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
  620:                                            $is_course,$filecounts,$mode,
  621:                                            $files_by_group{$group},
  622:                                            \%fileshash,$group);
  623:             if ($grpout) {
  624:                 $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
  625:             }
  626:         }
  627:     } else {
  628:         my %allfileshash;
  629:         $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
  630:                                       $filecounts,$mode,\%access_controls,
  631:                                       \%allfileshash);
  632:     }
  633:     if ($mode eq 'listfiles') {
  634:         if ($filecounts->{'both'}) {
  635:              $r->print($diroutput);
  636:         } else {
  637:             my $access_text;
  638:             if (ref($lt) eq 'HASH') {
  639:                 $access_text = $lt->{$portaccess};   
  640:             }
  641:             $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
  642:         }
  643:     }
  644:     return $filecounts;
  645: }
  646: 
  647: { 
  648:     my $count=0;
  649:     sub portfolio_table_start {
  650: 	$count=0;
  651: 	return '<table class="LC_aboutme_port">';
  652:     }
  653:     sub portfolio_row_start {
  654: 	$count++;
  655: 	my $class = ($count%2)?'LC_odd_row'
  656: 	                      :'LC_even_row';
  657: 	return '<tr class="'.$class.'">';
  658:     }
  659: }
  660: 
  661: sub build_hierarchy {
  662:     my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
  663:         $allfileshash,$group) = @_;
  664:     foreach my $filename (sort(keys(%{$access_info}))) {
  665:         my $access_status =
  666:            &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group,                                                 $$access_info{$filename});
  667:         if ($portaccess eq 'both') {
  668:             if (($access_status ne 'ok') &&
  669:                 ($access_status !~  /^[^:]+:guest_/)) {
  670:                 next;
  671:             }
  672:         } elsif ($portaccess eq 'withoutpass') {
  673:             if ($access_status ne 'ok') {
  674:                 next;
  675:             }
  676:         } elsif ($portaccess eq 'withpass') {
  677:             if ($access_status !~  /^[^:]+:guest_/) {
  678:                 next;
  679:             }
  680:         }
  681:         if ($mode eq 'listfiles') {
  682:             $filename =~ s/^\///;
  683:             my @pathitems = split('/',$filename);
  684:             my $lasthash = $allfileshash;
  685:             while (@pathitems > 1) {
  686:                 my $newlevel = shift(@pathitems);
  687:                 if (!exists($lasthash->{$newlevel})) {
  688:                     $lasthash->{$newlevel} = {};
  689:                 }
  690:                 $lasthash = $lasthash->{$newlevel};
  691:             }
  692:             $lasthash->{$pathitems[0]} = $filename;
  693:         }
  694:         if ($access_status eq 'ok') {
  695:             $filecounts->{'withoutpass'} ++;
  696:         } elsif ($access_status =~  /^[^:]+:guest_/) {
  697:             $filecounts->{'withpass'} ++;
  698:         }
  699:     }
  700:     $filecounts->{'both'} =  $filecounts->{'withoutpass'} +
  701:                               $filecounts->{'withpass'};
  702:     my $output;
  703:     if ($mode eq 'listfiles') {
  704:         if ($filecounts->{'both'} > 0) {
  705:             $output = &portfolio_table_start();
  706:             $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
  707:                                         $group);
  708:             $output .= '</table>';
  709:         }
  710:     }
  711:     return $output;
  712: }
  713: 
  714: sub parse_directory {
  715:     my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
  716:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  717:     $depth++;
  718:     my $output;
  719: 
  720:     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
  721:                                                                 $group);
  722:     my $getpropath = 1;
  723:     my %dirlist = map {
  724: 	    ((split('&',$_,2))[0],1)
  725: 	} &Apache::lonnet::dirlist($portfolio_root.$path,$cdom,$cnum,$getpropath);
  726:     foreach my $item (sort(keys(%{$currhash}))) {
  727:         $output .= &portfolio_row_start();
  728:         $output .= '<td style="padding-left: '.($depth*25).'px">';
  729:         if (ref($currhash->{$item}) eq 'HASH') {
  730:             my $title=&HTML::Entities::encode($item,'<>&"');
  731:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" />&nbsp;'.$title;
  732: 	    $output .= '</td><td></td></tr>';
  733:             $output .= &parse_directory($r,$depth,$currhash->{$item},
  734: 					$path.'/'.$item,$is_course,$group);
  735:         } else {
  736: 	    my $file_name; 
  737: 	    if ($currhash->{$item} =~ m|/([^/]+)$|) {
  738: 		$file_name = $1;
  739: 	    } else {
  740: 		$file_name = $currhash->{$item};
  741: 	    }
  742: 	    my $have_meta = exists($dirlist{$file_name.'.meta'});
  743:             my $url;
  744:             if ($is_course) {
  745:                 $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
  746:                        '/portfolio/'.$currhash->{$item};
  747:             } else { 
  748: 	        $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
  749: 		       $currhash->{$item};
  750:             }
  751:             my $showname;
  752: 	    if ($have_meta) {
  753: 		$showname = &Apache::lonnet::metadata($url,'title');
  754: 	    }
  755: 	    if ($showname eq '') {
  756: 		$showname = $file_name;
  757: 	    } else {
  758: 		$showname = $file_name.' ('.$showname.')';
  759: 	    }
  760: 
  761:             $showname=&HTML::Entities::encode($showname,'<>&"');
  762:             $output .= '<a href="'.$url.'">'.
  763: 		'<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
  764: 		'&nbsp;'.$showname.'</a>';
  765: 	    $output.='</td><td>';
  766: 	    if ($have_meta) {
  767: 		$output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Catalog Information').'" src="'.
  768: 		&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
  769: 		'" class="LC_icon" /></a>';
  770: 	    }
  771: 	    $output .= '</td></tr>';
  772:         }
  773:     }
  774:     return $output;
  775: }
  776: 
  777: sub aboutme_access {
  778:     my ($uname,$udom) = @_;
  779:     my $privcheck = $env{'request.course.id'};
  780:     my $sec;
  781:     if ($env{'request.course.sec'} ne '') {
  782:         $sec = $env{'request.course.sec'};
  783:         $privcheck .= '/'.$sec;
  784:     }
  785:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  786:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  787:     if (($cdom eq '') || ($cnum eq '')) {
  788:         my %coursehash = &coursedescription($env{'request.course.id'});
  789:         $cdom = $coursehash{'domain'};
  790:         $cnum = $coursehash{'cnum'};
  791:     }
  792:     if ((&Apache::lonnet::allowed('srm',$privcheck)) || 
  793:         (&Apache::lonnet::allowed('dff',$privcheck))) {
  794:         if (&in_course($uname,$udom,$cnum,$cdom)) {
  795:             return 1;
  796:         }
  797:     }
  798:     return;
  799: }
  800: 
  801: 1;
  802: __END__

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