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

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

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