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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # "About Me" Personal Information
1.1       www         3: #
1.81    ! ehlerst     4: # $Id: lonaboutme.pm,v 1.80 2008/12/09 22:16:23 raeburn Exp $
1.1       www         5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: 
1.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.81    ! ehlerst   307: 		&Apache::lontemplate::start_ContentBox($r);
        !           308: 		$r->print($image);
        !           309: 		&Apache::lontemplate::send_message($r,$cnum,$cdom);
        !           310: 		&Apache::lontemplate::end_ContentBox($r);
        !           311: 		&Apache::lontemplate::end_columnSection($r);
        !           312: 		&Apache::lontemplate::start_columnSection($r);
        !           313: 		&Apache::lontemplate::start_ContentBox($r);
        !           314: 		&print_portfiles_link($r,$is_course);
        !           315: 		if(&Apache::lonrss::advertisefeeds($cnum,$cdom) ne ''){
        !           316: 			$r->print('<div class="ContentBoxSpecial">');
        !           317: 			$r->print('<h4 class="hcell">'.'RSS Feeds and Blogs'.'</h4>');
        !           318: 			$r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom));
        !           319: 			$r->print('</div>');
        !           320: 		}
        !           321: 		&Apache::lontemplate::end_ContentBox($r);
        !           322: 		&Apache::lontemplate::end_columnSection($r);
1.71      amueller  323:        }
                    324: 
1.23      sakharuk  325:        if ($allowed) {
1.69      raeburn   326:            if ($env{'form.popup'}) {
                    327:                $r->print('<input type="hidden" name="popup" value="'.
                    328:                          $env{'form.popup'}.'" />');
                    329:            }
1.2       www       330: 	   $r->print('</form>');
                    331:        }
1.46      albertel  332:        if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
1.2       www       333:     } else {
1.17      www       334:        $r->print('<p>'.&mt('No personal information provided').'.</p>');
1.8       www       335:     }
1.43      raeburn   336: 
                    337:     if ($target ne 'tex') {
1.71      amueller  338:         # &print_portfiles_link($r,$is_course); #old Print files
                    339: 
1.43      raeburn   340:     }
                    341: 
1.63      albertel  342:     if ($env{'request.course.id'}
                    343: 	&& &Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    344: 	&& &in_course($cdom,$cnum)) {
                    345: 	if ($target ne 'tex') {
                    346: 	    $r->print('<a name="coursecomment" />');
                    347: 	    $r->print('<hr /><h3>'.
                    348: 		      &mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'</h3>'.
                    349: 		      &mt('Shared by course faculty and staff').
                    350: 		      &Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message").
                    351: 		      '<br />');
                    352: 	    &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
                    353: 	    $r->print('<hr />');
                    354: 	    if (&Apache::lonnet::allowed('vsa',
                    355: 					 $env{'request.course.id'}) ||
                    356: 		&Apache::lonnet::allowed('vsa',
                    357: 					 $env{'request.course.id'}.'/'.
                    358: 					 $env{'request.course.sec'})) {
                    359: 		$r->print(&Apache::loncommon::track_student_link
                    360: 			  ('View recent activity by this student',
                    361: 			   $cnum,$cdom).('&nbsp;'x2));
1.22      sakharuk  362: 	    }
1.63      albertel  363: 	    $r->print(&Apache::loncommon::noteswrapper('Add Records',$cnum,$cdom));
                    364: 	} else {
                    365: 	    $r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
                    366: 	    &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
                    367: 	}
1.1       www       368:     }
1.40      albertel  369:     if ($target ne 'tex') {
1.69      raeburn   370:         if ($env{'form.popup'}) {
                    371:             $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a>');
                    372:         }
1.71      amueller  373: 	$r->print('<br />'.&mt('Last updated').': '.$lastmod);
1.40      albertel  374: 	$r->print(&Apache::loncommon::end_page());
                    375:     } else {
                    376: 	$r->print('\end{document}');
                    377:     }
1.71      amueller  378: 
                    379:   
                    380: 	
1.1       www       381:     return OK;
1.43      raeburn   382: }
                    383: 
