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

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

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