File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.78: download - view: text, annotated - select for diffs
Tue Dec 9 10:45:44 2008 UTC (15 years, 5 months ago) by ehlerst
Branches: MAIN
CVS tags: HEAD
included print_image function in lonaboutme.pm.

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

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