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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # "About Me" Personal Information
1.1       www         3: #
1.70.4.4! raeburn     4: # $Id: lonaboutme.pm,v 1.70.4.3 2010/01/30 18:03:40 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:     }
1.70.4.4! raeburn   399:     my $typesref;
        !           400:     if ($type eq 'all') {
        !           401:         $typesref = ['active','previous','future'];
        !           402:     } elsif ($type eq 'previous' || $type eq 'future') {
        !           403:         $typesref = [$type];
        !           404:     }
        !           405:     my %roles = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
        !           406:                                              $typesref,undef,[$cdom]);
        !           407:     my ($tmp) = keys(%roles);
        !           408:     return 0 if ($tmp =~ /^(con_lost|error|no_such_host)/i);
        !           409:     my @course_roles = grep(/^\Q$cnum\E:\Q$cdom\E:/, keys(%roles));
        !           410:     if (@course_roles > 0) {
        !           411:         return 1;
1.63      albertel  412:     }
                    413:     return 0;
                    414: }
                    415: 
1.43      raeburn   416: sub aboutme_info {
1.55      raeburn   417:     my ($r,$is_course) = @_;
1.43      raeburn   418:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.55      raeburn   419:     my $name;
                    420:     if (!$is_course) {
                    421:         $name = &Apache::loncommon::plainname($cnum,$cdom);
                    422:     }
1.43      raeburn   423:     return ($cdom,$cnum,$name);
                    424: }
                    425: 
                    426: sub print_portfiles_link {
1.55      raeburn   427:     my ($r,$is_course) = @_;
                    428:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.64      raeburn   429:     my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
                    430:                                       $cdom,$cnum,$name);
1.47      albertel  431:     my $query_string = &build_query_string();
1.43      raeburn   432:     my $output;
1.55      raeburn   433:     my %lt = &Apache::lonlocal::texthash(
1.70.4.1  raeburn   434:         vpfi => 'Viewable portfolio files',
                    435:         vgpf => 'Viewable group portfolio files',
                    436:         difl => 'Display file listing',
                    437:     );                     
