File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.92: download - view: text, annotated - select for diffs
Thu Feb 12 21:15:47 2009 UTC (15 years, 3 months ago) by schafran
Branches: MAIN
CVS tags: HEAD
consistent wording, email -> e-mail, catalog information -> metadata, e-mail vs. message

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

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