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