1: # The LearningOnline Network
2: # Personal Information Page
3: #
4: # $Id: lonaboutme.pm,v 1.101 2009/02/20 17:45:40 neumanie 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 Page"));
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' => 'Personal Information Page',
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 Page"}];
209: my $start_page =
210: &Apache::loncommon::start_page("Personal Information Page",$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>');
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:
238: if ($allowed) {
239:
240: $r->print('<p><b>'.&mt('Privacy Note').':</b> '.
241: &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.'). '</p><p>'.
242: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).'</p>');
243: }
244:
245: if (($env{'form.uploaddoc.filename'}) &&
246: ($env{'form.storeupl'}) && ($allowed)) {
247: if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
248: if ($syllabus{'uploaded.photourl'}) {
249: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
250: }
251: $syllabus{'uploaded.photourl'}=
252: &Apache::lonnet::userphotoupload('uploaddoc','aboutme');
253: }
254: $syllabus{'uploaded.lastmodified'}=time;
255: &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
256: }
257: if ($allowed && $env{'form.delupl'}) {
258: if ($syllabus{'uploaded.photourl'}) {
259: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
260: delete($syllabus{'uploaded.photourl'});
261: &Apache::lonnet::del('aboutme',['uploaded.photourl'],$cdom,$cnum);
262: }
263: }
264: if (($allowed) && ($env{'form.storesyl'})) {
265: foreach my $syl_field (keys(%syllabusfields)) {
266: my $field=$env{'form.'.$syl_field};
267: $field=~s/\s+$//s;
268: $field=&Apache::lonfeedback::clear_out_html($field,
269: $env{'user.adv'});
270: $syllabus{$syl_field}=$field;
271: }
272: $syllabus{'uploaded.lastmodified'}=time;
273: &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
274: }
275:
276: my $lastmod;
277: my $image;
278: # ---------------------------------------------------------------- Get syllabus
279: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
280: $lastmod=$syllabus{'uploaded.lastmodified'};
281: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
282: $r->print('<br />'.&mt('Last updated').': '.$lastmod);
283:
284:
285: if ($syllabus{'uploaded.photourl'}) {
286: &Apache::lonnet::allowuploaded('/adm/aboutme',
287: $syllabus{'uploaded.photourl'});
288:
289: #This call is to resize all "Personal Information" images in the LonCapa System. When its done, you can remove this line.
290: &Apache::lonnet::resizeImage(&Apache::lonnet::filelocation('',$syllabus{'uploaded.photourl'}));
291: #---End Resize---
292:
293: $image=qq{<img name="userPhoto" src="$syllabus{'uploaded.photourl'} " class="LC_AboutMe_Image" />};
294:
295: if ($target eq 'tex') {
296: $image=&Apache::lonxml::xmlparse($r,'tex',$image);
297: }
298:
299: }
300: #---Print Functions
301: if( $target ne 'tex'){
302: &Apache::lontemplate::print_start_page_functions($r);
303: if($allowed){
304: $query_string = &build_query_string({'forcestudent' => '1','popup' => $env{'form.popup'}});
305: &Apache::lontemplate::print_functions_content($r,'<a href="'.$r->uri.$query_string.'">'.&mt('Show Public View').'</a>'.&Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView'));
306: }elsif($privleged){
307: $query_string = &build_query_string({'forceedit' => '1','popup' => $env{'form.popup'}});
308: &Apache::lontemplate::print_functions_content($r,'<a href="'.$r->uri.$query_string.'">'. &mt('Edit').'</a>');
309: }
310: &Apache::lontemplate::print_functions_content($r,&Apache::lontemplate::send_message($r,$cnum,$cdom));
311:
312: if ($env{'request.course.id'} && &Apache::lonnet::allowed('srm',$env{'request.course.id'}) && &in_course($cdom,$cnum)) {
313: if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) || &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
314: $env{'request.course.sec'})) {
315: &Apache::lontemplate::print_functions_content($r,&Apache::loncommon::track_student_link('View recent activity by this student',
316: $cnum,$cdom).(' 'x2));
317: }
318: &Apache::lontemplate::print_functions_content($r,&Apache::loncommon::noteswrapper(&mt('Add Records'),$cnum,$cdom));
319: }
320: &Apache::lontemplate::print_end_page_functions($r);
321: }
322: if ($allowed) {
323: $r->print(
324: '<form method="post" enctype="multipart/form-data">'.
325: '<h3>'.&mt('Upload a Photo').'</h3>'.
326: '<input type="file" name="uploaddoc" size="50" />'.
327: '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />'.
328: '<input type="hidden" name="popup" value="'.$env{'form.popup'}.'" />'.
329: '</form><form method="post"><input type="submit" name="delupl" value="'.&mt('Delete Photo').'" /> </form><p>
330: ');
331:
332: }
333:
334: if($allowed) {
335: $r->print('<form method="post">');
336: }
337:
338: if($target ne 'tex') #print Image
339: {
340: &Apache::lontemplate::start_ContentBox($r);
341: &Apache::lontemplate::end_ContentBox($r);
342: $r->print($image);
343:
344: }#End Print Image
345:
346: #Print Content eg. Contactinfo aboutme,...
347: &Apache::lontemplate::print_aboutme_content_template($r,$allowed,$target,\%syllabusfields,\%syllabus);
348: #End Print Content
349:
350: if($target ne 'tex')#Begin Print RSS and portfiles
351: {
352: &print_portfiles_link($r,$is_course);
353: if(&Apache::lonrss::advertisefeeds($cnum,$cdom) ne ''){
354: &Apache::lontemplate::print_template($r,'RSS Feeds and Blogs',&Apache::lonrss::advertisefeeds($cnum,$cdom),1,'LC_ContentBoxSpecial');
355: }
356:
357: } #End Print RSS and portfiles
358:
359:
360: if ($allowed) {
361: if ($env{'form.popup'}) {
362: $r->print('<input type="hidden" name="popup" value="'.
363: $env{'form.popup'}.'" />');
364: }
365: $r->print('</form>');
366: }
367: if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
368: } else {
369: # &Apache::lontemplate::send_message($r,$cnum,$cdom);
370: $r->print('<p>'.&mt('No personal information provided').'.</p>');
371: }
372: if($target ne 'tex'){
373: $r->print('</blockquote>');
374: $r->print('</div>');
375: }
376:
377: if ($env{'request.course.id'}
378: && &Apache::lonnet::allowed('srm',$env{'request.course.id'})
379: && &in_course($cdom,$cnum)) {
380: if ($target ne 'tex') {
381: $r->print('<a name="coursecomment" />');
382: $r->print('<hr /><h3>'.
383: &mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'</h3>'.
384: &mt('Shared by course faculty and staff').
385: &Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message").
386: '<br />');
387: &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
388:
389: } else {
390: $r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
391: &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
392: }
393: }
394: if ($target ne 'tex') {
395: if ($env{'form.popup'}) {
396: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a>');
397: }
398: $r->print(&Apache::loncommon::end_page());
399: } else {
400: $r->print('\end{document}');
401: }
402:
403:
404:
405: return OK;
406: }
407:
408: sub in_course {
409: my ($udom,$uname,$cdom,$cnum,$type) = @_;
410: $type ||= 'any';
411: if (!defined($cdom) || !defined($cnum)) {
412: my $cid = $env{'request.course.id'};
413: $cdom = $env{'course.'.$cid.'.domain'};
414: $cnum = $env{'course.'.$cid.'.num'};
415: }
416: my %roles = &Apache::lonnet::dump('roles',$udom,$uname);
417: my @course_roles = grep(m{^/\Q$cdom\E/\Q$cnum\E[/_]}, keys(%roles));
418: return 0 if (!@course_roles);
419: return 1 if ($type eq 'any');
420: my $now = time();
421: foreach my $role (@course_roles) {
422: my (undef,$role_end,$role_start)=split(/\_/,$roles{$role});
423: my $status = 'active';
424: if ($role_start > 0 && $now < $role_start) {
425: $status = 'future';
426: }
427: if ($role_end > 0 && $now > $role_end) {
428: $status = 'previous';
429: }
430: return 1 if ($status eq $type);
431: }
432: return 0;
433: }
434:
435: sub aboutme_info {
436: my ($r,$is_course) = @_;
437: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
438: my $name;
439: if (!$is_course) {
440: $name = &Apache::loncommon::plainname($cnum,$cdom);
441: }
442: return ($cdom,$cnum,$name);
443: }
444:
445: sub print_portfiles_link {
446: my ($r,$is_course) = @_;
447: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
448: my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
449: $cdom,$cnum,$name);
450: my $query_string = &build_query_string();
451: my $output;
452: my %lt = &Apache::lonlocal::texthash(
453: vpfi => 'Viewable portfolio files',
454: vgpf => 'Viewable group portfolio files',
455: difl => 'Display file listing',
456: );
457: if ($filecounts->{'both'} > 0) {
458: $output = '<div class="LC_ContentBoxSpecial"><h4 class="LC_hcell">';
459: $output .= ($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
460:
461: #$output = '<h4>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
462: $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
463: $query_string.'">'.$lt{'difl'}.
464: '</a><br /><br />';
465: if ($filecounts->{'both'} == 1) {
466: if ($is_course) {
467: $output .= &mt('One group portfolio file is available.').'<ul>';
468: } else {
469: $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
470: }
471: } else {
472: if ($is_course) {
473: $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
474: } else {
475: $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
476: }
477: }
478: if ($filecounts->{'withoutpass'}) {
479: $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
480: }
481: if ($filecounts->{'withpass'}) {
482: $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
483: }
484: $output .= '</ul>';
485: $output .='</p>';
486: $output .='</div>';
487: }
488: $r->print($output);
489: return;
490: }
491:
492: sub build_query_string {
493: my ($new_items) = @_;
494: my $query_string;
495: my @formelements = ('register');
496: my $new = 0;
497: if (ref($new_items) eq 'HASH') {
498: $new = 1;
499: if (!defined($new_items->{'forceedit'}) &&
500: !defined($new_items->{'forcestudent'})) {
501: push(@formelements,('forceedit','forcestudent'));
502: }
503: } else {
504: push(@formelements,('forceedit','forcestudent'));
505: }
506: foreach my $element (@formelements) {
507: if (exists($env{'form.'.$element})) {
508: if ((!$new) || (!defined($new_items->{$element}))) {
509: $query_string .= '&'.$element.'='.$env{'form.'.$element};
510: }
511: }
512: }
513: if ($new) {
514: foreach my $key (keys(%{$new_items})) {
515: $query_string .= '&'.$key.'='.$new_items->{$key};
516: }
517: }
518: $query_string =~ s/^\&/\?/;
519: return $query_string;
520: }
521:
522: sub display_portfolio_header {
523: my ($r,$is_course) = @_;
524: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
525: my $query_string = &build_query_string();
526: &Apache::lonhtmlcommon::clear_breadcrumbs();
527: my $forcestudent='';
528: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
529:
530: my $output;
531: if ($is_course) {
532: $output =
533: &Apache::loncommon::start_page('Viewable group portfolio files',undef,
534: {'function' => $forcestudent,
535: 'domain' => $cdom,});
536: $output .= '<h3>'.&mt('Group Portfolio files').'</h3>';
537: } else {
538: $output =
539: &Apache::loncommon::start_page('Viewable portfolio files',undef,
540: {'function' => $forcestudent,
541: 'domain' => $cdom,});
542: if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
543: &Apache::lonhtmlcommon::add_breadcrumb
544: ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
545: text=>"Personal Information Page - $name",
546: title=>"Go to personal information page for $name"}, {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
547: text=>"Viewable files - $name",
548: title=>"Viewable portfolio files for $name"}
549: );
550: $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
551: }
552: $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
553: }
554: $r->print($output);
555: return;
556: }
557:
558: sub display_portfolio_files {
559: my ($r,$is_course) = @_;
560: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
561: my %lt = ( withoutpass => 'passphrase not required',
562: withpass => 'passphrase protected',
563: both => 'all access types ',);
564: %lt = &Apache::lonlocal::texthash(%lt);
565:
566: my $portaccess = 'withoutpass';
567: if (exists($env{'form.portaccess'})) {
568: $portaccess = $env{'form.portaccess'};
569: }
570:
571: my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
572: .'" name="displaystatus" method="post">'.
573: &mt('File access type: ').'<select name="portaccess">';
574: foreach my $type ('withoutpass','withpass','both') {
575: $output .= '<option value="'.$type.'" ';
576: if ($portaccess eq $type) {
577: $output .= 'selected="selected"';
578: }
579: $output .= '>'.$lt{$type}.'</option>';
580: }
581: $output .= '</select>'."\n".
582: '<input type="submit" name="portaccessbutton" value="'.
583: &mt('Update display').'" />';
584: $output .= '</form><br /><br />';
585: $r->print($output);
586: my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
587: $cdom,$cnum,$name);
588: if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
589: my $query_string = &build_query_string();
590: $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
591: '/aboutme'.$query_string.'">');
592: if ($is_course) {
593: $r->print(&mt('Course Information page'));
594: } else {
595: $r->print(&mt('Information about [_1]',$name));
596: }
597: $r->print('</a>');
598: }
599: return;
600: }
601:
602: sub portfolio_files {
603: my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
604: my $filecounts = {
605: withpass => 0,
606: withoutpass => 0,
607: both => 0,
608: };
609: my $current_permissions =
610: &Apache::lonnet::get_portfile_permissions($cdom,$cnum);
611: my %access_controls =
612: &Apache::lonnet::get_access_controls($current_permissions);
613: my $portaccess;
614: if ($mode eq 'showlink') {
615: $portaccess = 'both';
616: } else {
617: $portaccess = 'withoutpass';
618: if (exists($env{'form.portaccess'})) {
619: $portaccess = $env{'form.portaccess'};
620: }
621: }
622:
623: my $diroutput;
624: if ($is_course) {
625: my %files_by_group;
626: foreach my $filename (sort(keys(%access_controls))) {
627: my ($group,$path) = split('/',$filename,2);
628: $files_by_group{$group}{$path} = $access_controls{$filename};
629: }
630: foreach my $group (sort(keys(%files_by_group))) {
631: my %fileshash;
632: my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
633: $is_course,$filecounts,$mode,
634: $files_by_group{$group},
635: \%fileshash,$group);
636: if ($grpout) {
637: $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
638: }
639: }
640: } else {
641: my %allfileshash;
642: $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
643: $filecounts,$mode,\%access_controls,
644: \%allfileshash);
645: }
646: if ($mode eq 'listfiles') {
647: if ($filecounts->{'both'}) {
648: $r->print($diroutput);
649: } else {
650: my $access_text;
651: if (ref($lt) eq 'HASH') {
652: $access_text = $lt->{$portaccess};
653: }
654: $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
655: }
656: }
657: return $filecounts;
658: }
659:
660: {
661: my $count=0;
662: sub portfolio_table_start {
663: $count=0;
664: return '<table class="LC_aboutme_port">';
665: }
666: sub portfolio_row_start {
667: $count++;
668: my $class = ($count%2)?'LC_odd_row'
669: :'LC_even_row';
670: return '<tr class="'.$class.'">';
671: }
672: }
673:
674: sub build_hierarchy {
675: my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
676: $allfileshash,$group) = @_;
677: foreach my $filename (sort(keys(%{$access_info}))) {
678: my $access_status =
679: &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group, $$access_info{$filename});
680: if ($portaccess eq 'both') {
681: if (($access_status ne 'ok') &&
682: ($access_status !~ /^[^:]+:guest_/)) {
683: next;
684: }
685: } elsif ($portaccess eq 'withoutpass') {
686: if ($access_status ne 'ok') {
687: next;
688: }
689: } elsif ($portaccess eq 'withpass') {
690: if ($access_status !~ /^[^:]+:guest_/) {
691: next;
692: }
693: }
694: if ($mode eq 'listfiles') {
695: $filename =~ s/^\///;
696: my @pathitems = split('/',$filename);
697: my $lasthash = $allfileshash;
698: while (@pathitems > 1) {
699: my $newlevel = shift(@pathitems);
700: if (!exists($lasthash->{$newlevel})) {
701: $lasthash->{$newlevel} = {};
702: }
703: $lasthash = $lasthash->{$newlevel};
704: }
705: $lasthash->{$pathitems[0]} = $filename;
706: }
707: if ($access_status eq 'ok') {
708: $filecounts->{'withoutpass'} ++;
709: } elsif ($access_status =~ /^[^:]+:guest_/) {
710: $filecounts->{'withpass'} ++;
711: }
712: }
713: $filecounts->{'both'} = $filecounts->{'withoutpass'} +
714: $filecounts->{'withpass'};
715: my $output;
716: if ($mode eq 'listfiles') {
717: if ($filecounts->{'both'} > 0) {
718: $output = &portfolio_table_start();
719: $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
720: $group);
721: $output .= '</table>';
722: }
723: }
724: return $output;
725: }
726:
727: sub parse_directory {
728: my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
729: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
730: $depth++;
731: my $output;
732:
733: my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
734: $group);
735: my $getpropath = 1;
736: my %dirlist = map {
737: ((split('&',$_,2))[0],1)
738: } &Apache::lonnet::dirlist($portfolio_root.$path,$cdom,$cnum,$getpropath);
739: foreach my $item (sort(keys(%{$currhash}))) {
740: $output .= &portfolio_row_start();
741: $output .= '<td style="padding-left: '.($depth*25).'px">';
742: if (ref($currhash->{$item}) eq 'HASH') {
743: my $title=&HTML::Entities::encode($item,'<>&"');
744: $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" /> '.$title;
745: $output .= '</td><td></td></tr>';
746: $output .= &parse_directory($r,$depth,$currhash->{$item},
747: $path.'/'.$item,$is_course,$group);
748: } else {
749: my $file_name;
750: if ($currhash->{$item} =~ m|/([^/]+)$|) {
751: $file_name = $1;
752: } else {
753: $file_name = $currhash->{$item};
754: }
755: my $have_meta = exists($dirlist{$file_name.'.meta'});
756: my $url;
757: if ($is_course) {
758: $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
759: '/portfolio/'.$currhash->{$item};
760: } else {
761: $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
762: $currhash->{$item};
763: }
764: my $showname;
765: if ($have_meta) {
766: $showname = &Apache::lonnet::metadata($url,'title');
767: }
768: if ($showname eq '') {
769: $showname = $file_name;
770: } else {
771: $showname = $file_name.' ('.$showname.')';
772: }
773:
774: $showname=&HTML::Entities::encode($showname,'<>&"');
775: $output .= '<a href="'.$url.'">'.
776: '<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
777: ' '.$showname.'</a>';
778: $output.='</td><td>';
779: if ($have_meta) {
780: $output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Metadata').'" src="'.
781: &Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
782: '" class="LC_icon" /></a>';
783: }
784: $output .= '</td></tr>';
785: }
786: }
787: return $output;
788: }
789:
790: sub aboutme_access {
791: my ($uname,$udom) = @_;
792: my $privcheck = $env{'request.course.id'};
793: my $sec;
794: if ($env{'request.course.sec'} ne '') {
795: $sec = $env{'request.course.sec'};
796: $privcheck .= '/'.$sec;
797: }
798: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
799: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
800: if (($cdom eq '') || ($cnum eq '')) {
801: my %coursehash = &coursedescription($env{'request.course.id'});
802: $cdom = $coursehash{'domain'};
803: $cnum = $coursehash{'cnum'};
804: }
805: if ((&Apache::lonnet::allowed('srm',$privcheck)) ||
806: (&Apache::lonnet::allowed('dff',$privcheck))) {
807: if (&in_course($uname,$udom,$cnum,$cdom)) {
808: return 1;
809: }
810: }
811: return;
812: }
813:
814: 1;
815: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>