File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.161.2.1: download - view: text, annotated - select for diffs
Wed Jul 3 23:49:50 2024 UTC (3 weeks, 4 days ago) by raeburn
Branches: version_2_11_X
CVS tags: version_2_11_5
Diff to branchpoint 1.161: preferred, unified
- For 2.11
  Backport 1.165

    1: # The LearningOnline Network
    2: # Personal Information Page
    3: #
    4: # $Id: lonaboutme.pm,v 1.161.2.1 2024/07/03 23:49:50 raeburn Exp $
    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: =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 aboutme_info()
   54: 
   55: =item print_portfiles_link()
   56: 
   57: =item build_query_string()
   58: 
   59: =item display_portfolio_header()
   60: 
   61: =item display_portfolio_files()
   62: 
   63: =item portfolio_files()
   64: 
   65: =item build_hierarchy()
   66: 
   67: =item parse_directory()
   68: 
   69: =back
   70: 
   71: =cut
   72: 
   73: 
   74: package Apache::lonaboutme;
   75: 
   76: use strict;
   77: use Apache::Constants qw(:common);
   78: use Apache::loncommon;
   79: use Apache::lonnet;
   80: use Apache::lontexconvert;
   81: use Apache::lonhtmlgateway;
   82: use Apache::lonrss();
   83: use Apache::lonlocal;
   84: use Apache::lonmsgdisplay();
   85: use Apache::lontemplate;
   86: use Apache::longroup;
   87: use HTML::Entities();
   88: use Image::Magick;
   89: 
   90: sub handler {
   91:     my $r = shift;
   92:     &Apache::loncommon::content_type($r,'text/html');
   93:     $r->send_http_header;
   94:     return OK if $r->header_only;
   95:     my $target=$env{'form.grade_target'};
   96: # ------------------------------------------------------------ Print the screen
   97:     if ($target eq 'tex') {
   98:         $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
   99:     }
  100:     my (undef,undef,$cdom,$cnum,undef,$action)=split(/\//,$r->uri);
  101:     my $is_course;
  102: # Is this even a user?
  103:     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
  104:         &Apache::loncommon::simple_error_page($r,'No info',
  105:             'No user information available');
  106:         return OK;
  107:     } else {
  108:         $is_course = &Apache::lonnet::is_course($cdom,$cnum);
  109:     }
  110: 
  111:     my $clientip = &Apache::lonnet::get_requestor_ip($r);
  112:     my $candisplay = 1;
  113:     if (!$is_course) {
  114:         if ($action ne 'portfolio') {
  115:             if (($env{'user.name'} eq $cnum) && ($env{'user.domain'} eq $cdom)) {
  116:                 $candisplay = &Apache::lonnet::usertools_access($cnum,$cdom,'aboutme');
  117:             } else {
  118:                 $candisplay = &Apache::loncommon::aboutme_on($cnum,$cdom);
  119:             }
  120:             if ((!$candisplay) && ($env{'request.course.id'})) {
  121:                 $candisplay = &aboutme_access($cnum,$cdom);
  122:             }
  123:             if (!$candisplay) {
  124:                 if ($target eq 'tex') {
  125:                     $r->print('\noindent{\large\textbf{'.&mt('No user personal information page available').'}}\\\\\\\\');
  126:                 } else {
  127:                     $r->print(&Apache::loncommon::start_page("Personal Information Page"));
  128:                     $r->print('<p class="_LC_info">'.&mt('No user personal information page available') .'</p>'.
  129:                         &mt('This is a result of one of the following:').'<ul>'.
  130:                         '<li>'.&mt('The administrator of this domain has disabled personal information page functionality for this specific user.').'</li>'.
  131:                         '<li>'.&mt('The domain has been configured to disable, by default, personal information page functionality for all users in the domain.').'</li>'.
  132:                         '</ul>');
  133:                     $r->print(&Apache::loncommon::end_page());
  134:                 }
  135:                 return OK;
  136:             }
  137:         }
  138:     }
  139: 
  140: # --------------------------------------------------------- The syllabus fields
  141:     my %syllabusfields=&Apache::lonlocal::texthash(
  142:        'aaa_contactinfo'   => 'Contact Information',
  143:        'bbb_aboutme'       => 'Personal Information',
  144:        'ccc_webreferences' => 'Web References');
  145: 
  146: # ------------------------------------------------------------ Get Query String
  147:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  148:                         ['forceedit','forcestudent','todocs',
  149:                          'register','popup','folderpath','title']);
  150: # ----------------------------------------------- Available Portfolio file display
  151:     if (($target ne 'tex') && ($action eq 'portfolio')) {
  152:         &display_portfolio_header($r,$is_course);
  153:         if ((!$is_course) && (!&Apache::lonnet::usertools_access($cnum,$cdom,'portfolio'))) {
  154:             $r->print('<h2>'.&mt('No user portfolio available') .'</h2>'.
  155:                 &mt('This is a result of one of the following:').'<ul>'.
  156:                 '<li>'.&mt('The administrator of this domain has disabled portfolio functionality for this specific user.').'</li>'.
  157:                 '<li>'.&mt('The domain has been configured to disable, by default, portfolio functionality for all users in the domain.').'</li>'.
  158:                 '</ul>');
  159:         } else {
  160:             my ($blocked,$blocktext) =
  161:                 &Apache::loncommon::blocking_status('port',$clientip,$cnum,$cdom);
  162:             if (!$blocked) {
  163:                 &display_portfolio_files($r,$is_course);
  164:             } else {
  165:                 $r->print($blocktext);
  166:             }
  167:         }
  168:         $r->print(&Apache::loncommon::end_page());
  169:         return OK;
  170:     }
  171: 
  172:     if ($is_course) {
  173:         if ($target ne 'tex') {
  174:             my $args = {'function'       => undef,
  175:                         'domain'         => $cdom};
  176:             if ($env{'form.register'}) {
  177:                 $args->{'force_register'} = $env{'form.register'};
  178:             } else {
  179:                 my %coursedescription = 
  180:                     &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
  181:                 my $cdescr = $coursedescription{'description'};
  182:                 my $brcrum = [{href=>"/adm/$cdom/$cnum/aboutme",
  183:                                text=>&mt('Course Information - [_1]',$cdescr),
  184:                                no_mt=>1}
  185:                              ];
  186:                 $args->{'bread_crumbs'} = $brcrum;
  187:             }
  188:             my $start_page = &Apache::loncommon::start_page(
  189:                                  "Course Information",undef,$args);
  190:             $r->print($start_page);
  191:             $r->print('<h2>'.&mt('Group Portfolio').'</h2>');
  192:             &print_portfiles_link($r,$is_course);
  193:             $r->print(&Apache::loncommon::end_page());
  194:         }
  195:         return OK;
  196:     }
  197: 
  198: #------------Get rights
  199:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
  200:     my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
  201:     my ($allowed,$coursedomain,$coursenum);
  202:     if ($env{'request.course.id'}) {
  203:         $coursedomain = $env{'course.'.$env{'request.course.id'}.'.domain'};
  204:         $coursenum = $env{'course.'.$env{'request.course.id'}.'.num'};
  205:     }
  206:     my ($cfile) = 
  207:         &Apache::lonnet::can_edit_resource($env{'request.noversionuri'},
  208:                                            $coursenum,$coursedomain,
  209:                                            $env{'request.noversionuri'},
  210:                                            $env{'request.symb'});
  211:     if ($cfile ne '') {
  212:         $allowed = 1;
  213:     }
  214: 
  215:     if (!$env{'form.forceedit'} or $target eq 'tex') { $allowed=0; }
  216: 
  217: # --------------------------------------- There is such a user, get environment
  218: 
  219:     if ($target ne 'tex') {
  220:         my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
  221:         my $args = {'function' => undef,
  222:                     'domain'   => $cdom,
  223:                     'force_register' => $env{'form.register'},
  224:                    };
  225:         if ($env{'form.popup'}) { # Don't show breadcrumbs in popup window 
  226:             $args->{'no_nav_bar'} = 1;
  227:         } elsif (!$env{'form.register'}) { #Don't show breadcrumbs twice, when this page is part of course content and you call it
  228:             if (($env{'request.course.id'}) &&
  229:                  ($env{'form.folderpath'} =~ /^supplemental/)) {
  230:                 my $crstype = &Apache::loncommon::course_type();
  231:                 my $title = $env{'form.title'};
  232:                 if ($title eq '') {
  233:                     $title = &mt('Personal Information Page');
  234:                 }
  235:                 my $brcrum =
  236:                     &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
  237:                 if (ref($brcrum) eq 'ARRAY') {
  238:                     $args->{'bread_crumbs'} = $brcrum;
  239:                 }
  240:             } else {
  241:                 $args->{'bread_crumbs'} = [{href=>"/adm/$cdom/$cnum/aboutme",
  242:                                             text=>"Personal Information Page"}];
  243:             }
  244:         }
  245:         my $start_page = &Apache::loncommon::start_page('Personal Information Page',$rss_link,$args);
  246:         $r->print($start_page);
  247:    }
  248:    my ($blocked,$blocktext) =
  249:        &Apache::loncommon::blocking_status('about',$clientip,$cnum,$cdom);
  250:    if ($blocked) {
  251:        if ($target eq 'tex') {
  252:            $r->print('\noindent{\large\textbf{'.&mt('No user personal information page available').'}}\\\\\\\\');
  253:        } else {
  254:            $r->print($blocktext);
  255:        }
  256:        $r->print(&Apache::loncommon::end_page());
  257:        return OK;
  258:    }
  259: 
  260: #----------------Print Privacy note (edit mode) or last modified date. 
  261: 
  262:     if ($target ne 'tex') {
  263:         #Print Privacy Note
  264:         if ($allowed) {
  265:             $r->print('<div class="LC_info">'
  266:                 .'<b>'.&mt('Privacy Note:').'</b> '
  267:                 .&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.')
  268:                 .'</div>'
  269:             );
  270:         } elsif ($syllabus{'uploaded.lastmodified'}) {
  271:         #Print last modified
  272:             my $lastmod=$syllabus{'uploaded.lastmodified'};
  273:             $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
  274:             $r->print('<div class="LC_info">');
  275:             $r->print(&mt('Last updated').': '.$lastmod . '');
  276:             $r->print('</div>');
  277:         }
  278:     }
  279: 
  280: #------Print Headtitle
  281:      if ($target ne 'tex') {
  282:          $r->print('<div class="LC_Box">'.
  283:                    '<h2 class="LC_hcell">'.&Apache::loncommon::plainname($cnum,$cdom).'</h2>');
  284:          if ($allowed) {
  285:              $r->print('<div style="margin: 0; float:left;">');
  286:              if ($courseenv{'nickname'}) {
  287:                  $r->print('<h2>&quot;'.$courseenv{'nickname'}.'&quot;</h2>');
  288:              }
  289:              $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3></div>');
  290:              #Print Help Text
  291:              $r->print('<div style="margin: 0; float:right;">'.
  292:                        &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).
  293:                        '</div><br clear="all" />');
  294:          } else {
  295:              if ($courseenv{'nickname'}) {
  296:                  $r->print('<h2>&quot;'.$courseenv{'nickname'}.'&quot;</h2>');
  297:              }
  298:              $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>');
  299:          }
  300:      } else {
  301:         $r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
  302:         $r->print('\textbf{'.&Apache::lonnet::domain($cdom,'description').'}\\\\');
  303:     }
  304: # does this user have privileges to post, etc?
  305: 
  306: 
  307:     my $query_string;
  308: 
  309:     if (($env{'form.uploaddoc.filename'}) &&
  310:           ($env{'form.storeupl'}) && ($allowed)) {
  311:         if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
  312:             if ($syllabus{'uploaded.photourl'}) {
  313:                 &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  314:             }
  315:             $syllabus{'uploaded.photourl'}=
  316:                 &Apache::lonnet::userfileupload('uploaddoc',undef,'aboutme',
  317:                     undef,undef,undef,undef,undef,undef,undef,'400','500');
  318:          }
  319:         $syllabus{'uploaded.lastmodified'}=time;
  320:         &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
  321:     }
  322:     if ($allowed && $env{'form.delupl'}) {
  323:         if ($syllabus{'uploaded.photourl'}) {
  324:             &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  325:             delete($syllabus{'uploaded.photourl'});
  326:             &Apache::lonnet::del('aboutme',['uploaded.photourl'],$cdom,$cnum);
  327:         }
  328:     }
  329:     if (($allowed) && ($env{'form.storesyl'})) {
  330:         foreach my $syl_field (keys(%syllabusfields)) {
  331:             my $field=$env{'form.'.$syl_field};
  332:             chomp($field);
  333:             my $gateway = Apache::lonhtmlgateway->new();
  334:             $field = $gateway->process_incoming_html($field,1);
  335:             $syllabus{$syl_field}=$field;
  336:         }
  337:         $syllabus{'uploaded.lastmodified'}=time;
  338:         &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
  339:     }
  340: 
  341:     my $image;
  342: # ---------------------------------------------------------------- Get syllabus
  343:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
  344:         if ($syllabus{'uploaded.photourl'}) {
  345:             &Apache::lonnet::allowuploaded('/adm/aboutme',$syllabus{'uploaded.photourl'});
  346: 
  347:             $image=qq|<img name="userPhoto" src="$syllabus{'uploaded.photourl'} " class="LC_AboutMe_Image" alt="Photo of the user" />|;
  348: 
  349:             if ($target eq 'tex') {
  350:                 $image=&Apache::lonxml::xmlparse($r,'tex',$image);
  351:             }
  352:         }
  353: 
  354:         if ($allowed) {
  355:             $r->print(
  356:                 '<form name="UploadPhoto" method="post" enctype="multipart/form-data" action="">'.
  357:                 '<h3>'.&mt('Upload a Photo').'</h3>'.
  358:                 '<p class="LC_info">'.
  359:                 &mt('LON-CAPA will automatically scale your uploaded file so the image will not exceed a width of 400px and a height of 500px.').'</p>'.
  360:                 '<input type="file" name="uploaddoc" size="50" />'.
  361:                 '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />'.
  362:                 '<input type="hidden" name="popup" value="'.$env{'form.popup'}.'" />'.
  363:                 '</form>');
  364:             if ($syllabus{'uploaded.photourl'}) {
  365:                 $r->print('<form name="delPhoto" method="post" action="" ><input type="submit" name="delupl" value="'.&mt('Delete Photo').'" /> </form>')
  366:             }
  367:             $r->print('<p></p>');
  368:         }
  369: 
  370:         if($allowed) {
  371:             $r->print('<form name="lonaboutmeFields" method="post" action="" >');
  372:         }
  373: 
  374:         if ($target ne 'tex') { #print Image
  375:             $r->print($image.'<div class="LC_clear_float_footer"></div>');
  376: 
  377:         } #End Print Image
  378: 
  379:        #Print Content eg. Contactinfo aboutme,...
  380:         &Apache::lontemplate::print_aboutme_content_template($r,$allowed,$target,\%syllabusfields,\%syllabus);
  381:        #End Print Content
  382: 
  383:         if ($target ne 'tex') { #Begin Print RSS and portfiles
  384:             &print_portfiles_link($r,$is_course);
  385:             if (&Apache::lonrss::advertisefeeds($cnum,$cdom) ne '') {
  386:                 &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box');
  387:                 $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom));
  388:                 &Apache::lontemplate::print_end_template($r);
  389:             }
  390: 
  391:         } #End  Print RSS and portfiles
  392: 
  393: 
  394:         if ($allowed) {
  395:             if ($env{'form.popup'}) {
  396:                 $r->print('<input type="hidden" name="popup" value="'.
  397:                     $env{'form.popup'}.'" />');
  398:             }
  399:             $r->print('</form>');
  400:         }
  401:         if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
  402:     } else {
  403:         $r->print('<p class="LC_info">'.&mt('No personal information provided').'.</p>');
  404:     }
  405: 
  406:     if ($env{'request.course.id'}
  407:         && &Apache::lonnet::allowed('srm',$env{'request.course.id'})
  408:         && &Apache::lonnet::in_course($cdom,$cnum,$coursedomain,$coursenum,undef,1)) {
  409:         if ($target ne 'tex') {
  410:             $r->print('<a name="coursecomment" />');
  411:             &Apache::lontemplate::print_start_template($r,&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course'),'LC_Box');
  412:             $r->print('<span class="LC_info">');
  413:             $r->print(&mt('Shared by course faculty and staff').&Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message"));
  414:             $r->print('</span>');
  415:             &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
  416:             &Apache::lontemplate::print_end_template($r);
  417: 
  418:         } else {
  419:             $r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
  420:             &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom,$target);
  421:         }
  422:     }
  423:     if ($target ne 'tex') {
  424:         $r->print('</div>');
  425:         if ($env{'form.popup'}) {
  426:             $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
  427:         }
  428:         $r->print(&Apache::loncommon::end_page());
  429:     } else {
  430:         $r->print('\end{document}');
  431:     }
  432: 
  433: 
  434: 
  435:     return OK;
  436: }
  437: 
  438: sub aboutme_info {
  439:     my ($r,$is_course) = @_;
  440:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
  441:     my $name;
  442:     if (!$is_course) {
  443:         $name = &Apache::loncommon::plainname($cnum,$cdom);
  444:     }
  445:     return ($cdom,$cnum,$name);
  446: }
  447: 
  448: sub print_portfiles_link {
  449:     my ($r,$is_course) = @_;
  450:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  451:     my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
  452:                                       $cdom,$cnum,$name);
  453:     my $query_string = &build_query_string();
  454:     my $output;
  455:     my %lt = &Apache::lonlocal::texthash(
  456:         'vpfi' => 'Viewable portfolio files',
  457:         'vgpf' => 'Viewable group portfolio files',
  458:         'difl' => 'Display file listing',
  459:     );
  460:     if ($filecounts->{'both'} > 0) {
  461:         $output = '<div class="LC_Box"><h4 class="LC_hcell">';
  462:         $output .= ($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
  463: 
  464:        #$output = '<h4>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
  465:         $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
  466:             $query_string.'">'.$lt{'difl'}.
  467:             '</a><br /><br />';
  468:         if ($filecounts->{'both'} == 1) {
  469:             if ($is_course) {
  470:                 $output .= &mt('One group portfolio file is available.').'<ul>';
  471:             } else {
  472:                 $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
  473:             }
  474:         } else {
  475:             if ($is_course) {
  476:                 $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
  477:             } else {
  478:                 $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
  479:             }
  480:         }
  481:         if ($filecounts->{'withoutpass'}) {
  482:             $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
  483:         }
  484:         if ($filecounts->{'withpass'}) {
  485:             $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
  486:         }
  487:         $output .= '</ul>';
  488:         $output .= '</div>';
  489:     } elsif ($is_course) {
  490:         $output .= '<div class="LC_info">'.&mt('There are currently no publicly accessible or password protected group portfolio files.').'</div>'; 
  491:     }
  492:     $r->print($output);
  493:     return;
  494: }
  495: 
  496: sub build_query_string {
  497:     my ($new_items) = @_;
  498:     my $query_string;
  499:     my @formelements = ('register');
  500:     my $new = 0;
  501:     if (ref($new_items) eq 'HASH') {
  502:         $new = 1;
  503:         if (!defined($new_items->{'forceedit'}) &&
  504:             !defined($new_items->{'forcestudent'})) {
  505:             push(@formelements,('forceedit','forcestudent'));
  506:         }
  507:     } else {
  508:         push(@formelements,('forceedit','forcestudent'));
  509:     }
  510:     foreach my $element (@formelements) {
  511:         if (exists($env{'form.'.$element})) {
  512:             if ((!$new) || (!defined($new_items->{$element}))) {
  513:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
  514:             }
  515:         }
  516:     }
  517:     if ($new) {
  518:         foreach my $key (keys(%{$new_items})) {
  519:             $query_string .= '&amp;'.$key.'='.$new_items->{$key};
  520:         }
  521:     }
  522:     $query_string =~ s/^\&amp;/\?/;
  523:     return $query_string;
  524: }
  525: 
  526: sub display_portfolio_header {
  527:     my ($r,$is_course) = @_;
  528:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  529:     my $query_string = &build_query_string();
  530:     my $args = {'domain' => $cdom};
  531:     if ($env{'form.forcestudent'}) {
  532:         $args->{'function'} = 'student';
  533:     }
  534:     my $output;
  535:     if ($is_course) {
  536:         if (($env{'request.course.id'} eq $cdom.'_'.$cnum) && 
  537:             ($env{'form.register'})) {
  538:             $args->{force_register} = $env{'form.register'};
  539:         } else {
  540:             my %coursedescription = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
  541:             my $cdescr = $coursedescription{'description'}; 
  542:             my $brcrum = [{href=>"/adm/$cdom/$cnum/aboutme".$query_string,
  543:                            text=>&mt('Course Information - [_1]',$cdescr),
  544:                            no_mt=>1},
  545:                           {href=>"/adm/$cdom/$cnum/aboutme/portfolio".$query_string,
  546:                            text=>'Viewable group portfolio files'}
  547:                          ];
  548:             $args->{bread_crumbs} = $brcrum;
  549:         }
  550:         $output = &Apache::loncommon::start_page('Viewable group portfolio files',undef,$args).
  551:                   '<h3>'.&mt('Group Portfolio files').'</h3>';
  552:     } else {
  553:         if ($env{'request.course.id'} && $env{'form.register'}) {
  554:             $args->{force_register} = $env{'form.register'};
  555:         } else {
  556:             my $brcrum = [{href  => "/adm/$cdom/$cnum/aboutme".$query_string,
  557:                           text  => &mt('Personal Information Page - [_1]',$name),
  558:                           title => &mt('Go to personal information page for [_1]',$name),
  559:                           no_mt => 1},
  560:                          {href  => "/adm/$cdom/$cnum/aboutme/portfolio".$query_string,
  561:                           text  => &mt('Viewable files'),
  562:                           title => &mt('Viewable portfolio files for [_1]',$name),
  563:                           no_mt => 1}
  564:                          ];
  565:             $args->{bread_crumbs} = $brcrum;
  566:         } 
  567:         $output  = 
  568:             &Apache::loncommon::start_page('Viewable portfolio files',
  569:                                            undef,$args).
  570:             '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
  571:     }
  572:     $r->print($output);
  573:     return;
  574: }
  575: 
  576: sub display_portfolio_files {
  577:     my ($r,$is_course) = @_;
  578:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  579:     my %lt = &Apache::lonlocal::texthash(
  580:         'withoutpass' => 'passphrase not required',
  581:         'withpass'    => 'passphrase protected',
  582:         'both'        => 'all access types ',
  583:     );
  584: 
  585:     my $portaccess = 'withoutpass';
  586:     if (exists($env{'form.portaccess'})) {
  587:         $portaccess = $env{'form.portaccess'};
  588:     }
  589: 
  590:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
  591:         .'" name="displaystatus" method="post">'.
  592:         &mt('File access type: ').'<select name="portaccess">';
  593:     foreach my $type ('withoutpass','withpass','both') {
  594:         $output .= '<option value="'.$type.'" ';
  595:         if ($portaccess eq $type) {
  596:             $output .= 'selected="selected"';
  597:         }
  598:         $output .= '>'.$lt{$type}.'</option>';
  599:     }
  600:     $output .= '</select>'."\n";
  601:     if ($env{'form.register'}) {
  602:         $output .= '<input type="hidden" name="register" value="'.$env{'form.register'}.'" />'."\n";
  603:     }
  604:     $output .= '<input type="submit" name="portaccessbutton" value="'.
  605:                &mt('Update display').'" />'.
  606:                '</form><br /><br />';
  607:     $r->print($output);
  608:     my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
  609:                                       $cdom,$cnum,$name);
  610:     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
  611:         if ($env{'request.course.id'} && $env{'form.register'}) {
  612:             my $query_string = &build_query_string();
  613:             $r->print('<br /><a href="/adm/'.$cdom.'/'.$cnum.
  614:                       '/aboutme'.$query_string.'">');
  615:             if ($is_course) {
  616:                 $r->print(&mt('Course Information page'));
  617:             } else {
  618:                 $r->print(&mt('Information about [_1]',$name));
  619:             }
  620:             $r->print('</a>');
  621:         }
  622:     }
  623:     return;
  624: }
  625: 
  626: sub portfolio_files {
  627:     my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
  628:     my $filecounts = {
  629:                        withpass    => 0,
  630:                        withoutpass => 0,
  631:                        both        => 0,
  632:                      };
  633:     my $current_permissions =
  634:     &Apache::lonnet::get_portfile_permissions($cdom,$cnum);
  635:     my %access_controls =
  636:     &Apache::lonnet::get_access_controls($current_permissions);
  637:     my $portaccess;
  638:     if ($mode eq 'showlink') {
  639:         $portaccess = 'both';
  640:     } else {
  641:         $portaccess = 'withoutpass';
  642:         if (exists($env{'form.portaccess'})) {
  643:             $portaccess = $env{'form.portaccess'};
  644:         }
  645:     }
  646: 
  647:     my $diroutput;
  648:     if ($is_course) {
  649:         my %files_by_group;
  650:         my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
  651:         foreach my $filename (sort(keys(%access_controls))) {
  652:             my ($group,$path) = split('/',$filename,2);
  653:             if (exists($curr_groups{$group})) {
  654:                 $files_by_group{$group}{$path} = $access_controls{$filename};
  655:             }
  656:         }
  657:         foreach my $group (sort(keys(%files_by_group))) {
  658:             my %fileshash;
  659:             my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
  660:                                            $is_course,$filecounts,$mode,
  661:                                            $files_by_group{$group},
  662:                                            \%fileshash,$group);
  663:             if ($grpout) {
  664:                 $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
  665:             }
  666:         }
  667:     } else {
  668:         my %allfileshash;
  669:         $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
  670:                                       $filecounts,$mode,\%access_controls,
  671:                                       \%allfileshash);
  672:     }
  673:     if ($mode eq 'listfiles') {
  674:         if ($filecounts->{'both'}) {
  675:              $r->print($diroutput);
  676:         } else {
  677:             my $access_text;
  678:             if (ref($lt) eq 'HASH') {
  679:                 $access_text = $lt->{$portaccess};
  680:             }
  681:             $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
  682:         }
  683:     }
  684:     return $filecounts;
  685: }
  686: 
  687: sub build_hierarchy {
  688:     my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
  689:         $allfileshash,$group) = @_;
  690:     my $clientip = &Apache::lonnet::get_requestor_ip($r);
  691:     foreach my $filename (sort(keys(%{$access_info}))) {
  692:         my $access_status =
  693:            &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group,$clientip,
  694:                                                  $access_info->{$filename});
  695:         if ($portaccess eq 'both') {
  696:             if (($access_status ne 'ok') &&
  697:                 ($access_status !~  /^[^:]+:guest_/)) {
  698:                 next;
  699:             }
  700:         } elsif ($portaccess eq 'withoutpass') {
  701:             if ($access_status ne 'ok') {
  702:                 next;
  703:             }
  704:         } elsif ($portaccess eq 'withpass') {
  705:             if ($access_status !~  /^[^:]+:guest_/) {
  706:                 next;
  707:             }
  708:         }
  709:         if ($mode eq 'listfiles') {
  710:             $filename =~ s/^\///;
  711:             my @pathitems = split('/',$filename);
  712:             my $lasthash = $allfileshash;
  713:             while (@pathitems > 1) {
  714:                 my $newlevel = shift(@pathitems);
  715:                 if (!exists($lasthash->{$newlevel})) {
  716:                     $lasthash->{$newlevel} = {};
  717:                 }
  718:                 $lasthash = $lasthash->{$newlevel};
  719:             }
  720:             $lasthash->{$pathitems[0]} = $filename;
  721:         }
  722:         if ($access_status eq 'ok') {
  723:             $filecounts->{'withoutpass'} ++;
  724:         } elsif ($access_status =~  /^[^:]+:guest_/) {
  725:             $filecounts->{'withpass'} ++;
  726:         }
  727:     }
  728:     $filecounts->{'both'} =  $filecounts->{'withoutpass'} +
  729:                               $filecounts->{'withpass'};
  730:     my $output;
  731:     if ($mode eq 'listfiles') {
  732:         if ($filecounts->{'both'} > 0) {
  733:             $output = &Apache::loncommon::start_data_table();
  734:             $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
  735:                                         $group);
  736:             $output .= &Apache::loncommon::end_data_table();
  737:         }
  738:     }
  739:     return $output;
  740: }
  741: 
  742: sub parse_directory {
  743:     my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
  744:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
  745:     $depth++;
  746:     my $output;
  747: 
  748:     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
  749:                                                                 $group);
  750:     my $getpropath = 1;
  751:     my ($listref,$listerror) =
  752:         &Apache::lonnet::dirlist($portfolio_root.$path,$cdom,$cnum,$getpropath);
  753:     my %dirlist;
  754:     if (ref($listref) eq 'ARRAY') {
  755:         %dirlist = map { ((split('&',$_,2))[0],1) } @{$listref};
  756:     }
  757:     foreach my $item (sort(keys(%{$currhash}))) {
  758:         $output .= &Apache::loncommon::start_data_table_row();
  759:         $output .= '<td style="padding-left: '.($depth*25).'px">';
  760:         if (ref($currhash->{$item}) eq 'HASH') {
  761:             my $title=&HTML::Entities::encode($item,'<>&"');
  762:             $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" />&nbsp;'.$title;
  763:             $output .= '</td><td>&nbsp;</td>'
  764:                       .&Apache::loncommon::end_data_table_row();
  765:             $output .= &parse_directory($r,$depth,$currhash->{$item},
  766:                     $path.'/'.$item,$is_course,$group);
  767:         } else {
  768:             my $file_name;
  769:             if ($currhash->{$item} =~ m|/([^/]+)$|) {
  770:                 $file_name = $1;
  771:             } else {
  772:                 $file_name = $currhash->{$item};
  773:             }
  774:             my $have_meta = exists($dirlist{$file_name.'.meta'});
  775:             my $url;
  776:             if ($is_course) {
  777:                 $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
  778:                     '/portfolio/'.$currhash->{$item};
  779:             } else {
  780:                 $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.$currhash->{$item};
  781:             }
  782:             my $showname;
  783:             if ($have_meta) {
  784:                 $showname = &Apache::lonnet::metadata($url,'title');
  785:             }
  786:             if ($showname eq '') {
  787:                 $showname = $file_name;
  788:             } else {
  789:                 $showname = $file_name.' ('.$showname.')';
  790:             }
  791: 
  792:             $showname=&HTML::Entities::encode($showname,'<>&"');
  793:             $output .= '<a href="'.$url.'">'.
  794:                 '<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
  795:                 '&nbsp;'.$showname.'</a>';
  796:             $output.='</td><td>';
  797:             if ($have_meta) {
  798:                 $output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Metadata').'" src="'.
  799:                     &Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.png').
  800:                     '" class="LC_icon" /></a>';
  801:             }
  802:             $output .= '</td>'
  803:                 .&Apache::loncommon::end_data_table_row();
  804:         }
  805:     } 
  806:     return $output;
  807: }
  808: 
  809: sub aboutme_access {
  810:     my ($uname,$udom) = @_;
  811:     my $privcheck = $env{'request.course.id'};
  812:     my $sec;
  813:     if ($env{'request.course.sec'} ne '') {
  814:         $sec = $env{'request.course.sec'};
  815:         $privcheck .= '/'.$sec;
  816:     }
  817:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  818:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  819:     if (($cdom eq '') || ($cnum eq '')) {
  820:         my %coursehash = &Apache::lonnet::coursedescription($env{'request.course.id'});
  821:         $cdom = $coursehash{'domain'};
  822:         $cnum = $coursehash{'cnum'};
  823:     }
  824:     if ((&Apache::lonnet::allowed('srm',$privcheck)) ||
  825:         (&Apache::lonnet::allowed('dff',$privcheck))) {
  826:         if (&Apache::lonnet::in_course($uname,$udom,$cnum,$cdom,undef,1)) {
  827:             return 1;
  828:         }
  829:     }
  830:     return;
  831: }
  832: 
  833: 1;
  834: __END__

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