Annotation of loncom/interface/loncreateuser.pm, revision 1.374
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.374 ! raeburn 4: # $Id: loncreateuser.pm,v 1.373 2013/02/06 16:10:27 bisitz Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
1.324 raeburn 54: Custom roles can be defined by a Domain Coordinator, Course Coordinator
55: or Community Coordinator via the Manage User functionality.
56: The custom role editor screen will show all privileges which can be
57: assigned to users. For a complete list of privileges, please see
58: C</home/httpd/lonTabs/rolesplain.tab>.
1.66 bowersj2 59:
1.324 raeburn 60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
1.66 bowersj2 62:
63: =cut
1.1 www 64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
1.54 bowersj2 68: use Apache::loncommon;
1.68 www 69: use Apache::lonlocal;
1.117 raeburn 70: use Apache::longroup;
1.190 raeburn 71: use Apache::lonuserutils;
1.307 raeburn 72: use Apache::loncoursequeueadmin;
1.139 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1 www 74:
1.20 harris41 75: my $loginscript; # piece of javascript used in two separate instances
76: my $authformnop;
77: my $authformkrb;
78: my $authformint;
79: my $authformfsys;
80: my $authformloc;
81:
1.94 matthew 82: sub initialize_authen_forms {
1.227 raeburn 83: my ($dom,$formname,$curr_authtype,$mode) = @_;
84: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
85: my %param = ( formname => $formname,
1.187 raeburn 86: kerb_def_dom => $krbdefdom,
1.227 raeburn 87: kerb_def_auth => $krbdef,
1.187 raeburn 88: domain => $dom,
89: );
1.188 raeburn 90: my %abv_auth = &auth_abbrev();
1.227 raeburn 91: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 92: my $long_auth = $1;
1.227 raeburn 93: my $curr_autharg = $2;
1.188 raeburn 94: my %abv_auth = &auth_abbrev();
95: $param{'curr_authtype'} = $abv_auth{$long_auth};
96: if ($long_auth =~ /^krb(4|5)$/) {
97: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 98: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 99: }
1.205 raeburn 100: if ($mode eq 'modifyuser') {
101: $param{'mode'} = $mode;
102: }
1.187 raeburn 103: }
1.227 raeburn 104: $loginscript = &Apache::loncommon::authform_header(%param);
105: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 106: $authformnop = &Apache::loncommon::authform_nochange(%param);
107: $authformint = &Apache::loncommon::authform_internal(%param);
108: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
109: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 110: }
111:
1.188 raeburn 112: sub auth_abbrev {
113: my %abv_auth = (
1.368 raeburn 114: krb5 => 'krb',
115: krb4 => 'krb',
116: internal => 'int',
117: localauth => 'loc',
118: unix => 'fsys',
1.188 raeburn 119: );
120: return %abv_auth;
121: }
1.43 www 122:
1.134 raeburn 123: # ====================================================
124:
125: sub portfolio_quota {
126: my ($ccuname,$ccdomain) = @_;
127: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 128: 'usrt' => "User Tools",
129: 'disk' => "Disk space allocated to user's portfolio files",
130: 'cuqu' => "Current quota",
131: 'cust' => "Custom quota",
132: 'defa' => "Default",
133: 'chqu' => "Change quota",
1.134 raeburn 134: );
1.149 raeburn 135: my ($currquota,$quotatype,$inststatus,$defquota) =
136: &Apache::loncommon::get_user_quota($ccuname,$ccdomain);
137: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
138: my ($longinsttype,$showquota,$custom_on,$custom_off,$defaultinfo);
139: if ($inststatus ne '') {
140: if ($usertypes->{$inststatus} ne '') {
141: $longinsttype = $usertypes->{$inststatus};
142: }
143: }
144: $custom_on = ' ';
145: $custom_off = ' checked="checked" ';
146: my $quota_javascript = <<"END_SCRIPT";
147: <script type="text/javascript">
1.301 bisitz 148: // <![CDATA[
1.149 raeburn 149: function quota_changes(caller) {
150: if (caller == "custom") {
151: if (document.cu.customquota[0].checked) {
152: document.cu.portfolioquota.value = "";
153: }
154: }
155: if (caller == "quota") {
156: document.cu.customquota[1].checked = true;
157: }
158: }
1.301 bisitz 159: // ]]>
1.149 raeburn 160: </script>
161: END_SCRIPT
162: if ($quotatype eq 'custom') {
163: $custom_on = $custom_off;
164: $custom_off = ' ';
165: $showquota = $currquota;
166: if ($longinsttype eq '') {
1.230 bisitz 167: $defaultinfo = &mt('For this user, the default quota would be [_1]'
168: .' Mb.',$defquota);
1.149 raeburn 169: } else {
1.231 raeburn 170: $defaultinfo = &mt("For this user, the default quota would be [_1]".
171: " Mb, as determined by the user's institutional".
172: " affiliation ([_2]).",$defquota,$longinsttype);
1.149 raeburn 173: }
174: } else {
175: if ($longinsttype eq '') {
1.230 bisitz 176: $defaultinfo = &mt('For this user, the default quota is [_1]'
177: .' Mb.',$defquota);
1.149 raeburn 178: } else {
1.231 raeburn 179: $defaultinfo = &mt("For this user, the default quota of [_1]".
180: " Mb, is determined by the user's institutional".
181: " affiliation ([_2]).",$defquota,$longinsttype);
1.149 raeburn 182: }
183: }
1.267 raeburn 184:
185: my $output = $quota_javascript."\n".
186: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
187: &Apache::loncommon::start_data_table();
188:
189: if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1.275 raeburn 190: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 191: }
192: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
193: $output .= '<tr class="LC_info_row">'."\n".
194: ' <td>'.$lt{'disk'}.'</td>'."\n".
195: ' </tr>'."\n".
196: &Apache::loncommon::start_data_table_row()."\n".
197: ' <td>'.$lt{'cuqu'}.': '.
198: $currquota.' Mb. '.
199: $defaultinfo.'</td>'."\n".
200: &Apache::loncommon::end_data_table_row()."\n".
201: &Apache::loncommon::start_data_table_row()."\n".
202: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
203: ': <label>'.
204: '<input type="radio" name="customquota" value="0" '.
205: $custom_off.' onchange="javascript:quota_changes('."'custom'".')"'.
206: ' />'.$lt{'defa'}.' ('.$defquota.' Mb).</label> '.
207: ' <label><input type="radio" name="customquota" value="1" '.
208: $custom_on.' onchange="javascript:quota_changes('."'custom'".')" />'.
209: $lt{'cust'}.':</label> '.
210: '<input type="text" name="portfolioquota" size ="5" value="'.
211: $showquota.'" onfocus="javascript:quota_changes('."'quota'".')" '.
212: '/> Mb</span></td>'."\n".
213: &Apache::loncommon::end_data_table_row()."\n";
214: }
215: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 216: return $output;
217: }
218:
1.275 raeburn 219: sub build_tools_display {
220: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 221: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 222: $colspan,$isadv,%domconfig);
1.275 raeburn 223: my %lt = &Apache::lonlocal::texthash (
224: 'blog' => "Personal User Blog",
225: 'aboutme' => "Personal Information Page",
1.361 raeburn 226: 'webdav' => "WebDAV access to authoring spaces (if SSL and author/co-author)",
1.275 raeburn 227: 'portfolio' => "Personal User Portfolio",
228: 'avai' => "Available",
229: 'cusa' => "availability",
230: 'chse' => "Change setting",
231: 'usde' => "Use default",
232: 'uscu' => "Use custom",
233: 'official' => 'Can request creation of official courses',
1.299 raeburn 234: 'unofficial' => 'Can request creation of unofficial courses',
235: 'community' => 'Can request creation of communities',
1.362 raeburn 236: 'requestauthor' => 'Can request author space',
1.275 raeburn 237: );
1.279 raeburn 238: if ($context eq 'requestcourses') {
1.275 raeburn 239: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 240: 'requestcourses.official','requestcourses.unofficial',
241: 'requestcourses.community');
242: @usertools = ('official','unofficial','community');
1.309 raeburn 243: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 244: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
245: %reqtitles = &courserequest_titles();
246: %reqdisplay = &courserequest_display();
247: $colspan = ' colspan="2"';
1.332 raeburn 248: %domconfig =
249: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
250: $isadv = &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1.362 raeburn 251: } elsif ($context eq 'requestauthor') {
252: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
253: 'requestauthor');
254: @usertools = ('requestauthor');
255: @options =('norequest','approval','automatic');
256: %reqtitles = &requestauthor_titles();
257: %reqdisplay = &requestauthor_display();
258: $colspan = ' colspan="2"';
259: %domconfig =
260: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 261: } else {
262: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 263: 'tools.aboutme','tools.portfolio','tools.blog',
264: 'tools.webdav');
265: @usertools = ('aboutme','blog','webdav','portfolio');
1.275 raeburn 266: }
267: foreach my $item (@usertools) {
1.306 raeburn 268: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
269: $currdisp,$custdisp,$custradio);
1.275 raeburn 270: $cust_off = 'checked="checked" ';
271: $tool_on = 'checked="checked" ';
272: $curr_access =
273: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
274: $context);
1.362 raeburn 275: if ($context eq 'requestauthor') {
276: if ($userenv{$context} ne '') {
277: $cust_on = ' checked="checked" ';
278: $cust_off = '';
279: }
280: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 281: $cust_on = ' checked="checked" ';
282: $cust_off = '';
283: }
284: if ($context eq 'requestcourses') {
285: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 286: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 287: } else {
288: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 289: }
1.362 raeburn 290: } elsif ($context eq 'requestauthor') {
291: if ($userenv{$context} eq '') {
292: $custom_access = &mt('Currently from default setting.');
293: } else {
294: $custom_access = &mt('Currently from custom setting.');
295: }
1.275 raeburn 296: } else {
1.306 raeburn 297: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 298: $custom_access =
1.306 raeburn 299: &mt('Availability determined currently from default setting.');
300: if (!$curr_access) {
301: $tool_off = 'checked="checked" ';
302: $tool_on = '';
303: }
304: } else {
1.314 raeburn 305: $custom_access =
1.306 raeburn 306: &mt('Availability determined currently from custom setting.');
307: if ($userenv{$context.'.'.$item} == 0) {
308: $tool_off = 'checked="checked" ';
309: $tool_on = '';
310: }
1.275 raeburn 311: }
312: }
313: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 314: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 315: ' </tr>'."\n".
1.306 raeburn 316: &Apache::loncommon::start_data_table_row()."\n";
1.362 raeburn 317: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 318: my ($curroption,$currlimit);
1.362 raeburn 319: my $envkey = $context.'.'.$item;
320: if ($context eq 'requestauthor') {
321: $envkey = $context;
322: }
323: if ($userenv{$envkey} ne '') {
324: $curroption = $userenv{$envkey};
1.332 raeburn 325: } else {
326: my (@inststatuses);
1.362 raeburn 327: if ($context eq 'requestcourses') {
328: $curroption =
329: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
330: $isadv,$ccdomain,$item,
331: \@inststatuses,\%domconfig);
332: } else {
333: $curroption =
334: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
335: $isadv,$ccdomain,undef,
336: \@inststatuses,\%domconfig);
337: }
1.332 raeburn 338: }
1.306 raeburn 339: if (!$curroption) {
340: $curroption = 'norequest';
341: }
342: if ($curroption =~ /^autolimit=(\d*)$/) {
343: $currlimit = $1;
1.314 raeburn 344: if ($currlimit eq '') {
345: $currdisp = &mt('Yes, automatic creation');
346: } else {
347: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
348: }
1.306 raeburn 349: } else {
350: $currdisp = $reqdisplay{$curroption};
351: }
352: $custdisp = '<table>';
353: foreach my $option (@options) {
354: my $val = $option;
355: if ($option eq 'norequest') {
356: $val = 0;
357: }
358: if ($option eq 'validate') {
359: my $canvalidate = 0;
360: if (ref($validations{$item}) eq 'HASH') {
361: if ($validations{$item}{'_custom_'}) {
362: $canvalidate = 1;
363: }
364: }
365: next if (!$canvalidate);
366: }
367: my $checked = '';
368: if ($option eq $curroption) {
369: $checked = ' checked="checked"';
370: } elsif ($option eq 'autolimit') {
371: if ($curroption =~ /^autolimit/) {
372: $checked = ' checked="checked"';
373: }
374: }
1.362 raeburn 375: my $name = 'crsreq_'.$item;
376: if ($context eq 'requestauthor') {
377: $name = $item;
378: }
1.306 raeburn 379: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 380: '<input type="radio" name="'.$name.'" '.
381: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 382: $reqtitles{$option}.'</label> ';
383: if ($option eq 'autolimit') {
1.362 raeburn 384: $custdisp .= '<input type="text" name="'.$name.
385: '_limit" size="1" '.
1.314 raeburn 386: 'value="'.$currlimit.'" /></span><br />'.
387: $reqtitles{'unlimited'};
1.362 raeburn 388: } else {
389: $custdisp .= '</span>';
390: }
391: $custdisp .= '</td></tr>';
1.306 raeburn 392: }
393: $custdisp .= '</table>';
394: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
395: } else {
396: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 397: my $name = $context.'_'.$item;
398: if ($context eq 'requestauthor') {
399: $name = $context;
400: }
1.306 raeburn 401: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 402: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 403: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 404: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 405: $tool_off.'/>'.&mt('Off').'</label></span>';
406: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
407: '</span>';
408: }
409: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
410: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.275 raeburn 411: &Apache::loncommon::end_data_table_row()."\n".
412: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 413: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
414: $lt{'chse'}.': <label>'.
1.275 raeburn 415: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 416: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
417: '<label><input type="radio" name="custom'.$item.'" value="1" '.
418: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 419: &Apache::loncommon::end_data_table_row()."\n";
420: }
421: return $output;
422: }
423:
1.300 raeburn 424: sub coursereq_externaluser {
425: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 426: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 427: my %lt = &Apache::lonlocal::texthash (
428: 'official' => 'Can request creation of official courses',
429: 'unofficial' => 'Can request creation of unofficial courses',
430: 'community' => 'Can request creation of communities',
431: );
432:
433: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
434: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
435: 'reqcrsotherdom.community');
436: @usertools = ('official','unofficial','community');
1.309 raeburn 437: @options = ('approval','validate','autolimit');
1.306 raeburn 438: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
439: my $optregex = join('|',@options);
440: my %reqtitles = &courserequest_titles();
1.300 raeburn 441: foreach my $item (@usertools) {
1.306 raeburn 442: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 443: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
444: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 445: foreach my $req (@curr) {
446: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
447: $curroption = $1;
448: $currlimit = $2;
449: last;
1.306 raeburn 450: }
451: }
1.314 raeburn 452: if (!$curroption) {
453: $curroption = 'norequest';
454: $tooloff = ' checked="checked"';
455: }
1.306 raeburn 456: } else {
457: $curroption = 'norequest';
458: $tooloff = ' checked="checked"';
459: }
460: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 461: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
462: '<table><tr><td valign="top">'."\n".
1.306 raeburn 463: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 464: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
465: '</label></td>';
1.306 raeburn 466: foreach my $option (@options) {
467: if ($option eq 'validate') {
468: my $canvalidate = 0;
469: if (ref($validations{$item}) eq 'HASH') {
470: if ($validations{$item}{'_external_'}) {
471: $canvalidate = 1;
472: }
473: }
474: next if (!$canvalidate);
475: }
476: my $checked = '';
477: if ($option eq $curroption) {
478: $checked = ' checked="checked"';
479: }
1.314 raeburn 480: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 481: '<input type="radio" name="reqcrsotherdom_'.$item.
482: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 483: $reqtitles{$option}.'</label>';
1.306 raeburn 484: if ($option eq 'autolimit') {
1.314 raeburn 485: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 486: $item.'_limit" size="1" '.
1.314 raeburn 487: 'value="'.$currlimit.'" /></span>'.
488: '<br />'.$reqtitles{'unlimited'};
489: } else {
490: $output .= '</span>';
1.300 raeburn 491: }
1.314 raeburn 492: $output .= '</td>';
1.300 raeburn 493: }
1.314 raeburn 494: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 495: &Apache::loncommon::end_data_table_row()."\n";
496: }
497: return $output;
498: }
499:
1.362 raeburn 500: sub domainrole_req {
501: my ($ccuname,$ccdomain) = @_;
502: return '<br /><h3>'.
503: &mt('User Can Request Assignment of Domain Roles?').
504: '</h3>'."\n".
505: &Apache::loncommon::start_data_table().
506: &build_tools_display($ccuname,$ccdomain,
507: 'requestauthor').
508: &Apache::loncommon::end_data_table();
509: }
510:
1.306 raeburn 511: sub courserequest_titles {
512: my %titles = &Apache::lonlocal::texthash (
513: official => 'Official',
514: unofficial => 'Unofficial',
515: community => 'Communities',
516: norequest => 'Not allowed',
1.309 raeburn 517: approval => 'Approval by Dom. Coord.',
1.306 raeburn 518: validate => 'With validation',
519: autolimit => 'Numerical limit',
1.314 raeburn 520: unlimited => '(blank for unlimited)',
1.306 raeburn 521: );
522: return %titles;
523: }
524:
525: sub courserequest_display {
526: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 527: approval => 'Yes, need approval',
1.306 raeburn 528: validate => 'Yes, with validation',
529: norequest => 'No',
530: );
531: return %titles;
532: }
533:
1.362 raeburn 534: sub requestauthor_titles {
535: my %titles = &Apache::lonlocal::texthash (
536: norequest => 'Not allowed',
537: approval => 'Approval by Dom. Coord.',
538: automatic => 'Automatic approval',
539: );
540: return %titles;
541:
542: }
543:
544: sub requestauthor_display {
545: my %titles = &Apache::lonlocal::texthash (
546: approval => 'Yes, need approval',
547: automatic => 'Yes, automatic approval',
548: norequest => 'No',
549: );
550: return %titles;
551: }
552:
553: sub curr_requestauthor {
554: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
555: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
556: if ($uname eq '' || $udom eq '') {
557: $uname = $env{'user.name'};
558: $udom = $env{'user.domain'};
559: $isadv = $env{'user.adv'};
560: }
561: my (%userenv,%settings,$val);
562: my @options = ('automatic','approval');
563: %userenv =
564: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
565: if ($userenv{'requestauthor'}) {
566: $val = $userenv{'requestauthor'};
567: @{$inststatuses} = ('_custom_');
568: } else {
569: my %alltasks;
570: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
571: %settings = %{$domconfig->{'requestauthor'}};
572: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
573: $val = $settings{'_LC_adv'};
574: @{$inststatuses} = ('_LC_adv_');
575: } else {
576: if ($userenv{'inststatus'} ne '') {
577: @{$inststatuses} = split(',',$userenv{'inststatus'});
578: } else {
579: @{$inststatuses} = ('default');
580: }
581: foreach my $status (@{$inststatuses}) {
582: if (exists($settings{$status})) {
583: my $value = $settings{$status};
584: next unless ($value);
585: unless (exists($alltasks{$value})) {
586: if (ref($alltasks{$value}) eq 'ARRAY') {
587: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
588: push(@{$alltasks{$value}},$status);
589: }
590: } else {
591: @{$alltasks{$value}} = ($status);
592: }
593: }
594: }
595: }
596: foreach my $option (@options) {
597: if ($alltasks{$option}) {
598: $val = $option;
599: last;
600: }
601: }
602: }
603: }
604: }
605: return $val;
606: }
607:
1.2 www 608: # =================================================================== Phase one
1.1 www 609:
1.42 matthew 610: sub print_username_entry_form {
1.351 raeburn 611: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum) = @_;
1.101 albertel 612: my $defdom=$env{'request.role.domain'};
1.160 raeburn 613: my $formtoset = 'crtuser';
614: if (exists($env{'form.startrolename'})) {
615: $formtoset = 'docustom';
616: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 617: } elsif ($env{'form.origform'} eq 'crtusername') {
618: $formtoset = $env{'form.origform'};
1.160 raeburn 619: }
620:
621: my ($jsback,$elements) = &crumb_utilities();
622:
623: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 624: '<script type="text/javascript">'."\n".
1.301 bisitz 625: '// <![CDATA['."\n".
626: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
627: '// ]]>'."\n".
1.162 raeburn 628: '</script>'."\n";
1.160 raeburn 629:
1.324 raeburn 630: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
631: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
632: && (&Apache::lonnet::allowed('mcr','/'))) {
633: $jscript .= &customrole_javascript();
634: }
1.224 raeburn 635: my $helpitem = 'Course_Change_Privileges';
636: if ($env{'form.action'} eq 'custom') {
637: $helpitem = 'Course_Editing_Custom_Roles';
638: } elsif ($env{'form.action'} eq 'singlestudent') {
639: $helpitem = 'Course_Add_Student';
640: }
1.351 raeburn 641: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
642: if ($env{'form.action'} eq 'custom') {
643: push(@{$brcrum},
644: {href=>"javascript:backPage(document.crtuser)",
645: text=>"Pick custom role",
646: help => $helpitem,}
647: );
648: } else {
649: push (@{$brcrum},
650: {href => "javascript:backPage(document.crtuser)",
651: text => $breadcrumb_text{'search'},
652: help => $helpitem,
653: faq => 282,
654: bug => 'Instructor Interface',}
655: );
656: }
657: my %loaditems = (
658: 'onload' => "javascript:setFormElements(document.$formtoset)",
659: );
660: my $args = {bread_crumbs => $brcrum,
661: bread_crumbs_component => 'User Management',
662: add_entries => \%loaditems,};
663: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
664:
1.71 sakharuk 665: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 666: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 667: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 668: 'srad' => 'Search for a user and modify/add user information or roles',
1.71 sakharuk 669: 'usr' => "Username",
670: 'dom' => "Domain",
1.324 raeburn 671: 'ecrp' => "Define or Edit Custom Role",
672: 'nr' => "role name",
1.282 schafran 673: 'cre' => "Next",
1.71 sakharuk 674: );
1.351 raeburn 675:
1.214 raeburn 676: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 677: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 678: my $newroletext = &mt('Define new custom role:');
679: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
680: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
681: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
682: '<h3>'.$lt{'ecrp'}.'</h3>'.
683: &Apache::loncommon::start_data_table().
684: &Apache::loncommon::start_data_table_row().
685: '<td>');
686: if (keys(%existingroles) > 0) {
687: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
688: } else {
689: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
690: }
691: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
692: &Apache::loncommon::end_data_table_row());
693: if (keys(%existingroles) > 0) {
694: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
695: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
696: &mt('View/Modify existing role:').'</b></label></td>'.
697: '<td align="center"><br />'.
698: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 699: '<option value="" selected="selected">'.
1.324 raeburn 700: &mt('Select'));
701: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 702: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 703: }
704: $r->print('</select>'.
705: '</td>'.
706: &Apache::loncommon::end_data_table_row());
707: }
708: $r->print(&Apache::loncommon::end_data_table().'<p>'.
709: '<input name="customeditor" type="submit" value="'.
710: $lt{'cre'}.'" /></p>'.
711: '</form>');
1.190 raeburn 712: }
1.213 raeburn 713: } else {
1.229 raeburn 714: my $actiontext = $lt{'srad'};
1.213 raeburn 715: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 716: if ($crstype eq 'Community') {
717: $actiontext = $lt{'srme'};
718: } else {
719: $actiontext = $lt{'srst'};
720: }
1.213 raeburn 721: }
1.324 raeburn 722: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 723: if ($env{'form.origform'} ne 'crtusername') {
724: $r->print("\n".$response);
725: }
1.318 raeburn 726: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype));
1.107 www 727: }
1.110 albertel 728: }
729:
1.324 raeburn 730: sub customrole_javascript {
731: my $js = <<"END";
732: <script type="text/javascript">
733: // <![CDATA[
734:
735: function setCustomFields() {
736: if (document.docustom.customroleaction.length > 0) {
737: for (var i=0; i<document.docustom.customroleaction.length; i++) {
738: if (document.docustom.customroleaction[i].checked) {
739: if (document.docustom.customroleaction[i].value == 'new') {
740: document.docustom.rolename.selectedIndex = 0;
741: } else {
742: document.docustom.newrolename.value = '';
743: }
744: }
745: }
746: }
747: return;
748: }
749:
750: function setCustomAction(caller) {
751: if (document.docustom.customroleaction.length > 0) {
752: for (var i=0; i<document.docustom.customroleaction.length; i++) {
753: if (document.docustom.customroleaction[i].value == caller) {
754: document.docustom.customroleaction[i].checked = true;
755: }
756: }
757: }
758: setCustomFields();
759: return;
760: }
761:
762: // ]]>
763: </script>
764: END
765: return $js;
766: }
767:
1.160 raeburn 768: sub entry_form {
1.318 raeburn 769: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype) = @_;
1.229 raeburn 770: my ($usertype,$inexact);
1.214 raeburn 771: if (ref($srch) eq 'HASH') {
772: if (($srch->{'srchin'} eq 'dom') &&
773: ($srch->{'srchby'} eq 'uname') &&
774: ($srch->{'srchtype'} eq 'exact') &&
775: ($srch->{'srchdomain'} ne '') &&
776: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 777: my (%curr_rules,%got_rules);
1.214 raeburn 778: my ($rules,$ruleorder) =
779: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 780: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 781: } else {
782: $inexact = 1;
1.214 raeburn 783: }
1.207 raeburn 784: }
1.214 raeburn 785: my $cancreate =
786: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.160 raeburn 787: my $userpicker =
1.179 raeburn 788: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.214 raeburn 789: 'document.crtuser',$cancreate,$usertype);
1.160 raeburn 790: my $srchbutton = &mt('Search');
1.229 raeburn 791: if ($env{'form.action'} eq 'singlestudent') {
792: $srchbutton = &mt('Search and Enroll');
793: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
794: $srchbutton = &mt('Search or Add New User');
795: }
1.207 raeburn 796: my $output = <<"ENDBLOCK";
1.160 raeburn 797: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 798: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 799: <input type="hidden" name="phase" value="get_user_info" />
800: $userpicker
1.179 raeburn 801: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 802: </form>
1.207 raeburn 803: ENDBLOCK
1.229 raeburn 804: if ($env{'form.phase'} eq '') {
1.207 raeburn 805: my $defdom=$env{'request.role.domain'};
806: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
807: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 808: 'enro' => 'Enroll one student',
1.318 raeburn 809: 'enrm' => 'Enroll one member',
1.229 raeburn 810: 'admo' => 'Add/modify a single user',
811: 'crea' => 'create new user if required',
812: 'uskn' => "username is known",
1.207 raeburn 813: 'crnu' => 'Create a new user',
814: 'usr' => 'Username',
815: 'dom' => 'in domain',
1.229 raeburn 816: 'enrl' => 'Enroll',
817: 'cram' => 'Create/Modify user',
1.207 raeburn 818: );
1.229 raeburn 819: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
820: my ($title,$buttontext,$showresponse);
1.318 raeburn 821: if ($env{'form.action'} eq 'singlestudent') {
822: if ($crstype eq 'Community') {
823: $title = $lt{'enrm'};
824: } else {
825: $title = $lt{'enro'};
826: }
1.229 raeburn 827: $buttontext = $lt{'enrl'};
828: } else {
829: $title = $lt{'admo'};
830: $buttontext = $lt{'cram'};
831: }
832: if ($cancreate) {
833: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
834: } else {
835: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
836: }
837: if ($env{'form.origform'} eq 'crtusername') {
838: $showresponse = $responsemsg;
839: }
1.207 raeburn 840: $output .= <<"ENDDOCUMENT";
1.229 raeburn 841: <br />
1.207 raeburn 842: <form action="/adm/createuser" method="post" name="crtusername">
843: <input type="hidden" name="action" value="$env{'form.action'}" />
844: <input type="hidden" name="phase" value="createnewuser" />
845: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 846: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 847: <input type="hidden" name="srchin" value="dom" />
848: <input type="hidden" name="forcenewuser" value="1" />
849: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 850: <h3>$title</h3>
851: $showresponse
1.207 raeburn 852: <table>
853: <tr>
854: <td>$lt{'usr'}:</td>
855: <td><input type="text" size="15" name="srchterm" /></td>
856: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 857: <td> $sellink </td>
858: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 859: </tr>
860: </table>
861: </form>
1.160 raeburn 862: ENDDOCUMENT
1.207 raeburn 863: }
1.160 raeburn 864: return $output;
865: }
1.110 albertel 866:
867: sub user_modification_js {
1.113 raeburn 868: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
869:
1.110 albertel 870: return <<END;
871: <script type="text/javascript" language="Javascript">
1.301 bisitz 872: // <![CDATA[
1.314 raeburn 873:
1.110 albertel 874: $pjump_def
875: $dc_setcourse_code
876:
877: function dateset() {
878: eval("document.cu."+document.cu.pres_marker.value+
879: ".value=document.cu.pres_value.value");
1.359 www 880: modalWindow.close();
1.110 albertel 881: }
882:
1.113 raeburn 883: $nondc_setsection_code
1.301 bisitz 884: // ]]>
1.110 albertel 885: </script>
886: END
1.2 www 887: }
888:
889: # =================================================================== Phase two
1.160 raeburn 890: sub print_user_selection_page {
1.351 raeburn 891: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 892: my @fields = ('username','domain','lastname','firstname','permanentemail');
893: my $sortby = $env{'form.sortby'};
894:
895: if (!grep(/^\Q$sortby\E$/,@fields)) {
896: $sortby = 'lastname';
897: }
898:
899: my ($jsback,$elements) = &crumb_utilities();
900:
901: my $jscript = (<<ENDSCRIPT);
902: <script type="text/javascript">
1.301 bisitz 903: // <![CDATA[
1.160 raeburn 904: function pickuser(uname,udom) {
905: document.usersrchform.seluname.value=uname;
906: document.usersrchform.seludom.value=udom;
907: document.usersrchform.phase.value="userpicked";
908: document.usersrchform.submit();
909: }
910:
911: $jsback
1.301 bisitz 912: // ]]>
1.160 raeburn 913: </script>
914: ENDSCRIPT
915:
916: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 917: 'usrch' => "User Search to add/modify roles",
918: 'stusrch' => "User Search to enroll student",
1.318 raeburn 919: 'memsrch' => "User Search to enroll member",
1.179 raeburn 920: 'usel' => "Select a user to add/modify roles",
1.318 raeburn 921: 'stusel' => "Select a user to enroll as a student",
922: 'memsel' => "Select a user to enroll as a member",
1.160 raeburn 923: 'username' => "username",
924: 'domain' => "domain",
925: 'lastname' => "last name",
926: 'firstname' => "first name",
927: 'permanentemail' => "permanent e-mail",
928: );
1.302 raeburn 929: if ($context eq 'requestcrs') {
930: $r->print('<div>');
931: } else {
1.318 raeburn 932: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 933: my $helpitem;
934: if ($env{'form.action'} eq 'singleuser') {
935: $helpitem = 'Course_Change_Privileges';
936: } elsif ($env{'form.action'} eq 'singlestudent') {
937: $helpitem = 'Course_Add_Student';
938: }
939: push (@{$brcrum},
940: {href => "javascript:backPage(document.usersrchform,'','')",
941: text => $breadcrumb_text{'search'},
942: faq => 282,
943: bug => 'Instructor Interface',},
944: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
945: text => $breadcrumb_text{'userpicked'},
946: faq => 282,
947: bug => 'Instructor Interface',
948: help => $helpitem}
949: );
950: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 951: if ($env{'form.action'} eq 'singleuser') {
952: $r->print("<b>$lt{'usrch'}</b><br />");
1.318 raeburn 953: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.302 raeburn 954: $r->print('<h3>'.$lt{'usel'}.'</h3>');
955: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 956: $r->print($jscript."<b>");
957: if ($crstype eq 'Community') {
958: $r->print($lt{'memsrch'});
959: } else {
960: $r->print($lt{'stusrch'});
961: }
962: $r->print("</b><br />");
963: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
964: $r->print('</form><h3>');
965: if ($crstype eq 'Community') {
966: $r->print($lt{'memsel'});
967: } else {
968: $r->print($lt{'stusel'});
969: }
970: $r->print('</h3>');
1.302 raeburn 971: }
1.179 raeburn 972: }
1.160 raeburn 973: $r->print('<form name="usersrchform" method="post">'.
974: &Apache::loncommon::start_data_table()."\n".
975: &Apache::loncommon::start_data_table_header_row()."\n".
976: ' <th> </th>'."\n");
977: foreach my $field (@fields) {
978: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
979: "'".$field."'".';document.usersrchform.submit();">'.
980: $lt{$field}.'</a></th>'."\n");
981: }
982: $r->print(&Apache::loncommon::end_data_table_header_row());
983:
984: my @sorted_users = sort {
1.167 albertel 985: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 986: ||
1.167 albertel 987: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 988: ||
989: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 990: ||
991: lc($a) cmp lc($b)
1.160 raeburn 992: } (keys(%$srch_results));
993:
994: foreach my $user (@sorted_users) {
995: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 996: my $onclick;
997: if ($context eq 'requestcrs') {
1.314 raeburn 998: $onclick =
1.302 raeburn 999: 'onclick="javascript:gochoose('."'$uname','$udom',".
1000: "'$srch_results->{$user}->{firstname}',".
1001: "'$srch_results->{$user}->{lastname}',".
1002: "'$srch_results->{$user}->{permanentemail}'".');"';
1003: } else {
1.314 raeburn 1004: $onclick =
1.302 raeburn 1005: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1006: }
1.160 raeburn 1007: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1008: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1009: $onclick.' /></td>'.
1.160 raeburn 1010: '<td><tt>'.$uname.'</tt></td>'.
1011: '<td><tt>'.$udom.'</tt></td>');
1012: foreach my $field ('lastname','firstname','permanentemail') {
1013: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1014: }
1015: $r->print(&Apache::loncommon::end_data_table_row());
1016: }
1017: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1018: if (ref($srcharray) eq 'ARRAY') {
1019: foreach my $item (@{$srcharray}) {
1020: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1021: }
1022: }
1.160 raeburn 1023: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1024: ' <input type="hidden" name="seluname" value="" />'."\n".
1025: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1026: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1027: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1028: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1029: if ($context eq 'requestcrs') {
1030: $r->print($opener_elements.'</form></div>');
1031: } else {
1.351 raeburn 1032: $r->print($response.'</form>');
1.302 raeburn 1033: }
1.160 raeburn 1034: }
1035:
1036: sub print_user_query_page {
1.351 raeburn 1037: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1038: # FIXME - this is for a network-wide name search (similar to catalog search)
1039: # To use frames with similar behavior to catalog/portfolio search.
1040: # To be implemented.
1041: return;
1042: }
1043:
1.42 matthew 1044: sub print_user_modification_page {
1.351 raeburn 1045: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,$brcrum) = @_;
1.185 raeburn 1046: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1047: my $usermsg = &mt('No username and/or domain provided.');
1048: $env{'form.phase'} = '';
1.351 raeburn 1049: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum);
1.58 www 1050: return;
1051: }
1.213 raeburn 1052: my ($form,$formname);
1053: if ($env{'form.action'} eq 'singlestudent') {
1054: $form = 'document.enrollstudent';
1055: $formname = 'enrollstudent';
1056: } else {
1057: $form = 'document.cu';
1058: $formname = 'cu';
1059: }
1.188 raeburn 1060: my %abv_auth = &auth_abbrev();
1.227 raeburn 1061: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1062: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1063: if ($uhome eq 'no_host') {
1.215 raeburn 1064: my $usertype;
1065: my ($rules,$ruleorder) =
1066: &Apache::lonnet::inst_userrules($ccdomain,'username');
1067: $usertype =
1.353 raeburn 1068: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1069: \%curr_rules,\%got_rules);
1.215 raeburn 1070: my $cancreate =
1071: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1072: $usertype);
1073: if (!$cancreate) {
1.292 bisitz 1074: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1075: my %usertypetext = (
1076: official => 'institutional',
1077: unofficial => 'non-institutional',
1078: );
1079: my $response;
1080: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1081: $response = '<span class="LC_warning">'.
1082: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1083: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1084: '</span><br />';
1085: }
1.292 bisitz 1086: $response .= '<p class="LC_warning">'
1087: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1088: .' '
1089: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
1090: ,'<a href="'.$helplink.'">','</a>')
1091: .'</p><br />';
1.215 raeburn 1092: $env{'form.phase'} = '';
1.351 raeburn 1093: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum);
1.215 raeburn 1094: return;
1095: }
1.188 raeburn 1096: $newuser = 1;
1.193 raeburn 1097: my $checkhash;
1098: my $checks = { 'username' => 1 };
1.196 raeburn 1099: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1100: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1101: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1102: if (ref($alerts{'username'}) eq 'HASH') {
1103: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1104: my $domdesc =
1.193 raeburn 1105: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1106: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1107: my $userchkmsg;
1108: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1109: $userchkmsg =
1110: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1111: $domdesc,1).
1112: &Apache::loncommon::user_rule_formats($ccdomain,
1113: $domdesc,$curr_rules{$ccdomain}{'username'},
1114: 'username');
1.196 raeburn 1115: }
1.215 raeburn 1116: $env{'form.phase'} = '';
1.351 raeburn 1117: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum);
1.196 raeburn 1118: return;
1.215 raeburn 1119: }
1.193 raeburn 1120: }
1.185 raeburn 1121: }
1.187 raeburn 1122: } else {
1.188 raeburn 1123: $newuser = 0;
1.185 raeburn 1124: }
1.160 raeburn 1125: if ($response) {
1.215 raeburn 1126: $response = '<br />'.$response;
1.160 raeburn 1127: }
1.149 raeburn 1128:
1.52 matthew 1129: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1130: my $dc_setcourse_code = '';
1.119 raeburn 1131: my $nondc_setsection_code = '';
1.112 albertel 1132: my %loaditem;
1.114 albertel 1133:
1.216 raeburn 1134: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1135:
1.216 raeburn 1136: my $js = &validation_javascript($context,$ccdomain,$pjump_def,
1137: $groupslist,$newuser,$formname,\%loaditem);
1.318 raeburn 1138: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.224 raeburn 1139: my $helpitem = 'Course_Change_Privileges';
1140: if ($env{'form.action'} eq 'singlestudent') {
1141: $helpitem = 'Course_Add_Student';
1142: }
1.351 raeburn 1143: push (@{$brcrum},
1144: {href => "javascript:backPage($form)",
1145: text => $breadcrumb_text{'search'},
1146: faq => 282,
1147: bug => 'Instructor Interface',});
1148: if ($env{'form.phase'} eq 'userpicked') {
1149: push(@{$brcrum},
1150: {href => "javascript:backPage($form,'get_user_info','select')",
1151: text => $breadcrumb_text{'userpicked'},
1152: faq => 282,
1153: bug => 'Instructor Interface',});
1154: }
1155: push(@{$brcrum},
1156: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1157: text => $breadcrumb_text{'modify'},
1158: faq => 282,
1159: bug => 'Instructor Interface',
1160: help => $helpitem});
1161: my $args = {'add_entries' => \%loaditem,
1162: 'bread_crumbs' => $brcrum,
1163: 'bread_crumbs_component' => 'User Management'};
1164: if ($env{'form.popup'}) {
1165: $args->{'no_nav_bar'} = 1;
1166: }
1167: my $start_page =
1168: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1169:
1.25 matthew 1170: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1171: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1172: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1173: <input type="hidden" name="ccuname" value="$ccuname" />
1174: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1175: <input type="hidden" name="pres_value" value="" />
1176: <input type="hidden" name="pres_type" value="" />
1177: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1178: ENDFORMINFO
1.329 raeburn 1179: my (%inccourses,$roledom);
1180: if ($context eq 'course') {
1181: $inccourses{$env{'request.course.id'}}=1;
1182: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1183: } elsif ($context eq 'author') {
1184: $roledom = $env{'request.role.domain'};
1185: } elsif ($context eq 'domain') {
1186: foreach my $key (keys(%env)) {
1187: $roledom = $env{'request.role.domain'};
1188: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1189: $inccourses{$1.'_'.$2}=1;
1190: }
1191: }
1192: } else {
1193: foreach my $key (keys(%env)) {
1194: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1195: $inccourses{$1.'_'.$2}=1;
1196: }
1.2 www 1197: }
1.24 matthew 1198: }
1.216 raeburn 1199: if ($newuser) {
1.362 raeburn 1200: my ($portfolioform,$domroleform);
1.267 raeburn 1201: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1202: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1203: # Current user has quota or user tools modification privileges
1.188 raeburn 1204: $portfolioform = '<br />'.&portfolio_quota($ccuname,$ccdomain);
1.134 raeburn 1205: }
1.362 raeburn 1206: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
1207: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1208: }
1.227 raeburn 1209: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1210: my %lt=&Apache::lonlocal::texthash(
1211: 'cnu' => 'Create New User',
1.213 raeburn 1212: 'ast' => 'as a student',
1.318 raeburn 1213: 'ame' => 'as a member',
1.188 raeburn 1214: 'ind' => 'in domain',
1215: 'lg' => 'Login Data',
1.190 raeburn 1216: 'hs' => "Home Server",
1.188 raeburn 1217: );
1.185 raeburn 1218: $r->print(<<ENDTITLE);
1.110 albertel 1219: $start_page
1.160 raeburn 1220: $response
1.25 matthew 1221: $forminfo
1.31 matthew 1222: <script type="text/javascript" language="Javascript">
1.301 bisitz 1223: // <![CDATA[
1.20 harris41 1224: $loginscript
1.301 bisitz 1225: // ]]>
1.31 matthew 1226: </script>
1.20 harris41 1227: <input type='hidden' name='makeuser' value='1' />
1.216 raeburn 1228: <h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain
1.185 raeburn 1229: ENDTITLE
1.213 raeburn 1230: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1231: if ($crstype eq 'Community') {
1232: $r->print(' ('.$lt{'ame'}.')');
1233: } else {
1234: $r->print(' ('.$lt{'ast'}.')');
1235: }
1.213 raeburn 1236: }
1237: $r->print('</h2>'."\n".'<div class="LC_left_float">');
1.206 raeburn 1238: my $personal_table =
1.210 raeburn 1239: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1240: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 1241: $r->print($personal_table);
1.187 raeburn 1242: my ($home_server_pick,$numlib) =
1243: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1244: 'default','hide');
1245: if ($numlib > 1) {
1246: $r->print("
1.185 raeburn 1247: <br />
1.187 raeburn 1248: $lt{'hs'}: $home_server_pick
1249: <br />");
1250: } else {
1251: $r->print($home_server_pick);
1252: }
1.304 raeburn 1253: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1254: $r->print('<br /><h3>'.
1255: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1256: &Apache::loncommon::start_data_table().
1257: &build_tools_display($ccuname,$ccdomain,
1258: 'requestcourses').
1259: &Apache::loncommon::end_data_table());
1260: }
1.188 raeburn 1261: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1262: $lt{'lg'}.'</h3>');
1.185 raeburn 1263: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1264: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1265: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1266: my ($rules,$ruleorder) =
1267: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1268: if (ref($rules) eq 'HASH') {
1.193 raeburn 1269: if (ref($rules->{$matchedrule}) eq 'HASH') {
1270: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1271: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1272: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1273: } else {
1.193 raeburn 1274: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1275: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1276: if ($authtype =~ /^krb(4|5)$/) {
1277: my $ver = $1;
1278: if ($authparm ne '') {
1279: $fixedauth = <<"KERB";
1280: <input type="hidden" name="login" value="krb" />
1281: <input type="hidden" name="krbver" value="$ver" />
1282: <input type="hidden" name="krbarg" value="$authparm" />
1283: KERB
1284: }
1285: } else {
1286: $fixedauth =
1287: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1288: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1289: $fixedauth .=
1290: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1291: } else {
1.273 raeburn 1292: if ($authtype eq 'int') {
1293: $varauth = '<br />'.
1.301 bisitz 1294: &mt('[_1] Internally authenticated (with initial password [_2])','','<input type="password" size="10" name="intarg" value="" />')."<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.273 raeburn 1295: } elsif ($authtype eq 'loc') {
1296: $varauth = '<br />'.
1297: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1298: } else {
1299: $varauth =
1.185 raeburn 1300: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1301: }
1.185 raeburn 1302: }
1303: }
1304: }
1305: } else {
1.190 raeburn 1306: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1307: }
1308: }
1309: if ($authmsg) {
1310: $r->print(<<ENDAUTH);
1311: $fixedauth
1312: $authmsg
1313: $varauth
1314: ENDAUTH
1315: }
1316: } else {
1.190 raeburn 1317: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1318: }
1.362 raeburn 1319: $r->print($portfolioform.$domroleform);
1.215 raeburn 1320: if ($env{'form.action'} eq 'singlestudent') {
1321: $r->print(&date_sections_select($context,$newuser,$formname,
1.374 ! raeburn 1322: $permission,$crstype));
1.215 raeburn 1323: }
1324: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1325: } else { # user already exists
1.79 albertel 1326: my %lt=&Apache::lonlocal::texthash(
1.191 raeburn 1327: 'cup' => "Modify existing user: ",
1.213 raeburn 1328: 'ens' => "Enroll one student: ",
1.318 raeburn 1329: 'enm' => "Enroll one member: ",
1.72 sakharuk 1330: 'id' => "in domain",
1331: );
1.26 matthew 1332: $r->print(<<ENDCHANGEUSER);
1.110 albertel 1333: $start_page
1.25 matthew 1334: $forminfo
1.213 raeburn 1335: <h2>
1.26 matthew 1336: ENDCHANGEUSER
1.213 raeburn 1337: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1338: if ($crstype eq 'Community') {
1339: $r->print($lt{'enm'});
1340: } else {
1341: $r->print($lt{'ens'});
1342: }
1.213 raeburn 1343: } else {
1344: $r->print($lt{'cup'});
1345: }
1346: $r->print(' "'.$ccuname.'" '.$lt{'id'}.' "'.$ccdomain.'"</h2>'.
1347: "\n".'<div class="LC_left_float">');
1.206 raeburn 1348: my ($personal_table,$showforceid) =
1.210 raeburn 1349: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1350: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 1351: $r->print($personal_table);
1352: if ($showforceid) {
1.362 raeburn 1353: $r->print('<table>'.&Apache::lonuserutils::forceid_change($context).'</table>');
1.199 raeburn 1354: }
1.275 raeburn 1355: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1356: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1357: &Apache::loncommon::start_data_table());
1.314 raeburn 1358: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1359: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1360: } else {
1361: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1362: $env{'request.role.domain'}));
1363: }
1364: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1365: }
1.199 raeburn 1366: $r->print('</div>');
1.362 raeburn 1367: my @order = ('auth','quota','tools','requestauthor');
1368: my %user_text;
1369: my ($isadv,$isauthor) =
1370: &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1371: if ((!$isauthor) &&
1372: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
1373: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1374: }
1375: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1376: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1377: (&Apache::lonnet::allowed('mut',$ccdomain))) {
1.188 raeburn 1378: # Current user has quota modification privileges
1.362 raeburn 1379: $user_text{'quota'} = &portfolio_quota($ccuname,$ccdomain);
1.267 raeburn 1380: }
1381: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1382: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1383: # Get the user's portfolio information
1384: my %portq = &Apache::lonnet::get('environment',['portfolioquota'],
1385: $ccdomain,$ccuname);
1386: my %lt=&Apache::lonlocal::texthash(
1387: 'dska' => "Disk space allocated to user's portfolio files",
1388: 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
1389: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1390: );
1.362 raeburn 1391: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1392: <h3>$lt{'dska'}</h3>
1393: $lt{'youd'} $lt{'ichr'}: $ccdomain
1394: ENDNOPORTPRIV
1.267 raeburn 1395: }
1396: }
1397: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1398: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1399: my %lt=&Apache::lonlocal::texthash(
1400: 'utav' => "User Tools Availability",
1.361 raeburn 1401: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1402: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1403: );
1.362 raeburn 1404: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1405: <h3>$lt{'utav'}</h3>
1406: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1407: ENDNOTOOLSPRIV
1408: }
1.188 raeburn 1409: }
1.362 raeburn 1410: my $gotdiv = 0;
1411: foreach my $item (@order) {
1412: if ($user_text{$item} ne '') {
1413: unless ($gotdiv) {
1414: $r->print('<div class="LC_left_float">');
1415: $gotdiv = 1;
1416: }
1417: $r->print('<br />'.$user_text{$item});
1418: }
1419: }
1420: if ($env{'form.action'} eq 'singlestudent') {
1421: unless ($gotdiv) {
1422: $r->print('<div class="LC_left_float">');
1.213 raeburn 1423: }
1.374 ! raeburn 1424: $r->print(&date_sections_select($context,$newuser,$formname,
! 1425: $permission,$crstype));
! 1426: }
1.362 raeburn 1427: if ($gotdiv) {
1428: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1429: }
1.217 raeburn 1430: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1431: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1432: $roledom,$crstype);
1.217 raeburn 1433: }
1.25 matthew 1434: } ## End of new user/old user logic
1.218 raeburn 1435: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1436: my $btntxt;
1437: if ($crstype eq 'Community') {
1438: $btntxt = &mt('Enroll Member');
1439: } else {
1440: $btntxt = &mt('Enroll Student');
1441: }
1442: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.218 raeburn 1443: } else {
1444: $r->print('<h3>'.&mt('Add Roles').'</h3>');
1445: my $addrolesdisplay = 0;
1446: if ($context eq 'domain' || $context eq 'author') {
1447: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1448: }
1449: if ($context eq 'domain') {
1.357 raeburn 1450: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1451: if (!$addrolesdisplay) {
1452: $addrolesdisplay = $add_domainroles;
1.2 www 1453: }
1.218 raeburn 1454: $r->print(&course_level_dc($env{'request.role.domain'},'Course'));
1.301 bisitz 1455: $r->print('<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1456: } elsif ($context eq 'author') {
1457: if ($addrolesdisplay) {
1.262 schafran 1458: $r->print('<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1459: if ($newuser) {
1.301 bisitz 1460: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1461: } else {
1.301 bisitz 1462: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1463: }
1.188 raeburn 1464: } else {
1.218 raeburn 1465: $r->print('<br /><a href="javascript:backPage(document.cu)">'.
1466: &mt('Back to previous page').'</a>');
1.188 raeburn 1467: }
1468: } else {
1.218 raeburn 1469: $r->print(&course_level_table(%inccourses));
1.301 bisitz 1470: $r->print('<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1471: }
1.88 raeburn 1472: }
1.188 raeburn 1473: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1474: $r->print('<input type="hidden" name="currstate" value="" />');
1.352 raeburn 1475: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form>');
1.218 raeburn 1476: return;
1.2 www 1477: }
1.1 www 1478:
1.213 raeburn 1479: sub singleuser_breadcrumb {
1.318 raeburn 1480: my ($crstype) = @_;
1.213 raeburn 1481: my %breadcrumb_text;
1482: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1483: if ($crstype eq 'Community') {
1484: $breadcrumb_text{'search'} = 'Enroll a member';
1485: } else {
1486: $breadcrumb_text{'search'} = 'Enroll a student';
1487: }
1.213 raeburn 1488: $breadcrumb_text{'userpicked'} = 'Select a user',
1489: $breadcrumb_text{'modify'} = 'Set section/dates',
1490: } else {
1.229 raeburn 1491: $breadcrumb_text{'search'} = 'Create/modify a user';
1.213 raeburn 1492: $breadcrumb_text{'userpicked'} = 'Select a user',
1493: $breadcrumb_text{'modify'} = 'Set user role',
1494: }
1495: return %breadcrumb_text;
1496: }
1497:
1498: sub date_sections_select {
1.374 ! raeburn 1499: my ($context,$newuser,$formname,$permission,$crstype) = @_;
1.213 raeburn 1500: my $cid = $env{'request.course.id'};
1501: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1502: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1503: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1504: undef,$formname,$permission);
1505: my $rowtitle = 'Section';
1506: my $secbox = '<h3>'.&mt('Section').'</h3>'."\n".
1507: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.374 ! raeburn 1508: $permission,$context,'',$crstype);
1.213 raeburn 1509: my $output = $date_table.$secbox;
1510: return $output;
1511: }
1512:
1.216 raeburn 1513: sub validation_javascript {
1514: my ($context,$ccdomain,$pjump_def,$groupslist,$newuser,$formname,
1515: $loaditem) = @_;
1516: my $dc_setcourse_code = '';
1517: my $nondc_setsection_code = '';
1518: if ($context eq 'domain') {
1519: my $dcdom = $env{'request.role.domain'};
1520: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1521: $dc_setcourse_code =
1522: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1523: } else {
1.227 raeburn 1524: my $checkauth;
1525: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1526: $checkauth = 1;
1527: }
1528: if ($context eq 'course') {
1529: $nondc_setsection_code =
1530: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1531: undef,$checkauth);
1532: }
1533: if ($checkauth) {
1534: $nondc_setsection_code .=
1535: &Apache::lonuserutils::verify_authen($formname,$context);
1536: }
1.216 raeburn 1537: }
1538: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1539: $nondc_setsection_code,$groupslist);
1540: my ($jsback,$elements) = &crumb_utilities();
1541: $js .= "\n".
1.301 bisitz 1542: '<script type="text/javascript">'."\n".
1543: '// <![CDATA['."\n".
1544: $jsback."\n".
1545: '// ]]>'."\n".
1546: '</script>'."\n";
1.216 raeburn 1547: return $js;
1548: }
1549:
1.217 raeburn 1550: sub display_existing_roles {
1.329 raeburn 1551: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype) = @_;
1552: my $now=time;
1553: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1554: 'rer' => "Existing Roles",
1555: 'rev' => "Revoke",
1556: 'del' => "Delete",
1557: 'ren' => "Re-Enable",
1558: 'rol' => "Role",
1559: 'ext' => "Extent",
1560: 'sta' => "Start",
1561: 'end' => "End",
1562: );
1.329 raeburn 1563: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1564: if ($context eq 'course' || $context eq 'author') {
1565: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1566: my %roleshash =
1567: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1568: ['active','previous','future'],\@roles,$roledom,1);
1569: foreach my $key (keys(%roleshash)) {
1570: my ($start,$end) = split(':',$roleshash{$key});
1571: next if ($start eq '-1' || $end eq '-1');
1572: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1573: if ($context eq 'course') {
1574: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1575: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1576: } elsif ($context eq 'author') {
1577: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1578: }
1579: my ($newkey,$newvalue,$newrole);
1580: $newkey = '/'.$rdom.'/'.$rnum;
1581: if ($sec ne '') {
1582: $newkey .= '/'.$sec;
1583: }
1584: $newvalue = $role;
1585: if ($role =~ /^cr/) {
1586: $newrole = 'cr';
1587: } else {
1588: $newrole = $role;
1589: }
1590: $newkey .= '_'.$newrole;
1591: if ($start ne '' && $end ne '') {
1592: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1593: } elsif ($end ne '') {
1594: $newvalue .= '_'.$end;
1.329 raeburn 1595: }
1596: $rolesdump{$newkey} = $newvalue;
1597: }
1598: } else {
1.360 raeburn 1599: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1600: }
1601: # Build up table of user roles to allow revocation and re-enabling of roles.
1602: my ($tmp) = keys(%rolesdump);
1603: return if ($tmp =~ /^(con_lost|error)/i);
1604: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1605: my $b1=join('_',(split('_',$b))[1,0]);
1606: return $a1 cmp $b1;
1607: } keys(%rolesdump)) {
1608: next if ($area =~ /^rolesdef/);
1609: my $envkey=$area;
1610: my $role = $rolesdump{$area};
1611: my $thisrole=$area;
1612: $area =~ s/\_\w\w$//;
1613: my ($role_code,$role_end_time,$role_start_time) =
1614: split(/_/,$role);
1.217 raeburn 1615: # Is this a custom role? Get role owner and title.
1.329 raeburn 1616: my ($croleudom,$croleuname,$croletitle)=
1617: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1618: my $allowed=0;
1619: my $delallowed=0;
1620: my $sortkey=$role_code;
1621: my $class='Unknown';
1622: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
1623: $class='Course';
1624: my ($coursedom,$coursedir) = ($1,$2);
1625: my $cid = $1.'_'.$2;
1626: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1627: my %coursedata=
1628: &Apache::lonnet::coursedescription($cid);
1629: if ($coursedir =~ /^$match_community$/) {
1630: $class='Community';
1631: }
1632: $sortkey.="\0$coursedom";
1633: my $carea;
1634: if (defined($coursedata{'description'})) {
1635: $carea=$coursedata{'description'}.
1636: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1637: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1638: $sortkey.="\0".$coursedata{'description'};
1639: } else {
1640: if ($class eq 'Community') {
1641: $carea=&mt('Unavailable community').': '.$area;
1642: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1643: } else {
1644: $carea=&mt('Unavailable course').': '.$area;
1645: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1646: }
1.329 raeburn 1647: }
1648: $sortkey.="\0$coursedir";
1649: $inccourses->{$cid}=1;
1650: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1651: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1652: $allowed=1;
1653: }
1654: unless ($allowed) {
1.365 raeburn 1655: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1656: if ($isowner) {
1657: if (($role_code eq 'co') && ($class eq 'Community')) {
1658: $allowed = 1;
1659: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1660: $allowed = 1;
1661: }
1.217 raeburn 1662: }
1.329 raeburn 1663: }
1664: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1665: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1666: $delallowed=1;
1667: }
1.217 raeburn 1668: # - custom role. Needs more info, too
1.329 raeburn 1669: if ($croletitle) {
1670: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1671: $allowed=1;
1672: $thisrole.='.'.$role_code;
1.217 raeburn 1673: }
1.329 raeburn 1674: }
1675: if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
1.373 bisitz 1676: $carea.='<br />'.&mt('Section: [_1]',$3);
1.329 raeburn 1677: $sortkey.="\0$3";
1678: if (!$allowed) {
1679: if ($env{'request.course.sec'} eq $3) {
1680: if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
1681: $allowed = 1;
1.217 raeburn 1682: }
1683: }
1684: }
1.329 raeburn 1685: }
1686: $area=$carea;
1687: } else {
1688: $sortkey.="\0".$area;
1689: # Determine if current user is able to revoke privileges
1690: if ($area=~m{^/($match_domain)/}) {
1691: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1692: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1693: $allowed=1;
1.217 raeburn 1694: }
1.329 raeburn 1695: if (((&Apache::lonnet::allowed('dro',$1)) ||
1696: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1697: ($role_code ne 'dc')) {
1698: $delallowed=1;
1.217 raeburn 1699: }
1.329 raeburn 1700: } else {
1701: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1702: $allowed=1;
1703: }
1704: }
1.363 raeburn 1705: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.329 raeburn 1706: $class='Construction Space';
1707: } elsif ($role_code eq 'su') {
1708: $class='System';
1.217 raeburn 1709: } else {
1.329 raeburn 1710: $class='Domain';
1.217 raeburn 1711: }
1.329 raeburn 1712: }
1713: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1714: $area=~m{/($match_domain)/($match_username)};
1715: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1716: $allowed=1;
1.217 raeburn 1717: } else {
1.329 raeburn 1718: $allowed=0;
1.217 raeburn 1719: }
1.329 raeburn 1720: }
1721: my $row = '';
1722: $row.= '<td>';
1723: my $active=1;
1724: $active=0 if (($role_end_time) && ($now>$role_end_time));
1725: if (($active) && ($allowed)) {
1726: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1727: } else {
1728: if ($active) {
1729: $row.=' ';
1.217 raeburn 1730: } else {
1.329 raeburn 1731: $row.=&mt('expired or revoked');
1.217 raeburn 1732: }
1.329 raeburn 1733: }
1734: $row.='</td><td>';
1735: if ($allowed && !$active) {
1736: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1737: } else {
1738: $row.=' ';
1739: }
1740: $row.='</td><td>';
1741: if ($delallowed) {
1742: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1743: } else {
1744: $row.=' ';
1745: }
1746: my $plaintext='';
1747: if (!$croletitle) {
1748: $plaintext=&Apache::lonnet::plaintext($role_code,$class)
1749: } else {
1750: $plaintext=
1.346 bisitz 1751: &mt('Customrole [_1][_2]defined by [_3]',
1752: '"'.$croletitle.'"',
1753: '<br />',
1754: $croleuname.':'.$croleudom);
1.329 raeburn 1755: }
1756: $row.= '</td><td>'.$plaintext.
1757: '</td><td>'.$area.
1758: '</td><td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1759: : ' ' ).
1760: '</td><td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1761: : ' ' )
1762: ."</td>";
1763: $sortrole{$sortkey}=$envkey;
1764: $roletext{$envkey}=$row;
1765: $roleclass{$envkey}=$class;
1766: $rolepriv{$envkey}=$allowed;
1767: } # end of foreach (table building loop)
1768:
1769: my $rolesdisplay = 0;
1770: my %output = ();
1771: foreach my $type ('Construction Space','Course','Community','Domain','System','Unknown') {
1772: $output{$type} = '';
1773: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1774: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1775: $output{$type}.=
1776: &Apache::loncommon::start_data_table_row().
1777: $roletext{$sortrole{$which}}.
1778: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1779: }
1.329 raeburn 1780: }
1781: unless($output{$type} eq '') {
1782: $output{$type} = '<tr class="LC_info_row">'.
1783: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1784: $output{$type};
1785: $rolesdisplay = 1;
1786: }
1787: }
1788: if ($rolesdisplay == 1) {
1789: my $contextrole='';
1790: if ($env{'request.course.id'}) {
1791: if (&Apache::loncommon::course_type() eq 'Community') {
1792: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 1793: } else {
1.329 raeburn 1794: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 1795: }
1.329 raeburn 1796: } elsif ($env{'request.role'} =~ /^au\./) {
1797: $contextrole = &mt('Existing Co-Author Roles in your Construction Space');
1798: } else {
1799: $contextrole = &mt('Existing Roles in this Domain');
1800: }
1801: $r->print('
1.217 raeburn 1802: <h3>'.$lt{'rer'}.'</h3>'.
1.329 raeburn 1803: '<div>'.$contextrole.'</div>'.
1.217 raeburn 1804: &Apache::loncommon::start_data_table("LC_createuser").
1805: &Apache::loncommon::start_data_table_header_row().
1806: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
1807: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
1808: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1809: &Apache::loncommon::end_data_table_header_row());
1.329 raeburn 1810: foreach my $type ('Construction Space','Course','Community','Domain','System','Unknown') {
1811: if ($output{$type}) {
1812: $r->print($output{$type}."\n");
1.217 raeburn 1813: }
1814: }
1.329 raeburn 1815: $r->print(&Apache::loncommon::end_data_table());
1816: }
1.217 raeburn 1817: return;
1818: }
1819:
1.218 raeburn 1820: sub new_coauthor_roles {
1821: my ($r,$ccuname,$ccdomain) = @_;
1822: my $addrolesdisplay = 0;
1823: #
1824: # Co-Author
1825: #
1826: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
1827: $env{'request.role.domain'}) &&
1828: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1829: # No sense in assigning co-author role to yourself
1830: $addrolesdisplay = 1;
1831: my $cuname=$env{'user.name'};
1832: my $cudom=$env{'request.role.domain'};
1833: my %lt=&Apache::lonlocal::texthash(
1834: 'cs' => "Construction Space",
1835: 'act' => "Activate",
1836: 'rol' => "Role",
1837: 'ext' => "Extent",
1838: 'sta' => "Start",
1839: 'end' => "End",
1840: 'cau' => "Co-Author",
1841: 'caa' => "Assistant Co-Author",
1842: 'ssd' => "Set Start Date",
1843: 'sed' => "Set End Date"
1844: );
1845: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
1846: &Apache::loncommon::start_data_table()."\n".
1847: &Apache::loncommon::start_data_table_header_row()."\n".
1848: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
1849: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
1850: '<th>'.$lt{'end'}.'</th>'."\n".
1851: &Apache::loncommon::end_data_table_header_row()."\n".
1852: &Apache::loncommon::start_data_table_row().'
1853: <td>
1.291 bisitz 1854: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 1855: </td>
1856: <td>'.$lt{'cau'}.'</td>
1857: <td>'.$cudom.'_'.$cuname.'</td>
1858: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
1859: <a href=
1860: "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>
1861: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
1862: <a href=
1863: "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".
1864: &Apache::loncommon::end_data_table_row()."\n".
1865: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 1866: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 1867: <td>'.$lt{'caa'}.'</td>
1868: <td>'.$cudom.'_'.$cuname.'</td>
1869: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
1870: <a href=
1871: "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>
1872: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
1873: <a href=
1874: "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".
1875: &Apache::loncommon::end_data_table_row()."\n".
1876: &Apache::loncommon::end_data_table());
1877: } elsif ($env{'request.role'} =~ /^au\./) {
1878: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
1879: $env{'request.role.domain'}))) {
1880: $r->print('<span class="LC_error">'.
1881: &mt('You do not have privileges to assign co-author roles.').
1882: '</span>');
1883: } elsif (($env{'user.name'} eq $ccuname) &&
1884: ($env{'user.domain'} eq $ccdomain)) {
1885: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Construction Space is not permitted'));
1886: }
1887: }
1888: return $addrolesdisplay;;
1889: }
1890:
1891: sub new_domain_roles {
1.357 raeburn 1892: my ($r,$ccdomain) = @_;
1.218 raeburn 1893: my $addrolesdisplay = 0;
1894: #
1895: # Domain level
1896: #
1897: my $num_domain_level = 0;
1898: my $domaintext =
1899: '<h4>'.&mt('Domain Level').'</h4>'.
1900: &Apache::loncommon::start_data_table().
1901: &Apache::loncommon::start_data_table_header_row().
1902: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
1903: &mt('Extent').'</th>'.
1904: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
1905: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 1906: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 1907: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 1908: foreach my $role (@allroles) {
1909: next if ($role eq 'ad');
1.357 raeburn 1910: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 1911: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1912: my $plrole=&Apache::lonnet::plaintext($role);
1913: my %lt=&Apache::lonlocal::texthash(
1914: 'ssd' => "Set Start Date",
1915: 'sed' => "Set End Date"
1916: );
1917: $num_domain_level ++;
1918: $domaintext .=
1919: &Apache::loncommon::start_data_table_row().
1.291 bisitz 1920: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 1921: <td>'.$plrole.'</td>
1922: <td>'.$thisdomain.'</td>
1923: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
1924: <a href=
1925: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1926: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
1927: <a href=
1928: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
1929: &Apache::loncommon::end_data_table_row();
1930: }
1931: }
1932: }
1933: $domaintext.= &Apache::loncommon::end_data_table();
1934: if ($num_domain_level > 0) {
1935: $r->print($domaintext);
1936: $addrolesdisplay = 1;
1937: }
1938: return $addrolesdisplay;
1939: }
1940:
1.188 raeburn 1941: sub user_authentication {
1.227 raeburn 1942: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 1943: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 1944: my $outcome;
1.188 raeburn 1945: # Check for a bad authentication type
1946: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
1947: # bad authentication scheme
1948: my %lt=&Apache::lonlocal::texthash(
1949: 'err' => "ERROR",
1950: 'uuas' => "This user has an unrecognized authentication scheme",
1951: 'adcs' => "Please alert a domain coordinator of this situation",
1952: 'sldb' => "Please specify login data below",
1953: 'ld' => "Login Data"
1954: );
1955: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 1956: &initialize_authen_forms($ccdomain,$formname);
1957:
1.190 raeburn 1958: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 1959: $outcome = <<ENDBADAUTH;
1960: <script type="text/javascript" language="Javascript">
1.301 bisitz 1961: // <![CDATA[
1.188 raeburn 1962: $loginscript
1.301 bisitz 1963: // ]]>
1.188 raeburn 1964: </script>
1965: <span class="LC_error">$lt{'err'}:
1966: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
1967: <h3>$lt{'ld'}</h3>
1968: $choices
1969: ENDBADAUTH
1970: } else {
1971: # This user is not allowed to modify the user's
1972: # authentication scheme, so just notify them of the problem
1973: $outcome = <<ENDBADAUTH;
1974: <span class="LC_error"> $lt{'err'}:
1975: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
1976: </span>
1977: ENDBADAUTH
1978: }
1979: } else { # Authentication type is valid
1.227 raeburn 1980: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 1981: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 1982: &modify_login_block($ccdomain,$currentauth);
1983: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1984: # Current user has login modification privileges
1985: my %lt=&Apache::lonlocal::texthash (
1986: 'ld' => "Login Data",
1987: 'ccld' => "Change Current Login Data",
1988: 'enld' => "Enter New Login Data"
1989: );
1990: $outcome =
1991: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 1992: '// <![CDATA['."\n".
1.188 raeburn 1993: $loginscript."\n".
1.301 bisitz 1994: '// ]]>'."\n".
1.188 raeburn 1995: '</script>'."\n".
1996: '<h3>'.$lt{'ld'}.'</h3>'.
1997: &Apache::loncommon::start_data_table().
1.205 raeburn 1998: &Apache::loncommon::start_data_table_row().
1.188 raeburn 1999: '<td>'.$authformnop;
2000: if ($can_modify) {
2001: $outcome .= '</td>'."\n".
2002: &Apache::loncommon::end_data_table_row().
2003: &Apache::loncommon::start_data_table_row().
2004: '<td>'.$authformcurrent.'</td>'.
2005: &Apache::loncommon::end_data_table_row()."\n";
2006: } else {
1.200 raeburn 2007: $outcome .= ' ('.$authformcurrent.')</td>'.
2008: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2009: }
1.205 raeburn 2010: foreach my $item (@authform_others) {
2011: $outcome .= &Apache::loncommon::start_data_table_row().
2012: '<td>'.$item.'</td>'.
2013: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2014: }
1.205 raeburn 2015: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2016: } else {
2017: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
2018: my %lt=&Apache::lonlocal::texthash(
2019: 'ccld' => "Change Current Login Data",
2020: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2021: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2022: );
2023: $outcome .= <<ENDNOPRIV;
2024: <h3>$lt{'ccld'}</h3>
2025: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2026: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2027: ENDNOPRIV
2028: }
2029: }
2030: } ## End of "check for bad authentication type" logic
2031: return $outcome;
2032: }
2033:
1.187 raeburn 2034: sub modify_login_block {
2035: my ($dom,$currentauth) = @_;
2036: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2037: my ($authnum,%can_assign) =
2038: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2039: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2040: if ($currentauth=~/^krb(4|5):/) {
2041: $authformcurrent=$authformkrb;
2042: if ($can_assign{'int'}) {
1.205 raeburn 2043: push(@authform_others,$authformint);
1.187 raeburn 2044: }
2045: if ($can_assign{'loc'}) {
1.205 raeburn 2046: push(@authform_others,$authformloc);
1.187 raeburn 2047: }
2048: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2049: $show_override_msg = 1;
2050: }
2051: } elsif ($currentauth=~/^internal:/) {
2052: $authformcurrent=$authformint;
2053: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2054: push(@authform_others,$authformkrb);
1.187 raeburn 2055: }
2056: if ($can_assign{'loc'}) {
1.205 raeburn 2057: push(@authform_others,$authformloc);
1.187 raeburn 2058: }
2059: if ($can_assign{'int'}) {
2060: $show_override_msg = 1;
2061: }
2062: } elsif ($currentauth=~/^unix:/) {
2063: $authformcurrent=$authformfsys;
2064: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2065: push(@authform_others,$authformkrb);
1.187 raeburn 2066: }
2067: if ($can_assign{'int'}) {
1.205 raeburn 2068: push(@authform_others,$authformint);
1.187 raeburn 2069: }
2070: if ($can_assign{'loc'}) {
1.205 raeburn 2071: push(@authform_others,$authformloc);
1.187 raeburn 2072: }
2073: if ($can_assign{'fsys'}) {
2074: $show_override_msg = 1;
2075: }
2076: } elsif ($currentauth=~/^localauth:/) {
2077: $authformcurrent=$authformloc;
2078: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2079: push(@authform_others,$authformkrb);
1.187 raeburn 2080: }
2081: if ($can_assign{'int'}) {
1.205 raeburn 2082: push(@authform_others,$authformint);
1.187 raeburn 2083: }
2084: if ($can_assign{'loc'}) {
2085: $show_override_msg = 1;
2086: }
2087: }
2088: if ($show_override_msg) {
1.205 raeburn 2089: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2090: '</td></tr>'."\n".
2091: '<tr><td> </td>'.
2092: '<td><b>'.&mt('Currently in use').'</b></td>'.
2093: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2094: &mt('will override current values').
1.205 raeburn 2095: '</span></td></tr></table>';
1.187 raeburn 2096: }
1.205 raeburn 2097: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2098: }
2099:
1.188 raeburn 2100: sub personal_data_display {
1.252 raeburn 2101: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
1.286 raeburn 2102: my ($output,$showforceid,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2103: my @userinfo = ('firstname','middlename','lastname','generation',
2104: 'permanentemail','id');
1.252 raeburn 2105: my $rowcount = 0;
2106: my $editable = 0;
1.286 raeburn 2107: %canmodify_status =
2108: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2109: ['inststatus'],$rolesarray);
1.253 raeburn 2110: if (!$newuser) {
1.188 raeburn 2111: # Get the users information
2112: %userenv = &Apache::lonnet::get('environment',
2113: ['firstname','middlename','lastname','generation',
1.286 raeburn 2114: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2115: %canmodify =
2116: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2117: \@userinfo,$rolesarray);
1.257 raeburn 2118: } elsif ($context eq 'selfcreate') {
2119: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2120: $inst_results,$rolesarray);
1.188 raeburn 2121: }
2122: my %lt=&Apache::lonlocal::texthash(
2123: 'pd' => "Personal Data",
2124: 'firstname' => "First Name",
2125: 'middlename' => "Middle Name",
2126: 'lastname' => "Last Name",
2127: 'generation' => "Generation",
2128: 'permanentemail' => "Permanent e-mail address",
1.259 bisitz 2129: 'id' => "Student/Employee ID",
1.286 raeburn 2130: 'lg' => "Login Data",
2131: 'inststatus' => "Affiliation",
1.188 raeburn 2132: );
2133: my %textboxsize = (
2134: firstname => '15',
2135: middlename => '15',
2136: lastname => '15',
2137: generation => '5',
2138: permanentemail => '25',
2139: id => '15',
2140: );
2141: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2142: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2143: &Apache::lonhtmlcommon::start_pick_box();
2144: foreach my $item (@userinfo) {
2145: my $rowtitle = $lt{$item};
1.252 raeburn 2146: my $hiderow = 0;
1.188 raeburn 2147: if ($item eq 'generation') {
2148: $rowtitle = $genhelp.$rowtitle;
2149: }
1.252 raeburn 2150: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2151: if ($newuser) {
1.210 raeburn 2152: if (ref($inst_results) eq 'HASH') {
2153: if ($inst_results->{$item} ne '') {
1.252 raeburn 2154: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2155: } else {
1.252 raeburn 2156: if ($context eq 'selfcreate') {
2157: if ($canmodify{$item}) {
2158: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2159: $editable ++;
2160: } else {
2161: $hiderow = 1;
2162: }
1.253 raeburn 2163: } else {
2164: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2165: }
1.210 raeburn 2166: }
1.188 raeburn 2167: } else {
1.252 raeburn 2168: if ($context eq 'selfcreate') {
1.287 raeburn 2169: if (($item eq 'permanentemail') && ($newuser eq 'email')) {
2170: $row .= $ccuname;
1.252 raeburn 2171: } else {
1.287 raeburn 2172: if ($canmodify{$item}) {
2173: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
2174: $editable ++;
2175: } else {
2176: $hiderow = 1;
2177: }
1.252 raeburn 2178: }
1.253 raeburn 2179: } else {
2180: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2181: }
1.188 raeburn 2182: }
2183: } else {
1.219 raeburn 2184: if ($canmodify{$item}) {
1.252 raeburn 2185: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.188 raeburn 2186: } else {
1.252 raeburn 2187: $row .= $userenv{$item};
1.188 raeburn 2188: }
1.206 raeburn 2189: if ($item eq 'id') {
1.219 raeburn 2190: $showforceid = $canmodify{$item};
2191: }
1.188 raeburn 2192: }
1.252 raeburn 2193: $row .= &Apache::lonhtmlcommon::row_closure(1);
2194: if (!$hiderow) {
2195: $output .= $row;
2196: $rowcount ++;
2197: }
1.188 raeburn 2198: }
1.286 raeburn 2199: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2200: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2201: if (ref($types) eq 'ARRAY') {
2202: if (@{$types} > 0) {
2203: my ($hiderow,$shown);
2204: if ($canmodify_status{'inststatus'}) {
2205: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2206: } else {
2207: if ($userenv{'inststatus'} eq '') {
2208: $hiderow = 1;
1.334 raeburn 2209: } else {
2210: my @showitems;
2211: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2212: if (exists($usertypes->{$item})) {
2213: push(@showitems,$usertypes->{$item});
2214: } else {
2215: push(@showitems,$item);
2216: }
2217: }
2218: if (@showitems) {
2219: $shown = join(', ',@showitems);
2220: } else {
2221: $hiderow = 1;
2222: }
1.286 raeburn 2223: }
2224: }
2225: if (!$hiderow) {
2226: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affliations'),undef,'LC_oddrow_value')."\n".
2227: $shown.&Apache::lonhtmlcommon::row_closure(1);
2228: if ($context eq 'selfcreate') {
2229: $rowcount ++;
2230: }
2231: $output .= $row;
2232: }
2233: }
2234: }
2235: }
1.188 raeburn 2236: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2237: if (wantarray) {
1.252 raeburn 2238: if ($context eq 'selfcreate') {
2239: return($output,$rowcount,$editable);
2240: } else {
2241: return ($output,$showforceid);
2242: }
1.206 raeburn 2243: } else {
2244: return $output;
2245: }
1.188 raeburn 2246: }
2247:
1.286 raeburn 2248: sub pick_inst_statuses {
2249: my ($curr,$usertypes,$types) = @_;
2250: my ($output,$rem,@currtypes);
2251: if ($curr ne '') {
2252: @currtypes = map { &unescape($_); } split(/:/,$curr);
2253: }
2254: my $numinrow = 2;
2255: if (ref($types) eq 'ARRAY') {
2256: $output = '<table>';
2257: my $lastcolspan;
2258: for (my $i=0; $i<@{$types}; $i++) {
2259: if (defined($usertypes->{$types->[$i]})) {
2260: my $rem = $i%($numinrow);
2261: if ($rem == 0) {
2262: if ($i<@{$types}-1) {
2263: if ($i > 0) {
2264: $output .= '</tr>';
2265: }
2266: $output .= '<tr>';
2267: }
2268: } elsif ($i==@{$types}-1) {
2269: my $colsleft = $numinrow - $rem;
2270: if ($colsleft > 1) {
2271: $lastcolspan = ' colspan="'.$colsleft.'"';
2272: }
2273: }
2274: my $check = ' ';
2275: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2276: $check = ' checked="checked" ';
2277: }
2278: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2279: '<span class="LC_nobreak"><label>'.
2280: '<input type="checkbox" name="inststatus" '.
2281: 'value="'.$types->[$i].'"'.$check.'/>'.
2282: $usertypes->{$types->[$i]}.'</label></span></td>';
2283: }
2284: }
2285: $output .= '</tr></table>';
2286: }
2287: return $output;
2288: }
2289:
1.257 raeburn 2290: sub selfcreate_canmodify {
2291: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2292: if (ref($inst_results) eq 'HASH') {
2293: my @inststatuses = &get_inststatuses($inst_results);
2294: if (@inststatuses == 0) {
2295: @inststatuses = ('default');
2296: }
2297: $rolesarray = \@inststatuses;
2298: }
2299: my %canmodify =
2300: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2301: $rolesarray);
2302: return %canmodify;
2303: }
2304:
1.252 raeburn 2305: sub get_inststatuses {
2306: my ($insthashref) = @_;
2307: my @inststatuses = ();
2308: if (ref($insthashref) eq 'HASH') {
2309: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2310: @inststatuses = @{$insthashref->{'inststatus'}};
2311: }
2312: }
2313: return @inststatuses;
2314: }
2315:
1.4 www 2316: # ================================================================= Phase Three
1.42 matthew 2317: sub update_user_data {
1.351 raeburn 2318: my ($r,$context,$crstype,$brcrum) = @_;
1.101 albertel 2319: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2320: $env{'form.ccdomain'});
1.27 matthew 2321: # Error messages
1.188 raeburn 2322: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2323: my $end = '</span><br /><br />';
2324: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2325: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2326: &mt('Return to previous page').'</a>'.
2327: &Apache::loncommon::end_page();
2328: my $now = time;
1.40 www 2329: my $title;
1.101 albertel 2330: if (exists($env{'form.makeuser'})) {
1.40 www 2331: $title='Set Privileges for New User';
2332: } else {
2333: $title='Modify User Privileges';
2334: }
1.213 raeburn 2335: my $newuser = 0;
1.160 raeburn 2336: my ($jsback,$elements) = &crumb_utilities();
2337: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2338: '// <![CDATA['."\n".
2339: $jsback."\n".
2340: '// ]]>'."\n".
2341: '</script>'."\n";
1.318 raeburn 2342: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 2343: push (@{$brcrum},
2344: {href => "javascript:backPage(document.userupdate)",
2345: text => $breadcrumb_text{'search'},
2346: faq => 282,
2347: bug => 'Instructor Interface',}
2348: );
2349: if ($env{'form.prevphase'} eq 'userpicked') {
2350: push(@{$brcrum},
2351: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2352: text => $breadcrumb_text{'userpicked'},
2353: faq => 282,
2354: bug => 'Instructor Interface',});
1.233 raeburn 2355: }
1.224 raeburn 2356: my $helpitem = 'Course_Change_Privileges';
2357: if ($env{'form.action'} eq 'singlestudent') {
2358: $helpitem = 'Course_Add_Student';
2359: }
1.351 raeburn 2360: push(@{$brcrum},
2361: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2362: text => $breadcrumb_text{'modify'},
2363: faq => 282,
2364: bug => 'Instructor Interface',},
2365: {href => "/adm/createuser",
2366: text => "Result",
2367: faq => 282,
2368: bug => 'Instructor Interface',
2369: help => $helpitem});
2370: my $args = {bread_crumbs => $brcrum,
2371: bread_crumbs_component => 'User Management'};
2372: if ($env{'form.popup'}) {
2373: $args->{'no_nav_bar'} = 1;
2374: }
2375: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2376: $r->print(&update_result_form($uhome));
1.27 matthew 2377: # Check Inputs
1.101 albertel 2378: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2379: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2380: return;
2381: }
1.138 albertel 2382: if ( $env{'form.ccuname'} ne
2383: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2384: $r->print($error.&mt('Invalid login name.').' '.
2385: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2386: $end.$rtnlink);
1.27 matthew 2387: return;
2388: }
1.101 albertel 2389: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2390: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2391: return;
2392: }
1.138 albertel 2393: if ( $env{'form.ccdomain'} ne
2394: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2395: $r->print($error.&mt('Invalid domain name.').' '.
2396: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2397: $end.$rtnlink);
1.27 matthew 2398: return;
2399: }
1.219 raeburn 2400: if ($uhome eq 'no_host') {
2401: $newuser = 1;
2402: }
1.101 albertel 2403: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2404: # Modifying an existing user, so check the validity of the name
2405: if ($uhome eq 'no_host') {
1.73 sakharuk 2406: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 2407: $env{'form.ccuname'}.&mt(' in domain ').
2408: $env{'form.ccdomain'}.'.');
1.29 matthew 2409: return;
2410: }
2411: }
1.27 matthew 2412: # Determine authentication method and password for the user being modified
2413: my $amode='';
2414: my $genpwd='';
1.101 albertel 2415: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2416: $amode='krb';
1.101 albertel 2417: $amode.=$env{'form.krbver'};
2418: $genpwd=$env{'form.krbarg'};
2419: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2420: $amode='internal';
1.101 albertel 2421: $genpwd=$env{'form.intarg'};
2422: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2423: $amode='unix';
1.101 albertel 2424: $genpwd=$env{'form.fsysarg'};
2425: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2426: $amode='localauth';
1.101 albertel 2427: $genpwd=$env{'form.locarg'};
1.27 matthew 2428: $genpwd=" " if (!$genpwd);
1.101 albertel 2429: } elsif (($env{'form.login'} eq 'nochange') ||
2430: ($env{'form.login'} eq '' )) {
1.34 matthew 2431: # There is no need to tell the user we did not change what they
2432: # did not ask us to change.
1.35 matthew 2433: # If they are creating a new user but have not specified login
2434: # information this will be caught below.
1.30 matthew 2435: } else {
1.367 golterma 2436: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2437: return;
1.27 matthew 2438: }
1.164 albertel 2439:
1.188 raeburn 2440: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2441: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2442: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2443: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2444:
1.193 raeburn 2445: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2446: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2447: my @usertools = ('aboutme','blog','webdav','portfolio');
1.299 raeburn 2448: my @requestcourses = ('official','unofficial','community');
1.362 raeburn 2449: my @requestauthor = ('requestauthor');
1.286 raeburn 2450: my ($othertitle,$usertypes,$types) =
2451: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2452: my %canmodify_status =
2453: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2454: ['inststatus']);
1.101 albertel 2455: if ($env{'form.makeuser'}) {
1.164 albertel 2456: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2457: # Check for the authentication mode and password
2458: if (! $amode || ! $genpwd) {
1.193 raeburn 2459: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2460: return;
1.18 albertel 2461: }
1.29 matthew 2462: # Determine desired host
1.101 albertel 2463: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2464: if (lc($desiredhost) eq 'default') {
2465: $desiredhost = undef;
2466: } else {
1.147 albertel 2467: my %home_servers =
2468: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2469: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2470: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2471: return;
2472: }
2473: }
2474: # Check ID format
2475: my %checkhash;
2476: my %checks = ('id' => 1);
2477: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2478: 'newuser' => $newuser,
1.196 raeburn 2479: 'id' => $env{'form.cid'},
1.193 raeburn 2480: );
1.196 raeburn 2481: if ($env{'form.cid'} ne '') {
2482: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2483: \%rulematch,\%inst_results,\%curr_rules);
2484: if (ref($alerts{'id'}) eq 'HASH') {
2485: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2486: my $domdesc =
2487: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2488: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2489: my $userchkmsg;
2490: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2491: $userchkmsg =
2492: &Apache::loncommon::instrule_disallow_msg('id',
2493: $domdesc,1).
2494: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2495: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2496: }
2497: $r->print($error.&mt('Invalid ID format').$end.
2498: $userchkmsg.$rtnlink);
2499: return;
2500: }
2501: }
1.29 matthew 2502: }
2503: }
1.367 golterma 2504: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2505: # Call modifyuser
2506: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2507: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2508: $amode,$genpwd,$env{'form.cfirstname'},
2509: $env{'form.cmiddlename'},$env{'form.clastname'},
2510: $env{'form.cgeneration'},undef,$desiredhost,
2511: $env{'form.cpermanentemail'});
1.77 www 2512: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2513: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2514: $env{'form.ccdomain'});
1.334 raeburn 2515: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2516: if ($uhome ne 'no_host') {
1.334 raeburn 2517: if ($context eq 'domain') {
2518: if ($env{'form.customquota'} == 1) {
2519: if ($env{'form.portfolioquota'} eq '') {
2520: $newcustom{'quota'} = 0;
2521: } else {
2522: $newcustom{'quota'} = $env{'form.portfolioquota'};
2523: $newcustom{'quota'} =~ s/[^\d\.]//g;
2524: }
2525: $changed{'quota'} = "a_admin($newcustom{'quota'},\%changeHash);
2526: }
2527: foreach my $item (@usertools) {
2528: if ($env{'form.custom'.$item} == 1) {
2529: $newcustom{$item} = $env{'form.tools_'.$item};
2530: $changed{$item} = &tool_admin($item,$newcustom{$item},
2531: \%changeHash,'tools');
2532: }
1.267 raeburn 2533: }
1.334 raeburn 2534: foreach my $item (@requestcourses) {
1.341 raeburn 2535: if ($env{'form.custom'.$item} == 1) {
2536: $newcustom{$item} = $env{'form.crsreq_'.$item};
2537: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2538: $newcustom{$item} .= '=';
2539: unless ($env{'form.crsreq_'.$item.'_limit'} =~ /\D/) {
2540: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2541: }
1.334 raeburn 2542: }
1.341 raeburn 2543: $changed{$item} = &tool_admin($item,$newcustom{$item},
2544: \%changeHash,'requestcourses');
1.334 raeburn 2545: }
1.275 raeburn 2546: }
1.362 raeburn 2547: if ($env{'form.customrequestauthor'} == 1) {
2548: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2549: $changed{'requestauthor'} = &tool_admin('requestauthor',
2550: $newcustom{'requestauthor'},
2551: \%changeHash,'requestauthor');
2552: }
1.275 raeburn 2553: }
1.334 raeburn 2554: if ($canmodify_status{'inststatus'}) {
2555: if (exists($env{'form.inststatus'})) {
2556: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2557: if (@inststatuses > 0) {
2558: $changeHash{'inststatus'} = join(',',@inststatuses);
2559: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2560: }
2561: }
1.232 raeburn 2562: }
1.334 raeburn 2563: if (keys(%changed)) {
2564: foreach my $item (@userinfo) {
2565: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2566: }
1.267 raeburn 2567: my $chgresult =
2568: &Apache::lonnet::put('environment',\%changeHash,
2569: $env{'form.ccdomain'},$env{'form.ccuname'});
2570: }
1.232 raeburn 2571: }
1.219 raeburn 2572: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2573: &Apache::lonnet::hostname($uhome));
1.101 albertel 2574: } elsif (($env{'form.login'} ne 'nochange') &&
2575: ($env{'form.login'} ne '' )) {
1.27 matthew 2576: # Modify user privileges
2577: if (! $amode || ! $genpwd) {
1.193 raeburn 2578: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2579: return;
1.20 harris41 2580: }
1.27 matthew 2581: # Only allow authentification modification if the person has authority
1.101 albertel 2582: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2583: $r->print('Modifying authentication: '.
1.31 matthew 2584: &Apache::lonnet::modifyuserauth(
1.101 albertel 2585: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2586: $amode,$genpwd));
1.102 albertel 2587: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2588: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2589: } else {
1.27 matthew 2590: # Okay, this is a non-fatal error.
1.193 raeburn 2591: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
1.27 matthew 2592: }
1.28 matthew 2593: }
1.344 bisitz 2594: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2595: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2596: ##
1.343 raeburn 2597: my (@userroles,%userupdate,$cnum,$cdom,%namechanged);
1.213 raeburn 2598: if ($context eq 'course') {
2599: ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2600: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.213 raeburn 2601: }
1.101 albertel 2602: if (! $env{'form.makeuser'} ) {
1.28 matthew 2603: # Check for need to change
2604: my %userenv = &Apache::lonnet::get
1.134 raeburn 2605: ('environment',['firstname','middlename','lastname','generation',
1.267 raeburn 2606: 'id','permanentemail','portfolioquota','inststatus','tools.aboutme',
1.361 raeburn 2607: 'tools.blog','tools.webdav','tools.portfolio',
2608: 'requestcourses.official','requestcourses.unofficial',
2609: 'requestcourses.community','reqcrsotherdom.official',
1.362 raeburn 2610: 'reqcrsotherdom.unofficial','reqcrsotherdom.community',
2611: 'requestauthor'],
1.160 raeburn 2612: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2613: my ($tmp) = keys(%userenv);
2614: if ($tmp =~ /^(con_lost|error)/i) {
2615: %userenv = ();
2616: }
1.206 raeburn 2617: my $no_forceid_alert;
2618: # Check to see if user information can be changed
2619: my %domconfig =
2620: &Apache::lonnet::get_dom('configuration',['usermodification'],
2621: $env{'form.ccdomain'});
1.213 raeburn 2622: my @statuses = ('active','future');
2623: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2624: my ($auname,$audom);
1.220 raeburn 2625: if ($context eq 'author') {
1.206 raeburn 2626: $auname = $env{'user.name'};
2627: $audom = $env{'user.domain'};
2628: }
2629: foreach my $item (keys(%roles)) {
1.220 raeburn 2630: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2631: if ($context eq 'course') {
2632: if ($cnum ne '' && $cdom ne '') {
2633: if ($rolenum eq $cnum && $roledom eq $cdom) {
2634: if (!grep(/^\Q$role\E$/,@userroles)) {
2635: push(@userroles,$role);
2636: }
2637: }
2638: }
2639: } elsif ($context eq 'author') {
2640: if ($rolenum eq $auname && $roledom eq $audom) {
2641: if (!grep(/^\Q$role\E$/,@userroles)) {
2642: push(@userroles,$role);
2643: }
2644: }
2645: }
2646: }
1.220 raeburn 2647: if ($env{'form.action'} eq 'singlestudent') {
2648: if (!grep(/^st$/,@userroles)) {
2649: push(@userroles,'st');
2650: }
2651: } else {
2652: # Check for course or co-author roles being activated or re-enabled
2653: if ($context eq 'author' || $context eq 'course') {
2654: foreach my $key (keys(%env)) {
2655: if ($context eq 'author') {
2656: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2657: if (!grep(/^\Q$1\E$/,@userroles)) {
2658: push(@userroles,$1);
2659: }
2660: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2661: if (!grep(/^\Q$1\E$/,@userroles)) {
2662: push(@userroles,$1);
2663: }
1.206 raeburn 2664: }
1.220 raeburn 2665: } elsif ($context eq 'course') {
2666: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2667: if (!grep(/^\Q$1\E$/,@userroles)) {
2668: push(@userroles,$1);
2669: }
2670: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
2671: if (!grep(/^\Q$1\E$/,@userroles)) {
2672: push(@userroles,$1);
2673: }
1.206 raeburn 2674: }
2675: }
2676: }
2677: }
2678: }
2679: #Check to see if we can change personal data for the user
2680: my (@mod_disallowed,@longroles);
2681: foreach my $role (@userroles) {
2682: if ($role eq 'cr') {
2683: push(@longroles,'Custom');
2684: } else {
1.318 raeburn 2685: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 2686: }
2687: }
1.219 raeburn 2688: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
2689: foreach my $item (@userinfo) {
1.28 matthew 2690: # Strip leading and trailing whitespace
1.203 raeburn 2691: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 2692: if (!$canmodify{$item}) {
1.207 raeburn 2693: if (defined($env{'form.c'.$item})) {
2694: if ($env{'form.c'.$item} ne $userenv{$item}) {
2695: push(@mod_disallowed,$item);
2696: }
1.206 raeburn 2697: }
2698: $env{'form.c'.$item} = $userenv{$item};
2699: }
1.28 matthew 2700: }
1.259 bisitz 2701: # Check to see if we can change the Student/Employee ID
1.196 raeburn 2702: my $forceid = $env{'form.forceid'};
2703: my $recurseid = $env{'form.recurseid'};
2704: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 2705: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
2706: $env{'form.ccuname'});
2707: if (($uidhash{$env{'form.ccuname'}}) &&
2708: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
2709: (!$forceid)) {
2710: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
2711: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 2712: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 2713: .'<br />'
2714: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
2715: .'<br />'."\n";
1.203 raeburn 2716: }
2717: }
2718: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 2719: my $checkhash;
2720: my $checks = { 'id' => 1 };
2721: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
2722: { 'newuser' => $newuser,
2723: 'id' => $env{'form.cid'},
2724: };
2725: &Apache::loncommon::user_rule_check($checkhash,$checks,
2726: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
2727: if (ref($alerts{'id'}) eq 'HASH') {
2728: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 2729: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 2730: }
2731: }
2732: }
1.286 raeburn 2733: my ($quotachanged,$oldportfolioquota,$newportfolioquota,$oldinststatus,
1.334 raeburn 2734: $newinststatus,$oldisdefault,$newisdefault,%oldsettings,
1.339 raeburn 2735: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
2736: $olddefquota,$oldsettingstatus,$newdefquota,$newsettingstatus);
1.334 raeburn 2737: @disporder = ('inststatus');
2738: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 2739: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 2740: } else {
2741: push(@disporder,'reqcrsotherdom');
2742: }
2743: push(@disporder,('quota','tools'));
1.338 raeburn 2744: $oldinststatus = $userenv{'inststatus'};
1.339 raeburn 2745: ($olddefquota,$oldsettingstatus) =
1.334 raeburn 2746: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus);
1.339 raeburn 2747: ($newdefquota,$newsettingstatus) = ($olddefquota,$oldsettingstatus);
1.334 raeburn 2748: my %canshow;
1.220 raeburn 2749: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 2750: $canshow{'quota'} = 1;
1.220 raeburn 2751: }
1.267 raeburn 2752: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 2753: $canshow{'tools'} = 1;
1.267 raeburn 2754: }
1.275 raeburn 2755: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 2756: $canshow{'requestcourses'} = 1;
1.300 raeburn 2757: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 2758: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 2759: }
1.286 raeburn 2760: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 2761: $canshow{'inststatus'} = 1;
1.286 raeburn 2762: }
1.362 raeburn 2763: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
2764: $canshow{'requestauthor'} = 1;
2765: }
1.267 raeburn 2766: my (%changeHash,%changed);
1.286 raeburn 2767: if ($oldinststatus eq '') {
1.334 raeburn 2768: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 2769: } else {
2770: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2771: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2772: } else {
1.334 raeburn 2773: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 2774: }
2775: }
2776: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 2777: if ($canmodify_status{'inststatus'}) {
2778: $canshow{'inststatus'} = 1;
1.286 raeburn 2779: if (exists($env{'form.inststatus'})) {
2780: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2781: if (@inststatuses > 0) {
2782: $newinststatus = join(':',map { &escape($_); } @inststatuses);
2783: $changeHash{'inststatus'} = $newinststatus;
2784: if ($newinststatus ne $oldinststatus) {
2785: $changed{'inststatus'} = $newinststatus;
1.339 raeburn 2786: ($newdefquota,$newsettingstatus) =
2787: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus);
1.286 raeburn 2788: }
2789: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 2790: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 2791: } else {
1.337 raeburn 2792: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 2793: }
1.334 raeburn 2794: }
2795: } else {
2796: $newinststatus = '';
2797: $changeHash{'inststatus'} = $newinststatus;
2798: $newsettings{'inststatus'} = $othertitle;
2799: if ($newinststatus ne $oldinststatus) {
2800: $changed{'inststatus'} = $changeHash{'inststatus'};
1.339 raeburn 2801: ($newdefquota,$newsettingstatus) =
2802: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus);
1.286 raeburn 2803: }
2804: }
1.334 raeburn 2805: } elsif ($context ne 'selfcreate') {
2806: $canshow{'inststatus'} = 1;
1.337 raeburn 2807: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 2808: }
1.204 raeburn 2809: $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
1.334 raeburn 2810: if ($context eq 'domain') {
2811: if ($userenv{'portfolioquota'} ne '') {
2812: $oldportfolioquota = $userenv{'portfolioquota'};
2813: if ($env{'form.customquota'} == 1) {
2814: if ($env{'form.portfolioquota'} eq '') {
2815: $newportfolioquota = 0;
2816: } else {
2817: $newportfolioquota = $env{'form.portfolioquota'};
2818: $newportfolioquota =~ s/[^\d\.]//g;
2819: }
2820: if ($newportfolioquota != $oldportfolioquota) {
2821: $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash);
2822: }
1.149 raeburn 2823: } else {
1.334 raeburn 2824: $changed{'quota'} = "a_admin('',\%changeHash);
1.339 raeburn 2825: $newportfolioquota = $newdefquota;
1.334 raeburn 2826: $newisdefault = 1;
1.149 raeburn 2827: }
1.334 raeburn 2828: } else {
2829: $oldisdefault = 1;
1.339 raeburn 2830: $oldportfolioquota = $olddefquota;
1.334 raeburn 2831: if ($env{'form.customquota'} == 1) {
2832: if ($env{'form.portfolioquota'} eq '') {
2833: $newportfolioquota = 0;
2834: } else {
2835: $newportfolioquota = $env{'form.portfolioquota'};
2836: $newportfolioquota =~ s/[^\d\.]//g;
2837: }
1.267 raeburn 2838: $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash);
1.334 raeburn 2839: } else {
1.339 raeburn 2840: $newportfolioquota = $newdefquota;
1.334 raeburn 2841: $newisdefault = 1;
1.134 raeburn 2842: }
2843: }
1.334 raeburn 2844: if ($oldisdefault) {
1.339 raeburn 2845: $oldsettingstext{'quota'} = &get_defaultquota_text($oldsettingstatus);
1.334 raeburn 2846: }
2847: if ($newisdefault) {
1.339 raeburn 2848: $newsettingstext{'quota'} = &get_defaultquota_text($newsettingstatus);
1.334 raeburn 2849: }
2850: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
2851: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
2852: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
2853: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
2854: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.362 raeburn 2855: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,\%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 2856: } else {
1.334 raeburn 2857: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
2858: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 2859: }
2860: }
1.334 raeburn 2861: foreach my $item (@userinfo) {
2862: if ($env{'form.c'.$item} ne $userenv{$item}) {
2863: $namechanged{$item} = 1;
2864: }
1.204 raeburn 2865: }
1.334 raeburn 2866: $oldsettings{'quota'} = $oldportfolioquota.' Mb';
2867: $newsettings{'quota'} = $newportfolioquota.' Mb';
2868: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 2869: my ($chgresult,$namechgresult);
2870: if (keys(%changed) > 0) {
2871: $chgresult =
1.204 raeburn 2872: &Apache::lonnet::put('environment',\%changeHash,
2873: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 2874: if ($chgresult eq 'ok') {
2875: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
2876: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 2877: my %newenvhash;
2878: foreach my $key (keys(%changed)) {
1.299 raeburn 2879: if (($key eq 'official') || ($key eq 'unofficial')
2880: || ($key eq 'community')) {
1.279 raeburn 2881: $newenvhash{'environment.requestcourses.'.$key} =
2882: $changeHash{'requestcourses.'.$key};
1.362 raeburn 2883: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 2884: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 2885: } else {
2886: $newenvhash{'environment.canrequest.'.$key} =
2887: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2888: $key,'reload','requestcourses');
2889: }
1.362 raeburn 2890: } elsif ($key eq 'requestauthor') {
2891: $newenvhash{'environment.'.$key} = $changeHash{$key};
2892: if ($changeHash{$key}) {
2893: $newenvhash{'environment.canrequest.author'} = 1;
2894: } else {
2895: $newenvhash{'environment.canrequest.author'} =
2896: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2897: $key,'reload','requestauthor');
2898: }
1.275 raeburn 2899: } elsif ($key ne 'quota') {
1.270 raeburn 2900: $newenvhash{'environment.tools.'.$key} =
2901: $changeHash{'tools.'.$key};
1.279 raeburn 2902: if ($changeHash{'tools.'.$key} ne '') {
2903: $newenvhash{'environment.availabletools.'.$key} =
2904: $changeHash{'tools.'.$key};
2905: } else {
2906: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 2907: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2908: $key,'reload','tools');
1.279 raeburn 2909: }
1.270 raeburn 2910: }
2911: }
1.271 raeburn 2912: if (keys(%newenvhash)) {
2913: &Apache::lonnet::appenv(\%newenvhash);
2914: }
1.267 raeburn 2915: }
2916: }
1.204 raeburn 2917: }
1.334 raeburn 2918: if (keys(%namechanged) > 0) {
1.337 raeburn 2919: foreach my $field (@userinfo) {
2920: $changeHash{$field} = $env{'form.c'.$field};
2921: }
2922: # Make the change
1.204 raeburn 2923: $namechgresult =
2924: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
2925: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
2926: $changeHash{'firstname'},$changeHash{'middlename'},
2927: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 2928: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 2929: %userupdate = (
2930: lastname => $env{'form.clastname'},
2931: middlename => $env{'form.cmiddlename'},
2932: firstname => $env{'form.cfirstname'},
2933: generation => $env{'form.cgeneration'},
2934: id => $env{'form.cid'},
2935: );
1.204 raeburn 2936: }
1.334 raeburn 2937: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 2938: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 2939: # Tell the user we changed the name
1.334 raeburn 2940: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 2941: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 2942: \%oldsettings, \%oldsettingstext,\%newsettings,
2943: \%newsettingstext);
1.203 raeburn 2944: if ($env{'form.cid'} ne $userenv{'id'}) {
2945: &Apache::lonnet::idput($env{'form.ccdomain'},
2946: ($env{'form.ccuname'} => $env{'form.cid'}));
2947: if (($recurseid) &&
2948: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
2949: my $idresult =
2950: &Apache::lonuserutils::propagate_id_change(
2951: $env{'form.ccuname'},$env{'form.ccdomain'},
2952: \%userupdate);
2953: $r->print('<br />'.$idresult.'<br />');
2954: }
1.196 raeburn 2955: }
1.149 raeburn 2956: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
2957: ($env{'form.ccuname'} eq $env{'user.name'})) {
2958: my %newenvhash;
2959: foreach my $key (keys(%changeHash)) {
2960: $newenvhash{'environment.'.$key} = $changeHash{$key};
2961: }
1.238 raeburn 2962: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 2963: }
1.28 matthew 2964: } else { # error occurred
1.188 raeburn 2965: $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
2966: $env{'form.ccuname'}.' '.&mt('in domain').' '.
1.206 raeburn 2967: $env{'form.ccdomain'}.'</span><br />');
1.28 matthew 2968: }
1.334 raeburn 2969: } else { # End of if ($env ... ) logic
1.275 raeburn 2970: # They did not want to change the users name, quota, tool availability,
2971: # or ability to request creation of courses,
1.267 raeburn 2972: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 2973: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 2974: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 2975: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 2976: }
1.206 raeburn 2977: if (@mod_disallowed) {
2978: my ($rolestr,$contextname);
2979: if (@longroles > 0) {
2980: $rolestr = join(', ',@longroles);
2981: } else {
2982: $rolestr = &mt('No roles');
2983: }
2984: if ($context eq 'course') {
2985: $contextname = &mt('course');
2986: } elsif ($context eq 'author') {
2987: $contextname = &mt('co-author');
2988: }
2989: $r->print(&mt('The following fields were not updated: ').'<ul>');
2990: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2991: foreach my $field (@mod_disallowed) {
2992: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
2993: }
1.207 raeburn 2994: $r->print('</ul>');
2995: if (@mod_disallowed == 1) {
2996: $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));
2997: } else {
2998: $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));
2999: }
1.292 bisitz 3000: my $helplink = 'javascript:helpMenu('."'display'".')';
3001: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3002: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3003: ,'<a href="'.$helplink.'">','</a>')
3004: .'<br />');
1.206 raeburn 3005: }
1.259 bisitz 3006: $r->print('<span class="LC_warning">'
3007: .$no_forceid_alert
3008: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3009: .'</span>');
1.4 www 3010: }
1.367 golterma 3011: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3012: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 3013: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype);
3014: $r->print('<p><a href="javascript:backPage(document.userupdate)">');
3015: if ($crstype eq 'Community') {
3016: $r->print(&mt('Enroll Another Member'));
3017: } else {
3018: $r->print(&mt('Enroll Another Student'));
3019: }
3020: $r->print('</a></p>');
1.220 raeburn 3021: } else {
1.239 raeburn 3022: my @rolechanges = &update_roles($r,$context);
1.334 raeburn 3023: if (keys(%namechanged) > 0) {
1.220 raeburn 3024: if ($context eq 'course') {
3025: if (@userroles > 0) {
1.225 raeburn 3026: if ((@rolechanges == 0) ||
3027: (!(grep(/^st$/,@rolechanges)))) {
3028: if (grep(/^st$/,@userroles)) {
3029: my $classlistupdated =
3030: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3031: $cnum,$env{'form.ccdomain'},
3032: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3033: }
1.220 raeburn 3034: }
3035: }
3036: }
3037: }
1.226 raeburn 3038: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3039: $env{'form.ccdomain'});
3040: if ($env{'form.popup'}) {
3041: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3042: } else {
1.367 golterma 3043: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3044: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3045: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3046: }
1.220 raeburn 3047: }
3048: }
3049:
1.334 raeburn 3050: sub display_userinfo {
1.362 raeburn 3051: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3052: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3053: $newsetting,$newsettingtext) = @_;
3054: return unless (ref($order) eq 'ARRAY' &&
3055: ref($canshow) eq 'HASH' &&
3056: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3057: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3058: ref($usertools) eq 'ARRAY' &&
3059: ref($userenv) eq 'HASH' &&
3060: ref($changedhash) eq 'HASH' &&
3061: ref($oldsetting) eq 'HASH' &&
3062: ref($oldsettingtext) eq 'HASH' &&
3063: ref($newsetting) eq 'HASH' &&
3064: ref($newsettingtext) eq 'HASH');
3065: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3066: 'ui' => 'User Information',
1.334 raeburn 3067: 'uic' => 'User Information Changed',
3068: 'firstname' => 'First Name',
3069: 'middlename' => 'Middle Name',
3070: 'lastname' => 'Last Name',
3071: 'generation' => 'Generation',
3072: 'id' => 'Student/Employee ID',
3073: 'permanentemail' => 'Permanent e-mail address',
3074: 'quota' => 'Disk space allocated to portfolio files',
3075: 'blog' => 'Blog Availability',
1.361 raeburn 3076: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3077: 'aboutme' => 'Personal Information Page Availability',
3078: 'portfolio' => 'Portfolio Availability',
3079: 'official' => 'Can Request Official Courses',
3080: 'unofficial' => 'Can Request Unofficial Courses',
3081: 'community' => 'Can Request Communities',
1.362 raeburn 3082: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3083: 'inststatus' => "Affiliation",
3084: 'prvs' => 'Previous Value:',
3085: 'chto' => 'Changed To:'
3086: );
3087: if ($changed) {
1.372 raeburn 3088: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3089: &Apache::loncommon::start_data_table().
3090: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3091: $r->print("<th> </th>\n");
1.367 golterma 3092: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3093: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3094: $r->print(&Apache::loncommon::end_data_table_header_row());
3095: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3096:
3097:
1.334 raeburn 3098: foreach my $item (@userinfo) {
3099: my $value = $env{'form.c'.$item};
1.367 golterma 3100: #show changes only:
3101: unless($value eq $userenv->{$item}){
3102: $r->print(&Apache::loncommon::start_data_table_row());
3103:
3104: $r->print("<td>$lt{$item}</td>\n");
3105: $r->print('<td>'.$userenv->{$item}.' </td>');
3106: $r->print("<td>$value </td>\n");
3107:
3108: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3109: }
3110: }
3111: foreach my $entry (@{$order}) {
1.367 golterma 3112: if ($canshow->{$entry} && ($newsetting->{$entry} ne $newsetting->{$entry})) {
3113: $r->print(&Apache::loncommon::start_data_table_row());
1.334 raeburn 3114: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom')) {
3115: foreach my $item (@{$requestcourses}) {
1.367 golterma 3116: $r->print("<td>$lt{$item}</td>\n");
3117: $r->print("<td>$oldsetting->{$item} $oldsettingtext->{$item}</td>\n");
1.334 raeburn 3118: my $value = $newsetting->{$item}.' '.$newsettingtext->{$item};
3119: if ($changedhash->{$item}) {
3120: $value = '<span class="LC_cusr_emph">'.$value.'</span>';
3121: }
3122: $r->print("<td>$value </td>\n");
3123: }
3124: } elsif ($entry eq 'tools') {
3125: foreach my $item (@{$usertools}) {
1.367 golterma 3126: $r->print("<td>$lt{$item}</td>\n");
3127: $r->print("<td>$oldsetting->{$item} $oldsettingtext->{$item}</td>\n");
1.334 raeburn 3128: my $value = $newsetting->{$item}.' '.$newsettingtext->{$item};
3129: if ($changedhash->{$item}) {
3130: $value = '<span class="LC_cusr_emph">'.$value.'</span>';
3131: }
3132: $r->print("<td>$value </td>\n");
3133: }
3134: } else {
1.367 golterma 3135: $r->print("<td>$lt{$entry}</td>\n");
3136: $r->print("<td>$oldsetting->{$entry} $oldsettingtext->{$entry} </td>\n");
1.334 raeburn 3137: my $value = $newsetting->{$entry}.' '.$newsettingtext->{$entry};
3138: if ($changedhash->{$entry}) {
3139: $value = '<span class="LC_cusr_emph">'.$value.'</span>';
3140: }
3141: $r->print("<td>$value </td>\n");
3142: }
1.367 golterma 3143: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3144: }
3145: }
1.367 golterma 3146: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3147: } else {
3148: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3149: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3150: }
3151: return;
3152: }
3153:
1.275 raeburn 3154: sub tool_changes {
3155: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3156: $changed,$newaccess,$newaccesstext) = @_;
3157: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3158: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3159: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3160: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3161: return;
3162: }
1.300 raeburn 3163: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3164: my @options = ('approval','validate','autolimit');
1.306 raeburn 3165: my $optregex = join('|',@options);
3166: my %reqdisplay = &courserequest_display();
1.300 raeburn 3167: my $cdom = $env{'request.role.domain'};
3168: foreach my $tool (@{$usertools}) {
1.314 raeburn 3169: $oldaccesstext->{$tool} = &mt('No');
3170: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3171: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.314 raeburn 3172: my $newop;
3173: if ($env{'form.'.$context.'_'.$tool}) {
3174: $newop = $env{'form.'.$context.'_'.$tool};
3175: if ($newop eq 'autolimit') {
3176: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3177: $limit =~ s/\D+//g;
3178: $newop .= '='.$limit;
3179: }
3180: }
1.300 raeburn 3181: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3182: if ($newop) {
3183: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3184: $changeHash,$context);
3185: if ($changed->{$tool}) {
1.314 raeburn 3186: $newaccesstext->{$tool} = &mt('Yes');
1.300 raeburn 3187: } else {
3188: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3189: }
3190: }
3191: } else {
3192: my @curr = split(',',$userenv->{$context.'.'.$tool});
3193: my @new;
3194: my $changedoms;
1.314 raeburn 3195: foreach my $req (@curr) {
3196: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3197: $oldaccesstext->{$tool} = &mt('Yes');
3198: my $oldop = $1;
3199: if ($oldop ne $newop) {
3200: $changedoms = 1;
3201: foreach my $item (@curr) {
3202: my ($reqdom,$option) = split(':',$item);
3203: unless ($reqdom eq $cdom) {
3204: push(@new,$item);
3205: }
3206: }
3207: if ($newop) {
3208: push(@new,$cdom.':'.$newop);
1.300 raeburn 3209: }
1.314 raeburn 3210: @new = sort(@new);
1.300 raeburn 3211: }
1.314 raeburn 3212: last;
1.300 raeburn 3213: }
1.314 raeburn 3214: }
3215: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3216: $changedoms = 1;
1.306 raeburn 3217: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3218: }
3219: if ($changedoms) {
1.314 raeburn 3220: my $newdomstr;
1.300 raeburn 3221: if (@new) {
3222: $newdomstr = join(',',@new);
3223: }
3224: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3225: $context);
3226: if ($changed->{$tool}) {
3227: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3228: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3229: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3230: $limit =~ s/\D+//g;
3231: if ($limit) {
3232: $newaccesstext->{$tool} = &mt('Yes, up to limit of [quant,_1,request] per user.',$limit);
3233: } else {
1.306 raeburn 3234: $newaccesstext->{$tool} = &mt('Yes, processed automatically');
3235: }
1.314 raeburn 3236: } else {
1.306 raeburn 3237: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3238: }
1.300 raeburn 3239: } else {
1.306 raeburn 3240: $newaccesstext->{$tool} = &mt('No');
1.300 raeburn 3241: }
3242: }
3243: }
3244: }
3245: }
3246: return;
3247: }
1.275 raeburn 3248: foreach my $tool (@{$usertools}) {
1.362 raeburn 3249: my ($newval,$envkey);
3250: $envkey = $context.'.'.$tool;
1.306 raeburn 3251: if ($context eq 'requestcourses') {
3252: $newval = $env{'form.crsreq_'.$tool};
3253: if ($newval eq 'autolimit') {
3254: $newval .= '='.$env{'form.crsreq_'.$tool.'_limit'};
3255: }
1.362 raeburn 3256: } elsif ($context eq 'requestauthor') {
3257: $newval = $env{'form.'.$context};
3258: $envkey = $context;
1.314 raeburn 3259: } else {
1.306 raeburn 3260: $newval = $env{'form.'.$context.'_'.$tool};
3261: }
1.362 raeburn 3262: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3263: $oldaccess->{$tool} = &mt('custom');
1.362 raeburn 3264: if ($userenv->{$envkey}) {
1.275 raeburn 3265: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3266: } else {
3267: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3268: }
1.362 raeburn 3269: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3270: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3271: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3272: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3273: $context);
1.275 raeburn 3274: if ($changed->{$tool}) {
3275: $newaccess->{$tool} = &mt('custom');
1.306 raeburn 3276: if ($newval) {
1.275 raeburn 3277: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3278: } else {
3279: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3280: }
3281: } else {
3282: $newaccess->{$tool} = $oldaccess->{$tool};
3283: if ($userenv->{$context.'.'.$tool}) {
3284: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3285: } else {
3286: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3287: }
3288: }
3289: } else {
3290: $newaccess->{$tool} = $oldaccess->{$tool};
3291: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3292: }
3293: } else {
3294: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3295: if ($changed->{$tool}) {
3296: $newaccess->{$tool} = &mt('default');
3297: } else {
3298: $newaccess->{$tool} = $oldaccess->{$tool};
3299: if ($userenv->{$context.'.'.$tool}) {
1.300 raeburn 3300: $newaccesstext->{$tool} = &mt("availability set to 'on'");
1.275 raeburn 3301: } else {
1.300 raeburn 3302: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.275 raeburn 3303: }
3304: }
3305: }
3306: } else {
3307: $oldaccess->{$tool} = &mt('default');
3308: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3309: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3310: $context);
1.275 raeburn 3311: if ($changed->{$tool}) {
3312: $newaccess->{$tool} = &mt('custom');
1.306 raeburn 3313: if ($newval) {
1.275 raeburn 3314: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3315: } else {
3316: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3317: }
3318: } else {
3319: $newaccess->{$tool} = $oldaccess->{$tool};
3320: }
3321: } else {
3322: $newaccess->{$tool} = $oldaccess->{$tool};
3323: }
3324: }
3325: }
3326: return;
3327: }
3328:
1.220 raeburn 3329: sub update_roles {
1.239 raeburn 3330: my ($r,$context) = @_;
1.4 www 3331: my $now=time;
1.225 raeburn 3332: my @rolechanges;
1.220 raeburn 3333: my %disallowed;
1.73 sakharuk 3334: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 3335: foreach my $key (keys (%env)) {
3336: next if (! $env{$key});
1.190 raeburn 3337: next if ($key eq 'form.action');
1.27 matthew 3338: # Revoke roles
1.135 raeburn 3339: if ($key=~/^form\.rev/) {
3340: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3341: # Revoke standard role
1.170 albertel 3342: my ($scope,$role) = ($1,$2);
3343: my $result =
3344: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3345: $env{'form.ccuname'},
1.239 raeburn 3346: $scope,$role,'','',$context);
1.367 golterma 3347: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3348: &mt('Revoking [_1] in [_2]',
3349: &Apache::lonnet::plaintext($role),
1.372 raeburn 3350: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3351: $result ne "ok").'<br />');
3352: if ($result ne "ok") {
3353: $r->print(&mt('Error: [_1]',$result).'<br />');
3354: }
1.170 albertel 3355: if ($role eq 'st') {
1.202 raeburn 3356: my $result =
1.198 raeburn 3357: &Apache::lonuserutils::classlist_drop($scope,
3358: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3359: $now);
1.367 golterma 3360: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3361: }
1.225 raeburn 3362: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3363: push(@rolechanges,$role);
3364: }
1.196 raeburn 3365: }
1.195 raeburn 3366: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3367: # Revoke custom role
1.369 bisitz 3368: my $result = &Apache::lonnet::revokecustomrole(
3369: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3370: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3371: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3372: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3373: $result ne 'ok').'<br />');
3374: if ($result ne "ok") {
3375: $r->print(&mt('Error: [_1]',$result).'<br />');
3376: }
1.225 raeburn 3377: if (!grep(/^cr$/,@rolechanges)) {
3378: push(@rolechanges,'cr');
3379: }
1.64 www 3380: }
1.135 raeburn 3381: } elsif ($key=~/^form\.del/) {
3382: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3383: # Delete standard role
1.170 albertel 3384: my ($scope,$role) = ($1,$2);
3385: my $result =
3386: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3387: $env{'form.ccuname'},
1.239 raeburn 3388: $scope,$role,$now,0,1,'',
3389: $context);
1.367 golterma 3390: $r->print(&Apache::lonhtmlcommon::confirm_success(
3391: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3392: &Apache::lonnet::plaintext($role),
1.372 raeburn 3393: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3394: $result ne 'ok').'<br />');
3395: if ($result ne "ok") {
3396: $r->print(&mt('Error: [_1]',$result).'<br />');
3397: }
1.367 golterma 3398:
1.170 albertel 3399: if ($role eq 'st') {
1.202 raeburn 3400: my $result =
1.198 raeburn 3401: &Apache::lonuserutils::classlist_drop($scope,
3402: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3403: $now);
1.369 bisitz 3404: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3405: }
1.225 raeburn 3406: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3407: push(@rolechanges,$role);
3408: }
1.116 raeburn 3409: }
1.139 albertel 3410: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3411: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3412: # Delete custom role
1.369 bisitz 3413: my $result =
3414: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3415: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3416: 0,1,$context);
3417: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3418: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3419: $result ne "ok").'<br />');
3420: if ($result ne "ok") {
3421: $r->print(&mt('Error: [_1]',$result).'<br />');
3422: }
1.367 golterma 3423:
1.225 raeburn 3424: if (!grep(/^cr$/,@rolechanges)) {
3425: push(@rolechanges,'cr');
3426: }
1.116 raeburn 3427: }
1.135 raeburn 3428: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3429: my $udom = $env{'form.ccdomain'};
3430: my $uname = $env{'form.ccuname'};
1.116 raeburn 3431: # Re-enable standard role
1.135 raeburn 3432: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3433: my $url = $1;
3434: my $role = $2;
3435: my $logmsg;
3436: my $output;
3437: if ($role eq 'st') {
1.141 albertel 3438: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 ! raeburn 3439: my ($cdom,$cnum,$csec) = ($1,$2,$3);
! 3440: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context);
1.220 raeburn 3441: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3442: if ($result eq 'refused' && $logmsg) {
3443: $output = $logmsg;
3444: } else {
1.369 bisitz 3445: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3446: }
1.89 raeburn 3447: } else {
1.372 raeburn 3448: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3449: &Apache::lonnet::plaintext($role),
3450: &Apache::loncommon::show_role_extent($url,$context,'st'),
3451: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3452: }
3453: }
3454: } else {
1.101 albertel 3455: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3456: $env{'form.ccuname'},$url,$role,0,$now,'','',
3457: $context);
1.367 golterma 3458: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3459: &Apache::lonnet::plaintext($role),
3460: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3461: if ($result ne "ok") {
3462: $output .= &mt('Error: [_1]',$result).'<br />';
3463: }
3464: }
1.89 raeburn 3465: $r->print($output);
1.225 raeburn 3466: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3467: push(@rolechanges,$role);
3468: }
1.113 raeburn 3469: }
1.116 raeburn 3470: # Re-enable custom role
1.139 albertel 3471: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3472: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3473: my $result = &Apache::lonnet::assigncustomrole(
3474: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3475: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3476: $r->print(&Apache::lonhtmlcommon::confirm_success(
3477: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 3478: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3479: $result ne "ok").'<br />');
3480: if ($result ne "ok") {
3481: $r->print(&mt('Error: [_1]',$result).'<br />');
3482: }
1.225 raeburn 3483: if (!grep(/^cr$/,@rolechanges)) {
3484: push(@rolechanges,'cr');
3485: }
1.116 raeburn 3486: }
1.135 raeburn 3487: } elsif ($key=~/^form\.act/) {
1.101 albertel 3488: my $udom = $env{'form.ccdomain'};
3489: my $uname = $env{'form.ccuname'};
1.141 albertel 3490: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3491: # Activate a custom role
1.83 albertel 3492: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3493: my $url='/'.$one.'/'.$two;
3494: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3495:
1.101 albertel 3496: my $start = ( $env{'form.start_'.$full} ?
3497: $env{'form.start_'.$full} :
1.88 raeburn 3498: $now );
1.101 albertel 3499: my $end = ( $env{'form.end_'.$full} ?
3500: $env{'form.end_'.$full} :
1.88 raeburn 3501: 0 );
3502:
3503: # split multiple sections
3504: my %sections = ();
1.101 albertel 3505: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3506: if ($num_sections == 0) {
1.240 raeburn 3507: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3508: } else {
1.114 albertel 3509: my %curr_groups =
1.117 raeburn 3510: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 3511: foreach my $sec (sort {$a cmp $b} keys %sections) {
3512: if (($sec eq 'none') || ($sec eq 'all') ||
3513: exists($curr_groups{$sec})) {
3514: $disallowed{$sec} = $url;
3515: next;
3516: }
3517: my $securl = $url.'/'.$sec;
1.240 raeburn 3518: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3519: }
3520: }
1.225 raeburn 3521: if (!grep(/^cr$/,@rolechanges)) {
3522: push(@rolechanges,'cr');
3523: }
1.142 raeburn 3524: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 3525: # Activate roles for sections with 3 id numbers
3526: # set start, end times, and the url for the class
1.83 albertel 3527: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 3528: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
3529: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3530: $now );
1.101 albertel 3531: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
3532: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3533: 0 );
1.83 albertel 3534: my $url='/'.$one.'/'.$two;
1.88 raeburn 3535: my $type = 'three';
3536: # split multiple sections
3537: my %sections = ();
1.101 albertel 3538: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 3539: if ($num_sections == 0) {
1.240 raeburn 3540: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 3541: } else {
1.114 albertel 3542: my %curr_groups =
1.117 raeburn 3543: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 3544: my $emptysec = 0;
3545: foreach my $sec (sort {$a cmp $b} keys %sections) {
3546: $sec =~ s/\W//g;
1.113 raeburn 3547: if ($sec ne '') {
3548: if (($sec eq 'none') || ($sec eq 'all') ||
3549: exists($curr_groups{$sec})) {
3550: $disallowed{$sec} = $url;
3551: next;
3552: }
1.88 raeburn 3553: my $securl = $url.'/'.$sec;
1.240 raeburn 3554: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context));
1.88 raeburn 3555: } else {
3556: $emptysec = 1;
3557: }
3558: }
3559: if ($emptysec) {
1.240 raeburn 3560: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 3561: }
1.225 raeburn 3562: }
3563: if (!grep(/^\Q$three\E$/,@rolechanges)) {
3564: push(@rolechanges,$three);
3565: }
1.135 raeburn 3566: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 3567: # Activate roles for sections with two id numbers
3568: # set start, end times, and the url for the class
1.101 albertel 3569: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
3570: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 3571: $now );
1.101 albertel 3572: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
3573: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 3574: 0 );
1.225 raeburn 3575: my $one = $1;
3576: my $two = $2;
3577: my $url='/'.$one.'/';
1.88 raeburn 3578: # split multiple sections
3579: my %sections = ();
1.225 raeburn 3580: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 3581: if ($num_sections == 0) {
1.240 raeburn 3582: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3583: } else {
3584: my $emptysec = 0;
3585: foreach my $sec (sort {$a cmp $b} keys %sections) {
3586: if ($sec ne '') {
3587: my $securl = $url.'/'.$sec;
1.240 raeburn 3588: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 3589: } else {
3590: $emptysec = 1;
3591: }
3592: }
3593: if ($emptysec) {
1.240 raeburn 3594: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3595: }
3596: }
1.225 raeburn 3597: if (!grep(/^\Q$two\E$/,@rolechanges)) {
3598: push(@rolechanges,$two);
3599: }
1.64 www 3600: } else {
1.190 raeburn 3601: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 3602: }
1.113 raeburn 3603: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 3604: $r->print('<p class="LC_warning">');
1.113 raeburn 3605: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 3606: $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 3607: } else {
1.274 bisitz 3608: $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 3609: }
1.274 bisitz 3610: $r->print('</p><p>'
3611: .&mt('Please [_1]go back[_2] and choose a different section name.'
3612: ,'<a href="javascript:history.go(-1)'
3613: ,'</a>')
3614: .'</p><br />'
3615: );
1.113 raeburn 3616: }
3617: }
1.101 albertel 3618: } # End of foreach (keys(%env))
1.75 www 3619: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 3620: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 3621: if (@rolechanges == 0) {
1.372 raeburn 3622: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 3623: }
1.225 raeburn 3624: return @rolechanges;
1.220 raeburn 3625: }
3626:
3627: sub enroll_single_student {
1.318 raeburn 3628: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype) = @_;
3629: $r->print('<h3>');
3630: if ($crstype eq 'Community') {
3631: $r->print(&mt('Enrolling Member'));
3632: } else {
3633: $r->print(&mt('Enrolling Student'));
3634: }
3635: $r->print('</h3>');
1.220 raeburn 3636:
3637: # Remove non alphanumeric values from section
3638: $env{'form.sections'}=~s/\W//g;
3639:
3640: # Clean out any old student roles the user has in this class.
3641: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
3642: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
3643: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
3644: my $enroll_result =
3645: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
3646: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
3647: $env{'form.cmiddlename'},$env{'form.clastname'},
3648: $env{'form.generation'},$env{'form.sections'},$enddate,
1.239 raeburn 3649: $startdate,'manual',undef,$env{'request.course.id'},'',$context);
1.220 raeburn 3650: if ($enroll_result =~ /^ok/) {
3651: $r->print(&mt('<b>[_1]</b> enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'}));
3652: if ($env{'form.sections'} ne '') {
3653: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
3654: }
3655: my ($showstart,$showend);
3656: if ($startdate <= $now) {
3657: $showstart = &mt('Access starts immediately');
3658: } else {
3659: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
3660: }
3661: if ($enddate == 0) {
3662: $showend = &mt('ends: no ending date');
3663: } else {
3664: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
3665: }
3666: $r->print('.<br />'.$showstart.'; '.$showend);
3667: if ($startdate <= $now && !$newuser) {
1.318 raeburn 3668: $r->print('<p> ');
3669: if ($crstype eq 'Community') {
3670: $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.'));
3671: } else {
3672: $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.'));
3673: }
3674: $r->print('</p>');
1.220 raeburn 3675: }
3676: } else {
3677: $r->print(&mt('unable to enroll').": ".$enroll_result);
3678: }
3679: return;
1.188 raeburn 3680: }
3681:
1.204 raeburn 3682: sub get_defaultquota_text {
3683: my ($settingstatus) = @_;
3684: my $defquotatext;
3685: if ($settingstatus eq '') {
3686: $defquotatext = &mt('(default)');
3687: } else {
3688: my ($usertypes,$order) =
3689: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
3690: if ($usertypes->{$settingstatus} eq '') {
3691: $defquotatext = &mt('(default)');
3692: } else {
3693: $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
3694: }
3695: }
3696: return $defquotatext;
3697: }
3698:
1.188 raeburn 3699: sub update_result_form {
3700: my ($uhome) = @_;
3701: my $outcome =
1.367 golterma 3702: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 3703: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 3704: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3705: }
1.207 raeburn 3706: if ($env{'form.origname'} ne '') {
3707: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
3708: }
1.160 raeburn 3709: foreach my $item ('sortby','seluname','seludom') {
3710: if (exists($env{'form.'.$item})) {
1.188 raeburn 3711: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3712: }
3713: }
1.188 raeburn 3714: if ($uhome eq 'no_host') {
3715: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
3716: }
3717: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
3718: '<input type ="hidden" name="currstate" value="" />'."\n".
1.220 raeburn 3719: '<input type ="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 3720: '</form>';
3721: return $outcome;
1.4 www 3722: }
3723:
1.149 raeburn 3724: sub quota_admin {
3725: my ($setquota,$changeHash) = @_;
3726: my $quotachanged;
3727: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
3728: # Current user has quota modification privileges
1.267 raeburn 3729: if (ref($changeHash) eq 'HASH') {
3730: $quotachanged = 1;
3731: $changeHash->{'portfolioquota'} = $setquota;
3732: }
1.149 raeburn 3733: }
3734: return $quotachanged;
3735: }
3736:
1.267 raeburn 3737: sub tool_admin {
1.275 raeburn 3738: my ($tool,$settool,$changeHash,$context) = @_;
3739: my $canchange = 0;
1.279 raeburn 3740: if ($context eq 'requestcourses') {
1.275 raeburn 3741: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
3742: $canchange = 1;
3743: }
1.300 raeburn 3744: } elsif ($context eq 'reqcrsotherdom') {
3745: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
3746: $canchange = 1;
3747: }
1.362 raeburn 3748: } elsif ($context eq 'requestauthor') {
3749: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
3750: $canchange = 1;
3751: }
1.275 raeburn 3752: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
3753: # Current user has quota modification privileges
3754: $canchange = 1;
3755: }
1.267 raeburn 3756: my $toolchanged;
1.275 raeburn 3757: if ($canchange) {
1.267 raeburn 3758: if (ref($changeHash) eq 'HASH') {
3759: $toolchanged = 1;
1.362 raeburn 3760: if ($tool eq 'requestauthor') {
3761: $changeHash->{$context} = $settool;
3762: } else {
3763: $changeHash->{$context.'.'.$tool} = $settool;
3764: }
1.267 raeburn 3765: }
3766: }
3767: return $toolchanged;
3768: }
3769:
1.88 raeburn 3770: sub build_roles {
1.89 raeburn 3771: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 3772: my $num_sections = 0;
3773: if ($sectionstr=~ /,/) {
3774: my @secnums = split/,/,$sectionstr;
1.89 raeburn 3775: if ($role eq 'st') {
3776: $secnums[0] =~ s/\W//g;
3777: $$sections{$secnums[0]} = 1;
3778: $num_sections = 1;
3779: } else {
3780: foreach my $sec (@secnums) {
3781: $sec =~ ~s/\W//g;
1.150 banghart 3782: if (!($sec eq "")) {
1.89 raeburn 3783: if (exists($$sections{$sec})) {
3784: $$sections{$sec} ++;
3785: } else {
3786: $$sections{$sec} = 1;
3787: $num_sections ++;
3788: }
1.88 raeburn 3789: }
3790: }
3791: }
3792: } else {
3793: $sectionstr=~s/\W//g;
3794: unless ($sectionstr eq '') {
3795: $$sections{$sectionstr} = 1;
3796: $num_sections ++;
3797: }
3798: }
1.129 albertel 3799:
1.88 raeburn 3800: return $num_sections;
3801: }
3802:
1.58 www 3803: # ========================================================== Custom Role Editor
3804:
3805: sub custom_role_editor {
1.351 raeburn 3806: my ($r,$brcrum) = @_;
1.324 raeburn 3807: my $action = $env{'form.customroleaction'};
3808: my $rolename;
3809: if ($action eq 'new') {
3810: $rolename=$env{'form.newrolename'};
3811: } else {
3812: $rolename=$env{'form.rolename'};
1.59 www 3813: }
3814:
1.324 raeburn 3815: my ($crstype,$context);
3816: if ($env{'request.course.id'}) {
3817: $crstype = &Apache::loncommon::course_type();
3818: $context = 'course';
3819: } else {
3820: $context = 'domain';
3821: $crstype = $env{'form.templatecrstype'};
3822: }
1.351 raeburn 3823:
3824: $rolename=~s/[^A-Za-z0-9]//gs;
3825: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
3826: &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
3827: return;
3828: }
3829:
1.153 banghart 3830: # ------------------------------------------------------- What can be assigned?
3831: my %full=();
3832: my %courselevel=();
3833: my %courselevelcurrent=();
1.61 www 3834: my $syspriv='';
3835: my $dompriv='';
3836: my $coursepriv='';
1.153 banghart 3837: my $body_top;
1.59 www 3838: my ($rdummy,$roledef)=
3839: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 3840: # ------------------------------------------------------- Does this role exist?
1.153 banghart 3841: $body_top .= '<h2>';
1.59 www 3842: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 3843: $body_top .= &mt('Existing Role').' "';
1.61 www 3844: # ------------------------------------------------- Get current role privileges
3845: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.324 raeburn 3846: if ($crstype eq 'Community') {
3847: $syspriv =~ s/bre\&S//;
3848: }
1.59 www 3849: } else {
1.153 banghart 3850: $body_top .= &mt('New Role').' "';
1.59 www 3851: $roledef='';
3852: }
1.153 banghart 3853: $body_top .= $rolename.'"</h2>';
1.135 raeburn 3854: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
3855: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3856: if (!$restrict) { $restrict='F'; }
1.60 www 3857: $courselevel{$priv}=$restrict;
1.61 www 3858: if ($coursepriv=~/\:$priv/) {
3859: $courselevelcurrent{$priv}=1;
3860: }
1.60 www 3861: $full{$priv}=1;
3862: }
3863: my %domainlevel=();
1.61 www 3864: my %domainlevelcurrent=();
1.135 raeburn 3865: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
3866: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3867: if (!$restrict) { $restrict='F'; }
1.60 www 3868: $domainlevel{$priv}=$restrict;
1.61 www 3869: if ($dompriv=~/\:$priv/) {
3870: $domainlevelcurrent{$priv}=1;
3871: }
1.60 www 3872: $full{$priv}=1;
3873: }
1.61 www 3874: my %systemlevel=();
3875: my %systemlevelcurrent=();
1.135 raeburn 3876: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
3877: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3878: if (!$restrict) { $restrict='F'; }
1.61 www 3879: $systemlevel{$priv}=$restrict;
3880: if ($syspriv=~/\:$priv/) {
3881: $systemlevelcurrent{$priv}=1;
3882: }
3883: $full{$priv}=1;
3884: }
1.160 raeburn 3885: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 3886: my $button_code = "\n";
1.153 banghart 3887: my $head_script = "\n";
1.301 bisitz 3888: $head_script .= '<script type="text/javascript">'."\n"
3889: .'// <![CDATA['."\n";
1.324 raeburn 3890: my @template_roles = ("in","ta","ep");
3891: if ($context eq 'domain') {
3892: push(@template_roles,"ad");
1.318 raeburn 3893: }
1.324 raeburn 3894: push(@template_roles,"st");
1.318 raeburn 3895: if ($crstype eq 'Community') {
3896: unshift(@template_roles,'co');
3897: } else {
3898: unshift(@template_roles,'cc');
3899: }
1.154 banghart 3900: foreach my $role (@template_roles) {
1.324 raeburn 3901: $head_script .= &make_script_template($role,$crstype);
1.318 raeburn 3902: $button_code .= &make_button_code($role,$crstype).' ';
1.154 banghart 3903: }
1.324 raeburn 3904: my $context_code;
3905: if ($context eq 'domain') {
3906: my $checkedCommunity = '';
3907: my $checkedCourse = ' checked="checked"';
3908: if ($env{'form.templatecrstype'} eq 'Community') {
3909: $checkedCommunity = $checkedCourse;
3910: $checkedCourse = '';
3911: }
3912: $context_code = '<label>'.
3913: '<input type="radio" name="templatecrstype" value="Course"'.$checkedCourse.' onclick="this.form.submit();">'.
3914: &mt('Course').
3915: '</label>'.(' ' x2).
3916: '<label>'.
3917: '<input type="radio" name="templatecrstype" value="Community"'.$checkedCommunity.' onclick="this.form.submit();">'.
3918: &mt('Community').
3919: '</label>'.
3920: '</fieldset>'.
3921: '<input type="hidden" name="customroleaction" value="'.
3922: $action.'" />';
3923: if ($env{'form.customroleaction'} eq 'new') {
3924: $context_code .= '<input type="hidden" name="newrolename" value="'.
3925: $rolename.'" />';
3926: } else {
3927: $context_code .= '<input type="hidden" name="rolename" value="'.
3928: $rolename.'" />';
3929: }
3930: $context_code .= '<input type="hidden" name="action" value="custom" />'.
3931: '<input type="hidden" name="phase" value="selected_custom_edit" />';
3932: }
3933:
1.301 bisitz 3934: $head_script .= "\n".$jsback."\n"
3935: .'// ]]>'."\n"
3936: .'</script>'."\n";
1.351 raeburn 3937: push (@{$brcrum},
3938: {href => "javascript:backPage(document.form1,'pickrole','')",
3939: text => "Pick custom role",
3940: faq => 282,bug=>'Instructor Interface',},
3941: {href => "javascript:backPage(document.form1,'','')",
3942: text => "Edit custom role",
3943: faq => 282,
3944: bug => 'Instructor Interface',
3945: help => 'Course_Editing_Custom_Roles'}
3946: );
3947: my $args = { bread_crumbs => $brcrum,
3948: bread_crumbs_component => 'User Management'};
3949:
3950: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
3951: $head_script,$args).
3952: $body_top);
1.73 sakharuk 3953: my %lt=&Apache::lonlocal::texthash(
3954: 'prv' => "Privilege",
1.131 raeburn 3955: 'crl' => "Course Level",
1.73 sakharuk 3956: 'dml' => "Domain Level",
1.150 banghart 3957: 'ssl' => "System Level");
1.264 bisitz 3958:
1.324 raeburn 3959: $r->print('<div class="LC_left_float">'
1.264 bisitz 3960: .'<form action=""><fieldset>'
3961: .'<legend>'.&mt('Select a Template').'</legend>'
3962: .$button_code
1.324 raeburn 3963: .'</fieldset></form></div>');
3964: if ($context_code) {
3965: $r->print('<div class="LC_left_float">'
3966: .'<form action="/adm/createuser" method="post"><fieldset>'
3967: .'<legend>'.&mt('Context').'</legend>'
3968: .$context_code
3969: .'</form>'
3970: .'</div>'
3971: );
3972: }
3973: $r->print('<br clear="all" />');
1.264 bisitz 3974:
1.61 www 3975: $r->print(<<ENDCCF);
1.160 raeburn 3976: <form name="form1" method="post">
1.61 www 3977: <input type="hidden" name="phase" value="set_custom_roles" />
3978: <input type="hidden" name="rolename" value="$rolename" />
3979: ENDCCF
1.135 raeburn 3980: $r->print(&Apache::loncommon::start_data_table().
3981: &Apache::loncommon::start_data_table_header_row().
3982: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
3983: '</th><th>'.$lt{'ssl'}.'</th>'.
3984: &Apache::loncommon::end_data_table_header_row());
1.324 raeburn 3985: foreach my $priv (sort(keys(%full))) {
1.318 raeburn 3986: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
1.135 raeburn 3987: $r->print(&Apache::loncommon::start_data_table_row().
3988: '<td>'.$privtext.'</td><td>'.
1.288 bisitz 3989: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c"'.
3990: ($courselevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.61 www 3991: '</td><td>'.
1.288 bisitz 3992: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.
3993: ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.324 raeburn 3994: '</td><td>');
3995: if ($priv eq 'bre' && $crstype eq 'Community') {
3996: $r->print(' ');
3997: } else {
3998: $r->print($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
3999: ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':' ');
4000: }
4001: $r->print('</td>'.
4002: &Apache::loncommon::end_data_table_row());
1.60 www 4003: }
1.135 raeburn 4004: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4005: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4006: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 4007: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4008: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4009: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4010: }
1.153 banghart 4011: # --------------------------------------------------------
4012: sub make_script_template {
1.324 raeburn 4013: my ($role,$crstype) = @_;
1.153 banghart 4014: my %full_c=();
4015: my %full_d=();
4016: my %full_s=();
4017: my $return_script;
4018: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4019: my ($priv,$restrict)=split(/\&/,$item);
4020: $full_c{$priv}=1;
4021: }
4022: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4023: my ($priv,$restrict)=split(/\&/,$item);
4024: $full_d{$priv}=1;
4025: }
1.154 banghart 4026: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.324 raeburn 4027: next if (($crstype eq 'Community') && ($item eq 'bre&S'));
1.153 banghart 4028: my ($priv,$restrict)=split(/\&/,$item);
4029: $full_s{$priv}=1;
4030: }
4031: $return_script .= 'function set_'.$role.'() {'."\n";
4032: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
4033: my %role_c;
1.155 banghart 4034: foreach my $priv (@temp) {
1.153 banghart 4035: my ($priv_item, $dummy) = split(/\&/,$priv);
4036: $role_c{$priv_item} = 1;
4037: }
1.269 raeburn 4038: my %role_d;
4039: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
4040: foreach my $priv(@temp) {
4041: my ($priv_item, $dummy) = split(/\&/,$priv);
4042: $role_d{$priv_item} = 1;
4043: }
4044: my %role_s;
4045: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
4046: foreach my $priv(@temp) {
4047: my ($priv_item, $dummy) = split(/\&/,$priv);
4048: $role_s{$priv_item} = 1;
4049: }
1.153 banghart 4050: foreach my $priv_item (keys(%full_c)) {
4051: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4052: if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
4053: (exists($role_s{$priv}))) {
1.153 banghart 4054: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
4055: } else {
4056: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
4057: }
4058: }
1.154 banghart 4059: foreach my $priv_item (keys(%full_d)) {
4060: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 4061: if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
1.154 banghart 4062: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
4063: } else {
4064: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
4065: }
4066: }
4067: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 4068: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 4069: if (exists($role_s{$priv})) {
4070: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
4071: } else {
4072: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
4073: }
1.153 banghart 4074: }
4075: $return_script .= '}'."\n";
1.154 banghart 4076: return ($return_script);
4077: }
4078: # ----------------------------------------------------------
4079: sub make_button_code {
1.318 raeburn 4080: my ($role,$crstype) = @_;
4081: my $label = &Apache::lonnet::plaintext($role,$crstype);
1.301 bisitz 4082: my $button_code = '<input type="button" onclick="set_'.$role.'()" value="'.$label.'" />';
1.154 banghart 4083: return ($button_code);
1.153 banghart 4084: }
1.61 www 4085: # ---------------------------------------------------------- Call to definerole
4086: sub set_custom_role {
1.351 raeburn 4087: my ($r,$context,$brcrum) = @_;
1.101 albertel 4088: my $rolename=$env{'form.rolename'};
1.63 www 4089: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4090: if (!$rolename) {
1.351 raeburn 4091: &custom_role_editor($r,$brcrum);
1.61 www 4092: return;
4093: }
1.160 raeburn 4094: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4095: my $jscript = '<script type="text/javascript">'
4096: .'// <![CDATA['."\n"
4097: .$jsback."\n"
4098: .'// ]]>'."\n"
4099: .'</script>'."\n";
1.352 raeburn 4100: push(@{$brcrum},
4101: {href => "javascript:backPage(document.customresult,'pickrole','')",
4102: text => "Pick custom role",
4103: faq => 282,
4104: bug => 'Instructor Interface',},
4105: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4106: text => "Edit custom role",
4107: faq => 282,
4108: bug => 'Instructor Interface',},
4109: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4110: text => "Result",
4111: faq => 282,
4112: bug => 'Instructor Interface',
4113: help => 'Course_Editing_Custom_Roles'},
4114: );
4115: my $args = { bread_crumbs => $brcrum,
1.351 raeburn 4116: bread_crumbs_component => 'User Management'};
4117: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4118:
1.61 www 4119: my ($rdummy,$roledef)=
1.110 albertel 4120: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4121:
1.61 www 4122: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4123: $r->print('<h3>');
1.61 www 4124: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4125: $r->print(&mt('Existing Role').' "');
1.61 www 4126: } else {
1.73 sakharuk 4127: $r->print(&mt('New Role').' "');
1.61 www 4128: $roledef='';
4129: }
1.188 raeburn 4130: $r->print($rolename.'"</h3>');
1.61 www 4131: # ------------------------------------------------------- What can be assigned?
4132: my $sysrole='';
4133: my $domrole='';
4134: my $courole='';
4135:
1.135 raeburn 4136: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
4137: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4138: if (!$restrict) { $restrict=''; }
4139: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 4140: $courole.=':'.$item;
1.61 www 4141: }
4142: }
4143:
1.135 raeburn 4144: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
4145: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4146: if (!$restrict) { $restrict=''; }
4147: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 4148: $domrole.=':'.$item;
1.61 www 4149: }
4150: }
4151:
1.135 raeburn 4152: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
4153: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 4154: if (!$restrict) { $restrict=''; }
4155: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 4156: $sysrole.=':'.$item;
1.61 www 4157: }
4158: }
1.63 www 4159: $r->print('<br />Defining Role: '.
1.61 www 4160: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 4161: if ($env{'request.course.id'}) {
4162: my $url='/'.$env{'request.course.id'};
1.63 www 4163: $url=~s/\_/\//g;
1.73 sakharuk 4164: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 4165: &Apache::lonnet::assigncustomrole($env{'user.domain'},
4166: $env{'user.name'},
1.63 www 4167: $url,
1.101 albertel 4168: $env{'user.domain'},
4169: $env{'user.name'},
1.240 raeburn 4170: $rolename,undef,undef,undef,$context));
1.63 www 4171: }
1.190 raeburn 4172: $r->print('<p><a href="javascript:backPage(document.customresult,'."'pickrole'".')">'.&mt('Create or edit another custom role').'</a></p><form name="customresult" method="post">');
1.160 raeburn 4173: $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
1.58 www 4174: }
4175:
1.2 www 4176: # ================================================================ Main Handler
4177: sub handler {
4178: my $r = shift;
4179: if ($r->header_only) {
1.68 www 4180: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4181: $r->send_http_header;
4182: return OK;
4183: }
1.318 raeburn 4184: my ($context,$crstype);
1.190 raeburn 4185: if ($env{'request.course.id'}) {
4186: $context = 'course';
1.318 raeburn 4187: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4188: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4189: $context = 'author';
1.190 raeburn 4190: } else {
4191: $context = 'domain';
4192: }
4193: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4194: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
4195: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
1.190 raeburn 4196: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4197: my $args;
4198: my $brcrum = [];
4199: my $bread_crumbs_component = 'User Management';
1.202 raeburn 4200: if ($env{'form.action'} ne 'dateselect') {
1.351 raeburn 4201: $brcrum = [{href=>"/adm/createuser",
4202: text=>"User Management",
4203: 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'}
4204: ];
1.202 raeburn 4205: }
1.289 droeschl 4206: #SD Following files not added to help, because the corresponding .tex-files seem to
4207: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 4208: my ($permission,$allowed) =
1.318 raeburn 4209: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 4210: if (!$allowed) {
1.358 raeburn 4211: if ($context eq 'course') {
4212: $r->internal_redirect('/adm/viewclasslist');
4213: return OK;
4214: }
1.190 raeburn 4215: $env{'user.error.msg'}=
4216: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4217: "or view user status.";
4218: return HTTP_NOT_ACCEPTABLE;
4219: }
4220:
4221: &Apache::loncommon::content_type($r,'text/html');
4222: $r->send_http_header;
4223:
4224: # Main switch on form.action and form.state, as appropriate
4225: if (! exists($env{'form.action'})) {
1.351 raeburn 4226: $args = {bread_crumbs => $brcrum,
4227: bread_crumbs_component => $bread_crumbs_component};
4228: $r->print(&header(undef,$args));
1.318 raeburn 4229: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4230: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.351 raeburn 4231: push(@{$brcrum},
4232: { href => '/adm/createuser?action=upload&state=',
4233: text => 'Upload Users List',
4234: help => 'Course_Create_Class_List',
4235: });
4236: $bread_crumbs_component = 'Upload Users List';
4237: $args = {bread_crumbs => $brcrum,
4238: bread_crumbs_component => $bread_crumbs_component};
4239: $r->print(&header(undef,$args));
1.190 raeburn 4240: $r->print('<form name="studentform" method="post" '.
4241: 'enctype="multipart/form-data" '.
4242: ' action="/adm/createuser">'."\n");
4243: if (! exists($env{'form.state'})) {
4244: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4245: } elsif ($env{'form.state'} eq 'got_file') {
1.221 raeburn 4246: &Apache::lonuserutils::print_upload_manager_form($r,$context,
1.318 raeburn 4247: $permission,$crstype);
1.190 raeburn 4248: } elsif ($env{'form.state'} eq 'enrolling') {
4249: if ($env{'form.datatoken'}) {
1.221 raeburn 4250: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission);
1.190 raeburn 4251: }
4252: } else {
4253: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4254: }
1.213 raeburn 4255: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4256: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 4257: my $phase = $env{'form.phase'};
4258: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4259: &Apache::loncreateuser::restore_prev_selections();
4260: my $srch;
4261: foreach my $item (@search) {
4262: $srch->{$item} = $env{'form.'.$item};
4263: }
1.207 raeburn 4264: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
4265: ($phase eq 'createnewuser')) {
4266: if ($env{'form.phase'} eq 'createnewuser') {
4267: my $response;
4268: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4269: my $response =
4270: '<span class="LC_warning">'
4271: .&mt('You must specify a valid username. Only the following are allowed:'
4272: .' letters numbers - . @')
4273: .'</span>';
1.221 raeburn 4274: $env{'form.phase'} = '';
1.351 raeburn 4275: &print_username_entry_form($r,$context,$response,$srch,undef,$crstype,$brcrum);
1.207 raeburn 4276: } else {
4277: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4278: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4279: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4280: $srch,$response,$context,
1.351 raeburn 4281: $permission,$crstype,$brcrum);
1.207 raeburn 4282: }
4283: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4284: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4285: &user_search_result($context,$srch);
1.190 raeburn 4286: if ($env{'form.currstate'} eq 'modify') {
4287: $currstate = $env{'form.currstate'};
4288: }
4289: if ($currstate eq 'select') {
4290: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4291: \@search,$context,undef,$crstype,
4292: $brcrum);
1.190 raeburn 4293: } elsif ($currstate eq 'modify') {
4294: my ($ccuname,$ccdomain);
4295: if (($srch->{'srchby'} eq 'uname') &&
4296: ($srch->{'srchtype'} eq 'exact')) {
4297: $ccuname = $srch->{'srchterm'};
4298: $ccdomain= $srch->{'srchdomain'};
4299: } else {
4300: my @matchedunames = keys(%{$results});
4301: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4302: }
4303: $ccuname =&LONCAPA::clean_username($ccuname);
4304: $ccdomain=&LONCAPA::clean_domain($ccdomain);
4305: if ($env{'form.forcenewuser'}) {
4306: $response = '';
4307: }
4308: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4309: $srch,$response,$context,
1.351 raeburn 4310: $permission,$crstype,$brcrum);
1.190 raeburn 4311: } elsif ($currstate eq 'query') {
1.351 raeburn 4312: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4313: } else {
1.229 raeburn 4314: $env{'form.phase'} = '';
1.207 raeburn 4315: &print_username_entry_form($r,$context,$response,$srch,
1.351 raeburn 4316: $forcenewuser,$crstype,$brcrum);
1.190 raeburn 4317: }
4318: } elsif ($env{'form.phase'} eq 'userpicked') {
4319: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4320: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 4321: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.351 raeburn 4322: $context,$permission,$crstype,
4323: $brcrum);
1.190 raeburn 4324: }
4325: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.351 raeburn 4326: &update_user_data($r,$context,$crstype,$brcrum);
1.190 raeburn 4327: } else {
1.351 raeburn 4328: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4329: $brcrum);
1.190 raeburn 4330: }
4331: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
4332: if ($env{'form.phase'} eq 'set_custom_roles') {
1.351 raeburn 4333: &set_custom_role($r,$context,$brcrum);
1.190 raeburn 4334: } else {
1.351 raeburn 4335: &custom_role_editor($r,$brcrum);
1.190 raeburn 4336: }
1.362 raeburn 4337: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4338: ($permission->{'cusr'}) &&
4339: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4340: push(@{$brcrum},
4341: {href => '/adm/createuser?action=processauthorreq',
4342: text => 'Authoring space requests',
4343: help => 'Domain_Role_Approvals'});
4344: $bread_crumbs_component = 'Authoring requests';
4345: if ($env{'form.state'} eq 'done') {
4346: push(@{$brcrum},
4347: {href => '/adm/createuser?action=authorreqqueue',
4348: text => 'Result',
4349: help => 'Domain_Role_Approvals'});
4350: $bread_crumbs_component = 'Authoring request result';
4351: }
4352: $args = { bread_crumbs => $brcrum,
4353: bread_crumbs_component => $bread_crumbs_component};
4354: $r->print(&header(undef,$args));
4355: if (!exists($env{'form.state'})) {
4356: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4357: $env{'request.role.domain'}));
4358: } elsif ($env{'form.state'} eq 'done') {
4359: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4360: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4361: $env{'request.role.domain'}));
4362: }
1.207 raeburn 4363: } elsif (($env{'form.action'} eq 'listusers') &&
4364: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 4365: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 4366: push(@{$brcrum},
4367: {href => '/adm/createuser?action=listusers',
4368: text => "List Users"},
4369: {href => "/adm/createuser",
4370: text => "Result",
4371: help => 'Course_View_Class_List'});
4372: $bread_crumbs_component = 'Update Users';
4373: $args = {bread_crumbs => $brcrum,
4374: bread_crumbs_component => $bread_crumbs_component};
4375: $r->print(&header(undef,$args));
1.202 raeburn 4376: my $setting = $env{'form.roletype'};
4377: my $choice = $env{'form.bulkaction'};
4378: if ($permission->{'cusr'}) {
1.336 raeburn 4379: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 4380: } else {
4381: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 4382: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 4383: }
4384: } else {
1.351 raeburn 4385: push(@{$brcrum},
4386: {href => '/adm/createuser?action=listusers',
4387: text => "List Users",
4388: help => 'Course_View_Class_List'});
4389: $bread_crumbs_component = 'List Users';
4390: $args = {bread_crumbs => $brcrum,
4391: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 4392: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4393: my $formname = 'studentform';
1.364 raeburn 4394: my $hidecall = "hide_searching();";
1.321 raeburn 4395: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
4396: ($env{'form.roletype'} eq 'community'))) {
4397: if ($env{'form.roletype'} eq 'course') {
4398: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
4399: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
4400: $formname);
4401: } elsif ($env{'form.roletype'} eq 'community') {
4402: $cb_jscript =
4403: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
4404: my %elements = (
4405: coursepick => 'radio',
4406: coursetotal => 'text',
4407: courselist => 'text',
4408: );
4409: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
4410: }
1.364 raeburn 4411: $jscript .= &verify_user_display($context)."\n".
4412: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 4413: my $js = &add_script($jscript).$cb_jscript;
4414: my $loadcode =
4415: &Apache::lonuserutils::course_selector_loadcode($formname);
4416: if ($loadcode ne '') {
1.364 raeburn 4417: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
4418: } else {
4419: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 4420: }
1.351 raeburn 4421: $r->print(&header($js,$args));
1.191 raeburn 4422: } else {
1.364 raeburn 4423: $args->{add_entries} = {onload => $hidecall};
4424: $jscript = &verify_user_display($context).
4425: &Apache::loncommon::check_uncheck_jscript();
4426: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 4427: }
1.202 raeburn 4428: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
4429: $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
1.191 raeburn 4430: }
1.213 raeburn 4431: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 4432: my $brtext;
4433: if ($crstype eq 'Community') {
4434: $brtext = 'Drop Members';
4435: } else {
4436: $brtext = 'Drop Students';
4437: }
1.351 raeburn 4438: push(@{$brcrum},
4439: {href => '/adm/createuser?action=drop',
4440: text => $brtext,
4441: help => 'Course_Drop_Student'});
4442: if ($env{'form.state'} eq 'done') {
4443: push(@{$brcrum},
4444: {href=>'/adm/createuser?action=drop',
4445: text=>"Result"});
4446: }
4447: $bread_crumbs_component = $brtext;
4448: $args = {bread_crumbs => $brcrum,
4449: bread_crumbs_component => $bread_crumbs_component};
4450: $r->print(&header(undef,$args));
1.213 raeburn 4451: if (!exists($env{'form.state'})) {
1.318 raeburn 4452: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 4453: } elsif ($env{'form.state'} eq 'done') {
4454: &Apache::lonuserutils::update_user_list($r,$context,undef,
4455: $env{'form.action'});
4456: }
1.202 raeburn 4457: } elsif ($env{'form.action'} eq 'dateselect') {
4458: if ($permission->{'cusr'}) {
1.351 raeburn 4459: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.221 raeburn 4460: &Apache::lonuserutils::date_section_selector($context,
1.351 raeburn 4461: $permission,$crstype));
1.202 raeburn 4462: } else {
1.351 raeburn 4463: $r->print(&header(undef,{'no_nav_bar' => 1}).
4464: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 4465: }
1.237 raeburn 4466: } elsif ($env{'form.action'} eq 'selfenroll') {
1.351 raeburn 4467: push(@{$brcrum},
4468: {href => '/adm/createuser?action=selfenroll',
4469: text => "Configure Self-enrollment",
4470: help => 'Course_Self_Enrollment'});
1.237 raeburn 4471: if (!exists($env{'form.state'})) {
1.351 raeburn 4472: $args = { bread_crumbs => $brcrum,
4473: bread_crumbs_component => 'Configure Self-enrollment'};
4474: $r->print(&header(undef,$args));
1.241 raeburn 4475: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.237 raeburn 4476: &print_selfenroll_menu($r,$context,$permission);
4477: } elsif ($env{'form.state'} eq 'done') {
1.351 raeburn 4478: push (@{$brcrum},
4479: {href=>'/adm/createuser?action=selfenroll',
4480: text=>"Result"});
4481: $args = { bread_crumbs => $brcrum,
4482: bread_crumbs_component => 'Self-enrollment result'};
4483: $r->print(&header(undef,$args));
1.241 raeburn 4484: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
4485: &update_selfenroll_config($r,$context,$permission);
1.237 raeburn 4486: }
1.277 raeburn 4487: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.351 raeburn 4488: push(@{$brcrum},
4489: {href => '/adm/createuser?action=selfenrollqueue',
4490: text => 'Enrollment requests',
4491: help => 'Course_Self_Enrollment'});
4492: $bread_crumbs_component = 'Enrollment requests';
4493: if ($env{'form.state'} eq 'done') {
4494: push(@{$brcrum},
4495: {href => '/adm/createuser?action=selfenrollqueue',
4496: text => 'Result',
4497: help => 'Course_Self_Enrollment'});
4498: $bread_crumbs_component = 'Enrollment result';
4499: }
4500: $args = { bread_crumbs => $brcrum,
4501: bread_crumbs_component => $bread_crumbs_component};
4502: $r->print(&header(undef,$args));
1.277 raeburn 4503: my $cid = $env{'request.course.id'};
4504: my $cdom = $env{'course.'.$cid.'.domain'};
4505: my $cnum = $env{'course.'.$cid.'.num'};
1.307 raeburn 4506: my $coursedesc = $env{'course.'.$cid.'.description'};
1.277 raeburn 4507: if (!exists($env{'form.state'})) {
4508: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
1.307 raeburn 4509: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
4510: $cdom,$cnum));
1.277 raeburn 4511: } elsif ($env{'form.state'} eq 'done') {
4512: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
1.307 raeburn 4513: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
4514: $cdom,$cnum,$coursedesc));
1.277 raeburn 4515: }
1.239 raeburn 4516: } elsif ($env{'form.action'} eq 'changelogs') {
1.363 raeburn 4517: my $helpitem;
4518: if ($context eq 'course') {
4519: $helpitem = 'Course_User_Logs';
4520: }
1.351 raeburn 4521: push (@{$brcrum},
4522: {href => '/adm/createuser?action=changelogs',
4523: text => 'User Management Logs',
1.363 raeburn 4524: help => $helpitem});
1.351 raeburn 4525: $bread_crumbs_component = 'User Changes';
4526: $args = { bread_crumbs => $brcrum,
4527: bread_crumbs_component => $bread_crumbs_component};
4528: $r->print(&header(undef,$args));
4529: &print_userchangelogs_display($r,$context,$permission);
1.190 raeburn 4530: } else {
1.351 raeburn 4531: $bread_crumbs_component = 'User Management';
4532: $args = { bread_crumbs => $brcrum,
4533: bread_crumbs_component => $bread_crumbs_component};
4534: $r->print(&header(undef,$args));
1.318 raeburn 4535: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4536: }
1.351 raeburn 4537: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 4538: return OK;
4539: }
4540:
4541: sub header {
1.351 raeburn 4542: my ($jscript,$args) = @_;
1.190 raeburn 4543: my $start_page;
1.351 raeburn 4544: if (ref($args) eq 'HASH') {
4545: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 4546: } else {
1.351 raeburn 4547: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 4548: }
4549: return $start_page;
4550: }
1.2 www 4551:
1.191 raeburn 4552: sub add_script {
4553: my ($js) = @_;
1.301 bisitz 4554: return '<script type="text/javascript">'."\n"
4555: .'// <![CDATA['."\n"
4556: .$js."\n"
4557: .'// ]]>'."\n"
4558: .'</script>'."\n";
1.191 raeburn 4559: }
4560:
1.202 raeburn 4561: sub verify_user_display {
1.364 raeburn 4562: my ($context) = @_;
1.374 ! raeburn 4563: my %lt = &Apache::lonlocal::texthash (
! 4564: course => 'course(s): description, section(s), status',
! 4565: community => 'community(s): description, section(s), status',
! 4566: author => 'author',
! 4567: );
1.364 raeburn 4568: my $photos;
4569: if (($context eq 'course') && $env{'request.course.id'}) {
4570: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
4571: }
1.202 raeburn 4572: my $output = <<"END";
4573:
1.364 raeburn 4574: function hide_searching() {
4575: if (document.getElementById('searching')) {
4576: document.getElementById('searching').style.display = 'none';
4577: }
4578: return;
4579: }
4580:
1.202 raeburn 4581: function display_update() {
4582: document.studentform.action.value = 'listusers';
4583: document.studentform.phase.value = 'display';
4584: document.studentform.submit();
4585: }
4586:
1.364 raeburn 4587: function updateCols(caller) {
4588: var context = '$context';
4589: var photos = '$photos';
4590: if (caller == 'Status') {
1.374 ! raeburn 4591: if ((context == 'domain') &&
! 4592: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
! 4593: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 4594: document.getElementById('showcolstatus').checked = false;
4595: document.getElementById('showcolstatus').disabled = 'disabled';
4596: document.getElementById('showcolstart').checked = false;
4597: document.getElementById('showcolend').checked = false;
1.374 ! raeburn 4598: } else {
! 4599: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
! 4600: document.getElementById('showcolstatus').checked = true;
! 4601: document.getElementById('showcolstatus').disabled = '';
! 4602: document.getElementById('showcolstart').checked = true;
! 4603: document.getElementById('showcolend').checked = true;
! 4604: } else {
! 4605: document.getElementById('showcolstatus').checked = false;
! 4606: document.getElementById('showcolstatus').disabled = 'disabled';
! 4607: document.getElementById('showcolstart').checked = false;
! 4608: document.getElementById('showcolend').checked = false;
! 4609: }
1.364 raeburn 4610: }
4611: }
4612: if (caller == 'output') {
4613: if (photos == 1) {
4614: if (document.getElementById('showcolphoto')) {
4615: var photoitem = document.getElementById('showcolphoto');
4616: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
4617: photoitem.checked = true;
4618: photoitem.disabled = '';
4619: } else {
4620: photoitem.checked = false;
4621: photoitem.disabled = 'disabled';
4622: }
4623: }
4624: }
4625: }
4626: if (caller == 'showrole') {
1.371 raeburn 4627: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
4628: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 4629: document.getElementById('showcolrole').checked = true;
4630: document.getElementById('showcolrole').disabled = '';
4631: } else {
4632: document.getElementById('showcolrole').checked = false;
4633: document.getElementById('showcolrole').disabled = 'disabled';
4634: }
1.374 ! raeburn 4635: if (context == 'domain') {
! 4636: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
! 4637: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
! 4638: document.getElementById('showcolstatus').checked = false;
! 4639: document.getElementById('showcolstatus').disabled = 'disabled';
! 4640: document.getElementById('showcolstart').checked = false;
! 4641: document.getElementById('showcolend').checked = false;
! 4642: } else {
! 4643: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
! 4644: document.getElementById('showcolstatus').checked = true;
! 4645: document.getElementById('showcolstatus').disabled = '';
! 4646: document.getElementById('showcolstart').checked = true;
! 4647: document.getElementById('showcolend').checked = true;
! 4648: }
! 4649: }
! 4650: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
! 4651: document.getElementById('showcolextent').disabled = 'disabled';
! 4652: document.getElementById('showcolextent').checked = 'false';
! 4653: document.getElementById('showextent').style.display='none';
! 4654: document.getElementById('showcoltextextent').innerHTML = '';
! 4655: } else {
! 4656: document.getElementById('showextent').style.display='block';
! 4657: document.getElementById('showextent').style.textAlign='left';
! 4658: document.getElementById('showextent').style.textFace='normal';
! 4659: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
! 4660: document.getElementById('showcolextent').disabled = '';
! 4661: document.getElementById('showcolextent').checked = 'true';
! 4662: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
! 4663: } else {
! 4664: document.getElementById('showcolextent').disabled = '';
! 4665: document.getElementById('showcolextent').checked = 'true';
! 4666: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
! 4667: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
! 4668: } else {
! 4669: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
! 4670: }
! 4671: }
! 4672: }
! 4673: }
1.364 raeburn 4674: }
4675: return;
4676: }
4677:
1.202 raeburn 4678: END
4679: return $output;
4680:
4681: }
4682:
1.190 raeburn 4683: ###############################################################
4684: ###############################################################
4685: # Menu Phase One
4686: sub print_main_menu {
1.318 raeburn 4687: my ($permission,$context,$crstype) = @_;
4688: my $linkcontext = $context;
4689: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
4690: if (($context eq 'course') && ($crstype eq 'Community')) {
4691: $linkcontext = lc($crstype);
4692: $stuterm = 'Members';
4693: }
1.208 raeburn 4694: my %links = (
1.298 droeschl 4695: domain => {
4696: upload => 'Upload a File of Users',
4697: singleuser => 'Add/Modify a User',
4698: listusers => 'Manage Users',
4699: },
4700: author => {
4701: upload => 'Upload a File of Co-authors',
4702: singleuser => 'Add/Modify a Co-author',
4703: listusers => 'Manage Co-authors',
4704: },
4705: course => {
4706: upload => 'Upload a File of Course Users',
4707: singleuser => 'Add/Modify a Course User',
1.354 www 4708: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 4709: },
1.318 raeburn 4710: community => {
4711: upload => 'Upload a File of Community Users',
4712: singleuser => 'Add/Modify a Community User',
1.354 www 4713: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 4714: },
4715: );
4716: my %linktitles = (
4717: domain => {
4718: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
4719: listusers => 'Show and manage users in this domain.',
4720: },
4721: author => {
4722: singleuser => 'Add a user with a co- or assistant author role.',
4723: listusers => 'Show and manage co- or assistant authors.',
4724: },
4725: course => {
4726: singleuser => 'Add a user with a certain role to this course.',
4727: listusers => 'Show and manage users in this course.',
4728: },
4729: community => {
4730: singleuser => 'Add a user with a certain role to this community.',
4731: listusers => 'Show and manage users in this community.',
4732: },
1.298 droeschl 4733: );
4734: my @menu = ( {categorytitle => 'Single Users',
4735: items =>
4736: [
4737: {
1.318 raeburn 4738: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 4739: icon => 'edit-redo.png',
4740: #help => 'Course_Change_Privileges',
4741: url => '/adm/createuser?action=singleuser',
4742: permission => $permission->{'cusr'},
1.318 raeburn 4743: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 4744: },
4745: ]},
4746:
4747: {categorytitle => 'Multiple Users',
4748: items =>
4749: [
4750: {
1.318 raeburn 4751: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 4752: icon => 'uplusr.png',
1.298 droeschl 4753: #help => 'Course_Create_Class_List',
4754: url => '/adm/createuser?action=upload',
4755: permission => $permission->{'cusr'},
4756: linktitle => 'Upload a CSV or a text file containing users.',
4757: },
4758: {
1.318 raeburn 4759: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 4760: icon => 'mngcu.png',
1.298 droeschl 4761: #help => 'Course_View_Class_List',
4762: url => '/adm/createuser?action=listusers',
4763: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 4764: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 4765: },
4766:
4767: ]},
4768:
4769: {categorytitle => 'Administration',
4770: items => [ ]},
4771: );
4772:
1.265 mielkec 4773: if ($context eq 'domain'){
1.298 droeschl 4774:
4775: push(@{ $menu[2]->{items} }, #Category: Administration
4776: {
4777: linktext => 'Custom Roles',
4778: icon => 'emblem-photos.png',
4779: #help => 'Course_Editing_Custom_Roles',
4780: url => '/adm/createuser?action=custom',
4781: permission => $permission->{'custom'},
4782: linktitle => 'Configure a custom role.',
4783: },
1.362 raeburn 4784: {
4785: linktext => 'Authoring Space Requests',
4786: icon => 'selfenrl-queue.png',
4787: #help => 'Domain_Role_Approvals',
4788: url => '/adm/createuser?action=processauthorreq',
4789: permission => $permission->{'cusr'},
4790: linktitle => 'Approve or reject author role requests',
4791: },
1.363 raeburn 4792: {
4793: linktext => 'Change Log',
4794: icon => 'document-properties.png',
4795: #help => 'Course_User_Logs',
4796: url => '/adm/createuser?action=changelogs',
4797: permission => $permission->{'cusr'},
4798: linktitle => 'View change log.',
4799: },
1.298 droeschl 4800: );
4801:
1.265 mielkec 4802: }elsif ($context eq 'course'){
1.298 droeschl 4803: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 4804:
4805: my %linktext = (
4806: 'Course' => {
4807: single => 'Add/Modify a Student',
4808: drop => 'Drop Students',
4809: groups => 'Course Groups',
4810: },
4811: 'Community' => {
4812: single => 'Add/Modify a Member',
4813: drop => 'Drop Members',
4814: groups => 'Community Groups',
4815: },
4816: );
4817:
4818: my %linktitle = (
4819: 'Course' => {
4820: single => 'Add a user with the role of student to this course',
4821: drop => 'Remove a student from this course.',
4822: groups => 'Manage course groups',
4823: },
4824: 'Community' => {
4825: single => 'Add a user with the role of member to this community',
4826: drop => 'Remove a member from this community.',
4827: groups => 'Manage community groups',
4828: },
4829: );
4830:
1.298 droeschl 4831: push(@{ $menu[0]->{items} }, #Category: Single Users
4832: {
1.318 raeburn 4833: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 4834: #help => 'Course_Add_Student',
4835: icon => 'list-add.png',
4836: url => '/adm/createuser?action=singlestudent',
4837: permission => $permission->{'cusr'},
1.318 raeburn 4838: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 4839: },
4840: );
4841:
4842: push(@{ $menu[1]->{items} }, #Category: Multiple Users
4843: {
1.318 raeburn 4844: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 4845: icon => 'edit-undo.png',
4846: #help => 'Course_Drop_Student',
4847: url => '/adm/createuser?action=drop',
4848: permission => $permission->{'cusr'},
1.318 raeburn 4849: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 4850: },
4851: );
4852: push(@{ $menu[2]->{items} }, #Category: Administration
4853: {
4854: linktext => 'Custom Roles',
4855: icon => 'emblem-photos.png',
4856: #help => 'Course_Editing_Custom_Roles',
4857: url => '/adm/createuser?action=custom',
4858: permission => $permission->{'custom'},
4859: linktitle => 'Configure a custom role.',
4860: },
4861: {
1.318 raeburn 4862: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 4863: icon => 'grps.png',
1.298 droeschl 4864: #help => 'Course_Manage_Group',
4865: url => '/adm/coursegroups?refpage=cusr',
4866: permission => $permission->{'grp_manage'},
1.318 raeburn 4867: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 4868: },
4869: {
1.328 wenzelju 4870: linktext => 'Change Log',
1.298 droeschl 4871: icon => 'document-properties.png',
4872: #help => 'Course_User_Logs',
4873: url => '/adm/createuser?action=changelogs',
4874: permission => $permission->{'cusr'},
4875: linktitle => 'View change log.',
4876: },
4877: );
1.277 raeburn 4878: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 4879: push(@{ $menu[2]->{items} },
4880: {
4881: linktext => 'Enrollment Requests',
4882: icon => 'selfenrl-queue.png',
4883: #help => 'Course_Approve_Selfenroll',
4884: url => '/adm/createuser?action=selfenrollqueue',
4885: permission => $permission->{'cusr'},
4886: linktitle =>'Approve or reject enrollment requests.',
4887: },
4888: );
1.277 raeburn 4889: }
1.298 droeschl 4890:
1.265 mielkec 4891: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 4892: if ($crstype ne 'Community') {
4893: push(@{ $menu[2]->{items} },
4894: {
4895: linktext => 'Automated Enrollment',
4896: icon => 'roles.png',
4897: #help => 'Course_Automated_Enrollment',
4898: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
4899: && $permission->{'cusr'}),
4900: url => '/adm/populate',
4901: linktitle => 'Automated enrollment manager.',
4902: }
4903: );
4904: }
4905: push(@{ $menu[2]->{items} },
1.298 droeschl 4906: {
4907: linktext => 'User Self-Enrollment',
1.342 wenzelju 4908: icon => 'self_enroll.png',
1.298 droeschl 4909: #help => 'Course_Self_Enrollment',
4910: url => '/adm/createuser?action=selfenroll',
4911: permission => $permission->{'cusr'},
1.317 bisitz 4912: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 4913: },
4914: );
4915: }
1.363 raeburn 4916: } elsif ($context eq 'author') {
1.370 raeburn 4917: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 4918: {
4919: linktext => 'Change Log',
4920: icon => 'document-properties.png',
4921: #help => 'Course_User_Logs',
4922: url => '/adm/createuser?action=changelogs',
4923: permission => $permission->{'cusr'},
4924: linktitle => 'View change log.',
4925: },
1.370 raeburn 4926: );
1.363 raeburn 4927: }
4928: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 4929: # { text => 'View Log-in History',
4930: # help => 'Course_User_Logins',
4931: # action => 'logins',
4932: # permission => $permission->{'cusr'},
4933: # });
1.190 raeburn 4934: }
4935:
1.189 albertel 4936: sub restore_prev_selections {
4937: my %saveable_parameters = ('srchby' => 'scalar',
4938: 'srchin' => 'scalar',
4939: 'srchtype' => 'scalar',
4940: );
4941: &Apache::loncommon::store_settings('user','user_picker',
4942: \%saveable_parameters);
4943: &Apache::loncommon::restore_settings('user','user_picker',
4944: \%saveable_parameters);
4945: }
4946:
1.237 raeburn 4947: sub print_selfenroll_menu {
4948: my ($r,$context,$permission) = @_;
1.322 raeburn 4949: my $crstype = &Apache::loncommon::course_type();
1.237 raeburn 4950: my $formname = 'enrollstudent';
4951: my $nolink = 1;
4952: my ($row,$lt) = &get_selfenroll_titles();
4953: my $groupslist = &Apache::lonuserutils::get_groupslist();
4954: my $setsec_js =
4955: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 4956: my %alerts = &Apache::lonlocal::texthash(
4957: acto => 'Activation of self-enrollment was selected for the following domain(s)',
4958: butn => 'but no user types have been checked.',
4959: wilf => "Please uncheck 'activate' or check at least one type.",
4960: );
4961: my $selfenroll_js = <<"ENDSCRIPT";
4962: function update_types(caller,num) {
4963: var delidx = getIndexByName('selfenroll_delete');
4964: var actidx = getIndexByName('selfenroll_activate');
4965: if (caller == 'selfenroll_all') {
4966: var selall;
4967: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4968: if (document.$formname.selfenroll_all[i].checked) {
4969: selall = document.$formname.selfenroll_all[i].value;
4970: }
4971: }
4972: if (selall == 1) {
4973: if (delidx != -1) {
4974: if (document.$formname.selfenroll_delete.length) {
4975: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
4976: document.$formname.selfenroll_delete[j].checked = true;
4977: }
4978: } else {
4979: document.$formname.elements[delidx].checked = true;
4980: }
4981: }
4982: if (actidx != -1) {
4983: if (document.$formname.selfenroll_activate.length) {
4984: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4985: document.$formname.selfenroll_activate[j].checked = false;
4986: }
4987: } else {
4988: document.$formname.elements[actidx].checked = false;
4989: }
4990: }
4991: document.$formname.selfenroll_newdom.selectedIndex = 0;
4992: }
4993: }
4994: if (caller == 'selfenroll_activate') {
4995: if (document.$formname.selfenroll_activate.length) {
4996: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4997: if (document.$formname.selfenroll_activate[j].value == num) {
4998: if (document.$formname.selfenroll_activate[j].checked) {
4999: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5000: if (document.$formname.selfenroll_all[i].value == '1') {
5001: document.$formname.selfenroll_all[i].checked = false;
5002: }
5003: if (document.$formname.selfenroll_all[i].value == '0') {
5004: document.$formname.selfenroll_all[i].checked = true;
5005: }
5006: }
5007: }
5008: }
5009: }
5010: } else {
5011: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5012: if (document.$formname.selfenroll_all[i].value == '1') {
5013: document.$formname.selfenroll_all[i].checked = false;
5014: }
5015: if (document.$formname.selfenroll_all[i].value == '0') {
5016: document.$formname.selfenroll_all[i].checked = true;
5017: }
5018: }
5019: }
5020: }
5021: if (caller == 'selfenroll_delete') {
5022: if (document.$formname.selfenroll_delete.length) {
5023: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5024: if (document.$formname.selfenroll_delete[j].value == num) {
5025: if (document.$formname.selfenroll_delete[j].checked) {
5026: var delindex = getIndexByName('selfenroll_types_'+num);
5027: if (delindex != -1) {
5028: if (document.$formname.elements[delindex].length) {
5029: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5030: document.$formname.elements[delindex][k].checked = false;
5031: }
5032: } else {
5033: document.$formname.elements[delindex].checked = false;
5034: }
5035: }
5036: }
5037: }
5038: }
5039: } else {
5040: if (document.$formname.selfenroll_delete.checked) {
5041: var delindex = getIndexByName('selfenroll_types_'+num);
5042: if (delindex != -1) {
5043: if (document.$formname.elements[delindex].length) {
5044: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5045: document.$formname.elements[delindex][k].checked = false;
5046: }
5047: } else {
5048: document.$formname.elements[delindex].checked = false;
5049: }
5050: }
5051: }
5052: }
5053: }
5054: return;
5055: }
5056:
5057: function validate_types(form) {
5058: var needaction = new Array();
5059: var countfail = 0;
5060: var actidx = getIndexByName('selfenroll_activate');
5061: if (actidx != -1) {
5062: if (document.$formname.selfenroll_activate.length) {
5063: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5064: var num = document.$formname.selfenroll_activate[j].value;
5065: if (document.$formname.selfenroll_activate[j].checked) {
5066: countfail = check_types(num,countfail,needaction)
5067: }
5068: }
5069: } else {
5070: if (document.$formname.selfenroll_activate.checked) {
5071: var num = document.enrollstudent.selfenroll_activate.value;
5072: countfail = check_types(num,countfail,needaction)
5073: }
5074: }
5075: }
5076: if (countfail > 0) {
5077: var msg = "$alerts{'acto'}\\n";
5078: var loopend = needaction.length -1;
5079: if (loopend > 0) {
5080: for (var m=0; m<loopend; m++) {
5081: msg += needaction[m]+", ";
5082: }
5083: }
5084: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5085: alert(msg);
5086: return;
5087: }
5088: setSections(form);
5089: }
5090:
5091: function check_types(num,countfail,needaction) {
5092: var typeidx = getIndexByName('selfenroll_types_'+num);
5093: var count = 0;
5094: if (typeidx != -1) {
5095: if (document.$formname.elements[typeidx].length) {
5096: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5097: if (document.$formname.elements[typeidx][k].checked) {
5098: count ++;
5099: }
5100: }
5101: } else {
5102: if (document.$formname.elements[typeidx].checked) {
5103: count ++;
5104: }
5105: }
5106: if (count == 0) {
5107: var domidx = getIndexByName('selfenroll_dom_'+num);
5108: if (domidx != -1) {
5109: var domname = document.$formname.elements[domidx].value;
5110: needaction[countfail] = domname;
5111: countfail ++;
5112: }
5113: }
5114: }
5115: return countfail;
5116: }
5117:
5118: function getIndexByName(item) {
5119: for (var i=0;i<document.$formname.elements.length;i++) {
5120: if (document.$formname.elements[i].name == item) {
5121: return i;
5122: }
5123: }
5124: return -1;
5125: }
5126: ENDSCRIPT
1.256 raeburn 5127: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5128: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5129:
1.237 raeburn 5130: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5131: '// <![CDATA['."\n".
1.249 raeburn 5132: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5133: '// ]]>'."\n".
1.237 raeburn 5134: '</script>'."\n".
1.256 raeburn 5135: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
5136: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
5137: if (ref($visactions) eq 'HASH') {
5138: if ($visible) {
1.283 bisitz 5139: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
1.256 raeburn 5140: } else {
1.283 bisitz 5141: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5142: .$visactions->{'yous'}.
1.256 raeburn 5143: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5144: if (ref($vismsgs) eq 'ARRAY') {
5145: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5146: foreach my $item (@{$vismsgs}) {
5147: $output .= '<li>'.$visactions->{$item}.'</li>';
5148: }
5149: $output .= '</ul>';
5150: }
5151: $output .= '</p>';
5152: }
5153: }
5154: $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
5155: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5156: if (ref($row) eq 'ARRAY') {
5157: foreach my $item (@{$row}) {
5158: my $title = $item;
5159: if (ref($lt) eq 'HASH') {
5160: $title = $lt->{$item};
5161: }
1.297 bisitz 5162: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5163: if ($item eq 'types') {
5164: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 5165: my $showdomdesc = 1;
5166: my $includeempty = 1;
5167: my $num = 0;
5168: $output .= &Apache::loncommon::start_data_table().
5169: &Apache::loncommon::start_data_table_row()
5170: .'<td colspan="2"><span class="LC_nobreak"><label>'
5171: .&mt('Any user in any domain:')
5172: .' <input type="radio" name="selfenroll_all" value="1" ';
5173: if ($curr_types eq '*') {
5174: $output .= ' checked="checked" ';
5175: }
1.249 raeburn 5176: $output .= 'onchange="javascript:update_types('.
5177: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
5178: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 5179: if ($curr_types ne '*') {
5180: $output .= ' checked="checked" ';
5181: }
1.249 raeburn 5182: $output .= ' onchange="javascript:update_types('.
5183: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
5184: &Apache::loncommon::end_data_table_row().
5185: &Apache::loncommon::end_data_table().
5186: &mt('Or').'<br />'.
5187: &Apache::loncommon::start_data_table();
1.241 raeburn 5188: my %currdoms;
1.249 raeburn 5189: if ($curr_types eq '') {
1.241 raeburn 5190: $output .= &new_selfenroll_dom_row($cdom,'0');
5191: } elsif ($curr_types ne '*') {
5192: my @entries = split(/;/,$curr_types);
5193: if (@entries > 0) {
5194: foreach my $entry (@entries) {
5195: my ($currdom,$typestr) = split(/:/,$entry);
5196: $currdoms{$currdom} = 1;
5197: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 5198: my @currinsttypes = split(',',$typestr);
1.241 raeburn 5199: $output .= &Apache::loncommon::start_data_table_row()
5200: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
5201: .' '.$domdesc.' ('.$currdom.')'
5202: .'</b><input type="hidden" name="selfenroll_dom_'.$num
5203: .'" value="'.$currdom.'" /></span><br />'
5204: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 5205: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 5206: .&mt('Delete').'</label></span></td>';
1.249 raeburn 5207: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 5208: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
5209: .&Apache::loncommon::end_data_table_row();
5210: $num ++;
5211: }
5212: }
5213: }
1.249 raeburn 5214: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 5215: if ($curr_types eq '*') {
1.249 raeburn 5216: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 5217: } elsif ($curr_types eq '') {
1.249 raeburn 5218: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 5219: }
5220: $output .= &Apache::loncommon::start_data_table_row()
5221: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
5222: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
5223: $includeempty,$showdomdesc)
5224: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
5225: .'</td>'.&Apache::loncommon::end_data_table_row()
5226: .&Apache::loncommon::end_data_table();
1.237 raeburn 5227: } elsif ($item eq 'registered') {
5228: my ($regon,$regoff);
5229: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
5230: $regon = ' checked="checked" ';
5231: $regoff = ' ';
5232: } else {
5233: $regon = ' ';
5234: $regoff = ' checked="checked" ';
5235: }
5236: $output .= '<label>'.
1.245 raeburn 5237: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 5238: &mt('Yes').'</label> <label>'.
1.245 raeburn 5239: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 5240: &mt('No').'</label>';
1.237 raeburn 5241: } elsif ($item eq 'enroll_dates') {
5242: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
5243: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
5244: if ($starttime eq '') {
5245: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
5246: }
5247: if ($endtime eq '') {
5248: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
5249: }
5250: my $startform =
5251: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
5252: undef,undef,undef,undef,undef,undef,undef,$nolink);
5253: my $endform =
5254: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
5255: undef,undef,undef,undef,undef,undef,undef,$nolink);
5256: $output .= &selfenroll_date_forms($startform,$endform);
5257: } elsif ($item eq 'access_dates') {
5258: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
5259: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
5260: if ($starttime eq '') {
5261: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
5262: }
5263: if ($endtime eq '') {
5264: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
5265: }
5266: my $startform =
5267: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
5268: undef,undef,undef,undef,undef,undef,undef,$nolink);
5269: my $endform =
5270: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
5271: undef,undef,undef,undef,undef,undef,undef,$nolink);
5272: $output .= &selfenroll_date_forms($startform,$endform);
5273: } elsif ($item eq 'section') {
5274: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
5275: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
5276: my $newsecval;
5277: if ($currsec ne 'none' && $currsec ne '') {
5278: if (!defined($sections_count{$currsec})) {
5279: $newsecval = $currsec;
5280: }
5281: }
5282: my $sections_select =
5283: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
5284: $output .= '<table class="LC_createuser">'."\n".
5285: '<tr class="LC_section_row">'."\n".
5286: '<td align="center">'.&mt('Existing sections')."\n".
5287: '<br />'.$sections_select.'</td><td align="center">'.
5288: &mt('New section').'<br />'."\n".
5289: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
5290: '<input type="hidden" name="sections" value="" />'."\n".
5291: '<input type="hidden" name="state" value="done" />'."\n".
5292: '</td></tr></table>'."\n";
1.276 raeburn 5293: } elsif ($item eq 'approval') {
5294: my ($appon,$appoff);
5295: my $cid = $env{'request.course.id'};
5296: my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
5297: if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) {
5298: $appon = ' checked="checked" ';
5299: $appoff = ' ';
5300: } else {
5301: $appon = ' ';
5302: $appoff = ' checked="checked" ';
5303: }
5304: $output .= '<label>'.
5305: '<input type="radio" name="selfenroll_approval" value="1"'.$appon.'/>'.
5306: &mt('Yes').'</label> <label>'.
5307: '<input type="radio" name="selfenroll_approval" value="0"'.$appoff.'/>'.
5308: &mt('No').'</label>';
5309: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
5310: my (@ccs,%notified);
1.322 raeburn 5311: my $ccrole = 'cc';
5312: if ($crstype eq 'Community') {
5313: $ccrole = 'co';
5314: }
5315: if ($advhash{$ccrole}) {
5316: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 5317: }
5318: if ($currnotified) {
5319: foreach my $current (split(/,/,$currnotified)) {
5320: $notified{$current} = 1;
5321: if (!grep(/^\Q$current\E$/,@ccs)) {
5322: push(@ccs,$current);
5323: }
5324: }
5325: }
5326: if (@ccs) {
1.277 raeburn 5327: $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 5328: &Apache::loncommon::start_data_table_row();
5329: my $count = 0;
5330: my $numcols = 4;
5331: foreach my $cc (sort(@ccs)) {
5332: my $notifyon;
5333: my ($ccuname,$ccudom) = split(/:/,$cc);
5334: if ($notified{$cc}) {
5335: $notifyon = ' checked="checked" ';
5336: }
5337: if ($count && !$count%$numcols) {
5338: $output .= &Apache::loncommon::end_data_table_row().
5339: &Apache::loncommon::start_data_table_row()
5340: }
5341: $output .= '<td><span class="LC_nobreak"><label>'.
5342: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
5343: &Apache::loncommon::plainname($ccuname,$ccudom).
5344: '</label></span></td>';
1.343 raeburn 5345: $count ++;
1.276 raeburn 5346: }
5347: my $rem = $count%$numcols;
5348: if ($rem) {
5349: my $emptycols = $numcols - $rem;
5350: for (my $i=0; $i<$emptycols; $i++) {
5351: $output .= '<td> </td>';
5352: }
5353: }
5354: $output .= &Apache::loncommon::end_data_table_row().
5355: &Apache::loncommon::end_data_table();
5356: }
5357: } elsif ($item eq 'limit') {
5358: my ($crslimit,$selflimit,$nolimit);
5359: my $cid = $env{'request.course.id'};
5360: my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'};
5361: my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
1.343 raeburn 5362: $nolimit = ' checked="checked" ';
1.276 raeburn 5363: if ($currlim eq 'allstudents') {
5364: $crslimit = ' checked="checked" ';
5365: $selflimit = ' ';
5366: $nolimit = ' ';
5367: } elsif ($currlim eq 'selfenrolled') {
5368: $crslimit = ' ';
5369: $selflimit = ' checked="checked" ';
5370: $nolimit = ' ';
5371: } else {
5372: $crslimit = ' ';
5373: $selflimit = ' ';
5374: }
5375: $output .= '<table><tr><td><label>'.
1.278 raeburn 5376: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 5377: &mt('No limit').'</label></td><td><label>'.
5378: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
5379: &mt('Limit by total students').'</label></td><td><label>'.
5380: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
5381: &mt('Limit by total self-enrolled students').
5382: '</td></tr><tr>'.
5383: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
5384: (' 'x3).&mt('Maximum number allowed: ').
5385: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 5386: }
5387: $output .= &Apache::lonhtmlcommon::row_closure(1);
5388: }
5389: }
5390: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 5391: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 5392: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.241 raeburn 5393: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 5394: $r->print($output);
5395: return;
5396: }
5397:
1.256 raeburn 5398: sub visible_in_cat {
5399: my ($cdom,$cnum) = @_;
5400: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5401: my ($cathash,%settable,@vismsgs,$cansetvis);
5402: my %visactions = &Apache::lonlocal::texthash(
1.316 bisitz 5403: vis => 'Your course/community currently appears in the Course/Community Catalog for this domain.',
1.256 raeburn 5404: 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 5405: miss => 'Your course/community does not currently appear in the Course/Community Catalog for this domain.',
1.256 raeburn 5406: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
5407: 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 5408: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
1.256 raeburn 5409: take => 'Take the following action to ensure the course appears in the Catalog:',
5410: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
5411: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
5412: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
5413: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
5414: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
5415: 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',
5416: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
5417: );
1.347 raeburn 5418: $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>"');
5419: $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>"');
5420: $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 5421: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5422: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
5423: $settable{'togglecats'} = 1;
5424: }
5425: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
5426: $settable{'categorize'} = 1;
5427: }
5428: $cathash = $domconf{'coursecategories'}{'cats'};
5429: }
1.260 raeburn 5430: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 5431: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
5432: } elsif ($settable{'togglecats'}) {
5433: $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 5434: } elsif ($settable{'categorize'}) {
1.256 raeburn 5435: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
5436: } else {
5437: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
5438: }
5439:
5440: my %currsettings =
5441: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
5442: $cdom,$cnum);
5443: my $visible = 0;
5444: if ($currsettings{'internal.coursecode'} ne '') {
5445: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5446: $cathash = $domconf{'coursecategories'}{'cats'};
5447: if (ref($cathash) eq 'HASH') {
5448: if ($cathash->{'instcode::0'} eq '') {
5449: push(@vismsgs,'dc_addinst');
5450: } else {
5451: $visible = 1;
5452: }
5453: } else {
5454: $visible = 1;
5455: }
5456: } else {
5457: $visible = 1;
5458: }
5459: } else {
5460: if (ref($cathash) eq 'HASH') {
5461: if ($cathash->{'instcode::0'} ne '') {
5462: push(@vismsgs,'dc_instcode');
5463: }
5464: } else {
5465: push(@vismsgs,'dc_instcode');
5466: }
5467: }
5468: if ($currsettings{'categories'} ne '') {
5469: my $cathash;
5470: if (ref($domconf{'coursecategories'}) eq 'HASH') {
5471: $cathash = $domconf{'coursecategories'}{'cats'};
5472: if (ref($cathash) eq 'HASH') {
5473: if (keys(%{$cathash}) == 0) {
5474: push(@vismsgs,'dc_catalog');
5475: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
5476: push(@vismsgs,'dc_categories');
5477: } else {
5478: my @currcategories = split('&',$currsettings{'categories'});
5479: my $matched = 0;
5480: foreach my $cat (@currcategories) {
5481: if ($cathash->{$cat} ne '') {
5482: $visible = 1;
5483: $matched = 1;
5484: last;
5485: }
5486: }
5487: if (!$matched) {
1.260 raeburn 5488: if ($settable{'categorize'}) {
1.256 raeburn 5489: push(@vismsgs,'chgcat');
5490: } else {
5491: push(@vismsgs,'dc_chgcat');
5492: }
5493: }
5494: }
5495: }
5496: }
5497: } else {
5498: if (ref($cathash) eq 'HASH') {
5499: if ((keys(%{$cathash}) > 1) ||
5500: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 5501: if ($settable{'categorize'}) {
1.256 raeburn 5502: push(@vismsgs,'addcat');
5503: } else {
5504: push(@vismsgs,'dc_addcat');
5505: }
5506: }
5507: }
5508: }
5509: if ($currsettings{'hidefromcat'} eq 'yes') {
5510: $visible = 0;
5511: if ($settable{'togglecats'}) {
5512: unshift(@vismsgs,'unhide');
5513: } else {
5514: unshift(@vismsgs,'dc_unhide')
5515: }
5516: }
5517: return ($visible,$cansetvis,\@vismsgs,\%visactions);
5518: }
5519:
1.241 raeburn 5520: sub new_selfenroll_dom_row {
5521: my ($newdom,$num) = @_;
5522: my $domdesc = &Apache::lonnet::domain($newdom);
5523: my $output;
5524: if ($domdesc ne '') {
5525: $output .= &Apache::loncommon::start_data_table_row()
5526: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
5527: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 5528: .'" value="'.$newdom.'" /></span><br />'
5529: .'<span class="LC_nobreak"><label><input type="checkbox" '
5530: .'name="selfenroll_activate" value="'.$num.'" '
5531: .'onchange="javascript:update_types('
5532: ."'selfenroll_activate','$num'".');" />'
5533: .&mt('Activate').'</label></span></td>';
1.241 raeburn 5534: my @currinsttypes;
5535: $output .= '<td>'.&mt('User types:').'<br />'
5536: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
5537: .&Apache::loncommon::end_data_table_row();
5538: }
5539: return $output;
5540: }
5541:
5542: sub selfenroll_inst_types {
5543: my ($num,$currdom,$currinsttypes) = @_;
5544: my $output;
5545: my $numinrow = 4;
5546: my $count = 0;
5547: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 5548: my $othervalue = 'any';
1.241 raeburn 5549: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 5550: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 5551: $othervalue = 'other';
5552: }
1.241 raeburn 5553: $output .= '<table><tr>';
5554: foreach my $type (@{$types}) {
5555: if (($count > 0) && ($count%$numinrow == 0)) {
5556: $output .= '</tr><tr>';
5557: }
5558: if (defined($usertypes->{$type})) {
1.257 raeburn 5559: my $esc_type = &escape($type);
1.241 raeburn 5560: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 5561: $esc_type.'" ';
1.241 raeburn 5562: if (ref($currinsttypes) eq 'ARRAY') {
5563: if (@{$currinsttypes} > 0) {
1.249 raeburn 5564: if (grep(/^any$/,@{$currinsttypes})) {
5565: $output .= 'checked="checked"';
1.257 raeburn 5566: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 5567: $output .= 'checked="checked"';
5568: }
1.249 raeburn 5569: } else {
5570: $output .= 'checked="checked"';
1.241 raeburn 5571: }
5572: }
5573: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
5574: }
5575: $count ++;
5576: }
5577: if (($count > 0) && ($count%$numinrow == 0)) {
5578: $output .= '</tr><tr>';
5579: }
1.249 raeburn 5580: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 5581: if (ref($currinsttypes) eq 'ARRAY') {
5582: if (@{$currinsttypes} > 0) {
1.249 raeburn 5583: if (grep(/^any$/,@{$currinsttypes})) {
5584: $output .= ' checked="checked"';
5585: } elsif ($othervalue eq 'other') {
5586: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
5587: $output .= ' checked="checked"';
5588: }
1.241 raeburn 5589: }
1.249 raeburn 5590: } else {
5591: $output .= ' checked="checked"';
1.241 raeburn 5592: }
1.249 raeburn 5593: } else {
5594: $output .= ' checked="checked"';
1.241 raeburn 5595: }
5596: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
5597: }
5598: return $output;
5599: }
5600:
1.237 raeburn 5601: sub selfenroll_date_forms {
5602: my ($startform,$endform) = @_;
5603: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 5604: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 5605: 'LC_oddrow_value')."\n".
5606: $startform."\n".
5607: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 5608: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 5609: 'LC_oddrow_value')."\n".
5610: $endform."\n".
5611: &Apache::lonhtmlcommon::row_closure(1).
5612: &Apache::lonhtmlcommon::end_pick_box();
5613: return $output;
5614: }
5615:
1.239 raeburn 5616: sub print_userchangelogs_display {
5617: my ($r,$context,$permission) = @_;
1.363 raeburn 5618: my $formname = 'rolelog';
5619: my ($username,$domain,$crstype,%roleslog);
5620: if ($context eq 'domain') {
5621: $domain = $env{'request.role.domain'};
5622: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
5623: } else {
5624: if ($context eq 'course') {
5625: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
5626: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
5627: $crstype = &Apache::loncommon::course_type();
5628: my %saveable_parameters = ('show' => 'scalar',);
5629: &Apache::loncommon::store_course_settings('roles_log',
5630: \%saveable_parameters);
5631: &Apache::loncommon::restore_course_settings('roles_log',
5632: \%saveable_parameters);
5633: } elsif ($context eq 'author') {
5634: $domain = $env{'user.domain'};
5635: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
5636: $username = $env{'user.name'};
5637: } else {
5638: undef($domain);
5639: }
5640: }
5641: if ($domain ne '' && $username ne '') {
5642: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
5643: }
5644: }
1.239 raeburn 5645: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
5646:
5647: # set defaults
5648: my $now = time();
5649: my $defstart = $now - (7*24*3600); #7 days ago
5650: my %defaults = (
5651: page => '1',
5652: show => '10',
5653: role => 'any',
5654: chgcontext => 'any',
5655: rolelog_start_date => $defstart,
5656: rolelog_end_date => $now,
5657: );
5658: my $more_records = 0;
5659:
5660: # set current
5661: my %curr;
5662: foreach my $item ('show','page','role','chgcontext') {
5663: $curr{$item} = $env{'form.'.$item};
5664: }
5665: my ($startdate,$enddate) =
5666: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
5667: $curr{'rolelog_start_date'} = $startdate;
5668: $curr{'rolelog_end_date'} = $enddate;
5669: foreach my $key (keys(%defaults)) {
5670: if ($curr{$key} eq '') {
5671: $curr{$key} = $defaults{$key};
5672: }
5673: }
1.248 raeburn 5674: my (%whodunit,%changed,$version);
5675: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 5676: my ($minshown,$maxshown);
1.255 raeburn 5677: $minshown = 1;
1.239 raeburn 5678: my $count = 0;
5679: if ($curr{'show'} ne &mt('all')) {
5680: $maxshown = $curr{'page'} * $curr{'show'};
5681: if ($curr{'page'} > 1) {
5682: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
5683: }
5684: }
1.301 bisitz 5685:
1.327 raeburn 5686: # Form Header
5687: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 5688: &role_display_filter($context,$formname,$domain,$username,\%curr,
5689: $version,$crstype));
1.327 raeburn 5690:
5691: # Create navigation
5692: my ($nav_script,$nav_links) = &userlogdisplay_nav($formname,\%curr,$more_records);
5693: my $showntableheader = 0;
5694:
5695: # Table Header
5696: my $tableheader =
5697: &Apache::loncommon::start_data_table_header_row()
5698: .'<th> </th>'
5699: .'<th>'.&mt('When').'</th>'
5700: .'<th>'.&mt('Who made the change').'</th>'
5701: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 5702: .'<th>'.&mt('Role').'</th>';
5703:
5704: if ($context eq 'course') {
5705: $tableheader .= '<th>'.&mt('Section').'</th>';
5706: }
5707: $tableheader .=
5708: '<th>'.&mt('Context').'</th>'
1.327 raeburn 5709: .'<th>'.&mt('Start').'</th>'
5710: .'<th>'.&mt('End').'</th>'
5711: .&Apache::loncommon::end_data_table_header_row();
5712:
5713: # Display user change log data
1.239 raeburn 5714: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
5715: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
5716: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
5717: if ($curr{'show'} ne &mt('all')) {
5718: if ($count >= $curr{'page'} * $curr{'show'}) {
5719: $more_records = 1;
5720: last;
5721: }
5722: }
5723: if ($curr{'role'} ne 'any') {
5724: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
5725: }
5726: if ($curr{'chgcontext'} ne 'any') {
5727: if ($curr{'chgcontext'} eq 'selfenroll') {
5728: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
5729: } else {
5730: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
5731: }
5732: }
5733: $count ++;
5734: next if ($count < $minshown);
1.327 raeburn 5735: unless ($showntableheader) {
5736: $r->print($nav_script
5737: .$nav_links
5738: .&Apache::loncommon::start_data_table()
5739: .$tableheader);
5740: $r->rflush();
5741: $showntableheader = 1;
5742: }
1.239 raeburn 5743: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
5744: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
5745: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
5746: }
5747: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
5748: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
5749: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
5750: }
5751: my $sec = $roleslog{$id}{'logentry'}{'section'};
5752: if ($sec eq '') {
5753: $sec = &mt('None');
5754: }
5755: my ($rolestart,$roleend);
5756: if ($roleslog{$id}{'delflag'}) {
5757: $rolestart = &mt('deleted');
5758: $roleend = &mt('deleted');
5759: } else {
5760: $rolestart = $roleslog{$id}{'logentry'}{'start'};
5761: $roleend = $roleslog{$id}{'logentry'}{'end'};
5762: if ($rolestart eq '' || $rolestart == 0) {
5763: $rolestart = &mt('No start date');
5764: } else {
5765: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
5766: }
5767: if ($roleend eq '' || $roleend == 0) {
5768: $roleend = &mt('No end date');
5769: } else {
5770: $roleend = &Apache::lonlocal::locallocaltime($roleend);
5771: }
5772: }
5773: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
5774: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
5775: $chgcontext = 'selfenroll';
5776: }
1.363 raeburn 5777: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 5778: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
5779: $chgcontext = $lt{$chgcontext};
5780: }
1.327 raeburn 5781: $r->print(
1.301 bisitz 5782: &Apache::loncommon::start_data_table_row()
5783: .'<td>'.$count.'</td>'
5784: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
5785: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
5786: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 5787: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
5788: if ($context eq 'course') {
5789: $r->print('<td>'.$sec.'</td>');
5790: }
5791: $r->print(
5792: '<td>'.$chgcontext.'</td>'
1.301 bisitz 5793: .'<td>'.$rolestart.'</td>'
5794: .'<td>'.$roleend.'</td>'
1.327 raeburn 5795: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 5796: }
5797:
1.327 raeburn 5798: if ($showntableheader) { # Table footer, if content displayed above
5799: $r->print(&Apache::loncommon::end_data_table()
5800: .$nav_links);
5801: } else { # No content displayed above
1.301 bisitz 5802: $r->print('<p class="LC_info">'
5803: .&mt('There are no records to display.')
5804: .'</p>'
5805: );
1.239 raeburn 5806: }
1.301 bisitz 5807:
1.327 raeburn 5808: # Form Footer
5809: $r->print(
5810: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
5811: .'<input type="hidden" name="action" value="changelogs" />'
5812: .'</form>');
5813: return;
5814: }
1.301 bisitz 5815:
1.327 raeburn 5816: sub userlogdisplay_nav {
5817: my ($formname,$curr,$more_records) = @_;
5818: my ($nav_script,$nav_links);
5819: if (ref($curr) eq 'HASH') {
5820: # Create Navigation:
5821: # Navigation Script
5822: $nav_script = <<"ENDSCRIPT";
1.239 raeburn 5823: <script type="text/javascript">
1.301 bisitz 5824: // <![CDATA[
1.239 raeburn 5825: function chgPage(caller) {
5826: if (caller == 'previous') {
5827: document.$formname.page.value --;
5828: }
5829: if (caller == 'next') {
5830: document.$formname.page.value ++;
5831: }
1.327 raeburn 5832: document.$formname.submit();
1.239 raeburn 5833: return;
5834: }
1.301 bisitz 5835: // ]]>
1.239 raeburn 5836: </script>
5837: ENDSCRIPT
1.327 raeburn 5838: # Navigation Buttons
5839: $nav_links = '<p>';
5840: if (($curr->{'page'} > 1) || ($more_records)) {
5841: if ($curr->{'page'} > 1) {
5842: $nav_links .= '<input type="button"'
5843: .' onclick="javascript:chgPage('."'previous'".');"'
5844: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
5845: .'" /> ';
5846: }
5847: if ($more_records) {
5848: $nav_links .= '<input type="button"'
5849: .' onclick="javascript:chgPage('."'next'".');"'
5850: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
5851: .'" />';
5852: }
1.301 bisitz 5853: }
1.327 raeburn 5854: $nav_links .= '</p>';
1.301 bisitz 5855: }
1.327 raeburn 5856: return ($nav_script,$nav_links);
1.239 raeburn 5857: }
5858:
5859: sub role_display_filter {
1.363 raeburn 5860: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
5861: my $lctype;
5862: if ($context eq 'course') {
5863: $lctype = lc($crstype);
5864: }
1.239 raeburn 5865: my $nolink = 1;
5866: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 5867: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 5868: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
5869: (&mt('all'),5,10,20,50,100,1000,10000)).
5870: '</td><td> </td>';
5871: my $startform =
5872: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
5873: $curr->{'rolelog_start_date'},undef,
5874: undef,undef,undef,undef,undef,undef,$nolink);
5875: my $endform =
5876: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
5877: $curr->{'rolelog_end_date'},undef,
5878: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 5879: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 5880: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
5881: '<table><tr><td>'.&mt('After:').
5882: '</td><td>'.$startform.'</td></tr>'.
5883: '<tr><td>'.&mt('Before:').'</td>'.
5884: '<td>'.$endform.'</td></tr></table>'.
5885: '</td>'.
5886: '<td> </td>'.
1.239 raeburn 5887: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
5888: '<select name="role"><option value="any"';
5889: if ($curr->{'role'} eq 'any') {
5890: $output .= ' selected="selected"';
5891: }
5892: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 5893: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 5894: foreach my $role (@roles) {
5895: my $plrole;
5896: if ($role eq 'cr') {
5897: $plrole = &mt('Custom Role');
5898: } else {
1.318 raeburn 5899: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 5900: }
5901: my $selstr = '';
5902: if ($role eq $curr->{'role'}) {
5903: $selstr = ' selected="selected"';
5904: }
5905: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
5906: }
1.301 bisitz 5907: $output .= '</select></td>'.
5908: '<td> </td>'.
5909: '<td valign="top"><b>'.
1.239 raeburn 5910: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 5911: my @posscontexts;
5912: if ($context eq 'course') {
5913: @posscontexts = ('any','auto','updatenow','createcourse','course','domain','selfenroll','requestcourses');
5914: } elsif ($context eq 'domain') {
5915: @posscontexts = ('any','domain','requestauthor','domconfig','server');
5916: } else {
5917: @posscontexts = ('any','author','domain');
5918: }
5919: foreach my $chgtype (@posscontexts) {
1.239 raeburn 5920: my $selstr = '';
5921: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 5922: $selstr = ' selected="selected"';
1.239 raeburn 5923: }
1.363 raeburn 5924: if ($context eq 'course') {
5925: if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) {
5926: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
5927: }
1.239 raeburn 5928: }
5929: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 5930: }
1.303 bisitz 5931: $output .= '</select></td>'
5932: .'</tr></table>';
5933:
5934: # Update Display button
5935: $output .= '<p>'
5936: .'<input type="submit" value="'.&mt('Update Display').'" />'
5937: .'</p>';
5938:
5939: # Server version info
1.363 raeburn 5940: my $needsrev = '2.11.0';
5941: if ($context eq 'course') {
5942: $needsrev = '2.7.0';
5943: }
5944:
1.303 bisitz 5945: $output .= '<p class="LC_info">'
5946: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 5947: ,$needsrev);
1.248 raeburn 5948: if ($version) {
1.303 bisitz 5949: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
5950: }
5951: $output .= '</p><hr />';
1.239 raeburn 5952: return $output;
5953: }
5954:
5955: sub rolechg_contexts {
1.363 raeburn 5956: my ($context,$crstype) = @_;
5957: my %lt;
5958: if ($context eq 'course') {
5959: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 5960: any => 'Any',
5961: auto => 'Automated enrollment',
5962: updatenow => 'Roster Update',
5963: createcourse => 'Course Creation',
5964: course => 'User Management in course',
5965: domain => 'User Management in domain',
1.313 raeburn 5966: selfenroll => 'Self-enrolled',
1.318 raeburn 5967: requestcourses => 'Course Request',
1.239 raeburn 5968: );
1.363 raeburn 5969: if ($crstype eq 'Community') {
5970: $lt{'createcourse'} = &mt('Community Creation');
5971: $lt{'course'} = &mt('User Management in community');
5972: $lt{'requestcourses'} = &mt('Community Request');
5973: }
5974: } elsif ($context eq 'domain') {
5975: %lt = &Apache::lonlocal::texthash (
5976: any => 'Any',
5977: domain => 'User Management in domain',
5978: requestauthor => 'Authoring Request',
5979: server => 'Command line script (DC role)',
5980: domconfig => 'Self-enrolled',
5981: );
5982: } else {
5983: %lt = &Apache::lonlocal::texthash (
5984: any => 'Any',
5985: domain => 'User Management in domain',
5986: author => 'User Management by author',
5987: );
5988: }
1.239 raeburn 5989: return %lt;
5990: }
5991:
1.27 matthew 5992: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 5993: sub user_search_result {
1.221 raeburn 5994: my ($context,$srch) = @_;
1.160 raeburn 5995: my %allhomes;
5996: my %inst_matches;
5997: my %srch_results;
1.181 raeburn 5998: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 5999: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 6000: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 6001: $response = &mt('Invalid search.');
6002: }
6003: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
6004: $response = &mt('Invalid search.');
6005: }
1.177 raeburn 6006: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 6007: $response = &mt('Invalid search.');
6008: }
6009: if ($srch->{'srchterm'} eq '') {
6010: $response = &mt('You must enter a search term.');
6011: }
1.183 raeburn 6012: if ($srch->{'srchterm'} =~ /^\s+$/) {
6013: $response = &mt('Your search term must contain more than just spaces.');
6014: }
1.160 raeburn 6015: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
6016: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 6017: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 6018: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
6019: }
6020: }
6021: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
6022: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 6023: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 6024: my $unamecheck = $srch->{'srchterm'};
6025: if ($srch->{'srchtype'} eq 'contains') {
6026: if ($unamecheck !~ /^\w/) {
6027: $unamecheck = 'a'.$unamecheck;
6028: }
6029: }
6030: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 6031: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
6032: }
1.160 raeburn 6033: }
6034: }
1.180 raeburn 6035: if ($response ne '') {
6036: $response = '<span class="LC_warning">'.$response.'</span>';
6037: }
1.160 raeburn 6038: if ($srch->{'srchin'} eq 'instd') {
6039: my $instd_chk = &directorysrch_check($srch);
6040: if ($instd_chk ne 'ok') {
1.180 raeburn 6041: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
6042: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 6043: }
6044: }
6045: if ($response ne '') {
1.180 raeburn 6046: return ($currstate,$response);
1.160 raeburn 6047: }
6048: if ($srch->{'srchby'} eq 'uname') {
6049: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
6050: if ($env{'form.forcenew'}) {
6051: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
6052: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6053: if ($uhome eq 'no_host') {
6054: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 6055: my $showdom = &display_domain_info($env{'request.role.domain'});
6056: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 6057: } else {
1.179 raeburn 6058: $currstate = 'modify';
1.160 raeburn 6059: }
6060: } else {
1.179 raeburn 6061: $currstate = 'modify';
1.160 raeburn 6062: }
6063: } else {
6064: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 6065: if ($srch->{'srchtype'} eq 'exact') {
6066: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
6067: if ($uhome eq 'no_host') {
1.179 raeburn 6068: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6069: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6070: } else {
1.179 raeburn 6071: $currstate = 'modify';
1.310 raeburn 6072: my $uname = $srch->{'srchterm'};
6073: my $udom = $srch->{'srchdomain'};
6074: $srch_results{$uname.':'.$udom} =
6075: { &Apache::lonnet::get('environment',
6076: ['firstname',
6077: 'lastname',
6078: 'permanentemail'],
6079: $udom,$uname)
6080: };
1.162 raeburn 6081: }
6082: } else {
6083: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6084: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6085: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6086: }
6087: } else {
1.167 albertel 6088: my $courseusers = &get_courseusers();
1.162 raeburn 6089: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 6090: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 6091: $currstate = 'modify';
1.162 raeburn 6092: } else {
1.179 raeburn 6093: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6094: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 6095: }
1.160 raeburn 6096: } else {
1.167 albertel 6097: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 6098: my ($cuname,$cudomain) = split(/:/,$user);
6099: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 6100: my $matched = 0;
6101: if ($srch->{'srchtype'} eq 'begins') {
6102: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
6103: $matched = 1;
6104: }
6105: } else {
6106: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
6107: $matched = 1;
6108: }
6109: }
6110: if ($matched) {
1.167 albertel 6111: $srch_results{$user} =
6112: {&Apache::lonnet::get('environment',
6113: ['firstname',
6114: 'lastname',
1.194 albertel 6115: 'permanentemail'],
6116: $cudomain,$cuname)};
1.162 raeburn 6117: }
6118: }
6119: }
1.179 raeburn 6120: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6121: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6122: }
6123: }
6124: }
6125: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6126: $currstate = 'query';
1.160 raeburn 6127: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6128: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6129: if ($dirsrchres eq 'ok') {
6130: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6131: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6132: } else {
6133: my $showdom = &display_domain_info($srch->{'srchdomain'});
6134: $response = '<span class="LC_warning">'.
6135: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6136: '</span><br />'.
6137: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6138: '<br /><br />';
6139: }
1.160 raeburn 6140: }
6141: } else {
6142: if ($srch->{'srchin'} eq 'dom') {
6143: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 6144: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6145: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6146: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 6147: my $courseusers = &get_courseusers();
6148: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 6149: my ($uname,$udom) = split(/:/,$user);
6150: my %names = &Apache::loncommon::getnames($uname,$udom);
6151: my %emails = &Apache::loncommon::getemails($uname,$udom);
6152: if ($srch->{'srchby'} eq 'lastname') {
6153: if ((($srch->{'srchtype'} eq 'exact') &&
6154: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 6155: (($srch->{'srchtype'} eq 'begins') &&
6156: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 6157: (($srch->{'srchtype'} eq 'contains') &&
6158: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
6159: $srch_results{$user} = {firstname => $names{'firstname'},
6160: lastname => $names{'lastname'},
6161: permanentemail => $emails{'permanentemail'},
6162: };
6163: }
6164: } elsif ($srch->{'srchby'} eq 'lastfirst') {
6165: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 6166: $srchlast =~ s/\s+$//;
6167: $srchfirst =~ s/^\s+//;
1.160 raeburn 6168: if ($srch->{'srchtype'} eq 'exact') {
6169: if (($names{'lastname'} eq $srchlast) &&
6170: ($names{'firstname'} eq $srchfirst)) {
6171: $srch_results{$user} = {firstname => $names{'firstname'},
6172: lastname => $names{'lastname'},
6173: permanentemail => $emails{'permanentemail'},
6174:
6175: };
6176: }
1.177 raeburn 6177: } elsif ($srch->{'srchtype'} eq 'begins') {
6178: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
6179: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
6180: $srch_results{$user} = {firstname => $names{'firstname'},
6181: lastname => $names{'lastname'},
6182: permanentemail => $emails{'permanentemail'},
6183: };
6184: }
6185: } else {
1.160 raeburn 6186: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
6187: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
6188: $srch_results{$user} = {firstname => $names{'firstname'},
6189: lastname => $names{'lastname'},
6190: permanentemail => $emails{'permanentemail'},
6191: };
6192: }
6193: }
6194: }
6195: }
1.179 raeburn 6196: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6197: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 6198: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 6199: $currstate = 'query';
1.160 raeburn 6200: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 6201: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
6202: if ($dirsrchres eq 'ok') {
6203: ($currstate,$response,$forcenewuser) =
1.221 raeburn 6204: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 6205: } else {
6206: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
6207: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
6208: '</span><br />'.
6209: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
6210: '<br /><br />';
6211: }
1.160 raeburn 6212: }
6213: }
1.179 raeburn 6214: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 6215: }
6216:
6217: sub directorysrch_check {
6218: my ($srch) = @_;
6219: my $can_search = 0;
6220: my $response;
6221: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
6222: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 6223: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 6224: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
6225: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 6226: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 6227: }
6228: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
6229: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 6230: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 6231: }
6232: my @usertypes = split(/:/,$env{'environment.inststatus'});
6233: if (!@usertypes) {
6234: push(@usertypes,'default');
6235: }
6236: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
6237: foreach my $type (@usertypes) {
6238: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
6239: $can_search = 1;
6240: last;
6241: }
6242: }
6243: }
6244: if (!$can_search) {
6245: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
6246: my @longtypes;
6247: foreach my $item (@usertypes) {
1.229 raeburn 6248: if (defined($insttypes->{$item})) {
6249: push (@longtypes,$insttypes->{$item});
6250: } elsif ($item eq 'default') {
6251: push (@longtypes,&mt('other'));
6252: }
1.160 raeburn 6253: }
6254: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 6255: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 6256: }
1.160 raeburn 6257: } else {
6258: $can_search = 1;
6259: }
6260: } else {
1.180 raeburn 6261: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 6262: }
6263: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 6264: uname => 'username',
1.160 raeburn 6265: lastfirst => 'last name, first name',
1.167 albertel 6266: lastname => 'last name',
1.172 raeburn 6267: contains => 'contains',
1.178 raeburn 6268: exact => 'as exact match to',
6269: begins => 'begins with',
1.160 raeburn 6270: );
6271: if ($can_search) {
6272: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
6273: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 6274: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 6275: }
6276: } else {
1.180 raeburn 6277: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 6278: }
6279: }
6280: if ($can_search) {
1.178 raeburn 6281: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
6282: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
6283: return 'ok';
6284: } else {
1.180 raeburn 6285: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 6286: }
6287: } else {
6288: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
6289: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
6290: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
6291: return 'ok';
6292: } else {
1.180 raeburn 6293: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 6294: }
1.160 raeburn 6295: }
6296: }
6297: }
6298:
6299: sub get_courseusers {
6300: my %advhash;
1.167 albertel 6301: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 6302: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
6303: foreach my $role (sort(keys(%coursepersonnel))) {
6304: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 6305: if (!exists($classlist->{$user})) {
6306: $classlist->{$user} = [];
6307: }
1.160 raeburn 6308: }
6309: }
1.167 albertel 6310: return $classlist;
1.160 raeburn 6311: }
6312:
6313: sub build_search_response {
1.221 raeburn 6314: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 6315: my ($currstate,$response,$forcenewuser);
1.160 raeburn 6316: my %names = (
1.330 bisitz 6317: 'uname' => 'username',
6318: 'lastname' => 'last name',
1.160 raeburn 6319: 'lastfirst' => 'last name, first name',
1.330 bisitz 6320: 'crs' => 'this course',
6321: 'dom' => 'LON-CAPA domain',
6322: 'instd' => 'the institutional directory for domain',
1.160 raeburn 6323: );
6324:
6325: my %single = (
1.180 raeburn 6326: begins => 'A match',
1.160 raeburn 6327: contains => 'A match',
1.180 raeburn 6328: exact => 'An exact match',
1.160 raeburn 6329: );
6330: my %nomatch = (
1.180 raeburn 6331: begins => 'No match',
1.160 raeburn 6332: contains => 'No match',
1.180 raeburn 6333: exact => 'No exact match',
1.160 raeburn 6334: );
6335: if (keys(%srch_results) > 1) {
1.179 raeburn 6336: $currstate = 'select';
1.160 raeburn 6337: } else {
6338: if (keys(%srch_results) == 1) {
1.179 raeburn 6339: $currstate = 'modify';
1.180 raeburn 6340: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
6341: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 6342: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 6343: }
1.330 bisitz 6344: } else { # Search has nothing found. Prepare message to user.
6345: $response = '<span class="LC_warning">';
1.180 raeburn 6346: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 6347: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
6348: '<b>'.$srch->{'srchterm'}.'</b>',
6349: &display_domain_info($srch->{'srchdomain'}));
6350: } else {
6351: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
6352: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 6353: }
6354: $response .= '</span>';
1.330 bisitz 6355:
1.160 raeburn 6356: if ($srch->{'srchin'} ne 'alc') {
6357: $forcenewuser = 1;
6358: my $cansrchinst = 0;
6359: if ($srch->{'srchdomain'}) {
6360: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
6361: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6362: if ($domconfig{'directorysrch'}{'available'}) {
6363: $cansrchinst = 1;
6364: }
6365: }
6366: }
1.180 raeburn 6367: if ((($srch->{'srchby'} eq 'lastfirst') ||
6368: ($srch->{'srchby'} eq 'lastname')) &&
6369: ($srch->{'srchin'} eq 'dom')) {
6370: if ($cansrchinst) {
6371: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 6372: }
6373: }
1.180 raeburn 6374: if ($srch->{'srchin'} eq 'crs') {
6375: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
6376: }
6377: }
1.305 raeburn 6378: my $createdom = $env{'request.role.domain'};
6379: if ($context eq 'requestcrs') {
6380: if ($env{'form.coursedom'} ne '') {
6381: $createdom = $env{'form.coursedom'};
6382: }
6383: }
6384: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $createdom)) {
1.221 raeburn 6385: my $cancreate =
1.305 raeburn 6386: &Apache::lonuserutils::can_create_user($createdom,$context);
6387: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 6388: if ($cancreate) {
1.305 raeburn 6389: my $showdom = &display_domain_info($createdom);
1.266 bisitz 6390: $response .= '<br /><br />'
6391: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 6392: .'<br />';
6393: if ($context eq 'requestcrs') {
6394: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
6395: } else {
6396: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
6397: }
6398: $response .='<ul><li>'
1.266 bisitz 6399: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
6400: .'</li><li>'
6401: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
6402: .'</li><li>'
6403: .&mt('Provide the proposed username')
6404: .'</li><li>'
6405: .&mt("Click 'Search'")
6406: .'</li></ul><br />';
1.221 raeburn 6407: } else {
6408: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.305 raeburn 6409: $response .= '<br /><br />';
6410: if ($context eq 'requestcrs') {
1.314 raeburn 6411: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.305 raeburn 6412: } else {
6413: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
6414: }
6415: $response .= '<br />'
6416: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 6417: ,' <a'.$helplink.'>'
6418: ,'</a>')
1.305 raeburn 6419: .'<br /><br />';
1.221 raeburn 6420: }
1.160 raeburn 6421: }
6422: }
6423: }
1.179 raeburn 6424: return ($currstate,$response,$forcenewuser);
1.160 raeburn 6425: }
6426:
1.180 raeburn 6427: sub display_domain_info {
6428: my ($dom) = @_;
6429: my $output = $dom;
6430: if ($dom ne '') {
6431: my $domdesc = &Apache::lonnet::domain($dom,'description');
6432: if ($domdesc ne '') {
6433: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
6434: }
6435: }
6436: return $output;
6437: }
6438:
1.160 raeburn 6439: sub crumb_utilities {
6440: my %elements = (
6441: crtuser => {
6442: srchterm => 'text',
1.172 raeburn 6443: srchin => 'selectbox',
1.160 raeburn 6444: srchby => 'selectbox',
6445: srchtype => 'selectbox',
6446: srchdomain => 'selectbox',
6447: },
1.207 raeburn 6448: crtusername => {
6449: srchterm => 'text',
6450: srchdomain => 'selectbox',
6451: },
1.160 raeburn 6452: docustom => {
6453: rolename => 'selectbox',
6454: newrolename => 'textbox',
6455: },
1.179 raeburn 6456: studentform => {
6457: srchterm => 'text',
6458: srchin => 'selectbox',
6459: srchby => 'selectbox',
6460: srchtype => 'selectbox',
6461: srchdomain => 'selectbox',
6462: },
1.160 raeburn 6463: );
6464:
6465: my $jsback .= qq|
6466: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 6467: if (typeof prevphase == 'undefined') {
6468: formname.phase.value = '';
6469: }
6470: else {
6471: formname.phase.value = prevphase;
6472: }
6473: if (typeof prevstate == 'undefined') {
6474: formname.currstate.value = '';
6475: }
6476: else {
6477: formname.currstate.value = prevstate;
6478: }
1.160 raeburn 6479: formname.submit();
6480: }
6481: |;
6482: return ($jsback,\%elements);
6483: }
6484:
1.26 matthew 6485: sub course_level_table {
1.89 raeburn 6486: my (%inccourses) = @_;
1.26 matthew 6487: my $table = '';
1.62 www 6488: # Custom Roles?
6489:
1.190 raeburn 6490: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 6491: my %lt=&Apache::lonlocal::texthash(
6492: 'exs' => "Existing sections",
6493: 'new' => "Define new section",
6494: 'ssd' => "Set Start Date",
6495: 'sed' => "Set End Date",
1.131 raeburn 6496: 'crl' => "Course Level",
1.89 raeburn 6497: 'act' => "Activate",
6498: 'rol' => "Role",
6499: 'ext' => "Extent",
1.113 raeburn 6500: 'grs' => "Section",
1.89 raeburn 6501: 'sta' => "Start",
6502: 'end' => "End"
6503: );
1.62 www 6504:
1.329 raeburn 6505: foreach my $protectedcourse (sort(keys(%inccourses))) {
1.135 raeburn 6506: my $thiscourse=$protectedcourse;
1.26 matthew 6507: $thiscourse=~s:_:/:g;
6508: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 6509: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 6510: my $area=$coursedata{'description'};
1.321 raeburn 6511: my $crstype=$coursedata{'type'};
1.135 raeburn 6512: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 6513: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 6514: my %sections_count;
1.101 albertel 6515: if (defined($env{'request.course.id'})) {
6516: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 6517: %sections_count =
6518: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 6519: }
6520: }
1.321 raeburn 6521: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 6522: foreach my $role (@roles) {
1.321 raeburn 6523: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 6524: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
6525: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 6526: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.329 raeburn 6527: $plrole,\%sections_count,\%lt);
1.221 raeburn 6528: } elsif ($env{'request.course.sec'} ne '') {
6529: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
6530: $env{'request.course.sec'})) {
6531: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
6532: $plrole,\%sections_count,\%lt);
1.26 matthew 6533: }
6534: }
6535: }
1.221 raeburn 6536: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 6537: foreach my $cust (sort(keys(%customroles))) {
6538: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 6539: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
6540: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
6541: $cust,\%sections_count,\%lt);
6542: }
1.62 www 6543: }
1.26 matthew 6544: }
6545: return '' if ($table eq ''); # return nothing if there is nothing
6546: # in the table
1.188 raeburn 6547: my $result;
6548: if (!$env{'request.course.id'}) {
6549: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
6550: }
6551: $result .=
1.136 raeburn 6552: &Apache::loncommon::start_data_table().
6553: &Apache::loncommon::start_data_table_header_row().
6554: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
6555: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
6556: &Apache::loncommon::end_data_table_header_row().
6557: $table.
6558: &Apache::loncommon::end_data_table();
1.26 matthew 6559: return $result;
6560: }
1.88 raeburn 6561:
1.221 raeburn 6562: sub course_level_row {
6563: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_;
1.222 raeburn 6564: my $row = &Apache::loncommon::start_data_table_row().
6565: ' <td><input type="checkbox" name="act_'.
6566: $protectedcourse.'_'.$role.'" /></td>'."\n".
6567: ' <td>'.$plrole.'</td>'."\n".
6568: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.322 raeburn 6569: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 6570: $row .= '<td> </td>';
1.221 raeburn 6571: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 6572: $row .= ' <td><input type="hidden" value="'.
6573: $env{'request.course.sec'}.'" '.
6574: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
6575: $env{'request.course.sec'}.'</td>';
1.221 raeburn 6576: } else {
6577: if (ref($sections_count) eq 'HASH') {
6578: my $currsec =
6579: &Apache::lonuserutils::course_sections($sections_count,
6580: $protectedcourse.'_'.$role);
1.222 raeburn 6581: $row .= '<td><table class="LC_createuser">'."\n".
6582: '<tr class="LC_section_row">'."\n".
6583: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
6584: $currsec.'</td>'."\n".
6585: ' <td> </td>'."\n".
6586: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 6587: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
6588: '" value="" />'.
6589: '<input type="hidden" '.
6590: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 6591: '</tr></table></td>'."\n";
1.221 raeburn 6592: } else {
1.222 raeburn 6593: $row .= '<td><input type="text" size="10" '.
6594: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 6595: }
6596: }
1.222 raeburn 6597: $row .= <<ENDTIMEENTRY;
6598: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 6599: <a href=
6600: "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 6601: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 6602: <a href=
6603: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
6604: ENDTIMEENTRY
1.222 raeburn 6605: $row .= &Apache::loncommon::end_data_table_row();
6606: return $row;
1.221 raeburn 6607: }
6608:
1.88 raeburn 6609: sub course_level_dc {
6610: my ($dcdom) = @_;
1.190 raeburn 6611: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 6612: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 6613: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
6614: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 6615: '<input type="hidden" name="dccourse" value="" />';
1.355 www 6616: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 6617: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.323 raeburn 6618: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser');
1.88 raeburn 6619: my %lt=&Apache::lonlocal::texthash(
6620: 'rol' => "Role",
1.113 raeburn 6621: 'grs' => "Section",
1.88 raeburn 6622: 'exs' => "Existing sections",
6623: 'new' => "Define new section",
6624: 'sta' => "Start",
6625: 'end' => "End",
6626: 'ssd' => "Set Start Date",
1.355 www 6627: 'sed' => "Set End Date",
6628: 'scc' => "Course/Community"
1.88 raeburn 6629: );
1.323 raeburn 6630: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 6631: &Apache::loncommon::start_data_table().
6632: &Apache::loncommon::start_data_table_header_row().
1.355 www 6633: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 6634: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 6635: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 6636: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
6637: $courseform.(' ' x4).'</span></td>'."\n".
1.323 raeburn 6638: '<td valign><br /><select name="role">'."\n";
1.213 raeburn 6639: foreach my $role (@roles) {
1.135 raeburn 6640: my $plrole=&Apache::lonnet::plaintext($role);
6641: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 6642: }
6643: if ( keys %customroles > 0) {
1.135 raeburn 6644: foreach my $cust (sort keys %customroles) {
1.101 albertel 6645: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 6646: '_'.$env{'user.name'}.'_'.$cust;
6647: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 6648: }
6649: }
6650: $otheritems .= '</select></td><td>'.
6651: '<table border="0" cellspacing="0" cellpadding="0">'.
6652: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
6653: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
6654: '<td> </td>'.
6655: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 6656: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 6657: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 6658: '<input type="hidden" name="groups" value="" />'.
6659: '<input type="hidden" name="crstype" value="" /></td>'.
1.88 raeburn 6660: '</tr></table></td>';
6661: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 6662: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 6663: <a href=
6664: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 6665: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 6666: <a href=
6667: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
6668: ENDTIMEENTRY
1.136 raeburn 6669: $otheritems .= &Apache::loncommon::end_data_table_row().
6670: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 6671: return $cb_jscript.$header.$hiddenitems.$otheritems;
6672: }
6673:
1.237 raeburn 6674: sub update_selfenroll_config {
1.241 raeburn 6675: my ($r,$context,$permission) = @_;
1.237 raeburn 6676: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 6677: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 6678: my (%changes,%warning);
6679: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6680: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 6681: my $curr_types;
1.237 raeburn 6682: if (ref($row) eq 'ARRAY') {
6683: foreach my $item (@{$row}) {
6684: if ($item eq 'enroll_dates') {
6685: my (%currenrolldate,%newenrolldate);
6686: foreach my $type ('start','end') {
6687: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
6688: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
6689: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
6690: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
6691: }
6692: }
6693: } elsif ($item eq 'access_dates') {
6694: my (%currdate,%newdate);
6695: foreach my $type ('start','end') {
6696: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
6697: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
6698: if ($newdate{$type} ne $currdate{$type}) {
6699: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
6700: }
6701: }
1.241 raeburn 6702: } elsif ($item eq 'types') {
6703: $curr_types =
6704: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
6705: if ($env{'form.selfenroll_all'}) {
6706: if ($curr_types ne '*') {
6707: $changes{'internal.selfenroll_types'} = '*';
6708: } else {
6709: next;
6710: }
6711: } else {
1.249 raeburn 6712: my %currdoms;
1.241 raeburn 6713: my @entries = split(/;/,$curr_types);
6714: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 6715: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 6716: my $newnum = 0;
1.249 raeburn 6717: my @latesttypes;
6718: foreach my $num (@activations) {
6719: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
6720: if (@types > 0) {
1.241 raeburn 6721: @types = sort(@types);
6722: my $typestr = join(',',@types);
1.249 raeburn 6723: my $typedom = $env{'form.selfenroll_dom_'.$num};
6724: $latesttypes[$newnum] = $typedom.':'.$typestr;
6725: $currdoms{$typedom} = 1;
1.241 raeburn 6726: $newnum ++;
6727: }
6728: }
1.338 raeburn 6729: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
6730: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 6731: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
6732: if (@types > 0) {
6733: @types = sort(@types);
6734: my $typestr = join(',',@types);
6735: my $typedom = $env{'form.selfenroll_dom_'.$j};
6736: $latesttypes[$newnum] = $typedom.':'.$typestr;
6737: $currdoms{$typedom} = 1;
6738: $newnum ++;
6739: }
6740: }
6741: }
6742: if ($env{'form.selfenroll_newdom'} ne '') {
6743: my $typedom = $env{'form.selfenroll_newdom'};
6744: if ((!defined($currdoms{$typedom})) &&
6745: (&Apache::lonnet::domain($typedom) ne '')) {
6746: my $typestr;
6747: my ($othertitle,$usertypes,$types) =
6748: &Apache::loncommon::sorted_inst_types($typedom);
6749: my $othervalue = 'any';
6750: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6751: if (@{$types} > 0) {
1.257 raeburn 6752: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 6753: $othervalue = 'other';
1.258 raeburn 6754: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 6755: }
6756: $typestr = $othervalue;
6757: } else {
6758: $typestr = $othervalue;
6759: }
6760: $latesttypes[$newnum] = $typedom.':'.$typestr;
6761: $newnum ++ ;
6762: }
6763: }
1.241 raeburn 6764: my $selfenroll_types = join(';',@latesttypes);
6765: if ($selfenroll_types ne $curr_types) {
6766: $changes{'internal.selfenroll_types'} = $selfenroll_types;
6767: }
6768: }
1.276 raeburn 6769: } elsif ($item eq 'limit') {
6770: my $newlimit = $env{'form.selfenroll_limit'};
6771: my $newcap = $env{'form.selfenroll_cap'};
6772: $newcap =~s/\s+//g;
6773: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
6774: $currlimit = 'none' if ($currlimit eq '');
6775: my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
6776: if ($newlimit ne $currlimit) {
6777: if ($newlimit ne 'none') {
6778: if ($newcap =~ /^\d+$/) {
6779: if ($newcap ne $currcap) {
6780: $changes{'internal.selfenroll_cap'} = $newcap;
6781: }
6782: $changes{'internal.selfenroll_limit'} = $newlimit;
6783: } else {
6784: $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.');
6785: }
6786: } elsif ($currcap ne '') {
6787: $changes{'internal.selfenroll_cap'} = '';
6788: $changes{'internal.selfenroll_limit'} = $newlimit;
6789: }
6790: } elsif ($currlimit ne 'none') {
6791: if ($newcap =~ /^\d+$/) {
6792: if ($newcap ne $currcap) {
6793: $changes{'internal.selfenroll_cap'} = $newcap;
6794: }
6795: } else {
6796: $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.');
6797: }
6798: }
6799: } elsif ($item eq 'approval') {
6800: my (@currnotified,@newnotified);
6801: my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
6802: my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
6803: if ($currnotifylist ne '') {
6804: @currnotified = split(/,/,$currnotifylist);
6805: @currnotified = sort(@currnotified);
6806: }
6807: my $newapproval = $env{'form.selfenroll_approval'};
6808: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
6809: @newnotified = sort(@newnotified);
6810: if ($newapproval ne $currapproval) {
6811: $changes{'internal.selfenroll_approval'} = $newapproval;
6812: if (!$newapproval) {
6813: if ($currnotifylist ne '') {
6814: $changes{'internal.selfenroll_notifylist'} = '';
6815: }
6816: } else {
6817: my @differences =
1.295 raeburn 6818: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 6819: if (@differences > 0) {
6820: if (@newnotified > 0) {
6821: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6822: } else {
6823: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6824: }
6825: }
6826: }
6827: } else {
1.295 raeburn 6828: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 6829: if (@differences > 0) {
6830: if (@newnotified > 0) {
6831: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6832: } else {
6833: $changes{'internal.selfenroll_notifylist'} = '';
6834: }
6835: }
6836: }
1.237 raeburn 6837: } else {
6838: my $curr_val =
6839: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
6840: my $newval = $env{'form.selfenroll_'.$item};
6841: if ($item eq 'section') {
6842: $newval = $env{'form.sections'};
1.241 raeburn 6843: if (defined($curr_groups{$newval})) {
1.237 raeburn 6844: $newval = $curr_val;
6845: $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');
6846: } elsif ($newval eq 'all') {
6847: $newval = $curr_val;
1.274 bisitz 6848: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 6849: }
6850: if ($newval eq '') {
6851: $newval = 'none';
6852: }
6853: }
6854: if ($newval ne $curr_val) {
6855: $changes{'internal.selfenroll_'.$item} = $newval;
6856: }
1.241 raeburn 6857: }
1.237 raeburn 6858: }
6859: if (keys(%warning) > 0) {
6860: foreach my $item (@{$row}) {
6861: if (exists($warning{$item})) {
6862: $r->print($warning{$item}.'<br />');
6863: }
6864: }
6865: }
6866: if (keys(%changes) > 0) {
6867: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
6868: if ($putresult eq 'ok') {
6869: if ((exists($changes{'internal.selfenroll_types'})) ||
6870: (exists($changes{'internal.selfenroll_start_date'})) ||
6871: (exists($changes{'internal.selfenroll_end_date'}))) {
6872: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
6873: $cnum,undef,undef,'Course');
6874: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
6875: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
6876: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
6877: if (exists($changes{'internal.'.$item})) {
6878: $crsinfo{$env{'request.course.id'}}{$item} =
6879: $changes{'internal.'.$item};
6880: }
6881: }
6882: my $crsputresult =
6883: &Apache::lonnet::courseidput($cdom,\%crsinfo,
6884: $chome,'notime');
6885: }
6886: }
6887: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
6888: foreach my $item (@{$row}) {
6889: my $title = $item;
6890: if (ref($lt) eq 'HASH') {
6891: $title = $lt->{$item};
6892: }
6893: if ($item eq 'enroll_dates') {
6894: foreach my $type ('start','end') {
6895: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
6896: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 6897: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 6898: $title,$type,$newdate).'</li>');
6899: }
6900: }
6901: } elsif ($item eq 'access_dates') {
6902: foreach my $type ('start','end') {
6903: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
6904: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 6905: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 6906: $title,$type,$newdate).'</li>');
6907: }
6908: }
1.276 raeburn 6909: } elsif ($item eq 'limit') {
6910: if ((exists($changes{'internal.selfenroll_limit'})) ||
6911: (exists($changes{'internal.selfenroll_cap'}))) {
6912: my ($newval,$newcap);
6913: if ($changes{'internal.selfenroll_cap'} ne '') {
6914: $newcap = $changes{'internal.selfenroll_cap'}
6915: } else {
6916: $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
6917: }
6918: if ($changes{'internal.selfenroll_limit'} eq 'none') {
6919: $newval = &mt('No limit');
6920: } elsif ($changes{'internal.selfenroll_limit'} eq
6921: 'allstudents') {
6922: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
6923: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
6924: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
6925: } else {
6926: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
6927: if ($currlimit eq 'allstudents') {
6928: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
6929: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 6930: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 6931: }
6932: }
6933: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
6934: }
6935: } elsif ($item eq 'approval') {
6936: if ((exists($changes{'internal.selfenroll_approval'})) ||
6937: (exists($changes{'internal.selfenroll_notifylist'}))) {
6938: my ($newval,$newnotify);
6939: if (exists($changes{'internal.selfenroll_notifylist'})) {
6940: $newnotify = $changes{'internal.selfenroll_notifylist'};
6941: } else {
6942: $newnotify = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
6943: }
6944: if ($changes{'internal.selfenroll_approval'}) {
6945: $newval = &mt('Yes');
6946: } elsif ($changes{'internal.selfenroll_approval'} eq '0') {
6947: $newval = &mt('No');
6948: } else {
6949: my $currapproval =
6950: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
6951: if ($currapproval) {
6952: $newval = &mt('Yes');
6953: } else {
6954: $newval = &mt('No');
6955: }
6956: }
6957: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
6958: if ($newnotify) {
1.277 raeburn 6959: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 6960: } else {
1.277 raeburn 6961: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 6962: }
6963: $r->print('</li>'."\n");
6964: }
1.237 raeburn 6965: } else {
6966: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 6967: my $newval = $changes{'internal.selfenroll_'.$item};
6968: if ($item eq 'types') {
6969: if ($newval eq '') {
6970: $newval = &mt('None');
6971: } elsif ($newval eq '*') {
6972: $newval = &mt('Any user in any domain');
6973: }
1.245 raeburn 6974: } elsif ($item eq 'registered') {
6975: if ($newval eq '1') {
6976: $newval = &mt('Yes');
6977: } elsif ($newval eq '0') {
6978: $newval = &mt('No');
6979: }
1.241 raeburn 6980: }
1.244 bisitz 6981: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 6982: }
6983: }
6984: }
6985: $r->print('</ul>');
6986: my %newenvhash;
6987: foreach my $key (keys(%changes)) {
6988: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
6989: }
1.238 raeburn 6990: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 6991: } else {
6992: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
6993: }
6994: } else {
1.249 raeburn 6995: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 6996: }
6997: } else {
1.249 raeburn 6998: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 6999: }
1.256 raeburn 7000: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
7001: if (ref($visactions) eq 'HASH') {
7002: if (!$visible) {
1.366 bisitz 7003: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.256 raeburn 7004: '<br />');
7005: if (ref($vismsgs) eq 'ARRAY') {
7006: $r->print('<br />'.$visactions->{'take'}.'<ul>');
7007: foreach my $item (@{$vismsgs}) {
7008: $r->print('<li>'.$visactions->{$item}.'</li>');
7009: }
7010: $r->print('</ul>');
7011: }
7012: $r->print($cansetvis);
7013: }
7014: }
1.237 raeburn 7015: return;
7016: }
7017:
7018: sub get_selfenroll_titles {
1.276 raeburn 7019: my @row = ('types','registered','enroll_dates','access_dates','section',
7020: 'approval','limit');
1.237 raeburn 7021: my %lt = &Apache::lonlocal::texthash (
7022: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 7023: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 7024: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 7025: access_dates => 'Course access dates assigned to self-enrolling users',
7026: section => 'Section assigned to self-enrolling users',
1.276 raeburn 7027: approval => 'Self-enrollment requests need approval?',
7028: limit => 'Enrollment limit',
1.237 raeburn 7029: );
7030: return (\@row,\%lt);
7031: }
7032:
1.27 matthew 7033: #---------------------------------------------- end functions for &phase_two
1.29 matthew 7034:
7035: #--------------------------------- functions for &phase_two and &phase_three
7036:
7037: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 7038:
1.1 www 7039: 1;
7040: __END__
1.2 www 7041:
7042:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>