1.43      raeburn   438:     if ($filecounts->{'both'} > 0) {
1.55      raeburn   439:         $output = '<h3>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h3>';
1.47      albertel  440:         $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
1.55      raeburn   441:                    $query_string.'">'.$lt{'difl'}.
1.43      raeburn   442:                    '</a><br /><br />';
1.53      raeburn   443:         if ($filecounts->{'both'} == 1) {
1.55      raeburn   444:             if ($is_course) {
                    445:                 $output .= &mt('One group portfolio file is available.').'<ul>';
                    446:             } else {
1.56      albertel  447:                 $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
1.55      raeburn   448:             }
1.53      raeburn   449:         } else {
1.55      raeburn   450:             if ($is_course) {
1.56      albertel  451:                 $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
1.55      raeburn   452:             } else {
                    453:                 $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
                    454:             }
1.53      raeburn   455:         }
1.43      raeburn   456:         if ($filecounts->{'withoutpass'}) {
1.54      albertel  457: 	    $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
1.43      raeburn   458:         }
                    459:         if ($filecounts->{'withpass'}) {
1.54      albertel  460: 	    $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
1.43      raeburn   461:         }
                    462:         $output .= '</ul>';
                    463:     }
                    464:     $r->print($output);
                    465:     return;
                    466: }
                    467: 
                    468: sub build_query_string {
                    469:     my ($new_items) = @_;
                    470:     my $query_string;
                    471:     my @formelements = ('register'); 
1.47      albertel  472:     my $new = 0;
1.43      raeburn   473:     if (ref($new_items) eq 'HASH') {
1.47      albertel  474:         $new = 1;
1.43      raeburn   475:         if (!defined($new_items->{'forceedit'}) && 
                    476:             !defined($new_items->{'forcestudent'})) {
                    477:             push(@formelements,('forceedit','forcestudent'));
                    478:         }
                    479:     } else {
                    480:         push(@formelements,('forceedit','forcestudent'));
                    481:     }
                    482:     foreach my $element (@formelements) {
                    483:         if (exists($env{'form.'.$element})) {
1.47      albertel  484:             if ((!$new) || (!defined($new_items->{$element}))) {
1.43      raeburn   485:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
                    486:             }
                    487:         }
                    488:     }
1.47      albertel  489:     if ($new) {
1.43      raeburn   490:         foreach my $key (keys(%{$new_items})) {
                    491:             $query_string .= '&amp;'.$key.'='.$new_items->{$key};
                    492:         }
                    493:     }
                    494:     $query_string =~ s/^\&amp;/\?/;
                    495:     return $query_string;
                    496: }
                    497: 
                    498: sub display_portfolio_header {
1.55      raeburn   499:     my ($r,$is_course) = @_;
                    500:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.43      raeburn   501:     my $query_string = &build_query_string();
                    502:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    503:     my $forcestudent='';
                    504:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.55      raeburn   505: 
                    506:     my $output;
                    507:     if ($is_course) {
                    508:         $output = 
                    509:             &Apache::loncommon::start_page('Viewable group portfolio files',undef,
                    510:                                             {'function' => $forcestudent,
                    511:                                              'domain'   => $cdom,});
                    512:         $output .= '<h3>'.&mt('Group Portfolio files').'</h3>';
                    513:     } else {
                    514:         $output  =
                    515:             &Apache::loncommon::start_page('Viewable portfolio files',undef,
                    516:                                             {'function' => $forcestudent,
1.43      raeburn   517:                                              'domain'   => $cdom,});
1.55      raeburn   518:         if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
                    519:             &Apache::lonhtmlcommon::add_breadcrumb
1.70.4.1  raeburn   520:                 ({href  => "/adm/$cdom/$cnum/aboutme".$query_string,
                    521:                   text  => &mt('Personal information Page - [_1]',$name),
                    522:                   title => &mt('Go to personal information page for [_1]',$name)},                 {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
                    523:                   text  => &mt('Viewable files - [_1]',$name),
                    524:                   title => &mt('Viewable portfolio files for [_1]',$name)}
1.55      raeburn   525:             );
                    526:             $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
                    527:         }
                    528:         $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
1.53      raeburn   529:     }
1.43      raeburn   530:     $r->print($output);
                    531:     return;
                    532: }
                    533: 
                    534: sub display_portfolio_files {
1.55      raeburn   535:     my ($r,$is_course) = @_;
                    536:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.70.4.1  raeburn   537:     my %lt = &Apache::lonlocal::texthash(
                    538:          withoutpass => 'passphrase not required',
                    539: 	 withpass    => 'passphrase protected',
                    540: 	 both        => 'all access types ',
                    541:     );
1.47      albertel  542: 
1.43      raeburn   543:     my $portaccess = 'withoutpass';
                    544:     if (exists($env{'form.portaccess'})) {
                    545:         $portaccess = $env{'form.portaccess'};
                    546:     }
1.47      albertel  547: 
1.45      albertel  548:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
                    549: 	.'" name="displaystatus" method="post">'.
                    550: 	&mt('File access type: ').'<select name="portaccess">';
1.43      raeburn   551:     foreach my $type ('withoutpass','withpass','both') {
                    552:         $output .= '<option value="'.$type.'" ';
                    553:         if ($portaccess eq $type) {
                    554:             $output .= 'selected="selected"';
                    555:         }
1.53      raeburn   556:         $output .= '>'.$lt{$type}.'</option>';
1.43      raeburn   557:     }
                    558:     $output .= '</select>'."\n".
                    559:                '<input type="submit" name="portaccessbutton" value="'.
1.47      albertel  560:                &mt('Update display').'" />';
1.43      raeburn   561:     $output .= '</form><br /><br />';
                    562:     $r->print($output);
1.64      raeburn   563:     my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
                    564:                                       $cdom,$cnum,$name);
1.53      raeburn   565:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
                    566:         my $query_string = &build_query_string();
                    567:         $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
1.55      raeburn   568:                   '/aboutme'.$query_string.'">');
                    569:         if ($is_course) {
                    570:             $r->print(&mt('Course Information page'));
                    571:         } else {
                    572:             $r->print(&mt('Information about [_1]',$name));
                    573:         }
                    574:         $r->print('</a>');
