1: # The LearningOnline Network
2: # "About Me" Personal Information
3: #
4: # $Id: lonaboutme.pm,v 1.54 2006/09/13 21:37:29 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: if ($filecounts->{'both'} == 1) {
282: $output .= &mt('One portfolio file owned by [_2] is available.',$filecounts->{'both'},$name).'<ul>';
283: } else {
284: $output .= &mt('A total of [_1] portfolio files owned by [_2] are available.',$filecounts->{'both'},$name).'<ul>';
285: }
286: if ($filecounts->{'withoutpass'}) {
287: $output .= '<li>'.&mt('[quant,_1,file is,files are] publicly accessible.',$filecounts->{'withoutpass'}).'</li>';
288: }
289: if ($filecounts->{'withpass'}) {
290: $output .= '<li>'.&mt('[quant,_1,file requires,files require] a passphrase for access.',$filecounts->{'withpass'}).'</li>';
291: }
292: $output .= '</ul>';
293: }
294: $r->print($output);
295: return;
296: }
297:
298: sub build_query_string {
299: my ($new_items) = @_;
300: my $query_string;
301: my @formelements = ('register');
302: my $new = 0;
303: if (ref($new_items) eq 'HASH') {
304: $new = 1;
305: if (!defined($new_items->{'forceedit'}) &&
306: !defined($new_items->{'forcestudent'})) {
307: push(@formelements,('forceedit','forcestudent'));
308: }
309: } else {
310: push(@formelements,('forceedit','forcestudent'));
311: }
312: foreach my $element (@formelements) {
313: if (exists($env{'form.'.$element})) {
314: if ((!$new) || (!defined($new_items->{$element}))) {
315: $query_string .= '&'.$element.'='.$env{'form.'.$element};
316: }
317: }
318: }
319: if ($new) {
320: foreach my $key (keys(%{$new_items})) {
321: $query_string .= '&'.$key.'='.$new_items->{$key};
322: }
323: }
324: $query_string =~ s/^\&/\?/;
325: return $query_string;
326: }
327:
328: sub display_portfolio_header {
329: my ($r) = @_;
330: my ($cdom,$cnum,$name) = &aboutme_info($r);
331: my $query_string = &build_query_string();
332: &Apache::lonhtmlcommon::clear_breadcrumbs();
333: my $forcestudent='';
334: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
335: my $output =
336: &Apache::loncommon::start_page('Viewable portfolio files',undef,
337: {'function' => $forcestudent,
338: 'domain' => $cdom,});
339: if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
340: &Apache::lonhtmlcommon::add_breadcrumb
341: ({href=>"/adm/$cdom/$cnum/aboutme".$query_string,
342: text=>"Personal information - $name",
343: title=>"Go to personal information page for $name"},
344: {href=>"/adm/$cdom/$cnum/aboutme/portfolio",
345: text=>"Viewable files - $name",
346: title=>"Viewable portfolio files for $name"}
347: );
348: $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Viewable portfolio files.'));
349: }
350: $output .= '<h3>'.&mt('Portfolio files for [_1]',$name).'</h3>';
351: $r->print($output);
352: return;
353: }
354:
355: sub display_portfolio_files {
356: my ($r) = @_;
357: my ($cdom,$cnum,$name) = &aboutme_info($r);
358: my %lt = ( withoutpass => 'passphrase not required',
359: withpass => 'passphrase protected',
360: both => 'all access types ',);
361: %lt = &Apache::lonlocal::texthash(%lt);
362:
363: my $portaccess = 'withoutpass';
364: if (exists($env{'form.portaccess'})) {
365: $portaccess = $env{'form.portaccess'};
366: }
367:
368: my $output = '<form action="'.&HTML::Entities::encode($r->uri,'<>&"')
369: .'" name="displaystatus" method="post">'.
370: &mt('File access type: ').'<select name="portaccess">';
371: foreach my $type ('withoutpass','withpass','both') {
372: $output .= '<option value="'.$type.'" ';
373: if ($portaccess eq $type) {
374: $output .= 'selected="selected"';
375: }
376: $output .= '>'.$lt{$type}.'</option>';
377: }
378: $output .= '</select>'."\n".
379: '<input type="submit" name="portaccessbutton" value="'.
380: &mt('Update display').'" />';
381: $output .= '</form><br /><br />';
382: $r->print($output);
383: my $filecounts = &portfolio_files($r,'listfiles',\%lt);
384: if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
385: my $query_string = &build_query_string();
386: $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
387: '/aboutme'.$query_string.'">'.
388: &mt('Information about [_1]',$name).'</a>');
389: }
390: return;
391: }
392:
393: sub portfolio_files {
394: my ($r,$mode,$lt) = @_;
395: my ($cdom,$cnum,$name) = &aboutme_info($r);
396: my $filecounts = {
397: withpass => 0,
398: withoutpass => 0,
399: both => 0,
400: };
401: my $current_permissions =
402: &Apache::lonnet::get_portfile_permissions($cdom,$cnum);
403: my %access_controls =
404: &Apache::lonnet::get_access_controls($current_permissions);
405: my %allfileshash;
406: my $portaccess;
407: if ($mode eq 'showlink') {
408: $portaccess = 'both';
409: } else {
410: $portaccess = 'withoutpass';
411: if (exists($env{'form.portaccess'})) {
412: $portaccess = $env{'form.portaccess'};
413: }
414: }
415:
416: foreach my $filename (keys(%access_controls)) {
417: my $access_status =
418: &Apache::lonnet::get_portfolio_access($cdom,$cnum,$filename,undef,
419: $access_controls{$filename});
420: if ($portaccess eq 'both') {
421: if (($access_status ne 'ok') &&
422: ($access_status !~ /^[^:]+:guest_/)) {
423: next;
424: }
425: } elsif ($portaccess eq 'withoutpass') {
426: if ($access_status ne 'ok') {
427: next;
428: }
429: } elsif ($portaccess eq 'withpass') {
430: if ($access_status !~ /^[^:]+:guest_/) {
431: next;
432: }
433: }
434: if ($mode eq 'listfiles') {
435: $filename =~ s/^\///;
436: my @pathitems = split('/',$filename);
437: my $lasthash = \%allfileshash;
438: while (@pathitems > 1) {
439: my $newlevel = shift(@pathitems);
440: if (!exists($lasthash->{$newlevel})) {
441: $lasthash->{$newlevel} = {};
442: }
443: $lasthash = $lasthash->{$newlevel};
444: }
445: $lasthash->{$pathitems[0]} = $filename;
446: }
447: if ($access_status eq 'ok') {
448: $filecounts->{'withoutpass'} ++;
449: } elsif ($access_status =~ /^[^:]+:guest_/) {
450: $filecounts->{'withpass'} ++;
451: }
452: }
453: $filecounts->{'both'} = $filecounts->{'withoutpass'} +
454: $filecounts->{'withpass'};
455: if ($mode eq 'listfiles') {
456: my $output;
457: if (keys(%allfileshash) > 0) {
458: $output = &portfolio_table_start();
459: $output .= &parse_directory($r,0,\%allfileshash,'');
460: $output .= '</table>';
461: } else {
462: my $access_text;
463: if (ref($lt) eq 'HASH') {
464: $access_text = $lt->{$portaccess};
465: }
466: $output .= &mt('There are no available files of the specified access type: [_1]',$access_text);
467: }
468: $r->print($output);
469: }
470: return $filecounts;
471: }
472:
473: {
474: my $count=0;
475: sub portfolio_table_start {
476: $count=0;
477: return '<table class="LC_aboutme_port">';
478: }
479: sub portfolio_row_start {
480: $count++;
481: my $class = ($count%2)?'LC_odd_row'
482: :'LC_even_row';
483: return '<tr class="'.$class.'">';
484: }
485: }
486:
487: sub parse_directory {
488: my ($r,$depth,$currhash,$path) = @_;
489: my ($cdom,$cnum,$name) = &aboutme_info($r);
490: $depth++;
491: my $output;
492:
493: my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum);
494: my %dirlist = map {
495: ((split('&',$_,2))[0],1)
496: } &Apache::lonnet::dirlist($path,$cdom,$cnum,$portfolio_root);
497: foreach my $item (sort(keys(%{$currhash}))) {
498: $output .= &portfolio_row_start();
499: $output .= '<td style="padding-left: '.($depth*25).'px">';
500: if (ref($currhash->{$item}) eq 'HASH') {
501: my $title=&HTML::Entities::encode($item,'<>&"');
502: $output .= '<img src="'.&Apache::loncommon::lonhttpdurl("/adm/lonIcons/navmap.folder.open.gif").'" alt="'.&mt('Folder').' '.$title.'" class="LC_icon" /> '.$title;
503: $output .= '</td><td></td></tr>';
504: $output .= &parse_directory($r,$depth,$currhash->{$item},
505: $path.'/'.$item);
506: } else {
507:
508:
509: my $file_name;
510: if ($currhash->{$item} =~ m|/([^/]+)$|) {
511: $file_name = $1;
512: } else {
513: $file_name = $currhash->{$item};
514: }
515: my $have_meta = exists($dirlist{$file_name.'.meta'});
516: my $url = '/uploaded/'.$cdom.'/'.$cnum.'/portfolio/'.
517: $currhash->{$item};
518:
519: my $showname;
520: if ($have_meta) {
521: $showname = &Apache::lonnet::metadata($url,'title');
522: }
523: if ($showname eq '') {
524: $showname = $file_name;
525: } else {
526: $showname = $file_name.' ('.$showname.')';
527: }
528:
529: $showname=&HTML::Entities::encode($showname,'<>&"');
530: $output .= '<a href="'.$url.'">'.
531: '<img alt="" src="'.&Apache::loncommon::icon($currhash->{$item}).'" class="LC_icon" />'.
532: ' '.$showname.'</a>';
533: $output.='</td><td>';
534: if ($have_meta) {
535: $output.= '<a href="'.$url.'.meta"><img alt="'.&mt('Catalog Information').'" src="'.
536: &Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').
537: '" class="LC_icon" /></a>';
538: }
539: $output .= '</td></tr>';
540: }
541: }
542: return $output;
543: }
544:
545: 1;
546: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>