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