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