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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # "About Me" Personal Information
1.1       www         3: #
1.68    ! raeburn     4: # $Id: lonaboutme.pm,v 1.67 2008/01/16 12:24:01 bisitz Exp $
1.1       www         5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: 
                     29: package Apache::lonaboutme;
                     30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common);
                     33: use Apache::loncommon;
                     34: use Apache::lonnet;
1.2       www        35: use Apache::lontexconvert;
1.12      www        36: use Apache::lonfeedback;
1.39      www        37: use Apache::lonrss();
1.17      www        38: use Apache::lonlocal;
1.41      albertel   39: use Apache::lonmsgdisplay();
1.52      albertel   40: use HTML::Entities();
1.1       www        41: 
                     42: sub handler {
                     43:     my $r = shift;
1.17      www        44:     &Apache::loncommon::content_type($r,'text/html');
1.1       www        45:     $r->send_http_header;
                     46:     return OK if $r->header_only;
1.37      albertel   47:     my $target=$env{'form.grade_target'};
1.1       www        48: # ------------------------------------------------------------ Print the screen
1.40      albertel   49:     if ($target eq 'tex') {
1.37      albertel   50: 	$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.22      sakharuk   51:     }
1.47      albertel   52:     my (undef,undef,$cdom,$cnum,undef,$action)=split(/\//,$r->uri);
1.55      raeburn    53:     my $is_course;
1.2       www        54: # Is this even a user?
                     55:     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
1.40      albertel   56: 	&Apache::loncommon::simple_error_page($r,'No info',
                     57: 					      'No user information available');
1.2       www        58:         return OK;
1.55      raeburn    59:     } else {
1.59      raeburn    60:         $is_course = &Apache::lonnet::is_course($cdom,$cnum);
1.2       www        61:     }
1.55      raeburn    62: 
1.2       www        63: # --------------------------------------------------------- The syllabus fields
1.17      www        64:     my %syllabusfields=&Apache::lonlocal::texthash(
1.3       www        65:        'aaa_contactinfo'   => 'Contact Information',
                     66:        'bbb_aboutme'       => 'About Me',
                     67:        'ccc_webreferences' => 'Web References');
1.2       www        68: 
1.13      www        69: # ------------------------------------------------------------ Get Query String
1.47      albertel   70:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                     71: 					    ['forceedit','forcestudent',
                     72: 					     'register']);
1.43      raeburn    73: 
                     74: # ----------------------------------------------- Available Portfolio file display 
1.47      albertel   75:     if (($target ne 'tex') && ($action eq 'portfolio')) {
1.55      raeburn    76:         &display_portfolio_header($r,$is_course);
1.60      raeburn    77:         my ($blocked,$blocktext) = 
                     78:            &Apache::loncommon::blocking_status('port',$cnum,$cdom);
                     79:         if (!$blocked) {
                     80:             &display_portfolio_files($r,$is_course);
                     81:         } else {
                     82:             $r->print($blocktext);
                     83:         }
1.43      raeburn    84:         $r->print(&Apache::loncommon::end_page());
                     85:         return OK;
                     86:     }
                     87: 
1.55      raeburn    88:     if ($is_course) {
                     89:         if ($target ne 'tex') {
                     90:             my $start_page =
                     91:                 &Apache::loncommon::start_page(
                     92:                     "Course Information",
                     93:                      undef,
                     94:                      {'function' => $env{'forcestudent'},
                     95:                       'domain'   => $cdom,
                     96:                       'force_register' => $env{'forceregister'},});
                     97:             $r->print($start_page);
                     98:             $r->print('<h2>'.&mt('Group files').'</h2>');
                     99:             &print_portfiles_link($r,$is_course);
                    100:             $r->print(&Apache::loncommon::end_page());
                    101:         }
                    102:         return OK;
                    103:     }
                    104: 
1.2       www       105: # --------------------------------------------------------------- Force Student
                    106:     my $forcestudent='';
1.37      albertel  107:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.43      raeburn   108: 
                    109:     my $forceregister = '';
                    110:     if ($forcestudent eq '') {
                    111:         $forceregister = $env{'form.register'};
                    112:     }
