1: # The LearningOnline Network with CAPA
2: # Handler to display the coauthors
3: #
4: # $Id: lonviewcoauthors.pm,v 1.3 2023/11/04 01:56:04 raeburn 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: ##############################################################
30:
31: package Apache::lonviewcoauthors;
32:
33: use strict;
34: use Apache::loncommon();
35: use Apache::lonhtmlcommon();
36: use Apache::Constants qw(:common :http);
37: use Apache::lonlocal;
38: use Apache::lonnet;
39: use LONCAPA qw(:DEFAULT :match);
40:
41: ###################################################################
42: ###################################################################
43:
44: ###################################################################
45: ###################################################################
46:
47: =pod
48:
49: =item &handler
50:
51: The typical handler you see in all these modules. Takes $r, the
52: http request, as an argument.
53:
54: =cut
55:
56: ###################################################################
57: ###################################################################
58: sub handler {
59: my $r=shift;
60: if ($r->header_only) {
61: &Apache::loncommon::content_type($r,'text/html');
62: $r->send_http_header;
63: return OK;
64: }
65: my ($role,$audom,$auname,$canview,$canedit,$start_page);
66: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
67: ['forceedit','state','action','caller']);
68:
69: # Get permissions
70: ($role,$audom,$auname,$canview,$canedit) = &get_allowable();
71: unless ($canview) {
72: $env{'user.error.msg'}=
73: "/adm/viewcoauthors:not in co-author role";
74: return HTTP_NOT_ACCEPTABLE;
75: }
76: &Apache::loncommon::content_type($r,'text/html');
77: $r->send_http_header;
78:
79: # Get view settings
80: my %viewsettings = &retrieve_view_settings($auname,$audom,$role);
81:
82: # Get caller
83: my $caller;
84: if ($env{'form.caller'} eq '/adm/createuser') {
85: $caller = $env{'form.caller'};
86: } else {
87: $caller = '/adm/viewcoauthors';
88: }
89:
90: # Get breadcrumbs
91: my $brcrum = [{'href' => $caller,
92: 'text' => 'Co-author listing'},];
93: if (($canedit) && ($env{'form.forceedit'})) {
94: &get_editor_crumbs($brcrum,$caller);
95: }
96:
97: # Print page header
98: my $args = { 'bread_crumbs' => $brcrum };
99: $r->print(&Apache::loncommon::start_page('Co-authors listing',undef,
100: $args));
101:
102: if (($canedit) && ($env{'form.forceedit'})) {
103: $r->print(&edit_settings($audom,$auname,$role,$caller,\%viewsettings));
104: } elsif ($viewsettings{'show'} eq 'none') {
105: $r->print('<h3>'.&mt('Coauthor-viewable listing').'</h3>'.
106: '<p class="LC_info">'.&mt('Listing of co-authors not enabled for this Authoring Space').'</p>');
107: } else {
108: &print_coauthors($r,$auname,$audom,$role,$caller,\%viewsettings);
109: }
110:
111: # Print page footer
112: $r->print(&Apache::loncommon::end_page());
113: return OK;
114: }
115:
116: sub get_allowable {
117: my ($role,$audom,$auname,$canview,$canedit);
118: if ($env{'request.role'} =~ m{^(ca|aa)\./($match_domain)/($match_username)$}) {
119: ($role,$audom,$auname) = ($1,$2,$3);
120: if ((&Apache::lonnet::allowed('vca',"$audom/$auname")) ||
121: (&Apache::lonnet::allowed('vaa',"$audom/$auname"))) {
122: if ($env{"environment.internal.manager./$audom/$auname"}) {
123: $canedit = 1;
124: }
125: }
126: $canview = 1;
127: } elsif ($env{'request.role'} eq "au./$env{'user.domain'}/") {
128: $role = 'au';
129: $auname = $env{'user.name'};
130: $audom = $env{'user.domain'};
131: if ((&Apache::lonnet::allowed('cca',"$audom/$auname")) ||
132: (&Apache::lonnet::allowed('caa',"$audom/$auname"))) {
133: $canedit = 1;
134: }
135: $canview = 1;
136: }
137: return ($role,$audom,$auname,$canview,$canedit);
138: }
139:
140: sub retrieve_view_settings {
141: my ($auname,$audom,$role) = @_;
142: my %viewsettings;
143: if (($auname ne '') & ($audom ne '')) {
144: if ($role eq 'au') {
145: if (exists($env{'environment.coauthorlist'})) {
146: $viewsettings{'show'} = $env{'environment.coauthorlist'};
147: }
148: if (exists($env{'environment.coauthoroptin'})) {
149: $viewsettings{'optin'} = $env{'environment.coauthoroptin'};
150: }
151: } elsif ($env{"environment.internal.coauthorlist./$audom/$auname"} =~ /^(role|all|none)$/) {
152: $viewsettings{'show'} = $env{"environment.internal.coauthorlist./$audom/$auname"};
153: $viewsettings{'optin'} = $env{"environment.internal.coauthoroptin./$audom/$auname"};
154: }
155: }
156: unless ((exists($viewsettings{'show'})) && (exists($viewsettings{'optin'}))) {
157: if ($audom ne '') {
158: my %domconfig =
159: &Apache::lonnet::get_dom('configuration',['authordefaults'],$audom);
160: my %domdefs;
161: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
162: if (exists($domconfig{'authordefaults'}{'coauthorlist'})) {
163: $domdefs{'show'} = $domconfig{'authordefaults'}{'coauthorlist'};
164: }
165: if (exists($domconfig{'authordefaults'}{'coauthoroptin'})) {
166: $domdefs{'optin'} = $domconfig{'authordefaults'}{'coauthoroptin'};
167: }
168: }
169: unless (exists($viewsettings{'show'})) {
170: if (exists($domdefs{'show'})) {
171: $viewsettings{'show'} = $domdefs{'show'};
172: }
173: }
174: unless (exists($viewsettings{'optin'})) {
175: if (exists($domdefs{'optin'})) {
176: $viewsettings{'optin'} = $domdefs{'optin'};
177: }
178: }
179: }
180: }
181: unless (exists($viewsettings{'show'})) {
182: $viewsettings{'show'} = 'none';
183: }
184: unless (exists($viewsettings{'optin'})) {
185: $viewsettings{'optin'} = '0';
186: }
187: return %viewsettings;
188: }
189:
190: sub get_editor_crumbs {
191: my ($brcrum,$caller) = @_;
192: my $querystr = '?forceedit=1';
193: if ($caller eq '/adm/createuser') {
194: $querystr .= '&action=calist';
195: }
196: if (ref($brcrum) eq 'ARRAY') {
197: push(@{$brcrum},
198: {'href' => $caller.$querystr,
199: 'text' => 'Configure co-author listing'});
200: if ($env{'form.state'} eq 'setconfig') {
201: push(@{$brcrum},
202: {'href' => $caller.$querystr,
203: 'text' => 'Result'});
204: }
205: }
206: return;
207: }
208:
209: sub edit_settings {
210: my ($audom,$auname,$role,$caller,$settingsref) = @_;
211: my %viewsettings;
212: if (ref($settingsref) eq 'HASH') {
213: %viewsettings = %{$settingsref};
214: } else {
215: %viewsettings = &retrieve_view_settings($auname,$audom,$role);
216: }
217: my %userenv = &Apache::lonnet::userenvironment($audom,$auname,
218: 'coauthorlist','coauthoroptin');
219: my %titles = &Apache::lonlocal::texthash (
220: coauthorlist => 'List availability',
221: coauthoroptin => 'User agreement needed for listing',
222: );
223: my %options = &Apache::lonlocal::texthash (
224: role => "List only same type of co-author role as viewer",
225: all => "List both co-author(s) and assistant co-author(s)",
226: none => "No listing",
227: );
228: my %lt = &Apache::lonlocal::texthash (
229: yes => 'Yes',
230: no => 'No',
231: slcc => 'Settings for listing of co-authors changed',
232: ncms => 'No changes made to settings for listing of co-authors',
233: apos => 'A problem occurred saving your changes.',
234: cloc => 'Configure listing of co-authors',
235: set => 'Setting',
236: vale => 'Value',
237: sav => 'Save changes'
238: );
239: my $output;
240: if ($env{'form.state'} eq 'setconfig') {
241: my (%changed,$message);
242: my ($numchanged,%changes,%disallowed);
243: foreach my $key ('coauthorlist','coauthoroptin') {
244: if ($key eq 'coauthorlist') {
245: next unless ($env{'form.'.$key} =~ /^all|role|none$/);
246: } elsif ($key eq 'coauthoroptin') {
247: next unless ($env{'form.'.$key} =~ /^0|1$/);
248: }
249: if ($userenv{$key} ne $env{'form.'.$key}) {
250: $changed{$key} = $env{'form.'.$key};
251: }
252: }
253: if (keys(%changed)) {
254: my $putres = &Apache::lonnet::put('environment',\%changed,
255: $audom,$auname);
256: if ($putres eq 'ok') {
257: my $author;
258: if (($audom eq $env{'user.domain'}) && ($auname eq $env{'user.name'})) {
259: $author = 1;
260: }
261: my (%envhash,%newvaltext);
262: foreach my $key (keys(%changed)) {
263: if ($author) {
264: $envhash{"environment.$key"} = $changed{$key};
265: } else {
266: $envhash{"environment.internal.$key./$audom/$auname"} = $changed{$key};
267: }
268: if ($key eq 'coauthorlist') {
269: $newvaltext{$key} = $options{$changed{$key}};
270: } elsif ($key eq 'coauthoroptin') {
271: $newvaltext{$key} = ($changed{$key}? $lt{'yes'} : $lt{'no'});
272: }
273: }
274: &Apache::lonnet::appenv(\%envhash);
275: $output = '<h3>'.$lt{'slcc'}.'</h3><ul>';
276: foreach my $key ('coauthorlist','coauthoroptin') {
277: if (exists($changed{$key})) {
278: $output .= '<li>'.
279: &mt('[_1] set to "[_2]"',
280: $titles{$key},$newvaltext{$key}).
281: '</li>';
282: }
283: }
284: $output .= '</ul>';
285: } else {
286: $output = '<h3>'.$lt{'ncms'}.'</h3>'.
287: '<p class="LC_warning">'.$lt{'apos'}.'</p>';
288: }
289: } else {
290: $output = '<h3>'.$lt{'ncms'}.'</h3>';
291: }
292: } else {
293: my %sel;
294: foreach my $option (keys(%options)) {
295: if ($option eq $viewsettings{'show'}) {
296: $sel{$option} = ' selected="selected"';
297: } else {
298: $sel{$option} = '';
299: }
300: }
301: my ($checkedon,$checkedoff);
302: if ($viewsettings{'optin'}) {
303: $checkedon = ' checked="checked"';
304: } else {
305: $checkedoff = ' checked="checked"';
306: }
307: my $forceedit;
308: if ($env{'form.forceedit'}) {
309: $forceedit = 1;
310: }
311: my $hiddenaction;
312: if ($caller eq '/adm/createuser') {
313: $hiddenaction = '<input type="hidden" name="action" value="calist" />'."\n";
314: }
315: $output = '<h3>'.$lt{'cloc'}.'</h3>'."\n".
316: '<form method="post" name="display" action="'.$caller.'">'."\n".
317: '<input type="hidden" name="caller" value="'.$caller.'" />'."\n".
318: '<input type="hidden" name="state" value="setconfig" />'."\n".
319: '<input type="hidden" name="forceedit" value="'.$forceedit.'" />'."\n".
320: $hiddenaction.
321: &Apache::loncommon::start_data_table().
322: &Apache::loncommon::start_data_table_header_row().
323: '<th>'.$lt{'set'}.'</th><th>'.$lt{'val'}.'</th>'.
324: &Apache::loncommon::end_data_table_header_row().
325: &Apache::loncommon::start_data_table_row().
326: '<td>'.
327: $titles{'coauthorlist'}.'</td>'.
328: '<td><select name="coauthorlist">'.
329: '<option value="none"'.$sel{'none'}.'>'.$options{'none'}.'</option>'.
330: '<option value="role"'.$sel{'role'}.'>'.$options{'role'}.'</option>'.
331: '<option value="all"'.$sel{'all'}.'>'.$options{'all'}.'</option>'.
332: '</select></td>'.
333: &Apache::loncommon::end_data_table_row().
334: &Apache::loncommon::start_data_table_row().
335: '<td>'.$titles{'coauthoroptin'}.'</td>'.
336: '<td><span class="LC_nobreak">'.
337: '<label><input type="radio" name="coauthoroptin" value="0" '.
338: $checkedoff.' />'.$lt{'no'}.'</label> '.
339: '<label><input type="radio" name="coauthoroptin" value="1" '.
340: $checkedon.' />'.$lt{'yes'}.'</label>'.
341: '</span></td>'.
342: &Apache::loncommon::end_data_table_row().
343: &Apache::loncommon::end_data_table().
344: '<br clear="all" />'.
345: '<input type="submit" value="'.$lt{'sav'}.'" />'.
346: '</form>';
347: }
348: return $output;
349: }
350:
351: sub print_coauthors {
352: my ($r,$auname,$audom,$role,$caller,$settingsref) = @_;
353: my %viewsettings;
354: if (ref($settingsref) eq 'HASH') {
355: %viewsettings = %{$settingsref};
356: } else {
357: %viewsettings =
358: &Apache::lonviewcoauthors::&retrieve_view_settings($auname,$audom,$role);
359: }
360: my %lt = &Apache::lonlocal::texthash (
361: cvl => 'Coauthor-viewable listing',
362: nam => 'Name',
363: usr => 'Username:Domain',
364: rol => 'Role(s)',
365: and => 'and',
366: utd => 'Unable to determine Authoring Space context',
367: );
368: if (($auname ne '') && ($audom ne '')) {
369: my (%shownstatus,%coauthors);
370: $r->print("<h3>$lt{'cvl'}</h3>");
371: if ($env{'form.action'} eq 'setenv') {
372: $r->print(&process_coauthor_prefs($auname,$audom,$caller));
373: }
374: if ($viewsettings{'optin'}) {
375: if ($env{'request.role'} =~ /^(ca|aa)/) {
376: $r->print(&coauthor_listing_form($auname,$audom,$caller));
377: }
378: %shownstatus = &Apache::lonnet::dump('showncoauthors',$audom,$auname);
379: }
380: my $fullcount = 0;
381: my $viewablecount = 0;
382: my $displaycount = 0;
383: my $getmanagers = 1;
384: my ($output,$roletype);
385: my @showroles;
386: if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
387: @showroles = ('ca','aa');
388: } elsif ($viewsettings{'show'} eq 'role') {
389: ($roletype) = ($env{'request.role'} =~ m{^(ca|aa)\./$audom/$auname$});
390: if ($roletype ne '') {
391: @showroles = ($roletype);
392: if ($roletype eq 'aa') {
393: undef($getmanagers);
394: }
395: }
396: } else {
397: @showroles = ('ca','aa');
398: }
399: my %coauthors = &Apache::lonnet::get_my_roles($auname,$audom,undef,undef,
400: \@showroles,[$audom]);
401: my (%userinfo,%showuser);
402: foreach my $item (keys(%coauthors)) {
403: my ($username,$domain,$userrole) = split(/:/,$item);
404: my ($start,$end) = split(/:/,$coauthors{$item});
405: next if ($start eq '-1' && $end eq '-1');
406: if (ref($userinfo{$username.':'.$domain}) eq 'HASH') {
407: if (ref($userinfo{$username.':'.$domain}{roles}) eq 'ARRAY') {
408: unless (grep(/^$userrole$/,@{$userinfo{$username.':'.$domain}{roles}})) {
409: push(@{$userinfo{$username.':'.$domain}{roles}},$userrole);
410: }
411: } else {
412: $userinfo{$username.':'.$domain}{roles} = [$userrole];
413: }
414: } else {
415: $userinfo{$username.':'.$domain}{fullname} =
416: &Apache::loncommon::plainname($username,$domain,'lastname');
417: $userinfo{$username.':'.$domain}{roles} = [$userrole];
418: }
419: if ($viewsettings{'optin'}) {
420: if ($shownstatus{$username.':'.$domain}) {
421: $showuser{$username.':'.$domain} = $userinfo{$username.':'.$domain};
422: }
423: } else {
424: $showuser{$username.':'.$domain} = $userinfo{$username.':'.$domain};
425: }
426: }
427: $fullcount = scalar(keys(%userinfo));
428: $viewablecount = scalar(keys(%showuser));
429: my @rolenames = map { &Apache::lonnet::plaintext($_); } ('ca','aa');
430: if ($viewsettings{'optin'}) {
431: $displaycount = $viewablecount;
432: if ($fullcount > $viewablecount) {
433: if ($viewablecount) {
434: $output = &mt('Only users who have opted to be listed ([_1] out of [_2] users) are shown.',
435: $viewablecount,$fullcount).'<br />';
436: } else {
437: if ($fullcount == 1) {
438: if ($roletype) {
439: $output = &mt('The one user with a [_1] role has opted not to be listed.',
440: &Apache::lonnet::plaintext($roletype));
441: } else {
442: $output = &mt('The one user with a [_1] or [_2] role has opted not to be listed.',
443: $rolenames[0],$rolenames[1]);
444: }
445: } else {
446: if ($roletype) {
447: $output = &mt('None of the [_1] users with a [_2] role have opted to be listed.',
448: $fullcount,&Apache::lonnet::plaintext($roletype));
449: } else {
450: $output = &mt('None of the [_1] users with a [_2] or [_3] role have opted to be listed.',
451: $fullcount,$rolenames[0],$rolenames[1]);
452: }
453: }
454: }
455: } else {
456: if ($fullcount > 1) {
457: if ($roletype) {
458: $output = &mt('All [_1] users with a [_2] role have opted to be listed.',
459: $fullcount,&Apache::lonnet::plaintext($roletype));
460: } else {
461: $output = &mt('All [_1] users with a [_2] or [_3] role have opted to be listed.',
462: $fullcount,$rolenames[0],$rolenames[1]);
463: }
464: } elsif ($fullcount == 1) {
465: if ($roletype) {
466: $output = &mt('The one user with a [_1] role has opted to be listed.',
467: &Apache::lonnet::plaintext($roletype));
468: } else {
469: $output = &mt('The one user with a [_1] or [_2] role has opted to be listed.',
470: $rolenames[0],$rolenames[1]);
471: }
472: } else {
473: if ($roletype) {
474: $output = &mt('There are no users with a [_1] role.',
475: &Apache::lonnet::plaintext($roletype));
476: } else {
477: $output = &mt('There are no users with a [_1] or [_2] role.',
478: $rolenames[0],$rolenames[1]);
479: }
480: }
481: }
482: } else {
483: $displaycount = $fullcount;
484: if ($fullcount > 1) {
485: if ($roletype) {
486: $output = &mt('All [_1] users with a [_2] role are shown.',
487: $fullcount,&Apache::lonnet::plaintext($roletype));
488: } else {
489: $output = &mt('All [_1] users with a [_2] or [_3] role are shown.',
490: $fullcount,$rolenames[0],$rolenames[1]);
491: }
492: } elsif ($fullcount == 1) {
493: if ($roletype) {
494: $output = &mt('The one user with a [_1] role is shown.',
495: &Apache::lonnet::plaintext($roletype));
496: } else {
497: $output = &mt('The one user with a [_1] or [_2] role is shown.',
498: $rolenames[0],$rolenames[1]);
499: }
500: } else {
501: if ($roletype) {
502: $output = &mt('There are no users with a [_1] role.',
503: &Apache::lonnet::plaintext($roletype));
504: } else {
505: $output = &mt('There are no users with a [_1] or [_2] role.',
506: $rolenames[0],$rolenames[1]);
507: }
508: }
509: }
510: if ($displaycount) {
511: $r->print('<h4>'.$output.'</h4>');
512: my $table = '<br />'.&Apache::loncommon::start_data_table()."\n".
513: &Apache::loncommon::start_data_table_header_row()."\n".
514: '<th></th>'. # for the count
515: '<th>'.$lt{'nam'}.'</th>'.
516: '<th>'.$lt{'usr'}.'</th>';
517: unless ($roletype) {
518: $table .= '<th>'.$lt{'rol'}.'</th>';
519: }
520: $table .= &Apache::loncommon::end_data_table_header_row()."\n";
521: my $count = 0;
522: my %camanagers;
523: if ($getmanagers) {
524: my %userenv = &Apache::lonnet::userenvironment($audom,$auname,
525: 'authormanagers');
526: map { $camanagers{$_} = 1; } split(/,/,$userenv{'authormanagers'});
527: }
528: my @sorted = sort {
529: lc($showuser{$a}{fullname}) cmp lc($showuser{$b}{fullname})
530: } (keys(%showuser));
531: foreach my $user (@sorted) {
532: my ($username,$domain) = split(/:/,$user);
533: $count ++;
534: $table .= &Apache::loncommon::start_data_table_row()."\n".
535: '<td>'.$count.'</td>'.
536: '<td>';
537: if ($camanagers{$user}) {
538: $table .= '<span style="font-face:bold;">*</span>';
539: } else {
540: $table .= ' 'x2;
541: }
542: $table .= &Apache::loncommon::aboutmewrapper($showuser{$user}{fullname},
543: $username,$domain).
544: '</td>'.
545: '<td>'.&Apache::loncommon::messagewrapper
546: ('<img src="/adm/lonIcons/mailto.gif" border="0" /> '.
547: $user,$username,$domain).
548: '</td>';
549: unless ($roletype) {
550: $table .= '<td>'.
551: join(" $lt{'and'} ", map { &Apache::lonnet::plaintext($_); }
552: @{$showuser{$user}{roles}}).
553: '</td>';
554: }
555: $table .= &Apache::loncommon::end_data_table_row()."\n";
556: }
557: $table .= &Apache::loncommon::end_data_table()."\n";
558: $r->print($table);
559: if (keys(%camanagers)) {
560: $r->print('<br /><span class="LC_fontsize_medium">'.
561: &mt('[_1]*[_2] indicates co-author can add/revoke co-author roles',
562: '<span style="font-face:bold;">','</span>').
563: '</span>');
564: }
565: } else {
566: $r->print('<div class="LC_info">'.$output.'</div>');
567: }
568: } else {
569: $r->print('<div class="LC_warning"'.$lt{'utd'}.'</div>');
570: }
571: return;
572: }
573:
574: sub coauthor_listing_form {
575: my ($auname,$audom,$caller) = @_;
576: my $showinlist = $env{"environment.internal.showinlist./$audom/$auname"};
577: my ($showoff,$showon);
578: if ($showinlist) {
579: $showon = ' checked="checked" ';
580: $showoff = ' ';
581: } else {
582: $showoff = ' checked="checked" ';
583: $showon = ' ';
584: }
585: my %lt = &Apache::lonlocal::texthash (
586: yls => 'Your listing status',
587: yci => 'You are currently included in the coauthor-viewable listing.',
588: iyl => 'Include yourself in the listing?',
589: y => 'Yes',
590: n => 'No',
591: sav => 'Save changes',
592: );
593: my $output =
594: '<div class="LC_left_float">'
595: .'<fieldset><legend>'.$lt{'yls'}.'</legend>';
596: if ($showinlist) {
597: $output .= $lt{'yci'};
598: } else {
599: $output .= &mt('You are currently [_1]not[_2] included in the coauthor-viewable listing.','<b>','</b>');
600: }
601: $output .= '<br />'.$lt{'iyl'}.' '.
602: '<form name="coauthorparm" method="post" action="'.$caller.'">'.
603: '<span class="LC_nobreak">'.
604: '<label><input type="radio" name="showinlist" value="1"'.$showon.'/>'.$lt{'y'}.'</label> <label>'.
605: '<input type="radio" name="showinlist" value="0"'.$showoff.'/>'.$lt{'n'}.
606: '</label></span><br /><br />'.
607: '<input type="hidden" name="action" value="setenv" />'.
608: '<input type="submit" name="coauthorsubmit" value="'.$lt{'sav'}.'" />'.
609: '</form></fieldset></div><br clear="all" />';
610: return $output;
611: }
612:
613: sub process_coauthor_prefs {
614: my ($auname,$audom,$caller) = @_;
615: my $uname = $env{'user.name'};
616: my $udom = $env{'user.domain'};
617: my $user = $uname.':'.$udom;
618: my %shown = &Apache::lonnet::get('showncoauthors',[$user],$audom,$auname);
619: my %lt = &Apache::lonlocal::texthash (
620: on => 'on',
621: off => 'off',
622: err => 'Error occurred saving display setting.',
623: );
624: my $visibility = $lt{'off'};
625: my $showinlist = $env{'form.showinlist'};
626: if ($showinlist) {
627: $visibility = $lt{'on'};
628: }
629: my $listed = 0;
630: if ($shown{$user}) {
631: $listed = 1;
632: }
633:
634: my $output;
635: if ($listed ne $showinlist) {
636: my %changeHash = (
637: "internal.showinlist./$audom/$auname" => $showinlist,
638: );
639: my $putresult = &Apache::lonnet::put('environment',
640: \%changeHash,$udom,$uname);
641: if ($putresult eq 'ok') {
642: &Apache::lonnet::appenv({"environment.internal.showinlist./$audom/$auname" => $showinlist});
643: my $result = &Apache::lonnet::put('showncoauthors',{$user => $showinlist,},$audom,$auname);
644: if ($result eq 'ok') {
645: $output .=
646: &Apache::lonhtmlcommon::confirm_success(
647: &mt("Display of your name in the coauthor-viewable listing set to [_1].",'<b>'.$visibility.'</b>'));
648: } else {
649: $output .= &Apache::lonhtmlcommon::confirm_success($lt{'err'},1);
650: }
651: } else {
652: $output .= &Apache::lonhtmlcommon::confirm_success($lt{'err'},1);
653: }
654: } else {
655: $output .=
656: &Apache::lonhtmlcommon::confirm_success(
657: &mt("Display of your name in the coauthor-viewable listing unchanged (set to [_1]).",'<b>'.$visibility.'</b>'));
658: }
659: $output = &Apache::loncommon::confirmwrapper($output);
660: return $output;
661: }
662:
663: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>