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