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

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

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