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

1.1       www         1: # The LearningOnline Network
1.97      weissno     2: # Personal Information Page
1.1       www         3: #
1.99    ! neumanie    4: # $Id: lonaboutme.pm,v 1.98 2009/02/19 12:10:44 weissno 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);
                    345: 		if(&Apache::lonrss::advertisefeeds($cnum,$cdom) ne ''){
1.89      harmsja   346: 			$r->print('<div class="LC_ContentBoxSpecial">');
                    347: 			$r->print('<h4 class="LC_hcell">'.'RSS Feeds and Blogs'.'</h4>');
1.81      ehlerst   348: 			$r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom));
                    349: 			$r->print('</div>');
1.99    ! neumanie  350: 		}	
1.93      neumanie  351: 		
                    352:        }#End  Print RSS and portfiles
1.95      schualex  353: 
                    354:        $r->print('</blockquote>');
                    355:        $r->print('</div>');
1.23      sakharuk  356:        if ($allowed) {
1.69      raeburn   357:            if ($env{'form.popup'}) {
                    358:                $r->print('<input type="hidden" name="popup" value="'.
                    359:                          $env{'form.popup'}.'" />');
                    360:            }
1.2       www       361: 	   $r->print('</form>');
                    362:        }
1.46      albertel  363:        if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
1.2       www       364:     } else {
1.99    ! neumanie  365: 	# &Apache::lontemplate::send_message($r,$cnum,$cdom);
1.17      www       366:        $r->print('<p>'.&mt('No personal information provided').'.</p>');
1.8       www       367:     }
1.93      neumanie  368:     
1.43      raeburn   369: 
1.63      albertel  370:     if ($env{'request.course.id'}
                    371: 	&& &Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    372: 	&& &in_course($cdom,$cnum)) {
                    373: 	if ($target ne 'tex') {
                    374: 	    $r->print('<a name="coursecomment" />');
                    375: 	    $r->print('<hr /><h3>'.
                    376: 		      &mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'</h3>'.
                    377: 		      &mt('Shared by course faculty and staff').
                    378: 		      &Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message").
                    379: 		      '<br />');
                    380: 	    &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
                    381: 	    $r->print('<hr />');
                    382: 	    if (&Apache::lonnet::allowed('vsa',
                    383: 					 $env{'request.course.id'}) ||
                    384: 		&Apache::lonnet::allowed('vsa',
                    385: 					 $env{'request.course.id'}.'/'.
                    386: 					 $env{'request.course.sec'})) {
                    387: 		$r->print(&Apache::loncommon::track_student_link
                    388: 			  ('View recent activity by this student',
                    389: 			   $cnum,$cdom).('&nbsp;'x2));
1.22      sakharuk  390: 	    }
1.90      bisitz    391: 	    $r->print(&Apache::loncommon::noteswrapper(&mt('Add Records'),$cnum,$cdom));
1.63      albertel  392: 	} else {
                    393: 	    $r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
                    394: 	    &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
                    395: 	}
1.1       www       396:     }
1.40      albertel  397:     if ($target ne 'tex') {
1.69      raeburn   398:         if ($env{'form.popup'}) {
                    399:             $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a>');
                    400:         }
1.40      albertel  401: 	$r->print(&Apache::loncommon::end_page());
                    402:     } else {
                    403: 	$r->print('\end{document}');
                    404:     }
1.71      amueller  405: 
                    406:   
                    407: 	
1.1       www       408:     return OK;
1.43      raeburn   409: }
                    410: 
1.63      albertel  411: sub in_course {
                    412:     my ($udom,$uname,$cdom,$cnum,$type) = @_;
                    413:     $type ||= 'any';
                    414:     if (!defined($cdom) || !defined($cnum)) {
                    415: 	my $cid  = $env{'request.course.id'};
                    416: 	$cdom = $env{'course.'.$cid.'.domain'};
                    417: 	$cnum = $env{'course.'.$cid.'.num'};
                    418:     }
                    419:     my %roles = &Apache::lonnet::dump('roles',$udom,$uname);
                    420:     my @course_roles = grep(m{^/\Q$cdom\E/\Q$cnum\E[/_]}, keys(%roles));
                    421:     return 0 if (!@course_roles);
                    422:     return 1 if ($type eq 'any');
                    423:     my $now = time();
                    424:     foreach my $role (@course_roles) {
                    425: 	my (undef,$role_end,$role_start)=split(/\_/,$roles{$role});
                    426: 	my $status = 'active';
                    427: 	if ($role_start > 0 && $now < $role_start) {
                    428: 	    $status = 'future';
                    429: 	}
                    430: 	if ($role_end > 0 && $now > $role_end) {
                    431: 	    $status = 'previous';
                    432: 	}
                    433: 	return 1 if ($status eq $type);
                    434:     }
                    435:     return 0;
                    436: }
                    437: 
