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