1.63      albertel  384: sub in_course {
                    385:     my ($udom,$uname,$cdom,$cnum,$type) = @_;
                    386:     $type ||= 'any';
                    387:     if (!defined($cdom) || !defined($cnum)) {
                    388: 	my $cid  = $env{'request.course.id'};
                    389: 	$cdom = $env{'course.'.$cid.'.domain'};
                    390: 	$cnum = $env{'course.'.$cid.'.num'};
                    391:     }
                    392:     my %roles = &Apache::lonnet::dump('roles',$udom,$uname);
                    393:     my @course_roles = grep(m{^/\Q$cdom\E/\Q$cnum\E[/_]}, keys(%roles));
                    394:     return 0 if (!@course_roles);
                    395:     return 1 if ($type eq 'any');
                    396:     my $now = time();
                    397:     foreach my $role (@course_roles) {
                    398: 	my (undef,$role_end,$role_start)=split(/\_/,$roles{$role});
                    399: 	my $status = 'active';
                    400: 	if ($role_start > 0 && $now < $role_start) {
                    401: 	    $status = 'future';
                    402: 	}
                    403: 	if ($role_end > 0 && $now > $role_end) {
                    404: 	    $status = 'previous';
                    405: 	}
                    406: 	return 1 if ($status eq $type);
                    407:     }
                    408:     return 0;
                    409: }
                    410: 
1.43      raeburn   411: sub aboutme_info {
1.55      raeburn   412:     my ($r,$is_course) = @_;
1.43      raeburn   413:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.55      raeburn   414:     my $name;
                    415:     if (!$is_course) {
                    416:         $name = &Apache::loncommon::plainname($cnum,$cdom);
                    417:     }
1.43      raeburn   418:     return ($cdom,$cnum,$name);
                    419: }
                    420: 
                    421: sub print_portfiles_link {
1.55      raeburn   422:     my ($r,$is_course) = @_;
                    423:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.64      raeburn   424:     my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
                    425:                                       $cdom,$cnum,$name);
1.47      albertel  426:     my $query_string = &build_query_string();
1.43      raeburn   427:     my $output;
1.55      raeburn   428:     my %lt = &Apache::lonlocal::texthash(
                    429:                          vpfi => 'Viewable portfolio files',
                    430:                          vgpf => 'Viewable group portfolio files',
                    431:                          difl => 'Display file listing',
                    432:              );                     
1.43      raeburn   433:     if ($filecounts->{'both'} > 0) {
1.76      harmsja   434: 	$output = '<div class="ContentBoxSpecial"><h4 class="hcell">';
                    435: 	$output .= ($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
1.71      amueller  436:         
1.76      harmsja   437: 	#$output = '<h4>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
1.47      albertel  438:         $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
1.55      raeburn   439:                    $query_string.'">'.$lt{'difl'}.
1.43      raeburn   440:                    '</a><br /><br />';
1.53      raeburn   441:         if ($filecounts->{'both'} == 1) {
1.55      raeburn   442:             if ($is_course) {
                    443:                 $output .= &mt('One group portfolio file is available.').'<ul>';
                    444:             } else {
1.56      albertel  445:                 $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
1.55      raeburn   446:             }
1.53      raeburn   447:         } else {
1.55      raeburn   448:             if ($is_course) {
1.56      albertel  449:                 $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
1.55      raeburn   450:             } else {
                    451:                 $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
                    452:             }
1.53      raeburn   453:         }
1.43      raeburn   454:         if ($filecounts->{'withoutpass'}) {
1.54      albertel  455: 	    $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
1.43      raeburn   456:         }
                    457:         if ($filecounts->{'withpass'}) {
1.54      albertel  458: 	    $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
1.43      raeburn   459:         }
                    460:         $output .= '</ul>';
1.76      harmsja   461: 	$output .='</p>';
1.81    ! ehlerst   462: 	$output .='</div>';
1.43      raeburn   463:     }
                    464:     $r->print($output);
                    465:     return;
                    466: }
                    467: 
                    468: sub build_query_string {
                    469:     my ($new_items) = @_;
                    470:     my $query_string;
                    471:     my @formelements = ('register'); 
1.47      albertel  472:     my $new = 0;
1.43      raeburn   473:     if (ref($new_items) eq 'HASH') {
1.47      albertel  474:         $new = 1;
1.43      raeburn   475:         if (!defined($new_items->{'forceedit'}) && 
                    476:             !defined($new_items->{'forcestudent'})) {
                    477:             push(@formelements,('forceedit','forcestudent'));
                    478:         }
                    479:     } else {
                    480:         push(@formelements,('forceedit','forcestudent'));
                    481:     }
                    482:     foreach my $element (@formelements) {
                    483:         if (exists($env{'form.'.$element})) {
1.47      albertel  484:             if ((!$new) || (!defined($new_items->{$element}))) {
1.43      raeburn   485:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
                    486:             }
                    487:         }
                    488:     }
1.47      albertel  489:     if ($new) {
1.43      raeburn   490:         foreach my $key (keys(%{$new_items})) {
                    491:             $query_string .= '&amp;'.$key.'='.$new_items->{$key};
                    492:         }
                    493:     }
                    494:     $query_string =~ s/^\&amp;/\?/;
                    495:     return $query_string;
                    496: }
                    497: 
                    498: sub display_portfolio_header {
1.55      raeburn   499:     my ($r,$is_course) = @_;
                    500:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.43      raeburn   501:     my $query_string = &build_query_string();
                    502:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    503:     my $forcestudent='';
                    504:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.55      raeburn   505: 
                    506:     my $output;
                    507:     if ($is_course) {
                    508:         $output = 
                    509:             &Apache::loncommon::start_page('Viewable group portfolio files',undef,
                    510:                                             {'function' => $forcestudent,
                    511:                                              'domain'   => $cdom,});
                    512:         $output .= '<h3>'.&mt('Group Portfolio files').'</h3>';
                    513:     } else {
                    514:         $output  =
                    515:             &Apache::loncommon::start_page('Viewable portfolio files',undef,
                    516:                                             {'function' => $forcestudent,
1.43      raeburn   517:                                              'domain'   => $cdom,});
1.55      raeburn   518:         if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
                    519:             &Apache::lonhtmlcommon::add_breadcrumb
                    520:                 ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
                    521:                   text=>"Personal information - $name",
                    522:                   title=>"Go to personal information page for $name"},                 {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
                    523:                   text=>"Viewable files - $name",
                    524:                   title=>"Viewable portfolio files for $name"}
                    525:             );
                    526:             $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
                    527:         }
                    528:         $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
