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