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