Annotation of loncom/interface/loncreateuser.pm, revision 1.370
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.370 ! raeburn 4: # $Id: loncreateuser.pm,v 1.369 2012/12/21 14:49:50 bisitz Exp $
1.22 albertel 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: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
1.324 raeburn 54: Custom roles can be defined by a Domain Coordinator, Course Coordinator
55: or Community Coordinator via the Manage User functionality.
56: The custom role editor screen will show all privileges which can be
57: assigned to users. For a complete list of privileges, please see
58: C</home/httpd/lonTabs/rolesplain.tab>.
1.66 bowersj2 59:
1.324 raeburn 60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
1.66 bowersj2 62:
63: =cut
1.1 www 64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
1.54 bowersj2 68: use Apache::loncommon;
1.68 www 69: use Apache::lonlocal;
1.117 raeburn 70: use Apache::longroup;
1.190 raeburn 71: use Apache::lonuserutils;
1.307 raeburn 72: use Apache::loncoursequeueadmin;
1.139 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1 www 74:
1.20 harris41 75: my $loginscript; # piece of javascript used in two separate instances
76: my $authformnop;
77: my $authformkrb;
78: my $authformint;
79: my $authformfsys;
80: my $authformloc;
81:
1.94 matthew 82: sub initialize_authen_forms {
1.227 raeburn 83: my ($dom,$formname,$curr_authtype,$mode) = @_;
84: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
85: my %param = ( formname => $formname,
1.187 raeburn 86: kerb_def_dom => $krbdefdom,
1.227 raeburn 87: kerb_def_auth => $krbdef,
1.187 raeburn 88: domain => $dom,
89: );
1.188 raeburn 90: my %abv_auth = &auth_abbrev();
1.227 raeburn 91: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 92: my $long_auth = $1;
1.227 raeburn 93: my $curr_autharg = $2;
1.188 raeburn 94: my %abv_auth = &auth_abbrev();
95: $param{'curr_authtype'} = $abv_auth{$long_auth};
96: if ($long_auth =~ /^krb(4|5)$/) {
97: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 98: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 99: }
1.205 raeburn 100: if ($mode eq 'modifyuser') {
101: $param{'mode'} = $mode;
102: }
1.187 raeburn 103: }
1.227 raeburn 104: $loginscript = &Apache::loncommon::authform_header(%param);
105: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 106: $authformnop = &Apache::loncommon::authform_nochange(%param);
107: $authformint = &Apache::loncommon::authform_internal(%param);
108: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
109: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 110: }
111:
1.188 raeburn 112: sub auth_abbrev {
113: my %abv_auth = (
1.368 raeburn 114: krb5 => 'krb',
115: krb4 => 'krb',
116: internal => 'int',
117: localauth => 'loc',
118: unix => 'fsys',
1.188 raeburn 119: );
120: return %abv_auth;
121: }
1.43 www 122:
1.134 raeburn 123: # ====================================================
124:
125: sub portfolio_quota {
126: my ($ccuname,$ccdomain) = @_;
127: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 128: 'usrt' => "User Tools",
129: 'disk' => "Disk space allocated to user's portfolio files",
130: 'cuqu' => "Current quota",
131: 'cust' => "Custom quota",
132: 'defa' => "Default",
133: 'chqu' => "Change quota",
1.134 raeburn 134: );
1.149 raeburn 135: my ($currquota,$quotatype,$inststatus,$defquota) =
136: &Apache::loncommon::get_user_quota($ccuname,$ccdomain);
137: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
138: my ($longinsttype,$showquota,$custom_on,$custom_off,$defaultinfo);
139: if ($inststatus ne '') {
140: if ($usertypes->{$inststatus} ne '') {
141: $longinsttype = $usertypes->{$inststatus};
142: }
143: }
144: $custom_on = ' ';
145: $custom_off = ' checked="checked" ';
146: my $quota_javascript = <<"END_SCRIPT";
147: <script type="text/javascript">
1.301 bisitz 148: // <![CDATA[
1.149 raeburn 149: function quota_changes(caller) {
150: if (caller == "custom") {
151: if (document.cu.customquota[0].checked) {
152: document.cu.portfolioquota.value = "";
153: }
154: }
155: if (caller == "quota") {
156: document.cu.customquota[1].checked = true;
157: }
158: }
1.301 bisitz 159: // ]]>
1.149 raeburn 160: </script>
161: END_SCRIPT
162: if ($quotatype eq 'custom') {
163: $custom_on = $custom_off;
164: $custom_off = ' ';
165: $showquota = $currquota;
166: if ($longinsttype eq '') {
1.230 bisitz 167: $defaultinfo = &mt('For this user, the default quota would be [_1]'
168: .' Mb.',$defquota);
1.149 raeburn 169: } else {
1.231 raeburn 170: $defaultinfo = &mt("For this user, the default quota would be [_1]".
171: " Mb, as determined by the user's institutional".
172: " affiliation ([_2]).",$defquota,$longinsttype);
1.149 raeburn 173: }
174: } else {
175: if ($longinsttype eq '') {
1.230 bisitz 176: $defaultinfo = &mt('For this user, the default quota is [_1]'
177: .' Mb.',$defquota);
1.149 raeburn 178: } else {
1.231 raeburn 179: $defaultinfo = &mt("For this user, the default quota of [_1]".
180: " Mb, is determined by the user's institutional".
181: " affiliation ([_2]).",$defquota,$longinsttype);
1.149 raeburn 182: }
183: }
1.267 raeburn 184:
185: my $output = $quota_javascript."\n".
186: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
187: &Apache::loncommon::start_data_table();
188:
189: if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1.275 raeburn 190: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 191: }
192: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
193: $output .= '<tr class="LC_info_row">'."\n".
194: ' <td>'.$lt{'disk'}.'</td>'."\n".
195: ' </tr>'."\n".
196: &Apache::loncommon::start_data_table_row()."\n".
197: ' <td>'.$lt{'cuqu'}.': '.
198: $currquota.' Mb. '.
199: $defaultinfo.'</td>'."\n".
200: &Apache::loncommon::end_data_table_row()."\n".
201: &Apache::loncommon::start_data_table_row()."\n".
202: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
203: ': <label>'.
204: '<input type="radio" name="customquota" value="0" '.
205: $custom_off.' onchange="javascript:quota_changes('."'custom'".')"'.
206: ' />'.$lt{'defa'}.' ('.$defquota.' Mb).</label> '.
207: ' <label><input type="radio" name="customquota" value="1" '.
208: $custom_on.' onchange="javascript:quota_changes('."'custom'".')" />'.
209: $lt{'cust'}.':</label> '.
210: '<input type="text" name="portfolioquota" size ="5" value="'.
211: $showquota.'" onfocus="javascript:quota_changes('."'quota'".')" '.
212: '/> Mb</span></td>'."\n".
213: &Apache::loncommon::end_data_table_row()."\n";
214: }
215: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 216: return $output;
217: }
218:
1.275 raeburn 219: sub build_tools_display {
220: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 221: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 222: $colspan,$isadv,%domconfig);
1.275 raeburn 223: my %lt = &Apache::lonlocal::texthash (
224: 'blog' => "Personal User Blog",
225: 'aboutme' => "Personal Information Page",
1.361 raeburn 226: 'webdav' => "WebDAV access to authoring spaces (if SSL and author/co-author)",
1.275 raeburn 227: 'portfolio' => "Personal User Portfolio",
228: 'avai' => "Available",
229: 'cusa' => "availability",
230: 'chse' => "Change setting",
231: 'usde' => "Use default",
232: 'uscu' => "Use custom",
233: 'official' => 'Can request creation of official courses',
1.299 raeburn 234: 'unofficial' => 'Can request creation of unofficial courses',
235: 'community' => 'Can request creation of communities',
1.362 raeburn 236: 'requestauthor' => 'Can request author space',
1.275 raeburn 237: );
1.279 raeburn 238: if ($context eq 'requestcourses') {
1.275 raeburn 239: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 240: 'requestcourses.official','requestcourses.unofficial',
241: 'requestcourses.community');
242: @usertools = ('official','unofficial','community');
1.309 raeburn 243: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 244: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
245: %reqtitles = &courserequest_titles();
246: %reqdisplay = &courserequest_display();
247: $colspan = ' colspan="2"';
1.332 raeburn 248: %domconfig =
249: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
250: $isadv = &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1.362 raeburn 251: } elsif ($context eq 'requestauthor') {
252: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
253: 'requestauthor');
254: @usertools = ('requestauthor');
255: @options =('norequest','approval','automatic');
256: %reqtitles = &requestauthor_titles();
257: %reqdisplay = &requestauthor_display();
258: $colspan = ' colspan="2"';
259: %domconfig =
260: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 261: } else {
262: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 263: 'tools.aboutme','tools.portfolio','tools.blog',
264: 'tools.webdav');
265: @usertools = ('aboutme','blog','webdav','portfolio');
1.275 raeburn 266: }
267: foreach my $item (@usertools) {
1.306 raeburn 268: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
269: $currdisp,$custdisp,$custradio);
1.275 raeburn 270: $cust_off = 'checked="checked" ';
271: $tool_on = 'checked="checked" ';
272: $curr_access =
273: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
274: $context);
1.362 raeburn 275: if ($context eq 'requestauthor') {
276: if ($userenv{$context} ne '') {
277: $cust_on = ' checked="checked" ';
278: $cust_off = '';
279: }
280: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 281: $cust_on = ' checked="checked" ';
282: $cust_off = '';
283: }
284: if ($context eq 'requestcourses') {
285: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 286: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 287: } else {
288: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 289: }
1.362 raeburn 290: } elsif ($context eq 'requestauthor') {
291: if ($userenv{$context} eq '') {
292: $custom_access = &mt('Currently from default setting.');
293: } else {
294: $custom_access = &mt('Currently from custom setting.');
295: }
1.275 raeburn 296: } else {
1.306 raeburn 297: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 298: $custom_access =
1.306 raeburn 299: &mt('Availability determined currently from default setting.');
300: if (!$curr_access) {
301: $tool_off = 'checked="checked" ';
302: $tool_on = '';
303: }
304: } else {
1.314 raeburn 305: $custom_access =
1.306 raeburn 306: &mt('Availability determined currently from custom setting.');
307: if ($userenv{$context.'.'.$item} == 0) {
308: $tool_off = 'checked="checked" ';
309: $tool_on = '';
310: }
1.275 raeburn 311: }
312: }
313: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 314: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 315: ' </tr>'."\n".
1.306 raeburn 316: &Apache::loncommon::start_data_table_row()."\n";
1.362 raeburn 317: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 318: my ($curroption,$currlimit);
1.362 raeburn 319: my $envkey = $context.'.'.$item;
320: if ($context eq 'requestauthor') {
321: $envkey = $context;
322: }
323: if ($userenv{$envkey} ne '') {
324: $curroption = $userenv{$envkey};
1.332 raeburn 325: } else {
326: my (@inststatuses);
1.362 raeburn 327: if ($context eq 'requestcourses') {
328: $curroption =
329: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
330: $isadv,$ccdomain,$item,
331: \@inststatuses,\%domconfig);
332: } else {
333: $curroption =
334: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
335: $isadv,$ccdomain,undef,
336: \@inststatuses,\%domconfig);
337: }
1.332 raeburn 338: }
1.306 raeburn 339: if (!$curroption) {
340: $curroption = 'norequest';
341: }
342: if ($curroption =~ /^autolimit=(\d*)$/) {
343: $currlimit = $1;
1.314 raeburn 344: if ($currlimit eq '') {
345: $currdisp = &mt('Yes, automatic creation');
346: } else {
347: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
348: }
1.306 raeburn 349: } else {
350: $currdisp = $reqdisplay{$curroption};
351: }
352: $custdisp = '<table>';
353: foreach my $option (@options) {
354: my $val = $option;
355: if ($option eq 'norequest') {
356: $val = 0;
357: }
358: if ($option eq 'validate') {
359: my $canvalidate = 0;
360: if (ref($validations{$item}) eq 'HASH') {
361: if ($validations{$item}{'_custom_'}) {
362: $canvalidate = 1;
363: }
364: }
365: next if (!$canvalidate);
366: }
367: my $checked = '';
368: if ($option eq $curroption) {
369: $checked = ' checked="checked"';
370: } elsif ($option eq 'autolimit') {
371: if ($curroption =~ /^autolimit/) {
372: $checked = ' checked="checked"';
373: }
374: }
1.362 raeburn 375: my $name = 'crsreq_'.$item;
376: if ($context eq 'requestauthor') {
377: $name = $item;
378: }
1.306 raeburn 379: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 380: '<input type="radio" name="'.$name.'" '.
381: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 382: $reqtitles{$option}.'</label> ';
383: if ($option eq 'autolimit') {
1.362 raeburn 384: $custdisp .= '<input type="text" name="'.$name.
385: '_limit" size="1" '.
1.314 raeburn 386: 'value="'.$currlimit.'" /></span><br />'.
387: $reqtitles{'unlimited'};
1.362 raeburn 388: } else {
389: $custdisp .= '</span>';
390: }
391: $custdisp .= '</td></tr>';
1.306 raeburn 392: }
393: $custdisp .= '</table>';
394: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
395: } else {
396: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 397: my $name = $context.'_'.$item;
398: if ($context eq 'requestauthor') {
399: $name = $context;
400: }
1.306 raeburn 401: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 402: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 403: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 404: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 405: $tool_off.'/>'.&mt('Off').'</label></span>';
406: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
407: '</span>';
408: }
409: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
410: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.275 raeburn 411: &Apache::loncommon::end_data_table_row()."\n".
412: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 413: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
414: $lt{'chse'}.': <label>'.
1.275 raeburn 415: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 416: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
417: '<label><input type="radio" name="custom'.$item.'" value="1" '.
418: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 419: &Apache::loncommon::end_data_table_row()."\n";
420: }
421: return $output;
422: }
423:
1.300 raeburn 424: sub coursereq_externaluser {
425: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 426: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 427: my %lt = &Apache::lonlocal::texthash (
428: 'official' => 'Can request creation of official courses',
429: 'unofficial' => 'Can request creation of unofficial courses',
430: 'community' => 'Can request creation of communities',
431: );
432:
433: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
434: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
435: 'reqcrsotherdom.community');
436: @usertools = ('official','unofficial','community');
1.309 raeburn 437: @options = ('approval','validate','autolimit');
1.306 raeburn 438: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
439: my $optregex = join('|',@options);
440: my %reqtitles = &courserequest_titles();
1.300 raeburn 441: foreach my $item (@usertools) {
1.306 raeburn 442: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 443: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
444: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 445: foreach my $req (@curr) {
446: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
447: $curroption = $1;
448: $currlimit = $2;
449: last;
1.306 raeburn 450: }
451: }
1.314 raeburn 452: if (!$curroption) {
453: $curroption = 'norequest';
454: $tooloff = ' checked="checked"';
455: }
1.306 raeburn 456: } else {
457: $curroption = 'norequest';
458: $tooloff = ' checked="checked"';
459: }
460: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 461: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
462: '<table><tr><td valign="top">'."\n".
1.306 raeburn 463: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 464: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
465: '</label></td>';
1.306 raeburn 466: foreach my $option (@options) {
467: if ($option eq 'validate') {
468: my $canvalidate = 0;
469: if (ref($validations{$item}) eq 'HASH') {
470: if ($validations{$item}{'_external_'}) {
471: $canvalidate = 1;
472: }
473: }
474: next if (!$canvalidate);
475: }
476: my $checked = '';
477: if ($option eq $curroption) {
478: $checked = ' checked="checked"';
479: }
1.314 raeburn 480: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 481: '<input type="radio" name="reqcrsotherdom_'.$item.
482: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 483: $reqtitles{$option}.'</label>';
1.306 raeburn 484: if ($option eq 'autolimit') {
1.314 raeburn 485: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 486: $item.'_limit" size="1" '.
1.314 raeburn 487: 'value="'.$currlimit.'" /></span>'.
488: '<br />'.$reqtitles{'unlimited'};
489: } else {
490: $output .= '</span>';
1.300 raeburn 491: }
1.314 raeburn 492: $output .= '</td>';
1.300 raeburn 493: }
1.314 raeburn 494: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 495: &Apache::loncommon::end_data_table_row()."\n";
496: }
497: return $output;
498: }
499:
1.362 raeburn 500: sub domainrole_req {
501: my ($ccuname,$ccdomain) = @_;
502: return '<br /><h3>'.
503: &mt('User Can Request Assignment of Domain Roles?').
504: '</h3>'."\n".
505: &Apache::loncommon::start_data_table().
506: &build_tools_display($ccuname,$ccdomain,
507: 'requestauthor').
508: &Apache::loncommon::end_data_table();
509: }
510:
1.306 raeburn 511: sub courserequest_titles {
512: my %titles = &Apache::lonlocal::texthash (
513: official => 'Official',
514: unofficial => 'Unofficial',
515: community => 'Communities',
516: norequest => 'Not allowed',
1.309 raeburn 517: approval => 'Approval by Dom. Coord.',
1.306 raeburn 518: validate => 'With validation',
519: autolimit => 'Numerical limit',
1.314 raeburn 520: unlimited => '(blank for unlimited)',
1.306 raeburn 521: );
522: return %titles;
523: }
524:
525: sub courserequest_display {
526: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 527: approval => 'Yes, need approval',
1.306 raeburn 528: validate => 'Yes, with validation',
529: norequest => 'No',
530: );
531: return %titles;
532: }
533:
1.362 raeburn 534: sub requestauthor_titles {
535: my %titles = &Apache::lonlocal::texthash (
536: norequest => 'Not allowed',
537: approval => 'Approval by Dom. Coord.',
538: automatic => 'Automatic approval',
539: );
540: return %titles;
541:
542: }
543:
544: sub requestauthor_display {
545: my %titles = &Apache::lonlocal::texthash (
546: approval => 'Yes, need approval',
547: automatic => 'Yes, automatic approval',
548: norequest => 'No',
549: );
550: return %titles;
551: }
552:
553: sub curr_requestauthor {
554: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
555: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
556: if ($uname eq '' || $udom eq '') {
557: $uname = $env{'user.name'};
558: $udom = $env{'user.domain'};
559: $isadv = $env{'user.adv'};
560: }
561: my (%userenv,%settings,$val);
562: my @options = ('automatic','approval');
563: %userenv =
564: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
565: if ($userenv{'requestauthor'}) {
566: $val = $userenv{'requestauthor'};
567: @{$inststatuses} = ('_custom_');
568: } else {
569: my %alltasks;
570: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
571: %settings = %{$domconfig->{'requestauthor'}};
572: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
573: $val = $settings{'_LC_adv'};
574: @{$inststatuses} = ('_LC_adv_');
575: } else {
576: if ($userenv{'inststatus'} ne '') {
577: @{$inststatuses} = split(',',$userenv{'inststatus'});
578: } else {
579: @{$inststatuses} = ('default');
580: }
581: foreach my $status (@{$inststatuses}) {
582: if (exists($settings{$status})) {
583: my $value = $settings{$status};
584: next unless ($value);
585: unless (exists($alltasks{$value})) {
586: if (ref($alltasks{$value}) eq 'ARRAY') {
587: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
588: push(@{$alltasks{$value}},$status);
589: }
590: } else {
591: @{$alltasks{$value}} = ($status);
592: }
593: }
594: }
595: }
596: foreach my $option (@options) {
597: if ($alltasks{$option}) {
598: $val = $option;
599: last;
600: }
601: }
602: }
603: }
604: }
605: return $val;
606: }
607:
1.2 www 608: # =================================================================== Phase one
1.1 www 609:
1.42 matthew 610: sub print_username_entry_form {
1.351 raeburn 611: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum) = @_;
1.101 albertel 612: my $defdom=$env{'request.role.domain'};
1.160 raeburn 613: my $formtoset = 'crtuser';
614: if (exists($env{'form.startrolename'})) {
615: $formtoset = 'docustom';
616: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 617: } elsif ($env{'form.origform'} eq 'crtusername') {
618: $formtoset = $env{'form.origform'};
1.160 raeburn 619: }
620:
621: my ($jsback,$elements) = &crumb_utilities();
622:
623: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 624: '<script type="text/javascript">'."\n".
1.301 bisitz 625: '// <![CDATA['."\n".
626: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
627: '// ]]>'."\n".
1.162 raeburn 628: '</script>'."\n";
1.160 raeburn 629:
1.324 raeburn 630: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
631: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
632: && (&Apache::lonnet::allowed('mcr','/'))) {
633: $jscript .= &customrole_javascript();
634: }
1.224 raeburn 635: my $helpitem = 'Course_Change_Privileges';
636: if ($env{'form.action'} eq 'custom') {
637: $helpitem = 'Course_Editing_Custom_Roles';
638: } elsif ($env{'form.action'} eq 'singlestudent') {
639: $helpitem = 'Course_Add_Student';
640: }
1.351 raeburn 641: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
642: if ($env{'form.action'} eq 'custom') {
643: push(@{$brcrum},
644: {href=>"javascript:backPage(document.crtuser)",
645: text=>"Pick custom role",
646: help => $helpitem,}
647: );
648: } else {
649: push (@{$brcrum},
650: {href => "javascript:backPage(document.crtuser)",
651: text => $breadcrumb_text{'search'},
652: help => $helpitem,
653: faq => 282,
654: bug => 'Instructor Interface',}
655: );
656: }
657: my %loaditems = (
658: 'onload' => "javascript:setFormElements(document.$formtoset)",
659: );
660: my $args = {bread_crumbs => $brcrum,
661: bread_crumbs_component => 'User Management',
662: add_entries => \%loaditems,};
663: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
664:
1.71 sakharuk 665: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 666: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 667: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 668: 'srad' => 'Search for a user and modify/add user information or roles',
1.71 sakharuk 669: 'usr' => "Username",
670: 'dom' => "Domain",
1.324 raeburn 671: 'ecrp' => "Define or Edit Custom Role",
672: 'nr' => "role name",
1.282 schafran 673: 'cre' => "Next",
1.71 sakharuk 674: );
1.351 raeburn 675:
1.214 raeburn 676: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 677: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 678: my $newroletext = &mt('Define new custom role:');
679: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
680: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
681: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
682: '<h3>'.$lt{'ecrp'}.'</h3>'.
683: &Apache::loncommon::start_data_table().
684: &Apache::loncommon::start_data_table_row().
685: '<td>');
686: if (keys(%existingroles) > 0) {
687: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
688: } else {
689: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
690: }
691: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
692: &Apache::loncommon::end_data_table_row());
693: if (keys(%existingroles) > 0) {
694: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
695: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
696: &mt('View/Modify existing role:').'</b></label></td>'.
697: '<td align="center"><br />'.
698: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 699: '<option value="" selected="selected">'.
1.324 raeburn 700: &mt('Select'));
701: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 702: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 703: }
704: $r->print('</select>'.
705: '</td>'.
706: &Apache::loncommon::end_data_table_row());
707: }
708: $r->print(&Apache::loncommon::end_data_table().'<p>'.
709: '<input name="customeditor" type="submit" value="'.
710: $lt{'cre'}.'" /></p>'.
711: '</form>');
1.190 raeburn 712: }
1.213 raeburn 713: } else {
1.229 raeburn 714: my $actiontext = $lt{'srad'};
1.213 raeburn 715: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 716: if ($crstype eq 'Community') {
717: $actiontext = $lt{'srme'};
718: } else {
719: $actiontext = $lt{'srst'};
720: }
1.213 raeburn 721: }
1.324 raeburn 722: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 723: if ($env{'form.origform'} ne 'crtusername') {
724: $r->print("\n".$response);
725: }
1.318 raeburn 726: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype));
1.107 www 727: }
1.110 albertel 728: }
729:
1.324 raeburn 730: sub customrole_javascript {
731: my $js = <<"END";
732: <script type="text/javascript">
733: // <![CDATA[
734:
735: function setCustomFields() {
736: if (document.docustom.customroleaction.length > 0) {
737: for (var i=0; i<document.docustom.customroleaction.length; i++) {
738: if (document.docustom.customroleaction[i].checked) {
739: if (document.docustom.customroleaction[i].value == 'new') {
740: document.docustom.rolename.selectedIndex = 0;
741: } else {
742: document.docustom.newrolename.value = '';
743: }
744: }
745: }
746: }
747: return;
748: }
749:
750: function setCustomAction(caller) {
751: if (document.docustom.customroleaction.length > 0) {
752: for (var i=0; i<document.docustom.customroleaction.length; i++) {
753: if (document.docustom.customroleaction[i].value == caller) {
754: document.docustom.customroleaction[i].checked = true;
755: }
756: }
757: }
758: setCustomFields();
759: return;
760: }
761:
762: // ]]>
763: </script>
764: END
765: return $js;
766: }
767:
1.160 raeburn 768: sub entry_form {
1.318 raeburn 769: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype) = @_;
1.229 raeburn 770: my ($usertype,$inexact);
1.214 raeburn 771: if (ref($srch) eq 'HASH') {
772: if (($srch->{'srchin'} eq 'dom') &&
773: ($srch->{'srchby'} eq 'uname') &&
774: ($srch->{'srchtype'} eq 'exact') &&
775: ($srch->{'srchdomain'} ne '') &&
776: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 777: my (%curr_rules,%got_rules);
1.214 raeburn 778: my ($rules,$ruleorder) =
779: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 780: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 781: } else {
782: $inexact = 1;
1.214 raeburn 783: }
1.207 raeburn 784: }
1.214 raeburn 785: my $cancreate =
786: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.160 raeburn 787: my $userpicker =
1.179 raeburn 788: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.214 raeburn 789: 'document.crtuser',$cancreate,$usertype);
1.160 raeburn 790: my $srchbutton = &mt('Search');
1.229 raeburn 791: if ($env{'form.action'} eq 'singlestudent') {
792: $srchbutton = &mt('Search and Enroll');
793: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
794: $srchbutton = &mt('Search or Add New User');
795: }
1.207 raeburn 796: my $output = <<"ENDBLOCK";
1.160 raeburn 797: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 798: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 799: <input type="hidden" name="phase" value="get_user_info" />
800: $userpicker
1.179 raeburn 801: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 802: </form>
1.207 raeburn 803: ENDBLOCK
1.229 raeburn 804: if ($env{'form.phase'} eq '') {
1.207 raeburn 805: my $defdom=$env{'request.role.domain'};
806: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
807: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 808: 'enro' => 'Enroll one student',
1.318 raeburn 809: 'enrm' => 'Enroll one member',
1.229 raeburn 810: 'admo' => 'Add/modify a single user',
811: 'crea' => 'create new user if required',
812: 'uskn' => "username is known",
1.207 raeburn 813: 'crnu' => 'Create a new user',
814: 'usr' => 'Username',
815: 'dom' => 'in domain',
1.229 raeburn 816: 'enrl' => 'Enroll',
817: 'cram' => 'Create/Modify user',
1.207 raeburn 818: );
1.229 raeburn 819: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
820: my ($title,$buttontext,$showresponse);
1.318 raeburn 821: if ($env{'form.action'} eq 'singlestudent') {
822: if ($crstype eq 'Community') {
823: $title = $lt{'enrm'};
824: } else {
825: $title = $lt{'enro'};
826: }
1.229 raeburn 827: $buttontext = $lt{'enrl'};
828: } else {
829: $title = $lt{'admo'};
830: $buttontext = $lt{'cram'};
831: }
832: if ($cancreate) {
833: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
834: } else {
835: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
836: }
837: if ($env{'form.origform'} eq 'crtusername') {
838: $showresponse = $responsemsg;
839: }
1.207 raeburn 840: $output .= <<"ENDDOCUMENT";
1.229 raeburn 841: <br />
1.207 raeburn 842: <form action="/adm/createuser" method="post" name="crtusername">
843: <input type="hidden" name="action" value="$env{'form.action'}" />
844: <input type="hidden" name="phase" value="createnewuser" />
845: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 846: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 847: <input type="hidden" name="srchin" value="dom" />
848: <input type="hidden" name="forcenewuser" value="1" />
849: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 850: <h3>$title</h3>
851: $showresponse
1.207 raeburn 852: <table>
853: <tr>
854: <td>$lt{'usr'}:</td>
855: <td><input type="text" size="15" name="srchterm" /></td>
856: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 857: <td> $sellink </td>
858: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 859: </tr>
860: </table>
861: </form>
1.160 raeburn 862: ENDDOCUMENT
1.207 raeburn 863: }
1.160 raeburn 864: return $output;
865: }
1.110 albertel 866:
867: sub user_modification_js {
1.113 raeburn 868: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
869:
1.110 albertel 870: return <<END;
871: <script type="text/javascript" language="Javascript">
1.301 bisitz 872: // <![CDATA[
1.314 raeburn 873:
1.110 albertel 874: $pjump_def
875: $dc_setcourse_code
876:
877: function dateset() {
878: eval("document.cu."+document.cu.pres_marker.value+
879: ".value=document.cu.pres_value.value");
1.359 www 880: modalWindow.close();
1.110 albertel 881: }
882:
1.113 raeburn 883: $nondc_setsection_code
1.301 bisitz 884: // ]]>
1.110 albertel 885: </script>
886: END
1.2 www 887: }
888:
889: # =================================================================== Phase two
1.160 raeburn 890: sub print_user_selection_page {
1.351 raeburn 891: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 892: my @fields = ('username','domain','lastname','firstname','permanentemail');
893: my $sortby = $env{'form.sortby'};
894:
895: if (!grep(/^\Q$sortby\E$/,@fields)) {
896: $sortby = 'lastname';
897: }
898:
899: my ($jsback,$elements) = &crumb_utilities();
900:
901: my $jscript = (<<ENDSCRIPT);
902: <script type="text/javascript">
1.301 bisitz 903: // <![CDATA[
1.160 raeburn 904: function pickuser(uname,udom) {
905: document.usersrchform.seluname.value=uname;
906: document.usersrchform.seludom.value=udom;
907: document.usersrchform.phase.value="userpicked";
908: document.usersrchform.submit();
909: }
910:
911: $jsback
1.301 bisitz 912: // ]]>
1.160 raeburn 913: </script>
914: ENDSCRIPT
915:
916: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 917: 'usrch' => "User Search to add/modify roles",
918: 'stusrch' => "User Search to enroll student",
1.318 raeburn 919: 'memsrch' => "User Search to enroll member",
1.179 raeburn 920: 'usel' => "Select a user to add/modify roles",
1.318 raeburn 921: 'stusel' => "Select a user to enroll as a student",
922: 'memsel' => "Select a user to enroll as a member",
1.160 raeburn 923: 'username' => "username",
924: 'domain' => "domain",
925: 'lastname' => "last name",
926: 'firstname' => "first name",
927: 'permanentemail' => "permanent e-mail",
928: );
1.302 raeburn 929: if ($context eq 'requestcrs') {
930: $r->print('<div>');
931: } else {
1.318 raeburn 932: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 933: my $helpitem;
934: if ($env{'form.action'} eq 'singleuser') {
935: $helpitem = 'Course_Change_Privileges';
936: } elsif ($env{'form.action'} eq 'singlestudent') {
937: $helpitem = 'Course_Add_Student';
938: }
939: push (@{$brcrum},
940: {href => "javascript:backPage(document.usersrchform,'','')",
941: text => $breadcrumb_text{'search'},
942: faq => 282,
943: bug => 'Instructor Interface',},
944: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
945: text => $breadcrumb_text{'userpicked'},
946: faq => 282,
947: bug => 'Instructor Interface',
948: help => $helpitem}
949: );
950: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 951: if ($env{'form.action'} eq 'singleuser') {
952: $r->print("<b>$lt{'usrch'}</b><br />");
1.318 raeburn 953: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.302 raeburn 954: $r->print('<h3>'.$lt{'usel'}.'</h3>');
955: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 956: $r->print($jscript."<b>");
957: if ($crstype eq 'Community') {
958: $r->print($lt{'memsrch'});
959: } else {
960: $r->print($lt{'stusrch'});
961: }
962: $r->print("</b><br />");
963: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
964: $r->print('</form><h3>');
965: if ($crstype eq 'Community') {
966: $r->print($lt{'memsel'});
967: } else {
968: $r->print($lt{'stusel'});
969: }
970: $r->print('</h3>');
1.302 raeburn 971: }
1.179 raeburn 972: }
1.160 raeburn 973: $r->print('<form name="usersrchform" method="post">'.
974: &Apache::loncommon::start_data_table()."\n".
975: &Apache::loncommon::start_data_table_header_row()."\n".
976: ' <th> </th>'."\n");
977: foreach my $field (@fields) {
978: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
979: "'".$field."'".';document.usersrchform.submit();">'.
980: $lt{$field}.'</a></th>'."\n");
981: }
982: $r->print(&Apache::loncommon::end_data_table_header_row());
983:
984: my @sorted_users = sort {
1.167 albertel 985: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 986: ||
1.167 albertel 987: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 988: ||
989: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 990: ||
991: lc($a) cmp lc($b)
1.160 raeburn 992: } (keys(%$srch_results));
993:
994: foreach my $user (@sorted_users) {
995: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 996: my $onclick;
997: if ($context eq 'requestcrs') {
1.314 raeburn 998: $onclick =
1.302 raeburn 999: 'onclick="javascript:gochoose('."'$uname','$udom',".
1000: "'$srch_results->{$user}->{firstname}',".
1001: "'$srch_results->{$user}->{lastname}',".
1002: "'$srch_results->{$user}->{permanentemail}'".');"';
1003: } else {
1.314 raeburn 1004: $onclick =
1.302 raeburn 1005: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1006: }
1.160 raeburn 1007: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1008: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1009: $onclick.' /></td>'.
1.160 raeburn 1010: '<td><tt>'.$uname.'</tt></td>'.
1011: '<td><tt>'.$udom.'</tt></td>');
1012: foreach my $field ('lastname','firstname','permanentemail') {
1013: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1014: }
1015: $r->print(&Apache::loncommon::end_data_table_row());
1016: }
1017: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1018: if (ref($srcharray) eq 'ARRAY') {
1019: foreach my $item (@{$srcharray}) {
1020: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1021: }
1022: }
1.160 raeburn 1023: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1024: ' <input type="hidden" name="seluname" value="" />'."\n".
1025: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1026: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1027: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1028: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1029: if ($context eq 'requestcrs') {
1030: $r->print($opener_elements.'</form></div>');
1031: } else {
1.351 raeburn 1032: $r->print($response.'</form>');
1.302 raeburn 1033: }
1.160 raeburn 1034: }
1035:
1036: sub print_user_query_page {
1.351 raeburn 1037: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1038: # FIXME - this is for a network-wide name search (similar to catalog search)
1039: # To use frames with similar behavior to catalog/portfolio search.
1040: # To be implemented.
1041: return;
1042: }
1043:
1.42 matthew 1044: sub print_user_modification_page {
1.351 raeburn 1045: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,$brcrum) = @_;
1.185 raeburn 1046: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1047: my $usermsg = &mt('No username and/or domain provided.');
1048: $env{'form.phase'} = '';
1.351 raeburn 1049: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum);
1.58 www 1050: return;
1051: }
1.213 raeburn 1052: my ($form,$formname);
1053: if ($env{'form.action'} eq 'singlestudent') {
1054: $form = 'document.enrollstudent';
1055: $formname = 'enrollstudent';
1056: } else {
1057: $form = 'document.cu';
1058: $formname = 'cu';
1059: }
1.188 raeburn 1060: my %abv_auth = &auth_abbrev();
1.227 raeburn 1061: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1062: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1063: if ($uhome eq 'no_host') {
1.215 raeburn 1064: my $usertype;
1065: my ($rules,$ruleorder) =
1066: &Apache::lonnet::inst_userrules($ccdomain,'username');
1067: $usertype =
1.353 raeburn 1068: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1069: \%curr_rules,\%got_rules);
1.215 raeburn 1070: my $cancreate =
1071: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1072: $usertype);
1073: if (!$cancreate) {
1.292 bisitz 1074: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1075: my %usertypetext = (
1076: official => 'institutional',
1077: unofficial => 'non-institutional',
1078: );
1079: my $response;
1080: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1081: $response = '<span class="LC_warning">'.
1082: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1083: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1084: '</span><br />';
1085: }
1.292 bisitz 1086: $response .= '<p class="LC_warning">'
1087: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1088: .' '
1089: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
1090: ,'<a href="'.$helplink.'">','</a>')
1091: .'</p><br />';
1.215 raeburn 1092: $env{'form.phase'} = '';
1.351 raeburn 1093: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum);
1.215 raeburn 1094: return;
1095: }
1.188 raeburn 1096: $newuser = 1;
1.193 raeburn 1097: my $checkhash;
1098: my $checks = { 'username' => 1 };
1.196 raeburn 1099: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1100: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1101: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1102: if (ref($alerts{'username'}) eq 'HASH') {
1103: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1104: my $domdesc =
1.193 raeburn 1105: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1106: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1107: my $userchkmsg;
1108: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1109: $userchkmsg =
1110: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1111: $domdesc,1).
1112: &Apache::loncommon::user_rule_formats($ccdomain,
1113: $domdesc,$curr_rules{$ccdomain}{'username'},
1114: 'username');
1.196 raeburn 1115: }
1.215 raeburn 1116: $env{'form.phase'} = '';
1.351 raeburn 1117: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum);
1.196 raeburn 1118: return;
1.215 raeburn 1119: }
1.193 raeburn 1120: }
1.185 raeburn 1121: }
1.187 raeburn 1122: } else {
1.188 raeburn 1123: $newuser = 0;
1.185 raeburn 1124: }
1.160 raeburn 1125: if ($response) {
1.215 raeburn 1126: $response = '<br />'.$response;
1.160 raeburn 1127: }
1.149 raeburn 1128:
1.52 matthew 1129: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1130: my $dc_setcourse_code = '';
1.119 raeburn 1131: my $nondc_setsection_code = '';
1.112 albertel 1132: my %loaditem;
1.114 albertel 1133:
1.216 raeburn 1134: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1135:
1.216 raeburn 1136: my $js = &validation_javascript($context,$ccdomain,$pjump_def,
1137: $groupslist,$newuser,$formname,\%loaditem);
1.318 raeburn 1138: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.224 raeburn 1139: my $helpitem = 'Course_Change_Privileges';
1140: if ($env{'form.action'} eq 'singlestudent') {
1141: $helpitem = 'Course_Add_Student';
1142: }
1.351 raeburn 1143: push (@{$brcrum},
1144: {href => "javascript:backPage($form)",
1145: text => $breadcrumb_text{'search'},
1146: faq => 282,
1147: bug => 'Instructor Interface',});
1148: if ($env{'form.phase'} eq 'userpicked') {
1149: push(@{$brcrum},
1150: {href => "javascript:backPage($form,'get_user_info','select')",
1151: text => $breadcrumb_text{'userpicked'},
1152: faq => 282,
1153: bug => 'Instructor Interface',});
1154: }
1155: push(@{$brcrum},
1156: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1157: text => $breadcrumb_text{'modify'},
1158: faq => 282,
1159: bug => 'Instructor Interface',
1160: help => $helpitem});
1161: my $args = {'add_entries' => \%loaditem,
1162: 'bread_crumbs' => $brcrum,
1163: 'bread_crumbs_component' => 'User Management'};
1164: if ($env{'form.popup'}) {
1165: $args->{'no_nav_bar'} = 1;
1166: }
1167: my $start_page =
1168: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1169:
1.25 matthew 1170: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1171: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1172: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1173: <input type="hidden" name="ccuname" value="$ccuname" />
1174: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1175: <input type="hidden" name="pres_value" value="" />
1176: <input type="hidden" name="pres_type" value="" />
1177: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1178: ENDFORMINFO
1.329 raeburn 1179: my (%inccourses,$roledom);
1180: if ($context eq 'course') {
1181: $inccourses{$env{'request.course.id'}}=1;
1182: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1183: } elsif ($context eq 'author') {
1184: $roledom = $env{'request.role.domain'};
1185: } elsif ($context eq 'domain') {
1186: foreach my $key (keys(%env)) {
1187: $roledom = $env{'request.role.domain'};
1188: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1189: $inccourses{$1.'_'.$2}=1;
1190: }
1191: }
1192: } else {
1193: foreach my $key (keys(%env)) {
1194: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1195: $inccourses{$1.'_'.$2}=1;
1196: }
1.2 www 1197: }
1.24 matthew 1198: }
1.216 raeburn 1199: if ($newuser) {
1.362 raeburn 1200: my ($portfolioform,$domroleform);
1.267 raeburn 1201: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1202: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1203: # Current user has quota or user tools modification privileges
1.188 raeburn 1204: $portfolioform = '<br />'.&portfolio_quota($ccuname,$ccdomain);
1.134 raeburn 1205: }
1.362 raeburn 1206: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
1207: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1208: }
1.227 raeburn 1209: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1210: my %lt=&Apache::lonlocal::texthash(
1211: 'cnu' => 'Create New User',
1.213 raeburn 1212: 'ast' => 'as a student',
1.318 raeburn 1213: 'ame' => 'as a member',
1.188 raeburn 1214: 'ind' => 'in domain',
1215: 'lg' => 'Login Data',
1.190 raeburn 1216: 'hs' => "Home Server",
1.188 raeburn 1217: );
1.185 raeburn 1218: $r->print(<<ENDTITLE);
1.110 albertel 1219: $start_page
1.160 raeburn 1220: $response
1.25 matthew 1221: $forminfo
1.31 matthew 1222: <script type="text/javascript" language="Javascript">
1.301 bisitz 1223: // <![CDATA[
1.20 harris41 1224: $loginscript
1.301 bisitz 1225: // ]]>
1.31 matthew 1226: </script>
1.20 harris41 1227: <input type='hidden' name='makeuser' value='1' />
1.216 raeburn 1228: <h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain
1.185 raeburn 1229: ENDTITLE
1.213 raeburn 1230: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1231: if ($crstype eq 'Community') {
1232: $r->print(' ('.$lt{'ame'}.')');
1233: } else {
1234: $r->print(' ('.$lt{'ast'}.')');
1235: }
1.213 raeburn 1236: }
1237: $r->print('</h2>'."\n".'<div class="LC_left_float">');
1.206 raeburn 1238: my $personal_table =
1.210 raeburn 1239: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1240: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 1241: $r->print($personal_table);
1.187 raeburn 1242: my ($home_server_pick,$numlib) =
1243: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1244: 'default','hide');
1245: if ($numlib > 1) {
1246: $r->print("
1.185 raeburn 1247: <br />
1.187 raeburn 1248: $lt{'hs'}: $home_server_pick
1249: <br />");
1250: } else {
1251: $r->print($home_server_pick);
1252: }
1.304 raeburn 1253: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1254: $r->print('<br /><h3>'.
1255: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1256: &Apache::loncommon::start_data_table().
1257: &build_tools_display($ccuname,$ccdomain,
1258: 'requestcourses').
1259: &Apache::loncommon::end_data_table());
1260: }
1.188 raeburn 1261: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1262: $lt{'lg'}.'</h3>');
1.185 raeburn 1263: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1264: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1265: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1266: my ($rules,$ruleorder) =
1267: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1268: if (ref($rules) eq 'HASH') {
1.193 raeburn 1269: if (ref($rules->{$matchedrule}) eq 'HASH') {
1270: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1271: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1272: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1273: } else {
1.193 raeburn 1274: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1275: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1276: if ($authtype =~ /^krb(4|5)$/) {
1277: my $ver = $1;
1278: if ($authparm ne '') {
1279: $fixedauth = <<"KERB";
1280: <input type="hidden" name="login" value="krb" />
1281: <input type="hidden" name="krbver" value="$ver" />
1282: <input type="hidden" name="krbarg" value="$authparm" />
1283: KERB
1284: }
1285: } else {
1286: $fixedauth =
1287: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1288: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1289: $fixedauth .=
1290: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1291: } else {
1.273 raeburn 1292: if ($authtype eq 'int') {
1293: $varauth = '<br />'.
1.301 bisitz 1294: &mt('[_1] Internally authenticated (with initial password [_2])','','<input type="password" size="10" name="intarg" value="" />')."<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.273 raeburn 1295: } elsif ($authtype eq 'loc') {
1296: $varauth = '<br />'.
1297: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1298: } else {
1299: $varauth =
1.185 raeburn 1300: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1301: }
1.185 raeburn 1302: }
1303: }
1304: }
1305: } else {
1.190 raeburn 1306: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1307: }
1308: }
1309: if ($authmsg) {
1310: $r->print(<<ENDAUTH);
1311: $fixedauth
1312: $authmsg
1313: $varauth
1314: ENDAUTH
1315: }
1316: } else {
1.190 raeburn 1317: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1318: }
1.362 raeburn 1319: $r->print($portfolioform.$domroleform);
1.215 raeburn 1320: if ($env{'form.action'} eq 'singlestudent') {
1321: $r->print(&date_sections_select($context,$newuser,$formname,
1322: $permission));
1323: }
1324: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1325: } else { # user already exists
1.79 albertel 1326: my %lt=&Apache::lonlocal::texthash(
1.191 raeburn 1327: 'cup' => "Modify existing user: ",
1.213 raeburn 1328: 'ens' => "Enroll one student: ",
1.318 raeburn 1329: 'enm' => "Enroll one member: ",
1.72 sakharuk 1330: 'id' => "in domain",
1331: );
1.26 matthew 1332: $r->print(<<ENDCHANGEUSER);
1.110 albertel 1333: $start_page
1.25 matthew 1334: $forminfo
1.213 raeburn 1335: <h2>
1.26 matthew 1336: ENDCHANGEUSER
1.213 raeburn 1337: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1338: if ($crstype eq 'Community') {
1339: $r->print($lt{'enm'});
1340: } else {
1341: $r->print($lt{'ens'});
1342: }
1.213 raeburn 1343: } else {
1344: $r->print($lt{'cup'});
1345: }
1346: $r->print(' "'.$ccuname.'" '.$lt{'id'}.' "'.$ccdomain.'"</h2>'.
1347: "\n".'<div class="LC_left_float">');
1.206 raeburn 1348: my ($personal_table,$showforceid) =
1.210 raeburn 1349: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1350: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 1351: $r->print($personal_table);
1352: if ($showforceid) {
1.362 raeburn 1353: $r->print('<table>'.&Apache::lonuserutils::forceid_change($context).'</table>');
1.199 raeburn 1354: }
1.275 raeburn 1355: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1356: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1357: &Apache::loncommon::start_data_table());
1.314 raeburn 1358: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1359: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1360: } else {
1361: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1362: $env{'request.role.domain'}));
1363: }
1364: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1365: }
1.199 raeburn 1366: $r->print('</div>');
1.362 raeburn 1367: my @order = ('auth','quota','tools','requestauthor');
1368: my %user_text;
1369: my ($isadv,$isauthor) =
1370: &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1371: if ((!$isauthor) &&
1372: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
1373: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1374: }
1375: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1376: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1377: (&Apache::lonnet::allowed('mut',$ccdomain))) {
1.188 raeburn 1378: # Current user has quota modification privileges
1.362 raeburn 1379: $user_text{'quota'} = &portfolio_quota($ccuname,$ccdomain);
1.267 raeburn 1380: }
1381: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1382: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1383: # Get the user's portfolio information
1384: my %portq = &Apache::lonnet::get('environment',['portfolioquota'],
1385: $ccdomain,$ccuname);
1386: my %lt=&Apache::lonlocal::texthash(
1387: 'dska' => "Disk space allocated to user's portfolio files",
1388: 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
1389: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1390: );
1.362 raeburn 1391: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1392: <h3>$lt{'dska'}</h3>
1393: $lt{'youd'} $lt{'ichr'}: $ccdomain
1394: ENDNOPORTPRIV
1.267 raeburn 1395: }
1396: }
1397: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1398: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1399: my %lt=&Apache::lonlocal::texthash(
1400: 'utav' => "User Tools Availability",
1.361 raeburn 1401: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1402: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1403: );
1.362 raeburn 1404: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1405: <h3>$lt{'utav'}</h3>
1406: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1407: ENDNOTOOLSPRIV
1408: }
1.188 raeburn 1409: }
1.362 raeburn 1410: my $gotdiv = 0;
1411: foreach my $item (@order) {
1412: if ($user_text{$item} ne '') {
1413: unless ($gotdiv) {
1414: $r->print('<div class="LC_left_float">');
1415: $gotdiv = 1;
1416: }
1417: $r->print('<br />'.$user_text{$item});
1418: }
1419: }
1420: if ($env{'form.action'} eq 'singlestudent') {
1421: unless ($gotdiv) {
1422: $r->print('<div class="LC_left_float">');
1.213 raeburn 1423: }
1.362 raeburn 1424: $r->print(&date_sections_select($context,$newuser,$formname));
1425: }
1426: if ($gotdiv) {
1427: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1428: }
1.217 raeburn 1429: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1430: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1431: $roledom,$crstype);
1.217 raeburn 1432: }
1.25 matthew 1433: } ## End of new user/old user logic
1.218 raeburn 1434: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1435: my $btntxt;
1436: if ($crstype eq 'Community') {
1437: $btntxt = &mt('Enroll Member');
1438: } else {
1439: $btntxt = &mt('Enroll Student');
1440: }
1441: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.218 raeburn 1442: } else {
1443: $r->print('<h3>'.&mt('Add Roles').'</h3>');
1444: my $addrolesdisplay = 0;
1445: if ($context eq 'domain' || $context eq 'author') {
1446: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1447: }
1448: if ($context eq 'domain') {
1.357 raeburn 1449: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1450: if (!$addrolesdisplay) {
1451: $addrolesdisplay = $add_domainroles;
1.2 www 1452: }
1.218 raeburn 1453: $r->print(&course_level_dc($env{'request.role.domain'},'Course'));
1.301 bisitz 1454: $r->print('<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1455: } elsif ($context eq 'author') {
1456: if ($addrolesdisplay) {
1.262 schafran 1457: $r->print('<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1458: if ($newuser) {
1.301 bisitz 1459: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1460: } else {
1.301 bisitz 1461: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1462: }
1.188 raeburn 1463: } else {
1.218 raeburn 1464: $r->print('<br /><a href="javascript:backPage(document.cu)">'.
1465: &mt('Back to previous page').'</a>');
1.188 raeburn 1466: }
1467: } else {
1.218 raeburn 1468: $r->print(&course_level_table(%inccourses));
1.301 bisitz 1469: $r->print('<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1470: }
1.88 raeburn 1471: }
1.188 raeburn 1472: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1473: $r->print('<input type="hidden" name="currstate" value="" />');
1.352 raeburn 1474: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form>');
1.218 raeburn 1475: return;
1.2 www 1476: }
1.1 www 1477:
1.213 raeburn 1478: sub singleuser_breadcrumb {
1.318 raeburn 1479: my ($crstype) = @_;
1.213 raeburn 1480: my %breadcrumb_text;
1481: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1482: if ($crstype eq 'Community') {
1483: $breadcrumb_text{'search'} = 'Enroll a member';
1484: } else {
1485: $breadcrumb_text{'search'} = 'Enroll a student';
1486: }
1.213 raeburn 1487: $breadcrumb_text{'userpicked'} = 'Select a user',
1488: $breadcrumb_text{'modify'} = 'Set section/dates',
1489: } else {
1.229 raeburn 1490: $breadcrumb_text{'search'} = 'Create/modify a user';
1.213 raeburn 1491: $breadcrumb_text{'userpicked'} = 'Select a user',
1492: $breadcrumb_text{'modify'} = 'Set user role',
1493: }
1494: return %breadcrumb_text;
1495: }
1496:
1497: sub date_sections_select {
1498: my ($context,$newuser,$formname,$permission) = @_;
1499: my $cid = $env{'request.course.id'};
1500: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1501: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1502: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1503: undef,$formname,$permission);
1504: my $rowtitle = 'Section';
1505: my $secbox = '<h3>'.&mt('Section').'</h3>'."\n".
1506: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1507: $permission);
1508: my $output = $date_table.$secbox;
1509: return $output;
1510: }
1511:
1.216 raeburn 1512: sub validation_javascript {
1513: my ($context,$ccdomain,$pjump_def,$groupslist,$newuser,$formname,
1514: $loaditem) = @_;
1515: my $dc_setcourse_code = '';
1516: my $nondc_setsection_code = '';
1517: if ($context eq 'domain') {
1518: my $dcdom = $env{'request.role.domain'};
1519: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1520: $dc_setcourse_code =
1521: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1522: } else {
1.227 raeburn 1523: my $checkauth;
1524: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1525: $checkauth = 1;
1526: }
1527: if ($context eq 'course') {
1528: $nondc_setsection_code =
1529: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1530: undef,$checkauth);
1531: }
1532: if ($checkauth) {
1533: $nondc_setsection_code .=
1534: &Apache::lonuserutils::verify_authen($formname,$context);
1535: }
1.216 raeburn 1536: }
1537: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1538: $nondc_setsection_code,$groupslist);
1539: my ($jsback,$elements) = &crumb_utilities();
1540: $js .= "\n".
1.301 bisitz 1541: '<script type="text/javascript">'."\n".
1542: '// <![CDATA['."\n".
1543: $jsback."\n".
1544: '// ]]>'."\n".
1545: '</script>'."\n";
1.216 raeburn 1546: return $js;
1547: }
1548:
1.217 raeburn 1549: sub display_existing_roles {
1.329 raeburn 1550: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype) = @_;
1551: my $now=time;
1552: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1553: 'rer' => "Existing Roles",
1554: 'rev' => "Revoke",
1555: 'del' => "Delete",
1556: 'ren' => "Re-Enable",
1557: 'rol' => "Role",
1558: 'ext' => "Extent",
1559: 'sta' => "Start",
1560: 'end' => "End",
1561: );
1.329 raeburn 1562: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1563: if ($context eq 'course' || $context eq 'author') {
1564: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1565: my %roleshash =
1566: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1567: ['active','previous','future'],\@roles,$roledom,1);
1568: foreach my $key (keys(%roleshash)) {
1569: my ($start,$end) = split(':',$roleshash{$key});
1570: next if ($start eq '-1' || $end eq '-1');
1571: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1572: if ($context eq 'course') {
1573: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1574: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1575: } elsif ($context eq 'author') {
1576: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1577: }
1578: my ($newkey,$newvalue,$newrole);
1579: $newkey = '/'.$rdom.'/'.$rnum;
1580: if ($sec ne '') {
1581: $newkey .= '/'.$sec;
1582: }
1583: $newvalue = $role;
1584: if ($role =~ /^cr/) {
1585: $newrole = 'cr';
1586: } else {
1587: $newrole = $role;
1588: }
1589: $newkey .= '_'.$newrole;
1590: if ($start ne '' && $end ne '') {
1591: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1592: } elsif ($end ne '') {
1593: $newvalue .= '_'.$end;
1.329 raeburn 1594: }
1595: $rolesdump{$newkey} = $newvalue;
1596: }
1597: } else {
1.360 raeburn 1598: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1599: }
1600: # Build up table of user roles to allow revocation and re-enabling of roles.
1601: my ($tmp) = keys(%rolesdump);
1602: return if ($tmp =~ /^(con_lost|error)/i);
1603: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1604: my $b1=join('_',(split('_',$b))[1,0]);
1605: return $a1 cmp $b1;
1606: } keys(%rolesdump)) {
1607: next if ($area =~ /^rolesdef/);
1608: my $envkey=$area;
1609: my $role = $rolesdump{$area};
1610: my $thisrole=$area;
1611: $area =~ s/\_\w\w$//;
1612: my ($role_code,$role_end_time,$role_start_time) =
1613: split(/_/,$role);
1.217 raeburn 1614: # Is this a custom role? Get role owner and title.
1.329 raeburn 1615: my ($croleudom,$croleuname,$croletitle)=
1616: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1617: my $allowed=0;
1618: my $delallowed=0;
1619: my $sortkey=$role_code;
1620: my $class='Unknown';
1621: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
1622: $class='Course';
1623: my ($coursedom,$coursedir) = ($1,$2);
1624: my $cid = $1.'_'.$2;
1625: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1626: my %coursedata=
1627: &Apache::lonnet::coursedescription($cid);
1628: if ($coursedir =~ /^$match_community$/) {
1629: $class='Community';
1630: }
1631: $sortkey.="\0$coursedom";
1632: my $carea;
1633: if (defined($coursedata{'description'})) {
1634: $carea=$coursedata{'description'}.
1635: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1636: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1637: $sortkey.="\0".$coursedata{'description'};
1638: } else {
1639: if ($class eq 'Community') {
1640: $carea=&mt('Unavailable community').': '.$area;
1641: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1642: } else {
1643: $carea=&mt('Unavailable course').': '.$area;
1644: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1645: }
1.329 raeburn 1646: }
1647: $sortkey.="\0$coursedir";
1648: $inccourses->{$cid}=1;
1649: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1650: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1651: $allowed=1;
1652: }
1653: unless ($allowed) {
1.365 raeburn 1654: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1655: if ($isowner) {
1656: if (($role_code eq 'co') && ($class eq 'Community')) {
1657: $allowed = 1;
1658: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1659: $allowed = 1;
1660: }
1.217 raeburn 1661: }
1.329 raeburn 1662: }
1663: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1664: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1665: $delallowed=1;
1666: }
1.217 raeburn 1667: # - custom role. Needs more info, too
1.329 raeburn 1668: if ($croletitle) {
1669: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1670: $allowed=1;
1671: $thisrole.='.'.$role_code;
1.217 raeburn 1672: }
1.329 raeburn 1673: }
1674: if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
1675: $carea.='<br />Section: '.$3;
1676: $sortkey.="\0$3";
1677: if (!$allowed) {
1678: if ($env{'request.course.sec'} eq $3) {
1679: if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
1680: $allowed = 1;
1.217 raeburn 1681: }
1682: }
1683: }
1.329 raeburn 1684: }
1685: $area=$carea;
1686: } else {
1687: $sortkey.="\0".$area;
1688: # Determine if current user is able to revoke privileges
1689: if ($area=~m{^/($match_domain)/}) {
1690: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1691: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1692: $allowed=1;
1.217 raeburn 1693: }
1.329 raeburn 1694: if (((&Apache::lonnet::allowed('dro',$1)) ||
1695: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1696: ($role_code ne 'dc')) {
1697: $delallowed=1;
1.217 raeburn 1698: }
1.329 raeburn 1699: } else {
1700: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1701: $allowed=1;
1702: }
1703: }
1.363 raeburn 1704: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.329 raeburn 1705: $class='Construction Space';
1706: } elsif ($role_code eq 'su') {
1707: $class='System';
1.217 raeburn 1708: } else {
1.329 raeburn 1709: $class='Domain';
1.217 raeburn 1710: }
1.329 raeburn 1711: }
1712: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1713: $area=~m{/($match_domain)/($match_username)};
1714: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1715: $allowed=1;
1.217 raeburn 1716: } else {
1.329 raeburn 1717: $allowed=0;
1.217 raeburn 1718: }
1.329 raeburn 1719: }
1720: my $row = '';
1721: $row.= '<td>';
1722: my $active=1;
1723: $active=0 if (($role_end_time) && ($now>$role_end_time));
1724: if (($active) && ($allowed)) {
1725: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1726: } else {
1727: if ($active) {
1728: $row.=' ';
1.217 raeburn 1729: } else {
1.329 raeburn 1730: $row.=&mt('expired or revoked');
1.217 raeburn 1731: }
1.329 raeburn 1732: }
1733: $row.='</td><td>';
1734: if ($allowed && !$active) {
1735: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1736: } else {
1737: $row.=' ';
1738: }
1739: $row.='</td><td>';
1740: if ($delallowed) {
1741: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1742: } else {
1743: $row.=' ';
1744: }
1745: my $plaintext='';
1746: if (!$croletitle) {
1747: $plaintext=&Apache::lonnet::plaintext($role_code,$class)
1748: } else {
1749: $plaintext=
1.346 bisitz 1750: &mt('Customrole [_1][_2]defined by [_3]',
1751: '"'.$croletitle.'"',
1752: '<br />',
1753: $croleuname.':'.$croleudom);
1.329 raeburn 1754: }
1755: $row.= '</td><td>'.$plaintext.
1756: '</td><td>'.$area.
1757: '</td><td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1758: : ' ' ).
1759: '</td><td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1760: : ' ' )
1761: ."</td>";
1762: $sortrole{$sortkey}=$envkey;
1763: $roletext{$envkey}=$row;
1764: $roleclass{$envkey}=$class;
1765: $rolepriv{$envkey}=$allowed;
1766: } # end of foreach (table building loop)
1767:
1768: my $rolesdisplay = 0;
1769: my %output = ();
1770: foreach my $type ('Construction Space','Course','Community','Domain','System','Unknown') {
1771: $output{$type} = '';
1772: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1773: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1774: $output{$type}.=
1775: &Apache::loncommon::start_data_table_row().
1776: $roletext{$sortrole{$which}}.
1777: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1778: }
1.329 raeburn 1779: }
1780: unless($output{$type} eq '') {
1781: $output{$type} = '<tr class="LC_info_row">'.
1782: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1783: $output{$type};
1784: $rolesdisplay = 1;
1785: }
1786: }
1787: if ($rolesdisplay == 1) {
1788: my $contextrole='';
1789: if ($env{'request.course.id'}) {
1790: if (&Apache::loncommon::course_type() eq 'Community') {
1791: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 1792: } else {
1.329 raeburn 1793: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 1794: }
1.329 raeburn 1795: } elsif ($env{'request.role'} =~ /^au\./) {
1796: $contextrole = &mt('Existing Co-Author Roles in your Construction Space');
1797: } else {
1798: $contextrole = &mt('Existing Roles in this Domain');
1799: }
1800: $r->print('
1.217 raeburn 1801: <h3>'.$lt{'rer'}.'</h3>'.
1.329 raeburn 1802: '<div>'.$contextrole.'</div>'.
1.217 raeburn 1803: &Apache::loncommon::start_data_table("LC_createuser").
1804: &Apache::loncommon::start_data_table_header_row().
1805: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
1806: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
1807: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1808: &Apache::loncommon::end_data_table_header_row());
1.329 raeburn 1809: foreach my $type ('Construction Space','Course','Community','Domain','System','Unknown') {
1810: if ($output{$type}) {
1811: $r->print($output{$type}."\n");
1.217 raeburn 1812: }
1813: }
1.329 raeburn 1814: $r->print(&Apache::loncommon::end_data_table());
1815: }
1.217 raeburn 1816: return;
1817: }
1818:
1.218 raeburn 1819: sub new_coauthor_roles {
1820: my ($r,$ccuname,$ccdomain) = @_;
1821: my $addrolesdisplay = 0;
1822: #
1823: # Co-Author
1824: #
1825: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
1826: $env{'request.role.domain'}) &&
1827: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1828: # No sense in assigning co-author role to yourself
1829: $addrolesdisplay = 1;
1830: my $cuname=$env{'user.name'};
1831: my $cudom=$env{'request.role.domain'};
1832: my %lt=&Apache::lonlocal::texthash(
1833: 'cs' => "Construction Space",
1834: 'act' => "Activate",
1835: 'rol' => "Role",
1836: 'ext' => "Extent",
1837: 'sta' => "Start",
1838: 'end' => "End",
1839: 'cau' => "Co-Author",
1840: 'caa' => "Assistant Co-Author",
1841: 'ssd' => "Set Start Date",
1842: 'sed' => "Set End Date"
1843: );
1844: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
1845: &Apache::loncommon::start_data_table()."\n".
1846: &Apache::loncommon::start_data_table_header_row()."\n".
1847: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
1848: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
1849: '<th>'.$lt{'end'}.'</th>'."\n".
1850: &Apache::loncommon::end_data_table_header_row()."\n".
1851: &Apache::loncommon::start_data_table_row().'
1852: <td>
1.291 bisitz 1853: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 1854: </td>
1855: <td>'.$lt{'cau'}.'</td>
1856: <td>'.$cudom.'_'.$cuname.'</td>
1857: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
1858: <a href=
1859: "javascript:pjump('."'date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1860: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
1861: <a href=
1862: "javascript:pjump('."'date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
1863: &Apache::loncommon::end_data_table_row()."\n".
1864: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 1865: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 1866: <td>'.$lt{'caa'}.'</td>
1867: <td>'.$cudom.'_'.$cuname.'</td>
1868: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
1869: <a href=
1870: "javascript:pjump('."'date_start','Start Date Assistant Co-Author',document.cu.start_$cudom\_$cuname\_aa.value,'start_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1871: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
1872: <a href=
1873: "javascript:pjump('."'date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
1874: &Apache::loncommon::end_data_table_row()."\n".
1875: &Apache::loncommon::end_data_table());
1876: } elsif ($env{'request.role'} =~ /^au\./) {
1877: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
1878: $env{'request.role.domain'}))) {
1879: $r->print('<span class="LC_error">'.
1880: &mt('You do not have privileges to assign co-author roles.').
1881: '</span>');
1882: } elsif (($env{'user.name'} eq $ccuname) &&
1883: ($env{'user.domain'} eq $ccdomain)) {
1884: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Construction Space is not permitted'));
1885: }
1886: }
1887: return $addrolesdisplay;;
1888: }
1889:
1890: sub new_domain_roles {
1.357 raeburn 1891: my ($r,$ccdomain) = @_;
1.218 raeburn 1892: my $addrolesdisplay = 0;
1893: #
1894: # Domain level
1895: #
1896: my $num_domain_level = 0;
1897: my $domaintext =
1898: '<h4>'.&mt('Domain Level').'</h4>'.
1899: &Apache::loncommon::start_data_table().
1900: &Apache::loncommon::start_data_table_header_row().
1901: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
1902: &mt('Extent').'</th>'.
1903: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
1904: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 1905: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 1906: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 1907: foreach my $role (@allroles) {
1908: next if ($role eq 'ad');
1.357 raeburn 1909: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 1910: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1911: my $plrole=&Apache::lonnet::plaintext($role);
1912: my %lt=&Apache::lonlocal::texthash(
1913: 'ssd' => "Set Start Date",
1914: 'sed' => "Set End Date"
1915: );
1916: $num_domain_level ++;
1917: $domaintext .=
1918: &Apache::loncommon::start_data_table_row().
1.291 bisitz 1919: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 1920: <td>'.$plrole.'</td>
1921: <td>'.$thisdomain.'</td>
1922: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
1923: <a href=
1924: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1925: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
1926: <a href=
1927: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
1928: &Apache::loncommon::end_data_table_row();
1929: }
1930: }
1931: }
1932: $domaintext.= &Apache::loncommon::end_data_table();
1933: if ($num_domain_level > 0) {
1934: $r->print($domaintext);
1935: $addrolesdisplay = 1;
1936: }
1937: return $addrolesdisplay;
1938: }
1939:
1.188 raeburn 1940: sub user_authentication {
1.227 raeburn 1941: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 1942: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 1943: my $outcome;
1.188 raeburn 1944: # Check for a bad authentication type
1945: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
1946: # bad authentication scheme
1947: my %lt=&Apache::lonlocal::texthash(
1948: 'err' => "ERROR",
1949: 'uuas' => "This user has an unrecognized authentication scheme",
1950: 'adcs' => "Please alert a domain coordinator of this situation",
1951: 'sldb' => "Please specify login data below",
1952: 'ld' => "Login Data"
1953: );
1954: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 1955: &initialize_authen_forms($ccdomain,$formname);
1956:
1.190 raeburn 1957: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 1958: $outcome = <<ENDBADAUTH;
1959: <script type="text/javascript" language="Javascript">
1.301 bisitz 1960: // <![CDATA[
1.188 raeburn 1961: $loginscript
1.301 bisitz 1962: // ]]>
1.188 raeburn 1963: </script>
1964: <span class="LC_error">$lt{'err'}:
1965: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
1966: <h3>$lt{'ld'}</h3>
1967: $choices
1968: ENDBADAUTH
1969: } else {
1970: # This user is not allowed to modify the user's
1971: # authentication scheme, so just notify them of the problem
1972: $outcome = <<ENDBADAUTH;
1973: <span class="LC_error"> $lt{'err'}:
1974: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
1975: </span>
1976: ENDBADAUTH
1977: }
1978: } else { # Authentication type is valid
1.227 raeburn 1979: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 1980: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 1981: &modify_login_block($ccdomain,$currentauth);
1982: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1983: # Current user has login modification privileges
1984: my %lt=&Apache::lonlocal::texthash (
1985: 'ld' => "Login Data",
1986: 'ccld' => "Change Current Login Data",
1987: 'enld' => "Enter New Login Data"
1988: );
1989: $outcome =
1990: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 1991: '// <![CDATA['."\n".
1.188 raeburn 1992: $loginscript."\n".
1.301 bisitz 1993: '// ]]>'."\n".
1.188 raeburn 1994: '</script>'."\n".
1995: '<h3>'.$lt{'ld'}.'</h3>'.
1996: &Apache::loncommon::start_data_table().
1.205 raeburn 1997: &Apache::loncommon::start_data_table_row().
1.188 raeburn 1998: '<td>'.$authformnop;
1999: if ($can_modify) {
2000: $outcome .= '</td>'."\n".
2001: &Apache::loncommon::end_data_table_row().
2002: &Apache::loncommon::start_data_table_row().
2003: '<td>'.$authformcurrent.'</td>'.
2004: &Apache::loncommon::end_data_table_row()."\n";
2005: } else {
1.200 raeburn 2006: $outcome .= ' ('.$authformcurrent.')</td>'.
2007: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2008: }
1.205 raeburn 2009: foreach my $item (@authform_others) {
2010: $outcome .= &Apache::loncommon::start_data_table_row().
2011: '<td>'.$item.'</td>'.
2012: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2013: }
1.205 raeburn 2014: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2015: } else {
2016: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
2017: my %lt=&Apache::lonlocal::texthash(
2018: 'ccld' => "Change Current Login Data",
2019: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2020: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2021: );
2022: $outcome .= <<ENDNOPRIV;
2023: <h3>$lt{'ccld'}</h3>
2024: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2025: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2026: ENDNOPRIV
2027: }
2028: }
2029: } ## End of "check for bad authentication type" logic
2030: return $outcome;
2031: }
2032:
1.187 raeburn 2033: sub modify_login_block {
2034: my ($dom,$currentauth) = @_;
2035: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2036: my ($authnum,%can_assign) =
2037: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2038: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2039: if ($currentauth=~/^krb(4|5):/) {
2040: $authformcurrent=$authformkrb;
2041: if ($can_assign{'int'}) {
1.205 raeburn 2042: push(@authform_others,$authformint);
1.187 raeburn 2043: }
2044: if ($can_assign{'loc'}) {
1.205 raeburn 2045: push(@authform_others,$authformloc);
1.187 raeburn 2046: }
2047: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2048: $show_override_msg = 1;
2049: }
2050: } elsif ($currentauth=~/^internal:/) {
2051: $authformcurrent=$authformint;
2052: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2053: push(@authform_others,$authformkrb);
1.187 raeburn 2054: }
2055: if ($can_assign{'loc'}) {
1.205 raeburn 2056: push(@authform_others,$authformloc);
1.187 raeburn 2057: }
2058: if ($can_assign{'int'}) {
2059: $show_override_msg = 1;
2060: }
2061: } elsif ($currentauth=~/^unix:/) {
2062: $authformcurrent=$authformfsys;
2063: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2064: push(@authform_others,$authformkrb);
1.187 raeburn 2065: }
2066: if ($can_assign{'int'}) {
1.205 raeburn 2067: push(@authform_others,$authformint);
1.187 raeburn 2068: }
2069: if ($can_assign{'loc'}) {
1.205 raeburn 2070: push(@authform_others,$authformloc);
1.187 raeburn 2071: }
2072: if ($can_assign{'fsys'}) {
2073: $show_override_msg = 1;
2074: }
2075: } elsif ($currentauth=~/^localauth:/) {
2076: $authformcurrent=$authformloc;
2077: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2078: push(@authform_others,$authformkrb);
1.187 raeburn 2079: }
2080: if ($can_assign{'int'}) {
1.205 raeburn 2081: push(@authform_others,$authformint);
1.187 raeburn 2082: }
2083: if ($can_assign{'loc'}) {
2084: $show_override_msg = 1;
2085: }
2086: }
2087: if ($show_override_msg) {
1.205 raeburn 2088: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2089: '</td></tr>'."\n".
2090: '<tr><td> </td>'.
2091: '<td><b>'.&mt('Currently in use').'</b></td>'.
2092: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2093: &mt('will override current values').
1.205 raeburn 2094: '</span></td></tr></table>';
1.187 raeburn 2095: }
1.205 raeburn 2096: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2097: }
2098:
1.188 raeburn 2099: sub personal_data_display {
1.252 raeburn 2100: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
1.286 raeburn 2101: my ($output,$showforceid,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2102: my @userinfo = ('firstname','middlename','lastname','generation',
2103: 'permanentemail','id');
1.252 raeburn 2104: my $rowcount = 0;
2105: my $editable = 0;
1.286 raeburn 2106: %canmodify_status =
2107: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2108: ['inststatus'],$rolesarray);
1.253 raeburn 2109: if (!$newuser) {
1.188 raeburn 2110: # Get the users information
2111: %userenv = &Apache::lonnet::get('environment',
2112: ['firstname','middlename','lastname','generation',
1.286 raeburn 2113: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2114: %canmodify =
2115: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2116: \@userinfo,$rolesarray);
1.257 raeburn 2117: } elsif ($context eq 'selfcreate') {
2118: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2119: $inst_results,$rolesarray);
1.188 raeburn 2120: }
2121: my %lt=&Apache::lonlocal::texthash(
2122: 'pd' => "Personal Data",
2123: 'firstname' => "First Name",
2124: 'middlename' => "Middle Name",
2125: 'lastname' => "Last Name",
2126: 'generation' => "Generation",
2127: 'permanentemail' => "Permanent e-mail address",
1.259 bisitz 2128: 'id' => "Student/Employee ID",
1.286 raeburn 2129: 'lg' => "Login Data",
2130: 'inststatus' => "Affiliation",
1.188 raeburn 2131: );
2132: my %textboxsize = (
2133: firstname => '15',
2134: middlename => '15',
2135: lastname => '15',
2136: generation => '5',
2137: permanentemail => '25',
2138: id => '15',
2139: );
2140: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2141: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2142: &Apache::lonhtmlcommon::start_pick_box();
2143: foreach my $item (@userinfo) {
2144: my $rowtitle = $lt{$item};
1.252 raeburn 2145: my $hiderow = 0;
1.188 raeburn 2146: if ($item eq 'generation') {
2147: $rowtitle = $genhelp.$rowtitle;
2148: }
1.252 raeburn 2149: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2150: if ($newuser) {
1.210 raeburn 2151: if (ref($inst_results) eq 'HASH') {
2152: if ($inst_results->{$item} ne '') {
1.252 raeburn 2153: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2154: } else {
1.252 raeburn 2155: if ($context eq 'selfcreate') {
2156: if ($canmodify{$item}) {
2157: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2158: $editable ++;
2159: } else {
2160: $hiderow = 1;
2161: }
1.253 raeburn 2162: } else {
2163: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2164: }
1.210 raeburn 2165: }
1.188 raeburn 2166: } else {
1.252 raeburn 2167: if ($context eq 'selfcreate') {
1.287 raeburn 2168: if (($item eq 'permanentemail') && ($newuser eq 'email')) {
2169: $row .= $ccuname;
1.252 raeburn 2170: } else {
1.287 raeburn 2171: if ($canmodify{$item}) {
2172: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2173: $editable ++;
2174: } else {
2175: $hiderow = 1;
2176: }
1.252 raeburn 2177: }
1.253 raeburn 2178: } else {
2179: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2180: }
1.188 raeburn 2181: }
2182: } else {
1.219 raeburn 2183: if ($canmodify{$item}) {
1.252 raeburn 2184: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.188 raeburn 2185: } else {
1.252 raeburn 2186: $row .= $userenv{$item};
1.188 raeburn 2187: }
1.206 raeburn 2188: if ($item eq 'id') {
1.219 raeburn 2189: $showforceid = $canmodify{$item};
2190: }
1.188 raeburn 2191: }
1.252 raeburn 2192: $row .= &Apache::lonhtmlcommon::row_closure(1);
2193: if (!$hiderow) {
2194: $output .= $row;
2195: $rowcount ++;
2196: }
1.188 raeburn 2197: }
1.286 raeburn 2198: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2199: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2200: if (ref($types) eq 'ARRAY') {
2201: if (@{$types} > 0) {
2202: my ($hiderow,$shown);
2203: if ($canmodify_status{'inststatus'}) {
2204: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2205: } else {
2206: if ($userenv{'inststatus'} eq '') {
2207: $hiderow = 1;
1.334 raeburn 2208: } else {
2209: my @showitems;
2210: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2211: if (exists($usertypes->{$item})) {
2212: push(@showitems,$usertypes->{$item});
2213: } else {
2214: push(@showitems,$item);
2215: }
2216: }
2217: if (@showitems) {
2218: $shown = join(', ',@showitems);
2219: } else {
2220: $hiderow = 1;
2221: }
1.286 raeburn 2222: }
2223: }
2224: if (!$hiderow) {
2225: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affliations'),undef,'LC_oddrow_value')."\n".
2226: $shown.&Apache::lonhtmlcommon::row_closure(1);
2227: if ($context eq 'selfcreate') {
2228: $rowcount ++;
2229: }
2230: $output .= $row;
2231: }
2232: }
2233: }
2234: }
1.188 raeburn 2235: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2236: if (wantarray) {
1.252 raeburn 2237: if ($context eq 'selfcreate') {
2238: return($output,$rowcount,$editable);
2239: } else {
2240: return ($output,$showforceid);
2241: }
1.206 raeburn 2242: } else {
2243: return $output;
2244: }
1.188 raeburn 2245: }
2246:
1.286 raeburn 2247: sub pick_inst_statuses {
2248: my ($curr,$usertypes,$types) = @_;
2249: my ($output,$rem,@currtypes);
2250: if ($curr ne '') {
2251: @currtypes = map { &unescape($_); } split(/:/,$curr);
2252: }
2253: my $numinrow = 2;
2254: if (ref($types) eq 'ARRAY') {
2255: $output = '<table>';
2256: my $lastcolspan;
2257: for (my $i=0; $i<@{$types}; $i++) {
2258: if (defined($usertypes->{$types->[$i]})) {
2259: my $rem = $i%($numinrow);
2260: if ($rem == 0) {
2261: if ($i<@{$types}-1) {
2262: if ($i > 0) {
2263: $output .= '</tr>';
2264: }
2265: $output .= '<tr>';
2266: }
2267: } elsif ($i==@{$types}-1) {
2268: my $colsleft = $numinrow - $rem;
2269: if ($colsleft > 1) {
2270: $lastcolspan = ' colspan="'.$colsleft.'"';
2271: }
2272: }
2273: my $check = ' ';
2274: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2275: $check = ' checked="checked" ';
2276: }
2277: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2278: '<span class="LC_nobreak"><label>'.
2279: '<input type="checkbox" name="inststatus" '.
2280: 'value="'.$types->[$i].'"'.$check.'/>'.
2281: $usertypes->{$types->[$i]}.'</label></span></td>';
2282: }
2283: }
2284: $output .= '</tr></table>';
2285: }
2286: return $output;
2287: }
2288:
1.257 raeburn 2289: sub selfcreate_canmodify {
2290: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2291: if (ref($inst_results) eq 'HASH') {
2292: my @inststatuses = &get_inststatuses($inst_results);
2293: if (@inststatuses == 0) {
2294: @inststatuses = ('default');
2295: }
2296: $rolesarray = \@inststatuses;
2297: }
2298: my %canmodify =
2299: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2300: $rolesarray);
2301: return %canmodify;
2302: }
2303:
1.252 raeburn 2304: sub get_inststatuses {
2305: my ($insthashref) = @_;
2306: my @inststatuses = ();
2307: if (ref($insthashref) eq 'HASH') {
2308: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2309: @inststatuses = @{$insthashref->{'inststatus'}};
2310: }
2311: }
2312: return @inststatuses;
2313: }
2314:
1.4 www 2315: # ================================================================= Phase Three
1.42 matthew 2316: sub update_user_data {
1.351 raeburn 2317: my ($r,$context,$crstype,$brcrum) = @_;
1.101 albertel 2318: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2319: $env{'form.ccdomain'});
1.27 matthew 2320: # Error messages
1.188 raeburn 2321: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2322: my $end = '</span><br /><br />';
2323: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2324: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2325: &mt('Return to previous page').'</a>'.
2326: &Apache::loncommon::end_page();
2327: my $now = time;
1.40 www 2328: my $title;
1.101 albertel 2329: if (exists($env{'form.makeuser'})) {
1.40 www 2330: $title='Set Privileges for New User';
2331: } else {
2332: $title='Modify User Privileges';
2333: }
1.213 raeburn 2334: my $newuser = 0;
1.160 raeburn 2335: my ($jsback,$elements) = &crumb_utilities();
2336: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2337: '// <![CDATA['."\n".
2338: $jsback."\n".
2339: '// ]]>'."\n".
2340: '</script>'."\n";
1.318 raeburn 2341: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 2342: push (@{$brcrum},
2343: {href => "javascript:backPage(document.userupdate)",
2344: text => $breadcrumb_text{'search'},
2345: faq => 282,
2346: bug => 'Instructor Interface',}
2347: );
2348: if ($env{'form.prevphase'} eq 'userpicked') {
2349: push(@{$brcrum},
2350: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2351: text => $breadcrumb_text{'userpicked'},
2352: faq => 282,
2353: bug => 'Instructor Interface',});
1.233 raeburn 2354: }
1.224 raeburn 2355: my $helpitem = 'Course_Change_Privileges';
2356: if ($env{'form.action'} eq 'singlestudent') {
2357: $helpitem = 'Course_Add_Student';
2358: }
1.351 raeburn 2359: push(@{$brcrum},
2360: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2361: text => $breadcrumb_text{'modify'},
2362: faq => 282,
2363: bug => 'Instructor Interface',},
2364: {href => "/adm/createuser",
2365: text => "Result",
2366: faq => 282,
2367: bug => 'Instructor Interface',
2368: help => $helpitem});
2369: my $args = {bread_crumbs => $brcrum,
2370: bread_crumbs_component => 'User Management'};
2371: if ($env{'form.popup'}) {
2372: $args->{'no_nav_bar'} = 1;
2373: }
2374: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2375: $r->print(&update_result_form($uhome));
1.27 matthew 2376: # Check Inputs
1.101 albertel 2377: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2378: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2379: return;
2380: }
1.138 albertel 2381: if ( $env{'form.ccuname'} ne
2382: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2383: $r->print($error.&mt('Invalid login name.').' '.
2384: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2385: $end.$rtnlink);
1.27 matthew 2386: return;
2387: }
1.101 albertel 2388: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2389: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2390: return;
2391: }
1.138 albertel 2392: if ( $env{'form.ccdomain'} ne
2393: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2394: $r->print($error.&mt('Invalid domain name.').' '.
2395: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2396: $end.$rtnlink);
1.27 matthew 2397: return;
2398: }
1.219 raeburn 2399: if ($uhome eq 'no_host') {
2400: $newuser = 1;
2401: }
1.101 albertel 2402: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2403: # Modifying an existing user, so check the validity of the name
2404: if ($uhome eq 'no_host') {
1.73 sakharuk 2405: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 2406: $env{'form.ccuname'}.&mt(' in domain ').
2407: $env{'form.ccdomain'}.'.');
1.29 matthew 2408: return;
2409: }
2410: }
1.27 matthew 2411: # Determine authentication method and password for the user being modified
2412: my $amode='';
2413: my $genpwd='';
1.101 albertel 2414: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2415: $amode='krb';
1.101 albertel 2416: $amode.=$env{'form.krbver'};
2417: $genpwd=$env{'form.krbarg'};
2418: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2419: $amode='internal';
1.101 albertel 2420: $genpwd=$env{'form.intarg'};
2421: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2422: $amode='unix';
1.101 albertel 2423: $genpwd=$env{'form.fsysarg'};
2424: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2425: $amode='localauth';
1.101 albertel 2426: $genpwd=$env{'form.locarg'};
1.27 matthew 2427: $genpwd=" " if (!$genpwd);
1.101 albertel 2428: } elsif (($env{'form.login'} eq 'nochange') ||
2429: ($env{'form.login'} eq '' )) {
1.34 matthew 2430: # There is no need to tell the user we did not change what they
2431: # did not ask us to change.
1.35 matthew 2432: # If they are creating a new user but have not specified login
2433: # information this will be caught below.
1.30 matthew 2434: } else {
1.367 golterma 2435: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2436: return;
1.27 matthew 2437: }
1.164 albertel 2438:
1.188 raeburn 2439: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2440: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2441: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2442: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2443:
1.193 raeburn 2444: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2445: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2446: my @usertools = ('aboutme','blog','webdav','portfolio');
1.299 raeburn 2447: my @requestcourses = ('official','unofficial','community');
1.362 raeburn 2448: my @requestauthor = ('requestauthor');
1.286 raeburn 2449: my ($othertitle,$usertypes,$types) =
2450: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2451: my %canmodify_status =
2452: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2453: ['inststatus']);
1.101 albertel 2454: if ($env{'form.makeuser'}) {
1.164 albertel 2455: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2456: # Check for the authentication mode and password
2457: if (! $amode || ! $genpwd) {
1.193 raeburn 2458: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2459: return;
1.18 albertel 2460: }
1.29 matthew 2461: # Determine desired host
1.101 albertel 2462: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2463: if (lc($desiredhost) eq 'default') {
2464: $desiredhost = undef;
2465: } else {
1.147 albertel 2466: my %home_servers =
2467: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2468: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2469: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2470: return;
2471: }
2472: }
2473: # Check ID format
2474: my %checkhash;
2475: my %checks = ('id' => 1);
2476: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2477: 'newuser' => $newuser,
1.196 raeburn 2478: 'id' => $env{'form.cid'},
1.193 raeburn 2479: );
1.196 raeburn 2480: if ($env{'form.cid'} ne '') {
2481: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2482: \%rulematch,\%inst_results,\%curr_rules);
2483: if (ref($alerts{'id'}) eq 'HASH') {
2484: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2485: my $domdesc =
2486: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2487: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2488: my $userchkmsg;
2489: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2490: $userchkmsg =
2491: &Apache::loncommon::instrule_disallow_msg('id',
2492: $domdesc,1).
2493: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2494: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2495: }
2496: $r->print($error.&mt('Invalid ID format').$end.
2497: $userchkmsg.$rtnlink);
2498: return;
2499: }
2500: }
1.29 matthew 2501: }
2502: }
1.367 golterma 2503: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2504: # Call modifyuser
2505: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2506: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2507: $amode,$genpwd,$env{'form.cfirstname'},
2508: $env{'form.cmiddlename'},$env{'form.clastname'},
2509: $env{'form.cgeneration'},undef,$desiredhost,
2510: $env{'form.cpermanentemail'});
1.77 www 2511: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2512: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2513: $env{'form.ccdomain'});
1.334 raeburn 2514: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2515: if ($uhome ne 'no_host') {
1.334 raeburn 2516: if ($context eq 'domain') {
2517: if ($env{'form.customquota'} == 1) {
2518: if ($env{'form.portfolioquota'} eq '') {
2519: $newcustom{'quota'} = 0;
2520: } else {
2521: $newcustom{'quota'} = $env{'form.portfolioquota'};
2522: $newcustom{'quota'} =~ s/[^\d\.]//g;
2523: }
2524: $changed{'quota'} = "a_admin($newcustom{'quota'},\%changeHash);
2525: }
2526: foreach my $item (@usertools) {
2527: if ($env{'form.custom'.$item} == 1) {
2528: $newcustom{$item} = $env{'form.tools_'.$item};
2529: $changed{$item} = &tool_admin($item,$newcustom{$item},
2530: \%changeHash,'tools');
2531: }
1.267 raeburn 2532: }
1.334 raeburn 2533: foreach my $item (@requestcourses) {
1.341 raeburn 2534: if ($env{'form.custom'.$item} == 1) {
2535: $newcustom{$item} = $env{'form.crsreq_'.$item};
2536: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2537: $newcustom{$item} .= '=';
2538: unless ($env{'form.crsreq_'.$item.'_limit'} =~ /\D/) {
2539: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2540: }
1.334 raeburn 2541: }
1.341 raeburn 2542: $changed{$item} = &tool_admin($item,$newcustom{$item},
2543: \%changeHash,'requestcourses');
1.334 raeburn 2544: }
1.275 raeburn 2545: }
1.362 raeburn 2546: if ($env{'form.customrequestauthor'} == 1) {
2547: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2548: $changed{'requestauthor'} = &tool_admin('requestauthor',
2549: $newcustom{'requestauthor'},
2550: \%changeHash,'requestauthor');
2551: }
1.275 raeburn 2552: }
1.334 raeburn 2553: if ($canmodify_status{'inststatus'}) {
2554: if (exists($env{'form.inststatus'})) {
2555: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2556: if (@inststatuses > 0) {
2557: $changeHash{'inststatus'} = join(',',@inststatuses);
2558: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2559: }
2560: }
1.232 raeburn 2561: }
1.334 raeburn 2562: if (keys(%changed)) {
2563: foreach my $item (@userinfo) {
2564: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2565: }
1.267 raeburn 2566: my $chgresult =
2567: &Apache::lonnet::put('environment',\%changeHash,
2568: $env{'form.ccdomain'},$env{'form.ccuname'});
2569: }
1.232 raeburn 2570: }
1.219 raeburn 2571: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2572: &Apache::lonnet::hostname($uhome));
1.101 albertel 2573: } elsif (($env{'form.login'} ne 'nochange') &&
2574: ($env{'form.login'} ne '' )) {
1.27 matthew 2575: # Modify user privileges
2576: if (! $amode || ! $genpwd) {
1.193 raeburn 2577: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2578: return;
1.20 harris41 2579: }
1.27 matthew 2580: # Only allow authentification modification if the person has authority
1.101 albertel 2581: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2582: $r->print('Modifying authentication: '.
1.31 matthew 2583: &Apache::lonnet::modifyuserauth(
1.101 albertel 2584: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2585: $amode,$genpwd));
1.102 albertel 2586: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2587: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2588: } else {
1.27 matthew 2589: # Okay, this is a non-fatal error.
1.193 raeburn 2590: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
1.27 matthew 2591: }
1.28 matthew 2592: }
1.344 bisitz 2593: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2594: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2595: ##
1.343 raeburn 2596: my (@userroles,%userupdate,$cnum,$cdom,%namechanged);
1.213 raeburn 2597: if ($context eq 'course') {
2598: ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2599: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.213 raeburn 2600: }
1.101 albertel 2601: if (! $env{'form.makeuser'} ) {
1.28 matthew 2602: # Check for need to change
2603: my %userenv = &Apache::lonnet::get
1.134 raeburn 2604: ('environment',['firstname','middlename','lastname','generation',
1.267 raeburn 2605: 'id','permanentemail','portfolioquota','inststatus','tools.aboutme',
1.361 raeburn 2606: 'tools.blog','tools.webdav','tools.portfolio',
2607: 'requestcourses.official','requestcourses.unofficial',
2608: 'requestcourses.community','reqcrsotherdom.official',
1.362 raeburn 2609: 'reqcrsotherdom.unofficial','reqcrsotherdom.community',
2610: 'requestauthor'],
1.160 raeburn 2611: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2612: my ($tmp) = keys(%userenv);
2613: if ($tmp =~ /^(con_lost|error)/i) {
2614: %userenv = ();
2615: }
1.206 raeburn 2616: my $no_forceid_alert;
2617: # Check to see if user information can be changed
2618: my %domconfig =
2619: &Apache::lonnet::get_dom('configuration',['usermodification'],
2620: $env{'form.ccdomain'});
1.213 raeburn 2621: my @statuses = ('active','future');
2622: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2623: my ($auname,$audom);
1.220 raeburn 2624: if ($context eq 'author') {
1.206 raeburn 2625: $auname = $env{'user.name'};
2626: $audom = $env{'user.domain'};
2627: }
2628: foreach my $item (keys(%roles)) {
1.220 raeburn 2629: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2630: if ($context eq 'course') {
2631: if ($cnum ne '' && $cdom ne '') {
2632: if ($rolenum eq $cnum && $roledom eq $cdom) {
2633: if (!grep(/^\Q$role\E$/,@userroles)) {
2634: push(@userroles,$role);
2635: }
2636: }
2637: }
2638: } elsif ($context eq 'author') {
2639: if ($rolenum eq $auname && $roledom eq $audom) {
2640: if (!grep(/^\Q$role\E$/,@userroles)) {
2641: push(@userroles,$role);
2642: }
2643: }
2644: }
2645: }
1.220 raeburn 2646: if ($env{'form.action'} eq 'singlestudent') {
2647: if (!grep(/^st$/,@userroles)) {
2648: push(@userroles,'st');
2649: }
2650: } else {
2651: # Check for course or co-author roles being activated or re-enabled
2652: if ($context eq 'author' || $context eq 'course') {
2653: foreach my $key (keys(%env)) {
2654: if ($context eq 'author') {
2655: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2656: if (!grep(/^\Q$1\E$/,@userroles)) {
2657: push(@userroles,$1);
2658: }
2659: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2660: if (!grep(/^\Q$1\E$/,@userroles)) {
2661: push(@userroles,$1);
2662: }
1.206 raeburn 2663: }
1.220 raeburn 2664: } elsif ($context eq 'course') {
2665: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2666: if (!grep(/^\Q$1\E$/,@userroles)) {
2667: push(@userroles,$1);
2668: }
2669: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
2670: if (!grep(/^\Q$1\E$/,@userroles)) {
2671: push(@userroles,$1);
2672: }
1.206 raeburn 2673: }
2674: }
2675: }
2676: }
2677: }
2678: #Check to see if we can change personal data for the user
2679: my (@mod_disallowed,@longroles);
2680: foreach my $role (@userroles) {
2681: if ($role eq 'cr') {
2682: push(@longroles,'Custom');
2683: } else {
1.318 raeburn 2684: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 2685: }
2686: }
1.219 raeburn 2687: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
2688: foreach my $item (@userinfo) {
1.28 matthew 2689: # Strip leading and trailing whitespace
1.203 raeburn 2690: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 2691: if (!$canmodify{$item}) {
1.207 raeburn 2692: if (defined($env{'form.c'.$item})) {
2693: if ($env{'form.c'.$item} ne $userenv{$item}) {
2694: push(@mod_disallowed,$item);
2695: }
1.206 raeburn 2696: }
2697: $env{'form.c'.$item} = $userenv{$item};
2698: }
1.28 matthew 2699: }
1.259 bisitz 2700: # Check to see if we can change the Student/Employee ID
1.196 raeburn 2701: my $forceid = $env{'form.forceid'};
2702: my $recurseid = $env{'form.recurseid'};
2703: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 2704: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
2705: $env{'form.ccuname'});
2706: if (($uidhash{$env{'form.ccuname'}}) &&
2707: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
2708: (!$forceid)) {
2709: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
2710: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 2711: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 2712: .'<br />'
2713: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
2714: .'<br />'."\n";
1.203 raeburn 2715: }
2716: }
2717: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 2718: my $checkhash;
2719: my $checks = { 'id' => 1 };
2720: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
2721: { 'newuser' => $newuser,
2722: 'id' => $env{'form.cid'},
2723: };
2724: &Apache::loncommon::user_rule_check($checkhash,$checks,
2725: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
2726: if (ref($alerts{'id'}) eq 'HASH') {
2727: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 2728: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 2729: }
2730: }
2731: }
1.286 raeburn 2732: my ($quotachanged,$oldportfolioquota,$newportfolioquota,$oldinststatus,
1.334 raeburn 2733: $newinststatus,$oldisdefault,$newisdefault,%oldsettings,
1.339 raeburn 2734: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
2735: $olddefquota,$oldsettingstatus,$newdefquota,$newsettingstatus);
1.334 raeburn 2736: @disporder = ('inststatus');
2737: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 2738: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 2739: } else {
2740: push(@disporder,'reqcrsotherdom');
2741: }
2742: push(@disporder,('quota','tools'));
1.338 raeburn 2743: $oldinststatus = $userenv{'inststatus'};
1.339 raeburn 2744: ($olddefquota,$oldsettingstatus) =
1.334 raeburn 2745: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus);
1.339 raeburn 2746: ($newdefquota,$newsettingstatus) = ($olddefquota,$oldsettingstatus);
1.334 raeburn 2747: my %canshow;
1.220 raeburn 2748: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 2749: $canshow{'quota'} = 1;
1.220 raeburn 2750: }
1.267 raeburn 2751: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 2752: $canshow{'tools'} = 1;
1.267 raeburn 2753: }
1.275 raeburn 2754: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 2755: $canshow{'requestcourses'} = 1;
1.300 raeburn 2756: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 2757: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 2758: }
1.286 raeburn 2759: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 2760: $canshow{'inststatus'} = 1;
1.286 raeburn 2761: }
1.362 raeburn 2762: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
2763: $canshow{'requestauthor'} = 1;
2764: }
1.267 raeburn 2765: my (%changeHash,%changed);
1.286 raeburn 2766: if ($oldinststatus eq '') {
1.334 raeburn 2767: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 2768: } else {
2769: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2770: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2771: } else {
1.334 raeburn 2772: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2773: }
2774: }
2775: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 2776: if ($canmodify_status{'inststatus'}) {
2777: $canshow{'inststatus'} = 1;
1.286 raeburn 2778: if (exists($env{'form.inststatus'})) {
2779: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2780: if (@inststatuses > 0) {
2781: $newinststatus = join(':',map { &escape($_); } @inststatuses);
2782: $changeHash{'inststatus'} = $newinststatus;
2783: if ($newinststatus ne $oldinststatus) {
2784: $changed{'inststatus'} = $newinststatus;
1.339 raeburn 2785: ($newdefquota,$newsettingstatus) =
2786: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus);
1.286 raeburn 2787: }
2788: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2789: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 2790: } else {
1.337 raeburn 2791: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 2792: }
1.334 raeburn 2793: }
2794: } else {
2795: $newinststatus = '';
2796: $changeHash{'inststatus'} = $newinststatus;
2797: $newsettings{'inststatus'} = $othertitle;
2798: if ($newinststatus ne $oldinststatus) {
2799: $changed{'inststatus'} = $changeHash{'inststatus'};
1.339 raeburn 2800: ($newdefquota,$newsettingstatus) =
2801: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus);
1.286 raeburn 2802: }
2803: }
1.334 raeburn 2804: } elsif ($context ne 'selfcreate') {
2805: $canshow{'inststatus'} = 1;
1.337 raeburn 2806: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 2807: }
1.204 raeburn 2808: $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
1.334 raeburn 2809: if ($context eq 'domain') {
2810: if ($userenv{'portfolioquota'} ne '') {
2811: $oldportfolioquota = $userenv{'portfolioquota'};
2812: if ($env{'form.customquota'} == 1) {
2813: if ($env{'form.portfolioquota'} eq '') {
2814: $newportfolioquota = 0;
2815: } else {
2816: $newportfolioquota = $env{'form.portfolioquota'};
2817: $newportfolioquota =~ s/[^\d\.]//g;
2818: }
2819: if ($newportfolioquota != $oldportfolioquota) {
2820: $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash);
2821: }
1.149 raeburn 2822: } else {
1.334 raeburn 2823: $changed{'quota'} = "a_admin('',\%changeHash);
1.339 raeburn 2824: $newportfolioquota = $newdefquota;
1.334 raeburn 2825: $newisdefault = 1;
1.149 raeburn 2826: }
1.334 raeburn 2827: } else {
2828: $oldisdefault = 1;
1.339 raeburn 2829: $oldportfolioquota = $olddefquota;
1.334 raeburn 2830: if ($env{'form.customquota'} == 1) {
2831: if ($env{'form.portfolioquota'} eq '') {
2832: $newportfolioquota = 0;
2833: } else {
2834: $newportfolioquota = $env{'form.portfolioquota'};
2835: $newportfolioquota =~ s/[^\d\.]//g;
2836: }
1.267 raeburn 2837: $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash);
1.334 raeburn 2838: } else {
1.339 raeburn 2839: $newportfolioquota = $newdefquota;
1.334 raeburn 2840: $newisdefault = 1;
1.134 raeburn 2841: }
2842: }
1.334 raeburn 2843: if ($oldisdefault) {
1.339 raeburn 2844: $oldsettingstext{'quota'} = &get_defaultquota_text($oldsettingstatus);
1.334 raeburn 2845: }
2846: if ($newisdefault) {
1.339 raeburn 2847: $newsettingstext{'quota'} = &get_defaultquota_text($newsettingstatus);
1.334 raeburn 2848: }
2849: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
2850: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
2851: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
2852: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
2853: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.362 raeburn 2854: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,\%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 2855: } else {
1.334 raeburn 2856: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
2857: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 2858: }
2859: }
1.334 raeburn 2860: foreach my $item (@userinfo) {
2861: if ($env{'form.c'.$item} ne $userenv{$item}) {
2862: $namechanged{$item} = 1;
2863: }
1.204 raeburn 2864: }
1.334 raeburn 2865: $oldsettings{'quota'} = $oldportfolioquota.' Mb';
2866: $newsettings{'quota'} = $newportfolioquota.' Mb';
2867: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 2868: my ($chgresult,$namechgresult);
2869: if (keys(%changed) > 0) {
2870: $chgresult =
1.204 raeburn 2871: &Apache::lonnet::put('environment',\%changeHash,
2872: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 2873: if ($chgresult eq 'ok') {
2874: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
2875: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 2876: my %newenvhash;
2877: foreach my $key (keys(%changed)) {
1.299 raeburn 2878: if (($key eq 'official') || ($key eq 'unofficial')
2879: || ($key eq 'community')) {
1.279 raeburn 2880: $newenvhash{'environment.requestcourses.'.$key} =
2881: $changeHash{'requestcourses.'.$key};
1.362 raeburn 2882: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 2883: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 2884: } else {
2885: $newenvhash{'environment.canrequest.'.$key} =
2886: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2887: $key,'reload','requestcourses');
2888: }
1.362 raeburn 2889: } elsif ($key eq 'requestauthor') {
2890: $newenvhash{'environment.'.$key} = $changeHash{$key};
2891: if ($changeHash{$key}) {
2892: $newenvhash{'environment.canrequest.author'} = 1;
2893: } else {
2894: $newenvhash{'environment.canrequest.author'} =
2895: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2896: $key,'reload','requestauthor');
2897: }
1.275 raeburn 2898: } elsif ($key ne 'quota') {
1.270 raeburn 2899: $newenvhash{'environment.tools.'.$key} =
2900: $changeHash{'tools.'.$key};
1.279 raeburn 2901: if ($changeHash{'tools.'.$key} ne '') {
2902: $newenvhash{'environment.availabletools.'.$key} =
2903: $changeHash{'tools.'.$key};
2904: } else {
2905: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 2906: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2907: $key,'reload','tools');
1.279 raeburn 2908: }
1.270 raeburn 2909: }
2910: }
1.271 raeburn 2911: if (keys(%newenvhash)) {
2912: &Apache::lonnet::appenv(\%newenvhash);
2913: }
1.267 raeburn 2914: }
2915: }
1.204 raeburn 2916: }
1.334 raeburn 2917: if (keys(%namechanged) > 0) {
1.337 raeburn 2918: foreach my $field (@userinfo) {
2919: $changeHash{$field} = $env{'form.c'.$field};
2920: }
2921: # Make the change
1.204 raeburn 2922: $namechgresult =
2923: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
2924: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
2925: $changeHash{'firstname'},$changeHash{'middlename'},
2926: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 2927: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 2928: %userupdate = (
2929: lastname => $env{'form.clastname'},
2930: middlename => $env{'form.cmiddlename'},
2931: firstname => $env{'form.cfirstname'},
2932: generation => $env{'form.cgeneration'},
2933: id => $env{'form.cid'},
2934: );
1.204 raeburn 2935: }
1.334 raeburn 2936: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 2937: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 2938: # Tell the user we changed the name
1.334 raeburn 2939: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 2940: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 2941: \%oldsettings, \%oldsettingstext,\%newsettings,
2942: \%newsettingstext);
1.203 raeburn 2943: if ($env{'form.cid'} ne $userenv{'id'}) {
2944: &Apache::lonnet::idput($env{'form.ccdomain'},
2945: ($env{'form.ccuname'} => $env{'form.cid'}));
2946: if (($recurseid) &&
2947: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
2948: my $idresult =
2949: &Apache::lonuserutils::propagate_id_change(
2950: $env{'form.ccuname'},$env{'form.ccdomain'},
2951: \%userupdate);
2952: $r->print('<br />'.$idresult.'<br />');
2953: }
1.196 raeburn 2954: }
1.149 raeburn 2955: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
2956: ($env{'form.ccuname'} eq $env{'user.name'})) {
2957: my %newenvhash;
2958: foreach my $key (keys(%changeHash)) {
2959: $newenvhash{'environment.'.$key} = $changeHash{$key};
2960: }
1.238 raeburn 2961: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 2962: }
1.28 matthew 2963: } else { # error occurred
1.188 raeburn 2964: $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
2965: $env{'form.ccuname'}.' '.&mt('in domain').' '.
1.206 raeburn 2966: $env{'form.ccdomain'}.'</span><br />');
1.28 matthew 2967: }
1.334 raeburn 2968: } else { # End of if ($env ... ) logic
1.275 raeburn 2969: # They did not want to change the users name, quota, tool availability,
2970: # or ability to request creation of courses,
1.267 raeburn 2971: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 2972: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 2973: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 2974: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 2975: }
1.206 raeburn 2976: if (@mod_disallowed) {
2977: my ($rolestr,$contextname);
2978: if (@longroles > 0) {
2979: $rolestr = join(', ',@longroles);
2980: } else {
2981: $rolestr = &mt('No roles');
2982: }
2983: if ($context eq 'course') {
2984: $contextname = &mt('course');
2985: } elsif ($context eq 'author') {
2986: $contextname = &mt('co-author');
2987: }
2988: $r->print(&mt('The following fields were not updated: ').'<ul>');
2989: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2990: foreach my $field (@mod_disallowed) {
2991: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
2992: }
1.207 raeburn 2993: $r->print('</ul>');
2994: if (@mod_disallowed == 1) {
2995: $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future [_1] roles:",$contextname));
2996: } else {
2997: $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future [_1] roles:",$contextname));
2998: }
1.292 bisitz 2999: my $helplink = 'javascript:helpMenu('."'display'".')';
3000: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3001: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3002: ,'<a href="'.$helplink.'">','</a>')
3003: .'<br />');
1.206 raeburn 3004: }
1.259 bisitz 3005: $r->print('<span class="LC_warning">'
3006: .$no_forceid_alert
3007: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3008: .'</span>');
1.4 www 3009: }
1.367 golterma 3010: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3011: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 3012: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype);
3013: $r->print('<p><a href="javascript:backPage(document.userupdate)">');
3014: if ($crstype eq 'Community') {
3015: $r->print(&mt('Enroll Another Member'));
3016: } else {
3017: $r->print(&mt('Enroll Another Student'));
3018: }
3019: $r->print('</a></p>');
1.220 raeburn 3020: } else {
1.239 raeburn 3021: my @rolechanges = &update_roles($r,$context);
1.334 raeburn 3022: if (keys(%namechanged) > 0) {
1.220 raeburn 3023: if ($context eq 'course') {
3024: if (@userroles > 0) {
1.225 raeburn 3025: if ((@rolechanges == 0) ||
3026: (!(grep(/^st$/,@rolechanges)))) {
3027: if (grep(/^st$/,@userroles)) {
3028: my $classlistupdated =
3029: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3030: $cnum,$env{'form.ccdomain'},
3031: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3032: }
1.220 raeburn 3033: }
3034: }
3035: }
3036: }
1.226 raeburn 3037: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3038: $env{'form.ccdomain'});
3039: if ($env{'form.popup'}) {
3040: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3041: } else {
1.367 golterma 3042: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3043: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3044: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3045: }
1.220 raeburn 3046: }
3047: }
3048:
1.334 raeburn 3049: sub display_userinfo {
1.362 raeburn 3050: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3051: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3052: $newsetting,$newsettingtext) = @_;
3053: return unless (ref($order) eq 'ARRAY' &&
3054: ref($canshow) eq 'HASH' &&
3055: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3056: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3057: ref($usertools) eq 'ARRAY' &&
3058: ref($userenv) eq 'HASH' &&
3059: ref($changedhash) eq 'HASH' &&
3060: ref($oldsetting) eq 'HASH' &&
3061: ref($oldsettingtext) eq 'HASH' &&
3062: ref($newsetting) eq 'HASH' &&
3063: ref($newsettingtext) eq 'HASH');
3064: my %lt=&Apache::lonlocal::texthash(
3065: 'ui' => 'User Information (unchanged)',
3066: 'uic' => 'User Information Changed',
3067: 'firstname' => 'First Name',
3068: 'middlename' => 'Middle Name',
3069: 'lastname' => 'Last Name',
3070: 'generation' => 'Generation',
3071: 'id' => 'Student/Employee ID',
3072: 'permanentemail' => 'Permanent e-mail address',
3073: 'quota' => 'Disk space allocated to portfolio files',
3074: 'blog' => 'Blog Availability',
1.361 raeburn 3075: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3076: 'aboutme' => 'Personal Information Page Availability',
3077: 'portfolio' => 'Portfolio Availability',
3078: 'official' => 'Can Request Official Courses',
3079: 'unofficial' => 'Can Request Unofficial Courses',
3080: 'community' => 'Can Request Communities',
1.362 raeburn 3081: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3082: 'inststatus' => "Affiliation",
3083: 'prvs' => 'Previous Value:',
3084: 'chto' => 'Changed To:'
3085: );
3086: my $title = $lt{'ui'};
3087: if ($changed) {
3088: $title = $lt{'uic'};
1.367 golterma 3089: $r->print('<h4>'.$title.'</h4>'.
3090: &Apache::loncommon::start_data_table().
3091: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3092: $r->print("<th> </th>\n");
1.367 golterma 3093: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3094: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3095: $r->print(&Apache::loncommon::end_data_table_header_row());
3096: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3097:
3098:
1.334 raeburn 3099: foreach my $item (@userinfo) {
3100: my $value = $env{'form.c'.$item};
1.367 golterma 3101: #show changes only:
3102: unless($value eq $userenv->{$item}){
3103: $r->print(&Apache::loncommon::start_data_table_row());
3104:
3105: $r->print("<td>$lt{$item}</td>\n");
3106: $r->print('<td>'.$userenv->{$item}.' </td>');
3107: $r->print("<td>$value </td>\n");
3108:
3109: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3110: }
3111: }
3112: foreach my $entry (@{$order}) {
1.367 golterma 3113: if ($canshow->{$entry} && ($newsetting->{$entry} ne $newsetting->{$entry})) {
3114: $r->print(&Apache::loncommon::start_data_table_row());
1.334 raeburn 3115: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom')) {
3116: foreach my $item (@{$requestcourses}) {
1.367 golterma 3117: $r->print("<td>$lt{$item}</td>\n");
3118: $r->print("<td>$oldsetting->{$item} $oldsettingtext->{$item}</td>\n");
1.334 raeburn 3119: my $value = $newsetting->{$item}.' '.$newsettingtext->{$item};
3120: if ($changedhash->{$item}) {
3121: $value = '<span class="LC_cusr_emph">'.$value.'</span>';
3122: }
3123: $r->print("<td>$value </td>\n");
3124: }
3125: } elsif ($entry eq 'tools') {
3126: foreach my $item (@{$usertools}) {
1.367 golterma 3127: $r->print("<td>$lt{$item}</td>\n");
3128: $r->print("<td>$oldsetting->{$item} $oldsettingtext->{$item}</td>\n");
1.334 raeburn 3129: my $value = $newsetting->{$item}.' '.$newsettingtext->{$item};
3130: if ($changedhash->{$item}) {
3131: $value = '<span class="LC_cusr_emph">'.$value.'</span>';
3132: }
3133: $r->print("<td>$value </td>\n");
3134: }
3135: } else {
1.367 golterma 3136: $r->print("<td>$lt{$entry}</td>\n");
3137: $r->print("<td>$oldsetting->{$entry} $oldsettingtext->{$entry} </td>\n");
1.334 raeburn 3138: my $value = $newsetting->{$entry}.' '.$newsettingtext->{$entry};
3139: if ($changedhash->{$entry}) {
3140: $value = '<span class="LC_cusr_emph">'.$value.'</span>';
3141: }
3142: $r->print("<td>$value </td>\n");
3143: }
1.367 golterma 3144: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3145: }
3146: }
1.367 golterma 3147: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.334 raeburn 3148: }
3149: return;
3150: }
3151:
1.275 raeburn 3152: sub tool_changes {
3153: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3154: $changed,$newaccess,$newaccesstext) = @_;
3155: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3156: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3157: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3158: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3159: return;
3160: }
1.300 raeburn 3161: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3162: my @options = ('approval','validate','autolimit');
1.306 raeburn 3163: my $optregex = join('|',@options);
3164: my %reqdisplay = &courserequest_display();
1.300 raeburn 3165: my $cdom = $env{'request.role.domain'};
3166: foreach my $tool (@{$usertools}) {
1.314 raeburn 3167: $oldaccesstext->{$tool} = &mt('No');
3168: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3169: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.314 raeburn 3170: my $newop;
3171: if ($env{'form.'.$context.'_'.$tool}) {
3172: $newop = $env{'form.'.$context.'_'.$tool};
3173: if ($newop eq 'autolimit') {
3174: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3175: $limit =~ s/\D+//g;
3176: $newop .= '='.$limit;
3177: }
3178: }
1.300 raeburn 3179: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3180: if ($newop) {
3181: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3182: $changeHash,$context);
3183: if ($changed->{$tool}) {
1.314 raeburn 3184: $newaccesstext->{$tool} = &mt('Yes');
1.300 raeburn 3185: } else {
3186: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3187: }
3188: }
3189: } else {
3190: my @curr = split(',',$userenv->{$context.'.'.$tool});
3191: my @new;
3192: my $changedoms;
1.314 raeburn 3193: foreach my $req (@curr) {
3194: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3195: $oldaccesstext->{$tool} = &mt('Yes');
3196: my $oldop = $1;
3197: if ($oldop ne $newop) {
3198: $changedoms = 1;
3199: foreach my $item (@curr) {
3200: my ($reqdom,$option) = split(':',$item);
3201: unless ($reqdom eq $cdom) {
3202: push(@new,$item);
3203: }
3204: }
3205: if ($newop) {
3206: push(@new,$cdom.':'.$newop);
1.300 raeburn 3207: }
1.314 raeburn 3208: @new = sort(@new);
1.300 raeburn 3209: }
1.314 raeburn 3210: last;
1.300 raeburn 3211: }
1.314 raeburn 3212: }
3213: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3214: $changedoms = 1;
1.306 raeburn 3215: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3216: }
3217: if ($changedoms) {
1.314 raeburn 3218: my $newdomstr;
1.300 raeburn 3219: if (@new) {
3220: $newdomstr = join(',',@new);
3221: }
3222: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3223: $context);
3224: if ($changed->{$tool}) {
3225: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3226: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3227: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3228: $limit =~ s/\D+//g;
3229: if ($limit) {
3230: $newaccesstext->{$tool} = &mt('Yes, up to limit of [quant,_1,request] per user.',$limit);
3231: } else {
1.306 raeburn 3232: $newaccesstext->{$tool} = &mt('Yes, processed automatically');
3233: }
1.314 raeburn 3234: } else {
1.306 raeburn 3235: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3236: }
1.300 raeburn 3237: } else {
1.306 raeburn 3238: $newaccesstext->{$tool} = &mt('No');
1.300 raeburn 3239: }
3240: }
3241: }
3242: }
3243: }
3244: return;
3245: }
1.275 raeburn 3246: foreach my $tool (@{$usertools}) {
1.362 raeburn 3247: my ($newval,$envkey);
3248: $envkey = $context.'.'.$tool;
1.306 raeburn 3249: if ($context eq 'requestcourses') {
3250: $newval = $env{'form.crsreq_'.$tool};
3251: if ($newval eq 'autolimit') {
3252: $newval .= '='.$env{'form.crsreq_'.$tool.'_limit'};
3253: }
1.362 raeburn 3254: } elsif ($context eq 'requestauthor') {
3255: $newval = $env{'form.'.$context};
3256: $envkey = $context;
1.314 raeburn 3257: } else {
1.306 raeburn 3258: $newval = $env{'form.'.$context.'_'.$tool};
3259: }
1.362 raeburn 3260: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3261: $oldaccess->{$tool} = &mt('custom');
1.362 raeburn 3262: if ($userenv->{$envkey}) {
1.275 raeburn 3263: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3264: } else {
3265: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3266: }
1.362 raeburn 3267: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3268: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3269: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3270: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3271: $context);
1.275 raeburn 3272: if ($changed->{$tool}) {
3273: $newaccess->{$tool} = &mt('custom');
1.306 raeburn 3274: if ($newval) {
1.275 raeburn 3275: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3276: } else {
3277: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3278: }
3279: } else {
3280: $newaccess->{$tool} = $oldaccess->{$tool};
3281: if ($userenv->{$context.'.'.$tool}) {
3282: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3283: } else {
3284: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3285: }
3286: }
3287: } else {
3288: $newaccess->{$tool} = $oldaccess->{$tool};
3289: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3290: }
3291: } else {
3292: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3293: if ($changed->{$tool}) {
3294: $newaccess->{$tool} = &mt('default');
3295: } else {
3296: $newaccess->{$tool} = $oldaccess->{$tool};
3297: if ($userenv->{$context.'.'.$tool}) {
1.300 raeburn 3298: $newaccesstext->{$tool} = &mt("availability set to 'on'");
1.275 raeburn 3299: } else {
1.300 raeburn 3300: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.275 raeburn 3301: }
3302: }
3303: }
3304: } else {
3305: $oldaccess->{$tool} = &mt('default');
3306: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3307: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3308: $context);
1.275 raeburn 3309: if ($changed->{$tool}) {
3310: $newaccess->{$tool} = &mt('custom');
1.306 raeburn 3311: if ($newval) {
1.275 raeburn 3312: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3313: } else {
3314: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3315: }
3316: } else {
3317: $newaccess->{$tool} = $oldaccess->{$tool};
3318: }
3319: } else {
3320: $newaccess->{$tool} = $oldaccess->{$tool};
3321: }
3322: }
3323: }
3324: return;
3325: }
3326:
1.220 raeburn 3327: sub update_roles {
1.239 raeburn 3328: my ($r,$context) = @_;
1.4 www 3329: my $now=time;
1.225 raeburn 3330: my @rolechanges;
1.220 raeburn 3331: my %disallowed;
1.73 sakharuk 3332: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 3333: foreach my $key (keys (%env)) {
3334: next if (! $env{$key});
1.190 raeburn 3335: next if ($key eq 'form.action');
1.27 matthew 3336: # Revoke roles
1.135 raeburn 3337: if ($key=~/^form\.rev/) {
3338: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3339: # Revoke standard role
1.170 albertel 3340: my ($scope,$role) = ($1,$2);
3341: my $result =
3342: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3343: $env{'form.ccuname'},
1.239 raeburn 3344: $scope,$role,'','',$context);
1.367 golterma 3345: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3346: &mt('Revoking [_1] in [_2]',
3347: &Apache::lonnet::plaintext($role),
3348: '"'.&cid_to_cname($scope).'"'),
3349: $result ne "ok").'<br />');
3350: if ($result ne "ok") {
3351: $r->print(&mt('Error: [_1]',$result).'<br />');
3352: }
1.170 albertel 3353: if ($role eq 'st') {
1.202 raeburn 3354: my $result =
1.198 raeburn 3355: &Apache::lonuserutils::classlist_drop($scope,
3356: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3357: $now);
1.367 golterma 3358: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3359: }
1.225 raeburn 3360: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3361: push(@rolechanges,$role);
3362: }
1.196 raeburn 3363: }
1.195 raeburn 3364: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3365: # Revoke custom role
1.369 bisitz 3366: my $result = &Apache::lonnet::revokecustomrole(
3367: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3368: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3369: &mt('Revoking custom role [_1] by [_2] in [_3]',
3370: $4,$3.':'.$2,'"'.&cid_to_cname($1).'"'),
3371: $result ne 'ok').'<br />');
3372: if ($result ne "ok") {
3373: $r->print(&mt('Error: [_1]',$result).'<br />');
3374: }
1.225 raeburn 3375: if (!grep(/^cr$/,@rolechanges)) {
3376: push(@rolechanges,'cr');
3377: }
1.64 www 3378: }
1.135 raeburn 3379: } elsif ($key=~/^form\.del/) {
3380: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3381: # Delete standard role
1.170 albertel 3382: my ($scope,$role) = ($1,$2);
3383: my $result =
3384: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3385: $env{'form.ccuname'},
1.239 raeburn 3386: $scope,$role,$now,0,1,'',
3387: $context);
1.367 golterma 3388: $r->print(&Apache::lonhtmlcommon::confirm_success(
3389: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3390: &Apache::lonnet::plaintext($role),
3391: '"'.&cid_to_cname($scope).'"'),
3392: $result ne 'ok').'<br />');
3393: if ($result ne "ok") {
3394: $r->print(&mt('Error: [_1]',$result).'<br />');
3395: }
1.367 golterma 3396:
1.170 albertel 3397: if ($role eq 'st') {
1.202 raeburn 3398: my $result =
1.198 raeburn 3399: &Apache::lonuserutils::classlist_drop($scope,
3400: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3401: $now);
1.369 bisitz 3402: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3403: }
1.225 raeburn 3404: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3405: push(@rolechanges,$role);
3406: }
1.116 raeburn 3407: }
1.139 albertel 3408: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3409: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3410: # Delete custom role
1.369 bisitz 3411: my $result =
3412: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3413: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3414: 0,1,$context);
3415: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
3416: $rolename,$rnam.':'.$rdom,'"'.&cid_to_cname($1).'"'),
3417: $result ne "ok").'<br />');
3418: if ($result ne "ok") {
3419: $r->print(&mt('Error: [_1]',$result).'<br />');
3420: }
1.367 golterma 3421:
1.225 raeburn 3422: if (!grep(/^cr$/,@rolechanges)) {
3423: push(@rolechanges,'cr');
3424: }
1.116 raeburn 3425: }
1.135 raeburn 3426: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3427: my $udom = $env{'form.ccdomain'};
3428: my $uname = $env{'form.ccuname'};
1.116 raeburn 3429: # Re-enable standard role
1.135 raeburn 3430: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3431: my $url = $1;
3432: my $role = $2;
3433: my $logmsg;
3434: my $output;
3435: if ($role eq 'st') {
1.141 albertel 3436: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.129 albertel 3437: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.220 raeburn 3438: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3439: if ($result eq 'refused' && $logmsg) {
3440: $output = $logmsg;
3441: } else {
1.369 bisitz 3442: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3443: }
1.89 raeburn 3444: } else {
1.367 golterma 3445: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',&Apache::lonnet::plaintext($role),
3446: '"'.&cid_to_cname($url).'"',&Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3447: }
3448: }
3449: } else {
1.101 albertel 3450: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3451: $env{'form.ccuname'},$url,$role,0,$now,'','',
3452: $context);
1.367 golterma 3453: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.369 bisitz 3454: &Apache::lonnet::plaintext($role),'"'.&cid_to_cname($url).'"'),$result ne "ok").'<br />';
3455: if ($result ne "ok") {
3456: $output .= &mt('Error: [_1]',$result).'<br />';
3457: }
3458: }
1.89 raeburn 3459: $r->print($output);
1.225 raeburn 3460: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3461: push(@rolechanges,$role);
3462: }
1.113 raeburn 3463: }
1.116 raeburn 3464: # Re-enable custom role
1.139 albertel 3465: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3466: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3467: my $result = &Apache::lonnet::assigncustomrole(
3468: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3469: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3470: $r->print(&Apache::lonhtmlcommon::confirm_success(
3471: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
3472: $rolename,$rnam.':'.$rdom,'"'.&cid_to_cname($1).'"'),
3473: $result ne "ok").'<br />');
3474: if ($result ne "ok") {
3475: $r->print(&mt('Error: [_1]',$result).'<br />');
3476: }
1.225 raeburn 3477: if (!grep(/^cr$/,@rolechanges)) {
3478: push(@rolechanges,'cr');
3479: }
1.116 raeburn 3480: }
1.135 raeburn 3481: } elsif ($key=~/^form\.act/) {
1.101 albertel 3482: my $udom = $env{'form.ccdomain'};
3483: my $uname = $env{'form.ccuname'};
1.141 albertel 3484: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3485: # Activate a custom role
1.83 albertel 3486: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3487: my $url='/'.$one.'/'.$two;
3488: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3489:
1.101 albertel 3490: my $start = ( $env{'form.start_'.$full} ?
3491: $env{'form.start_'.$full} :
1.88 raeburn 3492: $now );
1.101 albertel 3493: my $end = ( $env{'form.end_'.$full} ?
3494: $env{'form.end_'.$full} :
1.88 raeburn 3495: 0 );
3496:
3497: # split multiple sections
3498: my %sections = ();
1.101 albertel 3499: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3500: if ($num_sections == 0) {
1.240 raeburn 3501: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3502: } else {
1.114 albertel 3503: my %curr_groups =
1.117 raeburn 3504: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 3505: foreach my $sec (sort {$a cmp $b} keys %sections) {
3506: if (($sec eq 'none') || ($sec eq 'all') ||
3507: exists($curr_groups{$sec})) {
3508: $disallowed{$sec} = $url;
3509: next;
3510: }
3511: my $securl = $url.'/'.$sec;
1.240 raeburn 3512: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3513: }
3514: }
1.225 raeburn 3515: if (!grep(/^cr$/,@rolechanges)) {
3516: push(@rolechanges,'cr');
3517: }
1.142 raeburn 3518: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 3519: # Activate roles for sections with 3 id numbers
3520: # set start, end times, and the url for the class
1.83 albertel 3521: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 3522: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
3523: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3524: $now );
1.101 albertel 3525: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
3526: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3527: 0 );
1.83 albertel 3528: my $url='/'.$one.'/'.$two;
1.88 raeburn 3529: my $type = 'three';
3530: # split multiple sections
3531: my %sections = ();
1.101 albertel 3532: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 3533: if ($num_sections == 0) {
1.240 raeburn 3534: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 3535: } else {
1.114 albertel 3536: my %curr_groups =
1.117 raeburn 3537: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 3538: my $emptysec = 0;
3539: foreach my $sec (sort {$a cmp $b} keys %sections) {
3540: $sec =~ s/\W//g;
1.113 raeburn 3541: if ($sec ne '') {
3542: if (($sec eq 'none') || ($sec eq 'all') ||
3543: exists($curr_groups{$sec})) {
3544: $disallowed{$sec} = $url;
3545: next;
3546: }
1.88 raeburn 3547: my $securl = $url.'/'.$sec;
1.240 raeburn 3548: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context));
1.88 raeburn 3549: } else {
3550: $emptysec = 1;
3551: }
3552: }
3553: if ($emptysec) {
1.240 raeburn 3554: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 3555: }
1.225 raeburn 3556: }
3557: if (!grep(/^\Q$three\E$/,@rolechanges)) {
3558: push(@rolechanges,$three);
3559: }
1.135 raeburn 3560: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 3561: # Activate roles for sections with two id numbers
3562: # set start, end times, and the url for the class
1.101 albertel 3563: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
3564: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 3565: $now );
1.101 albertel 3566: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
3567: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 3568: 0 );
1.225 raeburn 3569: my $one = $1;
3570: my $two = $2;
3571: my $url='/'.$one.'/';
1.88 raeburn 3572: # split multiple sections
3573: my %sections = ();
1.225 raeburn 3574: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 3575: if ($num_sections == 0) {
1.240 raeburn 3576: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3577: } else {
3578: my $emptysec = 0;
3579: foreach my $sec (sort {$a cmp $b} keys %sections) {
3580: if ($sec ne '') {
3581: my $securl = $url.'/'.$sec;
1.240 raeburn 3582: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 3583: } else {
3584: $emptysec = 1;
3585: }
3586: }
3587: if ($emptysec) {
1.240 raeburn 3588: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3589: }
3590: }
1.225 raeburn 3591: if (!grep(/^\Q$two\E$/,@rolechanges)) {
3592: push(@rolechanges,$two);
3593: }
1.64 www 3594: } else {
1.190 raeburn 3595: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 3596: }
1.113 raeburn 3597: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 3598: $r->print('<p class="LC_warning">');
1.113 raeburn 3599: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 3600: $r->print(&mt('[_1] may not be used as the name for a section, as it is a reserved word.','<tt>'.$key.'</tt>'));
1.113 raeburn 3601: } else {
1.274 bisitz 3602: $r->print(&mt('[_1] may not be used as the name for a section, as it is the name of a course group.','<tt>'.$key.'</tt>'));
1.113 raeburn 3603: }
1.274 bisitz 3604: $r->print('</p><p>'
3605: .&mt('Please [_1]go back[_2] and choose a different section name.'
3606: ,'<a href="javascript:history.go(-1)'
3607: ,'</a>')
3608: .'</p><br />'
3609: );
1.113 raeburn 3610: }
3611: }
1.101 albertel 3612: } # End of foreach (keys(%env))
1.75 www 3613: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 3614: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 3615: if (@rolechanges == 0) {
1.193 raeburn 3616: $r->print(&mt('No roles to modify'));
3617: }
1.225 raeburn 3618: return @rolechanges;
1.220 raeburn 3619: }
3620:
3621: sub enroll_single_student {
1.318 raeburn 3622: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype) = @_;
3623: $r->print('<h3>');
3624: if ($crstype eq 'Community') {
3625: $r->print(&mt('Enrolling Member'));
3626: } else {
3627: $r->print(&mt('Enrolling Student'));
3628: }
3629: $r->print('</h3>');
1.220 raeburn 3630:
3631: # Remove non alphanumeric values from section
3632: $env{'form.sections'}=~s/\W//g;
3633:
3634: # Clean out any old student roles the user has in this class.
3635: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
3636: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
3637: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
3638: my $enroll_result =
3639: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
3640: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
3641: $env{'form.cmiddlename'},$env{'form.clastname'},
3642: $env{'form.generation'},$env{'form.sections'},$enddate,
1.239 raeburn 3643: $startdate,'manual',undef,$env{'request.course.id'},'',$context);
1.220 raeburn 3644: if ($enroll_result =~ /^ok/) {
3645: $r->print(&mt('<b>[_1]</b> enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'}));
3646: if ($env{'form.sections'} ne '') {
3647: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
3648: }
3649: my ($showstart,$showend);
3650: if ($startdate <= $now) {
3651: $showstart = &mt('Access starts immediately');
3652: } else {
3653: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
3654: }
3655: if ($enddate == 0) {
3656: $showend = &mt('ends: no ending date');
3657: } else {
3658: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
3659: }
3660: $r->print('.<br />'.$showstart.'; '.$showend);
3661: if ($startdate <= $now && !$newuser) {
1.318 raeburn 3662: $r->print('<p> ');
3663: if ($crstype eq 'Community') {
3664: $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role will be available when the member next logs in.'));
3665: } else {
3666: $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role will be available when the student next logs in.'));
3667: }
3668: $r->print('</p>');
1.220 raeburn 3669: }
3670: } else {
3671: $r->print(&mt('unable to enroll').": ".$enroll_result);
3672: }
3673: return;
1.188 raeburn 3674: }
3675:
1.204 raeburn 3676: sub get_defaultquota_text {
3677: my ($settingstatus) = @_;
3678: my $defquotatext;
3679: if ($settingstatus eq '') {
3680: $defquotatext = &mt('(default)');
3681: } else {
3682: my ($usertypes,$order) =
3683: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
3684: if ($usertypes->{$settingstatus} eq '') {
3685: $defquotatext = &mt('(default)');
3686: } else {
3687: $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
3688: }
3689: }
3690: return $defquotatext;
3691: }
3692:
1.188 raeburn 3693: sub update_result_form {
3694: my ($uhome) = @_;
3695: my $outcome =
1.367 golterma 3696: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 3697: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 3698: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3699: }
1.207 raeburn 3700: if ($env{'form.origname'} ne '') {
3701: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
3702: }
1.160 raeburn 3703: foreach my $item ('sortby','seluname','seludom') {
3704: if (exists($env{'form.'.$item})) {
1.188 raeburn 3705: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3706: }
3707: }
1.188 raeburn 3708: if ($uhome eq 'no_host') {
3709: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
3710: }
3711: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
3712: '<input type ="hidden" name="currstate" value="" />'."\n".
1.220 raeburn 3713: '<input type ="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 3714: '</form>';
3715: return $outcome;
1.4 www 3716: }
3717:
1.149 raeburn 3718: sub quota_admin {
3719: my ($setquota,$changeHash) = @_;
3720: my $quotachanged;
3721: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
3722: # Current user has quota modification privileges
1.267 raeburn 3723: if (ref($changeHash) eq 'HASH') {
3724: $quotachanged = 1;
3725: $changeHash->{'portfolioquota'} = $setquota;
3726: }
1.149 raeburn 3727: }
3728: return $quotachanged;
3729: }
3730:
1.267 raeburn 3731: sub tool_admin {
1.275 raeburn 3732: my ($tool,$settool,$changeHash,$context) = @_;
3733: my $canchange = 0;
1.279 raeburn 3734: if ($context eq 'requestcourses') {
1.275 raeburn 3735: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
3736: $canchange = 1;
3737: }
1.300 raeburn 3738: } elsif ($context eq 'reqcrsotherdom') {
3739: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
3740: $canchange = 1;
3741: }
1.362 raeburn 3742: } elsif ($context eq 'requestauthor') {
3743: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
3744: $canchange = 1;
3745: }
1.275 raeburn 3746: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
3747: # Current user has quota modification privileges
3748: $canchange = 1;
3749: }
1.267 raeburn 3750: my $toolchanged;
1.275 raeburn 3751: if ($canchange) {
1.267 raeburn 3752: if (ref($changeHash) eq 'HASH') {
3753: $toolchanged = 1;
1.362 raeburn 3754: if ($tool eq 'requestauthor') {
3755: $changeHash->{$context} = $settool;
3756: } else {
3757: $changeHash->{$context.'.'.$tool} = $settool;
3758: }
1.267 raeburn 3759: }
3760: }
3761: return $toolchanged;
3762: }
3763:
1.88 raeburn 3764: sub build_roles {
1.89 raeburn 3765: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 3766: my $num_sections = 0;
3767: if ($sectionstr=~ /,/) {
3768: my @secnums = split/,/,$sectionstr;
1.89 raeburn 3769: if ($role eq 'st') {
3770: $secnums[0] =~ s/\W//g;
3771: $$sections{$secnums[0]} = 1;
3772: $num_sections = 1;
3773: } else {
3774: foreach my $sec (@secnums) {
3775: $sec =~ ~s/\W//g;
1.150 banghart 3776: if (!($sec eq "")) {
1.89 raeburn 3777: if (exists($$sections{$sec})) {
3778: $$sections{$sec} ++;
3779: } else {
3780: $$sections{$sec} = 1;
3781: $num_sections ++;
3782: }
1.88 raeburn 3783: }
3784: }
3785: }
3786: } else {
3787: $sectionstr=~s/\W//g;
3788: unless ($sectionstr eq '') {
3789: $$sections{$sectionstr} = 1;
3790: $num_sections ++;
3791: }
3792: }
1.129 albertel 3793:
1.88 raeburn 3794: return $num_sections;
3795: }
3796:
1.58 www 3797: # ========================================================== Custom Role Editor
3798:
3799: sub custom_role_editor {
1.351 raeburn 3800: my ($r,$brcrum) = @_;
1.324 raeburn 3801: my $action = $env{'form.customroleaction'};
3802: my $rolename;
3803: if ($action eq 'new') {
3804: $rolename=$env{'form.newrolename'};
3805: } else {
3806: $rolename=$env{'form.rolename'};
1.59 www 3807: }
3808:
1.324 raeburn 3809: my ($crstype,$context);
3810: if ($env{'request.course.id'}) {
3811: $crstype = &Apache::loncommon::course_type();
3812: $context = 'course';
3813: } else {
3814: $context = 'domain';
3815: $crstype = $env{'form.templatecrstype'};
3816: }
1.351 raeburn 3817:
3818: $rolename=~s/[^A-Za-z0-9]//gs;
3819: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
3820: &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
3821: return;
3822: }
3823:
1.153 banghart 3824: # ------------------------------------------------------- What can be assigned?
3825: my %full=();
3826: my %courselevel=();
3827: my %courselevelcurrent=();
1.61 www 3828: my $syspriv='';
3829: my $dompriv='';
3830: my $coursepriv='';
1.153 banghart 3831: my $body_top;
1.59 www 3832: my ($rdummy,$roledef)=
3833: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 3834: # ------------------------------------------------------- Does this role exist?
1.153 banghart 3835: $body_top .= '<h2>';
1.59 www 3836: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 3837: $body_top .= &mt('Existing Role').' "';
1.61 www 3838: # ------------------------------------------------- Get current role privileges
3839: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.324 raeburn 3840: if ($crstype eq 'Community') {
3841: $syspriv =~ s/bre\&S//;
3842: }
1.59 www 3843: } else {
1.153 banghart 3844: $body_top .= &mt('New Role').' "';
1.59 www 3845: $roledef='';
3846: }
1.153 banghart 3847: $body_top .= $rolename.'"</h2>';
1.135 raeburn 3848: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
3849: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3850: if (!$restrict) { $restrict='F'; }
1.60 www 3851: $courselevel{$priv}=$restrict;
1.61 www 3852: if ($coursepriv=~/\:$priv/) {
3853: $courselevelcurrent{$priv}=1;
3854: }
1.60 www 3855: $full{$priv}=1;
3856: }
3857: my %domainlevel=();
1.61 www 3858: my %domainlevelcurrent=();
1.135 raeburn 3859: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
3860: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3861: if (!$restrict) { $restrict='F'; }
1.60 www 3862: $domainlevel{$priv}=$restrict;
1.61 www 3863: if ($dompriv=~/\:$priv/) {
3864: $domainlevelcurrent{$priv}=1;
3865: }
1.60 www 3866: $full{$priv}=1;
3867: }
1.61 www 3868: my %systemlevel=();
3869: my %systemlevelcurrent=();
1.135 raeburn 3870: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
3871: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3872: if (!$restrict) { $restrict='F'; }
1.61 www 3873: $systemlevel{$priv}=$restrict;
3874: if ($syspriv=~/\:$priv/) {
3875: $systemlevelcurrent{$priv}=1;
3876: }
3877: $full{$priv}=1;
3878: }
1.160 raeburn 3879: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 3880: my $button_code = "\n";
1.153 banghart 3881: my $head_script = "\n";
1.301 bisitz 3882: $head_script .= '<script type="text/javascript">'."\n"
3883: .'// <![CDATA['."\n";
1.324 raeburn 3884: my @template_roles = ("in","ta","ep");
3885: if ($context eq 'domain') {
3886: push(@template_roles,"ad");
1.318 raeburn 3887: }
1.324 raeburn 3888: push(@template_roles,"st");
1.318 raeburn 3889: if ($crstype eq 'Community') {
3890: unshift(@template_roles,'co');
3891: } else {
3892: unshift(@template_roles,'cc');
3893: }
1.154 banghart 3894: foreach my $role (@template_roles) {
1.324 raeburn 3895: $head_script .= &make_script_template($role,$crstype);
1.318 raeburn 3896: $button_code .= &make_button_code($role,$crstype).' ';
1.154 banghart 3897: }
1.324 raeburn 3898: my $context_code;
3899: if ($context eq 'domain') {
3900: my $checkedCommunity = '';
3901: my $checkedCourse = ' checked="checked"';
3902: if ($env{'form.templatecrstype'} eq 'Community') {
3903: $checkedCommunity = $checkedCourse;
3904: $checkedCourse = '';
3905: }
3906: $context_code = '<label>'.
3907: '<input type="radio" name="templatecrstype" value="Course"'.$checkedCourse.' onclick="this.form.submit();">'.
3908: &mt('Course').
3909: '</label>'.(' ' x2).
3910: '<label>'.
3911: '<input type="radio" name="templatecrstype" value="Community"'.$checkedCommunity.' onclick="this.form.submit();">'.
3912: &mt('Community').
3913: '</label>'.
3914: '</fieldset>'.
3915: '<input type="hidden" name="customroleaction" value="'.
3916: $action.'" />';
3917: if ($env{'form.customroleaction'} eq 'new') {
3918: $context_code .= '<input type="hidden" name="newrolename" value="'.
3919: $rolename.'" />';
3920: } else {
3921: $context_code .= '<input type="hidden" name="rolename" value="'.
3922: $rolename.'" />';
3923: }
3924: $context_code .= '<input type="hidden" name="action" value="custom" />'.
3925: '<input type="hidden" name="phase" value="selected_custom_edit" />';
3926: }
3927:
1.301 bisitz 3928: $head_script .= "\n".$jsback."\n"
3929: .'// ]]>'."\n"
3930: .'</script>'."\n";
1.351 raeburn 3931: push (@{$brcrum},
3932: {href => "javascript:backPage(document.form1,'pickrole','')",
3933: text => "Pick custom role",
3934: faq => 282,bug=>'Instructor Interface',},
3935: {href => "javascript:backPage(document.form1,'','')",
3936: text => "Edit custom role",
3937: faq => 282,
3938: bug => 'Instructor Interface',
3939: help => 'Course_Editing_Custom_Roles'}
3940: );
3941: my $args = { bread_crumbs => $brcrum,
3942: bread_crumbs_component => 'User Management'};
3943:
3944: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
3945: $head_script,$args).
3946: $body_top);
1.73 sakharuk 3947: my %lt=&Apache::lonlocal::texthash(
3948: 'prv' => "Privilege",
1.131 raeburn 3949: 'crl' => "Course Level",
1.73 sakharuk 3950: 'dml' => "Domain Level",
1.150 banghart 3951: 'ssl' => "System Level");
1.264 bisitz 3952:
1.324 raeburn 3953: $r->print('<div class="LC_left_float">'
1.264 bisitz 3954: .'<form action=""><fieldset>'
3955: .'<legend>'.&mt('Select a Template').'</legend>'
3956: .$button_code
1.324 raeburn 3957: .'</fieldset></form></div>');
3958: if ($context_code) {
3959: $r->print('<div class="LC_left_float">'
3960: .'<form action="/adm/createuser" method="post"><fieldset>'
3961: .'<legend>'.&mt('Context').'</legend>'
3962: .$context_code
3963: .'</form>'
3964: .'</div>'
3965: );
3966: }
3967: $r->print('<br clear="all" />');
1.264 bisitz 3968:
1.61 www 3969: $r->print(<<ENDCCF);
1.160 raeburn 3970: <form name="form1" method="post">
1.61 www 3971: <input type="hidden" name="phase" value="set_custom_roles" />
3972: <input type="hidden" name="rolename" value="$rolename" />
3973: ENDCCF
1.135 raeburn 3974: $r->print(&Apache::loncommon::start_data_table().
3975: &Apache::loncommon::start_data_table_header_row().
3976: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
3977: '</th><th>'.$lt{'ssl'}.'</th>'.
3978: &Apache::loncommon::end_data_table_header_row());
1.324 raeburn 3979: foreach my $priv (sort(keys(%full))) {
1.318 raeburn 3980: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
1.135 raeburn 3981: $r->print(&Apache::loncommon::start_data_table_row().
3982: '<td>'.$privtext.'</td><td>'.
1.288 bisitz 3983: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c"'.
3984: ($courselevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.61 www 3985: '</td><td>'.
1.288 bisitz 3986: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.
3987: ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.324 raeburn 3988: '</td><td>');
3989: if ($priv eq 'bre' && $crstype eq 'Community') {
3990: $r->print(' ');
3991: } else {
3992: $r->print($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
3993: ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':' ');
3994: }
3995: $r->print('</td>'.
3996: &Apache::loncommon::end_data_table_row());
1.60 www 3997: }
1.135 raeburn 3998: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 3999: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4000: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 4001: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4002: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4003: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4004: }
1.153 banghart 4005: # --------------------------------------------------------
4006: sub make_script_template {
1.324 raeburn 4007: my ($role,$crstype) = @_;
1.153 banghart 4008: my %full_c=();
4009: my %full_d=();
4010: my %full_s=();
4011: my $return_script;
4012: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4013: my ($priv,$restrict)=split(/\&/,$item);
4014: $full_c{$priv}=1;
4015: }
4016: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4017: my ($priv,$restrict)=split(/\&/,$item);
4018: $full_d{$priv}=1;
4019: }
1.154 banghart 4020: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.324 raeburn 4021: next if (($crstype eq 'Community') && ($item eq 'bre&S'));
1.153 banghart 4022: my ($priv,$restrict)=split(/\&/,$item);
4023: $full_s{$priv}=1;
4024: }
4025: $return_script .= 'function set_'.$role.'() {'."\n";
4026: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
4027: my %role_c;
1.155 banghart 4028: foreach my $priv (@temp) {
1.153 banghart 4029: my ($priv_item, $dummy) = split(/\&/,$priv);
4030: $role_c{$priv_item} = 1;
4031: }
1.269 raeburn 4032: my %role_d;
4033: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
4034: foreach my $priv(@temp) {
4035: my ($priv_item, $dummy) = split(/\&/,$priv);
4036: $role_d{$priv_item} = 1;
4037: }
4038: my %role_s;
4039: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
4040: foreach my $priv(@temp) {
4041: my ($priv_item, $dummy) = split(/\&/,$priv);
4042: $role_s{$priv_item} = 1;
4043: }
1.153 banghart 4044: foreach my $priv_item (keys(%full_c)) {
4045: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4046: if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
4047: (exists($role_s{$priv}))) {
1.153 banghart 4048: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
4049: } else {
4050: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
4051: }
4052: }
1.154 banghart 4053: foreach my $priv_item (keys(%full_d)) {
4054: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4055: if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
1.154 banghart 4056: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
4057: } else {
4058: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
4059: }
4060: }
4061: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 4062: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 4063: if (exists($role_s{$priv})) {
4064: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
4065: } else {
4066: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
4067: }
1.153 banghart 4068: }
4069: $return_script .= '}'."\n";
1.154 banghart 4070: return ($return_script);
4071: }
4072: # ----------------------------------------------------------
4073: sub make_button_code {
1.318 raeburn 4074: my ($role,$crstype) = @_;
4075: my $label = &Apache::lonnet::plaintext($role,$crstype);
1.301 bisitz 4076: my $button_code = '<input type="button" onclick="set_'.$role.'()" value="'.$label.'" />';
1.154 banghart 4077: return ($button_code);
1.153 banghart 4078: }
1.61 www 4079: # ---------------------------------------------------------- Call to definerole
4080: sub set_custom_role {
1.351 raeburn 4081: my ($r,$context,$brcrum) = @_;
1.101 albertel 4082: my $rolename=$env{'form.rolename'};
1.63 www 4083: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4084: if (!$rolename) {
1.351 raeburn 4085: &custom_role_editor($r,$brcrum);
1.61 www 4086: return;
4087: }
1.160 raeburn 4088: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4089: my $jscript = '<script type="text/javascript">'
4090: .'// <![CDATA['."\n"
4091: .$jsback."\n"
4092: .'// ]]>'."\n"
4093: .'</script>'."\n";
1.352 raeburn 4094: push(@{$brcrum},
4095: {href => "javascript:backPage(document.customresult,'pickrole','')",
4096: text => "Pick custom role",
4097: faq => 282,
4098: bug => 'Instructor Interface',},
4099: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4100: text => "Edit custom role",
4101: faq => 282,
4102: bug => 'Instructor Interface',},
4103: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4104: text => "Result",
4105: faq => 282,
4106: bug => 'Instructor Interface',
4107: help => 'Course_Editing_Custom_Roles'},
4108: );
4109: my $args = { bread_crumbs => $brcrum,
1.351 raeburn 4110: bread_crumbs_component => 'User Management'};
4111: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4112:
1.61 www 4113: my ($rdummy,$roledef)=
1.110 albertel 4114: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4115:
1.61 www 4116: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4117: $r->print('<h3>');
1.61 www 4118: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4119: $r->print(&mt('Existing Role').' "');
1.61 www 4120: } else {
1.73 sakharuk 4121: $r->print(&mt('New Role').' "');
1.61 www 4122: $roledef='';
4123: }
1.188 raeburn 4124: $r->print($rolename.'"</h3>');
1.61 www 4125: # ------------------------------------------------------- What can be assigned?
4126: my $sysrole='';
4127: my $domrole='';
4128: my $courole='';
4129:
1.135 raeburn 4130: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4131: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4132: if (!$restrict) { $restrict=''; }
4133: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 4134: $courole.=':'.$item;
1.61 www 4135: }
4136: }
4137:
1.135 raeburn 4138: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4139: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4140: if (!$restrict) { $restrict=''; }
4141: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 4142: $domrole.=':'.$item;
1.61 www 4143: }
4144: }
4145:
1.135 raeburn 4146: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4147: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4148: if (!$restrict) { $restrict=''; }
4149: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 4150: $sysrole.=':'.$item;
1.61 www 4151: }
4152: }
1.63 www 4153: $r->print('<br />Defining Role: '.
1.61 www 4154: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 4155: if ($env{'request.course.id'}) {
4156: my $url='/'.$env{'request.course.id'};
1.63 www 4157: $url=~s/\_/\//g;
1.73 sakharuk 4158: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 4159: &Apache::lonnet::assigncustomrole($env{'user.domain'},
4160: $env{'user.name'},
1.63 www 4161: $url,
1.101 albertel 4162: $env{'user.domain'},
4163: $env{'user.name'},
1.240 raeburn 4164: $rolename,undef,undef,undef,$context));
1.63 www 4165: }
1.190 raeburn 4166: $r->print('<p><a href="javascript:backPage(document.customresult,'."'pickrole'".')">'.&mt('Create or edit another custom role').'</a></p><form name="customresult" method="post">');
1.160 raeburn 4167: $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
1.58 www 4168: }
4169:
1.2 www 4170: # ================================================================ Main Handler
4171: sub handler {
4172: my $r = shift;
4173: if ($r->header_only) {
1.68 www 4174: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4175: $r->send_http_header;
4176: return OK;
4177: }
1.318 raeburn 4178: my ($context,$crstype);
1.190 raeburn 4179: if ($env{'request.course.id'}) {
4180: $context = 'course';
1.318 raeburn 4181: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4182: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4183: $context = 'author';
1.190 raeburn 4184: } else {
4185: $context = 'domain';
4186: }
4187: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4188: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
4189: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
1.190 raeburn 4190: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4191: my $args;
4192: my $brcrum = [];
4193: my $bread_crumbs_component = 'User Management';
1.202 raeburn 4194: if ($env{'form.action'} ne 'dateselect') {
1.351 raeburn 4195: $brcrum = [{href=>"/adm/createuser",
4196: text=>"User Management",
4197: help=>'Course_Create_Class_List,Course_Change_Privileges,Course_View_Class_List,Course_Editing_Custom_Roles,Course_Add_Student,Course_Drop_Student,Course_Automated_Enrollment,Course_Self_Enrollment,Course_Manage_Group'}
4198: ];
1.202 raeburn 4199: }
1.289 droeschl 4200: #SD Following files not added to help, because the corresponding .tex-files seem to
4201: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 4202: my ($permission,$allowed) =
1.318 raeburn 4203: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 4204: if (!$allowed) {
1.358 raeburn 4205: if ($context eq 'course') {
4206: $r->internal_redirect('/adm/viewclasslist');
4207: return OK;
4208: }
1.190 raeburn 4209: $env{'user.error.msg'}=
4210: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4211: "or view user status.";
4212: return HTTP_NOT_ACCEPTABLE;
4213: }
4214:
4215: &Apache::loncommon::content_type($r,'text/html');
4216: $r->send_http_header;
4217:
4218: # Main switch on form.action and form.state, as appropriate
4219: if (! exists($env{'form.action'})) {
1.351 raeburn 4220: $args = {bread_crumbs => $brcrum,
4221: bread_crumbs_component => $bread_crumbs_component};
4222: $r->print(&header(undef,$args));
1.318 raeburn 4223: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4224: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.351 raeburn 4225: push(@{$brcrum},
4226: { href => '/adm/createuser?action=upload&state=',
4227: text => 'Upload Users List',
4228: help => 'Course_Create_Class_List',
4229: });
4230: $bread_crumbs_component = 'Upload Users List';
4231: $args = {bread_crumbs => $brcrum,
4232: bread_crumbs_component => $bread_crumbs_component};
4233: $r->print(&header(undef,$args));
1.190 raeburn 4234: $r->print('<form name="studentform" method="post" '.
4235: 'enctype="multipart/form-data" '.
4236: ' action="/adm/createuser">'."\n");
4237: if (! exists($env{'form.state'})) {
4238: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4239: } elsif ($env{'form.state'} eq 'got_file') {
1.221 raeburn 4240: &Apache::lonuserutils::print_upload_manager_form($r,$context,
1.318 raeburn 4241: $permission,$crstype);
1.190 raeburn 4242: } elsif ($env{'form.state'} eq 'enrolling') {
4243: if ($env{'form.datatoken'}) {
1.221 raeburn 4244: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission);
1.190 raeburn 4245: }
4246: } else {
4247: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4248: }
1.213 raeburn 4249: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4250: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 4251: my $phase = $env{'form.phase'};
4252: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4253: &Apache::loncreateuser::restore_prev_selections();
4254: my $srch;
4255: foreach my $item (@search) {
4256: $srch->{$item} = $env{'form.'.$item};
4257: }
1.207 raeburn 4258: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
4259: ($phase eq 'createnewuser')) {
4260: if ($env{'form.phase'} eq 'createnewuser') {
4261: my $response;
4262: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4263: my $response =
4264: '<span class="LC_warning">'
4265: .&mt('You must specify a valid username. Only the following are allowed:'
4266: .' letters numbers - . @')
4267: .'</span>';
1.221 raeburn 4268: $env{'form.phase'} = '';
1.351 raeburn 4269: &print_username_entry_form($r,$context,$response,$srch,undef,$crstype,$brcrum);
1.207 raeburn 4270: } else {
4271: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4272: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4273: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4274: $srch,$response,$context,
1.351 raeburn 4275: $permission,$crstype,$brcrum);
1.207 raeburn 4276: }
4277: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4278: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4279: &user_search_result($context,$srch);
1.190 raeburn 4280: if ($env{'form.currstate'} eq 'modify') {
4281: $currstate = $env{'form.currstate'};
4282: }
4283: if ($currstate eq 'select') {
4284: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4285: \@search,$context,undef,$crstype,
4286: $brcrum);
1.190 raeburn 4287: } elsif ($currstate eq 'modify') {
4288: my ($ccuname,$ccdomain);
4289: if (($srch->{'srchby'} eq 'uname') &&
4290: ($srch->{'srchtype'} eq 'exact')) {
4291: $ccuname = $srch->{'srchterm'};
4292: $ccdomain= $srch->{'srchdomain'};
4293: } else {
4294: my @matchedunames = keys(%{$results});
4295: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4296: }
4297: $ccuname =&LONCAPA::clean_username($ccuname);
4298: $ccdomain=&LONCAPA::clean_domain($ccdomain);
4299: if ($env{'form.forcenewuser'}) {
4300: $response = '';
4301: }
4302: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4303: $srch,$response,$context,
1.351 raeburn 4304: $permission,$crstype,$brcrum);
1.190 raeburn 4305: } elsif ($currstate eq 'query') {
1.351 raeburn 4306: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4307: } else {
1.229 raeburn 4308: $env{'form.phase'} = '';
1.207 raeburn 4309: &print_username_entry_form($r,$context,$response,$srch,
1.351 raeburn 4310: $forcenewuser,$crstype,$brcrum);
1.190 raeburn 4311: }
4312: } elsif ($env{'form.phase'} eq 'userpicked') {
4313: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4314: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 4315: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.351 raeburn 4316: $context,$permission,$crstype,
4317: $brcrum);
1.190 raeburn 4318: }
4319: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.351 raeburn 4320: &update_user_data($r,$context,$crstype,$brcrum);
1.190 raeburn 4321: } else {
1.351 raeburn 4322: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4323: $brcrum);
1.190 raeburn 4324: }
4325: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
4326: if ($env{'form.phase'} eq 'set_custom_roles') {
1.351 raeburn 4327: &set_custom_role($r,$context,$brcrum);
1.190 raeburn 4328: } else {
1.351 raeburn 4329: &custom_role_editor($r,$brcrum);
1.190 raeburn 4330: }
1.362 raeburn 4331: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4332: ($permission->{'cusr'}) &&
4333: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4334: push(@{$brcrum},
4335: {href => '/adm/createuser?action=processauthorreq',
4336: text => 'Authoring space requests',
4337: help => 'Domain_Role_Approvals'});
4338: $bread_crumbs_component = 'Authoring requests';
4339: if ($env{'form.state'} eq 'done') {
4340: push(@{$brcrum},
4341: {href => '/adm/createuser?action=authorreqqueue',
4342: text => 'Result',
4343: help => 'Domain_Role_Approvals'});
4344: $bread_crumbs_component = 'Authoring request result';
4345: }
4346: $args = { bread_crumbs => $brcrum,
4347: bread_crumbs_component => $bread_crumbs_component};
4348: $r->print(&header(undef,$args));
4349: if (!exists($env{'form.state'})) {
4350: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4351: $env{'request.role.domain'}));
4352: } elsif ($env{'form.state'} eq 'done') {
4353: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4354: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4355: $env{'request.role.domain'}));
4356: }
1.207 raeburn 4357: } elsif (($env{'form.action'} eq 'listusers') &&
4358: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 4359: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 4360: push(@{$brcrum},
4361: {href => '/adm/createuser?action=listusers',
4362: text => "List Users"},
4363: {href => "/adm/createuser",
4364: text => "Result",
4365: help => 'Course_View_Class_List'});
4366: $bread_crumbs_component = 'Update Users';
4367: $args = {bread_crumbs => $brcrum,
4368: bread_crumbs_component => $bread_crumbs_component};
4369: $r->print(&header(undef,$args));
1.202 raeburn 4370: my $setting = $env{'form.roletype'};
4371: my $choice = $env{'form.bulkaction'};
4372: if ($permission->{'cusr'}) {
1.336 raeburn 4373: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 4374: } else {
4375: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 4376: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 4377: }
4378: } else {
1.351 raeburn 4379: push(@{$brcrum},
4380: {href => '/adm/createuser?action=listusers',
4381: text => "List Users",
4382: help => 'Course_View_Class_List'});
4383: $bread_crumbs_component = 'List Users';
4384: $args = {bread_crumbs => $brcrum,
4385: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 4386: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4387: my $formname = 'studentform';
1.364 raeburn 4388: my $hidecall = "hide_searching();";
1.321 raeburn 4389: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
4390: ($env{'form.roletype'} eq 'community'))) {
4391: if ($env{'form.roletype'} eq 'course') {
4392: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
4393: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
4394: $formname);
4395: } elsif ($env{'form.roletype'} eq 'community') {
4396: $cb_jscript =
4397: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
4398: my %elements = (
4399: coursepick => 'radio',
4400: coursetotal => 'text',
4401: courselist => 'text',
4402: );
4403: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
4404: }
1.364 raeburn 4405: $jscript .= &verify_user_display($context)."\n".
4406: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 4407: my $js = &add_script($jscript).$cb_jscript;
4408: my $loadcode =
4409: &Apache::lonuserutils::course_selector_loadcode($formname);
4410: if ($loadcode ne '') {
1.364 raeburn 4411: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
4412: } else {
4413: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 4414: }
1.351 raeburn 4415: $r->print(&header($js,$args));
1.191 raeburn 4416: } else {
1.364 raeburn 4417: $args->{add_entries} = {onload => $hidecall};
4418: $jscript = &verify_user_display($context).
4419: &Apache::loncommon::check_uncheck_jscript();
4420: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 4421: }
1.202 raeburn 4422: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
4423: $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
1.191 raeburn 4424: }
1.213 raeburn 4425: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 4426: my $brtext;
4427: if ($crstype eq 'Community') {
4428: $brtext = 'Drop Members';
4429: } else {
4430: $brtext = 'Drop Students';
4431: }
1.351 raeburn 4432: push(@{$brcrum},
4433: {href => '/adm/createuser?action=drop',
4434: text => $brtext,
4435: help => 'Course_Drop_Student'});
4436: if ($env{'form.state'} eq 'done') {
4437: push(@{$brcrum},
4438: {href=>'/adm/createuser?action=drop',
4439: text=>"Result"});
4440: }
4441: $bread_crumbs_component = $brtext;
4442: $args = {bread_crumbs => $brcrum,
4443: bread_crumbs_component => $bread_crumbs_component};
4444: $r->print(&header(undef,$args));
1.213 raeburn 4445: if (!exists($env{'form.state'})) {
1.318 raeburn 4446: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 4447: } elsif ($env{'form.state'} eq 'done') {
4448: &Apache::lonuserutils::update_user_list($r,$context,undef,
4449: $env{'form.action'});
4450: }
1.202 raeburn 4451: } elsif ($env{'form.action'} eq 'dateselect') {
4452: if ($permission->{'cusr'}) {
1.351 raeburn 4453: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.221 raeburn 4454: &Apache::lonuserutils::date_section_selector($context,
1.351 raeburn 4455: $permission,$crstype));
1.202 raeburn 4456: } else {
1.351 raeburn 4457: $r->print(&header(undef,{'no_nav_bar' => 1}).
4458: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 4459: }
1.237 raeburn 4460: } elsif ($env{'form.action'} eq 'selfenroll') {
1.351 raeburn 4461: push(@{$brcrum},
4462: {href => '/adm/createuser?action=selfenroll',
4463: text => "Configure Self-enrollment",
4464: help => 'Course_Self_Enrollment'});
1.237 raeburn 4465: if (!exists($env{'form.state'})) {
1.351 raeburn 4466: $args = { bread_crumbs => $brcrum,
4467: bread_crumbs_component => 'Configure Self-enrollment'};
4468: $r->print(&header(undef,$args));
1.241 raeburn 4469: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.237 raeburn 4470: &print_selfenroll_menu($r,$context,$permission);
4471: } elsif ($env{'form.state'} eq 'done') {
1.351 raeburn 4472: push (@{$brcrum},
4473: {href=>'/adm/createuser?action=selfenroll',
4474: text=>"Result"});
4475: $args = { bread_crumbs => $brcrum,
4476: bread_crumbs_component => 'Self-enrollment result'};
4477: $r->print(&header(undef,$args));
1.241 raeburn 4478: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
4479: &update_selfenroll_config($r,$context,$permission);
1.237 raeburn 4480: }
1.277 raeburn 4481: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.351 raeburn 4482: push(@{$brcrum},
4483: {href => '/adm/createuser?action=selfenrollqueue',
4484: text => 'Enrollment requests',
4485: help => 'Course_Self_Enrollment'});
4486: $bread_crumbs_component = 'Enrollment requests';
4487: if ($env{'form.state'} eq 'done') {
4488: push(@{$brcrum},
4489: {href => '/adm/createuser?action=selfenrollqueue',
4490: text => 'Result',
4491: help => 'Course_Self_Enrollment'});
4492: $bread_crumbs_component = 'Enrollment result';
4493: }
4494: $args = { bread_crumbs => $brcrum,
4495: bread_crumbs_component => $bread_crumbs_component};
4496: $r->print(&header(undef,$args));
1.277 raeburn 4497: my $cid = $env{'request.course.id'};
4498: my $cdom = $env{'course.'.$cid.'.domain'};
4499: my $cnum = $env{'course.'.$cid.'.num'};
1.307 raeburn 4500: my $coursedesc = $env{'course.'.$cid.'.description'};
1.277 raeburn 4501: if (!exists($env{'form.state'})) {
4502: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
1.307 raeburn 4503: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
4504: $cdom,$cnum));
1.277 raeburn 4505: } elsif ($env{'form.state'} eq 'done') {
4506: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
1.307 raeburn 4507: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
4508: $cdom,$cnum,$coursedesc));
1.277 raeburn 4509: }
1.239 raeburn 4510: } elsif ($env{'form.action'} eq 'changelogs') {
1.363 raeburn 4511: my $helpitem;
4512: if ($context eq 'course') {
4513: $helpitem = 'Course_User_Logs';
4514: }
1.351 raeburn 4515: push (@{$brcrum},
4516: {href => '/adm/createuser?action=changelogs',
4517: text => 'User Management Logs',
1.363 raeburn 4518: help => $helpitem});
1.351 raeburn 4519: $bread_crumbs_component = 'User Changes';
4520: $args = { bread_crumbs => $brcrum,
4521: bread_crumbs_component => $bread_crumbs_component};
4522: $r->print(&header(undef,$args));
4523: &print_userchangelogs_display($r,$context,$permission);
1.190 raeburn 4524: } else {
1.351 raeburn 4525: $bread_crumbs_component = 'User Management';
4526: $args = { bread_crumbs => $brcrum,
4527: bread_crumbs_component => $bread_crumbs_component};
4528: $r->print(&header(undef,$args));
1.318 raeburn 4529: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4530: }
1.351 raeburn 4531: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 4532: return OK;
4533: }
4534:
4535: sub header {
1.351 raeburn 4536: my ($jscript,$args) = @_;
1.190 raeburn 4537: my $start_page;
1.351 raeburn 4538: if (ref($args) eq 'HASH') {
4539: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 4540: } else {
1.351 raeburn 4541: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 4542: }
4543: return $start_page;
4544: }
1.2 www 4545:
1.191 raeburn 4546: sub add_script {
4547: my ($js) = @_;
1.301 bisitz 4548: return '<script type="text/javascript">'."\n"
4549: .'// <![CDATA['."\n"
4550: .$js."\n"
4551: .'// ]]>'."\n"
4552: .'</script>'."\n";
1.191 raeburn 4553: }
4554:
1.202 raeburn 4555: sub verify_user_display {
1.364 raeburn 4556: my ($context) = @_;
4557: my $photos;
4558: if (($context eq 'course') && $env{'request.course.id'}) {
4559: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
4560: }
1.202 raeburn 4561: my $output = <<"END";
4562:
1.364 raeburn 4563: function hide_searching() {
4564: if (document.getElementById('searching')) {
4565: document.getElementById('searching').style.display = 'none';
4566: }
4567: return;
4568: }
4569:
1.202 raeburn 4570: function display_update() {
4571: document.studentform.action.value = 'listusers';
4572: document.studentform.phase.value = 'display';
4573: document.studentform.submit();
4574: }
4575:
1.364 raeburn 4576: function updateCols(caller) {
4577: var context = '$context';
4578: var photos = '$photos';
4579: if (caller == 'Status') {
4580: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
4581: document.getElementById('showcolstatus').checked = true;
4582: document.getElementById('showcolstatus').disabled = '';
4583: document.getElementById('showcolstart').checked = true;
4584: document.getElementById('showcolend').checked = true;
4585: } else {
4586: document.getElementById('showcolstatus').checked = false;
4587: document.getElementById('showcolstatus').disabled = 'disabled';
4588: document.getElementById('showcolstart').checked = false;
4589: document.getElementById('showcolend').checked = false;
4590: }
4591: }
4592: if (caller == 'output') {
4593: if (photos == 1) {
4594: if (document.getElementById('showcolphoto')) {
4595: var photoitem = document.getElementById('showcolphoto');
4596: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
4597: photoitem.checked = true;
4598: photoitem.disabled = '';
4599: } else {
4600: photoitem.checked = false;
4601: photoitem.disabled = 'disabled';
4602: }
4603: }
4604: }
4605: }
4606: if (caller == 'showrole') {
4607: if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') {
4608: document.getElementById('showcolrole').checked = true;
4609: document.getElementById('showcolrole').disabled = '';
4610: } else {
4611: document.getElementById('showcolrole').checked = false;
4612: document.getElementById('showcolrole').disabled = 'disabled';
4613: }
4614: }
4615: return;
4616: }
4617:
1.202 raeburn 4618: END
4619: return $output;
4620:
4621: }
4622:
1.190 raeburn 4623: ###############################################################
4624: ###############################################################
4625: # Menu Phase One
4626: sub print_main_menu {
1.318 raeburn 4627: my ($permission,$context,$crstype) = @_;
4628: my $linkcontext = $context;
4629: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
4630: if (($context eq 'course') && ($crstype eq 'Community')) {
4631: $linkcontext = lc($crstype);
4632: $stuterm = 'Members';
4633: }
1.208 raeburn 4634: my %links = (
1.298 droeschl 4635: domain => {
4636: upload => 'Upload a File of Users',
4637: singleuser => 'Add/Modify a User',
4638: listusers => 'Manage Users',
4639: },
4640: author => {
4641: upload => 'Upload a File of Co-authors',
4642: singleuser => 'Add/Modify a Co-author',
4643: listusers => 'Manage Co-authors',
4644: },
4645: course => {
4646: upload => 'Upload a File of Course Users',
4647: singleuser => 'Add/Modify a Course User',
1.354 www 4648: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 4649: },
1.318 raeburn 4650: community => {
4651: upload => 'Upload a File of Community Users',
4652: singleuser => 'Add/Modify a Community User',
1.354 www 4653: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 4654: },
4655: );
4656: my %linktitles = (
4657: domain => {
4658: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
4659: listusers => 'Show and manage users in this domain.',
4660: },
4661: author => {
4662: singleuser => 'Add a user with a co- or assistant author role.',
4663: listusers => 'Show and manage co- or assistant authors.',
4664: },
4665: course => {
4666: singleuser => 'Add a user with a certain role to this course.',
4667: listusers => 'Show and manage users in this course.',
4668: },
4669: community => {
4670: singleuser => 'Add a user with a certain role to this community.',
4671: listusers => 'Show and manage users in this community.',
4672: },
1.298 droeschl 4673: );
4674: my @menu = ( {categorytitle => 'Single Users',
4675: items =>
4676: [
4677: {
1.318 raeburn 4678: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 4679: icon => 'edit-redo.png',
4680: #help => 'Course_Change_Privileges',
4681: url => '/adm/createuser?action=singleuser',
4682: permission => $permission->{'cusr'},
1.318 raeburn 4683: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 4684: },
4685: ]},
4686:
4687: {categorytitle => 'Multiple Users',
4688: items =>
4689: [
4690: {
1.318 raeburn 4691: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 4692: icon => 'uplusr.png',
1.298 droeschl 4693: #help => 'Course_Create_Class_List',
4694: url => '/adm/createuser?action=upload',
4695: permission => $permission->{'cusr'},
4696: linktitle => 'Upload a CSV or a text file containing users.',
4697: },
4698: {
1.318 raeburn 4699: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 4700: icon => 'mngcu.png',
1.298 droeschl 4701: #help => 'Course_View_Class_List',
4702: url => '/adm/createuser?action=listusers',
4703: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 4704: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 4705: },
4706:
4707: ]},
4708:
4709: {categorytitle => 'Administration',
4710: items => [ ]},
4711: );
4712:
1.265 mielkec 4713: if ($context eq 'domain'){
1.298 droeschl 4714:
4715: push(@{ $menu[2]->{items} }, #Category: Administration
4716: {
4717: linktext => 'Custom Roles',
4718: icon => 'emblem-photos.png',
4719: #help => 'Course_Editing_Custom_Roles',
4720: url => '/adm/createuser?action=custom',
4721: permission => $permission->{'custom'},
4722: linktitle => 'Configure a custom role.',
4723: },
1.362 raeburn 4724: {
4725: linktext => 'Authoring Space Requests',
4726: icon => 'selfenrl-queue.png',
4727: #help => 'Domain_Role_Approvals',
4728: url => '/adm/createuser?action=processauthorreq',
4729: permission => $permission->{'cusr'},
4730: linktitle => 'Approve or reject author role requests',
4731: },
1.363 raeburn 4732: {
4733: linktext => 'Change Log',
4734: icon => 'document-properties.png',
4735: #help => 'Course_User_Logs',
4736: url => '/adm/createuser?action=changelogs',
4737: permission => $permission->{'cusr'},
4738: linktitle => 'View change log.',
4739: },
1.298 droeschl 4740: );
4741:
1.265 mielkec 4742: }elsif ($context eq 'course'){
1.298 droeschl 4743: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 4744:
4745: my %linktext = (
4746: 'Course' => {
4747: single => 'Add/Modify a Student',
4748: drop => 'Drop Students',
4749: groups => 'Course Groups',
4750: },
4751: 'Community' => {
4752: single => 'Add/Modify a Member',
4753: drop => 'Drop Members',
4754: groups => 'Community Groups',
4755: },
4756: );
4757:
4758: my %linktitle = (
4759: 'Course' => {
4760: single => 'Add a user with the role of student to this course',
4761: drop => 'Remove a student from this course.',
4762: groups => 'Manage course groups',
4763: },
4764: 'Community' => {
4765: single => 'Add a user with the role of member to this community',
4766: drop => 'Remove a member from this community.',
4767: groups => 'Manage community groups',
4768: },
4769: );
4770:
1.298 droeschl 4771: push(@{ $menu[0]->{items} }, #Category: Single Users
4772: {
1.318 raeburn 4773: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 4774: #help => 'Course_Add_Student',
4775: icon => 'list-add.png',
4776: url => '/adm/createuser?action=singlestudent',
4777: permission => $permission->{'cusr'},
1.318 raeburn 4778: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 4779: },
4780: );
4781:
4782: push(@{ $menu[1]->{items} }, #Category: Multiple Users
4783: {
1.318 raeburn 4784: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 4785: icon => 'edit-undo.png',
4786: #help => 'Course_Drop_Student',
4787: url => '/adm/createuser?action=drop',
4788: permission => $permission->{'cusr'},
1.318 raeburn 4789: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 4790: },
4791: );
4792: push(@{ $menu[2]->{items} }, #Category: Administration
4793: {
4794: linktext => 'Custom Roles',
4795: icon => 'emblem-photos.png',
4796: #help => 'Course_Editing_Custom_Roles',
4797: url => '/adm/createuser?action=custom',
4798: permission => $permission->{'custom'},
4799: linktitle => 'Configure a custom role.',
4800: },
4801: {
1.318 raeburn 4802: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 4803: icon => 'grps.png',
1.298 droeschl 4804: #help => 'Course_Manage_Group',
4805: url => '/adm/coursegroups?refpage=cusr',
4806: permission => $permission->{'grp_manage'},
1.318 raeburn 4807: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 4808: },
4809: {
1.328 wenzelju 4810: linktext => 'Change Log',
1.298 droeschl 4811: icon => 'document-properties.png',
4812: #help => 'Course_User_Logs',
4813: url => '/adm/createuser?action=changelogs',
4814: permission => $permission->{'cusr'},
4815: linktitle => 'View change log.',
4816: },
4817: );
1.277 raeburn 4818: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 4819: push(@{ $menu[2]->{items} },
4820: {
4821: linktext => 'Enrollment Requests',
4822: icon => 'selfenrl-queue.png',
4823: #help => 'Course_Approve_Selfenroll',
4824: url => '/adm/createuser?action=selfenrollqueue',
4825: permission => $permission->{'cusr'},
4826: linktitle =>'Approve or reject enrollment requests.',
4827: },
4828: );
1.277 raeburn 4829: }
1.298 droeschl 4830:
1.265 mielkec 4831: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 4832: if ($crstype ne 'Community') {
4833: push(@{ $menu[2]->{items} },
4834: {
4835: linktext => 'Automated Enrollment',
4836: icon => 'roles.png',
4837: #help => 'Course_Automated_Enrollment',
4838: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
4839: && $permission->{'cusr'}),
4840: url => '/adm/populate',
4841: linktitle => 'Automated enrollment manager.',
4842: }
4843: );
4844: }
4845: push(@{ $menu[2]->{items} },
1.298 droeschl 4846: {
4847: linktext => 'User Self-Enrollment',
1.342 wenzelju 4848: icon => 'self_enroll.png',
1.298 droeschl 4849: #help => 'Course_Self_Enrollment',
4850: url => '/adm/createuser?action=selfenroll',
4851: permission => $permission->{'cusr'},
1.317 bisitz 4852: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 4853: },
4854: );
4855: }
1.363 raeburn 4856: } elsif ($context eq 'author') {
1.370 ! raeburn 4857: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 4858: {
4859: linktext => 'Change Log',
4860: icon => 'document-properties.png',
4861: #help => 'Course_User_Logs',
4862: url => '/adm/createuser?action=changelogs',
4863: permission => $permission->{'cusr'},
4864: linktitle => 'View change log.',
4865: },
1.370 ! raeburn 4866: );
1.363 raeburn 4867: }
4868: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 4869: # { text => 'View Log-in History',
4870: # help => 'Course_User_Logins',
4871: # action => 'logins',
4872: # permission => $permission->{'cusr'},
4873: # });
1.190 raeburn 4874: }
4875:
1.189 albertel 4876: sub restore_prev_selections {
4877: my %saveable_parameters = ('srchby' => 'scalar',
4878: 'srchin' => 'scalar',
4879: 'srchtype' => 'scalar',
4880: );
4881: &Apache::loncommon::store_settings('user','user_picker',
4882: \%saveable_parameters);
4883: &Apache::loncommon::restore_settings('user','user_picker',
4884: \%saveable_parameters);
4885: }
4886:
1.237 raeburn 4887: sub print_selfenroll_menu {
4888: my ($r,$context,$permission) = @_;
1.322 raeburn 4889: my $crstype = &Apache::loncommon::course_type();
1.237 raeburn 4890: my $formname = 'enrollstudent';
4891: my $nolink = 1;
4892: my ($row,$lt) = &get_selfenroll_titles();
4893: my $groupslist = &Apache::lonuserutils::get_groupslist();
4894: my $setsec_js =
4895: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 4896: my %alerts = &Apache::lonlocal::texthash(
4897: acto => 'Activation of self-enrollment was selected for the following domain(s)',
4898: butn => 'but no user types have been checked.',
4899: wilf => "Please uncheck 'activate' or check at least one type.",
4900: );
4901: my $selfenroll_js = <<"ENDSCRIPT";
4902: function update_types(caller,num) {
4903: var delidx = getIndexByName('selfenroll_delete');
4904: var actidx = getIndexByName('selfenroll_activate');
4905: if (caller == 'selfenroll_all') {
4906: var selall;
4907: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4908: if (document.$formname.selfenroll_all[i].checked) {
4909: selall = document.$formname.selfenroll_all[i].value;
4910: }
4911: }
4912: if (selall == 1) {
4913: if (delidx != -1) {
4914: if (document.$formname.selfenroll_delete.length) {
4915: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
4916: document.$formname.selfenroll_delete[j].checked = true;
4917: }
4918: } else {
4919: document.$formname.elements[delidx].checked = true;
4920: }
4921: }
4922: if (actidx != -1) {
4923: if (document.$formname.selfenroll_activate.length) {
4924: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4925: document.$formname.selfenroll_activate[j].checked = false;
4926: }
4927: } else {
4928: document.$formname.elements[actidx].checked = false;
4929: }
4930: }
4931: document.$formname.selfenroll_newdom.selectedIndex = 0;
4932: }
4933: }
4934: if (caller == 'selfenroll_activate') {
4935: if (document.$formname.selfenroll_activate.length) {
4936: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4937: if (document.$formname.selfenroll_activate[j].value == num) {
4938: if (document.$formname.selfenroll_activate[j].checked) {
4939: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4940: if (document.$formname.selfenroll_all[i].value == '1') {
4941: document.$formname.selfenroll_all[i].checked = false;
4942: }
4943: if (document.$formname.selfenroll_all[i].value == '0') {
4944: document.$formname.selfenroll_all[i].checked = true;
4945: }
4946: }
4947: }
4948: }
4949: }
4950: } else {
4951: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4952: if (document.$formname.selfenroll_all[i].value == '1') {
4953: document.$formname.selfenroll_all[i].checked = false;
4954: }
4955: if (document.$formname.selfenroll_all[i].value == '0') {
4956: document.$formname.selfenroll_all[i].checked = true;
4957: }
4958: }
4959: }
4960: }
4961: if (caller == 'selfenroll_delete') {
4962: if (document.$formname.selfenroll_delete.length) {
4963: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
4964: if (document.$formname.selfenroll_delete[j].value == num) {
4965: if (document.$formname.selfenroll_delete[j].checked) {
4966: var delindex = getIndexByName('selfenroll_types_'+num);
4967: if (delindex != -1) {
4968: if (document.$formname.elements[delindex].length) {
4969: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
4970: document.$formname.elements[delindex][k].checked = false;
4971: }
4972: } else {
4973: document.$formname.elements[delindex].checked = false;
4974: }
4975: }
4976: }
4977: }
4978: }
4979: } else {
4980: if (document.$formname.selfenroll_delete.checked) {
4981: var delindex = getIndexByName('selfenroll_types_'+num);
4982: if (delindex != -1) {
4983: if (document.$formname.elements[delindex].length) {
4984: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
4985: document.$formname.elements[delindex][k].checked = false;
4986: }
4987: } else {
4988: document.$formname.elements[delindex].checked = false;
4989: }
4990: }
4991: }
4992: }
4993: }
4994: return;
4995: }
4996:
4997: function validate_types(form) {
4998: var needaction = new Array();
4999: var countfail = 0;
5000: var actidx = getIndexByName('selfenroll_activate');
5001: if (actidx != -1) {
5002: if (document.$formname.selfenroll_activate.length) {
5003: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5004: var num = document.$formname.selfenroll_activate[j].value;
5005: if (document.$formname.selfenroll_activate[j].checked) {
5006: countfail = check_types(num,countfail,needaction)
5007: }
5008: }
5009: } else {
5010: if (document.$formname.selfenroll_activate.checked) {
5011: var num = document.enrollstudent.selfenroll_activate.value;
5012: countfail = check_types(num,countfail,needaction)
5013: }
5014: }
5015: }
5016: if (countfail > 0) {
5017: var msg = "$alerts{'acto'}\\n";
5018: var loopend = needaction.length -1;
5019: if (loopend > 0) {
5020: for (var m=0; m<loopend; m++) {
5021: msg += needaction[m]+", ";
5022: }
5023: }
5024: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5025: alert(msg);
5026: return;
5027: }
5028: setSections(form);
5029: }
5030:
5031: function check_types(num,countfail,needaction) {
5032: var typeidx = getIndexByName('selfenroll_types_'+num);
5033: var count = 0;
5034: if (typeidx != -1) {
5035: if (document.$formname.elements[typeidx].length) {
5036: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5037: if (document.$formname.elements[typeidx][k].checked) {
5038: count ++;
5039: }
5040: }
5041: } else {
5042: if (document.$formname.elements[typeidx].checked) {
5043: count ++;
5044: }
5045: }
5046: if (count == 0) {
5047: var domidx = getIndexByName('selfenroll_dom_'+num);
5048: if (domidx != -1) {
5049: var domname = document.$formname.elements[domidx].value;
5050: needaction[countfail] = domname;
5051: countfail ++;
5052: }
5053: }
5054: }
5055: return countfail;
5056: }
5057:
5058: function getIndexByName(item) {
5059: for (var i=0;i<document.$formname.elements.length;i++) {
5060: if (document.$formname.elements[i].name == item) {
5061: return i;
5062: }
5063: }
5064: return -1;
5065: }
5066: ENDSCRIPT
1.256 raeburn 5067: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5068: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5069:
1.237 raeburn 5070: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5071: '// <![CDATA['."\n".
1.249 raeburn 5072: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5073: '// ]]>'."\n".
1.237 raeburn 5074: '</script>'."\n".
1.256 raeburn 5075: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
5076: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
5077: if (ref($visactions) eq 'HASH') {
5078: if ($visible) {
1.283 bisitz 5079: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
1.256 raeburn 5080: } else {
1.283 bisitz 5081: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5082: .$visactions->{'yous'}.
1.256 raeburn 5083: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5084: if (ref($vismsgs) eq 'ARRAY') {
5085: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5086: foreach my $item (@{$vismsgs}) {
5087: $output .= '<li>'.$visactions->{$item}.'</li>';
5088: }
5089: $output .= '</ul>';
5090: }
5091: $output .= '</p>';
5092: }
5093: }
5094: $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
5095: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5096: if (ref($row) eq 'ARRAY') {
5097: foreach my $item (@{$row}) {
5098: my $title = $item;
5099: if (ref($lt) eq 'HASH') {
5100: $title = $lt->{$item};
5101: }
1.297 bisitz 5102: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5103: if ($item eq 'types') {
5104: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 5105: my $showdomdesc = 1;
5106: my $includeempty = 1;
5107: my $num = 0;
5108: $output .= &Apache::loncommon::start_data_table().
5109: &Apache::loncommon::start_data_table_row()
5110: .'<td colspan="2"><span class="LC_nobreak"><label>'
5111: .&mt('Any user in any domain:')
5112: .' <input type="radio" name="selfenroll_all" value="1" ';
5113: if ($curr_types eq '*') {
5114: $output .= ' checked="checked" ';
5115: }
1.249 raeburn 5116: $output .= 'onchange="javascript:update_types('.
5117: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
5118: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 5119: if ($curr_types ne '*') {
5120: $output .= ' checked="checked" ';
5121: }
1.249 raeburn 5122: $output .= ' onchange="javascript:update_types('.
5123: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
5124: &Apache::loncommon::end_data_table_row().
5125: &Apache::loncommon::end_data_table().
5126: &mt('Or').'<br />'.
5127: &Apache::loncommon::start_data_table();
1.241 raeburn 5128: my %currdoms;
1.249 raeburn 5129: if ($curr_types eq '') {
1.241 raeburn 5130: $output .= &new_selfenroll_dom_row($cdom,'0');
5131: } elsif ($curr_types ne '*') {
5132: my @entries = split(/;/,$curr_types);
5133: if (@entries > 0) {
5134: foreach my $entry (@entries) {
5135: my ($currdom,$typestr) = split(/:/,$entry);
5136: $currdoms{$currdom} = 1;
5137: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 5138: my @currinsttypes = split(',',$typestr);
1.241 raeburn 5139: $output .= &Apache::loncommon::start_data_table_row()
5140: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
5141: .' '.$domdesc.' ('.$currdom.')'
5142: .'</b><input type="hidden" name="selfenroll_dom_'.$num
5143: .'" value="'.$currdom.'" /></span><br />'
5144: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 5145: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 5146: .&mt('Delete').'</label></span></td>';
1.249 raeburn 5147: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 5148: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
5149: .&Apache::loncommon::end_data_table_row();
5150: $num ++;
5151: }
5152: }
5153: }
1.249 raeburn 5154: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 5155: if ($curr_types eq '*') {
1.249 raeburn 5156: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 5157: } elsif ($curr_types eq '') {
1.249 raeburn 5158: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 5159: }
5160: $output .= &Apache::loncommon::start_data_table_row()
5161: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
5162: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
5163: $includeempty,$showdomdesc)
5164: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
5165: .'</td>'.&Apache::loncommon::end_data_table_row()
5166: .&Apache::loncommon::end_data_table();
1.237 raeburn 5167: } elsif ($item eq 'registered') {
5168: my ($regon,$regoff);
5169: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
5170: $regon = ' checked="checked" ';
5171: $regoff = ' ';
5172: } else {
5173: $regon = ' ';
5174: $regoff = ' checked="checked" ';
5175: }
5176: $output .= '<label>'.
1.245 raeburn 5177: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 5178: &mt('Yes').'</label> <label>'.
1.245 raeburn 5179: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 5180: &mt('No').'</label>';
1.237 raeburn 5181: } elsif ($item eq 'enroll_dates') {
5182: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
5183: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
5184: if ($starttime eq '') {
5185: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
5186: }
5187: if ($endtime eq '') {
5188: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
5189: }
5190: my $startform =
5191: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
5192: undef,undef,undef,undef,undef,undef,undef,$nolink);
5193: my $endform =
5194: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
5195: undef,undef,undef,undef,undef,undef,undef,$nolink);
5196: $output .= &selfenroll_date_forms($startform,$endform);
5197: } elsif ($item eq 'access_dates') {
5198: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
5199: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
5200: if ($starttime eq '') {
5201: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
5202: }
5203: if ($endtime eq '') {
5204: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
5205: }
5206: my $startform =
5207: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
5208: undef,undef,undef,undef,undef,undef,undef,$nolink);
5209: my $endform =
5210: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
5211: undef,undef,undef,undef,undef,undef,undef,$nolink);
5212: $output .= &selfenroll_date_forms($startform,$endform);
5213: } elsif ($item eq 'section') {
5214: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
5215: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
5216: my $newsecval;
5217: if ($currsec ne 'none' && $currsec ne '') {
5218: if (!defined($sections_count{$currsec})) {
5219: $newsecval = $currsec;
5220: }
5221: }
5222: my $sections_select =
5223: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
5224: $output .= '<table class="LC_createuser">'."\n".
5225: '<tr class="LC_section_row">'."\n".
5226: '<td align="center">'.&mt('Existing sections')."\n".
5227: '<br />'.$sections_select.'</td><td align="center">'.
5228: &mt('New section').'<br />'."\n".
5229: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
5230: '<input type="hidden" name="sections" value="" />'."\n".
5231: '<input type="hidden" name="state" value="done" />'."\n".
5232: '</td></tr></table>'."\n";
1.276 raeburn 5233: } elsif ($item eq 'approval') {
5234: my ($appon,$appoff);
5235: my $cid = $env{'request.course.id'};
5236: my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
5237: if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) {
5238: $appon = ' checked="checked" ';
5239: $appoff = ' ';
5240: } else {
5241: $appon = ' ';
5242: $appoff = ' checked="checked" ';
5243: }
5244: $output .= '<label>'.
5245: '<input type="radio" name="selfenroll_approval" value="1"'.$appon.'/>'.
5246: &mt('Yes').'</label> <label>'.
5247: '<input type="radio" name="selfenroll_approval" value="0"'.$appoff.'/>'.
5248: &mt('No').'</label>';
5249: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
5250: my (@ccs,%notified);
1.322 raeburn 5251: my $ccrole = 'cc';
5252: if ($crstype eq 'Community') {
5253: $ccrole = 'co';
5254: }
5255: if ($advhash{$ccrole}) {
5256: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 5257: }
5258: if ($currnotified) {
5259: foreach my $current (split(/,/,$currnotified)) {
5260: $notified{$current} = 1;
5261: if (!grep(/^\Q$current\E$/,@ccs)) {
5262: push(@ccs,$current);
5263: }
5264: }
5265: }
5266: if (@ccs) {
1.277 raeburn 5267: $output .= '<br />'.&mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.&Apache::loncommon::start_data_table().
1.276 raeburn 5268: &Apache::loncommon::start_data_table_row();
5269: my $count = 0;
5270: my $numcols = 4;
5271: foreach my $cc (sort(@ccs)) {
5272: my $notifyon;
5273: my ($ccuname,$ccudom) = split(/:/,$cc);
5274: if ($notified{$cc}) {
5275: $notifyon = ' checked="checked" ';
5276: }
5277: if ($count && !$count%$numcols) {
5278: $output .= &Apache::loncommon::end_data_table_row().
5279: &Apache::loncommon::start_data_table_row()
5280: }
5281: $output .= '<td><span class="LC_nobreak"><label>'.
5282: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
5283: &Apache::loncommon::plainname($ccuname,$ccudom).
5284: '</label></span></td>';
1.343 raeburn 5285: $count ++;
1.276 raeburn 5286: }
5287: my $rem = $count%$numcols;
5288: if ($rem) {
5289: my $emptycols = $numcols - $rem;
5290: for (my $i=0; $i<$emptycols; $i++) {
5291: $output .= '<td> </td>';
5292: }
5293: }
5294: $output .= &Apache::loncommon::end_data_table_row().
5295: &Apache::loncommon::end_data_table();
5296: }
5297: } elsif ($item eq 'limit') {
5298: my ($crslimit,$selflimit,$nolimit);
5299: my $cid = $env{'request.course.id'};
5300: my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'};
5301: my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
1.343 raeburn 5302: $nolimit = ' checked="checked" ';
1.276 raeburn 5303: if ($currlim eq 'allstudents') {
5304: $crslimit = ' checked="checked" ';
5305: $selflimit = ' ';
5306: $nolimit = ' ';
5307: } elsif ($currlim eq 'selfenrolled') {
5308: $crslimit = ' ';
5309: $selflimit = ' checked="checked" ';
5310: $nolimit = ' ';
5311: } else {
5312: $crslimit = ' ';
5313: $selflimit = ' ';
5314: }
5315: $output .= '<table><tr><td><label>'.
1.278 raeburn 5316: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 5317: &mt('No limit').'</label></td><td><label>'.
5318: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
5319: &mt('Limit by total students').'</label></td><td><label>'.
5320: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
5321: &mt('Limit by total self-enrolled students').
5322: '</td></tr><tr>'.
5323: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
5324: (' 'x3).&mt('Maximum number allowed: ').
5325: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 5326: }
5327: $output .= &Apache::lonhtmlcommon::row_closure(1);
5328: }
5329: }
5330: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 5331: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 5332: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.241 raeburn 5333: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 5334: $r->print($output);
5335: return;
5336: }
5337:
1.256 raeburn 5338: sub visible_in_cat {
5339: my ($cdom,$cnum) = @_;
5340: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5341: my ($cathash,%settable,@vismsgs,$cansetvis);
5342: my %visactions = &Apache::lonlocal::texthash(
1.316 bisitz 5343: vis => 'Your course/community currently appears in the Course/Community Catalog for this domain.',
1.256 raeburn 5344: gen => 'Courses can be both self-cataloging, based on an institutional code (e.g., fs08phy231), or can be assigned categories from a hierarchy defined for the domain.',
1.316 bisitz 5345: miss => 'Your course/community does not currently appear in the Course/Community Catalog for this domain.',
1.256 raeburn 5346: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
5347: coca => 'Courses can be absent from the Catalog, because they do not have an institutional code, have no assigned category, or have been specifically excluded.',
1.282 schafran 5348: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
1.256 raeburn 5349: take => 'Take the following action to ensure the course appears in the Catalog:',
5350: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
5351: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
5352: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
5353: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
5354: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
5355: dc_chgcat => 'Ask a domain coordinator to change the category assigned to the course, as the one currently assigned is no longer used in the domain',
5356: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
5357: );
1.347 raeburn 5358: $visactions{'unhide'} = &mt('Use [_1]Categorize course[_2] to change the "Exclude from course catalog" setting.','<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
5359: $visactions{'chgcat'} = &mt('Use [_1]Categorize course[_2] to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
5360: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
1.256 raeburn 5361: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5362: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
5363: $settable{'togglecats'} = 1;
5364: }
5365: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
5366: $settable{'categorize'} = 1;
5367: }
5368: $cathash = $domconf{'coursecategories'}{'cats'};
5369: }
1.260 raeburn 5370: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 5371: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
5372: } elsif ($settable{'togglecats'}) {
5373: $cansetvis = &mt('You are able to choose to exclude this course from the catalog, but only a Domain Coordinator may assign a course category.');
1.260 raeburn 5374: } elsif ($settable{'categorize'}) {
1.256 raeburn 5375: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
5376: } else {
5377: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
5378: }
5379:
5380: my %currsettings =
5381: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
5382: $cdom,$cnum);
5383: my $visible = 0;
5384: if ($currsettings{'internal.coursecode'} ne '') {
5385: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5386: $cathash = $domconf{'coursecategories'}{'cats'};
5387: if (ref($cathash) eq 'HASH') {
5388: if ($cathash->{'instcode::0'} eq '') {
5389: push(@vismsgs,'dc_addinst');
5390: } else {
5391: $visible = 1;
5392: }
5393: } else {
5394: $visible = 1;
5395: }
5396: } else {
5397: $visible = 1;
5398: }
5399: } else {
5400: if (ref($cathash) eq 'HASH') {
5401: if ($cathash->{'instcode::0'} ne '') {
5402: push(@vismsgs,'dc_instcode');
5403: }
5404: } else {
5405: push(@vismsgs,'dc_instcode');
5406: }
5407: }
5408: if ($currsettings{'categories'} ne '') {
5409: my $cathash;
5410: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5411: $cathash = $domconf{'coursecategories'}{'cats'};
5412: if (ref($cathash) eq 'HASH') {
5413: if (keys(%{$cathash}) == 0) {
5414: push(@vismsgs,'dc_catalog');
5415: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
5416: push(@vismsgs,'dc_categories');
5417: } else {
5418: my @currcategories = split('&',$currsettings{'categories'});
5419: my $matched = 0;
5420: foreach my $cat (@currcategories) {
5421: if ($cathash->{$cat} ne '') {
5422: $visible = 1;
5423: $matched = 1;
5424: last;
5425: }
5426: }
5427: if (!$matched) {
1.260 raeburn 5428: if ($settable{'categorize'}) {
1.256 raeburn 5429: push(@vismsgs,'chgcat');
5430: } else {
5431: push(@vismsgs,'dc_chgcat');
5432: }
5433: }
5434: }
5435: }
5436: }
5437: } else {
5438: if (ref($cathash) eq 'HASH') {
5439: if ((keys(%{$cathash}) > 1) ||
5440: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 5441: if ($settable{'categorize'}) {
1.256 raeburn 5442: push(@vismsgs,'addcat');
5443: } else {
5444: push(@vismsgs,'dc_addcat');
5445: }
5446: }
5447: }
5448: }
5449: if ($currsettings{'hidefromcat'} eq 'yes') {
5450: $visible = 0;
5451: if ($settable{'togglecats'}) {
5452: unshift(@vismsgs,'unhide');
5453: } else {
5454: unshift(@vismsgs,'dc_unhide')
5455: }
5456: }
5457: return ($visible,$cansetvis,\@vismsgs,\%visactions);
5458: }
5459:
1.241 raeburn 5460: sub new_selfenroll_dom_row {
5461: my ($newdom,$num) = @_;
5462: my $domdesc = &Apache::lonnet::domain($newdom);
5463: my $output;
5464: if ($domdesc ne '') {
5465: $output .= &Apache::loncommon::start_data_table_row()
5466: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
5467: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 5468: .'" value="'.$newdom.'" /></span><br />'
5469: .'<span class="LC_nobreak"><label><input type="checkbox" '
5470: .'name="selfenroll_activate" value="'.$num.'" '
5471: .'onchange="javascript:update_types('
5472: ."'selfenroll_activate','$num'".');" />'
5473: .&mt('Activate').'</label></span></td>';
1.241 raeburn 5474: my @currinsttypes;
5475: $output .= '<td>'.&mt('User types:').'<br />'
5476: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
5477: .&Apache::loncommon::end_data_table_row();
5478: }
5479: return $output;
5480: }
5481:
5482: sub selfenroll_inst_types {
5483: my ($num,$currdom,$currinsttypes) = @_;
5484: my $output;
5485: my $numinrow = 4;
5486: my $count = 0;
5487: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 5488: my $othervalue = 'any';
1.241 raeburn 5489: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 5490: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 5491: $othervalue = 'other';
5492: }
1.241 raeburn 5493: $output .= '<table><tr>';
5494: foreach my $type (@{$types}) {
5495: if (($count > 0) && ($count%$numinrow == 0)) {
5496: $output .= '</tr><tr>';
5497: }
5498: if (defined($usertypes->{$type})) {
1.257 raeburn 5499: my $esc_type = &escape($type);
1.241 raeburn 5500: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 5501: $esc_type.'" ';
1.241 raeburn 5502: if (ref($currinsttypes) eq 'ARRAY') {
5503: if (@{$currinsttypes} > 0) {
1.249 raeburn 5504: if (grep(/^any$/,@{$currinsttypes})) {
5505: $output .= 'checked="checked"';
1.257 raeburn 5506: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 5507: $output .= 'checked="checked"';
5508: }
1.249 raeburn 5509: } else {
5510: $output .= 'checked="checked"';
1.241 raeburn 5511: }
5512: }
5513: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
5514: }
5515: $count ++;
5516: }
5517: if (($count > 0) && ($count%$numinrow == 0)) {
5518: $output .= '</tr><tr>';
5519: }
1.249 raeburn 5520: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 5521: if (ref($currinsttypes) eq 'ARRAY') {
5522: if (@{$currinsttypes} > 0) {
1.249 raeburn 5523: if (grep(/^any$/,@{$currinsttypes})) {
5524: $output .= ' checked="checked"';
5525: } elsif ($othervalue eq 'other') {
5526: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
5527: $output .= ' checked="checked"';
5528: }
1.241 raeburn 5529: }
1.249 raeburn 5530: } else {
5531: $output .= ' checked="checked"';
1.241 raeburn 5532: }
1.249 raeburn 5533: } else {
5534: $output .= ' checked="checked"';
1.241 raeburn 5535: }
5536: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
5537: }
5538: return $output;
5539: }
5540:
1.237 raeburn 5541: sub selfenroll_date_forms {
5542: my ($startform,$endform) = @_;
5543: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 5544: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 5545: 'LC_oddrow_value')."\n".
5546: $startform."\n".
5547: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 5548: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 5549: 'LC_oddrow_value')."\n".
5550: $endform."\n".
5551: &Apache::lonhtmlcommon::row_closure(1).
5552: &Apache::lonhtmlcommon::end_pick_box();
5553: return $output;
5554: }
5555:
1.239 raeburn 5556: sub print_userchangelogs_display {
5557: my ($r,$context,$permission) = @_;
1.363 raeburn 5558: my $formname = 'rolelog';
5559: my ($username,$domain,$crstype,%roleslog);
5560: if ($context eq 'domain') {
5561: $domain = $env{'request.role.domain'};
5562: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
5563: } else {
5564: if ($context eq 'course') {
5565: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
5566: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
5567: $crstype = &Apache::loncommon::course_type();
5568: my %saveable_parameters = ('show' => 'scalar',);
5569: &Apache::loncommon::store_course_settings('roles_log',
5570: \%saveable_parameters);
5571: &Apache::loncommon::restore_course_settings('roles_log',
5572: \%saveable_parameters);
5573: } elsif ($context eq 'author') {
5574: $domain = $env{'user.domain'};
5575: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
5576: $username = $env{'user.name'};
5577: } else {
5578: undef($domain);
5579: }
5580: }
5581: if ($domain ne '' && $username ne '') {
5582: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
5583: }
5584: }
1.239 raeburn 5585: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
5586:
5587: # set defaults
5588: my $now = time();
5589: my $defstart = $now - (7*24*3600); #7 days ago
5590: my %defaults = (
5591: page => '1',
5592: show => '10',
5593: role => 'any',
5594: chgcontext => 'any',
5595: rolelog_start_date => $defstart,
5596: rolelog_end_date => $now,
5597: );
5598: my $more_records = 0;
5599:
5600: # set current
5601: my %curr;
5602: foreach my $item ('show','page','role','chgcontext') {
5603: $curr{$item} = $env{'form.'.$item};
5604: }
5605: my ($startdate,$enddate) =
5606: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
5607: $curr{'rolelog_start_date'} = $startdate;
5608: $curr{'rolelog_end_date'} = $enddate;
5609: foreach my $key (keys(%defaults)) {
5610: if ($curr{$key} eq '') {
5611: $curr{$key} = $defaults{$key};
5612: }
5613: }
1.248 raeburn 5614: my (%whodunit,%changed,$version);
5615: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 5616: my ($minshown,$maxshown);
1.255 raeburn 5617: $minshown = 1;
1.239 raeburn 5618: my $count = 0;
5619: if ($curr{'show'} ne &mt('all')) {
5620: $maxshown = $curr{'page'} * $curr{'show'};
5621: if ($curr{'page'} > 1) {
5622: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
5623: }
5624: }
1.301 bisitz 5625:
1.327 raeburn 5626: # Form Header
5627: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 5628: &role_display_filter($context,$formname,$domain,$username,\%curr,
5629: $version,$crstype));
1.327 raeburn 5630:
5631: # Create navigation
5632: my ($nav_script,$nav_links) = &userlogdisplay_nav($formname,\%curr,$more_records);
5633: my $showntableheader = 0;
5634:
5635: # Table Header
5636: my $tableheader =
5637: &Apache::loncommon::start_data_table_header_row()
5638: .'<th> </th>'
5639: .'<th>'.&mt('When').'</th>'
5640: .'<th>'.&mt('Who made the change').'</th>'
5641: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 5642: .'<th>'.&mt('Role').'</th>';
5643:
5644: if ($context eq 'course') {
5645: $tableheader .= '<th>'.&mt('Section').'</th>';
5646: }
5647: $tableheader .=
5648: '<th>'.&mt('Context').'</th>'
1.327 raeburn 5649: .'<th>'.&mt('Start').'</th>'
5650: .'<th>'.&mt('End').'</th>'
5651: .&Apache::loncommon::end_data_table_header_row();
5652:
5653: # Display user change log data
1.239 raeburn 5654: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
5655: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
5656: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
5657: if ($curr{'show'} ne &mt('all')) {
5658: if ($count >= $curr{'page'} * $curr{'show'}) {
5659: $more_records = 1;
5660: last;
5661: }
5662: }
5663: if ($curr{'role'} ne 'any') {
5664: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
5665: }
5666: if ($curr{'chgcontext'} ne 'any') {
5667: if ($curr{'chgcontext'} eq 'selfenroll') {
5668: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
5669: } else {
5670: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
5671: }
5672: }
5673: $count ++;
5674: next if ($count < $minshown);
1.327 raeburn 5675: unless ($showntableheader) {
5676: $r->print($nav_script
5677: .$nav_links
5678: .&Apache::loncommon::start_data_table()
5679: .$tableheader);
5680: $r->rflush();
5681: $showntableheader = 1;
5682: }
1.239 raeburn 5683: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
5684: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
5685: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
5686: }
5687: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
5688: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
5689: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
5690: }
5691: my $sec = $roleslog{$id}{'logentry'}{'section'};
5692: if ($sec eq '') {
5693: $sec = &mt('None');
5694: }
5695: my ($rolestart,$roleend);
5696: if ($roleslog{$id}{'delflag'}) {
5697: $rolestart = &mt('deleted');
5698: $roleend = &mt('deleted');
5699: } else {
5700: $rolestart = $roleslog{$id}{'logentry'}{'start'};
5701: $roleend = $roleslog{$id}{'logentry'}{'end'};
5702: if ($rolestart eq '' || $rolestart == 0) {
5703: $rolestart = &mt('No start date');
5704: } else {
5705: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
5706: }
5707: if ($roleend eq '' || $roleend == 0) {
5708: $roleend = &mt('No end date');
5709: } else {
5710: $roleend = &Apache::lonlocal::locallocaltime($roleend);
5711: }
5712: }
5713: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
5714: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
5715: $chgcontext = 'selfenroll';
5716: }
1.363 raeburn 5717: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 5718: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
5719: $chgcontext = $lt{$chgcontext};
5720: }
1.327 raeburn 5721: $r->print(
1.301 bisitz 5722: &Apache::loncommon::start_data_table_row()
5723: .'<td>'.$count.'</td>'
5724: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
5725: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
5726: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 5727: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
5728: if ($context eq 'course') {
5729: $r->print('<td>'.$sec.'</td>');
5730: }
5731: $r->print(
5732: '<td>'.$chgcontext.'</td>'
1.301 bisitz 5733: .'<td>'.$rolestart.'</td>'
5734: .'<td>'.$roleend.'</td>'
1.327 raeburn 5735: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 5736: }
5737:
1.327 raeburn 5738: if ($showntableheader) { # Table footer, if content displayed above
5739: $r->print(&Apache::loncommon::end_data_table()
5740: .$nav_links);
5741: } else { # No content displayed above
1.301 bisitz 5742: $r->print('<p class="LC_info">'
5743: .&mt('There are no records to display.')
5744: .'</p>'
5745: );
1.239 raeburn 5746: }
1.301 bisitz 5747:
1.327 raeburn 5748: # Form Footer
5749: $r->print(
5750: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
5751: .'<input type="hidden" name="action" value="changelogs" />'
5752: .'</form>');
5753: return;
5754: }
1.301 bisitz 5755:
1.327 raeburn 5756: sub userlogdisplay_nav {
5757: my ($formname,$curr,$more_records) = @_;
5758: my ($nav_script,$nav_links);
5759: if (ref($curr) eq 'HASH') {
5760: # Create Navigation:
5761: # Navigation Script
5762: $nav_script = <<"ENDSCRIPT";
1.239 raeburn 5763: <script type="text/javascript">
1.301 bisitz 5764: // <![CDATA[
1.239 raeburn 5765: function chgPage(caller) {
5766: if (caller == 'previous') {
5767: document.$formname.page.value --;
5768: }
5769: if (caller == 'next') {
5770: document.$formname.page.value ++;
5771: }
1.327 raeburn 5772: document.$formname.submit();
1.239 raeburn 5773: return;
5774: }
1.301 bisitz 5775: // ]]>
1.239 raeburn 5776: </script>
5777: ENDSCRIPT
1.327 raeburn 5778: # Navigation Buttons
5779: $nav_links = '<p>';
5780: if (($curr->{'page'} > 1) || ($more_records)) {
5781: if ($curr->{'page'} > 1) {
5782: $nav_links .= '<input type="button"'
5783: .' onclick="javascript:chgPage('."'previous'".');"'
5784: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
5785: .'" /> ';
5786: }
5787: if ($more_records) {
5788: $nav_links .= '<input type="button"'
5789: .' onclick="javascript:chgPage('."'next'".');"'
5790: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
5791: .'" />';
5792: }
1.301 bisitz 5793: }
1.327 raeburn 5794: $nav_links .= '</p>';
1.301 bisitz 5795: }
1.327 raeburn 5796: return ($nav_script,$nav_links);
1.239 raeburn 5797: }
5798:
5799: sub role_display_filter {
1.363 raeburn 5800: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
5801: my $lctype;
5802: if ($context eq 'course') {
5803: $lctype = lc($crstype);
5804: }
1.239 raeburn 5805: my $nolink = 1;
5806: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 5807: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 5808: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
5809: (&mt('all'),5,10,20,50,100,1000,10000)).
5810: '</td><td> </td>';
5811: my $startform =
5812: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
5813: $curr->{'rolelog_start_date'},undef,
5814: undef,undef,undef,undef,undef,undef,$nolink);
5815: my $endform =
5816: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
5817: $curr->{'rolelog_end_date'},undef,
5818: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 5819: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 5820: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
5821: '<table><tr><td>'.&mt('After:').
5822: '</td><td>'.$startform.'</td></tr>'.
5823: '<tr><td>'.&mt('Before:').'</td>'.
5824: '<td>'.$endform.'</td></tr></table>'.
5825: '</td>'.
5826: '<td> </td>'.
1.239 raeburn 5827: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
5828: '<select name="role"><option value="any"';
5829: if ($curr->{'role'} eq 'any') {
5830: $output .= ' selected="selected"';
5831: }
5832: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 5833: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 5834: foreach my $role (@roles) {
5835: my $plrole;
5836: if ($role eq 'cr') {
5837: $plrole = &mt('Custom Role');
5838: } else {
1.318 raeburn 5839: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 5840: }
5841: my $selstr = '';
5842: if ($role eq $curr->{'role'}) {
5843: $selstr = ' selected="selected"';
5844: }
5845: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
5846: }
1.301 bisitz 5847: $output .= '</select></td>'.
5848: '<td> </td>'.
5849: '<td valign="top"><b>'.
1.239 raeburn 5850: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 5851: my @posscontexts;
5852: if ($context eq 'course') {
5853: @posscontexts = ('any','auto','updatenow','createcourse','course','domain','selfenroll','requestcourses');
5854: } elsif ($context eq 'domain') {
5855: @posscontexts = ('any','domain','requestauthor','domconfig','server');
5856: } else {
5857: @posscontexts = ('any','author','domain');
5858: }
5859: foreach my $chgtype (@posscontexts) {
1.239 raeburn 5860: my $selstr = '';
5861: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 5862: $selstr = ' selected="selected"';
1.239 raeburn 5863: }
1.363 raeburn 5864: if ($context eq 'course') {
5865: if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) {
5866: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
5867: }
1.239 raeburn 5868: }
5869: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 5870: }
1.303 bisitz 5871: $output .= '</select></td>'
5872: .'</tr></table>';
5873:
5874: # Update Display button
5875: $output .= '<p>'
5876: .'<input type="submit" value="'.&mt('Update Display').'" />'
5877: .'</p>';
5878:
5879: # Server version info
1.363 raeburn 5880: my $needsrev = '2.11.0';
5881: if ($context eq 'course') {
5882: $needsrev = '2.7.0';
5883: }
5884:
1.303 bisitz 5885: $output .= '<p class="LC_info">'
5886: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 5887: ,$needsrev);
1.248 raeburn 5888: if ($version) {
1.303 bisitz 5889: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
5890: }
5891: $output .= '</p><hr />';
1.239 raeburn 5892: return $output;
5893: }
5894:
5895: sub rolechg_contexts {
1.363 raeburn 5896: my ($context,$crstype) = @_;
5897: my %lt;
5898: if ($context eq 'course') {
5899: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 5900: any => 'Any',
5901: auto => 'Automated enrollment',
5902: updatenow => 'Roster Update',
5903: createcourse => 'Course Creation',
5904: course => 'User Management in course',
5905: domain => 'User Management in domain',
1.313 raeburn 5906: selfenroll => 'Self-enrolled',
1.318 raeburn 5907: requestcourses => 'Course Request',
1.239 raeburn 5908: );
1.363 raeburn 5909: if ($crstype eq 'Community') {
5910: $lt{'createcourse'} = &mt('Community Creation');
5911: $lt{'course'} = &mt('User Management in community');
5912: $lt{'requestcourses'} = &mt('Community Request');
5913: }
5914: } elsif ($context eq 'domain') {
5915: %lt = &Apache::lonlocal::texthash (
5916: any => 'Any',
5917: domain => 'User Management in domain',
5918: requestauthor => 'Authoring Request',
5919: server => 'Command line script (DC role)',
5920: domconfig => 'Self-enrolled',
5921: );
5922: } else {
5923: %lt = &Apache::lonlocal::texthash (
5924: any => 'Any',
5925: domain => 'User Management in domain',
5926: author => 'User Management by author',
5927: );
5928: }
1.239 raeburn 5929: return %lt;
5930: }
5931:
1.27 matthew 5932: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 5933: sub user_search_result {
1.221 raeburn 5934: my ($context,$srch) = @_;
1.160 raeburn 5935: my %allhomes;
5936: my %inst_matches;
5937: my %srch_results;
1.181 raeburn 5938: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 5939: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 5940: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 5941: $response = &mt('Invalid search.');
5942: }
5943: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
5944: $response = &mt('Invalid search.');
5945: }
1.177 raeburn 5946: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 5947: $response = &mt('Invalid search.');
5948: }
5949: if ($srch->{'srchterm'} eq '') {
5950: $response = &mt('You must enter a search term.');
5951: }
1.183 raeburn 5952: if ($srch->{'srchterm'} =~ /^\s+$/) {
5953: $response = &mt('Your search term must contain more than just spaces.');
5954: }
1.160 raeburn 5955: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
5956: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 5957: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 5958: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
5959: }
5960: }
5961: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
5962: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 5963: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 5964: my $unamecheck = $srch->{'srchterm'};
5965: if ($srch->{'srchtype'} eq 'contains') {
5966: if ($unamecheck !~ /^\w/) {
5967: $unamecheck = 'a'.$unamecheck;
5968: }
5969: }
5970: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 5971: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
5972: }
1.160 raeburn 5973: }
5974: }
1.180 raeburn 5975: if ($response ne '') {
5976: $response = '<span class="LC_warning">'.$response.'</span>';
5977: }
1.160 raeburn 5978: if ($srch->{'srchin'} eq 'instd') {
5979: my $instd_chk = &directorysrch_check($srch);
5980: if ($instd_chk ne 'ok') {
1.180 raeburn 5981: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
5982: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 5983: }
5984: }
5985: if ($response ne '') {
1.180 raeburn 5986: return ($currstate,$response);
1.160 raeburn 5987: }
5988: if ($srch->{'srchby'} eq 'uname') {
5989: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
5990: if ($env{'form.forcenew'}) {
5991: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
5992: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
5993: if ($uhome eq 'no_host') {
5994: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 5995: my $showdom = &display_domain_info($env{'request.role.domain'});
5996: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 5997: } else {
1.179 raeburn 5998: $currstate = 'modify';
1.160 raeburn 5999: }
6000: } else {
1.179 raeburn 6001: $currstate = 'modify';
1.160 raeburn 6002: }
6003: } else {
6004: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 6005: if ($srch->{'srchtype'} eq 'exact') {
6006: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6007: if ($uhome eq 'no_host') {
1.179 raeburn 6008: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6009: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6010: } else {
1.179 raeburn 6011: $currstate = 'modify';
1.310 raeburn 6012: my $uname = $srch->{'srchterm'};
6013: my $udom = $srch->{'srchdomain'};
6014: $srch_results{$uname.':'.$udom} =
6015: { &Apache::lonnet::get('environment',
6016: ['firstname',
6017: 'lastname',
6018: 'permanentemail'],
6019: $udom,$uname)
6020: };
1.162 raeburn 6021: }
6022: } else {
6023: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6024: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6025: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6026: }
6027: } else {
1.167 albertel 6028: my $courseusers = &get_courseusers();
1.162 raeburn 6029: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 6030: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 6031: $currstate = 'modify';
1.162 raeburn 6032: } else {
1.179 raeburn 6033: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6034: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6035: }
1.160 raeburn 6036: } else {
1.167 albertel 6037: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 6038: my ($cuname,$cudomain) = split(/:/,$user);
6039: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 6040: my $matched = 0;
6041: if ($srch->{'srchtype'} eq 'begins') {
6042: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
6043: $matched = 1;
6044: }
6045: } else {
6046: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
6047: $matched = 1;
6048: }
6049: }
6050: if ($matched) {
1.167 albertel 6051: $srch_results{$user} =
6052: {&Apache::lonnet::get('environment',
6053: ['firstname',
6054: 'lastname',
1.194 albertel 6055: 'permanentemail'],
6056: $cudomain,$cuname)};
1.162 raeburn 6057: }
6058: }
6059: }
1.179 raeburn 6060: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6061: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6062: }
6063: }
6064: }
6065: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6066: $currstate = 'query';
1.160 raeburn 6067: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6068: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6069: if ($dirsrchres eq 'ok') {
6070: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6071: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6072: } else {
6073: my $showdom = &display_domain_info($srch->{'srchdomain'});
6074: $response = '<span class="LC_warning">'.
6075: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6076: '</span><br />'.
6077: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6078: '<br /><br />';
6079: }
1.160 raeburn 6080: }
6081: } else {
6082: if ($srch->{'srchin'} eq 'dom') {
6083: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6084: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6085: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6086: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 6087: my $courseusers = &get_courseusers();
6088: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 6089: my ($uname,$udom) = split(/:/,$user);
6090: my %names = &Apache::loncommon::getnames($uname,$udom);
6091: my %emails = &Apache::loncommon::getemails($uname,$udom);
6092: if ($srch->{'srchby'} eq 'lastname') {
6093: if ((($srch->{'srchtype'} eq 'exact') &&
6094: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 6095: (($srch->{'srchtype'} eq 'begins') &&
6096: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 6097: (($srch->{'srchtype'} eq 'contains') &&
6098: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
6099: $srch_results{$user} = {firstname => $names{'firstname'},
6100: lastname => $names{'lastname'},
6101: permanentemail => $emails{'permanentemail'},
6102: };
6103: }
6104: } elsif ($srch->{'srchby'} eq 'lastfirst') {
6105: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 6106: $srchlast =~ s/\s+$//;
6107: $srchfirst =~ s/^\s+//;
1.160 raeburn 6108: if ($srch->{'srchtype'} eq 'exact') {
6109: if (($names{'lastname'} eq $srchlast) &&
6110: ($names{'firstname'} eq $srchfirst)) {
6111: $srch_results{$user} = {firstname => $names{'firstname'},
6112: lastname => $names{'lastname'},
6113: permanentemail => $emails{'permanentemail'},
6114:
6115: };
6116: }
1.177 raeburn 6117: } elsif ($srch->{'srchtype'} eq 'begins') {
6118: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
6119: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
6120: $srch_results{$user} = {firstname => $names{'firstname'},
6121: lastname => $names{'lastname'},
6122: permanentemail => $emails{'permanentemail'},
6123: };
6124: }
6125: } else {
1.160 raeburn 6126: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
6127: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
6128: $srch_results{$user} = {firstname => $names{'firstname'},
6129: lastname => $names{'lastname'},
6130: permanentemail => $emails{'permanentemail'},
6131: };
6132: }
6133: }
6134: }
6135: }
1.179 raeburn 6136: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6137: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6138: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6139: $currstate = 'query';
1.160 raeburn 6140: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6141: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6142: if ($dirsrchres eq 'ok') {
6143: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6144: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6145: } else {
6146: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
6147: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6148: '</span><br />'.
6149: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6150: '<br /><br />';
6151: }
1.160 raeburn 6152: }
6153: }
1.179 raeburn 6154: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 6155: }
6156:
6157: sub directorysrch_check {
6158: my ($srch) = @_;
6159: my $can_search = 0;
6160: my $response;
6161: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
6162: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 6163: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 6164: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
6165: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 6166: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 6167: }
6168: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
6169: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 6170: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 6171: }
6172: my @usertypes = split(/:/,$env{'environment.inststatus'});
6173: if (!@usertypes) {
6174: push(@usertypes,'default');
6175: }
6176: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
6177: foreach my $type (@usertypes) {
6178: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
6179: $can_search = 1;
6180: last;
6181: }
6182: }
6183: }
6184: if (!$can_search) {
6185: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
6186: my @longtypes;
6187: foreach my $item (@usertypes) {
1.229 raeburn 6188: if (defined($insttypes->{$item})) {
6189: push (@longtypes,$insttypes->{$item});
6190: } elsif ($item eq 'default') {
6191: push (@longtypes,&mt('other'));
6192: }
1.160 raeburn 6193: }
6194: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 6195: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 6196: }
1.160 raeburn 6197: } else {
6198: $can_search = 1;
6199: }
6200: } else {
1.180 raeburn 6201: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 6202: }
6203: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 6204: uname => 'username',
1.160 raeburn 6205: lastfirst => 'last name, first name',
1.167 albertel 6206: lastname => 'last name',
1.172 raeburn 6207: contains => 'contains',
1.178 raeburn 6208: exact => 'as exact match to',
6209: begins => 'begins with',
1.160 raeburn 6210: );
6211: if ($can_search) {
6212: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
6213: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 6214: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 6215: }
6216: } else {
1.180 raeburn 6217: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 6218: }
6219: }
6220: if ($can_search) {
1.178 raeburn 6221: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
6222: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
6223: return 'ok';
6224: } else {
1.180 raeburn 6225: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 6226: }
6227: } else {
6228: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
6229: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
6230: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
6231: return 'ok';
6232: } else {
1.180 raeburn 6233: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 6234: }
1.160 raeburn 6235: }
6236: }
6237: }
6238:
6239: sub get_courseusers {
6240: my %advhash;
1.167 albertel 6241: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 6242: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
6243: foreach my $role (sort(keys(%coursepersonnel))) {
6244: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 6245: if (!exists($classlist->{$user})) {
6246: $classlist->{$user} = [];
6247: }
1.160 raeburn 6248: }
6249: }
1.167 albertel 6250: return $classlist;
1.160 raeburn 6251: }
6252:
6253: sub build_search_response {
1.221 raeburn 6254: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 6255: my ($currstate,$response,$forcenewuser);
1.160 raeburn 6256: my %names = (
1.330 bisitz 6257: 'uname' => 'username',
6258: 'lastname' => 'last name',
1.160 raeburn 6259: 'lastfirst' => 'last name, first name',
1.330 bisitz 6260: 'crs' => 'this course',
6261: 'dom' => 'LON-CAPA domain',
6262: 'instd' => 'the institutional directory for domain',
1.160 raeburn 6263: );
6264:
6265: my %single = (
1.180 raeburn 6266: begins => 'A match',
1.160 raeburn 6267: contains => 'A match',
1.180 raeburn 6268: exact => 'An exact match',
1.160 raeburn 6269: );
6270: my %nomatch = (
1.180 raeburn 6271: begins => 'No match',
1.160 raeburn 6272: contains => 'No match',
1.180 raeburn 6273: exact => 'No exact match',
1.160 raeburn 6274: );
6275: if (keys(%srch_results) > 1) {
1.179 raeburn 6276: $currstate = 'select';
1.160 raeburn 6277: } else {
6278: if (keys(%srch_results) == 1) {
1.179 raeburn 6279: $currstate = 'modify';
1.180 raeburn 6280: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
6281: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 6282: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 6283: }
1.330 bisitz 6284: } else { # Search has nothing found. Prepare message to user.
6285: $response = '<span class="LC_warning">';
1.180 raeburn 6286: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 6287: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
6288: '<b>'.$srch->{'srchterm'}.'</b>',
6289: &display_domain_info($srch->{'srchdomain'}));
6290: } else {
6291: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
6292: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 6293: }
6294: $response .= '</span>';
1.330 bisitz 6295:
1.160 raeburn 6296: if ($srch->{'srchin'} ne 'alc') {
6297: $forcenewuser = 1;
6298: my $cansrchinst = 0;
6299: if ($srch->{'srchdomain'}) {
6300: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
6301: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6302: if ($domconfig{'directorysrch'}{'available'}) {
6303: $cansrchinst = 1;
6304: }
6305: }
6306: }
1.180 raeburn 6307: if ((($srch->{'srchby'} eq 'lastfirst') ||
6308: ($srch->{'srchby'} eq 'lastname')) &&
6309: ($srch->{'srchin'} eq 'dom')) {
6310: if ($cansrchinst) {
6311: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 6312: }
6313: }
1.180 raeburn 6314: if ($srch->{'srchin'} eq 'crs') {
6315: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
6316: }
6317: }
1.305 raeburn 6318: my $createdom = $env{'request.role.domain'};
6319: if ($context eq 'requestcrs') {
6320: if ($env{'form.coursedom'} ne '') {
6321: $createdom = $env{'form.coursedom'};
6322: }
6323: }
6324: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $createdom)) {
1.221 raeburn 6325: my $cancreate =
1.305 raeburn 6326: &Apache::lonuserutils::can_create_user($createdom,$context);
6327: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 6328: if ($cancreate) {
1.305 raeburn 6329: my $showdom = &display_domain_info($createdom);
1.266 bisitz 6330: $response .= '<br /><br />'
6331: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 6332: .'<br />';
6333: if ($context eq 'requestcrs') {
6334: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
6335: } else {
6336: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
6337: }
6338: $response .='<ul><li>'
1.266 bisitz 6339: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
6340: .'</li><li>'
6341: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
6342: .'</li><li>'
6343: .&mt('Provide the proposed username')
6344: .'</li><li>'
6345: .&mt("Click 'Search'")
6346: .'</li></ul><br />';
1.221 raeburn 6347: } else {
6348: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.305 raeburn 6349: $response .= '<br /><br />';
6350: if ($context eq 'requestcrs') {
1.314 raeburn 6351: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.305 raeburn 6352: } else {
6353: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
6354: }
6355: $response .= '<br />'
6356: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 6357: ,' <a'.$helplink.'>'
6358: ,'</a>')
1.305 raeburn 6359: .'<br /><br />';
1.221 raeburn 6360: }
1.160 raeburn 6361: }
6362: }
6363: }
1.179 raeburn 6364: return ($currstate,$response,$forcenewuser);
1.160 raeburn 6365: }
6366:
1.180 raeburn 6367: sub display_domain_info {
6368: my ($dom) = @_;
6369: my $output = $dom;
6370: if ($dom ne '') {
6371: my $domdesc = &Apache::lonnet::domain($dom,'description');
6372: if ($domdesc ne '') {
6373: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
6374: }
6375: }
6376: return $output;
6377: }
6378:
1.160 raeburn 6379: sub crumb_utilities {
6380: my %elements = (
6381: crtuser => {
6382: srchterm => 'text',
1.172 raeburn 6383: srchin => 'selectbox',
1.160 raeburn 6384: srchby => 'selectbox',
6385: srchtype => 'selectbox',
6386: srchdomain => 'selectbox',
6387: },
1.207 raeburn 6388: crtusername => {
6389: srchterm => 'text',
6390: srchdomain => 'selectbox',
6391: },
1.160 raeburn 6392: docustom => {
6393: rolename => 'selectbox',
6394: newrolename => 'textbox',
6395: },
1.179 raeburn 6396: studentform => {
6397: srchterm => 'text',
6398: srchin => 'selectbox',
6399: srchby => 'selectbox',
6400: srchtype => 'selectbox',
6401: srchdomain => 'selectbox',
6402: },
1.160 raeburn 6403: );
6404:
6405: my $jsback .= qq|
6406: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 6407: if (typeof prevphase == 'undefined') {
6408: formname.phase.value = '';
6409: }
6410: else {
6411: formname.phase.value = prevphase;
6412: }
6413: if (typeof prevstate == 'undefined') {
6414: formname.currstate.value = '';
6415: }
6416: else {
6417: formname.currstate.value = prevstate;
6418: }
1.160 raeburn 6419: formname.submit();
6420: }
6421: |;
6422: return ($jsback,\%elements);
6423: }
6424:
1.26 matthew 6425: sub course_level_table {
1.89 raeburn 6426: my (%inccourses) = @_;
1.26 matthew 6427: my $table = '';
1.62 www 6428: # Custom Roles?
6429:
1.190 raeburn 6430: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 6431: my %lt=&Apache::lonlocal::texthash(
6432: 'exs' => "Existing sections",
6433: 'new' => "Define new section",
6434: 'ssd' => "Set Start Date",
6435: 'sed' => "Set End Date",
1.131 raeburn 6436: 'crl' => "Course Level",
1.89 raeburn 6437: 'act' => "Activate",
6438: 'rol' => "Role",
6439: 'ext' => "Extent",
1.113 raeburn 6440: 'grs' => "Section",
1.89 raeburn 6441: 'sta' => "Start",
6442: 'end' => "End"
6443: );
1.62 www 6444:
1.329 raeburn 6445: foreach my $protectedcourse (sort(keys(%inccourses))) {
1.135 raeburn 6446: my $thiscourse=$protectedcourse;
1.26 matthew 6447: $thiscourse=~s:_:/:g;
6448: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 6449: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 6450: my $area=$coursedata{'description'};
1.321 raeburn 6451: my $crstype=$coursedata{'type'};
1.135 raeburn 6452: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 6453: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 6454: my %sections_count;
1.101 albertel 6455: if (defined($env{'request.course.id'})) {
6456: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 6457: %sections_count =
6458: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 6459: }
6460: }
1.321 raeburn 6461: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 6462: foreach my $role (@roles) {
1.321 raeburn 6463: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 6464: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
6465: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 6466: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.329 raeburn 6467: $plrole,\%sections_count,\%lt);
1.221 raeburn 6468: } elsif ($env{'request.course.sec'} ne '') {
6469: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
6470: $env{'request.course.sec'})) {
6471: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
6472: $plrole,\%sections_count,\%lt);
1.26 matthew 6473: }
6474: }
6475: }
1.221 raeburn 6476: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 6477: foreach my $cust (sort(keys(%customroles))) {
6478: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 6479: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
6480: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
6481: $cust,\%sections_count,\%lt);
6482: }
1.62 www 6483: }
1.26 matthew 6484: }
6485: return '' if ($table eq ''); # return nothing if there is nothing
6486: # in the table
1.188 raeburn 6487: my $result;
6488: if (!$env{'request.course.id'}) {
6489: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
6490: }
6491: $result .=
1.136 raeburn 6492: &Apache::loncommon::start_data_table().
6493: &Apache::loncommon::start_data_table_header_row().
6494: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
6495: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
6496: &Apache::loncommon::end_data_table_header_row().
6497: $table.
6498: &Apache::loncommon::end_data_table();
1.26 matthew 6499: return $result;
6500: }
1.88 raeburn 6501:
1.221 raeburn 6502: sub course_level_row {
6503: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_;
1.222 raeburn 6504: my $row = &Apache::loncommon::start_data_table_row().
6505: ' <td><input type="checkbox" name="act_'.
6506: $protectedcourse.'_'.$role.'" /></td>'."\n".
6507: ' <td>'.$plrole.'</td>'."\n".
6508: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.322 raeburn 6509: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 6510: $row .= '<td> </td>';
1.221 raeburn 6511: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 6512: $row .= ' <td><input type="hidden" value="'.
6513: $env{'request.course.sec'}.'" '.
6514: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
6515: $env{'request.course.sec'}.'</td>';
1.221 raeburn 6516: } else {
6517: if (ref($sections_count) eq 'HASH') {
6518: my $currsec =
6519: &Apache::lonuserutils::course_sections($sections_count,
6520: $protectedcourse.'_'.$role);
1.222 raeburn 6521: $row .= '<td><table class="LC_createuser">'."\n".
6522: '<tr class="LC_section_row">'."\n".
6523: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
6524: $currsec.'</td>'."\n".
6525: ' <td> </td>'."\n".
6526: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 6527: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
6528: '" value="" />'.
6529: '<input type="hidden" '.
6530: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 6531: '</tr></table></td>'."\n";
1.221 raeburn 6532: } else {
1.222 raeburn 6533: $row .= '<td><input type="text" size="10" '.
6534: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 6535: }
6536: }
1.222 raeburn 6537: $row .= <<ENDTIMEENTRY;
6538: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 6539: <a href=
6540: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$role.value,'start_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'ssd'}</a></td>
1.222 raeburn 6541: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 6542: <a href=
6543: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
6544: ENDTIMEENTRY
1.222 raeburn 6545: $row .= &Apache::loncommon::end_data_table_row();
6546: return $row;
1.221 raeburn 6547: }
6548:
1.88 raeburn 6549: sub course_level_dc {
6550: my ($dcdom) = @_;
1.190 raeburn 6551: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 6552: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 6553: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
6554: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 6555: '<input type="hidden" name="dccourse" value="" />';
1.355 www 6556: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 6557: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.323 raeburn 6558: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser');
1.88 raeburn 6559: my %lt=&Apache::lonlocal::texthash(
6560: 'rol' => "Role",
1.113 raeburn 6561: 'grs' => "Section",
1.88 raeburn 6562: 'exs' => "Existing sections",
6563: 'new' => "Define new section",
6564: 'sta' => "Start",
6565: 'end' => "End",
6566: 'ssd' => "Set Start Date",
1.355 www 6567: 'sed' => "Set End Date",
6568: 'scc' => "Course/Community"
1.88 raeburn 6569: );
1.323 raeburn 6570: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 6571: &Apache::loncommon::start_data_table().
6572: &Apache::loncommon::start_data_table_header_row().
1.355 www 6573: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 6574: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 6575: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 6576: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
6577: $courseform.(' ' x4).'</span></td>'."\n".
1.323 raeburn 6578: '<td valign><br /><select name="role">'."\n";
1.213 raeburn 6579: foreach my $role (@roles) {
1.135 raeburn 6580: my $plrole=&Apache::lonnet::plaintext($role);
6581: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 6582: }
6583: if ( keys %customroles > 0) {
1.135 raeburn 6584: foreach my $cust (sort keys %customroles) {
1.101 albertel 6585: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 6586: '_'.$env{'user.name'}.'_'.$cust;
6587: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 6588: }
6589: }
6590: $otheritems .= '</select></td><td>'.
6591: '<table border="0" cellspacing="0" cellpadding="0">'.
6592: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
6593: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
6594: '<td> </td>'.
6595: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 6596: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 6597: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 6598: '<input type="hidden" name="groups" value="" />'.
6599: '<input type="hidden" name="crstype" value="" /></td>'.
1.88 raeburn 6600: '</tr></table></td>';
6601: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 6602: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 6603: <a href=
6604: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 6605: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 6606: <a href=
6607: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
6608: ENDTIMEENTRY
1.136 raeburn 6609: $otheritems .= &Apache::loncommon::end_data_table_row().
6610: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 6611: return $cb_jscript.$header.$hiddenitems.$otheritems;
6612: }
6613:
1.237 raeburn 6614: sub update_selfenroll_config {
1.241 raeburn 6615: my ($r,$context,$permission) = @_;
1.237 raeburn 6616: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 6617: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 6618: my (%changes,%warning);
6619: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6620: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 6621: my $curr_types;
1.237 raeburn 6622: if (ref($row) eq 'ARRAY') {
6623: foreach my $item (@{$row}) {
6624: if ($item eq 'enroll_dates') {
6625: my (%currenrolldate,%newenrolldate);
6626: foreach my $type ('start','end') {
6627: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
6628: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
6629: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
6630: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
6631: }
6632: }
6633: } elsif ($item eq 'access_dates') {
6634: my (%currdate,%newdate);
6635: foreach my $type ('start','end') {
6636: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
6637: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
6638: if ($newdate{$type} ne $currdate{$type}) {
6639: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
6640: }
6641: }
1.241 raeburn 6642: } elsif ($item eq 'types') {
6643: $curr_types =
6644: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
6645: if ($env{'form.selfenroll_all'}) {
6646: if ($curr_types ne '*') {
6647: $changes{'internal.selfenroll_types'} = '*';
6648: } else {
6649: next;
6650: }
6651: } else {
1.249 raeburn 6652: my %currdoms;
1.241 raeburn 6653: my @entries = split(/;/,$curr_types);
6654: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 6655: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 6656: my $newnum = 0;
1.249 raeburn 6657: my @latesttypes;
6658: foreach my $num (@activations) {
6659: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
6660: if (@types > 0) {
1.241 raeburn 6661: @types = sort(@types);
6662: my $typestr = join(',',@types);
1.249 raeburn 6663: my $typedom = $env{'form.selfenroll_dom_'.$num};
6664: $latesttypes[$newnum] = $typedom.':'.$typestr;
6665: $currdoms{$typedom} = 1;
1.241 raeburn 6666: $newnum ++;
6667: }
6668: }
1.338 raeburn 6669: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
6670: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 6671: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
6672: if (@types > 0) {
6673: @types = sort(@types);
6674: my $typestr = join(',',@types);
6675: my $typedom = $env{'form.selfenroll_dom_'.$j};
6676: $latesttypes[$newnum] = $typedom.':'.$typestr;
6677: $currdoms{$typedom} = 1;
6678: $newnum ++;
6679: }
6680: }
6681: }
6682: if ($env{'form.selfenroll_newdom'} ne '') {
6683: my $typedom = $env{'form.selfenroll_newdom'};
6684: if ((!defined($currdoms{$typedom})) &&
6685: (&Apache::lonnet::domain($typedom) ne '')) {
6686: my $typestr;
6687: my ($othertitle,$usertypes,$types) =
6688: &Apache::loncommon::sorted_inst_types($typedom);
6689: my $othervalue = 'any';
6690: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6691: if (@{$types} > 0) {
1.257 raeburn 6692: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 6693: $othervalue = 'other';
1.258 raeburn 6694: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 6695: }
6696: $typestr = $othervalue;
6697: } else {
6698: $typestr = $othervalue;
6699: }
6700: $latesttypes[$newnum] = $typedom.':'.$typestr;
6701: $newnum ++ ;
6702: }
6703: }
1.241 raeburn 6704: my $selfenroll_types = join(';',@latesttypes);
6705: if ($selfenroll_types ne $curr_types) {
6706: $changes{'internal.selfenroll_types'} = $selfenroll_types;
6707: }
6708: }
1.276 raeburn 6709: } elsif ($item eq 'limit') {
6710: my $newlimit = $env{'form.selfenroll_limit'};
6711: my $newcap = $env{'form.selfenroll_cap'};
6712: $newcap =~s/\s+//g;
6713: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
6714: $currlimit = 'none' if ($currlimit eq '');
6715: my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
6716: if ($newlimit ne $currlimit) {
6717: if ($newlimit ne 'none') {
6718: if ($newcap =~ /^\d+$/) {
6719: if ($newcap ne $currcap) {
6720: $changes{'internal.selfenroll_cap'} = $newcap;
6721: }
6722: $changes{'internal.selfenroll_limit'} = $newlimit;
6723: } else {
6724: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.&mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
6725: }
6726: } elsif ($currcap ne '') {
6727: $changes{'internal.selfenroll_cap'} = '';
6728: $changes{'internal.selfenroll_limit'} = $newlimit;
6729: }
6730: } elsif ($currlimit ne 'none') {
6731: if ($newcap =~ /^\d+$/) {
6732: if ($newcap ne $currcap) {
6733: $changes{'internal.selfenroll_cap'} = $newcap;
6734: }
6735: } else {
6736: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.&mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
6737: }
6738: }
6739: } elsif ($item eq 'approval') {
6740: my (@currnotified,@newnotified);
6741: my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
6742: my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
6743: if ($currnotifylist ne '') {
6744: @currnotified = split(/,/,$currnotifylist);
6745: @currnotified = sort(@currnotified);
6746: }
6747: my $newapproval = $env{'form.selfenroll_approval'};
6748: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
6749: @newnotified = sort(@newnotified);
6750: if ($newapproval ne $currapproval) {
6751: $changes{'internal.selfenroll_approval'} = $newapproval;
6752: if (!$newapproval) {
6753: if ($currnotifylist ne '') {
6754: $changes{'internal.selfenroll_notifylist'} = '';
6755: }
6756: } else {
6757: my @differences =
1.295 raeburn 6758: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 6759: if (@differences > 0) {
6760: if (@newnotified > 0) {
6761: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6762: } else {
6763: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6764: }
6765: }
6766: }
6767: } else {
1.295 raeburn 6768: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 6769: if (@differences > 0) {
6770: if (@newnotified > 0) {
6771: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6772: } else {
6773: $changes{'internal.selfenroll_notifylist'} = '';
6774: }
6775: }
6776: }
1.237 raeburn 6777: } else {
6778: my $curr_val =
6779: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
6780: my $newval = $env{'form.selfenroll_'.$item};
6781: if ($item eq 'section') {
6782: $newval = $env{'form.sections'};
1.241 raeburn 6783: if (defined($curr_groups{$newval})) {
1.237 raeburn 6784: $newval = $curr_val;
6785: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.&mt('Group names and section names must be distinct');
6786: } elsif ($newval eq 'all') {
6787: $newval = $curr_val;
1.274 bisitz 6788: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 6789: }
6790: if ($newval eq '') {
6791: $newval = 'none';
6792: }
6793: }
6794: if ($newval ne $curr_val) {
6795: $changes{'internal.selfenroll_'.$item} = $newval;
6796: }
1.241 raeburn 6797: }
1.237 raeburn 6798: }
6799: if (keys(%warning) > 0) {
6800: foreach my $item (@{$row}) {
6801: if (exists($warning{$item})) {
6802: $r->print($warning{$item}.'<br />');
6803: }
6804: }
6805: }
6806: if (keys(%changes) > 0) {
6807: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
6808: if ($putresult eq 'ok') {
6809: if ((exists($changes{'internal.selfenroll_types'})) ||
6810: (exists($changes{'internal.selfenroll_start_date'})) ||
6811: (exists($changes{'internal.selfenroll_end_date'}))) {
6812: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
6813: $cnum,undef,undef,'Course');
6814: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
6815: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
6816: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
6817: if (exists($changes{'internal.'.$item})) {
6818: $crsinfo{$env{'request.course.id'}}{$item} =
6819: $changes{'internal.'.$item};
6820: }
6821: }
6822: my $crsputresult =
6823: &Apache::lonnet::courseidput($cdom,\%crsinfo,
6824: $chome,'notime');
6825: }
6826: }
6827: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
6828: foreach my $item (@{$row}) {
6829: my $title = $item;
6830: if (ref($lt) eq 'HASH') {
6831: $title = $lt->{$item};
6832: }
6833: if ($item eq 'enroll_dates') {
6834: foreach my $type ('start','end') {
6835: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
6836: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 6837: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 6838: $title,$type,$newdate).'</li>');
6839: }
6840: }
6841: } elsif ($item eq 'access_dates') {
6842: foreach my $type ('start','end') {
6843: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
6844: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 6845: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 6846: $title,$type,$newdate).'</li>');
6847: }
6848: }
1.276 raeburn 6849: } elsif ($item eq 'limit') {
6850: if ((exists($changes{'internal.selfenroll_limit'})) ||
6851: (exists($changes{'internal.selfenroll_cap'}))) {
6852: my ($newval,$newcap);
6853: if ($changes{'internal.selfenroll_cap'} ne '') {
6854: $newcap = $changes{'internal.selfenroll_cap'}
6855: } else {
6856: $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
6857: }
6858: if ($changes{'internal.selfenroll_limit'} eq 'none') {
6859: $newval = &mt('No limit');
6860: } elsif ($changes{'internal.selfenroll_limit'} eq
6861: 'allstudents') {
6862: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
6863: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
6864: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
6865: } else {
6866: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
6867: if ($currlimit eq 'allstudents') {
6868: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
6869: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 6870: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 6871: }
6872: }
6873: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
6874: }
6875: } elsif ($item eq 'approval') {
6876: if ((exists($changes{'internal.selfenroll_approval'})) ||
6877: (exists($changes{'internal.selfenroll_notifylist'}))) {
6878: my ($newval,$newnotify);
6879: if (exists($changes{'internal.selfenroll_notifylist'})) {
6880: $newnotify = $changes{'internal.selfenroll_notifylist'};
6881: } else {
6882: $newnotify = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
6883: }
6884: if ($changes{'internal.selfenroll_approval'}) {
6885: $newval = &mt('Yes');
6886: } elsif ($changes{'internal.selfenroll_approval'} eq '0') {
6887: $newval = &mt('No');
6888: } else {
6889: my $currapproval =
6890: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
6891: if ($currapproval) {
6892: $newval = &mt('Yes');
6893: } else {
6894: $newval = &mt('No');
6895: }
6896: }
6897: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
6898: if ($newnotify) {
1.277 raeburn 6899: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 6900: } else {
1.277 raeburn 6901: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 6902: }
6903: $r->print('</li>'."\n");
6904: }
1.237 raeburn 6905: } else {
6906: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 6907: my $newval = $changes{'internal.selfenroll_'.$item};
6908: if ($item eq 'types') {
6909: if ($newval eq '') {
6910: $newval = &mt('None');
6911: } elsif ($newval eq '*') {
6912: $newval = &mt('Any user in any domain');
6913: }
1.245 raeburn 6914: } elsif ($item eq 'registered') {
6915: if ($newval eq '1') {
6916: $newval = &mt('Yes');
6917: } elsif ($newval eq '0') {
6918: $newval = &mt('No');
6919: }
1.241 raeburn 6920: }
1.244 bisitz 6921: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 6922: }
6923: }
6924: }
6925: $r->print('</ul>');
6926: my %newenvhash;
6927: foreach my $key (keys(%changes)) {
6928: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
6929: }
1.238 raeburn 6930: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 6931: } else {
6932: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
6933: }
6934: } else {
1.249 raeburn 6935: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 6936: }
6937: } else {
1.249 raeburn 6938: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 6939: }
1.256 raeburn 6940: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
6941: if (ref($visactions) eq 'HASH') {
6942: if (!$visible) {
1.366 bisitz 6943: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.256 raeburn 6944: '<br />');
6945: if (ref($vismsgs) eq 'ARRAY') {
6946: $r->print('<br />'.$visactions->{'take'}.'<ul>');
6947: foreach my $item (@{$vismsgs}) {
6948: $r->print('<li>'.$visactions->{$item}.'</li>');
6949: }
6950: $r->print('</ul>');
6951: }
6952: $r->print($cansetvis);
6953: }
6954: }
1.237 raeburn 6955: return;
6956: }
6957:
6958: sub get_selfenroll_titles {
1.276 raeburn 6959: my @row = ('types','registered','enroll_dates','access_dates','section',
6960: 'approval','limit');
1.237 raeburn 6961: my %lt = &Apache::lonlocal::texthash (
6962: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 6963: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 6964: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 6965: access_dates => 'Course access dates assigned to self-enrolling users',
6966: section => 'Section assigned to self-enrolling users',
1.276 raeburn 6967: approval => 'Self-enrollment requests need approval?',
6968: limit => 'Enrollment limit',
1.237 raeburn 6969: );
6970: return (\@row,\%lt);
6971: }
6972:
1.27 matthew 6973: #---------------------------------------------- end functions for &phase_two
1.29 matthew 6974:
6975: #--------------------------------- functions for &phase_two and &phase_three
6976:
6977: #--------------------------end of functions for &phase_two and &phase_three
1.367 golterma 6978: sub cid_to_cname(){
6979: my $courseid = shift;
6980: $courseid =~ s/^\///;
6981: $courseid =~ s/\//_/;
6982: return $env{'course.'.$courseid.'.description'};
6983: }
1.1 www 6984: 1;
6985: __END__
1.2 www 6986:
6987:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>