Annotation of loncom/interface/lonaboutme.pm, revision 1.104
1.1 www 1: # The LearningOnline Network
1.97 weissno 2: # Personal Information Page
1.1 www 3: #
1.104 ! weissno 4: # $Id: lonaboutme.pm,v 1.104 2009/02/25 13:55:57 weissno Exp $
1.1 www 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:
1.74 jms 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:
1.1 www 76: package Apache::lonaboutme;
77:
78: use strict;
79: use Apache::Constants qw(:common);
80: use Apache::loncommon;
81: use Apache::lonnet;
1.2 www 82: use Apache::lontexconvert;
1.12 www 83: use Apache::lonfeedback;
1.39 www 84: use Apache::lonrss();
1.17 www 85: use Apache::lonlocal;
1.41 albertel 86: use Apache::lonmsgdisplay();
1.72 amueller 87: use Apache::lontemplate;
1.52 albertel 88: use HTML::Entities();
1.91 neumanie 89: use Image::Magick;
1.1 www 90:
91: sub handler {
92: my $r = shift;
1.17 www 93: &Apache::loncommon::content_type($r,'text/html');
1.1 www 94: $r->send_http_header;
95: return OK if $r->header_only;
1.37 albertel 96: my $target=$env{'form.grade_target'};
1.1 www 97: # ------------------------------------------------------------ Print the screen
1.40 albertel 98: if ($target eq 'tex') {
1.37 albertel 99: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.22 sakharuk 100: }
1.47 albertel 101: my (undef,undef,$cdom,$cnum,undef,$action)=split(/\//,$r->uri);
1.55 raeburn 102: my $is_course;
1.2 www 103: # Is this even a user?
104: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
1.40 albertel 105: &Apache::loncommon::simple_error_page($r,'No info',
106: 'No user information available');
1.2 www 107: return OK;
1.55 raeburn 108: } else {
1.59 raeburn 109: $is_course = &Apache::lonnet::is_course($cdom,$cnum);
1.2 www 110: }
1.55 raeburn 111:
1.77 raeburn 112: my $candisplay = 1;
113: if (!$is_course) {
1.80 raeburn 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 {
1.97 weissno 123: $r->print(&Apache::loncommon::start_page("Personal Information Page"));
1.80 raeburn 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;
1.77 raeburn 132: }
133: }
134: }
135:
1.2 www 136: # --------------------------------------------------------- The syllabus fields
1.17 www 137: my %syllabusfields=&Apache::lonlocal::texthash(
1.3 www 138: 'aaa_contactinfo' => 'Contact Information',
1.103 weissno 139: 'bbb_aboutme' => 'Personal Information',
1.3 www 140: 'ccc_webreferences' => 'Web References');
1.2 www 141:
1.13 www 142: # ------------------------------------------------------------ Get Query String
1.47 albertel 143: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
144: ['forceedit','forcestudent',
1.69 raeburn 145: 'register','popup']);
1.43 raeburn 146:
147: # ----------------------------------------------- Available Portfolio file display
1.47 albertel 148: if (($target ne 'tex') && ($action eq 'portfolio')) {
1.55 raeburn 149: &display_portfolio_header($r,$is_course);
1.80 raeburn 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>');
1.60 raeburn 156: } else {
1.80 raeburn 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: }
1.60 raeburn 164: }
1.43 raeburn 165: $r->print(&Apache::loncommon::end_page());
166: return OK;
167: }
168:
1.55 raeburn 169: if ($is_course) {
170: if ($target ne 'tex') {
1.85 raeburn 171: my $brcrum = [{href=>"/adm/navmaps",text=>"Navigate Course Contents"},
172: {href=>"/adm/aboutme",text=>"Course Information"}];
1.55 raeburn 173: my $start_page =
174: &Apache::loncommon::start_page(
175: "Course Information",
176: undef,
177: {'function' => $env{'forcestudent'},
178: 'domain' => $cdom,
1.82 kaisler 179: 'force_register' => $env{'forceregister'},
1.85 raeburn 180: 'bread_crumbs' => $brcrum});
1.55 raeburn 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:
1.2 www 189: # --------------------------------------------------------------- Force Student
190: my $forcestudent='';
1.37 albertel 191: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.43 raeburn 192:
193: my $forceregister = '';
194: if ($forcestudent eq '') {
195: $forceregister = $env{'form.register'};
196: }
1.2 www 197:
198: # --------------------------------------- There is such a user, get environment
199: my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.22 sakharuk 200: if ($target ne 'tex') {
1.65 albertel 201: my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
1.69 raeburn 202: my $args = {'function' => $forcestudent,
203: 'domain' => $cdom,
204: 'force_register' => $forceregister};
205: if ($env{'form.popup'}) {
206: $args->{'no_nav_bar'} = 1;
207: }
1.98 weissno 208: $args->{'bread_crumbs'} = [{href=>"/adm/fhwfdev/$cnum/aboutme",text=>"Personal Information Page"}];
1.40 albertel 209: my $start_page =
1.97 weissno 210: &Apache::loncommon::start_page("Personal Information Page",$rss_link,$args);
1.40 albertel 211: $r->print($start_page);
1.95 schualex 212: $r->print('<div class="LC_ContentBoxSpecial">');
213: $r->print('<h2 class="LC_hcell">'.&Apache::loncommon::plainname($cnum,$cdom).'</h2>');
1.22 sakharuk 214: } else {
215: $r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
216: }
1.6 www 217: if ($courseenv{'nickname'}) {
218: $r->print(
1.7 albertel 219: '<h2>"'.$courseenv{'nickname'}.
1.6 www 220: '"</h2>');
221: }
1.22 sakharuk 222: if ($target ne 'tex') {
1.95 schualex 223: $r->print('<blockquote>');
1.101 neumanie 224: $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>');
1.22 sakharuk 225: } else {
1.61 albertel 226: $r->print('\textbf{'.&Apache::lonnet::domain($cdom,'description').'}\\\\');
1.22 sakharuk 227: }
1.2 www 228: my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
229: my $allowed=0;
230:
1.1 www 231: # does this user have privileges to post, etc?
1.2 www 232:
1.37 albertel 233: my $privleged=$allowed=(($env{'user.name'} eq $cnum) &&
234: ($env{'user.domain'} eq $cdom));
1.23 sakharuk 235: if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.87 ehlerst 236: my $query_string;
1.99 neumanie 237:
1.2 www 238: if ($allowed) {
1.99 neumanie 239:
1.32 albertel 240: $r->print('<p><b>'.&mt('Privacy Note').':</b> '.
1.99 neumanie 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>'.
1.87 ehlerst 242: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).'</p>');
1.99 neumanie 243: }
244:
1.37 albertel 245: if (($env{'form.uploaddoc.filename'}) &&
246: ($env{'form.storeupl'}) && ($allowed)) {
247: if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
1.24 albertel 248: if ($syllabus{'uploaded.photourl'}) {
249: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
250: }
251: $syllabus{'uploaded.photourl'}=
1.79 amueller 252: &Apache::lonnet::userphotoupload('uploaddoc','aboutme');
1.3 www 253: }
254: $syllabus{'uploaded.lastmodified'}=time;
255: &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
256: }
1.37 albertel 257: if ($allowed && $env{'form.delupl'}) {
1.32 albertel 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: }
1.37 albertel 264: if (($allowed) && ($env{'form.storesyl'})) {
1.57 albertel 265: foreach my $syl_field (keys(%syllabusfields)) {
266: my $field=$env{'form.'.$syl_field};
1.2 www 267: $field=~s/\s+$//s;
1.11 www 268: $field=&Apache::lonfeedback::clear_out_html($field,
1.37 albertel 269: $env{'user.adv'});
1.57 albertel 270: $syllabus{$syl_field}=$field;
1.2 www 271: }
272: $syllabus{'uploaded.lastmodified'}=time;
273: &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
274: }
275:
1.71 amueller 276: my $lastmod;
277: my $image;
1.2 www 278: # ---------------------------------------------------------------- Get syllabus
279: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.71 amueller 280: $lastmod=$syllabus{'uploaded.lastmodified'};
1.18 www 281: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
1.93 neumanie 282: $r->print('<br />'.&mt('Last updated').': '.$lastmod);
1.99 neumanie 283:
284:
1.3 www 285: if ($syllabus{'uploaded.photourl'}) {
1.24 albertel 286: &Apache::lonnet::allowuploaded('/adm/aboutme',
287: $syllabus{'uploaded.photourl'});
1.91 neumanie 288:
1.97 weissno 289: #This call is to resize all "Personal Information" images in the LonCapa System. When its done, you can remove this line.
1.91 neumanie 290: &Apache::lonnet::resizeImage(&Apache::lonnet::filelocation('',$syllabus{'uploaded.photourl'}));
1.93 neumanie 291: #---End Resize---
1.91 neumanie 292:
1.94 neumanie 293: $image=qq{<img name="userPhoto" src="$syllabus{'uploaded.photourl'} " class="LC_AboutMe_Image" />};
1.91 neumanie 294:
1.27 albertel 295: if ($target eq 'tex') {
296: $image=&Apache::lonxml::xmlparse($r,'tex',$image);
1.26 sakharuk 297: }
1.93 neumanie 298:
1.3 www 299: }
1.101 neumanie 300: #---Print Functions
1.99 neumanie 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));
1.101 neumanie 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);
1.99 neumanie 321: }
1.23 sakharuk 322: if ($allowed) {
1.3 www 323: $r->print(
324: '<form method="post" enctype="multipart/form-data">'.
1.18 www 325: '<h3>'.&mt('Upload a Photo').'</h3>'.
1.68 raeburn 326: '<input type="file" name="uploaddoc" size="50" />'.
327: '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />'.
1.69 raeburn 328: '<input type="hidden" name="popup" value="'.$env{'form.popup'}.'" />'.
1.93 neumanie 329: '</form><form method="post"><input type="submit" name="delupl" value="'.&mt('Delete Photo').'" /> </form><p>
1.83 schualex 330: ');
1.32 albertel 331:
1.2 www 332: }
1.86 schualex 333:
334: if($allowed) {
335: $r->print('<form method="post">');
336: }
337:
1.93 neumanie 338: if($target ne 'tex') #print Image
339: {
1.101 neumanie 340: &Apache::lontemplate::start_ContentBox($r);
1.81 ehlerst 341: &Apache::lontemplate::end_ContentBox($r);
1.93 neumanie 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
1.101 neumanie 351: {
1.81 ehlerst 352: &print_portfiles_link($r,$is_course);
1.100 neumanie 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');
1.101 neumanie 355: }
1.93 neumanie 356:
1.101 neumanie 357: } #End Print RSS and portfiles
1.95 schualex 358:
1.101 neumanie 359:
1.23 sakharuk 360: if ($allowed) {
1.69 raeburn 361: if ($env{'form.popup'}) {
362: $r->print('<input type="hidden" name="popup" value="'.
363: $env{'form.popup'}.'" />');
364: }
1.2 www 365: $r->print('</form>');
366: }
1.46 albertel 367: if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
1.2 www 368: } else {
1.99 neumanie 369: # &Apache::lontemplate::send_message($r,$cnum,$cdom);
1.17 www 370: $r->print('<p>'.&mt('No personal information provided').'.</p>');
1.8 www 371: }
1.101 neumanie 372: if($target ne 'tex'){
1.102 schualex 373: #$r->print('</blockquote>');
374: #$r->print('</div>');
1.101 neumanie 375: }
1.43 raeburn 376:
1.63 albertel 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 />');
1.101 neumanie 387: &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
388:
1.63 albertel 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: }
1.1 www 393: }
1.102 schualex 394: $r->print('</blockquote>');
395: $r->print('</div>');
1.40 albertel 396: if ($target ne 'tex') {
1.69 raeburn 397: if ($env{'form.popup'}) {
398: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a>');
399: }
1.40 albertel 400: $r->print(&Apache::loncommon::end_page());
401: } else {
402: $r->print('\end{document}');
403: }
1.71 amueller 404:
405:
406:
1.1 www 407: return OK;
1.43 raeburn 408: }
409:
1.63 albertel 410: sub in_course {
411: my ($udom,$uname,$cdom,$cnum,$type) = @_;
412: $type ||= 'any';
413: if (!defined($cdom) || !defined($cnum)) {
414: my $cid = $env{'request.course.id'};
415: $cdom = $env{'course.'.$cid.'.domain'};
416: $cnum = $env{'course.'.$cid.'.num'};
417: }
418: my %roles = &Apache::lonnet::dump('roles',$udom,$uname);
419: my @course_roles = grep(m{^/\Q$cdom\E/\Q$cnum\E[/_]}, keys(%roles));
420: return 0 if (!@course_roles);
421: return 1 if ($type eq 'any');
422: my $now = time();
423: foreach my $role (@course_roles) {
424: my (undef,$role_end,$role_start)=split(/\_/,$roles{$role});
425: my $status = 'active';
426: if ($role_start > 0 && $now < $role_start) {
427: $status = 'future';
428: }
429: if ($role_end > 0 && $now > $role_end) {
430: $status = 'previous';
431: }
432: return 1 if ($status eq $type);
433: }
434: return 0;
435: }
436:
1.43 raeburn 437: sub aboutme_info {
1.55 raeburn 438: my ($r,$is_course) = @_;
1.43 raeburn 439: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.55 raeburn 440: my $name;
441: if (!$is_course) {
442: $name = &Apache::loncommon::plainname($cnum,$cdom);
443: }
1.43 raeburn 444: return ($cdom,$cnum,$name);
445: }
446:
447: sub print_portfiles_link {
1.55 raeburn 448: my ($r,$is_course) = @_;
449: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.64 raeburn 450: my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
451: $cdom,$cnum,$name);
1.47 albertel 452: my $query_string = &build_query_string();
1.43 raeburn 453: my $output;
1.55 raeburn 454: my %lt = &Apache::lonlocal::texthash(
455: vpfi => 'Viewable portfolio files',
456: vgpf => 'Viewable group portfolio files',
457: difl => 'Display file listing',
458: );
1.43 raeburn 459: if ($filecounts->{'both'} > 0) {
1.89 harmsja 460: $output = '<div class="LC_ContentBoxSpecial"><h4 class="LC_hcell">';
1.76 harmsja 461: $output .= ($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
1.71 amueller 462:
1.76 harmsja 463: #$output = '<h4>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
1.47 albertel 464: $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
1.55 raeburn 465: $query_string.'">'.$lt{'difl'}.
1.43 raeburn 466: '</a><br /><br />';
1.53 raeburn 467: if ($filecounts->{'both'} == 1) {
1.55 raeburn 468: if ($is_course) {
469: $output .= &mt('One group portfolio file is available.').'<ul>';
470: } else {
1.56 albertel 471: $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
1.55 raeburn 472: }
1.53 raeburn 473: } else {
1.55 raeburn 474: if ($is_course) {
1.56 albertel 475: $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
1.55 raeburn 476: } else {
477: $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
478: }
1.53 raeburn 479: }
1.43 raeburn 480: if ($filecounts->{'withoutpass'}) {
1.54 albertel 481: $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
1.43 raeburn 482: }
483: if ($filecounts->{'withpass'}) {
1.54 albertel 484: $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
1.43 raeburn 485: }
486: $output .= '</ul>';
1.76 harmsja 487: $output .='</p>';
1.81 ehlerst 488: $output .='</div>';
1.43 raeburn 489: }
490: $r->print($output);
491: return;
492: }
493:
494: sub build_query_string {
495: my ($new_items) = @_;
496: my $query_string;
497: my @formelements = ('register');
1.47 albertel 498: my $new = 0;
1.43 raeburn 499: if (ref($new_items) eq 'HASH') {
1.47 albertel 500: $new = 1;
1.43 raeburn 501: if (!defined($new_items->{'forceedit'}) &&
502: !defined($new_items->{'forcestudent'})) {
503: push(@formelements,('forceedit','forcestudent'));
504: }
505: } else {
506: push(@formelements,('forceedit','forcestudent'));
507: }
508: foreach my $element (@formelements) {
509: if (exists($env{'form.'.$element})) {
1.47 albertel 510: if ((!$new) || (!defined($new_items->{$element}))) {
1.43 raeburn 511: $query_string .= '&'.$element.'='.$env{'form.'.$element};
512: }
513: }
514: }
1.47 albertel 515: if ($new) {
1.43 raeburn 516: foreach my $key (keys(%{$new_items})) {
517: $query_string .= '&'.$key.'='.$new_items->{$key};
518: }
519: }
520: $query_string =~ s/^\&/\?/;
521: return $query_string;
522: }
523:
524: sub display_portfolio_header {
1.55 raeburn 525: my ($r,$is_course) = @_;
526: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.43 raeburn 527: my $query_string = &build_query_string();
528: &Apache::lonhtmlcommon::clear_breadcrumbs();
529: my $forcestudent='';
530: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.55 raeburn 531:
532: my $output;
533: if ($is_course) {
534: $output =
535: &Apache::loncommon::start_page('Viewable group portfolio files',undef,
536: {'function' => $forcestudent,
537: 'domain' => $cdom,});
538: $output .= '<h3>'.&mt('Group Portfolio files').'</h3>';
539: } else {
540: $output =
541: &Apache::loncommon::start_page('Viewable portfolio files',undef,
542: {'function' => $forcestudent,
1.43 raeburn 543: 'domain' => $cdom,});
1.55 raeburn 544: if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
545: &Apache::lonhtmlcommon::add_breadcrumb
546: ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
1.104 ! weissno 547: text=>&mt('Personal Information Page - [_1]',$name),
! 548: title=>&mt('Go to personal information page for [_1]',$name)},
! 549: {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
! 550: text=>&mt('Viewable files - [_1]',$name),
! 551: title=>&mt('Viewable portfolio files for [_1]',$name)}
1.55 raeburn 552: );
553: $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
554: }
555: $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
1.53 raeburn 556: }
1.43 raeburn 557: $r->print($output);
558: return;
559: }
560:
561: sub display_portfolio_files {
1.55 raeburn 562: my ($r,$is_course) = @_;
563: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.47 albertel 564: my %lt = ( withoutpass => 'passphrase not required',
565: withpass => 'passphrase protected',
566: both => 'all access types ',);
567: %lt = &Apache::lonlocal::texthash(%lt);
568:
1.43 raeburn 569: my $portaccess = 'withoutpass';
570: if (exists($env{'form.portaccess'})) {
571: $portaccess = $env{'form.portaccess'};
572: }
1.47 albertel 573:
1.45 albertel 574: my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
575: .'" name="displaystatus" method="post">'.
576: &mt('File access type: ').'<select name="portaccess">';
1.43 raeburn 577: foreach my $type ('withoutpass','withpass','both') {
578: $output .= '<option value="'.$type.'" ';
579: if ($portaccess eq $type) {
580: $output .= 'selected="selected"';
581: }
1.53 raeburn 582: $output .= '>'.$lt{$type}.'</option>';
1.43 raeburn 583: }
584: $output .= '</select>'."\n".
585: '<input type="submit" name="portaccessbutton" value="'.
1.47 albertel 586: &mt('Update display').'" />';
1.43 raeburn 587: $output .= '</form><br /><br />';
588: $r->print($output);
1.64 raeburn 589: my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
590: $cdom,$cnum,$name);
1.53 raeburn 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.
1.55 raeburn 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>');
1.53 raeburn 601: }
1.43 raeburn 602: return;
603: }
604:
605: sub portfolio_files {
1.64 raeburn 606: my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
1.43 raeburn 607: my $filecounts = {
608: withpass => 0,
609: withoutpass => 0,
610: both => 0,
611: };
612: my $current_permissions =
1.44 albertel 613: &Apache::lonnet::get_portfile_permissions($cdom,$cnum);
1.43 raeburn 614: my %access_controls =
1.44 albertel 615: &Apache::lonnet::get_access_controls($current_permissions);
1.43 raeburn 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:
1.55 raeburn 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});
1.43 raeburn 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);
1.55 raeburn 700: my $lasthash = $allfileshash;
1.43 raeburn 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'};
1.55 raeburn 718: my $output;
1.43 raeburn 719: if ($mode eq 'listfiles') {
1.55 raeburn 720: if ($filecounts->{'both'} > 0) {
1.45 albertel 721: $output = &portfolio_table_start();
1.55 raeburn 722: $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
723: $group);
1.43 raeburn 724: $output .= '</table>';
725: }
1.45 albertel 726: }
1.55 raeburn 727: return $output;
1.45 albertel 728: }
729:
1.43 raeburn 730: sub parse_directory {
1.55 raeburn 731: my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
732: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.45 albertel 733: $depth++;
734: my $output;
1.49 albertel 735:
1.55 raeburn 736: my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
737: $group);
1.70 raeburn 738: my $getpropath = 1;
1.49 albertel 739: my %dirlist = map {
740: ((split('&',$_,2))[0],1)
1.70 raeburn 741: } &Apache::lonnet::dirlist($portfolio_root.$path,$cdom,$cnum,$getpropath);
1.43 raeburn 742: foreach my $item (sort(keys(%{$currhash}))) {
1.45 albertel 743: $output .= &portfolio_row_start();
744: $output .= '<td style="padding-left: '.($depth*25).'px">';
1.43 raeburn 745: if (ref($currhash->{$item}) eq 'HASH') {
1.45 albertel 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;
1.47 albertel 748: $output .= '</td><td></td></tr>';
1.49 albertel 749: $output .= &parse_directory($r,$depth,$currhash->{$item},
1.55 raeburn 750: $path.'/'.$item,$is_course,$group);
1.43 raeburn 751: } else {
1.50 albertel 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'});
1.55 raeburn 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: }
1.43 raeburn 767: my $showname;
1.50 albertel 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:
1.45 albertel 777: $showname=&HTML::Entities::encode($showname,'<>&"');
1.49 albertel 778: $output .= '<a href="'.$url.'">'.
779: '<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
780: ' '.$showname.'</a>';
781: $output.='</td><td>';
1.50 albertel 782: if ($have_meta) {
1.92 schafran 783: $output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Metadata').'" src="'.
1.47 albertel 784: &Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
1.49 albertel 785: '" class="LC_icon" /></a>';
786: }
1.45 albertel 787: $output .= '</td></tr>';
1.43 raeburn 788: }
789: }
1.45 albertel 790: return $output;
1.43 raeburn 791: }
1.1 www 792:
1.77 raeburn 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: }
1.84 raeburn 808: if ((&Apache::lonnet::allowed('srm',$privcheck)) ||
809: (&Apache::lonnet::allowed('dff',$privcheck))) {
1.77 raeburn 810: if (&in_course($uname,$udom,$cnum,$cdom)) {
811: return 1;
812: }
813: }
814: return;
815: }
816:
1.1 www 817: 1;
818: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>