File:
[LON-CAPA] /
loncom /
interface /
lonaboutme.pm
Revision
1.65:
download - view:
text,
annotated -
select for diffs
Fri Jul 27 00:17:17 2007 UTC (17 years, 2 months ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_6_0,
version_2_5_X,
version_2_5_99_1,
version_2_5_99_0,
version_2_5_2,
version_2_5_1,
version_2_5_0,
version_2_4_99_0,
HEAD
- BUG#5336 - add <link> rss advertisments to the aboutme page and rss pages
1: # The LearningOnline Network
2: # "About Me" Personal Information
3: #
4: # $Id: lonaboutme.pm,v 1.65 2007/07/27 00:17:17 albertel 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: package Apache::lonaboutme;
30:
31: use strict;
32: use Apache::Constants qw(:common);
33: use Apache::loncommon;
34: use Apache::lonnet;
35: use Apache::lontexconvert;
36: use Apache::lonfeedback;
37: use Apache::lonrss();
38: use Apache::lonlocal;
39: use Apache::lonmsgdisplay();
40: use HTML::Entities();
41:
42: sub handler {
43: my $r = shift;
44: &Apache::loncommon::content_type($r,'text/html');
45: $r->send_http_header;
46: return OK if $r->header_only;
47: my $target=$env{'form.grade_target'};
48: # ------------------------------------------------------------ Print the screen
49: if ($target eq 'tex') {
50: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
51: }
52: my (undef,undef,$cdom,$cnum,undef,$action)=split(/\//,$r->uri);
53: my $is_course;
54: # Is this even a user?
55: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
56: &Apache::loncommon::simple_error_page($r,'No info',
57: 'No user information available');
58: return OK;
59: } else {
60: $is_course = &Apache::lonnet::is_course($cdom,$cnum);
61: }
62:
63: # --------------------------------------------------------- The syllabus fields
64: my %syllabusfields=&Apache::lonlocal::texthash(
65: 'aaa_contactinfo' => 'Contact Information',
66: 'bbb_aboutme' => 'About Me',
67: 'ccc_webreferences' => 'Web References');
68:
69: # ------------------------------------------------------------ Get Query String
70: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
71: ['forceedit','forcestudent',
72: 'register']);
73:
74: # ----------------------------------------------- Available Portfolio file display
75: if (($target ne 'tex') && ($action eq 'portfolio')) {
76: &display_portfolio_header($r,$is_course);
77: my ($blocked,$blocktext) =
78: &Apache::loncommon::blocking_status('port',$cnum,$cdom);
79: if (!$blocked) {
80: &display_portfolio_files($r,$is_course);
81: } else {
82: $r->print($blocktext);
83: }
84: $r->print(&Apache::loncommon::end_page());
85: return OK;
86: }
87:
88: if ($is_course) {
89: if ($target ne 'tex') {
90: my $start_page =
91: &Apache::loncommon::start_page(
92: "Course Information",
93: undef,
94: {'function' => $env{'forcestudent'},
95: 'domain' => $cdom,
96: 'force_register' => $env{'forceregister'},});
97: $r->print($start_page);
98: $r->print('<h2>'.&mt('Group files').'</h2>');
99: &print_portfiles_link($r,$is_course);
100: $r->print(&Apache::loncommon::end_page());
101: }
102: return OK;
103: }
104:
105: # --------------------------------------------------------------- Force Student
106: my $forcestudent='';
107: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
108:
109: my $forceregister = '';
110: if ($forcestudent eq '') {
111: $forceregister = $env{'form.register'};
112: }
113:
114: # --------------------------------------- There is such a user, get environment
115: my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
116: if ($target ne 'tex') {
117: my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
118: my $start_page =
119: &Apache::loncommon::start_page("Personal Information", $rss_link,
120: {'function' => $forcestudent,
121: 'domain' => $cdom,
122: 'force_register' =>
123: $forceregister,});
124: $r->print($start_page);
125: $r->print('<h1>'.&Apache::loncommon::plainname($cnum,$cdom).'</h1>');
126: } else {
127: $r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
128: }
129: if ($courseenv{'nickname'}) {
130: $r->print(
131: '<h2>"'.$courseenv{'nickname'}.
132: '"</h2>');
133: }
134: if ($target ne 'tex') {
135: $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>'.
136: '<p>'.&Apache::loncommon::messagewrapper('Send me a message',$cnum,$cdom).'</p>'.&Apache::lonrss::advertisefeeds($cnum,$cdom));
137: } else {
138: $r->print('\textbf{'.&Apache::lonnet::domain($cdom,'description').'}\\\\');
139: }
140: my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
141: my $allowed=0;
142:
143: # does this user have privileges to post, etc?
144:
145: my $privleged=$allowed=(($env{'user.name'} eq $cnum) &&
146: ($env{'user.domain'} eq $cdom));
147: if ($forcestudent or $target eq 'tex') { $allowed=0; }
148:
149: if ($allowed) {
150: my $query_string = &build_query_string({'forcestudent' => '1',});
151: $r->print('<p><b>'.&mt('Privacy Note').':</b> '.
152: &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.').
153: '</p>'.
154: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'</p><p><a href="'.$r->uri.$query_string.'">Show Public View</a>'.
155: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
156: } elsif ($privleged && $target ne 'tex') {
157: my $query_string = &build_query_string({'forceedit' => '1',});
158: $r->print('<p><a href="'.$r->uri.$query_string.'"><font size="+1">'.
159: &mt('Edit').'</font></a></p>');
160: }
161: if (($env{'form.uploaddoc.filename'}) &&
162: ($env{'form.storeupl'}) && ($allowed)) {
163: if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
164: if ($syllabus{'uploaded.photourl'}) {
165: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
166: }
167: $syllabus{'uploaded.photourl'}=
168: &Apache::lonnet::userfileupload('uploaddoc',undef,'aboutme');
169: }
170: $syllabus{'uploaded.lastmodified'}=time;
171: &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
172: }
173: if ($allowed && $env{'form.delupl'}) {
174: if ($syllabus{'uploaded.photourl'}) {
175: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
176: delete($syllabus{'uploaded.photourl'});
177: &Apache::lonnet::del('aboutme',['uploaded.photourl'],$cdom,$cnum);
178: }
179: }
180: if (($allowed) && ($env{'form.storesyl'})) {
181: foreach my $syl_field (keys(%syllabusfields)) {
182: my $field=$env{'form.'.$syl_field};
183: $field=~s/\s+$//s;
184: $field=&Apache::lonfeedback::clear_out_html($field,
185: $env{'user.adv'});
186: $syllabus{$syl_field}=$field;
187: }
188: $syllabus{'uploaded.lastmodified'}=time;
189: &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
190: }
191:
192: # ---------------------------------------------------------------- Get syllabus
193: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
194: my $lastmod=$syllabus{'uploaded.lastmodified'};
195: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
196: $r->print(&mt('Last updated').': '.$lastmod);
197: if ($syllabus{'uploaded.photourl'}) {
198: &Apache::lonnet::allowuploaded('/adm/aboutme',
199: $syllabus{'uploaded.photourl'});
200: my $image=
201: qq{<img src="$syllabus{'uploaded.photourl'}" align="right" />};
202: if ($target eq 'tex') {
203: $image=&Apache::lonxml::xmlparse($r,'tex',$image);
204: }
205: $r->print($image);
206: }
207: if ($allowed) {
208: $r->print(
209: '<form method="post">
210: <input type="submit" name="delupl" value="Delete Photo" />
211: </form>'.
212: '<form method="post" enctype="multipart/form-data">'.
213: '<h3>'.&mt('Upload a Photo').'</h3>'.
214: '<input type="file" name="uploaddoc" size="50">'.
215: '<input type="submit" name="storeupl" value="Upload">'.
216: '</form><form method="post">');
217:
218: }
219: foreach my $field (sort(keys(%syllabusfields))) {
220: if (($syllabus{$field}) || ($allowed)) {
221: my $message=$syllabus{$field};
222: &Apache::lonfeedback::newline_to_br(\$message);
223: $message
224: =~s/(http\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
225: if ($allowed) {
226: $message=&Apache::lonspeller::markeduptext($message);
227: }
228: $message=&Apache::lontexconvert::msgtexconverted($message);
229: if ($target ne 'tex') {
230: $r->print('<h3>'.$syllabusfields{$field}.'</h3><blockquote>'.
231: $message.'</blockquote>');
232: } else {
233: $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
234: &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
235: }
236: if ($allowed) {
237: $r->print('<br /><textarea cols="80" rows="6" name="'.$field.'">'.
238: &HTML::Entities::encode($syllabus{$field},'"&<>').
239: '</textarea><input type="submit" name="storesyl" value="'.
240: &mt('Save').'" />');
241: }
242: }
243: }
244: if ($allowed) {
245: $r->print('</form>');
246: }
247: if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
248: } else {
249: $r->print('<p>'.&mt('No personal information provided').'.</p>');
250: }
251:
252: if ($target ne 'tex') {
253: &print_portfiles_link($r,$is_course);
254: }
255:
256: if ($env{'request.course.id'}
257: && &Apache::lonnet::allowed('srm',$env{'request.course.id'})
258: && &in_course($cdom,$cnum)) {
259: if ($target ne 'tex') {
260: $r->print('<a name="coursecomment" />');
261: $r->print('<hr /><h3>'.
262: &mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'</h3>'.
263: &mt('Shared by course faculty and staff').
264: &Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message").
265: '<br />');
266: &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
267: $r->print('<hr />');
268: if (&Apache::lonnet::allowed('vsa',
269: $env{'request.course.id'}) ||
270: &Apache::lonnet::allowed('vsa',
271: $env{'request.course.id'}.'/'.
272: $env{'request.course.sec'})) {
273: $r->print(&Apache::loncommon::track_student_link
274: ('View recent activity by this student',
275: $cnum,$cdom).(' 'x2));
276: }
277: $r->print(&Apache::loncommon::noteswrapper('Add Records',$cnum,$cdom));
278: } else {
279: $r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
280: &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
281: }
282: }
283: if ($target ne 'tex') {
284: $r->print(&Apache::loncommon::end_page());
285: } else {
286: $r->print('\end{document}');
287: }
288: return OK;
289: }
290:
291: sub in_course {
292: my ($udom,$uname,$cdom,$cnum,$type) = @_;
293: $type ||= 'any';
294: if (!defined($cdom) || !defined($cnum)) {
295: my $cid = $env{'request.course.id'};
296: $cdom = $env{'course.'.$cid.'.domain'};
297: $cnum = $env{'course.'.$cid.'.num'};
298: }
299: my %roles = &Apache::lonnet::dump('roles',$udom,$uname);
300: my @course_roles = grep(m{^/\Q$cdom\E/\Q$cnum\E[/_]}, keys(%roles));
301: return 0 if (!@course_roles);
302: return 1 if ($type eq 'any');
303: my $now = time();
304: foreach my $role (@course_roles) {
305: my (undef,$role_end,$role_start)=split(/\_/,$roles{$role});
306: my $status = 'active';
307: if ($role_start > 0 && $now < $role_start) {
308: $status = 'future';
309: }
310: if ($role_end > 0 && $now > $role_end) {
311: $status = 'previous';
312: }
313: return 1 if ($status eq $type);
314: }
315: return 0;
316: }
317:
318: sub aboutme_info {
319: my ($r,$is_course) = @_;
320: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
321: my $name;
322: if (!$is_course) {
323: $name = &Apache::loncommon::plainname($cnum,$cdom);
324: }
325: return ($cdom,$cnum,$name);
326: }
327:
328: sub print_portfiles_link {
329: my ($r,$is_course) = @_;
330: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
331: my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
332: $cdom,$cnum,$name);
333: my $query_string = &build_query_string();
334: my $output;
335: my %lt = &Apache::lonlocal::texthash(
336: vpfi => 'Viewable portfolio files',
337: vgpf => 'Viewable group portfolio files',
338: difl => 'Display file listing',
339: );
340: if ($filecounts->{'both'} > 0) {
341: $output = '<h3>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h3>';
342: $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
343: $query_string.'">'.$lt{'difl'}.
344: '</a><br /><br />';
345: if ($filecounts->{'both'} == 1) {
346: if ($is_course) {
347: $output .= &mt('One group portfolio file is available.').'<ul>';
348: } else {
349: $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
350: }
351: } else {
352: if ($is_course) {
353: $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
354: } else {
355: $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
356: }
357: }
358: if ($filecounts->{'withoutpass'}) {
359: $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
360: }
361: if ($filecounts->{'withpass'}) {
362: $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
363: }
364: $output .= '</ul>';
365: }
366: $r->print($output);
367: return;
368: }
369:
370: sub build_query_string {
371: my ($new_items) = @_;
372: my $query_string;
373: my @formelements = ('register');
374: my $new = 0;
375: if (ref($new_items) eq 'HASH') {
376: $new = 1;
377: if (!defined($new_items->{'forceedit'}) &&
378: !defined($new_items->{'forcestudent'})) {
379: push(@formelements,('forceedit','forcestudent'));
380: }
381: } else {
382: push(@formelements,('forceedit','forcestudent'));
383: }
384: foreach my $element (@formelements) {
385: if (exists($env{'form.'.$element})) {
386: if ((!$new) || (!defined($new_items->{$element}))) {
387: $query_string .= '&'.$element.'='.$env{'form.'.$element};
388: }
389: }
390: }
391: if ($new) {
392: foreach my $key (keys(%{$new_items})) {
393: $query_string .= '&'.$key.'='.$new_items->{$key};
394: }
395: }
396: $query_string =~ s/^\&/\?/;
397: return $query_string;
398: }
399:
400: sub display_portfolio_header {
401: my ($r,$is_course) = @_;
402: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
403: my $query_string = &build_query_string();
404: &Apache::lonhtmlcommon::clear_breadcrumbs();
405: my $forcestudent='';
406: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
407:
408: my $output;
409: if ($is_course) {
410: $output =
411: &Apache::loncommon::start_page('Viewable group portfolio files',undef,
412: {'function' => $forcestudent,
413: 'domain' => $cdom,});
414: $output .= '<h3>'.&mt('Group Portfolio files').'</h3>';
415: } else {
416: $output =
417: &Apache::loncommon::start_page('Viewable portfolio files',undef,
418: {'function' => $forcestudent,
419: 'domain' => $cdom,});
420: if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
421: &Apache::lonhtmlcommon::add_breadcrumb
422: ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
423: text=>"Personal information - $name",
424: title=>"Go to personal information page for $name"}, {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
425: text=>"Viewable files - $name",
426: title=>"Viewable portfolio files for $name"}
427: );
428: $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
429: }
430: $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
431: }
432: $r->print($output);
433: return;
434: }
435:
436: sub display_portfolio_files {
437: my ($r,$is_course) = @_;
438: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
439: my %lt = ( withoutpass => 'passphrase not required',
440: withpass => 'passphrase protected',
441: both => 'all access types ',);
442: %lt = &Apache::lonlocal::texthash(%lt);
443:
444: my $portaccess = 'withoutpass';
445: if (exists($env{'form.portaccess'})) {
446: $portaccess = $env{'form.portaccess'};
447: }
448:
449: my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
450: .'" name="displaystatus" method="post">'.
451: &mt('File access type: ').'<select name="portaccess">';
452: foreach my $type ('withoutpass','withpass','both') {
453: $output .= '<option value="'.$type.'" ';
454: if ($portaccess eq $type) {
455: $output .= 'selected="selected"';
456: }
457: $output .= '>'.$lt{$type}.'</option>';
458: }
459: $output .= '</select>'."\n".
460: '<input type="submit" name="portaccessbutton" value="'.
461: &mt('Update display').'" />';
462: $output .= '</form><br /><br />';
463: $r->print($output);
464: my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
465: $cdom,$cnum,$name);
466: if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
467: my $query_string = &build_query_string();
468: $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
469: '/aboutme'.$query_string.'">');
470: if ($is_course) {
471: $r->print(&mt('Course Information page'));
472: } else {
473: $r->print(&mt('Information about [_1]',$name));
474: }
475: $r->print('</a>');
476: }
477: return;
478: }
479:
480: sub portfolio_files {
481: my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
482: my $filecounts = {
483: withpass => 0,
484: withoutpass => 0,
485: both => 0,
486: };
487: my $current_permissions =
488: &Apache::lonnet::get_portfile_permissions($cdom,$cnum);
489: my %access_controls =
490: &Apache::lonnet::get_access_controls($current_permissions);
491: my $portaccess;
492: if ($mode eq 'showlink') {
493: $portaccess = 'both';
494: } else {
495: $portaccess = 'withoutpass';
496: if (exists($env{'form.portaccess'})) {
497: $portaccess = $env{'form.portaccess'};
498: }
499: }
500:
501: my $diroutput;
502: if ($is_course) {
503: my %files_by_group;
504: foreach my $filename (sort(keys(%access_controls))) {
505: my ($group,$path) = split('/',$filename,2);
506: $files_by_group{$group}{$path} = $access_controls{$filename};
507: }
508: foreach my $group (sort(keys(%files_by_group))) {
509: my %fileshash;
510: my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
511: $is_course,$filecounts,$mode,
512: $files_by_group{$group},
513: \%fileshash,$group);
514: if ($grpout) {
515: $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
516: }
517: }
518: } else {
519: my %allfileshash;
520: $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
521: $filecounts,$mode,\%access_controls,
522: \%allfileshash);
523: }
524: if ($mode eq 'listfiles') {
525: if ($filecounts->{'both'}) {
526: $r->print($diroutput);
527: } else {
528: my $access_text;
529: if (ref($lt) eq 'HASH') {
530: $access_text = $lt->{$portaccess};
531: }
532: $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
533: }
534: }
535: return $filecounts;
536: }
537:
538: {
539: my $count=0;
540: sub portfolio_table_start {
541: $count=0;
542: return '<table class="LC_aboutme_port">';
543: }
544: sub portfolio_row_start {
545: $count++;
546: my $class = ($count%2)?'LC_odd_row'
547: :'LC_even_row';
548: return '<tr class="'.$class.'">';
549: }
550: }
551:
552: sub build_hierarchy {
553: my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
554: $allfileshash,$group) = @_;
555: foreach my $filename (sort(keys(%{$access_info}))) {
556: my $access_status =
557: &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group, $$access_info{$filename});
558: if ($portaccess eq 'both') {
559: if (($access_status ne 'ok') &&
560: ($access_status !~ /^[^:]+:guest_/)) {
561: next;
562: }
563: } elsif ($portaccess eq 'withoutpass') {
564: if ($access_status ne 'ok') {
565: next;
566: }
567: } elsif ($portaccess eq 'withpass') {
568: if ($access_status !~ /^[^:]+:guest_/) {
569: next;
570: }
571: }
572: if ($mode eq 'listfiles') {
573: $filename =~ s/^\///;
574: my @pathitems = split('/',$filename);
575: my $lasthash = $allfileshash;
576: while (@pathitems > 1) {
577: my $newlevel = shift(@pathitems);
578: if (!exists($lasthash->{$newlevel})) {
579: $lasthash->{$newlevel} = {};
580: }
581: $lasthash = $lasthash->{$newlevel};
582: }
583: $lasthash->{$pathitems[0]} = $filename;
584: }
585: if ($access_status eq 'ok') {
586: $filecounts->{'withoutpass'} ++;
587: } elsif ($access_status =~ /^[^:]+:guest_/) {
588: $filecounts->{'withpass'} ++;
589: }
590: }
591: $filecounts->{'both'} = $filecounts->{'withoutpass'} +
592: $filecounts->{'withpass'};
593: my $output;
594: if ($mode eq 'listfiles') {
595: if ($filecounts->{'both'} > 0) {
596: $output = &portfolio_table_start();
597: $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
598: $group);
599: $output .= '</table>';
600: }
601: }
602: return $output;
603: }
604:
605: sub parse_directory {
606: my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
607: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
608: $depth++;
609: my $output;
610:
611: my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
612: $group);
613: my %dirlist = map {
614: ((split('&',$_,2))[0],1)
615: } &Apache::lonnet::dirlist($path,$cdom,$cnum,$portfolio_root);
616: foreach my $item (sort(keys(%{$currhash}))) {
617: $output .= &portfolio_row_start();
618: $output .= '<td style="padding-left: '.($depth*25).'px">';
619: if (ref($currhash->{$item}) eq 'HASH') {
620: my $title=&HTML::Entities::encode($item,'<>&"');
621: $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" /> '.$title;
622: $output .= '</td><td></td></tr>';
623: $output .= &parse_directory($r,$depth,$currhash->{$item},
624: $path.'/'.$item,$is_course,$group);
625: } else {
626: my $file_name;
627: if ($currhash->{$item} =~ m|/([^/]+)$|) {
628: $file_name = $1;
629: } else {
630: $file_name = $currhash->{$item};
631: }
632: my $have_meta = exists($dirlist{$file_name.'.meta'});
633: my $url;
634: if ($is_course) {
635: $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
636: '/portfolio/'.$currhash->{$item};
637: } else {
638: $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
639: $currhash->{$item};
640: }
641: my $showname;
642: if ($have_meta) {
643: $showname = &Apache::lonnet::metadata($url,'title');
644: }
645: if ($showname eq '') {
646: $showname = $file_name;
647: } else {
648: $showname = $file_name.' ('.$showname.')';
649: }
650:
651: $showname=&HTML::Entities::encode($showname,'<>&"');
652: $output .= '<a href="'.$url.'">'.
653: '<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
654: ' '.$showname.'</a>';
655: $output.='</td><td>';
656: if ($have_meta) {
657: $output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Catalog Information').'" src="'.
658: &Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
659: '" class="LC_icon" /></a>';
660: }
661: $output .= '</td></tr>';
662: }
663: }
664: return $output;
665: }
666:
667: 1;
668: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>