1.53      raeburn   529:     }
1.43      raeburn   530:     $r->print($output);
                    531:     return;
                    532: }
                    533: 
                    534: sub display_portfolio_files {
1.55      raeburn   535:     my ($r,$is_course) = @_;
                    536:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.47      albertel  537:     my %lt = ( withoutpass => 'passphrase not required',
                    538: 	       withpass    => 'passphrase protected',
                    539: 	       both        => 'all access types ',);
                    540:     %lt = &Apache::lonlocal::texthash(%lt);
                    541: 
1.43      raeburn   542:     my $portaccess = 'withoutpass';
                    543:     if (exists($env{'form.portaccess'})) {
                    544:         $portaccess = $env{'form.portaccess'};
                    545:     }
1.47      albertel  546: 
1.45      albertel  547:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
                    548: 	.'" name="displaystatus" method="post">'.
                    549: 	&mt('File access type: ').'<select name="portaccess">';
1.43      raeburn   550:     foreach my $type ('withoutpass','withpass','both') {
                    551:         $output .= '<option value="'.$type.'" ';
                    552:         if ($portaccess eq $type) {
                    553:             $output .= 'selected="selected"';
                    554:         }
1.53      raeburn   555:         $output .= '>'.$lt{$type}.'</option>';
1.43      raeburn   556:     }
                    557:     $output .= '</select>'."\n".
                    558:                '<input type="submit" name="portaccessbutton" value="'.
1.47      albertel  559:                &mt('Update display').'" />';
1.43      raeburn   560:     $output .= '</form><br /><br />';
                    561:     $r->print($output);
1.64      raeburn   562:     my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
                    563:                                       $cdom,$cnum,$name);
1.53      raeburn   564:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
                    565:         my $query_string = &build_query_string();
                    566:         $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
1.55      raeburn   567:                   '/aboutme'.$query_string.'">');
                    568:         if ($is_course) {
                    569:             $r->print(&mt('Course Information page'));
                    570:         } else {
                    571:             $r->print(&mt('Information about [_1]',$name));
                    572:         }
                    573:         $r->print('</a>');
