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