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

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

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