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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # "About Me" Personal Information
1.1       www         3: #
1.57    ! albertel    4: # $Id: lonaboutme.pm,v 1.56 2006/09/21 15:50:10 albertel Exp $
1.1       www         5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: 
                     29: package Apache::lonaboutme;
                     30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common);
                     33: use Apache::loncommon;
                     34: use Apache::lonnet;
1.2       www        35: use Apache::lontexconvert;
1.12      www        36: use Apache::lonfeedback;
1.39      www        37: use Apache::lonrss();
1.17      www        38: use Apache::lonlocal;
1.41      albertel   39: use Apache::lonmsgdisplay();
1.52      albertel   40: use HTML::Entities();
1.1       www        41: 
                     42: sub handler {
                     43:     my $r = shift;
1.17      www        44:     &Apache::loncommon::content_type($r,'text/html');
1.1       www        45:     $r->send_http_header;
                     46:     return OK if $r->header_only;
1.37      albertel   47:     my $target=$env{'form.grade_target'};
1.1       www        48: # ------------------------------------------------------------ Print the screen
1.40      albertel   49:     if ($target eq 'tex') {
1.37      albertel   50: 	$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.22      sakharuk   51:     }
1.47      albertel   52:     my (undef,undef,$cdom,$cnum,undef,$action)=split(/\//,$r->uri);
1.55      raeburn    53:     my $is_course;
1.2       www        54: # Is this even a user?
                     55:     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
1.40      albertel   56: 	&Apache::loncommon::simple_error_page($r,'No info',
                     57: 					      'No user information available');
1.2       www        58:         return OK;
1.55      raeburn    59:     } else {
                     60:         $is_course = &check_for_course($cdom,$cnum);
1.2       www        61:     }
1.55      raeburn    62: 
1.2       www        63: # --------------------------------------------------------- The syllabus fields
1.17      www        64:     my %syllabusfields=&Apache::lonlocal::texthash(
1.3       www        65:        'aaa_contactinfo'   => 'Contact Information',
                     66:        'bbb_aboutme'       => 'About Me',
                     67:        'ccc_webreferences' => 'Web References');
1.2       www        68: 
1.13      www        69: # ------------------------------------------------------------ Get Query String
1.47      albertel   70:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                     71: 					    ['forceedit','forcestudent',
                     72: 					     'register']);
1.43      raeburn    73: 
                     74: # ----------------------------------------------- Available Portfolio file display 
1.47      albertel   75:     if (($target ne 'tex') && ($action eq 'portfolio')) {
1.55      raeburn    76:         &display_portfolio_header($r,$is_course);
                     77:         &display_portfolio_files($r,$is_course);
1.43      raeburn    78:         $r->print(&Apache::loncommon::end_page());
                     79:         return OK;
                     80:     }
                     81: 
1.55      raeburn    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: 
1.2       www        99: # --------------------------------------------------------------- Force Student
                    100:     my $forcestudent='';
1.37      albertel  101:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.43      raeburn   102: 
                    103:     my $forceregister = '';
                    104:     if ($forcestudent eq '') {
                    105:         $forceregister = $env{'form.register'};
                    106:     }
1.2       www       107:        
                    108: # --------------------------------------- There is such a user, get environment
                    109:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.22      sakharuk  110:     if ($target ne 'tex') {
1.40      albertel  111: 	my $start_page = 
                    112: 	    &Apache::loncommon::start_page("Personal Information",undef,
                    113: 					   {'function'       => $forcestudent,
1.47      albertel  114:  					    'domain'         => $cdom,
1.40      albertel  115: 					    'force_register' =>
1.43      raeburn   116: 						            $forceregister,});
1.40      albertel  117: 	$r->print($start_page);
1.22      sakharuk  118: 	$r->print('<h1>'.&Apache::loncommon::plainname($cnum,$cdom).'</h1>');
                    119:     } else {
                    120: 	$r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
                    121:     }
