Annotation of loncom/interface/loncreateuser.pm, revision 1.409
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.409 ! raeburn 4: # $Id: loncreateuser.pm,v 1.408 2016/02/17 19:15:48 raeburn 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:
1.378 raeburn 125: sub user_quotas {
1.134 raeburn 126: my ($ccuname,$ccdomain) = @_;
127: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 128: 'usrt' => "User Tools",
129: 'cust' => "Custom quota",
130: 'chqu' => "Change quota",
1.134 raeburn 131: );
1.378 raeburn 132:
1.149 raeburn 133: my $quota_javascript = <<"END_SCRIPT";
134: <script type="text/javascript">
1.301 bisitz 135: // <![CDATA[
1.378 raeburn 136: function quota_changes(caller,context) {
137: var customoff = document.getElementById('custom_'+context+'quota_off');
138: var customon = document.getElementById('custom_'+context+'quota_on');
139: var number = document.getElementById(context+'quota');
1.149 raeburn 140: if (caller == "custom") {
1.378 raeburn 141: if (customoff) {
142: if (customoff.checked) {
143: number.value = "";
144: }
1.149 raeburn 145: }
146: }
147: if (caller == "quota") {
1.378 raeburn 148: if (customon) {
149: customon.checked = true;
150: }
1.149 raeburn 151: }
1.378 raeburn 152: return;
1.149 raeburn 153: }
1.301 bisitz 154: // ]]>
1.149 raeburn 155: </script>
156: END_SCRIPT
1.378 raeburn 157: my $longinsttype;
158: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
1.267 raeburn 159: my $output = $quota_javascript."\n".
160: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
161: &Apache::loncommon::start_data_table();
162:
163: if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1.275 raeburn 164: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 165: }
1.378 raeburn 166:
167: my %titles = &Apache::lonlocal::texthash (
168: portfolio => "Disk space allocated to user's portfolio files",
1.385 bisitz 169: author => "Disk space allocated to user's Authoring Space (if role assigned)",
1.378 raeburn 170: );
171: foreach my $name ('portfolio','author') {
172: my ($currquota,$quotatype,$inststatus,$defquota) =
173: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
174: if ($longinsttype eq '') {
175: if ($inststatus ne '') {
176: if ($usertypes->{$inststatus} ne '') {
177: $longinsttype = $usertypes->{$inststatus};
178: }
179: }
180: }
181: my ($showquota,$custom_on,$custom_off,$defaultinfo);
182: $custom_on = ' ';
183: $custom_off = ' checked="checked" ';
184: if ($quotatype eq 'custom') {
185: $custom_on = $custom_off;
186: $custom_off = ' ';
187: $showquota = $currquota;
188: if ($longinsttype eq '') {
189: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 raeburn 190: .' MB.',$defquota);
1.378 raeburn 191: } else {
192: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 raeburn 193: " MB, as determined by the user's institutional".
1.378 raeburn 194: " affiliation ([_2]).",$defquota,$longinsttype);
195: }
196: } else {
197: if ($longinsttype eq '') {
198: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 raeburn 199: .' MB.',$defquota);
1.378 raeburn 200: } else {
201: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 raeburn 202: " MB, is determined by the user's institutional".
1.378 raeburn 203: " affiliation ([_2]).",$defquota,$longinsttype);
204: }
205: }
206:
207: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
208: $output .= '<tr class="LC_info_row">'."\n".
209: ' <td>'.$titles{$name}.'</td>'."\n".
210: ' </tr>'."\n".
211: &Apache::loncommon::start_data_table_row()."\n".
1.390 bisitz 212: ' <td><span class="LC_nobreak">'.
213: &mt('Current quota: [_1] MB',$currquota).'</span> '.
1.378 raeburn 214: $defaultinfo.'</td>'."\n".
215: &Apache::loncommon::end_data_table_row()."\n".
216: &Apache::loncommon::start_data_table_row()."\n".
217: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
218: ': <label>'.
219: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
1.379 raeburn 220: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.390 bisitz 221: ' /><span class="LC_nobreak">'.
222: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
1.378 raeburn 223: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
1.379 raeburn 224: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.378 raeburn 225: ' />'.$lt{'cust'}.':</label> '.
1.379 raeburn 226: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
227: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
1.390 bisitz 228: ' /> '.&mt('MB').'</span></td>'."\n".
1.378 raeburn 229: &Apache::loncommon::end_data_table_row()."\n";
230: }
231: }
1.267 raeburn 232: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 233: return $output;
234: }
235:
1.275 raeburn 236: sub build_tools_display {
237: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 238: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 239: $colspan,$isadv,%domconfig);
1.275 raeburn 240: my %lt = &Apache::lonlocal::texthash (
241: 'blog' => "Personal User Blog",
242: 'aboutme' => "Personal Information Page",
1.385 bisitz 243: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
1.275 raeburn 244: 'portfolio' => "Personal User Portfolio",
245: 'avai' => "Available",
246: 'cusa' => "availability",
247: 'chse' => "Change setting",
248: 'usde' => "Use default",
249: 'uscu' => "Use custom",
250: 'official' => 'Can request creation of official courses',
1.299 raeburn 251: 'unofficial' => 'Can request creation of unofficial courses',
252: 'community' => 'Can request creation of communities',
1.384 raeburn 253: 'textbook' => 'Can request creation of textbook courses',
1.362 raeburn 254: 'requestauthor' => 'Can request author space',
1.275 raeburn 255: );
1.279 raeburn 256: if ($context eq 'requestcourses') {
1.275 raeburn 257: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 258: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 259: 'requestcourses.community','requestcourses.textbook');
260: @usertools = ('official','unofficial','community','textbook');
1.309 raeburn 261: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 262: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
263: %reqtitles = &courserequest_titles();
264: %reqdisplay = &courserequest_display();
265: $colspan = ' colspan="2"';
1.332 raeburn 266: %domconfig =
267: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
268: $isadv = &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1.362 raeburn 269: } elsif ($context eq 'requestauthor') {
270: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
271: 'requestauthor');
272: @usertools = ('requestauthor');
273: @options =('norequest','approval','automatic');
274: %reqtitles = &requestauthor_titles();
275: %reqdisplay = &requestauthor_display();
276: $colspan = ' colspan="2"';
277: %domconfig =
278: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 279: } else {
280: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 281: 'tools.aboutme','tools.portfolio','tools.blog',
282: 'tools.webdav');
283: @usertools = ('aboutme','blog','webdav','portfolio');
1.275 raeburn 284: }
285: foreach my $item (@usertools) {
1.306 raeburn 286: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
287: $currdisp,$custdisp,$custradio);
1.275 raeburn 288: $cust_off = 'checked="checked" ';
289: $tool_on = 'checked="checked" ';
290: $curr_access =
291: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
292: $context);
1.362 raeburn 293: if ($context eq 'requestauthor') {
294: if ($userenv{$context} ne '') {
295: $cust_on = ' checked="checked" ';
296: $cust_off = '';
297: }
298: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 299: $cust_on = ' checked="checked" ';
300: $cust_off = '';
301: }
302: if ($context eq 'requestcourses') {
303: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 304: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 305: } else {
306: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 307: }
1.362 raeburn 308: } elsif ($context eq 'requestauthor') {
309: if ($userenv{$context} eq '') {
310: $custom_access = &mt('Currently from default setting.');
311: } else {
312: $custom_access = &mt('Currently from custom setting.');
313: }
1.275 raeburn 314: } else {
1.306 raeburn 315: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 316: $custom_access =
1.306 raeburn 317: &mt('Availability determined currently from default setting.');
318: if (!$curr_access) {
319: $tool_off = 'checked="checked" ';
320: $tool_on = '';
321: }
322: } else {
1.314 raeburn 323: $custom_access =
1.306 raeburn 324: &mt('Availability determined currently from custom setting.');
325: if ($userenv{$context.'.'.$item} == 0) {
326: $tool_off = 'checked="checked" ';
327: $tool_on = '';
328: }
1.275 raeburn 329: }
330: }
331: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 332: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 333: ' </tr>'."\n".
1.306 raeburn 334: &Apache::loncommon::start_data_table_row()."\n";
1.362 raeburn 335: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 336: my ($curroption,$currlimit);
1.362 raeburn 337: my $envkey = $context.'.'.$item;
338: if ($context eq 'requestauthor') {
339: $envkey = $context;
340: }
341: if ($userenv{$envkey} ne '') {
342: $curroption = $userenv{$envkey};
1.332 raeburn 343: } else {
344: my (@inststatuses);
1.362 raeburn 345: if ($context eq 'requestcourses') {
346: $curroption =
347: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
348: $isadv,$ccdomain,$item,
349: \@inststatuses,\%domconfig);
350: } else {
351: $curroption =
352: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
353: $isadv,$ccdomain,undef,
354: \@inststatuses,\%domconfig);
355: }
1.332 raeburn 356: }
1.306 raeburn 357: if (!$curroption) {
358: $curroption = 'norequest';
359: }
360: if ($curroption =~ /^autolimit=(\d*)$/) {
361: $currlimit = $1;
1.314 raeburn 362: if ($currlimit eq '') {
363: $currdisp = &mt('Yes, automatic creation');
364: } else {
365: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
366: }
1.306 raeburn 367: } else {
368: $currdisp = $reqdisplay{$curroption};
369: }
370: $custdisp = '<table>';
371: foreach my $option (@options) {
372: my $val = $option;
373: if ($option eq 'norequest') {
374: $val = 0;
375: }
376: if ($option eq 'validate') {
377: my $canvalidate = 0;
378: if (ref($validations{$item}) eq 'HASH') {
379: if ($validations{$item}{'_custom_'}) {
380: $canvalidate = 1;
381: }
382: }
383: next if (!$canvalidate);
384: }
385: my $checked = '';
386: if ($option eq $curroption) {
387: $checked = ' checked="checked"';
388: } elsif ($option eq 'autolimit') {
389: if ($curroption =~ /^autolimit/) {
390: $checked = ' checked="checked"';
391: }
392: }
1.362 raeburn 393: my $name = 'crsreq_'.$item;
394: if ($context eq 'requestauthor') {
395: $name = $item;
396: }
1.306 raeburn 397: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 398: '<input type="radio" name="'.$name.'" '.
399: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 400: $reqtitles{$option}.'</label> ';
401: if ($option eq 'autolimit') {
1.362 raeburn 402: $custdisp .= '<input type="text" name="'.$name.
403: '_limit" size="1" '.
1.314 raeburn 404: 'value="'.$currlimit.'" /></span><br />'.
405: $reqtitles{'unlimited'};
1.362 raeburn 406: } else {
407: $custdisp .= '</span>';
408: }
409: $custdisp .= '</td></tr>';
1.306 raeburn 410: }
411: $custdisp .= '</table>';
412: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
413: } else {
414: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 415: my $name = $context.'_'.$item;
416: if ($context eq 'requestauthor') {
417: $name = $context;
418: }
1.306 raeburn 419: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 420: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 421: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 422: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 423: $tool_off.'/>'.&mt('Off').'</label></span>';
424: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
425: '</span>';
426: }
427: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
428: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.275 raeburn 429: &Apache::loncommon::end_data_table_row()."\n".
430: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 431: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
432: $lt{'chse'}.': <label>'.
1.275 raeburn 433: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 434: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
435: '<label><input type="radio" name="custom'.$item.'" value="1" '.
436: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 437: &Apache::loncommon::end_data_table_row()."\n";
438: }
439: return $output;
440: }
441:
1.300 raeburn 442: sub coursereq_externaluser {
443: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 444: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 445: my %lt = &Apache::lonlocal::texthash (
446: 'official' => 'Can request creation of official courses',
447: 'unofficial' => 'Can request creation of unofficial courses',
448: 'community' => 'Can request creation of communities',
1.384 raeburn 449: 'textbook' => 'Can request creation of textbook courses',
1.300 raeburn 450: );
451:
452: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
453: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.384 raeburn 454: 'reqcrsotherdom.community','reqcrsotherdom.textbook');
455: @usertools = ('official','unofficial','community','textbook');
1.309 raeburn 456: @options = ('approval','validate','autolimit');
1.306 raeburn 457: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
458: my $optregex = join('|',@options);
459: my %reqtitles = &courserequest_titles();
1.300 raeburn 460: foreach my $item (@usertools) {
1.306 raeburn 461: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 462: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
463: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 464: foreach my $req (@curr) {
465: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
466: $curroption = $1;
467: $currlimit = $2;
468: last;
1.306 raeburn 469: }
470: }
1.314 raeburn 471: if (!$curroption) {
472: $curroption = 'norequest';
473: $tooloff = ' checked="checked"';
474: }
1.306 raeburn 475: } else {
476: $curroption = 'norequest';
477: $tooloff = ' checked="checked"';
478: }
479: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 480: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
481: '<table><tr><td valign="top">'."\n".
1.306 raeburn 482: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 483: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
484: '</label></td>';
1.306 raeburn 485: foreach my $option (@options) {
486: if ($option eq 'validate') {
487: my $canvalidate = 0;
488: if (ref($validations{$item}) eq 'HASH') {
489: if ($validations{$item}{'_external_'}) {
490: $canvalidate = 1;
491: }
492: }
493: next if (!$canvalidate);
494: }
495: my $checked = '';
496: if ($option eq $curroption) {
497: $checked = ' checked="checked"';
498: }
1.314 raeburn 499: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 500: '<input type="radio" name="reqcrsotherdom_'.$item.
501: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 502: $reqtitles{$option}.'</label>';
1.306 raeburn 503: if ($option eq 'autolimit') {
1.314 raeburn 504: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 505: $item.'_limit" size="1" '.
1.314 raeburn 506: 'value="'.$currlimit.'" /></span>'.
507: '<br />'.$reqtitles{'unlimited'};
508: } else {
509: $output .= '</span>';
1.300 raeburn 510: }
1.314 raeburn 511: $output .= '</td>';
1.300 raeburn 512: }
1.314 raeburn 513: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 514: &Apache::loncommon::end_data_table_row()."\n";
515: }
516: return $output;
517: }
518:
1.362 raeburn 519: sub domainrole_req {
520: my ($ccuname,$ccdomain) = @_;
521: return '<br /><h3>'.
522: &mt('User Can Request Assignment of Domain Roles?').
523: '</h3>'."\n".
524: &Apache::loncommon::start_data_table().
525: &build_tools_display($ccuname,$ccdomain,
526: 'requestauthor').
527: &Apache::loncommon::end_data_table();
528: }
529:
1.306 raeburn 530: sub courserequest_titles {
531: my %titles = &Apache::lonlocal::texthash (
532: official => 'Official',
533: unofficial => 'Unofficial',
534: community => 'Communities',
1.384 raeburn 535: textbook => 'Textbook',
1.306 raeburn 536: norequest => 'Not allowed',
1.309 raeburn 537: approval => 'Approval by Dom. Coord.',
1.306 raeburn 538: validate => 'With validation',
539: autolimit => 'Numerical limit',
1.314 raeburn 540: unlimited => '(blank for unlimited)',
1.306 raeburn 541: );
542: return %titles;
543: }
544:
545: sub courserequest_display {
546: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 547: approval => 'Yes, need approval',
1.306 raeburn 548: validate => 'Yes, with validation',
549: norequest => 'No',
550: );
551: return %titles;
552: }
553:
1.362 raeburn 554: sub requestauthor_titles {
555: my %titles = &Apache::lonlocal::texthash (
556: norequest => 'Not allowed',
557: approval => 'Approval by Dom. Coord.',
558: automatic => 'Automatic approval',
559: );
560: return %titles;
561:
562: }
563:
564: sub requestauthor_display {
565: my %titles = &Apache::lonlocal::texthash (
566: approval => 'Yes, need approval',
567: automatic => 'Yes, automatic approval',
568: norequest => 'No',
569: );
570: return %titles;
571: }
572:
1.383 raeburn 573: sub requestchange_display {
574: my %titles = &Apache::lonlocal::texthash (
575: approval => "availability set to 'on' (approval required)",
576: automatic => "availability set to 'on' (automatic approval)",
577: norequest => "availability set to 'off'",
578: );
579: return %titles;
580: }
581:
1.362 raeburn 582: sub curr_requestauthor {
583: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
584: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
585: if ($uname eq '' || $udom eq '') {
586: $uname = $env{'user.name'};
587: $udom = $env{'user.domain'};
588: $isadv = $env{'user.adv'};
589: }
590: my (%userenv,%settings,$val);
591: my @options = ('automatic','approval');
592: %userenv =
593: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
594: if ($userenv{'requestauthor'}) {
595: $val = $userenv{'requestauthor'};
596: @{$inststatuses} = ('_custom_');
597: } else {
598: my %alltasks;
599: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
600: %settings = %{$domconfig->{'requestauthor'}};
601: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
602: $val = $settings{'_LC_adv'};
603: @{$inststatuses} = ('_LC_adv_');
604: } else {
605: if ($userenv{'inststatus'} ne '') {
606: @{$inststatuses} = split(',',$userenv{'inststatus'});
607: } else {
608: @{$inststatuses} = ('default');
609: }
610: foreach my $status (@{$inststatuses}) {
611: if (exists($settings{$status})) {
612: my $value = $settings{$status};
613: next unless ($value);
614: unless (exists($alltasks{$value})) {
615: if (ref($alltasks{$value}) eq 'ARRAY') {
616: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
617: push(@{$alltasks{$value}},$status);
618: }
619: } else {
620: @{$alltasks{$value}} = ($status);
621: }
622: }
623: }
624: }
625: foreach my $option (@options) {
626: if ($alltasks{$option}) {
627: $val = $option;
628: last;
629: }
630: }
631: }
632: }
633: }
634: return $val;
635: }
636:
1.2 www 637: # =================================================================== Phase one
1.1 www 638:
1.42 matthew 639: sub print_username_entry_form {
1.351 raeburn 640: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum) = @_;
1.101 albertel 641: my $defdom=$env{'request.role.domain'};
1.160 raeburn 642: my $formtoset = 'crtuser';
643: if (exists($env{'form.startrolename'})) {
644: $formtoset = 'docustom';
645: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 646: } elsif ($env{'form.origform'} eq 'crtusername') {
647: $formtoset = $env{'form.origform'};
1.160 raeburn 648: }
649:
650: my ($jsback,$elements) = &crumb_utilities();
651:
652: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 653: '<script type="text/javascript">'."\n".
1.301 bisitz 654: '// <![CDATA['."\n".
655: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
656: '// ]]>'."\n".
1.162 raeburn 657: '</script>'."\n";
1.160 raeburn 658:
1.324 raeburn 659: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
660: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
661: && (&Apache::lonnet::allowed('mcr','/'))) {
662: $jscript .= &customrole_javascript();
663: }
1.224 raeburn 664: my $helpitem = 'Course_Change_Privileges';
665: if ($env{'form.action'} eq 'custom') {
666: $helpitem = 'Course_Editing_Custom_Roles';
667: } elsif ($env{'form.action'} eq 'singlestudent') {
668: $helpitem = 'Course_Add_Student';
669: }
1.351 raeburn 670: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
671: if ($env{'form.action'} eq 'custom') {
672: push(@{$brcrum},
673: {href=>"javascript:backPage(document.crtuser)",
674: text=>"Pick custom role",
675: help => $helpitem,}
676: );
677: } else {
678: push (@{$brcrum},
679: {href => "javascript:backPage(document.crtuser)",
680: text => $breadcrumb_text{'search'},
681: help => $helpitem,
682: faq => 282,
683: bug => 'Instructor Interface',}
684: );
685: }
686: my %loaditems = (
687: 'onload' => "javascript:setFormElements(document.$formtoset)",
688: );
689: my $args = {bread_crumbs => $brcrum,
690: bread_crumbs_component => 'User Management',
691: add_entries => \%loaditems,};
692: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
693:
1.71 sakharuk 694: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 695: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 696: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 697: 'srad' => 'Search for a user and modify/add user information or roles',
1.71 sakharuk 698: 'usr' => "Username",
699: 'dom' => "Domain",
1.324 raeburn 700: 'ecrp' => "Define or Edit Custom Role",
701: 'nr' => "role name",
1.282 schafran 702: 'cre' => "Next",
1.71 sakharuk 703: );
1.351 raeburn 704:
1.214 raeburn 705: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 706: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 707: my $newroletext = &mt('Define new custom role:');
708: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
709: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
710: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
711: '<h3>'.$lt{'ecrp'}.'</h3>'.
712: &Apache::loncommon::start_data_table().
713: &Apache::loncommon::start_data_table_row().
714: '<td>');
715: if (keys(%existingroles) > 0) {
716: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
717: } else {
718: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
719: }
720: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
721: &Apache::loncommon::end_data_table_row());
722: if (keys(%existingroles) > 0) {
723: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
724: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
725: &mt('View/Modify existing role:').'</b></label></td>'.
726: '<td align="center"><br />'.
727: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 728: '<option value="" selected="selected">'.
1.324 raeburn 729: &mt('Select'));
730: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 731: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 732: }
733: $r->print('</select>'.
734: '</td>'.
735: &Apache::loncommon::end_data_table_row());
736: }
737: $r->print(&Apache::loncommon::end_data_table().'<p>'.
738: '<input name="customeditor" type="submit" value="'.
739: $lt{'cre'}.'" /></p>'.
740: '</form>');
1.190 raeburn 741: }
1.213 raeburn 742: } else {
1.229 raeburn 743: my $actiontext = $lt{'srad'};
1.213 raeburn 744: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 745: if ($crstype eq 'Community') {
746: $actiontext = $lt{'srme'};
747: } else {
748: $actiontext = $lt{'srst'};
749: }
1.213 raeburn 750: }
1.324 raeburn 751: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 752: if ($env{'form.origform'} ne 'crtusername') {
753: $r->print("\n".$response);
754: }
1.318 raeburn 755: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype));
1.107 www 756: }
1.110 albertel 757: }
758:
1.324 raeburn 759: sub customrole_javascript {
760: my $js = <<"END";
761: <script type="text/javascript">
762: // <![CDATA[
763:
764: function setCustomFields() {
765: if (document.docustom.customroleaction.length > 0) {
766: for (var i=0; i<document.docustom.customroleaction.length; i++) {
767: if (document.docustom.customroleaction[i].checked) {
768: if (document.docustom.customroleaction[i].value == 'new') {
769: document.docustom.rolename.selectedIndex = 0;
770: } else {
771: document.docustom.newrolename.value = '';
772: }
773: }
774: }
775: }
776: return;
777: }
778:
779: function setCustomAction(caller) {
780: if (document.docustom.customroleaction.length > 0) {
781: for (var i=0; i<document.docustom.customroleaction.length; i++) {
782: if (document.docustom.customroleaction[i].value == caller) {
783: document.docustom.customroleaction[i].checked = true;
784: }
785: }
786: }
787: setCustomFields();
788: return;
789: }
790:
791: // ]]>
792: </script>
793: END
794: return $js;
795: }
796:
1.160 raeburn 797: sub entry_form {
1.318 raeburn 798: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype) = @_;
1.229 raeburn 799: my ($usertype,$inexact);
1.214 raeburn 800: if (ref($srch) eq 'HASH') {
801: if (($srch->{'srchin'} eq 'dom') &&
802: ($srch->{'srchby'} eq 'uname') &&
803: ($srch->{'srchtype'} eq 'exact') &&
804: ($srch->{'srchdomain'} ne '') &&
805: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 806: my (%curr_rules,%got_rules);
1.214 raeburn 807: my ($rules,$ruleorder) =
808: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 809: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 810: } else {
811: $inexact = 1;
1.214 raeburn 812: }
1.207 raeburn 813: }
1.214 raeburn 814: my $cancreate =
815: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.160 raeburn 816: my $userpicker =
1.179 raeburn 817: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.214 raeburn 818: 'document.crtuser',$cancreate,$usertype);
1.160 raeburn 819: my $srchbutton = &mt('Search');
1.229 raeburn 820: if ($env{'form.action'} eq 'singlestudent') {
821: $srchbutton = &mt('Search and Enroll');
822: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
823: $srchbutton = &mt('Search or Add New User');
824: }
1.207 raeburn 825: my $output = <<"ENDBLOCK";
1.160 raeburn 826: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 827: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 828: <input type="hidden" name="phase" value="get_user_info" />
829: $userpicker
1.179 raeburn 830: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 831: </form>
1.207 raeburn 832: ENDBLOCK
1.229 raeburn 833: if ($env{'form.phase'} eq '') {
1.207 raeburn 834: my $defdom=$env{'request.role.domain'};
835: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
836: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 837: 'enro' => 'Enroll one student',
1.318 raeburn 838: 'enrm' => 'Enroll one member',
1.229 raeburn 839: 'admo' => 'Add/modify a single user',
840: 'crea' => 'create new user if required',
841: 'uskn' => "username is known",
1.207 raeburn 842: 'crnu' => 'Create a new user',
843: 'usr' => 'Username',
844: 'dom' => 'in domain',
1.229 raeburn 845: 'enrl' => 'Enroll',
846: 'cram' => 'Create/Modify user',
1.207 raeburn 847: );
1.229 raeburn 848: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
849: my ($title,$buttontext,$showresponse);
1.318 raeburn 850: if ($env{'form.action'} eq 'singlestudent') {
851: if ($crstype eq 'Community') {
852: $title = $lt{'enrm'};
853: } else {
854: $title = $lt{'enro'};
855: }
1.229 raeburn 856: $buttontext = $lt{'enrl'};
857: } else {
858: $title = $lt{'admo'};
859: $buttontext = $lt{'cram'};
860: }
861: if ($cancreate) {
862: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
863: } else {
864: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
865: }
866: if ($env{'form.origform'} eq 'crtusername') {
867: $showresponse = $responsemsg;
868: }
1.207 raeburn 869: $output .= <<"ENDDOCUMENT";
1.229 raeburn 870: <br />
1.207 raeburn 871: <form action="/adm/createuser" method="post" name="crtusername">
872: <input type="hidden" name="action" value="$env{'form.action'}" />
873: <input type="hidden" name="phase" value="createnewuser" />
874: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 875: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 876: <input type="hidden" name="srchin" value="dom" />
877: <input type="hidden" name="forcenewuser" value="1" />
878: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 879: <h3>$title</h3>
880: $showresponse
1.207 raeburn 881: <table>
882: <tr>
883: <td>$lt{'usr'}:</td>
884: <td><input type="text" size="15" name="srchterm" /></td>
885: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 886: <td> $sellink </td>
887: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 888: </tr>
889: </table>
890: </form>
1.160 raeburn 891: ENDDOCUMENT
1.207 raeburn 892: }
1.160 raeburn 893: return $output;
894: }
1.110 albertel 895:
896: sub user_modification_js {
1.113 raeburn 897: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
898:
1.110 albertel 899: return <<END;
900: <script type="text/javascript" language="Javascript">
1.301 bisitz 901: // <![CDATA[
1.314 raeburn 902:
1.110 albertel 903: $pjump_def
904: $dc_setcourse_code
905:
906: function dateset() {
907: eval("document.cu."+document.cu.pres_marker.value+
908: ".value=document.cu.pres_value.value");
1.359 www 909: modalWindow.close();
1.110 albertel 910: }
911:
1.113 raeburn 912: $nondc_setsection_code
1.301 bisitz 913: // ]]>
1.110 albertel 914: </script>
915: END
1.2 www 916: }
917:
918: # =================================================================== Phase two
1.160 raeburn 919: sub print_user_selection_page {
1.351 raeburn 920: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 921: my @fields = ('username','domain','lastname','firstname','permanentemail');
922: my $sortby = $env{'form.sortby'};
923:
924: if (!grep(/^\Q$sortby\E$/,@fields)) {
925: $sortby = 'lastname';
926: }
927:
928: my ($jsback,$elements) = &crumb_utilities();
929:
930: my $jscript = (<<ENDSCRIPT);
931: <script type="text/javascript">
1.301 bisitz 932: // <![CDATA[
1.160 raeburn 933: function pickuser(uname,udom) {
934: document.usersrchform.seluname.value=uname;
935: document.usersrchform.seludom.value=udom;
936: document.usersrchform.phase.value="userpicked";
937: document.usersrchform.submit();
938: }
939:
940: $jsback
1.301 bisitz 941: // ]]>
1.160 raeburn 942: </script>
943: ENDSCRIPT
944:
945: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 946: 'usrch' => "User Search to add/modify roles",
947: 'stusrch' => "User Search to enroll student",
1.318 raeburn 948: 'memsrch' => "User Search to enroll member",
1.179 raeburn 949: 'usel' => "Select a user to add/modify roles",
1.318 raeburn 950: 'stusel' => "Select a user to enroll as a student",
951: 'memsel' => "Select a user to enroll as a member",
1.160 raeburn 952: 'username' => "username",
953: 'domain' => "domain",
954: 'lastname' => "last name",
955: 'firstname' => "first name",
956: 'permanentemail' => "permanent e-mail",
957: );
1.302 raeburn 958: if ($context eq 'requestcrs') {
959: $r->print('<div>');
960: } else {
1.318 raeburn 961: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 962: my $helpitem;
963: if ($env{'form.action'} eq 'singleuser') {
964: $helpitem = 'Course_Change_Privileges';
965: } elsif ($env{'form.action'} eq 'singlestudent') {
966: $helpitem = 'Course_Add_Student';
967: }
968: push (@{$brcrum},
969: {href => "javascript:backPage(document.usersrchform,'','')",
970: text => $breadcrumb_text{'search'},
971: faq => 282,
972: bug => 'Instructor Interface',},
973: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
974: text => $breadcrumb_text{'userpicked'},
975: faq => 282,
976: bug => 'Instructor Interface',
977: help => $helpitem}
978: );
979: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 980: if ($env{'form.action'} eq 'singleuser') {
981: $r->print("<b>$lt{'usrch'}</b><br />");
1.318 raeburn 982: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.302 raeburn 983: $r->print('<h3>'.$lt{'usel'}.'</h3>');
984: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 985: $r->print($jscript."<b>");
986: if ($crstype eq 'Community') {
987: $r->print($lt{'memsrch'});
988: } else {
989: $r->print($lt{'stusrch'});
990: }
991: $r->print("</b><br />");
992: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
993: $r->print('</form><h3>');
994: if ($crstype eq 'Community') {
995: $r->print($lt{'memsel'});
996: } else {
997: $r->print($lt{'stusel'});
998: }
999: $r->print('</h3>');
1.302 raeburn 1000: }
1.179 raeburn 1001: }
1.380 bisitz 1002: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1003: &Apache::loncommon::start_data_table()."\n".
1004: &Apache::loncommon::start_data_table_header_row()."\n".
1005: ' <th> </th>'."\n");
1006: foreach my $field (@fields) {
1007: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1008: "'".$field."'".';document.usersrchform.submit();">'.
1009: $lt{$field}.'</a></th>'."\n");
1010: }
1011: $r->print(&Apache::loncommon::end_data_table_header_row());
1012:
1013: my @sorted_users = sort {
1.167 albertel 1014: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1015: ||
1.167 albertel 1016: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1017: ||
1018: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1019: ||
1020: lc($a) cmp lc($b)
1.160 raeburn 1021: } (keys(%$srch_results));
1022:
1023: foreach my $user (@sorted_users) {
1024: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1025: my $onclick;
1026: if ($context eq 'requestcrs') {
1.314 raeburn 1027: $onclick =
1.302 raeburn 1028: 'onclick="javascript:gochoose('."'$uname','$udom',".
1029: "'$srch_results->{$user}->{firstname}',".
1030: "'$srch_results->{$user}->{lastname}',".
1031: "'$srch_results->{$user}->{permanentemail}'".');"';
1032: } else {
1.314 raeburn 1033: $onclick =
1.302 raeburn 1034: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1035: }
1.160 raeburn 1036: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1037: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1038: $onclick.' /></td>'.
1.160 raeburn 1039: '<td><tt>'.$uname.'</tt></td>'.
1040: '<td><tt>'.$udom.'</tt></td>');
1041: foreach my $field ('lastname','firstname','permanentemail') {
1042: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1043: }
1044: $r->print(&Apache::loncommon::end_data_table_row());
1045: }
1046: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1047: if (ref($srcharray) eq 'ARRAY') {
1048: foreach my $item (@{$srcharray}) {
1049: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1050: }
1051: }
1.160 raeburn 1052: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1053: ' <input type="hidden" name="seluname" value="" />'."\n".
1054: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1055: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1056: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1057: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1058: if ($context eq 'requestcrs') {
1059: $r->print($opener_elements.'</form></div>');
1060: } else {
1.351 raeburn 1061: $r->print($response.'</form>');
1.302 raeburn 1062: }
1.160 raeburn 1063: }
1064:
1065: sub print_user_query_page {
1.351 raeburn 1066: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1067: # FIXME - this is for a network-wide name search (similar to catalog search)
1068: # To use frames with similar behavior to catalog/portfolio search.
1069: # To be implemented.
1070: return;
1071: }
1072:
1.42 matthew 1073: sub print_user_modification_page {
1.375 raeburn 1074: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1075: $brcrum,$showcredits) = @_;
1.185 raeburn 1076: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1077: my $usermsg = &mt('No username and/or domain provided.');
1078: $env{'form.phase'} = '';
1.351 raeburn 1079: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum);
1.58 www 1080: return;
1081: }
1.213 raeburn 1082: my ($form,$formname);
1083: if ($env{'form.action'} eq 'singlestudent') {
1084: $form = 'document.enrollstudent';
1085: $formname = 'enrollstudent';
1086: } else {
1087: $form = 'document.cu';
1088: $formname = 'cu';
1089: }
1.188 raeburn 1090: my %abv_auth = &auth_abbrev();
1.227 raeburn 1091: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1092: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1093: if ($uhome eq 'no_host') {
1.215 raeburn 1094: my $usertype;
1095: my ($rules,$ruleorder) =
1096: &Apache::lonnet::inst_userrules($ccdomain,'username');
1097: $usertype =
1.353 raeburn 1098: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1099: \%curr_rules,\%got_rules);
1.215 raeburn 1100: my $cancreate =
1101: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1102: $usertype);
1103: if (!$cancreate) {
1.292 bisitz 1104: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1105: my %usertypetext = (
1106: official => 'institutional',
1107: unofficial => 'non-institutional',
1108: );
1109: my $response;
1110: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1111: $response = '<span class="LC_warning">'.
1112: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1113: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1114: '</span><br />';
1115: }
1.292 bisitz 1116: $response .= '<p class="LC_warning">'
1117: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1118: .' '
1119: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
1120: ,'<a href="'.$helplink.'">','</a>')
1121: .'</p><br />';
1.215 raeburn 1122: $env{'form.phase'} = '';
1.351 raeburn 1123: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum);
1.215 raeburn 1124: return;
1125: }
1.188 raeburn 1126: $newuser = 1;
1.193 raeburn 1127: my $checkhash;
1128: my $checks = { 'username' => 1 };
1.196 raeburn 1129: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1130: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1131: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1132: if (ref($alerts{'username'}) eq 'HASH') {
1133: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1134: my $domdesc =
1.193 raeburn 1135: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1136: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1137: my $userchkmsg;
1138: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1139: $userchkmsg =
1140: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1141: $domdesc,1).
1142: &Apache::loncommon::user_rule_formats($ccdomain,
1143: $domdesc,$curr_rules{$ccdomain}{'username'},
1144: 'username');
1.196 raeburn 1145: }
1.215 raeburn 1146: $env{'form.phase'} = '';
1.351 raeburn 1147: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum);
1.196 raeburn 1148: return;
1.215 raeburn 1149: }
1.193 raeburn 1150: }
1.185 raeburn 1151: }
1.187 raeburn 1152: } else {
1.188 raeburn 1153: $newuser = 0;
1.185 raeburn 1154: }
1.160 raeburn 1155: if ($response) {
1.215 raeburn 1156: $response = '<br />'.$response;
1.160 raeburn 1157: }
1.149 raeburn 1158:
1.52 matthew 1159: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1160: my $dc_setcourse_code = '';
1.119 raeburn 1161: my $nondc_setsection_code = '';
1.112 albertel 1162: my %loaditem;
1.114 albertel 1163:
1.216 raeburn 1164: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1165:
1.375 raeburn 1166: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1167: $groupslist,$newuser,$formname,\%loaditem);
1.318 raeburn 1168: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.224 raeburn 1169: my $helpitem = 'Course_Change_Privileges';
1170: if ($env{'form.action'} eq 'singlestudent') {
1171: $helpitem = 'Course_Add_Student';
1172: }
1.351 raeburn 1173: push (@{$brcrum},
1174: {href => "javascript:backPage($form)",
1175: text => $breadcrumb_text{'search'},
1176: faq => 282,
1177: bug => 'Instructor Interface',});
1178: if ($env{'form.phase'} eq 'userpicked') {
1179: push(@{$brcrum},
1180: {href => "javascript:backPage($form,'get_user_info','select')",
1181: text => $breadcrumb_text{'userpicked'},
1182: faq => 282,
1183: bug => 'Instructor Interface',});
1184: }
1185: push(@{$brcrum},
1186: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1187: text => $breadcrumb_text{'modify'},
1188: faq => 282,
1189: bug => 'Instructor Interface',
1190: help => $helpitem});
1191: my $args = {'add_entries' => \%loaditem,
1192: 'bread_crumbs' => $brcrum,
1193: 'bread_crumbs_component' => 'User Management'};
1194: if ($env{'form.popup'}) {
1195: $args->{'no_nav_bar'} = 1;
1196: }
1197: my $start_page =
1198: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1199:
1.25 matthew 1200: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1201: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1202: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1203: <input type="hidden" name="ccuname" value="$ccuname" />
1204: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1205: <input type="hidden" name="pres_value" value="" />
1206: <input type="hidden" name="pres_type" value="" />
1207: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1208: ENDFORMINFO
1.375 raeburn 1209: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1210: if ($context eq 'course') {
1211: $inccourses{$env{'request.course.id'}}=1;
1212: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1213: if ($showcredits) {
1214: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1215: }
1.329 raeburn 1216: } elsif ($context eq 'author') {
1217: $roledom = $env{'request.role.domain'};
1218: } elsif ($context eq 'domain') {
1219: foreach my $key (keys(%env)) {
1220: $roledom = $env{'request.role.domain'};
1221: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1222: $inccourses{$1.'_'.$2}=1;
1223: }
1224: }
1225: } else {
1226: foreach my $key (keys(%env)) {
1227: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1228: $inccourses{$1.'_'.$2}=1;
1229: }
1.2 www 1230: }
1.24 matthew 1231: }
1.389 bisitz 1232: my $title = '';
1.216 raeburn 1233: if ($newuser) {
1.362 raeburn 1234: my ($portfolioform,$domroleform);
1.267 raeburn 1235: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1236: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1237: # Current user has quota or user tools modification privileges
1.378 raeburn 1238: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1239: }
1.383 raeburn 1240: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1241: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1242: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1243: }
1.227 raeburn 1244: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1245: my %lt=&Apache::lonlocal::texthash(
1246: 'lg' => 'Login Data',
1.190 raeburn 1247: 'hs' => "Home Server",
1.188 raeburn 1248: );
1.185 raeburn 1249: $r->print(<<ENDTITLE);
1.110 albertel 1250: $start_page
1.160 raeburn 1251: $response
1.25 matthew 1252: $forminfo
1.31 matthew 1253: <script type="text/javascript" language="Javascript">
1.301 bisitz 1254: // <![CDATA[
1.20 harris41 1255: $loginscript
1.301 bisitz 1256: // ]]>
1.31 matthew 1257: </script>
1.20 harris41 1258: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1259: ENDTITLE
1.213 raeburn 1260: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1261: if ($crstype eq 'Community') {
1.389 bisitz 1262: $title = &mt('Create New User [_1] in domain [_2] as a member',
1263: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1264: } else {
1.389 bisitz 1265: $title = &mt('Create New User [_1] in domain [_2] as a student',
1266: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1267: }
1.389 bisitz 1268: } else {
1269: $title = &mt('Create New User [_1] in domain [_2]',
1270: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1271: }
1.389 bisitz 1272: $r->print('<h2>'.$title.'</h2>'."\n");
1273: $r->print('<div class="LC_left_float">');
1.393 raeburn 1274: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1275: $inst_results{$ccuname.':'.$ccdomain}));
1276: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1277: my ($home_server_pick,$numlib) =
1278: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1279: 'default','hide');
1280: if ($numlib > 1) {
1281: $r->print("
1.185 raeburn 1282: <br />
1.187 raeburn 1283: $lt{'hs'}: $home_server_pick
1284: <br />");
1285: } else {
1286: $r->print($home_server_pick);
1287: }
1.304 raeburn 1288: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1289: $r->print('<br /><h3>'.
1290: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1291: &Apache::loncommon::start_data_table().
1292: &build_tools_display($ccuname,$ccdomain,
1293: 'requestcourses').
1294: &Apache::loncommon::end_data_table());
1295: }
1.188 raeburn 1296: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1297: $lt{'lg'}.'</h3>');
1.185 raeburn 1298: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1299: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1300: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1301: my ($rules,$ruleorder) =
1302: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1303: if (ref($rules) eq 'HASH') {
1.193 raeburn 1304: if (ref($rules->{$matchedrule}) eq 'HASH') {
1305: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1306: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1307: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1308: } else {
1.193 raeburn 1309: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1310: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1311: if ($authtype =~ /^krb(4|5)$/) {
1312: my $ver = $1;
1313: if ($authparm ne '') {
1314: $fixedauth = <<"KERB";
1315: <input type="hidden" name="login" value="krb" />
1316: <input type="hidden" name="krbver" value="$ver" />
1317: <input type="hidden" name="krbarg" value="$authparm" />
1318: KERB
1319: }
1320: } else {
1321: $fixedauth =
1322: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1323: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1324: $fixedauth .=
1325: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1326: } else {
1.273 raeburn 1327: if ($authtype eq 'int') {
1328: $varauth = '<br />'.
1.301 bisitz 1329: &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 1330: } elsif ($authtype eq 'loc') {
1331: $varauth = '<br />'.
1332: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1333: } else {
1334: $varauth =
1.185 raeburn 1335: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1336: }
1.185 raeburn 1337: }
1338: }
1339: }
1340: } else {
1.190 raeburn 1341: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1342: }
1343: }
1344: if ($authmsg) {
1345: $r->print(<<ENDAUTH);
1346: $fixedauth
1347: $authmsg
1348: $varauth
1349: ENDAUTH
1350: }
1351: } else {
1.190 raeburn 1352: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1353: }
1.362 raeburn 1354: $r->print($portfolioform.$domroleform);
1.215 raeburn 1355: if ($env{'form.action'} eq 'singlestudent') {
1356: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1357: $permission,$crstype,$ccuname,
1358: $ccdomain,$showcredits));
1.215 raeburn 1359: }
1360: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1361: } else { # user already exists
1.389 bisitz 1362: $r->print($start_page.$forminfo);
1.213 raeburn 1363: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1364: if ($crstype eq 'Community') {
1.389 bisitz 1365: $title = &mt('Enroll one member: [_1] in domain [_2]',
1366: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1367: } else {
1.389 bisitz 1368: $title = &mt('Enroll one student: [_1] in domain [_2]',
1369: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1370: }
1.213 raeburn 1371: } else {
1.389 bisitz 1372: $title = &mt('Modify existing user: [_1] in domain [_2]',
1373: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1374: }
1.389 bisitz 1375: $r->print('<h2>'.$title.'</h2>'."\n");
1376: $r->print('<div class="LC_left_float">');
1.393 raeburn 1377: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1378: $inst_results{$ccuname.':'.$ccdomain}));
1.275 raeburn 1379: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1380: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1381: &Apache::loncommon::start_data_table());
1.314 raeburn 1382: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1383: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1384: } else {
1385: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1386: $env{'request.role.domain'}));
1387: }
1388: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1389: }
1.199 raeburn 1390: $r->print('</div>');
1.362 raeburn 1391: my @order = ('auth','quota','tools','requestauthor');
1392: my %user_text;
1393: my ($isadv,$isauthor) =
1394: &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1395: if ((!$isauthor) &&
1.383 raeburn 1396: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))
1397: && ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1398: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1399: }
1400: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1401: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1402: (&Apache::lonnet::allowed('mut',$ccdomain))) {
1.188 raeburn 1403: # Current user has quota modification privileges
1.378 raeburn 1404: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1405: }
1406: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1407: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1408: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1409: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1410: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1411: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1412: );
1.362 raeburn 1413: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1414: <h3>$lt{'dska'}</h3>
1415: $lt{'youd'} $lt{'ichr'}: $ccdomain
1416: ENDNOPORTPRIV
1.267 raeburn 1417: }
1418: }
1419: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1420: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1421: my %lt=&Apache::lonlocal::texthash(
1422: 'utav' => "User Tools Availability",
1.361 raeburn 1423: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1424: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1425: );
1.362 raeburn 1426: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1427: <h3>$lt{'utav'}</h3>
1428: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1429: ENDNOTOOLSPRIV
1430: }
1.188 raeburn 1431: }
1.362 raeburn 1432: my $gotdiv = 0;
1433: foreach my $item (@order) {
1434: if ($user_text{$item} ne '') {
1435: unless ($gotdiv) {
1436: $r->print('<div class="LC_left_float">');
1437: $gotdiv = 1;
1438: }
1439: $r->print('<br />'.$user_text{$item});
1440: }
1441: }
1442: if ($env{'form.action'} eq 'singlestudent') {
1443: unless ($gotdiv) {
1444: $r->print('<div class="LC_left_float">');
1.213 raeburn 1445: }
1.375 raeburn 1446: my $credits;
1447: if ($showcredits) {
1448: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1449: if ($credits eq '') {
1450: $credits = $defaultcredits;
1451: }
1452: }
1.374 raeburn 1453: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1454: $permission,$crstype,$ccuname,
1455: $ccdomain,$showcredits));
1.374 raeburn 1456: }
1.362 raeburn 1457: if ($gotdiv) {
1458: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1459: }
1.217 raeburn 1460: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1461: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1462: $roledom,$crstype);
1.217 raeburn 1463: }
1.25 matthew 1464: } ## End of new user/old user logic
1.218 raeburn 1465: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1466: my $btntxt;
1467: if ($crstype eq 'Community') {
1468: $btntxt = &mt('Enroll Member');
1469: } else {
1470: $btntxt = &mt('Enroll Student');
1471: }
1472: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.218 raeburn 1473: } else {
1.393 raeburn 1474: $r->print('<div class="LC_left_float">'.
1475: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1476: my $addrolesdisplay = 0;
1477: if ($context eq 'domain' || $context eq 'author') {
1478: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1479: }
1480: if ($context eq 'domain') {
1.357 raeburn 1481: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1482: if (!$addrolesdisplay) {
1483: $addrolesdisplay = $add_domainroles;
1.2 www 1484: }
1.375 raeburn 1485: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1486: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1487: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1488: } elsif ($context eq 'author') {
1489: if ($addrolesdisplay) {
1.393 raeburn 1490: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1491: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1492: if ($newuser) {
1.301 bisitz 1493: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1494: } else {
1.301 bisitz 1495: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1496: }
1.188 raeburn 1497: } else {
1.393 raeburn 1498: $r->print('</fieldset></div>'.
1499: '<div class="LC_clear_float_footer"></div>'.
1500: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1501: &mt('Back to previous page').'</a>');
1.188 raeburn 1502: }
1503: } else {
1.375 raeburn 1504: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1505: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1506: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1507: }
1.88 raeburn 1508: }
1.188 raeburn 1509: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1510: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1511: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1512: return;
1.2 www 1513: }
1.1 www 1514:
1.213 raeburn 1515: sub singleuser_breadcrumb {
1.318 raeburn 1516: my ($crstype) = @_;
1.213 raeburn 1517: my %breadcrumb_text;
1518: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1519: if ($crstype eq 'Community') {
1520: $breadcrumb_text{'search'} = 'Enroll a member';
1521: } else {
1522: $breadcrumb_text{'search'} = 'Enroll a student';
1523: }
1.213 raeburn 1524: $breadcrumb_text{'userpicked'} = 'Select a user',
1525: $breadcrumb_text{'modify'} = 'Set section/dates',
1526: } else {
1.229 raeburn 1527: $breadcrumb_text{'search'} = 'Create/modify a user';
1.213 raeburn 1528: $breadcrumb_text{'userpicked'} = 'Select a user',
1529: $breadcrumb_text{'modify'} = 'Set user role',
1530: }
1531: return %breadcrumb_text;
1532: }
1533:
1534: sub date_sections_select {
1.375 raeburn 1535: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1536: $showcredits) = @_;
1537: my $credits;
1538: if ($showcredits) {
1539: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1540: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1541: if ($credits eq '') {
1542: $credits = $defaultcredits;
1543: }
1544: }
1.213 raeburn 1545: my $cid = $env{'request.course.id'};
1546: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1547: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1548: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1549: undef,$formname,$permission);
1550: my $rowtitle = 'Section';
1.375 raeburn 1551: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1552: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1553: $permission,$context,'',$crstype,
1554: $showcredits,$credits);
1.213 raeburn 1555: my $output = $date_table.$secbox;
1556: return $output;
1557: }
1558:
1.216 raeburn 1559: sub validation_javascript {
1.375 raeburn 1560: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1561: $loaditem) = @_;
1562: my $dc_setcourse_code = '';
1563: my $nondc_setsection_code = '';
1564: if ($context eq 'domain') {
1565: my $dcdom = $env{'request.role.domain'};
1566: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1567: $dc_setcourse_code =
1568: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1569: } else {
1.227 raeburn 1570: my $checkauth;
1571: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1572: $checkauth = 1;
1573: }
1574: if ($context eq 'course') {
1575: $nondc_setsection_code =
1576: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1577: undef,$checkauth,
1578: $crstype);
1.227 raeburn 1579: }
1580: if ($checkauth) {
1581: $nondc_setsection_code .=
1582: &Apache::lonuserutils::verify_authen($formname,$context);
1583: }
1.216 raeburn 1584: }
1585: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1586: $nondc_setsection_code,$groupslist);
1587: my ($jsback,$elements) = &crumb_utilities();
1588: $js .= "\n".
1.301 bisitz 1589: '<script type="text/javascript">'."\n".
1590: '// <![CDATA['."\n".
1591: $jsback."\n".
1592: '// ]]>'."\n".
1593: '</script>'."\n";
1.216 raeburn 1594: return $js;
1595: }
1596:
1.217 raeburn 1597: sub display_existing_roles {
1.375 raeburn 1598: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1599: $showcredits) = @_;
1.329 raeburn 1600: my $now=time;
1601: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1602: 'rer' => "Existing Roles",
1603: 'rev' => "Revoke",
1604: 'del' => "Delete",
1605: 'ren' => "Re-Enable",
1606: 'rol' => "Role",
1607: 'ext' => "Extent",
1.375 raeburn 1608: 'crd' => "Credits",
1.217 raeburn 1609: 'sta' => "Start",
1610: 'end' => "End",
1611: );
1.329 raeburn 1612: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1613: if ($context eq 'course' || $context eq 'author') {
1614: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1615: my %roleshash =
1616: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1617: ['active','previous','future'],\@roles,$roledom,1);
1618: foreach my $key (keys(%roleshash)) {
1619: my ($start,$end) = split(':',$roleshash{$key});
1620: next if ($start eq '-1' || $end eq '-1');
1621: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1622: if ($context eq 'course') {
1623: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1624: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1625: } elsif ($context eq 'author') {
1626: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1627: }
1628: my ($newkey,$newvalue,$newrole);
1629: $newkey = '/'.$rdom.'/'.$rnum;
1630: if ($sec ne '') {
1631: $newkey .= '/'.$sec;
1632: }
1633: $newvalue = $role;
1634: if ($role =~ /^cr/) {
1635: $newrole = 'cr';
1636: } else {
1637: $newrole = $role;
1638: }
1639: $newkey .= '_'.$newrole;
1640: if ($start ne '' && $end ne '') {
1641: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1642: } elsif ($end ne '') {
1643: $newvalue .= '_'.$end;
1.329 raeburn 1644: }
1645: $rolesdump{$newkey} = $newvalue;
1646: }
1647: } else {
1.360 raeburn 1648: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1649: }
1650: # Build up table of user roles to allow revocation and re-enabling of roles.
1651: my ($tmp) = keys(%rolesdump);
1652: return if ($tmp =~ /^(con_lost|error)/i);
1653: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1654: my $b1=join('_',(split('_',$b))[1,0]);
1655: return $a1 cmp $b1;
1656: } keys(%rolesdump)) {
1657: next if ($area =~ /^rolesdef/);
1658: my $envkey=$area;
1659: my $role = $rolesdump{$area};
1660: my $thisrole=$area;
1661: $area =~ s/\_\w\w$//;
1662: my ($role_code,$role_end_time,$role_start_time) =
1663: split(/_/,$role);
1.217 raeburn 1664: # Is this a custom role? Get role owner and title.
1.329 raeburn 1665: my ($croleudom,$croleuname,$croletitle)=
1666: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1667: my $allowed=0;
1668: my $delallowed=0;
1669: my $sortkey=$role_code;
1670: my $class='Unknown';
1.375 raeburn 1671: my $credits='';
1.329 raeburn 1672: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
1673: $class='Course';
1674: my ($coursedom,$coursedir) = ($1,$2);
1675: my $cid = $1.'_'.$2;
1676: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1677: my %coursedata=
1678: &Apache::lonnet::coursedescription($cid);
1679: if ($coursedir =~ /^$match_community$/) {
1680: $class='Community';
1681: }
1682: $sortkey.="\0$coursedom";
1683: my $carea;
1684: if (defined($coursedata{'description'})) {
1685: $carea=$coursedata{'description'}.
1686: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1687: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1688: $sortkey.="\0".$coursedata{'description'};
1689: } else {
1690: if ($class eq 'Community') {
1691: $carea=&mt('Unavailable community').': '.$area;
1692: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1693: } else {
1694: $carea=&mt('Unavailable course').': '.$area;
1695: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1696: }
1.329 raeburn 1697: }
1698: $sortkey.="\0$coursedir";
1699: $inccourses->{$cid}=1;
1.375 raeburn 1700: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1701: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1702: $credits =
1703: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1704: $coursedom,$coursedir);
1705: if ($credits eq '') {
1706: $credits = $defaultcredits;
1707: }
1708: }
1.329 raeburn 1709: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1710: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1711: $allowed=1;
1712: }
1713: unless ($allowed) {
1.365 raeburn 1714: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1715: if ($isowner) {
1716: if (($role_code eq 'co') && ($class eq 'Community')) {
1717: $allowed = 1;
1718: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1719: $allowed = 1;
1720: }
1.217 raeburn 1721: }
1.329 raeburn 1722: }
1723: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1724: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1725: $delallowed=1;
1726: }
1.217 raeburn 1727: # - custom role. Needs more info, too
1.329 raeburn 1728: if ($croletitle) {
1729: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1730: $allowed=1;
1731: $thisrole.='.'.$role_code;
1.217 raeburn 1732: }
1.329 raeburn 1733: }
1734: if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
1.373 bisitz 1735: $carea.='<br />'.&mt('Section: [_1]',$3);
1.329 raeburn 1736: $sortkey.="\0$3";
1737: if (!$allowed) {
1738: if ($env{'request.course.sec'} eq $3) {
1739: if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
1740: $allowed = 1;
1.217 raeburn 1741: }
1742: }
1743: }
1.329 raeburn 1744: }
1745: $area=$carea;
1746: } else {
1747: $sortkey.="\0".$area;
1748: # Determine if current user is able to revoke privileges
1749: if ($area=~m{^/($match_domain)/}) {
1750: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1751: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1752: $allowed=1;
1.217 raeburn 1753: }
1.329 raeburn 1754: if (((&Apache::lonnet::allowed('dro',$1)) ||
1755: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1756: ($role_code ne 'dc')) {
1757: $delallowed=1;
1.217 raeburn 1758: }
1.329 raeburn 1759: } else {
1760: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1761: $allowed=1;
1762: }
1763: }
1.363 raeburn 1764: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1765: $class='Authoring Space';
1.329 raeburn 1766: } elsif ($role_code eq 'su') {
1767: $class='System';
1.217 raeburn 1768: } else {
1.329 raeburn 1769: $class='Domain';
1.217 raeburn 1770: }
1.329 raeburn 1771: }
1772: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1773: $area=~m{/($match_domain)/($match_username)};
1774: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1775: $allowed=1;
1.217 raeburn 1776: } else {
1.329 raeburn 1777: $allowed=0;
1.217 raeburn 1778: }
1.329 raeburn 1779: }
1780: my $row = '';
1781: $row.= '<td>';
1782: my $active=1;
1783: $active=0 if (($role_end_time) && ($now>$role_end_time));
1784: if (($active) && ($allowed)) {
1785: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1786: } else {
1787: if ($active) {
1788: $row.=' ';
1.217 raeburn 1789: } else {
1.329 raeburn 1790: $row.=&mt('expired or revoked');
1.217 raeburn 1791: }
1.329 raeburn 1792: }
1793: $row.='</td><td>';
1794: if ($allowed && !$active) {
1795: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1796: } else {
1797: $row.=' ';
1798: }
1799: $row.='</td><td>';
1800: if ($delallowed) {
1801: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1802: } else {
1803: $row.=' ';
1804: }
1805: my $plaintext='';
1806: if (!$croletitle) {
1.375 raeburn 1807: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1808: if (($showcredits) && ($credits ne '')) {
1809: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1810: '<span class="LC_fontsize_small">'.
1811: &mt('Credits: [_1]',$credits).
1812: '</span></span>';
1813: }
1.329 raeburn 1814: } else {
1815: $plaintext=
1.395 bisitz 1816: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1817: '"'.$croletitle.'"',
1818: '<br />',
1819: $croleuname.':'.$croleudom);
1.329 raeburn 1820: }
1821: $row.= '</td><td>'.$plaintext.
1822: '</td><td>'.$area.
1823: '</td><td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1824: : ' ' ).
1825: '</td><td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1826: : ' ' )
1827: ."</td>";
1828: $sortrole{$sortkey}=$envkey;
1829: $roletext{$envkey}=$row;
1830: $roleclass{$envkey}=$class;
1831: $rolepriv{$envkey}=$allowed;
1832: } # end of foreach (table building loop)
1833:
1834: my $rolesdisplay = 0;
1835: my %output = ();
1.377 raeburn 1836: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1837: $output{$type} = '';
1838: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1839: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1840: $output{$type}.=
1841: &Apache::loncommon::start_data_table_row().
1842: $roletext{$sortrole{$which}}.
1843: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1844: }
1.329 raeburn 1845: }
1846: unless($output{$type} eq '') {
1847: $output{$type} = '<tr class="LC_info_row">'.
1848: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1849: $output{$type};
1850: $rolesdisplay = 1;
1851: }
1852: }
1853: if ($rolesdisplay == 1) {
1854: my $contextrole='';
1855: if ($env{'request.course.id'}) {
1856: if (&Apache::loncommon::course_type() eq 'Community') {
1857: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 1858: } else {
1.329 raeburn 1859: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 1860: }
1.329 raeburn 1861: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 1862: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 1863: } else {
1864: $contextrole = &mt('Existing Roles in this Domain');
1865: }
1.393 raeburn 1866: $r->print('<div class="LC_left_float">'.
1.375 raeburn 1867: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 1868: &Apache::loncommon::start_data_table("LC_createuser").
1869: &Apache::loncommon::start_data_table_header_row().
1870: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
1871: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
1872: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1873: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 1874: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1875: if ($output{$type}) {
1876: $r->print($output{$type}."\n");
1.217 raeburn 1877: }
1878: }
1.375 raeburn 1879: $r->print(&Apache::loncommon::end_data_table().
1880: '</fieldset></div>');
1.329 raeburn 1881: }
1.217 raeburn 1882: return;
1883: }
1884:
1.218 raeburn 1885: sub new_coauthor_roles {
1886: my ($r,$ccuname,$ccdomain) = @_;
1887: my $addrolesdisplay = 0;
1888: #
1889: # Co-Author
1890: #
1891: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
1892: $env{'request.role.domain'}) &&
1893: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1894: # No sense in assigning co-author role to yourself
1895: $addrolesdisplay = 1;
1896: my $cuname=$env{'user.name'};
1897: my $cudom=$env{'request.role.domain'};
1898: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 1899: 'cs' => "Authoring Space",
1.218 raeburn 1900: 'act' => "Activate",
1901: 'rol' => "Role",
1902: 'ext' => "Extent",
1903: 'sta' => "Start",
1904: 'end' => "End",
1905: 'cau' => "Co-Author",
1906: 'caa' => "Assistant Co-Author",
1907: 'ssd' => "Set Start Date",
1908: 'sed' => "Set End Date"
1909: );
1910: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
1911: &Apache::loncommon::start_data_table()."\n".
1912: &Apache::loncommon::start_data_table_header_row()."\n".
1913: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
1914: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
1915: '<th>'.$lt{'end'}.'</th>'."\n".
1916: &Apache::loncommon::end_data_table_header_row()."\n".
1917: &Apache::loncommon::start_data_table_row().'
1918: <td>
1.291 bisitz 1919: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 1920: </td>
1921: <td>'.$lt{'cau'}.'</td>
1922: <td>'.$cudom.'_'.$cuname.'</td>
1923: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
1924: <a href=
1925: "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>
1926: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
1927: <a href=
1928: "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".
1929: &Apache::loncommon::end_data_table_row()."\n".
1930: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 1931: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 1932: <td>'.$lt{'caa'}.'</td>
1933: <td>'.$cudom.'_'.$cuname.'</td>
1934: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
1935: <a href=
1936: "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>
1937: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
1938: <a href=
1939: "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".
1940: &Apache::loncommon::end_data_table_row()."\n".
1941: &Apache::loncommon::end_data_table());
1942: } elsif ($env{'request.role'} =~ /^au\./) {
1943: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
1944: $env{'request.role.domain'}))) {
1945: $r->print('<span class="LC_error">'.
1946: &mt('You do not have privileges to assign co-author roles.').
1947: '</span>');
1948: } elsif (($env{'user.name'} eq $ccuname) &&
1949: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 1950: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Authoring Space is not permitted'));
1.218 raeburn 1951: }
1952: }
1953: return $addrolesdisplay;;
1954: }
1955:
1956: sub new_domain_roles {
1.357 raeburn 1957: my ($r,$ccdomain) = @_;
1.218 raeburn 1958: my $addrolesdisplay = 0;
1959: #
1960: # Domain level
1961: #
1962: my $num_domain_level = 0;
1963: my $domaintext =
1964: '<h4>'.&mt('Domain Level').'</h4>'.
1965: &Apache::loncommon::start_data_table().
1966: &Apache::loncommon::start_data_table_header_row().
1967: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
1968: &mt('Extent').'</th>'.
1969: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
1970: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 1971: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 1972: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 1973: foreach my $role (@allroles) {
1974: next if ($role eq 'ad');
1.357 raeburn 1975: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 1976: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1977: my $plrole=&Apache::lonnet::plaintext($role);
1978: my %lt=&Apache::lonlocal::texthash(
1979: 'ssd' => "Set Start Date",
1980: 'sed' => "Set End Date"
1981: );
1982: $num_domain_level ++;
1983: $domaintext .=
1984: &Apache::loncommon::start_data_table_row().
1.291 bisitz 1985: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 1986: <td>'.$plrole.'</td>
1987: <td>'.$thisdomain.'</td>
1988: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
1989: <a href=
1990: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1991: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
1992: <a href=
1993: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
1994: &Apache::loncommon::end_data_table_row();
1995: }
1996: }
1997: }
1998: $domaintext.= &Apache::loncommon::end_data_table();
1999: if ($num_domain_level > 0) {
2000: $r->print($domaintext);
2001: $addrolesdisplay = 1;
2002: }
2003: return $addrolesdisplay;
2004: }
2005:
1.188 raeburn 2006: sub user_authentication {
1.227 raeburn 2007: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2008: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2009: my $outcome;
1.188 raeburn 2010: # Check for a bad authentication type
2011: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2012: # bad authentication scheme
2013: my %lt=&Apache::lonlocal::texthash(
2014: 'err' => "ERROR",
2015: 'uuas' => "This user has an unrecognized authentication scheme",
2016: 'adcs' => "Please alert a domain coordinator of this situation",
2017: 'sldb' => "Please specify login data below",
2018: 'ld' => "Login Data"
2019: );
2020: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2021: &initialize_authen_forms($ccdomain,$formname);
2022:
1.190 raeburn 2023: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2024: $outcome = <<ENDBADAUTH;
2025: <script type="text/javascript" language="Javascript">
1.301 bisitz 2026: // <![CDATA[
1.188 raeburn 2027: $loginscript
1.301 bisitz 2028: // ]]>
1.188 raeburn 2029: </script>
2030: <span class="LC_error">$lt{'err'}:
2031: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2032: <h3>$lt{'ld'}</h3>
2033: $choices
2034: ENDBADAUTH
2035: } else {
2036: # This user is not allowed to modify the user's
2037: # authentication scheme, so just notify them of the problem
2038: $outcome = <<ENDBADAUTH;
2039: <span class="LC_error"> $lt{'err'}:
2040: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2041: </span>
2042: ENDBADAUTH
2043: }
2044: } else { # Authentication type is valid
1.227 raeburn 2045: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2046: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2047: &modify_login_block($ccdomain,$currentauth);
2048: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2049: # Current user has login modification privileges
2050: my %lt=&Apache::lonlocal::texthash (
2051: 'ld' => "Login Data",
2052: 'ccld' => "Change Current Login Data",
2053: 'enld' => "Enter New Login Data"
2054: );
2055: $outcome =
2056: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2057: '// <![CDATA['."\n".
1.188 raeburn 2058: $loginscript."\n".
1.301 bisitz 2059: '// ]]>'."\n".
1.188 raeburn 2060: '</script>'."\n".
2061: '<h3>'.$lt{'ld'}.'</h3>'.
2062: &Apache::loncommon::start_data_table().
1.205 raeburn 2063: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2064: '<td>'.$authformnop;
2065: if ($can_modify) {
2066: $outcome .= '</td>'."\n".
2067: &Apache::loncommon::end_data_table_row().
2068: &Apache::loncommon::start_data_table_row().
2069: '<td>'.$authformcurrent.'</td>'.
2070: &Apache::loncommon::end_data_table_row()."\n";
2071: } else {
1.200 raeburn 2072: $outcome .= ' ('.$authformcurrent.')</td>'.
2073: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2074: }
1.205 raeburn 2075: foreach my $item (@authform_others) {
2076: $outcome .= &Apache::loncommon::start_data_table_row().
2077: '<td>'.$item.'</td>'.
2078: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2079: }
1.205 raeburn 2080: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2081: } else {
2082: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
2083: my %lt=&Apache::lonlocal::texthash(
2084: 'ccld' => "Change Current Login Data",
2085: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2086: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2087: );
2088: $outcome .= <<ENDNOPRIV;
2089: <h3>$lt{'ccld'}</h3>
2090: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2091: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2092: ENDNOPRIV
2093: }
2094: }
2095: } ## End of "check for bad authentication type" logic
2096: return $outcome;
2097: }
2098:
1.187 raeburn 2099: sub modify_login_block {
2100: my ($dom,$currentauth) = @_;
2101: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2102: my ($authnum,%can_assign) =
2103: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2104: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2105: if ($currentauth=~/^krb(4|5):/) {
2106: $authformcurrent=$authformkrb;
2107: if ($can_assign{'int'}) {
1.205 raeburn 2108: push(@authform_others,$authformint);
1.187 raeburn 2109: }
2110: if ($can_assign{'loc'}) {
1.205 raeburn 2111: push(@authform_others,$authformloc);
1.187 raeburn 2112: }
2113: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2114: $show_override_msg = 1;
2115: }
2116: } elsif ($currentauth=~/^internal:/) {
2117: $authformcurrent=$authformint;
2118: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2119: push(@authform_others,$authformkrb);
1.187 raeburn 2120: }
2121: if ($can_assign{'loc'}) {
1.205 raeburn 2122: push(@authform_others,$authformloc);
1.187 raeburn 2123: }
2124: if ($can_assign{'int'}) {
2125: $show_override_msg = 1;
2126: }
2127: } elsif ($currentauth=~/^unix:/) {
2128: $authformcurrent=$authformfsys;
2129: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2130: push(@authform_others,$authformkrb);
1.187 raeburn 2131: }
2132: if ($can_assign{'int'}) {
1.205 raeburn 2133: push(@authform_others,$authformint);
1.187 raeburn 2134: }
2135: if ($can_assign{'loc'}) {
1.205 raeburn 2136: push(@authform_others,$authformloc);
1.187 raeburn 2137: }
2138: if ($can_assign{'fsys'}) {
2139: $show_override_msg = 1;
2140: }
2141: } elsif ($currentauth=~/^localauth:/) {
2142: $authformcurrent=$authformloc;
2143: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2144: push(@authform_others,$authformkrb);
1.187 raeburn 2145: }
2146: if ($can_assign{'int'}) {
1.205 raeburn 2147: push(@authform_others,$authformint);
1.187 raeburn 2148: }
2149: if ($can_assign{'loc'}) {
2150: $show_override_msg = 1;
2151: }
2152: }
2153: if ($show_override_msg) {
1.205 raeburn 2154: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2155: '</td></tr>'."\n".
2156: '<tr><td> </td>'.
2157: '<td><b>'.&mt('Currently in use').'</b></td>'.
2158: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2159: &mt('will override current values').
1.205 raeburn 2160: '</span></td></tr></table>';
1.187 raeburn 2161: }
1.205 raeburn 2162: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2163: }
2164:
1.188 raeburn 2165: sub personal_data_display {
1.391 raeburn 2166: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
1.409 ! raeburn 2167: $now,$captchaform,$emailusername,$usertype,$recaptchaversion) = @_;
1.388 bisitz 2168: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2169: my @userinfo = ('firstname','middlename','lastname','generation',
2170: 'permanentemail','id');
1.252 raeburn 2171: my $rowcount = 0;
2172: my $editable = 0;
1.391 raeburn 2173: my %textboxsize = (
2174: firstname => '15',
2175: middlename => '15',
2176: lastname => '15',
2177: generation => '5',
2178: permanentemail => '25',
2179: id => '15',
2180: );
2181:
2182: my %lt=&Apache::lonlocal::texthash(
2183: 'pd' => "Personal Data",
2184: 'firstname' => "First Name",
2185: 'middlename' => "Middle Name",
2186: 'lastname' => "Last Name",
2187: 'generation' => "Generation",
2188: 'permanentemail' => "Permanent e-mail address",
2189: 'id' => "Student/Employee ID",
2190: 'lg' => "Login Data",
2191: 'inststatus' => "Affiliation",
2192: 'email' => 'E-mail address',
2193: 'valid' => 'Validation',
2194: );
2195:
2196: %canmodify_status =
1.286 raeburn 2197: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2198: ['inststatus'],$rolesarray);
1.253 raeburn 2199: if (!$newuser) {
1.188 raeburn 2200: # Get the users information
2201: %userenv = &Apache::lonnet::get('environment',
2202: ['firstname','middlename','lastname','generation',
1.286 raeburn 2203: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2204: %canmodify =
2205: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2206: \@userinfo,$rolesarray);
1.257 raeburn 2207: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2208: if ($newuser eq 'email') {
1.396 raeburn 2209: if (ref($emailusername) eq 'HASH') {
2210: if (ref($emailusername->{$usertype}) eq 'HASH') {
2211: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
2212: @userinfo = ();
2213: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2214: foreach my $field (@{$infofields}) {
2215: if ($emailusername->{$usertype}->{$field}) {
2216: push(@userinfo,$field);
2217: $canmodify{$field} = 1;
2218: unless ($textboxsize{$field}) {
2219: $textboxsize{$field} = 25;
2220: }
2221: unless ($lt{$field}) {
2222: $lt{$field} = $infotitles->{$field};
2223: }
2224: if ($emailusername->{$usertype}->{$field} eq 'required') {
2225: $lt{$field} .= '<b>*</b>';
2226: }
1.391 raeburn 2227: }
2228: }
2229: }
2230: }
2231: }
2232: } else {
2233: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2234: $inst_results,$rolesarray);
2235: }
1.188 raeburn 2236: }
1.391 raeburn 2237:
1.188 raeburn 2238: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2239: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2240: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2241: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.396 raeburn 2242: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2243: 'LC_oddrow_value')."\n".
1.394 raeburn 2244: '<input type="text" name="uname" size="25" value="" autocomplete="off" />';
1.391 raeburn 2245: $rowcount ++;
2246: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.408 raeburn 2247: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2248: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2249: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2250: 'LC_pick_box_title',
2251: 'LC_oddrow_value')."\n".
2252: $upassone."\n".
2253: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2254: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2255: 'LC_pick_box_title',
2256: 'LC_oddrow_value')."\n".
2257: $upasstwo.
2258: &Apache::lonhtmlcommon::row_closure()."\n";
2259: }
1.188 raeburn 2260: foreach my $item (@userinfo) {
2261: my $rowtitle = $lt{$item};
1.252 raeburn 2262: my $hiderow = 0;
1.188 raeburn 2263: if ($item eq 'generation') {
2264: $rowtitle = $genhelp.$rowtitle;
2265: }
1.252 raeburn 2266: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2267: if ($newuser) {
1.210 raeburn 2268: if (ref($inst_results) eq 'HASH') {
2269: if ($inst_results->{$item} ne '') {
1.252 raeburn 2270: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2271: } else {
1.252 raeburn 2272: if ($context eq 'selfcreate') {
1.391 raeburn 2273: if ($canmodify{$item}) {
1.394 raeburn 2274: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2275: $editable ++;
2276: } else {
2277: $hiderow = 1;
2278: }
1.253 raeburn 2279: } else {
2280: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2281: }
1.210 raeburn 2282: }
1.188 raeburn 2283: } else {
1.252 raeburn 2284: if ($context eq 'selfcreate') {
1.401 raeburn 2285: if ($canmodify{$item}) {
2286: if ($newuser eq 'email') {
2287: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2288: } else {
1.401 raeburn 2289: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2290: }
1.401 raeburn 2291: $editable ++;
2292: } else {
2293: $hiderow = 1;
1.252 raeburn 2294: }
1.253 raeburn 2295: } else {
2296: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2297: }
1.188 raeburn 2298: }
2299: } else {
1.219 raeburn 2300: if ($canmodify{$item}) {
1.252 raeburn 2301: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2302: if (($item eq 'id') && (!$newuser)) {
2303: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2304: }
1.188 raeburn 2305: } else {
1.252 raeburn 2306: $row .= $userenv{$item};
1.188 raeburn 2307: }
2308: }
1.252 raeburn 2309: $row .= &Apache::lonhtmlcommon::row_closure(1);
2310: if (!$hiderow) {
2311: $output .= $row;
2312: $rowcount ++;
2313: }
1.188 raeburn 2314: }
1.286 raeburn 2315: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2316: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2317: if (ref($types) eq 'ARRAY') {
2318: if (@{$types} > 0) {
2319: my ($hiderow,$shown);
2320: if ($canmodify_status{'inststatus'}) {
2321: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2322: } else {
2323: if ($userenv{'inststatus'} eq '') {
2324: $hiderow = 1;
1.334 raeburn 2325: } else {
2326: my @showitems;
2327: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2328: if (exists($usertypes->{$item})) {
2329: push(@showitems,$usertypes->{$item});
2330: } else {
2331: push(@showitems,$item);
2332: }
2333: }
2334: if (@showitems) {
2335: $shown = join(', ',@showitems);
2336: } else {
2337: $hiderow = 1;
2338: }
1.286 raeburn 2339: }
2340: }
2341: if (!$hiderow) {
1.389 bisitz 2342: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2343: $shown.&Apache::lonhtmlcommon::row_closure(1);
2344: if ($context eq 'selfcreate') {
2345: $rowcount ++;
2346: }
2347: $output .= $row;
2348: }
2349: }
2350: }
2351: }
1.391 raeburn 2352: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2353: if ($captchaform) {
2354: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'},
1.409 ! raeburn 2355: 'LC_pick_box_title')."\n";
! 2356: if ($recaptchaversion >=2) {
! 2357: $output .= '<script src="https://www.google.com/recaptcha/api.js"></script>'."\n";
! 2358: }
! 2359: $output .= $captchaform."\n".'<br /><br />'.
1.391 raeburn 2360: &Apache::lonhtmlcommon::row_closure(1);
2361: $rowcount ++;
2362: }
2363: my $submit_text = &mt('Create account');
2364: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2365: '<br /><input type="submit" name="createaccount" value="'.
2366: $submit_text.'" />'.
1.396 raeburn 2367: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2368: &Apache::lonhtmlcommon::row_closure(1);
2369: }
1.188 raeburn 2370: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2371: if (wantarray) {
1.252 raeburn 2372: if ($context eq 'selfcreate') {
2373: return($output,$rowcount,$editable);
2374: } else {
1.388 bisitz 2375: return $output;
1.252 raeburn 2376: }
1.206 raeburn 2377: } else {
2378: return $output;
2379: }
1.188 raeburn 2380: }
2381:
1.286 raeburn 2382: sub pick_inst_statuses {
2383: my ($curr,$usertypes,$types) = @_;
2384: my ($output,$rem,@currtypes);
2385: if ($curr ne '') {
2386: @currtypes = map { &unescape($_); } split(/:/,$curr);
2387: }
2388: my $numinrow = 2;
2389: if (ref($types) eq 'ARRAY') {
2390: $output = '<table>';
2391: my $lastcolspan;
2392: for (my $i=0; $i<@{$types}; $i++) {
2393: if (defined($usertypes->{$types->[$i]})) {
2394: my $rem = $i%($numinrow);
2395: if ($rem == 0) {
2396: if ($i<@{$types}-1) {
2397: if ($i > 0) {
2398: $output .= '</tr>';
2399: }
2400: $output .= '<tr>';
2401: }
2402: } elsif ($i==@{$types}-1) {
2403: my $colsleft = $numinrow - $rem;
2404: if ($colsleft > 1) {
2405: $lastcolspan = ' colspan="'.$colsleft.'"';
2406: }
2407: }
2408: my $check = ' ';
2409: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2410: $check = ' checked="checked" ';
2411: }
2412: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2413: '<span class="LC_nobreak"><label>'.
2414: '<input type="checkbox" name="inststatus" '.
2415: 'value="'.$types->[$i].'"'.$check.'/>'.
2416: $usertypes->{$types->[$i]}.'</label></span></td>';
2417: }
2418: }
2419: $output .= '</tr></table>';
2420: }
2421: return $output;
2422: }
2423:
1.257 raeburn 2424: sub selfcreate_canmodify {
2425: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2426: if (ref($inst_results) eq 'HASH') {
2427: my @inststatuses = &get_inststatuses($inst_results);
2428: if (@inststatuses == 0) {
2429: @inststatuses = ('default');
2430: }
2431: $rolesarray = \@inststatuses;
2432: }
2433: my %canmodify =
2434: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2435: $rolesarray);
2436: return %canmodify;
2437: }
2438:
1.252 raeburn 2439: sub get_inststatuses {
2440: my ($insthashref) = @_;
2441: my @inststatuses = ();
2442: if (ref($insthashref) eq 'HASH') {
2443: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2444: @inststatuses = @{$insthashref->{'inststatus'}};
2445: }
2446: }
2447: return @inststatuses;
2448: }
2449:
1.4 www 2450: # ================================================================= Phase Three
1.42 matthew 2451: sub update_user_data {
1.375 raeburn 2452: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2453: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2454: $env{'form.ccdomain'});
1.27 matthew 2455: # Error messages
1.188 raeburn 2456: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2457: my $end = '</span><br /><br />';
2458: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2459: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2460: &mt('Return to previous page').'</a>'.
2461: &Apache::loncommon::end_page();
2462: my $now = time;
1.40 www 2463: my $title;
1.101 albertel 2464: if (exists($env{'form.makeuser'})) {
1.40 www 2465: $title='Set Privileges for New User';
2466: } else {
2467: $title='Modify User Privileges';
2468: }
1.213 raeburn 2469: my $newuser = 0;
1.160 raeburn 2470: my ($jsback,$elements) = &crumb_utilities();
2471: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2472: '// <![CDATA['."\n".
2473: $jsback."\n".
2474: '// ]]>'."\n".
2475: '</script>'."\n";
1.318 raeburn 2476: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 2477: push (@{$brcrum},
2478: {href => "javascript:backPage(document.userupdate)",
2479: text => $breadcrumb_text{'search'},
2480: faq => 282,
2481: bug => 'Instructor Interface',}
2482: );
2483: if ($env{'form.prevphase'} eq 'userpicked') {
2484: push(@{$brcrum},
2485: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2486: text => $breadcrumb_text{'userpicked'},
2487: faq => 282,
2488: bug => 'Instructor Interface',});
1.233 raeburn 2489: }
1.224 raeburn 2490: my $helpitem = 'Course_Change_Privileges';
2491: if ($env{'form.action'} eq 'singlestudent') {
2492: $helpitem = 'Course_Add_Student';
2493: }
1.351 raeburn 2494: push(@{$brcrum},
2495: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2496: text => $breadcrumb_text{'modify'},
2497: faq => 282,
2498: bug => 'Instructor Interface',},
2499: {href => "/adm/createuser",
2500: text => "Result",
2501: faq => 282,
2502: bug => 'Instructor Interface',
2503: help => $helpitem});
2504: my $args = {bread_crumbs => $brcrum,
2505: bread_crumbs_component => 'User Management'};
2506: if ($env{'form.popup'}) {
2507: $args->{'no_nav_bar'} = 1;
2508: }
2509: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2510: $r->print(&update_result_form($uhome));
1.27 matthew 2511: # Check Inputs
1.101 albertel 2512: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2513: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2514: return;
2515: }
1.138 albertel 2516: if ( $env{'form.ccuname'} ne
2517: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2518: $r->print($error.&mt('Invalid login name.').' '.
2519: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2520: $end.$rtnlink);
1.27 matthew 2521: return;
2522: }
1.101 albertel 2523: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2524: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2525: return;
2526: }
1.138 albertel 2527: if ( $env{'form.ccdomain'} ne
2528: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2529: $r->print($error.&mt('Invalid domain name.').' '.
2530: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2531: $end.$rtnlink);
1.27 matthew 2532: return;
2533: }
1.219 raeburn 2534: if ($uhome eq 'no_host') {
2535: $newuser = 1;
2536: }
1.101 albertel 2537: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2538: # Modifying an existing user, so check the validity of the name
2539: if ($uhome eq 'no_host') {
1.389 bisitz 2540: $r->print(
2541: $error
2542: .'<p class="LC_error">'
2543: .&mt('Unable to determine home server for [_1] in domain [_2].',
2544: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2545: .'</p>');
1.29 matthew 2546: return;
2547: }
2548: }
1.27 matthew 2549: # Determine authentication method and password for the user being modified
2550: my $amode='';
2551: my $genpwd='';
1.101 albertel 2552: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2553: $amode='krb';
1.101 albertel 2554: $amode.=$env{'form.krbver'};
2555: $genpwd=$env{'form.krbarg'};
2556: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2557: $amode='internal';
1.101 albertel 2558: $genpwd=$env{'form.intarg'};
2559: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2560: $amode='unix';
1.101 albertel 2561: $genpwd=$env{'form.fsysarg'};
2562: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2563: $amode='localauth';
1.101 albertel 2564: $genpwd=$env{'form.locarg'};
1.27 matthew 2565: $genpwd=" " if (!$genpwd);
1.101 albertel 2566: } elsif (($env{'form.login'} eq 'nochange') ||
2567: ($env{'form.login'} eq '' )) {
1.34 matthew 2568: # There is no need to tell the user we did not change what they
2569: # did not ask us to change.
1.35 matthew 2570: # If they are creating a new user but have not specified login
2571: # information this will be caught below.
1.30 matthew 2572: } else {
1.367 golterma 2573: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2574: return;
1.27 matthew 2575: }
1.164 albertel 2576:
1.188 raeburn 2577: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2578: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2579: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2580: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2581:
1.193 raeburn 2582: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2583: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2584: my @usertools = ('aboutme','blog','webdav','portfolio');
1.384 raeburn 2585: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 2586: my @requestauthor = ('requestauthor');
1.286 raeburn 2587: my ($othertitle,$usertypes,$types) =
2588: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2589: my %canmodify_status =
2590: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2591: ['inststatus']);
1.101 albertel 2592: if ($env{'form.makeuser'}) {
1.164 albertel 2593: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2594: # Check for the authentication mode and password
2595: if (! $amode || ! $genpwd) {
1.193 raeburn 2596: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2597: return;
1.18 albertel 2598: }
1.29 matthew 2599: # Determine desired host
1.101 albertel 2600: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2601: if (lc($desiredhost) eq 'default') {
2602: $desiredhost = undef;
2603: } else {
1.147 albertel 2604: my %home_servers =
2605: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2606: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2607: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2608: return;
2609: }
2610: }
2611: # Check ID format
2612: my %checkhash;
2613: my %checks = ('id' => 1);
2614: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2615: 'newuser' => $newuser,
1.196 raeburn 2616: 'id' => $env{'form.cid'},
1.193 raeburn 2617: );
1.196 raeburn 2618: if ($env{'form.cid'} ne '') {
2619: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2620: \%rulematch,\%inst_results,\%curr_rules);
2621: if (ref($alerts{'id'}) eq 'HASH') {
2622: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2623: my $domdesc =
2624: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2625: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2626: my $userchkmsg;
2627: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2628: $userchkmsg =
2629: &Apache::loncommon::instrule_disallow_msg('id',
2630: $domdesc,1).
2631: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2632: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2633: }
2634: $r->print($error.&mt('Invalid ID format').$end.
2635: $userchkmsg.$rtnlink);
2636: return;
2637: }
2638: }
1.29 matthew 2639: }
2640: }
1.367 golterma 2641: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2642: # Call modifyuser
2643: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2644: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2645: $amode,$genpwd,$env{'form.cfirstname'},
2646: $env{'form.cmiddlename'},$env{'form.clastname'},
2647: $env{'form.cgeneration'},undef,$desiredhost,
2648: $env{'form.cpermanentemail'});
1.77 www 2649: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2650: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2651: $env{'form.ccdomain'});
1.334 raeburn 2652: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2653: if ($uhome ne 'no_host') {
1.334 raeburn 2654: if ($context eq 'domain') {
1.378 raeburn 2655: foreach my $name ('portfolio','author') {
2656: if ($env{'form.custom_'.$name.'quota'} == 1) {
2657: if ($env{'form.'.$name.'quota'} eq '') {
2658: $newcustom{$name.'quota'} = 0;
2659: } else {
2660: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2661: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2662: }
2663: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2664: $changed{$name.'quota'} = 1;
2665: }
1.334 raeburn 2666: }
2667: }
2668: foreach my $item (@usertools) {
2669: if ($env{'form.custom'.$item} == 1) {
2670: $newcustom{$item} = $env{'form.tools_'.$item};
2671: $changed{$item} = &tool_admin($item,$newcustom{$item},
2672: \%changeHash,'tools');
2673: }
1.267 raeburn 2674: }
1.334 raeburn 2675: foreach my $item (@requestcourses) {
1.341 raeburn 2676: if ($env{'form.custom'.$item} == 1) {
2677: $newcustom{$item} = $env{'form.crsreq_'.$item};
2678: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2679: $newcustom{$item} .= '=';
1.383 raeburn 2680: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2681: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2682: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2683: }
1.334 raeburn 2684: }
1.341 raeburn 2685: $changed{$item} = &tool_admin($item,$newcustom{$item},
2686: \%changeHash,'requestcourses');
1.334 raeburn 2687: }
1.275 raeburn 2688: }
1.362 raeburn 2689: if ($env{'form.customrequestauthor'} == 1) {
2690: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2691: $changed{'requestauthor'} = &tool_admin('requestauthor',
2692: $newcustom{'requestauthor'},
2693: \%changeHash,'requestauthor');
2694: }
1.275 raeburn 2695: }
1.334 raeburn 2696: if ($canmodify_status{'inststatus'}) {
2697: if (exists($env{'form.inststatus'})) {
2698: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2699: if (@inststatuses > 0) {
2700: $changeHash{'inststatus'} = join(',',@inststatuses);
2701: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2702: }
2703: }
1.232 raeburn 2704: }
1.334 raeburn 2705: if (keys(%changed)) {
2706: foreach my $item (@userinfo) {
2707: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2708: }
1.267 raeburn 2709: my $chgresult =
2710: &Apache::lonnet::put('environment',\%changeHash,
2711: $env{'form.ccdomain'},$env{'form.ccuname'});
2712: }
1.232 raeburn 2713: }
1.219 raeburn 2714: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2715: &Apache::lonnet::hostname($uhome));
1.101 albertel 2716: } elsif (($env{'form.login'} ne 'nochange') &&
2717: ($env{'form.login'} ne '' )) {
1.27 matthew 2718: # Modify user privileges
2719: if (! $amode || ! $genpwd) {
1.193 raeburn 2720: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2721: return;
1.20 harris41 2722: }
1.395 bisitz 2723: # Only allow authentication modification if the person has authority
1.101 albertel 2724: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2725: $r->print('Modifying authentication: '.
1.31 matthew 2726: &Apache::lonnet::modifyuserauth(
1.101 albertel 2727: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2728: $amode,$genpwd));
1.102 albertel 2729: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2730: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2731: } else {
1.27 matthew 2732: # Okay, this is a non-fatal error.
1.395 bisitz 2733: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2734: }
1.28 matthew 2735: }
1.344 bisitz 2736: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2737: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2738: ##
1.375 raeburn 2739: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2740: if ($context eq 'course') {
1.375 raeburn 2741: ($cnum,$cdom) =
2742: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2743: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2744: if ($showcredits) {
2745: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2746: }
1.213 raeburn 2747: }
1.101 albertel 2748: if (! $env{'form.makeuser'} ) {
1.28 matthew 2749: # Check for need to change
2750: my %userenv = &Apache::lonnet::get
1.134 raeburn 2751: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2752: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2753: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2754: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2755: 'requestcourses.community','requestcourses.textbook',
2756: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2757: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.362 raeburn 2758: 'requestauthor'],
1.160 raeburn 2759: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2760: my ($tmp) = keys(%userenv);
2761: if ($tmp =~ /^(con_lost|error)/i) {
2762: %userenv = ();
2763: }
1.206 raeburn 2764: my $no_forceid_alert;
2765: # Check to see if user information can be changed
2766: my %domconfig =
2767: &Apache::lonnet::get_dom('configuration',['usermodification'],
2768: $env{'form.ccdomain'});
1.213 raeburn 2769: my @statuses = ('active','future');
2770: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2771: my ($auname,$audom);
1.220 raeburn 2772: if ($context eq 'author') {
1.206 raeburn 2773: $auname = $env{'user.name'};
2774: $audom = $env{'user.domain'};
2775: }
2776: foreach my $item (keys(%roles)) {
1.220 raeburn 2777: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2778: if ($context eq 'course') {
2779: if ($cnum ne '' && $cdom ne '') {
2780: if ($rolenum eq $cnum && $roledom eq $cdom) {
2781: if (!grep(/^\Q$role\E$/,@userroles)) {
2782: push(@userroles,$role);
2783: }
2784: }
2785: }
2786: } elsif ($context eq 'author') {
2787: if ($rolenum eq $auname && $roledom eq $audom) {
2788: if (!grep(/^\Q$role\E$/,@userroles)) {
2789: push(@userroles,$role);
2790: }
2791: }
2792: }
2793: }
1.220 raeburn 2794: if ($env{'form.action'} eq 'singlestudent') {
2795: if (!grep(/^st$/,@userroles)) {
2796: push(@userroles,'st');
2797: }
2798: } else {
2799: # Check for course or co-author roles being activated or re-enabled
2800: if ($context eq 'author' || $context eq 'course') {
2801: foreach my $key (keys(%env)) {
2802: if ($context eq 'author') {
2803: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2804: if (!grep(/^\Q$1\E$/,@userroles)) {
2805: push(@userroles,$1);
2806: }
2807: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2808: if (!grep(/^\Q$1\E$/,@userroles)) {
2809: push(@userroles,$1);
2810: }
1.206 raeburn 2811: }
1.220 raeburn 2812: } elsif ($context eq 'course') {
2813: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2814: if (!grep(/^\Q$1\E$/,@userroles)) {
2815: push(@userroles,$1);
2816: }
2817: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
2818: if (!grep(/^\Q$1\E$/,@userroles)) {
2819: push(@userroles,$1);
2820: }
1.206 raeburn 2821: }
2822: }
2823: }
2824: }
2825: }
2826: #Check to see if we can change personal data for the user
2827: my (@mod_disallowed,@longroles);
2828: foreach my $role (@userroles) {
2829: if ($role eq 'cr') {
2830: push(@longroles,'Custom');
2831: } else {
1.318 raeburn 2832: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 2833: }
2834: }
1.219 raeburn 2835: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
2836: foreach my $item (@userinfo) {
1.28 matthew 2837: # Strip leading and trailing whitespace
1.203 raeburn 2838: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 2839: if (!$canmodify{$item}) {
1.207 raeburn 2840: if (defined($env{'form.c'.$item})) {
2841: if ($env{'form.c'.$item} ne $userenv{$item}) {
2842: push(@mod_disallowed,$item);
2843: }
1.206 raeburn 2844: }
2845: $env{'form.c'.$item} = $userenv{$item};
2846: }
1.28 matthew 2847: }
1.259 bisitz 2848: # Check to see if we can change the Student/Employee ID
1.196 raeburn 2849: my $forceid = $env{'form.forceid'};
2850: my $recurseid = $env{'form.recurseid'};
2851: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 2852: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
2853: $env{'form.ccuname'});
2854: if (($uidhash{$env{'form.ccuname'}}) &&
2855: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
2856: (!$forceid)) {
2857: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
2858: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 2859: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 2860: .'<br />'
2861: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
2862: .'<br />'."\n";
1.203 raeburn 2863: }
2864: }
2865: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 2866: my $checkhash;
2867: my $checks = { 'id' => 1 };
2868: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
2869: { 'newuser' => $newuser,
2870: 'id' => $env{'form.cid'},
2871: };
2872: &Apache::loncommon::user_rule_check($checkhash,$checks,
2873: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
2874: if (ref($alerts{'id'}) eq 'HASH') {
2875: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 2876: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 2877: }
2878: }
2879: }
1.378 raeburn 2880: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
2881: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 2882: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 2883: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 2884: @disporder = ('inststatus');
2885: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 2886: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 2887: } else {
2888: push(@disporder,'reqcrsotherdom');
2889: }
2890: push(@disporder,('quota','tools'));
1.338 raeburn 2891: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 2892: foreach my $name ('portfolio','author') {
2893: ($olddefquota{$name},$oldsettingstatus{$name}) =
2894: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
2895: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
2896: }
1.334 raeburn 2897: my %canshow;
1.220 raeburn 2898: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 2899: $canshow{'quota'} = 1;
1.220 raeburn 2900: }
1.267 raeburn 2901: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 2902: $canshow{'tools'} = 1;
1.267 raeburn 2903: }
1.275 raeburn 2904: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 2905: $canshow{'requestcourses'} = 1;
1.300 raeburn 2906: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 2907: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 2908: }
1.286 raeburn 2909: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 2910: $canshow{'inststatus'} = 1;
1.286 raeburn 2911: }
1.362 raeburn 2912: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
2913: $canshow{'requestauthor'} = 1;
2914: }
1.267 raeburn 2915: my (%changeHash,%changed);
1.286 raeburn 2916: if ($oldinststatus eq '') {
1.334 raeburn 2917: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 2918: } else {
2919: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2920: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2921: } else {
1.334 raeburn 2922: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2923: }
2924: }
2925: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 2926: if ($canmodify_status{'inststatus'}) {
2927: $canshow{'inststatus'} = 1;
1.286 raeburn 2928: if (exists($env{'form.inststatus'})) {
2929: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2930: if (@inststatuses > 0) {
2931: $newinststatus = join(':',map { &escape($_); } @inststatuses);
2932: $changeHash{'inststatus'} = $newinststatus;
2933: if ($newinststatus ne $oldinststatus) {
2934: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 2935: foreach my $name ('portfolio','author') {
2936: ($newdefquota{$name},$newsettingstatus{$name}) =
2937: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
2938: }
1.286 raeburn 2939: }
2940: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2941: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 2942: } else {
1.337 raeburn 2943: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 2944: }
1.334 raeburn 2945: }
2946: } else {
2947: $newinststatus = '';
2948: $changeHash{'inststatus'} = $newinststatus;
2949: $newsettings{'inststatus'} = $othertitle;
2950: if ($newinststatus ne $oldinststatus) {
2951: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 2952: foreach my $name ('portfolio','author') {
2953: ($newdefquota{$name},$newsettingstatus{$name}) =
2954: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
2955: }
1.286 raeburn 2956: }
2957: }
1.334 raeburn 2958: } elsif ($context ne 'selfcreate') {
2959: $canshow{'inststatus'} = 1;
1.337 raeburn 2960: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 2961: }
1.378 raeburn 2962: foreach my $name ('portfolio','author') {
2963: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
2964: }
1.334 raeburn 2965: if ($context eq 'domain') {
1.378 raeburn 2966: foreach my $name ('portfolio','author') {
2967: if ($userenv{$name.'quota'} ne '') {
2968: $oldquota{$name} = $userenv{$name.'quota'};
2969: if ($env{'form.custom_'.$name.'quota'} == 1) {
2970: if ($env{'form.'.$name.'quota'} eq '') {
2971: $newquota{$name} = 0;
2972: } else {
2973: $newquota{$name} = $env{'form.'.$name.'quota'};
2974: $newquota{$name} =~ s/[^\d\.]//g;
2975: }
2976: if ($newquota{$name} != $oldquota{$name}) {
2977: if ("a_admin($newquota{$name},\%changeHash,$name)) {
2978: $changed{$name.'quota'} = 1;
2979: }
2980: }
1.334 raeburn 2981: } else {
1.378 raeburn 2982: if ("a_admin('',\%changeHash,$name)) {
2983: $changed{$name.'quota'} = 1;
2984: $newquota{$name} = $newdefquota{$name};
2985: $newisdefault{$name} = 1;
2986: }
1.334 raeburn 2987: }
1.149 raeburn 2988: } else {
1.378 raeburn 2989: $oldisdefault{$name} = 1;
2990: $oldquota{$name} = $olddefquota{$name};
2991: if ($env{'form.custom_'.$name.'quota'} == 1) {
2992: if ($env{'form.'.$name.'quota'} eq '') {
2993: $newquota{$name} = 0;
2994: } else {
2995: $newquota{$name} = $env{'form.'.$name.'quota'};
2996: $newquota{$name} =~ s/[^\d\.]//g;
2997: }
2998: if ("a_admin($newquota{$name},\%changeHash,$name)) {
2999: $changed{$name.'quota'} = 1;
3000: }
1.334 raeburn 3001: } else {
1.378 raeburn 3002: $newquota{$name} = $newdefquota{$name};
3003: $newisdefault{$name} = 1;
1.334 raeburn 3004: }
1.378 raeburn 3005: }
3006: if ($oldisdefault{$name}) {
3007: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3008: } else {
3009: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3010: }
3011: if ($newisdefault{$name}) {
3012: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3013: } else {
3014: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3015: }
3016: }
1.334 raeburn 3017: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3018: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3019: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3020: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3021: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3022: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3023: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3024: } else {
1.334 raeburn 3025: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3026: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3027: }
3028: }
1.334 raeburn 3029: foreach my $item (@userinfo) {
3030: if ($env{'form.c'.$item} ne $userenv{$item}) {
3031: $namechanged{$item} = 1;
3032: }
1.204 raeburn 3033: }
1.378 raeburn 3034: foreach my $name ('portfolio','author') {
1.390 bisitz 3035: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3036: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3037: }
1.334 raeburn 3038: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3039: my ($chgresult,$namechgresult);
3040: if (keys(%changed) > 0) {
3041: $chgresult =
1.204 raeburn 3042: &Apache::lonnet::put('environment',\%changeHash,
3043: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3044: if ($chgresult eq 'ok') {
3045: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3046: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3047: my %newenvhash;
3048: foreach my $key (keys(%changed)) {
1.299 raeburn 3049: if (($key eq 'official') || ($key eq 'unofficial')
1.403 raeburn 3050: || ($key eq 'community') || ($key eq 'textbook')) {
1.279 raeburn 3051: $newenvhash{'environment.requestcourses.'.$key} =
3052: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3053: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3054: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3055: } else {
3056: $newenvhash{'environment.canrequest.'.$key} =
3057: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3058: $key,'reload','requestcourses');
3059: }
1.362 raeburn 3060: } elsif ($key eq 'requestauthor') {
3061: $newenvhash{'environment.'.$key} = $changeHash{$key};
3062: if ($changeHash{$key}) {
3063: $newenvhash{'environment.canrequest.author'} = 1;
3064: } else {
3065: $newenvhash{'environment.canrequest.author'} =
3066: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3067: $key,'reload','requestauthor');
3068: }
1.275 raeburn 3069: } elsif ($key ne 'quota') {
1.270 raeburn 3070: $newenvhash{'environment.tools.'.$key} =
3071: $changeHash{'tools.'.$key};
1.279 raeburn 3072: if ($changeHash{'tools.'.$key} ne '') {
3073: $newenvhash{'environment.availabletools.'.$key} =
3074: $changeHash{'tools.'.$key};
3075: } else {
3076: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3077: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3078: $key,'reload','tools');
1.279 raeburn 3079: }
1.270 raeburn 3080: }
3081: }
1.271 raeburn 3082: if (keys(%newenvhash)) {
3083: &Apache::lonnet::appenv(\%newenvhash);
3084: }
1.267 raeburn 3085: }
3086: }
1.204 raeburn 3087: }
1.334 raeburn 3088: if (keys(%namechanged) > 0) {
1.337 raeburn 3089: foreach my $field (@userinfo) {
3090: $changeHash{$field} = $env{'form.c'.$field};
3091: }
3092: # Make the change
1.204 raeburn 3093: $namechgresult =
3094: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3095: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3096: $changeHash{'firstname'},$changeHash{'middlename'},
3097: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3098: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3099: %userupdate = (
3100: lastname => $env{'form.clastname'},
3101: middlename => $env{'form.cmiddlename'},
3102: firstname => $env{'form.cfirstname'},
3103: generation => $env{'form.cgeneration'},
3104: id => $env{'form.cid'},
3105: );
1.204 raeburn 3106: }
1.334 raeburn 3107: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3108: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3109: # Tell the user we changed the name
1.334 raeburn 3110: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3111: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3112: \%oldsettings, \%oldsettingstext,\%newsettings,
3113: \%newsettingstext);
1.203 raeburn 3114: if ($env{'form.cid'} ne $userenv{'id'}) {
3115: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3116: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3117: if (($recurseid) &&
3118: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3119: my $idresult =
3120: &Apache::lonuserutils::propagate_id_change(
3121: $env{'form.ccuname'},$env{'form.ccdomain'},
3122: \%userupdate);
3123: $r->print('<br />'.$idresult.'<br />');
3124: }
1.196 raeburn 3125: }
1.149 raeburn 3126: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3127: ($env{'form.ccuname'} eq $env{'user.name'})) {
3128: my %newenvhash;
3129: foreach my $key (keys(%changeHash)) {
3130: $newenvhash{'environment.'.$key} = $changeHash{$key};
3131: }
1.238 raeburn 3132: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3133: }
1.28 matthew 3134: } else { # error occurred
1.389 bisitz 3135: $r->print(
3136: '<p class="LC_error">'
3137: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3138: '"'.$env{'form.ccuname'}.'"',
3139: '"'.$env{'form.ccdomain'}.'"')
3140: .'</p>');
1.28 matthew 3141: }
1.334 raeburn 3142: } else { # End of if ($env ... ) logic
1.275 raeburn 3143: # They did not want to change the users name, quota, tool availability,
3144: # or ability to request creation of courses,
1.267 raeburn 3145: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3146: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3147: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3148: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3149: }
1.206 raeburn 3150: if (@mod_disallowed) {
3151: my ($rolestr,$contextname);
3152: if (@longroles > 0) {
3153: $rolestr = join(', ',@longroles);
3154: } else {
3155: $rolestr = &mt('No roles');
3156: }
3157: if ($context eq 'course') {
1.399 bisitz 3158: $contextname = 'course';
1.206 raeburn 3159: } elsif ($context eq 'author') {
1.399 bisitz 3160: $contextname = 'co-author';
1.206 raeburn 3161: }
3162: $r->print(&mt('The following fields were not updated: ').'<ul>');
3163: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3164: foreach my $field (@mod_disallowed) {
3165: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3166: }
1.207 raeburn 3167: $r->print('</ul>');
3168: if (@mod_disallowed == 1) {
1.399 bisitz 3169: $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future $contextname roles:"));
1.207 raeburn 3170: } else {
1.399 bisitz 3171: $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future $contextname roles:"));
1.207 raeburn 3172: }
1.292 bisitz 3173: my $helplink = 'javascript:helpMenu('."'display'".')';
3174: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3175: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3176: ,'<a href="'.$helplink.'">','</a>')
3177: .'<br />');
1.206 raeburn 3178: }
1.259 bisitz 3179: $r->print('<span class="LC_warning">'
3180: .$no_forceid_alert
3181: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3182: .'</span>');
1.4 www 3183: }
1.367 golterma 3184: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3185: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3186: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3187: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3188: my $linktext = ($crstype eq 'Community' ?
3189: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3190: $r->print(
3191: &Apache::lonhtmlcommon::actionbox([
3192: '<a href="javascript:backPage(document.userupdate)">'
3193: .($crstype eq 'Community' ?
3194: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3195: .'</a>']));
1.220 raeburn 3196: } else {
1.375 raeburn 3197: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3198: if (keys(%namechanged) > 0) {
1.220 raeburn 3199: if ($context eq 'course') {
3200: if (@userroles > 0) {
1.225 raeburn 3201: if ((@rolechanges == 0) ||
3202: (!(grep(/^st$/,@rolechanges)))) {
3203: if (grep(/^st$/,@userroles)) {
3204: my $classlistupdated =
3205: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3206: $cnum,$env{'form.ccdomain'},
3207: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3208: }
1.220 raeburn 3209: }
3210: }
3211: }
3212: }
1.226 raeburn 3213: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3214: $env{'form.ccdomain'});
3215: if ($env{'form.popup'}) {
3216: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3217: } else {
1.367 golterma 3218: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3219: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3220: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3221: }
1.220 raeburn 3222: }
3223: }
3224:
1.334 raeburn 3225: sub display_userinfo {
1.362 raeburn 3226: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3227: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3228: $newsetting,$newsettingtext) = @_;
3229: return unless (ref($order) eq 'ARRAY' &&
3230: ref($canshow) eq 'HASH' &&
3231: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3232: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3233: ref($usertools) eq 'ARRAY' &&
3234: ref($userenv) eq 'HASH' &&
3235: ref($changedhash) eq 'HASH' &&
3236: ref($oldsetting) eq 'HASH' &&
3237: ref($oldsettingtext) eq 'HASH' &&
3238: ref($newsetting) eq 'HASH' &&
3239: ref($newsettingtext) eq 'HASH');
3240: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3241: 'ui' => 'User Information',
1.334 raeburn 3242: 'uic' => 'User Information Changed',
3243: 'firstname' => 'First Name',
3244: 'middlename' => 'Middle Name',
3245: 'lastname' => 'Last Name',
3246: 'generation' => 'Generation',
3247: 'id' => 'Student/Employee ID',
3248: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3249: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3250: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3251: 'blog' => 'Blog Availability',
1.361 raeburn 3252: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3253: 'aboutme' => 'Personal Information Page Availability',
3254: 'portfolio' => 'Portfolio Availability',
3255: 'official' => 'Can Request Official Courses',
3256: 'unofficial' => 'Can Request Unofficial Courses',
3257: 'community' => 'Can Request Communities',
1.384 raeburn 3258: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 3259: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3260: 'inststatus' => "Affiliation",
3261: 'prvs' => 'Previous Value:',
3262: 'chto' => 'Changed To:'
3263: );
3264: if ($changed) {
1.372 raeburn 3265: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3266: &Apache::loncommon::start_data_table().
3267: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3268: $r->print("<th> </th>\n");
1.367 golterma 3269: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3270: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3271: $r->print(&Apache::loncommon::end_data_table_header_row());
3272: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3273:
1.334 raeburn 3274: foreach my $item (@userinfo) {
3275: my $value = $env{'form.c'.$item};
1.367 golterma 3276: #show changes only:
1.383 raeburn 3277: unless ($value eq $userenv->{$item}){
1.367 golterma 3278: $r->print(&Apache::loncommon::start_data_table_row());
3279: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3280: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3281: $r->print("<td>$value </td>\n");
3282: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3283: }
3284: }
3285: foreach my $entry (@{$order}) {
1.383 raeburn 3286: if ($canshow->{$entry}) {
3287: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3288: my @items;
3289: if ($entry eq 'requestauthor') {
3290: @items = ($entry);
3291: } else {
3292: @items = @{$requestcourses};
1.384 raeburn 3293: }
1.383 raeburn 3294: foreach my $item (@items) {
3295: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3296: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3297: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3298: $r->print("<td>$lt{$item}</td>\n");
3299: $r->print("<td>".$oldsetting->{$item});
3300: if ($oldsettingtext->{$item}) {
3301: if ($oldsetting->{$item}) {
3302: $r->print(' -- ');
3303: }
3304: $r->print($oldsettingtext->{$item});
3305: }
3306: $r->print("</td>\n");
3307: $r->print("<td>".$newsetting->{$item});
3308: if ($newsettingtext->{$item}) {
3309: if ($newsetting->{$item}) {
3310: $r->print(' -- ');
3311: }
3312: $r->print($newsettingtext->{$item});
3313: }
3314: $r->print("</td>\n");
3315: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3316: }
3317: }
3318: } elsif ($entry eq 'tools') {
3319: foreach my $item (@{$usertools}) {
1.383 raeburn 3320: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3321: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3322: $r->print("<td>$lt{$item}</td>\n");
3323: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3324: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3325: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3326: }
3327: }
1.378 raeburn 3328: } elsif ($entry eq 'quota') {
3329: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3330: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3331: foreach my $name ('portfolio','author') {
1.383 raeburn 3332: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3333: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3334: $r->print("<td>$lt{$name.$entry}</td>\n");
3335: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3336: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3337: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3338: }
3339: }
3340: }
1.334 raeburn 3341: } else {
1.383 raeburn 3342: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3343: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3344: $r->print("<td>$lt{$entry}</td>\n");
3345: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3346: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3347: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3348: }
3349: }
3350: }
3351: }
1.367 golterma 3352: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3353: } else {
3354: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3355: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3356: }
3357: return;
3358: }
3359:
1.275 raeburn 3360: sub tool_changes {
3361: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3362: $changed,$newaccess,$newaccesstext) = @_;
3363: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3364: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3365: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3366: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3367: return;
3368: }
1.383 raeburn 3369: my %reqdisplay = &requestchange_display();
1.300 raeburn 3370: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3371: my @options = ('approval','validate','autolimit');
1.306 raeburn 3372: my $optregex = join('|',@options);
1.300 raeburn 3373: my $cdom = $env{'request.role.domain'};
3374: foreach my $tool (@{$usertools}) {
1.383 raeburn 3375: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3376: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3377: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3378: my ($newop,$limit);
1.314 raeburn 3379: if ($env{'form.'.$context.'_'.$tool}) {
3380: $newop = $env{'form.'.$context.'_'.$tool};
3381: if ($newop eq 'autolimit') {
1.383 raeburn 3382: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3383: $limit =~ s/\D+//g;
3384: $newop .= '='.$limit;
3385: }
3386: }
1.300 raeburn 3387: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3388: if ($newop) {
3389: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3390: $changeHash,$context);
3391: if ($changed->{$tool}) {
1.383 raeburn 3392: if ($newop =~ /^autolimit/) {
3393: if ($limit) {
3394: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3395: } else {
3396: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3397: }
3398: } else {
3399: $newaccesstext->{$tool} = $reqdisplay{$newop};
3400: }
1.300 raeburn 3401: } else {
3402: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3403: }
3404: }
3405: } else {
3406: my @curr = split(',',$userenv->{$context.'.'.$tool});
3407: my @new;
3408: my $changedoms;
1.314 raeburn 3409: foreach my $req (@curr) {
3410: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3411: my $oldop = $1;
1.383 raeburn 3412: if ($oldop =~ /^autolimit=(\d*)/) {
3413: my $limit = $1;
3414: if ($limit) {
3415: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3416: } else {
3417: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3418: }
3419: } else {
3420: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3421: }
1.314 raeburn 3422: if ($oldop ne $newop) {
3423: $changedoms = 1;
3424: foreach my $item (@curr) {
3425: my ($reqdom,$option) = split(':',$item);
3426: unless ($reqdom eq $cdom) {
3427: push(@new,$item);
3428: }
3429: }
3430: if ($newop) {
3431: push(@new,$cdom.':'.$newop);
1.300 raeburn 3432: }
1.314 raeburn 3433: @new = sort(@new);
1.300 raeburn 3434: }
1.314 raeburn 3435: last;
1.300 raeburn 3436: }
1.314 raeburn 3437: }
3438: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3439: $changedoms = 1;
1.306 raeburn 3440: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3441: }
3442: if ($changedoms) {
1.314 raeburn 3443: my $newdomstr;
1.300 raeburn 3444: if (@new) {
3445: $newdomstr = join(',',@new);
3446: }
3447: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3448: $context);
3449: if ($changed->{$tool}) {
3450: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3451: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3452: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3453: $limit =~ s/\D+//g;
3454: if ($limit) {
1.383 raeburn 3455: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3456: } else {
1.383 raeburn 3457: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3458: }
1.314 raeburn 3459: } else {
1.306 raeburn 3460: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3461: }
1.300 raeburn 3462: } else {
1.383 raeburn 3463: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3464: }
3465: }
3466: }
3467: }
3468: }
3469: return;
3470: }
1.275 raeburn 3471: foreach my $tool (@{$usertools}) {
1.383 raeburn 3472: my ($newval,$limit,$envkey);
1.362 raeburn 3473: $envkey = $context.'.'.$tool;
1.306 raeburn 3474: if ($context eq 'requestcourses') {
3475: $newval = $env{'form.crsreq_'.$tool};
3476: if ($newval eq 'autolimit') {
1.383 raeburn 3477: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3478: $limit =~ s/\D+//g;
3479: $newval .= '='.$limit;
1.306 raeburn 3480: }
1.362 raeburn 3481: } elsif ($context eq 'requestauthor') {
3482: $newval = $env{'form.'.$context};
3483: $envkey = $context;
1.314 raeburn 3484: } else {
1.306 raeburn 3485: $newval = $env{'form.'.$context.'_'.$tool};
3486: }
1.362 raeburn 3487: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3488: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3489: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3490: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3491: my $currlimit = $1;
3492: if ($currlimit eq '') {
3493: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3494: } else {
3495: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3496: }
3497: } elsif ($userenv->{$envkey}) {
3498: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3499: } else {
3500: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3501: }
1.275 raeburn 3502: } else {
1.383 raeburn 3503: if ($userenv->{$envkey}) {
3504: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3505: } else {
3506: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3507: }
1.275 raeburn 3508: }
1.362 raeburn 3509: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3510: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3511: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3512: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3513: $context);
1.275 raeburn 3514: if ($changed->{$tool}) {
3515: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3516: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3517: if ($newval =~ /^autolimit/) {
3518: if ($limit) {
3519: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3520: } else {
3521: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3522: }
3523: } elsif ($newval) {
3524: $newaccesstext->{$tool} = $reqdisplay{$newval};
3525: } else {
3526: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3527: }
1.275 raeburn 3528: } else {
1.383 raeburn 3529: if ($newval) {
3530: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3531: } else {
3532: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3533: }
1.275 raeburn 3534: }
3535: } else {
3536: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3537: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3538: if ($newval =~ /^autolimit/) {
3539: if ($limit) {
3540: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3541: } else {
3542: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3543: }
3544: } elsif ($newval) {
3545: $newaccesstext->{$tool} = $reqdisplay{$newval};
3546: } else {
3547: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3548: }
1.275 raeburn 3549: } else {
1.383 raeburn 3550: if ($userenv->{$context.'.'.$tool}) {
3551: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3552: } else {
3553: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3554: }
1.275 raeburn 3555: }
3556: }
3557: } else {
3558: $newaccess->{$tool} = $oldaccess->{$tool};
3559: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3560: }
3561: } else {
3562: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3563: if ($changed->{$tool}) {
3564: $newaccess->{$tool} = &mt('default');
3565: } else {
3566: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3567: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3568: if ($newval =~ /^autolimit/) {
3569: if ($limit) {
3570: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3571: } else {
3572: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3573: }
3574: } elsif ($newval) {
3575: $newaccesstext->{$tool} = $reqdisplay{$newval};
3576: } else {
3577: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3578: }
1.275 raeburn 3579: } else {
1.383 raeburn 3580: if ($userenv->{$context.'.'.$tool}) {
3581: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3582: } else {
3583: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3584: }
1.275 raeburn 3585: }
3586: }
3587: }
3588: } else {
3589: $oldaccess->{$tool} = &mt('default');
3590: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3591: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3592: $context);
1.275 raeburn 3593: if ($changed->{$tool}) {
3594: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3595: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3596: if ($newval =~ /^autolimit/) {
3597: if ($limit) {
3598: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3599: } else {
3600: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3601: }
3602: } elsif ($newval) {
3603: $newaccesstext->{$tool} = $reqdisplay{$newval};
3604: } else {
3605: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3606: }
1.275 raeburn 3607: } else {
1.383 raeburn 3608: if ($newval) {
3609: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3610: } else {
3611: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3612: }
1.275 raeburn 3613: }
3614: } else {
3615: $newaccess->{$tool} = $oldaccess->{$tool};
3616: }
3617: } else {
3618: $newaccess->{$tool} = $oldaccess->{$tool};
3619: }
3620: }
3621: }
3622: return;
3623: }
3624:
1.220 raeburn 3625: sub update_roles {
1.375 raeburn 3626: my ($r,$context,$showcredits) = @_;
1.4 www 3627: my $now=time;
1.225 raeburn 3628: my @rolechanges;
1.220 raeburn 3629: my %disallowed;
1.73 sakharuk 3630: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3631: foreach my $key (keys(%env)) {
1.135 raeburn 3632: next if (! $env{$key});
1.190 raeburn 3633: next if ($key eq 'form.action');
1.27 matthew 3634: # Revoke roles
1.135 raeburn 3635: if ($key=~/^form\.rev/) {
3636: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3637: # Revoke standard role
1.170 albertel 3638: my ($scope,$role) = ($1,$2);
3639: my $result =
3640: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3641: $env{'form.ccuname'},
1.239 raeburn 3642: $scope,$role,'','',$context);
1.367 golterma 3643: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3644: &mt('Revoking [_1] in [_2]',
3645: &Apache::lonnet::plaintext($role),
1.372 raeburn 3646: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3647: $result ne "ok").'<br />');
3648: if ($result ne "ok") {
3649: $r->print(&mt('Error: [_1]',$result).'<br />');
3650: }
1.170 albertel 3651: if ($role eq 'st') {
1.202 raeburn 3652: my $result =
1.198 raeburn 3653: &Apache::lonuserutils::classlist_drop($scope,
3654: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3655: $now);
1.367 golterma 3656: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3657: }
1.225 raeburn 3658: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3659: push(@rolechanges,$role);
3660: }
1.196 raeburn 3661: }
1.195 raeburn 3662: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3663: # Revoke custom role
1.369 bisitz 3664: my $result = &Apache::lonnet::revokecustomrole(
3665: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3666: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3667: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3668: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3669: $result ne 'ok').'<br />');
3670: if ($result ne "ok") {
3671: $r->print(&mt('Error: [_1]',$result).'<br />');
3672: }
1.225 raeburn 3673: if (!grep(/^cr$/,@rolechanges)) {
3674: push(@rolechanges,'cr');
3675: }
1.64 www 3676: }
1.135 raeburn 3677: } elsif ($key=~/^form\.del/) {
3678: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3679: # Delete standard role
1.170 albertel 3680: my ($scope,$role) = ($1,$2);
3681: my $result =
3682: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3683: $env{'form.ccuname'},
1.239 raeburn 3684: $scope,$role,$now,0,1,'',
3685: $context);
1.367 golterma 3686: $r->print(&Apache::lonhtmlcommon::confirm_success(
3687: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3688: &Apache::lonnet::plaintext($role),
1.372 raeburn 3689: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3690: $result ne 'ok').'<br />');
3691: if ($result ne "ok") {
3692: $r->print(&mt('Error: [_1]',$result).'<br />');
3693: }
1.367 golterma 3694:
1.170 albertel 3695: if ($role eq 'st') {
1.202 raeburn 3696: my $result =
1.198 raeburn 3697: &Apache::lonuserutils::classlist_drop($scope,
3698: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3699: $now);
1.369 bisitz 3700: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3701: }
1.225 raeburn 3702: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3703: push(@rolechanges,$role);
3704: }
1.116 raeburn 3705: }
1.139 albertel 3706: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3707: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3708: # Delete custom role
1.369 bisitz 3709: my $result =
3710: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3711: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3712: 0,1,$context);
3713: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3714: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3715: $result ne "ok").'<br />');
3716: if ($result ne "ok") {
3717: $r->print(&mt('Error: [_1]',$result).'<br />');
3718: }
1.367 golterma 3719:
1.225 raeburn 3720: if (!grep(/^cr$/,@rolechanges)) {
3721: push(@rolechanges,'cr');
3722: }
1.116 raeburn 3723: }
1.135 raeburn 3724: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3725: my $udom = $env{'form.ccdomain'};
3726: my $uname = $env{'form.ccuname'};
1.116 raeburn 3727: # Re-enable standard role
1.135 raeburn 3728: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3729: my $url = $1;
3730: my $role = $2;
3731: my $logmsg;
3732: my $output;
3733: if ($role eq 'st') {
1.141 albertel 3734: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3735: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3736: my $credits;
3737: if ($showcredits) {
3738: my $defaultcredits =
3739: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3740: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3741: }
3742: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3743: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3744: if ($result eq 'refused' && $logmsg) {
3745: $output = $logmsg;
3746: } else {
1.369 bisitz 3747: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3748: }
1.89 raeburn 3749: } else {
1.372 raeburn 3750: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3751: &Apache::lonnet::plaintext($role),
3752: &Apache::loncommon::show_role_extent($url,$context,'st'),
3753: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3754: }
3755: }
3756: } else {
1.101 albertel 3757: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3758: $env{'form.ccuname'},$url,$role,0,$now,'','',
3759: $context);
1.367 golterma 3760: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3761: &Apache::lonnet::plaintext($role),
3762: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3763: if ($result ne "ok") {
3764: $output .= &mt('Error: [_1]',$result).'<br />';
3765: }
3766: }
1.89 raeburn 3767: $r->print($output);
1.225 raeburn 3768: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3769: push(@rolechanges,$role);
3770: }
1.113 raeburn 3771: }
1.116 raeburn 3772: # Re-enable custom role
1.139 albertel 3773: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3774: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3775: my $result = &Apache::lonnet::assigncustomrole(
3776: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3777: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3778: $r->print(&Apache::lonhtmlcommon::confirm_success(
3779: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 3780: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3781: $result ne "ok").'<br />');
3782: if ($result ne "ok") {
3783: $r->print(&mt('Error: [_1]',$result).'<br />');
3784: }
1.225 raeburn 3785: if (!grep(/^cr$/,@rolechanges)) {
3786: push(@rolechanges,'cr');
3787: }
1.116 raeburn 3788: }
1.135 raeburn 3789: } elsif ($key=~/^form\.act/) {
1.101 albertel 3790: my $udom = $env{'form.ccdomain'};
3791: my $uname = $env{'form.ccuname'};
1.141 albertel 3792: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3793: # Activate a custom role
1.83 albertel 3794: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3795: my $url='/'.$one.'/'.$two;
3796: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3797:
1.101 albertel 3798: my $start = ( $env{'form.start_'.$full} ?
3799: $env{'form.start_'.$full} :
1.88 raeburn 3800: $now );
1.101 albertel 3801: my $end = ( $env{'form.end_'.$full} ?
3802: $env{'form.end_'.$full} :
1.88 raeburn 3803: 0 );
3804:
3805: # split multiple sections
3806: my %sections = ();
1.101 albertel 3807: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3808: if ($num_sections == 0) {
1.240 raeburn 3809: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3810: } else {
1.114 albertel 3811: my %curr_groups =
1.117 raeburn 3812: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 3813: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 3814: if (($sec eq 'none') || ($sec eq 'all') ||
3815: exists($curr_groups{$sec})) {
3816: $disallowed{$sec} = $url;
3817: next;
3818: }
3819: my $securl = $url.'/'.$sec;
1.240 raeburn 3820: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3821: }
3822: }
1.225 raeburn 3823: if (!grep(/^cr$/,@rolechanges)) {
3824: push(@rolechanges,'cr');
3825: }
1.142 raeburn 3826: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 3827: # Activate roles for sections with 3 id numbers
3828: # set start, end times, and the url for the class
1.83 albertel 3829: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 3830: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
3831: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3832: $now );
1.101 albertel 3833: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
3834: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3835: 0 );
1.83 albertel 3836: my $url='/'.$one.'/'.$two;
1.88 raeburn 3837: my $type = 'three';
3838: # split multiple sections
3839: my %sections = ();
1.101 albertel 3840: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 3841: my $credits;
3842: if ($three eq 'st') {
3843: if ($showcredits) {
3844: my $defaultcredits =
3845: &Apache::lonuserutils::get_defaultcredits($one,$two);
3846: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
3847: $credits =~ s/[^\d\.]//g;
3848: if ($credits eq $defaultcredits) {
3849: undef($credits);
3850: }
3851: }
3852: }
1.88 raeburn 3853: if ($num_sections == 0) {
1.375 raeburn 3854: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 3855: } else {
1.114 albertel 3856: my %curr_groups =
1.117 raeburn 3857: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 3858: my $emptysec = 0;
1.404 raeburn 3859: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 3860: $sec =~ s/\W//g;
1.113 raeburn 3861: if ($sec ne '') {
3862: if (($sec eq 'none') || ($sec eq 'all') ||
3863: exists($curr_groups{$sec})) {
3864: $disallowed{$sec} = $url;
3865: next;
3866: }
1.88 raeburn 3867: my $securl = $url.'/'.$sec;
1.375 raeburn 3868: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 3869: } else {
3870: $emptysec = 1;
3871: }
3872: }
3873: if ($emptysec) {
1.375 raeburn 3874: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 3875: }
1.225 raeburn 3876: }
3877: if (!grep(/^\Q$three\E$/,@rolechanges)) {
3878: push(@rolechanges,$three);
3879: }
1.135 raeburn 3880: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 3881: # Activate roles for sections with two id numbers
3882: # set start, end times, and the url for the class
1.101 albertel 3883: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
3884: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 3885: $now );
1.101 albertel 3886: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
3887: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 3888: 0 );
1.225 raeburn 3889: my $one = $1;
3890: my $two = $2;
3891: my $url='/'.$one.'/';
1.88 raeburn 3892: # split multiple sections
3893: my %sections = ();
1.225 raeburn 3894: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 3895: if ($num_sections == 0) {
1.240 raeburn 3896: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3897: } else {
3898: my $emptysec = 0;
1.404 raeburn 3899: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 3900: if ($sec ne '') {
3901: my $securl = $url.'/'.$sec;
1.240 raeburn 3902: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 3903: } else {
3904: $emptysec = 1;
3905: }
3906: }
3907: if ($emptysec) {
1.240 raeburn 3908: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3909: }
3910: }
1.225 raeburn 3911: if (!grep(/^\Q$two\E$/,@rolechanges)) {
3912: push(@rolechanges,$two);
3913: }
1.64 www 3914: } else {
1.190 raeburn 3915: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 3916: }
1.113 raeburn 3917: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 3918: $r->print('<p class="LC_warning">');
1.113 raeburn 3919: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 3920: $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 3921: } else {
1.274 bisitz 3922: $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 3923: }
1.274 bisitz 3924: $r->print('</p><p>'
3925: .&mt('Please [_1]go back[_2] and choose a different section name.'
3926: ,'<a href="javascript:history.go(-1)'
3927: ,'</a>')
3928: .'</p><br />'
3929: );
1.113 raeburn 3930: }
3931: }
1.101 albertel 3932: } # End of foreach (keys(%env))
1.75 www 3933: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 3934: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 3935: if (@rolechanges == 0) {
1.372 raeburn 3936: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 3937: }
1.225 raeburn 3938: return @rolechanges;
1.220 raeburn 3939: }
3940:
1.375 raeburn 3941: sub get_user_credits {
3942: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
3943: if ($cdom eq '' || $cnum eq '') {
3944: return unless ($env{'request.course.id'});
3945: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3946: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3947: }
3948: my $credits;
3949: my %currhash =
3950: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
3951: if (keys(%currhash) > 0) {
3952: my @items = split(/:/,$currhash{$uname.':'.$udom});
3953: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
3954: $credits = $items[$crdidx];
3955: $credits =~ s/[^\d\.]//g;
3956: }
3957: if ($credits eq $defaultcredits) {
3958: undef($credits);
3959: }
3960: return $credits;
3961: }
3962:
1.220 raeburn 3963: sub enroll_single_student {
1.375 raeburn 3964: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
3965: $showcredits,$defaultcredits) = @_;
1.318 raeburn 3966: $r->print('<h3>');
3967: if ($crstype eq 'Community') {
3968: $r->print(&mt('Enrolling Member'));
3969: } else {
3970: $r->print(&mt('Enrolling Student'));
3971: }
3972: $r->print('</h3>');
1.220 raeburn 3973:
3974: # Remove non alphanumeric values from section
3975: $env{'form.sections'}=~s/\W//g;
3976:
1.375 raeburn 3977: my $credits;
3978: if (($showcredits) && ($env{'form.credits'} ne '')) {
3979: $credits = $env{'form.credits'};
3980: $credits =~ s/[^\d\.]//g;
3981: if ($credits ne '') {
3982: if ($credits eq $defaultcredits) {
3983: undef($credits);
3984: }
3985: }
3986: }
3987:
1.220 raeburn 3988: # Clean out any old student roles the user has in this class.
3989: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
3990: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
3991: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
3992: my $enroll_result =
3993: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
3994: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
3995: $env{'form.cmiddlename'},$env{'form.clastname'},
3996: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 3997: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
3998: $credits);
1.220 raeburn 3999: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4000: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4001: if ($env{'form.sections'} ne '') {
4002: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4003: }
4004: my ($showstart,$showend);
4005: if ($startdate <= $now) {
4006: $showstart = &mt('Access starts immediately');
4007: } else {
4008: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4009: }
4010: if ($enddate == 0) {
4011: $showend = &mt('ends: no ending date');
4012: } else {
4013: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4014: }
4015: $r->print('.<br />'.$showstart.'; '.$showend);
4016: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4017: $r->print('<p class="LC_info">');
1.318 raeburn 4018: if ($crstype eq 'Community') {
1.392 raeburn 4019: $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
1.318 raeburn 4020: } else {
1.392 raeburn 4021: $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
1.318 raeburn 4022: }
4023: $r->print('</p>');
1.220 raeburn 4024: }
4025: } else {
4026: $r->print(&mt('unable to enroll').": ".$enroll_result);
4027: }
4028: return;
1.188 raeburn 4029: }
4030:
1.204 raeburn 4031: sub get_defaultquota_text {
4032: my ($settingstatus) = @_;
4033: my $defquotatext;
4034: if ($settingstatus eq '') {
1.383 raeburn 4035: $defquotatext = &mt('default');
1.204 raeburn 4036: } else {
4037: my ($usertypes,$order) =
4038: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4039: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4040: $defquotatext = &mt('default');
1.204 raeburn 4041: } else {
1.383 raeburn 4042: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4043: }
4044: }
4045: return $defquotatext;
4046: }
4047:
1.188 raeburn 4048: sub update_result_form {
4049: my ($uhome) = @_;
4050: my $outcome =
1.367 golterma 4051: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4052: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4053: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4054: }
1.207 raeburn 4055: if ($env{'form.origname'} ne '') {
4056: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4057: }
1.160 raeburn 4058: foreach my $item ('sortby','seluname','seludom') {
4059: if (exists($env{'form.'.$item})) {
1.188 raeburn 4060: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4061: }
4062: }
1.188 raeburn 4063: if ($uhome eq 'no_host') {
4064: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4065: }
4066: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4067: '<input type="hidden" name="currstate" value="" />'."\n".
4068: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4069: '</form>';
4070: return $outcome;
1.4 www 4071: }
4072:
1.149 raeburn 4073: sub quota_admin {
1.378 raeburn 4074: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4075: my $quotachanged;
4076: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4077: # Current user has quota modification privileges
1.267 raeburn 4078: if (ref($changeHash) eq 'HASH') {
4079: $quotachanged = 1;
1.378 raeburn 4080: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4081: }
1.149 raeburn 4082: }
4083: return $quotachanged;
4084: }
4085:
1.267 raeburn 4086: sub tool_admin {
1.275 raeburn 4087: my ($tool,$settool,$changeHash,$context) = @_;
4088: my $canchange = 0;
1.279 raeburn 4089: if ($context eq 'requestcourses') {
1.275 raeburn 4090: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4091: $canchange = 1;
4092: }
1.300 raeburn 4093: } elsif ($context eq 'reqcrsotherdom') {
4094: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4095: $canchange = 1;
4096: }
1.362 raeburn 4097: } elsif ($context eq 'requestauthor') {
4098: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4099: $canchange = 1;
4100: }
1.275 raeburn 4101: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4102: # Current user has quota modification privileges
4103: $canchange = 1;
4104: }
1.267 raeburn 4105: my $toolchanged;
1.275 raeburn 4106: if ($canchange) {
1.267 raeburn 4107: if (ref($changeHash) eq 'HASH') {
4108: $toolchanged = 1;
1.362 raeburn 4109: if ($tool eq 'requestauthor') {
4110: $changeHash->{$context} = $settool;
4111: } else {
4112: $changeHash->{$context.'.'.$tool} = $settool;
4113: }
1.267 raeburn 4114: }
4115: }
4116: return $toolchanged;
4117: }
4118:
1.88 raeburn 4119: sub build_roles {
1.89 raeburn 4120: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4121: my $num_sections = 0;
4122: if ($sectionstr=~ /,/) {
4123: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4124: if ($role eq 'st') {
4125: $secnums[0] =~ s/\W//g;
4126: $$sections{$secnums[0]} = 1;
4127: $num_sections = 1;
4128: } else {
4129: foreach my $sec (@secnums) {
4130: $sec =~ ~s/\W//g;
1.150 banghart 4131: if (!($sec eq "")) {
1.89 raeburn 4132: if (exists($$sections{$sec})) {
4133: $$sections{$sec} ++;
4134: } else {
4135: $$sections{$sec} = 1;
4136: $num_sections ++;
4137: }
1.88 raeburn 4138: }
4139: }
4140: }
4141: } else {
4142: $sectionstr=~s/\W//g;
4143: unless ($sectionstr eq '') {
4144: $$sections{$sectionstr} = 1;
4145: $num_sections ++;
4146: }
4147: }
1.129 albertel 4148:
1.88 raeburn 4149: return $num_sections;
4150: }
4151:
1.58 www 4152: # ========================================================== Custom Role Editor
4153:
4154: sub custom_role_editor {
1.351 raeburn 4155: my ($r,$brcrum) = @_;
1.324 raeburn 4156: my $action = $env{'form.customroleaction'};
4157: my $rolename;
4158: if ($action eq 'new') {
4159: $rolename=$env{'form.newrolename'};
4160: } else {
4161: $rolename=$env{'form.rolename'};
1.59 www 4162: }
4163:
1.324 raeburn 4164: my ($crstype,$context);
4165: if ($env{'request.course.id'}) {
4166: $crstype = &Apache::loncommon::course_type();
4167: $context = 'course';
4168: } else {
4169: $context = 'domain';
4170: $crstype = $env{'form.templatecrstype'};
4171: }
1.351 raeburn 4172:
4173: $rolename=~s/[^A-Za-z0-9]//gs;
4174: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
4175: &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
4176: return;
4177: }
4178:
1.153 banghart 4179: # ------------------------------------------------------- What can be assigned?
4180: my %full=();
4181: my %courselevel=();
4182: my %courselevelcurrent=();
1.61 www 4183: my $syspriv='';
4184: my $dompriv='';
4185: my $coursepriv='';
1.153 banghart 4186: my $body_top;
1.393 raeburn 4187: my $newrole;
1.59 www 4188: my ($rdummy,$roledef)=
4189: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 4190: # ------------------------------------------------------- Does this role exist?
1.153 banghart 4191: $body_top .= '<h2>';
1.59 www 4192: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 4193: $body_top .= &mt('Existing Role').' "';
1.61 www 4194: # ------------------------------------------------- Get current role privileges
4195: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.324 raeburn 4196: if ($crstype eq 'Community') {
4197: $syspriv =~ s/bre\&S//;
4198: }
1.59 www 4199: } else {
1.393 raeburn 4200: $newrole = 1;
1.153 banghart 4201: $body_top .= &mt('New Role').' "';
1.59 www 4202: $roledef='';
4203: }
1.153 banghart 4204: $body_top .= $rolename.'"</h2>';
1.135 raeburn 4205: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4206: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4207: if (!$restrict) { $restrict='F'; }
1.60 www 4208: $courselevel{$priv}=$restrict;
1.61 www 4209: if ($coursepriv=~/\:$priv/) {
4210: $courselevelcurrent{$priv}=1;
4211: }
1.60 www 4212: $full{$priv}=1;
4213: }
4214: my %domainlevel=();
1.61 www 4215: my %domainlevelcurrent=();
1.135 raeburn 4216: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4217: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4218: if (!$restrict) { $restrict='F'; }
1.60 www 4219: $domainlevel{$priv}=$restrict;
1.61 www 4220: if ($dompriv=~/\:$priv/) {
4221: $domainlevelcurrent{$priv}=1;
4222: }
1.60 www 4223: $full{$priv}=1;
4224: }
1.61 www 4225: my %systemlevel=();
4226: my %systemlevelcurrent=();
1.135 raeburn 4227: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4228: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4229: if (!$restrict) { $restrict='F'; }
1.61 www 4230: $systemlevel{$priv}=$restrict;
4231: if ($syspriv=~/\:$priv/) {
4232: $systemlevelcurrent{$priv}=1;
4233: }
4234: $full{$priv}=1;
4235: }
1.160 raeburn 4236: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 4237: my $button_code = "\n";
1.153 banghart 4238: my $head_script = "\n";
1.301 bisitz 4239: $head_script .= '<script type="text/javascript">'."\n"
4240: .'// <![CDATA['."\n";
1.324 raeburn 4241: my @template_roles = ("in","ta","ep");
4242: if ($context eq 'domain') {
4243: push(@template_roles,"ad");
1.318 raeburn 4244: }
1.324 raeburn 4245: push(@template_roles,"st");
1.318 raeburn 4246: if ($crstype eq 'Community') {
4247: unshift(@template_roles,'co');
4248: } else {
4249: unshift(@template_roles,'cc');
4250: }
1.154 banghart 4251: foreach my $role (@template_roles) {
1.324 raeburn 4252: $head_script .= &make_script_template($role,$crstype);
1.318 raeburn 4253: $button_code .= &make_button_code($role,$crstype).' ';
1.154 banghart 4254: }
1.324 raeburn 4255: my $context_code;
4256: if ($context eq 'domain') {
4257: my $checkedCommunity = '';
4258: my $checkedCourse = ' checked="checked"';
4259: if ($env{'form.templatecrstype'} eq 'Community') {
4260: $checkedCommunity = $checkedCourse;
4261: $checkedCourse = '';
4262: }
4263: $context_code = '<label>'.
4264: '<input type="radio" name="templatecrstype" value="Course"'.$checkedCourse.' onclick="this.form.submit();">'.
4265: &mt('Course').
4266: '</label>'.(' ' x2).
4267: '<label>'.
4268: '<input type="radio" name="templatecrstype" value="Community"'.$checkedCommunity.' onclick="this.form.submit();">'.
4269: &mt('Community').
4270: '</label>'.
4271: '</fieldset>'.
4272: '<input type="hidden" name="customroleaction" value="'.
4273: $action.'" />';
4274: if ($env{'form.customroleaction'} eq 'new') {
4275: $context_code .= '<input type="hidden" name="newrolename" value="'.
4276: $rolename.'" />';
4277: } else {
4278: $context_code .= '<input type="hidden" name="rolename" value="'.
4279: $rolename.'" />';
4280: }
4281: $context_code .= '<input type="hidden" name="action" value="custom" />'.
4282: '<input type="hidden" name="phase" value="selected_custom_edit" />';
4283: }
4284:
1.301 bisitz 4285: $head_script .= "\n".$jsback."\n"
4286: .'// ]]>'."\n"
4287: .'</script>'."\n";
1.351 raeburn 4288: push (@{$brcrum},
4289: {href => "javascript:backPage(document.form1,'pickrole','')",
4290: text => "Pick custom role",
4291: faq => 282,bug=>'Instructor Interface',},
4292: {href => "javascript:backPage(document.form1,'','')",
4293: text => "Edit custom role",
4294: faq => 282,
4295: bug => 'Instructor Interface',
4296: help => 'Course_Editing_Custom_Roles'}
4297: );
4298: my $args = { bread_crumbs => $brcrum,
4299: bread_crumbs_component => 'User Management'};
4300:
4301: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4302: $head_script,$args).
4303: $body_top);
1.73 sakharuk 4304: my %lt=&Apache::lonlocal::texthash(
4305: 'prv' => "Privilege",
1.131 raeburn 4306: 'crl' => "Course Level",
1.73 sakharuk 4307: 'dml' => "Domain Level",
1.150 banghart 4308: 'ssl' => "System Level");
1.264 bisitz 4309:
1.324 raeburn 4310: $r->print('<div class="LC_left_float">'
1.264 bisitz 4311: .'<form action=""><fieldset>'
4312: .'<legend>'.&mt('Select a Template').'</legend>'
4313: .$button_code
1.324 raeburn 4314: .'</fieldset></form></div>');
4315: if ($context_code) {
4316: $r->print('<div class="LC_left_float">'
4317: .'<form action="/adm/createuser" method="post"><fieldset>'
4318: .'<legend>'.&mt('Context').'</legend>'
4319: .$context_code
4320: .'</form>'
4321: .'</div>'
4322: );
4323: }
4324: $r->print('<br clear="all" />');
1.264 bisitz 4325:
1.61 www 4326: $r->print(<<ENDCCF);
1.380 bisitz 4327: <form name="form1" method="post" action="">
1.61 www 4328: <input type="hidden" name="phase" value="set_custom_roles" />
4329: <input type="hidden" name="rolename" value="$rolename" />
4330: ENDCCF
1.135 raeburn 4331: $r->print(&Apache::loncommon::start_data_table().
4332: &Apache::loncommon::start_data_table_header_row().
4333: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
4334: '</th><th>'.$lt{'ssl'}.'</th>'.
4335: &Apache::loncommon::end_data_table_header_row());
1.324 raeburn 4336: foreach my $priv (sort(keys(%full))) {
1.318 raeburn 4337: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
1.135 raeburn 4338: $r->print(&Apache::loncommon::start_data_table_row().
4339: '<td>'.$privtext.'</td><td>'.
1.288 bisitz 4340: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c"'.
4341: ($courselevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.61 www 4342: '</td><td>'.
1.288 bisitz 4343: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.
4344: ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.324 raeburn 4345: '</td><td>');
4346: if ($priv eq 'bre' && $crstype eq 'Community') {
4347: $r->print(' ');
4348: } else {
4349: $r->print($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
4350: ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':' ');
4351: }
4352: $r->print('</td>'.
4353: &Apache::loncommon::end_data_table_row());
1.60 www 4354: }
1.135 raeburn 4355: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4356: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4357: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 4358: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4359: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4360: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4361: }
1.153 banghart 4362: # --------------------------------------------------------
4363: sub make_script_template {
1.324 raeburn 4364: my ($role,$crstype) = @_;
1.153 banghart 4365: my %full_c=();
4366: my %full_d=();
4367: my %full_s=();
4368: my $return_script;
4369: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4370: my ($priv,$restrict)=split(/\&/,$item);
4371: $full_c{$priv}=1;
4372: }
4373: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4374: my ($priv,$restrict)=split(/\&/,$item);
4375: $full_d{$priv}=1;
4376: }
1.154 banghart 4377: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.324 raeburn 4378: next if (($crstype eq 'Community') && ($item eq 'bre&S'));
1.153 banghart 4379: my ($priv,$restrict)=split(/\&/,$item);
4380: $full_s{$priv}=1;
4381: }
4382: $return_script .= 'function set_'.$role.'() {'."\n";
4383: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
4384: my %role_c;
1.155 banghart 4385: foreach my $priv (@temp) {
1.153 banghart 4386: my ($priv_item, $dummy) = split(/\&/,$priv);
4387: $role_c{$priv_item} = 1;
4388: }
1.269 raeburn 4389: my %role_d;
4390: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
4391: foreach my $priv(@temp) {
4392: my ($priv_item, $dummy) = split(/\&/,$priv);
4393: $role_d{$priv_item} = 1;
4394: }
4395: my %role_s;
4396: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
4397: foreach my $priv(@temp) {
4398: my ($priv_item, $dummy) = split(/\&/,$priv);
4399: $role_s{$priv_item} = 1;
4400: }
1.153 banghart 4401: foreach my $priv_item (keys(%full_c)) {
4402: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4403: if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
4404: (exists($role_s{$priv}))) {
1.153 banghart 4405: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
4406: } else {
4407: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
4408: }
4409: }
1.154 banghart 4410: foreach my $priv_item (keys(%full_d)) {
4411: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4412: if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
1.154 banghart 4413: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
4414: } else {
4415: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
4416: }
4417: }
4418: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 4419: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 4420: if (exists($role_s{$priv})) {
4421: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
4422: } else {
4423: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
4424: }
1.153 banghart 4425: }
4426: $return_script .= '}'."\n";
1.154 banghart 4427: return ($return_script);
4428: }
4429: # ----------------------------------------------------------
4430: sub make_button_code {
1.318 raeburn 4431: my ($role,$crstype) = @_;
4432: my $label = &Apache::lonnet::plaintext($role,$crstype);
1.301 bisitz 4433: my $button_code = '<input type="button" onclick="set_'.$role.'()" value="'.$label.'" />';
1.154 banghart 4434: return ($button_code);
1.153 banghart 4435: }
1.61 www 4436: # ---------------------------------------------------------- Call to definerole
4437: sub set_custom_role {
1.351 raeburn 4438: my ($r,$context,$brcrum) = @_;
1.101 albertel 4439: my $rolename=$env{'form.rolename'};
1.63 www 4440: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4441: if (!$rolename) {
1.351 raeburn 4442: &custom_role_editor($r,$brcrum);
1.61 www 4443: return;
4444: }
1.160 raeburn 4445: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4446: my $jscript = '<script type="text/javascript">'
4447: .'// <![CDATA['."\n"
4448: .$jsback."\n"
4449: .'// ]]>'."\n"
4450: .'</script>'."\n";
1.352 raeburn 4451: push(@{$brcrum},
4452: {href => "javascript:backPage(document.customresult,'pickrole','')",
4453: text => "Pick custom role",
4454: faq => 282,
4455: bug => 'Instructor Interface',},
4456: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4457: text => "Edit custom role",
4458: faq => 282,
4459: bug => 'Instructor Interface',},
4460: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4461: text => "Result",
4462: faq => 282,
4463: bug => 'Instructor Interface',
4464: help => 'Course_Editing_Custom_Roles'},
4465: );
4466: my $args = { bread_crumbs => $brcrum,
1.351 raeburn 4467: bread_crumbs_component => 'User Management'};
4468: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4469:
1.393 raeburn 4470: my $newrole;
1.61 www 4471: my ($rdummy,$roledef)=
1.110 albertel 4472: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4473:
1.61 www 4474: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4475: $r->print('<h3>');
1.61 www 4476: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4477: $r->print(&mt('Existing Role').' "');
1.61 www 4478: } else {
1.73 sakharuk 4479: $r->print(&mt('New Role').' "');
1.61 www 4480: $roledef='';
1.393 raeburn 4481: $newrole = 1;
1.61 www 4482: }
1.188 raeburn 4483: $r->print($rolename.'"</h3>');
1.61 www 4484: # ------------------------------------------------------- What can be assigned?
4485: my $sysrole='';
4486: my $domrole='';
4487: my $courole='';
4488:
1.135 raeburn 4489: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4490: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4491: if (!$restrict) { $restrict=''; }
4492: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 4493: $courole.=':'.$item;
1.61 www 4494: }
4495: }
4496:
1.135 raeburn 4497: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4498: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4499: if (!$restrict) { $restrict=''; }
4500: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 4501: $domrole.=':'.$item;
1.61 www 4502: }
4503: }
4504:
1.135 raeburn 4505: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4506: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4507: if (!$restrict) { $restrict=''; }
4508: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 4509: $sysrole.=':'.$item;
1.61 www 4510: }
4511: }
1.387 bisitz 4512: # Assign role; Compile and show result
4513: my $errmsg;
4514: my $result =
4515: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole);
4516: if ($result ne 'ok') {
4517: $errmsg = ': '.$result;
4518: }
4519: my $message =
4520: &Apache::lonhtmlcommon::confirm_success(
4521: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4522: if ($env{'request.course.id'}) {
4523: my $url='/'.$env{'request.course.id'};
1.63 www 4524: $url=~s/\_/\//g;
1.387 bisitz 4525: $result =
4526: &Apache::lonnet::assigncustomrole(
4527: $env{'user.domain'},$env{'user.name'},
4528: $url,
4529: $env{'user.domain'},$env{'user.name'},
4530: $rolename,undef,undef,undef,$context);
4531: if ($result ne 'ok') {
4532: $errmsg = ': '.$result;
4533: }
4534: $message .=
4535: '<br />'
4536: .&Apache::lonhtmlcommon::confirm_success(
4537: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4538: }
1.380 bisitz 4539: $r->print(
1.387 bisitz 4540: &Apache::loncommon::confirmwrapper($message)
4541: .'<br />'
4542: .&Apache::lonhtmlcommon::actionbox([
4543: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4544: .&mt('Create or edit another custom role')
4545: .'</a>'])
1.380 bisitz 4546: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4547: .&Apache::lonhtmlcommon::echo_form_input([])
4548: .'</form>'
1.380 bisitz 4549: );
1.58 www 4550: }
4551:
1.2 www 4552: # ================================================================ Main Handler
4553: sub handler {
4554: my $r = shift;
4555: if ($r->header_only) {
1.68 www 4556: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4557: $r->send_http_header;
4558: return OK;
4559: }
1.318 raeburn 4560: my ($context,$crstype);
1.190 raeburn 4561: if ($env{'request.course.id'}) {
4562: $context = 'course';
1.318 raeburn 4563: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4564: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4565: $context = 'author';
1.190 raeburn 4566: } else {
4567: $context = 'domain';
4568: }
1.375 raeburn 4569:
1.190 raeburn 4570: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4571: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4572: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4573: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4574: my $args;
4575: my $brcrum = [];
4576: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4577: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4578: $brcrum = [{href=>"/adm/createuser",
4579: text=>"User Management",
4580: 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'}
4581: ];
1.202 raeburn 4582: }
1.289 droeschl 4583: #SD Following files not added to help, because the corresponding .tex-files seem to
4584: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 4585: my ($permission,$allowed) =
1.318 raeburn 4586: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 4587: if (!$allowed) {
1.358 raeburn 4588: if ($context eq 'course') {
4589: $r->internal_redirect('/adm/viewclasslist');
4590: return OK;
4591: }
1.190 raeburn 4592: $env{'user.error.msg'}=
4593: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4594: "or view user status.";
4595: return HTTP_NOT_ACCEPTABLE;
4596: }
4597:
4598: &Apache::loncommon::content_type($r,'text/html');
4599: $r->send_http_header;
4600:
1.375 raeburn 4601: my $showcredits;
4602: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4603: ($context eq 'domain')) {
4604: my %domdefaults =
4605: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4606: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4607: $showcredits = 1;
4608: }
4609: }
4610:
1.190 raeburn 4611: # Main switch on form.action and form.state, as appropriate
4612: if (! exists($env{'form.action'})) {
1.351 raeburn 4613: $args = {bread_crumbs => $brcrum,
4614: bread_crumbs_component => $bread_crumbs_component};
4615: $r->print(&header(undef,$args));
1.318 raeburn 4616: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4617: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.351 raeburn 4618: push(@{$brcrum},
4619: { href => '/adm/createuser?action=upload&state=',
4620: text => 'Upload Users List',
4621: help => 'Course_Create_Class_List',
4622: });
4623: $bread_crumbs_component = 'Upload Users List';
4624: $args = {bread_crumbs => $brcrum,
4625: bread_crumbs_component => $bread_crumbs_component};
4626: $r->print(&header(undef,$args));
1.190 raeburn 4627: $r->print('<form name="studentform" method="post" '.
4628: 'enctype="multipart/form-data" '.
4629: ' action="/adm/createuser">'."\n");
4630: if (! exists($env{'form.state'})) {
4631: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4632: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4633: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4634: $crstype,$showcredits);
1.190 raeburn 4635: } elsif ($env{'form.state'} eq 'enrolling') {
4636: if ($env{'form.datatoken'}) {
1.375 raeburn 4637: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4638: $showcredits);
1.190 raeburn 4639: }
4640: } else {
4641: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4642: }
1.213 raeburn 4643: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4644: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 4645: my $phase = $env{'form.phase'};
4646: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4647: &Apache::loncreateuser::restore_prev_selections();
4648: my $srch;
4649: foreach my $item (@search) {
4650: $srch->{$item} = $env{'form.'.$item};
4651: }
1.207 raeburn 4652: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
4653: ($phase eq 'createnewuser')) {
4654: if ($env{'form.phase'} eq 'createnewuser') {
4655: my $response;
4656: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4657: my $response =
4658: '<span class="LC_warning">'
4659: .&mt('You must specify a valid username. Only the following are allowed:'
4660: .' letters numbers - . @')
4661: .'</span>';
1.221 raeburn 4662: $env{'form.phase'} = '';
1.375 raeburn 4663: &print_username_entry_form($r,$context,$response,$srch,undef,
4664: $crstype,$brcrum,$showcredits);
1.207 raeburn 4665: } else {
4666: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4667: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4668: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4669: $srch,$response,$context,
1.375 raeburn 4670: $permission,$crstype,$brcrum,
4671: $showcredits);
1.207 raeburn 4672: }
4673: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4674: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4675: &user_search_result($context,$srch);
1.190 raeburn 4676: if ($env{'form.currstate'} eq 'modify') {
4677: $currstate = $env{'form.currstate'};
4678: }
4679: if ($currstate eq 'select') {
4680: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4681: \@search,$context,undef,$crstype,
4682: $brcrum);
1.190 raeburn 4683: } elsif ($currstate eq 'modify') {
4684: my ($ccuname,$ccdomain);
4685: if (($srch->{'srchby'} eq 'uname') &&
4686: ($srch->{'srchtype'} eq 'exact')) {
4687: $ccuname = $srch->{'srchterm'};
4688: $ccdomain= $srch->{'srchdomain'};
4689: } else {
4690: my @matchedunames = keys(%{$results});
4691: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4692: }
4693: $ccuname =&LONCAPA::clean_username($ccuname);
4694: $ccdomain=&LONCAPA::clean_domain($ccdomain);
4695: if ($env{'form.forcenewuser'}) {
4696: $response = '';
4697: }
4698: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4699: $srch,$response,$context,
1.351 raeburn 4700: $permission,$crstype,$brcrum);
1.190 raeburn 4701: } elsif ($currstate eq 'query') {
1.351 raeburn 4702: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4703: } else {
1.229 raeburn 4704: $env{'form.phase'} = '';
1.207 raeburn 4705: &print_username_entry_form($r,$context,$response,$srch,
1.351 raeburn 4706: $forcenewuser,$crstype,$brcrum);
1.190 raeburn 4707: }
4708: } elsif ($env{'form.phase'} eq 'userpicked') {
4709: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4710: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 4711: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.351 raeburn 4712: $context,$permission,$crstype,
4713: $brcrum);
1.190 raeburn 4714: }
4715: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4716: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4717: } else {
1.351 raeburn 4718: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4719: $brcrum);
1.190 raeburn 4720: }
4721: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
4722: if ($env{'form.phase'} eq 'set_custom_roles') {
1.351 raeburn 4723: &set_custom_role($r,$context,$brcrum);
1.190 raeburn 4724: } else {
1.351 raeburn 4725: &custom_role_editor($r,$brcrum);
1.190 raeburn 4726: }
1.362 raeburn 4727: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4728: ($permission->{'cusr'}) &&
4729: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4730: push(@{$brcrum},
4731: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4732: text => 'Authoring Space requests',
1.362 raeburn 4733: help => 'Domain_Role_Approvals'});
4734: $bread_crumbs_component = 'Authoring requests';
4735: if ($env{'form.state'} eq 'done') {
4736: push(@{$brcrum},
4737: {href => '/adm/createuser?action=authorreqqueue',
4738: text => 'Result',
4739: help => 'Domain_Role_Approvals'});
4740: $bread_crumbs_component = 'Authoring request result';
4741: }
4742: $args = { bread_crumbs => $brcrum,
4743: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4744: my $js = &usernamerequest_javascript();
4745: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4746: if (!exists($env{'form.state'})) {
4747: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4748: $env{'request.role.domain'}));
4749: } elsif ($env{'form.state'} eq 'done') {
4750: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4751: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4752: $env{'request.role.domain'}));
4753: }
1.391 raeburn 4754: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4755: ($permission->{'cusr'}) &&
4756: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4757: push(@{$brcrum},
4758: {href => '/adm/createuser?action=processusernamereq',
4759: text => 'LON-CAPA account requests',
4760: help => 'Domain_Username_Approvals'});
4761: $bread_crumbs_component = 'Account requests';
4762: if ($env{'form.state'} eq 'done') {
4763: push(@{$brcrum},
4764: {href => '/adm/createuser?action=usernamereqqueue',
4765: text => 'Result',
4766: help => 'Domain_Username_Approvals'});
4767: $bread_crumbs_component = 'LON-CAPA account request result';
4768: }
4769: $args = { bread_crumbs => $brcrum,
4770: bread_crumbs_component => $bread_crumbs_component};
4771: my $js = &usernamerequest_javascript();
4772: $r->print(&header(&add_script($js),$args));
4773: if (!exists($env{'form.state'})) {
4774: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4775: $env{'request.role.domain'}));
4776: } elsif ($env{'form.state'} eq 'done') {
4777: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4778: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4779: $env{'request.role.domain'}));
4780: }
4781: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4782: ($permission->{'cusr'})) {
4783: my $dom = $env{'form.domain'};
4784: my $uname = $env{'form.username'};
4785: my $warning;
4786: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4787: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4788: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4789: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4790: if ($uhome eq 'no_host') {
4791: my $queue = $env{'form.queue'};
4792: my $reqkey = &escape($uname).'_'.$queue;
4793: my $namespace = 'usernamequeue';
4794: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4795: my %queued =
4796: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4797: unless ($queued{$reqkey}) {
4798: $warning = &mt('No information was found for this LON-CAPA account request.');
4799: }
4800: } else {
4801: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4802: }
4803: } else {
4804: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4805: }
4806: } else {
4807: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4808: }
4809: } else {
4810: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4811: }
4812: my $args = { only_body => 1 };
4813: $r->print(&header(undef,$args).
4814: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4815: if ($warning ne '') {
4816: $r->print('<div class="LC_warning">'.$warning.'</div>');
4817: } else {
4818: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4819: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4820: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4821: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4822: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4823: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4824: my %info =
4825: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4826: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4827: my $usertype = $info{$uname}{'inststatus'};
4828: unless ($usertype) {
4829: $usertype = 'default';
4830: }
4831: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
4832: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
4833: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
4834: my ($num,$count,$showstatus);
4835: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
4836: unless ($usertype eq 'default') {
4837: my ($othertitle,$usertypes,$types) =
4838: &Apache::loncommon::sorted_inst_types($dom);
4839: if (ref($usertypes) eq 'HASH') {
4840: if ($usertypes->{$usertype}) {
4841: $showstatus = $usertypes->{$usertype};
4842: $count ++;
4843: }
4844: }
4845: }
4846: foreach my $field (@{$infofields}) {
4847: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
4848: next unless ($infotitles->{$field});
4849: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
4850: $info{$uname}{$field});
4851: $num ++;
4852: if ($count == $num) {
4853: $r->print(&Apache::lonhtmlcommon::row_closure(1));
4854: } else {
4855: $r->print(&Apache::lonhtmlcommon::row_closure());
4856: }
4857: }
4858: if ($showstatus) {
4859: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type (self-reported)')).
4860: $showstatus.
4861: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 4862: }
1.396 raeburn 4863: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
1.391 raeburn 4864: }
4865: }
4866: }
4867: }
4868: }
4869: }
4870: $r->print(&close_popup_form());
4871: }
1.207 raeburn 4872: } elsif (($env{'form.action'} eq 'listusers') &&
4873: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 4874: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 4875: push(@{$brcrum},
4876: {href => '/adm/createuser?action=listusers',
4877: text => "List Users"},
4878: {href => "/adm/createuser",
4879: text => "Result",
4880: help => 'Course_View_Class_List'});
4881: $bread_crumbs_component = 'Update Users';
4882: $args = {bread_crumbs => $brcrum,
4883: bread_crumbs_component => $bread_crumbs_component};
4884: $r->print(&header(undef,$args));
1.202 raeburn 4885: my $setting = $env{'form.roletype'};
4886: my $choice = $env{'form.bulkaction'};
4887: if ($permission->{'cusr'}) {
1.336 raeburn 4888: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 4889: } else {
4890: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 4891: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 4892: }
4893: } else {
1.351 raeburn 4894: push(@{$brcrum},
4895: {href => '/adm/createuser?action=listusers',
4896: text => "List Users",
4897: help => 'Course_View_Class_List'});
4898: $bread_crumbs_component = 'List Users';
4899: $args = {bread_crumbs => $brcrum,
4900: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 4901: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4902: my $formname = 'studentform';
1.364 raeburn 4903: my $hidecall = "hide_searching();";
1.321 raeburn 4904: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
4905: ($env{'form.roletype'} eq 'community'))) {
4906: if ($env{'form.roletype'} eq 'course') {
4907: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
4908: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
4909: $formname);
4910: } elsif ($env{'form.roletype'} eq 'community') {
4911: $cb_jscript =
4912: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
4913: my %elements = (
4914: coursepick => 'radio',
4915: coursetotal => 'text',
4916: courselist => 'text',
4917: );
4918: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
4919: }
1.364 raeburn 4920: $jscript .= &verify_user_display($context)."\n".
4921: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 4922: my $js = &add_script($jscript).$cb_jscript;
4923: my $loadcode =
4924: &Apache::lonuserutils::course_selector_loadcode($formname);
4925: if ($loadcode ne '') {
1.364 raeburn 4926: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
4927: } else {
4928: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 4929: }
1.351 raeburn 4930: $r->print(&header($js,$args));
1.191 raeburn 4931: } else {
1.364 raeburn 4932: $args->{add_entries} = {onload => $hidecall};
4933: $jscript = &verify_user_display($context).
4934: &Apache::loncommon::check_uncheck_jscript();
4935: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 4936: }
1.202 raeburn 4937: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 4938: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
4939: $showcredits);
1.191 raeburn 4940: }
1.213 raeburn 4941: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 4942: my $brtext;
4943: if ($crstype eq 'Community') {
4944: $brtext = 'Drop Members';
4945: } else {
4946: $brtext = 'Drop Students';
4947: }
1.351 raeburn 4948: push(@{$brcrum},
4949: {href => '/adm/createuser?action=drop',
4950: text => $brtext,
4951: help => 'Course_Drop_Student'});
4952: if ($env{'form.state'} eq 'done') {
4953: push(@{$brcrum},
4954: {href=>'/adm/createuser?action=drop',
4955: text=>"Result"});
4956: }
4957: $bread_crumbs_component = $brtext;
4958: $args = {bread_crumbs => $brcrum,
4959: bread_crumbs_component => $bread_crumbs_component};
4960: $r->print(&header(undef,$args));
1.213 raeburn 4961: if (!exists($env{'form.state'})) {
1.318 raeburn 4962: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 4963: } elsif ($env{'form.state'} eq 'done') {
4964: &Apache::lonuserutils::update_user_list($r,$context,undef,
4965: $env{'form.action'});
4966: }
1.202 raeburn 4967: } elsif ($env{'form.action'} eq 'dateselect') {
4968: if ($permission->{'cusr'}) {
1.351 raeburn 4969: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 4970: &Apache::lonuserutils::date_section_selector($context,$permission,
4971: $crstype,$showcredits));
1.202 raeburn 4972: } else {
1.351 raeburn 4973: $r->print(&header(undef,{'no_nav_bar' => 1}).
4974: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 4975: }
1.237 raeburn 4976: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 4977: if ($permission->{selfenrolladmin}) {
4978: my $cid = $env{'request.course.id'};
4979: my $cdom = $env{'course.'.$cid.'.domain'};
4980: my $cnum = $env{'course.'.$cid.'.num'};
4981: my %currsettings = (
4982: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
4983: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
4984: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
4985: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
4986: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
4987: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
4988: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
4989: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
4990: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
4991: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
4992: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
4993: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
4994: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 4995: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 4996: );
4997: push(@{$brcrum},
4998: {href => '/adm/createuser?action=selfenroll',
4999: text => "Configure Self-enrollment",
5000: help => 'Course_Self_Enrollment'});
5001: if (!exists($env{'form.state'})) {
5002: $args = { bread_crumbs => $brcrum,
5003: bread_crumbs_component => 'Configure Self-enrollment'};
5004: $r->print(&header(undef,$args));
5005: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5006: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5007: } elsif ($env{'form.state'} eq 'done') {
5008: push (@{$brcrum},
5009: {href=>'/adm/createuser?action=selfenroll',
5010: text=>"Result"});
5011: $args = { bread_crumbs => $brcrum,
5012: bread_crumbs_component => 'Self-enrollment result'};
5013: $r->print(&header(undef,$args));
5014: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5015: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5016: }
5017: } else {
5018: $r->print(&header(undef,{'no_nav_bar' => 1}).
5019: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5020: }
1.277 raeburn 5021: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.351 raeburn 5022: push(@{$brcrum},
5023: {href => '/adm/createuser?action=selfenrollqueue',
5024: text => 'Enrollment requests',
5025: help => 'Course_Self_Enrollment'});
5026: $bread_crumbs_component = 'Enrollment requests';
5027: if ($env{'form.state'} eq 'done') {
5028: push(@{$brcrum},
5029: {href => '/adm/createuser?action=selfenrollqueue',
5030: text => 'Result',
5031: help => 'Course_Self_Enrollment'});
5032: $bread_crumbs_component = 'Enrollment result';
5033: }
5034: $args = { bread_crumbs => $brcrum,
5035: bread_crumbs_component => $bread_crumbs_component};
5036: $r->print(&header(undef,$args));
1.277 raeburn 5037: my $cid = $env{'request.course.id'};
5038: my $cdom = $env{'course.'.$cid.'.domain'};
5039: my $cnum = $env{'course.'.$cid.'.num'};
1.307 raeburn 5040: my $coursedesc = $env{'course.'.$cid.'.description'};
1.277 raeburn 5041: if (!exists($env{'form.state'})) {
5042: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
1.307 raeburn 5043: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5044: $cdom,$cnum));
1.277 raeburn 5045: } elsif ($env{'form.state'} eq 'done') {
5046: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
1.307 raeburn 5047: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5048: $cdom,$cnum,$coursedesc));
1.277 raeburn 5049: }
1.239 raeburn 5050: } elsif ($env{'form.action'} eq 'changelogs') {
1.363 raeburn 5051: my $helpitem;
5052: if ($context eq 'course') {
5053: $helpitem = 'Course_User_Logs';
5054: }
1.351 raeburn 5055: push (@{$brcrum},
5056: {href => '/adm/createuser?action=changelogs',
5057: text => 'User Management Logs',
1.363 raeburn 5058: help => $helpitem});
1.351 raeburn 5059: $bread_crumbs_component = 'User Changes';
5060: $args = { bread_crumbs => $brcrum,
5061: bread_crumbs_component => $bread_crumbs_component};
5062: $r->print(&header(undef,$args));
5063: &print_userchangelogs_display($r,$context,$permission);
1.190 raeburn 5064: } else {
1.351 raeburn 5065: $bread_crumbs_component = 'User Management';
5066: $args = { bread_crumbs => $brcrum,
5067: bread_crumbs_component => $bread_crumbs_component};
5068: $r->print(&header(undef,$args));
1.318 raeburn 5069: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5070: }
1.351 raeburn 5071: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5072: return OK;
5073: }
5074:
5075: sub header {
1.351 raeburn 5076: my ($jscript,$args) = @_;
1.190 raeburn 5077: my $start_page;
1.351 raeburn 5078: if (ref($args) eq 'HASH') {
5079: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5080: } else {
1.351 raeburn 5081: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5082: }
5083: return $start_page;
5084: }
1.2 www 5085:
1.191 raeburn 5086: sub add_script {
5087: my ($js) = @_;
1.301 bisitz 5088: return '<script type="text/javascript">'."\n"
5089: .'// <![CDATA['."\n"
5090: .$js."\n"
5091: .'// ]]>'."\n"
5092: .'</script>'."\n";
1.191 raeburn 5093: }
5094:
1.391 raeburn 5095: sub usernamerequest_javascript {
5096: my $js = <<ENDJS;
5097:
5098: function openusernamereqdisplay(dom,uname,queue) {
5099: var url = '/adm/createuser?action=displayuserreq';
5100: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5101: var title = 'Account_Request_Browser';
5102: var options = 'scrollbars=1,resizable=1,menubar=0';
5103: options += ',width=700,height=600';
5104: var stdeditbrowser = open(url,title,options,'1');
5105: stdeditbrowser.focus();
5106: return;
5107: }
5108:
5109: ENDJS
5110: }
5111:
5112: sub close_popup_form {
5113: my $close= &mt('Close Window');
5114: return << "END";
5115: <p><form name="displayreq" action="" method="post">
5116: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5117: </form></p>
5118: END
5119: }
5120:
1.202 raeburn 5121: sub verify_user_display {
1.364 raeburn 5122: my ($context) = @_;
1.374 raeburn 5123: my %lt = &Apache::lonlocal::texthash (
5124: course => 'course(s): description, section(s), status',
5125: community => 'community(s): description, section(s), status',
5126: author => 'author',
5127: );
1.364 raeburn 5128: my $photos;
5129: if (($context eq 'course') && $env{'request.course.id'}) {
5130: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5131: }
1.202 raeburn 5132: my $output = <<"END";
5133:
1.364 raeburn 5134: function hide_searching() {
5135: if (document.getElementById('searching')) {
5136: document.getElementById('searching').style.display = 'none';
5137: }
5138: return;
5139: }
5140:
1.202 raeburn 5141: function display_update() {
5142: document.studentform.action.value = 'listusers';
5143: document.studentform.phase.value = 'display';
5144: document.studentform.submit();
5145: }
5146:
1.364 raeburn 5147: function updateCols(caller) {
5148: var context = '$context';
5149: var photos = '$photos';
5150: if (caller == 'Status') {
1.374 raeburn 5151: if ((context == 'domain') &&
5152: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5153: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5154: document.getElementById('showcolstatus').checked = false;
5155: document.getElementById('showcolstatus').disabled = 'disabled';
5156: document.getElementById('showcolstart').checked = false;
5157: document.getElementById('showcolend').checked = false;
1.374 raeburn 5158: } else {
5159: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5160: document.getElementById('showcolstatus').checked = true;
5161: document.getElementById('showcolstatus').disabled = '';
5162: document.getElementById('showcolstart').checked = true;
5163: document.getElementById('showcolend').checked = true;
5164: } else {
5165: document.getElementById('showcolstatus').checked = false;
5166: document.getElementById('showcolstatus').disabled = 'disabled';
5167: document.getElementById('showcolstart').checked = false;
5168: document.getElementById('showcolend').checked = false;
5169: }
1.364 raeburn 5170: }
5171: }
5172: if (caller == 'output') {
5173: if (photos == 1) {
5174: if (document.getElementById('showcolphoto')) {
5175: var photoitem = document.getElementById('showcolphoto');
5176: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5177: photoitem.checked = true;
5178: photoitem.disabled = '';
5179: } else {
5180: photoitem.checked = false;
5181: photoitem.disabled = 'disabled';
5182: }
5183: }
5184: }
5185: }
5186: if (caller == 'showrole') {
1.371 raeburn 5187: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5188: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5189: document.getElementById('showcolrole').checked = true;
5190: document.getElementById('showcolrole').disabled = '';
5191: } else {
5192: document.getElementById('showcolrole').checked = false;
5193: document.getElementById('showcolrole').disabled = 'disabled';
5194: }
1.374 raeburn 5195: if (context == 'domain') {
1.382 raeburn 5196: var quotausageshow = 0;
1.374 raeburn 5197: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5198: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5199: document.getElementById('showcolstatus').checked = false;
5200: document.getElementById('showcolstatus').disabled = 'disabled';
5201: document.getElementById('showcolstart').checked = false;
5202: document.getElementById('showcolend').checked = false;
5203: } else {
5204: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5205: document.getElementById('showcolstatus').checked = true;
5206: document.getElementById('showcolstatus').disabled = '';
5207: document.getElementById('showcolstart').checked = true;
5208: document.getElementById('showcolend').checked = true;
5209: }
5210: }
5211: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5212: document.getElementById('showcolextent').disabled = 'disabled';
5213: document.getElementById('showcolextent').checked = 'false';
5214: document.getElementById('showextent').style.display='none';
5215: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5216: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5217: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5218: if (document.getElementById('showcolauthorusage')) {
5219: document.getElementById('showcolauthorusage').disabled = '';
5220: }
5221: if (document.getElementById('showcolauthorquota')) {
5222: document.getElementById('showcolauthorquota').disabled = '';
5223: }
5224: quotausageshow = 1;
5225: }
1.374 raeburn 5226: } else {
5227: document.getElementById('showextent').style.display='block';
5228: document.getElementById('showextent').style.textAlign='left';
5229: document.getElementById('showextent').style.textFace='normal';
5230: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5231: document.getElementById('showcolextent').disabled = '';
5232: document.getElementById('showcolextent').checked = 'true';
5233: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5234: } else {
5235: document.getElementById('showcolextent').disabled = '';
5236: document.getElementById('showcolextent').checked = 'true';
5237: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5238: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5239: } else {
5240: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5241: }
5242: }
5243: }
1.382 raeburn 5244: if (quotausageshow == 0) {
5245: if (document.getElementById('showcolauthorusage')) {
5246: document.getElementById('showcolauthorusage').checked = false;
5247: document.getElementById('showcolauthorusage').disabled = 'disabled';
5248: }
5249: if (document.getElementById('showcolauthorquota')) {
5250: document.getElementById('showcolauthorquota').checked = false;
5251: document.getElementById('showcolauthorquota').disabled = 'disabled';
5252: }
5253: }
1.374 raeburn 5254: }
1.364 raeburn 5255: }
5256: return;
5257: }
5258:
1.202 raeburn 5259: END
5260: return $output;
5261:
5262: }
5263:
1.190 raeburn 5264: ###############################################################
5265: ###############################################################
5266: # Menu Phase One
5267: sub print_main_menu {
1.318 raeburn 5268: my ($permission,$context,$crstype) = @_;
5269: my $linkcontext = $context;
5270: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5271: if (($context eq 'course') && ($crstype eq 'Community')) {
5272: $linkcontext = lc($crstype);
5273: $stuterm = 'Members';
5274: }
1.208 raeburn 5275: my %links = (
1.298 droeschl 5276: domain => {
5277: upload => 'Upload a File of Users',
5278: singleuser => 'Add/Modify a User',
5279: listusers => 'Manage Users',
5280: },
5281: author => {
5282: upload => 'Upload a File of Co-authors',
5283: singleuser => 'Add/Modify a Co-author',
5284: listusers => 'Manage Co-authors',
5285: },
5286: course => {
5287: upload => 'Upload a File of Course Users',
5288: singleuser => 'Add/Modify a Course User',
1.354 www 5289: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5290: },
1.318 raeburn 5291: community => {
5292: upload => 'Upload a File of Community Users',
5293: singleuser => 'Add/Modify a Community User',
1.354 www 5294: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5295: },
5296: );
5297: my %linktitles = (
5298: domain => {
5299: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5300: listusers => 'Show and manage users in this domain.',
5301: },
5302: author => {
5303: singleuser => 'Add a user with a co- or assistant author role.',
5304: listusers => 'Show and manage co- or assistant authors.',
5305: },
5306: course => {
5307: singleuser => 'Add a user with a certain role to this course.',
5308: listusers => 'Show and manage users in this course.',
5309: },
5310: community => {
5311: singleuser => 'Add a user with a certain role to this community.',
5312: listusers => 'Show and manage users in this community.',
5313: },
1.298 droeschl 5314: );
5315: my @menu = ( {categorytitle => 'Single Users',
5316: items =>
5317: [
5318: {
1.318 raeburn 5319: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5320: icon => 'edit-redo.png',
5321: #help => 'Course_Change_Privileges',
5322: url => '/adm/createuser?action=singleuser',
5323: permission => $permission->{'cusr'},
1.318 raeburn 5324: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5325: },
5326: ]},
5327:
5328: {categorytitle => 'Multiple Users',
5329: items =>
5330: [
5331: {
1.318 raeburn 5332: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5333: icon => 'uplusr.png',
1.298 droeschl 5334: #help => 'Course_Create_Class_List',
5335: url => '/adm/createuser?action=upload',
5336: permission => $permission->{'cusr'},
5337: linktitle => 'Upload a CSV or a text file containing users.',
5338: },
5339: {
1.318 raeburn 5340: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5341: icon => 'mngcu.png',
1.298 droeschl 5342: #help => 'Course_View_Class_List',
5343: url => '/adm/createuser?action=listusers',
5344: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5345: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5346: },
5347:
5348: ]},
5349:
5350: {categorytitle => 'Administration',
5351: items => [ ]},
5352: );
5353:
1.265 mielkec 5354: if ($context eq 'domain'){
1.298 droeschl 5355:
5356: push(@{ $menu[2]->{items} }, #Category: Administration
5357: {
5358: linktext => 'Custom Roles',
5359: icon => 'emblem-photos.png',
5360: #help => 'Course_Editing_Custom_Roles',
5361: url => '/adm/createuser?action=custom',
5362: permission => $permission->{'custom'},
5363: linktitle => 'Configure a custom role.',
5364: },
1.362 raeburn 5365: {
5366: linktext => 'Authoring Space Requests',
5367: icon => 'selfenrl-queue.png',
5368: #help => 'Domain_Role_Approvals',
5369: url => '/adm/createuser?action=processauthorreq',
5370: permission => $permission->{'cusr'},
5371: linktitle => 'Approve or reject author role requests',
5372: },
1.363 raeburn 5373: {
1.391 raeburn 5374: linktext => 'LON-CAPA Account Requests',
5375: icon => 'list-add.png',
5376: #help => 'Domain_Username_Approvals',
5377: url => '/adm/createuser?action=processusernamereq',
5378: permission => $permission->{'cusr'},
5379: linktitle => 'Approve or reject LON-CAPA account requests',
5380: },
5381: {
1.363 raeburn 5382: linktext => 'Change Log',
5383: icon => 'document-properties.png',
5384: #help => 'Course_User_Logs',
5385: url => '/adm/createuser?action=changelogs',
5386: permission => $permission->{'cusr'},
5387: linktitle => 'View change log.',
5388: },
1.298 droeschl 5389: );
5390:
1.265 mielkec 5391: }elsif ($context eq 'course'){
1.298 droeschl 5392: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5393:
5394: my %linktext = (
5395: 'Course' => {
5396: single => 'Add/Modify a Student',
5397: drop => 'Drop Students',
5398: groups => 'Course Groups',
5399: },
5400: 'Community' => {
5401: single => 'Add/Modify a Member',
5402: drop => 'Drop Members',
5403: groups => 'Community Groups',
5404: },
5405: );
5406:
5407: my %linktitle = (
5408: 'Course' => {
5409: single => 'Add a user with the role of student to this course',
5410: drop => 'Remove a student from this course.',
5411: groups => 'Manage course groups',
5412: },
5413: 'Community' => {
5414: single => 'Add a user with the role of member to this community',
5415: drop => 'Remove a member from this community.',
5416: groups => 'Manage community groups',
5417: },
5418: );
5419:
1.298 droeschl 5420: push(@{ $menu[0]->{items} }, #Category: Single Users
5421: {
1.318 raeburn 5422: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5423: #help => 'Course_Add_Student',
5424: icon => 'list-add.png',
5425: url => '/adm/createuser?action=singlestudent',
5426: permission => $permission->{'cusr'},
1.318 raeburn 5427: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5428: },
5429: );
5430:
5431: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5432: {
1.318 raeburn 5433: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5434: icon => 'edit-undo.png',
5435: #help => 'Course_Drop_Student',
5436: url => '/adm/createuser?action=drop',
5437: permission => $permission->{'cusr'},
1.318 raeburn 5438: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5439: },
5440: );
5441: push(@{ $menu[2]->{items} }, #Category: Administration
5442: {
5443: linktext => 'Custom Roles',
5444: icon => 'emblem-photos.png',
5445: #help => 'Course_Editing_Custom_Roles',
5446: url => '/adm/createuser?action=custom',
5447: permission => $permission->{'custom'},
5448: linktitle => 'Configure a custom role.',
5449: },
5450: {
1.318 raeburn 5451: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5452: icon => 'grps.png',
1.298 droeschl 5453: #help => 'Course_Manage_Group',
5454: url => '/adm/coursegroups?refpage=cusr',
5455: permission => $permission->{'grp_manage'},
1.318 raeburn 5456: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5457: },
5458: {
1.328 wenzelju 5459: linktext => 'Change Log',
1.298 droeschl 5460: icon => 'document-properties.png',
5461: #help => 'Course_User_Logs',
5462: url => '/adm/createuser?action=changelogs',
5463: permission => $permission->{'cusr'},
5464: linktitle => 'View change log.',
5465: },
5466: );
1.277 raeburn 5467: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5468: push(@{ $menu[2]->{items} },
1.398 raeburn 5469: {
1.298 droeschl 5470: linktext => 'Enrollment Requests',
5471: icon => 'selfenrl-queue.png',
5472: #help => 'Course_Approve_Selfenroll',
5473: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5474: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5475: linktitle =>'Approve or reject enrollment requests.',
5476: },
5477: );
1.277 raeburn 5478: }
1.298 droeschl 5479:
1.265 mielkec 5480: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5481: if ($crstype ne 'Community') {
5482: push(@{ $menu[2]->{items} },
5483: {
5484: linktext => 'Automated Enrollment',
5485: icon => 'roles.png',
5486: #help => 'Course_Automated_Enrollment',
5487: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
5488: && $permission->{'cusr'}),
5489: url => '/adm/populate',
5490: linktitle => 'Automated enrollment manager.',
5491: }
5492: );
5493: }
5494: push(@{ $menu[2]->{items} },
1.298 droeschl 5495: {
5496: linktext => 'User Self-Enrollment',
1.342 wenzelju 5497: icon => 'self_enroll.png',
1.298 droeschl 5498: #help => 'Course_Self_Enrollment',
5499: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5500: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5501: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5502: },
5503: );
5504: }
1.363 raeburn 5505: } elsif ($context eq 'author') {
1.370 raeburn 5506: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5507: {
5508: linktext => 'Change Log',
5509: icon => 'document-properties.png',
5510: #help => 'Course_User_Logs',
5511: url => '/adm/createuser?action=changelogs',
5512: permission => $permission->{'cusr'},
5513: linktitle => 'View change log.',
5514: },
1.370 raeburn 5515: );
1.363 raeburn 5516: }
5517: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5518: # { text => 'View Log-in History',
5519: # help => 'Course_User_Logins',
5520: # action => 'logins',
5521: # permission => $permission->{'cusr'},
5522: # });
1.190 raeburn 5523: }
5524:
1.189 albertel 5525: sub restore_prev_selections {
5526: my %saveable_parameters = ('srchby' => 'scalar',
5527: 'srchin' => 'scalar',
5528: 'srchtype' => 'scalar',
5529: );
5530: &Apache::loncommon::store_settings('user','user_picker',
5531: \%saveable_parameters);
5532: &Apache::loncommon::restore_settings('user','user_picker',
5533: \%saveable_parameters);
5534: }
5535:
1.237 raeburn 5536: sub print_selfenroll_menu {
1.398 raeburn 5537: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional) = @_;
1.322 raeburn 5538: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5539: my $formname = 'selfenroll';
1.237 raeburn 5540: my $nolink = 1;
1.398 raeburn 5541: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5542: my $groupslist = &Apache::lonuserutils::get_groupslist();
5543: my $setsec_js =
5544: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5545: my %alerts = &Apache::lonlocal::texthash(
5546: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5547: butn => 'but no user types have been checked.',
5548: wilf => "Please uncheck 'activate' or check at least one type.",
5549: );
1.405 damieng 5550: &js_escape(\%alerts);
1.249 raeburn 5551: my $selfenroll_js = <<"ENDSCRIPT";
5552: function update_types(caller,num) {
5553: var delidx = getIndexByName('selfenroll_delete');
5554: var actidx = getIndexByName('selfenroll_activate');
5555: if (caller == 'selfenroll_all') {
5556: var selall;
5557: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5558: if (document.$formname.selfenroll_all[i].checked) {
5559: selall = document.$formname.selfenroll_all[i].value;
5560: }
5561: }
5562: if (selall == 1) {
5563: if (delidx != -1) {
5564: if (document.$formname.selfenroll_delete.length) {
5565: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5566: document.$formname.selfenroll_delete[j].checked = true;
5567: }
5568: } else {
5569: document.$formname.elements[delidx].checked = true;
5570: }
5571: }
5572: if (actidx != -1) {
5573: if (document.$formname.selfenroll_activate.length) {
5574: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5575: document.$formname.selfenroll_activate[j].checked = false;
5576: }
5577: } else {
5578: document.$formname.elements[actidx].checked = false;
5579: }
5580: }
5581: document.$formname.selfenroll_newdom.selectedIndex = 0;
5582: }
5583: }
5584: if (caller == 'selfenroll_activate') {
5585: if (document.$formname.selfenroll_activate.length) {
5586: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5587: if (document.$formname.selfenroll_activate[j].value == num) {
5588: if (document.$formname.selfenroll_activate[j].checked) {
5589: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5590: if (document.$formname.selfenroll_all[i].value == '1') {
5591: document.$formname.selfenroll_all[i].checked = false;
5592: }
5593: if (document.$formname.selfenroll_all[i].value == '0') {
5594: document.$formname.selfenroll_all[i].checked = true;
5595: }
5596: }
5597: }
5598: }
5599: }
5600: } else {
5601: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5602: if (document.$formname.selfenroll_all[i].value == '1') {
5603: document.$formname.selfenroll_all[i].checked = false;
5604: }
5605: if (document.$formname.selfenroll_all[i].value == '0') {
5606: document.$formname.selfenroll_all[i].checked = true;
5607: }
5608: }
5609: }
5610: }
5611: if (caller == 'selfenroll_delete') {
5612: if (document.$formname.selfenroll_delete.length) {
5613: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5614: if (document.$formname.selfenroll_delete[j].value == num) {
5615: if (document.$formname.selfenroll_delete[j].checked) {
5616: var delindex = getIndexByName('selfenroll_types_'+num);
5617: if (delindex != -1) {
5618: if (document.$formname.elements[delindex].length) {
5619: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5620: document.$formname.elements[delindex][k].checked = false;
5621: }
5622: } else {
5623: document.$formname.elements[delindex].checked = false;
5624: }
5625: }
5626: }
5627: }
5628: }
5629: } else {
5630: if (document.$formname.selfenroll_delete.checked) {
5631: var delindex = getIndexByName('selfenroll_types_'+num);
5632: if (delindex != -1) {
5633: if (document.$formname.elements[delindex].length) {
5634: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5635: document.$formname.elements[delindex][k].checked = false;
5636: }
5637: } else {
5638: document.$formname.elements[delindex].checked = false;
5639: }
5640: }
5641: }
5642: }
5643: }
5644: return;
5645: }
5646:
5647: function validate_types(form) {
5648: var needaction = new Array();
5649: var countfail = 0;
5650: var actidx = getIndexByName('selfenroll_activate');
5651: if (actidx != -1) {
5652: if (document.$formname.selfenroll_activate.length) {
5653: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5654: var num = document.$formname.selfenroll_activate[j].value;
5655: if (document.$formname.selfenroll_activate[j].checked) {
5656: countfail = check_types(num,countfail,needaction)
5657: }
5658: }
5659: } else {
5660: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5661: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5662: countfail = check_types(num,countfail,needaction)
5663: }
5664: }
5665: }
5666: if (countfail > 0) {
5667: var msg = "$alerts{'acto'}\\n";
5668: var loopend = needaction.length -1;
5669: if (loopend > 0) {
5670: for (var m=0; m<loopend; m++) {
5671: msg += needaction[m]+", ";
5672: }
5673: }
5674: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5675: alert(msg);
5676: return;
5677: }
5678: setSections(form);
5679: }
5680:
5681: function check_types(num,countfail,needaction) {
5682: var typeidx = getIndexByName('selfenroll_types_'+num);
5683: var count = 0;
5684: if (typeidx != -1) {
5685: if (document.$formname.elements[typeidx].length) {
5686: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5687: if (document.$formname.elements[typeidx][k].checked) {
5688: count ++;
5689: }
5690: }
5691: } else {
5692: if (document.$formname.elements[typeidx].checked) {
5693: count ++;
5694: }
5695: }
5696: if (count == 0) {
5697: var domidx = getIndexByName('selfenroll_dom_'+num);
5698: if (domidx != -1) {
5699: var domname = document.$formname.elements[domidx].value;
5700: needaction[countfail] = domname;
5701: countfail ++;
5702: }
5703: }
5704: }
5705: return countfail;
5706: }
5707:
1.398 raeburn 5708: function toggleNotify() {
5709: var selfenrollApproval = 0;
5710: if (document.$formname.selfenroll_approval.length) {
5711: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5712: if (document.$formname.selfenroll_approval[i].checked) {
5713: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5714: break;
5715: }
5716: }
5717: }
5718: if (document.getElementById('notified')) {
5719: if (selfenrollApproval == 0) {
5720: document.getElementById('notified').style.display='none';
5721: } else {
5722: document.getElementById('notified').style.display='block';
5723: }
5724: }
5725: return;
5726: }
5727:
1.249 raeburn 5728: function getIndexByName(item) {
5729: for (var i=0;i<document.$formname.elements.length;i++) {
5730: if (document.$formname.elements[i].name == item) {
5731: return i;
5732: }
5733: }
5734: return -1;
5735: }
5736: ENDSCRIPT
1.256 raeburn 5737:
1.237 raeburn 5738: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5739: '// <![CDATA['."\n".
1.249 raeburn 5740: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5741: '// ]]>'."\n".
1.237 raeburn 5742: '</script>'."\n".
1.256 raeburn 5743: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 5744:
5745: my $visactions = &cat_visibility();
5746: my ($cathash,%cattype);
5747: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5748: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5749: $cathash = $domconfig{'coursecategories'}{'cats'};
5750: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5751: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 5752: if ($cattype{'auth'} eq '') {
5753: $cattype{'auth'} = 'std';
5754: }
5755: if ($cattype{'unauth'} eq '') {
5756: $cattype{'unauth'} = 'std';
5757: }
1.400 raeburn 5758: } else {
5759: $cathash = {};
5760: $cattype{'auth'} = 'std';
5761: $cattype{'unauth'} = 'std';
5762: }
5763: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
5764: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5765: '<br />'.
5766: '<br />'.$visactions->{'take'}.'<ul>'.
5767: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
5768: '</ul>');
5769: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
5770: if ($currsettings->{'uniquecode'}) {
5771: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
5772: } else {
5773: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5774: '<br />'.
5775: '<br />'.$visactions->{'take'}.'<ul>'.
5776: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
5777: '</ul><br />');
5778: }
5779: } else {
5780: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
5781: if (ref($visactions) eq 'HASH') {
5782: if ($visible) {
5783: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
5784: } else {
5785: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5786: .$visactions->{'yous'}.
5787: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5788: if (ref($vismsgs) eq 'ARRAY') {
5789: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5790: foreach my $item (@{$vismsgs}) {
5791: $output .= '<li>'.$visactions->{$item}.'</li>';
5792: }
5793: $output .= '</ul>';
1.256 raeburn 5794: }
1.400 raeburn 5795: $output .= '</p>';
1.256 raeburn 5796: }
5797: }
5798: }
1.398 raeburn 5799: my $actionhref = '/adm/createuser';
5800: if ($context eq 'domain') {
5801: $actionhref = '/adm/modifycourse';
5802: }
1.400 raeburn 5803:
5804: my %noedit;
5805: unless ($context eq 'domain') {
5806: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
5807: }
1.398 raeburn 5808: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 5809: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5810: if (ref($row) eq 'ARRAY') {
5811: foreach my $item (@{$row}) {
5812: my $title = $item;
5813: if (ref($lt) eq 'HASH') {
5814: $title = $lt->{$item};
5815: }
1.297 bisitz 5816: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5817: if ($item eq 'types') {
1.398 raeburn 5818: my $curr_types;
5819: if (ref($currsettings) eq 'HASH') {
5820: $curr_types = $currsettings->{'selfenroll_types'};
5821: }
1.400 raeburn 5822: if ($noedit{$item}) {
5823: if ($curr_types eq '*') {
5824: $output .= &mt('Any user in any domain');
5825: } else {
5826: my @entries = split(/;/,$curr_types);
5827: if (@entries > 0) {
5828: $output .= '<ul>';
5829: foreach my $entry (@entries) {
5830: my ($currdom,$typestr) = split(/:/,$entry);
5831: next if ($typestr eq '');
5832: my $domdesc = &Apache::lonnet::domain($currdom);
5833: my @currinsttypes = split(',',$typestr);
5834: my ($othertitle,$usertypes,$types) =
5835: &Apache::loncommon::sorted_inst_types($currdom);
5836: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5837: $usertypes->{'any'} = &mt('any user');
5838: if (keys(%{$usertypes}) > 0) {
5839: $usertypes->{'other'} = &mt('other users');
5840: }
5841: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
5842: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
5843: }
5844: }
5845: $output .= '</ul>';
5846: } else {
5847: $output .= &mt('None');
5848: }
5849: }
5850: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5851: next;
5852: }
1.241 raeburn 5853: my $showdomdesc = 1;
5854: my $includeempty = 1;
5855: my $num = 0;
5856: $output .= &Apache::loncommon::start_data_table().
5857: &Apache::loncommon::start_data_table_row()
5858: .'<td colspan="2"><span class="LC_nobreak"><label>'
5859: .&mt('Any user in any domain:')
5860: .' <input type="radio" name="selfenroll_all" value="1" ';
5861: if ($curr_types eq '*') {
5862: $output .= ' checked="checked" ';
5863: }
1.249 raeburn 5864: $output .= 'onchange="javascript:update_types('.
5865: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
5866: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 5867: if ($curr_types ne '*') {
5868: $output .= ' checked="checked" ';
5869: }
1.249 raeburn 5870: $output .= ' onchange="javascript:update_types('.
5871: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
5872: &Apache::loncommon::end_data_table_row().
5873: &Apache::loncommon::end_data_table().
5874: &mt('Or').'<br />'.
5875: &Apache::loncommon::start_data_table();
1.241 raeburn 5876: my %currdoms;
1.249 raeburn 5877: if ($curr_types eq '') {
1.241 raeburn 5878: $output .= &new_selfenroll_dom_row($cdom,'0');
5879: } elsif ($curr_types ne '*') {
5880: my @entries = split(/;/,$curr_types);
5881: if (@entries > 0) {
5882: foreach my $entry (@entries) {
5883: my ($currdom,$typestr) = split(/:/,$entry);
5884: $currdoms{$currdom} = 1;
5885: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 5886: my @currinsttypes = split(',',$typestr);
1.241 raeburn 5887: $output .= &Apache::loncommon::start_data_table_row()
5888: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
5889: .' '.$domdesc.' ('.$currdom.')'
5890: .'</b><input type="hidden" name="selfenroll_dom_'.$num
5891: .'" value="'.$currdom.'" /></span><br />'
5892: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 5893: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 5894: .&mt('Delete').'</label></span></td>';
1.249 raeburn 5895: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 5896: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
5897: .&Apache::loncommon::end_data_table_row();
5898: $num ++;
5899: }
5900: }
5901: }
1.249 raeburn 5902: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 5903: if ($curr_types eq '*') {
1.249 raeburn 5904: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 5905: } elsif ($curr_types eq '') {
1.249 raeburn 5906: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 5907: }
5908: $output .= &Apache::loncommon::start_data_table_row()
5909: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
5910: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
5911: $includeempty,$showdomdesc)
5912: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
5913: .'</td>'.&Apache::loncommon::end_data_table_row()
5914: .&Apache::loncommon::end_data_table();
1.237 raeburn 5915: } elsif ($item eq 'registered') {
5916: my ($regon,$regoff);
1.398 raeburn 5917: my $registered;
5918: if (ref($currsettings) eq 'HASH') {
5919: $registered = $currsettings->{'selfenroll_registered'};
5920: }
1.400 raeburn 5921: if ($noedit{$item}) {
5922: if ($registered) {
5923: $output .= &mt('Must be registered in course');
5924: } else {
5925: $output .= &mt('No requirement');
5926: }
5927: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5928: next;
5929: }
1.398 raeburn 5930: if ($registered) {
1.237 raeburn 5931: $regon = ' checked="checked" ';
5932: $regoff = ' ';
5933: } else {
5934: $regon = ' ';
5935: $regoff = ' checked="checked" ';
5936: }
5937: $output .= '<label>'.
1.245 raeburn 5938: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 5939: &mt('Yes').'</label> <label>'.
1.245 raeburn 5940: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 5941: &mt('No').'</label>';
1.237 raeburn 5942: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 5943: my ($starttime,$endtime);
5944: if (ref($currsettings) eq 'HASH') {
5945: $starttime = $currsettings->{'selfenroll_start_date'};
5946: $endtime = $currsettings->{'selfenroll_end_date'};
5947: if ($starttime eq '') {
5948: $starttime = $currsettings->{'default_enrollment_start_date'};
5949: }
5950: if ($endtime eq '') {
5951: $endtime = $currsettings->{'default_enrollment_end_date'};
5952: }
1.237 raeburn 5953: }
1.400 raeburn 5954: if ($noedit{$item}) {
5955: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
5956: &Apache::lonlocal::locallocaltime($endtime));
5957: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5958: next;
5959: }
1.237 raeburn 5960: my $startform =
5961: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
5962: undef,undef,undef,undef,undef,undef,undef,$nolink);
5963: my $endform =
5964: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
5965: undef,undef,undef,undef,undef,undef,undef,$nolink);
5966: $output .= &selfenroll_date_forms($startform,$endform);
5967: } elsif ($item eq 'access_dates') {
1.398 raeburn 5968: my ($starttime,$endtime);
5969: if (ref($currsettings) eq 'HASH') {
5970: $starttime = $currsettings->{'selfenroll_start_access'};
5971: $endtime = $currsettings->{'selfenroll_end_access'};
5972: if ($starttime eq '') {
5973: $starttime = $currsettings->{'default_enrollment_start_date'};
5974: }
5975: if ($endtime eq '') {
5976: $endtime = $currsettings->{'default_enrollment_end_date'};
5977: }
1.237 raeburn 5978: }
1.400 raeburn 5979: if ($noedit{$item}) {
5980: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
5981: &Apache::lonlocal::locallocaltime($endtime));
5982: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5983: next;
5984: }
1.237 raeburn 5985: my $startform =
5986: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
5987: undef,undef,undef,undef,undef,undef,undef,$nolink);
5988: my $endform =
5989: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
5990: undef,undef,undef,undef,undef,undef,undef,$nolink);
5991: $output .= &selfenroll_date_forms($startform,$endform);
5992: } elsif ($item eq 'section') {
1.398 raeburn 5993: my $currsec;
5994: if (ref($currsettings) eq 'HASH') {
5995: $currsec = $currsettings->{'selfenroll_section'};
5996: }
1.237 raeburn 5997: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
5998: my $newsecval;
5999: if ($currsec ne 'none' && $currsec ne '') {
6000: if (!defined($sections_count{$currsec})) {
6001: $newsecval = $currsec;
6002: }
6003: }
1.400 raeburn 6004: if ($noedit{$item}) {
6005: if ($currsec ne '') {
6006: $output .= $currsec;
6007: } else {
6008: $output .= &mt('No specific section');
6009: }
6010: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6011: next;
6012: }
1.237 raeburn 6013: my $sections_select =
6014: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
6015: $output .= '<table class="LC_createuser">'."\n".
6016: '<tr class="LC_section_row">'."\n".
6017: '<td align="center">'.&mt('Existing sections')."\n".
6018: '<br />'.$sections_select.'</td><td align="center">'.
6019: &mt('New section').'<br />'."\n".
6020: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
6021: '<input type="hidden" name="sections" value="" />'."\n".
6022: '</td></tr></table>'."\n";
1.276 raeburn 6023: } elsif ($item eq 'approval') {
1.398 raeburn 6024: my ($currnotified,$currapproval,%appchecked);
6025: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
6026: if (ref($currsettings) eq 'HASH') {
6027: $currnotified = $currsettings->{'selfenroll_notifylist'};
6028: $currapproval = $currsettings->{'selfenroll_approval'};
6029: }
6030: if ($currapproval !~ /^[012]$/) {
6031: $currapproval = 0;
6032: }
1.400 raeburn 6033: if ($noedit{$item}) {
6034: $output .= $selfdescs{'approval'}{$currapproval}.
6035: '<br />'.&mt('(Set by Domain Coordinator)');
6036: next;
6037: }
1.398 raeburn 6038: $appchecked{$currapproval} = ' checked="checked"';
6039: for my $i (0..2) {
6040: $output .= '<label>'.
6041: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
6042: $appchecked{$i}.' onclick="toggleNotify();" />'.$selfdescs{'approval'}{$i}.
6043: '</label>'.(' 'x2);
1.276 raeburn 6044: }
6045: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6046: my (@ccs,%notified);
1.322 raeburn 6047: my $ccrole = 'cc';
6048: if ($crstype eq 'Community') {
6049: $ccrole = 'co';
6050: }
6051: if ($advhash{$ccrole}) {
6052: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6053: }
6054: if ($currnotified) {
6055: foreach my $current (split(/,/,$currnotified)) {
6056: $notified{$current} = 1;
6057: if (!grep(/^\Q$current\E$/,@ccs)) {
6058: push(@ccs,$current);
6059: }
6060: }
6061: }
6062: if (@ccs) {
1.398 raeburn 6063: my $style;
6064: unless ($currapproval) {
6065: $style = ' style="display: none;"';
6066: }
6067: $output .= '<br /><div id="notified"'.$style.'>'.
6068: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6069: &Apache::loncommon::start_data_table().
1.276 raeburn 6070: &Apache::loncommon::start_data_table_row();
6071: my $count = 0;
6072: my $numcols = 4;
6073: foreach my $cc (sort(@ccs)) {
6074: my $notifyon;
6075: my ($ccuname,$ccudom) = split(/:/,$cc);
6076: if ($notified{$cc}) {
6077: $notifyon = ' checked="checked" ';
6078: }
6079: if ($count && !$count%$numcols) {
6080: $output .= &Apache::loncommon::end_data_table_row().
6081: &Apache::loncommon::start_data_table_row()
6082: }
6083: $output .= '<td><span class="LC_nobreak"><label>'.
6084: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
6085: &Apache::loncommon::plainname($ccuname,$ccudom).
6086: '</label></span></td>';
1.343 raeburn 6087: $count ++;
1.276 raeburn 6088: }
6089: my $rem = $count%$numcols;
6090: if ($rem) {
6091: my $emptycols = $numcols - $rem;
6092: for (my $i=0; $i<$emptycols; $i++) {
6093: $output .= '<td> </td>';
6094: }
6095: }
6096: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6097: &Apache::loncommon::end_data_table().
6098: '</div>';
1.276 raeburn 6099: }
6100: } elsif ($item eq 'limit') {
1.398 raeburn 6101: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6102: if (ref($currsettings) eq 'HASH') {
6103: $currlim = $currsettings->{'selfenroll_limit'};
6104: $currcap = $currsettings->{'selfenroll_cap'};
6105: }
1.400 raeburn 6106: if ($noedit{$item}) {
6107: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6108: if ($currlim eq 'allstudents') {
6109: $output .= &mt('Limit by total students');
6110: } elsif ($currlim eq 'selfenrolled') {
6111: $output .= &mt('Limit by total self-enrolled students');
6112: }
6113: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6114: '<br />'.&mt('(Set by Domain Coordinator)');
6115: } else {
6116: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6117: }
6118: next;
6119: }
1.276 raeburn 6120: if ($currlim eq 'allstudents') {
6121: $crslimit = ' checked="checked" ';
6122: $selflimit = ' ';
6123: $nolimit = ' ';
6124: } elsif ($currlim eq 'selfenrolled') {
6125: $crslimit = ' ';
6126: $selflimit = ' checked="checked" ';
6127: $nolimit = ' ';
6128: } else {
6129: $crslimit = ' ';
6130: $selflimit = ' ';
1.398 raeburn 6131: $nolimit = ' checked="checked" ';
1.276 raeburn 6132: }
6133: $output .= '<table><tr><td><label>'.
1.278 raeburn 6134: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 6135: &mt('No limit').'</label></td><td><label>'.
6136: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
6137: &mt('Limit by total students').'</label></td><td><label>'.
6138: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
6139: &mt('Limit by total self-enrolled students').
6140: '</td></tr><tr>'.
6141: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6142: (' 'x3).&mt('Maximum number allowed: ').
6143: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 6144: }
6145: $output .= &Apache::lonhtmlcommon::row_closure(1);
6146: }
6147: }
6148: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 6149: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 6150: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.400 raeburn 6151: .'<input type="hidden" name="action" value="selfenroll" />'
6152: .'<input type="hidden" name="state" value="done" />'."\n".
1.398 raeburn 6153: $additional.'</form>';
1.237 raeburn 6154: $r->print($output);
6155: return;
6156: }
6157:
1.400 raeburn 6158: sub get_noedit_fields {
6159: my ($cdom,$cnum,$crstype,$row) = @_;
6160: my %noedit;
6161: if (ref($row) eq 'ARRAY') {
6162: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6163: 'internal.selfenrollmgrdc',
6164: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6165: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6166: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6167: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6168: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6169: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6170: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6171:
6172: foreach my $item (@{$row}) {
6173: next if ($specific_managebycc{$item});
6174: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6175: $noedit{$item} = 1;
6176: }
6177: }
6178: }
6179: return %noedit;
6180: }
6181:
6182: sub visible_in_stdcat {
6183: my ($cdom,$cnum,$domconf) = @_;
6184: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6185: unless (ref($domconf) eq 'HASH') {
6186: return ($visible,$cansetvis,\@vismsgs);
6187: }
6188: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6189: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6190: $settable{'togglecats'} = 1;
6191: }
1.400 raeburn 6192: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6193: $settable{'categorize'} = 1;
6194: }
1.400 raeburn 6195: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6196: }
1.260 raeburn 6197: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6198: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6199: } elsif ($settable{'togglecats'}) {
6200: $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 6201: } elsif ($settable{'categorize'}) {
1.256 raeburn 6202: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6203: } else {
6204: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6205: }
6206:
6207: my %currsettings =
6208: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6209: $cdom,$cnum);
1.400 raeburn 6210: $visible = 0;
1.256 raeburn 6211: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6212: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6213: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6214: if (ref($cathash) eq 'HASH') {
6215: if ($cathash->{'instcode::0'} eq '') {
6216: push(@vismsgs,'dc_addinst');
6217: } else {
6218: $visible = 1;
6219: }
6220: } else {
6221: $visible = 1;
6222: }
6223: } else {
6224: $visible = 1;
6225: }
6226: } else {
6227: if (ref($cathash) eq 'HASH') {
6228: if ($cathash->{'instcode::0'} ne '') {
6229: push(@vismsgs,'dc_instcode');
6230: }
6231: } else {
6232: push(@vismsgs,'dc_instcode');
6233: }
6234: }
6235: if ($currsettings{'categories'} ne '') {
6236: my $cathash;
1.400 raeburn 6237: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6238: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6239: if (ref($cathash) eq 'HASH') {
6240: if (keys(%{$cathash}) == 0) {
6241: push(@vismsgs,'dc_catalog');
6242: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6243: push(@vismsgs,'dc_categories');
6244: } else {
6245: my @currcategories = split('&',$currsettings{'categories'});
6246: my $matched = 0;
6247: foreach my $cat (@currcategories) {
6248: if ($cathash->{$cat} ne '') {
6249: $visible = 1;
6250: $matched = 1;
6251: last;
6252: }
6253: }
6254: if (!$matched) {
1.260 raeburn 6255: if ($settable{'categorize'}) {
1.256 raeburn 6256: push(@vismsgs,'chgcat');
6257: } else {
6258: push(@vismsgs,'dc_chgcat');
6259: }
6260: }
6261: }
6262: }
6263: }
6264: } else {
6265: if (ref($cathash) eq 'HASH') {
6266: if ((keys(%{$cathash}) > 1) ||
6267: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6268: if ($settable{'categorize'}) {
1.256 raeburn 6269: push(@vismsgs,'addcat');
6270: } else {
6271: push(@vismsgs,'dc_addcat');
6272: }
6273: }
6274: }
6275: }
6276: if ($currsettings{'hidefromcat'} eq 'yes') {
6277: $visible = 0;
6278: if ($settable{'togglecats'}) {
6279: unshift(@vismsgs,'unhide');
6280: } else {
6281: unshift(@vismsgs,'dc_unhide')
6282: }
6283: }
1.400 raeburn 6284: return ($visible,$cansetvis,\@vismsgs);
6285: }
6286:
6287: sub cat_visibility {
6288: my %visactions = &Apache::lonlocal::texthash(
6289: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6290: 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.',
6291: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6292: none => 'Display of a course catalog is disabled for this domain.',
6293: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6294: 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.',
6295: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6296: take => 'Take the following action to ensure the course appears in the Catalog:',
6297: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6298: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6299: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6300: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6301: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6302: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6303: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6304: 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',
6305: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6306: );
6307: $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>"');
6308: $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>"');
6309: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6310: return \%visactions;
1.256 raeburn 6311: }
6312:
1.241 raeburn 6313: sub new_selfenroll_dom_row {
6314: my ($newdom,$num) = @_;
6315: my $domdesc = &Apache::lonnet::domain($newdom);
6316: my $output;
6317: if ($domdesc ne '') {
6318: $output .= &Apache::loncommon::start_data_table_row()
6319: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6320: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6321: .'" value="'.$newdom.'" /></span><br />'
6322: .'<span class="LC_nobreak"><label><input type="checkbox" '
6323: .'name="selfenroll_activate" value="'.$num.'" '
6324: .'onchange="javascript:update_types('
6325: ."'selfenroll_activate','$num'".');" />'
6326: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6327: my @currinsttypes;
6328: $output .= '<td>'.&mt('User types:').'<br />'
6329: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6330: .&Apache::loncommon::end_data_table_row();
6331: }
6332: return $output;
6333: }
6334:
6335: sub selfenroll_inst_types {
6336: my ($num,$currdom,$currinsttypes) = @_;
6337: my $output;
6338: my $numinrow = 4;
6339: my $count = 0;
6340: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6341: my $othervalue = 'any';
1.241 raeburn 6342: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6343: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6344: $othervalue = 'other';
6345: }
1.241 raeburn 6346: $output .= '<table><tr>';
6347: foreach my $type (@{$types}) {
6348: if (($count > 0) && ($count%$numinrow == 0)) {
6349: $output .= '</tr><tr>';
6350: }
6351: if (defined($usertypes->{$type})) {
1.257 raeburn 6352: my $esc_type = &escape($type);
1.241 raeburn 6353: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6354: $esc_type.'" ';
1.241 raeburn 6355: if (ref($currinsttypes) eq 'ARRAY') {
6356: if (@{$currinsttypes} > 0) {
1.249 raeburn 6357: if (grep(/^any$/,@{$currinsttypes})) {
6358: $output .= 'checked="checked"';
1.257 raeburn 6359: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6360: $output .= 'checked="checked"';
6361: }
1.249 raeburn 6362: } else {
6363: $output .= 'checked="checked"';
1.241 raeburn 6364: }
6365: }
6366: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
6367: }
6368: $count ++;
6369: }
6370: if (($count > 0) && ($count%$numinrow == 0)) {
6371: $output .= '</tr><tr>';
6372: }
1.249 raeburn 6373: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6374: if (ref($currinsttypes) eq 'ARRAY') {
6375: if (@{$currinsttypes} > 0) {
1.249 raeburn 6376: if (grep(/^any$/,@{$currinsttypes})) {
6377: $output .= ' checked="checked"';
6378: } elsif ($othervalue eq 'other') {
6379: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6380: $output .= ' checked="checked"';
6381: }
1.241 raeburn 6382: }
1.249 raeburn 6383: } else {
6384: $output .= ' checked="checked"';
1.241 raeburn 6385: }
1.249 raeburn 6386: } else {
6387: $output .= ' checked="checked"';
1.241 raeburn 6388: }
6389: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
6390: }
6391: return $output;
6392: }
6393:
1.237 raeburn 6394: sub selfenroll_date_forms {
6395: my ($startform,$endform) = @_;
6396: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6397: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6398: 'LC_oddrow_value')."\n".
6399: $startform."\n".
6400: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6401: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6402: 'LC_oddrow_value')."\n".
6403: $endform."\n".
6404: &Apache::lonhtmlcommon::row_closure(1).
6405: &Apache::lonhtmlcommon::end_pick_box();
6406: return $output;
6407: }
6408:
1.239 raeburn 6409: sub print_userchangelogs_display {
6410: my ($r,$context,$permission) = @_;
1.363 raeburn 6411: my $formname = 'rolelog';
6412: my ($username,$domain,$crstype,%roleslog);
6413: if ($context eq 'domain') {
6414: $domain = $env{'request.role.domain'};
6415: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6416: } else {
6417: if ($context eq 'course') {
6418: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6419: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6420: $crstype = &Apache::loncommon::course_type();
6421: my %saveable_parameters = ('show' => 'scalar',);
6422: &Apache::loncommon::store_course_settings('roles_log',
6423: \%saveable_parameters);
6424: &Apache::loncommon::restore_course_settings('roles_log',
6425: \%saveable_parameters);
6426: } elsif ($context eq 'author') {
6427: $domain = $env{'user.domain'};
6428: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6429: $username = $env{'user.name'};
6430: } else {
6431: undef($domain);
6432: }
6433: }
6434: if ($domain ne '' && $username ne '') {
6435: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6436: }
6437: }
1.239 raeburn 6438: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6439:
6440: # set defaults
6441: my $now = time();
6442: my $defstart = $now - (7*24*3600); #7 days ago
6443: my %defaults = (
6444: page => '1',
6445: show => '10',
6446: role => 'any',
6447: chgcontext => 'any',
6448: rolelog_start_date => $defstart,
6449: rolelog_end_date => $now,
6450: );
6451: my $more_records = 0;
6452:
6453: # set current
6454: my %curr;
6455: foreach my $item ('show','page','role','chgcontext') {
6456: $curr{$item} = $env{'form.'.$item};
6457: }
6458: my ($startdate,$enddate) =
6459: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6460: $curr{'rolelog_start_date'} = $startdate;
6461: $curr{'rolelog_end_date'} = $enddate;
6462: foreach my $key (keys(%defaults)) {
6463: if ($curr{$key} eq '') {
6464: $curr{$key} = $defaults{$key};
6465: }
6466: }
1.248 raeburn 6467: my (%whodunit,%changed,$version);
6468: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6469: my ($minshown,$maxshown);
1.255 raeburn 6470: $minshown = 1;
1.239 raeburn 6471: my $count = 0;
6472: if ($curr{'show'} ne &mt('all')) {
6473: $maxshown = $curr{'page'} * $curr{'show'};
6474: if ($curr{'page'} > 1) {
6475: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6476: }
6477: }
1.301 bisitz 6478:
1.327 raeburn 6479: # Form Header
6480: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6481: &role_display_filter($context,$formname,$domain,$username,\%curr,
6482: $version,$crstype));
1.327 raeburn 6483:
6484: # Create navigation
6485: my ($nav_script,$nav_links) = &userlogdisplay_nav($formname,\%curr,$more_records);
6486: my $showntableheader = 0;
6487:
6488: # Table Header
6489: my $tableheader =
6490: &Apache::loncommon::start_data_table_header_row()
6491: .'<th> </th>'
6492: .'<th>'.&mt('When').'</th>'
6493: .'<th>'.&mt('Who made the change').'</th>'
6494: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6495: .'<th>'.&mt('Role').'</th>';
6496:
6497: if ($context eq 'course') {
6498: $tableheader .= '<th>'.&mt('Section').'</th>';
6499: }
6500: $tableheader .=
6501: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6502: .'<th>'.&mt('Start').'</th>'
6503: .'<th>'.&mt('End').'</th>'
6504: .&Apache::loncommon::end_data_table_header_row();
6505:
6506: # Display user change log data
1.239 raeburn 6507: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6508: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6509: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
6510: if ($curr{'show'} ne &mt('all')) {
6511: if ($count >= $curr{'page'} * $curr{'show'}) {
6512: $more_records = 1;
6513: last;
6514: }
6515: }
6516: if ($curr{'role'} ne 'any') {
6517: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6518: }
6519: if ($curr{'chgcontext'} ne 'any') {
6520: if ($curr{'chgcontext'} eq 'selfenroll') {
6521: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6522: } else {
6523: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6524: }
6525: }
6526: $count ++;
6527: next if ($count < $minshown);
1.327 raeburn 6528: unless ($showntableheader) {
6529: $r->print($nav_script
6530: .$nav_links
6531: .&Apache::loncommon::start_data_table()
6532: .$tableheader);
6533: $r->rflush();
6534: $showntableheader = 1;
6535: }
1.239 raeburn 6536: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6537: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6538: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6539: }
6540: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6541: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6542: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6543: }
6544: my $sec = $roleslog{$id}{'logentry'}{'section'};
6545: if ($sec eq '') {
6546: $sec = &mt('None');
6547: }
6548: my ($rolestart,$roleend);
6549: if ($roleslog{$id}{'delflag'}) {
6550: $rolestart = &mt('deleted');
6551: $roleend = &mt('deleted');
6552: } else {
6553: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6554: $roleend = $roleslog{$id}{'logentry'}{'end'};
6555: if ($rolestart eq '' || $rolestart == 0) {
6556: $rolestart = &mt('No start date');
6557: } else {
6558: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6559: }
6560: if ($roleend eq '' || $roleend == 0) {
6561: $roleend = &mt('No end date');
6562: } else {
6563: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6564: }
6565: }
6566: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6567: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6568: $chgcontext = 'selfenroll';
6569: }
1.363 raeburn 6570: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6571: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6572: $chgcontext = $lt{$chgcontext};
6573: }
1.327 raeburn 6574: $r->print(
1.301 bisitz 6575: &Apache::loncommon::start_data_table_row()
6576: .'<td>'.$count.'</td>'
6577: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6578: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6579: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6580: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6581: if ($context eq 'course') {
6582: $r->print('<td>'.$sec.'</td>');
6583: }
6584: $r->print(
6585: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6586: .'<td>'.$rolestart.'</td>'
6587: .'<td>'.$roleend.'</td>'
1.327 raeburn 6588: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6589: }
6590:
1.327 raeburn 6591: if ($showntableheader) { # Table footer, if content displayed above
6592: $r->print(&Apache::loncommon::end_data_table()
6593: .$nav_links);
6594: } else { # No content displayed above
1.301 bisitz 6595: $r->print('<p class="LC_info">'
6596: .&mt('There are no records to display.')
6597: .'</p>'
6598: );
1.239 raeburn 6599: }
1.301 bisitz 6600:
1.327 raeburn 6601: # Form Footer
6602: $r->print(
6603: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6604: .'<input type="hidden" name="action" value="changelogs" />'
6605: .'</form>');
6606: return;
6607: }
1.301 bisitz 6608:
1.327 raeburn 6609: sub userlogdisplay_nav {
6610: my ($formname,$curr,$more_records) = @_;
6611: my ($nav_script,$nav_links);
6612: if (ref($curr) eq 'HASH') {
6613: # Create Navigation:
6614: # Navigation Script
6615: $nav_script = <<"ENDSCRIPT";
1.239 raeburn 6616: <script type="text/javascript">
1.301 bisitz 6617: // <![CDATA[
1.239 raeburn 6618: function chgPage(caller) {
6619: if (caller == 'previous') {
6620: document.$formname.page.value --;
6621: }
6622: if (caller == 'next') {
6623: document.$formname.page.value ++;
6624: }
1.327 raeburn 6625: document.$formname.submit();
1.239 raeburn 6626: return;
6627: }
1.301 bisitz 6628: // ]]>
1.239 raeburn 6629: </script>
6630: ENDSCRIPT
1.327 raeburn 6631: # Navigation Buttons
6632: $nav_links = '<p>';
6633: if (($curr->{'page'} > 1) || ($more_records)) {
6634: if ($curr->{'page'} > 1) {
6635: $nav_links .= '<input type="button"'
6636: .' onclick="javascript:chgPage('."'previous'".');"'
6637: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
6638: .'" /> ';
6639: }
6640: if ($more_records) {
6641: $nav_links .= '<input type="button"'
6642: .' onclick="javascript:chgPage('."'next'".');"'
6643: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
6644: .'" />';
6645: }
1.301 bisitz 6646: }
1.327 raeburn 6647: $nav_links .= '</p>';
1.301 bisitz 6648: }
1.327 raeburn 6649: return ($nav_script,$nav_links);
1.239 raeburn 6650: }
6651:
6652: sub role_display_filter {
1.363 raeburn 6653: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
6654: my $lctype;
6655: if ($context eq 'course') {
6656: $lctype = lc($crstype);
6657: }
1.239 raeburn 6658: my $nolink = 1;
6659: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 6660: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 6661: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
6662: (&mt('all'),5,10,20,50,100,1000,10000)).
6663: '</td><td> </td>';
6664: my $startform =
6665: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
6666: $curr->{'rolelog_start_date'},undef,
6667: undef,undef,undef,undef,undef,undef,$nolink);
6668: my $endform =
6669: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
6670: $curr->{'rolelog_end_date'},undef,
6671: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 6672: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 6673: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
6674: '<table><tr><td>'.&mt('After:').
6675: '</td><td>'.$startform.'</td></tr>'.
6676: '<tr><td>'.&mt('Before:').'</td>'.
6677: '<td>'.$endform.'</td></tr></table>'.
6678: '</td>'.
6679: '<td> </td>'.
1.239 raeburn 6680: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
6681: '<select name="role"><option value="any"';
6682: if ($curr->{'role'} eq 'any') {
6683: $output .= ' selected="selected"';
6684: }
6685: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 6686: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 6687: foreach my $role (@roles) {
6688: my $plrole;
6689: if ($role eq 'cr') {
6690: $plrole = &mt('Custom Role');
6691: } else {
1.318 raeburn 6692: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 6693: }
6694: my $selstr = '';
6695: if ($role eq $curr->{'role'}) {
6696: $selstr = ' selected="selected"';
6697: }
6698: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
6699: }
1.301 bisitz 6700: $output .= '</select></td>'.
6701: '<td> </td>'.
6702: '<td valign="top"><b>'.
1.239 raeburn 6703: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 6704: my @posscontexts;
6705: if ($context eq 'course') {
1.376 raeburn 6706: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 6707: } elsif ($context eq 'domain') {
6708: @posscontexts = ('any','domain','requestauthor','domconfig','server');
6709: } else {
6710: @posscontexts = ('any','author','domain');
6711: }
6712: foreach my $chgtype (@posscontexts) {
1.239 raeburn 6713: my $selstr = '';
6714: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 6715: $selstr = ' selected="selected"';
1.239 raeburn 6716: }
1.363 raeburn 6717: if ($context eq 'course') {
1.376 raeburn 6718: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 6719: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
6720: }
1.239 raeburn 6721: }
6722: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 6723: }
1.303 bisitz 6724: $output .= '</select></td>'
6725: .'</tr></table>';
6726:
6727: # Update Display button
6728: $output .= '<p>'
6729: .'<input type="submit" value="'.&mt('Update Display').'" />'
6730: .'</p>';
6731:
6732: # Server version info
1.363 raeburn 6733: my $needsrev = '2.11.0';
6734: if ($context eq 'course') {
6735: $needsrev = '2.7.0';
6736: }
6737:
1.303 bisitz 6738: $output .= '<p class="LC_info">'
6739: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 6740: ,$needsrev);
1.248 raeburn 6741: if ($version) {
1.303 bisitz 6742: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
6743: }
6744: $output .= '</p><hr />';
1.239 raeburn 6745: return $output;
6746: }
6747:
6748: sub rolechg_contexts {
1.363 raeburn 6749: my ($context,$crstype) = @_;
6750: my %lt;
6751: if ($context eq 'course') {
6752: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 6753: any => 'Any',
1.376 raeburn 6754: automated => 'Automated Enrollment',
1.239 raeburn 6755: updatenow => 'Roster Update',
6756: createcourse => 'Course Creation',
6757: course => 'User Management in course',
6758: domain => 'User Management in domain',
1.313 raeburn 6759: selfenroll => 'Self-enrolled',
1.318 raeburn 6760: requestcourses => 'Course Request',
1.239 raeburn 6761: );
1.363 raeburn 6762: if ($crstype eq 'Community') {
6763: $lt{'createcourse'} = &mt('Community Creation');
6764: $lt{'course'} = &mt('User Management in community');
6765: $lt{'requestcourses'} = &mt('Community Request');
6766: }
6767: } elsif ($context eq 'domain') {
6768: %lt = &Apache::lonlocal::texthash (
6769: any => 'Any',
6770: domain => 'User Management in domain',
6771: requestauthor => 'Authoring Request',
6772: server => 'Command line script (DC role)',
6773: domconfig => 'Self-enrolled',
6774: );
6775: } else {
6776: %lt = &Apache::lonlocal::texthash (
6777: any => 'Any',
6778: domain => 'User Management in domain',
6779: author => 'User Management by author',
6780: );
6781: }
1.239 raeburn 6782: return %lt;
6783: }
6784:
1.27 matthew 6785: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 6786: sub user_search_result {
1.221 raeburn 6787: my ($context,$srch) = @_;
1.160 raeburn 6788: my %allhomes;
6789: my %inst_matches;
6790: my %srch_results;
1.181 raeburn 6791: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 6792: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 6793: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 6794: $response = &mt('Invalid search.');
6795: }
6796: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
6797: $response = &mt('Invalid search.');
6798: }
1.177 raeburn 6799: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 6800: $response = &mt('Invalid search.');
6801: }
6802: if ($srch->{'srchterm'} eq '') {
6803: $response = &mt('You must enter a search term.');
6804: }
1.183 raeburn 6805: if ($srch->{'srchterm'} =~ /^\s+$/) {
6806: $response = &mt('Your search term must contain more than just spaces.');
6807: }
1.160 raeburn 6808: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
6809: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 6810: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 6811: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
6812: }
6813: }
6814: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
6815: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 6816: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 6817: my $unamecheck = $srch->{'srchterm'};
6818: if ($srch->{'srchtype'} eq 'contains') {
6819: if ($unamecheck !~ /^\w/) {
6820: $unamecheck = 'a'.$unamecheck;
6821: }
6822: }
6823: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 6824: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
6825: }
1.160 raeburn 6826: }
6827: }
1.180 raeburn 6828: if ($response ne '') {
6829: $response = '<span class="LC_warning">'.$response.'</span>';
6830: }
1.160 raeburn 6831: if ($srch->{'srchin'} eq 'instd') {
6832: my $instd_chk = &directorysrch_check($srch);
6833: if ($instd_chk ne 'ok') {
1.180 raeburn 6834: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
6835: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 6836: }
6837: }
6838: if ($response ne '') {
1.180 raeburn 6839: return ($currstate,$response);
1.160 raeburn 6840: }
6841: if ($srch->{'srchby'} eq 'uname') {
6842: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
6843: if ($env{'form.forcenew'}) {
6844: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
6845: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6846: if ($uhome eq 'no_host') {
6847: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 6848: my $showdom = &display_domain_info($env{'request.role.domain'});
6849: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 6850: } else {
1.179 raeburn 6851: $currstate = 'modify';
1.160 raeburn 6852: }
6853: } else {
1.179 raeburn 6854: $currstate = 'modify';
1.160 raeburn 6855: }
6856: } else {
6857: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 6858: if ($srch->{'srchtype'} eq 'exact') {
6859: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6860: if ($uhome eq 'no_host') {
1.179 raeburn 6861: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6862: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6863: } else {
1.179 raeburn 6864: $currstate = 'modify';
1.310 raeburn 6865: my $uname = $srch->{'srchterm'};
6866: my $udom = $srch->{'srchdomain'};
6867: $srch_results{$uname.':'.$udom} =
6868: { &Apache::lonnet::get('environment',
6869: ['firstname',
6870: 'lastname',
6871: 'permanentemail'],
6872: $udom,$uname)
6873: };
1.162 raeburn 6874: }
6875: } else {
6876: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6877: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6878: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6879: }
6880: } else {
1.167 albertel 6881: my $courseusers = &get_courseusers();
1.162 raeburn 6882: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 6883: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 6884: $currstate = 'modify';
1.162 raeburn 6885: } else {
1.179 raeburn 6886: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6887: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6888: }
1.160 raeburn 6889: } else {
1.167 albertel 6890: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 6891: my ($cuname,$cudomain) = split(/:/,$user);
6892: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 6893: my $matched = 0;
6894: if ($srch->{'srchtype'} eq 'begins') {
6895: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
6896: $matched = 1;
6897: }
6898: } else {
6899: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
6900: $matched = 1;
6901: }
6902: }
6903: if ($matched) {
1.167 albertel 6904: $srch_results{$user} =
6905: {&Apache::lonnet::get('environment',
6906: ['firstname',
6907: 'lastname',
1.194 albertel 6908: 'permanentemail'],
6909: $cudomain,$cuname)};
1.162 raeburn 6910: }
6911: }
6912: }
1.179 raeburn 6913: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6914: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6915: }
6916: }
6917: }
6918: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6919: $currstate = 'query';
1.160 raeburn 6920: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6921: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6922: if ($dirsrchres eq 'ok') {
6923: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6924: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6925: } else {
6926: my $showdom = &display_domain_info($srch->{'srchdomain'});
6927: $response = '<span class="LC_warning">'.
6928: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6929: '</span><br />'.
6930: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6931: '<br /><br />';
6932: }
1.160 raeburn 6933: }
6934: } else {
6935: if ($srch->{'srchin'} eq 'dom') {
6936: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6937: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6938: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6939: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 6940: my $courseusers = &get_courseusers();
6941: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 6942: my ($uname,$udom) = split(/:/,$user);
6943: my %names = &Apache::loncommon::getnames($uname,$udom);
6944: my %emails = &Apache::loncommon::getemails($uname,$udom);
6945: if ($srch->{'srchby'} eq 'lastname') {
6946: if ((($srch->{'srchtype'} eq 'exact') &&
6947: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 6948: (($srch->{'srchtype'} eq 'begins') &&
6949: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 6950: (($srch->{'srchtype'} eq 'contains') &&
6951: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
6952: $srch_results{$user} = {firstname => $names{'firstname'},
6953: lastname => $names{'lastname'},
6954: permanentemail => $emails{'permanentemail'},
6955: };
6956: }
6957: } elsif ($srch->{'srchby'} eq 'lastfirst') {
6958: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 6959: $srchlast =~ s/\s+$//;
6960: $srchfirst =~ s/^\s+//;
1.160 raeburn 6961: if ($srch->{'srchtype'} eq 'exact') {
6962: if (($names{'lastname'} eq $srchlast) &&
6963: ($names{'firstname'} eq $srchfirst)) {
6964: $srch_results{$user} = {firstname => $names{'firstname'},
6965: lastname => $names{'lastname'},
6966: permanentemail => $emails{'permanentemail'},
6967:
6968: };
6969: }
1.177 raeburn 6970: } elsif ($srch->{'srchtype'} eq 'begins') {
6971: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
6972: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
6973: $srch_results{$user} = {firstname => $names{'firstname'},
6974: lastname => $names{'lastname'},
6975: permanentemail => $emails{'permanentemail'},
6976: };
6977: }
6978: } else {
1.160 raeburn 6979: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
6980: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
6981: $srch_results{$user} = {firstname => $names{'firstname'},
6982: lastname => $names{'lastname'},
6983: permanentemail => $emails{'permanentemail'},
6984: };
6985: }
6986: }
6987: }
6988: }
1.179 raeburn 6989: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6990: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6991: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6992: $currstate = 'query';
1.160 raeburn 6993: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6994: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6995: if ($dirsrchres eq 'ok') {
6996: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6997: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6998: } else {
6999: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
7000: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
7001: '</span><br />'.
7002: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
7003: '<br /><br />';
7004: }
1.160 raeburn 7005: }
7006: }
1.179 raeburn 7007: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 7008: }
7009:
7010: sub directorysrch_check {
7011: my ($srch) = @_;
7012: my $can_search = 0;
7013: my $response;
7014: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
7015: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 7016: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 7017: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
7018: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 7019: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 7020: }
7021: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
7022: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 7023: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 7024: }
7025: my @usertypes = split(/:/,$env{'environment.inststatus'});
7026: if (!@usertypes) {
7027: push(@usertypes,'default');
7028: }
7029: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
7030: foreach my $type (@usertypes) {
7031: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
7032: $can_search = 1;
7033: last;
7034: }
7035: }
7036: }
7037: if (!$can_search) {
7038: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
7039: my @longtypes;
7040: foreach my $item (@usertypes) {
1.229 raeburn 7041: if (defined($insttypes->{$item})) {
7042: push (@longtypes,$insttypes->{$item});
7043: } elsif ($item eq 'default') {
7044: push (@longtypes,&mt('other'));
7045: }
1.160 raeburn 7046: }
7047: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 7048: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 7049: }
1.160 raeburn 7050: } else {
7051: $can_search = 1;
7052: }
7053: } else {
1.180 raeburn 7054: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 7055: }
7056: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 7057: uname => 'username',
1.160 raeburn 7058: lastfirst => 'last name, first name',
1.167 albertel 7059: lastname => 'last name',
1.172 raeburn 7060: contains => 'contains',
1.178 raeburn 7061: exact => 'as exact match to',
7062: begins => 'begins with',
1.160 raeburn 7063: );
7064: if ($can_search) {
7065: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
7066: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 7067: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 7068: }
7069: } else {
1.180 raeburn 7070: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 7071: }
7072: }
7073: if ($can_search) {
1.178 raeburn 7074: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
7075: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
7076: return 'ok';
7077: } else {
1.180 raeburn 7078: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 7079: }
7080: } else {
7081: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
7082: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
7083: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
7084: return 'ok';
7085: } else {
1.180 raeburn 7086: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 7087: }
1.160 raeburn 7088: }
7089: }
7090: }
7091:
7092: sub get_courseusers {
7093: my %advhash;
1.167 albertel 7094: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 7095: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
7096: foreach my $role (sort(keys(%coursepersonnel))) {
7097: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 7098: if (!exists($classlist->{$user})) {
7099: $classlist->{$user} = [];
7100: }
1.160 raeburn 7101: }
7102: }
1.167 albertel 7103: return $classlist;
1.160 raeburn 7104: }
7105:
7106: sub build_search_response {
1.221 raeburn 7107: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 7108: my ($currstate,$response,$forcenewuser);
1.160 raeburn 7109: my %names = (
1.330 bisitz 7110: 'uname' => 'username',
7111: 'lastname' => 'last name',
1.160 raeburn 7112: 'lastfirst' => 'last name, first name',
1.330 bisitz 7113: 'crs' => 'this course',
7114: 'dom' => 'LON-CAPA domain',
7115: 'instd' => 'the institutional directory for domain',
1.160 raeburn 7116: );
7117:
7118: my %single = (
1.180 raeburn 7119: begins => 'A match',
1.160 raeburn 7120: contains => 'A match',
1.180 raeburn 7121: exact => 'An exact match',
1.160 raeburn 7122: );
7123: my %nomatch = (
1.180 raeburn 7124: begins => 'No match',
1.160 raeburn 7125: contains => 'No match',
1.180 raeburn 7126: exact => 'No exact match',
1.160 raeburn 7127: );
7128: if (keys(%srch_results) > 1) {
1.179 raeburn 7129: $currstate = 'select';
1.160 raeburn 7130: } else {
7131: if (keys(%srch_results) == 1) {
1.179 raeburn 7132: $currstate = 'modify';
1.180 raeburn 7133: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
7134: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 7135: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 7136: }
1.330 bisitz 7137: } else { # Search has nothing found. Prepare message to user.
7138: $response = '<span class="LC_warning">';
1.180 raeburn 7139: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 7140: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
7141: '<b>'.$srch->{'srchterm'}.'</b>',
7142: &display_domain_info($srch->{'srchdomain'}));
7143: } else {
7144: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
7145: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 7146: }
7147: $response .= '</span>';
1.330 bisitz 7148:
1.160 raeburn 7149: if ($srch->{'srchin'} ne 'alc') {
7150: $forcenewuser = 1;
7151: my $cansrchinst = 0;
7152: if ($srch->{'srchdomain'}) {
7153: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
7154: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7155: if ($domconfig{'directorysrch'}{'available'}) {
7156: $cansrchinst = 1;
7157: }
7158: }
7159: }
1.180 raeburn 7160: if ((($srch->{'srchby'} eq 'lastfirst') ||
7161: ($srch->{'srchby'} eq 'lastname')) &&
7162: ($srch->{'srchin'} eq 'dom')) {
7163: if ($cansrchinst) {
7164: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 7165: }
7166: }
1.180 raeburn 7167: if ($srch->{'srchin'} eq 'crs') {
7168: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
7169: }
7170: }
1.305 raeburn 7171: my $createdom = $env{'request.role.domain'};
7172: if ($context eq 'requestcrs') {
7173: if ($env{'form.coursedom'} ne '') {
7174: $createdom = $env{'form.coursedom'};
7175: }
7176: }
7177: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $createdom)) {
1.221 raeburn 7178: my $cancreate =
1.305 raeburn 7179: &Apache::lonuserutils::can_create_user($createdom,$context);
7180: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 7181: if ($cancreate) {
1.305 raeburn 7182: my $showdom = &display_domain_info($createdom);
1.266 bisitz 7183: $response .= '<br /><br />'
7184: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 7185: .'<br />';
7186: if ($context eq 'requestcrs') {
7187: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
7188: } else {
7189: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
7190: }
7191: $response .='<ul><li>'
1.266 bisitz 7192: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
7193: .'</li><li>'
7194: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
7195: .'</li><li>'
7196: .&mt('Provide the proposed username')
7197: .'</li><li>'
7198: .&mt("Click 'Search'")
7199: .'</li></ul><br />';
1.221 raeburn 7200: } else {
7201: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.305 raeburn 7202: $response .= '<br /><br />';
7203: if ($context eq 'requestcrs') {
1.314 raeburn 7204: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.305 raeburn 7205: } else {
7206: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
7207: }
7208: $response .= '<br />'
7209: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 7210: ,' <a'.$helplink.'>'
7211: ,'</a>')
1.305 raeburn 7212: .'<br /><br />';
1.221 raeburn 7213: }
1.160 raeburn 7214: }
7215: }
7216: }
1.179 raeburn 7217: return ($currstate,$response,$forcenewuser);
1.160 raeburn 7218: }
7219:
1.180 raeburn 7220: sub display_domain_info {
7221: my ($dom) = @_;
7222: my $output = $dom;
7223: if ($dom ne '') {
7224: my $domdesc = &Apache::lonnet::domain($dom,'description');
7225: if ($domdesc ne '') {
7226: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
7227: }
7228: }
7229: return $output;
7230: }
7231:
1.160 raeburn 7232: sub crumb_utilities {
7233: my %elements = (
7234: crtuser => {
7235: srchterm => 'text',
1.172 raeburn 7236: srchin => 'selectbox',
1.160 raeburn 7237: srchby => 'selectbox',
7238: srchtype => 'selectbox',
7239: srchdomain => 'selectbox',
7240: },
1.207 raeburn 7241: crtusername => {
7242: srchterm => 'text',
7243: srchdomain => 'selectbox',
7244: },
1.160 raeburn 7245: docustom => {
7246: rolename => 'selectbox',
7247: newrolename => 'textbox',
7248: },
1.179 raeburn 7249: studentform => {
7250: srchterm => 'text',
7251: srchin => 'selectbox',
7252: srchby => 'selectbox',
7253: srchtype => 'selectbox',
7254: srchdomain => 'selectbox',
7255: },
1.160 raeburn 7256: );
7257:
7258: my $jsback .= qq|
7259: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 7260: if (typeof prevphase == 'undefined') {
7261: formname.phase.value = '';
7262: }
7263: else {
7264: formname.phase.value = prevphase;
7265: }
7266: if (typeof prevstate == 'undefined') {
7267: formname.currstate.value = '';
7268: }
7269: else {
7270: formname.currstate.value = prevstate;
7271: }
1.160 raeburn 7272: formname.submit();
7273: }
7274: |;
7275: return ($jsback,\%elements);
7276: }
7277:
1.26 matthew 7278: sub course_level_table {
1.375 raeburn 7279: my ($inccourses,$showcredits,$defaultcredits) = @_;
7280: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 7281: my $table = '';
1.62 www 7282: # Custom Roles?
7283:
1.190 raeburn 7284: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 7285: my %lt=&Apache::lonlocal::texthash(
7286: 'exs' => "Existing sections",
7287: 'new' => "Define new section",
7288: 'ssd' => "Set Start Date",
7289: 'sed' => "Set End Date",
1.131 raeburn 7290: 'crl' => "Course Level",
1.89 raeburn 7291: 'act' => "Activate",
7292: 'rol' => "Role",
7293: 'ext' => "Extent",
1.113 raeburn 7294: 'grs' => "Section",
1.375 raeburn 7295: 'crd' => "Credits",
1.89 raeburn 7296: 'sta' => "Start",
7297: 'end' => "End"
7298: );
1.62 www 7299:
1.375 raeburn 7300: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 7301: my $thiscourse=$protectedcourse;
1.26 matthew 7302: $thiscourse=~s:_:/:g;
7303: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 7304: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 7305: my $area=$coursedata{'description'};
1.321 raeburn 7306: my $crstype=$coursedata{'type'};
1.135 raeburn 7307: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 7308: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 7309: my %sections_count;
1.101 albertel 7310: if (defined($env{'request.course.id'})) {
7311: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 7312: %sections_count =
7313: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 7314: }
7315: }
1.321 raeburn 7316: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 7317: foreach my $role (@roles) {
1.321 raeburn 7318: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 7319: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
7320: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 7321: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 7322: $plrole,\%sections_count,\%lt,
1.402 raeburn 7323: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 7324: } elsif ($env{'request.course.sec'} ne '') {
7325: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
7326: $env{'request.course.sec'})) {
7327: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 7328: $plrole,\%sections_count,\%lt,
1.402 raeburn 7329: $showcredits,$defaultcredits,$crstype);
1.26 matthew 7330: }
7331: }
7332: }
1.221 raeburn 7333: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 7334: foreach my $cust (sort(keys(%customroles))) {
7335: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 7336: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
7337: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 7338: $cust,\%sections_count,\%lt,
7339: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 7340: }
1.62 www 7341: }
1.26 matthew 7342: }
7343: return '' if ($table eq ''); # return nothing if there is nothing
7344: # in the table
1.188 raeburn 7345: my $result;
7346: if (!$env{'request.course.id'}) {
7347: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
7348: }
7349: $result .=
1.136 raeburn 7350: &Apache::loncommon::start_data_table().
7351: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 7352: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 7353: '<th>'.$lt{'ext'}.'</th><th>'."\n";
7354: if ($showcredits) {
7355: $result .= $lt{'crd'}.'</th>';
7356: }
7357: $result .=
1.375 raeburn 7358: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
7359: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 7360: &Apache::loncommon::end_data_table_header_row().
7361: $table.
7362: &Apache::loncommon::end_data_table();
1.26 matthew 7363: return $result;
7364: }
1.88 raeburn 7365:
1.221 raeburn 7366: sub course_level_row {
1.375 raeburn 7367: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 7368: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 7369: my $creditem;
1.222 raeburn 7370: my $row = &Apache::loncommon::start_data_table_row().
7371: ' <td><input type="checkbox" name="act_'.
7372: $protectedcourse.'_'.$role.'" /></td>'."\n".
7373: ' <td>'.$plrole.'</td>'."\n".
7374: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 7375: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 7376: $row .=
7377: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
7378: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
7379: } else {
7380: $row .= '<td> </td>';
7381: }
1.322 raeburn 7382: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 7383: $row .= '<td> </td>';
1.221 raeburn 7384: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 7385: $row .= ' <td><input type="hidden" value="'.
7386: $env{'request.course.sec'}.'" '.
7387: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
7388: $env{'request.course.sec'}.'</td>';
1.221 raeburn 7389: } else {
7390: if (ref($sections_count) eq 'HASH') {
7391: my $currsec =
7392: &Apache::lonuserutils::course_sections($sections_count,
7393: $protectedcourse.'_'.$role);
1.222 raeburn 7394: $row .= '<td><table class="LC_createuser">'."\n".
7395: '<tr class="LC_section_row">'."\n".
7396: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
7397: $currsec.'</td>'."\n".
7398: ' <td> </td>'."\n".
7399: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 7400: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
7401: '" value="" />'.
7402: '<input type="hidden" '.
7403: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 7404: '</tr></table></td>'."\n";
1.221 raeburn 7405: } else {
1.222 raeburn 7406: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 7407: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 7408: }
7409: }
1.222 raeburn 7410: $row .= <<ENDTIMEENTRY;
7411: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 7412: <a href=
7413: "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 7414: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 7415: <a href=
7416: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
7417: ENDTIMEENTRY
1.222 raeburn 7418: $row .= &Apache::loncommon::end_data_table_row();
7419: return $row;
1.221 raeburn 7420: }
7421:
1.88 raeburn 7422: sub course_level_dc {
1.375 raeburn 7423: my ($dcdom,$showcredits) = @_;
1.190 raeburn 7424: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 7425: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 7426: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
7427: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 7428: '<input type="hidden" name="dccourse" value="" />';
1.355 www 7429: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 7430: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 7431: my $credit_elem;
7432: if ($showcredits) {
7433: $credit_elem = 'credits';
7434: }
7435: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 7436: my %lt=&Apache::lonlocal::texthash(
7437: 'rol' => "Role",
1.113 raeburn 7438: 'grs' => "Section",
1.88 raeburn 7439: 'exs' => "Existing sections",
7440: 'new' => "Define new section",
7441: 'sta' => "Start",
7442: 'end' => "End",
7443: 'ssd' => "Set Start Date",
1.355 www 7444: 'sed' => "Set End Date",
1.375 raeburn 7445: 'scc' => "Course/Community",
7446: 'crd' => "Credits",
1.88 raeburn 7447: );
1.323 raeburn 7448: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 7449: &Apache::loncommon::start_data_table().
7450: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 7451: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 7452: '<th>'.$lt{'grs'}.'</th>'."\n";
7453: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
7454: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 7455: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 7456: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 7457: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
7458: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 7459: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 7460: foreach my $role (@roles) {
1.135 raeburn 7461: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 7462: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 7463: }
1.404 raeburn 7464: if ( keys(%customroles) > 0) {
7465: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 7466: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 7467: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 7468: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 7469: }
7470: }
7471: $otheritems .= '</select></td><td>'.
7472: '<table border="0" cellspacing="0" cellpadding="0">'.
7473: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 7474: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 7475: '<td> </td>'.
7476: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 7477: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 7478: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 7479: '<input type="hidden" name="groups" value="" />'.
7480: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 7481: '</tr></table></td>'."\n";
7482: if ($showcredits) {
7483: $otheritems .= '<td><br />'."\n".
1.397 bisitz 7484: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 7485: }
1.88 raeburn 7486: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 7487: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 7488: <a href=
7489: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 7490: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 7491: <a href=
7492: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
7493: ENDTIMEENTRY
1.136 raeburn 7494: $otheritems .= &Apache::loncommon::end_data_table_row().
7495: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 7496: return $cb_jscript.$header.$hiddenitems.$otheritems;
7497: }
7498:
1.237 raeburn 7499: sub update_selfenroll_config {
1.400 raeburn 7500: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 7501: return unless (ref($currsettings) eq 'HASH');
7502: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
7503: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 7504: my (%changes,%warning);
1.241 raeburn 7505: my $curr_types;
1.400 raeburn 7506: my %noedit;
7507: unless ($context eq 'domain') {
7508: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
7509: }
1.237 raeburn 7510: if (ref($row) eq 'ARRAY') {
7511: foreach my $item (@{$row}) {
1.400 raeburn 7512: next if ($noedit{$item});
1.237 raeburn 7513: if ($item eq 'enroll_dates') {
7514: my (%currenrolldate,%newenrolldate);
7515: foreach my $type ('start','end') {
1.398 raeburn 7516: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 7517: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
7518: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
7519: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
7520: }
7521: }
7522: } elsif ($item eq 'access_dates') {
7523: my (%currdate,%newdate);
7524: foreach my $type ('start','end') {
1.398 raeburn 7525: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 7526: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
7527: if ($newdate{$type} ne $currdate{$type}) {
7528: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
7529: }
7530: }
1.241 raeburn 7531: } elsif ($item eq 'types') {
1.398 raeburn 7532: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 7533: if ($env{'form.selfenroll_all'}) {
7534: if ($curr_types ne '*') {
7535: $changes{'internal.selfenroll_types'} = '*';
7536: } else {
7537: next;
7538: }
7539: } else {
1.249 raeburn 7540: my %currdoms;
1.241 raeburn 7541: my @entries = split(/;/,$curr_types);
7542: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 7543: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 7544: my $newnum = 0;
1.249 raeburn 7545: my @latesttypes;
7546: foreach my $num (@activations) {
7547: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
7548: if (@types > 0) {
1.241 raeburn 7549: @types = sort(@types);
7550: my $typestr = join(',',@types);
1.249 raeburn 7551: my $typedom = $env{'form.selfenroll_dom_'.$num};
7552: $latesttypes[$newnum] = $typedom.':'.$typestr;
7553: $currdoms{$typedom} = 1;
1.241 raeburn 7554: $newnum ++;
7555: }
7556: }
1.338 raeburn 7557: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
7558: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 7559: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
7560: if (@types > 0) {
7561: @types = sort(@types);
7562: my $typestr = join(',',@types);
7563: my $typedom = $env{'form.selfenroll_dom_'.$j};
7564: $latesttypes[$newnum] = $typedom.':'.$typestr;
7565: $currdoms{$typedom} = 1;
7566: $newnum ++;
7567: }
7568: }
7569: }
7570: if ($env{'form.selfenroll_newdom'} ne '') {
7571: my $typedom = $env{'form.selfenroll_newdom'};
7572: if ((!defined($currdoms{$typedom})) &&
7573: (&Apache::lonnet::domain($typedom) ne '')) {
7574: my $typestr;
7575: my ($othertitle,$usertypes,$types) =
7576: &Apache::loncommon::sorted_inst_types($typedom);
7577: my $othervalue = 'any';
7578: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7579: if (@{$types} > 0) {
1.257 raeburn 7580: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 7581: $othervalue = 'other';
1.258 raeburn 7582: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 7583: }
7584: $typestr = $othervalue;
7585: } else {
7586: $typestr = $othervalue;
7587: }
7588: $latesttypes[$newnum] = $typedom.':'.$typestr;
7589: $newnum ++ ;
7590: }
7591: }
1.241 raeburn 7592: my $selfenroll_types = join(';',@latesttypes);
7593: if ($selfenroll_types ne $curr_types) {
7594: $changes{'internal.selfenroll_types'} = $selfenroll_types;
7595: }
7596: }
1.276 raeburn 7597: } elsif ($item eq 'limit') {
7598: my $newlimit = $env{'form.selfenroll_limit'};
7599: my $newcap = $env{'form.selfenroll_cap'};
7600: $newcap =~s/\s+//g;
1.398 raeburn 7601: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 7602: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 7603: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 7604: if ($newlimit ne $currlimit) {
7605: if ($newlimit ne 'none') {
7606: if ($newcap =~ /^\d+$/) {
7607: if ($newcap ne $currcap) {
7608: $changes{'internal.selfenroll_cap'} = $newcap;
7609: }
7610: $changes{'internal.selfenroll_limit'} = $newlimit;
7611: } else {
1.398 raeburn 7612: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
7613: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 7614: }
7615: } elsif ($currcap ne '') {
7616: $changes{'internal.selfenroll_cap'} = '';
7617: $changes{'internal.selfenroll_limit'} = $newlimit;
7618: }
7619: } elsif ($currlimit ne 'none') {
7620: if ($newcap =~ /^\d+$/) {
7621: if ($newcap ne $currcap) {
7622: $changes{'internal.selfenroll_cap'} = $newcap;
7623: }
7624: } else {
1.398 raeburn 7625: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
7626: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 7627: }
7628: }
7629: } elsif ($item eq 'approval') {
7630: my (@currnotified,@newnotified);
1.398 raeburn 7631: my $currapproval = $currsettings->{'selfenroll_approval'};
7632: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 7633: if ($currnotifylist ne '') {
7634: @currnotified = split(/,/,$currnotifylist);
7635: @currnotified = sort(@currnotified);
7636: }
7637: my $newapproval = $env{'form.selfenroll_approval'};
7638: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
7639: @newnotified = sort(@newnotified);
7640: if ($newapproval ne $currapproval) {
7641: $changes{'internal.selfenroll_approval'} = $newapproval;
7642: if (!$newapproval) {
7643: if ($currnotifylist ne '') {
7644: $changes{'internal.selfenroll_notifylist'} = '';
7645: }
7646: } else {
7647: my @differences =
1.295 raeburn 7648: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 7649: if (@differences > 0) {
7650: if (@newnotified > 0) {
7651: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7652: } else {
7653: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7654: }
7655: }
7656: }
7657: } else {
1.295 raeburn 7658: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 7659: if (@differences > 0) {
7660: if (@newnotified > 0) {
7661: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7662: } else {
7663: $changes{'internal.selfenroll_notifylist'} = '';
7664: }
7665: }
7666: }
1.237 raeburn 7667: } else {
1.398 raeburn 7668: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 7669: my $newval = $env{'form.selfenroll_'.$item};
7670: if ($item eq 'section') {
7671: $newval = $env{'form.sections'};
1.241 raeburn 7672: if (defined($curr_groups{$newval})) {
1.237 raeburn 7673: $newval = $curr_val;
1.398 raeburn 7674: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
7675: &mt('Group names and section names must be distinct');
1.237 raeburn 7676: } elsif ($newval eq 'all') {
7677: $newval = $curr_val;
1.274 bisitz 7678: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 7679: }
7680: if ($newval eq '') {
7681: $newval = 'none';
7682: }
7683: }
7684: if ($newval ne $curr_val) {
7685: $changes{'internal.selfenroll_'.$item} = $newval;
7686: }
1.241 raeburn 7687: }
1.237 raeburn 7688: }
7689: if (keys(%warning) > 0) {
7690: foreach my $item (@{$row}) {
7691: if (exists($warning{$item})) {
7692: $r->print($warning{$item}.'<br />');
7693: }
7694: }
7695: }
7696: if (keys(%changes) > 0) {
7697: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
7698: if ($putresult eq 'ok') {
7699: if ((exists($changes{'internal.selfenroll_types'})) ||
7700: (exists($changes{'internal.selfenroll_start_date'})) ||
7701: (exists($changes{'internal.selfenroll_end_date'}))) {
7702: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
7703: $cnum,undef,undef,'Course');
7704: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 7705: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 7706: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
7707: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 7708: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 7709: }
7710: }
7711: my $crsputresult =
7712: &Apache::lonnet::courseidput($cdom,\%crsinfo,
7713: $chome,'notime');
7714: }
7715: }
7716: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
7717: foreach my $item (@{$row}) {
7718: my $title = $item;
7719: if (ref($lt) eq 'HASH') {
7720: $title = $lt->{$item};
7721: }
7722: if ($item eq 'enroll_dates') {
7723: foreach my $type ('start','end') {
7724: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
7725: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 7726: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 7727: $title,$type,$newdate).'</li>');
7728: }
7729: }
7730: } elsif ($item eq 'access_dates') {
7731: foreach my $type ('start','end') {
7732: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
7733: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 7734: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 7735: $title,$type,$newdate).'</li>');
7736: }
7737: }
1.276 raeburn 7738: } elsif ($item eq 'limit') {
7739: if ((exists($changes{'internal.selfenroll_limit'})) ||
7740: (exists($changes{'internal.selfenroll_cap'}))) {
7741: my ($newval,$newcap);
7742: if ($changes{'internal.selfenroll_cap'} ne '') {
7743: $newcap = $changes{'internal.selfenroll_cap'}
7744: } else {
1.398 raeburn 7745: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 7746: }
7747: if ($changes{'internal.selfenroll_limit'} eq 'none') {
7748: $newval = &mt('No limit');
7749: } elsif ($changes{'internal.selfenroll_limit'} eq
7750: 'allstudents') {
7751: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
7752: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
7753: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
7754: } else {
1.398 raeburn 7755: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 7756: if ($currlimit eq 'allstudents') {
7757: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
7758: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 7759: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 7760: }
7761: }
7762: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
7763: }
7764: } elsif ($item eq 'approval') {
7765: if ((exists($changes{'internal.selfenroll_approval'})) ||
7766: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 7767: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 7768: my ($newval,$newnotify);
7769: if (exists($changes{'internal.selfenroll_notifylist'})) {
7770: $newnotify = $changes{'internal.selfenroll_notifylist'};
7771: } else {
1.398 raeburn 7772: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 7773: }
1.398 raeburn 7774: if (exists($changes{'internal.selfenroll_approval'})) {
7775: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
7776: $changes{'internal.selfenroll_approval'} = '0';
7777: }
7778: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 7779: } else {
1.398 raeburn 7780: my $currapproval = $currsettings->{'selfenroll_approval'};
7781: if ($currapproval !~ /^[012]$/) {
7782: $currapproval = 0;
1.276 raeburn 7783: }
1.398 raeburn 7784: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 7785: }
7786: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
7787: if ($newnotify) {
1.277 raeburn 7788: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 7789: } else {
1.277 raeburn 7790: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 7791: }
7792: $r->print('</li>'."\n");
7793: }
1.237 raeburn 7794: } else {
7795: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 7796: my $newval = $changes{'internal.selfenroll_'.$item};
7797: if ($item eq 'types') {
7798: if ($newval eq '') {
7799: $newval = &mt('None');
7800: } elsif ($newval eq '*') {
7801: $newval = &mt('Any user in any domain');
7802: }
1.245 raeburn 7803: } elsif ($item eq 'registered') {
7804: if ($newval eq '1') {
7805: $newval = &mt('Yes');
7806: } elsif ($newval eq '0') {
7807: $newval = &mt('No');
7808: }
1.241 raeburn 7809: }
1.244 bisitz 7810: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 7811: }
7812: }
7813: }
7814: $r->print('</ul>');
1.398 raeburn 7815: if ($env{'course.'.$cid.'.description'} ne '') {
7816: my %newenvhash;
7817: foreach my $key (keys(%changes)) {
7818: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
7819: }
7820: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 7821: }
7822: } else {
1.398 raeburn 7823: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
7824: &mt('The error was: [_1].',$putresult));
1.237 raeburn 7825: }
7826: } else {
1.249 raeburn 7827: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 7828: }
7829: } else {
1.249 raeburn 7830: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 7831: }
1.400 raeburn 7832: my $visactions = &cat_visibility();
7833: my ($cathash,%cattype);
7834: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
7835: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7836: $cathash = $domconfig{'coursecategories'}{'cats'};
7837: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
7838: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
7839: } else {
7840: $cathash = {};
7841: $cattype{'auth'} = 'std';
7842: $cattype{'unauth'} = 'std';
7843: }
7844: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
7845: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7846: '<br />'.
7847: '<br />'.$visactions->{'take'}.'<ul>'.
7848: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
7849: '</ul>');
7850: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
7851: if ($currsettings->{'uniquecode'}) {
7852: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
7853: } else {
1.366 bisitz 7854: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 7855: '<br />'.
7856: '<br />'.$visactions->{'take'}.'<ul>'.
7857: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
7858: '</ul><br />');
7859: }
7860: } else {
7861: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
7862: if (ref($visactions) eq 'HASH') {
7863: if (!$visible) {
7864: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7865: '<br />');
7866: if (ref($vismsgs) eq 'ARRAY') {
7867: $r->print('<br />'.$visactions->{'take'}.'<ul>');
7868: foreach my $item (@{$vismsgs}) {
7869: $r->print('<li>'.$visactions->{$item}.'</li>');
7870: }
7871: $r->print('</ul>');
1.256 raeburn 7872: }
1.400 raeburn 7873: $r->print($cansetvis);
1.256 raeburn 7874: }
7875: }
7876: }
1.237 raeburn 7877: return;
7878: }
7879:
1.27 matthew 7880: #---------------------------------------------- end functions for &phase_two
1.29 matthew 7881:
7882: #--------------------------------- functions for &phase_two and &phase_three
7883:
7884: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 7885:
1.1 www 7886: 1;
7887: __END__
1.2 www 7888:
7889:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>