1.43      raeburn   438: sub aboutme_info {
1.55      raeburn   439:     my ($r,$is_course) = @_;
1.43      raeburn   440:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.55      raeburn   441:     my $name;
                    442:     if (!$is_course) {
                    443:         $name = &Apache::loncommon::plainname($cnum,$cdom);
                    444:     }
1.43      raeburn   445:     return ($cdom,$cnum,$name);
                    446: }
                    447: 
                    448: sub print_portfiles_link {
1.55      raeburn   449:     my ($r,$is_course) = @_;
                    450:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.64      raeburn   451:     my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
                    452:                                       $cdom,$cnum,$name);
1.47      albertel  453:     my $query_string = &build_query_string();
1.43      raeburn   454:     my $output;
1.55      raeburn   455:     my %lt = &Apache::lonlocal::texthash(
                    456:                          vpfi => 'Viewable portfolio files',
                    457:                          vgpf => 'Viewable group portfolio files',
                    458:                          difl => 'Display file listing',
                    459:              );                     
1.43      raeburn   460:     if ($filecounts->{'both'} > 0) {
1.89      harmsja   461: 	$output = '<div class="LC_ContentBoxSpecial"><h4 class="LC_hcell">';
1.76      harmsja   462: 	$output .= ($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
1.71      amueller  463:         
1.76      harmsja   464: 	#$output = '<h4>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
1.47      albertel  465:         $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
1.55      raeburn   466:                    $query_string.'">'.$lt{'difl'}.
1.43      raeburn   467:                    '</a><br /><br />';
1.53      raeburn   468:         if ($filecounts->{'both'} == 1) {
1.55      raeburn   469:             if ($is_course) {
                    470:                 $output .= &mt('One group portfolio file is available.').'<ul>';
                    471:             } else {
1.56      albertel  472:                 $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
1.55      raeburn   473:             }
1.53      raeburn   474:         } else {
1.55      raeburn   475:             if ($is_course) {
1.56      albertel  476:                 $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
1.55      raeburn   477:             } else {
                    478:                 $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
                    479:             }
1.53      raeburn   480:         }
1.43      raeburn   481:         if ($filecounts->{'withoutpass'}) {
1.54      albertel  482: 	    $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
1.43      raeburn   483:         }
                    484:         if ($filecounts->{'withpass'}) {
1.54      albertel  485: 	    $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
1.43      raeburn   486:         }
                    487:         $output .= '</ul>';
1.76      harmsja   488: 	$output .='</p>';
1.81      ehlerst   489: 	$output .='</div>';
1.43      raeburn   490:     }
                    491:     $r->print($output);
                    492:     return;
                    493: }
                    494: 
                    495: sub build_query_string {
                    496:     my ($new_items) = @_;
                    497:     my $query_string;
                    498:     my @formelements = ('register'); 
1.47      albertel  499:     my $new = 0;
1.43      raeburn   500:     if (ref($new_items) eq 'HASH') {
1.47      albertel  501:         $new = 1;
1.43      raeburn   502:         if (!defined($new_items->{'forceedit'}) && 
                    503:             !defined($new_items->{'forcestudent'})) {
                    504:             push(@formelements,('forceedit','forcestudent'));
                    505:         }
                    506:     } else {
                    507:         push(@formelements,('forceedit','forcestudent'));
                    508:     }
                    509:     foreach my $element (@formelements) {
                    510:         if (exists($env{'form.'.$element})) {
1.47      albertel  511:             if ((!$new) || (!defined($new_items->{$element}))) {
1.43      raeburn   512:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
                    513:             }
                    514:         }
                    515:     }
1.47      albertel  516:     if ($new) {
1.43      raeburn   517:         foreach my $key (keys(%{$new_items})) {
                    518:             $query_string .= '&amp;'.$key.'='.$new_items->{$key};
                    519:         }
                    520:     }
                    521:     $query_string =~ s/^\&amp;/\?/;
                    522:     return $query_string;
                    523: }
                    524: 
                    525: sub display_portfolio_header {
1.55      raeburn   526:     my ($r,$is_course) = @_;
                    527:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.43      raeburn   528:     my $query_string = &build_query_string();
                    529:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    530:     my $forcestudent='';
                    531:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.55      raeburn   532: 
                    533:     my $output;
                    534:     if ($is_course) {
                    535:         $output = 
                    536:             &Apache::loncommon::start_page('Viewable group portfolio files',undef,
                    537:                                             {'function' => $forcestudent,
                    538:                                              'domain'   => $cdom,});
                    539:         $output .= '<h3>'.&mt('Group Portfolio files').'</h3>';
                    540:     } else {
                    541:         $output  =
                    542:             &Apache::loncommon::start_page('Viewable portfolio files',undef,
                    543:                                             {'function' => $forcestudent,
1.43      raeburn   544:                                              'domain'   => $cdom,});
1.55      raeburn   545:         if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
                    546:             &Apache::lonhtmlcommon::add_breadcrumb
                    547:                 ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
1.97      weissno   548:                   text=>"Personal Information Page - $name",
                    549:                   title=>"Go to personal information page for $name"},                 {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
1.55      raeburn   550:                   text=>"Viewable files - $name",
                    551:                   title=>"Viewable portfolio files for $name"}
                    552:             );
                    553:             $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
                    554:         }
                    555:         $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
