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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # "About Me" Personal Information
1.1       www         3: #
1.61    ! albertel    4: # $Id: lonaboutme.pm,v 1.60 2006/12/11 03:46:31 raeburn 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.40      albertel  117: 	my $start_page = 
                    118: 	    &Apache::loncommon::start_page("Personal Information",undef,
                    119: 					   {'function'       => $forcestudent,
1.47      albertel  120:  					    'domain'         => $cdom,
1.40      albertel  121: 					    'force_register' =>
1.43      raeburn   122: 						            $forceregister,});
1.40      albertel  123: 	$r->print($start_page);
1.22      sakharuk  124: 	$r->print('<h1>'.&Apache::loncommon::plainname($cnum,$cdom).'</h1>');
                    125:     } else {
                    126: 	$r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
                    127:     }
1.6       www       128:     if ($courseenv{'nickname'}) {
                    129:        $r->print(
1.7       albertel  130:          '<h2>&quot;'.$courseenv{'nickname'}.
1.6       www       131:          '&quot;</h2>');
                    132:     }
1.22      sakharuk  133:     if ($target ne 'tex') {
1.61    ! albertel  134: 	$r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>'.
1.39      www       135: 		  '<p>'.&Apache::loncommon::messagewrapper('Send me a message',$cnum,$cdom).'</p>'.&Apache::lonrss::advertisefeeds($cnum,$cdom));
1.22      sakharuk  136:     } else {
1.61    ! albertel  137: 	$r->print('\textbf{'.&Apache::lonnet::domain($cdom,'description').'}\\\\');
1.22      sakharuk  138:     }
1.2       www       139:     my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
                    140:     my $allowed=0;
                    141: 
1.1       www       142: # does this user have privileges to post, etc?
1.2       www       143: 
1.37      albertel  144:        my $privleged=$allowed=(($env{'user.name'} eq $cnum) && 
                    145: 			       ($env{'user.domain'} eq $cdom));
1.23      sakharuk  146:        if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.2       www       147:  
                    148:        if ($allowed) {
1.43      raeburn   149:            my $query_string = &build_query_string({'forcestudent' => '1',});
1.32      albertel  150: 	   $r->print('<p><b>'.&mt('Privacy Note').':</b> '.
                    151: 		     &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.').
                    152: 		     '</p>'.
1.43      raeburn   153: 		     &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'</p><p><a href="'.$r->uri.$query_string.'">Show Public View</a>'.
1.32      albertel  154: 		     &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
                    155:        } elsif ($privleged && $target ne 'tex') {
1.43      raeburn   156:            my $query_string = &build_query_string({'forceedit' => '1',});
                    157: 	   $r->print('<p><a href="'.$r->uri.$query_string.'"><font size="+1">'.
1.32      albertel  158: 		     &mt('Edit').'</font></a></p>');
                    159:        }
1.37      albertel  160:       if (($env{'form.uploaddoc.filename'}) &&
                    161:           ($env{'form.storeupl'}) && ($allowed)) {
                    162:  	  if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
1.24      albertel  163: 	      if ($syllabus{'uploaded.photourl'}) {
                    164: 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
                    165: 	      }
                    166: 	      $syllabus{'uploaded.photourl'}=
                    167:                  &Apache::lonnet::userfileupload('uploaddoc',undef,'aboutme');
1.3       www       168:  	  }
                    169:           $syllabus{'uploaded.lastmodified'}=time;
                    170:           &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
                    171:        }
1.37      albertel  172:     if ($allowed && $env{'form.delupl'}) {
1.32      albertel  173: 	if ($syllabus{'uploaded.photourl'}) {
                    174: 	    &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
                    175: 	    delete($syllabus{'uploaded.photourl'});
                    176: 	    &Apache::lonnet::del('aboutme',['uploaded.photourl'],$cdom,$cnum);
                    177: 	}
                    178:     }
