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