1.2       www       113:        
                    114: # --------------------------------------- There is such a user, get environment
                    115:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.22      sakharuk  116:     if ($target ne 'tex') {
1.65      albertel  117: 	my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
1.40      albertel  118: 	my $start_page = 
1.65      albertel  119: 	    &Apache::loncommon::start_page("Personal Information", $rss_link,
1.40      albertel  120: 					   {'function'       => $forcestudent,
1.47      albertel  121:  					    'domain'         => $cdom,
1.40      albertel  122: 					    'force_register' =>
1.43      raeburn   123: 						            $forceregister,});
1.40      albertel  124: 	$r->print($start_page);
1.22      sakharuk  125: 	$r->print('<h1>'.&Apache::loncommon::plainname($cnum,$cdom).'</h1>');
                    126:     } else {
                    127: 	$r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
                    128:     }
1.6       www       129:     if ($courseenv{'nickname'}) {
                    130:        $r->print(
1.7       albertel  131:          '<h2>&quot;'.$courseenv{'nickname'}.
1.6       www       132:          '&quot;</h2>');
                    133:     }
1.22      sakharuk  134:     if ($target ne 'tex') {
1.61      albertel  135: 	$r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>'.
1.66      bisitz    136: 		  '<p>'.&Apache::loncommon::messagewrapper(&mt('Send me a message'),$cnum,$cdom).'</p>'.&Apache::lonrss::advertisefeeds($cnum,$cdom));
1.22      sakharuk  137:     } else {
1.61      albertel  138: 	$r->print('\textbf{'.&Apache::lonnet::domain($cdom,'description').'}\\\\');
1.22      sakharuk  139:     }
1.2       www       140:     my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
                    141:     my $allowed=0;
                    142: 
1.1       www       143: # does this user have privileges to post, etc?
1.2       www       144: 
1.37      albertel  145:        my $privleged=$allowed=(($env{'user.name'} eq $cnum) && 
                    146: 			       ($env{'user.domain'} eq $cdom));
1.23      sakharuk  147:        if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.2       www       148:  
                    149:        if ($allowed) {
1.43      raeburn   150:            my $query_string = &build_query_string({'forcestudent' => '1',});
1.32      albertel  151: 	   $r->print('<p><b>'.&mt('Privacy Note').':</b> '.
                    152: 		     &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.').
                    153: 		     '</p>'.
1.67      bisitz    154: 		     &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).'</p><p><a href="'.$r->uri.$query_string.'">'.&mt('Show Public View').'</a>'.
1.32      albertel  155: 		     &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
                    156:        } elsif ($privleged && $target ne 'tex') {
1.43      raeburn   157:            my $query_string = &build_query_string({'forceedit' => '1',});
                    158: 	   $r->print('<p><a href="'.$r->uri.$query_string.'"><font size="+1">'.
1.32      albertel  159: 		     &mt('Edit').'</font></a></p>');
                    160:        }
1.37      albertel  161:       if (($env{'form.uploaddoc.filename'}) &&
                    162:           ($env{'form.storeupl'}) && ($allowed)) {
                    163:  	  if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
1.24      albertel  164: 	      if ($syllabus{'uploaded.photourl'}) {
                    165: 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
                    166: 	      }
                    167: 	      $syllabus{'uploaded.photourl'}=
                    168:                  &Apache::lonnet::userfileupload('uploaddoc',undef,'aboutme');
1.3       www       169:  	  }
                    170:           $syllabus{'uploaded.lastmodified'}=time;
                    171:           &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
                    172:        }
1.37      albertel  173:     if ($allowed && $env{'form.delupl'}) {
1.32      albertel  174: 	if ($syllabus{'uploaded.photourl'}) {
                    175: 	    &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
                    176: 	    delete($syllabus{'uploaded.photourl'});
                    177: 	    &Apache::lonnet::del('aboutme',['uploaded.photourl'],$cdom,$cnum);
                    178: 	}
                    179:     }
1.37      albertel  180:        if (($allowed) && ($env{'form.storesyl'})) {
1.57      albertel  181: 	   foreach my $syl_field (keys(%syllabusfields)) {
                    182:                my $field=$env{'form.'.$syl_field};
1.2       www       183:                $field=~s/\s+$//s;
1.11      www       184:                $field=&Apache::lonfeedback::clear_out_html($field,
1.37      albertel  185:                                                            $env{'user.adv'});
1.57      albertel  186: 	       $syllabus{$syl_field}=$field;
1.2       www       187:            }
                    188:            $syllabus{'uploaded.lastmodified'}=time;
                    189:            &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
                    190:        }
                    191: 
                    192: # ---------------------------------------------------------------- Get syllabus
                    193:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.5       www       194:        my $lastmod=$syllabus{'uploaded.lastmodified'};
