File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.81: download - view: text, annotated - select for diffs
Wed Dec 10 15:58:36 2008 UTC (15 years, 6 months ago) by ehlerst
Branches: MAIN
CVS tags: HEAD
removed an unnecessary function in lontemplate.pm and added a function for sending a message. layout changes in lonaboutme.pm.

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

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