1.6       www       122:     if ($courseenv{'nickname'}) {
                    123:        $r->print(
1.7       albertel  124:          '<h2>&quot;'.$courseenv{'nickname'}.
1.6       www       125:          '&quot;</h2>');
                    126:     }
1.22      sakharuk  127:     if ($target ne 'tex') {
                    128: 	$r->print('<h3>'.$Apache::lonnet::domaindescription{$cdom}.'</h3>'.
1.39      www       129: 		  '<p>'.&Apache::loncommon::messagewrapper('Send me a message',$cnum,$cdom).'</p>'.&Apache::lonrss::advertisefeeds($cnum,$cdom));
1.22      sakharuk  130:     } else {
                    131: 	$r->print('\textbf{'.$Apache::lonnet::domaindescription{$cdom}.'}\\\\');
                    132:     }
1.2       www       133:     my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
                    134:     my $allowed=0;
                    135: 
1.1       www       136: # does this user have privileges to post, etc?
1.2       www       137: 
1.37      albertel  138:        my $privleged=$allowed=(($env{'user.name'} eq $cnum) && 
                    139: 			       ($env{'user.domain'} eq $cdom));
1.23      sakharuk  140:        if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.2       www       141:  
                    142:        if ($allowed) {
1.43      raeburn   143:            my $query_string = &build_query_string({'forcestudent' => '1',});
1.32      albertel  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>'.
1.43      raeburn   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>'.
1.32      albertel  148: 		     &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
                    149:        } elsif ($privleged && $target ne 'tex') {
1.43      raeburn   150:            my $query_string = &build_query_string({'forceedit' => '1',});
                    151: 	   $r->print('<p><a href="'.$r->uri.$query_string.'"><font size="+1">'.
1.32      albertel  152: 		     &mt('Edit').'</font></a></p>');
                    153:        }
1.37      albertel  154:       if (($env{'form.uploaddoc.filename'}) &&
                    155:           ($env{'form.storeupl'}) && ($allowed)) {
                    156:  	  if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
1.24      albertel  157: 	      if ($syllabus{'uploaded.photourl'}) {
                    158: 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
                    159: 	      }
                    160: 	      $syllabus{'uploaded.photourl'}=
                    161:                  &Apache::lonnet::userfileupload('uploaddoc',undef,'aboutme');
1.3       www       162:  	  }
                    163:           $syllabus{'uploaded.lastmodified'}=time;
                    164:           &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
                    165:        }