1.53      raeburn   575:     }
1.43      raeburn   576:     return;
                    577: }
                    578: 
                    579: sub portfolio_files {
1.64      raeburn   580:     my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
1.43      raeburn   581:     my $filecounts = {
                    582:                        withpass    => 0,
                    583:                        withoutpass => 0,
                    584:                        both        => 0,
                    585:                      };
                    586:     my $current_permissions =
1.44      albertel  587: 	&Apache::lonnet::get_portfile_permissions($cdom,$cnum);
1.43      raeburn   588:     my %access_controls = 
1.44      albertel  589: 	&Apache::lonnet::get_access_controls($current_permissions);
1.43      raeburn   590:     my $portaccess;
                    591:     if ($mode eq 'showlink') {
                    592:         $portaccess = 'both';
                    593:     } else {
                    594:         $portaccess = 'withoutpass';
                    595:         if (exists($env{'form.portaccess'})) {
                    596:             $portaccess = $env{'form.portaccess'};
                    597:         }
                    598:     }
                    599: 
1.55      raeburn   600:     my $diroutput;
                    601:     if ($is_course) {
                    602:         my %files_by_group;
                    603:         foreach my $filename (sort(keys(%access_controls))) {
                    604:             my ($group,$path) = split('/',$filename,2);
                    605:             $files_by_group{$group}{$path} = $access_controls{$filename}; 
                    606:         }
                    607:         foreach my $group (sort(keys(%files_by_group))) {
                    608:             my %fileshash;
                    609:             my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
                    610:                                            $is_course,$filecounts,$mode,
                    611:                                            $files_by_group{$group},
                    612:                                            \%fileshash,$group);
                    613:             if ($grpout) {
                    614:                 $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
                    615:             }
                    616:         }
                    617:     } else {
                    618:         my %allfileshash;
                    619:         $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
                    620:                                       $filecounts,$mode,\%access_controls,
                    621:                                       \%allfileshash);
                    622:     }
                    623:     if ($mode eq 'listfiles') {
                    624:         if ($filecounts->{'both'}) {
                    625:              $r->print($diroutput);
                    626:         } else {
                    627:             my $access_text;
                    628:             if (ref($lt) eq 'HASH') {
                    629:                 $access_text = $lt->{$portaccess};   
                    630:             }
                    631:             $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
                    632:         }
                    633:     }
                    634:     return $filecounts;
                    635: }
                    636: 
                    637: { 
                    638:     my $count=0;
                    639:     sub portfolio_table_start {
                    640: 	$count=0;
                    641: 	return '<table class="LC_aboutme_port">';
                    642:     }
                    643:     sub portfolio_row_start {
                    644: 	$count++;
                    645: 	my $class = ($count%2)?'LC_odd_row'
                    646: 	                      :'LC_even_row';
                    647: 	return '<tr class="'.$class.'">';
                    648:     }
                    649: }
                    650: 
                    651: sub build_hierarchy {
                    652:     my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
                    653:         $allfileshash,$group) = @_;
                    654:     foreach my $filename (sort(keys(%{$access_info}))) {
                    655:         my $access_status =
                    656:            &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group,                                                 $$access_info{$filename});
1.43      raeburn   657:         if ($portaccess eq 'both') {
                    658:             if (($access_status ne 'ok') &&
                    659:                 ($access_status !~  /^[^:]+:guest_/)) {
                    660:                 next;
                    661:             }
                    662:         } elsif ($portaccess eq 'withoutpass') {
                    663:             if ($access_status ne 'ok') {
                    664:                 next;
                    665:             }
                    666:         } elsif ($portaccess eq 'withpass') {
                    667:             if ($access_status !~  /^[^:]+:guest_/) {
                    668:                 next;
                    669:             }
                    670:         }
                    671:         if ($mode eq 'listfiles') {
                    672:             $filename =~ s/^\///;
                    673:             my @pathitems = split('/',$filename);
1.55      raeburn   674:             my $lasthash = $allfileshash;
1.43      raeburn   675:             while (@pathitems > 1) {
                    676:                 my $newlevel = shift(@pathitems);
                    677:                 if (!exists($lasthash->{$newlevel})) {
                    678:                     $lasthash->{$newlevel} = {};
                    679:                 }
                    680:                 $lasthash = $lasthash->{$newlevel};
                    681:             }
                    682:             $lasthash->{$pathitems[0]} = $filename;
                    683:         }
                    684:         if ($access_status eq 'ok') {
                    685:             $filecounts->{'withoutpass'} ++;
                    686:         } elsif ($access_status =~  /^[^:]+:guest_/) {
                    687:             $filecounts->{'withpass'} ++;
                    688:         }
                    689:     }
                    690:     $filecounts->{'both'} =  $filecounts->{'withoutpass'} +
                    691:                               $filecounts->{'withpass'};
1.55      raeburn   692:     my $output;
1.43      raeburn   693:     if ($mode eq 'listfiles') {
1.55      raeburn   694:         if ($filecounts->{'both'} > 0) {
1.45      albertel  695:             $output = &portfolio_table_start();
1.55      raeburn   696:             $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
                    697:                                         $group);
1.43      raeburn   698:             $output .= '</table>';
                    699:         }