1.18      www       195:        $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
                    196:        $r->print(&mt('Last updated').': '.$lastmod);
1.3       www       197:        if ($syllabus{'uploaded.photourl'}) {
1.24      albertel  198: 	   &Apache::lonnet::allowuploaded('/adm/aboutme',
                    199: 					  $syllabus{'uploaded.photourl'});
1.33      matthew   200: 	   my $image=
                    201:                qq{<img src="$syllabus{'uploaded.photourl'}" align="right" />};
1.27      albertel  202: 	   if ($target eq 'tex') {
                    203: 	       $image=&Apache::lonxml::xmlparse($r,'tex',$image);
1.26      sakharuk  204: 	   }
1.27      albertel  205: 	   $r->print($image);
1.3       www       206:        }
1.23      sakharuk  207:        if ($allowed) {
1.3       www       208:            $r->print(
1.32      albertel  209: 	 '<form method="post">
1.66      bisitz    210:                <input type="submit" name="delupl" value="'.&mt('Delete Photo').'" />
1.32      albertel  211:           </form>'.
1.3       www       212: 	 '<form method="post" enctype="multipart/form-data">'.
1.18      www       213:          '<h3>'.&mt('Upload a Photo').'</h3>'.
1.68    ! raeburn   214:          '<input type="file" name="uploaddoc" size="50" />'.
        !           215:          '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />'.
1.3       www       216: 	 '</form><form method="post">');
1.32      albertel  217: 
1.2       www       218:        }
1.57      albertel  219:        foreach my $field (sort(keys(%syllabusfields))) {
                    220:           if (($syllabus{$field}) || ($allowed)) {
                    221:               my $message=$syllabus{$field};
1.38      albertel  222: 	      &Apache::lonfeedback::newline_to_br(\$message);
1.2       www       223:               $message
                    224:              =~s/(http\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.29      www       225: 	      if ($allowed) {
                    226: 		  $message=&Apache::lonspeller::markeduptext($message);
                    227: 	      }
1.2       www       228: 	      $message=&Apache::lontexconvert::msgtexconverted($message);
1.22      sakharuk  229: 	      if ($target ne 'tex') {
1.57      albertel  230: 		  $r->print('<h3>'.$syllabusfields{$field}.'</h3><blockquote>'.
1.22      sakharuk  231:                             $message.'</blockquote>');
                    232: 	      } else {
1.57      albertel  233: 		     $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
1.25      sakharuk  234: 			       &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
1.22      sakharuk  235: 	      }
1.23      sakharuk  236:               if ($allowed) {
1.57      albertel  237:                  $r->print('<br /><textarea cols="80" rows="6" name="'.$field.'">'.
                    238: 			   &HTML::Entities::encode($syllabus{$field},'"&<>').
1.17      www       239:            '</textarea><input type="submit" name="storesyl" value="'.
1.62      albertel  240: 			   &mt('Save').'" />');
1.2       www       241: 	      }
                    242: 	  }
                    243:        }
1.23      sakharuk  244:        if ($allowed) {
1.2       www       245: 	   $r->print('</form>');
                    246:        }
1.46      albertel  247:        if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
1.2       www       248:     } else {
1.17      www       249:        $r->print('<p>'.&mt('No personal information provided').'.</p>');
1.8       www       250:     }
1.43      raeburn   251: 
                    252:     if ($target ne 'tex') {
1.55      raeburn   253:         &print_portfiles_link($r,$is_course);
1.43      raeburn   254:     }
                    255: 
1.63      albertel  256:     if ($env{'request.course.id'}
                    257: 	&& &Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    258: 	&& &in_course($cdom,$cnum)) {
                    259: 	if ($target ne 'tex') {
                    260: 	    $r->print('<a name="coursecomment" />');
                    261: 	    $r->print('<hr /><h3>'.
                    262: 		      &mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'</h3>'.
                    263: 		      &mt('Shared by course faculty and staff').
                    264: 		      &Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message").
                    265: 		      '<br />');
                    266: 	    &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
                    267: 	    $r->print('<hr />');
                    268: 	    if (&Apache::lonnet::allowed('vsa',
                    269: 					 $env{'request.course.id'}) ||
                    270: 		&Apache::lonnet::allowed('vsa',
                    271: 					 $env{'request.course.id'}.'/'.
                    272: 					 $env{'request.course.sec'})) {
                    273: 		$r->print(&Apache::loncommon::track_student_link
                    274: 			  ('View recent activity by this student',
                    275: 			   $cnum,$cdom).('&nbsp;'x2));
1.22      sakharuk  276: 	    }
1.63      albertel  277: 	    $r->print(&Apache::loncommon::noteswrapper('Add Records',$cnum,$cdom));
                    278: 	} else {
                    279: 	    $r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
                    280: 	    &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
                    281: 	}
1.1       www       282:     }
1.40      albertel  283:     if ($target ne 'tex') {
                    284: 	$r->print(&Apache::loncommon::end_page());
                    285:     } else {
                    286: 	$r->print('\end{document}');
                    287:     }
