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