Annotation of loncom/interface/loncreateuser.pm, revision 1.400
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.400 ! raeburn 4: # $Id: loncreateuser.pm,v 1.399 2014/04/25 17:56:42 bisitz Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
1.324 raeburn 54: Custom roles can be defined by a Domain Coordinator, Course Coordinator
55: or Community Coordinator via the Manage User functionality.
56: The custom role editor screen will show all privileges which can be
57: assigned to users. For a complete list of privileges, please see
58: C</home/httpd/lonTabs/rolesplain.tab>.
1.66 bowersj2 59:
1.324 raeburn 60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
1.66 bowersj2 62:
63: =cut
1.1 www 64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
1.54 bowersj2 68: use Apache::loncommon;
1.68 www 69: use Apache::lonlocal;
1.117 raeburn 70: use Apache::longroup;
1.190 raeburn 71: use Apache::lonuserutils;
1.307 raeburn 72: use Apache::loncoursequeueadmin;
1.139 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1 www 74:
1.20 harris41 75: my $loginscript; # piece of javascript used in two separate instances
76: my $authformnop;
77: my $authformkrb;
78: my $authformint;
79: my $authformfsys;
80: my $authformloc;
81:
1.94 matthew 82: sub initialize_authen_forms {
1.227 raeburn 83: my ($dom,$formname,$curr_authtype,$mode) = @_;
84: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
85: my %param = ( formname => $formname,
1.187 raeburn 86: kerb_def_dom => $krbdefdom,
1.227 raeburn 87: kerb_def_auth => $krbdef,
1.187 raeburn 88: domain => $dom,
89: );
1.188 raeburn 90: my %abv_auth = &auth_abbrev();
1.227 raeburn 91: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 92: my $long_auth = $1;
1.227 raeburn 93: my $curr_autharg = $2;
1.188 raeburn 94: my %abv_auth = &auth_abbrev();
95: $param{'curr_authtype'} = $abv_auth{$long_auth};
96: if ($long_auth =~ /^krb(4|5)$/) {
97: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 98: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 99: }
1.205 raeburn 100: if ($mode eq 'modifyuser') {
101: $param{'mode'} = $mode;
102: }
1.187 raeburn 103: }
1.227 raeburn 104: $loginscript = &Apache::loncommon::authform_header(%param);
105: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 106: $authformnop = &Apache::loncommon::authform_nochange(%param);
107: $authformint = &Apache::loncommon::authform_internal(%param);
108: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
109: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 110: }
111:
1.188 raeburn 112: sub auth_abbrev {
113: my %abv_auth = (
1.368 raeburn 114: krb5 => 'krb',
115: krb4 => 'krb',
116: internal => 'int',
117: localauth => 'loc',
118: unix => 'fsys',
1.188 raeburn 119: );
120: return %abv_auth;
121: }
1.43 www 122:
1.134 raeburn 123: # ====================================================
124:
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.396 raeburn 2167: $now,$captchaform,$emailusername,$usertype) = @_;
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.394 raeburn 2247: my $upassone = '<input type="password" name="upass'.$now.'" size="10" autocomplete="off" />';
2248: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="10" 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.287 raeburn 2285: if (($item eq 'permanentemail') && ($newuser eq 'email')) {
2286: $row .= $ccuname;
1.252 raeburn 2287: } else {
1.287 raeburn 2288: if ($canmodify{$item}) {
1.391 raeburn 2289: if ($newuser eq 'email') {
1.394 raeburn 2290: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.391 raeburn 2291: } else {
1.394 raeburn 2292: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.391 raeburn 2293: }
1.287 raeburn 2294: $editable ++;
2295: } else {
2296: $hiderow = 1;
2297: }
1.252 raeburn 2298: }
1.253 raeburn 2299: } else {
2300: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2301: }
1.188 raeburn 2302: }
2303: } else {
1.219 raeburn 2304: if ($canmodify{$item}) {
1.252 raeburn 2305: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2306: if (($item eq 'id') && (!$newuser)) {
2307: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2308: }
1.188 raeburn 2309: } else {
1.252 raeburn 2310: $row .= $userenv{$item};
1.188 raeburn 2311: }
2312: }
1.252 raeburn 2313: $row .= &Apache::lonhtmlcommon::row_closure(1);
2314: if (!$hiderow) {
2315: $output .= $row;
2316: $rowcount ++;
2317: }
1.188 raeburn 2318: }
1.286 raeburn 2319: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2320: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2321: if (ref($types) eq 'ARRAY') {
2322: if (@{$types} > 0) {
2323: my ($hiderow,$shown);
2324: if ($canmodify_status{'inststatus'}) {
2325: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2326: } else {
2327: if ($userenv{'inststatus'} eq '') {
2328: $hiderow = 1;
1.334 raeburn 2329: } else {
2330: my @showitems;
2331: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2332: if (exists($usertypes->{$item})) {
2333: push(@showitems,$usertypes->{$item});
2334: } else {
2335: push(@showitems,$item);
2336: }
2337: }
2338: if (@showitems) {
2339: $shown = join(', ',@showitems);
2340: } else {
2341: $hiderow = 1;
2342: }
1.286 raeburn 2343: }
2344: }
2345: if (!$hiderow) {
1.389 bisitz 2346: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2347: $shown.&Apache::lonhtmlcommon::row_closure(1);
2348: if ($context eq 'selfcreate') {
2349: $rowcount ++;
2350: }
2351: $output .= $row;
2352: }
2353: }
2354: }
2355: }
1.391 raeburn 2356: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2357: if ($captchaform) {
2358: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'},
2359: 'LC_pick_box_title')."\n".
2360: $captchaform."\n".'<br /><br />'.
2361: &Apache::lonhtmlcommon::row_closure(1);
2362: $rowcount ++;
2363: }
2364: my $submit_text = &mt('Create account');
2365: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2366: '<br /><input type="submit" name="createaccount" value="'.
2367: $submit_text.'" />'.
1.396 raeburn 2368: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2369: &Apache::lonhtmlcommon::row_closure(1);
2370: }
1.188 raeburn 2371: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2372: if (wantarray) {
1.252 raeburn 2373: if ($context eq 'selfcreate') {
2374: return($output,$rowcount,$editable);
2375: } else {
1.388 bisitz 2376: return $output;
1.252 raeburn 2377: }
1.206 raeburn 2378: } else {
2379: return $output;
2380: }
1.188 raeburn 2381: }
2382:
1.286 raeburn 2383: sub pick_inst_statuses {
2384: my ($curr,$usertypes,$types) = @_;
2385: my ($output,$rem,@currtypes);
2386: if ($curr ne '') {
2387: @currtypes = map { &unescape($_); } split(/:/,$curr);
2388: }
2389: my $numinrow = 2;
2390: if (ref($types) eq 'ARRAY') {
2391: $output = '<table>';
2392: my $lastcolspan;
2393: for (my $i=0; $i<@{$types}; $i++) {
2394: if (defined($usertypes->{$types->[$i]})) {
2395: my $rem = $i%($numinrow);
2396: if ($rem == 0) {
2397: if ($i<@{$types}-1) {
2398: if ($i > 0) {
2399: $output .= '</tr>';
2400: }
2401: $output .= '<tr>';
2402: }
2403: } elsif ($i==@{$types}-1) {
2404: my $colsleft = $numinrow - $rem;
2405: if ($colsleft > 1) {
2406: $lastcolspan = ' colspan="'.$colsleft.'"';
2407: }
2408: }
2409: my $check = ' ';
2410: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2411: $check = ' checked="checked" ';
2412: }
2413: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2414: '<span class="LC_nobreak"><label>'.
2415: '<input type="checkbox" name="inststatus" '.
2416: 'value="'.$types->[$i].'"'.$check.'/>'.
2417: $usertypes->{$types->[$i]}.'</label></span></td>';
2418: }
2419: }
2420: $output .= '</tr></table>';
2421: }
2422: return $output;
2423: }
2424:
1.257 raeburn 2425: sub selfcreate_canmodify {
2426: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2427: if (ref($inst_results) eq 'HASH') {
2428: my @inststatuses = &get_inststatuses($inst_results);
2429: if (@inststatuses == 0) {
2430: @inststatuses = ('default');
2431: }
2432: $rolesarray = \@inststatuses;
2433: }
2434: my %canmodify =
2435: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2436: $rolesarray);
2437: return %canmodify;
2438: }
2439:
1.252 raeburn 2440: sub get_inststatuses {
2441: my ($insthashref) = @_;
2442: my @inststatuses = ();
2443: if (ref($insthashref) eq 'HASH') {
2444: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2445: @inststatuses = @{$insthashref->{'inststatus'}};
2446: }
2447: }
2448: return @inststatuses;
2449: }
2450:
1.4 www 2451: # ================================================================= Phase Three
1.42 matthew 2452: sub update_user_data {
1.375 raeburn 2453: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2454: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2455: $env{'form.ccdomain'});
1.27 matthew 2456: # Error messages
1.188 raeburn 2457: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2458: my $end = '</span><br /><br />';
2459: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2460: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2461: &mt('Return to previous page').'</a>'.
2462: &Apache::loncommon::end_page();
2463: my $now = time;
1.40 www 2464: my $title;
1.101 albertel 2465: if (exists($env{'form.makeuser'})) {
1.40 www 2466: $title='Set Privileges for New User';
2467: } else {
2468: $title='Modify User Privileges';
2469: }
1.213 raeburn 2470: my $newuser = 0;
1.160 raeburn 2471: my ($jsback,$elements) = &crumb_utilities();
2472: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2473: '// <![CDATA['."\n".
2474: $jsback."\n".
2475: '// ]]>'."\n".
2476: '</script>'."\n";
1.318 raeburn 2477: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 2478: push (@{$brcrum},
2479: {href => "javascript:backPage(document.userupdate)",
2480: text => $breadcrumb_text{'search'},
2481: faq => 282,
2482: bug => 'Instructor Interface',}
2483: );
2484: if ($env{'form.prevphase'} eq 'userpicked') {
2485: push(@{$brcrum},
2486: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2487: text => $breadcrumb_text{'userpicked'},
2488: faq => 282,
2489: bug => 'Instructor Interface',});
1.233 raeburn 2490: }
1.224 raeburn 2491: my $helpitem = 'Course_Change_Privileges';
2492: if ($env{'form.action'} eq 'singlestudent') {
2493: $helpitem = 'Course_Add_Student';
2494: }
1.351 raeburn 2495: push(@{$brcrum},
2496: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2497: text => $breadcrumb_text{'modify'},
2498: faq => 282,
2499: bug => 'Instructor Interface',},
2500: {href => "/adm/createuser",
2501: text => "Result",
2502: faq => 282,
2503: bug => 'Instructor Interface',
2504: help => $helpitem});
2505: my $args = {bread_crumbs => $brcrum,
2506: bread_crumbs_component => 'User Management'};
2507: if ($env{'form.popup'}) {
2508: $args->{'no_nav_bar'} = 1;
2509: }
2510: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2511: $r->print(&update_result_form($uhome));
1.27 matthew 2512: # Check Inputs
1.101 albertel 2513: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2514: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2515: return;
2516: }
1.138 albertel 2517: if ( $env{'form.ccuname'} ne
2518: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2519: $r->print($error.&mt('Invalid login name.').' '.
2520: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2521: $end.$rtnlink);
1.27 matthew 2522: return;
2523: }
1.101 albertel 2524: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2525: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2526: return;
2527: }
1.138 albertel 2528: if ( $env{'form.ccdomain'} ne
2529: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2530: $r->print($error.&mt('Invalid domain name.').' '.
2531: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2532: $end.$rtnlink);
1.27 matthew 2533: return;
2534: }
1.219 raeburn 2535: if ($uhome eq 'no_host') {
2536: $newuser = 1;
2537: }
1.101 albertel 2538: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2539: # Modifying an existing user, so check the validity of the name
2540: if ($uhome eq 'no_host') {
1.389 bisitz 2541: $r->print(
2542: $error
2543: .'<p class="LC_error">'
2544: .&mt('Unable to determine home server for [_1] in domain [_2].',
2545: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2546: .'</p>');
1.29 matthew 2547: return;
2548: }
2549: }
1.27 matthew 2550: # Determine authentication method and password for the user being modified
2551: my $amode='';
2552: my $genpwd='';
1.101 albertel 2553: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2554: $amode='krb';
1.101 albertel 2555: $amode.=$env{'form.krbver'};
2556: $genpwd=$env{'form.krbarg'};
2557: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2558: $amode='internal';
1.101 albertel 2559: $genpwd=$env{'form.intarg'};
2560: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2561: $amode='unix';
1.101 albertel 2562: $genpwd=$env{'form.fsysarg'};
2563: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2564: $amode='localauth';
1.101 albertel 2565: $genpwd=$env{'form.locarg'};
1.27 matthew 2566: $genpwd=" " if (!$genpwd);
1.101 albertel 2567: } elsif (($env{'form.login'} eq 'nochange') ||
2568: ($env{'form.login'} eq '' )) {
1.34 matthew 2569: # There is no need to tell the user we did not change what they
2570: # did not ask us to change.
1.35 matthew 2571: # If they are creating a new user but have not specified login
2572: # information this will be caught below.
1.30 matthew 2573: } else {
1.367 golterma 2574: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2575: return;
1.27 matthew 2576: }
1.164 albertel 2577:
1.188 raeburn 2578: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2579: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2580: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2581: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2582:
1.193 raeburn 2583: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2584: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2585: my @usertools = ('aboutme','blog','webdav','portfolio');
1.384 raeburn 2586: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 2587: my @requestauthor = ('requestauthor');
1.286 raeburn 2588: my ($othertitle,$usertypes,$types) =
2589: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2590: my %canmodify_status =
2591: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2592: ['inststatus']);
1.101 albertel 2593: if ($env{'form.makeuser'}) {
1.164 albertel 2594: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2595: # Check for the authentication mode and password
2596: if (! $amode || ! $genpwd) {
1.193 raeburn 2597: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2598: return;
1.18 albertel 2599: }
1.29 matthew 2600: # Determine desired host
1.101 albertel 2601: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2602: if (lc($desiredhost) eq 'default') {
2603: $desiredhost = undef;
2604: } else {
1.147 albertel 2605: my %home_servers =
2606: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2607: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2608: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2609: return;
2610: }
2611: }
2612: # Check ID format
2613: my %checkhash;
2614: my %checks = ('id' => 1);
2615: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2616: 'newuser' => $newuser,
1.196 raeburn 2617: 'id' => $env{'form.cid'},
1.193 raeburn 2618: );
1.196 raeburn 2619: if ($env{'form.cid'} ne '') {
2620: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2621: \%rulematch,\%inst_results,\%curr_rules);
2622: if (ref($alerts{'id'}) eq 'HASH') {
2623: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2624: my $domdesc =
2625: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2626: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2627: my $userchkmsg;
2628: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2629: $userchkmsg =
2630: &Apache::loncommon::instrule_disallow_msg('id',
2631: $domdesc,1).
2632: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2633: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2634: }
2635: $r->print($error.&mt('Invalid ID format').$end.
2636: $userchkmsg.$rtnlink);
2637: return;
2638: }
2639: }
1.29 matthew 2640: }
2641: }
1.367 golterma 2642: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2643: # Call modifyuser
2644: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2645: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2646: $amode,$genpwd,$env{'form.cfirstname'},
2647: $env{'form.cmiddlename'},$env{'form.clastname'},
2648: $env{'form.cgeneration'},undef,$desiredhost,
2649: $env{'form.cpermanentemail'});
1.77 www 2650: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2651: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2652: $env{'form.ccdomain'});
1.334 raeburn 2653: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2654: if ($uhome ne 'no_host') {
1.334 raeburn 2655: if ($context eq 'domain') {
1.378 raeburn 2656: foreach my $name ('portfolio','author') {
2657: if ($env{'form.custom_'.$name.'quota'} == 1) {
2658: if ($env{'form.'.$name.'quota'} eq '') {
2659: $newcustom{$name.'quota'} = 0;
2660: } else {
2661: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2662: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2663: }
2664: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2665: $changed{$name.'quota'} = 1;
2666: }
1.334 raeburn 2667: }
2668: }
2669: foreach my $item (@usertools) {
2670: if ($env{'form.custom'.$item} == 1) {
2671: $newcustom{$item} = $env{'form.tools_'.$item};
2672: $changed{$item} = &tool_admin($item,$newcustom{$item},
2673: \%changeHash,'tools');
2674: }
1.267 raeburn 2675: }
1.334 raeburn 2676: foreach my $item (@requestcourses) {
1.341 raeburn 2677: if ($env{'form.custom'.$item} == 1) {
2678: $newcustom{$item} = $env{'form.crsreq_'.$item};
2679: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2680: $newcustom{$item} .= '=';
1.383 raeburn 2681: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2682: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2683: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2684: }
1.334 raeburn 2685: }
1.341 raeburn 2686: $changed{$item} = &tool_admin($item,$newcustom{$item},
2687: \%changeHash,'requestcourses');
1.334 raeburn 2688: }
1.275 raeburn 2689: }
1.362 raeburn 2690: if ($env{'form.customrequestauthor'} == 1) {
2691: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2692: $changed{'requestauthor'} = &tool_admin('requestauthor',
2693: $newcustom{'requestauthor'},
2694: \%changeHash,'requestauthor');
2695: }
1.275 raeburn 2696: }
1.334 raeburn 2697: if ($canmodify_status{'inststatus'}) {
2698: if (exists($env{'form.inststatus'})) {
2699: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2700: if (@inststatuses > 0) {
2701: $changeHash{'inststatus'} = join(',',@inststatuses);
2702: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2703: }
2704: }
1.232 raeburn 2705: }
1.334 raeburn 2706: if (keys(%changed)) {
2707: foreach my $item (@userinfo) {
2708: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2709: }
1.267 raeburn 2710: my $chgresult =
2711: &Apache::lonnet::put('environment',\%changeHash,
2712: $env{'form.ccdomain'},$env{'form.ccuname'});
2713: }
1.232 raeburn 2714: }
1.219 raeburn 2715: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2716: &Apache::lonnet::hostname($uhome));
1.101 albertel 2717: } elsif (($env{'form.login'} ne 'nochange') &&
2718: ($env{'form.login'} ne '' )) {
1.27 matthew 2719: # Modify user privileges
2720: if (! $amode || ! $genpwd) {
1.193 raeburn 2721: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2722: return;
1.20 harris41 2723: }
1.395 bisitz 2724: # Only allow authentication modification if the person has authority
1.101 albertel 2725: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2726: $r->print('Modifying authentication: '.
1.31 matthew 2727: &Apache::lonnet::modifyuserauth(
1.101 albertel 2728: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2729: $amode,$genpwd));
1.102 albertel 2730: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2731: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2732: } else {
1.27 matthew 2733: # Okay, this is a non-fatal error.
1.395 bisitz 2734: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2735: }
1.28 matthew 2736: }
1.344 bisitz 2737: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2738: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2739: ##
1.375 raeburn 2740: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2741: if ($context eq 'course') {
1.375 raeburn 2742: ($cnum,$cdom) =
2743: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2744: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2745: if ($showcredits) {
2746: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2747: }
1.213 raeburn 2748: }
1.101 albertel 2749: if (! $env{'form.makeuser'} ) {
1.28 matthew 2750: # Check for need to change
2751: my %userenv = &Apache::lonnet::get
1.134 raeburn 2752: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2753: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2754: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2755: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2756: 'requestcourses.community','requestcourses.textbook',
2757: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2758: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.362 raeburn 2759: 'requestauthor'],
1.160 raeburn 2760: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2761: my ($tmp) = keys(%userenv);
2762: if ($tmp =~ /^(con_lost|error)/i) {
2763: %userenv = ();
2764: }
1.206 raeburn 2765: my $no_forceid_alert;
2766: # Check to see if user information can be changed
2767: my %domconfig =
2768: &Apache::lonnet::get_dom('configuration',['usermodification'],
2769: $env{'form.ccdomain'});
1.213 raeburn 2770: my @statuses = ('active','future');
2771: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2772: my ($auname,$audom);
1.220 raeburn 2773: if ($context eq 'author') {
1.206 raeburn 2774: $auname = $env{'user.name'};
2775: $audom = $env{'user.domain'};
2776: }
2777: foreach my $item (keys(%roles)) {
1.220 raeburn 2778: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2779: if ($context eq 'course') {
2780: if ($cnum ne '' && $cdom ne '') {
2781: if ($rolenum eq $cnum && $roledom eq $cdom) {
2782: if (!grep(/^\Q$role\E$/,@userroles)) {
2783: push(@userroles,$role);
2784: }
2785: }
2786: }
2787: } elsif ($context eq 'author') {
2788: if ($rolenum eq $auname && $roledom eq $audom) {
2789: if (!grep(/^\Q$role\E$/,@userroles)) {
2790: push(@userroles,$role);
2791: }
2792: }
2793: }
2794: }
1.220 raeburn 2795: if ($env{'form.action'} eq 'singlestudent') {
2796: if (!grep(/^st$/,@userroles)) {
2797: push(@userroles,'st');
2798: }
2799: } else {
2800: # Check for course or co-author roles being activated or re-enabled
2801: if ($context eq 'author' || $context eq 'course') {
2802: foreach my $key (keys(%env)) {
2803: if ($context eq 'author') {
2804: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2805: if (!grep(/^\Q$1\E$/,@userroles)) {
2806: push(@userroles,$1);
2807: }
2808: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2809: if (!grep(/^\Q$1\E$/,@userroles)) {
2810: push(@userroles,$1);
2811: }
1.206 raeburn 2812: }
1.220 raeburn 2813: } elsif ($context eq 'course') {
2814: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2815: if (!grep(/^\Q$1\E$/,@userroles)) {
2816: push(@userroles,$1);
2817: }
2818: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
2819: if (!grep(/^\Q$1\E$/,@userroles)) {
2820: push(@userroles,$1);
2821: }
1.206 raeburn 2822: }
2823: }
2824: }
2825: }
2826: }
2827: #Check to see if we can change personal data for the user
2828: my (@mod_disallowed,@longroles);
2829: foreach my $role (@userroles) {
2830: if ($role eq 'cr') {
2831: push(@longroles,'Custom');
2832: } else {
1.318 raeburn 2833: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 2834: }
2835: }
1.219 raeburn 2836: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
2837: foreach my $item (@userinfo) {
1.28 matthew 2838: # Strip leading and trailing whitespace
1.203 raeburn 2839: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 2840: if (!$canmodify{$item}) {
1.207 raeburn 2841: if (defined($env{'form.c'.$item})) {
2842: if ($env{'form.c'.$item} ne $userenv{$item}) {
2843: push(@mod_disallowed,$item);
2844: }
1.206 raeburn 2845: }
2846: $env{'form.c'.$item} = $userenv{$item};
2847: }
1.28 matthew 2848: }
1.259 bisitz 2849: # Check to see if we can change the Student/Employee ID
1.196 raeburn 2850: my $forceid = $env{'form.forceid'};
2851: my $recurseid = $env{'form.recurseid'};
2852: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 2853: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
2854: $env{'form.ccuname'});
2855: if (($uidhash{$env{'form.ccuname'}}) &&
2856: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
2857: (!$forceid)) {
2858: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
2859: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 2860: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 2861: .'<br />'
2862: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
2863: .'<br />'."\n";
1.203 raeburn 2864: }
2865: }
2866: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 2867: my $checkhash;
2868: my $checks = { 'id' => 1 };
2869: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
2870: { 'newuser' => $newuser,
2871: 'id' => $env{'form.cid'},
2872: };
2873: &Apache::loncommon::user_rule_check($checkhash,$checks,
2874: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
2875: if (ref($alerts{'id'}) eq 'HASH') {
2876: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 2877: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 2878: }
2879: }
2880: }
1.378 raeburn 2881: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
2882: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 2883: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 2884: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 2885: @disporder = ('inststatus');
2886: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 2887: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 2888: } else {
2889: push(@disporder,'reqcrsotherdom');
2890: }
2891: push(@disporder,('quota','tools'));
1.338 raeburn 2892: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 2893: foreach my $name ('portfolio','author') {
2894: ($olddefquota{$name},$oldsettingstatus{$name}) =
2895: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
2896: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
2897: }
1.334 raeburn 2898: my %canshow;
1.220 raeburn 2899: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 2900: $canshow{'quota'} = 1;
1.220 raeburn 2901: }
1.267 raeburn 2902: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 2903: $canshow{'tools'} = 1;
1.267 raeburn 2904: }
1.275 raeburn 2905: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 2906: $canshow{'requestcourses'} = 1;
1.300 raeburn 2907: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 2908: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 2909: }
1.286 raeburn 2910: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 2911: $canshow{'inststatus'} = 1;
1.286 raeburn 2912: }
1.362 raeburn 2913: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
2914: $canshow{'requestauthor'} = 1;
2915: }
1.267 raeburn 2916: my (%changeHash,%changed);
1.286 raeburn 2917: if ($oldinststatus eq '') {
1.334 raeburn 2918: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 2919: } else {
2920: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2921: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2922: } else {
1.334 raeburn 2923: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2924: }
2925: }
2926: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 2927: if ($canmodify_status{'inststatus'}) {
2928: $canshow{'inststatus'} = 1;
1.286 raeburn 2929: if (exists($env{'form.inststatus'})) {
2930: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2931: if (@inststatuses > 0) {
2932: $newinststatus = join(':',map { &escape($_); } @inststatuses);
2933: $changeHash{'inststatus'} = $newinststatus;
2934: if ($newinststatus ne $oldinststatus) {
2935: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 2936: foreach my $name ('portfolio','author') {
2937: ($newdefquota{$name},$newsettingstatus{$name}) =
2938: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
2939: }
1.286 raeburn 2940: }
2941: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2942: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 2943: } else {
1.337 raeburn 2944: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 2945: }
1.334 raeburn 2946: }
2947: } else {
2948: $newinststatus = '';
2949: $changeHash{'inststatus'} = $newinststatus;
2950: $newsettings{'inststatus'} = $othertitle;
2951: if ($newinststatus ne $oldinststatus) {
2952: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 2953: foreach my $name ('portfolio','author') {
2954: ($newdefquota{$name},$newsettingstatus{$name}) =
2955: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
2956: }
1.286 raeburn 2957: }
2958: }
1.334 raeburn 2959: } elsif ($context ne 'selfcreate') {
2960: $canshow{'inststatus'} = 1;
1.337 raeburn 2961: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 2962: }
1.378 raeburn 2963: foreach my $name ('portfolio','author') {
2964: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
2965: }
1.334 raeburn 2966: if ($context eq 'domain') {
1.378 raeburn 2967: foreach my $name ('portfolio','author') {
2968: if ($userenv{$name.'quota'} ne '') {
2969: $oldquota{$name} = $userenv{$name.'quota'};
2970: if ($env{'form.custom_'.$name.'quota'} == 1) {
2971: if ($env{'form.'.$name.'quota'} eq '') {
2972: $newquota{$name} = 0;
2973: } else {
2974: $newquota{$name} = $env{'form.'.$name.'quota'};
2975: $newquota{$name} =~ s/[^\d\.]//g;
2976: }
2977: if ($newquota{$name} != $oldquota{$name}) {
2978: if ("a_admin($newquota{$name},\%changeHash,$name)) {
2979: $changed{$name.'quota'} = 1;
2980: }
2981: }
1.334 raeburn 2982: } else {
1.378 raeburn 2983: if ("a_admin('',\%changeHash,$name)) {
2984: $changed{$name.'quota'} = 1;
2985: $newquota{$name} = $newdefquota{$name};
2986: $newisdefault{$name} = 1;
2987: }
1.334 raeburn 2988: }
1.149 raeburn 2989: } else {
1.378 raeburn 2990: $oldisdefault{$name} = 1;
2991: $oldquota{$name} = $olddefquota{$name};
2992: if ($env{'form.custom_'.$name.'quota'} == 1) {
2993: if ($env{'form.'.$name.'quota'} eq '') {
2994: $newquota{$name} = 0;
2995: } else {
2996: $newquota{$name} = $env{'form.'.$name.'quota'};
2997: $newquota{$name} =~ s/[^\d\.]//g;
2998: }
2999: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3000: $changed{$name.'quota'} = 1;
3001: }
1.334 raeburn 3002: } else {
1.378 raeburn 3003: $newquota{$name} = $newdefquota{$name};
3004: $newisdefault{$name} = 1;
1.334 raeburn 3005: }
1.378 raeburn 3006: }
3007: if ($oldisdefault{$name}) {
3008: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3009: } else {
3010: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3011: }
3012: if ($newisdefault{$name}) {
3013: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3014: } else {
3015: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3016: }
3017: }
1.334 raeburn 3018: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3019: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3020: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3021: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3022: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3023: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3024: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3025: } else {
1.334 raeburn 3026: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3027: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3028: }
3029: }
1.334 raeburn 3030: foreach my $item (@userinfo) {
3031: if ($env{'form.c'.$item} ne $userenv{$item}) {
3032: $namechanged{$item} = 1;
3033: }
1.204 raeburn 3034: }
1.378 raeburn 3035: foreach my $name ('portfolio','author') {
1.390 bisitz 3036: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3037: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3038: }
1.334 raeburn 3039: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3040: my ($chgresult,$namechgresult);
3041: if (keys(%changed) > 0) {
3042: $chgresult =
1.204 raeburn 3043: &Apache::lonnet::put('environment',\%changeHash,
3044: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3045: if ($chgresult eq 'ok') {
3046: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3047: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3048: my %newenvhash;
3049: foreach my $key (keys(%changed)) {
1.299 raeburn 3050: if (($key eq 'official') || ($key eq 'unofficial')
3051: || ($key eq 'community')) {
1.279 raeburn 3052: $newenvhash{'environment.requestcourses.'.$key} =
3053: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3054: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3055: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3056: } else {
3057: $newenvhash{'environment.canrequest.'.$key} =
3058: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3059: $key,'reload','requestcourses');
3060: }
1.362 raeburn 3061: } elsif ($key eq 'requestauthor') {
3062: $newenvhash{'environment.'.$key} = $changeHash{$key};
3063: if ($changeHash{$key}) {
3064: $newenvhash{'environment.canrequest.author'} = 1;
3065: } else {
3066: $newenvhash{'environment.canrequest.author'} =
3067: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3068: $key,'reload','requestauthor');
3069: }
1.275 raeburn 3070: } elsif ($key ne 'quota') {
1.270 raeburn 3071: $newenvhash{'environment.tools.'.$key} =
3072: $changeHash{'tools.'.$key};
1.279 raeburn 3073: if ($changeHash{'tools.'.$key} ne '') {
3074: $newenvhash{'environment.availabletools.'.$key} =
3075: $changeHash{'tools.'.$key};
3076: } else {
3077: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3078: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3079: $key,'reload','tools');
1.279 raeburn 3080: }
1.270 raeburn 3081: }
3082: }
1.271 raeburn 3083: if (keys(%newenvhash)) {
3084: &Apache::lonnet::appenv(\%newenvhash);
3085: }
1.267 raeburn 3086: }
3087: }
1.204 raeburn 3088: }
1.334 raeburn 3089: if (keys(%namechanged) > 0) {
1.337 raeburn 3090: foreach my $field (@userinfo) {
3091: $changeHash{$field} = $env{'form.c'.$field};
3092: }
3093: # Make the change
1.204 raeburn 3094: $namechgresult =
3095: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3096: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3097: $changeHash{'firstname'},$changeHash{'middlename'},
3098: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3099: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3100: %userupdate = (
3101: lastname => $env{'form.clastname'},
3102: middlename => $env{'form.cmiddlename'},
3103: firstname => $env{'form.cfirstname'},
3104: generation => $env{'form.cgeneration'},
3105: id => $env{'form.cid'},
3106: );
1.204 raeburn 3107: }
1.334 raeburn 3108: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3109: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3110: # Tell the user we changed the name
1.334 raeburn 3111: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3112: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3113: \%oldsettings, \%oldsettingstext,\%newsettings,
3114: \%newsettingstext);
1.203 raeburn 3115: if ($env{'form.cid'} ne $userenv{'id'}) {
3116: &Apache::lonnet::idput($env{'form.ccdomain'},
3117: ($env{'form.ccuname'} => $env{'form.cid'}));
3118: if (($recurseid) &&
3119: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3120: my $idresult =
3121: &Apache::lonuserutils::propagate_id_change(
3122: $env{'form.ccuname'},$env{'form.ccdomain'},
3123: \%userupdate);
3124: $r->print('<br />'.$idresult.'<br />');
3125: }
1.196 raeburn 3126: }
1.149 raeburn 3127: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3128: ($env{'form.ccuname'} eq $env{'user.name'})) {
3129: my %newenvhash;
3130: foreach my $key (keys(%changeHash)) {
3131: $newenvhash{'environment.'.$key} = $changeHash{$key};
3132: }
1.238 raeburn 3133: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3134: }
1.28 matthew 3135: } else { # error occurred
1.389 bisitz 3136: $r->print(
3137: '<p class="LC_error">'
3138: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3139: '"'.$env{'form.ccuname'}.'"',
3140: '"'.$env{'form.ccdomain'}.'"')
3141: .'</p>');
1.28 matthew 3142: }
1.334 raeburn 3143: } else { # End of if ($env ... ) logic
1.275 raeburn 3144: # They did not want to change the users name, quota, tool availability,
3145: # or ability to request creation of courses,
1.267 raeburn 3146: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3147: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3148: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3149: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3150: }
1.206 raeburn 3151: if (@mod_disallowed) {
3152: my ($rolestr,$contextname);
3153: if (@longroles > 0) {
3154: $rolestr = join(', ',@longroles);
3155: } else {
3156: $rolestr = &mt('No roles');
3157: }
3158: if ($context eq 'course') {
1.399 bisitz 3159: $contextname = 'course';
1.206 raeburn 3160: } elsif ($context eq 'author') {
1.399 bisitz 3161: $contextname = 'co-author';
1.206 raeburn 3162: }
3163: $r->print(&mt('The following fields were not updated: ').'<ul>');
3164: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3165: foreach my $field (@mod_disallowed) {
3166: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3167: }
1.207 raeburn 3168: $r->print('</ul>');
3169: if (@mod_disallowed == 1) {
1.399 bisitz 3170: $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 3171: } else {
1.399 bisitz 3172: $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 3173: }
1.292 bisitz 3174: my $helplink = 'javascript:helpMenu('."'display'".')';
3175: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3176: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3177: ,'<a href="'.$helplink.'">','</a>')
3178: .'<br />');
1.206 raeburn 3179: }
1.259 bisitz 3180: $r->print('<span class="LC_warning">'
3181: .$no_forceid_alert
3182: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3183: .'</span>');
1.4 www 3184: }
1.367 golterma 3185: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3186: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3187: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3188: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3189: my $linktext = ($crstype eq 'Community' ?
3190: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3191: $r->print(
3192: &Apache::lonhtmlcommon::actionbox([
3193: '<a href="javascript:backPage(document.userupdate)">'
3194: .($crstype eq 'Community' ?
3195: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3196: .'</a>']));
1.220 raeburn 3197: } else {
1.375 raeburn 3198: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3199: if (keys(%namechanged) > 0) {
1.220 raeburn 3200: if ($context eq 'course') {
3201: if (@userroles > 0) {
1.225 raeburn 3202: if ((@rolechanges == 0) ||
3203: (!(grep(/^st$/,@rolechanges)))) {
3204: if (grep(/^st$/,@userroles)) {
3205: my $classlistupdated =
3206: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3207: $cnum,$env{'form.ccdomain'},
3208: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3209: }
1.220 raeburn 3210: }
3211: }
3212: }
3213: }
1.226 raeburn 3214: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3215: $env{'form.ccdomain'});
3216: if ($env{'form.popup'}) {
3217: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3218: } else {
1.367 golterma 3219: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3220: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3221: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3222: }
1.220 raeburn 3223: }
3224: }
3225:
1.334 raeburn 3226: sub display_userinfo {
1.362 raeburn 3227: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3228: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3229: $newsetting,$newsettingtext) = @_;
3230: return unless (ref($order) eq 'ARRAY' &&
3231: ref($canshow) eq 'HASH' &&
3232: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3233: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3234: ref($usertools) eq 'ARRAY' &&
3235: ref($userenv) eq 'HASH' &&
3236: ref($changedhash) eq 'HASH' &&
3237: ref($oldsetting) eq 'HASH' &&
3238: ref($oldsettingtext) eq 'HASH' &&
3239: ref($newsetting) eq 'HASH' &&
3240: ref($newsettingtext) eq 'HASH');
3241: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3242: 'ui' => 'User Information',
1.334 raeburn 3243: 'uic' => 'User Information Changed',
3244: 'firstname' => 'First Name',
3245: 'middlename' => 'Middle Name',
3246: 'lastname' => 'Last Name',
3247: 'generation' => 'Generation',
3248: 'id' => 'Student/Employee ID',
3249: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3250: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3251: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3252: 'blog' => 'Blog Availability',
1.361 raeburn 3253: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3254: 'aboutme' => 'Personal Information Page Availability',
3255: 'portfolio' => 'Portfolio Availability',
3256: 'official' => 'Can Request Official Courses',
3257: 'unofficial' => 'Can Request Unofficial Courses',
3258: 'community' => 'Can Request Communities',
1.384 raeburn 3259: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 3260: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3261: 'inststatus' => "Affiliation",
3262: 'prvs' => 'Previous Value:',
3263: 'chto' => 'Changed To:'
3264: );
3265: if ($changed) {
1.372 raeburn 3266: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3267: &Apache::loncommon::start_data_table().
3268: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3269: $r->print("<th> </th>\n");
1.367 golterma 3270: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3271: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3272: $r->print(&Apache::loncommon::end_data_table_header_row());
3273: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3274:
1.334 raeburn 3275: foreach my $item (@userinfo) {
3276: my $value = $env{'form.c'.$item};
1.367 golterma 3277: #show changes only:
1.383 raeburn 3278: unless ($value eq $userenv->{$item}){
1.367 golterma 3279: $r->print(&Apache::loncommon::start_data_table_row());
3280: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3281: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3282: $r->print("<td>$value </td>\n");
3283: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3284: }
3285: }
3286: foreach my $entry (@{$order}) {
1.383 raeburn 3287: if ($canshow->{$entry}) {
3288: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3289: my @items;
3290: if ($entry eq 'requestauthor') {
3291: @items = ($entry);
3292: } else {
3293: @items = @{$requestcourses};
1.384 raeburn 3294: }
1.383 raeburn 3295: foreach my $item (@items) {
3296: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3297: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3298: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3299: $r->print("<td>$lt{$item}</td>\n");
3300: $r->print("<td>".$oldsetting->{$item});
3301: if ($oldsettingtext->{$item}) {
3302: if ($oldsetting->{$item}) {
3303: $r->print(' -- ');
3304: }
3305: $r->print($oldsettingtext->{$item});
3306: }
3307: $r->print("</td>\n");
3308: $r->print("<td>".$newsetting->{$item});
3309: if ($newsettingtext->{$item}) {
3310: if ($newsetting->{$item}) {
3311: $r->print(' -- ');
3312: }
3313: $r->print($newsettingtext->{$item});
3314: }
3315: $r->print("</td>\n");
3316: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3317: }
3318: }
3319: } elsif ($entry eq 'tools') {
3320: foreach my $item (@{$usertools}) {
1.383 raeburn 3321: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3322: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3323: $r->print("<td>$lt{$item}</td>\n");
3324: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3325: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3326: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3327: }
3328: }
1.378 raeburn 3329: } elsif ($entry eq 'quota') {
3330: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3331: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3332: foreach my $name ('portfolio','author') {
1.383 raeburn 3333: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3334: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3335: $r->print("<td>$lt{$name.$entry}</td>\n");
3336: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3337: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3338: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3339: }
3340: }
3341: }
1.334 raeburn 3342: } else {
1.383 raeburn 3343: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3344: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3345: $r->print("<td>$lt{$entry}</td>\n");
3346: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3347: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3348: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3349: }
3350: }
3351: }
3352: }
1.367 golterma 3353: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3354: } else {
3355: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3356: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3357: }
3358: return;
3359: }
3360:
1.275 raeburn 3361: sub tool_changes {
3362: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3363: $changed,$newaccess,$newaccesstext) = @_;
3364: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3365: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3366: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3367: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3368: return;
3369: }
1.383 raeburn 3370: my %reqdisplay = &requestchange_display();
1.300 raeburn 3371: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3372: my @options = ('approval','validate','autolimit');
1.306 raeburn 3373: my $optregex = join('|',@options);
1.300 raeburn 3374: my $cdom = $env{'request.role.domain'};
3375: foreach my $tool (@{$usertools}) {
1.383 raeburn 3376: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3377: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3378: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3379: my ($newop,$limit);
1.314 raeburn 3380: if ($env{'form.'.$context.'_'.$tool}) {
3381: $newop = $env{'form.'.$context.'_'.$tool};
3382: if ($newop eq 'autolimit') {
1.383 raeburn 3383: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3384: $limit =~ s/\D+//g;
3385: $newop .= '='.$limit;
3386: }
3387: }
1.300 raeburn 3388: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3389: if ($newop) {
3390: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3391: $changeHash,$context);
3392: if ($changed->{$tool}) {
1.383 raeburn 3393: if ($newop =~ /^autolimit/) {
3394: if ($limit) {
3395: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3396: } else {
3397: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3398: }
3399: } else {
3400: $newaccesstext->{$tool} = $reqdisplay{$newop};
3401: }
1.300 raeburn 3402: } else {
3403: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3404: }
3405: }
3406: } else {
3407: my @curr = split(',',$userenv->{$context.'.'.$tool});
3408: my @new;
3409: my $changedoms;
1.314 raeburn 3410: foreach my $req (@curr) {
3411: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3412: my $oldop = $1;
1.383 raeburn 3413: if ($oldop =~ /^autolimit=(\d*)/) {
3414: my $limit = $1;
3415: if ($limit) {
3416: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3417: } else {
3418: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3419: }
3420: } else {
3421: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3422: }
1.314 raeburn 3423: if ($oldop ne $newop) {
3424: $changedoms = 1;
3425: foreach my $item (@curr) {
3426: my ($reqdom,$option) = split(':',$item);
3427: unless ($reqdom eq $cdom) {
3428: push(@new,$item);
3429: }
3430: }
3431: if ($newop) {
3432: push(@new,$cdom.':'.$newop);
1.300 raeburn 3433: }
1.314 raeburn 3434: @new = sort(@new);
1.300 raeburn 3435: }
1.314 raeburn 3436: last;
1.300 raeburn 3437: }
1.314 raeburn 3438: }
3439: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3440: $changedoms = 1;
1.306 raeburn 3441: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3442: }
3443: if ($changedoms) {
1.314 raeburn 3444: my $newdomstr;
1.300 raeburn 3445: if (@new) {
3446: $newdomstr = join(',',@new);
3447: }
3448: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3449: $context);
3450: if ($changed->{$tool}) {
3451: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3452: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3453: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3454: $limit =~ s/\D+//g;
3455: if ($limit) {
1.383 raeburn 3456: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3457: } else {
1.383 raeburn 3458: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3459: }
1.314 raeburn 3460: } else {
1.306 raeburn 3461: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3462: }
1.300 raeburn 3463: } else {
1.383 raeburn 3464: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3465: }
3466: }
3467: }
3468: }
3469: }
3470: return;
3471: }
1.275 raeburn 3472: foreach my $tool (@{$usertools}) {
1.383 raeburn 3473: my ($newval,$limit,$envkey);
1.362 raeburn 3474: $envkey = $context.'.'.$tool;
1.306 raeburn 3475: if ($context eq 'requestcourses') {
3476: $newval = $env{'form.crsreq_'.$tool};
3477: if ($newval eq 'autolimit') {
1.383 raeburn 3478: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3479: $limit =~ s/\D+//g;
3480: $newval .= '='.$limit;
1.306 raeburn 3481: }
1.362 raeburn 3482: } elsif ($context eq 'requestauthor') {
3483: $newval = $env{'form.'.$context};
3484: $envkey = $context;
1.314 raeburn 3485: } else {
1.306 raeburn 3486: $newval = $env{'form.'.$context.'_'.$tool};
3487: }
1.362 raeburn 3488: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3489: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3490: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3491: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3492: my $currlimit = $1;
3493: if ($currlimit eq '') {
3494: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3495: } else {
3496: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3497: }
3498: } elsif ($userenv->{$envkey}) {
3499: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3500: } else {
3501: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3502: }
1.275 raeburn 3503: } else {
1.383 raeburn 3504: if ($userenv->{$envkey}) {
3505: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3506: } else {
3507: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3508: }
1.275 raeburn 3509: }
1.362 raeburn 3510: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3511: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3512: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3513: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3514: $context);
1.275 raeburn 3515: if ($changed->{$tool}) {
3516: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3517: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3518: if ($newval =~ /^autolimit/) {
3519: if ($limit) {
3520: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3521: } else {
3522: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3523: }
3524: } elsif ($newval) {
3525: $newaccesstext->{$tool} = $reqdisplay{$newval};
3526: } else {
3527: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3528: }
1.275 raeburn 3529: } else {
1.383 raeburn 3530: if ($newval) {
3531: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3532: } else {
3533: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3534: }
1.275 raeburn 3535: }
3536: } else {
3537: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3538: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3539: if ($newval =~ /^autolimit/) {
3540: if ($limit) {
3541: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3542: } else {
3543: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3544: }
3545: } elsif ($newval) {
3546: $newaccesstext->{$tool} = $reqdisplay{$newval};
3547: } else {
3548: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3549: }
1.275 raeburn 3550: } else {
1.383 raeburn 3551: if ($userenv->{$context.'.'.$tool}) {
3552: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3553: } else {
3554: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3555: }
1.275 raeburn 3556: }
3557: }
3558: } else {
3559: $newaccess->{$tool} = $oldaccess->{$tool};
3560: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3561: }
3562: } else {
3563: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3564: if ($changed->{$tool}) {
3565: $newaccess->{$tool} = &mt('default');
3566: } else {
3567: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3568: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3569: if ($newval =~ /^autolimit/) {
3570: if ($limit) {
3571: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3572: } else {
3573: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3574: }
3575: } elsif ($newval) {
3576: $newaccesstext->{$tool} = $reqdisplay{$newval};
3577: } else {
3578: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3579: }
1.275 raeburn 3580: } else {
1.383 raeburn 3581: if ($userenv->{$context.'.'.$tool}) {
3582: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3583: } else {
3584: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3585: }
1.275 raeburn 3586: }
3587: }
3588: }
3589: } else {
3590: $oldaccess->{$tool} = &mt('default');
3591: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3592: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3593: $context);
1.275 raeburn 3594: if ($changed->{$tool}) {
3595: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3596: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3597: if ($newval =~ /^autolimit/) {
3598: if ($limit) {
3599: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3600: } else {
3601: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3602: }
3603: } elsif ($newval) {
3604: $newaccesstext->{$tool} = $reqdisplay{$newval};
3605: } else {
3606: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3607: }
1.275 raeburn 3608: } else {
1.383 raeburn 3609: if ($newval) {
3610: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3611: } else {
3612: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3613: }
1.275 raeburn 3614: }
3615: } else {
3616: $newaccess->{$tool} = $oldaccess->{$tool};
3617: }
3618: } else {
3619: $newaccess->{$tool} = $oldaccess->{$tool};
3620: }
3621: }
3622: }
3623: return;
3624: }
3625:
1.220 raeburn 3626: sub update_roles {
1.375 raeburn 3627: my ($r,$context,$showcredits) = @_;
1.4 www 3628: my $now=time;
1.225 raeburn 3629: my @rolechanges;
1.220 raeburn 3630: my %disallowed;
1.73 sakharuk 3631: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 3632: foreach my $key (keys (%env)) {
3633: next if (! $env{$key});
1.190 raeburn 3634: next if ($key eq 'form.action');
1.27 matthew 3635: # Revoke roles
1.135 raeburn 3636: if ($key=~/^form\.rev/) {
3637: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3638: # Revoke standard role
1.170 albertel 3639: my ($scope,$role) = ($1,$2);
3640: my $result =
3641: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3642: $env{'form.ccuname'},
1.239 raeburn 3643: $scope,$role,'','',$context);
1.367 golterma 3644: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3645: &mt('Revoking [_1] in [_2]',
3646: &Apache::lonnet::plaintext($role),
1.372 raeburn 3647: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3648: $result ne "ok").'<br />');
3649: if ($result ne "ok") {
3650: $r->print(&mt('Error: [_1]',$result).'<br />');
3651: }
1.170 albertel 3652: if ($role eq 'st') {
1.202 raeburn 3653: my $result =
1.198 raeburn 3654: &Apache::lonuserutils::classlist_drop($scope,
3655: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3656: $now);
1.367 golterma 3657: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3658: }
1.225 raeburn 3659: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3660: push(@rolechanges,$role);
3661: }
1.196 raeburn 3662: }
1.195 raeburn 3663: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3664: # Revoke custom role
1.369 bisitz 3665: my $result = &Apache::lonnet::revokecustomrole(
3666: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3667: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3668: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3669: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3670: $result ne 'ok').'<br />');
3671: if ($result ne "ok") {
3672: $r->print(&mt('Error: [_1]',$result).'<br />');
3673: }
1.225 raeburn 3674: if (!grep(/^cr$/,@rolechanges)) {
3675: push(@rolechanges,'cr');
3676: }
1.64 www 3677: }
1.135 raeburn 3678: } elsif ($key=~/^form\.del/) {
3679: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3680: # Delete standard role
1.170 albertel 3681: my ($scope,$role) = ($1,$2);
3682: my $result =
3683: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3684: $env{'form.ccuname'},
1.239 raeburn 3685: $scope,$role,$now,0,1,'',
3686: $context);
1.367 golterma 3687: $r->print(&Apache::lonhtmlcommon::confirm_success(
3688: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3689: &Apache::lonnet::plaintext($role),
1.372 raeburn 3690: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3691: $result ne 'ok').'<br />');
3692: if ($result ne "ok") {
3693: $r->print(&mt('Error: [_1]',$result).'<br />');
3694: }
1.367 golterma 3695:
1.170 albertel 3696: if ($role eq 'st') {
1.202 raeburn 3697: my $result =
1.198 raeburn 3698: &Apache::lonuserutils::classlist_drop($scope,
3699: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3700: $now);
1.369 bisitz 3701: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3702: }
1.225 raeburn 3703: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3704: push(@rolechanges,$role);
3705: }
1.116 raeburn 3706: }
1.139 albertel 3707: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3708: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3709: # Delete custom role
1.369 bisitz 3710: my $result =
3711: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3712: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3713: 0,1,$context);
3714: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3715: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3716: $result ne "ok").'<br />');
3717: if ($result ne "ok") {
3718: $r->print(&mt('Error: [_1]',$result).'<br />');
3719: }
1.367 golterma 3720:
1.225 raeburn 3721: if (!grep(/^cr$/,@rolechanges)) {
3722: push(@rolechanges,'cr');
3723: }
1.116 raeburn 3724: }
1.135 raeburn 3725: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3726: my $udom = $env{'form.ccdomain'};
3727: my $uname = $env{'form.ccuname'};
1.116 raeburn 3728: # Re-enable standard role
1.135 raeburn 3729: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3730: my $url = $1;
3731: my $role = $2;
3732: my $logmsg;
3733: my $output;
3734: if ($role eq 'st') {
1.141 albertel 3735: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3736: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3737: my $credits;
3738: if ($showcredits) {
3739: my $defaultcredits =
3740: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3741: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3742: }
3743: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3744: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3745: if ($result eq 'refused' && $logmsg) {
3746: $output = $logmsg;
3747: } else {
1.369 bisitz 3748: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3749: }
1.89 raeburn 3750: } else {
1.372 raeburn 3751: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3752: &Apache::lonnet::plaintext($role),
3753: &Apache::loncommon::show_role_extent($url,$context,'st'),
3754: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3755: }
3756: }
3757: } else {
1.101 albertel 3758: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3759: $env{'form.ccuname'},$url,$role,0,$now,'','',
3760: $context);
1.367 golterma 3761: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3762: &Apache::lonnet::plaintext($role),
3763: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3764: if ($result ne "ok") {
3765: $output .= &mt('Error: [_1]',$result).'<br />';
3766: }
3767: }
1.89 raeburn 3768: $r->print($output);
1.225 raeburn 3769: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3770: push(@rolechanges,$role);
3771: }
1.113 raeburn 3772: }
1.116 raeburn 3773: # Re-enable custom role
1.139 albertel 3774: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3775: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3776: my $result = &Apache::lonnet::assigncustomrole(
3777: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3778: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3779: $r->print(&Apache::lonhtmlcommon::confirm_success(
3780: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 3781: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3782: $result ne "ok").'<br />');
3783: if ($result ne "ok") {
3784: $r->print(&mt('Error: [_1]',$result).'<br />');
3785: }
1.225 raeburn 3786: if (!grep(/^cr$/,@rolechanges)) {
3787: push(@rolechanges,'cr');
3788: }
1.116 raeburn 3789: }
1.135 raeburn 3790: } elsif ($key=~/^form\.act/) {
1.101 albertel 3791: my $udom = $env{'form.ccdomain'};
3792: my $uname = $env{'form.ccuname'};
1.141 albertel 3793: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3794: # Activate a custom role
1.83 albertel 3795: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3796: my $url='/'.$one.'/'.$two;
3797: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3798:
1.101 albertel 3799: my $start = ( $env{'form.start_'.$full} ?
3800: $env{'form.start_'.$full} :
1.88 raeburn 3801: $now );
1.101 albertel 3802: my $end = ( $env{'form.end_'.$full} ?
3803: $env{'form.end_'.$full} :
1.88 raeburn 3804: 0 );
3805:
3806: # split multiple sections
3807: my %sections = ();
1.101 albertel 3808: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3809: if ($num_sections == 0) {
1.240 raeburn 3810: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3811: } else {
1.114 albertel 3812: my %curr_groups =
1.117 raeburn 3813: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 3814: foreach my $sec (sort {$a cmp $b} keys %sections) {
3815: if (($sec eq 'none') || ($sec eq 'all') ||
3816: exists($curr_groups{$sec})) {
3817: $disallowed{$sec} = $url;
3818: next;
3819: }
3820: my $securl = $url.'/'.$sec;
1.240 raeburn 3821: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3822: }
3823: }
1.225 raeburn 3824: if (!grep(/^cr$/,@rolechanges)) {
3825: push(@rolechanges,'cr');
3826: }
1.142 raeburn 3827: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 3828: # Activate roles for sections with 3 id numbers
3829: # set start, end times, and the url for the class
1.83 albertel 3830: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 3831: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
3832: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3833: $now );
1.101 albertel 3834: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
3835: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3836: 0 );
1.83 albertel 3837: my $url='/'.$one.'/'.$two;
1.88 raeburn 3838: my $type = 'three';
3839: # split multiple sections
3840: my %sections = ();
1.101 albertel 3841: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 3842: my $credits;
3843: if ($three eq 'st') {
3844: if ($showcredits) {
3845: my $defaultcredits =
3846: &Apache::lonuserutils::get_defaultcredits($one,$two);
3847: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
3848: $credits =~ s/[^\d\.]//g;
3849: if ($credits eq $defaultcredits) {
3850: undef($credits);
3851: }
3852: }
3853: }
1.88 raeburn 3854: if ($num_sections == 0) {
1.375 raeburn 3855: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 3856: } else {
1.114 albertel 3857: my %curr_groups =
1.117 raeburn 3858: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 3859: my $emptysec = 0;
3860: foreach my $sec (sort {$a cmp $b} keys %sections) {
3861: $sec =~ s/\W//g;
1.113 raeburn 3862: if ($sec ne '') {
3863: if (($sec eq 'none') || ($sec eq 'all') ||
3864: exists($curr_groups{$sec})) {
3865: $disallowed{$sec} = $url;
3866: next;
3867: }
1.88 raeburn 3868: my $securl = $url.'/'.$sec;
1.375 raeburn 3869: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 3870: } else {
3871: $emptysec = 1;
3872: }
3873: }
3874: if ($emptysec) {
1.375 raeburn 3875: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 3876: }
1.225 raeburn 3877: }
3878: if (!grep(/^\Q$three\E$/,@rolechanges)) {
3879: push(@rolechanges,$three);
3880: }
1.135 raeburn 3881: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 3882: # Activate roles for sections with two id numbers
3883: # set start, end times, and the url for the class
1.101 albertel 3884: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
3885: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 3886: $now );
1.101 albertel 3887: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
3888: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 3889: 0 );
1.225 raeburn 3890: my $one = $1;
3891: my $two = $2;
3892: my $url='/'.$one.'/';
1.88 raeburn 3893: # split multiple sections
3894: my %sections = ();
1.225 raeburn 3895: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 3896: if ($num_sections == 0) {
1.240 raeburn 3897: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3898: } else {
3899: my $emptysec = 0;
3900: foreach my $sec (sort {$a cmp $b} keys %sections) {
3901: if ($sec ne '') {
3902: my $securl = $url.'/'.$sec;
1.240 raeburn 3903: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 3904: } else {
3905: $emptysec = 1;
3906: }
3907: }
3908: if ($emptysec) {
1.240 raeburn 3909: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3910: }
3911: }
1.225 raeburn 3912: if (!grep(/^\Q$two\E$/,@rolechanges)) {
3913: push(@rolechanges,$two);
3914: }
1.64 www 3915: } else {
1.190 raeburn 3916: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 3917: }
1.113 raeburn 3918: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 3919: $r->print('<p class="LC_warning">');
1.113 raeburn 3920: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 3921: $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 3922: } else {
1.274 bisitz 3923: $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 3924: }
1.274 bisitz 3925: $r->print('</p><p>'
3926: .&mt('Please [_1]go back[_2] and choose a different section name.'
3927: ,'<a href="javascript:history.go(-1)'
3928: ,'</a>')
3929: .'</p><br />'
3930: );
1.113 raeburn 3931: }
3932: }
1.101 albertel 3933: } # End of foreach (keys(%env))
1.75 www 3934: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 3935: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 3936: if (@rolechanges == 0) {
1.372 raeburn 3937: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 3938: }
1.225 raeburn 3939: return @rolechanges;
1.220 raeburn 3940: }
3941:
1.375 raeburn 3942: sub get_user_credits {
3943: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
3944: if ($cdom eq '' || $cnum eq '') {
3945: return unless ($env{'request.course.id'});
3946: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3947: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3948: }
3949: my $credits;
3950: my %currhash =
3951: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
3952: if (keys(%currhash) > 0) {
3953: my @items = split(/:/,$currhash{$uname.':'.$udom});
3954: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
3955: $credits = $items[$crdidx];
3956: $credits =~ s/[^\d\.]//g;
3957: }
3958: if ($credits eq $defaultcredits) {
3959: undef($credits);
3960: }
3961: return $credits;
3962: }
3963:
1.220 raeburn 3964: sub enroll_single_student {
1.375 raeburn 3965: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
3966: $showcredits,$defaultcredits) = @_;
1.318 raeburn 3967: $r->print('<h3>');
3968: if ($crstype eq 'Community') {
3969: $r->print(&mt('Enrolling Member'));
3970: } else {
3971: $r->print(&mt('Enrolling Student'));
3972: }
3973: $r->print('</h3>');
1.220 raeburn 3974:
3975: # Remove non alphanumeric values from section
3976: $env{'form.sections'}=~s/\W//g;
3977:
1.375 raeburn 3978: my $credits;
3979: if (($showcredits) && ($env{'form.credits'} ne '')) {
3980: $credits = $env{'form.credits'};
3981: $credits =~ s/[^\d\.]//g;
3982: if ($credits ne '') {
3983: if ($credits eq $defaultcredits) {
3984: undef($credits);
3985: }
3986: }
3987: }
3988:
1.220 raeburn 3989: # Clean out any old student roles the user has in this class.
3990: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
3991: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
3992: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
3993: my $enroll_result =
3994: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
3995: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
3996: $env{'form.cmiddlename'},$env{'form.clastname'},
3997: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 3998: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
3999: $credits);
1.220 raeburn 4000: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4001: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4002: if ($env{'form.sections'} ne '') {
4003: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4004: }
4005: my ($showstart,$showend);
4006: if ($startdate <= $now) {
4007: $showstart = &mt('Access starts immediately');
4008: } else {
4009: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4010: }
4011: if ($enddate == 0) {
4012: $showend = &mt('ends: no ending date');
4013: } else {
4014: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4015: }
4016: $r->print('.<br />'.$showstart.'; '.$showend);
4017: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4018: $r->print('<p class="LC_info">');
1.318 raeburn 4019: if ($crstype eq 'Community') {
1.392 raeburn 4020: $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 4021: } else {
1.392 raeburn 4022: $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 4023: }
4024: $r->print('</p>');
1.220 raeburn 4025: }
4026: } else {
4027: $r->print(&mt('unable to enroll').": ".$enroll_result);
4028: }
4029: return;
1.188 raeburn 4030: }
4031:
1.204 raeburn 4032: sub get_defaultquota_text {
4033: my ($settingstatus) = @_;
4034: my $defquotatext;
4035: if ($settingstatus eq '') {
1.383 raeburn 4036: $defquotatext = &mt('default');
1.204 raeburn 4037: } else {
4038: my ($usertypes,$order) =
4039: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4040: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4041: $defquotatext = &mt('default');
1.204 raeburn 4042: } else {
1.383 raeburn 4043: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4044: }
4045: }
4046: return $defquotatext;
4047: }
4048:
1.188 raeburn 4049: sub update_result_form {
4050: my ($uhome) = @_;
4051: my $outcome =
1.367 golterma 4052: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4053: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4054: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4055: }
1.207 raeburn 4056: if ($env{'form.origname'} ne '') {
4057: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4058: }
1.160 raeburn 4059: foreach my $item ('sortby','seluname','seludom') {
4060: if (exists($env{'form.'.$item})) {
1.188 raeburn 4061: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4062: }
4063: }
1.188 raeburn 4064: if ($uhome eq 'no_host') {
4065: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4066: }
4067: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4068: '<input type="hidden" name="currstate" value="" />'."\n".
4069: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4070: '</form>';
4071: return $outcome;
1.4 www 4072: }
4073:
1.149 raeburn 4074: sub quota_admin {
1.378 raeburn 4075: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4076: my $quotachanged;
4077: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4078: # Current user has quota modification privileges
1.267 raeburn 4079: if (ref($changeHash) eq 'HASH') {
4080: $quotachanged = 1;
1.378 raeburn 4081: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4082: }
1.149 raeburn 4083: }
4084: return $quotachanged;
4085: }
4086:
1.267 raeburn 4087: sub tool_admin {
1.275 raeburn 4088: my ($tool,$settool,$changeHash,$context) = @_;
4089: my $canchange = 0;
1.279 raeburn 4090: if ($context eq 'requestcourses') {
1.275 raeburn 4091: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4092: $canchange = 1;
4093: }
1.300 raeburn 4094: } elsif ($context eq 'reqcrsotherdom') {
4095: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4096: $canchange = 1;
4097: }
1.362 raeburn 4098: } elsif ($context eq 'requestauthor') {
4099: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4100: $canchange = 1;
4101: }
1.275 raeburn 4102: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4103: # Current user has quota modification privileges
4104: $canchange = 1;
4105: }
1.267 raeburn 4106: my $toolchanged;
1.275 raeburn 4107: if ($canchange) {
1.267 raeburn 4108: if (ref($changeHash) eq 'HASH') {
4109: $toolchanged = 1;
1.362 raeburn 4110: if ($tool eq 'requestauthor') {
4111: $changeHash->{$context} = $settool;
4112: } else {
4113: $changeHash->{$context.'.'.$tool} = $settool;
4114: }
1.267 raeburn 4115: }
4116: }
4117: return $toolchanged;
4118: }
4119:
1.88 raeburn 4120: sub build_roles {
1.89 raeburn 4121: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4122: my $num_sections = 0;
4123: if ($sectionstr=~ /,/) {
4124: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4125: if ($role eq 'st') {
4126: $secnums[0] =~ s/\W//g;
4127: $$sections{$secnums[0]} = 1;
4128: $num_sections = 1;
4129: } else {
4130: foreach my $sec (@secnums) {
4131: $sec =~ ~s/\W//g;
1.150 banghart 4132: if (!($sec eq "")) {
1.89 raeburn 4133: if (exists($$sections{$sec})) {
4134: $$sections{$sec} ++;
4135: } else {
4136: $$sections{$sec} = 1;
4137: $num_sections ++;
4138: }
1.88 raeburn 4139: }
4140: }
4141: }
4142: } else {
4143: $sectionstr=~s/\W//g;
4144: unless ($sectionstr eq '') {
4145: $$sections{$sectionstr} = 1;
4146: $num_sections ++;
4147: }
4148: }
1.129 albertel 4149:
1.88 raeburn 4150: return $num_sections;
4151: }
4152:
1.58 www 4153: # ========================================================== Custom Role Editor
4154:
4155: sub custom_role_editor {
1.351 raeburn 4156: my ($r,$brcrum) = @_;
1.324 raeburn 4157: my $action = $env{'form.customroleaction'};
4158: my $rolename;
4159: if ($action eq 'new') {
4160: $rolename=$env{'form.newrolename'};
4161: } else {
4162: $rolename=$env{'form.rolename'};
1.59 www 4163: }
4164:
1.324 raeburn 4165: my ($crstype,$context);
4166: if ($env{'request.course.id'}) {
4167: $crstype = &Apache::loncommon::course_type();
4168: $context = 'course';
4169: } else {
4170: $context = 'domain';
4171: $crstype = $env{'form.templatecrstype'};
4172: }
1.351 raeburn 4173:
4174: $rolename=~s/[^A-Za-z0-9]//gs;
4175: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
4176: &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
4177: return;
4178: }
4179:
1.153 banghart 4180: # ------------------------------------------------------- What can be assigned?
4181: my %full=();
4182: my %courselevel=();
4183: my %courselevelcurrent=();
1.61 www 4184: my $syspriv='';
4185: my $dompriv='';
4186: my $coursepriv='';
1.153 banghart 4187: my $body_top;
1.393 raeburn 4188: my $newrole;
1.59 www 4189: my ($rdummy,$roledef)=
4190: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 4191: # ------------------------------------------------------- Does this role exist?
1.153 banghart 4192: $body_top .= '<h2>';
1.59 www 4193: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 4194: $body_top .= &mt('Existing Role').' "';
1.61 www 4195: # ------------------------------------------------- Get current role privileges
4196: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.324 raeburn 4197: if ($crstype eq 'Community') {
4198: $syspriv =~ s/bre\&S//;
4199: }
1.59 www 4200: } else {
1.393 raeburn 4201: $newrole = 1;
1.153 banghart 4202: $body_top .= &mt('New Role').' "';
1.59 www 4203: $roledef='';
4204: }
1.153 banghart 4205: $body_top .= $rolename.'"</h2>';
1.135 raeburn 4206: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4207: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4208: if (!$restrict) { $restrict='F'; }
1.60 www 4209: $courselevel{$priv}=$restrict;
1.61 www 4210: if ($coursepriv=~/\:$priv/) {
4211: $courselevelcurrent{$priv}=1;
4212: }
1.60 www 4213: $full{$priv}=1;
4214: }
4215: my %domainlevel=();
1.61 www 4216: my %domainlevelcurrent=();
1.135 raeburn 4217: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4218: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4219: if (!$restrict) { $restrict='F'; }
1.60 www 4220: $domainlevel{$priv}=$restrict;
1.61 www 4221: if ($dompriv=~/\:$priv/) {
4222: $domainlevelcurrent{$priv}=1;
4223: }
1.60 www 4224: $full{$priv}=1;
4225: }
1.61 www 4226: my %systemlevel=();
4227: my %systemlevelcurrent=();
1.135 raeburn 4228: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4229: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4230: if (!$restrict) { $restrict='F'; }
1.61 www 4231: $systemlevel{$priv}=$restrict;
4232: if ($syspriv=~/\:$priv/) {
4233: $systemlevelcurrent{$priv}=1;
4234: }
4235: $full{$priv}=1;
4236: }
1.160 raeburn 4237: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 4238: my $button_code = "\n";
1.153 banghart 4239: my $head_script = "\n";
1.301 bisitz 4240: $head_script .= '<script type="text/javascript">'."\n"
4241: .'// <![CDATA['."\n";
1.324 raeburn 4242: my @template_roles = ("in","ta","ep");
4243: if ($context eq 'domain') {
4244: push(@template_roles,"ad");
1.318 raeburn 4245: }
1.324 raeburn 4246: push(@template_roles,"st");
1.318 raeburn 4247: if ($crstype eq 'Community') {
4248: unshift(@template_roles,'co');
4249: } else {
4250: unshift(@template_roles,'cc');
4251: }
1.154 banghart 4252: foreach my $role (@template_roles) {
1.324 raeburn 4253: $head_script .= &make_script_template($role,$crstype);
1.318 raeburn 4254: $button_code .= &make_button_code($role,$crstype).' ';
1.154 banghart 4255: }
1.324 raeburn 4256: my $context_code;
4257: if ($context eq 'domain') {
4258: my $checkedCommunity = '';
4259: my $checkedCourse = ' checked="checked"';
4260: if ($env{'form.templatecrstype'} eq 'Community') {
4261: $checkedCommunity = $checkedCourse;
4262: $checkedCourse = '';
4263: }
4264: $context_code = '<label>'.
4265: '<input type="radio" name="templatecrstype" value="Course"'.$checkedCourse.' onclick="this.form.submit();">'.
4266: &mt('Course').
4267: '</label>'.(' ' x2).
4268: '<label>'.
4269: '<input type="radio" name="templatecrstype" value="Community"'.$checkedCommunity.' onclick="this.form.submit();">'.
4270: &mt('Community').
4271: '</label>'.
4272: '</fieldset>'.
4273: '<input type="hidden" name="customroleaction" value="'.
4274: $action.'" />';
4275: if ($env{'form.customroleaction'} eq 'new') {
4276: $context_code .= '<input type="hidden" name="newrolename" value="'.
4277: $rolename.'" />';
4278: } else {
4279: $context_code .= '<input type="hidden" name="rolename" value="'.
4280: $rolename.'" />';
4281: }
4282: $context_code .= '<input type="hidden" name="action" value="custom" />'.
4283: '<input type="hidden" name="phase" value="selected_custom_edit" />';
4284: }
4285:
1.301 bisitz 4286: $head_script .= "\n".$jsback."\n"
4287: .'// ]]>'."\n"
4288: .'</script>'."\n";
1.351 raeburn 4289: push (@{$brcrum},
4290: {href => "javascript:backPage(document.form1,'pickrole','')",
4291: text => "Pick custom role",
4292: faq => 282,bug=>'Instructor Interface',},
4293: {href => "javascript:backPage(document.form1,'','')",
4294: text => "Edit custom role",
4295: faq => 282,
4296: bug => 'Instructor Interface',
4297: help => 'Course_Editing_Custom_Roles'}
4298: );
4299: my $args = { bread_crumbs => $brcrum,
4300: bread_crumbs_component => 'User Management'};
4301:
4302: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4303: $head_script,$args).
4304: $body_top);
1.73 sakharuk 4305: my %lt=&Apache::lonlocal::texthash(
4306: 'prv' => "Privilege",
1.131 raeburn 4307: 'crl' => "Course Level",
1.73 sakharuk 4308: 'dml' => "Domain Level",
1.150 banghart 4309: 'ssl' => "System Level");
1.264 bisitz 4310:
1.324 raeburn 4311: $r->print('<div class="LC_left_float">'
1.264 bisitz 4312: .'<form action=""><fieldset>'
4313: .'<legend>'.&mt('Select a Template').'</legend>'
4314: .$button_code
1.324 raeburn 4315: .'</fieldset></form></div>');
4316: if ($context_code) {
4317: $r->print('<div class="LC_left_float">'
4318: .'<form action="/adm/createuser" method="post"><fieldset>'
4319: .'<legend>'.&mt('Context').'</legend>'
4320: .$context_code
4321: .'</form>'
4322: .'</div>'
4323: );
4324: }
4325: $r->print('<br clear="all" />');
1.264 bisitz 4326:
1.61 www 4327: $r->print(<<ENDCCF);
1.380 bisitz 4328: <form name="form1" method="post" action="">
1.61 www 4329: <input type="hidden" name="phase" value="set_custom_roles" />
4330: <input type="hidden" name="rolename" value="$rolename" />
4331: ENDCCF
1.135 raeburn 4332: $r->print(&Apache::loncommon::start_data_table().
4333: &Apache::loncommon::start_data_table_header_row().
4334: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
4335: '</th><th>'.$lt{'ssl'}.'</th>'.
4336: &Apache::loncommon::end_data_table_header_row());
1.324 raeburn 4337: foreach my $priv (sort(keys(%full))) {
1.318 raeburn 4338: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
1.135 raeburn 4339: $r->print(&Apache::loncommon::start_data_table_row().
4340: '<td>'.$privtext.'</td><td>'.
1.288 bisitz 4341: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c"'.
4342: ($courselevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.61 www 4343: '</td><td>'.
1.288 bisitz 4344: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.
4345: ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.324 raeburn 4346: '</td><td>');
4347: if ($priv eq 'bre' && $crstype eq 'Community') {
4348: $r->print(' ');
4349: } else {
4350: $r->print($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
4351: ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':' ');
4352: }
4353: $r->print('</td>'.
4354: &Apache::loncommon::end_data_table_row());
1.60 www 4355: }
1.135 raeburn 4356: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4357: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4358: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 4359: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4360: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4361: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4362: }
1.153 banghart 4363: # --------------------------------------------------------
4364: sub make_script_template {
1.324 raeburn 4365: my ($role,$crstype) = @_;
1.153 banghart 4366: my %full_c=();
4367: my %full_d=();
4368: my %full_s=();
4369: my $return_script;
4370: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4371: my ($priv,$restrict)=split(/\&/,$item);
4372: $full_c{$priv}=1;
4373: }
4374: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4375: my ($priv,$restrict)=split(/\&/,$item);
4376: $full_d{$priv}=1;
4377: }
1.154 banghart 4378: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.324 raeburn 4379: next if (($crstype eq 'Community') && ($item eq 'bre&S'));
1.153 banghart 4380: my ($priv,$restrict)=split(/\&/,$item);
4381: $full_s{$priv}=1;
4382: }
4383: $return_script .= 'function set_'.$role.'() {'."\n";
4384: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
4385: my %role_c;
1.155 banghart 4386: foreach my $priv (@temp) {
1.153 banghart 4387: my ($priv_item, $dummy) = split(/\&/,$priv);
4388: $role_c{$priv_item} = 1;
4389: }
1.269 raeburn 4390: my %role_d;
4391: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
4392: foreach my $priv(@temp) {
4393: my ($priv_item, $dummy) = split(/\&/,$priv);
4394: $role_d{$priv_item} = 1;
4395: }
4396: my %role_s;
4397: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
4398: foreach my $priv(@temp) {
4399: my ($priv_item, $dummy) = split(/\&/,$priv);
4400: $role_s{$priv_item} = 1;
4401: }
1.153 banghart 4402: foreach my $priv_item (keys(%full_c)) {
4403: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4404: if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
4405: (exists($role_s{$priv}))) {
1.153 banghart 4406: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
4407: } else {
4408: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
4409: }
4410: }
1.154 banghart 4411: foreach my $priv_item (keys(%full_d)) {
4412: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4413: if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
1.154 banghart 4414: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
4415: } else {
4416: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
4417: }
4418: }
4419: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 4420: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 4421: if (exists($role_s{$priv})) {
4422: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
4423: } else {
4424: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
4425: }
1.153 banghart 4426: }
4427: $return_script .= '}'."\n";
1.154 banghart 4428: return ($return_script);
4429: }
4430: # ----------------------------------------------------------
4431: sub make_button_code {
1.318 raeburn 4432: my ($role,$crstype) = @_;
4433: my $label = &Apache::lonnet::plaintext($role,$crstype);
1.301 bisitz 4434: my $button_code = '<input type="button" onclick="set_'.$role.'()" value="'.$label.'" />';
1.154 banghart 4435: return ($button_code);
1.153 banghart 4436: }
1.61 www 4437: # ---------------------------------------------------------- Call to definerole
4438: sub set_custom_role {
1.351 raeburn 4439: my ($r,$context,$brcrum) = @_;
1.101 albertel 4440: my $rolename=$env{'form.rolename'};
1.63 www 4441: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4442: if (!$rolename) {
1.351 raeburn 4443: &custom_role_editor($r,$brcrum);
1.61 www 4444: return;
4445: }
1.160 raeburn 4446: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4447: my $jscript = '<script type="text/javascript">'
4448: .'// <![CDATA['."\n"
4449: .$jsback."\n"
4450: .'// ]]>'."\n"
4451: .'</script>'."\n";
1.352 raeburn 4452: push(@{$brcrum},
4453: {href => "javascript:backPage(document.customresult,'pickrole','')",
4454: text => "Pick custom role",
4455: faq => 282,
4456: bug => 'Instructor Interface',},
4457: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4458: text => "Edit custom role",
4459: faq => 282,
4460: bug => 'Instructor Interface',},
4461: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4462: text => "Result",
4463: faq => 282,
4464: bug => 'Instructor Interface',
4465: help => 'Course_Editing_Custom_Roles'},
4466: );
4467: my $args = { bread_crumbs => $brcrum,
1.351 raeburn 4468: bread_crumbs_component => 'User Management'};
4469: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4470:
1.393 raeburn 4471: my $newrole;
1.61 www 4472: my ($rdummy,$roledef)=
1.110 albertel 4473: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4474:
1.61 www 4475: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4476: $r->print('<h3>');
1.61 www 4477: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4478: $r->print(&mt('Existing Role').' "');
1.61 www 4479: } else {
1.73 sakharuk 4480: $r->print(&mt('New Role').' "');
1.61 www 4481: $roledef='';
1.393 raeburn 4482: $newrole = 1;
1.61 www 4483: }
1.188 raeburn 4484: $r->print($rolename.'"</h3>');
1.61 www 4485: # ------------------------------------------------------- What can be assigned?
4486: my $sysrole='';
4487: my $domrole='';
4488: my $courole='';
4489:
1.135 raeburn 4490: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4491: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4492: if (!$restrict) { $restrict=''; }
4493: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 4494: $courole.=':'.$item;
1.61 www 4495: }
4496: }
4497:
1.135 raeburn 4498: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4499: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4500: if (!$restrict) { $restrict=''; }
4501: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 4502: $domrole.=':'.$item;
1.61 www 4503: }
4504: }
4505:
1.135 raeburn 4506: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4507: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4508: if (!$restrict) { $restrict=''; }
4509: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 4510: $sysrole.=':'.$item;
1.61 www 4511: }
4512: }
1.387 bisitz 4513: # Assign role; Compile and show result
4514: my $errmsg;
4515: my $result =
4516: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole);
4517: if ($result ne 'ok') {
4518: $errmsg = ': '.$result;
4519: }
4520: my $message =
4521: &Apache::lonhtmlcommon::confirm_success(
4522: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4523: if ($env{'request.course.id'}) {
4524: my $url='/'.$env{'request.course.id'};
1.63 www 4525: $url=~s/\_/\//g;
1.387 bisitz 4526: $result =
4527: &Apache::lonnet::assigncustomrole(
4528: $env{'user.domain'},$env{'user.name'},
4529: $url,
4530: $env{'user.domain'},$env{'user.name'},
4531: $rolename,undef,undef,undef,$context);
4532: if ($result ne 'ok') {
4533: $errmsg = ': '.$result;
4534: }
4535: $message .=
4536: '<br />'
4537: .&Apache::lonhtmlcommon::confirm_success(
4538: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4539: }
1.380 bisitz 4540: $r->print(
1.387 bisitz 4541: &Apache::loncommon::confirmwrapper($message)
4542: .'<br />'
4543: .&Apache::lonhtmlcommon::actionbox([
4544: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4545: .&mt('Create or edit another custom role')
4546: .'</a>'])
1.380 bisitz 4547: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4548: .&Apache::lonhtmlcommon::echo_form_input([])
4549: .'</form>'
1.380 bisitz 4550: );
1.58 www 4551: }
4552:
1.2 www 4553: # ================================================================ Main Handler
4554: sub handler {
4555: my $r = shift;
4556: if ($r->header_only) {
1.68 www 4557: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4558: $r->send_http_header;
4559: return OK;
4560: }
1.318 raeburn 4561: my ($context,$crstype);
1.190 raeburn 4562: if ($env{'request.course.id'}) {
4563: $context = 'course';
1.318 raeburn 4564: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4565: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4566: $context = 'author';
1.190 raeburn 4567: } else {
4568: $context = 'domain';
4569: }
1.375 raeburn 4570:
1.190 raeburn 4571: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4572: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4573: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4574: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4575: my $args;
4576: my $brcrum = [];
4577: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4578: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4579: $brcrum = [{href=>"/adm/createuser",
4580: text=>"User Management",
4581: 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'}
4582: ];
1.202 raeburn 4583: }
1.289 droeschl 4584: #SD Following files not added to help, because the corresponding .tex-files seem to
4585: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 4586: my ($permission,$allowed) =
1.318 raeburn 4587: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 4588: if (!$allowed) {
1.358 raeburn 4589: if ($context eq 'course') {
4590: $r->internal_redirect('/adm/viewclasslist');
4591: return OK;
4592: }
1.190 raeburn 4593: $env{'user.error.msg'}=
4594: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4595: "or view user status.";
4596: return HTTP_NOT_ACCEPTABLE;
4597: }
4598:
4599: &Apache::loncommon::content_type($r,'text/html');
4600: $r->send_http_header;
4601:
1.375 raeburn 4602: my $showcredits;
4603: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4604: ($context eq 'domain')) {
4605: my %domdefaults =
4606: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4607: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4608: $showcredits = 1;
4609: }
4610: }
4611:
1.190 raeburn 4612: # Main switch on form.action and form.state, as appropriate
4613: if (! exists($env{'form.action'})) {
1.351 raeburn 4614: $args = {bread_crumbs => $brcrum,
4615: bread_crumbs_component => $bread_crumbs_component};
4616: $r->print(&header(undef,$args));
1.318 raeburn 4617: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4618: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.351 raeburn 4619: push(@{$brcrum},
4620: { href => '/adm/createuser?action=upload&state=',
4621: text => 'Upload Users List',
4622: help => 'Course_Create_Class_List',
4623: });
4624: $bread_crumbs_component = 'Upload Users List';
4625: $args = {bread_crumbs => $brcrum,
4626: bread_crumbs_component => $bread_crumbs_component};
4627: $r->print(&header(undef,$args));
1.190 raeburn 4628: $r->print('<form name="studentform" method="post" '.
4629: 'enctype="multipart/form-data" '.
4630: ' action="/adm/createuser">'."\n");
4631: if (! exists($env{'form.state'})) {
4632: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4633: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4634: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4635: $crstype,$showcredits);
1.190 raeburn 4636: } elsif ($env{'form.state'} eq 'enrolling') {
4637: if ($env{'form.datatoken'}) {
1.375 raeburn 4638: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4639: $showcredits);
1.190 raeburn 4640: }
4641: } else {
4642: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4643: }
1.213 raeburn 4644: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4645: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 4646: my $phase = $env{'form.phase'};
4647: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4648: &Apache::loncreateuser::restore_prev_selections();
4649: my $srch;
4650: foreach my $item (@search) {
4651: $srch->{$item} = $env{'form.'.$item};
4652: }
1.207 raeburn 4653: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
4654: ($phase eq 'createnewuser')) {
4655: if ($env{'form.phase'} eq 'createnewuser') {
4656: my $response;
4657: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4658: my $response =
4659: '<span class="LC_warning">'
4660: .&mt('You must specify a valid username. Only the following are allowed:'
4661: .' letters numbers - . @')
4662: .'</span>';
1.221 raeburn 4663: $env{'form.phase'} = '';
1.375 raeburn 4664: &print_username_entry_form($r,$context,$response,$srch,undef,
4665: $crstype,$brcrum,$showcredits);
1.207 raeburn 4666: } else {
4667: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4668: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4669: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4670: $srch,$response,$context,
1.375 raeburn 4671: $permission,$crstype,$brcrum,
4672: $showcredits);
1.207 raeburn 4673: }
4674: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4675: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4676: &user_search_result($context,$srch);
1.190 raeburn 4677: if ($env{'form.currstate'} eq 'modify') {
4678: $currstate = $env{'form.currstate'};
4679: }
4680: if ($currstate eq 'select') {
4681: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4682: \@search,$context,undef,$crstype,
4683: $brcrum);
1.190 raeburn 4684: } elsif ($currstate eq 'modify') {
4685: my ($ccuname,$ccdomain);
4686: if (($srch->{'srchby'} eq 'uname') &&
4687: ($srch->{'srchtype'} eq 'exact')) {
4688: $ccuname = $srch->{'srchterm'};
4689: $ccdomain= $srch->{'srchdomain'};
4690: } else {
4691: my @matchedunames = keys(%{$results});
4692: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4693: }
4694: $ccuname =&LONCAPA::clean_username($ccuname);
4695: $ccdomain=&LONCAPA::clean_domain($ccdomain);
4696: if ($env{'form.forcenewuser'}) {
4697: $response = '';
4698: }
4699: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4700: $srch,$response,$context,
1.351 raeburn 4701: $permission,$crstype,$brcrum);
1.190 raeburn 4702: } elsif ($currstate eq 'query') {
1.351 raeburn 4703: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4704: } else {
1.229 raeburn 4705: $env{'form.phase'} = '';
1.207 raeburn 4706: &print_username_entry_form($r,$context,$response,$srch,
1.351 raeburn 4707: $forcenewuser,$crstype,$brcrum);
1.190 raeburn 4708: }
4709: } elsif ($env{'form.phase'} eq 'userpicked') {
4710: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4711: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 4712: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.351 raeburn 4713: $context,$permission,$crstype,
4714: $brcrum);
1.190 raeburn 4715: }
4716: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4717: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4718: } else {
1.351 raeburn 4719: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4720: $brcrum);
1.190 raeburn 4721: }
4722: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
4723: if ($env{'form.phase'} eq 'set_custom_roles') {
1.351 raeburn 4724: &set_custom_role($r,$context,$brcrum);
1.190 raeburn 4725: } else {
1.351 raeburn 4726: &custom_role_editor($r,$brcrum);
1.190 raeburn 4727: }
1.362 raeburn 4728: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4729: ($permission->{'cusr'}) &&
4730: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4731: push(@{$brcrum},
4732: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4733: text => 'Authoring Space requests',
1.362 raeburn 4734: help => 'Domain_Role_Approvals'});
4735: $bread_crumbs_component = 'Authoring requests';
4736: if ($env{'form.state'} eq 'done') {
4737: push(@{$brcrum},
4738: {href => '/adm/createuser?action=authorreqqueue',
4739: text => 'Result',
4740: help => 'Domain_Role_Approvals'});
4741: $bread_crumbs_component = 'Authoring request result';
4742: }
4743: $args = { bread_crumbs => $brcrum,
4744: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4745: my $js = &usernamerequest_javascript();
4746: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4747: if (!exists($env{'form.state'})) {
4748: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4749: $env{'request.role.domain'}));
4750: } elsif ($env{'form.state'} eq 'done') {
4751: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4752: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4753: $env{'request.role.domain'}));
4754: }
1.391 raeburn 4755: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4756: ($permission->{'cusr'}) &&
4757: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4758: push(@{$brcrum},
4759: {href => '/adm/createuser?action=processusernamereq',
4760: text => 'LON-CAPA account requests',
4761: help => 'Domain_Username_Approvals'});
4762: $bread_crumbs_component = 'Account requests';
4763: if ($env{'form.state'} eq 'done') {
4764: push(@{$brcrum},
4765: {href => '/adm/createuser?action=usernamereqqueue',
4766: text => 'Result',
4767: help => 'Domain_Username_Approvals'});
4768: $bread_crumbs_component = 'LON-CAPA account request result';
4769: }
4770: $args = { bread_crumbs => $brcrum,
4771: bread_crumbs_component => $bread_crumbs_component};
4772: my $js = &usernamerequest_javascript();
4773: $r->print(&header(&add_script($js),$args));
4774: if (!exists($env{'form.state'})) {
4775: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4776: $env{'request.role.domain'}));
4777: } elsif ($env{'form.state'} eq 'done') {
4778: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4779: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4780: $env{'request.role.domain'}));
4781: }
4782: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4783: ($permission->{'cusr'})) {
4784: my $dom = $env{'form.domain'};
4785: my $uname = $env{'form.username'};
4786: my $warning;
4787: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4788: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4789: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4790: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4791: if ($uhome eq 'no_host') {
4792: my $queue = $env{'form.queue'};
4793: my $reqkey = &escape($uname).'_'.$queue;
4794: my $namespace = 'usernamequeue';
4795: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4796: my %queued =
4797: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4798: unless ($queued{$reqkey}) {
4799: $warning = &mt('No information was found for this LON-CAPA account request.');
4800: }
4801: } else {
4802: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4803: }
4804: } else {
4805: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4806: }
4807: } else {
4808: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4809: }
4810: } else {
4811: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4812: }
4813: my $args = { only_body => 1 };
4814: $r->print(&header(undef,$args).
4815: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4816: if ($warning ne '') {
4817: $r->print('<div class="LC_warning">'.$warning.'</div>');
4818: } else {
4819: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4820: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4821: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4822: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4823: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4824: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4825: my %info =
4826: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4827: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4828: my $usertype = $info{$uname}{'inststatus'};
4829: unless ($usertype) {
4830: $usertype = 'default';
4831: }
4832: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
4833: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
4834: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
4835: my ($num,$count,$showstatus);
4836: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
4837: unless ($usertype eq 'default') {
4838: my ($othertitle,$usertypes,$types) =
4839: &Apache::loncommon::sorted_inst_types($dom);
4840: if (ref($usertypes) eq 'HASH') {
4841: if ($usertypes->{$usertype}) {
4842: $showstatus = $usertypes->{$usertype};
4843: $count ++;
4844: }
4845: }
4846: }
4847: foreach my $field (@{$infofields}) {
4848: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
4849: next unless ($infotitles->{$field});
4850: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
4851: $info{$uname}{$field});
4852: $num ++;
4853: if ($count == $num) {
4854: $r->print(&Apache::lonhtmlcommon::row_closure(1));
4855: } else {
4856: $r->print(&Apache::lonhtmlcommon::row_closure());
4857: }
4858: }
4859: if ($showstatus) {
4860: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type (self-reported)')).
4861: $showstatus.
4862: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 4863: }
1.396 raeburn 4864: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
1.391 raeburn 4865: }
4866: }
4867: }
4868: }
4869: }
4870: }
4871: $r->print(&close_popup_form());
4872: }
1.207 raeburn 4873: } elsif (($env{'form.action'} eq 'listusers') &&
4874: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 4875: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 4876: push(@{$brcrum},
4877: {href => '/adm/createuser?action=listusers',
4878: text => "List Users"},
4879: {href => "/adm/createuser",
4880: text => "Result",
4881: help => 'Course_View_Class_List'});
4882: $bread_crumbs_component = 'Update Users';
4883: $args = {bread_crumbs => $brcrum,
4884: bread_crumbs_component => $bread_crumbs_component};
4885: $r->print(&header(undef,$args));
1.202 raeburn 4886: my $setting = $env{'form.roletype'};
4887: my $choice = $env{'form.bulkaction'};
4888: if ($permission->{'cusr'}) {
1.336 raeburn 4889: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 4890: } else {
4891: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 4892: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 4893: }
4894: } else {
1.351 raeburn 4895: push(@{$brcrum},
4896: {href => '/adm/createuser?action=listusers',
4897: text => "List Users",
4898: help => 'Course_View_Class_List'});
4899: $bread_crumbs_component = 'List Users';
4900: $args = {bread_crumbs => $brcrum,
4901: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 4902: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4903: my $formname = 'studentform';
1.364 raeburn 4904: my $hidecall = "hide_searching();";
1.321 raeburn 4905: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
4906: ($env{'form.roletype'} eq 'community'))) {
4907: if ($env{'form.roletype'} eq 'course') {
4908: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
4909: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
4910: $formname);
4911: } elsif ($env{'form.roletype'} eq 'community') {
4912: $cb_jscript =
4913: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
4914: my %elements = (
4915: coursepick => 'radio',
4916: coursetotal => 'text',
4917: courselist => 'text',
4918: );
4919: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
4920: }
1.364 raeburn 4921: $jscript .= &verify_user_display($context)."\n".
4922: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 4923: my $js = &add_script($jscript).$cb_jscript;
4924: my $loadcode =
4925: &Apache::lonuserutils::course_selector_loadcode($formname);
4926: if ($loadcode ne '') {
1.364 raeburn 4927: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
4928: } else {
4929: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 4930: }
1.351 raeburn 4931: $r->print(&header($js,$args));
1.191 raeburn 4932: } else {
1.364 raeburn 4933: $args->{add_entries} = {onload => $hidecall};
4934: $jscript = &verify_user_display($context).
4935: &Apache::loncommon::check_uncheck_jscript();
4936: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 4937: }
1.202 raeburn 4938: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 4939: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
4940: $showcredits);
1.191 raeburn 4941: }
1.213 raeburn 4942: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 4943: my $brtext;
4944: if ($crstype eq 'Community') {
4945: $brtext = 'Drop Members';
4946: } else {
4947: $brtext = 'Drop Students';
4948: }
1.351 raeburn 4949: push(@{$brcrum},
4950: {href => '/adm/createuser?action=drop',
4951: text => $brtext,
4952: help => 'Course_Drop_Student'});
4953: if ($env{'form.state'} eq 'done') {
4954: push(@{$brcrum},
4955: {href=>'/adm/createuser?action=drop',
4956: text=>"Result"});
4957: }
4958: $bread_crumbs_component = $brtext;
4959: $args = {bread_crumbs => $brcrum,
4960: bread_crumbs_component => $bread_crumbs_component};
4961: $r->print(&header(undef,$args));
1.213 raeburn 4962: if (!exists($env{'form.state'})) {
1.318 raeburn 4963: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 4964: } elsif ($env{'form.state'} eq 'done') {
4965: &Apache::lonuserutils::update_user_list($r,$context,undef,
4966: $env{'form.action'});
4967: }
1.202 raeburn 4968: } elsif ($env{'form.action'} eq 'dateselect') {
4969: if ($permission->{'cusr'}) {
1.351 raeburn 4970: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 4971: &Apache::lonuserutils::date_section_selector($context,$permission,
4972: $crstype,$showcredits));
1.202 raeburn 4973: } else {
1.351 raeburn 4974: $r->print(&header(undef,{'no_nav_bar' => 1}).
4975: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 4976: }
1.237 raeburn 4977: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 4978: if ($permission->{selfenrolladmin}) {
4979: my $cid = $env{'request.course.id'};
4980: my $cdom = $env{'course.'.$cid.'.domain'};
4981: my $cnum = $env{'course.'.$cid.'.num'};
4982: my %currsettings = (
4983: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
4984: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
4985: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
4986: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
4987: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
4988: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
4989: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
4990: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
4991: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
4992: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
4993: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
4994: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
4995: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 ! raeburn 4996: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 4997: );
4998: push(@{$brcrum},
4999: {href => '/adm/createuser?action=selfenroll',
5000: text => "Configure Self-enrollment",
5001: help => 'Course_Self_Enrollment'});
5002: if (!exists($env{'form.state'})) {
5003: $args = { bread_crumbs => $brcrum,
5004: bread_crumbs_component => 'Configure Self-enrollment'};
5005: $r->print(&header(undef,$args));
5006: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5007: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5008: } elsif ($env{'form.state'} eq 'done') {
5009: push (@{$brcrum},
5010: {href=>'/adm/createuser?action=selfenroll',
5011: text=>"Result"});
5012: $args = { bread_crumbs => $brcrum,
5013: bread_crumbs_component => 'Self-enrollment result'};
5014: $r->print(&header(undef,$args));
5015: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 ! raeburn 5016: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5017: }
5018: } else {
5019: $r->print(&header(undef,{'no_nav_bar' => 1}).
5020: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5021: }
1.277 raeburn 5022: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.351 raeburn 5023: push(@{$brcrum},
5024: {href => '/adm/createuser?action=selfenrollqueue',
5025: text => 'Enrollment requests',
5026: help => 'Course_Self_Enrollment'});
5027: $bread_crumbs_component = 'Enrollment requests';
5028: if ($env{'form.state'} eq 'done') {
5029: push(@{$brcrum},
5030: {href => '/adm/createuser?action=selfenrollqueue',
5031: text => 'Result',
5032: help => 'Course_Self_Enrollment'});
5033: $bread_crumbs_component = 'Enrollment result';
5034: }
5035: $args = { bread_crumbs => $brcrum,
5036: bread_crumbs_component => $bread_crumbs_component};
5037: $r->print(&header(undef,$args));
1.277 raeburn 5038: my $cid = $env{'request.course.id'};
5039: my $cdom = $env{'course.'.$cid.'.domain'};
5040: my $cnum = $env{'course.'.$cid.'.num'};
1.307 raeburn 5041: my $coursedesc = $env{'course.'.$cid.'.description'};
1.277 raeburn 5042: if (!exists($env{'form.state'})) {
5043: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
1.307 raeburn 5044: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5045: $cdom,$cnum));
1.277 raeburn 5046: } elsif ($env{'form.state'} eq 'done') {
5047: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
1.307 raeburn 5048: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5049: $cdom,$cnum,$coursedesc));
1.277 raeburn 5050: }
1.239 raeburn 5051: } elsif ($env{'form.action'} eq 'changelogs') {
1.363 raeburn 5052: my $helpitem;
5053: if ($context eq 'course') {
5054: $helpitem = 'Course_User_Logs';
5055: }
1.351 raeburn 5056: push (@{$brcrum},
5057: {href => '/adm/createuser?action=changelogs',
5058: text => 'User Management Logs',
1.363 raeburn 5059: help => $helpitem});
1.351 raeburn 5060: $bread_crumbs_component = 'User Changes';
5061: $args = { bread_crumbs => $brcrum,
5062: bread_crumbs_component => $bread_crumbs_component};
5063: $r->print(&header(undef,$args));
5064: &print_userchangelogs_display($r,$context,$permission);
1.190 raeburn 5065: } else {
1.351 raeburn 5066: $bread_crumbs_component = 'User Management';
5067: $args = { bread_crumbs => $brcrum,
5068: bread_crumbs_component => $bread_crumbs_component};
5069: $r->print(&header(undef,$args));
1.318 raeburn 5070: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5071: }
1.351 raeburn 5072: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5073: return OK;
5074: }
5075:
5076: sub header {
1.351 raeburn 5077: my ($jscript,$args) = @_;
1.190 raeburn 5078: my $start_page;
1.351 raeburn 5079: if (ref($args) eq 'HASH') {
5080: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5081: } else {
1.351 raeburn 5082: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5083: }
5084: return $start_page;
5085: }
1.2 www 5086:
1.191 raeburn 5087: sub add_script {
5088: my ($js) = @_;
1.301 bisitz 5089: return '<script type="text/javascript">'."\n"
5090: .'// <![CDATA['."\n"
5091: .$js."\n"
5092: .'// ]]>'."\n"
5093: .'</script>'."\n";
1.191 raeburn 5094: }
5095:
1.391 raeburn 5096: sub usernamerequest_javascript {
5097: my $js = <<ENDJS;
5098:
5099: function openusernamereqdisplay(dom,uname,queue) {
5100: var url = '/adm/createuser?action=displayuserreq';
5101: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5102: var title = 'Account_Request_Browser';
5103: var options = 'scrollbars=1,resizable=1,menubar=0';
5104: options += ',width=700,height=600';
5105: var stdeditbrowser = open(url,title,options,'1');
5106: stdeditbrowser.focus();
5107: return;
5108: }
5109:
5110: ENDJS
5111: }
5112:
5113: sub close_popup_form {
5114: my $close= &mt('Close Window');
5115: return << "END";
5116: <p><form name="displayreq" action="" method="post">
5117: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5118: </form></p>
5119: END
5120: }
5121:
1.202 raeburn 5122: sub verify_user_display {
1.364 raeburn 5123: my ($context) = @_;
1.374 raeburn 5124: my %lt = &Apache::lonlocal::texthash (
5125: course => 'course(s): description, section(s), status',
5126: community => 'community(s): description, section(s), status',
5127: author => 'author',
5128: );
1.364 raeburn 5129: my $photos;
5130: if (($context eq 'course') && $env{'request.course.id'}) {
5131: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5132: }
1.202 raeburn 5133: my $output = <<"END";
5134:
1.364 raeburn 5135: function hide_searching() {
5136: if (document.getElementById('searching')) {
5137: document.getElementById('searching').style.display = 'none';
5138: }
5139: return;
5140: }
5141:
1.202 raeburn 5142: function display_update() {
5143: document.studentform.action.value = 'listusers';
5144: document.studentform.phase.value = 'display';
5145: document.studentform.submit();
5146: }
5147:
1.364 raeburn 5148: function updateCols(caller) {
5149: var context = '$context';
5150: var photos = '$photos';
5151: if (caller == 'Status') {
1.374 raeburn 5152: if ((context == 'domain') &&
5153: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5154: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5155: document.getElementById('showcolstatus').checked = false;
5156: document.getElementById('showcolstatus').disabled = 'disabled';
5157: document.getElementById('showcolstart').checked = false;
5158: document.getElementById('showcolend').checked = false;
1.374 raeburn 5159: } else {
5160: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5161: document.getElementById('showcolstatus').checked = true;
5162: document.getElementById('showcolstatus').disabled = '';
5163: document.getElementById('showcolstart').checked = true;
5164: document.getElementById('showcolend').checked = true;
5165: } else {
5166: document.getElementById('showcolstatus').checked = false;
5167: document.getElementById('showcolstatus').disabled = 'disabled';
5168: document.getElementById('showcolstart').checked = false;
5169: document.getElementById('showcolend').checked = false;
5170: }
1.364 raeburn 5171: }
5172: }
5173: if (caller == 'output') {
5174: if (photos == 1) {
5175: if (document.getElementById('showcolphoto')) {
5176: var photoitem = document.getElementById('showcolphoto');
5177: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5178: photoitem.checked = true;
5179: photoitem.disabled = '';
5180: } else {
5181: photoitem.checked = false;
5182: photoitem.disabled = 'disabled';
5183: }
5184: }
5185: }
5186: }
5187: if (caller == 'showrole') {
1.371 raeburn 5188: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5189: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5190: document.getElementById('showcolrole').checked = true;
5191: document.getElementById('showcolrole').disabled = '';
5192: } else {
5193: document.getElementById('showcolrole').checked = false;
5194: document.getElementById('showcolrole').disabled = 'disabled';
5195: }
1.374 raeburn 5196: if (context == 'domain') {
1.382 raeburn 5197: var quotausageshow = 0;
1.374 raeburn 5198: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5199: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5200: document.getElementById('showcolstatus').checked = false;
5201: document.getElementById('showcolstatus').disabled = 'disabled';
5202: document.getElementById('showcolstart').checked = false;
5203: document.getElementById('showcolend').checked = false;
5204: } else {
5205: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5206: document.getElementById('showcolstatus').checked = true;
5207: document.getElementById('showcolstatus').disabled = '';
5208: document.getElementById('showcolstart').checked = true;
5209: document.getElementById('showcolend').checked = true;
5210: }
5211: }
5212: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5213: document.getElementById('showcolextent').disabled = 'disabled';
5214: document.getElementById('showcolextent').checked = 'false';
5215: document.getElementById('showextent').style.display='none';
5216: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5217: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5218: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5219: if (document.getElementById('showcolauthorusage')) {
5220: document.getElementById('showcolauthorusage').disabled = '';
5221: }
5222: if (document.getElementById('showcolauthorquota')) {
5223: document.getElementById('showcolauthorquota').disabled = '';
5224: }
5225: quotausageshow = 1;
5226: }
1.374 raeburn 5227: } else {
5228: document.getElementById('showextent').style.display='block';
5229: document.getElementById('showextent').style.textAlign='left';
5230: document.getElementById('showextent').style.textFace='normal';
5231: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5232: document.getElementById('showcolextent').disabled = '';
5233: document.getElementById('showcolextent').checked = 'true';
5234: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5235: } else {
5236: document.getElementById('showcolextent').disabled = '';
5237: document.getElementById('showcolextent').checked = 'true';
5238: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5239: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5240: } else {
5241: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5242: }
5243: }
5244: }
1.382 raeburn 5245: if (quotausageshow == 0) {
5246: if (document.getElementById('showcolauthorusage')) {
5247: document.getElementById('showcolauthorusage').checked = false;
5248: document.getElementById('showcolauthorusage').disabled = 'disabled';
5249: }
5250: if (document.getElementById('showcolauthorquota')) {
5251: document.getElementById('showcolauthorquota').checked = false;
5252: document.getElementById('showcolauthorquota').disabled = 'disabled';
5253: }
5254: }
1.374 raeburn 5255: }
1.364 raeburn 5256: }
5257: return;
5258: }
5259:
1.202 raeburn 5260: END
5261: return $output;
5262:
5263: }
5264:
1.190 raeburn 5265: ###############################################################
5266: ###############################################################
5267: # Menu Phase One
5268: sub print_main_menu {
1.318 raeburn 5269: my ($permission,$context,$crstype) = @_;
5270: my $linkcontext = $context;
5271: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5272: if (($context eq 'course') && ($crstype eq 'Community')) {
5273: $linkcontext = lc($crstype);
5274: $stuterm = 'Members';
5275: }
1.208 raeburn 5276: my %links = (
1.298 droeschl 5277: domain => {
5278: upload => 'Upload a File of Users',
5279: singleuser => 'Add/Modify a User',
5280: listusers => 'Manage Users',
5281: },
5282: author => {
5283: upload => 'Upload a File of Co-authors',
5284: singleuser => 'Add/Modify a Co-author',
5285: listusers => 'Manage Co-authors',
5286: },
5287: course => {
5288: upload => 'Upload a File of Course Users',
5289: singleuser => 'Add/Modify a Course User',
1.354 www 5290: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5291: },
1.318 raeburn 5292: community => {
5293: upload => 'Upload a File of Community Users',
5294: singleuser => 'Add/Modify a Community User',
1.354 www 5295: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5296: },
5297: );
5298: my %linktitles = (
5299: domain => {
5300: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5301: listusers => 'Show and manage users in this domain.',
5302: },
5303: author => {
5304: singleuser => 'Add a user with a co- or assistant author role.',
5305: listusers => 'Show and manage co- or assistant authors.',
5306: },
5307: course => {
5308: singleuser => 'Add a user with a certain role to this course.',
5309: listusers => 'Show and manage users in this course.',
5310: },
5311: community => {
5312: singleuser => 'Add a user with a certain role to this community.',
5313: listusers => 'Show and manage users in this community.',
5314: },
1.298 droeschl 5315: );
5316: my @menu = ( {categorytitle => 'Single Users',
5317: items =>
5318: [
5319: {
1.318 raeburn 5320: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5321: icon => 'edit-redo.png',
5322: #help => 'Course_Change_Privileges',
5323: url => '/adm/createuser?action=singleuser',
5324: permission => $permission->{'cusr'},
1.318 raeburn 5325: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5326: },
5327: ]},
5328:
5329: {categorytitle => 'Multiple Users',
5330: items =>
5331: [
5332: {
1.318 raeburn 5333: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5334: icon => 'uplusr.png',
1.298 droeschl 5335: #help => 'Course_Create_Class_List',
5336: url => '/adm/createuser?action=upload',
5337: permission => $permission->{'cusr'},
5338: linktitle => 'Upload a CSV or a text file containing users.',
5339: },
5340: {
1.318 raeburn 5341: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5342: icon => 'mngcu.png',
1.298 droeschl 5343: #help => 'Course_View_Class_List',
5344: url => '/adm/createuser?action=listusers',
5345: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5346: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5347: },
5348:
5349: ]},
5350:
5351: {categorytitle => 'Administration',
5352: items => [ ]},
5353: );
5354:
1.265 mielkec 5355: if ($context eq 'domain'){
1.298 droeschl 5356:
5357: push(@{ $menu[2]->{items} }, #Category: Administration
5358: {
5359: linktext => 'Custom Roles',
5360: icon => 'emblem-photos.png',
5361: #help => 'Course_Editing_Custom_Roles',
5362: url => '/adm/createuser?action=custom',
5363: permission => $permission->{'custom'},
5364: linktitle => 'Configure a custom role.',
5365: },
1.362 raeburn 5366: {
5367: linktext => 'Authoring Space Requests',
5368: icon => 'selfenrl-queue.png',
5369: #help => 'Domain_Role_Approvals',
5370: url => '/adm/createuser?action=processauthorreq',
5371: permission => $permission->{'cusr'},
5372: linktitle => 'Approve or reject author role requests',
5373: },
1.363 raeburn 5374: {
1.391 raeburn 5375: linktext => 'LON-CAPA Account Requests',
5376: icon => 'list-add.png',
5377: #help => 'Domain_Username_Approvals',
5378: url => '/adm/createuser?action=processusernamereq',
5379: permission => $permission->{'cusr'},
5380: linktitle => 'Approve or reject LON-CAPA account requests',
5381: },
5382: {
1.363 raeburn 5383: linktext => 'Change Log',
5384: icon => 'document-properties.png',
5385: #help => 'Course_User_Logs',
5386: url => '/adm/createuser?action=changelogs',
5387: permission => $permission->{'cusr'},
5388: linktitle => 'View change log.',
5389: },
1.298 droeschl 5390: );
5391:
1.265 mielkec 5392: }elsif ($context eq 'course'){
1.298 droeschl 5393: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5394:
5395: my %linktext = (
5396: 'Course' => {
5397: single => 'Add/Modify a Student',
5398: drop => 'Drop Students',
5399: groups => 'Course Groups',
5400: },
5401: 'Community' => {
5402: single => 'Add/Modify a Member',
5403: drop => 'Drop Members',
5404: groups => 'Community Groups',
5405: },
5406: );
5407:
5408: my %linktitle = (
5409: 'Course' => {
5410: single => 'Add a user with the role of student to this course',
5411: drop => 'Remove a student from this course.',
5412: groups => 'Manage course groups',
5413: },
5414: 'Community' => {
5415: single => 'Add a user with the role of member to this community',
5416: drop => 'Remove a member from this community.',
5417: groups => 'Manage community groups',
5418: },
5419: );
5420:
1.298 droeschl 5421: push(@{ $menu[0]->{items} }, #Category: Single Users
5422: {
1.318 raeburn 5423: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5424: #help => 'Course_Add_Student',
5425: icon => 'list-add.png',
5426: url => '/adm/createuser?action=singlestudent',
5427: permission => $permission->{'cusr'},
1.318 raeburn 5428: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5429: },
5430: );
5431:
5432: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5433: {
1.318 raeburn 5434: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5435: icon => 'edit-undo.png',
5436: #help => 'Course_Drop_Student',
5437: url => '/adm/createuser?action=drop',
5438: permission => $permission->{'cusr'},
1.318 raeburn 5439: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5440: },
5441: );
5442: push(@{ $menu[2]->{items} }, #Category: Administration
5443: {
5444: linktext => 'Custom Roles',
5445: icon => 'emblem-photos.png',
5446: #help => 'Course_Editing_Custom_Roles',
5447: url => '/adm/createuser?action=custom',
5448: permission => $permission->{'custom'},
5449: linktitle => 'Configure a custom role.',
5450: },
5451: {
1.318 raeburn 5452: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5453: icon => 'grps.png',
1.298 droeschl 5454: #help => 'Course_Manage_Group',
5455: url => '/adm/coursegroups?refpage=cusr',
5456: permission => $permission->{'grp_manage'},
1.318 raeburn 5457: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5458: },
5459: {
1.328 wenzelju 5460: linktext => 'Change Log',
1.298 droeschl 5461: icon => 'document-properties.png',
5462: #help => 'Course_User_Logs',
5463: url => '/adm/createuser?action=changelogs',
5464: permission => $permission->{'cusr'},
5465: linktitle => 'View change log.',
5466: },
5467: );
1.277 raeburn 5468: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5469: push(@{ $menu[2]->{items} },
1.398 raeburn 5470: {
1.298 droeschl 5471: linktext => 'Enrollment Requests',
5472: icon => 'selfenrl-queue.png',
5473: #help => 'Course_Approve_Selfenroll',
5474: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5475: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5476: linktitle =>'Approve or reject enrollment requests.',
5477: },
5478: );
1.277 raeburn 5479: }
1.298 droeschl 5480:
1.265 mielkec 5481: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5482: if ($crstype ne 'Community') {
5483: push(@{ $menu[2]->{items} },
5484: {
5485: linktext => 'Automated Enrollment',
5486: icon => 'roles.png',
5487: #help => 'Course_Automated_Enrollment',
5488: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
5489: && $permission->{'cusr'}),
5490: url => '/adm/populate',
5491: linktitle => 'Automated enrollment manager.',
5492: }
5493: );
5494: }
5495: push(@{ $menu[2]->{items} },
1.298 droeschl 5496: {
5497: linktext => 'User Self-Enrollment',
1.342 wenzelju 5498: icon => 'self_enroll.png',
1.298 droeschl 5499: #help => 'Course_Self_Enrollment',
5500: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5501: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5502: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5503: },
5504: );
5505: }
1.363 raeburn 5506: } elsif ($context eq 'author') {
1.370 raeburn 5507: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5508: {
5509: linktext => 'Change Log',
5510: icon => 'document-properties.png',
5511: #help => 'Course_User_Logs',
5512: url => '/adm/createuser?action=changelogs',
5513: permission => $permission->{'cusr'},
5514: linktitle => 'View change log.',
5515: },
1.370 raeburn 5516: );
1.363 raeburn 5517: }
5518: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5519: # { text => 'View Log-in History',
5520: # help => 'Course_User_Logins',
5521: # action => 'logins',
5522: # permission => $permission->{'cusr'},
5523: # });
1.190 raeburn 5524: }
5525:
1.189 albertel 5526: sub restore_prev_selections {
5527: my %saveable_parameters = ('srchby' => 'scalar',
5528: 'srchin' => 'scalar',
5529: 'srchtype' => 'scalar',
5530: );
5531: &Apache::loncommon::store_settings('user','user_picker',
5532: \%saveable_parameters);
5533: &Apache::loncommon::restore_settings('user','user_picker',
5534: \%saveable_parameters);
5535: }
5536:
1.237 raeburn 5537: sub print_selfenroll_menu {
1.398 raeburn 5538: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional) = @_;
1.322 raeburn 5539: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5540: my $formname = 'selfenroll';
1.237 raeburn 5541: my $nolink = 1;
1.398 raeburn 5542: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5543: my $groupslist = &Apache::lonuserutils::get_groupslist();
5544: my $setsec_js =
5545: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5546: my %alerts = &Apache::lonlocal::texthash(
5547: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5548: butn => 'but no user types have been checked.',
5549: wilf => "Please uncheck 'activate' or check at least one type.",
5550: );
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'};
! 5752: } else {
! 5753: $cathash = {};
! 5754: $cattype{'auth'} = 'std';
! 5755: $cattype{'unauth'} = 'std';
! 5756: }
! 5757: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
! 5758: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
! 5759: '<br />'.
! 5760: '<br />'.$visactions->{'take'}.'<ul>'.
! 5761: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
! 5762: '</ul>');
! 5763: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
! 5764: if ($currsettings->{'uniquecode'}) {
! 5765: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
! 5766: } else {
! 5767: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
! 5768: '<br />'.
! 5769: '<br />'.$visactions->{'take'}.'<ul>'.
! 5770: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
! 5771: '</ul><br />');
! 5772: }
! 5773: } else {
! 5774: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
! 5775: if (ref($visactions) eq 'HASH') {
! 5776: if ($visible) {
! 5777: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
! 5778: } else {
! 5779: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
! 5780: .$visactions->{'yous'}.
! 5781: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
! 5782: if (ref($vismsgs) eq 'ARRAY') {
! 5783: $output .= '<br />'.$visactions->{'make'}.'<ul>';
! 5784: foreach my $item (@{$vismsgs}) {
! 5785: $output .= '<li>'.$visactions->{$item}.'</li>';
! 5786: }
! 5787: $output .= '</ul>';
1.256 raeburn 5788: }
1.400 ! raeburn 5789: $output .= '</p>';
1.256 raeburn 5790: }
5791: }
5792: }
1.398 raeburn 5793: my $actionhref = '/adm/createuser';
5794: if ($context eq 'domain') {
5795: $actionhref = '/adm/modifycourse';
5796: }
1.400 ! raeburn 5797:
! 5798: my %noedit;
! 5799: unless ($context eq 'domain') {
! 5800: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
! 5801: }
1.398 raeburn 5802: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 5803: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5804: if (ref($row) eq 'ARRAY') {
5805: foreach my $item (@{$row}) {
5806: my $title = $item;
5807: if (ref($lt) eq 'HASH') {
5808: $title = $lt->{$item};
5809: }
1.297 bisitz 5810: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5811: if ($item eq 'types') {
1.398 raeburn 5812: my $curr_types;
5813: if (ref($currsettings) eq 'HASH') {
5814: $curr_types = $currsettings->{'selfenroll_types'};
5815: }
1.400 ! raeburn 5816: if ($noedit{$item}) {
! 5817: if ($curr_types eq '*') {
! 5818: $output .= &mt('Any user in any domain');
! 5819: } else {
! 5820: my @entries = split(/;/,$curr_types);
! 5821: if (@entries > 0) {
! 5822: $output .= '<ul>';
! 5823: foreach my $entry (@entries) {
! 5824: my ($currdom,$typestr) = split(/:/,$entry);
! 5825: next if ($typestr eq '');
! 5826: my $domdesc = &Apache::lonnet::domain($currdom);
! 5827: my @currinsttypes = split(',',$typestr);
! 5828: my ($othertitle,$usertypes,$types) =
! 5829: &Apache::loncommon::sorted_inst_types($currdom);
! 5830: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
! 5831: $usertypes->{'any'} = &mt('any user');
! 5832: if (keys(%{$usertypes}) > 0) {
! 5833: $usertypes->{'other'} = &mt('other users');
! 5834: }
! 5835: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
! 5836: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
! 5837: }
! 5838: }
! 5839: $output .= '</ul>';
! 5840: } else {
! 5841: $output .= &mt('None');
! 5842: }
! 5843: }
! 5844: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
! 5845: next;
! 5846: }
1.241 raeburn 5847: my $showdomdesc = 1;
5848: my $includeempty = 1;
5849: my $num = 0;
5850: $output .= &Apache::loncommon::start_data_table().
5851: &Apache::loncommon::start_data_table_row()
5852: .'<td colspan="2"><span class="LC_nobreak"><label>'
5853: .&mt('Any user in any domain:')
5854: .' <input type="radio" name="selfenroll_all" value="1" ';
5855: if ($curr_types eq '*') {
5856: $output .= ' checked="checked" ';
5857: }
1.249 raeburn 5858: $output .= 'onchange="javascript:update_types('.
5859: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
5860: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 5861: if ($curr_types ne '*') {
5862: $output .= ' checked="checked" ';
5863: }
1.249 raeburn 5864: $output .= ' onchange="javascript:update_types('.
5865: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
5866: &Apache::loncommon::end_data_table_row().
5867: &Apache::loncommon::end_data_table().
5868: &mt('Or').'<br />'.
5869: &Apache::loncommon::start_data_table();
1.241 raeburn 5870: my %currdoms;
1.249 raeburn 5871: if ($curr_types eq '') {
1.241 raeburn 5872: $output .= &new_selfenroll_dom_row($cdom,'0');
5873: } elsif ($curr_types ne '*') {
5874: my @entries = split(/;/,$curr_types);
5875: if (@entries > 0) {
5876: foreach my $entry (@entries) {
5877: my ($currdom,$typestr) = split(/:/,$entry);
5878: $currdoms{$currdom} = 1;
5879: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 5880: my @currinsttypes = split(',',$typestr);
1.241 raeburn 5881: $output .= &Apache::loncommon::start_data_table_row()
5882: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
5883: .' '.$domdesc.' ('.$currdom.')'
5884: .'</b><input type="hidden" name="selfenroll_dom_'.$num
5885: .'" value="'.$currdom.'" /></span><br />'
5886: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 5887: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 5888: .&mt('Delete').'</label></span></td>';
1.249 raeburn 5889: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 5890: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
5891: .&Apache::loncommon::end_data_table_row();
5892: $num ++;
5893: }
5894: }
5895: }
1.249 raeburn 5896: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 5897: if ($curr_types eq '*') {
1.249 raeburn 5898: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 5899: } elsif ($curr_types eq '') {
1.249 raeburn 5900: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 5901: }
5902: $output .= &Apache::loncommon::start_data_table_row()
5903: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
5904: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
5905: $includeempty,$showdomdesc)
5906: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
5907: .'</td>'.&Apache::loncommon::end_data_table_row()
5908: .&Apache::loncommon::end_data_table();
1.237 raeburn 5909: } elsif ($item eq 'registered') {
5910: my ($regon,$regoff);
1.398 raeburn 5911: my $registered;
5912: if (ref($currsettings) eq 'HASH') {
5913: $registered = $currsettings->{'selfenroll_registered'};
5914: }
1.400 ! raeburn 5915: if ($noedit{$item}) {
! 5916: if ($registered) {
! 5917: $output .= &mt('Must be registered in course');
! 5918: } else {
! 5919: $output .= &mt('No requirement');
! 5920: }
! 5921: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
! 5922: next;
! 5923: }
1.398 raeburn 5924: if ($registered) {
1.237 raeburn 5925: $regon = ' checked="checked" ';
5926: $regoff = ' ';
5927: } else {
5928: $regon = ' ';
5929: $regoff = ' checked="checked" ';
5930: }
5931: $output .= '<label>'.
1.245 raeburn 5932: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 5933: &mt('Yes').'</label> <label>'.
1.245 raeburn 5934: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 5935: &mt('No').'</label>';
1.237 raeburn 5936: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 5937: my ($starttime,$endtime);
5938: if (ref($currsettings) eq 'HASH') {
5939: $starttime = $currsettings->{'selfenroll_start_date'};
5940: $endtime = $currsettings->{'selfenroll_end_date'};
5941: if ($starttime eq '') {
5942: $starttime = $currsettings->{'default_enrollment_start_date'};
5943: }
5944: if ($endtime eq '') {
5945: $endtime = $currsettings->{'default_enrollment_end_date'};
5946: }
1.237 raeburn 5947: }
1.400 ! raeburn 5948: if ($noedit{$item}) {
! 5949: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
! 5950: &Apache::lonlocal::locallocaltime($endtime));
! 5951: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
! 5952: next;
! 5953: }
1.237 raeburn 5954: my $startform =
5955: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
5956: undef,undef,undef,undef,undef,undef,undef,$nolink);
5957: my $endform =
5958: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
5959: undef,undef,undef,undef,undef,undef,undef,$nolink);
5960: $output .= &selfenroll_date_forms($startform,$endform);
5961: } elsif ($item eq 'access_dates') {
1.398 raeburn 5962: my ($starttime,$endtime);
5963: if (ref($currsettings) eq 'HASH') {
5964: $starttime = $currsettings->{'selfenroll_start_access'};
5965: $endtime = $currsettings->{'selfenroll_end_access'};
5966: if ($starttime eq '') {
5967: $starttime = $currsettings->{'default_enrollment_start_date'};
5968: }
5969: if ($endtime eq '') {
5970: $endtime = $currsettings->{'default_enrollment_end_date'};
5971: }
1.237 raeburn 5972: }
1.400 ! raeburn 5973: if ($noedit{$item}) {
! 5974: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
! 5975: &Apache::lonlocal::locallocaltime($endtime));
! 5976: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
! 5977: next;
! 5978: }
1.237 raeburn 5979: my $startform =
5980: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
5981: undef,undef,undef,undef,undef,undef,undef,$nolink);
5982: my $endform =
5983: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
5984: undef,undef,undef,undef,undef,undef,undef,$nolink);
5985: $output .= &selfenroll_date_forms($startform,$endform);
5986: } elsif ($item eq 'section') {
1.398 raeburn 5987: my $currsec;
5988: if (ref($currsettings) eq 'HASH') {
5989: $currsec = $currsettings->{'selfenroll_section'};
5990: }
1.237 raeburn 5991: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
5992: my $newsecval;
5993: if ($currsec ne 'none' && $currsec ne '') {
5994: if (!defined($sections_count{$currsec})) {
5995: $newsecval = $currsec;
5996: }
5997: }
1.400 ! raeburn 5998: if ($noedit{$item}) {
! 5999: if ($currsec ne '') {
! 6000: $output .= $currsec;
! 6001: } else {
! 6002: $output .= &mt('No specific section');
! 6003: }
! 6004: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
! 6005: next;
! 6006: }
1.237 raeburn 6007: my $sections_select =
6008: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
6009: $output .= '<table class="LC_createuser">'."\n".
6010: '<tr class="LC_section_row">'."\n".
6011: '<td align="center">'.&mt('Existing sections')."\n".
6012: '<br />'.$sections_select.'</td><td align="center">'.
6013: &mt('New section').'<br />'."\n".
6014: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
6015: '<input type="hidden" name="sections" value="" />'."\n".
6016: '</td></tr></table>'."\n";
1.276 raeburn 6017: } elsif ($item eq 'approval') {
1.398 raeburn 6018: my ($currnotified,$currapproval,%appchecked);
6019: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
6020: if (ref($currsettings) eq 'HASH') {
6021: $currnotified = $currsettings->{'selfenroll_notifylist'};
6022: $currapproval = $currsettings->{'selfenroll_approval'};
6023: }
6024: if ($currapproval !~ /^[012]$/) {
6025: $currapproval = 0;
6026: }
1.400 ! raeburn 6027: if ($noedit{$item}) {
! 6028: $output .= $selfdescs{'approval'}{$currapproval}.
! 6029: '<br />'.&mt('(Set by Domain Coordinator)');
! 6030: next;
! 6031: }
1.398 raeburn 6032: $appchecked{$currapproval} = ' checked="checked"';
6033: for my $i (0..2) {
6034: $output .= '<label>'.
6035: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
6036: $appchecked{$i}.' onclick="toggleNotify();" />'.$selfdescs{'approval'}{$i}.
6037: '</label>'.(' 'x2);
1.276 raeburn 6038: }
6039: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6040: my (@ccs,%notified);
1.322 raeburn 6041: my $ccrole = 'cc';
6042: if ($crstype eq 'Community') {
6043: $ccrole = 'co';
6044: }
6045: if ($advhash{$ccrole}) {
6046: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6047: }
6048: if ($currnotified) {
6049: foreach my $current (split(/,/,$currnotified)) {
6050: $notified{$current} = 1;
6051: if (!grep(/^\Q$current\E$/,@ccs)) {
6052: push(@ccs,$current);
6053: }
6054: }
6055: }
6056: if (@ccs) {
1.398 raeburn 6057: my $style;
6058: unless ($currapproval) {
6059: $style = ' style="display: none;"';
6060: }
6061: $output .= '<br /><div id="notified"'.$style.'>'.
6062: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6063: &Apache::loncommon::start_data_table().
1.276 raeburn 6064: &Apache::loncommon::start_data_table_row();
6065: my $count = 0;
6066: my $numcols = 4;
6067: foreach my $cc (sort(@ccs)) {
6068: my $notifyon;
6069: my ($ccuname,$ccudom) = split(/:/,$cc);
6070: if ($notified{$cc}) {
6071: $notifyon = ' checked="checked" ';
6072: }
6073: if ($count && !$count%$numcols) {
6074: $output .= &Apache::loncommon::end_data_table_row().
6075: &Apache::loncommon::start_data_table_row()
6076: }
6077: $output .= '<td><span class="LC_nobreak"><label>'.
6078: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
6079: &Apache::loncommon::plainname($ccuname,$ccudom).
6080: '</label></span></td>';
1.343 raeburn 6081: $count ++;
1.276 raeburn 6082: }
6083: my $rem = $count%$numcols;
6084: if ($rem) {
6085: my $emptycols = $numcols - $rem;
6086: for (my $i=0; $i<$emptycols; $i++) {
6087: $output .= '<td> </td>';
6088: }
6089: }
6090: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6091: &Apache::loncommon::end_data_table().
6092: '</div>';
1.276 raeburn 6093: }
6094: } elsif ($item eq 'limit') {
1.398 raeburn 6095: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6096: if (ref($currsettings) eq 'HASH') {
6097: $currlim = $currsettings->{'selfenroll_limit'};
6098: $currcap = $currsettings->{'selfenroll_cap'};
6099: }
1.400 ! raeburn 6100: if ($noedit{$item}) {
! 6101: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
! 6102: if ($currlim eq 'allstudents') {
! 6103: $output .= &mt('Limit by total students');
! 6104: } elsif ($currlim eq 'selfenrolled') {
! 6105: $output .= &mt('Limit by total self-enrolled students');
! 6106: }
! 6107: $output .= ' '.&mt('Maximum: [_1]',$currcap).
! 6108: '<br />'.&mt('(Set by Domain Coordinator)');
! 6109: } else {
! 6110: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
! 6111: }
! 6112: next;
! 6113: }
1.276 raeburn 6114: if ($currlim eq 'allstudents') {
6115: $crslimit = ' checked="checked" ';
6116: $selflimit = ' ';
6117: $nolimit = ' ';
6118: } elsif ($currlim eq 'selfenrolled') {
6119: $crslimit = ' ';
6120: $selflimit = ' checked="checked" ';
6121: $nolimit = ' ';
6122: } else {
6123: $crslimit = ' ';
6124: $selflimit = ' ';
1.398 raeburn 6125: $nolimit = ' checked="checked" ';
1.276 raeburn 6126: }
6127: $output .= '<table><tr><td><label>'.
1.278 raeburn 6128: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 6129: &mt('No limit').'</label></td><td><label>'.
6130: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
6131: &mt('Limit by total students').'</label></td><td><label>'.
6132: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
6133: &mt('Limit by total self-enrolled students').
6134: '</td></tr><tr>'.
6135: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6136: (' 'x3).&mt('Maximum number allowed: ').
6137: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 6138: }
6139: $output .= &Apache::lonhtmlcommon::row_closure(1);
6140: }
6141: }
6142: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 6143: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 6144: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.400 ! raeburn 6145: .'<input type="hidden" name="action" value="selfenroll" />'
! 6146: .'<input type="hidden" name="state" value="done" />'."\n".
1.398 raeburn 6147: $additional.'</form>';
1.237 raeburn 6148: $r->print($output);
6149: return;
6150: }
6151:
1.400 ! raeburn 6152: sub get_noedit_fields {
! 6153: my ($cdom,$cnum,$crstype,$row) = @_;
! 6154: my %noedit;
! 6155: if (ref($row) eq 'ARRAY') {
! 6156: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
! 6157: 'internal.selfenrollmgrdc',
! 6158: 'internal.selfenrollmgrcc'],$cdom,$cnum);
! 6159: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
! 6160: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
! 6161: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
! 6162: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
! 6163: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
! 6164: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
! 6165:
! 6166: foreach my $item (@{$row}) {
! 6167: next if ($specific_managebycc{$item});
! 6168: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
! 6169: $noedit{$item} = 1;
! 6170: }
! 6171: }
! 6172: }
! 6173: return %noedit;
! 6174: }
! 6175:
! 6176: sub visible_in_stdcat {
! 6177: my ($cdom,$cnum,$domconf) = @_;
! 6178: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
! 6179: unless (ref($domconf) eq 'HASH') {
! 6180: return ($visible,$cansetvis,\@vismsgs);
! 6181: }
! 6182: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
! 6183: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6184: $settable{'togglecats'} = 1;
6185: }
1.400 ! raeburn 6186: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6187: $settable{'categorize'} = 1;
6188: }
1.400 ! raeburn 6189: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6190: }
1.260 raeburn 6191: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6192: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6193: } elsif ($settable{'togglecats'}) {
6194: $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 6195: } elsif ($settable{'categorize'}) {
1.256 raeburn 6196: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6197: } else {
6198: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6199: }
6200:
6201: my %currsettings =
6202: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6203: $cdom,$cnum);
1.400 ! raeburn 6204: $visible = 0;
1.256 raeburn 6205: if ($currsettings{'internal.coursecode'} ne '') {
1.400 ! raeburn 6206: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
! 6207: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6208: if (ref($cathash) eq 'HASH') {
6209: if ($cathash->{'instcode::0'} eq '') {
6210: push(@vismsgs,'dc_addinst');
6211: } else {
6212: $visible = 1;
6213: }
6214: } else {
6215: $visible = 1;
6216: }
6217: } else {
6218: $visible = 1;
6219: }
6220: } else {
6221: if (ref($cathash) eq 'HASH') {
6222: if ($cathash->{'instcode::0'} ne '') {
6223: push(@vismsgs,'dc_instcode');
6224: }
6225: } else {
6226: push(@vismsgs,'dc_instcode');
6227: }
6228: }
6229: if ($currsettings{'categories'} ne '') {
6230: my $cathash;
1.400 ! raeburn 6231: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
! 6232: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6233: if (ref($cathash) eq 'HASH') {
6234: if (keys(%{$cathash}) == 0) {
6235: push(@vismsgs,'dc_catalog');
6236: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6237: push(@vismsgs,'dc_categories');
6238: } else {
6239: my @currcategories = split('&',$currsettings{'categories'});
6240: my $matched = 0;
6241: foreach my $cat (@currcategories) {
6242: if ($cathash->{$cat} ne '') {
6243: $visible = 1;
6244: $matched = 1;
6245: last;
6246: }
6247: }
6248: if (!$matched) {
1.260 raeburn 6249: if ($settable{'categorize'}) {
1.256 raeburn 6250: push(@vismsgs,'chgcat');
6251: } else {
6252: push(@vismsgs,'dc_chgcat');
6253: }
6254: }
6255: }
6256: }
6257: }
6258: } else {
6259: if (ref($cathash) eq 'HASH') {
6260: if ((keys(%{$cathash}) > 1) ||
6261: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6262: if ($settable{'categorize'}) {
1.256 raeburn 6263: push(@vismsgs,'addcat');
6264: } else {
6265: push(@vismsgs,'dc_addcat');
6266: }
6267: }
6268: }
6269: }
6270: if ($currsettings{'hidefromcat'} eq 'yes') {
6271: $visible = 0;
6272: if ($settable{'togglecats'}) {
6273: unshift(@vismsgs,'unhide');
6274: } else {
6275: unshift(@vismsgs,'dc_unhide')
6276: }
6277: }
1.400 ! raeburn 6278: return ($visible,$cansetvis,\@vismsgs);
! 6279: }
! 6280:
! 6281: sub cat_visibility {
! 6282: my %visactions = &Apache::lonlocal::texthash(
! 6283: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
! 6284: 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.',
! 6285: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
! 6286: none => 'Display of a course catalog is disabled for this domain.',
! 6287: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
! 6288: 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.',
! 6289: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
! 6290: take => 'Take the following action to ensure the course appears in the Catalog:',
! 6291: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
! 6292: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
! 6293: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
! 6294: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
! 6295: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
! 6296: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
! 6297: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
! 6298: 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',
! 6299: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
! 6300: );
! 6301: $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>"');
! 6302: $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>"');
! 6303: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
! 6304: return \%visactions;
1.256 raeburn 6305: }
6306:
1.241 raeburn 6307: sub new_selfenroll_dom_row {
6308: my ($newdom,$num) = @_;
6309: my $domdesc = &Apache::lonnet::domain($newdom);
6310: my $output;
6311: if ($domdesc ne '') {
6312: $output .= &Apache::loncommon::start_data_table_row()
6313: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6314: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6315: .'" value="'.$newdom.'" /></span><br />'
6316: .'<span class="LC_nobreak"><label><input type="checkbox" '
6317: .'name="selfenroll_activate" value="'.$num.'" '
6318: .'onchange="javascript:update_types('
6319: ."'selfenroll_activate','$num'".');" />'
6320: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6321: my @currinsttypes;
6322: $output .= '<td>'.&mt('User types:').'<br />'
6323: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6324: .&Apache::loncommon::end_data_table_row();
6325: }
6326: return $output;
6327: }
6328:
6329: sub selfenroll_inst_types {
6330: my ($num,$currdom,$currinsttypes) = @_;
6331: my $output;
6332: my $numinrow = 4;
6333: my $count = 0;
6334: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6335: my $othervalue = 'any';
1.241 raeburn 6336: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6337: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6338: $othervalue = 'other';
6339: }
1.241 raeburn 6340: $output .= '<table><tr>';
6341: foreach my $type (@{$types}) {
6342: if (($count > 0) && ($count%$numinrow == 0)) {
6343: $output .= '</tr><tr>';
6344: }
6345: if (defined($usertypes->{$type})) {
1.257 raeburn 6346: my $esc_type = &escape($type);
1.241 raeburn 6347: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6348: $esc_type.'" ';
1.241 raeburn 6349: if (ref($currinsttypes) eq 'ARRAY') {
6350: if (@{$currinsttypes} > 0) {
1.249 raeburn 6351: if (grep(/^any$/,@{$currinsttypes})) {
6352: $output .= 'checked="checked"';
1.257 raeburn 6353: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6354: $output .= 'checked="checked"';
6355: }
1.249 raeburn 6356: } else {
6357: $output .= 'checked="checked"';
1.241 raeburn 6358: }
6359: }
6360: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
6361: }
6362: $count ++;
6363: }
6364: if (($count > 0) && ($count%$numinrow == 0)) {
6365: $output .= '</tr><tr>';
6366: }
1.249 raeburn 6367: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6368: if (ref($currinsttypes) eq 'ARRAY') {
6369: if (@{$currinsttypes} > 0) {
1.249 raeburn 6370: if (grep(/^any$/,@{$currinsttypes})) {
6371: $output .= ' checked="checked"';
6372: } elsif ($othervalue eq 'other') {
6373: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6374: $output .= ' checked="checked"';
6375: }
1.241 raeburn 6376: }
1.249 raeburn 6377: } else {
6378: $output .= ' checked="checked"';
1.241 raeburn 6379: }
1.249 raeburn 6380: } else {
6381: $output .= ' checked="checked"';
1.241 raeburn 6382: }
6383: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
6384: }
6385: return $output;
6386: }
6387:
1.237 raeburn 6388: sub selfenroll_date_forms {
6389: my ($startform,$endform) = @_;
6390: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6391: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6392: 'LC_oddrow_value')."\n".
6393: $startform."\n".
6394: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6395: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6396: 'LC_oddrow_value')."\n".
6397: $endform."\n".
6398: &Apache::lonhtmlcommon::row_closure(1).
6399: &Apache::lonhtmlcommon::end_pick_box();
6400: return $output;
6401: }
6402:
1.239 raeburn 6403: sub print_userchangelogs_display {
6404: my ($r,$context,$permission) = @_;
1.363 raeburn 6405: my $formname = 'rolelog';
6406: my ($username,$domain,$crstype,%roleslog);
6407: if ($context eq 'domain') {
6408: $domain = $env{'request.role.domain'};
6409: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6410: } else {
6411: if ($context eq 'course') {
6412: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6413: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6414: $crstype = &Apache::loncommon::course_type();
6415: my %saveable_parameters = ('show' => 'scalar',);
6416: &Apache::loncommon::store_course_settings('roles_log',
6417: \%saveable_parameters);
6418: &Apache::loncommon::restore_course_settings('roles_log',
6419: \%saveable_parameters);
6420: } elsif ($context eq 'author') {
6421: $domain = $env{'user.domain'};
6422: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6423: $username = $env{'user.name'};
6424: } else {
6425: undef($domain);
6426: }
6427: }
6428: if ($domain ne '' && $username ne '') {
6429: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6430: }
6431: }
1.239 raeburn 6432: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6433:
6434: # set defaults
6435: my $now = time();
6436: my $defstart = $now - (7*24*3600); #7 days ago
6437: my %defaults = (
6438: page => '1',
6439: show => '10',
6440: role => 'any',
6441: chgcontext => 'any',
6442: rolelog_start_date => $defstart,
6443: rolelog_end_date => $now,
6444: );
6445: my $more_records = 0;
6446:
6447: # set current
6448: my %curr;
6449: foreach my $item ('show','page','role','chgcontext') {
6450: $curr{$item} = $env{'form.'.$item};
6451: }
6452: my ($startdate,$enddate) =
6453: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6454: $curr{'rolelog_start_date'} = $startdate;
6455: $curr{'rolelog_end_date'} = $enddate;
6456: foreach my $key (keys(%defaults)) {
6457: if ($curr{$key} eq '') {
6458: $curr{$key} = $defaults{$key};
6459: }
6460: }
1.248 raeburn 6461: my (%whodunit,%changed,$version);
6462: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6463: my ($minshown,$maxshown);
1.255 raeburn 6464: $minshown = 1;
1.239 raeburn 6465: my $count = 0;
6466: if ($curr{'show'} ne &mt('all')) {
6467: $maxshown = $curr{'page'} * $curr{'show'};
6468: if ($curr{'page'} > 1) {
6469: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6470: }
6471: }
1.301 bisitz 6472:
1.327 raeburn 6473: # Form Header
6474: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6475: &role_display_filter($context,$formname,$domain,$username,\%curr,
6476: $version,$crstype));
1.327 raeburn 6477:
6478: # Create navigation
6479: my ($nav_script,$nav_links) = &userlogdisplay_nav($formname,\%curr,$more_records);
6480: my $showntableheader = 0;
6481:
6482: # Table Header
6483: my $tableheader =
6484: &Apache::loncommon::start_data_table_header_row()
6485: .'<th> </th>'
6486: .'<th>'.&mt('When').'</th>'
6487: .'<th>'.&mt('Who made the change').'</th>'
6488: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6489: .'<th>'.&mt('Role').'</th>';
6490:
6491: if ($context eq 'course') {
6492: $tableheader .= '<th>'.&mt('Section').'</th>';
6493: }
6494: $tableheader .=
6495: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6496: .'<th>'.&mt('Start').'</th>'
6497: .'<th>'.&mt('End').'</th>'
6498: .&Apache::loncommon::end_data_table_header_row();
6499:
6500: # Display user change log data
1.239 raeburn 6501: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6502: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6503: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
6504: if ($curr{'show'} ne &mt('all')) {
6505: if ($count >= $curr{'page'} * $curr{'show'}) {
6506: $more_records = 1;
6507: last;
6508: }
6509: }
6510: if ($curr{'role'} ne 'any') {
6511: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6512: }
6513: if ($curr{'chgcontext'} ne 'any') {
6514: if ($curr{'chgcontext'} eq 'selfenroll') {
6515: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6516: } else {
6517: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6518: }
6519: }
6520: $count ++;
6521: next if ($count < $minshown);
1.327 raeburn 6522: unless ($showntableheader) {
6523: $r->print($nav_script
6524: .$nav_links
6525: .&Apache::loncommon::start_data_table()
6526: .$tableheader);
6527: $r->rflush();
6528: $showntableheader = 1;
6529: }
1.239 raeburn 6530: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6531: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6532: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6533: }
6534: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6535: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6536: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6537: }
6538: my $sec = $roleslog{$id}{'logentry'}{'section'};
6539: if ($sec eq '') {
6540: $sec = &mt('None');
6541: }
6542: my ($rolestart,$roleend);
6543: if ($roleslog{$id}{'delflag'}) {
6544: $rolestart = &mt('deleted');
6545: $roleend = &mt('deleted');
6546: } else {
6547: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6548: $roleend = $roleslog{$id}{'logentry'}{'end'};
6549: if ($rolestart eq '' || $rolestart == 0) {
6550: $rolestart = &mt('No start date');
6551: } else {
6552: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6553: }
6554: if ($roleend eq '' || $roleend == 0) {
6555: $roleend = &mt('No end date');
6556: } else {
6557: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6558: }
6559: }
6560: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6561: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6562: $chgcontext = 'selfenroll';
6563: }
1.363 raeburn 6564: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6565: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6566: $chgcontext = $lt{$chgcontext};
6567: }
1.327 raeburn 6568: $r->print(
1.301 bisitz 6569: &Apache::loncommon::start_data_table_row()
6570: .'<td>'.$count.'</td>'
6571: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6572: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6573: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6574: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6575: if ($context eq 'course') {
6576: $r->print('<td>'.$sec.'</td>');
6577: }
6578: $r->print(
6579: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6580: .'<td>'.$rolestart.'</td>'
6581: .'<td>'.$roleend.'</td>'
1.327 raeburn 6582: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6583: }
6584:
1.327 raeburn 6585: if ($showntableheader) { # Table footer, if content displayed above
6586: $r->print(&Apache::loncommon::end_data_table()
6587: .$nav_links);
6588: } else { # No content displayed above
1.301 bisitz 6589: $r->print('<p class="LC_info">'
6590: .&mt('There are no records to display.')
6591: .'</p>'
6592: );
1.239 raeburn 6593: }
1.301 bisitz 6594:
1.327 raeburn 6595: # Form Footer
6596: $r->print(
6597: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6598: .'<input type="hidden" name="action" value="changelogs" />'
6599: .'</form>');
6600: return;
6601: }
1.301 bisitz 6602:
1.327 raeburn 6603: sub userlogdisplay_nav {
6604: my ($formname,$curr,$more_records) = @_;
6605: my ($nav_script,$nav_links);
6606: if (ref($curr) eq 'HASH') {
6607: # Create Navigation:
6608: # Navigation Script
6609: $nav_script = <<"ENDSCRIPT";
1.239 raeburn 6610: <script type="text/javascript">
1.301 bisitz 6611: // <![CDATA[
1.239 raeburn 6612: function chgPage(caller) {
6613: if (caller == 'previous') {
6614: document.$formname.page.value --;
6615: }
6616: if (caller == 'next') {
6617: document.$formname.page.value ++;
6618: }
1.327 raeburn 6619: document.$formname.submit();
1.239 raeburn 6620: return;
6621: }
1.301 bisitz 6622: // ]]>
1.239 raeburn 6623: </script>
6624: ENDSCRIPT
1.327 raeburn 6625: # Navigation Buttons
6626: $nav_links = '<p>';
6627: if (($curr->{'page'} > 1) || ($more_records)) {
6628: if ($curr->{'page'} > 1) {
6629: $nav_links .= '<input type="button"'
6630: .' onclick="javascript:chgPage('."'previous'".');"'
6631: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
6632: .'" /> ';
6633: }
6634: if ($more_records) {
6635: $nav_links .= '<input type="button"'
6636: .' onclick="javascript:chgPage('."'next'".');"'
6637: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
6638: .'" />';
6639: }
1.301 bisitz 6640: }
1.327 raeburn 6641: $nav_links .= '</p>';
1.301 bisitz 6642: }
1.327 raeburn 6643: return ($nav_script,$nav_links);
1.239 raeburn 6644: }
6645:
6646: sub role_display_filter {
1.363 raeburn 6647: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
6648: my $lctype;
6649: if ($context eq 'course') {
6650: $lctype = lc($crstype);
6651: }
1.239 raeburn 6652: my $nolink = 1;
6653: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 6654: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 6655: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
6656: (&mt('all'),5,10,20,50,100,1000,10000)).
6657: '</td><td> </td>';
6658: my $startform =
6659: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
6660: $curr->{'rolelog_start_date'},undef,
6661: undef,undef,undef,undef,undef,undef,$nolink);
6662: my $endform =
6663: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
6664: $curr->{'rolelog_end_date'},undef,
6665: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 6666: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 6667: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
6668: '<table><tr><td>'.&mt('After:').
6669: '</td><td>'.$startform.'</td></tr>'.
6670: '<tr><td>'.&mt('Before:').'</td>'.
6671: '<td>'.$endform.'</td></tr></table>'.
6672: '</td>'.
6673: '<td> </td>'.
1.239 raeburn 6674: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
6675: '<select name="role"><option value="any"';
6676: if ($curr->{'role'} eq 'any') {
6677: $output .= ' selected="selected"';
6678: }
6679: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 6680: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 6681: foreach my $role (@roles) {
6682: my $plrole;
6683: if ($role eq 'cr') {
6684: $plrole = &mt('Custom Role');
6685: } else {
1.318 raeburn 6686: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 6687: }
6688: my $selstr = '';
6689: if ($role eq $curr->{'role'}) {
6690: $selstr = ' selected="selected"';
6691: }
6692: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
6693: }
1.301 bisitz 6694: $output .= '</select></td>'.
6695: '<td> </td>'.
6696: '<td valign="top"><b>'.
1.239 raeburn 6697: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 6698: my @posscontexts;
6699: if ($context eq 'course') {
1.376 raeburn 6700: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 6701: } elsif ($context eq 'domain') {
6702: @posscontexts = ('any','domain','requestauthor','domconfig','server');
6703: } else {
6704: @posscontexts = ('any','author','domain');
6705: }
6706: foreach my $chgtype (@posscontexts) {
1.239 raeburn 6707: my $selstr = '';
6708: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 6709: $selstr = ' selected="selected"';
1.239 raeburn 6710: }
1.363 raeburn 6711: if ($context eq 'course') {
1.376 raeburn 6712: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 6713: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
6714: }
1.239 raeburn 6715: }
6716: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 6717: }
1.303 bisitz 6718: $output .= '</select></td>'
6719: .'</tr></table>';
6720:
6721: # Update Display button
6722: $output .= '<p>'
6723: .'<input type="submit" value="'.&mt('Update Display').'" />'
6724: .'</p>';
6725:
6726: # Server version info
1.363 raeburn 6727: my $needsrev = '2.11.0';
6728: if ($context eq 'course') {
6729: $needsrev = '2.7.0';
6730: }
6731:
1.303 bisitz 6732: $output .= '<p class="LC_info">'
6733: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 6734: ,$needsrev);
1.248 raeburn 6735: if ($version) {
1.303 bisitz 6736: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
6737: }
6738: $output .= '</p><hr />';
1.239 raeburn 6739: return $output;
6740: }
6741:
6742: sub rolechg_contexts {
1.363 raeburn 6743: my ($context,$crstype) = @_;
6744: my %lt;
6745: if ($context eq 'course') {
6746: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 6747: any => 'Any',
1.376 raeburn 6748: automated => 'Automated Enrollment',
1.239 raeburn 6749: updatenow => 'Roster Update',
6750: createcourse => 'Course Creation',
6751: course => 'User Management in course',
6752: domain => 'User Management in domain',
1.313 raeburn 6753: selfenroll => 'Self-enrolled',
1.318 raeburn 6754: requestcourses => 'Course Request',
1.239 raeburn 6755: );
1.363 raeburn 6756: if ($crstype eq 'Community') {
6757: $lt{'createcourse'} = &mt('Community Creation');
6758: $lt{'course'} = &mt('User Management in community');
6759: $lt{'requestcourses'} = &mt('Community Request');
6760: }
6761: } elsif ($context eq 'domain') {
6762: %lt = &Apache::lonlocal::texthash (
6763: any => 'Any',
6764: domain => 'User Management in domain',
6765: requestauthor => 'Authoring Request',
6766: server => 'Command line script (DC role)',
6767: domconfig => 'Self-enrolled',
6768: );
6769: } else {
6770: %lt = &Apache::lonlocal::texthash (
6771: any => 'Any',
6772: domain => 'User Management in domain',
6773: author => 'User Management by author',
6774: );
6775: }
1.239 raeburn 6776: return %lt;
6777: }
6778:
1.27 matthew 6779: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 6780: sub user_search_result {
1.221 raeburn 6781: my ($context,$srch) = @_;
1.160 raeburn 6782: my %allhomes;
6783: my %inst_matches;
6784: my %srch_results;
1.181 raeburn 6785: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 6786: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 6787: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 6788: $response = &mt('Invalid search.');
6789: }
6790: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
6791: $response = &mt('Invalid search.');
6792: }
1.177 raeburn 6793: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 6794: $response = &mt('Invalid search.');
6795: }
6796: if ($srch->{'srchterm'} eq '') {
6797: $response = &mt('You must enter a search term.');
6798: }
1.183 raeburn 6799: if ($srch->{'srchterm'} =~ /^\s+$/) {
6800: $response = &mt('Your search term must contain more than just spaces.');
6801: }
1.160 raeburn 6802: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
6803: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 6804: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 6805: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
6806: }
6807: }
6808: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
6809: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 6810: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 6811: my $unamecheck = $srch->{'srchterm'};
6812: if ($srch->{'srchtype'} eq 'contains') {
6813: if ($unamecheck !~ /^\w/) {
6814: $unamecheck = 'a'.$unamecheck;
6815: }
6816: }
6817: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 6818: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
6819: }
1.160 raeburn 6820: }
6821: }
1.180 raeburn 6822: if ($response ne '') {
6823: $response = '<span class="LC_warning">'.$response.'</span>';
6824: }
1.160 raeburn 6825: if ($srch->{'srchin'} eq 'instd') {
6826: my $instd_chk = &directorysrch_check($srch);
6827: if ($instd_chk ne 'ok') {
1.180 raeburn 6828: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
6829: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 6830: }
6831: }
6832: if ($response ne '') {
1.180 raeburn 6833: return ($currstate,$response);
1.160 raeburn 6834: }
6835: if ($srch->{'srchby'} eq 'uname') {
6836: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
6837: if ($env{'form.forcenew'}) {
6838: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
6839: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6840: if ($uhome eq 'no_host') {
6841: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 6842: my $showdom = &display_domain_info($env{'request.role.domain'});
6843: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 6844: } else {
1.179 raeburn 6845: $currstate = 'modify';
1.160 raeburn 6846: }
6847: } else {
1.179 raeburn 6848: $currstate = 'modify';
1.160 raeburn 6849: }
6850: } else {
6851: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 6852: if ($srch->{'srchtype'} eq 'exact') {
6853: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6854: if ($uhome eq 'no_host') {
1.179 raeburn 6855: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6856: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6857: } else {
1.179 raeburn 6858: $currstate = 'modify';
1.310 raeburn 6859: my $uname = $srch->{'srchterm'};
6860: my $udom = $srch->{'srchdomain'};
6861: $srch_results{$uname.':'.$udom} =
6862: { &Apache::lonnet::get('environment',
6863: ['firstname',
6864: 'lastname',
6865: 'permanentemail'],
6866: $udom,$uname)
6867: };
1.162 raeburn 6868: }
6869: } else {
6870: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6871: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6872: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6873: }
6874: } else {
1.167 albertel 6875: my $courseusers = &get_courseusers();
1.162 raeburn 6876: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 6877: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 6878: $currstate = 'modify';
1.162 raeburn 6879: } else {
1.179 raeburn 6880: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6881: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6882: }
1.160 raeburn 6883: } else {
1.167 albertel 6884: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 6885: my ($cuname,$cudomain) = split(/:/,$user);
6886: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 6887: my $matched = 0;
6888: if ($srch->{'srchtype'} eq 'begins') {
6889: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
6890: $matched = 1;
6891: }
6892: } else {
6893: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
6894: $matched = 1;
6895: }
6896: }
6897: if ($matched) {
1.167 albertel 6898: $srch_results{$user} =
6899: {&Apache::lonnet::get('environment',
6900: ['firstname',
6901: 'lastname',
1.194 albertel 6902: 'permanentemail'],
6903: $cudomain,$cuname)};
1.162 raeburn 6904: }
6905: }
6906: }
1.179 raeburn 6907: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6908: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6909: }
6910: }
6911: }
6912: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6913: $currstate = 'query';
1.160 raeburn 6914: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6915: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6916: if ($dirsrchres eq 'ok') {
6917: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6918: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6919: } else {
6920: my $showdom = &display_domain_info($srch->{'srchdomain'});
6921: $response = '<span class="LC_warning">'.
6922: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6923: '</span><br />'.
6924: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6925: '<br /><br />';
6926: }
1.160 raeburn 6927: }
6928: } else {
6929: if ($srch->{'srchin'} eq 'dom') {
6930: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6931: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6932: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6933: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 6934: my $courseusers = &get_courseusers();
6935: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 6936: my ($uname,$udom) = split(/:/,$user);
6937: my %names = &Apache::loncommon::getnames($uname,$udom);
6938: my %emails = &Apache::loncommon::getemails($uname,$udom);
6939: if ($srch->{'srchby'} eq 'lastname') {
6940: if ((($srch->{'srchtype'} eq 'exact') &&
6941: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 6942: (($srch->{'srchtype'} eq 'begins') &&
6943: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 6944: (($srch->{'srchtype'} eq 'contains') &&
6945: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
6946: $srch_results{$user} = {firstname => $names{'firstname'},
6947: lastname => $names{'lastname'},
6948: permanentemail => $emails{'permanentemail'},
6949: };
6950: }
6951: } elsif ($srch->{'srchby'} eq 'lastfirst') {
6952: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 6953: $srchlast =~ s/\s+$//;
6954: $srchfirst =~ s/^\s+//;
1.160 raeburn 6955: if ($srch->{'srchtype'} eq 'exact') {
6956: if (($names{'lastname'} eq $srchlast) &&
6957: ($names{'firstname'} eq $srchfirst)) {
6958: $srch_results{$user} = {firstname => $names{'firstname'},
6959: lastname => $names{'lastname'},
6960: permanentemail => $emails{'permanentemail'},
6961:
6962: };
6963: }
1.177 raeburn 6964: } elsif ($srch->{'srchtype'} eq 'begins') {
6965: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
6966: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
6967: $srch_results{$user} = {firstname => $names{'firstname'},
6968: lastname => $names{'lastname'},
6969: permanentemail => $emails{'permanentemail'},
6970: };
6971: }
6972: } else {
1.160 raeburn 6973: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
6974: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
6975: $srch_results{$user} = {firstname => $names{'firstname'},
6976: lastname => $names{'lastname'},
6977: permanentemail => $emails{'permanentemail'},
6978: };
6979: }
6980: }
6981: }
6982: }
1.179 raeburn 6983: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6984: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6985: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6986: $currstate = 'query';
1.160 raeburn 6987: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6988: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6989: if ($dirsrchres eq 'ok') {
6990: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6991: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6992: } else {
6993: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
6994: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6995: '</span><br />'.
6996: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6997: '<br /><br />';
6998: }
1.160 raeburn 6999: }
7000: }
1.179 raeburn 7001: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 7002: }
7003:
7004: sub directorysrch_check {
7005: my ($srch) = @_;
7006: my $can_search = 0;
7007: my $response;
7008: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
7009: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 7010: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 7011: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
7012: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 7013: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 7014: }
7015: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
7016: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 7017: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 7018: }
7019: my @usertypes = split(/:/,$env{'environment.inststatus'});
7020: if (!@usertypes) {
7021: push(@usertypes,'default');
7022: }
7023: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
7024: foreach my $type (@usertypes) {
7025: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
7026: $can_search = 1;
7027: last;
7028: }
7029: }
7030: }
7031: if (!$can_search) {
7032: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
7033: my @longtypes;
7034: foreach my $item (@usertypes) {
1.229 raeburn 7035: if (defined($insttypes->{$item})) {
7036: push (@longtypes,$insttypes->{$item});
7037: } elsif ($item eq 'default') {
7038: push (@longtypes,&mt('other'));
7039: }
1.160 raeburn 7040: }
7041: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 7042: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 7043: }
1.160 raeburn 7044: } else {
7045: $can_search = 1;
7046: }
7047: } else {
1.180 raeburn 7048: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 7049: }
7050: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 7051: uname => 'username',
1.160 raeburn 7052: lastfirst => 'last name, first name',
1.167 albertel 7053: lastname => 'last name',
1.172 raeburn 7054: contains => 'contains',
1.178 raeburn 7055: exact => 'as exact match to',
7056: begins => 'begins with',
1.160 raeburn 7057: );
7058: if ($can_search) {
7059: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
7060: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 7061: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 7062: }
7063: } else {
1.180 raeburn 7064: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 7065: }
7066: }
7067: if ($can_search) {
1.178 raeburn 7068: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
7069: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
7070: return 'ok';
7071: } else {
1.180 raeburn 7072: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 7073: }
7074: } else {
7075: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
7076: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
7077: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
7078: return 'ok';
7079: } else {
1.180 raeburn 7080: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 7081: }
1.160 raeburn 7082: }
7083: }
7084: }
7085:
7086: sub get_courseusers {
7087: my %advhash;
1.167 albertel 7088: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 7089: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
7090: foreach my $role (sort(keys(%coursepersonnel))) {
7091: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 7092: if (!exists($classlist->{$user})) {
7093: $classlist->{$user} = [];
7094: }
1.160 raeburn 7095: }
7096: }
1.167 albertel 7097: return $classlist;
1.160 raeburn 7098: }
7099:
7100: sub build_search_response {
1.221 raeburn 7101: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 7102: my ($currstate,$response,$forcenewuser);
1.160 raeburn 7103: my %names = (
1.330 bisitz 7104: 'uname' => 'username',
7105: 'lastname' => 'last name',
1.160 raeburn 7106: 'lastfirst' => 'last name, first name',
1.330 bisitz 7107: 'crs' => 'this course',
7108: 'dom' => 'LON-CAPA domain',
7109: 'instd' => 'the institutional directory for domain',
1.160 raeburn 7110: );
7111:
7112: my %single = (
1.180 raeburn 7113: begins => 'A match',
1.160 raeburn 7114: contains => 'A match',
1.180 raeburn 7115: exact => 'An exact match',
1.160 raeburn 7116: );
7117: my %nomatch = (
1.180 raeburn 7118: begins => 'No match',
1.160 raeburn 7119: contains => 'No match',
1.180 raeburn 7120: exact => 'No exact match',
1.160 raeburn 7121: );
7122: if (keys(%srch_results) > 1) {
1.179 raeburn 7123: $currstate = 'select';
1.160 raeburn 7124: } else {
7125: if (keys(%srch_results) == 1) {
1.179 raeburn 7126: $currstate = 'modify';
1.180 raeburn 7127: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
7128: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 7129: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 7130: }
1.330 bisitz 7131: } else { # Search has nothing found. Prepare message to user.
7132: $response = '<span class="LC_warning">';
1.180 raeburn 7133: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 7134: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
7135: '<b>'.$srch->{'srchterm'}.'</b>',
7136: &display_domain_info($srch->{'srchdomain'}));
7137: } else {
7138: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
7139: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 7140: }
7141: $response .= '</span>';
1.330 bisitz 7142:
1.160 raeburn 7143: if ($srch->{'srchin'} ne 'alc') {
7144: $forcenewuser = 1;
7145: my $cansrchinst = 0;
7146: if ($srch->{'srchdomain'}) {
7147: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
7148: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7149: if ($domconfig{'directorysrch'}{'available'}) {
7150: $cansrchinst = 1;
7151: }
7152: }
7153: }
1.180 raeburn 7154: if ((($srch->{'srchby'} eq 'lastfirst') ||
7155: ($srch->{'srchby'} eq 'lastname')) &&
7156: ($srch->{'srchin'} eq 'dom')) {
7157: if ($cansrchinst) {
7158: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 7159: }
7160: }
1.180 raeburn 7161: if ($srch->{'srchin'} eq 'crs') {
7162: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
7163: }
7164: }
1.305 raeburn 7165: my $createdom = $env{'request.role.domain'};
7166: if ($context eq 'requestcrs') {
7167: if ($env{'form.coursedom'} ne '') {
7168: $createdom = $env{'form.coursedom'};
7169: }
7170: }
7171: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $createdom)) {
1.221 raeburn 7172: my $cancreate =
1.305 raeburn 7173: &Apache::lonuserutils::can_create_user($createdom,$context);
7174: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 7175: if ($cancreate) {
1.305 raeburn 7176: my $showdom = &display_domain_info($createdom);
1.266 bisitz 7177: $response .= '<br /><br />'
7178: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 7179: .'<br />';
7180: if ($context eq 'requestcrs') {
7181: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
7182: } else {
7183: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
7184: }
7185: $response .='<ul><li>'
1.266 bisitz 7186: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
7187: .'</li><li>'
7188: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
7189: .'</li><li>'
7190: .&mt('Provide the proposed username')
7191: .'</li><li>'
7192: .&mt("Click 'Search'")
7193: .'</li></ul><br />';
1.221 raeburn 7194: } else {
7195: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.305 raeburn 7196: $response .= '<br /><br />';
7197: if ($context eq 'requestcrs') {
1.314 raeburn 7198: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.305 raeburn 7199: } else {
7200: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
7201: }
7202: $response .= '<br />'
7203: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 7204: ,' <a'.$helplink.'>'
7205: ,'</a>')
1.305 raeburn 7206: .'<br /><br />';
1.221 raeburn 7207: }
1.160 raeburn 7208: }
7209: }
7210: }
1.179 raeburn 7211: return ($currstate,$response,$forcenewuser);
1.160 raeburn 7212: }
7213:
1.180 raeburn 7214: sub display_domain_info {
7215: my ($dom) = @_;
7216: my $output = $dom;
7217: if ($dom ne '') {
7218: my $domdesc = &Apache::lonnet::domain($dom,'description');
7219: if ($domdesc ne '') {
7220: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
7221: }
7222: }
7223: return $output;
7224: }
7225:
1.160 raeburn 7226: sub crumb_utilities {
7227: my %elements = (
7228: crtuser => {
7229: srchterm => 'text',
1.172 raeburn 7230: srchin => 'selectbox',
1.160 raeburn 7231: srchby => 'selectbox',
7232: srchtype => 'selectbox',
7233: srchdomain => 'selectbox',
7234: },
1.207 raeburn 7235: crtusername => {
7236: srchterm => 'text',
7237: srchdomain => 'selectbox',
7238: },
1.160 raeburn 7239: docustom => {
7240: rolename => 'selectbox',
7241: newrolename => 'textbox',
7242: },
1.179 raeburn 7243: studentform => {
7244: srchterm => 'text',
7245: srchin => 'selectbox',
7246: srchby => 'selectbox',
7247: srchtype => 'selectbox',
7248: srchdomain => 'selectbox',
7249: },
1.160 raeburn 7250: );
7251:
7252: my $jsback .= qq|
7253: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 7254: if (typeof prevphase == 'undefined') {
7255: formname.phase.value = '';
7256: }
7257: else {
7258: formname.phase.value = prevphase;
7259: }
7260: if (typeof prevstate == 'undefined') {
7261: formname.currstate.value = '';
7262: }
7263: else {
7264: formname.currstate.value = prevstate;
7265: }
1.160 raeburn 7266: formname.submit();
7267: }
7268: |;
7269: return ($jsback,\%elements);
7270: }
7271:
1.26 matthew 7272: sub course_level_table {
1.375 raeburn 7273: my ($inccourses,$showcredits,$defaultcredits) = @_;
7274: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 7275: my $table = '';
1.62 www 7276: # Custom Roles?
7277:
1.190 raeburn 7278: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 7279: my %lt=&Apache::lonlocal::texthash(
7280: 'exs' => "Existing sections",
7281: 'new' => "Define new section",
7282: 'ssd' => "Set Start Date",
7283: 'sed' => "Set End Date",
1.131 raeburn 7284: 'crl' => "Course Level",
1.89 raeburn 7285: 'act' => "Activate",
7286: 'rol' => "Role",
7287: 'ext' => "Extent",
1.113 raeburn 7288: 'grs' => "Section",
1.375 raeburn 7289: 'crd' => "Credits",
1.89 raeburn 7290: 'sta' => "Start",
7291: 'end' => "End"
7292: );
1.62 www 7293:
1.375 raeburn 7294: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 7295: my $thiscourse=$protectedcourse;
1.26 matthew 7296: $thiscourse=~s:_:/:g;
7297: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 7298: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 7299: my $area=$coursedata{'description'};
1.321 raeburn 7300: my $crstype=$coursedata{'type'};
1.135 raeburn 7301: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 7302: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 7303: my %sections_count;
1.101 albertel 7304: if (defined($env{'request.course.id'})) {
7305: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 7306: %sections_count =
7307: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 7308: }
7309: }
1.321 raeburn 7310: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 7311: foreach my $role (@roles) {
1.321 raeburn 7312: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 7313: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
7314: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 7315: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 7316: $plrole,\%sections_count,\%lt,
7317: $defaultcredits,$crstype);
1.221 raeburn 7318: } elsif ($env{'request.course.sec'} ne '') {
7319: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
7320: $env{'request.course.sec'})) {
7321: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 7322: $plrole,\%sections_count,\%lt,
7323: $defaultcredits,$crstype);
1.26 matthew 7324: }
7325: }
7326: }
1.221 raeburn 7327: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 7328: foreach my $cust (sort(keys(%customroles))) {
7329: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 7330: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
7331: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
7332: $cust,\%sections_count,\%lt);
7333: }
1.62 www 7334: }
1.26 matthew 7335: }
7336: return '' if ($table eq ''); # return nothing if there is nothing
7337: # in the table
1.188 raeburn 7338: my $result;
7339: if (!$env{'request.course.id'}) {
7340: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
7341: }
7342: $result .=
1.136 raeburn 7343: &Apache::loncommon::start_data_table().
7344: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 7345: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
7346: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'crd'}.'</th>'."\n".
7347: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
7348: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 7349: &Apache::loncommon::end_data_table_header_row().
7350: $table.
7351: &Apache::loncommon::end_data_table();
1.26 matthew 7352: return $result;
7353: }
1.88 raeburn 7354:
1.221 raeburn 7355: sub course_level_row {
1.375 raeburn 7356: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
7357: $lt,$defaultcredits,$crstype) = @_;
7358: my $creditem;
1.222 raeburn 7359: my $row = &Apache::loncommon::start_data_table_row().
7360: ' <td><input type="checkbox" name="act_'.
7361: $protectedcourse.'_'.$role.'" /></td>'."\n".
7362: ' <td>'.$plrole.'</td>'."\n".
7363: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.375 raeburn 7364: if (($role eq 'st') && ($crstype eq 'Course')) {
7365: $row .=
7366: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
7367: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
7368: } else {
7369: $row .= '<td> </td>';
7370: }
1.322 raeburn 7371: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 7372: $row .= '<td> </td>';
1.221 raeburn 7373: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 7374: $row .= ' <td><input type="hidden" value="'.
7375: $env{'request.course.sec'}.'" '.
7376: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
7377: $env{'request.course.sec'}.'</td>';
1.221 raeburn 7378: } else {
7379: if (ref($sections_count) eq 'HASH') {
7380: my $currsec =
7381: &Apache::lonuserutils::course_sections($sections_count,
7382: $protectedcourse.'_'.$role);
1.222 raeburn 7383: $row .= '<td><table class="LC_createuser">'."\n".
7384: '<tr class="LC_section_row">'."\n".
7385: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
7386: $currsec.'</td>'."\n".
7387: ' <td> </td>'."\n".
7388: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 7389: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
7390: '" value="" />'.
7391: '<input type="hidden" '.
7392: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 7393: '</tr></table></td>'."\n";
1.221 raeburn 7394: } else {
1.222 raeburn 7395: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 7396: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 7397: }
7398: }
1.222 raeburn 7399: $row .= <<ENDTIMEENTRY;
7400: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 7401: <a href=
7402: "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 7403: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 7404: <a href=
7405: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
7406: ENDTIMEENTRY
1.222 raeburn 7407: $row .= &Apache::loncommon::end_data_table_row();
7408: return $row;
1.221 raeburn 7409: }
7410:
1.88 raeburn 7411: sub course_level_dc {
1.375 raeburn 7412: my ($dcdom,$showcredits) = @_;
1.190 raeburn 7413: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 7414: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 7415: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
7416: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 7417: '<input type="hidden" name="dccourse" value="" />';
1.355 www 7418: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 7419: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 7420: my $credit_elem;
7421: if ($showcredits) {
7422: $credit_elem = 'credits';
7423: }
7424: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 7425: my %lt=&Apache::lonlocal::texthash(
7426: 'rol' => "Role",
1.113 raeburn 7427: 'grs' => "Section",
1.88 raeburn 7428: 'exs' => "Existing sections",
7429: 'new' => "Define new section",
7430: 'sta' => "Start",
7431: 'end' => "End",
7432: 'ssd' => "Set Start Date",
1.355 www 7433: 'sed' => "Set End Date",
1.375 raeburn 7434: 'scc' => "Course/Community",
7435: 'crd' => "Credits",
1.88 raeburn 7436: );
1.323 raeburn 7437: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 7438: &Apache::loncommon::start_data_table().
7439: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 7440: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 7441: '<th>'.$lt{'grs'}.'</th>'."\n";
7442: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
7443: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 7444: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 7445: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 7446: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
7447: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 7448: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 7449: foreach my $role (@roles) {
1.135 raeburn 7450: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 7451: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 7452: }
7453: if ( keys %customroles > 0) {
1.135 raeburn 7454: foreach my $cust (sort keys %customroles) {
1.101 albertel 7455: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 7456: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 7457: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 7458: }
7459: }
7460: $otheritems .= '</select></td><td>'.
7461: '<table border="0" cellspacing="0" cellpadding="0">'.
7462: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 7463: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 7464: '<td> </td>'.
7465: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 7466: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 7467: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 7468: '<input type="hidden" name="groups" value="" />'.
7469: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 7470: '</tr></table></td>'."\n";
7471: if ($showcredits) {
7472: $otheritems .= '<td><br />'."\n".
1.397 bisitz 7473: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 7474: }
1.88 raeburn 7475: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 7476: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 7477: <a href=
7478: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 7479: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 7480: <a href=
7481: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
7482: ENDTIMEENTRY
1.136 raeburn 7483: $otheritems .= &Apache::loncommon::end_data_table_row().
7484: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 7485: return $cb_jscript.$header.$hiddenitems.$otheritems;
7486: }
7487:
1.237 raeburn 7488: sub update_selfenroll_config {
1.400 ! raeburn 7489: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 7490: return unless (ref($currsettings) eq 'HASH');
7491: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
7492: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 7493: my (%changes,%warning);
1.241 raeburn 7494: my $curr_types;
1.400 ! raeburn 7495: my %noedit;
! 7496: unless ($context eq 'domain') {
! 7497: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
! 7498: }
1.237 raeburn 7499: if (ref($row) eq 'ARRAY') {
7500: foreach my $item (@{$row}) {
1.400 ! raeburn 7501: next if ($noedit{$item});
1.237 raeburn 7502: if ($item eq 'enroll_dates') {
7503: my (%currenrolldate,%newenrolldate);
7504: foreach my $type ('start','end') {
1.398 raeburn 7505: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 7506: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
7507: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
7508: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
7509: }
7510: }
7511: } elsif ($item eq 'access_dates') {
7512: my (%currdate,%newdate);
7513: foreach my $type ('start','end') {
1.398 raeburn 7514: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 7515: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
7516: if ($newdate{$type} ne $currdate{$type}) {
7517: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
7518: }
7519: }
1.241 raeburn 7520: } elsif ($item eq 'types') {
1.398 raeburn 7521: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 7522: if ($env{'form.selfenroll_all'}) {
7523: if ($curr_types ne '*') {
7524: $changes{'internal.selfenroll_types'} = '*';
7525: } else {
7526: next;
7527: }
7528: } else {
1.249 raeburn 7529: my %currdoms;
1.241 raeburn 7530: my @entries = split(/;/,$curr_types);
7531: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 7532: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 7533: my $newnum = 0;
1.249 raeburn 7534: my @latesttypes;
7535: foreach my $num (@activations) {
7536: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
7537: if (@types > 0) {
1.241 raeburn 7538: @types = sort(@types);
7539: my $typestr = join(',',@types);
1.249 raeburn 7540: my $typedom = $env{'form.selfenroll_dom_'.$num};
7541: $latesttypes[$newnum] = $typedom.':'.$typestr;
7542: $currdoms{$typedom} = 1;
1.241 raeburn 7543: $newnum ++;
7544: }
7545: }
1.338 raeburn 7546: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
7547: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 7548: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
7549: if (@types > 0) {
7550: @types = sort(@types);
7551: my $typestr = join(',',@types);
7552: my $typedom = $env{'form.selfenroll_dom_'.$j};
7553: $latesttypes[$newnum] = $typedom.':'.$typestr;
7554: $currdoms{$typedom} = 1;
7555: $newnum ++;
7556: }
7557: }
7558: }
7559: if ($env{'form.selfenroll_newdom'} ne '') {
7560: my $typedom = $env{'form.selfenroll_newdom'};
7561: if ((!defined($currdoms{$typedom})) &&
7562: (&Apache::lonnet::domain($typedom) ne '')) {
7563: my $typestr;
7564: my ($othertitle,$usertypes,$types) =
7565: &Apache::loncommon::sorted_inst_types($typedom);
7566: my $othervalue = 'any';
7567: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7568: if (@{$types} > 0) {
1.257 raeburn 7569: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 7570: $othervalue = 'other';
1.258 raeburn 7571: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 7572: }
7573: $typestr = $othervalue;
7574: } else {
7575: $typestr = $othervalue;
7576: }
7577: $latesttypes[$newnum] = $typedom.':'.$typestr;
7578: $newnum ++ ;
7579: }
7580: }
1.241 raeburn 7581: my $selfenroll_types = join(';',@latesttypes);
7582: if ($selfenroll_types ne $curr_types) {
7583: $changes{'internal.selfenroll_types'} = $selfenroll_types;
7584: }
7585: }
1.276 raeburn 7586: } elsif ($item eq 'limit') {
7587: my $newlimit = $env{'form.selfenroll_limit'};
7588: my $newcap = $env{'form.selfenroll_cap'};
7589: $newcap =~s/\s+//g;
1.398 raeburn 7590: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 7591: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 7592: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 7593: if ($newlimit ne $currlimit) {
7594: if ($newlimit ne 'none') {
7595: if ($newcap =~ /^\d+$/) {
7596: if ($newcap ne $currcap) {
7597: $changes{'internal.selfenroll_cap'} = $newcap;
7598: }
7599: $changes{'internal.selfenroll_limit'} = $newlimit;
7600: } else {
1.398 raeburn 7601: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
7602: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 7603: }
7604: } elsif ($currcap ne '') {
7605: $changes{'internal.selfenroll_cap'} = '';
7606: $changes{'internal.selfenroll_limit'} = $newlimit;
7607: }
7608: } elsif ($currlimit ne 'none') {
7609: if ($newcap =~ /^\d+$/) {
7610: if ($newcap ne $currcap) {
7611: $changes{'internal.selfenroll_cap'} = $newcap;
7612: }
7613: } else {
1.398 raeburn 7614: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
7615: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 7616: }
7617: }
7618: } elsif ($item eq 'approval') {
7619: my (@currnotified,@newnotified);
1.398 raeburn 7620: my $currapproval = $currsettings->{'selfenroll_approval'};
7621: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 7622: if ($currnotifylist ne '') {
7623: @currnotified = split(/,/,$currnotifylist);
7624: @currnotified = sort(@currnotified);
7625: }
7626: my $newapproval = $env{'form.selfenroll_approval'};
7627: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
7628: @newnotified = sort(@newnotified);
7629: if ($newapproval ne $currapproval) {
7630: $changes{'internal.selfenroll_approval'} = $newapproval;
7631: if (!$newapproval) {
7632: if ($currnotifylist ne '') {
7633: $changes{'internal.selfenroll_notifylist'} = '';
7634: }
7635: } else {
7636: my @differences =
1.295 raeburn 7637: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 7638: if (@differences > 0) {
7639: if (@newnotified > 0) {
7640: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7641: } else {
7642: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7643: }
7644: }
7645: }
7646: } else {
1.295 raeburn 7647: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 7648: if (@differences > 0) {
7649: if (@newnotified > 0) {
7650: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7651: } else {
7652: $changes{'internal.selfenroll_notifylist'} = '';
7653: }
7654: }
7655: }
1.237 raeburn 7656: } else {
1.398 raeburn 7657: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 7658: my $newval = $env{'form.selfenroll_'.$item};
7659: if ($item eq 'section') {
7660: $newval = $env{'form.sections'};
1.241 raeburn 7661: if (defined($curr_groups{$newval})) {
1.237 raeburn 7662: $newval = $curr_val;
1.398 raeburn 7663: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
7664: &mt('Group names and section names must be distinct');
1.237 raeburn 7665: } elsif ($newval eq 'all') {
7666: $newval = $curr_val;
1.274 bisitz 7667: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 7668: }
7669: if ($newval eq '') {
7670: $newval = 'none';
7671: }
7672: }
7673: if ($newval ne $curr_val) {
7674: $changes{'internal.selfenroll_'.$item} = $newval;
7675: }
1.241 raeburn 7676: }
1.237 raeburn 7677: }
7678: if (keys(%warning) > 0) {
7679: foreach my $item (@{$row}) {
7680: if (exists($warning{$item})) {
7681: $r->print($warning{$item}.'<br />');
7682: }
7683: }
7684: }
7685: if (keys(%changes) > 0) {
7686: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
7687: if ($putresult eq 'ok') {
7688: if ((exists($changes{'internal.selfenroll_types'})) ||
7689: (exists($changes{'internal.selfenroll_start_date'})) ||
7690: (exists($changes{'internal.selfenroll_end_date'}))) {
7691: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
7692: $cnum,undef,undef,'Course');
7693: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 7694: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 7695: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
7696: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 7697: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 7698: }
7699: }
7700: my $crsputresult =
7701: &Apache::lonnet::courseidput($cdom,\%crsinfo,
7702: $chome,'notime');
7703: }
7704: }
7705: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
7706: foreach my $item (@{$row}) {
7707: my $title = $item;
7708: if (ref($lt) eq 'HASH') {
7709: $title = $lt->{$item};
7710: }
7711: if ($item eq 'enroll_dates') {
7712: foreach my $type ('start','end') {
7713: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
7714: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 7715: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 7716: $title,$type,$newdate).'</li>');
7717: }
7718: }
7719: } elsif ($item eq 'access_dates') {
7720: foreach my $type ('start','end') {
7721: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
7722: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 7723: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 7724: $title,$type,$newdate).'</li>');
7725: }
7726: }
1.276 raeburn 7727: } elsif ($item eq 'limit') {
7728: if ((exists($changes{'internal.selfenroll_limit'})) ||
7729: (exists($changes{'internal.selfenroll_cap'}))) {
7730: my ($newval,$newcap);
7731: if ($changes{'internal.selfenroll_cap'} ne '') {
7732: $newcap = $changes{'internal.selfenroll_cap'}
7733: } else {
1.398 raeburn 7734: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 7735: }
7736: if ($changes{'internal.selfenroll_limit'} eq 'none') {
7737: $newval = &mt('No limit');
7738: } elsif ($changes{'internal.selfenroll_limit'} eq
7739: 'allstudents') {
7740: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
7741: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
7742: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
7743: } else {
1.398 raeburn 7744: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 7745: if ($currlimit eq 'allstudents') {
7746: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
7747: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 7748: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 7749: }
7750: }
7751: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
7752: }
7753: } elsif ($item eq 'approval') {
7754: if ((exists($changes{'internal.selfenroll_approval'})) ||
7755: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 7756: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 7757: my ($newval,$newnotify);
7758: if (exists($changes{'internal.selfenroll_notifylist'})) {
7759: $newnotify = $changes{'internal.selfenroll_notifylist'};
7760: } else {
1.398 raeburn 7761: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 7762: }
1.398 raeburn 7763: if (exists($changes{'internal.selfenroll_approval'})) {
7764: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
7765: $changes{'internal.selfenroll_approval'} = '0';
7766: }
7767: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 7768: } else {
1.398 raeburn 7769: my $currapproval = $currsettings->{'selfenroll_approval'};
7770: if ($currapproval !~ /^[012]$/) {
7771: $currapproval = 0;
1.276 raeburn 7772: }
1.398 raeburn 7773: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 7774: }
7775: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
7776: if ($newnotify) {
1.277 raeburn 7777: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 7778: } else {
1.277 raeburn 7779: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 7780: }
7781: $r->print('</li>'."\n");
7782: }
1.237 raeburn 7783: } else {
7784: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 7785: my $newval = $changes{'internal.selfenroll_'.$item};
7786: if ($item eq 'types') {
7787: if ($newval eq '') {
7788: $newval = &mt('None');
7789: } elsif ($newval eq '*') {
7790: $newval = &mt('Any user in any domain');
7791: }
1.245 raeburn 7792: } elsif ($item eq 'registered') {
7793: if ($newval eq '1') {
7794: $newval = &mt('Yes');
7795: } elsif ($newval eq '0') {
7796: $newval = &mt('No');
7797: }
1.241 raeburn 7798: }
1.244 bisitz 7799: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 7800: }
7801: }
7802: }
7803: $r->print('</ul>');
1.398 raeburn 7804: if ($env{'course.'.$cid.'.description'} ne '') {
7805: my %newenvhash;
7806: foreach my $key (keys(%changes)) {
7807: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
7808: }
7809: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 7810: }
7811: } else {
1.398 raeburn 7812: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
7813: &mt('The error was: [_1].',$putresult));
1.237 raeburn 7814: }
7815: } else {
1.249 raeburn 7816: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 7817: }
7818: } else {
1.249 raeburn 7819: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 7820: }
1.400 ! raeburn 7821: my $visactions = &cat_visibility();
! 7822: my ($cathash,%cattype);
! 7823: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
! 7824: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
! 7825: $cathash = $domconfig{'coursecategories'}{'cats'};
! 7826: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
! 7827: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
! 7828: } else {
! 7829: $cathash = {};
! 7830: $cattype{'auth'} = 'std';
! 7831: $cattype{'unauth'} = 'std';
! 7832: }
! 7833: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
! 7834: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
! 7835: '<br />'.
! 7836: '<br />'.$visactions->{'take'}.'<ul>'.
! 7837: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
! 7838: '</ul>');
! 7839: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
! 7840: if ($currsettings->{'uniquecode'}) {
! 7841: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
! 7842: } else {
1.366 bisitz 7843: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 ! raeburn 7844: '<br />'.
! 7845: '<br />'.$visactions->{'take'}.'<ul>'.
! 7846: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
! 7847: '</ul><br />');
! 7848: }
! 7849: } else {
! 7850: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
! 7851: if (ref($visactions) eq 'HASH') {
! 7852: if (!$visible) {
! 7853: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
! 7854: '<br />');
! 7855: if (ref($vismsgs) eq 'ARRAY') {
! 7856: $r->print('<br />'.$visactions->{'take'}.'<ul>');
! 7857: foreach my $item (@{$vismsgs}) {
! 7858: $r->print('<li>'.$visactions->{$item}.'</li>');
! 7859: }
! 7860: $r->print('</ul>');
1.256 raeburn 7861: }
1.400 ! raeburn 7862: $r->print($cansetvis);
1.256 raeburn 7863: }
7864: }
7865: }
1.237 raeburn 7866: return;
7867: }
7868:
1.27 matthew 7869: #---------------------------------------------- end functions for &phase_two
1.29 matthew 7870:
7871: #--------------------------------- functions for &phase_two and &phase_three
7872:
7873: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 7874:
1.1 www 7875: 1;
7876: __END__
1.2 www 7877:
7878:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>