1: # The LearningOnline Network
2: # "About Me" Personal Information
3: #
4: # $Id: lonaboutme.pm,v 1.70.4.2 2009/12/29 18:30:09 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: =pod
30:
31: =head1 NAME
32:
33: Apache::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: package Apache::lonaboutme;
76:
77: use strict;
78: use Apache::Constants qw(:common);
79: use Apache::loncommon;
80: use Apache::lonnet;
81: use Apache::lontexconvert;
82: use Apache::lonfeedback;
83: use Apache::lonrss();
84: use Apache::lonlocal;
85: use Apache::lonmsgdisplay();
86: use HTML::Entities();
87:
88: sub handler {
89: my $r = shift;
90: &Apache::loncommon::content_type($r,'text/html');
91: $r->send_http_header;
92: return OK if $r->header_only;
93: my $target=$env{'form.grade_target'};
94: # ------------------------------------------------------------ Print the screen
95: if ($target eq 'tex') {
96: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
97: }
98: my (undef,undef,$cdom,$cnum,undef,$action)=split(/\//,$r->uri);
99: my $is_course;
100: # Is this even a user?
101: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
102: &Apache::loncommon::simple_error_page($r,'No info',
103: 'No user information available');
104: return OK;
105: } else {
106: $is_course = &Apache::lonnet::is_course($cdom,$cnum);
107: }
108:
109: my $candisplay = 1;
110: if (!$is_course) {
111: if ($action ne 'portfolio') {
112: $candisplay = &Apache::lonnet::usertools_access($cnum,$cdom,'aboutme');
113: if ((!$candisplay) && ($env{'request.course.id'})) {
114: $candisplay = &aboutme_access($cnum,$cdom);
115: }
116: if (!$candisplay) {
117: if ($target eq 'tex') {
118: $r->print('\noindent{\large\textbf{'.&mt('No user home page available').'}}\\\\\\\\');
119: } else {
120: $r->print(&Apache::loncommon::start_page("Personal Information Page"));
121: $r->print('<h2>'.&mt('No personal information page available') .'</h2>'.
122: &mt('This is a result of one of the following:').'<ul>'.
123: '<li>'.&mt('The administrator of this domain has disabled personal information page functionality for this specific user.').'</li>'.
124: '<li>'.&mt('The domain has been configured to disable, by default, personal information page functionality for all users in the domain.').'</li>'.
125: '</ul>');
126: $r->print(&Apache::loncommon::end_page());
127: }
128: return OK;
129: }
130: }
131: }
132:
133: # --------------------------------------------------------- The syllabus fields
134: my %syllabusfields=&Apache::lonlocal::texthash(
135: 'aaa_contactinfo' => 'Contact Information',
136: 'bbb_aboutme' => 'Personal Information',
137: 'ccc_webreferences' => 'Web References');
138:
139: # ------------------------------------------------------------ Get Query String
140: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
141: ['forceedit','forcestudent',
142: 'register','popup']);
143:
144: # ----------------------------------------------- Available Portfolio file display
145: if (($target ne 'tex') && ($action eq 'portfolio')) {
146: &display_portfolio_header($r,$is_course);
147: if ((!$is_course) && (!&Apache::lonnet::usertools_access($cnum,$cdom,'portfolio'))) {
148: $r->print('<h2>'.&mt('No user portfolio available') .'</h2>'.
149: &mt('This is a result of one of the following:').'<ul>'.
150: '<li>'.&mt('The administrator of this domain has disabled portfolio functionality for this specific user.').'</li>'.
151: '<li>'.&mt('The domain has been configured to disable, by default, portfolio functionality for all users in the domain.').'</li>'.
152: '</ul>');
153: } else {
154: my ($blocked,$blocktext) =
155: &Apache::loncommon::blocking_status('port',$cnum,$cdom);
156: if (!$blocked) {
157: &display_portfolio_files($r,$is_course);
158: } else {
159: $r->print($blocktext);
160: }
161: $r->print(&Apache::loncommon::end_page());
162: return OK;
163: }
164: }
165:
166: if ($is_course) {
167: if ($target ne 'tex') {
168: my $brcrum = [{href=>"/adm/navmaps",text=>"Navigate Course Contents"},
169: {href=>"/adm/aboutme",text=>"Course Information"}];
170: my $start_page =
171: &Apache::loncommon::start_page(
172: "Course Information",
173: undef,
174: {'function' => $env{'forcestudent'},
175: 'domain' => $cdom,
176: 'force_register' => $env{'forceregister'},
177: 'bread_crumbs' => $brcrum});
178: $r->print($start_page);
179: $r->print('<h2>'.&mt('Group Portfolio').'</h2>');
180: &print_portfiles_link($r,$is_course);
181: $r->print(&Apache::loncommon::end_page());
182: }
183: return OK;
184: }
185:
186: # --------------------------------------------------------------- Force Student
187: my $forcestudent='';
188: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
189:
190: my $forceregister = '';
191: if ($forcestudent eq '') {
192: $forceregister = $env{'form.register'};
193: }
194:
195: # --------------------------------------- There is such a user, get environment
196: my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
197: if ($target ne 'tex') {
198: my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
199: my $args = {'function' => $forcestudent,
200: 'domain' => $cdom,
201: 'force_register' => $forceregister};
202: if ($env{'form.popup'}) {
203: $args->{'no_nav_bar'} = 1;
204: } else {
205: $args->{'bread_crumbs'} = [{href=>"/adm/$cdom/$cnum/aboutme",text=>"Personal Information Page"}];
206: }
207: my $start_page =
208: &Apache::loncommon::start_page("Personal Information Page",$rss_link,$args);
209: $r->print($start_page);
210: $r->print('<h1>'.&Apache::loncommon::plainname($cnum,$cdom).'</h1>');
211: } else {
212: $r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
213: }
214: if ($courseenv{'nickname'}) {
215: $r->print(
216: '<h2>"'.$courseenv{'nickname'}.
217: '"</h2>');
218: }
219: if ($target ne 'tex') {
220: $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>'.
221: '<p>'.&Apache::loncommon::messagewrapper(&mt('Send me a message'),$cnum,$cdom).'</p>'.&Apache::lonrss::advertisefeeds($cnum,$cdom));
222: } else {
223: $r->print('\textbf{'.&Apache::lonnet::domain($cdom,'description').'}\\\\');
224: }
225: my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
226: my $allowed=0;
227:
228: # does this user have privileges to post, etc?
229:
230: my $privleged=$allowed=(($env{'user.name'} eq $cnum) &&
231: ($env{'user.domain'} eq $cdom));
232: if ($forcestudent or $target eq 'tex') { $allowed=0; }
233:
234: if ($allowed) {
235: my $query_string = &build_query_string({'forcestudent' => '1','popup' => $env{'form.popup'}});
236: $r->print('<p class="LC_info"><b>'.&mt('Privacy Note:').'</b> '.
237: &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.').
238: '</p>'.
239: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).'</p><p><a href="'.$r->uri.$query_string.'">'.&mt('Show Public View').'</a>'.
240: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
241: } elsif ($privleged && $target ne 'tex') {
242: my $query_string = &build_query_string({'forceedit' => '1','popup' => $env{'form.popup'}});
243: $r->print('<p><a href="'.$r->uri.$query_string.'"><font size="+1">'.
244: &mt('Edit').'</font></a></p>');
245: }
246: if (($env{'form.uploaddoc.filename'}) &&
247: ($env{'form.storeupl'}) && ($allowed)) {
248: if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
249: if ($syllabus{'uploaded.photourl'}) {
250: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
251: }
252: $syllabus{'uploaded.photourl'}=
253: &Apache::lonnet::userfileupload('uploaddoc',undef,'aboutme');
254: }
255: $syllabus{'uploaded.lastmodified'}=time;
256: &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
257: }
258: if ($allowed && $env{'form.delupl'}) {
259: if ($syllabus{'uploaded.photourl'}) {
260: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
261: delete($syllabus{'uploaded.photourl'});
262: &Apache::lonnet::del('aboutme',['uploaded.photourl'],$cdom,$cnum);
263: }
264: }
265: if (($allowed) && ($env{'form.storesyl'})) {
266: foreach my $syl_field (keys(%syllabusfields)) {
267: my $field=$env{'form.'.$syl_field};
268: $field=~s/\s+$//s;
269: $field=&Apache::lonfeedback::clear_out_html($field,
270: $env{'user.adv'});
271: $syllabus{$syl_field}=$field;
272: }
273: $syllabus{'uploaded.lastmodified'}=time;
274: &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
275: }
276:
277: # ---------------------------------------------------------------- Get syllabus
278: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
279: my $lastmod=$syllabus{'uploaded.lastmodified'};
280: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
281: $r->print(&mt('Last updated').': '.$lastmod);
282: if ($syllabus{'uploaded.photourl'}) {
283: &Apache::lonnet::allowuploaded('/adm/aboutme',
284: $syllabus{'uploaded.photourl'});
285: my $image=
286: qq{<img src="$syllabus{'uploaded.photourl'}" align="right" />};
287: if ($target eq 'tex') {
288: $image=&Apache::lonxml::xmlparse($r,'tex',$image);
289: }
290: $r->print($image);
291: }
292: if ($allowed) {
293: $r->print(
294: '<form method="post">
295: <input type="submit" name="delupl" value="'.&mt('Delete Photo').'" />
296: </form>'.
297: '<form method="post" enctype="multipart/form-data">'.
298: '<h3>'.&mt('Upload a Photo').'</h3>'.
299: '<input type="file" name="uploaddoc" size="50" />'.
300: '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />'.
301: '<input type="hidden" name="popup" value="'.$env{'form.popup'}.'" />'.
302: '</form><form method="post">');
303:
304: }
305: foreach my $field (sort(keys(%syllabusfields))) {
306: if (($syllabus{$field}) || ($allowed)) {
307: my $message=$syllabus{$field};
308: &Apache::lonfeedback::newline_to_br(\$message);
309: $message
310: =~s/(http\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
311: if ($allowed) {
312: $message=&Apache::lonspeller::markeduptext($message);
313: }
314: $message=&Apache::lontexconvert::msgtexconverted($message);
315: if ($target ne 'tex') {
316: $r->print('<h3>'.$syllabusfields{$field}.'</h3><blockquote>'.
317: $message.'</blockquote>');
318: } else {
319: $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
320: &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
321: }
322: if ($allowed) {
323: $r->print('<br /><textarea cols="80" rows="6" name="'.$field.'">'.
324: &HTML::Entities::encode($syllabus{$field},'"&<>').
325: '</textarea><input type="submit" name="storesyl" value="'.
326: &mt('Save').'" />');
327: }
328: }
329: }
330: if ($allowed) {
331: if ($env{'form.popup'}) {
332: $r->print('<input type="hidden" name="popup" value="'.
333: $env{'form.popup'}.'" />');
334: }
335: $r->print('</form>');
336: }
337: if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
338: } else {
339: $r->print('<p>'.&mt('No personal information provided').'.</p>');
340: }
341:
342: if ($target ne 'tex') {
343: &print_portfiles_link($r,$is_course);
344: }
345:
346: if ($env{'request.course.id'}
347: && &Apache::lonnet::allowed('srm',$env{'request.course.id'})
348: && &in_course($cdom,$cnum)) {
349: if ($target ne 'tex') {
350: $r->print('<a name="coursecomment" />');
351: $r->print('<hr /><h3>'.
352: &mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'</h3><span class="LC_info">'.
353: &mt('Shared by course faculty and staff').
354: &Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message").
355: '</span><br />');
356: &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
357: $r->print('<hr />');
358: if (&Apache::lonnet::allowed('vsa',
359: $env{'request.course.id'}) ||
360: &Apache::lonnet::allowed('vsa',
361: $env{'request.course.id'}.'/'.
362: $env{'request.course.sec'})) {
363: $r->print(&Apache::loncommon::track_student_link
364: ('View recent activity by this student',
365: $cnum,$cdom).(' 'x2));
366: }
367: $r->print(&Apache::loncommon::noteswrapper(&mt('Add Records'),$cnum,$cdom));
368: } else {
369: $r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
370: &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
371: }
372: }
373: if ($target ne 'tex') {
374: if ($env{'request.course.id'}) {
375: if (&Apache::lonnet::allowed('vgr', $env{'request.course.id'}) ||
376: &Apache::lonnet::allowed('vgr', $env{'request.course.id'}.'/'.
377: $env{'request.course.sec'})) {
378: $r->print('<hr />'.&Apache::loncommon::slot_reservations_link('Slot reservation history',$cnum,$cdom));
379: }
380: }
381: if ($env{'form.popup'}) {
382: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a>');
383: }
384: $r->print(&Apache::loncommon::end_page());
385: } else {
386: $r->print('\end{document}');
387: }
388: return OK;
389: }
390:
391: sub in_course {
392: my ($udom,$uname,$cdom,$cnum,$type) = @_;
393: $type ||= 'any';
394: if (!defined($cdom) || !defined($cnum)) {
395: my $cid = $env{'request.course.id'};
396: $cdom = $env{'course.'.$cid.'.domain'};
397: $cnum = $env{'course.'.$cid.'.num'};
398: }
399: my %roles = &Apache::lonnet::dump('roles',$udom,$uname);
400: my @course_roles = grep(m{^/\Q$cdom\E/\Q$cnum\E[/_]}, keys(%roles));
401: return 0 if (!@course_roles);
402: return 1 if ($type eq 'any');
403: my $now = time();
404: foreach my $role (@course_roles) {
405: my (undef,$role_end,$role_start)=split(/\_/,$roles{$role});
406: my $status = 'active';
407: if ($role_start > 0 && $now < $role_start) {
408: $status = 'future';
409: }
410: if ($role_end > 0 && $now > $role_end) {
411: $status = 'previous';
412: }
413: return 1 if ($status eq $type);
414: }
415: return 0;
416: }
417:
418: sub aboutme_info {
419: my ($r,$is_course) = @_;
420: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
421: my $name;
422: if (!$is_course) {
423: $name = &Apache::loncommon::plainname($cnum,$cdom);
424: }
425: return ($cdom,$cnum,$name);
426: }
427:
428: sub print_portfiles_link {
429: my ($r,$is_course) = @_;
430: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
431: my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
432: $cdom,$cnum,$name);
433: my $query_string = &build_query_string();
434: my $output;
435: my %lt = &Apache::lonlocal::texthash(
436: vpfi => 'Viewable portfolio files',
437: vgpf => 'Viewable group portfolio files',
438: difl => 'Display file listing',
439: );
440: if ($filecounts->{'both'} > 0) {
441: $output = '<h3>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h3>';
442: $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
443: $query_string.'">'.$lt{'difl'}.
444: '</a><br /><br />';
445: if ($filecounts->{'both'} == 1) {
446: if ($is_course) {
447: $output .= &mt('One group portfolio file is available.').'<ul>';
448: } else {
449: $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
450: }
451: } else {
452: if ($is_course) {
453: $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
454: } else {
455: $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
456: }
457: }
458: if ($filecounts->{'withoutpass'}) {
459: $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
460: }
461: if ($filecounts->{'withpass'}) {
462: $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
463: }
464: $output .= '</ul>';
465: }
466: $r->print($output);
467: return;
468: }
469:
470: sub build_query_string {
471: my ($new_items) = @_;
472: my $query_string;
473: my @formelements = ('register');
474: my $new = 0;
475: if (ref($new_items) eq 'HASH') {
476: $new = 1;
477: if (!defined($new_items->{'forceedit'}) &&
478: !defined($new_items->{'forcestudent'})) {
479: push(@formelements,('forceedit','forcestudent'));
480: }
481: } else {
482: push(@formelements,('forceedit','forcestudent'));
483: }
484: foreach my $element (@formelements) {
485: if (exists($env{'form.'.$element})) {
486: if ((!$new) || (!defined($new_items->{$element}))) {
487: $query_string .= '&'.$element.'='.$env{'form.'.$element};
488: }
489: }
490: }
491: if ($new) {
492: foreach my $key (keys(%{$new_items})) {
493: $query_string .= '&'.$key.'='.$new_items->{$key};
494: }
495: }
496: $query_string =~ s/^\&/\?/;
497: return $query_string;
498: }
499:
500: sub display_portfolio_header {
501: my ($r,$is_course) = @_;
502: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
503: my $query_string = &build_query_string();
504: &Apache::lonhtmlcommon::clear_breadcrumbs();
505: my $forcestudent='';
506: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
507:
508: my $output;
509: if ($is_course) {
510: $output =
511: &Apache::loncommon::start_page('Viewable group portfolio files',undef,
512: {'function' => $forcestudent,
513: 'domain' => $cdom,});
514: $output .= '<h3>'.&mt('Group Portfolio files').'</h3>';
515: } else {
516: $output =
517: &Apache::loncommon::start_page('Viewable portfolio files',undef,
518: {'function' => $forcestudent,
519: 'domain' => $cdom,});
520: if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
521: &Apache::lonhtmlcommon::add_breadcrumb
522: ({href => "/adm/$cdom/$cnum/aboutme".$query_string,
523: text => &mt('Personal information Page - [_1]',$name),
524: title => &mt('Go to personal information page for [_1]',$name)}, {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
525: text => &mt('Viewable files - [_1]',$name),
526: title => &mt('Viewable portfolio files for [_1]',$name)}
527: );
528: $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
529: }
530: $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
531: }
532: $r->print($output);
533: return;
534: }
535:
536: sub display_portfolio_files {
537: my ($r,$is_course) = @_;
538: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
539: my %lt = &Apache::lonlocal::texthash(
540: withoutpass => 'passphrase not required',
541: withpass => 'passphrase protected',
542: both => 'all access types ',
543: );
544:
545: my $portaccess = 'withoutpass';
546: if (exists($env{'form.portaccess'})) {
547: $portaccess = $env{'form.portaccess'};
548: }
549:
550: my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
551: .'" name="displaystatus" method="post">'.
552: &mt('File access type: ').'<select name="portaccess">';
553: foreach my $type ('withoutpass','withpass','both') {
554: $output .= '<option value="'.$type.'" ';
555: if ($portaccess eq $type) {
556: $output .= 'selected="selected"';
557: }
558: $output .= '>'.$lt{$type}.'</option>';
559: }
560: $output .= '</select>'."\n".
561: '<input type="submit" name="portaccessbutton" value="'.
562: &mt('Update display').'" />';
563: $output .= '</form><br /><br />';
564: $r->print($output);
565: my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
566: $cdom,$cnum,$name);
567: if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
568: my $query_string = &build_query_string();
569: $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
570: '/aboutme'.$query_string.'">');
571: if ($is_course) {
572: $r->print(&mt('Course Information page'));
573: } else {
574: $r->print(&mt('Information about [_1]',$name));
575: }
576: $r->print('</a>');
577: }
578: return;
579: }
580:
581: sub portfolio_files {
582: my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
583: my $filecounts = {
584: withpass => 0,
585: withoutpass => 0,
586: both => 0,
587: };
588: my $current_permissions =
589: &Apache::lonnet::get_portfile_permissions($cdom,$cnum);
590: my %access_controls =
591: &Apache::lonnet::get_access_controls($current_permissions);
592: my $portaccess;
593: if ($mode eq 'showlink') {
594: $portaccess = 'both';
595: } else {
596: $portaccess = 'withoutpass';
597: if (exists($env{'form.portaccess'})) {
598: $portaccess = $env{'form.portaccess'};
599: }
600: }
601:
602: my $diroutput;
603: if ($is_course) {
604: my %files_by_group;
605: foreach my $filename (sort(keys(%access_controls))) {
606: my ($group,$path) = split('/',$filename,2);
607: $files_by_group{$group}{$path} = $access_controls{$filename};
608: }
609: foreach my $group (sort(keys(%files_by_group))) {
610: my %fileshash;
611: my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
612: $is_course,$filecounts,$mode,
613: $files_by_group{$group},
614: \%fileshash,$group);
615: if ($grpout) {
616: $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
617: }
618: }
619: } else {
620: my %allfileshash;
621: $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
622: $filecounts,$mode,\%access_controls,
623: \%allfileshash);
624: }
625: if ($mode eq 'listfiles') {
626: if ($filecounts->{'both'}) {
627: $r->print($diroutput);
628: } else {
629: my $access_text;
630: if (ref($lt) eq 'HASH') {
631: $access_text = $lt->{$portaccess};
632: }
633: $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
634: }
635: }
636: return $filecounts;
637: }
638:
639: {
640: my $count=0;
641: sub portfolio_table_start {
642: $count=0;
643: return '<table class="LC_aboutme_port">';
644: }
645: sub portfolio_row_start {
646: $count++;
647: my $class = ($count%2)?'LC_odd_row'
648: :'LC_even_row';
649: return '<tr class="'.$class.'">';
650: }
651: }
652:
653: sub build_hierarchy {
654: my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
655: $allfileshash,$group) = @_;
656: foreach my $filename (sort(keys(%{$access_info}))) {
657: my $access_status =
658: &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group, $$access_info{$filename});
659: if ($portaccess eq 'both') {
660: if (($access_status ne 'ok') &&
661: ($access_status !~ /^[^:]+:guest_/)) {
662: next;
663: }
664: } elsif ($portaccess eq 'withoutpass') {
665: if ($access_status ne 'ok') {
666: next;
667: }
668: } elsif ($portaccess eq 'withpass') {
669: if ($access_status !~ /^[^:]+:guest_/) {
670: next;
671: }
672: }
673: if ($mode eq 'listfiles') {
674: $filename =~ s/^\///;
675: my @pathitems = split('/',$filename);
676: my $lasthash = $allfileshash;
677: while (@pathitems > 1) {
678: my $newlevel = shift(@pathitems);
679: if (!exists($lasthash->{$newlevel})) {
680: $lasthash->{$newlevel} = {};
681: }
682: $lasthash = $lasthash->{$newlevel};
683: }
684: $lasthash->{$pathitems[0]} = $filename;
685: }
686: if ($access_status eq 'ok') {
687: $filecounts->{'withoutpass'} ++;
688: } elsif ($access_status =~ /^[^:]+:guest_/) {
689: $filecounts->{'withpass'} ++;
690: }
691: }
692: $filecounts->{'both'} = $filecounts->{'withoutpass'} +
693: $filecounts->{'withpass'};
694: my $output;
695: if ($mode eq 'listfiles') {
696: if ($filecounts->{'both'} > 0) {
697: $output = &portfolio_table_start();
698: $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
699: $group);
700: $output .= '</table>';
701: }
702: }
703: return $output;
704: }
705:
706: sub parse_directory {
707: my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
708: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
709: $depth++;
710: my $output;
711:
712: my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
713: $group);
714: my $getpropath = 1;
715: my %dirlist = map {
716: ((split('&',$_,2))[0],1)
717: } &Apache::lonnet::dirlist($portfolio_root.$path,$cdom,$cnum,$getpropath);
718: foreach my $item (sort(keys(%{$currhash}))) {
719: $output .= &portfolio_row_start();
720: $output .= '<td style="padding-left: '.($depth*25).'px">';
721: if (ref($currhash->{$item}) eq 'HASH') {
722: my $title=&HTML::Entities::encode($item,'<>&"');
723: $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" /> '.$title;
724: $output .= '</td><td></td></tr>';
725: $output .= &parse_directory($r,$depth,$currhash->{$item},
726: $path.'/'.$item,$is_course,$group);
727: } else {
728: my $file_name;
729: if ($currhash->{$item} =~ m|/([^/]+)$|) {
730: $file_name = $1;
731: } else {
732: $file_name = $currhash->{$item};
733: }
734: my $have_meta = exists($dirlist{$file_name.'.meta'});
735: my $url;
736: if ($is_course) {
737: $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
738: '/portfolio/'.$currhash->{$item};
739: } else {
740: $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
741: $currhash->{$item};
742: }
743: my $showname;
744: if ($have_meta) {
745: $showname = &Apache::lonnet::metadata($url,'title');
746: }
747: if ($showname eq '') {
748: $showname = $file_name;
749: } else {
750: $showname = $file_name.' ('.$showname.')';
751: }
752:
753: $showname=&HTML::Entities::encode($showname,'<>&"');
754: $output .= '<a href="'.$url.'">'.
755: '<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
756: ' '.$showname.'</a>';
757: $output.='</td><td>';
758: if ($have_meta) {
759: $output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Metadata').'" src="'.
760: &Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
761: '" class="LC_icon" /></a>';
762: }
763: $output .= '</td></tr>';
764: }
765: }
766: return $output;
767: }
768:
769: sub aboutme_access {
770: my ($uname,$udom) = @_;
771: my $privcheck = $env{'request.course.id'};
772: my $sec;
773: if ($env{'request.course.sec'} ne '') {
774: $sec = $env{'request.course.sec'};
775: $privcheck .= '/'.$sec;
776: }
777: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
778: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
779: if (($cdom eq '') || ($cnum eq '')) {
780: my %coursehash = &coursedescription($env{'request.course.id'});
781: $cdom = $coursehash{'domain'};
782: $cnum = $coursehash{'cnum'};
783: }
784: if ((&Apache::lonnet::allowed('srm',$privcheck)) ||
785: (&Apache::lonnet::allowed('dff',$privcheck))) {
786: if (&in_course($uname,$udom,$cnum,$cdom)) {
787: return 1;
788: }
789: }
790: return;
791: }
792:
793: 1;
794: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>