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