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

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

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