1.37      albertel  179:        if (($allowed) && ($env{'form.storesyl'})) {
1.57      albertel  180: 	   foreach my $syl_field (keys(%syllabusfields)) {
                    181:                my $field=$env{'form.'.$syl_field};
1.2       www       182:                $field=~s/\s+$//s;
1.11      www       183:                $field=&Apache::lonfeedback::clear_out_html($field,
1.37      albertel  184:                                                            $env{'user.adv'});
1.57      albertel  185: 	       $syllabus{$syl_field}=$field;
1.2       www       186:            }
                    187:            $syllabus{'uploaded.lastmodified'}=time;
                    188:            &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
                    189:        }
                    190: 
                    191: # ---------------------------------------------------------------- Get syllabus
                    192:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.5       www       193:        my $lastmod=$syllabus{'uploaded.lastmodified'};
1.18      www       194:        $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
                    195:        $r->print(&mt('Last updated').': '.$lastmod);
1.3       www       196:        if ($syllabus{'uploaded.photourl'}) {
1.24      albertel  197: 	   &Apache::lonnet::allowuploaded('/adm/aboutme',
                    198: 					  $syllabus{'uploaded.photourl'});
1.33      matthew   199: 	   my $image=
                    200:                qq{<img src="$syllabus{'uploaded.photourl'}" align="right" />};
1.27      albertel  201: 	   if ($target eq 'tex') {
                    202: 	       $image=&Apache::lonxml::xmlparse($r,'tex',$image);
1.26      sakharuk  203: 	   }
1.27      albertel  204: 	   $r->print($image);
1.3       www       205:        }
1.23      sakharuk  206:        if ($allowed) {
1.3       www       207:            $r->print(
1.32      albertel  208: 	 '<form method="post">
                    209:                <input type="submit" name="delupl" value="Delete Photo" />
                    210:           </form>'.
1.3       www       211: 	 '<form method="post" enctype="multipart/form-data">'.
1.18      www       212:          '<h3>'.&mt('Upload a Photo').'</h3>'.
1.3       www       213:          '<input type="file" name="uploaddoc" size="50">'.
                    214:          '<input type="submit" name="storeupl" value="Upload">'.
                    215: 	 '</form><form method="post">');
1.32      albertel  216: 
1.2       www       217:        }
1.57      albertel  218:        foreach my $field (sort(keys(%syllabusfields))) {
                    219:           if (($syllabus{$field}) || ($allowed)) {
                    220:               my $message=$syllabus{$field};
1.38      albertel  221: 	      &Apache::lonfeedback::newline_to_br(\$message);
1.2       www       222:               $message
                    223:              =~s/(http\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.29      www       224: 	      if ($allowed) {
                    225: 		  $message=&Apache::lonspeller::markeduptext($message);
                    226: 	      }
1.2       www       227: 	      $message=&Apache::lontexconvert::msgtexconverted($message);
1.22      sakharuk  228: 	      if ($target ne 'tex') {
1.57      albertel  229: 		  $r->print('<h3>'.$syllabusfields{$field}.'</h3><blockquote>'.
1.22      sakharuk  230:                             $message.'</blockquote>');
                    231: 	      } else {
1.57      albertel  232: 		     $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
1.25      sakharuk  233: 			       &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
1.22      sakharuk  234: 	      }
1.23      sakharuk  235:               if ($allowed) {
1.57      albertel  236:                  $r->print('<br /><textarea cols="80" rows="6" name="'.$field.'">'.
                    237: 			   &HTML::Entities::encode($syllabus{$field},'"&<>').
1.17      www       238:            '</textarea><input type="submit" name="storesyl" value="'.
                    239: 			   &mt('Store').'" />');
1.2       www       240: 	      }
                    241: 	  }
                    242:        }
1.23      sakharuk  243:        if ($allowed) {
1.2       www       244: 	   $r->print('</form>');
                    245:        }
1.46      albertel  246:        if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
1.2       www       247:     } else {
1.17      www       248:        $r->print('<p>'.&mt('No personal information provided').'.</p>');
1.8       www       249:     }
1.43      raeburn   250: 
                    251:     if ($target ne 'tex') {
1.55      raeburn   252:         &print_portfiles_link($r,$is_course);
1.43      raeburn   253:     }
                    254: 