1.53      raeburn   556:     }
1.43      raeburn   557:     $r->print($output);
                    558:     return;
                    559: }
                    560: 
                    561: sub display_portfolio_files {
1.55      raeburn   562:     my ($r,$is_course) = @_;
                    563:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.47      albertel  564:     my %lt = ( withoutpass => 'passphrase not required',
                    565: 	       withpass    => 'passphrase protected',
                    566: 	       both        => 'all access types ',);
                    567:     %lt = &Apache::lonlocal::texthash(%lt);
                    568: 
1.43      raeburn   569:     my $portaccess = 'withoutpass';
                    570:     if (exists($env{'form.portaccess'})) {
                    571:         $portaccess = $env{'form.portaccess'};
                    572:     }
1.47      albertel  573: 
1.45      albertel  574:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
                    575: 	.'" name="displaystatus" method="post">'.
                    576: 	&mt('File access type: ').'<select name="portaccess">';
1.43      raeburn   577:     foreach my $type ('withoutpass','withpass','both') {
                    578:         $output .= '<option value="'.$type.'" ';
                    579:         if ($portaccess eq $type) {
                    580:             $output .= 'selected="selected"';
                    581:         }
1.53      raeburn   582:         $output .= '>'.$lt{$type}.'</option>';
1.43      raeburn   583:     }
                    584:     $output .= '</select>'."\n".
                    585:                '<input type="submit" name="portaccessbutton" value="'.
1.47      albertel  586:                &mt('Update display').'" />';
1.43      raeburn   587:     $output .= '</form><br /><br />';
                    588:     $r->print($output);
1.64      raeburn   589:     my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
                    590:                                       $cdom,$cnum,$name);
1.53      raeburn   591:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
                    592:         my $query_string = &build_query_string();
                    593:         $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
1.55      raeburn   594:                   '/aboutme'.$query_string.'">');
                    595:         if ($is_course) {
                    596:             $r->print(&mt('Course Information page'));
                    597:         } else {
                    598:             $r->print(&mt('Information about [_1]',$name));
                    599:         }
                    600:         $r->print('</a>');
