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