1.45      albertel  700:     }
1.55      raeburn   701:     return $output;
1.45      albertel  702: }
                    703: 
1.43      raeburn   704: sub parse_directory {
1.55      raeburn   705:     my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
                    706:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.45      albertel  707:     $depth++;
                    708:     my $output;
1.49      albertel  709: 
1.55      raeburn   710:     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
                    711:                                                                 $group);
1.70      raeburn   712:     my $getpropath = 1;
1.49      albertel  713:     my %dirlist = map {
                    714: 	    ((split('&',$_,2))[0],1)
1.70      raeburn   715: 	} &Apache::lonnet::dirlist($portfolio_root.$path,$cdom,$cnum,$getpropath);
1.43      raeburn   716:     foreach my $item (sort(keys(%{$currhash}))) {
1.45      albertel  717:         $output .= &portfolio_row_start();
                    718:         $output .= '<td style="padding-left: '.($depth*25).'px">';
1.43      raeburn   719:         if (ref($currhash->{$item}) eq 'HASH') {
1.45      albertel  720:             my $title=&HTML::Entities::encode($item,'<>&"');
                    721:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" />&nbsp;'.$title;
1.47      albertel  722: 	    $output .= '</td><td></td></tr>';
1.49      albertel  723:             $output .= &parse_directory($r,$depth,$currhash->{$item},
1.55      raeburn   724: 					$path.'/'.$item,$is_course,$group);
1.43      raeburn   725:         } else {
1.50      albertel  726: 	    my $file_name; 
                    727: 	    if ($currhash->{$item} =~ m|/([^/]+)$|) {
                    728: 		$file_name = $1;
                    729: 	    } else {
                    730: 		$file_name = $currhash->{$item};
                    731: 	    }
                    732: 	    my $have_meta = exists($dirlist{$file_name.'.meta'});
1.55      raeburn   733:             my $url;
                    734:             if ($is_course) {
                    735:                 $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
                    736:                        '/portfolio/'.$currhash->{$item};
                    737:             } else { 
                    738: 	        $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
                    739: 		       $currhash->{$item};
                    740:             }
1.43      raeburn   741:             my $showname;
1.50      albertel  742: 	    if ($have_meta) {
                    743: 		$showname = &Apache::lonnet::metadata($url,'title');
                    744: 	    }
                    745: 	    if ($showname eq '') {
                    746: 		$showname = $file_name;
                    747: 	    } else {
                    748: 		$showname = $file_name.' ('.$showname.')';
                    749: 	    }
                    750: 
1.45      albertel  751:             $showname=&HTML::Entities::encode($showname,'<>&"');
1.49      albertel  752:             $output .= '<a href="'.$url.'">'.
                    753: 		'<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
                    754: 		'&nbsp;'.$showname.'</a>';
                    755: 	    $output.='</td><td>';
1.50      albertel  756: 	    if ($have_meta) {
1.70.4.1  raeburn   757: 		$output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Metadata').'" src="'.
1.47      albertel  758: 		&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
1.49      albertel  759: 		'" class="LC_icon" /></a>';
                    760: 	    }
1.45      albertel  761: 	    $output .= '</td></tr>';
1.43      raeburn   762:         }
                    763:     }
1.45      albertel  764:     return $output;
1.43      raeburn   765: }
1.1       www       766: 
1.70.4.1  raeburn   767: sub aboutme_access {
                    768:     my ($uname,$udom) = @_;
                    769:     my $privcheck = $env{'request.course.id'};
                    770:     my $sec;
                    771:     if ($env{'request.course.sec'} ne '') {
                    772:         $sec = $env{'request.course.sec'};
                    773:         $privcheck .= '/'.$sec;
                    774:     }
                    775:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    776:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    777:     if (($cdom eq '') || ($cnum eq '')) {
1.70.4.3  raeburn   778:         my %coursehash = &Apache::lonnet::coursedescription($env{'request.course.id'});
1.70.4.1  raeburn   779:         $cdom = $coursehash{'domain'};
                    780:         $cnum = $coursehash{'cnum'};
                    781:     }
1.70.4.2  raeburn   782:     if ((&Apache::lonnet::allowed('srm',$privcheck)) || 
1.70.4.1  raeburn   783:         (&Apache::lonnet::allowed('dff',$privcheck))) {
                    784:         if (&in_course($uname,$udom,$cnum,$cdom)) {
                    785:             return 1;
                    786:         }
                    787:     }
                    788:     return;
                    789: }
                    790: 
1.1       www       791: 1;
                    792: __END__

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