1.53      raeburn   601:     }
1.43      raeburn   602:     return;
                    603: }
                    604: 
                    605: sub portfolio_files {
1.64      raeburn   606:     my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
1.43      raeburn   607:     my $filecounts = {
                    608:                        withpass    => 0,
                    609:                        withoutpass => 0,
                    610:                        both        => 0,
                    611:                      };
                    612:     my $current_permissions =
1.44      albertel  613: 	&Apache::lonnet::get_portfile_permissions($cdom,$cnum);
1.43      raeburn   614:     my %access_controls = 
1.44      albertel  615: 	&Apache::lonnet::get_access_controls($current_permissions);
1.43      raeburn   616:     my $portaccess;
                    617:     if ($mode eq 'showlink') {
                    618:         $portaccess = 'both';
                    619:     } else {
                    620:         $portaccess = 'withoutpass';
                    621:         if (exists($env{'form.portaccess'})) {
                    622:             $portaccess = $env{'form.portaccess'};
                    623:         }
                    624:     }
                    625: 
1.55      raeburn   626:     my $diroutput;
                    627:     if ($is_course) {
                    628:         my %files_by_group;
                    629:         foreach my $filename (sort(keys(%access_controls))) {
                    630:             my ($group,$path) = split('/',$filename,2);
                    631:             $files_by_group{$group}{$path} = $access_controls{$filename}; 
                    632:         }
                    633:         foreach my $group (sort(keys(%files_by_group))) {
                    634:             my %fileshash;
                    635:             my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
                    636:                                            $is_course,$filecounts,$mode,
                    637:                                            $files_by_group{$group},
                    638:                                            \%fileshash,$group);
                    639:             if ($grpout) {
                    640:                 $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
                    641:             }
                    642:         }
                    643:     } else {
                    644:         my %allfileshash;
                    645:         $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
                    646:                                       $filecounts,$mode,\%access_controls,
                    647:                                       \%allfileshash);
                    648:     }
                    649:     if ($mode eq 'listfiles') {
                    650:         if ($filecounts->{'both'}) {
                    651:              $r->print($diroutput);
                    652:         } else {
                    653:             my $access_text;
                    654:             if (ref($lt) eq 'HASH') {
                    655:                 $access_text = $lt->{$portaccess};   
                    656:             }
                    657:             $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
                    658:         }
                    659:     }
                    660:     return $filecounts;
                    661: }
                    662: 
                    663: { 
                    664:     my $count=0;
                    665:     sub portfolio_table_start {
                    666: 	$count=0;
                    667: 	return '<table class="LC_aboutme_port">';
                    668:     }
                    669:     sub portfolio_row_start {
                    670: 	$count++;
                    671: 	my $class = ($count%2)?'LC_odd_row'
                    672: 	                      :'LC_even_row';
                    673: 	return '<tr class="'.$class.'">';
                    674:     }
                    675: }
                    676: 
                    677: sub build_hierarchy {
                    678:     my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
                    679:         $allfileshash,$group) = @_;
                    680:     foreach my $filename (sort(keys(%{$access_info}))) {
                    681:         my $access_status =
                    682:            &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group,                                                 $$access_info{$filename});
1.43      raeburn   683:         if ($portaccess eq 'both') {
                    684:             if (($access_status ne 'ok') &&
                    685:                 ($access_status !~  /^[^:]+:guest_/)) {
                    686:                 next;
                    687:             }
                    688:         } elsif ($portaccess eq 'withoutpass') {
                    689:             if ($access_status ne 'ok') {
                    690:                 next;
                    691:             }
                    692:         } elsif ($portaccess eq 'withpass') {
                    693:             if ($access_status !~  /^[^:]+:guest_/) {
                    694:                 next;
                    695:             }
                    696:         }
                    697:         if ($mode eq 'listfiles') {
                    698:             $filename =~ s/^\///;
                    699:             my @pathitems = split('/',$filename);
1.55      raeburn   700:             my $lasthash = $allfileshash;
1.43      raeburn   701:             while (@pathitems > 1) {
                    702:                 my $newlevel = shift(@pathitems);
                    703:                 if (!exists($lasthash->{$newlevel})) {
                    704:                     $lasthash->{$newlevel} = {};
                    705:                 }
                    706:                 $lasthash = $lasthash->{$newlevel};
                    707:             }
                    708:             $lasthash->{$pathitems[0]} = $filename;
                    709:         }
                    710:         if ($access_status eq 'ok') {
                    711:             $filecounts->{'withoutpass'} ++;
                    712:         } elsif ($access_status =~  /^[^:]+:guest_/) {
                    713:             $filecounts->{'withpass'} ++;
                    714:         }
                    715:     }
                    716:     $filecounts->{'both'} =  $filecounts->{'withoutpass'} +
                    717:                               $filecounts->{'withpass'};
1.55      raeburn   718:     my $output;
1.43      raeburn   719:     if ($mode eq 'listfiles') {
1.55      raeburn   720:         if ($filecounts->{'both'} > 0) {
1.45      albertel  721:             $output = &portfolio_table_start();
1.55      raeburn   722:             $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
                    723:                                         $group);
1.43      raeburn   724:             $output .= '</table>';
                    725:         }