1.37      albertel  166:     if ($allowed && $env{'form.delupl'}) {
1.32      albertel  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:     }
1.37      albertel  173:        if (($allowed) && ($env{'form.storesyl'})) {
1.57    ! albertel  174: 	   foreach my $syl_field (keys(%syllabusfields)) {
        !           175:                my $field=$env{'form.'.$syl_field};
1.2       www       176:                $field=~s/\s+$//s;
1.11      www       177:                $field=&Apache::lonfeedback::clear_out_html($field,
1.37      albertel  178:                                                            $env{'user.adv'});
1.57    ! albertel  179: 	       $syllabus{$syl_field}=$field;
1.2       www       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)) {
1.5       www       187:        my $lastmod=$syllabus{'uploaded.lastmodified'};
1.18      www       188:        $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
                    189:        $r->print(&mt('Last updated').': '.$lastmod);
1.3       www       190:        if ($syllabus{'uploaded.photourl'}) {
1.24      albertel  191: 	   &Apache::lonnet::allowuploaded('/adm/aboutme',
                    192: 					  $syllabus{'uploaded.photourl'});
1.33      matthew   193: 	   my $image=
                    194:                qq{<img src="$syllabus{'uploaded.photourl'}" align="right" />};
1.27      albertel  195: 	   if ($target eq 'tex') {
                    196: 	       $image=&Apache::lonxml::xmlparse($r,'tex',$image);
1.26      sakharuk  197: 	   }
1.27      albertel  198: 	   $r->print($image);
1.3       www       199:        }
1.23      sakharuk  200:        if ($allowed) {
1.3       www       201:            $r->print(
1.32      albertel  202: 	 '<form method="post">
                    203:                <input type="submit" name="delupl" value="Delete Photo" />
                    204:           </form>'.
1.3       www       205: 	 '<form method="post" enctype="multipart/form-data">'.
1.18      www       206:          '<h3>'.&mt('Upload a Photo').'</h3>'.
1.3       www       207:          '<input type="file" name="uploaddoc" size="50">'.
                    208:          '<input type="submit" name="storeupl" value="Upload">'.
                    209: 	 '</form><form method="post">');
1.32      albertel  210: 
1.2       www       211:        }
1.57    ! albertel  212:        foreach my $field (sort(keys(%syllabusfields))) {
        !           213:           if (($syllabus{$field}) || ($allowed)) {
        !           214:               my $message=$syllabus{$field};
1.38      albertel  215: 	      &Apache::lonfeedback::newline_to_br(\$message);
1.2       www       216:               $message
                    217:              =~s/(http\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.29      www       218: 	      if ($allowed) {
                    219: 		  $message=&Apache::lonspeller::markeduptext($message);
                    220: 	      }
1.2       www       221: 	      $message=&Apache::lontexconvert::msgtexconverted($message);
1.22      sakharuk  222: 	      if ($target ne 'tex') {
1.57    ! albertel  223: 		  $r->print('<h3>'.$syllabusfields{$field}.'</h3><blockquote>'.
1.22      sakharuk  224:                             $message.'</blockquote>');
                    225: 	      } else {
1.57    ! albertel  226: 		     $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
1.25      sakharuk  227: 			       &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
1.22      sakharuk  228: 	      }
1.23      sakharuk  229:               if ($allowed) {
1.57    ! albertel  230:                  $r->print('<br /><textarea cols="80" rows="6" name="'.$field.'">'.
        !           231: 			   &HTML::Entities::encode($syllabus{$field},'"&<>').
1.17      www       232:            '</textarea><input type="submit" name="storesyl" value="'.
                    233: 			   &mt('Store').'" />');
1.2       www       234: 	      }
                    235: 	  }
                    236:        }
1.23      sakharuk  237:        if ($allowed) {
1.2       www       238: 	   $r->print('</form>');
                    239:        }
1.46      albertel  240:        if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
1.2       www       241:     } else {
1.17      www       242:        $r->print('<p>'.&mt('No personal information provided').'.</p>');
1.8       www       243:     }
1.43      raeburn   244: 
                    245:     if ($target ne 'tex') {
1.55      raeburn   246:         &print_portfiles_link($r,$is_course);
1.43      raeburn   247:     }
                    248: 
1.37      albertel  249:     if ($env{'request.course.id'}) {
                    250: 	if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})) {
1.22      sakharuk  251: 	    if ($target ne 'tex') {
1.30      sakharuk  252: 		$r->print('<a name="coursecomment" />');
1.22      sakharuk  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").
1.19      www       257: '<br />');
1.41      albertel  258:                 &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
1.31      matthew   259:                 $r->print('<hr />');
                    260:                 if (&Apache::lonnet::allowed('vsa',
1.37      albertel  261:                                              $env{'request.course.id'}) ||
1.31      matthew   262:                     &Apache::lonnet::allowed('vsa',
1.37      albertel  263:                                              $env{'request.course.id'}.'/'.
                    264:                                              $env{'request.course.sec'})) {
1.35      matthew   265:                     $r->print(&Apache::loncommon::track_student_link
                    266:                               ('View recent activity by this student',
                    267:                                $cnum,$cdom).('&nbsp;'x2));
1.31      matthew   268:                 }
                    269:                 $r->print(&Apache::loncommon::noteswrapper('Add Records',$cnum,$cdom));
1.22      sakharuk  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').'\\\\\\\\');
1.41      albertel  272: 		&Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
1.22      sakharuk  273: 	    }
1.8       www       274:         }
1.1       www       275:     }
1.40      albertel  276:     if ($target ne 'tex') {
                    277: 	$r->print(&Apache::loncommon::end_page());
                    278:     } else {
                    279: 	$r->print('\end{document}');
                    280:     }