1.37      albertel  255:     if ($env{'request.course.id'}) {
                    256: 	if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})) {
1.22      sakharuk  257: 	    if ($target ne 'tex') {
1.30      sakharuk  258: 		$r->print('<a name="coursecomment" />');
1.22      sakharuk  259: 		$r->print('<hr /><h3>'.
                    260:                           &mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'</h3>'.
                    261:                           &mt('Shared by course faculty and staff').
                    262:                           &Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message").
1.19      www       263: '<br />');
1.41      albertel  264:                 &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
1.31      matthew   265:                 $r->print('<hr />');
                    266:                 if (&Apache::lonnet::allowed('vsa',
1.37      albertel  267:                                              $env{'request.course.id'}) ||
1.31      matthew   268:                     &Apache::lonnet::allowed('vsa',
1.37      albertel  269:                                              $env{'request.course.id'}.'/'.
                    270:                                              $env{'request.course.sec'})) {
1.35      matthew   271:                     $r->print(&Apache::loncommon::track_student_link
                    272:                               ('View recent activity by this student',
                    273:                                $cnum,$cdom).('&nbsp;'x2));
1.31      matthew   274:                 }
                    275:                 $r->print(&Apache::loncommon::noteswrapper('Add Records',$cnum,$cdom));
1.22      sakharuk  276: 	    } else {
                    277: 		$r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
1.41      albertel  278: 		&Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
1.22      sakharuk  279: 	    }
1.8       www       280:         }
1.1       www       281:     }
1.40      albertel  282:     if ($target ne 'tex') {
                    283: 	$r->print(&Apache::loncommon::end_page());
                    284:     } else {
                    285: 	$r->print('\end{document}');
                    286:     }
1.1       www       287:     return OK;
1.43      raeburn   288: }
                    289: 
                    290: sub aboutme_info {
1.55      raeburn   291:     my ($r,$is_course) = @_;
1.43      raeburn   292:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.55      raeburn   293:     my $name;
                    294:     if (!$is_course) {
                    295:         $name = &Apache::loncommon::plainname($cnum,$cdom);
                    296:     }
1.43      raeburn   297:     return ($cdom,$cnum,$name);
                    298: }
                    299: 
                    300: sub print_portfiles_link {
1.55      raeburn   301:     my ($r,$is_course) = @_;
                    302:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
                    303:     my $filecounts = &portfolio_files($r,'showlink',undef,$is_course);
1.47      albertel  304:     my $query_string = &build_query_string();
1.43      raeburn   305:     my $output;
1.55      raeburn   306:     my %lt = &Apache::lonlocal::texthash(
                    307:                          vpfi => 'Viewable portfolio files',
                    308:                          vgpf => 'Viewable group portfolio files',
                    309:                          difl => 'Display file listing',
                    310:              );                     
1.43      raeburn   311:     if ($filecounts->{'both'} > 0) {
1.55      raeburn   312:         $output = '<h3>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h3>';
1.47      albertel  313:         $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
1.55      raeburn   314:                    $query_string.'">'.$lt{'difl'}.
1.43      raeburn   315:                    '</a><br /><br />';
1.53      raeburn   316:         if ($filecounts->{'both'} == 1) {
1.55      raeburn   317:             if ($is_course) {
                    318:                 $output .= &mt('One group portfolio file is available.').'<ul>';
                    319:             } else {
1.56      albertel  320:                 $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
1.55      raeburn   321:             }
1.53      raeburn   322:         } else {
1.55      raeburn   323:             if ($is_course) {
1.56      albertel  324:                 $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
1.55      raeburn   325:             } else {
                    326:                 $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
                    327:             }
1.53      raeburn   328:         }
1.43      raeburn   329:         if ($filecounts->{'withoutpass'}) {
1.54      albertel  330: 	    $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
1.43      raeburn   331:         }
                    332:         if ($filecounts->{'withpass'}) {
1.54      albertel  333: 	    $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
1.43      raeburn   334:         }
                    335:         $output .= '</ul>';
                    336:     }
                    337:     $r->print($output);
                    338:     return;
                    339: }
                    340: 
                    341: sub build_query_string {
                    342:     my ($new_items) = @_;
                    343:     my $query_string;
                    344:     my @formelements = ('register'); 
1.47      albertel  345:     my $new = 0;
1.43      raeburn   346:     if (ref($new_items) eq 'HASH') {
1.47      albertel  347:         $new = 1;
1.43      raeburn   348:         if (!defined($new_items->{'forceedit'}) && 
                    349:             !defined($new_items->{'forcestudent'})) {
                    350:             push(@formelements,('forceedit','forcestudent'));
                    351:         }
                    352:     } else {
                    353:         push(@formelements,('forceedit','forcestudent'));
                    354:     }
                    355:     foreach my $element (@formelements) {
                    356:         if (exists($env{'form.'.$element})) {
1.47      albertel  357:             if ((!$new) || (!defined($new_items->{$element}))) {
1.43      raeburn   358:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
                    359:             }
                    360:         }
                    361:     }
1.47      albertel  362:     if ($new) {
1.43      raeburn   363:         foreach my $key (keys(%{$new_items})) {
                    364:             $query_string .= '&amp;'.$key.'='.$new_items->{$key};
                    365:         }
                    366:     }
                    367:     $query_string =~ s/^\&amp;/\?/;
                    368:     return $query_string;
                    369: }
                    370: 
                    371: sub display_portfolio_header {
1.55      raeburn   372:     my ($r,$is_course) = @_;
                    373:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.43      raeburn   374:     my $query_string = &build_query_string();
                    375:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    376:     my $forcestudent='';
                    377:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.55      raeburn   378: 
                    379:     my $output;
                    380:     if ($is_course) {
                    381:         $output = 
                    382:             &Apache::loncommon::start_page('Viewable group portfolio files',undef,
                    383:                                             {'function' => $forcestudent,
                    384:                                              'domain'   => $cdom,});
                    385:         $output .= '<h3>'.&mt('Group Portfolio files').'</h3>';
                    386:     } else {
                    387:         $output  =
                    388:             &Apache::loncommon::start_page('Viewable portfolio files',undef,
                    389:                                             {'function' => $forcestudent,
1.43      raeburn   390:                                              'domain'   => $cdom,});
1.55      raeburn   391:         if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
                    392:             &Apache::lonhtmlcommon::add_breadcrumb
                    393:                 ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
                    394:                   text=>"Personal information - $name",
                    395:                   title=>"Go to personal information page for $name"},                 {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
                    396:                   text=>"Viewable files - $name",
                    397:                   title=>"Viewable portfolio files for $name"}
                    398:             );
                    399:             $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
                    400:         }
                    401:         $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
