Annotation of loncom/interface/lonaboutme.pm, revision 1.70.4.2

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

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