1.53      raeburn   574:     }
1.43      raeburn   575:     return;
                    576: }
                    577: 
                    578: sub portfolio_files {
1.64      raeburn   579:     my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
1.43      raeburn   580:     my $filecounts = {
                    581:                        withpass    => 0,
                    582:                        withoutpass => 0,
                    583:                        both        => 0,
                    584:                      };
                    585:     my $current_permissions =
1.44      albertel  586: 	&Apache::lonnet::get_portfile_permissions($cdom,$cnum);
1.43      raeburn   587:     my %access_controls = 
1.44      albertel  588: 	&Apache::lonnet::get_access_controls($current_permissions);
1.43      raeburn   589:     my $portaccess;
                    590:     if ($mode eq 'showlink') {
                    591:         $portaccess = 'both';
                    592:     } else {
                    593:         $portaccess = 'withoutpass';
                    594:         if (exists($env{'form.portaccess'})) {
                    595:             $portaccess = $env{'form.portaccess'};
                    596:         }
                    597:     }
                    598: 
1.55      raeburn   599:     my $diroutput;
                    600:     if ($is_course) {
                    601:         my %files_by_group;
                    602:         foreach my $filename (sort(keys(%access_controls))) {
                    603:             my ($group,$path) = split('/',$filename,2);
                    604:             $files_by_group{$group}{$path} = $access_controls{$filename}; 
                    605:         }
                    606:         foreach my $group (sort(keys(%files_by_group))) {
                    607:             my %fileshash;
                    608:             my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
                    609:                                            $is_course,$filecounts,$mode,
                    610:                                            $files_by_group{$group},
                    611:                                            \%fileshash,$group);
                    612:             if ($grpout) {
                    613:                 $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
                    614:             }
                    615:         }
                    616:     } else {
                    617:         my %allfileshash;
                    618:         $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
                    619:                                       $filecounts,$mode,\%access_controls,
                    620:                                       \%allfileshash);
                    621:     }
                    622:     if ($mode eq 'listfiles') {
                    623:         if ($filecounts->{'both'}) {
                    624:              $r->print($diroutput);
                    625:         } else {
                    626:             my $access_text;
                    627:             if (ref($lt) eq 'HASH') {
                    628:                 $access_text = $lt->{$portaccess};   
                    629:             }
                    630:             $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
                    631:         }
                    632:     }
                    633:     return $filecounts;
                    634: }
                    635: 
                    636: { 
                    637:     my $count=0;
                    638:     sub portfolio_table_start {
                    639: 	$count=0;
                    640: 	return '<table class="LC_aboutme_port">';
                    641:     }
                    642:     sub portfolio_row_start {
                    643: 	$count++;
                    644: 	my $class = ($count%2)?'LC_odd_row'
                    645: 	                      :'LC_even_row';
                    646: 	return '<tr class="'.$class.'">';
                    647:     }
                    648: }
                    649: 
                    650: sub build_hierarchy {
                    651:     my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
                    652:         $allfileshash,$group) = @_;
                    653:     foreach my $filename (sort(keys(%{$access_info}))) {
                    654:         my $access_status =
                    655:            &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group,                                                 $$access_info{$filename});
1.43      raeburn   656:         if ($portaccess eq 'both') {
                    657:             if (($access_status ne 'ok') &&
                    658:                 ($access_status !~  /^[^:]+:guest_/)) {
                    659:                 next;
                    660:             }
                    661:         } elsif ($portaccess eq 'withoutpass') {
                    662:             if ($access_status ne 'ok') {
                    663:                 next;
                    664:             }
                    665:         } elsif ($portaccess eq 'withpass') {
                    666:             if ($access_status !~  /^[^:]+:guest_/) {
                    667:                 next;
                    668:             }
                    669:         }
                    670:         if ($mode eq 'listfiles') {
                    671:             $filename =~ s/^\///;
                    672:             my @pathitems = split('/',$filename);
1.55      raeburn   673:             my $lasthash = $allfileshash;
1.43      raeburn   674:             while (@pathitems > 1) {
                    675:                 my $newlevel = shift(@pathitems);
                    676:                 if (!exists($lasthash->{$newlevel})) {
                    677:                     $lasthash->{$newlevel} = {};
                    678:                 }
                    679:                 $lasthash = $lasthash->{$newlevel};
                    680:             }
                    681:             $lasthash->{$pathitems[0]} = $filename;
                    682:         }
                    683:         if ($access_status eq 'ok') {
                    684:             $filecounts->{'withoutpass'} ++;
                    685:         } elsif ($access_status =~  /^[^:]+:guest_/) {
                    686:             $filecounts->{'withpass'} ++;
                    687:         }
                    688:     }
                    689:     $filecounts->{'both'} =  $filecounts->{'withoutpass'} +
                    690:                               $filecounts->{'withpass'};
1.55      raeburn   691:     my $output;
1.43      raeburn   692:     if ($mode eq 'listfiles') {
1.55      raeburn   693:         if ($filecounts->{'both'} > 0) {
1.45      albertel  694:             $output = &portfolio_table_start();
1.55      raeburn   695:             $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
                    696:                                         $group);
1.43      raeburn   697:             $output .= '</table>';
                    698:         }
