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