1: # The LearningOnline Network
2: # "About Me" Personal Information
3: #
4: # $Id: lonaboutme.pm,v 1.52 2006/08/16 19:40:46 albertel Exp $
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;
35: use Apache::lontexconvert;
36: use Apache::lonfeedback;
37: use Apache::lonrss();
38: use Apache::lonlocal;
39: use Apache::lonmsgdisplay();
40: use HTML::Entities();
41:
42: sub handler {
43: my $r = shift;
44: &Apache::loncommon::content_type($r,'text/html');
45: $r->send_http_header;
46: return OK if $r->header_only;
47: my $target=$env{'form.grade_target'};
48: # ------------------------------------------------------------ Print the screen
49: if ($target eq 'tex') {
50: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
51: }
52: my (undef,undef,$cdom,$cnum,undef,$action)=split(/\//,$r->uri);
53: # Is this even a user?
54: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
55: &Apache::loncommon::simple_error_page($r,'No info',
56: 'No user information available');
57: return OK;
58: }
59: # --------------------------------------------------------- The syllabus fields
60: my %syllabusfields=&Apache::lonlocal::texthash(
61: 'aaa_contactinfo' => 'Contact Information',
62: 'bbb_aboutme' => 'About Me',
63: 'ccc_webreferences' => 'Web References');
64:
65: # ------------------------------------------------------------ Get Query String
66: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
67: ['forceedit','forcestudent',
68: 'register']);
69:
70: # ----------------------------------------------- Available Portfolio file display
71: if (($target ne 'tex') && ($action eq 'portfolio')) {
72: &display_portfolio_header($r);
73: &display_portfolio_files($r);
74: $r->print(&Apache::loncommon::end_page());
75: return OK;
76: }
77:
78: # --------------------------------------------------------------- Force Student
79: my $forcestudent='';
80: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
81:
82: my $forceregister = '';
83: if ($forcestudent eq '') {
84: $forceregister = $env{'form.register'};
85: }
86:
87: # --------------------------------------- There is such a user, get environment
88: my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
89: if ($target ne 'tex') {
90: my $start_page =
91: &Apache::loncommon::start_page("Personal Information",undef,
92: {'function' => $forcestudent,
93: 'domain' => $cdom,
94: 'force_register' =>
95: $forceregister,});
96: $r->print($start_page);
97: $r->print('<h1>'.&Apache::loncommon::plainname($cnum,$cdom).'</h1>');
98: } else {
99: $r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
100: }
101: if ($courseenv{'nickname'}) {
102: $r->print(
103: '<h2>"'.$courseenv{'nickname'}.
104: '"</h2>');
105: }
106: if ($target ne 'tex') {
107: $r->print('<h3>'.$Apache::lonnet::domaindescription{$cdom}.'</h3>'.
108: '<p>'.&Apache::loncommon::messagewrapper('Send me a message',$cnum,$cdom).'</p>'.&Apache::lonrss::advertisefeeds($cnum,$cdom));
109: } else {
110: $r->print('\textbf{'.$Apache::lonnet::domaindescription{$cdom}.'}\\\\');
111: }
112: my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
113: my $allowed=0;
114:
115: # does this user have privileges to post, etc?
116:
117: my $privleged=$allowed=(($env{'user.name'} eq $cnum) &&
118: ($env{'user.domain'} eq $cdom));
119: if ($forcestudent or $target eq 'tex') { $allowed=0; }
120:
121: if ($allowed) {
122: my $query_string = &build_query_string({'forcestudent' => '1',});
123: $r->print('<p><b>'.&mt('Privacy Note').':</b> '.
124: &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.').
125: '</p>'.
126: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'</p><p><a href="'.$r->uri.$query_string.'">Show Public View</a>'.
127: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
128: } elsif ($privleged && $target ne 'tex') {
129: my $query_string = &build_query_string({'forceedit' => '1',});
130: $r->print('<p><a href="'.$r->uri.$query_string.'"><font size="+1">'.
131: &mt('Edit').'</font></a></p>');
132: }
133: if (($env{'form.uploaddoc.filename'}) &&
134: ($env{'form.storeupl'}) && ($allowed)) {
135: if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
136: if ($syllabus{'uploaded.photourl'}) {
137: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
138: }
139: $syllabus{'uploaded.photourl'}=
140: &Apache::lonnet::userfileupload('uploaddoc',undef,'aboutme');
141: }
142: $syllabus{'uploaded.lastmodified'}=time;
143: &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
144: }
145: if ($allowed && $env{'form.delupl'}) {
146: if ($syllabus{'uploaded.photourl'}) {
147: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
148: delete($syllabus{'uploaded.photourl'});
149: &Apache::lonnet::del('aboutme',['uploaded.photourl'],$cdom,$cnum);
150: }
151: }
152: if (($allowed) && ($env{'form.storesyl'})) {
153: foreach (keys %syllabusfields) {
154: my $field=$env{'form.'.$_};
155: $field=~s/\s+$//s;
156: $field=&Apache::lonfeedback::clear_out_html($field,
157: $env{'user.adv'});
158: $syllabus{$_}=$field;
159: }
160: $syllabus{'uploaded.lastmodified'}=time;
161: &Apache::lonnet::put('aboutme',\%syllabus,$cdom,$cnum);
162: }
163:
164: # ---------------------------------------------------------------- Get syllabus
165: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
166: my $lastmod=$syllabus{'uploaded.lastmodified'};
167: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
168: $r->print(&mt('Last updated').': '.$lastmod);
169: if ($syllabus{'uploaded.photourl'}) {
170: &Apache::lonnet::allowuploaded('/adm/aboutme',
171: $syllabus{'uploaded.photourl'});
172: my $image=
173: qq{<img src="$syllabus{'uploaded.photourl'}" align="right" />};
174: if ($target eq 'tex') {
175: $image=&Apache::lonxml::xmlparse($r,'tex',$image);
176: }
177: $r->print($image);
178: }
179: if ($allowed) {
180: $r->print(
181: '<form method="post">
182: <input type="submit" name="delupl" value="Delete Photo" />
183: </form>'.
184: '<form method="post" enctype="multipart/form-data">'.
185: '<h3>'.&mt('Upload a Photo').'</h3>'.
186: '<input type="file" name="uploaddoc" size="50">'.
187: '<input type="submit" name="storeupl" value="Upload">'.
188: '</form><form method="post">');
189:
190: }
191: foreach (sort keys %syllabusfields) {
192: if (($syllabus{$_}) || ($allowed)) {
193: my $message=$syllabus{$_};
194: &Apache::lonfeedback::newline_to_br(\$message);
195: $message
196: =~s/(http\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
197: if ($allowed) {
198: $message=&Apache::lonspeller::markeduptext($message);
199: }
200: $message=&Apache::lontexconvert::msgtexconverted($message);
201: if ($target ne 'tex') {
202: $r->print('<h3>'.$syllabusfields{$_}.'</h3><blockquote>'.
203: $message.'</blockquote>');
204: } else {
205: $r->print('\\\\\textbf{'.$syllabusfields{$_}.'}\\\\'.
206: &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
207: }
208: if ($allowed) {
209: $r->print('<br /><textarea cols="80" rows="6" name="'.$_.'">'.
210: &HTML::Entities::encode($syllabus{$_},'"&<>').
211: '</textarea><input type="submit" name="storesyl" value="'.
212: &mt('Store').'" />');
213: }
214: }
215: }
216: if ($allowed) {
217: $r->print('</form>');
218: }
219: if ($target ne 'tex') {$r->print('<br />');} else {$r->print('\\\\');}
220: } else {
221: $r->print('<p>'.&mt('No personal information provided').'.</p>');
222: }
223:
224: if ($target ne 'tex') {
225: &print_portfiles_link($r);
226: }
227:
228: if ($env{'request.course.id'}) {
229: if (&Apache::lonnet::allowed('srm',$env{'request.course.id'})) {
230: if ($target ne 'tex') {
231: $r->print('<a name="coursecomment" />');
232: $r->print('<hr /><h3>'.
233: &mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'</h3>'.
234: &mt('Shared by course faculty and staff').
235: &Apache::loncommon::help_open_topic("Course_Face_To_Face_Records,Course_Critical_Message").
236: '<br />');
237: &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
238: $r->print('<hr />');
239: if (&Apache::lonnet::allowed('vsa',
240: $env{'request.course.id'}) ||
241: &Apache::lonnet::allowed('vsa',
242: $env{'request.course.id'}.'/'.
243: $env{'request.course.sec'})) {
244: $r->print(&Apache::loncommon::track_student_link
245: ('View recent activity by this student',
246: $cnum,$cdom).(' 'x2));
247: }
248: $r->print(&Apache::loncommon::noteswrapper('Add Records',$cnum,$cdom));
249: } else {
250: $r->print('\\\\\textbf{'.&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course').'}\\\\'.&mt('Shared by course faculty and staff').'\\\\\\\\');
251: &Apache::lonmsgdisplay::disfacetoface($r,$cnum,$cdom);
252: }
253: }
254: }
255: if ($target ne 'tex') {
256: $r->print(&Apache::loncommon::end_page());
257: } else {
258: $r->print('\end{document}');
259: }
260: return OK;
261: }
262:
263: sub aboutme_info {
264: my ($r) = @_;
265: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
266: my $name = &Apache::loncommon::plainname($cnum,$cdom);
267: return ($cdom,$cnum,$name);
268: }
269:
270: sub print_portfiles_link {
271: my ($r) = @_;
272: my ($cdom,$cnum,$name) = &aboutme_info($r);
273: my $filecounts = &portfolio_files($r,'showlink');
274: my $query_string = &build_query_string();
275: my $output;
276: if ($filecounts->{'both'} > 0) {
277: $output = &mt('<h3>Viewable portfolio files</h3>');
278: $output .= '<a href="/adm/'.$cdom.'/'.$cnum.'/aboutme/portfolio'.
279: $query_string.'">'.&mt('Display file listing').
280: '</a><br /><br />';
281: $output .= &mt('A total of [quant,_1,portfolio file] owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
282: if ($filecounts->{'withoutpass'}) {
283: $output .= '<li>'.&mt('[quant,_1,file] are publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
284: }
285: if ($filecounts->{'withpass'}) {
286: $output .= '<li>'.&mt('[quant,_1,file] require a passphrase for access.',$filecounts->{'withpass'}).'</li>';
287: }
288: $output .= '</ul>';
289: }
290: $r->print($output);
291: return;
292: }
293:
294: sub build_query_string {
295: my ($new_items) = @_;
296: my $query_string;
297: my @formelements = ('register');
298: my $new = 0;
299: if (ref($new_items) eq 'HASH') {
300: $new = 1;
301: if (!defined($new_items->{'forceedit'}) &&
302: !defined($new_items->{'forcestudent'})) {
303: push(@formelements,('forceedit','forcestudent'));
304: }
305: } else {
306: push(@formelements,('forceedit','forcestudent'));
307: }
308: foreach my $element (@formelements) {
309: if (exists($env{'form.'.$element})) {
310: if ((!$new) || (!defined($new_items->{$element}))) {
311: $query_string .= '&'.$element.'='.$env{'form.'.$element};
312: }
313: }
314: }
315: if ($new) {
316: foreach my $key (keys(%{$new_items})) {
317: $query_string .= '&'.$key.'='.$new_items->{$key};
318: }
319: }
320: $query_string =~ s/^\&/\?/;
321: return $query_string;
322: }
323:
324: sub display_portfolio_header {
325: my ($r) = @_;
326: my ($cdom,$cnum,$name) = &aboutme_info($r);
327: my $query_string = &build_query_string();
328: &Apache::lonhtmlcommon::clear_breadcrumbs();
329: my $forcestudent='';
330: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
331: my $output =
332: &Apache::loncommon::start_page('Viewable portfolio files',undef,
333: {'function' => $forcestudent,
334: 'domain' => $cdom,});
335: &Apache::lonhtmlcommon::add_breadcrumb
336: ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
337: text=>"Personal information - $name",
338: title=>"Go to personal information page for $name"},
339: {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
340: text=>"Viewable files - $name",
341: title=>"Viewable portfolio files for $name"}
342: );
343: $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
344: $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
345: $r->print($output);
346: return;
347: }
348:
349: sub display_portfolio_files {
350: my ($r) = @_;
351: my ($cdom,$cnum,$name) = &aboutme_info($r);
352: my %lt = ( withoutpass => 'passphrase not required',
353: withpass => 'passphrase protected',
354: both => 'all access types ',);
355: %lt = &Apache::lonlocal::texthash(%lt);
356:
357: my $portaccess = 'withoutpass';
358: if (exists($env{'form.portaccess'})) {
359: $portaccess = $env{'form.portaccess'};
360: }
361:
362: my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
363: .'" name="displaystatus" method="post">'.
364: &mt('File access type: ').'<select name="portaccess">';
365: foreach my $type ('withoutpass','withpass','both') {
366: $output .= '<option value="'.$type.'" ';
367: if ($portaccess eq $type) {
368: $output .= 'selected="selected"';
369: }
370: $output .= '>'.&mt($type).'</option>';
371: }
372: $output .= '</select>'."\n".
373: '<input type="submit" name="portaccessbutton" value="'.
374: &mt('Update display').'" />';
375: $output .= '</form><br /><br />';
376: $r->print($output);
377: my $filecounts = &portfolio_files($r,'listfiles',\%lt);
378: my $query_string = &build_query_string();
379: $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
380: '/aboutme'.$query_string.'">'.
381: &mt('Information about [_1]',$name).'</a>');
382: return;
383: }
384:
385: sub portfolio_files {
386: my ($r,$mode,$lt) = @_;
387: my ($cdom,$cnum,$name) = &aboutme_info($r);
388: my $filecounts = {
389: withpass => 0,
390: withoutpass => 0,
391: both => 0,
392: };
393: my $current_permissions =
394: &Apache::lonnet::get_portfile_permissions($cdom,$cnum);
395: my %access_controls =
396: &Apache::lonnet::get_access_controls($current_permissions);
397: my %allfileshash;
398: my $portaccess;
399: if ($mode eq 'showlink') {
400: $portaccess = 'both';
401: } else {
402: $portaccess = 'withoutpass';
403: if (exists($env{'form.portaccess'})) {
404: $portaccess = $env{'form.portaccess'};
405: }
406: }
407:
408: foreach my $filename (keys(%access_controls)) {
409: my $access_status =
410: &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,undef,
411: $access_controls{$filename});
412: if ($portaccess eq 'both') {
413: if (($access_status ne 'ok') &&
414: ($access_status !~ /^[^:]+:guest_/)) {
415: next;
416: }
417: } elsif ($portaccess eq 'withoutpass') {
418: if ($access_status ne 'ok') {
419: next;
420: }
421: } elsif ($portaccess eq 'withpass') {
422: if ($access_status !~ /^[^:]+:guest_/) {
423: next;
424: }
425: }
426: if ($mode eq 'listfiles') {
427: $filename =~ s/^\///;
428: my @pathitems = split('/',$filename);
429: my $lasthash = \%allfileshash;
430: while (@pathitems > 1) {
431: my $newlevel = shift(@pathitems);
432: if (!exists($lasthash->{$newlevel})) {
433: $lasthash->{$newlevel} = {};
434: }
435: $lasthash = $lasthash->{$newlevel};
436: }
437: $lasthash->{$pathitems[0]} = $filename;
438: }
439: if ($access_status eq 'ok') {
440: $filecounts->{'withoutpass'} ++;
441: } elsif ($access_status =~ /^[^:]+:guest_/) {
442: $filecounts->{'withpass'} ++;
443: }
444: }
445: $filecounts->{'both'} = $filecounts->{'withoutpass'} +
446: $filecounts->{'withpass'};
447: if ($mode eq 'listfiles') {
448: my $output;
449: if (keys(%allfileshash) > 0) {
450: $output = &portfolio_table_start();
451: $output .= &parse_directory($r,0,\%allfileshash,'');
452: $output .= '</table>';
453: } else {
454: my $access_text;
455: if (ref($lt) eq 'HASH') {
456: $access_text = $lt->{$portaccess};
457: }
458: $output .= &mt('There are no available files of the specified access type: [_1]',$access_text);
459: }
460: $r->print($output);
461: }
462: return $filecounts;
463: }
464:
465: {
466: my $count=0;
467: sub portfolio_table_start {
468: $count=0;
469: return '<table class="LC_aboutme_port">';
470: }
471: sub portfolio_row_start {
472: $count++;
473: my $class = ($count%2)?'LC_odd_row'
474: :'LC_even_row';
475: return '<tr class="'.$class.'">';
476: }
477: }
478:
479: sub parse_directory {
480: my ($r,$depth,$currhash,$path) = @_;
481: my ($cdom,$cnum,$name) = &aboutme_info($r);
482: $depth++;
483: my $output;
484:
485: my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum);
486: my %dirlist = map {
487: ((split('&',$_,2))[0],1)
488: } &Apache::lonnet::dirlist($path,$cdom,$cnum,$portfolio_root);
489: foreach my $item (sort(keys(%{$currhash}))) {
490: $output .= &portfolio_row_start();
491: $output .= '<td style="padding-left: '.($depth*25).'px">';
492: if (ref($currhash->{$item}) eq 'HASH') {
493: my $title=&HTML::Entities::encode($item,'<>&"');
494: $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" /> '.$title;
495: $output .= '</td><td></td></tr>';
496: $output .= &parse_directory($r,$depth,$currhash->{$item},
497: $path.'/'.$item);
498: } else {
499:
500:
501: my $file_name;
502: if ($currhash->{$item} =~ m|/([^/]+)$|) {
503: $file_name = $1;
504: } else {
505: $file_name = $currhash->{$item};
506: }
507: my $have_meta = exists($dirlist{$file_name.'.meta'});
508: my $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
509: $currhash->{$item};
510:
511: my $showname;
512: if ($have_meta) {
513: $showname = &Apache::lonnet::metadata($url,'title');
514: }
515: if ($showname eq '') {
516: $showname = $file_name;
517: } else {
518: $showname = $file_name.' ('.$showname.')';
519: }
520:
521: $showname=&HTML::Entities::encode($showname,'<>&"');
522: $output .= '<a href="'.$url.'">'.
523: '<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
524: ' '.$showname.'</a>';
525: $output.='</td><td>';
526: if ($have_meta) {
527: $output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Catalog Information').'" src="'.
528: &Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
529: '" class="LC_icon" /></a>';
530: }
531: $output .= '</td></tr>';
532: }
533: }
534: return $output;
535: }
536:
537: 1;
538: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>