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