Annotation of loncom/interface/lonviewcoauthors.pm, revision 1.6
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to display the coauthors
3: #
1.6 ! raeburn 4: # $Id: lonviewcoauthors.pm,v 1.5 2024/05/24 15:27:59 raeburn Exp $
1.1 raeburn 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();
1.3 raeburn 36: use Apache::Constants qw(:common :http);
1.1 raeburn 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 };
1.4 raeburn 99: $r->print(&Apache::loncommon::start_page('Co-author listing',undef,
1.1 raeburn 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: }
1.3 raeburn 217: my %userenv = &Apache::lonnet::userenvironment($audom,$auname,
1.1 raeburn 218: 'coauthorlist','coauthoroptin');
219: my %titles = &Apache::lonlocal::texthash (
220: coauthorlist => 'List availability',
1.4 raeburn 221: coauthoroptin => "Co-author's agreement needed for listing",
1.1 raeburn 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'}) {
1.2 raeburn 309: $forceedit = 1;
1.1 raeburn 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".
1.2 raeburn 320: $hiddenaction.
1.1 raeburn 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;
1.2 raeburn 354: if (ref($settingsref) eq 'HASH') {
1.1 raeburn 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',
1.2 raeburn 367: );
1.1 raeburn 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;
1.3 raeburn 383: my $getmanagers = 1;
1.1 raeburn 384: my ($output,$roletype);
385: my @showroles;
386: if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
1.2 raeburn 387: @showroles = ('ca','aa');
1.1 raeburn 388: } elsif ($viewsettings{'show'} eq 'role') {
389: ($roletype) = ($env{'request.role'} =~ m{^(ca|aa)\./$audom/$auname$});
390: if ($roletype ne '') {
391: @showroles = ($roletype);
1.3 raeburn 392: if ($roletype eq 'aa') {
393: undef($getmanagers);
394: }
1.1 raeburn 395: }
396: } else {
397: @showroles = ('ca','aa');
398: }
399: my %coauthors = &Apache::lonnet::get_my_roles($auname,$audom,undef,undef,
1.5 raeburn 400: \@showroles);
1.1 raeburn 401: my (%userinfo,%showuser);
402: foreach my $item (keys(%coauthors)) {
403: my ($username,$domain,$userrole) = split(/:/,$item);
1.6 ! raeburn 404: next if (($username eq '') && ($domain eq''));
1.1 raeburn 405: my ($start,$end) = split(/:/,$coauthors{$item});
406: next if ($start eq '-1' && $end eq '-1');
407: if (ref($userinfo{$username.':'.$domain}) eq 'HASH') {
408: if (ref($userinfo{$username.':'.$domain}{roles}) eq 'ARRAY') {
409: unless (grep(/^$userrole$/,@{$userinfo{$username.':'.$domain}{roles}})) {
410: push(@{$userinfo{$username.':'.$domain}{roles}},$userrole);
411: }
412: } else {
413: $userinfo{$username.':'.$domain}{roles} = [$userrole];
414: }
415: } else {
1.2 raeburn 416: $userinfo{$username.':'.$domain}{fullname} =
1.1 raeburn 417: &Apache::loncommon::plainname($username,$domain,'lastname');
418: $userinfo{$username.':'.$domain}{roles} = [$userrole];
419: }
420: if ($viewsettings{'optin'}) {
421: if ($shownstatus{$username.':'.$domain}) {
422: $showuser{$username.':'.$domain} = $userinfo{$username.':'.$domain};
423: }
424: } else {
425: $showuser{$username.':'.$domain} = $userinfo{$username.':'.$domain};
426: }
427: }
428: $fullcount = scalar(keys(%userinfo));
429: $viewablecount = scalar(keys(%showuser));
430: my @rolenames = map { &Apache::lonnet::plaintext($_); } ('ca','aa');
431: if ($viewsettings{'optin'}) {
432: $displaycount = $viewablecount;
433: if ($fullcount > $viewablecount) {
434: if ($viewablecount) {
435: $output = &mt('Only users who have opted to be listed ([_1] out of [_2] users) are shown.',
436: $viewablecount,$fullcount).'<br />';
437: } else {
438: if ($fullcount == 1) {
439: if ($roletype) {
440: $output = &mt('The one user with a [_1] role has opted not to be listed.',
441: &Apache::lonnet::plaintext($roletype));
442: } else {
443: $output = &mt('The one user with a [_1] or [_2] role has opted not to be listed.',
1.2 raeburn 444: $rolenames[0],$rolenames[1]);
1.1 raeburn 445: }
446: } else {
447: if ($roletype) {
448: $output = &mt('None of the [_1] users with a [_2] role have opted to be listed.',
449: $fullcount,&Apache::lonnet::plaintext($roletype));
450: } else {
451: $output = &mt('None of the [_1] users with a [_2] or [_3] role have opted to be listed.',
452: $fullcount,$rolenames[0],$rolenames[1]);
453: }
454: }
455: }
456: } else {
457: if ($fullcount > 1) {
458: if ($roletype) {
459: $output = &mt('All [_1] users with a [_2] role have opted to be listed.',
460: $fullcount,&Apache::lonnet::plaintext($roletype));
461: } else {
462: $output = &mt('All [_1] users with a [_2] or [_3] role have opted to be listed.',
1.2 raeburn 463: $fullcount,$rolenames[0],$rolenames[1]);
1.1 raeburn 464: }
465: } elsif ($fullcount == 1) {
466: if ($roletype) {
467: $output = &mt('The one user with a [_1] role has opted to be listed.',
468: &Apache::lonnet::plaintext($roletype));
469: } else {
470: $output = &mt('The one user with a [_1] or [_2] role has opted to be listed.',
471: $rolenames[0],$rolenames[1]);
472: }
473: } else {
474: if ($roletype) {
475: $output = &mt('There are no users with a [_1] role.',
476: &Apache::lonnet::plaintext($roletype));
477: } else {
478: $output = &mt('There are no users with a [_1] or [_2] role.',
479: $rolenames[0],$rolenames[1]);
480: }
481: }
482: }
483: } else {
484: $displaycount = $fullcount;
485: if ($fullcount > 1) {
486: if ($roletype) {
487: $output = &mt('All [_1] users with a [_2] role are shown.',
488: $fullcount,&Apache::lonnet::plaintext($roletype));
489: } else {
490: $output = &mt('All [_1] users with a [_2] or [_3] role are shown.',
491: $fullcount,$rolenames[0],$rolenames[1]);
492: }
493: } elsif ($fullcount == 1) {
494: if ($roletype) {
495: $output = &mt('The one user with a [_1] role is shown.',
496: &Apache::lonnet::plaintext($roletype));
497: } else {
498: $output = &mt('The one user with a [_1] or [_2] role is shown.',
499: $rolenames[0],$rolenames[1]);
500: }
501: } else {
502: if ($roletype) {
503: $output = &mt('There are no users with a [_1] role.',
504: &Apache::lonnet::plaintext($roletype));
505: } else {
506: $output = &mt('There are no users with a [_1] or [_2] role.',
507: $rolenames[0],$rolenames[1]);
508: }
509: }
510: }
511: if ($displaycount) {
512: $r->print('<h4>'.$output.'</h4>');
513: my $table = '<br />'.&Apache::loncommon::start_data_table()."\n".
514: &Apache::loncommon::start_data_table_header_row()."\n".
515: '<th></th>'. # for the count
516: '<th>'.$lt{'nam'}.'</th>'.
517: '<th>'.$lt{'usr'}.'</th>';
518: unless ($roletype) {
519: $table .= '<th>'.$lt{'rol'}.'</th>';
520: }
521: $table .= &Apache::loncommon::end_data_table_header_row()."\n";
522: my $count = 0;
1.3 raeburn 523: my %camanagers;
524: if ($getmanagers) {
525: my %userenv = &Apache::lonnet::userenvironment($audom,$auname,
526: 'authormanagers');
527: map { $camanagers{$_} = 1; } split(/,/,$userenv{'authormanagers'});
528: }
1.1 raeburn 529: my @sorted = sort {
530: lc($showuser{$a}{fullname}) cmp lc($showuser{$b}{fullname})
531: } (keys(%showuser));
532: foreach my $user (@sorted) {
533: my ($username,$domain) = split(/:/,$user);
1.2 raeburn 534: $count ++;
1.1 raeburn 535: $table .= &Apache::loncommon::start_data_table_row()."\n".
536: '<td>'.$count.'</td>'.
1.3 raeburn 537: '<td>';
538: if ($camanagers{$user}) {
539: $table .= '<span style="font-face:bold;">*</span>';
540: } else {
541: $table .= ' 'x2;
542: }
543: $table .= &Apache::loncommon::aboutmewrapper($showuser{$user}{fullname},
544: $username,$domain).
1.1 raeburn 545: '</td>'.
546: '<td>'.&Apache::loncommon::messagewrapper
547: ('<img src="/adm/lonIcons/mailto.gif" border="0" /> '.
548: $user,$username,$domain).
549: '</td>';
550: unless ($roletype) {
551: $table .= '<td>'.
1.2 raeburn 552: join(" $lt{'and'} ", map { &Apache::lonnet::plaintext($_); }
1.1 raeburn 553: @{$showuser{$user}{roles}}).
554: '</td>';
555: }
556: $table .= &Apache::loncommon::end_data_table_row()."\n";
557: }
558: $table .= &Apache::loncommon::end_data_table()."\n";
559: $r->print($table);
1.3 raeburn 560: if (keys(%camanagers)) {
561: $r->print('<br /><span class="LC_fontsize_medium">'.
562: &mt('[_1]*[_2] indicates co-author can add/revoke co-author roles',
563: '<span style="font-face:bold;">','</span>').
564: '</span>');
565: }
1.1 raeburn 566: } else {
567: $r->print('<div class="LC_info">'.$output.'</div>');
568: }
569: } else {
570: $r->print('<div class="LC_warning"'.$lt{'utd'}.'</div>');
571: }
572: return;
573: }
574:
575: sub coauthor_listing_form {
576: my ($auname,$audom,$caller) = @_;
577: my $showinlist = $env{"environment.internal.showinlist./$audom/$auname"};
578: my ($showoff,$showon);
579: if ($showinlist) {
580: $showon = ' checked="checked" ';
581: $showoff = ' ';
582: } else {
583: $showoff = ' checked="checked" ';
584: $showon = ' ';
585: }
586: my %lt = &Apache::lonlocal::texthash (
587: yls => 'Your listing status',
588: yci => 'You are currently included in the coauthor-viewable listing.',
589: iyl => 'Include yourself in the listing?',
590: y => 'Yes',
591: n => 'No',
592: sav => 'Save changes',
593: );
594: my $output =
595: '<div class="LC_left_float">'
596: .'<fieldset><legend>'.$lt{'yls'}.'</legend>';
597: if ($showinlist) {
598: $output .= $lt{'yci'};
599: } else {
600: $output .= &mt('You are currently [_1]not[_2] included in the coauthor-viewable listing.','<b>','</b>');
601: }
602: $output .= '<br />'.$lt{'iyl'}.' '.
603: '<form name="coauthorparm" method="post" action="'.$caller.'">'.
604: '<span class="LC_nobreak">'.
605: '<label><input type="radio" name="showinlist" value="1"'.$showon.'/>'.$lt{'y'}.'</label> <label>'.
606: '<input type="radio" name="showinlist" value="0"'.$showoff.'/>'.$lt{'n'}.
607: '</label></span><br /><br />'.
608: '<input type="hidden" name="action" value="setenv" />'.
609: '<input type="submit" name="coauthorsubmit" value="'.$lt{'sav'}.'" />'.
610: '</form></fieldset></div><br clear="all" />';
611: return $output;
612: }
613:
614: sub process_coauthor_prefs {
615: my ($auname,$audom,$caller) = @_;
616: my $uname = $env{'user.name'};
617: my $udom = $env{'user.domain'};
618: my $user = $uname.':'.$udom;
619: my %shown = &Apache::lonnet::get('showncoauthors',[$user],$audom,$auname);
620: my %lt = &Apache::lonlocal::texthash (
621: on => 'on',
622: off => 'off',
623: err => 'Error occurred saving display setting.',
624: );
625: my $visibility = $lt{'off'};
626: my $showinlist = $env{'form.showinlist'};
627: if ($showinlist) {
628: $visibility = $lt{'on'};
629: }
630: my $listed = 0;
631: if ($shown{$user}) {
632: $listed = 1;
633: }
634:
635: my $output;
636: if ($listed ne $showinlist) {
637: my %changeHash = (
638: "internal.showinlist./$audom/$auname" => $showinlist,
639: );
640: my $putresult = &Apache::lonnet::put('environment',
641: \%changeHash,$udom,$uname);
642: if ($putresult eq 'ok') {
643: &Apache::lonnet::appenv({"environment.internal.showinlist./$audom/$auname" => $showinlist});
644: my $result = &Apache::lonnet::put('showncoauthors',{$user => $showinlist,},$audom,$auname);
645: if ($result eq 'ok') {
646: $output .=
647: &Apache::lonhtmlcommon::confirm_success(
648: &mt("Display of your name in the coauthor-viewable listing set to [_1].",'<b>'.$visibility.'</b>'));
649: } else {
650: $output .= &Apache::lonhtmlcommon::confirm_success($lt{'err'},1);
651: }
652: } else {
653: $output .= &Apache::lonhtmlcommon::confirm_success($lt{'err'},1);
654: }
655: } else {
656: $output .=
657: &Apache::lonhtmlcommon::confirm_success(
658: &mt("Display of your name in the coauthor-viewable listing unchanged (set to [_1]).",'<b>'.$visibility.'</b>'));
659: }
660: $output = &Apache::loncommon::confirmwrapper($output);
661: return $output;
662: }
663:
664: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>