1.45      albertel  699:     }
1.55      raeburn   700:     return $output;
1.45      albertel  701: }
                    702: 
1.43      raeburn   703: sub parse_directory {
1.55      raeburn   704:     my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
                    705:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.45      albertel  706:     $depth++;
                    707:     my $output;
1.49      albertel  708: 
1.55      raeburn   709:     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
                    710:                                                                 $group);
1.70      raeburn   711:     my $getpropath = 1;
1.49      albertel  712:     my %dirlist = map {
                    713: 	    ((split('&',$_,2))[0],1)
1.70      raeburn   714: 	} &Apache::lonnet::dirlist($portfolio_root.$path,$cdom,$cnum,$getpropath);
1.43      raeburn   715:     foreach my $item (sort(keys(%{$currhash}))) {
1.45      albertel  716:         $output .= &portfolio_row_start();
                    717:         $output .= '<td style="padding-left: '.($depth*25).'px">';
1.43      raeburn   718:         if (ref($currhash->{$item}) eq 'HASH') {
1.45      albertel  719:             my $title=&HTML::Entities::encode($item,'<>&"');
                    720:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" />&nbsp;'.$title;
1.47      albertel  721: 	    $output .= '</td><td></td></tr>';
1.49      albertel  722:             $output .= &parse_directory($r,$depth,$currhash->{$item},
1.55      raeburn   723: 					$path.'/'.$item,$is_course,$group);
1.43      raeburn   724:         } else {
1.50      albertel  725: 	    my $file_name; 
                    726: 	    if ($currhash->{$item} =~ m|/([^/]+)$|) {
                    727: 		$file_name = $1;
                    728: 	    } else {
                    729: 		$file_name = $currhash->{$item};
                    730: 	    }
                    731: 	    my $have_meta = exists($dirlist{$file_name.'.meta'});
1.55      raeburn   732:             my $url;
                    733:             if ($is_course) {
                    734:                 $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
                    735:                        '/portfolio/'.$currhash->{$item};
                    736:             } else { 
                    737: 	        $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
                    738: 		       $currhash->{$item};
                    739:             }
1.43      raeburn   740:             my $showname;
1.50      albertel  741: 	    if ($have_meta) {
                    742: 		$showname = &Apache::lonnet::metadata($url,'title');
                    743: 	    }
                    744: 	    if ($showname eq '') {
                    745: 		$showname = $file_name;
                    746: 	    } else {
                    747: 		$showname = $file_name.' ('.$showname.')';
                    748: 	    }
                    749: 
1.45      albertel  750:             $showname=&HTML::Entities::encode($showname,'<>&"');
1.49      albertel  751:             $output .= '<a href="'.$url.'">'.
                    752: 		'<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
                    753: 		'&nbsp;'.$showname.'</a>';
                    754: 	    $output.='</td><td>';
1.50      albertel  755: 	    if ($have_meta) {
1.49      albertel  756: 		$output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Catalog Information').'" src="'.
1.47      albertel  757: 		&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
1.49      albertel  758: 		'" class="LC_icon" /></a>';
                    759: 	    }
1.45      albertel  760: 	    $output .= '</td></tr>';
1.43      raeburn   761:         }
                    762:     }
1.45      albertel  763:     return $output;
1.43      raeburn   764: }
1.1       www       765: 
1.77      raeburn   766: sub aboutme_access {
                    767:     my ($uname,$udom) = @_;
                    768:     my $privcheck = $env{'request.course.id'};
                    769:     my $sec;
                    770:     if ($env{'request.course.sec'} ne '') {
                    771:         $sec = $env{'request.course.sec'};
                    772:         $privcheck .= '/'.$sec;
                    773:     }
                    774:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    775:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    776:     if (($cdom eq '') || ($cnum eq '')) {
                    777:         my %coursehash = &coursedescription($env{'request.course.id'});
                    778:         $cdom = $coursehash{'domain'};
                    779:         $cnum = $coursehash{'cnum'};
                    780:     }
                    781:     if ((&allowed('srm',$privcheck)) || (&allowed('dff',$privcheck))) {
                    782:         if (&in_course($uname,$udom,$cnum,$cdom)) {
                    783:             return 1;
                    784:         }
                    785:     }
                    786:     return;
                    787: }
                    788: 
1.1       www       789: 1;
                    790: __END__

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