1.45      albertel  726:     }
1.55      raeburn   727:     return $output;
1.45      albertel  728: }
                    729: 
1.43      raeburn   730: sub parse_directory {
1.55      raeburn   731:     my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
                    732:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.45      albertel  733:     $depth++;
                    734:     my $output;
1.49      albertel  735: 
1.55      raeburn   736:     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
                    737:                                                                 $group);
1.70      raeburn   738:     my $getpropath = 1;
1.49      albertel  739:     my %dirlist = map {
                    740: 	    ((split('&',$_,2))[0],1)
1.70      raeburn   741: 	} &Apache::lonnet::dirlist($portfolio_root.$path,$cdom,$cnum,$getpropath);
1.43      raeburn   742:     foreach my $item (sort(keys(%{$currhash}))) {
1.45      albertel  743:         $output .= &portfolio_row_start();
                    744:         $output .= '<td style="padding-left: '.($depth*25).'px">';
1.43      raeburn   745:         if (ref($currhash->{$item}) eq 'HASH') {
1.45      albertel  746:             my $title=&HTML::Entities::encode($item,'<>&"');
                    747:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" />&nbsp;'.$title;
1.47      albertel  748: 	    $output .= '</td><td></td></tr>';
1.49      albertel  749:             $output .= &parse_directory($r,$depth,$currhash->{$item},
1.55      raeburn   750: 					$path.'/'.$item,$is_course,$group);
1.43      raeburn   751:         } else {
1.50      albertel  752: 	    my $file_name; 
                    753: 	    if ($currhash->{$item} =~ m|/([^/]+)$|) {
                    754: 		$file_name = $1;
                    755: 	    } else {
                    756: 		$file_name = $currhash->{$item};
                    757: 	    }
                    758: 	    my $have_meta = exists($dirlist{$file_name.'.meta'});
1.55      raeburn   759:             my $url;
                    760:             if ($is_course) {
                    761:                 $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
                    762:                        '/portfolio/'.$currhash->{$item};
                    763:             } else { 
                    764: 	        $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
                    765: 		       $currhash->{$item};
                    766:             }
1.43      raeburn   767:             my $showname;
1.50      albertel  768: 	    if ($have_meta) {
                    769: 		$showname = &Apache::lonnet::metadata($url,'title');
                    770: 	    }
                    771: 	    if ($showname eq '') {
                    772: 		$showname = $file_name;
                    773: 	    } else {
                    774: 		$showname = $file_name.' ('.$showname.')';
                    775: 	    }
                    776: 
1.45      albertel  777:             $showname=&HTML::Entities::encode($showname,'<>&"');
1.49      albertel  778:             $output .= '<a href="'.$url.'">'.
                    779: 		'<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
                    780: 		'&nbsp;'.$showname.'</a>';
                    781: 	    $output.='</td><td>';
1.50      albertel  782: 	    if ($have_meta) {
1.92      schafran  783: 		$output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Metadata').'" src="'.
1.47      albertel  784: 		&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
1.49      albertel  785: 		'" class="LC_icon" /></a>';
                    786: 	    }
1.45      albertel  787: 	    $output .= '</td></tr>';
1.43      raeburn   788:         }
                    789:     }
1.45      albertel  790:     return $output;
1.43      raeburn   791: }
1.1       www       792: 
1.77      raeburn   793: sub aboutme_access {
                    794:     my ($uname,$udom) = @_;
                    795:     my $privcheck = $env{'request.course.id'};
                    796:     my $sec;
                    797:     if ($env{'request.course.sec'} ne '') {
                    798:         $sec = $env{'request.course.sec'};
                    799:         $privcheck .= '/'.$sec;
                    800:     }
                    801:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    802:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    803:     if (($cdom eq '') || ($cnum eq '')) {
                    804:         my %coursehash = &coursedescription($env{'request.course.id'});
                    805:         $cdom = $coursehash{'domain'};
                    806:         $cnum = $coursehash{'cnum'};
                    807:     }
1.84      raeburn   808:     if ((&Apache::lonnet::allowed('srm',$privcheck)) || 
                    809:         (&Apache::lonnet::allowed('dff',$privcheck))) {
1.77      raeburn   810:         if (&in_course($uname,$udom,$cnum,$cdom)) {
                    811:             return 1;
                    812:         }
                    813:     }
                    814:     return;
                    815: }
                    816: 
1.1       www       817: 1;
                    818: __END__

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