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

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

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