1.1       www       288:     return OK;
1.43      raeburn   289: }
                    290: 
1.63      albertel  291: sub in_course {
                    292:     my ($udom,$uname,$cdom,$cnum,$type) = @_;
                    293:     $type ||= 'any';
                    294:     if (!defined($cdom) || !defined($cnum)) {
                    295: 	my $cid  = $env{'request.course.id'};
                    296: 	$cdom = $env{'course.'.$cid.'.domain'};
                    297: 	$cnum = $env{'course.'.$cid.'.num'};
                    298:     }
                    299:     my %roles = &Apache::lonnet::dump('roles',$udom,$uname);
                    300:     my @course_roles = grep(m{^/\Q$cdom\E/\Q$cnum\E[/_]}, keys(%roles));
                    301:     return 0 if (!@course_roles);
                    302:     return 1 if ($type eq 'any');
                    303:     my $now = time();
                    304:     foreach my $role (@course_roles) {
                    305: 	my (undef,$role_end,$role_start)=split(/\_/,$roles{$role});
                    306: 	my $status = 'active';
                    307: 	if ($role_start > 0 && $now < $role_start) {
                    308: 	    $status = 'future';
                    309: 	}
                    310: 	if ($role_end > 0 && $now > $role_end) {
                    311: 	    $status = 'previous';
                    312: 	}
                    313: 	return 1 if ($status eq $type);
                    314:     }
                    315:     return 0;
                    316: }
                    317: 
1.43      raeburn   318: sub aboutme_info {
1.55      raeburn   319:     my ($r,$is_course) = @_;
1.43      raeburn   320:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.55      raeburn   321:     my $name;
                    322:     if (!$is_course) {
                    323:         $name = &Apache::loncommon::plainname($cnum,$cdom);
                    324:     }
1.43      raeburn   325:     return ($cdom,$cnum,$name);
                    326: }
                    327: 
                    328: sub print_portfiles_link {
1.55      raeburn   329:     my ($r,$is_course) = @_;
                    330:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.64      raeburn   331:     my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
                    332:                                       $cdom,$cnum,$name);
1.47      albertel  333:     my $query_string = &build_query_string();
1.43      raeburn   334:     my $output;
1.55      raeburn   335:     my %lt = &Apache::lonlocal::texthash(
                    336:                          vpfi => 'Viewable portfolio files',
                    337:                          vgpf => 'Viewable group portfolio files',
                    338:                          difl => 'Display file listing',
                    339:              );                     
