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