File:  [LON-CAPA] / loncom / interface / lonaboutme.pm
Revision 1.57: download - view: text, annotated - select for diffs
Mon Oct 23 18:48:46 2006 UTC (17 years, 6 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- deathe to $_

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

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