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