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