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