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