1.1       www       281:     return OK;
1.43      raeburn   282: }
                    283: 
                    284: sub aboutme_info {
1.55      raeburn   285:     my ($r,$is_course) = @_;
1.43      raeburn   286:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.55      raeburn   287:     my $name;
                    288:     if (!$is_course) {
                    289:         $name = &Apache::loncommon::plainname($cnum,$cdom);
                    290:     }
1.43      raeburn   291:     return ($cdom,$cnum,$name);
                    292: }
                    293: 
                    294: sub print_portfiles_link {
1.55      raeburn   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);
1.47      albertel  298:     my $query_string = &build_query_string();
1.43      raeburn   299:     my $output;
1.55      raeburn   300:     my %lt = &Apache::lonlocal::texthash(
                    301:                          vpfi => 'Viewable portfolio files',
                    302:                          vgpf => 'Viewable group portfolio files',
                    303:                          difl => 'Display file listing',
                    304:              );                     
1.43      raeburn   305:     if ($filecounts->{'both'} > 0) {
1.55      raeburn   306:         $output = '<h3>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h3>';
1.47      albertel  307:         $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
1.55      raeburn   308:                    $query_string.'">'.$lt{'difl'}.
1.43      raeburn   309:                    '</a><br /><br />';
1.53      raeburn   310:         if ($filecounts->{'both'} == 1) {
1.55      raeburn   311:             if ($is_course) {
                    312:                 $output .= &mt('One group portfolio file is available.').'<ul>';
                    313:             } else {
1.56      albertel  314:                 $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
1.55      raeburn   315:             }
1.53      raeburn   316:         } else {
1.55      raeburn   317:             if ($is_course) {
1.56      albertel  318:                 $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
1.55      raeburn   319:             } else {
                    320:                 $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
                    321:             }
1.53      raeburn   322:         }
1.43      raeburn   323:         if ($filecounts->{'withoutpass'}) {
1.54      albertel  324: 	    $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
1.43      raeburn   325:         }
                    326:         if ($filecounts->{'withpass'}) {
1.54      albertel  327: 	    $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
1.43      raeburn   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'); 
1.47      albertel  339:     my $new = 0;
1.43      raeburn   340:     if (ref($new_items) eq 'HASH') {
1.47      albertel  341:         $new = 1;
1.43      raeburn   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})) {
1.47      albertel  351:             if ((!$new) || (!defined($new_items->{$element}))) {
1.43      raeburn   352:                 $query_string .= '&amp;'.$element.'='.$env{'form.'.$element};
                    353:             }
                    354:         }
                    355:     }
