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