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