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