Annotation of loncom/interface/lonaboutme.pm, revision 1.161
1.1 www 1: # The LearningOnline Network
1.97 weissno 2: # Personal Information Page
1.1 www 3: #
1.161 ! raeburn 4: # $Id: lonaboutme.pm,v 1.160 2021/01/02 21:07:36 raeburn 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 aboutme_info()
54:
55: =item print_portfiles_link()
56:
57: =item build_query_string()
58:
59: =item display_portfolio_header()
60:
61: =item display_portfolio_files()
62:
63: =item portfolio_files()
64:
65: =item build_hierarchy()
66:
67: =item parse_directory()
68:
69: =back
70:
71: =cut
72:
73:
1.1 www 74: package Apache::lonaboutme;
75:
76: use strict;
77: use Apache::Constants qw(:common);
78: use Apache::loncommon;
79: use Apache::lonnet;
1.2 www 80: use Apache::lontexconvert;
1.155 raeburn 81: use Apache::lonhtmlgateway;
1.39 www 82: use Apache::lonrss();
1.17 www 83: use Apache::lonlocal;
1.41 albertel 84: use Apache::lonmsgdisplay();
1.72 amueller 85: use Apache::lontemplate;
1.157 raeburn 86: use Apache::longroup;
1.52 albertel 87: use HTML::Entities();
1.91 neumanie 88: use Image::Magick;
1.1 www 89:
90: sub handler {
91: my $r = shift;
1.17 www 92: &Apache::loncommon::content_type($r,'text/html');
1.1 www 93: $r->send_http_header;
94: return OK if $r->header_only;
1.37 albertel 95: my $target=$env{'form.grade_target'};
1.1 www 96: # ------------------------------------------------------------ Print the screen
1.128 bisitz 97: if ($target eq 'tex') {
1.134 amueller 98: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.22 sakharuk 99: }
1.47 albertel 100: my (undef,undef,$cdom,$cnum,undef,$action)=split(/\//,$r->uri);
1.55 raeburn 101: my $is_course;
1.2 www 102: # Is this even a user?
103: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
1.134 amueller 104: &Apache::loncommon::simple_error_page($r,'No info',
105: 'No user information available');
1.2 www 106: return OK;
1.55 raeburn 107: } else {
1.59 raeburn 108: $is_course = &Apache::lonnet::is_course($cdom,$cnum);
1.2 www 109: }
1.55 raeburn 110:
1.161 ! raeburn 111: my $clientip = &Apache::lonnet::get_requestor_ip($r);
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') {
1.110 weissno 121: $r->print('\noindent{\large\textbf{'.&mt('No user personal information page available').'}}\\\\\\\\');
1.80 raeburn 122: } else {
1.97 weissno 123: $r->print(&Apache::loncommon::start_page("Personal Information Page"));
1.149 bisitz 124: $r->print('<p class="_LC_info">'.&mt('No user personal information page available') .'</p>'.
1.133 amueller 125: &mt('This is a result of one of the following:').'<ul>'.
126: '<li>'.&mt('The administrator of this domain has disabled personal information page functionality for this specific user.').'</li>'.
127: '<li>'.&mt('The domain has been configured to disable, by default, personal information page functionality for all users in the domain.').'</li>'.
128: '</ul>');
1.80 raeburn 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'},
1.153 raeburn 144: ['forceedit','forcestudent','todocs',
1.152 raeburn 145: 'register','popup','folderpath','title']);
1.125 bisitz 146: # ----------------------------------------------- Available Portfolio file display
1.47 albertel 147: if (($target ne 'tex') && ($action eq 'portfolio')) {
1.55 raeburn 148: &display_portfolio_header($r,$is_course);
1.80 raeburn 149: if ((!$is_course) && (!&Apache::lonnet::usertools_access($cnum,$cdom,'portfolio'))) {
150: $r->print('<h2>'.&mt('No user portfolio available') .'</h2>'.
1.133 amueller 151: &mt('This is a result of one of the following:').'<ul>'.
152: '<li>'.&mt('The administrator of this domain has disabled portfolio functionality for this specific user.').'</li>'.
153: '<li>'.&mt('The domain has been configured to disable, by default, portfolio functionality for all users in the domain.').'</li>'.
154: '</ul>');
1.60 raeburn 155: } else {
1.125 bisitz 156: my ($blocked,$blocktext) =
1.161 ! raeburn 157: &Apache::loncommon::blocking_status('port',$clientip,$cnum,$cdom);
1.80 raeburn 158: if (!$blocked) {
159: &display_portfolio_files($r,$is_course);
160: } else {
161: $r->print($blocktext);
162: }
1.60 raeburn 163: }
1.43 raeburn 164: $r->print(&Apache::loncommon::end_page());
165: return OK;
166: }
167:
1.55 raeburn 168: if ($is_course) {
169: if ($target ne 'tex') {
1.150 raeburn 170: my $args = {'function' => undef,
1.146 raeburn 171: 'domain' => $cdom};
172: if ($env{'form.register'}) {
173: $args->{'force_register'} = $env{'form.register'};
174: } else {
175: my %coursedescription =
176: &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
177: my $cdescr = $coursedescription{'description'};
178: my $brcrum = [{href=>"/adm/$cdom/$cnum/aboutme",
179: text=>&mt('Course Information - [_1]',$cdescr),
180: no_mt=>1}
181: ];
182: $args->{'bread_crumbs'} = $brcrum;
183: }
184: my $start_page = &Apache::loncommon::start_page(
185: "Course Information",undef,$args);
1.55 raeburn 186: $r->print($start_page);
1.111 weissno 187: $r->print('<h2>'.&mt('Group Portfolio').'</h2>');
1.55 raeburn 188: &print_portfiles_link($r,$is_course);
189: $r->print(&Apache::loncommon::end_page());
190: }
191: return OK;
192: }
193:
1.105 neumanie 194: #------------Get rights
1.134 amueller 195: my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.150 raeburn 196: my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
197: my ($allowed,$coursedomain,$coursenum);
198: if ($env{'request.course.id'}) {
199: $coursedomain = $env{'course.'.$env{'request.course.id'}.'.domain'};
200: $coursenum = $env{'course.'.$env{'request.course.id'}.'.num'};
201: }
202: my ($cfile) =
203: &Apache::lonnet::can_edit_resource($env{'request.noversionuri'},
204: $coursenum,$coursedomain,
205: $env{'request.noversionuri'},
206: $env{'request.symb'});
207: if ($cfile ne '') {
208: $allowed = 1;
209: }
210:
211: if (!$env{'form.forceedit'} or $target eq 'tex') { $allowed=0; }
1.125 bisitz 212:
1.2 www 213: # --------------------------------------- There is such a user, get environment
1.125 bisitz 214:
1.22 sakharuk 215: if ($target ne 'tex') {
1.134 amueller 216: my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
1.139 amueller 217: my $args = {'function' => undef,
1.69 raeburn 218: 'domain' => $cdom,
1.146 raeburn 219: 'force_register' => $env{'form.register'},
220: };
221: if ($env{'form.popup'}) { # Don't show breadcrumbs in popup window
1.69 raeburn 222: $args->{'no_nav_bar'} = 1;
1.146 raeburn 223: } elsif (!$env{'form.register'}) { #Don't show breadcrumbs twice, when this page is part of course content and you call it
1.152 raeburn 224: if (($env{'request.course.id'}) &&
225: ($env{'form.folderpath'} =~ /^supplemental/)) {
226: my $crstype = &Apache::loncommon::course_type();
227: my $title = $env{'form.title'};
228: if ($title eq '') {
229: $title = &mt('Personal Information Page');
230: }
231: my $brcrum =
232: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
233: if (ref($brcrum) eq 'ARRAY') {
234: $args->{'bread_crumbs'} = $brcrum;
235: }
236: } else {
237: $args->{'bread_crumbs'} = [{href=>"/adm/$cdom/$cnum/aboutme",
238: text=>"Personal Information Page"}];
239: }
1.69 raeburn 240: }
1.134 amueller 241: my $start_page = &Apache::loncommon::start_page('Personal Information Page',$rss_link,$args);
242: $r->print($start_page);
1.138 bisitz 243: }
1.160 raeburn 244: my ($blocked,$blocktext) =
1.161 ! raeburn 245: &Apache::loncommon::blocking_status('about',$clientip,$cnum,$cdom);
1.160 raeburn 246: if ($blocked) {
247: if ($target eq 'tex') {
248: $r->print('\noindent{\large\textbf{'.&mt('No user personal information page available').'}}\\\\\\\\');
249: } else {
250: $r->print($blocktext);
251: }
252: $r->print(&Apache::loncommon::end_page());
253: return OK;
254: }
1.138 bisitz 255:
1.150 raeburn 256: #----------------Print Privacy note (edit mode) or last modified date.
1.128 bisitz 257:
1.138 bisitz 258: if ($target ne 'tex') {
1.126 neumanie 259: #Print Privacy Note
260: if ($allowed) {
261: $r->print('<div class="LC_info">'
1.133 amueller 262: .'<b>'.&mt('Privacy Note:').'</b> '
263: .&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.')
264: .'</div>'
265: );
1.150 raeburn 266: } elsif ($syllabus{'uploaded.lastmodified'}) {
267: #Print last modified
268: my $lastmod=$syllabus{'uploaded.lastmodified'};
1.133 amueller 269: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
1.134 amueller 270: $r->print('<div class="LC_info">');
1.150 raeburn 271: $r->print(&mt('Last updated').': '.$lastmod . '');
1.134 amueller 272: $r->print('</div>');
1.133 amueller 273: }
1.126 neumanie 274: }
1.107 neumanie 275:
1.105 neumanie 276: #------Print Headtitle
1.134 amueller 277: if ($target ne 'tex') {
1.150 raeburn 278: $r->print('<div class="LC_Box">'.
279: '<h2 class="LC_hcell">'.&Apache::loncommon::plainname($cnum,$cdom).'</h2>');
280: if ($allowed) {
281: $r->print('<div style="margin: 0; float:left;">');
282: if ($courseenv{'nickname'}) {
283: $r->print('<h2>"'.$courseenv{'nickname'}.'"</h2>');
284: }
285: $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3></div>');
286: #Print Help Text
287: $r->print('<div style="margin: 0; float:right;">'.
288: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).
289: '</div><br clear="all" />');
290: } else {
291: if ($courseenv{'nickname'}) {
292: $r->print('<h2>"'.$courseenv{'nickname'}.'"</h2>');
293: }
294: $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>');
295: }
1.134 amueller 296: } else {
297: $r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
298: $r->print('\textbf{'.&Apache::lonnet::domain($cdom,'description').'}\\\\');
299: }
1.1 www 300: # does this user have privileges to post, etc?
1.2 www 301:
1.125 bisitz 302:
1.134 amueller 303: my $query_string;
1.125 bisitz 304:
1.133 amueller 305: if (($env{'form.uploaddoc.filename'}) &&
1.37 albertel 306: ($env{'form.storeupl'}) && ($allowed)) {
1.133 amueller 307: if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
1.134 amueller 308: if ($syllabus{'uploaded.photourl'}) {
309: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
310: }
311: $syllabus{'uploaded.photourl'}=
1.143 raeburn 312: &Apache::lonnet::userfileupload('uploaddoc',undef,'aboutme',
313: undef,undef,undef,undef,undef,undef,undef,'400','500');
1.134 amueller 314: }
1.133 amueller 315: $syllabus{'uploaded.lastmodified'}=time;
316: &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
317: }
1.37 albertel 318: if ($allowed && $env{'form.delupl'}) {
1.134 amueller 319: if ($syllabus{'uploaded.photourl'}) {
320: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
321: delete($syllabus{'uploaded.photourl'});
322: &Apache::lonnet::del('aboutme',['uploaded.photourl'],$cdom,$cnum);
323: }
1.133 amueller 324: }
325: if (($allowed) && ($env{'form.storesyl'})) {
1.134 amueller 326: foreach my $syl_field (keys(%syllabusfields)) {
1.133 amueller 327: my $field=$env{'form.'.$syl_field};
1.155 raeburn 328: chomp($field);
329: my $gateway = Apache::lonhtmlgateway->new();
330: $field = $gateway->process_incoming_html($field,1);
1.134 amueller 331: $syllabus{$syl_field}=$field;
1.133 amueller 332: }
333: $syllabus{'uploaded.lastmodified'}=time;
334: &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
1.32 albertel 335: }
1.2 www 336:
1.133 amueller 337: my $image;
1.2 www 338: # ---------------------------------------------------------------- Get syllabus
339: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.133 amueller 340: if ($syllabus{'uploaded.photourl'}) {
1.134 amueller 341: &Apache::lonnet::allowuploaded('/adm/aboutme',$syllabus{'uploaded.photourl'});
1.125 bisitz 342:
1.139 amueller 343: $image=qq|<img name="userPhoto" src="$syllabus{'uploaded.photourl'} " class="LC_AboutMe_Image" alt="Photo of the user" />|;
1.91 neumanie 344:
1.134 amueller 345: if ($target eq 'tex') {
346: $image=&Apache::lonxml::xmlparse($r,'tex',$image);
347: }
1.133 amueller 348: }
1.86 schualex 349:
1.133 amueller 350: if ($allowed) {
351: $r->print(
1.139 amueller 352: '<form name="UploadPhoto" method="post" enctype="multipart/form-data" action="">'.
1.133 amueller 353: '<h3>'.&mt('Upload a Photo').'</h3>'.
1.143 raeburn 354: '<p class="LC_info">'.
355: &mt('LON-CAPA will automatically scale your uploaded file so the image will not exceed a width of 400px and a height of 500px.').'</p>'.
1.133 amueller 356: '<input type="file" name="uploaddoc" size="50" />'.
357: '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />'.
358: '<input type="hidden" name="popup" value="'.$env{'form.popup'}.'" />'.
1.134 amueller 359: '</form>');
360: if ($syllabus{'uploaded.photourl'}) {
1.139 amueller 361: $r->print('<form name="delPhoto" method="post" action="" ><input type="submit" name="delupl" value="'.&mt('Delete Photo').'" /> </form>')
1.133 amueller 362: }
1.139 amueller 363: $r->print('<p></p>');
1.133 amueller 364: }
365:
1.134 amueller 366: if($allowed) {
1.139 amueller 367: $r->print('<form name="lonaboutmeFields" method="post" action="" >');
1.134 amueller 368: }
369:
370: if ($target ne 'tex') { #print Image
1.145 wenzelju 371: $r->print($image.'<div class="LC_clear_float_footer"></div>');
1.133 amueller 372:
1.134 amueller 373: } #End Print Image
1.133 amueller 374:
1.134 amueller 375: #Print Content eg. Contactinfo aboutme,...
1.133 amueller 376: &Apache::lontemplate::print_aboutme_content_template($r,$allowed,$target,\%syllabusfields,\%syllabus);
377: #End Print Content
378:
379: if ($target ne 'tex') { #Begin Print RSS and portfiles
1.134 amueller 380: &print_portfiles_link($r,$is_course);
381: if (&Apache::lonrss::advertisefeeds($cnum,$cdom) ne '') {
1.137 bisitz 382: &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box');
1.134 amueller 383: $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom));
384: &Apache::lontemplate::print_end_template($r);
385: }
1.125 bisitz 386:
1.133 amueller 387: } #End Print RSS and portfiles
1.95 schualex 388:
1.125 bisitz 389:
1.133 amueller 390: if ($allowed) {
391: if ($env{'form.popup'}) {
392: $r->print('<input type="hidden" name="popup" value="'.
393: $env{'form.popup'}.'" />');
394: }
1.134 amueller 395: $r->print('</form>');
1.133 amueller 396: }
397: if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
1.128 bisitz 398: } else {
1.149 bisitz 399: $r->print('<p class="LC_info">'.&mt('No personal information provided').'.</p>');
1.128 bisitz 400: }
1.43 raeburn 401:
1.63 albertel 402: if ($env{'request.course.id'}
1.134 amueller 403: && &Apache::lonnet::allowed('srm',$env{'request.course.id'})
1.151 raeburn 404: && &Apache::lonnet::in_course($cdom,$cnum,$coursedomain,$coursenum,undef,1)) {
1.134 amueller 405: if ($target ne 'tex') {
406: $r->print('<a name="coursecomment" />');
1.137 bisitz 407: &Apache::lontemplate::print_start_template($r,&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course'),'LC_Box');
1.134 amueller 408: $r->print('<span class="LC_info">');
409: $r->print(&mt('Shared by course faculty and staff').&Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message"));
1.139 amueller 410: $r->print('</span>');
1.140 amueller 411: &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
1.134 amueller 412: &Apache::lontemplate::print_end_template($r);
1.133 amueller 413:
1.134 amueller 414: } else {
415: $r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
1.158 raeburn 416: &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom,$target);
1.134 amueller 417: }
1.128 bisitz 418: }
1.40 albertel 419: if ($target ne 'tex') {
1.134 amueller 420: $r->print('</div>');
1.69 raeburn 421: if ($env{'form.popup'}) {
1.154 bisitz 422: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
1.69 raeburn 423: }
1.134 amueller 424: $r->print(&Apache::loncommon::end_page());
1.40 albertel 425: } else {
1.134 amueller 426: $r->print('\end{document}');
1.40 albertel 427: }
1.71 amueller 428:
1.125 bisitz 429:
430:
1.1 www 431: return OK;
1.43 raeburn 432: }
433:
434: sub aboutme_info {
1.55 raeburn 435: my ($r,$is_course) = @_;
1.43 raeburn 436: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.55 raeburn 437: my $name;
438: if (!$is_course) {
439: $name = &Apache::loncommon::plainname($cnum,$cdom);
440: }
1.43 raeburn 441: return ($cdom,$cnum,$name);
442: }
443:
444: sub print_portfiles_link {
1.55 raeburn 445: my ($r,$is_course) = @_;
446: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.64 raeburn 447: my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
448: $cdom,$cnum,$name);
1.47 albertel 449: my $query_string = &build_query_string();
1.43 raeburn 450: my $output;
1.55 raeburn 451: my %lt = &Apache::lonlocal::texthash(
1.113 bisitz 452: 'vpfi' => 'Viewable portfolio files',
453: 'vgpf' => 'Viewable group portfolio files',
454: 'difl' => 'Display file listing',
1.125 bisitz 455: );
1.43 raeburn 456: if ($filecounts->{'both'} > 0) {
1.137 bisitz 457: $output = '<div class="LC_Box"><h4 class="LC_hcell">';
1.136 bisitz 458: $output .= ($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
1.125 bisitz 459:
1.134 amueller 460: #$output = '<h4>'.($is_course?$lt{'vgpf'}:$lt{'vpfi'}).'</h4>';
1.47 albertel 461: $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
1.133 amueller 462: $query_string.'">'.$lt{'difl'}.
463: '</a><br /><br />';
1.53 raeburn 464: if ($filecounts->{'both'} == 1) {
1.55 raeburn 465: if ($is_course) {
466: $output .= &mt('One group portfolio file is available.').'<ul>';
467: } else {
1.56 albertel 468: $output .= &mt('One portfolio file owned by [_1] is available.',$name).'<ul>';
1.55 raeburn 469: }
1.53 raeburn 470: } else {
1.55 raeburn 471: if ($is_course) {
1.56 albertel 472: $output .= &mt('A total of [_1] group portfolio files are available.',$filecounts->{'both'}).'<ul>';
1.55 raeburn 473: } else {
474: $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
475: }
1.53 raeburn 476: }
1.43 raeburn 477: if ($filecounts->{'withoutpass'}) {
1.134 amueller 478: $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
1.43 raeburn 479: }
480: if ($filecounts->{'withpass'}) {
1.134 amueller 481: $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
1.43 raeburn 482: }
483: $output .= '</ul>';
1.136 bisitz 484: $output .= '</div>';
1.146 raeburn 485: } elsif ($is_course) {
486: $output .= '<div class="LC_info">'.&mt('There are currently no publicly accessible or password protected group portfolio files.').'</div>';
1.43 raeburn 487: }
488: $r->print($output);
489: return;
490: }
491:
492: sub build_query_string {
493: my ($new_items) = @_;
494: my $query_string;
1.125 bisitz 495: my @formelements = ('register');
1.47 albertel 496: my $new = 0;
1.43 raeburn 497: if (ref($new_items) eq 'HASH') {
1.47 albertel 498: $new = 1;
1.125 bisitz 499: if (!defined($new_items->{'forceedit'}) &&
1.43 raeburn 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})) {
1.47 albertel 508: if ((!$new) || (!defined($new_items->{$element}))) {
1.43 raeburn 509: $query_string .= '&'.$element.'='.$env{'form.'.$element};
510: }
511: }
512: }
1.47 albertel 513: if ($new) {
1.43 raeburn 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 {
1.55 raeburn 523: my ($r,$is_course) = @_;
524: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.43 raeburn 525: my $query_string = &build_query_string();
1.146 raeburn 526: my $args = {'domain' => $cdom};
527: if ($env{'form.forcestudent'}) {
528: $args->{'function'} = 'student';
529: }
1.55 raeburn 530: my $output;
531: if ($is_course) {
1.146 raeburn 532: if (($env{'request.course.id'} eq $cdom.'_'.$cnum) &&
533: ($env{'form.register'})) {
534: $args->{force_register} = $env{'form.register'};
535: } else {
536: my %coursedescription = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
537: my $cdescr = $coursedescription{'description'};
538: my $brcrum = [{href=>"/adm/$cdom/$cnum/aboutme".$query_string,
539: text=>&mt('Course Information - [_1]',$cdescr),
540: no_mt=>1},
541: {href=>"/adm/$cdom/$cnum/aboutme/portfolio".$query_string,
542: text=>'Viewable group portfolio files'}
543: ];
544: $args->{bread_crumbs} = $brcrum;
545: }
546: $output = &Apache::loncommon::start_page('Viewable group portfolio files',undef,$args).
547: '<h3>'.&mt('Group Portfolio files').'</h3>';
1.55 raeburn 548: } else {
1.146 raeburn 549: if ($env{'request.course.id'} && $env{'form.register'}) {
550: $args->{force_register} = $env{'form.register'};
551: } else {
552: my $brcrum = [{href => "/adm/$cdom/$cnum/aboutme".$query_string,
553: text => &mt('Personal Information Page - [_1]',$name),
554: title => &mt('Go to personal information page for [_1]',$name),
555: no_mt => 1},
556: {href => "/adm/$cdom/$cnum/aboutme/portfolio".$query_string,
1.156 bisitz 557: text => &mt('Viewable files'),
1.146 raeburn 558: title => &mt('Viewable portfolio files for [_1]',$name),
559: no_mt => 1}
560: ];
561: $args->{bread_crumbs} = $brcrum;
562: }
563: $output =
564: &Apache::loncommon::start_page('Viewable portfolio files',
565: undef,$args).
566: '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
1.53 raeburn 567: }
1.43 raeburn 568: $r->print($output);
569: return;
570: }
571:
572: sub display_portfolio_files {
1.55 raeburn 573: my ($r,$is_course) = @_;
574: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.113 bisitz 575: my %lt = &Apache::lonlocal::texthash(
576: 'withoutpass' => 'passphrase not required',
577: 'withpass' => 'passphrase protected',
578: 'both' => 'all access types ',
579: );
1.47 albertel 580:
1.43 raeburn 581: my $portaccess = 'withoutpass';
582: if (exists($env{'form.portaccess'})) {
583: $portaccess = $env{'form.portaccess'};
584: }
1.47 albertel 585:
1.45 albertel 586: my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
1.134 amueller 587: .'" name="displaystatus" method="post">'.
588: &mt('File access type: ').'<select name="portaccess">';
1.43 raeburn 589: foreach my $type ('withoutpass','withpass','both') {
590: $output .= '<option value="'.$type.'" ';
591: if ($portaccess eq $type) {
592: $output .= 'selected="selected"';
593: }
1.53 raeburn 594: $output .= '>'.$lt{$type}.'</option>';
1.43 raeburn 595: }
1.146 raeburn 596: $output .= '</select>'."\n";
597: if ($env{'form.register'}) {
598: $output .= '<input type="hidden" name="register" value="'.$env{'form.register'}.'" />'."\n";
599: }
600: $output .= '<input type="submit" name="portaccessbutton" value="'.
601: &mt('Update display').'" />'.
602: '</form><br /><br />';
1.43 raeburn 603: $r->print($output);
1.64 raeburn 604: my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
605: $cdom,$cnum,$name);
1.53 raeburn 606: if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
1.146 raeburn 607: if ($env{'request.course.id'} && $env{'form.register'}) {
608: my $query_string = &build_query_string();
609: $r->print('<br /><a href="/adm/'.$cdom.'/'.$cnum.
610: '/aboutme'.$query_string.'">');
611: if ($is_course) {
612: $r->print(&mt('Course Information page'));
613: } else {
614: $r->print(&mt('Information about [_1]',$name));
615: }
616: $r->print('</a>');
1.55 raeburn 617: }
1.53 raeburn 618: }
1.43 raeburn 619: return;
620: }
621:
622: sub portfolio_files {
1.64 raeburn 623: my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
1.43 raeburn 624: my $filecounts = {
625: withpass => 0,
626: withoutpass => 0,
627: both => 0,
628: };
629: my $current_permissions =
1.134 amueller 630: &Apache::lonnet::get_portfile_permissions($cdom,$cnum);
1.125 bisitz 631: my %access_controls =
1.134 amueller 632: &Apache::lonnet::get_access_controls($current_permissions);
1.43 raeburn 633: my $portaccess;
634: if ($mode eq 'showlink') {
635: $portaccess = 'both';
636: } else {
637: $portaccess = 'withoutpass';
638: if (exists($env{'form.portaccess'})) {
639: $portaccess = $env{'form.portaccess'};
640: }
641: }
642:
1.55 raeburn 643: my $diroutput;
644: if ($is_course) {
645: my %files_by_group;
1.157 raeburn 646: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.55 raeburn 647: foreach my $filename (sort(keys(%access_controls))) {
648: my ($group,$path) = split('/',$filename,2);
1.157 raeburn 649: if (exists($curr_groups{$group})) {
650: $files_by_group{$group}{$path} = $access_controls{$filename};
651: }
1.55 raeburn 652: }
653: foreach my $group (sort(keys(%files_by_group))) {
654: my %fileshash;
655: my $grpout .= &build_hierarchy($r,$cdom,$cnum,$portaccess,
656: $is_course,$filecounts,$mode,
657: $files_by_group{$group},
658: \%fileshash,$group);
659: if ($grpout) {
660: $diroutput .= '<h3>'.$group.'</h3>'.$grpout.'<br />';
661: }
662: }
663: } else {
664: my %allfileshash;
665: $diroutput = &build_hierarchy($r,$cdom,$cnum,$portaccess,$is_course,
666: $filecounts,$mode,\%access_controls,
667: \%allfileshash);
668: }
669: if ($mode eq 'listfiles') {
670: if ($filecounts->{'both'}) {
671: $r->print($diroutput);
672: } else {
673: my $access_text;
674: if (ref($lt) eq 'HASH') {
1.125 bisitz 675: $access_text = $lt->{$portaccess};
1.55 raeburn 676: }
677: $r->print(&mt('There are no available files of the specified access type: [_1]',$access_text));
678: }
679: }
680: return $filecounts;
681: }
682:
683: sub build_hierarchy {
684: my ($r,$cdom,$cnum,$portaccess,$is_course,$filecounts,$mode,$access_info,
685: $allfileshash,$group) = @_;
1.159 raeburn 686: my $clientip = &Apache::lonnet::get_requestor_ip($r);
1.55 raeburn 687: foreach my $filename (sort(keys(%{$access_info}))) {
688: my $access_status =
1.158 raeburn 689: &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,$group,$clientip,
690: $access_info->{$filename});
1.43 raeburn 691: if ($portaccess eq 'both') {
692: if (($access_status ne 'ok') &&
693: ($access_status !~ /^[^:]+:guest_/)) {
694: next;
695: }
696: } elsif ($portaccess eq 'withoutpass') {
697: if ($access_status ne 'ok') {
698: next;
699: }
700: } elsif ($portaccess eq 'withpass') {
701: if ($access_status !~ /^[^:]+:guest_/) {
702: next;
703: }
704: }
705: if ($mode eq 'listfiles') {
706: $filename =~ s/^\///;
707: my @pathitems = split('/',$filename);
1.55 raeburn 708: my $lasthash = $allfileshash;
1.43 raeburn 709: while (@pathitems > 1) {
710: my $newlevel = shift(@pathitems);
711: if (!exists($lasthash->{$newlevel})) {
712: $lasthash->{$newlevel} = {};
713: }
714: $lasthash = $lasthash->{$newlevel};
715: }
716: $lasthash->{$pathitems[0]} = $filename;
717: }
718: if ($access_status eq 'ok') {
719: $filecounts->{'withoutpass'} ++;
720: } elsif ($access_status =~ /^[^:]+:guest_/) {
721: $filecounts->{'withpass'} ++;
722: }
723: }
724: $filecounts->{'both'} = $filecounts->{'withoutpass'} +
725: $filecounts->{'withpass'};
1.55 raeburn 726: my $output;
1.43 raeburn 727: if ($mode eq 'listfiles') {
1.55 raeburn 728: if ($filecounts->{'both'} > 0) {
1.129 bisitz 729: $output = &Apache::loncommon::start_data_table();
1.55 raeburn 730: $output .= &parse_directory($r,0,$allfileshash,'',$is_course,
731: $group);
1.129 bisitz 732: $output .= &Apache::loncommon::end_data_table();
1.43 raeburn 733: }
1.45 albertel 734: }
1.55 raeburn 735: return $output;
1.45 albertel 736: }
737:
1.43 raeburn 738: sub parse_directory {
1.55 raeburn 739: my ($r,$depth,$currhash,$path,$is_course,$group) = @_;
740: my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
1.45 albertel 741: $depth++;
742: my $output;
1.49 albertel 743:
1.55 raeburn 744: my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
745: $group);
1.70 raeburn 746: my $getpropath = 1;
1.148 raeburn 747: my ($listref,$listerror) =
748: &Apache::lonnet::dirlist($portfolio_root.$path,$cdom,$cnum,$getpropath);
749: my %dirlist;
750: if (ref($listref) eq 'ARRAY') {
751: %dirlist = map { ((split('&',$_,2))[0],1) } @{$listref};
752: }
1.43 raeburn 753: foreach my $item (sort(keys(%{$currhash}))) {
1.129 bisitz 754: $output .= &Apache::loncommon::start_data_table_row();
1.45 albertel 755: $output .= '<td style="padding-left: '.($depth*25).'px">';
1.43 raeburn 756: if (ref($currhash->{$item}) eq 'HASH') {
1.45 albertel 757: my $title=&HTML::Entities::encode($item,'<>&"');
758: $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" /> '.$title;
1.134 amueller 759: $output .= '</td><td> </td>'
1.129 bisitz 760: .&Apache::loncommon::end_data_table_row();
1.49 albertel 761: $output .= &parse_directory($r,$depth,$currhash->{$item},
1.134 amueller 762: $path.'/'.$item,$is_course,$group);
1.43 raeburn 763: } else {
1.134 amueller 764: my $file_name;
765: if ($currhash->{$item} =~ m|/([^/]+)$|) {
766: $file_name = $1;
767: } else {
768: $file_name = $currhash->{$item};
769: }
770: my $have_meta = exists($dirlist{$file_name.'.meta'});
1.55 raeburn 771: my $url;
772: if ($is_course) {
773: $url = '/uploaded/'.$cdom.'/'.$cnum.'/groups/'.$group.
1.133 amueller 774: '/portfolio/'.$currhash->{$item};
1.125 bisitz 775: } else {
1.134 amueller 776: $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.$currhash->{$item};
1.55 raeburn 777: }
1.43 raeburn 778: my $showname;
1.134 amueller 779: if ($have_meta) {
780: $showname = &Apache::lonnet::metadata($url,'title');
781: }
782: if ($showname eq '') {
783: $showname = $file_name;
784: } else {
785: $showname = $file_name.' ('.$showname.')';
786: }
1.50 albertel 787:
1.45 albertel 788: $showname=&HTML::Entities::encode($showname,'<>&"');
1.49 albertel 789: $output .= '<a href="'.$url.'">'.
1.134 amueller 790: '<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
791: ' '.$showname.'</a>';
792: $output.='</td><td>';
793: if ($have_meta) {
794: $output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Metadata').'" src="'.
1.144 droeschl 795: &Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.png').
1.134 amueller 796: '" class="LC_icon" /></a>';
797: }
798: $output .= '</td>'
1.133 amueller 799: .&Apache::loncommon::end_data_table_row();
1.43 raeburn 800: }
1.133 amueller 801: }
1.45 albertel 802: return $output;
1.43 raeburn 803: }
1.1 www 804:
1.77 raeburn 805: sub aboutme_access {
806: my ($uname,$udom) = @_;
807: my $privcheck = $env{'request.course.id'};
808: my $sec;
809: if ($env{'request.course.sec'} ne '') {
810: $sec = $env{'request.course.sec'};
811: $privcheck .= '/'.$sec;
812: }
813: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
814: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
815: if (($cdom eq '') || ($cnum eq '')) {
1.142 raeburn 816: my %coursehash = &Apache::lonnet::coursedescription($env{'request.course.id'});
1.77 raeburn 817: $cdom = $coursehash{'domain'};
818: $cnum = $coursehash{'cnum'};
819: }
1.125 bisitz 820: if ((&Apache::lonnet::allowed('srm',$privcheck)) ||
1.84 raeburn 821: (&Apache::lonnet::allowed('dff',$privcheck))) {
1.151 raeburn 822: if (&Apache::lonnet::in_course($uname,$udom,$cnum,$cdom,undef,1)) {
1.77 raeburn 823: return 1;
824: }
825: }
826: return;
827: }
828:
1.1 www 829: 1;
830: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>