File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.137: download - view: text, annotated - select for diffs
Mon Jun 8 18:04:45 2009 UTC (14 years, 11 months ago) by bisitz
Branches: MAIN
CVS tags: HEAD
Just "LC_Box" instead of "LC_ContentBoxSpecial"
- Much shorter
- Always contains some kind of content
- Nothing special (LC_ContentBox doesn't exist besides id for Javascript in londocs.pm)

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

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