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