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