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