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

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

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