1.43      raeburn   340:     if ($filecounts->{'both'} > 0) {
1.55      raeburn   341:         $output = '<h3>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h3>';
1.47      albertel  342:         $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
1.55      raeburn   343:                    $query_string.'">'.$lt{'difl'}.
1.43      raeburn   344:                    '</a><br /><br />';
1.53      raeburn   345:         if ($filecounts->{'both'} == 1) {
1.55      raeburn   346:             if ($is_course) {
                    347:                 $output .= &mt('One group portfolio file is available.').'<ul>';
                    348:             } else {
1.56      albertel  349:                 $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
1.55      raeburn   350:             }
1.53      raeburn   351:         } else {
1.55      raeburn   352:             if ($is_course) {
1.56      albertel  353:                 $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
1.55      raeburn   354:             } else {
                    355:                 $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
                    356:             }
1.53      raeburn   357:         }
1.43      raeburn   358:         if ($filecounts->{'withoutpass'}) {
1.54      albertel  359: 	    $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
1.43      raeburn   360:         }
                    361:         if ($filecounts->{'withpass'}) {
1.54      albertel  362: 	    $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
1.43      raeburn   363:         }
                    364:         $output .= '</ul>';
                    365:     }
                    366:     $r->print($output);
                    367:     return;
                    368: }
                    369: 
                    370: sub build_query_string {
                    371:     my ($new_items) = @_;
                    372:     my $query_string;
                    373:     my @formelements = ('register'); 
1.47      albertel  374:     my $new = 0;
1.43      raeburn   375:     if (ref($new_items) eq 'HASH') {
1.47      albertel  376:         $new = 1;
1.43      raeburn   377:         if (!defined($new_items->{'forceedit'}) && 
                    378:             !defined($new_items->{'forcestudent'})) {
                    379:             push(@formelements,('forceedit','forcestudent'));
                    380:         }
                    381:     } else {
                    382:         push(@formelements,('forceedit','forcestudent'));
                    383:     }
                    384:     foreach my $element (@formelements) {
                    385:         if (exists($env{'form.'.$element})) {
1.47      albertel  386:             if ((!$new) || (!defined($new_items->{$element}))) {
1.43      raeburn   387:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
                    388:             }
                    389:         }
                    390:     }
1.47      albertel  391:     if ($new) {
1.43      raeburn   392:         foreach my $key (keys(%{$new_items})) {
                    393:             $query_string .= '&amp;'.$key.'='.$new_items->{$key};
                    394:         }
                    395:     }
                    396:     $query_string =~ s/^\&amp;/\?/;
                    397:     return $query_string;
                    398: }
                    399: 
                    400: sub display_portfolio_header {
1.55      raeburn   401:     my ($r,$is_course) = @_;
                    402:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.43      raeburn   403:     my $query_string = &build_query_string();
                    404:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    405:     my $forcestudent='';
                    406:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.55      raeburn   407: 
                    408:     my $output;
                    409:     if ($is_course) {
                    410:         $output = 
                    411:             &Apache::loncommon::start_page('Viewable group portfolio files',undef,
                    412:                                             {'function' => $forcestudent,
                    413:                                              'domain'   => $cdom,});
                    414:         $output .= '<h3>'.&mt('Group Portfolio files').'</h3>';
                    415:     } else {
                    416:         $output  =
                    417:             &Apache::loncommon::start_page('Viewable portfolio files',undef,
                    418:                                             {'function' => $forcestudent,
1.43      raeburn   419:                                              'domain'   => $cdom,});
1.55      raeburn   420:         if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
                    421:             &Apache::lonhtmlcommon::add_breadcrumb
                    422:                 ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
                    423:                   text=>"Personal information - $name",
                    424:                   title=>"Go to personal information page for $name"},                 {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
                    425:                   text=>"Viewable files - $name",
                    426:                   title=>"Viewable portfolio files for $name"}
                    427:             );
                    428:             $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
                    429:         }
                    430:         $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
1.53      raeburn   431:     }
1.43      raeburn   432:     $r->print($output);
                    433:     return;
                    434: }
                    435: 
                    436: sub display_portfolio_files {
1.55      raeburn   437:     my ($r,$is_course) = @_;
                    438:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.47      albertel  439:     my %lt = ( withoutpass => 'passphrase not required',
                    440: 	       withpass    => 'passphrase protected',
                    441: 	       both        => 'all access types ',);
                    442:     %lt = &Apache::lonlocal::texthash(%lt);
                    443: 
1.43      raeburn   444:     my $portaccess = 'withoutpass';
                    445:     if (exists($env{'form.portaccess'})) {
                    446:         $portaccess = $env{'form.portaccess'};
                    447:     }
1.47      albertel  448: 
1.45      albertel  449:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
                    450: 	.'" name="displaystatus" method="post">'.
                    451: 	&mt('File access type: ').'<select name="portaccess">';
1.43      raeburn   452:     foreach my $type ('withoutpass','withpass','both') {
                    453:         $output .= '<option value="'.$type.'" ';
                    454:         if ($portaccess eq $type) {
                    455:             $output .= 'selected="selected"';
                    456:         }
1.53      raeburn   457:         $output .= '>'.$lt{$type}.'</option>';
1.43      raeburn   458:     }
                    459:     $output .= '</select>'."\n".
                    460:                '<input type="submit" name="portaccessbutton" value="'.
1.47      albertel  461:                &mt('Update display').'" />';
1.43      raeburn   462:     $output .= '</form><br /><br />';
                    463:     $r->print($output);
1.64      raeburn   464:     my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
                    465:                                       $cdom,$cnum,$name);