1.53      raeburn   402:     }
1.43      raeburn   403:     $r->print($output);
                    404:     return;
                    405: }
                    406: 
                    407: sub display_portfolio_files {
1.55      raeburn   408:     my ($r,$is_course) = @_;
                    409:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.47      albertel  410:     my %lt = ( withoutpass => 'passphrase not required',
                    411: 	       withpass    => 'passphrase protected',
                    412: 	       both        => 'all access types ',);
                    413:     %lt = &Apache::lonlocal::texthash(%lt);
                    414: 
1.43      raeburn   415:     my $portaccess = 'withoutpass';
                    416:     if (exists($env{'form.portaccess'})) {
                    417:         $portaccess = $env{'form.portaccess'};
                    418:     }
1.47      albertel  419: 
1.45      albertel  420:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
                    421: 	.'" name="displaystatus" method="post">'.
                    422: 	&mt('File access type: ').'<select name="portaccess">';
1.43      raeburn   423:     foreach my $type ('withoutpass','withpass','both') {
                    424:         $output .= '<option value="'.$type.'" ';
                    425:         if ($portaccess eq $type) {
                    426:             $output .= 'selected="selected"';
                    427:         }
1.53      raeburn   428:         $output .= '>'.$lt{$type}.'</option>';
1.43      raeburn   429:     }
                    430:     $output .= '</select>'."\n".
                    431:                '<input type="submit" name="portaccessbutton" value="'.
1.47      albertel  432:                &mt('Update display').'" />';
1.43      raeburn   433:     $output .= '</form><br /><br />';
                    434:     $r->print($output);
1.55      raeburn   435:     my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course);
1.53      raeburn   436:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
                    437:         my $query_string = &build_query_string();
                    438:         $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
1.55      raeburn   439:                   '/aboutme'.$query_string.'">');
                    440:         if ($is_course) {
                    441:             $r->print(&mt('Course Information page'));
                    442:         } else {
                    443:             $r->print(&mt('Information about [_1]',$name));
                    444:         }
                    445:         $r->print('</a>');