1.47      albertel  356:     if ($new) {
1.43      raeburn   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 {
1.55      raeburn   366:     my ($r,$is_course) = @_;
                    367:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.43      raeburn   368:     my $query_string = &build_query_string();
                    369:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    370:     my $forcestudent='';
                    371:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.55      raeburn   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,
1.43      raeburn   384:                                              'domain'   => $cdom,});
1.55      raeburn   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>';
1.53      raeburn   396:     }
1.43      raeburn   397:     $r->print($output);
                    398:     return;
                    399: }
                    400: 
                    401: sub display_portfolio_files {
1.55      raeburn   402:     my ($r,$is_course) = @_;
                    403:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.47      albertel  404:     my %lt = ( withoutpass => 'passphrase not required',
                    405: 	       withpass    => 'passphrase protected',
                    406: 	       both        => 'all access types ',);
                    407:     %lt = &Apache::lonlocal::texthash(%lt);
                    408: 
1.43      raeburn   409:     my $portaccess = 'withoutpass';
                    410:     if (exists($env{'form.portaccess'})) {
                    411:         $portaccess = $env{'form.portaccess'};
                    412:     }
1.47      albertel  413: 
1.45      albertel  414:     my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
                    415: 	.'" name="displaystatus" method="post">'.
                    416: 	&mt('File access type: ').'<select name="portaccess">';
1.43      raeburn   417:     foreach my $type ('withoutpass','withpass','both') {
                    418:         $output .= '<option value="'.$type.'" ';
                    419:         if ($portaccess eq $type) {
                    420:             $output .= 'selected="selected"';
                    421:         }
1.53      raeburn   422:         $output .= '>'.$lt{$type}.'</option>';
1.43      raeburn   423:     }
                    424:     $output .= '</select>'."\n".
                    425:                '<input type="submit" name="portaccessbutton" value="'.
1.47      albertel  426:                &mt('Update display').'" />';
1.43      raeburn   427:     $output .= '</form><br /><br />';
                    428:     $r->print($output);
1.55      raeburn   429:     my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course);
1.53      raeburn   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.
1.55      raeburn   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>');
1.53      raeburn   440:     }
1.43      raeburn   441:     return;
                    442: }
                    443: 
                    444: sub portfolio_files {
1.55      raeburn   445:     my ($r,$mode,$lt,$is_course) = @_;
                    446:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.43      raeburn   447:     my $filecounts = {
                    448:                        withpass    => 0,
                    449:                        withoutpass => 0,
                    450:                        both        => 0,
                    451:                      };
                    452:     my $current_permissions =
1.44      albertel  453: 	&Apache::lonnet::get_portfile_permissions($cdom,$cnum);
1.43      raeburn   454:     my %access_controls = 
1.44      albertel  455: 	&Apache::lonnet::get_access_controls($current_permissions);
1.43      raeburn   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: 
1.55      raeburn   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});
1.43      raeburn   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);
1.55      raeburn   540:             my $lasthash = $allfileshash;
1.43      raeburn   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'};
1.55      raeburn   558:     my $output;
1.43      raeburn   559:     if ($mode eq 'listfiles') {
1.55      raeburn   560:         if ($filecounts->{'both'} > 0) {
1.45      albertel  561:             $output = &portfolio_table_start();
1.55      raeburn   562:             $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
                    563:                                         $group);
1.43      raeburn   564:             $output .= '</table>';
                    565:         }
1.45      albertel  566:     }
1.55      raeburn   567:     return $output;
1.45      albertel  568: }
                    569: 
1.43      raeburn   570: sub parse_directory {
1.55      raeburn   571:     my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
                    572:     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.45      albertel  573:     $depth++;
                    574:     my $output;
1.49      albertel  575: 
1.55      raeburn   576:     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
                    577:                                                                 $group);
1.49      albertel  578:     my %dirlist = map {
                    579: 	    ((split('&',$_,2))[0],1)
                    580: 	} &Apache::lonnet::dirlist($path,$cdom,$cnum,$portfolio_root);
1.43      raeburn   581:     foreach my $item (sort(keys(%{$currhash}))) {
1.45      albertel  582:         $output .= &portfolio_row_start();
                    583:         $output .= '<td style="padding-left: '.($depth*25).'px">';
1.43      raeburn   584:         if (ref($currhash->{$item}) eq 'HASH') {
1.45      albertel  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;
1.47      albertel  587: 	    $output .= '</td><td></td></tr>';
1.49      albertel  588:             $output .= &parse_directory($r,$depth,$currhash->{$item},
1.55      raeburn   589: 					$path.'/'.$item,$is_course,$group);
1.43      raeburn   590:         } else {
1.50      albertel  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'});
1.55      raeburn   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:             }
1.43      raeburn   606:             my $showname;
1.50      albertel  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: 
1.45      albertel  616:             $showname=&HTML::Entities::encode($showname,'<>&"');
1.49      albertel  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>';
1.50      albertel  621: 	    if ($have_meta) {
1.49      albertel  622: 		$output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Catalog Information').'" src="'.
1.47      albertel  623: 		&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
1.49      albertel  624: 		'" class="LC_icon" /></a>';
                    625: 	    }
1.45      albertel  626: 	    $output .= '</td></tr>';
1.43      raeburn   627:         }
                    628:     }
1.45      albertel  629:     return $output;
1.43      raeburn   630: }
1.1       www       631: 
1.55      raeburn   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: 
1.1       www       642: 1;
                    643: __END__

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