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