1.53      raeburn   466:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
                    467:         my $query_string = &build_query_string();
                    468:         $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
1.55      raeburn   469:                   '/aboutme'.$query_string.'">');
                    470:         if ($is_course) {
                    471:             $r->print(&mt('Course Information page'));
                    472:         } else {
                    473:             $r->print(&mt('Information about [_1]',$name));
                    474:         }
                    475:         $r->print('</a>');
1.53      raeburn   476:     }
1.43      raeburn   477:     return;
                    478: }
                    479: 
                    480: sub portfolio_files {
1.64      raeburn   481:     my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
1.43      raeburn   482:     my $filecounts = {
                    483:                        withpass    => 0,
                    484:                        withoutpass => 0,
                    485:                        both        => 0,
                    486:                      };
                    487:     my $current_permissions =
1.44      albertel  488: 	&Apache::lonnet::get_portfile_permissions($cdom,$cnum);
1.43      raeburn   489:     my %access_controls = 
1.44      albertel  490: 	&Apache::lonnet::get_access_controls($current_permissions);
1.43      raeburn   491:     my $portaccess;
                    492:     if ($mode eq 'showlink') {
                    493:         $portaccess = 'both';
                    494:     } else {
                    495:         $portaccess = 'withoutpass';
                    496:         if (exists($env{'form.portaccess'})) {
                    497:             $portaccess = $env{'form.portaccess'};
                    498:         }
                    499:     }
                    500: 
1.55      raeburn   501:     my $diroutput;
                    502:     if ($is_course) {
                    503:         my %files_by_group;
                    504:         foreach my $filename (sort(keys(%access_controls))) {
                    505:             my ($group,$path) = split('/',$filename,2);
                    506:             $files_by_group{$group}{$path} = $access_controls{$filename}; 
                    507:         }
                    508:         foreach my $group (sort(keys(%files_by_group))) {
                    509:             my %fileshash;
                    510:             my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
                    511:                                            $is_course,$filecounts,$mode,
                    512:                                            $files_by_group{$group},
                    513:                                            \%fileshash,$group);
                    514:             if ($grpout) {
                    515:                 $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
                    516:             }
                    517:         }
                    518:     } else {
                    519:         my %allfileshash;
                    520:         $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
                    521:                                       $filecounts,$mode,\%access_controls,
                    522:                                       \%allfileshash);
                    523:     }
                    524:     if ($mode eq 'listfiles') {
                    525:         if ($filecounts->{'both'}) {
                    526:              $r->print($diroutput);
                    527:         } else {
                    528:             my $access_text;
                    529:             if (ref($lt) eq 'HASH') {
                    530:                 $access_text = $lt->{$portaccess};   
                    531:             }
                    532:             $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
                    533:         }
                    534:     }
                    535:     return $filecounts;
                    536: }
                    537: 
                    538: { 
                    539:     my $count=0;
                    540:     sub portfolio_table_start {
                    541: 	$count=0;
                    542: 	return '<table class="LC_aboutme_port">';
                    543:     }
                    544:     sub portfolio_row_start {
                    545: 	$count++;
                    546: 	my $class = ($count%2)?'LC_odd_row'
                    547: 	                      :'LC_even_row';
                    548: 	return '<tr class="'.$class.'">';
                    549:     }
                    550: }
                    551: 
                    552: sub build_hierarchy {
                    553:     my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
                    554:         $allfileshash,$group) = @_;
                    555:     foreach my $filename (sort(keys(%{$access_info}))) {
                    556:         my $access_status =
                    557:            &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group,                                                 $$access_info{$filename});
1.43      raeburn   558:         if ($portaccess eq 'both') {
                    559:             if (($access_status ne 'ok') &&
                    560:                 ($access_status !~  /^[^:]+:guest_/)) {
                    561:                 next;
                    562:             }
                    563:         } elsif ($portaccess eq 'withoutpass') {
                    564:             if ($access_status ne 'ok') {
                    565:                 next;
                    566:             }
                    567:         } elsif ($portaccess eq 'withpass') {
                    568:             if ($access_status !~  /^[^:]+:guest_/) {
                    569:                 next;
                    570:             }
                    571:         }
                    572:         if ($mode eq 'listfiles') {
                    573:             $filename =~ s/^\///;
                    574:             my @pathitems = split('/',$filename);
1.55      raeburn   575:             my $lasthash = $allfileshash;
1.43      raeburn   576:             while (@pathitems > 1) {
                    577:                 my $newlevel = shift(@pathitems);
                    578:                 if (!exists($lasthash->{$newlevel})) {
                    579:                     $lasthash->{$newlevel} = {};
                    580:                 }
                    581:                 $lasthash = $lasthash->{$newlevel};
                    582:             }
                    583:             $lasthash->{$pathitems[0]} = $filename;
                    584:         }
                    585:         if ($access_status eq 'ok') {
                    586:             $filecounts->{'withoutpass'} ++;
                    587:         } elsif ($access_status =~  /^[^:]+:guest_/) {
                    588:             $filecounts->{'withpass'} ++;
                    589:         }
                    590:     }
                    591:     $filecounts->{'both'} =  $filecounts->{'withoutpass'} +
                    592:                               $filecounts->{'withpass'};
