Annotation of loncom/interface/loncreateuser.pm, revision 1.390
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.390 ! bisitz 4: # $Id: loncreateuser.pm,v 1.389 2014/02/10 18:39:29 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.206 raeburn 1274: my $personal_table =
1.210 raeburn 1275: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1276: $inst_results{$ccuname.':'.$ccdomain});
1.388 bisitz 1277: # (Do not offer Disable Safeguard here)
1.206 raeburn 1278: $r->print($personal_table);
1.187 raeburn 1279: my ($home_server_pick,$numlib) =
1280: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1281: 'default','hide');
1282: if ($numlib > 1) {
1283: $r->print("
1.185 raeburn 1284: <br />
1.187 raeburn 1285: $lt{'hs'}: $home_server_pick
1286: <br />");
1287: } else {
1288: $r->print($home_server_pick);
1289: }
1.304 raeburn 1290: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1291: $r->print('<br /><h3>'.
1292: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1293: &Apache::loncommon::start_data_table().
1294: &build_tools_display($ccuname,$ccdomain,
1295: 'requestcourses').
1296: &Apache::loncommon::end_data_table());
1297: }
1.188 raeburn 1298: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1299: $lt{'lg'}.'</h3>');
1.185 raeburn 1300: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1301: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1302: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1303: my ($rules,$ruleorder) =
1304: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1305: if (ref($rules) eq 'HASH') {
1.193 raeburn 1306: if (ref($rules->{$matchedrule}) eq 'HASH') {
1307: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1308: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1309: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1310: } else {
1.193 raeburn 1311: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1312: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1313: if ($authtype =~ /^krb(4|5)$/) {
1314: my $ver = $1;
1315: if ($authparm ne '') {
1316: $fixedauth = <<"KERB";
1317: <input type="hidden" name="login" value="krb" />
1318: <input type="hidden" name="krbver" value="$ver" />
1319: <input type="hidden" name="krbarg" value="$authparm" />
1320: KERB
1321: }
1322: } else {
1323: $fixedauth =
1324: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1325: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1326: $fixedauth .=
1327: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1328: } else {
1.273 raeburn 1329: if ($authtype eq 'int') {
1330: $varauth = '<br />'.
1.301 bisitz 1331: &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 1332: } elsif ($authtype eq 'loc') {
1333: $varauth = '<br />'.
1334: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1335: } else {
1336: $varauth =
1.185 raeburn 1337: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1338: }
1.185 raeburn 1339: }
1340: }
1341: }
1342: } else {
1.190 raeburn 1343: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1344: }
1345: }
1346: if ($authmsg) {
1347: $r->print(<<ENDAUTH);
1348: $fixedauth
1349: $authmsg
1350: $varauth
1351: ENDAUTH
1352: }
1353: } else {
1.190 raeburn 1354: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1355: }
1.362 raeburn 1356: $r->print($portfolioform.$domroleform);
1.215 raeburn 1357: if ($env{'form.action'} eq 'singlestudent') {
1358: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1359: $permission,$crstype,$ccuname,
1360: $ccdomain,$showcredits));
1.215 raeburn 1361: }
1362: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1363: } else { # user already exists
1.389 bisitz 1364: $r->print($start_page.$forminfo);
1.213 raeburn 1365: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1366: if ($crstype eq 'Community') {
1.389 bisitz 1367: $title = &mt('Enroll one member: [_1] in domain [_2]',
1368: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1369: } else {
1.389 bisitz 1370: $title = &mt('Enroll one student: [_1] in domain [_2]',
1371: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1372: }
1.213 raeburn 1373: } else {
1.389 bisitz 1374: $title = &mt('Modify existing user: [_1] in domain [_2]',
1375: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1376: }
1.389 bisitz 1377: $r->print('<h2>'.$title.'</h2>'."\n");
1378: $r->print('<div class="LC_left_float">');
1.388 bisitz 1379: my $personal_table =
1.210 raeburn 1380: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1381: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 1382: $r->print($personal_table);
1.275 raeburn 1383: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1384: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1385: &Apache::loncommon::start_data_table());
1.314 raeburn 1386: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1387: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1388: } else {
1389: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1390: $env{'request.role.domain'}));
1391: }
1392: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1393: }
1.199 raeburn 1394: $r->print('</div>');
1.362 raeburn 1395: my @order = ('auth','quota','tools','requestauthor');
1396: my %user_text;
1397: my ($isadv,$isauthor) =
1398: &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1399: if ((!$isauthor) &&
1.383 raeburn 1400: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))
1401: && ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1402: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1403: }
1404: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1405: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1406: (&Apache::lonnet::allowed('mut',$ccdomain))) {
1.188 raeburn 1407: # Current user has quota modification privileges
1.378 raeburn 1408: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1409: }
1410: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1411: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1412: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1413: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1414: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1415: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1416: );
1.362 raeburn 1417: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1418: <h3>$lt{'dska'}</h3>
1419: $lt{'youd'} $lt{'ichr'}: $ccdomain
1420: ENDNOPORTPRIV
1.267 raeburn 1421: }
1422: }
1423: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1424: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1425: my %lt=&Apache::lonlocal::texthash(
1426: 'utav' => "User Tools Availability",
1.361 raeburn 1427: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1428: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1429: );
1.362 raeburn 1430: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1431: <h3>$lt{'utav'}</h3>
1432: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1433: ENDNOTOOLSPRIV
1434: }
1.188 raeburn 1435: }
1.362 raeburn 1436: my $gotdiv = 0;
1437: foreach my $item (@order) {
1438: if ($user_text{$item} ne '') {
1439: unless ($gotdiv) {
1440: $r->print('<div class="LC_left_float">');
1441: $gotdiv = 1;
1442: }
1443: $r->print('<br />'.$user_text{$item});
1444: }
1445: }
1446: if ($env{'form.action'} eq 'singlestudent') {
1447: unless ($gotdiv) {
1448: $r->print('<div class="LC_left_float">');
1.213 raeburn 1449: }
1.375 raeburn 1450: my $credits;
1451: if ($showcredits) {
1452: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1453: if ($credits eq '') {
1454: $credits = $defaultcredits;
1455: }
1456: }
1.374 raeburn 1457: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1458: $permission,$crstype,$ccuname,
1459: $ccdomain,$showcredits));
1.374 raeburn 1460: }
1.362 raeburn 1461: if ($gotdiv) {
1462: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1463: }
1.217 raeburn 1464: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1465: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1466: $roledom,$crstype);
1.217 raeburn 1467: }
1.25 matthew 1468: } ## End of new user/old user logic
1.218 raeburn 1469: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1470: my $btntxt;
1471: if ($crstype eq 'Community') {
1472: $btntxt = &mt('Enroll Member');
1473: } else {
1474: $btntxt = &mt('Enroll Student');
1475: }
1476: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.218 raeburn 1477: } else {
1.375 raeburn 1478: $r->print('<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1479: my $addrolesdisplay = 0;
1480: if ($context eq 'domain' || $context eq 'author') {
1481: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1482: }
1483: if ($context eq 'domain') {
1.357 raeburn 1484: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1485: if (!$addrolesdisplay) {
1486: $addrolesdisplay = $add_domainroles;
1.2 www 1487: }
1.375 raeburn 1488: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1489: $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1490: } elsif ($context eq 'author') {
1491: if ($addrolesdisplay) {
1.375 raeburn 1492: $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1493: if ($newuser) {
1.301 bisitz 1494: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1495: } else {
1.301 bisitz 1496: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1497: }
1.188 raeburn 1498: } else {
1.375 raeburn 1499: $r->print('</fieldset><br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1500: &mt('Back to previous page').'</a>');
1.188 raeburn 1501: }
1502: } else {
1.375 raeburn 1503: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1504: $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1505: }
1.88 raeburn 1506: }
1.188 raeburn 1507: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1508: $r->print('<input type="hidden" name="currstate" value="" />');
1.352 raeburn 1509: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form>');
1.218 raeburn 1510: return;
1.2 www 1511: }
1.1 www 1512:
1.213 raeburn 1513: sub singleuser_breadcrumb {
1.318 raeburn 1514: my ($crstype) = @_;
1.213 raeburn 1515: my %breadcrumb_text;
1516: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1517: if ($crstype eq 'Community') {
1518: $breadcrumb_text{'search'} = 'Enroll a member';
1519: } else {
1520: $breadcrumb_text{'search'} = 'Enroll a student';
1521: }
1.213 raeburn 1522: $breadcrumb_text{'userpicked'} = 'Select a user',
1523: $breadcrumb_text{'modify'} = 'Set section/dates',
1524: } else {
1.229 raeburn 1525: $breadcrumb_text{'search'} = 'Create/modify a user';
1.213 raeburn 1526: $breadcrumb_text{'userpicked'} = 'Select a user',
1527: $breadcrumb_text{'modify'} = 'Set user role',
1528: }
1529: return %breadcrumb_text;
1530: }
1531:
1532: sub date_sections_select {
1.375 raeburn 1533: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1534: $showcredits) = @_;
1535: my $credits;
1536: if ($showcredits) {
1537: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1538: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1539: if ($credits eq '') {
1540: $credits = $defaultcredits;
1541: }
1542: }
1.213 raeburn 1543: my $cid = $env{'request.course.id'};
1544: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1545: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1546: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1547: undef,$formname,$permission);
1548: my $rowtitle = 'Section';
1.375 raeburn 1549: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1550: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1551: $permission,$context,'',$crstype,
1552: $showcredits,$credits);
1.213 raeburn 1553: my $output = $date_table.$secbox;
1554: return $output;
1555: }
1556:
1.216 raeburn 1557: sub validation_javascript {
1.375 raeburn 1558: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1559: $loaditem) = @_;
1560: my $dc_setcourse_code = '';
1561: my $nondc_setsection_code = '';
1562: if ($context eq 'domain') {
1563: my $dcdom = $env{'request.role.domain'};
1564: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1565: $dc_setcourse_code =
1566: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1567: } else {
1.227 raeburn 1568: my $checkauth;
1569: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1570: $checkauth = 1;
1571: }
1572: if ($context eq 'course') {
1573: $nondc_setsection_code =
1574: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1575: undef,$checkauth,
1576: $crstype);
1.227 raeburn 1577: }
1578: if ($checkauth) {
1579: $nondc_setsection_code .=
1580: &Apache::lonuserutils::verify_authen($formname,$context);
1581: }
1.216 raeburn 1582: }
1583: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1584: $nondc_setsection_code,$groupslist);
1585: my ($jsback,$elements) = &crumb_utilities();
1586: $js .= "\n".
1.301 bisitz 1587: '<script type="text/javascript">'."\n".
1588: '// <![CDATA['."\n".
1589: $jsback."\n".
1590: '// ]]>'."\n".
1591: '</script>'."\n";
1.216 raeburn 1592: return $js;
1593: }
1594:
1.217 raeburn 1595: sub display_existing_roles {
1.375 raeburn 1596: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1597: $showcredits) = @_;
1.329 raeburn 1598: my $now=time;
1599: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1600: 'rer' => "Existing Roles",
1601: 'rev' => "Revoke",
1602: 'del' => "Delete",
1603: 'ren' => "Re-Enable",
1604: 'rol' => "Role",
1605: 'ext' => "Extent",
1.375 raeburn 1606: 'crd' => "Credits",
1.217 raeburn 1607: 'sta' => "Start",
1608: 'end' => "End",
1609: );
1.329 raeburn 1610: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1611: if ($context eq 'course' || $context eq 'author') {
1612: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1613: my %roleshash =
1614: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1615: ['active','previous','future'],\@roles,$roledom,1);
1616: foreach my $key (keys(%roleshash)) {
1617: my ($start,$end) = split(':',$roleshash{$key});
1618: next if ($start eq '-1' || $end eq '-1');
1619: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1620: if ($context eq 'course') {
1621: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1622: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1623: } elsif ($context eq 'author') {
1624: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1625: }
1626: my ($newkey,$newvalue,$newrole);
1627: $newkey = '/'.$rdom.'/'.$rnum;
1628: if ($sec ne '') {
1629: $newkey .= '/'.$sec;
1630: }
1631: $newvalue = $role;
1632: if ($role =~ /^cr/) {
1633: $newrole = 'cr';
1634: } else {
1635: $newrole = $role;
1636: }
1637: $newkey .= '_'.$newrole;
1638: if ($start ne '' && $end ne '') {
1639: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1640: } elsif ($end ne '') {
1641: $newvalue .= '_'.$end;
1.329 raeburn 1642: }
1643: $rolesdump{$newkey} = $newvalue;
1644: }
1645: } else {
1.360 raeburn 1646: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1647: }
1648: # Build up table of user roles to allow revocation and re-enabling of roles.
1649: my ($tmp) = keys(%rolesdump);
1650: return if ($tmp =~ /^(con_lost|error)/i);
1651: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1652: my $b1=join('_',(split('_',$b))[1,0]);
1653: return $a1 cmp $b1;
1654: } keys(%rolesdump)) {
1655: next if ($area =~ /^rolesdef/);
1656: my $envkey=$area;
1657: my $role = $rolesdump{$area};
1658: my $thisrole=$area;
1659: $area =~ s/\_\w\w$//;
1660: my ($role_code,$role_end_time,$role_start_time) =
1661: split(/_/,$role);
1.217 raeburn 1662: # Is this a custom role? Get role owner and title.
1.329 raeburn 1663: my ($croleudom,$croleuname,$croletitle)=
1664: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1665: my $allowed=0;
1666: my $delallowed=0;
1667: my $sortkey=$role_code;
1668: my $class='Unknown';
1.375 raeburn 1669: my $credits='';
1.329 raeburn 1670: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
1671: $class='Course';
1672: my ($coursedom,$coursedir) = ($1,$2);
1673: my $cid = $1.'_'.$2;
1674: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1675: my %coursedata=
1676: &Apache::lonnet::coursedescription($cid);
1677: if ($coursedir =~ /^$match_community$/) {
1678: $class='Community';
1679: }
1680: $sortkey.="\0$coursedom";
1681: my $carea;
1682: if (defined($coursedata{'description'})) {
1683: $carea=$coursedata{'description'}.
1684: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1685: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1686: $sortkey.="\0".$coursedata{'description'};
1687: } else {
1688: if ($class eq 'Community') {
1689: $carea=&mt('Unavailable community').': '.$area;
1690: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1691: } else {
1692: $carea=&mt('Unavailable course').': '.$area;
1693: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1694: }
1.329 raeburn 1695: }
1696: $sortkey.="\0$coursedir";
1697: $inccourses->{$cid}=1;
1.375 raeburn 1698: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1699: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1700: $credits =
1701: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1702: $coursedom,$coursedir);
1703: if ($credits eq '') {
1704: $credits = $defaultcredits;
1705: }
1706: }
1.329 raeburn 1707: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1708: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1709: $allowed=1;
1710: }
1711: unless ($allowed) {
1.365 raeburn 1712: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1713: if ($isowner) {
1714: if (($role_code eq 'co') && ($class eq 'Community')) {
1715: $allowed = 1;
1716: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1717: $allowed = 1;
1718: }
1.217 raeburn 1719: }
1.329 raeburn 1720: }
1721: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1722: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1723: $delallowed=1;
1724: }
1.217 raeburn 1725: # - custom role. Needs more info, too
1.329 raeburn 1726: if ($croletitle) {
1727: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1728: $allowed=1;
1729: $thisrole.='.'.$role_code;
1.217 raeburn 1730: }
1.329 raeburn 1731: }
1732: if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
1.373 bisitz 1733: $carea.='<br />'.&mt('Section: [_1]',$3);
1.329 raeburn 1734: $sortkey.="\0$3";
1735: if (!$allowed) {
1736: if ($env{'request.course.sec'} eq $3) {
1737: if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
1738: $allowed = 1;
1.217 raeburn 1739: }
1740: }
1741: }
1.329 raeburn 1742: }
1743: $area=$carea;
1744: } else {
1745: $sortkey.="\0".$area;
1746: # Determine if current user is able to revoke privileges
1747: if ($area=~m{^/($match_domain)/}) {
1748: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1749: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1750: $allowed=1;
1.217 raeburn 1751: }
1.329 raeburn 1752: if (((&Apache::lonnet::allowed('dro',$1)) ||
1753: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1754: ($role_code ne 'dc')) {
1755: $delallowed=1;
1.217 raeburn 1756: }
1.329 raeburn 1757: } else {
1758: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1759: $allowed=1;
1760: }
1761: }
1.363 raeburn 1762: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1763: $class='Authoring Space';
1.329 raeburn 1764: } elsif ($role_code eq 'su') {
1765: $class='System';
1.217 raeburn 1766: } else {
1.329 raeburn 1767: $class='Domain';
1.217 raeburn 1768: }
1.329 raeburn 1769: }
1770: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1771: $area=~m{/($match_domain)/($match_username)};
1772: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1773: $allowed=1;
1.217 raeburn 1774: } else {
1.329 raeburn 1775: $allowed=0;
1.217 raeburn 1776: }
1.329 raeburn 1777: }
1778: my $row = '';
1779: $row.= '<td>';
1780: my $active=1;
1781: $active=0 if (($role_end_time) && ($now>$role_end_time));
1782: if (($active) && ($allowed)) {
1783: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1784: } else {
1785: if ($active) {
1786: $row.=' ';
1.217 raeburn 1787: } else {
1.329 raeburn 1788: $row.=&mt('expired or revoked');
1.217 raeburn 1789: }
1.329 raeburn 1790: }
1791: $row.='</td><td>';
1792: if ($allowed && !$active) {
1793: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1794: } else {
1795: $row.=' ';
1796: }
1797: $row.='</td><td>';
1798: if ($delallowed) {
1799: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1800: } else {
1801: $row.=' ';
1802: }
1803: my $plaintext='';
1804: if (!$croletitle) {
1.375 raeburn 1805: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1806: if (($showcredits) && ($credits ne '')) {
1807: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1808: '<span class="LC_fontsize_small">'.
1809: &mt('Credits: [_1]',$credits).
1810: '</span></span>';
1811: }
1.329 raeburn 1812: } else {
1813: $plaintext=
1.346 bisitz 1814: &mt('Customrole [_1][_2]defined by [_3]',
1815: '"'.$croletitle.'"',
1816: '<br />',
1817: $croleuname.':'.$croleudom);
1.329 raeburn 1818: }
1819: $row.= '</td><td>'.$plaintext.
1820: '</td><td>'.$area.
1821: '</td><td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1822: : ' ' ).
1823: '</td><td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1824: : ' ' )
1825: ."</td>";
1826: $sortrole{$sortkey}=$envkey;
1827: $roletext{$envkey}=$row;
1828: $roleclass{$envkey}=$class;
1829: $rolepriv{$envkey}=$allowed;
1830: } # end of foreach (table building loop)
1831:
1832: my $rolesdisplay = 0;
1833: my %output = ();
1.377 raeburn 1834: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1835: $output{$type} = '';
1836: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1837: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1838: $output{$type}.=
1839: &Apache::loncommon::start_data_table_row().
1840: $roletext{$sortrole{$which}}.
1841: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1842: }
1.329 raeburn 1843: }
1844: unless($output{$type} eq '') {
1845: $output{$type} = '<tr class="LC_info_row">'.
1846: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1847: $output{$type};
1848: $rolesdisplay = 1;
1849: }
1850: }
1851: if ($rolesdisplay == 1) {
1852: my $contextrole='';
1853: if ($env{'request.course.id'}) {
1854: if (&Apache::loncommon::course_type() eq 'Community') {
1855: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 1856: } else {
1.329 raeburn 1857: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 1858: }
1.329 raeburn 1859: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 1860: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 1861: } else {
1862: $contextrole = &mt('Existing Roles in this Domain');
1863: }
1.375 raeburn 1864: $r->print('<div>'.
1865: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 1866: &Apache::loncommon::start_data_table("LC_createuser").
1867: &Apache::loncommon::start_data_table_header_row().
1868: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
1869: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
1870: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1871: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 1872: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1873: if ($output{$type}) {
1874: $r->print($output{$type}."\n");
1.217 raeburn 1875: }
1876: }
1.375 raeburn 1877: $r->print(&Apache::loncommon::end_data_table().
1878: '</fieldset></div>');
1.329 raeburn 1879: }
1.217 raeburn 1880: return;
1881: }
1882:
1.218 raeburn 1883: sub new_coauthor_roles {
1884: my ($r,$ccuname,$ccdomain) = @_;
1885: my $addrolesdisplay = 0;
1886: #
1887: # Co-Author
1888: #
1889: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
1890: $env{'request.role.domain'}) &&
1891: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1892: # No sense in assigning co-author role to yourself
1893: $addrolesdisplay = 1;
1894: my $cuname=$env{'user.name'};
1895: my $cudom=$env{'request.role.domain'};
1896: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 1897: 'cs' => "Authoring Space",
1.218 raeburn 1898: 'act' => "Activate",
1899: 'rol' => "Role",
1900: 'ext' => "Extent",
1901: 'sta' => "Start",
1902: 'end' => "End",
1903: 'cau' => "Co-Author",
1904: 'caa' => "Assistant Co-Author",
1905: 'ssd' => "Set Start Date",
1906: 'sed' => "Set End Date"
1907: );
1908: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
1909: &Apache::loncommon::start_data_table()."\n".
1910: &Apache::loncommon::start_data_table_header_row()."\n".
1911: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
1912: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
1913: '<th>'.$lt{'end'}.'</th>'."\n".
1914: &Apache::loncommon::end_data_table_header_row()."\n".
1915: &Apache::loncommon::start_data_table_row().'
1916: <td>
1.291 bisitz 1917: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 1918: </td>
1919: <td>'.$lt{'cau'}.'</td>
1920: <td>'.$cudom.'_'.$cuname.'</td>
1921: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
1922: <a href=
1923: "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>
1924: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
1925: <a href=
1926: "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".
1927: &Apache::loncommon::end_data_table_row()."\n".
1928: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 1929: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 1930: <td>'.$lt{'caa'}.'</td>
1931: <td>'.$cudom.'_'.$cuname.'</td>
1932: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
1933: <a href=
1934: "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>
1935: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
1936: <a href=
1937: "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".
1938: &Apache::loncommon::end_data_table_row()."\n".
1939: &Apache::loncommon::end_data_table());
1940: } elsif ($env{'request.role'} =~ /^au\./) {
1941: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
1942: $env{'request.role.domain'}))) {
1943: $r->print('<span class="LC_error">'.
1944: &mt('You do not have privileges to assign co-author roles.').
1945: '</span>');
1946: } elsif (($env{'user.name'} eq $ccuname) &&
1947: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 1948: $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 1949: }
1950: }
1951: return $addrolesdisplay;;
1952: }
1953:
1954: sub new_domain_roles {
1.357 raeburn 1955: my ($r,$ccdomain) = @_;
1.218 raeburn 1956: my $addrolesdisplay = 0;
1957: #
1958: # Domain level
1959: #
1960: my $num_domain_level = 0;
1961: my $domaintext =
1962: '<h4>'.&mt('Domain Level').'</h4>'.
1963: &Apache::loncommon::start_data_table().
1964: &Apache::loncommon::start_data_table_header_row().
1965: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
1966: &mt('Extent').'</th>'.
1967: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
1968: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 1969: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 1970: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 1971: foreach my $role (@allroles) {
1972: next if ($role eq 'ad');
1.357 raeburn 1973: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 1974: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1975: my $plrole=&Apache::lonnet::plaintext($role);
1976: my %lt=&Apache::lonlocal::texthash(
1977: 'ssd' => "Set Start Date",
1978: 'sed' => "Set End Date"
1979: );
1980: $num_domain_level ++;
1981: $domaintext .=
1982: &Apache::loncommon::start_data_table_row().
1.291 bisitz 1983: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 1984: <td>'.$plrole.'</td>
1985: <td>'.$thisdomain.'</td>
1986: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
1987: <a href=
1988: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1989: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
1990: <a href=
1991: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
1992: &Apache::loncommon::end_data_table_row();
1993: }
1994: }
1995: }
1996: $domaintext.= &Apache::loncommon::end_data_table();
1997: if ($num_domain_level > 0) {
1998: $r->print($domaintext);
1999: $addrolesdisplay = 1;
2000: }
2001: return $addrolesdisplay;
2002: }
2003:
1.188 raeburn 2004: sub user_authentication {
1.227 raeburn 2005: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2006: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2007: my $outcome;
1.188 raeburn 2008: # Check for a bad authentication type
2009: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2010: # bad authentication scheme
2011: my %lt=&Apache::lonlocal::texthash(
2012: 'err' => "ERROR",
2013: 'uuas' => "This user has an unrecognized authentication scheme",
2014: 'adcs' => "Please alert a domain coordinator of this situation",
2015: 'sldb' => "Please specify login data below",
2016: 'ld' => "Login Data"
2017: );
2018: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2019: &initialize_authen_forms($ccdomain,$formname);
2020:
1.190 raeburn 2021: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2022: $outcome = <<ENDBADAUTH;
2023: <script type="text/javascript" language="Javascript">
1.301 bisitz 2024: // <![CDATA[
1.188 raeburn 2025: $loginscript
1.301 bisitz 2026: // ]]>
1.188 raeburn 2027: </script>
2028: <span class="LC_error">$lt{'err'}:
2029: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2030: <h3>$lt{'ld'}</h3>
2031: $choices
2032: ENDBADAUTH
2033: } else {
2034: # This user is not allowed to modify the user's
2035: # authentication scheme, so just notify them of the problem
2036: $outcome = <<ENDBADAUTH;
2037: <span class="LC_error"> $lt{'err'}:
2038: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2039: </span>
2040: ENDBADAUTH
2041: }
2042: } else { # Authentication type is valid
1.227 raeburn 2043: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2044: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2045: &modify_login_block($ccdomain,$currentauth);
2046: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2047: # Current user has login modification privileges
2048: my %lt=&Apache::lonlocal::texthash (
2049: 'ld' => "Login Data",
2050: 'ccld' => "Change Current Login Data",
2051: 'enld' => "Enter New Login Data"
2052: );
2053: $outcome =
2054: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2055: '// <![CDATA['."\n".
1.188 raeburn 2056: $loginscript."\n".
1.301 bisitz 2057: '// ]]>'."\n".
1.188 raeburn 2058: '</script>'."\n".
2059: '<h3>'.$lt{'ld'}.'</h3>'.
2060: &Apache::loncommon::start_data_table().
1.205 raeburn 2061: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2062: '<td>'.$authformnop;
2063: if ($can_modify) {
2064: $outcome .= '</td>'."\n".
2065: &Apache::loncommon::end_data_table_row().
2066: &Apache::loncommon::start_data_table_row().
2067: '<td>'.$authformcurrent.'</td>'.
2068: &Apache::loncommon::end_data_table_row()."\n";
2069: } else {
1.200 raeburn 2070: $outcome .= ' ('.$authformcurrent.')</td>'.
2071: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2072: }
1.205 raeburn 2073: foreach my $item (@authform_others) {
2074: $outcome .= &Apache::loncommon::start_data_table_row().
2075: '<td>'.$item.'</td>'.
2076: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2077: }
1.205 raeburn 2078: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2079: } else {
2080: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
2081: my %lt=&Apache::lonlocal::texthash(
2082: 'ccld' => "Change Current Login Data",
2083: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2084: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2085: );
2086: $outcome .= <<ENDNOPRIV;
2087: <h3>$lt{'ccld'}</h3>
2088: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2089: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2090: ENDNOPRIV
2091: }
2092: }
2093: } ## End of "check for bad authentication type" logic
2094: return $outcome;
2095: }
2096:
1.187 raeburn 2097: sub modify_login_block {
2098: my ($dom,$currentauth) = @_;
2099: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2100: my ($authnum,%can_assign) =
2101: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2102: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2103: if ($currentauth=~/^krb(4|5):/) {
2104: $authformcurrent=$authformkrb;
2105: if ($can_assign{'int'}) {
1.205 raeburn 2106: push(@authform_others,$authformint);
1.187 raeburn 2107: }
2108: if ($can_assign{'loc'}) {
1.205 raeburn 2109: push(@authform_others,$authformloc);
1.187 raeburn 2110: }
2111: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2112: $show_override_msg = 1;
2113: }
2114: } elsif ($currentauth=~/^internal:/) {
2115: $authformcurrent=$authformint;
2116: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2117: push(@authform_others,$authformkrb);
1.187 raeburn 2118: }
2119: if ($can_assign{'loc'}) {
1.205 raeburn 2120: push(@authform_others,$authformloc);
1.187 raeburn 2121: }
2122: if ($can_assign{'int'}) {
2123: $show_override_msg = 1;
2124: }
2125: } elsif ($currentauth=~/^unix:/) {
2126: $authformcurrent=$authformfsys;
2127: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2128: push(@authform_others,$authformkrb);
1.187 raeburn 2129: }
2130: if ($can_assign{'int'}) {
1.205 raeburn 2131: push(@authform_others,$authformint);
1.187 raeburn 2132: }
2133: if ($can_assign{'loc'}) {
1.205 raeburn 2134: push(@authform_others,$authformloc);
1.187 raeburn 2135: }
2136: if ($can_assign{'fsys'}) {
2137: $show_override_msg = 1;
2138: }
2139: } elsif ($currentauth=~/^localauth:/) {
2140: $authformcurrent=$authformloc;
2141: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2142: push(@authform_others,$authformkrb);
1.187 raeburn 2143: }
2144: if ($can_assign{'int'}) {
1.205 raeburn 2145: push(@authform_others,$authformint);
1.187 raeburn 2146: }
2147: if ($can_assign{'loc'}) {
2148: $show_override_msg = 1;
2149: }
2150: }
2151: if ($show_override_msg) {
1.205 raeburn 2152: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2153: '</td></tr>'."\n".
2154: '<tr><td> </td>'.
2155: '<td><b>'.&mt('Currently in use').'</b></td>'.
2156: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2157: &mt('will override current values').
1.205 raeburn 2158: '</span></td></tr></table>';
1.187 raeburn 2159: }
1.205 raeburn 2160: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2161: }
2162:
1.188 raeburn 2163: sub personal_data_display {
1.252 raeburn 2164: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
1.388 bisitz 2165: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2166: my @userinfo = ('firstname','middlename','lastname','generation',
2167: 'permanentemail','id');
1.252 raeburn 2168: my $rowcount = 0;
2169: my $editable = 0;
1.286 raeburn 2170: %canmodify_status =
2171: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2172: ['inststatus'],$rolesarray);
1.253 raeburn 2173: if (!$newuser) {
1.188 raeburn 2174: # Get the users information
2175: %userenv = &Apache::lonnet::get('environment',
2176: ['firstname','middlename','lastname','generation',
1.286 raeburn 2177: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2178: %canmodify =
2179: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2180: \@userinfo,$rolesarray);
1.257 raeburn 2181: } elsif ($context eq 'selfcreate') {
2182: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2183: $inst_results,$rolesarray);
1.188 raeburn 2184: }
2185: my %lt=&Apache::lonlocal::texthash(
2186: 'pd' => "Personal Data",
2187: 'firstname' => "First Name",
2188: 'middlename' => "Middle Name",
2189: 'lastname' => "Last Name",
2190: 'generation' => "Generation",
2191: 'permanentemail' => "Permanent e-mail address",
1.259 bisitz 2192: 'id' => "Student/Employee ID",
1.286 raeburn 2193: 'lg' => "Login Data",
2194: 'inststatus' => "Affiliation",
1.188 raeburn 2195: );
2196: my %textboxsize = (
2197: firstname => '15',
2198: middlename => '15',
2199: lastname => '15',
2200: generation => '5',
2201: permanentemail => '25',
2202: id => '15',
2203: );
2204: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2205: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2206: &Apache::lonhtmlcommon::start_pick_box();
2207: foreach my $item (@userinfo) {
2208: my $rowtitle = $lt{$item};
1.252 raeburn 2209: my $hiderow = 0;
1.188 raeburn 2210: if ($item eq 'generation') {
2211: $rowtitle = $genhelp.$rowtitle;
2212: }
1.252 raeburn 2213: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2214: if ($newuser) {
1.210 raeburn 2215: if (ref($inst_results) eq 'HASH') {
2216: if ($inst_results->{$item} ne '') {
1.252 raeburn 2217: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2218: } else {
1.252 raeburn 2219: if ($context eq 'selfcreate') {
2220: if ($canmodify{$item}) {
2221: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2222: $editable ++;
2223: } else {
2224: $hiderow = 1;
2225: }
1.253 raeburn 2226: } else {
2227: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2228: }
1.210 raeburn 2229: }
1.188 raeburn 2230: } else {
1.252 raeburn 2231: if ($context eq 'selfcreate') {
1.287 raeburn 2232: if (($item eq 'permanentemail') && ($newuser eq 'email')) {
2233: $row .= $ccuname;
1.252 raeburn 2234: } else {
1.287 raeburn 2235: if ($canmodify{$item}) {
2236: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2237: $editable ++;
2238: } else {
2239: $hiderow = 1;
2240: }
1.252 raeburn 2241: }
1.253 raeburn 2242: } else {
2243: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2244: }
1.188 raeburn 2245: }
2246: } else {
1.219 raeburn 2247: if ($canmodify{$item}) {
1.252 raeburn 2248: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.188 raeburn 2249: } else {
1.252 raeburn 2250: $row .= $userenv{$item};
1.188 raeburn 2251: }
1.388 bisitz 2252: if (($item eq 'id') && ($canmodify{$item})) {
2253: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
1.219 raeburn 2254: }
1.188 raeburn 2255: }
1.252 raeburn 2256: $row .= &Apache::lonhtmlcommon::row_closure(1);
2257: if (!$hiderow) {
2258: $output .= $row;
2259: $rowcount ++;
2260: }
1.188 raeburn 2261: }
1.286 raeburn 2262: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2263: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2264: if (ref($types) eq 'ARRAY') {
2265: if (@{$types} > 0) {
2266: my ($hiderow,$shown);
2267: if ($canmodify_status{'inststatus'}) {
2268: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2269: } else {
2270: if ($userenv{'inststatus'} eq '') {
2271: $hiderow = 1;
1.334 raeburn 2272: } else {
2273: my @showitems;
2274: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2275: if (exists($usertypes->{$item})) {
2276: push(@showitems,$usertypes->{$item});
2277: } else {
2278: push(@showitems,$item);
2279: }
2280: }
2281: if (@showitems) {
2282: $shown = join(', ',@showitems);
2283: } else {
2284: $hiderow = 1;
2285: }
1.286 raeburn 2286: }
2287: }
2288: if (!$hiderow) {
1.389 bisitz 2289: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2290: $shown.&Apache::lonhtmlcommon::row_closure(1);
2291: if ($context eq 'selfcreate') {
2292: $rowcount ++;
2293: }
2294: $output .= $row;
2295: }
2296: }
2297: }
2298: }
1.188 raeburn 2299: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2300: if (wantarray) {
1.252 raeburn 2301: if ($context eq 'selfcreate') {
2302: return($output,$rowcount,$editable);
2303: } else {
1.388 bisitz 2304: return $output;
1.252 raeburn 2305: }
1.206 raeburn 2306: } else {
2307: return $output;
2308: }
1.188 raeburn 2309: }
2310:
1.286 raeburn 2311: sub pick_inst_statuses {
2312: my ($curr,$usertypes,$types) = @_;
2313: my ($output,$rem,@currtypes);
2314: if ($curr ne '') {
2315: @currtypes = map { &unescape($_); } split(/:/,$curr);
2316: }
2317: my $numinrow = 2;
2318: if (ref($types) eq 'ARRAY') {
2319: $output = '<table>';
2320: my $lastcolspan;
2321: for (my $i=0; $i<@{$types}; $i++) {
2322: if (defined($usertypes->{$types->[$i]})) {
2323: my $rem = $i%($numinrow);
2324: if ($rem == 0) {
2325: if ($i<@{$types}-1) {
2326: if ($i > 0) {
2327: $output .= '</tr>';
2328: }
2329: $output .= '<tr>';
2330: }
2331: } elsif ($i==@{$types}-1) {
2332: my $colsleft = $numinrow - $rem;
2333: if ($colsleft > 1) {
2334: $lastcolspan = ' colspan="'.$colsleft.'"';
2335: }
2336: }
2337: my $check = ' ';
2338: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2339: $check = ' checked="checked" ';
2340: }
2341: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2342: '<span class="LC_nobreak"><label>'.
2343: '<input type="checkbox" name="inststatus" '.
2344: 'value="'.$types->[$i].'"'.$check.'/>'.
2345: $usertypes->{$types->[$i]}.'</label></span></td>';
2346: }
2347: }
2348: $output .= '</tr></table>';
2349: }
2350: return $output;
2351: }
2352:
1.257 raeburn 2353: sub selfcreate_canmodify {
2354: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2355: if (ref($inst_results) eq 'HASH') {
2356: my @inststatuses = &get_inststatuses($inst_results);
2357: if (@inststatuses == 0) {
2358: @inststatuses = ('default');
2359: }
2360: $rolesarray = \@inststatuses;
2361: }
2362: my %canmodify =
2363: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2364: $rolesarray);
2365: return %canmodify;
2366: }
2367:
1.252 raeburn 2368: sub get_inststatuses {
2369: my ($insthashref) = @_;
2370: my @inststatuses = ();
2371: if (ref($insthashref) eq 'HASH') {
2372: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2373: @inststatuses = @{$insthashref->{'inststatus'}};
2374: }
2375: }
2376: return @inststatuses;
2377: }
2378:
1.4 www 2379: # ================================================================= Phase Three
1.42 matthew 2380: sub update_user_data {
1.375 raeburn 2381: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2382: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2383: $env{'form.ccdomain'});
1.27 matthew 2384: # Error messages
1.188 raeburn 2385: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2386: my $end = '</span><br /><br />';
2387: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2388: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2389: &mt('Return to previous page').'</a>'.
2390: &Apache::loncommon::end_page();
2391: my $now = time;
1.40 www 2392: my $title;
1.101 albertel 2393: if (exists($env{'form.makeuser'})) {
1.40 www 2394: $title='Set Privileges for New User';
2395: } else {
2396: $title='Modify User Privileges';
2397: }
1.213 raeburn 2398: my $newuser = 0;
1.160 raeburn 2399: my ($jsback,$elements) = &crumb_utilities();
2400: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2401: '// <![CDATA['."\n".
2402: $jsback."\n".
2403: '// ]]>'."\n".
2404: '</script>'."\n";
1.318 raeburn 2405: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 2406: push (@{$brcrum},
2407: {href => "javascript:backPage(document.userupdate)",
2408: text => $breadcrumb_text{'search'},
2409: faq => 282,
2410: bug => 'Instructor Interface',}
2411: );
2412: if ($env{'form.prevphase'} eq 'userpicked') {
2413: push(@{$brcrum},
2414: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2415: text => $breadcrumb_text{'userpicked'},
2416: faq => 282,
2417: bug => 'Instructor Interface',});
1.233 raeburn 2418: }
1.224 raeburn 2419: my $helpitem = 'Course_Change_Privileges';
2420: if ($env{'form.action'} eq 'singlestudent') {
2421: $helpitem = 'Course_Add_Student';
2422: }
1.351 raeburn 2423: push(@{$brcrum},
2424: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2425: text => $breadcrumb_text{'modify'},
2426: faq => 282,
2427: bug => 'Instructor Interface',},
2428: {href => "/adm/createuser",
2429: text => "Result",
2430: faq => 282,
2431: bug => 'Instructor Interface',
2432: help => $helpitem});
2433: my $args = {bread_crumbs => $brcrum,
2434: bread_crumbs_component => 'User Management'};
2435: if ($env{'form.popup'}) {
2436: $args->{'no_nav_bar'} = 1;
2437: }
2438: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2439: $r->print(&update_result_form($uhome));
1.27 matthew 2440: # Check Inputs
1.101 albertel 2441: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2442: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2443: return;
2444: }
1.138 albertel 2445: if ( $env{'form.ccuname'} ne
2446: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2447: $r->print($error.&mt('Invalid login name.').' '.
2448: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2449: $end.$rtnlink);
1.27 matthew 2450: return;
2451: }
1.101 albertel 2452: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2453: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2454: return;
2455: }
1.138 albertel 2456: if ( $env{'form.ccdomain'} ne
2457: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2458: $r->print($error.&mt('Invalid domain name.').' '.
2459: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2460: $end.$rtnlink);
1.27 matthew 2461: return;
2462: }
1.219 raeburn 2463: if ($uhome eq 'no_host') {
2464: $newuser = 1;
2465: }
1.101 albertel 2466: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2467: # Modifying an existing user, so check the validity of the name
2468: if ($uhome eq 'no_host') {
1.389 bisitz 2469: $r->print(
2470: $error
2471: .'<p class="LC_error">'
2472: .&mt('Unable to determine home server for [_1] in domain [_2].',
2473: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2474: .'</p>');
1.29 matthew 2475: return;
2476: }
2477: }
1.27 matthew 2478: # Determine authentication method and password for the user being modified
2479: my $amode='';
2480: my $genpwd='';
1.101 albertel 2481: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2482: $amode='krb';
1.101 albertel 2483: $amode.=$env{'form.krbver'};
2484: $genpwd=$env{'form.krbarg'};
2485: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2486: $amode='internal';
1.101 albertel 2487: $genpwd=$env{'form.intarg'};
2488: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2489: $amode='unix';
1.101 albertel 2490: $genpwd=$env{'form.fsysarg'};
2491: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2492: $amode='localauth';
1.101 albertel 2493: $genpwd=$env{'form.locarg'};
1.27 matthew 2494: $genpwd=" " if (!$genpwd);
1.101 albertel 2495: } elsif (($env{'form.login'} eq 'nochange') ||
2496: ($env{'form.login'} eq '' )) {
1.34 matthew 2497: # There is no need to tell the user we did not change what they
2498: # did not ask us to change.
1.35 matthew 2499: # If they are creating a new user but have not specified login
2500: # information this will be caught below.
1.30 matthew 2501: } else {
1.367 golterma 2502: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2503: return;
1.27 matthew 2504: }
1.164 albertel 2505:
1.188 raeburn 2506: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2507: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2508: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2509: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2510:
1.193 raeburn 2511: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2512: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2513: my @usertools = ('aboutme','blog','webdav','portfolio');
1.384 raeburn 2514: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 2515: my @requestauthor = ('requestauthor');
1.286 raeburn 2516: my ($othertitle,$usertypes,$types) =
2517: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2518: my %canmodify_status =
2519: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2520: ['inststatus']);
1.101 albertel 2521: if ($env{'form.makeuser'}) {
1.164 albertel 2522: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2523: # Check for the authentication mode and password
2524: if (! $amode || ! $genpwd) {
1.193 raeburn 2525: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2526: return;
1.18 albertel 2527: }
1.29 matthew 2528: # Determine desired host
1.101 albertel 2529: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2530: if (lc($desiredhost) eq 'default') {
2531: $desiredhost = undef;
2532: } else {
1.147 albertel 2533: my %home_servers =
2534: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2535: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2536: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2537: return;
2538: }
2539: }
2540: # Check ID format
2541: my %checkhash;
2542: my %checks = ('id' => 1);
2543: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2544: 'newuser' => $newuser,
1.196 raeburn 2545: 'id' => $env{'form.cid'},
1.193 raeburn 2546: );
1.196 raeburn 2547: if ($env{'form.cid'} ne '') {
2548: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2549: \%rulematch,\%inst_results,\%curr_rules);
2550: if (ref($alerts{'id'}) eq 'HASH') {
2551: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2552: my $domdesc =
2553: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2554: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2555: my $userchkmsg;
2556: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2557: $userchkmsg =
2558: &Apache::loncommon::instrule_disallow_msg('id',
2559: $domdesc,1).
2560: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2561: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2562: }
2563: $r->print($error.&mt('Invalid ID format').$end.
2564: $userchkmsg.$rtnlink);
2565: return;
2566: }
2567: }
1.29 matthew 2568: }
2569: }
1.367 golterma 2570: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2571: # Call modifyuser
2572: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2573: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2574: $amode,$genpwd,$env{'form.cfirstname'},
2575: $env{'form.cmiddlename'},$env{'form.clastname'},
2576: $env{'form.cgeneration'},undef,$desiredhost,
2577: $env{'form.cpermanentemail'});
1.77 www 2578: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2579: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2580: $env{'form.ccdomain'});
1.334 raeburn 2581: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2582: if ($uhome ne 'no_host') {
1.334 raeburn 2583: if ($context eq 'domain') {
1.378 raeburn 2584: foreach my $name ('portfolio','author') {
2585: if ($env{'form.custom_'.$name.'quota'} == 1) {
2586: if ($env{'form.'.$name.'quota'} eq '') {
2587: $newcustom{$name.'quota'} = 0;
2588: } else {
2589: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2590: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2591: }
2592: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2593: $changed{$name.'quota'} = 1;
2594: }
1.334 raeburn 2595: }
2596: }
2597: foreach my $item (@usertools) {
2598: if ($env{'form.custom'.$item} == 1) {
2599: $newcustom{$item} = $env{'form.tools_'.$item};
2600: $changed{$item} = &tool_admin($item,$newcustom{$item},
2601: \%changeHash,'tools');
2602: }
1.267 raeburn 2603: }
1.334 raeburn 2604: foreach my $item (@requestcourses) {
1.341 raeburn 2605: if ($env{'form.custom'.$item} == 1) {
2606: $newcustom{$item} = $env{'form.crsreq_'.$item};
2607: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2608: $newcustom{$item} .= '=';
1.383 raeburn 2609: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2610: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2611: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2612: }
1.334 raeburn 2613: }
1.341 raeburn 2614: $changed{$item} = &tool_admin($item,$newcustom{$item},
2615: \%changeHash,'requestcourses');
1.334 raeburn 2616: }
1.275 raeburn 2617: }
1.362 raeburn 2618: if ($env{'form.customrequestauthor'} == 1) {
2619: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2620: $changed{'requestauthor'} = &tool_admin('requestauthor',
2621: $newcustom{'requestauthor'},
2622: \%changeHash,'requestauthor');
2623: }
1.275 raeburn 2624: }
1.334 raeburn 2625: if ($canmodify_status{'inststatus'}) {
2626: if (exists($env{'form.inststatus'})) {
2627: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2628: if (@inststatuses > 0) {
2629: $changeHash{'inststatus'} = join(',',@inststatuses);
2630: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2631: }
2632: }
1.232 raeburn 2633: }
1.334 raeburn 2634: if (keys(%changed)) {
2635: foreach my $item (@userinfo) {
2636: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2637: }
1.267 raeburn 2638: my $chgresult =
2639: &Apache::lonnet::put('environment',\%changeHash,
2640: $env{'form.ccdomain'},$env{'form.ccuname'});
2641: }
1.232 raeburn 2642: }
1.219 raeburn 2643: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2644: &Apache::lonnet::hostname($uhome));
1.101 albertel 2645: } elsif (($env{'form.login'} ne 'nochange') &&
2646: ($env{'form.login'} ne '' )) {
1.27 matthew 2647: # Modify user privileges
2648: if (! $amode || ! $genpwd) {
1.193 raeburn 2649: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2650: return;
1.20 harris41 2651: }
1.27 matthew 2652: # Only allow authentification modification if the person has authority
1.101 albertel 2653: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2654: $r->print('Modifying authentication: '.
1.31 matthew 2655: &Apache::lonnet::modifyuserauth(
1.101 albertel 2656: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2657: $amode,$genpwd));
1.102 albertel 2658: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2659: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2660: } else {
1.27 matthew 2661: # Okay, this is a non-fatal error.
1.193 raeburn 2662: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
1.27 matthew 2663: }
1.28 matthew 2664: }
1.344 bisitz 2665: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2666: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2667: ##
1.375 raeburn 2668: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2669: if ($context eq 'course') {
1.375 raeburn 2670: ($cnum,$cdom) =
2671: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2672: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2673: if ($showcredits) {
2674: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2675: }
1.213 raeburn 2676: }
1.101 albertel 2677: if (! $env{'form.makeuser'} ) {
1.28 matthew 2678: # Check for need to change
2679: my %userenv = &Apache::lonnet::get
1.134 raeburn 2680: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2681: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2682: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2683: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2684: 'requestcourses.community','requestcourses.textbook',
2685: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2686: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.362 raeburn 2687: 'requestauthor'],
1.160 raeburn 2688: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2689: my ($tmp) = keys(%userenv);
2690: if ($tmp =~ /^(con_lost|error)/i) {
2691: %userenv = ();
2692: }
1.206 raeburn 2693: my $no_forceid_alert;
2694: # Check to see if user information can be changed
2695: my %domconfig =
2696: &Apache::lonnet::get_dom('configuration',['usermodification'],
2697: $env{'form.ccdomain'});
1.213 raeburn 2698: my @statuses = ('active','future');
2699: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2700: my ($auname,$audom);
1.220 raeburn 2701: if ($context eq 'author') {
1.206 raeburn 2702: $auname = $env{'user.name'};
2703: $audom = $env{'user.domain'};
2704: }
2705: foreach my $item (keys(%roles)) {
1.220 raeburn 2706: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2707: if ($context eq 'course') {
2708: if ($cnum ne '' && $cdom ne '') {
2709: if ($rolenum eq $cnum && $roledom eq $cdom) {
2710: if (!grep(/^\Q$role\E$/,@userroles)) {
2711: push(@userroles,$role);
2712: }
2713: }
2714: }
2715: } elsif ($context eq 'author') {
2716: if ($rolenum eq $auname && $roledom eq $audom) {
2717: if (!grep(/^\Q$role\E$/,@userroles)) {
2718: push(@userroles,$role);
2719: }
2720: }
2721: }
2722: }
1.220 raeburn 2723: if ($env{'form.action'} eq 'singlestudent') {
2724: if (!grep(/^st$/,@userroles)) {
2725: push(@userroles,'st');
2726: }
2727: } else {
2728: # Check for course or co-author roles being activated or re-enabled
2729: if ($context eq 'author' || $context eq 'course') {
2730: foreach my $key (keys(%env)) {
2731: if ($context eq 'author') {
2732: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2733: if (!grep(/^\Q$1\E$/,@userroles)) {
2734: push(@userroles,$1);
2735: }
2736: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2737: if (!grep(/^\Q$1\E$/,@userroles)) {
2738: push(@userroles,$1);
2739: }
1.206 raeburn 2740: }
1.220 raeburn 2741: } elsif ($context eq 'course') {
2742: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2743: if (!grep(/^\Q$1\E$/,@userroles)) {
2744: push(@userroles,$1);
2745: }
2746: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
2747: if (!grep(/^\Q$1\E$/,@userroles)) {
2748: push(@userroles,$1);
2749: }
1.206 raeburn 2750: }
2751: }
2752: }
2753: }
2754: }
2755: #Check to see if we can change personal data for the user
2756: my (@mod_disallowed,@longroles);
2757: foreach my $role (@userroles) {
2758: if ($role eq 'cr') {
2759: push(@longroles,'Custom');
2760: } else {
1.318 raeburn 2761: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 2762: }
2763: }
1.219 raeburn 2764: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
2765: foreach my $item (@userinfo) {
1.28 matthew 2766: # Strip leading and trailing whitespace
1.203 raeburn 2767: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 2768: if (!$canmodify{$item}) {
1.207 raeburn 2769: if (defined($env{'form.c'.$item})) {
2770: if ($env{'form.c'.$item} ne $userenv{$item}) {
2771: push(@mod_disallowed,$item);
2772: }
1.206 raeburn 2773: }
2774: $env{'form.c'.$item} = $userenv{$item};
2775: }
1.28 matthew 2776: }
1.259 bisitz 2777: # Check to see if we can change the Student/Employee ID
1.196 raeburn 2778: my $forceid = $env{'form.forceid'};
2779: my $recurseid = $env{'form.recurseid'};
2780: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 2781: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
2782: $env{'form.ccuname'});
2783: if (($uidhash{$env{'form.ccuname'}}) &&
2784: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
2785: (!$forceid)) {
2786: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
2787: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 2788: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 2789: .'<br />'
2790: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
2791: .'<br />'."\n";
1.203 raeburn 2792: }
2793: }
2794: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 2795: my $checkhash;
2796: my $checks = { 'id' => 1 };
2797: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
2798: { 'newuser' => $newuser,
2799: 'id' => $env{'form.cid'},
2800: };
2801: &Apache::loncommon::user_rule_check($checkhash,$checks,
2802: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
2803: if (ref($alerts{'id'}) eq 'HASH') {
2804: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 2805: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 2806: }
2807: }
2808: }
1.378 raeburn 2809: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
2810: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 2811: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 2812: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 2813: @disporder = ('inststatus');
2814: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 2815: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 2816: } else {
2817: push(@disporder,'reqcrsotherdom');
2818: }
2819: push(@disporder,('quota','tools'));
1.338 raeburn 2820: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 2821: foreach my $name ('portfolio','author') {
2822: ($olddefquota{$name},$oldsettingstatus{$name}) =
2823: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
2824: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
2825: }
1.334 raeburn 2826: my %canshow;
1.220 raeburn 2827: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 2828: $canshow{'quota'} = 1;
1.220 raeburn 2829: }
1.267 raeburn 2830: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 2831: $canshow{'tools'} = 1;
1.267 raeburn 2832: }
1.275 raeburn 2833: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 2834: $canshow{'requestcourses'} = 1;
1.300 raeburn 2835: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 2836: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 2837: }
1.286 raeburn 2838: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 2839: $canshow{'inststatus'} = 1;
1.286 raeburn 2840: }
1.362 raeburn 2841: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
2842: $canshow{'requestauthor'} = 1;
2843: }
1.267 raeburn 2844: my (%changeHash,%changed);
1.286 raeburn 2845: if ($oldinststatus eq '') {
1.334 raeburn 2846: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 2847: } else {
2848: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2849: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2850: } else {
1.334 raeburn 2851: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2852: }
2853: }
2854: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 2855: if ($canmodify_status{'inststatus'}) {
2856: $canshow{'inststatus'} = 1;
1.286 raeburn 2857: if (exists($env{'form.inststatus'})) {
2858: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2859: if (@inststatuses > 0) {
2860: $newinststatus = join(':',map { &escape($_); } @inststatuses);
2861: $changeHash{'inststatus'} = $newinststatus;
2862: if ($newinststatus ne $oldinststatus) {
2863: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 2864: foreach my $name ('portfolio','author') {
2865: ($newdefquota{$name},$newsettingstatus{$name}) =
2866: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
2867: }
1.286 raeburn 2868: }
2869: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2870: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 2871: } else {
1.337 raeburn 2872: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 2873: }
1.334 raeburn 2874: }
2875: } else {
2876: $newinststatus = '';
2877: $changeHash{'inststatus'} = $newinststatus;
2878: $newsettings{'inststatus'} = $othertitle;
2879: if ($newinststatus ne $oldinststatus) {
2880: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 2881: foreach my $name ('portfolio','author') {
2882: ($newdefquota{$name},$newsettingstatus{$name}) =
2883: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
2884: }
1.286 raeburn 2885: }
2886: }
1.334 raeburn 2887: } elsif ($context ne 'selfcreate') {
2888: $canshow{'inststatus'} = 1;
1.337 raeburn 2889: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 2890: }
1.378 raeburn 2891: foreach my $name ('portfolio','author') {
2892: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
2893: }
1.334 raeburn 2894: if ($context eq 'domain') {
1.378 raeburn 2895: foreach my $name ('portfolio','author') {
2896: if ($userenv{$name.'quota'} ne '') {
2897: $oldquota{$name} = $userenv{$name.'quota'};
2898: if ($env{'form.custom_'.$name.'quota'} == 1) {
2899: if ($env{'form.'.$name.'quota'} eq '') {
2900: $newquota{$name} = 0;
2901: } else {
2902: $newquota{$name} = $env{'form.'.$name.'quota'};
2903: $newquota{$name} =~ s/[^\d\.]//g;
2904: }
2905: if ($newquota{$name} != $oldquota{$name}) {
2906: if ("a_admin($newquota{$name},\%changeHash,$name)) {
2907: $changed{$name.'quota'} = 1;
2908: }
2909: }
1.334 raeburn 2910: } else {
1.378 raeburn 2911: if ("a_admin('',\%changeHash,$name)) {
2912: $changed{$name.'quota'} = 1;
2913: $newquota{$name} = $newdefquota{$name};
2914: $newisdefault{$name} = 1;
2915: }
1.334 raeburn 2916: }
1.149 raeburn 2917: } else {
1.378 raeburn 2918: $oldisdefault{$name} = 1;
2919: $oldquota{$name} = $olddefquota{$name};
2920: if ($env{'form.custom_'.$name.'quota'} == 1) {
2921: if ($env{'form.'.$name.'quota'} eq '') {
2922: $newquota{$name} = 0;
2923: } else {
2924: $newquota{$name} = $env{'form.'.$name.'quota'};
2925: $newquota{$name} =~ s/[^\d\.]//g;
2926: }
2927: if ("a_admin($newquota{$name},\%changeHash,$name)) {
2928: $changed{$name.'quota'} = 1;
2929: }
1.334 raeburn 2930: } else {
1.378 raeburn 2931: $newquota{$name} = $newdefquota{$name};
2932: $newisdefault{$name} = 1;
1.334 raeburn 2933: }
1.378 raeburn 2934: }
2935: if ($oldisdefault{$name}) {
2936: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 2937: } else {
2938: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 2939: }
2940: if ($newisdefault{$name}) {
2941: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 2942: } else {
2943: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 2944: }
2945: }
1.334 raeburn 2946: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
2947: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
2948: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
2949: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
2950: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 2951: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
2952: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 2953: } else {
1.334 raeburn 2954: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
2955: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 2956: }
2957: }
1.334 raeburn 2958: foreach my $item (@userinfo) {
2959: if ($env{'form.c'.$item} ne $userenv{$item}) {
2960: $namechanged{$item} = 1;
2961: }
1.204 raeburn 2962: }
1.378 raeburn 2963: foreach my $name ('portfolio','author') {
1.390 ! bisitz 2964: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
! 2965: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 2966: }
1.334 raeburn 2967: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 2968: my ($chgresult,$namechgresult);
2969: if (keys(%changed) > 0) {
2970: $chgresult =
1.204 raeburn 2971: &Apache::lonnet::put('environment',\%changeHash,
2972: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 2973: if ($chgresult eq 'ok') {
2974: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
2975: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 2976: my %newenvhash;
2977: foreach my $key (keys(%changed)) {
1.299 raeburn 2978: if (($key eq 'official') || ($key eq 'unofficial')
2979: || ($key eq 'community')) {
1.279 raeburn 2980: $newenvhash{'environment.requestcourses.'.$key} =
2981: $changeHash{'requestcourses.'.$key};
1.362 raeburn 2982: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 2983: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 2984: } else {
2985: $newenvhash{'environment.canrequest.'.$key} =
2986: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2987: $key,'reload','requestcourses');
2988: }
1.362 raeburn 2989: } elsif ($key eq 'requestauthor') {
2990: $newenvhash{'environment.'.$key} = $changeHash{$key};
2991: if ($changeHash{$key}) {
2992: $newenvhash{'environment.canrequest.author'} = 1;
2993: } else {
2994: $newenvhash{'environment.canrequest.author'} =
2995: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2996: $key,'reload','requestauthor');
2997: }
1.275 raeburn 2998: } elsif ($key ne 'quota') {
1.270 raeburn 2999: $newenvhash{'environment.tools.'.$key} =
3000: $changeHash{'tools.'.$key};
1.279 raeburn 3001: if ($changeHash{'tools.'.$key} ne '') {
3002: $newenvhash{'environment.availabletools.'.$key} =
3003: $changeHash{'tools.'.$key};
3004: } else {
3005: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3006: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3007: $key,'reload','tools');
1.279 raeburn 3008: }
1.270 raeburn 3009: }
3010: }
1.271 raeburn 3011: if (keys(%newenvhash)) {
3012: &Apache::lonnet::appenv(\%newenvhash);
3013: }
1.267 raeburn 3014: }
3015: }
1.204 raeburn 3016: }
1.334 raeburn 3017: if (keys(%namechanged) > 0) {
1.337 raeburn 3018: foreach my $field (@userinfo) {
3019: $changeHash{$field} = $env{'form.c'.$field};
3020: }
3021: # Make the change
1.204 raeburn 3022: $namechgresult =
3023: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3024: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3025: $changeHash{'firstname'},$changeHash{'middlename'},
3026: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3027: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3028: %userupdate = (
3029: lastname => $env{'form.clastname'},
3030: middlename => $env{'form.cmiddlename'},
3031: firstname => $env{'form.cfirstname'},
3032: generation => $env{'form.cgeneration'},
3033: id => $env{'form.cid'},
3034: );
1.204 raeburn 3035: }
1.334 raeburn 3036: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3037: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3038: # Tell the user we changed the name
1.334 raeburn 3039: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3040: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3041: \%oldsettings, \%oldsettingstext,\%newsettings,
3042: \%newsettingstext);
1.203 raeburn 3043: if ($env{'form.cid'} ne $userenv{'id'}) {
3044: &Apache::lonnet::idput($env{'form.ccdomain'},
3045: ($env{'form.ccuname'} => $env{'form.cid'}));
3046: if (($recurseid) &&
3047: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3048: my $idresult =
3049: &Apache::lonuserutils::propagate_id_change(
3050: $env{'form.ccuname'},$env{'form.ccdomain'},
3051: \%userupdate);
3052: $r->print('<br />'.$idresult.'<br />');
3053: }
1.196 raeburn 3054: }
1.149 raeburn 3055: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3056: ($env{'form.ccuname'} eq $env{'user.name'})) {
3057: my %newenvhash;
3058: foreach my $key (keys(%changeHash)) {
3059: $newenvhash{'environment.'.$key} = $changeHash{$key};
3060: }
1.238 raeburn 3061: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3062: }
1.28 matthew 3063: } else { # error occurred
1.389 bisitz 3064: $r->print(
3065: '<p class="LC_error">'
3066: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3067: '"'.$env{'form.ccuname'}.'"',
3068: '"'.$env{'form.ccdomain'}.'"')
3069: .'</p>');
1.28 matthew 3070: }
1.334 raeburn 3071: } else { # End of if ($env ... ) logic
1.275 raeburn 3072: # They did not want to change the users name, quota, tool availability,
3073: # or ability to request creation of courses,
1.267 raeburn 3074: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3075: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3076: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3077: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3078: }
1.206 raeburn 3079: if (@mod_disallowed) {
3080: my ($rolestr,$contextname);
3081: if (@longroles > 0) {
3082: $rolestr = join(', ',@longroles);
3083: } else {
3084: $rolestr = &mt('No roles');
3085: }
3086: if ($context eq 'course') {
3087: $contextname = &mt('course');
3088: } elsif ($context eq 'author') {
3089: $contextname = &mt('co-author');
3090: }
3091: $r->print(&mt('The following fields were not updated: ').'<ul>');
3092: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3093: foreach my $field (@mod_disallowed) {
3094: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3095: }
1.207 raeburn 3096: $r->print('</ul>');
3097: if (@mod_disallowed == 1) {
3098: $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future [_1] roles:",$contextname));
3099: } else {
3100: $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future [_1] roles:",$contextname));
3101: }
1.292 bisitz 3102: my $helplink = 'javascript:helpMenu('."'display'".')';
3103: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3104: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3105: ,'<a href="'.$helplink.'">','</a>')
3106: .'<br />');
1.206 raeburn 3107: }
1.259 bisitz 3108: $r->print('<span class="LC_warning">'
3109: .$no_forceid_alert
3110: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3111: .'</span>');
1.4 www 3112: }
1.367 golterma 3113: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3114: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3115: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3116: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3117: my $linktext = ($crstype eq 'Community' ?
3118: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3119: $r->print(
3120: &Apache::lonhtmlcommon::actionbox([
3121: '<a href="javascript:backPage(document.userupdate)">'
3122: .($crstype eq 'Community' ?
3123: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3124: .'</a>']));
1.220 raeburn 3125: } else {
1.375 raeburn 3126: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3127: if (keys(%namechanged) > 0) {
1.220 raeburn 3128: if ($context eq 'course') {
3129: if (@userroles > 0) {
1.225 raeburn 3130: if ((@rolechanges == 0) ||
3131: (!(grep(/^st$/,@rolechanges)))) {
3132: if (grep(/^st$/,@userroles)) {
3133: my $classlistupdated =
3134: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3135: $cnum,$env{'form.ccdomain'},
3136: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3137: }
1.220 raeburn 3138: }
3139: }
3140: }
3141: }
1.226 raeburn 3142: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3143: $env{'form.ccdomain'});
3144: if ($env{'form.popup'}) {
3145: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3146: } else {
1.367 golterma 3147: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3148: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3149: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3150: }
1.220 raeburn 3151: }
3152: }
3153:
1.334 raeburn 3154: sub display_userinfo {
1.362 raeburn 3155: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3156: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3157: $newsetting,$newsettingtext) = @_;
3158: return unless (ref($order) eq 'ARRAY' &&
3159: ref($canshow) eq 'HASH' &&
3160: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3161: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3162: ref($usertools) eq 'ARRAY' &&
3163: ref($userenv) eq 'HASH' &&
3164: ref($changedhash) eq 'HASH' &&
3165: ref($oldsetting) eq 'HASH' &&
3166: ref($oldsettingtext) eq 'HASH' &&
3167: ref($newsetting) eq 'HASH' &&
3168: ref($newsettingtext) eq 'HASH');
3169: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3170: 'ui' => 'User Information',
1.334 raeburn 3171: 'uic' => 'User Information Changed',
3172: 'firstname' => 'First Name',
3173: 'middlename' => 'Middle Name',
3174: 'lastname' => 'Last Name',
3175: 'generation' => 'Generation',
3176: 'id' => 'Student/Employee ID',
3177: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3178: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3179: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3180: 'blog' => 'Blog Availability',
1.361 raeburn 3181: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3182: 'aboutme' => 'Personal Information Page Availability',
3183: 'portfolio' => 'Portfolio Availability',
3184: 'official' => 'Can Request Official Courses',
3185: 'unofficial' => 'Can Request Unofficial Courses',
3186: 'community' => 'Can Request Communities',
1.384 raeburn 3187: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 3188: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3189: 'inststatus' => "Affiliation",
3190: 'prvs' => 'Previous Value:',
3191: 'chto' => 'Changed To:'
3192: );
3193: if ($changed) {
1.372 raeburn 3194: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3195: &Apache::loncommon::start_data_table().
3196: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3197: $r->print("<th> </th>\n");
1.367 golterma 3198: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3199: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3200: $r->print(&Apache::loncommon::end_data_table_header_row());
3201: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3202:
1.334 raeburn 3203: foreach my $item (@userinfo) {
3204: my $value = $env{'form.c'.$item};
1.367 golterma 3205: #show changes only:
1.383 raeburn 3206: unless ($value eq $userenv->{$item}){
1.367 golterma 3207: $r->print(&Apache::loncommon::start_data_table_row());
3208: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3209: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3210: $r->print("<td>$value </td>\n");
3211: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3212: }
3213: }
3214: foreach my $entry (@{$order}) {
1.383 raeburn 3215: if ($canshow->{$entry}) {
3216: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3217: my @items;
3218: if ($entry eq 'requestauthor') {
3219: @items = ($entry);
3220: } else {
3221: @items = @{$requestcourses};
1.384 raeburn 3222: }
1.383 raeburn 3223: foreach my $item (@items) {
3224: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3225: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3226: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3227: $r->print("<td>$lt{$item}</td>\n");
3228: $r->print("<td>".$oldsetting->{$item});
3229: if ($oldsettingtext->{$item}) {
3230: if ($oldsetting->{$item}) {
3231: $r->print(' -- ');
3232: }
3233: $r->print($oldsettingtext->{$item});
3234: }
3235: $r->print("</td>\n");
3236: $r->print("<td>".$newsetting->{$item});
3237: if ($newsettingtext->{$item}) {
3238: if ($newsetting->{$item}) {
3239: $r->print(' -- ');
3240: }
3241: $r->print($newsettingtext->{$item});
3242: }
3243: $r->print("</td>\n");
3244: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3245: }
3246: }
3247: } elsif ($entry eq 'tools') {
3248: foreach my $item (@{$usertools}) {
1.383 raeburn 3249: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3250: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3251: $r->print("<td>$lt{$item}</td>\n");
3252: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3253: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3254: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3255: }
3256: }
1.378 raeburn 3257: } elsif ($entry eq 'quota') {
3258: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3259: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3260: foreach my $name ('portfolio','author') {
1.383 raeburn 3261: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3262: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3263: $r->print("<td>$lt{$name.$entry}</td>\n");
3264: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3265: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3266: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3267: }
3268: }
3269: }
1.334 raeburn 3270: } else {
1.383 raeburn 3271: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3272: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3273: $r->print("<td>$lt{$entry}</td>\n");
3274: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3275: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3276: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3277: }
3278: }
3279: }
3280: }
1.367 golterma 3281: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3282: } else {
3283: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3284: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3285: }
3286: return;
3287: }
3288:
1.275 raeburn 3289: sub tool_changes {
3290: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3291: $changed,$newaccess,$newaccesstext) = @_;
3292: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3293: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3294: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3295: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3296: return;
3297: }
1.383 raeburn 3298: my %reqdisplay = &requestchange_display();
1.300 raeburn 3299: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3300: my @options = ('approval','validate','autolimit');
1.306 raeburn 3301: my $optregex = join('|',@options);
1.300 raeburn 3302: my $cdom = $env{'request.role.domain'};
3303: foreach my $tool (@{$usertools}) {
1.383 raeburn 3304: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3305: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3306: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3307: my ($newop,$limit);
1.314 raeburn 3308: if ($env{'form.'.$context.'_'.$tool}) {
3309: $newop = $env{'form.'.$context.'_'.$tool};
3310: if ($newop eq 'autolimit') {
1.383 raeburn 3311: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3312: $limit =~ s/\D+//g;
3313: $newop .= '='.$limit;
3314: }
3315: }
1.300 raeburn 3316: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3317: if ($newop) {
3318: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3319: $changeHash,$context);
3320: if ($changed->{$tool}) {
1.383 raeburn 3321: if ($newop =~ /^autolimit/) {
3322: if ($limit) {
3323: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3324: } else {
3325: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3326: }
3327: } else {
3328: $newaccesstext->{$tool} = $reqdisplay{$newop};
3329: }
1.300 raeburn 3330: } else {
3331: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3332: }
3333: }
3334: } else {
3335: my @curr = split(',',$userenv->{$context.'.'.$tool});
3336: my @new;
3337: my $changedoms;
1.314 raeburn 3338: foreach my $req (@curr) {
3339: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3340: my $oldop = $1;
1.383 raeburn 3341: if ($oldop =~ /^autolimit=(\d*)/) {
3342: my $limit = $1;
3343: if ($limit) {
3344: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3345: } else {
3346: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3347: }
3348: } else {
3349: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3350: }
1.314 raeburn 3351: if ($oldop ne $newop) {
3352: $changedoms = 1;
3353: foreach my $item (@curr) {
3354: my ($reqdom,$option) = split(':',$item);
3355: unless ($reqdom eq $cdom) {
3356: push(@new,$item);
3357: }
3358: }
3359: if ($newop) {
3360: push(@new,$cdom.':'.$newop);
1.300 raeburn 3361: }
1.314 raeburn 3362: @new = sort(@new);
1.300 raeburn 3363: }
1.314 raeburn 3364: last;
1.300 raeburn 3365: }
1.314 raeburn 3366: }
3367: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3368: $changedoms = 1;
1.306 raeburn 3369: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3370: }
3371: if ($changedoms) {
1.314 raeburn 3372: my $newdomstr;
1.300 raeburn 3373: if (@new) {
3374: $newdomstr = join(',',@new);
3375: }
3376: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3377: $context);
3378: if ($changed->{$tool}) {
3379: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3380: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3381: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3382: $limit =~ s/\D+//g;
3383: if ($limit) {
1.383 raeburn 3384: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3385: } else {
1.383 raeburn 3386: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3387: }
1.314 raeburn 3388: } else {
1.306 raeburn 3389: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3390: }
1.300 raeburn 3391: } else {
1.383 raeburn 3392: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3393: }
3394: }
3395: }
3396: }
3397: }
3398: return;
3399: }
1.275 raeburn 3400: foreach my $tool (@{$usertools}) {
1.383 raeburn 3401: my ($newval,$limit,$envkey);
1.362 raeburn 3402: $envkey = $context.'.'.$tool;
1.306 raeburn 3403: if ($context eq 'requestcourses') {
3404: $newval = $env{'form.crsreq_'.$tool};
3405: if ($newval eq 'autolimit') {
1.383 raeburn 3406: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3407: $limit =~ s/\D+//g;
3408: $newval .= '='.$limit;
1.306 raeburn 3409: }
1.362 raeburn 3410: } elsif ($context eq 'requestauthor') {
3411: $newval = $env{'form.'.$context};
3412: $envkey = $context;
1.314 raeburn 3413: } else {
1.306 raeburn 3414: $newval = $env{'form.'.$context.'_'.$tool};
3415: }
1.362 raeburn 3416: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3417: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3418: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3419: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3420: my $currlimit = $1;
3421: if ($currlimit eq '') {
3422: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3423: } else {
3424: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3425: }
3426: } elsif ($userenv->{$envkey}) {
3427: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3428: } else {
3429: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3430: }
1.275 raeburn 3431: } else {
1.383 raeburn 3432: if ($userenv->{$envkey}) {
3433: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3434: } else {
3435: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3436: }
1.275 raeburn 3437: }
1.362 raeburn 3438: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3439: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3440: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3441: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3442: $context);
1.275 raeburn 3443: if ($changed->{$tool}) {
3444: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3445: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3446: if ($newval =~ /^autolimit/) {
3447: if ($limit) {
3448: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3449: } else {
3450: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3451: }
3452: } elsif ($newval) {
3453: $newaccesstext->{$tool} = $reqdisplay{$newval};
3454: } else {
3455: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3456: }
1.275 raeburn 3457: } else {
1.383 raeburn 3458: if ($newval) {
3459: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3460: } else {
3461: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3462: }
1.275 raeburn 3463: }
3464: } else {
3465: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3466: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3467: if ($newval =~ /^autolimit/) {
3468: if ($limit) {
3469: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3470: } else {
3471: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3472: }
3473: } elsif ($newval) {
3474: $newaccesstext->{$tool} = $reqdisplay{$newval};
3475: } else {
3476: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3477: }
1.275 raeburn 3478: } else {
1.383 raeburn 3479: if ($userenv->{$context.'.'.$tool}) {
3480: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3481: } else {
3482: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3483: }
1.275 raeburn 3484: }
3485: }
3486: } else {
3487: $newaccess->{$tool} = $oldaccess->{$tool};
3488: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3489: }
3490: } else {
3491: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3492: if ($changed->{$tool}) {
3493: $newaccess->{$tool} = &mt('default');
3494: } else {
3495: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3496: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3497: if ($newval =~ /^autolimit/) {
3498: if ($limit) {
3499: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3500: } else {
3501: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3502: }
3503: } elsif ($newval) {
3504: $newaccesstext->{$tool} = $reqdisplay{$newval};
3505: } else {
3506: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3507: }
1.275 raeburn 3508: } else {
1.383 raeburn 3509: if ($userenv->{$context.'.'.$tool}) {
3510: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3511: } else {
3512: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3513: }
1.275 raeburn 3514: }
3515: }
3516: }
3517: } else {
3518: $oldaccess->{$tool} = &mt('default');
3519: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3520: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3521: $context);
1.275 raeburn 3522: if ($changed->{$tool}) {
3523: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3524: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3525: if ($newval =~ /^autolimit/) {
3526: if ($limit) {
3527: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3528: } else {
3529: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3530: }
3531: } elsif ($newval) {
3532: $newaccesstext->{$tool} = $reqdisplay{$newval};
3533: } else {
3534: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3535: }
1.275 raeburn 3536: } else {
1.383 raeburn 3537: if ($newval) {
3538: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3539: } else {
3540: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3541: }
1.275 raeburn 3542: }
3543: } else {
3544: $newaccess->{$tool} = $oldaccess->{$tool};
3545: }
3546: } else {
3547: $newaccess->{$tool} = $oldaccess->{$tool};
3548: }
3549: }
3550: }
3551: return;
3552: }
3553:
1.220 raeburn 3554: sub update_roles {
1.375 raeburn 3555: my ($r,$context,$showcredits) = @_;
1.4 www 3556: my $now=time;
1.225 raeburn 3557: my @rolechanges;
1.220 raeburn 3558: my %disallowed;
1.73 sakharuk 3559: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 3560: foreach my $key (keys (%env)) {
3561: next if (! $env{$key});
1.190 raeburn 3562: next if ($key eq 'form.action');
1.27 matthew 3563: # Revoke roles
1.135 raeburn 3564: if ($key=~/^form\.rev/) {
3565: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3566: # Revoke standard role
1.170 albertel 3567: my ($scope,$role) = ($1,$2);
3568: my $result =
3569: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3570: $env{'form.ccuname'},
1.239 raeburn 3571: $scope,$role,'','',$context);
1.367 golterma 3572: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3573: &mt('Revoking [_1] in [_2]',
3574: &Apache::lonnet::plaintext($role),
1.372 raeburn 3575: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3576: $result ne "ok").'<br />');
3577: if ($result ne "ok") {
3578: $r->print(&mt('Error: [_1]',$result).'<br />');
3579: }
1.170 albertel 3580: if ($role eq 'st') {
1.202 raeburn 3581: my $result =
1.198 raeburn 3582: &Apache::lonuserutils::classlist_drop($scope,
3583: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3584: $now);
1.367 golterma 3585: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3586: }
1.225 raeburn 3587: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3588: push(@rolechanges,$role);
3589: }
1.196 raeburn 3590: }
1.195 raeburn 3591: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3592: # Revoke custom role
1.369 bisitz 3593: my $result = &Apache::lonnet::revokecustomrole(
3594: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3595: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3596: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3597: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3598: $result ne 'ok').'<br />');
3599: if ($result ne "ok") {
3600: $r->print(&mt('Error: [_1]',$result).'<br />');
3601: }
1.225 raeburn 3602: if (!grep(/^cr$/,@rolechanges)) {
3603: push(@rolechanges,'cr');
3604: }
1.64 www 3605: }
1.135 raeburn 3606: } elsif ($key=~/^form\.del/) {
3607: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3608: # Delete standard role
1.170 albertel 3609: my ($scope,$role) = ($1,$2);
3610: my $result =
3611: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3612: $env{'form.ccuname'},
1.239 raeburn 3613: $scope,$role,$now,0,1,'',
3614: $context);
1.367 golterma 3615: $r->print(&Apache::lonhtmlcommon::confirm_success(
3616: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3617: &Apache::lonnet::plaintext($role),
1.372 raeburn 3618: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3619: $result ne 'ok').'<br />');
3620: if ($result ne "ok") {
3621: $r->print(&mt('Error: [_1]',$result).'<br />');
3622: }
1.367 golterma 3623:
1.170 albertel 3624: if ($role eq 'st') {
1.202 raeburn 3625: my $result =
1.198 raeburn 3626: &Apache::lonuserutils::classlist_drop($scope,
3627: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3628: $now);
1.369 bisitz 3629: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3630: }
1.225 raeburn 3631: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3632: push(@rolechanges,$role);
3633: }
1.116 raeburn 3634: }
1.139 albertel 3635: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3636: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3637: # Delete custom role
1.369 bisitz 3638: my $result =
3639: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3640: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3641: 0,1,$context);
3642: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3643: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3644: $result ne "ok").'<br />');
3645: if ($result ne "ok") {
3646: $r->print(&mt('Error: [_1]',$result).'<br />');
3647: }
1.367 golterma 3648:
1.225 raeburn 3649: if (!grep(/^cr$/,@rolechanges)) {
3650: push(@rolechanges,'cr');
3651: }
1.116 raeburn 3652: }
1.135 raeburn 3653: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3654: my $udom = $env{'form.ccdomain'};
3655: my $uname = $env{'form.ccuname'};
1.116 raeburn 3656: # Re-enable standard role
1.135 raeburn 3657: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3658: my $url = $1;
3659: my $role = $2;
3660: my $logmsg;
3661: my $output;
3662: if ($role eq 'st') {
1.141 albertel 3663: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3664: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3665: my $credits;
3666: if ($showcredits) {
3667: my $defaultcredits =
3668: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3669: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3670: }
3671: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3672: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3673: if ($result eq 'refused' && $logmsg) {
3674: $output = $logmsg;
3675: } else {
1.369 bisitz 3676: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3677: }
1.89 raeburn 3678: } else {
1.372 raeburn 3679: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3680: &Apache::lonnet::plaintext($role),
3681: &Apache::loncommon::show_role_extent($url,$context,'st'),
3682: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3683: }
3684: }
3685: } else {
1.101 albertel 3686: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3687: $env{'form.ccuname'},$url,$role,0,$now,'','',
3688: $context);
1.367 golterma 3689: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3690: &Apache::lonnet::plaintext($role),
3691: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3692: if ($result ne "ok") {
3693: $output .= &mt('Error: [_1]',$result).'<br />';
3694: }
3695: }
1.89 raeburn 3696: $r->print($output);
1.225 raeburn 3697: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3698: push(@rolechanges,$role);
3699: }
1.113 raeburn 3700: }
1.116 raeburn 3701: # Re-enable custom role
1.139 albertel 3702: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3703: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3704: my $result = &Apache::lonnet::assigncustomrole(
3705: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3706: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3707: $r->print(&Apache::lonhtmlcommon::confirm_success(
3708: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 3709: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3710: $result ne "ok").'<br />');
3711: if ($result ne "ok") {
3712: $r->print(&mt('Error: [_1]',$result).'<br />');
3713: }
1.225 raeburn 3714: if (!grep(/^cr$/,@rolechanges)) {
3715: push(@rolechanges,'cr');
3716: }
1.116 raeburn 3717: }
1.135 raeburn 3718: } elsif ($key=~/^form\.act/) {
1.101 albertel 3719: my $udom = $env{'form.ccdomain'};
3720: my $uname = $env{'form.ccuname'};
1.141 albertel 3721: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3722: # Activate a custom role
1.83 albertel 3723: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3724: my $url='/'.$one.'/'.$two;
3725: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3726:
1.101 albertel 3727: my $start = ( $env{'form.start_'.$full} ?
3728: $env{'form.start_'.$full} :
1.88 raeburn 3729: $now );
1.101 albertel 3730: my $end = ( $env{'form.end_'.$full} ?
3731: $env{'form.end_'.$full} :
1.88 raeburn 3732: 0 );
3733:
3734: # split multiple sections
3735: my %sections = ();
1.101 albertel 3736: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3737: if ($num_sections == 0) {
1.240 raeburn 3738: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3739: } else {
1.114 albertel 3740: my %curr_groups =
1.117 raeburn 3741: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 3742: foreach my $sec (sort {$a cmp $b} keys %sections) {
3743: if (($sec eq 'none') || ($sec eq 'all') ||
3744: exists($curr_groups{$sec})) {
3745: $disallowed{$sec} = $url;
3746: next;
3747: }
3748: my $securl = $url.'/'.$sec;
1.240 raeburn 3749: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3750: }
3751: }
1.225 raeburn 3752: if (!grep(/^cr$/,@rolechanges)) {
3753: push(@rolechanges,'cr');
3754: }
1.142 raeburn 3755: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 3756: # Activate roles for sections with 3 id numbers
3757: # set start, end times, and the url for the class
1.83 albertel 3758: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 3759: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
3760: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3761: $now );
1.101 albertel 3762: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
3763: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3764: 0 );
1.83 albertel 3765: my $url='/'.$one.'/'.$two;
1.88 raeburn 3766: my $type = 'three';
3767: # split multiple sections
3768: my %sections = ();
1.101 albertel 3769: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 3770: my $credits;
3771: if ($three eq 'st') {
3772: if ($showcredits) {
3773: my $defaultcredits =
3774: &Apache::lonuserutils::get_defaultcredits($one,$two);
3775: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
3776: $credits =~ s/[^\d\.]//g;
3777: if ($credits eq $defaultcredits) {
3778: undef($credits);
3779: }
3780: }
3781: }
1.88 raeburn 3782: if ($num_sections == 0) {
1.375 raeburn 3783: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 3784: } else {
1.114 albertel 3785: my %curr_groups =
1.117 raeburn 3786: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 3787: my $emptysec = 0;
3788: foreach my $sec (sort {$a cmp $b} keys %sections) {
3789: $sec =~ s/\W//g;
1.113 raeburn 3790: if ($sec ne '') {
3791: if (($sec eq 'none') || ($sec eq 'all') ||
3792: exists($curr_groups{$sec})) {
3793: $disallowed{$sec} = $url;
3794: next;
3795: }
1.88 raeburn 3796: my $securl = $url.'/'.$sec;
1.375 raeburn 3797: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 3798: } else {
3799: $emptysec = 1;
3800: }
3801: }
3802: if ($emptysec) {
1.375 raeburn 3803: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 3804: }
1.225 raeburn 3805: }
3806: if (!grep(/^\Q$three\E$/,@rolechanges)) {
3807: push(@rolechanges,$three);
3808: }
1.135 raeburn 3809: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 3810: # Activate roles for sections with two id numbers
3811: # set start, end times, and the url for the class
1.101 albertel 3812: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
3813: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 3814: $now );
1.101 albertel 3815: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
3816: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 3817: 0 );
1.225 raeburn 3818: my $one = $1;
3819: my $two = $2;
3820: my $url='/'.$one.'/';
1.88 raeburn 3821: # split multiple sections
3822: my %sections = ();
1.225 raeburn 3823: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 3824: if ($num_sections == 0) {
1.240 raeburn 3825: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3826: } else {
3827: my $emptysec = 0;
3828: foreach my $sec (sort {$a cmp $b} keys %sections) {
3829: if ($sec ne '') {
3830: my $securl = $url.'/'.$sec;
1.240 raeburn 3831: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 3832: } else {
3833: $emptysec = 1;
3834: }
3835: }
3836: if ($emptysec) {
1.240 raeburn 3837: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3838: }
3839: }
1.225 raeburn 3840: if (!grep(/^\Q$two\E$/,@rolechanges)) {
3841: push(@rolechanges,$two);
3842: }
1.64 www 3843: } else {
1.190 raeburn 3844: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 3845: }
1.113 raeburn 3846: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 3847: $r->print('<p class="LC_warning">');
1.113 raeburn 3848: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 3849: $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 3850: } else {
1.274 bisitz 3851: $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 3852: }
1.274 bisitz 3853: $r->print('</p><p>'
3854: .&mt('Please [_1]go back[_2] and choose a different section name.'
3855: ,'<a href="javascript:history.go(-1)'
3856: ,'</a>')
3857: .'</p><br />'
3858: );
1.113 raeburn 3859: }
3860: }
1.101 albertel 3861: } # End of foreach (keys(%env))
1.75 www 3862: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 3863: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 3864: if (@rolechanges == 0) {
1.372 raeburn 3865: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 3866: }
1.225 raeburn 3867: return @rolechanges;
1.220 raeburn 3868: }
3869:
1.375 raeburn 3870: sub get_user_credits {
3871: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
3872: if ($cdom eq '' || $cnum eq '') {
3873: return unless ($env{'request.course.id'});
3874: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3875: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3876: }
3877: my $credits;
3878: my %currhash =
3879: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
3880: if (keys(%currhash) > 0) {
3881: my @items = split(/:/,$currhash{$uname.':'.$udom});
3882: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
3883: $credits = $items[$crdidx];
3884: $credits =~ s/[^\d\.]//g;
3885: }
3886: if ($credits eq $defaultcredits) {
3887: undef($credits);
3888: }
3889: return $credits;
3890: }
3891:
1.220 raeburn 3892: sub enroll_single_student {
1.375 raeburn 3893: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
3894: $showcredits,$defaultcredits) = @_;
1.318 raeburn 3895: $r->print('<h3>');
3896: if ($crstype eq 'Community') {
3897: $r->print(&mt('Enrolling Member'));
3898: } else {
3899: $r->print(&mt('Enrolling Student'));
3900: }
3901: $r->print('</h3>');
1.220 raeburn 3902:
3903: # Remove non alphanumeric values from section
3904: $env{'form.sections'}=~s/\W//g;
3905:
1.375 raeburn 3906: my $credits;
3907: if (($showcredits) && ($env{'form.credits'} ne '')) {
3908: $credits = $env{'form.credits'};
3909: $credits =~ s/[^\d\.]//g;
3910: if ($credits ne '') {
3911: if ($credits eq $defaultcredits) {
3912: undef($credits);
3913: }
3914: }
3915: }
3916:
1.220 raeburn 3917: # Clean out any old student roles the user has in this class.
3918: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
3919: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
3920: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
3921: my $enroll_result =
3922: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
3923: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
3924: $env{'form.cmiddlename'},$env{'form.clastname'},
3925: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 3926: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
3927: $credits);
1.220 raeburn 3928: if ($enroll_result =~ /^ok/) {
1.381 bisitz 3929: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 3930: if ($env{'form.sections'} ne '') {
3931: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
3932: }
3933: my ($showstart,$showend);
3934: if ($startdate <= $now) {
3935: $showstart = &mt('Access starts immediately');
3936: } else {
3937: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
3938: }
3939: if ($enddate == 0) {
3940: $showend = &mt('ends: no ending date');
3941: } else {
3942: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
3943: }
3944: $r->print('.<br />'.$showstart.'; '.$showend);
3945: if ($startdate <= $now && !$newuser) {
1.386 bisitz 3946: $r->print('<p class="LC_info">');
1.318 raeburn 3947: if ($crstype eq 'Community') {
3948: $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role will be available when the member next logs in.'));
3949: } else {
3950: $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role will be available when the student next logs in.'));
3951: }
3952: $r->print('</p>');
1.220 raeburn 3953: }
3954: } else {
3955: $r->print(&mt('unable to enroll').": ".$enroll_result);
3956: }
3957: return;
1.188 raeburn 3958: }
3959:
1.204 raeburn 3960: sub get_defaultquota_text {
3961: my ($settingstatus) = @_;
3962: my $defquotatext;
3963: if ($settingstatus eq '') {
1.383 raeburn 3964: $defquotatext = &mt('default');
1.204 raeburn 3965: } else {
3966: my ($usertypes,$order) =
3967: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
3968: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 3969: $defquotatext = &mt('default');
1.204 raeburn 3970: } else {
1.383 raeburn 3971: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 3972: }
3973: }
3974: return $defquotatext;
3975: }
3976:
1.188 raeburn 3977: sub update_result_form {
3978: my ($uhome) = @_;
3979: my $outcome =
1.367 golterma 3980: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 3981: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 3982: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3983: }
1.207 raeburn 3984: if ($env{'form.origname'} ne '') {
3985: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
3986: }
1.160 raeburn 3987: foreach my $item ('sortby','seluname','seludom') {
3988: if (exists($env{'form.'.$item})) {
1.188 raeburn 3989: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3990: }
3991: }
1.188 raeburn 3992: if ($uhome eq 'no_host') {
3993: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
3994: }
3995: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 3996: '<input type="hidden" name="currstate" value="" />'."\n".
3997: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 3998: '</form>';
3999: return $outcome;
1.4 www 4000: }
4001:
1.149 raeburn 4002: sub quota_admin {
1.378 raeburn 4003: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4004: my $quotachanged;
4005: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4006: # Current user has quota modification privileges
1.267 raeburn 4007: if (ref($changeHash) eq 'HASH') {
4008: $quotachanged = 1;
1.378 raeburn 4009: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4010: }
1.149 raeburn 4011: }
4012: return $quotachanged;
4013: }
4014:
1.267 raeburn 4015: sub tool_admin {
1.275 raeburn 4016: my ($tool,$settool,$changeHash,$context) = @_;
4017: my $canchange = 0;
1.279 raeburn 4018: if ($context eq 'requestcourses') {
1.275 raeburn 4019: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4020: $canchange = 1;
4021: }
1.300 raeburn 4022: } elsif ($context eq 'reqcrsotherdom') {
4023: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4024: $canchange = 1;
4025: }
1.362 raeburn 4026: } elsif ($context eq 'requestauthor') {
4027: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4028: $canchange = 1;
4029: }
1.275 raeburn 4030: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4031: # Current user has quota modification privileges
4032: $canchange = 1;
4033: }
1.267 raeburn 4034: my $toolchanged;
1.275 raeburn 4035: if ($canchange) {
1.267 raeburn 4036: if (ref($changeHash) eq 'HASH') {
4037: $toolchanged = 1;
1.362 raeburn 4038: if ($tool eq 'requestauthor') {
4039: $changeHash->{$context} = $settool;
4040: } else {
4041: $changeHash->{$context.'.'.$tool} = $settool;
4042: }
1.267 raeburn 4043: }
4044: }
4045: return $toolchanged;
4046: }
4047:
1.88 raeburn 4048: sub build_roles {
1.89 raeburn 4049: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4050: my $num_sections = 0;
4051: if ($sectionstr=~ /,/) {
4052: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4053: if ($role eq 'st') {
4054: $secnums[0] =~ s/\W//g;
4055: $$sections{$secnums[0]} = 1;
4056: $num_sections = 1;
4057: } else {
4058: foreach my $sec (@secnums) {
4059: $sec =~ ~s/\W//g;
1.150 banghart 4060: if (!($sec eq "")) {
1.89 raeburn 4061: if (exists($$sections{$sec})) {
4062: $$sections{$sec} ++;
4063: } else {
4064: $$sections{$sec} = 1;
4065: $num_sections ++;
4066: }
1.88 raeburn 4067: }
4068: }
4069: }
4070: } else {
4071: $sectionstr=~s/\W//g;
4072: unless ($sectionstr eq '') {
4073: $$sections{$sectionstr} = 1;
4074: $num_sections ++;
4075: }
4076: }
1.129 albertel 4077:
1.88 raeburn 4078: return $num_sections;
4079: }
4080:
1.58 www 4081: # ========================================================== Custom Role Editor
4082:
4083: sub custom_role_editor {
1.351 raeburn 4084: my ($r,$brcrum) = @_;
1.324 raeburn 4085: my $action = $env{'form.customroleaction'};
4086: my $rolename;
4087: if ($action eq 'new') {
4088: $rolename=$env{'form.newrolename'};
4089: } else {
4090: $rolename=$env{'form.rolename'};
1.59 www 4091: }
4092:
1.324 raeburn 4093: my ($crstype,$context);
4094: if ($env{'request.course.id'}) {
4095: $crstype = &Apache::loncommon::course_type();
4096: $context = 'course';
4097: } else {
4098: $context = 'domain';
4099: $crstype = $env{'form.templatecrstype'};
4100: }
1.351 raeburn 4101:
4102: $rolename=~s/[^A-Za-z0-9]//gs;
4103: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
4104: &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
4105: return;
4106: }
4107:
1.153 banghart 4108: # ------------------------------------------------------- What can be assigned?
4109: my %full=();
4110: my %courselevel=();
4111: my %courselevelcurrent=();
1.61 www 4112: my $syspriv='';
4113: my $dompriv='';
4114: my $coursepriv='';
1.153 banghart 4115: my $body_top;
1.59 www 4116: my ($rdummy,$roledef)=
4117: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 4118: # ------------------------------------------------------- Does this role exist?
1.153 banghart 4119: $body_top .= '<h2>';
1.59 www 4120: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 4121: $body_top .= &mt('Existing Role').' "';
1.61 www 4122: # ------------------------------------------------- Get current role privileges
4123: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.324 raeburn 4124: if ($crstype eq 'Community') {
4125: $syspriv =~ s/bre\&S//;
4126: }
1.59 www 4127: } else {
1.153 banghart 4128: $body_top .= &mt('New Role').' "';
1.59 www 4129: $roledef='';
4130: }
1.153 banghart 4131: $body_top .= $rolename.'"</h2>';
1.135 raeburn 4132: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4133: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4134: if (!$restrict) { $restrict='F'; }
1.60 www 4135: $courselevel{$priv}=$restrict;
1.61 www 4136: if ($coursepriv=~/\:$priv/) {
4137: $courselevelcurrent{$priv}=1;
4138: }
1.60 www 4139: $full{$priv}=1;
4140: }
4141: my %domainlevel=();
1.61 www 4142: my %domainlevelcurrent=();
1.135 raeburn 4143: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4144: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4145: if (!$restrict) { $restrict='F'; }
1.60 www 4146: $domainlevel{$priv}=$restrict;
1.61 www 4147: if ($dompriv=~/\:$priv/) {
4148: $domainlevelcurrent{$priv}=1;
4149: }
1.60 www 4150: $full{$priv}=1;
4151: }
1.61 www 4152: my %systemlevel=();
4153: my %systemlevelcurrent=();
1.135 raeburn 4154: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4155: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4156: if (!$restrict) { $restrict='F'; }
1.61 www 4157: $systemlevel{$priv}=$restrict;
4158: if ($syspriv=~/\:$priv/) {
4159: $systemlevelcurrent{$priv}=1;
4160: }
4161: $full{$priv}=1;
4162: }
1.160 raeburn 4163: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 4164: my $button_code = "\n";
1.153 banghart 4165: my $head_script = "\n";
1.301 bisitz 4166: $head_script .= '<script type="text/javascript">'."\n"
4167: .'// <![CDATA['."\n";
1.324 raeburn 4168: my @template_roles = ("in","ta","ep");
4169: if ($context eq 'domain') {
4170: push(@template_roles,"ad");
1.318 raeburn 4171: }
1.324 raeburn 4172: push(@template_roles,"st");
1.318 raeburn 4173: if ($crstype eq 'Community') {
4174: unshift(@template_roles,'co');
4175: } else {
4176: unshift(@template_roles,'cc');
4177: }
1.154 banghart 4178: foreach my $role (@template_roles) {
1.324 raeburn 4179: $head_script .= &make_script_template($role,$crstype);
1.318 raeburn 4180: $button_code .= &make_button_code($role,$crstype).' ';
1.154 banghart 4181: }
1.324 raeburn 4182: my $context_code;
4183: if ($context eq 'domain') {
4184: my $checkedCommunity = '';
4185: my $checkedCourse = ' checked="checked"';
4186: if ($env{'form.templatecrstype'} eq 'Community') {
4187: $checkedCommunity = $checkedCourse;
4188: $checkedCourse = '';
4189: }
4190: $context_code = '<label>'.
4191: '<input type="radio" name="templatecrstype" value="Course"'.$checkedCourse.' onclick="this.form.submit();">'.
4192: &mt('Course').
4193: '</label>'.(' ' x2).
4194: '<label>'.
4195: '<input type="radio" name="templatecrstype" value="Community"'.$checkedCommunity.' onclick="this.form.submit();">'.
4196: &mt('Community').
4197: '</label>'.
4198: '</fieldset>'.
4199: '<input type="hidden" name="customroleaction" value="'.
4200: $action.'" />';
4201: if ($env{'form.customroleaction'} eq 'new') {
4202: $context_code .= '<input type="hidden" name="newrolename" value="'.
4203: $rolename.'" />';
4204: } else {
4205: $context_code .= '<input type="hidden" name="rolename" value="'.
4206: $rolename.'" />';
4207: }
4208: $context_code .= '<input type="hidden" name="action" value="custom" />'.
4209: '<input type="hidden" name="phase" value="selected_custom_edit" />';
4210: }
4211:
1.301 bisitz 4212: $head_script .= "\n".$jsback."\n"
4213: .'// ]]>'."\n"
4214: .'</script>'."\n";
1.351 raeburn 4215: push (@{$brcrum},
4216: {href => "javascript:backPage(document.form1,'pickrole','')",
4217: text => "Pick custom role",
4218: faq => 282,bug=>'Instructor Interface',},
4219: {href => "javascript:backPage(document.form1,'','')",
4220: text => "Edit custom role",
4221: faq => 282,
4222: bug => 'Instructor Interface',
4223: help => 'Course_Editing_Custom_Roles'}
4224: );
4225: my $args = { bread_crumbs => $brcrum,
4226: bread_crumbs_component => 'User Management'};
4227:
4228: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4229: $head_script,$args).
4230: $body_top);
1.73 sakharuk 4231: my %lt=&Apache::lonlocal::texthash(
4232: 'prv' => "Privilege",
1.131 raeburn 4233: 'crl' => "Course Level",
1.73 sakharuk 4234: 'dml' => "Domain Level",
1.150 banghart 4235: 'ssl' => "System Level");
1.264 bisitz 4236:
1.324 raeburn 4237: $r->print('<div class="LC_left_float">'
1.264 bisitz 4238: .'<form action=""><fieldset>'
4239: .'<legend>'.&mt('Select a Template').'</legend>'
4240: .$button_code
1.324 raeburn 4241: .'</fieldset></form></div>');
4242: if ($context_code) {
4243: $r->print('<div class="LC_left_float">'
4244: .'<form action="/adm/createuser" method="post"><fieldset>'
4245: .'<legend>'.&mt('Context').'</legend>'
4246: .$context_code
4247: .'</form>'
4248: .'</div>'
4249: );
4250: }
4251: $r->print('<br clear="all" />');
1.264 bisitz 4252:
1.61 www 4253: $r->print(<<ENDCCF);
1.380 bisitz 4254: <form name="form1" method="post" action="">
1.61 www 4255: <input type="hidden" name="phase" value="set_custom_roles" />
4256: <input type="hidden" name="rolename" value="$rolename" />
4257: ENDCCF
1.135 raeburn 4258: $r->print(&Apache::loncommon::start_data_table().
4259: &Apache::loncommon::start_data_table_header_row().
4260: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
4261: '</th><th>'.$lt{'ssl'}.'</th>'.
4262: &Apache::loncommon::end_data_table_header_row());
1.324 raeburn 4263: foreach my $priv (sort(keys(%full))) {
1.318 raeburn 4264: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
1.135 raeburn 4265: $r->print(&Apache::loncommon::start_data_table_row().
4266: '<td>'.$privtext.'</td><td>'.
1.288 bisitz 4267: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c"'.
4268: ($courselevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.61 www 4269: '</td><td>'.
1.288 bisitz 4270: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.
4271: ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.324 raeburn 4272: '</td><td>');
4273: if ($priv eq 'bre' && $crstype eq 'Community') {
4274: $r->print(' ');
4275: } else {
4276: $r->print($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
4277: ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':' ');
4278: }
4279: $r->print('</td>'.
4280: &Apache::loncommon::end_data_table_row());
1.60 www 4281: }
1.135 raeburn 4282: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4283: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4284: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 4285: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4286: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4287: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4288: }
1.153 banghart 4289: # --------------------------------------------------------
4290: sub make_script_template {
1.324 raeburn 4291: my ($role,$crstype) = @_;
1.153 banghart 4292: my %full_c=();
4293: my %full_d=();
4294: my %full_s=();
4295: my $return_script;
4296: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4297: my ($priv,$restrict)=split(/\&/,$item);
4298: $full_c{$priv}=1;
4299: }
4300: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4301: my ($priv,$restrict)=split(/\&/,$item);
4302: $full_d{$priv}=1;
4303: }
1.154 banghart 4304: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.324 raeburn 4305: next if (($crstype eq 'Community') && ($item eq 'bre&S'));
1.153 banghart 4306: my ($priv,$restrict)=split(/\&/,$item);
4307: $full_s{$priv}=1;
4308: }
4309: $return_script .= 'function set_'.$role.'() {'."\n";
4310: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
4311: my %role_c;
1.155 banghart 4312: foreach my $priv (@temp) {
1.153 banghart 4313: my ($priv_item, $dummy) = split(/\&/,$priv);
4314: $role_c{$priv_item} = 1;
4315: }
1.269 raeburn 4316: my %role_d;
4317: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
4318: foreach my $priv(@temp) {
4319: my ($priv_item, $dummy) = split(/\&/,$priv);
4320: $role_d{$priv_item} = 1;
4321: }
4322: my %role_s;
4323: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
4324: foreach my $priv(@temp) {
4325: my ($priv_item, $dummy) = split(/\&/,$priv);
4326: $role_s{$priv_item} = 1;
4327: }
1.153 banghart 4328: foreach my $priv_item (keys(%full_c)) {
4329: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4330: if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
4331: (exists($role_s{$priv}))) {
1.153 banghart 4332: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
4333: } else {
4334: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
4335: }
4336: }
1.154 banghart 4337: foreach my $priv_item (keys(%full_d)) {
4338: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4339: if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
1.154 banghart 4340: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
4341: } else {
4342: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
4343: }
4344: }
4345: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 4346: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 4347: if (exists($role_s{$priv})) {
4348: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
4349: } else {
4350: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
4351: }
1.153 banghart 4352: }
4353: $return_script .= '}'."\n";
1.154 banghart 4354: return ($return_script);
4355: }
4356: # ----------------------------------------------------------
4357: sub make_button_code {
1.318 raeburn 4358: my ($role,$crstype) = @_;
4359: my $label = &Apache::lonnet::plaintext($role,$crstype);
1.301 bisitz 4360: my $button_code = '<input type="button" onclick="set_'.$role.'()" value="'.$label.'" />';
1.154 banghart 4361: return ($button_code);
1.153 banghart 4362: }
1.61 www 4363: # ---------------------------------------------------------- Call to definerole
4364: sub set_custom_role {
1.351 raeburn 4365: my ($r,$context,$brcrum) = @_;
1.101 albertel 4366: my $rolename=$env{'form.rolename'};
1.63 www 4367: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4368: if (!$rolename) {
1.351 raeburn 4369: &custom_role_editor($r,$brcrum);
1.61 www 4370: return;
4371: }
1.160 raeburn 4372: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4373: my $jscript = '<script type="text/javascript">'
4374: .'// <![CDATA['."\n"
4375: .$jsback."\n"
4376: .'// ]]>'."\n"
4377: .'</script>'."\n";
1.352 raeburn 4378: push(@{$brcrum},
4379: {href => "javascript:backPage(document.customresult,'pickrole','')",
4380: text => "Pick custom role",
4381: faq => 282,
4382: bug => 'Instructor Interface',},
4383: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4384: text => "Edit custom role",
4385: faq => 282,
4386: bug => 'Instructor Interface',},
4387: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4388: text => "Result",
4389: faq => 282,
4390: bug => 'Instructor Interface',
4391: help => 'Course_Editing_Custom_Roles'},
4392: );
4393: my $args = { bread_crumbs => $brcrum,
1.351 raeburn 4394: bread_crumbs_component => 'User Management'};
4395: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4396:
1.61 www 4397: my ($rdummy,$roledef)=
1.110 albertel 4398: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4399:
1.61 www 4400: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4401: $r->print('<h3>');
1.61 www 4402: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4403: $r->print(&mt('Existing Role').' "');
1.61 www 4404: } else {
1.73 sakharuk 4405: $r->print(&mt('New Role').' "');
1.61 www 4406: $roledef='';
4407: }
1.188 raeburn 4408: $r->print($rolename.'"</h3>');
1.61 www 4409: # ------------------------------------------------------- What can be assigned?
4410: my $sysrole='';
4411: my $domrole='';
4412: my $courole='';
4413:
1.135 raeburn 4414: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4415: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4416: if (!$restrict) { $restrict=''; }
4417: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 4418: $courole.=':'.$item;
1.61 www 4419: }
4420: }
4421:
1.135 raeburn 4422: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4423: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4424: if (!$restrict) { $restrict=''; }
4425: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 4426: $domrole.=':'.$item;
1.61 www 4427: }
4428: }
4429:
1.135 raeburn 4430: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4431: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4432: if (!$restrict) { $restrict=''; }
4433: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 4434: $sysrole.=':'.$item;
1.61 www 4435: }
4436: }
1.387 bisitz 4437: # Assign role; Compile and show result
4438: my $errmsg;
4439: my $result =
4440: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole);
4441: if ($result ne 'ok') {
4442: $errmsg = ': '.$result;
4443: }
4444: my $message =
4445: &Apache::lonhtmlcommon::confirm_success(
4446: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4447: if ($env{'request.course.id'}) {
4448: my $url='/'.$env{'request.course.id'};
1.63 www 4449: $url=~s/\_/\//g;
1.387 bisitz 4450: $result =
4451: &Apache::lonnet::assigncustomrole(
4452: $env{'user.domain'},$env{'user.name'},
4453: $url,
4454: $env{'user.domain'},$env{'user.name'},
4455: $rolename,undef,undef,undef,$context);
4456: if ($result ne 'ok') {
4457: $errmsg = ': '.$result;
4458: }
4459: $message .=
4460: '<br />'
4461: .&Apache::lonhtmlcommon::confirm_success(
4462: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4463: }
1.380 bisitz 4464: $r->print(
1.387 bisitz 4465: &Apache::loncommon::confirmwrapper($message)
4466: .'<br />'
4467: .&Apache::lonhtmlcommon::actionbox([
4468: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4469: .&mt('Create or edit another custom role')
4470: .'</a>'])
1.380 bisitz 4471: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4472: .&Apache::lonhtmlcommon::echo_form_input([])
4473: .'</form>'
1.380 bisitz 4474: );
1.58 www 4475: }
4476:
1.2 www 4477: # ================================================================ Main Handler
4478: sub handler {
4479: my $r = shift;
4480: if ($r->header_only) {
1.68 www 4481: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4482: $r->send_http_header;
4483: return OK;
4484: }
1.318 raeburn 4485: my ($context,$crstype);
1.190 raeburn 4486: if ($env{'request.course.id'}) {
4487: $context = 'course';
1.318 raeburn 4488: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4489: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4490: $context = 'author';
1.190 raeburn 4491: } else {
4492: $context = 'domain';
4493: }
1.375 raeburn 4494:
1.190 raeburn 4495: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4496: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
4497: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
1.190 raeburn 4498: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4499: my $args;
4500: my $brcrum = [];
4501: my $bread_crumbs_component = 'User Management';
1.202 raeburn 4502: if ($env{'form.action'} ne 'dateselect') {
1.351 raeburn 4503: $brcrum = [{href=>"/adm/createuser",
4504: text=>"User Management",
4505: 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'}
4506: ];
1.202 raeburn 4507: }
1.289 droeschl 4508: #SD Following files not added to help, because the corresponding .tex-files seem to
4509: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 4510: my ($permission,$allowed) =
1.318 raeburn 4511: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 4512: if (!$allowed) {
1.358 raeburn 4513: if ($context eq 'course') {
4514: $r->internal_redirect('/adm/viewclasslist');
4515: return OK;
4516: }
1.190 raeburn 4517: $env{'user.error.msg'}=
4518: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4519: "or view user status.";
4520: return HTTP_NOT_ACCEPTABLE;
4521: }
4522:
4523: &Apache::loncommon::content_type($r,'text/html');
4524: $r->send_http_header;
4525:
1.375 raeburn 4526: my $showcredits;
4527: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4528: ($context eq 'domain')) {
4529: my %domdefaults =
4530: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4531: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4532: $showcredits = 1;
4533: }
4534: }
4535:
1.190 raeburn 4536: # Main switch on form.action and form.state, as appropriate
4537: if (! exists($env{'form.action'})) {
1.351 raeburn 4538: $args = {bread_crumbs => $brcrum,
4539: bread_crumbs_component => $bread_crumbs_component};
4540: $r->print(&header(undef,$args));
1.318 raeburn 4541: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4542: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.351 raeburn 4543: push(@{$brcrum},
4544: { href => '/adm/createuser?action=upload&state=',
4545: text => 'Upload Users List',
4546: help => 'Course_Create_Class_List',
4547: });
4548: $bread_crumbs_component = 'Upload Users List';
4549: $args = {bread_crumbs => $brcrum,
4550: bread_crumbs_component => $bread_crumbs_component};
4551: $r->print(&header(undef,$args));
1.190 raeburn 4552: $r->print('<form name="studentform" method="post" '.
4553: 'enctype="multipart/form-data" '.
4554: ' action="/adm/createuser">'."\n");
4555: if (! exists($env{'form.state'})) {
4556: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4557: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4558: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4559: $crstype,$showcredits);
1.190 raeburn 4560: } elsif ($env{'form.state'} eq 'enrolling') {
4561: if ($env{'form.datatoken'}) {
1.375 raeburn 4562: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4563: $showcredits);
1.190 raeburn 4564: }
4565: } else {
4566: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4567: }
1.213 raeburn 4568: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4569: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 4570: my $phase = $env{'form.phase'};
4571: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4572: &Apache::loncreateuser::restore_prev_selections();
4573: my $srch;
4574: foreach my $item (@search) {
4575: $srch->{$item} = $env{'form.'.$item};
4576: }
1.207 raeburn 4577: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
4578: ($phase eq 'createnewuser')) {
4579: if ($env{'form.phase'} eq 'createnewuser') {
4580: my $response;
4581: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4582: my $response =
4583: '<span class="LC_warning">'
4584: .&mt('You must specify a valid username. Only the following are allowed:'
4585: .' letters numbers - . @')
4586: .'</span>';
1.221 raeburn 4587: $env{'form.phase'} = '';
1.375 raeburn 4588: &print_username_entry_form($r,$context,$response,$srch,undef,
4589: $crstype,$brcrum,$showcredits);
1.207 raeburn 4590: } else {
4591: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4592: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4593: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4594: $srch,$response,$context,
1.375 raeburn 4595: $permission,$crstype,$brcrum,
4596: $showcredits);
1.207 raeburn 4597: }
4598: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4599: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4600: &user_search_result($context,$srch);
1.190 raeburn 4601: if ($env{'form.currstate'} eq 'modify') {
4602: $currstate = $env{'form.currstate'};
4603: }
4604: if ($currstate eq 'select') {
4605: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4606: \@search,$context,undef,$crstype,
4607: $brcrum);
1.190 raeburn 4608: } elsif ($currstate eq 'modify') {
4609: my ($ccuname,$ccdomain);
4610: if (($srch->{'srchby'} eq 'uname') &&
4611: ($srch->{'srchtype'} eq 'exact')) {
4612: $ccuname = $srch->{'srchterm'};
4613: $ccdomain= $srch->{'srchdomain'};
4614: } else {
4615: my @matchedunames = keys(%{$results});
4616: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4617: }
4618: $ccuname =&LONCAPA::clean_username($ccuname);
4619: $ccdomain=&LONCAPA::clean_domain($ccdomain);
4620: if ($env{'form.forcenewuser'}) {
4621: $response = '';
4622: }
4623: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4624: $srch,$response,$context,
1.351 raeburn 4625: $permission,$crstype,$brcrum);
1.190 raeburn 4626: } elsif ($currstate eq 'query') {
1.351 raeburn 4627: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4628: } else {
1.229 raeburn 4629: $env{'form.phase'} = '';
1.207 raeburn 4630: &print_username_entry_form($r,$context,$response,$srch,
1.351 raeburn 4631: $forcenewuser,$crstype,$brcrum);
1.190 raeburn 4632: }
4633: } elsif ($env{'form.phase'} eq 'userpicked') {
4634: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4635: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 4636: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.351 raeburn 4637: $context,$permission,$crstype,
4638: $brcrum);
1.190 raeburn 4639: }
4640: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4641: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4642: } else {
1.351 raeburn 4643: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4644: $brcrum);
1.190 raeburn 4645: }
4646: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
4647: if ($env{'form.phase'} eq 'set_custom_roles') {
1.351 raeburn 4648: &set_custom_role($r,$context,$brcrum);
1.190 raeburn 4649: } else {
1.351 raeburn 4650: &custom_role_editor($r,$brcrum);
1.190 raeburn 4651: }
1.362 raeburn 4652: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4653: ($permission->{'cusr'}) &&
4654: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4655: push(@{$brcrum},
4656: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4657: text => 'Authoring Space requests',
1.362 raeburn 4658: help => 'Domain_Role_Approvals'});
4659: $bread_crumbs_component = 'Authoring requests';
4660: if ($env{'form.state'} eq 'done') {
4661: push(@{$brcrum},
4662: {href => '/adm/createuser?action=authorreqqueue',
4663: text => 'Result',
4664: help => 'Domain_Role_Approvals'});
4665: $bread_crumbs_component = 'Authoring request result';
4666: }
4667: $args = { bread_crumbs => $brcrum,
4668: bread_crumbs_component => $bread_crumbs_component};
4669: $r->print(&header(undef,$args));
4670: if (!exists($env{'form.state'})) {
4671: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4672: $env{'request.role.domain'}));
4673: } elsif ($env{'form.state'} eq 'done') {
4674: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4675: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4676: $env{'request.role.domain'}));
4677: }
1.207 raeburn 4678: } elsif (($env{'form.action'} eq 'listusers') &&
4679: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 4680: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 4681: push(@{$brcrum},
4682: {href => '/adm/createuser?action=listusers',
4683: text => "List Users"},
4684: {href => "/adm/createuser",
4685: text => "Result",
4686: help => 'Course_View_Class_List'});
4687: $bread_crumbs_component = 'Update Users';
4688: $args = {bread_crumbs => $brcrum,
4689: bread_crumbs_component => $bread_crumbs_component};
4690: $r->print(&header(undef,$args));
1.202 raeburn 4691: my $setting = $env{'form.roletype'};
4692: my $choice = $env{'form.bulkaction'};
4693: if ($permission->{'cusr'}) {
1.336 raeburn 4694: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 4695: } else {
4696: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 4697: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 4698: }
4699: } else {
1.351 raeburn 4700: push(@{$brcrum},
4701: {href => '/adm/createuser?action=listusers',
4702: text => "List Users",
4703: help => 'Course_View_Class_List'});
4704: $bread_crumbs_component = 'List Users';
4705: $args = {bread_crumbs => $brcrum,
4706: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 4707: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4708: my $formname = 'studentform';
1.364 raeburn 4709: my $hidecall = "hide_searching();";
1.321 raeburn 4710: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
4711: ($env{'form.roletype'} eq 'community'))) {
4712: if ($env{'form.roletype'} eq 'course') {
4713: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
4714: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
4715: $formname);
4716: } elsif ($env{'form.roletype'} eq 'community') {
4717: $cb_jscript =
4718: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
4719: my %elements = (
4720: coursepick => 'radio',
4721: coursetotal => 'text',
4722: courselist => 'text',
4723: );
4724: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
4725: }
1.364 raeburn 4726: $jscript .= &verify_user_display($context)."\n".
4727: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 4728: my $js = &add_script($jscript).$cb_jscript;
4729: my $loadcode =
4730: &Apache::lonuserutils::course_selector_loadcode($formname);
4731: if ($loadcode ne '') {
1.364 raeburn 4732: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
4733: } else {
4734: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 4735: }
1.351 raeburn 4736: $r->print(&header($js,$args));
1.191 raeburn 4737: } else {
1.364 raeburn 4738: $args->{add_entries} = {onload => $hidecall};
4739: $jscript = &verify_user_display($context).
4740: &Apache::loncommon::check_uncheck_jscript();
4741: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 4742: }
1.202 raeburn 4743: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 4744: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
4745: $showcredits);
1.191 raeburn 4746: }
1.213 raeburn 4747: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 4748: my $brtext;
4749: if ($crstype eq 'Community') {
4750: $brtext = 'Drop Members';
4751: } else {
4752: $brtext = 'Drop Students';
4753: }
1.351 raeburn 4754: push(@{$brcrum},
4755: {href => '/adm/createuser?action=drop',
4756: text => $brtext,
4757: help => 'Course_Drop_Student'});
4758: if ($env{'form.state'} eq 'done') {
4759: push(@{$brcrum},
4760: {href=>'/adm/createuser?action=drop',
4761: text=>"Result"});
4762: }
4763: $bread_crumbs_component = $brtext;
4764: $args = {bread_crumbs => $brcrum,
4765: bread_crumbs_component => $bread_crumbs_component};
4766: $r->print(&header(undef,$args));
1.213 raeburn 4767: if (!exists($env{'form.state'})) {
1.318 raeburn 4768: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 4769: } elsif ($env{'form.state'} eq 'done') {
4770: &Apache::lonuserutils::update_user_list($r,$context,undef,
4771: $env{'form.action'});
4772: }
1.202 raeburn 4773: } elsif ($env{'form.action'} eq 'dateselect') {
4774: if ($permission->{'cusr'}) {
1.351 raeburn 4775: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 4776: &Apache::lonuserutils::date_section_selector($context,$permission,
4777: $crstype,$showcredits));
1.202 raeburn 4778: } else {
1.351 raeburn 4779: $r->print(&header(undef,{'no_nav_bar' => 1}).
4780: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 4781: }
1.237 raeburn 4782: } elsif ($env{'form.action'} eq 'selfenroll') {
1.351 raeburn 4783: push(@{$brcrum},
4784: {href => '/adm/createuser?action=selfenroll',
4785: text => "Configure Self-enrollment",
4786: help => 'Course_Self_Enrollment'});
1.237 raeburn 4787: if (!exists($env{'form.state'})) {
1.351 raeburn 4788: $args = { bread_crumbs => $brcrum,
4789: bread_crumbs_component => 'Configure Self-enrollment'};
4790: $r->print(&header(undef,$args));
1.241 raeburn 4791: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.237 raeburn 4792: &print_selfenroll_menu($r,$context,$permission);
4793: } elsif ($env{'form.state'} eq 'done') {
1.351 raeburn 4794: push (@{$brcrum},
4795: {href=>'/adm/createuser?action=selfenroll',
4796: text=>"Result"});
4797: $args = { bread_crumbs => $brcrum,
4798: bread_crumbs_component => 'Self-enrollment result'};
4799: $r->print(&header(undef,$args));
1.241 raeburn 4800: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
4801: &update_selfenroll_config($r,$context,$permission);
1.237 raeburn 4802: }
1.277 raeburn 4803: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.351 raeburn 4804: push(@{$brcrum},
4805: {href => '/adm/createuser?action=selfenrollqueue',
4806: text => 'Enrollment requests',
4807: help => 'Course_Self_Enrollment'});
4808: $bread_crumbs_component = 'Enrollment requests';
4809: if ($env{'form.state'} eq 'done') {
4810: push(@{$brcrum},
4811: {href => '/adm/createuser?action=selfenrollqueue',
4812: text => 'Result',
4813: help => 'Course_Self_Enrollment'});
4814: $bread_crumbs_component = 'Enrollment result';
4815: }
4816: $args = { bread_crumbs => $brcrum,
4817: bread_crumbs_component => $bread_crumbs_component};
4818: $r->print(&header(undef,$args));
1.277 raeburn 4819: my $cid = $env{'request.course.id'};
4820: my $cdom = $env{'course.'.$cid.'.domain'};
4821: my $cnum = $env{'course.'.$cid.'.num'};
1.307 raeburn 4822: my $coursedesc = $env{'course.'.$cid.'.description'};
1.277 raeburn 4823: if (!exists($env{'form.state'})) {
4824: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
1.307 raeburn 4825: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
4826: $cdom,$cnum));
1.277 raeburn 4827: } elsif ($env{'form.state'} eq 'done') {
4828: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
1.307 raeburn 4829: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
4830: $cdom,$cnum,$coursedesc));
1.277 raeburn 4831: }
1.239 raeburn 4832: } elsif ($env{'form.action'} eq 'changelogs') {
1.363 raeburn 4833: my $helpitem;
4834: if ($context eq 'course') {
4835: $helpitem = 'Course_User_Logs';
4836: }
1.351 raeburn 4837: push (@{$brcrum},
4838: {href => '/adm/createuser?action=changelogs',
4839: text => 'User Management Logs',
1.363 raeburn 4840: help => $helpitem});
1.351 raeburn 4841: $bread_crumbs_component = 'User Changes';
4842: $args = { bread_crumbs => $brcrum,
4843: bread_crumbs_component => $bread_crumbs_component};
4844: $r->print(&header(undef,$args));
4845: &print_userchangelogs_display($r,$context,$permission);
1.190 raeburn 4846: } else {
1.351 raeburn 4847: $bread_crumbs_component = 'User Management';
4848: $args = { bread_crumbs => $brcrum,
4849: bread_crumbs_component => $bread_crumbs_component};
4850: $r->print(&header(undef,$args));
1.318 raeburn 4851: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4852: }
1.351 raeburn 4853: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 4854: return OK;
4855: }
4856:
4857: sub header {
1.351 raeburn 4858: my ($jscript,$args) = @_;
1.190 raeburn 4859: my $start_page;
1.351 raeburn 4860: if (ref($args) eq 'HASH') {
4861: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 4862: } else {
1.351 raeburn 4863: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 4864: }
4865: return $start_page;
4866: }
1.2 www 4867:
1.191 raeburn 4868: sub add_script {
4869: my ($js) = @_;
1.301 bisitz 4870: return '<script type="text/javascript">'."\n"
4871: .'// <![CDATA['."\n"
4872: .$js."\n"
4873: .'// ]]>'."\n"
4874: .'</script>'."\n";
1.191 raeburn 4875: }
4876:
1.202 raeburn 4877: sub verify_user_display {
1.364 raeburn 4878: my ($context) = @_;
1.374 raeburn 4879: my %lt = &Apache::lonlocal::texthash (
4880: course => 'course(s): description, section(s), status',
4881: community => 'community(s): description, section(s), status',
4882: author => 'author',
4883: );
1.364 raeburn 4884: my $photos;
4885: if (($context eq 'course') && $env{'request.course.id'}) {
4886: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
4887: }
1.202 raeburn 4888: my $output = <<"END";
4889:
1.364 raeburn 4890: function hide_searching() {
4891: if (document.getElementById('searching')) {
4892: document.getElementById('searching').style.display = 'none';
4893: }
4894: return;
4895: }
4896:
1.202 raeburn 4897: function display_update() {
4898: document.studentform.action.value = 'listusers';
4899: document.studentform.phase.value = 'display';
4900: document.studentform.submit();
4901: }
4902:
1.364 raeburn 4903: function updateCols(caller) {
4904: var context = '$context';
4905: var photos = '$photos';
4906: if (caller == 'Status') {
1.374 raeburn 4907: if ((context == 'domain') &&
4908: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
4909: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 4910: document.getElementById('showcolstatus').checked = false;
4911: document.getElementById('showcolstatus').disabled = 'disabled';
4912: document.getElementById('showcolstart').checked = false;
4913: document.getElementById('showcolend').checked = false;
1.374 raeburn 4914: } else {
4915: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
4916: document.getElementById('showcolstatus').checked = true;
4917: document.getElementById('showcolstatus').disabled = '';
4918: document.getElementById('showcolstart').checked = true;
4919: document.getElementById('showcolend').checked = true;
4920: } else {
4921: document.getElementById('showcolstatus').checked = false;
4922: document.getElementById('showcolstatus').disabled = 'disabled';
4923: document.getElementById('showcolstart').checked = false;
4924: document.getElementById('showcolend').checked = false;
4925: }
1.364 raeburn 4926: }
4927: }
4928: if (caller == 'output') {
4929: if (photos == 1) {
4930: if (document.getElementById('showcolphoto')) {
4931: var photoitem = document.getElementById('showcolphoto');
4932: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
4933: photoitem.checked = true;
4934: photoitem.disabled = '';
4935: } else {
4936: photoitem.checked = false;
4937: photoitem.disabled = 'disabled';
4938: }
4939: }
4940: }
4941: }
4942: if (caller == 'showrole') {
1.371 raeburn 4943: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
4944: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 4945: document.getElementById('showcolrole').checked = true;
4946: document.getElementById('showcolrole').disabled = '';
4947: } else {
4948: document.getElementById('showcolrole').checked = false;
4949: document.getElementById('showcolrole').disabled = 'disabled';
4950: }
1.374 raeburn 4951: if (context == 'domain') {
1.382 raeburn 4952: var quotausageshow = 0;
1.374 raeburn 4953: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
4954: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
4955: document.getElementById('showcolstatus').checked = false;
4956: document.getElementById('showcolstatus').disabled = 'disabled';
4957: document.getElementById('showcolstart').checked = false;
4958: document.getElementById('showcolend').checked = false;
4959: } else {
4960: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
4961: document.getElementById('showcolstatus').checked = true;
4962: document.getElementById('showcolstatus').disabled = '';
4963: document.getElementById('showcolstart').checked = true;
4964: document.getElementById('showcolend').checked = true;
4965: }
4966: }
4967: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
4968: document.getElementById('showcolextent').disabled = 'disabled';
4969: document.getElementById('showcolextent').checked = 'false';
4970: document.getElementById('showextent').style.display='none';
4971: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 4972: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
4973: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
4974: if (document.getElementById('showcolauthorusage')) {
4975: document.getElementById('showcolauthorusage').disabled = '';
4976: }
4977: if (document.getElementById('showcolauthorquota')) {
4978: document.getElementById('showcolauthorquota').disabled = '';
4979: }
4980: quotausageshow = 1;
4981: }
1.374 raeburn 4982: } else {
4983: document.getElementById('showextent').style.display='block';
4984: document.getElementById('showextent').style.textAlign='left';
4985: document.getElementById('showextent').style.textFace='normal';
4986: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
4987: document.getElementById('showcolextent').disabled = '';
4988: document.getElementById('showcolextent').checked = 'true';
4989: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
4990: } else {
4991: document.getElementById('showcolextent').disabled = '';
4992: document.getElementById('showcolextent').checked = 'true';
4993: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
4994: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
4995: } else {
4996: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
4997: }
4998: }
4999: }
1.382 raeburn 5000: if (quotausageshow == 0) {
5001: if (document.getElementById('showcolauthorusage')) {
5002: document.getElementById('showcolauthorusage').checked = false;
5003: document.getElementById('showcolauthorusage').disabled = 'disabled';
5004: }
5005: if (document.getElementById('showcolauthorquota')) {
5006: document.getElementById('showcolauthorquota').checked = false;
5007: document.getElementById('showcolauthorquota').disabled = 'disabled';
5008: }
5009: }
1.374 raeburn 5010: }
1.364 raeburn 5011: }
5012: return;
5013: }
5014:
1.202 raeburn 5015: END
5016: return $output;
5017:
5018: }
5019:
1.190 raeburn 5020: ###############################################################
5021: ###############################################################
5022: # Menu Phase One
5023: sub print_main_menu {
1.318 raeburn 5024: my ($permission,$context,$crstype) = @_;
5025: my $linkcontext = $context;
5026: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5027: if (($context eq 'course') && ($crstype eq 'Community')) {
5028: $linkcontext = lc($crstype);
5029: $stuterm = 'Members';
5030: }
1.208 raeburn 5031: my %links = (
1.298 droeschl 5032: domain => {
5033: upload => 'Upload a File of Users',
5034: singleuser => 'Add/Modify a User',
5035: listusers => 'Manage Users',
5036: },
5037: author => {
5038: upload => 'Upload a File of Co-authors',
5039: singleuser => 'Add/Modify a Co-author',
5040: listusers => 'Manage Co-authors',
5041: },
5042: course => {
5043: upload => 'Upload a File of Course Users',
5044: singleuser => 'Add/Modify a Course User',
1.354 www 5045: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5046: },
1.318 raeburn 5047: community => {
5048: upload => 'Upload a File of Community Users',
5049: singleuser => 'Add/Modify a Community User',
1.354 www 5050: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5051: },
5052: );
5053: my %linktitles = (
5054: domain => {
5055: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5056: listusers => 'Show and manage users in this domain.',
5057: },
5058: author => {
5059: singleuser => 'Add a user with a co- or assistant author role.',
5060: listusers => 'Show and manage co- or assistant authors.',
5061: },
5062: course => {
5063: singleuser => 'Add a user with a certain role to this course.',
5064: listusers => 'Show and manage users in this course.',
5065: },
5066: community => {
5067: singleuser => 'Add a user with a certain role to this community.',
5068: listusers => 'Show and manage users in this community.',
5069: },
1.298 droeschl 5070: );
5071: my @menu = ( {categorytitle => 'Single Users',
5072: items =>
5073: [
5074: {
1.318 raeburn 5075: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5076: icon => 'edit-redo.png',
5077: #help => 'Course_Change_Privileges',
5078: url => '/adm/createuser?action=singleuser',
5079: permission => $permission->{'cusr'},
1.318 raeburn 5080: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5081: },
5082: ]},
5083:
5084: {categorytitle => 'Multiple Users',
5085: items =>
5086: [
5087: {
1.318 raeburn 5088: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5089: icon => 'uplusr.png',
1.298 droeschl 5090: #help => 'Course_Create_Class_List',
5091: url => '/adm/createuser?action=upload',
5092: permission => $permission->{'cusr'},
5093: linktitle => 'Upload a CSV or a text file containing users.',
5094: },
5095: {
1.318 raeburn 5096: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5097: icon => 'mngcu.png',
1.298 droeschl 5098: #help => 'Course_View_Class_List',
5099: url => '/adm/createuser?action=listusers',
5100: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5101: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5102: },
5103:
5104: ]},
5105:
5106: {categorytitle => 'Administration',
5107: items => [ ]},
5108: );
5109:
1.265 mielkec 5110: if ($context eq 'domain'){
1.298 droeschl 5111:
5112: push(@{ $menu[2]->{items} }, #Category: Administration
5113: {
5114: linktext => 'Custom Roles',
5115: icon => 'emblem-photos.png',
5116: #help => 'Course_Editing_Custom_Roles',
5117: url => '/adm/createuser?action=custom',
5118: permission => $permission->{'custom'},
5119: linktitle => 'Configure a custom role.',
5120: },
1.362 raeburn 5121: {
5122: linktext => 'Authoring Space Requests',
5123: icon => 'selfenrl-queue.png',
5124: #help => 'Domain_Role_Approvals',
5125: url => '/adm/createuser?action=processauthorreq',
5126: permission => $permission->{'cusr'},
5127: linktitle => 'Approve or reject author role requests',
5128: },
1.363 raeburn 5129: {
5130: linktext => 'Change Log',
5131: icon => 'document-properties.png',
5132: #help => 'Course_User_Logs',
5133: url => '/adm/createuser?action=changelogs',
5134: permission => $permission->{'cusr'},
5135: linktitle => 'View change log.',
5136: },
1.298 droeschl 5137: );
5138:
1.265 mielkec 5139: }elsif ($context eq 'course'){
1.298 droeschl 5140: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5141:
5142: my %linktext = (
5143: 'Course' => {
5144: single => 'Add/Modify a Student',
5145: drop => 'Drop Students',
5146: groups => 'Course Groups',
5147: },
5148: 'Community' => {
5149: single => 'Add/Modify a Member',
5150: drop => 'Drop Members',
5151: groups => 'Community Groups',
5152: },
5153: );
5154:
5155: my %linktitle = (
5156: 'Course' => {
5157: single => 'Add a user with the role of student to this course',
5158: drop => 'Remove a student from this course.',
5159: groups => 'Manage course groups',
5160: },
5161: 'Community' => {
5162: single => 'Add a user with the role of member to this community',
5163: drop => 'Remove a member from this community.',
5164: groups => 'Manage community groups',
5165: },
5166: );
5167:
1.298 droeschl 5168: push(@{ $menu[0]->{items} }, #Category: Single Users
5169: {
1.318 raeburn 5170: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5171: #help => 'Course_Add_Student',
5172: icon => 'list-add.png',
5173: url => '/adm/createuser?action=singlestudent',
5174: permission => $permission->{'cusr'},
1.318 raeburn 5175: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5176: },
5177: );
5178:
5179: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5180: {
1.318 raeburn 5181: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5182: icon => 'edit-undo.png',
5183: #help => 'Course_Drop_Student',
5184: url => '/adm/createuser?action=drop',
5185: permission => $permission->{'cusr'},
1.318 raeburn 5186: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5187: },
5188: );
5189: push(@{ $menu[2]->{items} }, #Category: Administration
5190: {
5191: linktext => 'Custom Roles',
5192: icon => 'emblem-photos.png',
5193: #help => 'Course_Editing_Custom_Roles',
5194: url => '/adm/createuser?action=custom',
5195: permission => $permission->{'custom'},
5196: linktitle => 'Configure a custom role.',
5197: },
5198: {
1.318 raeburn 5199: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5200: icon => 'grps.png',
1.298 droeschl 5201: #help => 'Course_Manage_Group',
5202: url => '/adm/coursegroups?refpage=cusr',
5203: permission => $permission->{'grp_manage'},
1.318 raeburn 5204: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5205: },
5206: {
1.328 wenzelju 5207: linktext => 'Change Log',
1.298 droeschl 5208: icon => 'document-properties.png',
5209: #help => 'Course_User_Logs',
5210: url => '/adm/createuser?action=changelogs',
5211: permission => $permission->{'cusr'},
5212: linktitle => 'View change log.',
5213: },
5214: );
1.277 raeburn 5215: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5216: push(@{ $menu[2]->{items} },
5217: {
5218: linktext => 'Enrollment Requests',
5219: icon => 'selfenrl-queue.png',
5220: #help => 'Course_Approve_Selfenroll',
5221: url => '/adm/createuser?action=selfenrollqueue',
5222: permission => $permission->{'cusr'},
5223: linktitle =>'Approve or reject enrollment requests.',
5224: },
5225: );
1.277 raeburn 5226: }
1.298 droeschl 5227:
1.265 mielkec 5228: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5229: if ($crstype ne 'Community') {
5230: push(@{ $menu[2]->{items} },
5231: {
5232: linktext => 'Automated Enrollment',
5233: icon => 'roles.png',
5234: #help => 'Course_Automated_Enrollment',
5235: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
5236: && $permission->{'cusr'}),
5237: url => '/adm/populate',
5238: linktitle => 'Automated enrollment manager.',
5239: }
5240: );
5241: }
5242: push(@{ $menu[2]->{items} },
1.298 droeschl 5243: {
5244: linktext => 'User Self-Enrollment',
1.342 wenzelju 5245: icon => 'self_enroll.png',
1.298 droeschl 5246: #help => 'Course_Self_Enrollment',
5247: url => '/adm/createuser?action=selfenroll',
5248: permission => $permission->{'cusr'},
1.317 bisitz 5249: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5250: },
5251: );
5252: }
1.363 raeburn 5253: } elsif ($context eq 'author') {
1.370 raeburn 5254: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5255: {
5256: linktext => 'Change Log',
5257: icon => 'document-properties.png',
5258: #help => 'Course_User_Logs',
5259: url => '/adm/createuser?action=changelogs',
5260: permission => $permission->{'cusr'},
5261: linktitle => 'View change log.',
5262: },
1.370 raeburn 5263: );
1.363 raeburn 5264: }
5265: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5266: # { text => 'View Log-in History',
5267: # help => 'Course_User_Logins',
5268: # action => 'logins',
5269: # permission => $permission->{'cusr'},
5270: # });
1.190 raeburn 5271: }
5272:
1.189 albertel 5273: sub restore_prev_selections {
5274: my %saveable_parameters = ('srchby' => 'scalar',
5275: 'srchin' => 'scalar',
5276: 'srchtype' => 'scalar',
5277: );
5278: &Apache::loncommon::store_settings('user','user_picker',
5279: \%saveable_parameters);
5280: &Apache::loncommon::restore_settings('user','user_picker',
5281: \%saveable_parameters);
5282: }
5283:
1.237 raeburn 5284: sub print_selfenroll_menu {
5285: my ($r,$context,$permission) = @_;
1.322 raeburn 5286: my $crstype = &Apache::loncommon::course_type();
1.237 raeburn 5287: my $formname = 'enrollstudent';
5288: my $nolink = 1;
5289: my ($row,$lt) = &get_selfenroll_titles();
5290: my $groupslist = &Apache::lonuserutils::get_groupslist();
5291: my $setsec_js =
5292: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5293: my %alerts = &Apache::lonlocal::texthash(
5294: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5295: butn => 'but no user types have been checked.',
5296: wilf => "Please uncheck 'activate' or check at least one type.",
5297: );
5298: my $selfenroll_js = <<"ENDSCRIPT";
5299: function update_types(caller,num) {
5300: var delidx = getIndexByName('selfenroll_delete');
5301: var actidx = getIndexByName('selfenroll_activate');
5302: if (caller == 'selfenroll_all') {
5303: var selall;
5304: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5305: if (document.$formname.selfenroll_all[i].checked) {
5306: selall = document.$formname.selfenroll_all[i].value;
5307: }
5308: }
5309: if (selall == 1) {
5310: if (delidx != -1) {
5311: if (document.$formname.selfenroll_delete.length) {
5312: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5313: document.$formname.selfenroll_delete[j].checked = true;
5314: }
5315: } else {
5316: document.$formname.elements[delidx].checked = true;
5317: }
5318: }
5319: if (actidx != -1) {
5320: if (document.$formname.selfenroll_activate.length) {
5321: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5322: document.$formname.selfenroll_activate[j].checked = false;
5323: }
5324: } else {
5325: document.$formname.elements[actidx].checked = false;
5326: }
5327: }
5328: document.$formname.selfenroll_newdom.selectedIndex = 0;
5329: }
5330: }
5331: if (caller == 'selfenroll_activate') {
5332: if (document.$formname.selfenroll_activate.length) {
5333: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5334: if (document.$formname.selfenroll_activate[j].value == num) {
5335: if (document.$formname.selfenroll_activate[j].checked) {
5336: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5337: if (document.$formname.selfenroll_all[i].value == '1') {
5338: document.$formname.selfenroll_all[i].checked = false;
5339: }
5340: if (document.$formname.selfenroll_all[i].value == '0') {
5341: document.$formname.selfenroll_all[i].checked = true;
5342: }
5343: }
5344: }
5345: }
5346: }
5347: } else {
5348: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5349: if (document.$formname.selfenroll_all[i].value == '1') {
5350: document.$formname.selfenroll_all[i].checked = false;
5351: }
5352: if (document.$formname.selfenroll_all[i].value == '0') {
5353: document.$formname.selfenroll_all[i].checked = true;
5354: }
5355: }
5356: }
5357: }
5358: if (caller == 'selfenroll_delete') {
5359: if (document.$formname.selfenroll_delete.length) {
5360: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5361: if (document.$formname.selfenroll_delete[j].value == num) {
5362: if (document.$formname.selfenroll_delete[j].checked) {
5363: var delindex = getIndexByName('selfenroll_types_'+num);
5364: if (delindex != -1) {
5365: if (document.$formname.elements[delindex].length) {
5366: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5367: document.$formname.elements[delindex][k].checked = false;
5368: }
5369: } else {
5370: document.$formname.elements[delindex].checked = false;
5371: }
5372: }
5373: }
5374: }
5375: }
5376: } else {
5377: if (document.$formname.selfenroll_delete.checked) {
5378: var delindex = getIndexByName('selfenroll_types_'+num);
5379: if (delindex != -1) {
5380: if (document.$formname.elements[delindex].length) {
5381: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5382: document.$formname.elements[delindex][k].checked = false;
5383: }
5384: } else {
5385: document.$formname.elements[delindex].checked = false;
5386: }
5387: }
5388: }
5389: }
5390: }
5391: return;
5392: }
5393:
5394: function validate_types(form) {
5395: var needaction = new Array();
5396: var countfail = 0;
5397: var actidx = getIndexByName('selfenroll_activate');
5398: if (actidx != -1) {
5399: if (document.$formname.selfenroll_activate.length) {
5400: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5401: var num = document.$formname.selfenroll_activate[j].value;
5402: if (document.$formname.selfenroll_activate[j].checked) {
5403: countfail = check_types(num,countfail,needaction)
5404: }
5405: }
5406: } else {
5407: if (document.$formname.selfenroll_activate.checked) {
5408: var num = document.enrollstudent.selfenroll_activate.value;
5409: countfail = check_types(num,countfail,needaction)
5410: }
5411: }
5412: }
5413: if (countfail > 0) {
5414: var msg = "$alerts{'acto'}\\n";
5415: var loopend = needaction.length -1;
5416: if (loopend > 0) {
5417: for (var m=0; m<loopend; m++) {
5418: msg += needaction[m]+", ";
5419: }
5420: }
5421: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5422: alert(msg);
5423: return;
5424: }
5425: setSections(form);
5426: }
5427:
5428: function check_types(num,countfail,needaction) {
5429: var typeidx = getIndexByName('selfenroll_types_'+num);
5430: var count = 0;
5431: if (typeidx != -1) {
5432: if (document.$formname.elements[typeidx].length) {
5433: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5434: if (document.$formname.elements[typeidx][k].checked) {
5435: count ++;
5436: }
5437: }
5438: } else {
5439: if (document.$formname.elements[typeidx].checked) {
5440: count ++;
5441: }
5442: }
5443: if (count == 0) {
5444: var domidx = getIndexByName('selfenroll_dom_'+num);
5445: if (domidx != -1) {
5446: var domname = document.$formname.elements[domidx].value;
5447: needaction[countfail] = domname;
5448: countfail ++;
5449: }
5450: }
5451: }
5452: return countfail;
5453: }
5454:
5455: function getIndexByName(item) {
5456: for (var i=0;i<document.$formname.elements.length;i++) {
5457: if (document.$formname.elements[i].name == item) {
5458: return i;
5459: }
5460: }
5461: return -1;
5462: }
5463: ENDSCRIPT
1.256 raeburn 5464: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5465: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5466:
1.237 raeburn 5467: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5468: '// <![CDATA['."\n".
1.249 raeburn 5469: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5470: '// ]]>'."\n".
1.237 raeburn 5471: '</script>'."\n".
1.256 raeburn 5472: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
5473: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
5474: if (ref($visactions) eq 'HASH') {
5475: if ($visible) {
1.283 bisitz 5476: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
1.256 raeburn 5477: } else {
1.283 bisitz 5478: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5479: .$visactions->{'yous'}.
1.256 raeburn 5480: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5481: if (ref($vismsgs) eq 'ARRAY') {
5482: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5483: foreach my $item (@{$vismsgs}) {
5484: $output .= '<li>'.$visactions->{$item}.'</li>';
5485: }
5486: $output .= '</ul>';
5487: }
5488: $output .= '</p>';
5489: }
5490: }
5491: $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
5492: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5493: if (ref($row) eq 'ARRAY') {
5494: foreach my $item (@{$row}) {
5495: my $title = $item;
5496: if (ref($lt) eq 'HASH') {
5497: $title = $lt->{$item};
5498: }
1.297 bisitz 5499: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5500: if ($item eq 'types') {
5501: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 5502: my $showdomdesc = 1;
5503: my $includeempty = 1;
5504: my $num = 0;
5505: $output .= &Apache::loncommon::start_data_table().
5506: &Apache::loncommon::start_data_table_row()
5507: .'<td colspan="2"><span class="LC_nobreak"><label>'
5508: .&mt('Any user in any domain:')
5509: .' <input type="radio" name="selfenroll_all" value="1" ';
5510: if ($curr_types eq '*') {
5511: $output .= ' checked="checked" ';
5512: }
1.249 raeburn 5513: $output .= 'onchange="javascript:update_types('.
5514: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
5515: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 5516: if ($curr_types ne '*') {
5517: $output .= ' checked="checked" ';
5518: }
1.249 raeburn 5519: $output .= ' onchange="javascript:update_types('.
5520: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
5521: &Apache::loncommon::end_data_table_row().
5522: &Apache::loncommon::end_data_table().
5523: &mt('Or').'<br />'.
5524: &Apache::loncommon::start_data_table();
1.241 raeburn 5525: my %currdoms;
1.249 raeburn 5526: if ($curr_types eq '') {
1.241 raeburn 5527: $output .= &new_selfenroll_dom_row($cdom,'0');
5528: } elsif ($curr_types ne '*') {
5529: my @entries = split(/;/,$curr_types);
5530: if (@entries > 0) {
5531: foreach my $entry (@entries) {
5532: my ($currdom,$typestr) = split(/:/,$entry);
5533: $currdoms{$currdom} = 1;
5534: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 5535: my @currinsttypes = split(',',$typestr);
1.241 raeburn 5536: $output .= &Apache::loncommon::start_data_table_row()
5537: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
5538: .' '.$domdesc.' ('.$currdom.')'
5539: .'</b><input type="hidden" name="selfenroll_dom_'.$num
5540: .'" value="'.$currdom.'" /></span><br />'
5541: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 5542: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 5543: .&mt('Delete').'</label></span></td>';
1.249 raeburn 5544: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 5545: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
5546: .&Apache::loncommon::end_data_table_row();
5547: $num ++;
5548: }
5549: }
5550: }
1.249 raeburn 5551: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 5552: if ($curr_types eq '*') {
1.249 raeburn 5553: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 5554: } elsif ($curr_types eq '') {
1.249 raeburn 5555: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 5556: }
5557: $output .= &Apache::loncommon::start_data_table_row()
5558: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
5559: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
5560: $includeempty,$showdomdesc)
5561: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
5562: .'</td>'.&Apache::loncommon::end_data_table_row()
5563: .&Apache::loncommon::end_data_table();
1.237 raeburn 5564: } elsif ($item eq 'registered') {
5565: my ($regon,$regoff);
5566: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
5567: $regon = ' checked="checked" ';
5568: $regoff = ' ';
5569: } else {
5570: $regon = ' ';
5571: $regoff = ' checked="checked" ';
5572: }
5573: $output .= '<label>'.
1.245 raeburn 5574: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 5575: &mt('Yes').'</label> <label>'.
1.245 raeburn 5576: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 5577: &mt('No').'</label>';
1.237 raeburn 5578: } elsif ($item eq 'enroll_dates') {
5579: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
5580: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
5581: if ($starttime eq '') {
5582: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
5583: }
5584: if ($endtime eq '') {
5585: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
5586: }
5587: my $startform =
5588: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
5589: undef,undef,undef,undef,undef,undef,undef,$nolink);
5590: my $endform =
5591: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
5592: undef,undef,undef,undef,undef,undef,undef,$nolink);
5593: $output .= &selfenroll_date_forms($startform,$endform);
5594: } elsif ($item eq 'access_dates') {
5595: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
5596: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
5597: if ($starttime eq '') {
5598: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
5599: }
5600: if ($endtime eq '') {
5601: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
5602: }
5603: my $startform =
5604: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
5605: undef,undef,undef,undef,undef,undef,undef,$nolink);
5606: my $endform =
5607: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
5608: undef,undef,undef,undef,undef,undef,undef,$nolink);
5609: $output .= &selfenroll_date_forms($startform,$endform);
5610: } elsif ($item eq 'section') {
5611: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
5612: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
5613: my $newsecval;
5614: if ($currsec ne 'none' && $currsec ne '') {
5615: if (!defined($sections_count{$currsec})) {
5616: $newsecval = $currsec;
5617: }
5618: }
5619: my $sections_select =
5620: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
5621: $output .= '<table class="LC_createuser">'."\n".
5622: '<tr class="LC_section_row">'."\n".
5623: '<td align="center">'.&mt('Existing sections')."\n".
5624: '<br />'.$sections_select.'</td><td align="center">'.
5625: &mt('New section').'<br />'."\n".
5626: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
5627: '<input type="hidden" name="sections" value="" />'."\n".
5628: '<input type="hidden" name="state" value="done" />'."\n".
5629: '</td></tr></table>'."\n";
1.276 raeburn 5630: } elsif ($item eq 'approval') {
5631: my ($appon,$appoff);
5632: my $cid = $env{'request.course.id'};
5633: my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
5634: if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) {
5635: $appon = ' checked="checked" ';
5636: $appoff = ' ';
5637: } else {
5638: $appon = ' ';
5639: $appoff = ' checked="checked" ';
5640: }
5641: $output .= '<label>'.
5642: '<input type="radio" name="selfenroll_approval" value="1"'.$appon.'/>'.
5643: &mt('Yes').'</label> <label>'.
5644: '<input type="radio" name="selfenroll_approval" value="0"'.$appoff.'/>'.
5645: &mt('No').'</label>';
5646: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
5647: my (@ccs,%notified);
1.322 raeburn 5648: my $ccrole = 'cc';
5649: if ($crstype eq 'Community') {
5650: $ccrole = 'co';
5651: }
5652: if ($advhash{$ccrole}) {
5653: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 5654: }
5655: if ($currnotified) {
5656: foreach my $current (split(/,/,$currnotified)) {
5657: $notified{$current} = 1;
5658: if (!grep(/^\Q$current\E$/,@ccs)) {
5659: push(@ccs,$current);
5660: }
5661: }
5662: }
5663: if (@ccs) {
1.277 raeburn 5664: $output .= '<br />'.&mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.&Apache::loncommon::start_data_table().
1.276 raeburn 5665: &Apache::loncommon::start_data_table_row();
5666: my $count = 0;
5667: my $numcols = 4;
5668: foreach my $cc (sort(@ccs)) {
5669: my $notifyon;
5670: my ($ccuname,$ccudom) = split(/:/,$cc);
5671: if ($notified{$cc}) {
5672: $notifyon = ' checked="checked" ';
5673: }
5674: if ($count && !$count%$numcols) {
5675: $output .= &Apache::loncommon::end_data_table_row().
5676: &Apache::loncommon::start_data_table_row()
5677: }
5678: $output .= '<td><span class="LC_nobreak"><label>'.
5679: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
5680: &Apache::loncommon::plainname($ccuname,$ccudom).
5681: '</label></span></td>';
1.343 raeburn 5682: $count ++;
1.276 raeburn 5683: }
5684: my $rem = $count%$numcols;
5685: if ($rem) {
5686: my $emptycols = $numcols - $rem;
5687: for (my $i=0; $i<$emptycols; $i++) {
5688: $output .= '<td> </td>';
5689: }
5690: }
5691: $output .= &Apache::loncommon::end_data_table_row().
5692: &Apache::loncommon::end_data_table();
5693: }
5694: } elsif ($item eq 'limit') {
5695: my ($crslimit,$selflimit,$nolimit);
5696: my $cid = $env{'request.course.id'};
5697: my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'};
5698: my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
1.343 raeburn 5699: $nolimit = ' checked="checked" ';
1.276 raeburn 5700: if ($currlim eq 'allstudents') {
5701: $crslimit = ' checked="checked" ';
5702: $selflimit = ' ';
5703: $nolimit = ' ';
5704: } elsif ($currlim eq 'selfenrolled') {
5705: $crslimit = ' ';
5706: $selflimit = ' checked="checked" ';
5707: $nolimit = ' ';
5708: } else {
5709: $crslimit = ' ';
5710: $selflimit = ' ';
5711: }
5712: $output .= '<table><tr><td><label>'.
1.278 raeburn 5713: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 5714: &mt('No limit').'</label></td><td><label>'.
5715: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
5716: &mt('Limit by total students').'</label></td><td><label>'.
5717: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
5718: &mt('Limit by total self-enrolled students').
5719: '</td></tr><tr>'.
5720: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
5721: (' 'x3).&mt('Maximum number allowed: ').
5722: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 5723: }
5724: $output .= &Apache::lonhtmlcommon::row_closure(1);
5725: }
5726: }
5727: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 5728: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 5729: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.241 raeburn 5730: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 5731: $r->print($output);
5732: return;
5733: }
5734:
1.256 raeburn 5735: sub visible_in_cat {
5736: my ($cdom,$cnum) = @_;
5737: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5738: my ($cathash,%settable,@vismsgs,$cansetvis);
5739: my %visactions = &Apache::lonlocal::texthash(
1.316 bisitz 5740: vis => 'Your course/community currently appears in the Course/Community Catalog for this domain.',
1.256 raeburn 5741: gen => 'Courses can be both self-cataloging, based on an institutional code (e.g., fs08phy231), or can be assigned categories from a hierarchy defined for the domain.',
1.316 bisitz 5742: miss => 'Your course/community does not currently appear in the Course/Community Catalog for this domain.',
1.256 raeburn 5743: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
5744: coca => 'Courses can be absent from the Catalog, because they do not have an institutional code, have no assigned category, or have been specifically excluded.',
1.282 schafran 5745: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
1.256 raeburn 5746: take => 'Take the following action to ensure the course appears in the Catalog:',
5747: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
5748: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
5749: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
5750: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
5751: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
5752: 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',
5753: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
5754: );
1.347 raeburn 5755: $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>"');
5756: $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>"');
5757: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
1.256 raeburn 5758: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5759: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
5760: $settable{'togglecats'} = 1;
5761: }
5762: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
5763: $settable{'categorize'} = 1;
5764: }
5765: $cathash = $domconf{'coursecategories'}{'cats'};
5766: }
1.260 raeburn 5767: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 5768: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
5769: } elsif ($settable{'togglecats'}) {
5770: $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 5771: } elsif ($settable{'categorize'}) {
1.256 raeburn 5772: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
5773: } else {
5774: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
5775: }
5776:
5777: my %currsettings =
5778: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
5779: $cdom,$cnum);
5780: my $visible = 0;
5781: if ($currsettings{'internal.coursecode'} ne '') {
5782: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5783: $cathash = $domconf{'coursecategories'}{'cats'};
5784: if (ref($cathash) eq 'HASH') {
5785: if ($cathash->{'instcode::0'} eq '') {
5786: push(@vismsgs,'dc_addinst');
5787: } else {
5788: $visible = 1;
5789: }
5790: } else {
5791: $visible = 1;
5792: }
5793: } else {
5794: $visible = 1;
5795: }
5796: } else {
5797: if (ref($cathash) eq 'HASH') {
5798: if ($cathash->{'instcode::0'} ne '') {
5799: push(@vismsgs,'dc_instcode');
5800: }
5801: } else {
5802: push(@vismsgs,'dc_instcode');
5803: }
5804: }
5805: if ($currsettings{'categories'} ne '') {
5806: my $cathash;
5807: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5808: $cathash = $domconf{'coursecategories'}{'cats'};
5809: if (ref($cathash) eq 'HASH') {
5810: if (keys(%{$cathash}) == 0) {
5811: push(@vismsgs,'dc_catalog');
5812: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
5813: push(@vismsgs,'dc_categories');
5814: } else {
5815: my @currcategories = split('&',$currsettings{'categories'});
5816: my $matched = 0;
5817: foreach my $cat (@currcategories) {
5818: if ($cathash->{$cat} ne '') {
5819: $visible = 1;
5820: $matched = 1;
5821: last;
5822: }
5823: }
5824: if (!$matched) {
1.260 raeburn 5825: if ($settable{'categorize'}) {
1.256 raeburn 5826: push(@vismsgs,'chgcat');
5827: } else {
5828: push(@vismsgs,'dc_chgcat');
5829: }
5830: }
5831: }
5832: }
5833: }
5834: } else {
5835: if (ref($cathash) eq 'HASH') {
5836: if ((keys(%{$cathash}) > 1) ||
5837: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 5838: if ($settable{'categorize'}) {
1.256 raeburn 5839: push(@vismsgs,'addcat');
5840: } else {
5841: push(@vismsgs,'dc_addcat');
5842: }
5843: }
5844: }
5845: }
5846: if ($currsettings{'hidefromcat'} eq 'yes') {
5847: $visible = 0;
5848: if ($settable{'togglecats'}) {
5849: unshift(@vismsgs,'unhide');
5850: } else {
5851: unshift(@vismsgs,'dc_unhide')
5852: }
5853: }
5854: return ($visible,$cansetvis,\@vismsgs,\%visactions);
5855: }
5856:
1.241 raeburn 5857: sub new_selfenroll_dom_row {
5858: my ($newdom,$num) = @_;
5859: my $domdesc = &Apache::lonnet::domain($newdom);
5860: my $output;
5861: if ($domdesc ne '') {
5862: $output .= &Apache::loncommon::start_data_table_row()
5863: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
5864: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 5865: .'" value="'.$newdom.'" /></span><br />'
5866: .'<span class="LC_nobreak"><label><input type="checkbox" '
5867: .'name="selfenroll_activate" value="'.$num.'" '
5868: .'onchange="javascript:update_types('
5869: ."'selfenroll_activate','$num'".');" />'
5870: .&mt('Activate').'</label></span></td>';
1.241 raeburn 5871: my @currinsttypes;
5872: $output .= '<td>'.&mt('User types:').'<br />'
5873: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
5874: .&Apache::loncommon::end_data_table_row();
5875: }
5876: return $output;
5877: }
5878:
5879: sub selfenroll_inst_types {
5880: my ($num,$currdom,$currinsttypes) = @_;
5881: my $output;
5882: my $numinrow = 4;
5883: my $count = 0;
5884: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 5885: my $othervalue = 'any';
1.241 raeburn 5886: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 5887: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 5888: $othervalue = 'other';
5889: }
1.241 raeburn 5890: $output .= '<table><tr>';
5891: foreach my $type (@{$types}) {
5892: if (($count > 0) && ($count%$numinrow == 0)) {
5893: $output .= '</tr><tr>';
5894: }
5895: if (defined($usertypes->{$type})) {
1.257 raeburn 5896: my $esc_type = &escape($type);
1.241 raeburn 5897: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 5898: $esc_type.'" ';
1.241 raeburn 5899: if (ref($currinsttypes) eq 'ARRAY') {
5900: if (@{$currinsttypes} > 0) {
1.249 raeburn 5901: if (grep(/^any$/,@{$currinsttypes})) {
5902: $output .= 'checked="checked"';
1.257 raeburn 5903: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 5904: $output .= 'checked="checked"';
5905: }
1.249 raeburn 5906: } else {
5907: $output .= 'checked="checked"';
1.241 raeburn 5908: }
5909: }
5910: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
5911: }
5912: $count ++;
5913: }
5914: if (($count > 0) && ($count%$numinrow == 0)) {
5915: $output .= '</tr><tr>';
5916: }
1.249 raeburn 5917: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 5918: if (ref($currinsttypes) eq 'ARRAY') {
5919: if (@{$currinsttypes} > 0) {
1.249 raeburn 5920: if (grep(/^any$/,@{$currinsttypes})) {
5921: $output .= ' checked="checked"';
5922: } elsif ($othervalue eq 'other') {
5923: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
5924: $output .= ' checked="checked"';
5925: }
1.241 raeburn 5926: }
1.249 raeburn 5927: } else {
5928: $output .= ' checked="checked"';
1.241 raeburn 5929: }
1.249 raeburn 5930: } else {
5931: $output .= ' checked="checked"';
1.241 raeburn 5932: }
5933: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
5934: }
5935: return $output;
5936: }
5937:
1.237 raeburn 5938: sub selfenroll_date_forms {
5939: my ($startform,$endform) = @_;
5940: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 5941: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 5942: 'LC_oddrow_value')."\n".
5943: $startform."\n".
5944: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 5945: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 5946: 'LC_oddrow_value')."\n".
5947: $endform."\n".
5948: &Apache::lonhtmlcommon::row_closure(1).
5949: &Apache::lonhtmlcommon::end_pick_box();
5950: return $output;
5951: }
5952:
1.239 raeburn 5953: sub print_userchangelogs_display {
5954: my ($r,$context,$permission) = @_;
1.363 raeburn 5955: my $formname = 'rolelog';
5956: my ($username,$domain,$crstype,%roleslog);
5957: if ($context eq 'domain') {
5958: $domain = $env{'request.role.domain'};
5959: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
5960: } else {
5961: if ($context eq 'course') {
5962: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
5963: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
5964: $crstype = &Apache::loncommon::course_type();
5965: my %saveable_parameters = ('show' => 'scalar',);
5966: &Apache::loncommon::store_course_settings('roles_log',
5967: \%saveable_parameters);
5968: &Apache::loncommon::restore_course_settings('roles_log',
5969: \%saveable_parameters);
5970: } elsif ($context eq 'author') {
5971: $domain = $env{'user.domain'};
5972: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
5973: $username = $env{'user.name'};
5974: } else {
5975: undef($domain);
5976: }
5977: }
5978: if ($domain ne '' && $username ne '') {
5979: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
5980: }
5981: }
1.239 raeburn 5982: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
5983:
5984: # set defaults
5985: my $now = time();
5986: my $defstart = $now - (7*24*3600); #7 days ago
5987: my %defaults = (
5988: page => '1',
5989: show => '10',
5990: role => 'any',
5991: chgcontext => 'any',
5992: rolelog_start_date => $defstart,
5993: rolelog_end_date => $now,
5994: );
5995: my $more_records = 0;
5996:
5997: # set current
5998: my %curr;
5999: foreach my $item ('show','page','role','chgcontext') {
6000: $curr{$item} = $env{'form.'.$item};
6001: }
6002: my ($startdate,$enddate) =
6003: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6004: $curr{'rolelog_start_date'} = $startdate;
6005: $curr{'rolelog_end_date'} = $enddate;
6006: foreach my $key (keys(%defaults)) {
6007: if ($curr{$key} eq '') {
6008: $curr{$key} = $defaults{$key};
6009: }
6010: }
1.248 raeburn 6011: my (%whodunit,%changed,$version);
6012: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6013: my ($minshown,$maxshown);
1.255 raeburn 6014: $minshown = 1;
1.239 raeburn 6015: my $count = 0;
6016: if ($curr{'show'} ne &mt('all')) {
6017: $maxshown = $curr{'page'} * $curr{'show'};
6018: if ($curr{'page'} > 1) {
6019: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6020: }
6021: }
1.301 bisitz 6022:
1.327 raeburn 6023: # Form Header
6024: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6025: &role_display_filter($context,$formname,$domain,$username,\%curr,
6026: $version,$crstype));
1.327 raeburn 6027:
6028: # Create navigation
6029: my ($nav_script,$nav_links) = &userlogdisplay_nav($formname,\%curr,$more_records);
6030: my $showntableheader = 0;
6031:
6032: # Table Header
6033: my $tableheader =
6034: &Apache::loncommon::start_data_table_header_row()
6035: .'<th> </th>'
6036: .'<th>'.&mt('When').'</th>'
6037: .'<th>'.&mt('Who made the change').'</th>'
6038: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6039: .'<th>'.&mt('Role').'</th>';
6040:
6041: if ($context eq 'course') {
6042: $tableheader .= '<th>'.&mt('Section').'</th>';
6043: }
6044: $tableheader .=
6045: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6046: .'<th>'.&mt('Start').'</th>'
6047: .'<th>'.&mt('End').'</th>'
6048: .&Apache::loncommon::end_data_table_header_row();
6049:
6050: # Display user change log data
1.239 raeburn 6051: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6052: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6053: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
6054: if ($curr{'show'} ne &mt('all')) {
6055: if ($count >= $curr{'page'} * $curr{'show'}) {
6056: $more_records = 1;
6057: last;
6058: }
6059: }
6060: if ($curr{'role'} ne 'any') {
6061: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6062: }
6063: if ($curr{'chgcontext'} ne 'any') {
6064: if ($curr{'chgcontext'} eq 'selfenroll') {
6065: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6066: } else {
6067: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6068: }
6069: }
6070: $count ++;
6071: next if ($count < $minshown);
1.327 raeburn 6072: unless ($showntableheader) {
6073: $r->print($nav_script
6074: .$nav_links
6075: .&Apache::loncommon::start_data_table()
6076: .$tableheader);
6077: $r->rflush();
6078: $showntableheader = 1;
6079: }
1.239 raeburn 6080: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6081: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6082: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6083: }
6084: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6085: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6086: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6087: }
6088: my $sec = $roleslog{$id}{'logentry'}{'section'};
6089: if ($sec eq '') {
6090: $sec = &mt('None');
6091: }
6092: my ($rolestart,$roleend);
6093: if ($roleslog{$id}{'delflag'}) {
6094: $rolestart = &mt('deleted');
6095: $roleend = &mt('deleted');
6096: } else {
6097: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6098: $roleend = $roleslog{$id}{'logentry'}{'end'};
6099: if ($rolestart eq '' || $rolestart == 0) {
6100: $rolestart = &mt('No start date');
6101: } else {
6102: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6103: }
6104: if ($roleend eq '' || $roleend == 0) {
6105: $roleend = &mt('No end date');
6106: } else {
6107: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6108: }
6109: }
6110: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6111: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6112: $chgcontext = 'selfenroll';
6113: }
1.363 raeburn 6114: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6115: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6116: $chgcontext = $lt{$chgcontext};
6117: }
1.327 raeburn 6118: $r->print(
1.301 bisitz 6119: &Apache::loncommon::start_data_table_row()
6120: .'<td>'.$count.'</td>'
6121: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6122: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6123: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6124: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6125: if ($context eq 'course') {
6126: $r->print('<td>'.$sec.'</td>');
6127: }
6128: $r->print(
6129: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6130: .'<td>'.$rolestart.'</td>'
6131: .'<td>'.$roleend.'</td>'
1.327 raeburn 6132: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6133: }
6134:
1.327 raeburn 6135: if ($showntableheader) { # Table footer, if content displayed above
6136: $r->print(&Apache::loncommon::end_data_table()
6137: .$nav_links);
6138: } else { # No content displayed above
1.301 bisitz 6139: $r->print('<p class="LC_info">'
6140: .&mt('There are no records to display.')
6141: .'</p>'
6142: );
1.239 raeburn 6143: }
1.301 bisitz 6144:
1.327 raeburn 6145: # Form Footer
6146: $r->print(
6147: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6148: .'<input type="hidden" name="action" value="changelogs" />'
6149: .'</form>');
6150: return;
6151: }
1.301 bisitz 6152:
1.327 raeburn 6153: sub userlogdisplay_nav {
6154: my ($formname,$curr,$more_records) = @_;
6155: my ($nav_script,$nav_links);
6156: if (ref($curr) eq 'HASH') {
6157: # Create Navigation:
6158: # Navigation Script
6159: $nav_script = <<"ENDSCRIPT";
1.239 raeburn 6160: <script type="text/javascript">
1.301 bisitz 6161: // <![CDATA[
1.239 raeburn 6162: function chgPage(caller) {
6163: if (caller == 'previous') {
6164: document.$formname.page.value --;
6165: }
6166: if (caller == 'next') {
6167: document.$formname.page.value ++;
6168: }
1.327 raeburn 6169: document.$formname.submit();
1.239 raeburn 6170: return;
6171: }
1.301 bisitz 6172: // ]]>
1.239 raeburn 6173: </script>
6174: ENDSCRIPT
1.327 raeburn 6175: # Navigation Buttons
6176: $nav_links = '<p>';
6177: if (($curr->{'page'} > 1) || ($more_records)) {
6178: if ($curr->{'page'} > 1) {
6179: $nav_links .= '<input type="button"'
6180: .' onclick="javascript:chgPage('."'previous'".');"'
6181: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
6182: .'" /> ';
6183: }
6184: if ($more_records) {
6185: $nav_links .= '<input type="button"'
6186: .' onclick="javascript:chgPage('."'next'".');"'
6187: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
6188: .'" />';
6189: }
1.301 bisitz 6190: }
1.327 raeburn 6191: $nav_links .= '</p>';
1.301 bisitz 6192: }
1.327 raeburn 6193: return ($nav_script,$nav_links);
1.239 raeburn 6194: }
6195:
6196: sub role_display_filter {
1.363 raeburn 6197: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
6198: my $lctype;
6199: if ($context eq 'course') {
6200: $lctype = lc($crstype);
6201: }
1.239 raeburn 6202: my $nolink = 1;
6203: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 6204: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 6205: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
6206: (&mt('all'),5,10,20,50,100,1000,10000)).
6207: '</td><td> </td>';
6208: my $startform =
6209: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
6210: $curr->{'rolelog_start_date'},undef,
6211: undef,undef,undef,undef,undef,undef,$nolink);
6212: my $endform =
6213: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
6214: $curr->{'rolelog_end_date'},undef,
6215: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 6216: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 6217: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
6218: '<table><tr><td>'.&mt('After:').
6219: '</td><td>'.$startform.'</td></tr>'.
6220: '<tr><td>'.&mt('Before:').'</td>'.
6221: '<td>'.$endform.'</td></tr></table>'.
6222: '</td>'.
6223: '<td> </td>'.
1.239 raeburn 6224: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
6225: '<select name="role"><option value="any"';
6226: if ($curr->{'role'} eq 'any') {
6227: $output .= ' selected="selected"';
6228: }
6229: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 6230: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 6231: foreach my $role (@roles) {
6232: my $plrole;
6233: if ($role eq 'cr') {
6234: $plrole = &mt('Custom Role');
6235: } else {
1.318 raeburn 6236: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 6237: }
6238: my $selstr = '';
6239: if ($role eq $curr->{'role'}) {
6240: $selstr = ' selected="selected"';
6241: }
6242: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
6243: }
1.301 bisitz 6244: $output .= '</select></td>'.
6245: '<td> </td>'.
6246: '<td valign="top"><b>'.
1.239 raeburn 6247: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 6248: my @posscontexts;
6249: if ($context eq 'course') {
1.376 raeburn 6250: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 6251: } elsif ($context eq 'domain') {
6252: @posscontexts = ('any','domain','requestauthor','domconfig','server');
6253: } else {
6254: @posscontexts = ('any','author','domain');
6255: }
6256: foreach my $chgtype (@posscontexts) {
1.239 raeburn 6257: my $selstr = '';
6258: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 6259: $selstr = ' selected="selected"';
1.239 raeburn 6260: }
1.363 raeburn 6261: if ($context eq 'course') {
1.376 raeburn 6262: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 6263: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
6264: }
1.239 raeburn 6265: }
6266: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 6267: }
1.303 bisitz 6268: $output .= '</select></td>'
6269: .'</tr></table>';
6270:
6271: # Update Display button
6272: $output .= '<p>'
6273: .'<input type="submit" value="'.&mt('Update Display').'" />'
6274: .'</p>';
6275:
6276: # Server version info
1.363 raeburn 6277: my $needsrev = '2.11.0';
6278: if ($context eq 'course') {
6279: $needsrev = '2.7.0';
6280: }
6281:
1.303 bisitz 6282: $output .= '<p class="LC_info">'
6283: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 6284: ,$needsrev);
1.248 raeburn 6285: if ($version) {
1.303 bisitz 6286: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
6287: }
6288: $output .= '</p><hr />';
1.239 raeburn 6289: return $output;
6290: }
6291:
6292: sub rolechg_contexts {
1.363 raeburn 6293: my ($context,$crstype) = @_;
6294: my %lt;
6295: if ($context eq 'course') {
6296: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 6297: any => 'Any',
1.376 raeburn 6298: automated => 'Automated Enrollment',
1.239 raeburn 6299: updatenow => 'Roster Update',
6300: createcourse => 'Course Creation',
6301: course => 'User Management in course',
6302: domain => 'User Management in domain',
1.313 raeburn 6303: selfenroll => 'Self-enrolled',
1.318 raeburn 6304: requestcourses => 'Course Request',
1.239 raeburn 6305: );
1.363 raeburn 6306: if ($crstype eq 'Community') {
6307: $lt{'createcourse'} = &mt('Community Creation');
6308: $lt{'course'} = &mt('User Management in community');
6309: $lt{'requestcourses'} = &mt('Community Request');
6310: }
6311: } elsif ($context eq 'domain') {
6312: %lt = &Apache::lonlocal::texthash (
6313: any => 'Any',
6314: domain => 'User Management in domain',
6315: requestauthor => 'Authoring Request',
6316: server => 'Command line script (DC role)',
6317: domconfig => 'Self-enrolled',
6318: );
6319: } else {
6320: %lt = &Apache::lonlocal::texthash (
6321: any => 'Any',
6322: domain => 'User Management in domain',
6323: author => 'User Management by author',
6324: );
6325: }
1.239 raeburn 6326: return %lt;
6327: }
6328:
1.27 matthew 6329: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 6330: sub user_search_result {
1.221 raeburn 6331: my ($context,$srch) = @_;
1.160 raeburn 6332: my %allhomes;
6333: my %inst_matches;
6334: my %srch_results;
1.181 raeburn 6335: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 6336: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 6337: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 6338: $response = &mt('Invalid search.');
6339: }
6340: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
6341: $response = &mt('Invalid search.');
6342: }
1.177 raeburn 6343: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 6344: $response = &mt('Invalid search.');
6345: }
6346: if ($srch->{'srchterm'} eq '') {
6347: $response = &mt('You must enter a search term.');
6348: }
1.183 raeburn 6349: if ($srch->{'srchterm'} =~ /^\s+$/) {
6350: $response = &mt('Your search term must contain more than just spaces.');
6351: }
1.160 raeburn 6352: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
6353: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 6354: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 6355: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
6356: }
6357: }
6358: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
6359: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 6360: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 6361: my $unamecheck = $srch->{'srchterm'};
6362: if ($srch->{'srchtype'} eq 'contains') {
6363: if ($unamecheck !~ /^\w/) {
6364: $unamecheck = 'a'.$unamecheck;
6365: }
6366: }
6367: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 6368: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
6369: }
1.160 raeburn 6370: }
6371: }
1.180 raeburn 6372: if ($response ne '') {
6373: $response = '<span class="LC_warning">'.$response.'</span>';
6374: }
1.160 raeburn 6375: if ($srch->{'srchin'} eq 'instd') {
6376: my $instd_chk = &directorysrch_check($srch);
6377: if ($instd_chk ne 'ok') {
1.180 raeburn 6378: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
6379: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 6380: }
6381: }
6382: if ($response ne '') {
1.180 raeburn 6383: return ($currstate,$response);
1.160 raeburn 6384: }
6385: if ($srch->{'srchby'} eq 'uname') {
6386: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
6387: if ($env{'form.forcenew'}) {
6388: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
6389: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6390: if ($uhome eq 'no_host') {
6391: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 6392: my $showdom = &display_domain_info($env{'request.role.domain'});
6393: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 6394: } else {
1.179 raeburn 6395: $currstate = 'modify';
1.160 raeburn 6396: }
6397: } else {
1.179 raeburn 6398: $currstate = 'modify';
1.160 raeburn 6399: }
6400: } else {
6401: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 6402: if ($srch->{'srchtype'} eq 'exact') {
6403: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6404: if ($uhome eq 'no_host') {
1.179 raeburn 6405: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6406: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6407: } else {
1.179 raeburn 6408: $currstate = 'modify';
1.310 raeburn 6409: my $uname = $srch->{'srchterm'};
6410: my $udom = $srch->{'srchdomain'};
6411: $srch_results{$uname.':'.$udom} =
6412: { &Apache::lonnet::get('environment',
6413: ['firstname',
6414: 'lastname',
6415: 'permanentemail'],
6416: $udom,$uname)
6417: };
1.162 raeburn 6418: }
6419: } else {
6420: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6421: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6422: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6423: }
6424: } else {
1.167 albertel 6425: my $courseusers = &get_courseusers();
1.162 raeburn 6426: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 6427: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 6428: $currstate = 'modify';
1.162 raeburn 6429: } else {
1.179 raeburn 6430: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6431: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6432: }
1.160 raeburn 6433: } else {
1.167 albertel 6434: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 6435: my ($cuname,$cudomain) = split(/:/,$user);
6436: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 6437: my $matched = 0;
6438: if ($srch->{'srchtype'} eq 'begins') {
6439: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
6440: $matched = 1;
6441: }
6442: } else {
6443: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
6444: $matched = 1;
6445: }
6446: }
6447: if ($matched) {
1.167 albertel 6448: $srch_results{$user} =
6449: {&Apache::lonnet::get('environment',
6450: ['firstname',
6451: 'lastname',
1.194 albertel 6452: 'permanentemail'],
6453: $cudomain,$cuname)};
1.162 raeburn 6454: }
6455: }
6456: }
1.179 raeburn 6457: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6458: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6459: }
6460: }
6461: }
6462: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6463: $currstate = 'query';
1.160 raeburn 6464: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6465: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6466: if ($dirsrchres eq 'ok') {
6467: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6468: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6469: } else {
6470: my $showdom = &display_domain_info($srch->{'srchdomain'});
6471: $response = '<span class="LC_warning">'.
6472: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6473: '</span><br />'.
6474: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6475: '<br /><br />';
6476: }
1.160 raeburn 6477: }
6478: } else {
6479: if ($srch->{'srchin'} eq 'dom') {
6480: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6481: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6482: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6483: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 6484: my $courseusers = &get_courseusers();
6485: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 6486: my ($uname,$udom) = split(/:/,$user);
6487: my %names = &Apache::loncommon::getnames($uname,$udom);
6488: my %emails = &Apache::loncommon::getemails($uname,$udom);
6489: if ($srch->{'srchby'} eq 'lastname') {
6490: if ((($srch->{'srchtype'} eq 'exact') &&
6491: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 6492: (($srch->{'srchtype'} eq 'begins') &&
6493: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 6494: (($srch->{'srchtype'} eq 'contains') &&
6495: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
6496: $srch_results{$user} = {firstname => $names{'firstname'},
6497: lastname => $names{'lastname'},
6498: permanentemail => $emails{'permanentemail'},
6499: };
6500: }
6501: } elsif ($srch->{'srchby'} eq 'lastfirst') {
6502: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 6503: $srchlast =~ s/\s+$//;
6504: $srchfirst =~ s/^\s+//;
1.160 raeburn 6505: if ($srch->{'srchtype'} eq 'exact') {
6506: if (($names{'lastname'} eq $srchlast) &&
6507: ($names{'firstname'} eq $srchfirst)) {
6508: $srch_results{$user} = {firstname => $names{'firstname'},
6509: lastname => $names{'lastname'},
6510: permanentemail => $emails{'permanentemail'},
6511:
6512: };
6513: }
1.177 raeburn 6514: } elsif ($srch->{'srchtype'} eq 'begins') {
6515: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
6516: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
6517: $srch_results{$user} = {firstname => $names{'firstname'},
6518: lastname => $names{'lastname'},
6519: permanentemail => $emails{'permanentemail'},
6520: };
6521: }
6522: } else {
1.160 raeburn 6523: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
6524: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
6525: $srch_results{$user} = {firstname => $names{'firstname'},
6526: lastname => $names{'lastname'},
6527: permanentemail => $emails{'permanentemail'},
6528: };
6529: }
6530: }
6531: }
6532: }
1.179 raeburn 6533: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6534: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6535: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6536: $currstate = 'query';
1.160 raeburn 6537: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6538: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6539: if ($dirsrchres eq 'ok') {
6540: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6541: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6542: } else {
6543: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
6544: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6545: '</span><br />'.
6546: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6547: '<br /><br />';
6548: }
1.160 raeburn 6549: }
6550: }
1.179 raeburn 6551: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 6552: }
6553:
6554: sub directorysrch_check {
6555: my ($srch) = @_;
6556: my $can_search = 0;
6557: my $response;
6558: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
6559: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 6560: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 6561: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
6562: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 6563: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 6564: }
6565: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
6566: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 6567: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 6568: }
6569: my @usertypes = split(/:/,$env{'environment.inststatus'});
6570: if (!@usertypes) {
6571: push(@usertypes,'default');
6572: }
6573: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
6574: foreach my $type (@usertypes) {
6575: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
6576: $can_search = 1;
6577: last;
6578: }
6579: }
6580: }
6581: if (!$can_search) {
6582: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
6583: my @longtypes;
6584: foreach my $item (@usertypes) {
1.229 raeburn 6585: if (defined($insttypes->{$item})) {
6586: push (@longtypes,$insttypes->{$item});
6587: } elsif ($item eq 'default') {
6588: push (@longtypes,&mt('other'));
6589: }
1.160 raeburn 6590: }
6591: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 6592: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 6593: }
1.160 raeburn 6594: } else {
6595: $can_search = 1;
6596: }
6597: } else {
1.180 raeburn 6598: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 6599: }
6600: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 6601: uname => 'username',
1.160 raeburn 6602: lastfirst => 'last name, first name',
1.167 albertel 6603: lastname => 'last name',
1.172 raeburn 6604: contains => 'contains',
1.178 raeburn 6605: exact => 'as exact match to',
6606: begins => 'begins with',
1.160 raeburn 6607: );
6608: if ($can_search) {
6609: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
6610: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 6611: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 6612: }
6613: } else {
1.180 raeburn 6614: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 6615: }
6616: }
6617: if ($can_search) {
1.178 raeburn 6618: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
6619: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
6620: return 'ok';
6621: } else {
1.180 raeburn 6622: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 6623: }
6624: } else {
6625: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
6626: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
6627: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
6628: return 'ok';
6629: } else {
1.180 raeburn 6630: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 6631: }
1.160 raeburn 6632: }
6633: }
6634: }
6635:
6636: sub get_courseusers {
6637: my %advhash;
1.167 albertel 6638: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 6639: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
6640: foreach my $role (sort(keys(%coursepersonnel))) {
6641: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 6642: if (!exists($classlist->{$user})) {
6643: $classlist->{$user} = [];
6644: }
1.160 raeburn 6645: }
6646: }
1.167 albertel 6647: return $classlist;
1.160 raeburn 6648: }
6649:
6650: sub build_search_response {
1.221 raeburn 6651: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 6652: my ($currstate,$response,$forcenewuser);
1.160 raeburn 6653: my %names = (
1.330 bisitz 6654: 'uname' => 'username',
6655: 'lastname' => 'last name',
1.160 raeburn 6656: 'lastfirst' => 'last name, first name',
1.330 bisitz 6657: 'crs' => 'this course',
6658: 'dom' => 'LON-CAPA domain',
6659: 'instd' => 'the institutional directory for domain',
1.160 raeburn 6660: );
6661:
6662: my %single = (
1.180 raeburn 6663: begins => 'A match',
1.160 raeburn 6664: contains => 'A match',
1.180 raeburn 6665: exact => 'An exact match',
1.160 raeburn 6666: );
6667: my %nomatch = (
1.180 raeburn 6668: begins => 'No match',
1.160 raeburn 6669: contains => 'No match',
1.180 raeburn 6670: exact => 'No exact match',
1.160 raeburn 6671: );
6672: if (keys(%srch_results) > 1) {
1.179 raeburn 6673: $currstate = 'select';
1.160 raeburn 6674: } else {
6675: if (keys(%srch_results) == 1) {
1.179 raeburn 6676: $currstate = 'modify';
1.180 raeburn 6677: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
6678: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 6679: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 6680: }
1.330 bisitz 6681: } else { # Search has nothing found. Prepare message to user.
6682: $response = '<span class="LC_warning">';
1.180 raeburn 6683: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 6684: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
6685: '<b>'.$srch->{'srchterm'}.'</b>',
6686: &display_domain_info($srch->{'srchdomain'}));
6687: } else {
6688: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
6689: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 6690: }
6691: $response .= '</span>';
1.330 bisitz 6692:
1.160 raeburn 6693: if ($srch->{'srchin'} ne 'alc') {
6694: $forcenewuser = 1;
6695: my $cansrchinst = 0;
6696: if ($srch->{'srchdomain'}) {
6697: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
6698: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6699: if ($domconfig{'directorysrch'}{'available'}) {
6700: $cansrchinst = 1;
6701: }
6702: }
6703: }
1.180 raeburn 6704: if ((($srch->{'srchby'} eq 'lastfirst') ||
6705: ($srch->{'srchby'} eq 'lastname')) &&
6706: ($srch->{'srchin'} eq 'dom')) {
6707: if ($cansrchinst) {
6708: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 6709: }
6710: }
1.180 raeburn 6711: if ($srch->{'srchin'} eq 'crs') {
6712: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
6713: }
6714: }
1.305 raeburn 6715: my $createdom = $env{'request.role.domain'};
6716: if ($context eq 'requestcrs') {
6717: if ($env{'form.coursedom'} ne '') {
6718: $createdom = $env{'form.coursedom'};
6719: }
6720: }
6721: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $createdom)) {
1.221 raeburn 6722: my $cancreate =
1.305 raeburn 6723: &Apache::lonuserutils::can_create_user($createdom,$context);
6724: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 6725: if ($cancreate) {
1.305 raeburn 6726: my $showdom = &display_domain_info($createdom);
1.266 bisitz 6727: $response .= '<br /><br />'
6728: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 6729: .'<br />';
6730: if ($context eq 'requestcrs') {
6731: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
6732: } else {
6733: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
6734: }
6735: $response .='<ul><li>'
1.266 bisitz 6736: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
6737: .'</li><li>'
6738: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
6739: .'</li><li>'
6740: .&mt('Provide the proposed username')
6741: .'</li><li>'
6742: .&mt("Click 'Search'")
6743: .'</li></ul><br />';
1.221 raeburn 6744: } else {
6745: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.305 raeburn 6746: $response .= '<br /><br />';
6747: if ($context eq 'requestcrs') {
1.314 raeburn 6748: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.305 raeburn 6749: } else {
6750: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
6751: }
6752: $response .= '<br />'
6753: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 6754: ,' <a'.$helplink.'>'
6755: ,'</a>')
1.305 raeburn 6756: .'<br /><br />';
1.221 raeburn 6757: }
1.160 raeburn 6758: }
6759: }
6760: }
1.179 raeburn 6761: return ($currstate,$response,$forcenewuser);
1.160 raeburn 6762: }
6763:
1.180 raeburn 6764: sub display_domain_info {
6765: my ($dom) = @_;
6766: my $output = $dom;
6767: if ($dom ne '') {
6768: my $domdesc = &Apache::lonnet::domain($dom,'description');
6769: if ($domdesc ne '') {
6770: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
6771: }
6772: }
6773: return $output;
6774: }
6775:
1.160 raeburn 6776: sub crumb_utilities {
6777: my %elements = (
6778: crtuser => {
6779: srchterm => 'text',
1.172 raeburn 6780: srchin => 'selectbox',
1.160 raeburn 6781: srchby => 'selectbox',
6782: srchtype => 'selectbox',
6783: srchdomain => 'selectbox',
6784: },
1.207 raeburn 6785: crtusername => {
6786: srchterm => 'text',
6787: srchdomain => 'selectbox',
6788: },
1.160 raeburn 6789: docustom => {
6790: rolename => 'selectbox',
6791: newrolename => 'textbox',
6792: },
1.179 raeburn 6793: studentform => {
6794: srchterm => 'text',
6795: srchin => 'selectbox',
6796: srchby => 'selectbox',
6797: srchtype => 'selectbox',
6798: srchdomain => 'selectbox',
6799: },
1.160 raeburn 6800: );
6801:
6802: my $jsback .= qq|
6803: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 6804: if (typeof prevphase == 'undefined') {
6805: formname.phase.value = '';
6806: }
6807: else {
6808: formname.phase.value = prevphase;
6809: }
6810: if (typeof prevstate == 'undefined') {
6811: formname.currstate.value = '';
6812: }
6813: else {
6814: formname.currstate.value = prevstate;
6815: }
1.160 raeburn 6816: formname.submit();
6817: }
6818: |;
6819: return ($jsback,\%elements);
6820: }
6821:
1.26 matthew 6822: sub course_level_table {
1.375 raeburn 6823: my ($inccourses,$showcredits,$defaultcredits) = @_;
6824: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 6825: my $table = '';
1.62 www 6826: # Custom Roles?
6827:
1.190 raeburn 6828: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 6829: my %lt=&Apache::lonlocal::texthash(
6830: 'exs' => "Existing sections",
6831: 'new' => "Define new section",
6832: 'ssd' => "Set Start Date",
6833: 'sed' => "Set End Date",
1.131 raeburn 6834: 'crl' => "Course Level",
1.89 raeburn 6835: 'act' => "Activate",
6836: 'rol' => "Role",
6837: 'ext' => "Extent",
1.113 raeburn 6838: 'grs' => "Section",
1.375 raeburn 6839: 'crd' => "Credits",
1.89 raeburn 6840: 'sta' => "Start",
6841: 'end' => "End"
6842: );
1.62 www 6843:
1.375 raeburn 6844: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 6845: my $thiscourse=$protectedcourse;
1.26 matthew 6846: $thiscourse=~s:_:/:g;
6847: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 6848: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 6849: my $area=$coursedata{'description'};
1.321 raeburn 6850: my $crstype=$coursedata{'type'};
1.135 raeburn 6851: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 6852: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 6853: my %sections_count;
1.101 albertel 6854: if (defined($env{'request.course.id'})) {
6855: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 6856: %sections_count =
6857: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 6858: }
6859: }
1.321 raeburn 6860: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 6861: foreach my $role (@roles) {
1.321 raeburn 6862: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 6863: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
6864: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 6865: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 6866: $plrole,\%sections_count,\%lt,
6867: $defaultcredits,$crstype);
1.221 raeburn 6868: } elsif ($env{'request.course.sec'} ne '') {
6869: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
6870: $env{'request.course.sec'})) {
6871: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 6872: $plrole,\%sections_count,\%lt,
6873: $defaultcredits,$crstype);
1.26 matthew 6874: }
6875: }
6876: }
1.221 raeburn 6877: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 6878: foreach my $cust (sort(keys(%customroles))) {
6879: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 6880: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
6881: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
6882: $cust,\%sections_count,\%lt);
6883: }
1.62 www 6884: }
1.26 matthew 6885: }
6886: return '' if ($table eq ''); # return nothing if there is nothing
6887: # in the table
1.188 raeburn 6888: my $result;
6889: if (!$env{'request.course.id'}) {
6890: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
6891: }
6892: $result .=
1.136 raeburn 6893: &Apache::loncommon::start_data_table().
6894: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 6895: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
6896: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'crd'}.'</th>'."\n".
6897: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
6898: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 6899: &Apache::loncommon::end_data_table_header_row().
6900: $table.
6901: &Apache::loncommon::end_data_table();
1.26 matthew 6902: return $result;
6903: }
1.88 raeburn 6904:
1.221 raeburn 6905: sub course_level_row {
1.375 raeburn 6906: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
6907: $lt,$defaultcredits,$crstype) = @_;
6908: my $creditem;
1.222 raeburn 6909: my $row = &Apache::loncommon::start_data_table_row().
6910: ' <td><input type="checkbox" name="act_'.
6911: $protectedcourse.'_'.$role.'" /></td>'."\n".
6912: ' <td>'.$plrole.'</td>'."\n".
6913: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.375 raeburn 6914: if (($role eq 'st') && ($crstype eq 'Course')) {
6915: $row .=
6916: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
6917: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
6918: } else {
6919: $row .= '<td> </td>';
6920: }
1.322 raeburn 6921: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 6922: $row .= '<td> </td>';
1.221 raeburn 6923: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 6924: $row .= ' <td><input type="hidden" value="'.
6925: $env{'request.course.sec'}.'" '.
6926: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
6927: $env{'request.course.sec'}.'</td>';
1.221 raeburn 6928: } else {
6929: if (ref($sections_count) eq 'HASH') {
6930: my $currsec =
6931: &Apache::lonuserutils::course_sections($sections_count,
6932: $protectedcourse.'_'.$role);
1.222 raeburn 6933: $row .= '<td><table class="LC_createuser">'."\n".
6934: '<tr class="LC_section_row">'."\n".
6935: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
6936: $currsec.'</td>'."\n".
6937: ' <td> </td>'."\n".
6938: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 6939: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
6940: '" value="" />'.
6941: '<input type="hidden" '.
6942: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 6943: '</tr></table></td>'."\n";
1.221 raeburn 6944: } else {
1.222 raeburn 6945: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 6946: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 6947: }
6948: }
1.222 raeburn 6949: $row .= <<ENDTIMEENTRY;
6950: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 6951: <a href=
6952: "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 6953: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 6954: <a href=
6955: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
6956: ENDTIMEENTRY
1.222 raeburn 6957: $row .= &Apache::loncommon::end_data_table_row();
6958: return $row;
1.221 raeburn 6959: }
6960:
1.88 raeburn 6961: sub course_level_dc {
1.375 raeburn 6962: my ($dcdom,$showcredits) = @_;
1.190 raeburn 6963: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 6964: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 6965: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
6966: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 6967: '<input type="hidden" name="dccourse" value="" />';
1.355 www 6968: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 6969: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 6970: my $credit_elem;
6971: if ($showcredits) {
6972: $credit_elem = 'credits';
6973: }
6974: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 6975: my %lt=&Apache::lonlocal::texthash(
6976: 'rol' => "Role",
1.113 raeburn 6977: 'grs' => "Section",
1.88 raeburn 6978: 'exs' => "Existing sections",
6979: 'new' => "Define new section",
6980: 'sta' => "Start",
6981: 'end' => "End",
6982: 'ssd' => "Set Start Date",
1.355 www 6983: 'sed' => "Set End Date",
1.375 raeburn 6984: 'scc' => "Course/Community",
6985: 'crd' => "Credits",
1.88 raeburn 6986: );
1.323 raeburn 6987: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 6988: &Apache::loncommon::start_data_table().
6989: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 6990: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
6991: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'crd'}.'</th>'."\n".
6992: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 6993: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 6994: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 6995: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
6996: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 6997: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 6998: foreach my $role (@roles) {
1.135 raeburn 6999: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 7000: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 7001: }
7002: if ( keys %customroles > 0) {
1.135 raeburn 7003: foreach my $cust (sort keys %customroles) {
1.101 albertel 7004: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 7005: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 7006: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 7007: }
7008: }
7009: $otheritems .= '</select></td><td>'.
7010: '<table border="0" cellspacing="0" cellpadding="0">'.
7011: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 7012: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 7013: '<td> </td>'.
7014: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 7015: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 7016: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 7017: '<input type="hidden" name="groups" value="" />'.
7018: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 7019: '</tr></table></td>'."\n";
7020: if ($showcredits) {
7021: $otheritems .= '<td><br />'."\n".
7022: '<input type="text" size="3" name="credits" value="" />'."\n";
7023: }
1.88 raeburn 7024: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 7025: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 7026: <a href=
7027: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 7028: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 7029: <a href=
7030: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
7031: ENDTIMEENTRY
1.136 raeburn 7032: $otheritems .= &Apache::loncommon::end_data_table_row().
7033: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 7034: return $cb_jscript.$header.$hiddenitems.$otheritems;
7035: }
7036:
1.237 raeburn 7037: sub update_selfenroll_config {
1.241 raeburn 7038: my ($r,$context,$permission) = @_;
1.237 raeburn 7039: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 7040: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 7041: my (%changes,%warning);
7042: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7043: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 7044: my $curr_types;
1.237 raeburn 7045: if (ref($row) eq 'ARRAY') {
7046: foreach my $item (@{$row}) {
7047: if ($item eq 'enroll_dates') {
7048: my (%currenrolldate,%newenrolldate);
7049: foreach my $type ('start','end') {
7050: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
7051: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
7052: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
7053: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
7054: }
7055: }
7056: } elsif ($item eq 'access_dates') {
7057: my (%currdate,%newdate);
7058: foreach my $type ('start','end') {
7059: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
7060: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
7061: if ($newdate{$type} ne $currdate{$type}) {
7062: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
7063: }
7064: }
1.241 raeburn 7065: } elsif ($item eq 'types') {
7066: $curr_types =
7067: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
7068: if ($env{'form.selfenroll_all'}) {
7069: if ($curr_types ne '*') {
7070: $changes{'internal.selfenroll_types'} = '*';
7071: } else {
7072: next;
7073: }
7074: } else {
1.249 raeburn 7075: my %currdoms;
1.241 raeburn 7076: my @entries = split(/;/,$curr_types);
7077: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 7078: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 7079: my $newnum = 0;
1.249 raeburn 7080: my @latesttypes;
7081: foreach my $num (@activations) {
7082: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
7083: if (@types > 0) {
1.241 raeburn 7084: @types = sort(@types);
7085: my $typestr = join(',',@types);
1.249 raeburn 7086: my $typedom = $env{'form.selfenroll_dom_'.$num};
7087: $latesttypes[$newnum] = $typedom.':'.$typestr;
7088: $currdoms{$typedom} = 1;
1.241 raeburn 7089: $newnum ++;
7090: }
7091: }
1.338 raeburn 7092: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
7093: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 7094: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
7095: if (@types > 0) {
7096: @types = sort(@types);
7097: my $typestr = join(',',@types);
7098: my $typedom = $env{'form.selfenroll_dom_'.$j};
7099: $latesttypes[$newnum] = $typedom.':'.$typestr;
7100: $currdoms{$typedom} = 1;
7101: $newnum ++;
7102: }
7103: }
7104: }
7105: if ($env{'form.selfenroll_newdom'} ne '') {
7106: my $typedom = $env{'form.selfenroll_newdom'};
7107: if ((!defined($currdoms{$typedom})) &&
7108: (&Apache::lonnet::domain($typedom) ne '')) {
7109: my $typestr;
7110: my ($othertitle,$usertypes,$types) =
7111: &Apache::loncommon::sorted_inst_types($typedom);
7112: my $othervalue = 'any';
7113: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7114: if (@{$types} > 0) {
1.257 raeburn 7115: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 7116: $othervalue = 'other';
1.258 raeburn 7117: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 7118: }
7119: $typestr = $othervalue;
7120: } else {
7121: $typestr = $othervalue;
7122: }
7123: $latesttypes[$newnum] = $typedom.':'.$typestr;
7124: $newnum ++ ;
7125: }
7126: }
1.241 raeburn 7127: my $selfenroll_types = join(';',@latesttypes);
7128: if ($selfenroll_types ne $curr_types) {
7129: $changes{'internal.selfenroll_types'} = $selfenroll_types;
7130: }
7131: }
1.276 raeburn 7132: } elsif ($item eq 'limit') {
7133: my $newlimit = $env{'form.selfenroll_limit'};
7134: my $newcap = $env{'form.selfenroll_cap'};
7135: $newcap =~s/\s+//g;
7136: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
7137: $currlimit = 'none' if ($currlimit eq '');
7138: my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
7139: if ($newlimit ne $currlimit) {
7140: if ($newlimit ne 'none') {
7141: if ($newcap =~ /^\d+$/) {
7142: if ($newcap ne $currcap) {
7143: $changes{'internal.selfenroll_cap'} = $newcap;
7144: }
7145: $changes{'internal.selfenroll_limit'} = $newlimit;
7146: } else {
7147: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.&mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
7148: }
7149: } elsif ($currcap ne '') {
7150: $changes{'internal.selfenroll_cap'} = '';
7151: $changes{'internal.selfenroll_limit'} = $newlimit;
7152: }
7153: } elsif ($currlimit ne 'none') {
7154: if ($newcap =~ /^\d+$/) {
7155: if ($newcap ne $currcap) {
7156: $changes{'internal.selfenroll_cap'} = $newcap;
7157: }
7158: } else {
7159: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.&mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
7160: }
7161: }
7162: } elsif ($item eq 'approval') {
7163: my (@currnotified,@newnotified);
7164: my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
7165: my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
7166: if ($currnotifylist ne '') {
7167: @currnotified = split(/,/,$currnotifylist);
7168: @currnotified = sort(@currnotified);
7169: }
7170: my $newapproval = $env{'form.selfenroll_approval'};
7171: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
7172: @newnotified = sort(@newnotified);
7173: if ($newapproval ne $currapproval) {
7174: $changes{'internal.selfenroll_approval'} = $newapproval;
7175: if (!$newapproval) {
7176: if ($currnotifylist ne '') {
7177: $changes{'internal.selfenroll_notifylist'} = '';
7178: }
7179: } else {
7180: my @differences =
1.295 raeburn 7181: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 7182: if (@differences > 0) {
7183: if (@newnotified > 0) {
7184: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7185: } else {
7186: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7187: }
7188: }
7189: }
7190: } else {
1.295 raeburn 7191: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 7192: if (@differences > 0) {
7193: if (@newnotified > 0) {
7194: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
7195: } else {
7196: $changes{'internal.selfenroll_notifylist'} = '';
7197: }
7198: }
7199: }
1.237 raeburn 7200: } else {
7201: my $curr_val =
7202: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
7203: my $newval = $env{'form.selfenroll_'.$item};
7204: if ($item eq 'section') {
7205: $newval = $env{'form.sections'};
1.241 raeburn 7206: if (defined($curr_groups{$newval})) {
1.237 raeburn 7207: $newval = $curr_val;
7208: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.&mt('Group names and section names must be distinct');
7209: } elsif ($newval eq 'all') {
7210: $newval = $curr_val;
1.274 bisitz 7211: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 7212: }
7213: if ($newval eq '') {
7214: $newval = 'none';
7215: }
7216: }
7217: if ($newval ne $curr_val) {
7218: $changes{'internal.selfenroll_'.$item} = $newval;
7219: }
1.241 raeburn 7220: }
1.237 raeburn 7221: }
7222: if (keys(%warning) > 0) {
7223: foreach my $item (@{$row}) {
7224: if (exists($warning{$item})) {
7225: $r->print($warning{$item}.'<br />');
7226: }
7227: }
7228: }
7229: if (keys(%changes) > 0) {
7230: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
7231: if ($putresult eq 'ok') {
7232: if ((exists($changes{'internal.selfenroll_types'})) ||
7233: (exists($changes{'internal.selfenroll_start_date'})) ||
7234: (exists($changes{'internal.selfenroll_end_date'}))) {
7235: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
7236: $cnum,undef,undef,'Course');
7237: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
7238: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
7239: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
7240: if (exists($changes{'internal.'.$item})) {
7241: $crsinfo{$env{'request.course.id'}}{$item} =
7242: $changes{'internal.'.$item};
7243: }
7244: }
7245: my $crsputresult =
7246: &Apache::lonnet::courseidput($cdom,\%crsinfo,
7247: $chome,'notime');
7248: }
7249: }
7250: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
7251: foreach my $item (@{$row}) {
7252: my $title = $item;
7253: if (ref($lt) eq 'HASH') {
7254: $title = $lt->{$item};
7255: }
7256: if ($item eq 'enroll_dates') {
7257: foreach my $type ('start','end') {
7258: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
7259: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 7260: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 7261: $title,$type,$newdate).'</li>');
7262: }
7263: }
7264: } elsif ($item eq 'access_dates') {
7265: foreach my $type ('start','end') {
7266: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
7267: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 7268: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 7269: $title,$type,$newdate).'</li>');
7270: }
7271: }
1.276 raeburn 7272: } elsif ($item eq 'limit') {
7273: if ((exists($changes{'internal.selfenroll_limit'})) ||
7274: (exists($changes{'internal.selfenroll_cap'}))) {
7275: my ($newval,$newcap);
7276: if ($changes{'internal.selfenroll_cap'} ne '') {
7277: $newcap = $changes{'internal.selfenroll_cap'}
7278: } else {
7279: $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
7280: }
7281: if ($changes{'internal.selfenroll_limit'} eq 'none') {
7282: $newval = &mt('No limit');
7283: } elsif ($changes{'internal.selfenroll_limit'} eq
7284: 'allstudents') {
7285: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
7286: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
7287: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
7288: } else {
7289: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
7290: if ($currlimit eq 'allstudents') {
7291: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
7292: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 7293: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 7294: }
7295: }
7296: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
7297: }
7298: } elsif ($item eq 'approval') {
7299: if ((exists($changes{'internal.selfenroll_approval'})) ||
7300: (exists($changes{'internal.selfenroll_notifylist'}))) {
7301: my ($newval,$newnotify);
7302: if (exists($changes{'internal.selfenroll_notifylist'})) {
7303: $newnotify = $changes{'internal.selfenroll_notifylist'};
7304: } else {
7305: $newnotify = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
7306: }
7307: if ($changes{'internal.selfenroll_approval'}) {
7308: $newval = &mt('Yes');
7309: } elsif ($changes{'internal.selfenroll_approval'} eq '0') {
7310: $newval = &mt('No');
7311: } else {
7312: my $currapproval =
7313: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
7314: if ($currapproval) {
7315: $newval = &mt('Yes');
7316: } else {
7317: $newval = &mt('No');
7318: }
7319: }
7320: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
7321: if ($newnotify) {
1.277 raeburn 7322: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 7323: } else {
1.277 raeburn 7324: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 7325: }
7326: $r->print('</li>'."\n");
7327: }
1.237 raeburn 7328: } else {
7329: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 7330: my $newval = $changes{'internal.selfenroll_'.$item};
7331: if ($item eq 'types') {
7332: if ($newval eq '') {
7333: $newval = &mt('None');
7334: } elsif ($newval eq '*') {
7335: $newval = &mt('Any user in any domain');
7336: }
1.245 raeburn 7337: } elsif ($item eq 'registered') {
7338: if ($newval eq '1') {
7339: $newval = &mt('Yes');
7340: } elsif ($newval eq '0') {
7341: $newval = &mt('No');
7342: }
1.241 raeburn 7343: }
1.244 bisitz 7344: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 7345: }
7346: }
7347: }
7348: $r->print('</ul>');
7349: my %newenvhash;
7350: foreach my $key (keys(%changes)) {
7351: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
7352: }
1.238 raeburn 7353: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 7354: } else {
7355: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
7356: }
7357: } else {
1.249 raeburn 7358: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 7359: }
7360: } else {
1.249 raeburn 7361: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 7362: }
1.256 raeburn 7363: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
7364: if (ref($visactions) eq 'HASH') {
7365: if (!$visible) {
1.366 bisitz 7366: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.256 raeburn 7367: '<br />');
7368: if (ref($vismsgs) eq 'ARRAY') {
7369: $r->print('<br />'.$visactions->{'take'}.'<ul>');
7370: foreach my $item (@{$vismsgs}) {
7371: $r->print('<li>'.$visactions->{$item}.'</li>');
7372: }
7373: $r->print('</ul>');
7374: }
7375: $r->print($cansetvis);
7376: }
7377: }
1.237 raeburn 7378: return;
7379: }
7380:
7381: sub get_selfenroll_titles {
1.276 raeburn 7382: my @row = ('types','registered','enroll_dates','access_dates','section',
7383: 'approval','limit');
1.237 raeburn 7384: my %lt = &Apache::lonlocal::texthash (
7385: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 7386: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 7387: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 7388: access_dates => 'Course access dates assigned to self-enrolling users',
7389: section => 'Section assigned to self-enrolling users',
1.276 raeburn 7390: approval => 'Self-enrollment requests need approval?',
7391: limit => 'Enrollment limit',
1.237 raeburn 7392: );
7393: return (\@row,\%lt);
7394: }
7395:
1.27 matthew 7396: #---------------------------------------------- end functions for &phase_two
1.29 matthew 7397:
7398: #--------------------------------- functions for &phase_two and &phase_three
7399:
7400: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 7401:
1.1 www 7402: 1;
7403: __END__
1.2 www 7404:
7405:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>