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