1.55      raeburn   593:     my $output;
1.43      raeburn   594:     if ($mode eq 'listfiles') {
1.55      raeburn   595:         if ($filecounts->{'both'} > 0) {
1.45      albertel  596:             $output = &portfolio_table_start();
1.55      raeburn   597:             $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
                    598:                                         $group);
1.43      raeburn   599:             $output .= '</table>';
                    600:         }
1.45      albertel  601:     }
1.55      raeburn   602:     return $output;
1.45      albertel  603: }
                    604: 
1.43      raeburn   605: sub parse_directory {
1.55      raeburn   606:     my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
                    607:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.45      albertel  608:     $depth++;
                    609:     my $output;
1.49      albertel  610: 
1.55      raeburn   611:     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
                    612:                                                                 $group);
1.49      albertel  613:     my %dirlist = map {
                    614: 	    ((split('&',$_,2))[0],1)
                    615: 	} &Apache::lonnet::dirlist($path,$cdom,$cnum,$portfolio_root);
1.43      raeburn   616:     foreach my $item (sort(keys(%{$currhash}))) {
1.45      albertel  617:         $output .= &portfolio_row_start();
                    618:         $output .= '<td style="padding-left: '.($depth*25).'px">';
1.43      raeburn   619:         if (ref($currhash->{$item}) eq 'HASH') {
1.45      albertel  620:             my $title=&HTML::Entities::encode($item,'<>&"');
                    621:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" />&nbsp;'.$title;
1.47      albertel  622: 	    $output .= '</td><td></td></tr>';
1.49      albertel  623:             $output .= &parse_directory($r,$depth,$currhash->{$item},
1.55      raeburn   624: 					$path.'/'.$item,$is_course,$group);
1.43      raeburn   625:         } else {
1.50      albertel  626: 	    my $file_name; 
                    627: 	    if ($currhash->{$item} =~ m|/([^/]+)$|) {
                    628: 		$file_name = $1;
                    629: 	    } else {
                    630: 		$file_name = $currhash->{$item};
                    631: 	    }
                    632: 	    my $have_meta = exists($dirlist{$file_name.'.meta'});
1.55      raeburn   633:             my $url;
                    634:             if ($is_course) {
                    635:                 $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
                    636:                        '/portfolio/'.$currhash->{$item};
                    637:             } else { 
                    638: 	        $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
                    639: 		       $currhash->{$item};
                    640:             }
1.43      raeburn   641:             my $showname;
1.50      albertel  642: 	    if ($have_meta) {
                    643: 		$showname = &Apache::lonnet::metadata($url,'title');
                    644: 	    }
                    645: 	    if ($showname eq '') {
                    646: 		$showname = $file_name;
                    647: 	    } else {
                    648: 		$showname = $file_name.' ('.$showname.')';
                    649: 	    }
                    650: 
1.45      albertel  651:             $showname=&HTML::Entities::encode($showname,'<>&"');
1.49      albertel  652:             $output .= '<a href="'.$url.'">'.
                    653: 		'<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
                    654: 		'&nbsp;'.$showname.'</a>';
                    655: 	    $output.='</td><td>';
1.50      albertel  656: 	    if ($have_meta) {
1.49      albertel  657: 		$output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Catalog Information').'" src="'.
1.47      albertel  658: 		&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
1.49      albertel  659: 		'" class="LC_icon" /></a>';
                    660: 	    }
1.45      albertel  661: 	    $output .= '</td></tr>';
1.43      raeburn   662:         }
                    663:     }
1.45      albertel  664:     return $output;
1.43      raeburn   665: }
1.1       www       666: 
                    667: 1;
                    668: __END__

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