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