1.53      raeburn   446:     }
1.43      raeburn   447:     return;
                    448: }
                    449: 
                    450: sub portfolio_files {
1.55      raeburn   451:     my ($r,$mode,$lt,$is_course) = @_;
                    452:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.43      raeburn   453:     my $filecounts = {
                    454:                        withpass    => 0,
                    455:                        withoutpass => 0,
                    456:                        both        => 0,
                    457:                      };
                    458:     my $current_permissions =
1.44      albertel  459: 	&Apache::lonnet::get_portfile_permissions($cdom,$cnum);
1.43      raeburn   460:     my %access_controls = 
1.44      albertel  461: 	&Apache::lonnet::get_access_controls($current_permissions);
1.43      raeburn   462:     my $portaccess;
                    463:     if ($mode eq 'showlink') {
                    464:         $portaccess = 'both';
                    465:     } else {
                    466:         $portaccess = 'withoutpass';
                    467:         if (exists($env{'form.portaccess'})) {
                    468:             $portaccess = $env{'form.portaccess'};
                    469:         }
                    470:     }
                    471: 
1.55      raeburn   472:     my $diroutput;
                    473:     if ($is_course) {
                    474:         my %files_by_group;
                    475:         foreach my $filename (sort(keys(%access_controls))) {
                    476:             my ($group,$path) = split('/',$filename,2);
                    477:             $files_by_group{$group}{$path} = $access_controls{$filename}; 
                    478:         }
                    479:         foreach my $group (sort(keys(%files_by_group))) {
                    480:             my %fileshash;
                    481:             my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
                    482:                                            $is_course,$filecounts,$mode,
                    483:                                            $files_by_group{$group},
                    484:                                            \%fileshash,$group);
                    485:             if ($grpout) {
                    486:                 $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
                    487:             }
                    488:         }
                    489:     } else {
                    490:         my %allfileshash;
                    491:         $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
                    492:                                       $filecounts,$mode,\%access_controls,
                    493:                                       \%allfileshash);
                    494:     }
                    495:     if ($mode eq 'listfiles') {
                    496:         if ($filecounts->{'both'}) {
                    497:              $r->print($diroutput);
                    498:         } else {
                    499:             my $access_text;
                    500:             if (ref($lt) eq 'HASH') {
                    501:                 $access_text = $lt->{$portaccess};   
                    502:             }
                    503:             $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
                    504:         }
                    505:     }
                    506:     return $filecounts;
                    507: }
                    508: 
                    509: { 
                    510:     my $count=0;
                    511:     sub portfolio_table_start {
                    512: 	$count=0;
                    513: 	return '<table class="LC_aboutme_port">';
                    514:     }
                    515:     sub portfolio_row_start {
                    516: 	$count++;
                    517: 	my $class = ($count%2)?'LC_odd_row'
                    518: 	                      :'LC_even_row';
                    519: 	return '<tr class="'.$class.'">';
                    520:     }
                    521: }
                    522: 
                    523: sub build_hierarchy {
                    524:     my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
                    525:         $allfileshash,$group) = @_;
                    526:     foreach my $filename (sort(keys(%{$access_info}))) {
                    527:         my $access_status =
                    528:            &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group,                                                 $$access_info{$filename});
1.43      raeburn   529:         if ($portaccess eq 'both') {
                    530:             if (($access_status ne 'ok') &&
                    531:                 ($access_status !~  /^[^:]+:guest_/)) {
                    532:                 next;
                    533:             }
                    534:         } elsif ($portaccess eq 'withoutpass') {
                    535:             if ($access_status ne 'ok') {
                    536:                 next;
                    537:             }
                    538:         } elsif ($portaccess eq 'withpass') {
                    539:             if ($access_status !~  /^[^:]+:guest_/) {
                    540:                 next;
                    541:             }
                    542:         }
                    543:         if ($mode eq 'listfiles') {
                    544:             $filename =~ s/^\///;
                    545:             my @pathitems = split('/',$filename);
1.55      raeburn   546:             my $lasthash = $allfileshash;
1.43      raeburn   547:             while (@pathitems > 1) {
                    548:                 my $newlevel = shift(@pathitems);
                    549:                 if (!exists($lasthash->{$newlevel})) {
                    550:                     $lasthash->{$newlevel} = {};
                    551:                 }
                    552:                 $lasthash = $lasthash->{$newlevel};
                    553:             }
                    554:             $lasthash->{$pathitems[0]} = $filename;
                    555:         }
                    556:         if ($access_status eq 'ok') {
                    557:             $filecounts->{'withoutpass'} ++;
                    558:         } elsif ($access_status =~  /^[^:]+:guest_/) {
                    559:             $filecounts->{'withpass'} ++;
                    560:         }
                    561:     }
                    562:     $filecounts->{'both'} =  $filecounts->{'withoutpass'} +
                    563:                               $filecounts->{'withpass'};
1.55      raeburn   564:     my $output;
1.43      raeburn   565:     if ($mode eq 'listfiles') {
1.55      raeburn   566:         if ($filecounts->{'both'} > 0) {
1.45      albertel  567:             $output = &portfolio_table_start();
1.55      raeburn   568:             $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
                    569:                                         $group);
1.43      raeburn   570:             $output .= '</table>';
                    571:         }
1.45      albertel  572:     }
1.55      raeburn   573:     return $output;
1.45      albertel  574: }
                    575: 
1.43      raeburn   576: sub parse_directory {
1.55      raeburn   577:     my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
                    578:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.45      albertel  579:     $depth++;
                    580:     my $output;
1.49      albertel  581: 
1.55      raeburn   582:     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
                    583:                                                                 $group);
1.49      albertel  584:     my %dirlist = map {
                    585: 	    ((split('&',$_,2))[0],1)
                    586: 	} &Apache::lonnet::dirlist($path,$cdom,$cnum,$portfolio_root);
1.43      raeburn   587:     foreach my $item (sort(keys(%{$currhash}))) {
1.45      albertel  588:         $output .= &portfolio_row_start();
                    589:         $output .= '<td style="padding-left: '.($depth*25).'px">';
1.43      raeburn   590:         if (ref($currhash->{$item}) eq 'HASH') {
1.45      albertel  591:             my $title=&HTML::Entities::encode($item,'<>&"');
                    592:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" />&nbsp;'.$title;
1.47      albertel  593: 	    $output .= '</td><td></td></tr>';
1.49      albertel  594:             $output .= &parse_directory($r,$depth,$currhash->{$item},
1.55      raeburn   595: 					$path.'/'.$item,$is_course,$group);
1.43      raeburn   596:         } else {
1.50      albertel  597: 	    my $file_name; 
                    598: 	    if ($currhash->{$item} =~ m|/([^/]+)$|) {
                    599: 		$file_name = $1;
                    600: 	    } else {
                    601: 		$file_name = $currhash->{$item};
                    602: 	    }
                    603: 	    my $have_meta = exists($dirlist{$file_name.'.meta'});
1.55      raeburn   604:             my $url;
                    605:             if ($is_course) {
                    606:                 $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
                    607:                        '/portfolio/'.$currhash->{$item};
                    608:             } else { 
                    609: 	        $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
                    610: 		       $currhash->{$item};
                    611:             }
1.43      raeburn   612:             my $showname;
1.50      albertel  613: 	    if ($have_meta) {
                    614: 		$showname = &Apache::lonnet::metadata($url,'title');
                    615: 	    }
                    616: 	    if ($showname eq '') {
                    617: 		$showname = $file_name;
                    618: 	    } else {
                    619: 		$showname = $file_name.' ('.$showname.')';
                    620: 	    }
                    621: 
1.45      albertel  622:             $showname=&HTML::Entities::encode($showname,'<>&"');
1.49      albertel  623:             $output .= '<a href="'.$url.'">'.
                    624: 		'<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
                    625: 		'&nbsp;'.$showname.'</a>';
                    626: 	    $output.='</td><td>';
1.50      albertel  627: 	    if ($have_meta) {
1.49      albertel  628: 		$output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Catalog Information').'" src="'.
1.47      albertel  629: 		&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
1.49      albertel  630: 		'" class="LC_icon" /></a>';
                    631: 	    }
1.45      albertel  632: 	    $output .= '</td></tr>';
1.43      raeburn   633:         }
                    634:     }
1.45      albertel  635:     return $output;
1.43      raeburn   636: }
1.1       www       637: 
                    638: 1;
                    639: __END__

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