Annotation of loncom/interface/loncreateuser.pm, revision 1.295.2.22
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.295.2.22! raeburn 4: # $Id: loncreateuser.pm,v 1.295.2.21 2010/01/19 20:49:41 raeburn Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
54: Creating custom roles can be done by the Domain Coordinator through
55: the Create User functionality. That screen will show all privileges
56: that can be assigned to users. For a complete list of privileges,
57: please see C</home/httpd/lonTabs/rolesplain.tab>.
58:
59: Custom role definitions are stored in the C<roles.db> file of the role
60: author.
61:
62: =cut
1.1 www 63:
64: use strict;
65: use Apache::Constants qw(:common :http);
66: use Apache::lonnet;
1.54 bowersj2 67: use Apache::loncommon;
1.68 www 68: use Apache::lonlocal;
1.117 raeburn 69: use Apache::longroup;
1.190 raeburn 70: use Apache::lonuserutils;
1.295.2.7 raeburn 71: use Apache::loncoursequeueadmin;
1.139 albertel 72: use LONCAPA qw(:DEFAULT :match);
1.1 www 73:
1.20 harris41 74: my $loginscript; # piece of javascript used in two separate instances
75: my $authformnop;
76: my $authformkrb;
77: my $authformint;
78: my $authformfsys;
79: my $authformloc;
80:
1.94 matthew 81: sub initialize_authen_forms {
1.227 raeburn 82: my ($dom,$formname,$curr_authtype,$mode) = @_;
83: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
84: my %param = ( formname => $formname,
1.187 raeburn 85: kerb_def_dom => $krbdefdom,
1.227 raeburn 86: kerb_def_auth => $krbdef,
1.187 raeburn 87: domain => $dom,
88: );
1.188 raeburn 89: my %abv_auth = &auth_abbrev();
1.227 raeburn 90: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 91: my $long_auth = $1;
1.227 raeburn 92: my $curr_autharg = $2;
1.188 raeburn 93: my %abv_auth = &auth_abbrev();
94: $param{'curr_authtype'} = $abv_auth{$long_auth};
95: if ($long_auth =~ /^krb(4|5)$/) {
96: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 97: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 98: }
1.205 raeburn 99: if ($mode eq 'modifyuser') {
100: $param{'mode'} = $mode;
101: }
1.187 raeburn 102: }
1.227 raeburn 103: $loginscript = &Apache::loncommon::authform_header(%param);
104: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 105: $authformnop = &Apache::loncommon::authform_nochange(%param);
106: $authformint = &Apache::loncommon::authform_internal(%param);
107: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
108: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 109: }
110:
1.188 raeburn 111: sub auth_abbrev {
112: my %abv_auth = (
1.295.2.12 raeburn 113: krb5 => 'krb',
1.188 raeburn 114: krb4 => 'krb',
115: internal => 'int',
116: localuth => 'loc',
117: unix => 'fsys',
118: );
119: return %abv_auth;
120: }
1.43 www 121:
1.134 raeburn 122: # ====================================================
123:
124: sub portfolio_quota {
125: my ($ccuname,$ccdomain) = @_;
126: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 127: 'usrt' => "User Tools",
128: 'disk' => "Disk space allocated to user's portfolio files",
129: 'cuqu' => "Current quota",
130: 'cust' => "Custom quota",
131: 'defa' => "Default",
132: 'chqu' => "Change quota",
1.134 raeburn 133: );
1.149 raeburn 134: my ($currquota,$quotatype,$inststatus,$defquota) =
135: &Apache::loncommon::get_user_quota($ccuname,$ccdomain);
136: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
137: my ($longinsttype,$showquota,$custom_on,$custom_off,$defaultinfo);
138: if ($inststatus ne '') {
139: if ($usertypes->{$inststatus} ne '') {
140: $longinsttype = $usertypes->{$inststatus};
141: }
142: }
143: $custom_on = ' ';
144: $custom_off = ' checked="checked" ';
145: my $quota_javascript = <<"END_SCRIPT";
146: <script type="text/javascript">
1.295.2.4 raeburn 147: // <![CDATA[
1.149 raeburn 148: function quota_changes(caller) {
149: if (caller == "custom") {
150: if (document.cu.customquota[0].checked) {
151: document.cu.portfolioquota.value = "";
152: }
153: }
154: if (caller == "quota") {
155: document.cu.customquota[1].checked = true;
156: }
157: }
1.295.2.4 raeburn 158: // ]]>
1.149 raeburn 159: </script>
160: END_SCRIPT
161: if ($quotatype eq 'custom') {
162: $custom_on = $custom_off;
163: $custom_off = ' ';
164: $showquota = $currquota;
165: if ($longinsttype eq '') {
1.230 bisitz 166: $defaultinfo = &mt('For this user, the default quota would be [_1]'
167: .' Mb.',$defquota);
1.149 raeburn 168: } else {
1.231 raeburn 169: $defaultinfo = &mt("For this user, the default quota would be [_1]".
170: " Mb, as determined by the user's institutional".
171: " affiliation ([_2]).",$defquota,$longinsttype);
1.149 raeburn 172: }
173: } else {
174: if ($longinsttype eq '') {
1.230 bisitz 175: $defaultinfo = &mt('For this user, the default quota is [_1]'
176: .' Mb.',$defquota);
1.149 raeburn 177: } else {
1.231 raeburn 178: $defaultinfo = &mt("For this user, the default quota of [_1]".
179: " Mb, is determined by the user's institutional".
180: " affiliation ([_2]).",$defquota,$longinsttype);
1.149 raeburn 181: }
182: }
1.267 raeburn 183:
184: my $output = $quota_javascript."\n".
185: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
186: &Apache::loncommon::start_data_table();
187:
188: if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1.275 raeburn 189: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 190: }
191: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
192: $output .= '<tr class="LC_info_row">'."\n".
193: ' <td>'.$lt{'disk'}.'</td>'."\n".
194: ' </tr>'."\n".
195: &Apache::loncommon::start_data_table_row()."\n".
196: ' <td>'.$lt{'cuqu'}.': '.
197: $currquota.' Mb. '.
198: $defaultinfo.'</td>'."\n".
199: &Apache::loncommon::end_data_table_row()."\n".
200: &Apache::loncommon::start_data_table_row()."\n".
201: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
202: ': <label>'.
203: '<input type="radio" name="customquota" value="0" '.
204: $custom_off.' onchange="javascript:quota_changes('."'custom'".')"'.
205: ' />'.$lt{'defa'}.' ('.$defquota.' Mb).</label> '.
206: ' <label><input type="radio" name="customquota" value="1" '.
207: $custom_on.' onchange="javascript:quota_changes('."'custom'".')" />'.
208: $lt{'cust'}.':</label> '.
209: '<input type="text" name="portfolioquota" size ="5" value="'.
210: $showquota.'" onfocus="javascript:quota_changes('."'quota'".')" '.
211: '/> Mb</span></td>'."\n".
212: &Apache::loncommon::end_data_table_row()."\n";
213: }
214: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 215: return $output;
216: }
217:
1.275 raeburn 218: sub build_tools_display {
219: my ($ccuname,$ccdomain,$context) = @_;
1.295.2.7 raeburn 220: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
221: $colspan);
1.275 raeburn 222: my %lt = &Apache::lonlocal::texthash (
223: 'blog' => "Personal User Blog",
224: 'aboutme' => "Personal Information Page",
225: 'portfolio' => "Personal User Portfolio",
226: 'avai' => "Available",
227: 'cusa' => "availability",
228: 'chse' => "Change setting",
229: 'usde' => "Use default",
230: 'uscu' => "Use custom",
231: 'official' => 'Can request creation of official courses',
1.295.2.14 raeburn 232: 'unofficial' => 'Can request creation of unofficial courses',
1.275 raeburn 233: );
1.279 raeburn 234: if ($context eq 'requestcourses') {
1.275 raeburn 235: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.279 raeburn 236: 'requestcourses.official','requestcourses.unofficial');
1.275 raeburn 237: @usertools = ('official','unofficial');
1.295.2.10 raeburn 238: @options =('norequest','approval','autolimit','validate');
1.295.2.7 raeburn 239: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
240: %reqtitles = &courserequest_titles();
241: %reqdisplay = &courserequest_display();
242: $colspan = ' colspan="2"';
1.275 raeburn 243: } else {
244: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
245: 'tools.aboutme','tools.portfolio','tools.blog');
246: @usertools = ('aboutme','blog','portfolio');
247: }
248: foreach my $item (@usertools) {
1.295.2.7 raeburn 249: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
250: $currdisp,$custdisp,$custradio);
1.275 raeburn 251: $cust_off = 'checked="checked" ';
252: $tool_on = 'checked="checked" ';
253: $curr_access =
254: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
255: $context);
1.295.2.7 raeburn 256: if ($userenv{$context.'.'.$item} ne '') {
1.275 raeburn 257: $cust_on = ' checked="checked" ';
258: $cust_off = '';
1.295.2.7 raeburn 259: }
260: if ($context eq 'requestcourses') {
261: if ($userenv{$context.'.'.$item} eq '') {
262: $custom_access = &mt('Currently from default setting.');
263: } else {
264: $custom_access = &mt('Currently from custom setting.');
265: }
266: } else {
267: if ($userenv{$context.'.'.$item} eq '') {
268: $custom_access =
269: &mt('Availability determined currently from default setting.');
270: if (!$curr_access) {
271: $tool_off = 'checked="checked" ';
272: $tool_on = '';
273: }
274: } else {
275: $custom_access =
276: &mt('Availability determined currently from custom setting.');
277: if ($userenv{$context.'.'.$item} == 0) {
278: $tool_off = 'checked="checked" ';
279: $tool_on = '';
280: }
1.275 raeburn 281: }
282: }
283: $output .= ' <tr class="LC_info_row">'."\n".
1.295.2.7 raeburn 284: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 285: ' </tr>'."\n".
1.295.2.7 raeburn 286: &Apache::loncommon::start_data_table_row()."\n";
287: if ($context eq 'requestcourses') {
288: my ($curroption,$currlimit);
289: $curroption = $userenv{$context.'.'.$item};
290: if (!$curroption) {
291: $curroption = 'norequest';
292: }
293: if ($curroption =~ /^autolimit=(\d*)$/) {
294: $currlimit = $1;
1.295.2.14 raeburn 295: if ($currlimit eq '') {
296: $currdisp = &mt('Yes, automatic creation');
297: } else {
298: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
299: }
1.295.2.7 raeburn 300: } else {
301: $currdisp = $reqdisplay{$curroption};
302: }
303: $custdisp = '<table>';
304: foreach my $option (@options) {
305: my $val = $option;
306: if ($option eq 'norequest') {
307: $val = 0;
308: }
309: if ($option eq 'validate') {
310: my $canvalidate = 0;
311: if (ref($validations{$item}) eq 'HASH') {
312: if ($validations{$item}{'_custom_'}) {
313: $canvalidate = 1;
314: }
315: }
316: next if (!$canvalidate);
317: }
318: my $checked = '';
319: if ($option eq $curroption) {
320: $checked = ' checked="checked"';
321: } elsif ($option eq 'autolimit') {
322: if ($curroption =~ /^autolimit/) {
323: $checked = ' checked="checked"';
324: }
325: }
326: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
327: '<input type="radio" name="crsreq_'.$item.
328: '" value="'.$val.'"'.$checked.' />'.
329: $reqtitles{$option}.'</label> ';
330: if ($option eq 'autolimit') {
331: $custdisp .= '<input type="text" name="crsreq_'.
332: $item.'_limit" size="1" '.
1.295.2.14 raeburn 333: 'value="'.$currlimit.'" /></span><br />'.
334: $reqtitles{'unlimited'};
335: } else {
336: $custdisp .= '</span>';
1.295.2.7 raeburn 337: }
1.295.2.14 raeburn 338: $custdisp .= '</td></tr>';
1.295.2.7 raeburn 339: }
340: $custdisp .= '</table>';
341: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
342: } else {
343: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
344: $custdisp = '<span class="LC_nobreak"><label>'.
345: '<input type="radio" name="'.$context.'_'.$item.'"'.
346: ' value="1"'. $tool_on.'/>'.&mt('On').'</label> <label>'.
347: '<input type="radio" name="'.$context.'_'.$item.'" value="0" '.
348: $tool_off.'/>'.&mt('Off').'</label></span>';
349: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
350: '</span>';
351: }
352: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
353: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.275 raeburn 354: &Apache::loncommon::end_data_table_row()."\n".
355: &Apache::loncommon::start_data_table_row()."\n".
1.295.2.7 raeburn 356: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
357: $lt{'chse'}.': <label>'.
1.275 raeburn 358: '<input type="radio" name="custom'.$item.'" value="0" '.
1.295.2.7 raeburn 359: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
360: '<label><input type="radio" name="custom'.$item.'" value="1" '.
361: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 362: &Apache::loncommon::end_data_table_row()."\n";
363: }
364: return $output;
365: }
366:
1.295.2.3 raeburn 367: sub coursereq_externaluser {
368: my ($ccuname,$ccdomain,$cdom) = @_;
369: my (@usertools,@options,%validations,%userenv,$output);
370: my %lt = &Apache::lonlocal::texthash (
371: 'official' => 'Can request creation of official courses',
372: 'unofficial' => 'Can request creation of unofficial courses',
373: 'community' => 'Can request creation of communities',
374: );
375:
376: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
377: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
378: 'reqcrsotherdom.community');
379: @usertools = ('official','unofficial','community');
1.295.2.10 raeburn 380: @options = ('approval','validate','autolimit');
1.295.2.3 raeburn 381: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
382: my $optregex = join('|',@options);
383: my %reqtitles = &courserequest_titles();
384: foreach my $item (@usertools) {
385: my ($curroption,$currlimit,$tooloff);
386: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
387: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.295.2.14 raeburn 388: foreach my $req (@curr) {
389: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
390: $curroption = $1;
391: $currlimit = $2;
392: last;
1.295.2.3 raeburn 393: }
394: }
1.295.2.14 raeburn 395: if (!$curroption) {
396: $curroption = 'norequest';
397: $tooloff = ' checked="checked"';
398: }
1.295.2.3 raeburn 399: } else {
400: $curroption = 'norequest';
401: $tooloff = ' checked="checked"';
402: }
403: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.295.2.14 raeburn 404: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
405: '<table><tr><td valign="top">'."\n".
1.295.2.3 raeburn 406: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.295.2.14 raeburn 407: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
408: '</label></td>';
1.295.2.3 raeburn 409: foreach my $option (@options) {
410: if ($option eq 'validate') {
411: my $canvalidate = 0;
412: if (ref($validations{$item}) eq 'HASH') {
413: if ($validations{$item}{'_external_'}) {
414: $canvalidate = 1;
415: }
416: }
417: next if (!$canvalidate);
418: }
419: my $checked = '';
420: if ($option eq $curroption) {
421: $checked = ' checked="checked"';
422: }
1.295.2.14 raeburn 423: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.295.2.3 raeburn 424: '<input type="radio" name="reqcrsotherdom_'.$item.
425: '" value="'.$option.'"'.$checked.' />'.
1.295.2.14 raeburn 426: $reqtitles{$option}.'</label>';
1.295.2.3 raeburn 427: if ($option eq 'autolimit') {
1.295.2.14 raeburn 428: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.295.2.3 raeburn 429: $item.'_limit" size="1" '.
1.295.2.14 raeburn 430: 'value="'.$currlimit.'" /></span>'.
431: '<br />'.$reqtitles{'unlimited'};
432: } else {
433: $output .= '</span>';
1.295.2.3 raeburn 434: }
1.295.2.14 raeburn 435: $output .= '</td>';
1.295.2.3 raeburn 436: }
1.295.2.14 raeburn 437: $output .= '</td></tr></table></td>'."\n".
1.295.2.3 raeburn 438: &Apache::loncommon::end_data_table_row()."\n";
439: }
440: return $output;
441: }
442:
443: sub courserequest_titles {
444: my %titles = &Apache::lonlocal::texthash (
1.295.2.7 raeburn 445: official => 'Official',
446: unofficial => 'Unofficial',
447: community => 'Communities',
448: norequest => 'Not allowed',
1.295.2.10 raeburn 449: approval => 'Approval by Dom. Coord.',
1.295.2.3 raeburn 450: validate => 'With validation',
451: autolimit => 'Numerical limit',
1.295.2.14 raeburn 452: unlimited => '(blank for unlimited)',
1.295.2.3 raeburn 453: );
1.295.2.14 raeburn 454: return %titles;
455: }
456:
1.295.2.3 raeburn 457: sub courserequest_display {
458: my %titles = &Apache::lonlocal::texthash (
1.295.2.10 raeburn 459: approval => 'Yes, need approval',
1.295.2.3 raeburn 460: validate => 'Yes, with validation',
461: norequest => 'No',
1.295.2.14 raeburn 462: );
1.295.2.3 raeburn 463: return %titles;
464: }
465:
1.2 www 466: # =================================================================== Phase one
1.1 www 467:
1.42 matthew 468: sub print_username_entry_form {
1.295.2.18 raeburn 469: my ($r,$context,$response,$srch,$forcenewuser,$crstype) = @_;
1.101 albertel 470: my $defdom=$env{'request.role.domain'};
1.160 raeburn 471: my $formtoset = 'crtuser';
472: if (exists($env{'form.startrolename'})) {
473: $formtoset = 'docustom';
474: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 475: } elsif ($env{'form.origform'} eq 'crtusername') {
476: $formtoset = $env{'form.origform'};
1.160 raeburn 477: }
478:
479: my ($jsback,$elements) = &crumb_utilities();
480:
481: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 482: '<script type="text/javascript">'."\n".
1.295.2.4 raeburn 483: '// <![CDATA['."\n".
484: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
485: '// ]]>'."\n".
1.162 raeburn 486: '</script>'."\n";
1.160 raeburn 487:
488: my %loaditems = (
489: 'onload' => "javascript:setFormElements(document.$formtoset)",
490: );
1.295.2.18 raeburn 491: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.110 albertel 492: my $start_page =
1.190 raeburn 493: &Apache::loncommon::start_page('User Management',
1.160 raeburn 494: $jscript,{'add_entries' => \%loaditems,});
1.214 raeburn 495: if ($env{'form.action'} eq 'custom') {
496: &Apache::lonhtmlcommon::add_breadcrumb
497: ({href=>"javascript:backPage(document.crtuser)",
498: text=>"Pick custom role",});
499: } else {
1.190 raeburn 500: &Apache::lonhtmlcommon::add_breadcrumb
501: ({href=>"javascript:backPage(document.crtuser)",
1.229 raeburn 502: text=>$breadcrumb_text{'search'},
1.190 raeburn 503: faq=>282,bug=>'Instructor Interface',});
504: }
1.224 raeburn 505: my $helpitem = 'Course_Change_Privileges';
506: if ($env{'form.action'} eq 'custom') {
507: $helpitem = 'Course_Editing_Custom_Roles';
508: } elsif ($env{'form.action'} eq 'singlestudent') {
509: $helpitem = 'Course_Add_Student';
510: }
511: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
512: $helpitem);
1.190 raeburn 513: my %existingroles=&Apache::lonuserutils::my_custom_roles();
1.59 www 514: my $choice=&Apache::loncommon::select_form('make new role','rolename',
515: ('make new role' => 'Generate new role ...',%existingroles));
1.71 sakharuk 516: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 517: 'srst' => 'Search for a user and enroll as a student',
1.295.2.18 raeburn 518: 'srme' => 'Search for a user and enroll as a member',
519:
1.229 raeburn 520: 'srad' => 'Search for a user and modify/add user information or roles',
1.71 sakharuk 521: 'usr' => "Username",
522: 'dom' => "Domain",
523: 'ecrp' => "Edit Custom Role Privileges",
1.72 sakharuk 524: 'nr' => "Name of Role",
1.282 schafran 525: 'cre' => "Next",
1.71 sakharuk 526: );
1.190 raeburn 527: $r->print($start_page."\n".$crumbs);
1.214 raeburn 528: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 529: if (&Apache::lonnet::allowed('mcr','/')) {
530: $r->print(<<ENDCUSTOM);
1.58 www 531: <form action="/adm/createuser" method="post" name="docustom">
1.190 raeburn 532: <input type="hidden" name="action" value="$env{'form.action'}" />
1.157 albertel 533: <input type="hidden" name="phase" value="selected_custom_edit" />
1.224 raeburn 534: <h3>$lt{'ecrp'}</h3>
1.282 schafran 535: $choice $lt{'nr'}: <input type="text" size="15" name="newrolename" /><br />
1.71 sakharuk 536: <input name="customeditor" type="submit" value="$lt{'cre'}" />
1.107 www 537: </form>
1.106 www 538: ENDCUSTOM
1.190 raeburn 539: }
1.213 raeburn 540: } else {
1.229 raeburn 541: my $actiontext = $lt{'srad'};
1.213 raeburn 542: if ($env{'form.action'} eq 'singlestudent') {
1.295.2.18 raeburn 543: if ($crstype eq 'Community') {
544: $actiontext = $lt{'srme'};
545: } else {
546: $actiontext = $lt{'srst'};
547: }
1.213 raeburn 548: }
1.295.2.18 raeburn 549: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 550: if ($env{'form.origform'} ne 'crtusername') {
551: $r->print("\n".$response);
552: }
1.295.2.18 raeburn 553: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype));
1.107 www 554: }
1.110 albertel 555: $r->print(&Apache::loncommon::end_page());
556: }
557:
1.160 raeburn 558: sub entry_form {
1.295.2.18 raeburn 559: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype) = @_;
1.207 raeburn 560: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
1.229 raeburn 561: my ($usertype,$inexact);
1.214 raeburn 562: if (ref($srch) eq 'HASH') {
563: if (($srch->{'srchin'} eq 'dom') &&
564: ($srch->{'srchby'} eq 'uname') &&
565: ($srch->{'srchtype'} eq 'exact') &&
566: ($srch->{'srchdomain'} ne '') &&
567: ($srch->{'srchterm'} ne '')) {
568: my ($rules,$ruleorder) =
569: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
570: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules);
1.229 raeburn 571: } else {
572: $inexact = 1;
1.214 raeburn 573: }
1.207 raeburn 574: }
1.214 raeburn 575: my $cancreate =
576: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.160 raeburn 577: my $userpicker =
1.179 raeburn 578: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.214 raeburn 579: 'document.crtuser',$cancreate,$usertype);
1.160 raeburn 580: my $srchbutton = &mt('Search');
1.229 raeburn 581: if ($env{'form.action'} eq 'singlestudent') {
582: $srchbutton = &mt('Search and Enroll');
583: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
584: $srchbutton = &mt('Search or Add New User');
585: }
1.207 raeburn 586: my $output = <<"ENDBLOCK";
1.160 raeburn 587: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 588: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 589: <input type="hidden" name="phase" value="get_user_info" />
590: $userpicker
1.179 raeburn 591: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 592: </form>
1.207 raeburn 593: ENDBLOCK
1.229 raeburn 594: if ($env{'form.phase'} eq '') {
1.207 raeburn 595: my $defdom=$env{'request.role.domain'};
596: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
597: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 598: 'enro' => 'Enroll one student',
1.295.2.18 raeburn 599: 'enrm' => 'Enroll one member',
1.229 raeburn 600: 'admo' => 'Add/modify a single user',
601: 'crea' => 'create new user if required',
602: 'uskn' => "username is known",
1.207 raeburn 603: 'crnu' => 'Create a new user',
604: 'usr' => 'Username',
605: 'dom' => 'in domain',
1.229 raeburn 606: 'enrl' => 'Enroll',
607: 'cram' => 'Create/Modify user',
1.207 raeburn 608: );
1.229 raeburn 609: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
610: my ($title,$buttontext,$showresponse);
611: if ($env{'form.action'} eq 'singlestudent') {
1.295.2.18 raeburn 612: if ($crstype eq 'Community') {
613: $title = $lt{'enrm'};
614: } else {
615: $title = $lt{'enro'};
616: }
1.229 raeburn 617: $buttontext = $lt{'enrl'};
618: } else {
619: $title = $lt{'admo'};
620: $buttontext = $lt{'cram'};
621: }
622: if ($cancreate) {
623: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
624: } else {
625: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
626: }
627: if ($env{'form.origform'} eq 'crtusername') {
628: $showresponse = $responsemsg;
629: }
1.207 raeburn 630: $output .= <<"ENDDOCUMENT";
1.229 raeburn 631: <br />
1.207 raeburn 632: <form action="/adm/createuser" method="post" name="crtusername">
633: <input type="hidden" name="action" value="$env{'form.action'}" />
634: <input type="hidden" name="phase" value="createnewuser" />
635: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 636: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 637: <input type="hidden" name="srchin" value="dom" />
638: <input type="hidden" name="forcenewuser" value="1" />
639: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 640: <h3>$title</h3>
641: $showresponse
1.207 raeburn 642: <table>
643: <tr>
644: <td>$lt{'usr'}:</td>
645: <td><input type="text" size="15" name="srchterm" /></td>
646: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 647: <td> $sellink </td>
648: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 649: </tr>
650: </table>
651: </form>
1.160 raeburn 652: ENDDOCUMENT
1.207 raeburn 653: }
1.160 raeburn 654: return $output;
655: }
1.110 albertel 656:
657: sub user_modification_js {
1.113 raeburn 658: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
659:
1.110 albertel 660: return <<END;
661: <script type="text/javascript" language="Javascript">
1.295.2.4 raeburn 662: // <![CDATA[
1.110 albertel 663:
664: function pclose() {
665: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
666: "height=350,width=350,scrollbars=no,menubar=no");
667: parmwin.close();
668: }
669:
670: $pjump_def
671: $dc_setcourse_code
672:
673: function dateset() {
674: eval("document.cu."+document.cu.pres_marker.value+
675: ".value=document.cu.pres_value.value");
676: pclose();
677: }
678:
1.113 raeburn 679: $nondc_setsection_code
1.295.2.4 raeburn 680: // ]]>
1.110 albertel 681: </script>
682: END
1.2 www 683: }
684:
685: # =================================================================== Phase two
1.160 raeburn 686: sub print_user_selection_page {
1.295.2.18 raeburn 687: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype) = @_;
1.160 raeburn 688: my @fields = ('username','domain','lastname','firstname','permanentemail');
689: my $sortby = $env{'form.sortby'};
690:
691: if (!grep(/^\Q$sortby\E$/,@fields)) {
692: $sortby = 'lastname';
693: }
694:
695: my ($jsback,$elements) = &crumb_utilities();
696:
697: my $jscript = (<<ENDSCRIPT);
698: <script type="text/javascript">
1.295.2.4 raeburn 699: // <![CDATA[
1.160 raeburn 700: function pickuser(uname,udom) {
701: document.usersrchform.seluname.value=uname;
702: document.usersrchform.seludom.value=udom;
703: document.usersrchform.phase.value="userpicked";
704: document.usersrchform.submit();
705: }
706:
707: $jsback
1.295.2.4 raeburn 708: // ]]>
1.160 raeburn 709: </script>
710: ENDSCRIPT
711:
712: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 713: 'usrch' => "User Search to add/modify roles",
714: 'stusrch' => "User Search to enroll student",
1.295.2.18 raeburn 715: 'memsrch' => "User Search to enroll member",
1.179 raeburn 716: 'usel' => "Select a user to add/modify roles",
1.295.2.18 raeburn 717: 'stusel' => "Select a user to enroll as a student",
718: 'memsel' => "Select a user to enroll as a member",
1.160 raeburn 719: 'username' => "username",
720: 'domain' => "domain",
721: 'lastname' => "last name",
722: 'firstname' => "first name",
723: 'permanentemail' => "permanent e-mail",
724: );
1.295.2.7 raeburn 725: if ($context eq 'requestcrs') {
726: $r->print('<div>');
727: } else {
728: $r->print(&Apache::loncommon::start_page('User Management',$jscript));
1.229 raeburn 729:
1.295.2.18 raeburn 730: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.295.2.7 raeburn 731: &Apache::lonhtmlcommon::add_breadcrumb
732: ({href=>"javascript:backPage(document.usersrchform,'','')",
733: text=>$breadcrumb_text{'search'},
734: faq=>282,bug=>'Instructor Interface',},
735: {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
736: text=>$breadcrumb_text{'userpicked'},
737: faq=>282,bug=>'Instructor Interface',});
738: if ($env{'form.action'} eq 'singleuser') {
739: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
1.295.2.14 raeburn 740: 'Course_Change_Privileges'));
1.295.2.7 raeburn 741: $r->print("<b>$lt{'usrch'}</b><br />");
1.295.2.18 raeburn 742: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.295.2.7 raeburn 743: $r->print('<h3>'.$lt{'usel'}.'</h3>');
744: } elsif ($env{'form.action'} eq 'singlestudent') {
745: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
1.295.2.14 raeburn 746: 'Course_Add_Student'));
1.295.2.18 raeburn 747: $r->print($jscript."<b>");
748: if ($crstype eq 'Community') {
749: $r->print($lt{'memsrch'});
750: } else {
751: $r->print($lt{'stusrch'});
752: }
753: $r->print("</b><br />");
754: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
755: $r->print('</form><h3>');
756: if ($crstype eq 'Community') {
757: $r->print($lt{'memsel'});
758: } else {
759: $r->print($lt{'stusel'});
760: }
761: $r->print('</h3>');
1.295.2.7 raeburn 762: }
1.179 raeburn 763: }
1.160 raeburn 764: $r->print('<form name="usersrchform" method="post">'.
765: &Apache::loncommon::start_data_table()."\n".
766: &Apache::loncommon::start_data_table_header_row()."\n".
767: ' <th> </th>'."\n");
768: foreach my $field (@fields) {
769: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
770: "'".$field."'".';document.usersrchform.submit();">'.
771: $lt{$field}.'</a></th>'."\n");
772: }
773: $r->print(&Apache::loncommon::end_data_table_header_row());
774:
775: my @sorted_users = sort {
1.167 albertel 776: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 777: ||
1.167 albertel 778: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 779: ||
780: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 781: ||
782: lc($a) cmp lc($b)
1.160 raeburn 783: } (keys(%$srch_results));
784:
785: foreach my $user (@sorted_users) {
786: my ($uname,$udom) = split(/:/,$user);
1.295.2.7 raeburn 787: my $onclick;
788: if ($context eq 'requestcrs') {
789: $onclick =
790: 'onclick="javascript:gochoose('."'$uname','$udom',".
791: "'$srch_results->{$user}->{firstname}',".
792: "'$srch_results->{$user}->{lastname}',".
793: "'$srch_results->{$user}->{permanentemail}'".');"';
794: } else {
795: $onclick =
796: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
797: }
1.160 raeburn 798: $r->print(&Apache::loncommon::start_data_table_row().
1.295.2.7 raeburn 799: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
800: $onclick.' /></td>'.
1.160 raeburn 801: '<td><tt>'.$uname.'</tt></td>'.
802: '<td><tt>'.$udom.'</tt></td>');
803: foreach my $field ('lastname','firstname','permanentemail') {
804: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
805: }
806: $r->print(&Apache::loncommon::end_data_table_row());
807: }
808: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 809: if (ref($srcharray) eq 'ARRAY') {
810: foreach my $item (@{$srcharray}) {
811: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
812: }
813: }
1.160 raeburn 814: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
815: ' <input type="hidden" name="seluname" value="" />'."\n".
816: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 817: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 818: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 819: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.295.2.7 raeburn 820: if ($context eq 'requestcrs') {
821: $r->print($opener_elements.'</form></div>');
822: } else {
823: $r->print($response.'</form>'.&Apache::loncommon::end_page());
824: }
1.160 raeburn 825: }
826:
827: sub print_user_query_page {
1.179 raeburn 828: my ($r,$caller) = @_;
1.160 raeburn 829: # FIXME - this is for a network-wide name search (similar to catalog search)
830: # To use frames with similar behavior to catalog/portfolio search.
831: # To be implemented.
832: return;
833: }
834:
1.42 matthew 835: sub print_user_modification_page {
1.295.2.18 raeburn 836: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype) = @_;
1.185 raeburn 837: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 838: my $usermsg = &mt('No username and/or domain provided.');
839: $env{'form.phase'} = '';
1.295.2.18 raeburn 840: &print_username_entry_form($r,$context,$usermsg,'','',$crstype);
1.58 www 841: return;
842: }
1.213 raeburn 843: my ($form,$formname);
844: if ($env{'form.action'} eq 'singlestudent') {
845: $form = 'document.enrollstudent';
846: $formname = 'enrollstudent';
847: } else {
848: $form = 'document.cu';
849: $formname = 'cu';
850: }
1.188 raeburn 851: my %abv_auth = &auth_abbrev();
1.227 raeburn 852: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 853: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
854: if ($uhome eq 'no_host') {
1.215 raeburn 855: my $usertype;
856: my ($rules,$ruleorder) =
857: &Apache::lonnet::inst_userrules($ccdomain,'username');
858: $usertype =
859: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules);
860: my $cancreate =
861: &Apache::lonuserutils::can_create_user($ccdomain,$context,
862: $usertype);
863: if (!$cancreate) {
1.292 bisitz 864: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 865: my %usertypetext = (
866: official => 'institutional',
867: unofficial => 'non-institutional',
868: );
869: my $response;
870: if ($env{'form.origform'} eq 'crtusername') {
871: $response = '<span class="LC_warning">'.&mt('No match was found for the username ([_1]) in LON-CAPA domain: [_2]',$ccuname,$ccdomain).
872: '</span><br />';
873: }
1.292 bisitz 874: $response .= '<p class="LC_warning">'
875: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
876: .' '
877: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
878: ,'<a href="'.$helplink.'">','</a>')
879: .'</p><br />';
1.215 raeburn 880: $env{'form.phase'} = '';
1.295.2.18 raeburn 881: &print_username_entry_form($r,$context,$response,undef,undef,$crstype);
1.215 raeburn 882: return;
883: }
1.188 raeburn 884: $newuser = 1;
1.193 raeburn 885: my $checkhash;
886: my $checks = { 'username' => 1 };
1.196 raeburn 887: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 888: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 889: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
890: if (ref($alerts{'username'}) eq 'HASH') {
891: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
892: my $domdesc =
1.193 raeburn 893: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 894: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
895: my $userchkmsg;
896: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
897: $userchkmsg =
898: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 899: $domdesc,1).
900: &Apache::loncommon::user_rule_formats($ccdomain,
901: $domdesc,$curr_rules{$ccdomain}{'username'},
902: 'username');
1.196 raeburn 903: }
1.215 raeburn 904: $env{'form.phase'} = '';
1.295.2.18 raeburn 905: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype);
1.196 raeburn 906: return;
1.215 raeburn 907: }
1.193 raeburn 908: }
1.185 raeburn 909: }
1.187 raeburn 910: } else {
1.188 raeburn 911: $newuser = 0;
1.185 raeburn 912: }
1.160 raeburn 913: if ($response) {
1.215 raeburn 914: $response = '<br />'.$response;
1.160 raeburn 915: }
1.149 raeburn 916:
1.52 matthew 917: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 918: my $dc_setcourse_code = '';
1.119 raeburn 919: my $nondc_setsection_code = '';
1.112 albertel 920: my %loaditem;
1.114 albertel 921:
1.216 raeburn 922: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 923:
1.216 raeburn 924: my $js = &validation_javascript($context,$ccdomain,$pjump_def,
925: $groupslist,$newuser,$formname,\%loaditem);
1.233 raeburn 926: my $args = {'add_entries' => \%loaditem};
927: if ($env{'form.popup'}) {
928: $args->{'no_nav_bar'} = 1;
929: }
1.110 albertel 930: my $start_page =
1.233 raeburn 931: &Apache::loncommon::start_page('User Management',$js,$args);
1.295.2.18 raeburn 932: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.160 raeburn 933: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 934: ({href=>"javascript:backPage($form)",
935: text=>$breadcrumb_text{'search'},
1.160 raeburn 936: faq=>282,bug=>'Instructor Interface',});
937:
938: if ($env{'form.phase'} eq 'userpicked') {
939: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 940: ({href=>"javascript:backPage($form,'get_user_info','select')",
941: text=>$breadcrumb_text{'userpicked'},
1.160 raeburn 942: faq=>282,bug=>'Instructor Interface',});
943: }
944: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 945: ({href=>"javascript:backPage($form,'$env{'form.phase'}','modify')",
946: text=>$breadcrumb_text{'modify'},
1.160 raeburn 947: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 948: my $helpitem = 'Course_Change_Privileges';
949: if ($env{'form.action'} eq 'singlestudent') {
950: $helpitem = 'Course_Add_Student';
951: }
952: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
953: $helpitem);
1.3 www 954:
1.25 matthew 955: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 956: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 957: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 958: <input type="hidden" name="ccuname" value="$ccuname" />
959: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 960: <input type="hidden" name="pres_value" value="" />
961: <input type="hidden" name="pres_type" value="" />
962: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 963: ENDFORMINFO
1.2 www 964: my %inccourses;
1.135 raeburn 965: foreach my $key (keys(%env)) {
1.139 albertel 966: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1.2 www 967: $inccourses{$1.'_'.$2}=1;
968: }
1.24 matthew 969: }
1.216 raeburn 970: if ($newuser) {
1.134 raeburn 971: my $portfolioform;
1.267 raeburn 972: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
973: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
974: # Current user has quota or user tools modification privileges
1.188 raeburn 975: $portfolioform = '<br />'.&portfolio_quota($ccuname,$ccdomain);
1.134 raeburn 976: }
1.227 raeburn 977: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 978: my %lt=&Apache::lonlocal::texthash(
979: 'cnu' => 'Create New User',
1.213 raeburn 980: 'ast' => 'as a student',
1.295.2.18 raeburn 981: 'ame' => 'as a member',
1.188 raeburn 982: 'ind' => 'in domain',
983: 'lg' => 'Login Data',
1.190 raeburn 984: 'hs' => "Home Server",
1.188 raeburn 985: );
1.185 raeburn 986: $r->print(<<ENDTITLE);
1.110 albertel 987: $start_page
1.160 raeburn 988: $crumbs
989: $response
1.25 matthew 990: $forminfo
1.31 matthew 991: <script type="text/javascript" language="Javascript">
1.295.2.4 raeburn 992: // <![CDATA[
1.20 harris41 993: $loginscript
1.295.2.4 raeburn 994: // ]]>
1.31 matthew 995: </script>
1.20 harris41 996: <input type='hidden' name='makeuser' value='1' />
1.216 raeburn 997: <h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain
1.185 raeburn 998: ENDTITLE
1.213 raeburn 999: if ($env{'form.action'} eq 'singlestudent') {
1.295.2.18 raeburn 1000: if ($crstype eq 'Community') {
1001: $r->print(' ('.$lt{'ame'}.')');
1002: } else {
1003: $r->print(' ('.$lt{'ast'}.')');
1004: }
1.213 raeburn 1005: }
1006: $r->print('</h2>'."\n".'<div class="LC_left_float">');
1.206 raeburn 1007: my $personal_table =
1.210 raeburn 1008: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1009: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 1010: $r->print($personal_table);
1.187 raeburn 1011: my ($home_server_pick,$numlib) =
1012: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1013: 'default','hide');
1014: if ($numlib > 1) {
1015: $r->print("
1.185 raeburn 1016: <br />
1.187 raeburn 1017: $lt{'hs'}: $home_server_pick
1018: <br />");
1019: } else {
1020: $r->print($home_server_pick);
1021: }
1.295.2.5 raeburn 1022: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.295.2.18 raeburn 1023: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.295.2.5 raeburn 1024: &Apache::loncommon::start_data_table().
1025: &build_tools_display($ccuname,$ccdomain,
1026: 'requestcourses').
1027: &Apache::loncommon::end_data_table());
1028: }
1.188 raeburn 1029: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1030: $lt{'lg'}.'</h3>');
1.185 raeburn 1031: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1032: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1033: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1034: my ($rules,$ruleorder) =
1035: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1036: if (ref($rules) eq 'HASH') {
1.193 raeburn 1037: if (ref($rules->{$matchedrule}) eq 'HASH') {
1038: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1039: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1040: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1041: } else {
1.193 raeburn 1042: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1043: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1044: if ($authtype =~ /^krb(4|5)$/) {
1045: my $ver = $1;
1046: if ($authparm ne '') {
1047: $fixedauth = <<"KERB";
1048: <input type="hidden" name="login" value="krb" />
1049: <input type="hidden" name="krbver" value="$ver" />
1050: <input type="hidden" name="krbarg" value="$authparm" />
1051: KERB
1052: }
1053: } else {
1054: $fixedauth =
1055: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1056: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1057: $fixedauth .=
1058: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1059: } else {
1.273 raeburn 1060: if ($authtype eq 'int') {
1061: $varauth = '<br />'.
1.295.2.4 raeburn 1062: &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 1063: } elsif ($authtype eq 'loc') {
1064: $varauth = '<br />'.
1065: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1066: } else {
1067: $varauth =
1.185 raeburn 1068: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1069: }
1.185 raeburn 1070: }
1071: }
1072: }
1073: } else {
1.190 raeburn 1074: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1075: }
1076: }
1077: if ($authmsg) {
1078: $r->print(<<ENDAUTH);
1079: $fixedauth
1080: $authmsg
1081: $varauth
1082: ENDAUTH
1083: }
1084: } else {
1.190 raeburn 1085: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1086: }
1.215 raeburn 1087: $r->print($portfolioform);
1088: if ($env{'form.action'} eq 'singlestudent') {
1089: $r->print(&date_sections_select($context,$newuser,$formname,
1090: $permission));
1091: }
1092: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1093: } else { # user already exists
1.79 albertel 1094: my %lt=&Apache::lonlocal::texthash(
1.191 raeburn 1095: 'cup' => "Modify existing user: ",
1.213 raeburn 1096: 'ens' => "Enroll one student: ",
1.295.2.18 raeburn 1097: 'enm' => "Enroll one member: ",
1.72 sakharuk 1098: 'id' => "in domain",
1099: );
1.26 matthew 1100: $r->print(<<ENDCHANGEUSER);
1.110 albertel 1101: $start_page
1.160 raeburn 1102: $crumbs
1.25 matthew 1103: $forminfo
1.213 raeburn 1104: <h2>
1.26 matthew 1105: ENDCHANGEUSER
1.213 raeburn 1106: if ($env{'form.action'} eq 'singlestudent') {
1.295.2.18 raeburn 1107: if ($crstype eq 'Community') {
1108: $r->print($lt{'enm'});
1109: } else {
1110: $r->print($lt{'ens'});
1111: }
1.213 raeburn 1112: } else {
1113: $r->print($lt{'cup'});
1114: }
1115: $r->print(' "'.$ccuname.'" '.$lt{'id'}.' "'.$ccdomain.'"</h2>'.
1116: "\n".'<div class="LC_left_float">');
1.206 raeburn 1117: my ($personal_table,$showforceid) =
1.210 raeburn 1118: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
1119: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 1120: $r->print($personal_table);
1121: if ($showforceid) {
1.203 raeburn 1122: $r->print(&Apache::lonuserutils::forceid_change($context));
1.199 raeburn 1123: }
1.275 raeburn 1124: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.295.2.18 raeburn 1125: $r->print('<h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.295.2.4 raeburn 1126: &Apache::loncommon::start_data_table());
1.295.2.3 raeburn 1127: if ($env{'request.role.domain'} eq $ccdomain) {
1128: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1129: } else {
1130: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1131: $env{'request.role.domain'}));
1132: }
1133: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1134: }
1.199 raeburn 1135: $r->print('</div>');
1.227 raeburn 1136: my $user_auth_text = &user_authentication($ccuname,$ccdomain,$formname);
1.275 raeburn 1137: my ($user_quota_text,$user_tools_text,$user_reqcrs_text);
1.267 raeburn 1138: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1139: (&Apache::lonnet::allowed('mut',$ccdomain))) {
1.188 raeburn 1140: # Current user has quota modification privileges
1141: $user_quota_text = &portfolio_quota($ccuname,$ccdomain);
1.267 raeburn 1142: }
1143: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1144: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1145: # Get the user's portfolio information
1146: my %portq = &Apache::lonnet::get('environment',['portfolioquota'],
1147: $ccdomain,$ccuname);
1148: my %lt=&Apache::lonlocal::texthash(
1149: 'dska' => "Disk space allocated to user's portfolio files",
1150: 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
1151: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1152: );
1153: $user_quota_text = <<ENDNOPORTPRIV;
1.188 raeburn 1154: <h3>$lt{'dska'}</h3>
1155: $lt{'youd'} $lt{'ichr'}: $ccdomain
1156: ENDNOPORTPRIV
1.267 raeburn 1157: }
1158: }
1159: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1160: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1161: my %lt=&Apache::lonlocal::texthash(
1162: 'utav' => "User Tools Availability",
1.285 weissno 1163: 'yodo' => "You do not have privileges to modify Portfolio, Blog or Personal Information Page settings for this user.",
1.267 raeburn 1164: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1165: );
1166: $user_tools_text = <<ENDNOTOOLSPRIV;
1167: <h3>$lt{'utav'}</h3>
1168: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1169: ENDNOTOOLSPRIV
1170: }
1.188 raeburn 1171: }
1172: if ($user_auth_text ne '') {
1173: $r->print('<div class="LC_left_float">'.$user_auth_text);
1174: if ($user_quota_text ne '') {
1175: $r->print($user_quota_text);
1176: }
1.267 raeburn 1177: if ($user_tools_text ne '') {
1178: $r->print($user_tools_text);
1179: }
1.213 raeburn 1180: if ($env{'form.action'} eq 'singlestudent') {
1181: $r->print(&date_sections_select($context,$newuser,$formname));
1182: }
1.188 raeburn 1183: } elsif ($user_quota_text ne '') {
1.213 raeburn 1184: $r->print('<div class="LC_left_float">'.$user_quota_text);
1.267 raeburn 1185: if ($user_tools_text ne '') {
1186: $r->print($user_tools_text);
1187: }
1188: if ($env{'form.action'} eq 'singlestudent') {
1189: $r->print(&date_sections_select($context,$newuser,$formname));
1190: }
1191: } elsif ($user_tools_text ne '') {
1192: $r->print('<div class="LC_left_float">'.$user_tools_text);
1.213 raeburn 1193: if ($env{'form.action'} eq 'singlestudent') {
1194: $r->print(&date_sections_select($context,$newuser,$formname));
1195: }
1196: } else {
1197: if ($env{'form.action'} eq 'singlestudent') {
1198: $r->print('<div class="LC_left_float">'.
1199: &date_sections_select($context,$newuser,$formname));
1200: }
1.188 raeburn 1201: }
1.213 raeburn 1202: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.217 raeburn 1203: if ($env{'form.action'} ne 'singlestudent') {
1204: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses);
1205: }
1.25 matthew 1206: } ## End of new user/old user logic
1.218 raeburn 1207:
1208: if ($env{'form.action'} eq 'singlestudent') {
1.295.2.18 raeburn 1209: my $btntxt;
1210: if ($crstype eq 'Community') {
1211: $btntxt = &mt('Enroll Member');
1212: } else {
1213: $btntxt = &mt('Enroll Student');
1214: }
1215: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.218 raeburn 1216: } else {
1217: $r->print('<h3>'.&mt('Add Roles').'</h3>');
1218: my $addrolesdisplay = 0;
1219: if ($context eq 'domain' || $context eq 'author') {
1220: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1221: }
1222: if ($context eq 'domain') {
1223: my $add_domainroles = &new_domain_roles($r);
1224: if (!$addrolesdisplay) {
1225: $addrolesdisplay = $add_domainroles;
1.2 www 1226: }
1.218 raeburn 1227: $r->print(&course_level_dc($env{'request.role.domain'},'Course'));
1.295.2.4 raeburn 1228: $r->print('<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1229: } elsif ($context eq 'author') {
1230: if ($addrolesdisplay) {
1.262 schafran 1231: $r->print('<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1232: if ($newuser) {
1.295.2.4 raeburn 1233: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1234: } else {
1.295.2.4 raeburn 1235: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1236: }
1.188 raeburn 1237: } else {
1.218 raeburn 1238: $r->print('<br /><a href="javascript:backPage(document.cu)">'.
1239: &mt('Back to previous page').'</a>');
1.188 raeburn 1240: }
1241: } else {
1.218 raeburn 1242: $r->print(&course_level_table(%inccourses));
1.295.2.4 raeburn 1243: $r->print('<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1244: }
1.88 raeburn 1245: }
1.188 raeburn 1246: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1247: $r->print('<input type="hidden" name="currstate" value="" />');
1.160 raeburn 1248: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />');
1.110 albertel 1249: $r->print("</form>".&Apache::loncommon::end_page());
1.218 raeburn 1250: return;
1.2 www 1251: }
1.1 www 1252:
1.213 raeburn 1253: sub singleuser_breadcrumb {
1.295.2.18 raeburn 1254: my ($crstype) = @_;
1.213 raeburn 1255: my %breadcrumb_text;
1256: if ($env{'form.action'} eq 'singlestudent') {
1.295.2.18 raeburn 1257: if ($crstype eq 'Community') {
1258: $breadcrumb_text{'search'} = 'Enroll a member';
1259: } else {
1260: $breadcrumb_text{'search'} = 'Enroll a student';
1261: }
1.213 raeburn 1262: $breadcrumb_text{'userpicked'} = 'Select a user',
1263: $breadcrumb_text{'modify'} = 'Set section/dates',
1264: } else {
1.229 raeburn 1265: $breadcrumb_text{'search'} = 'Create/modify a user';
1.213 raeburn 1266: $breadcrumb_text{'userpicked'} = 'Select a user',
1267: $breadcrumb_text{'modify'} = 'Set user role',
1268: }
1269: return %breadcrumb_text;
1270: }
1271:
1272: sub date_sections_select {
1273: my ($context,$newuser,$formname,$permission) = @_;
1274: my $cid = $env{'request.course.id'};
1275: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1276: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1277: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1278: undef,$formname,$permission);
1279: my $rowtitle = 'Section';
1280: my $secbox = '<h3>'.&mt('Section').'</h3>'."\n".
1281: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1282: $permission);
1283: my $output = $date_table.$secbox;
1284: return $output;
1285: }
1286:
1.216 raeburn 1287: sub validation_javascript {
1288: my ($context,$ccdomain,$pjump_def,$groupslist,$newuser,$formname,
1289: $loaditem) = @_;
1290: my $dc_setcourse_code = '';
1291: my $nondc_setsection_code = '';
1292: if ($context eq 'domain') {
1293: my $dcdom = $env{'request.role.domain'};
1294: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1295: $dc_setcourse_code =
1296: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1297: } else {
1.227 raeburn 1298: my $checkauth;
1299: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1300: $checkauth = 1;
1301: }
1302: if ($context eq 'course') {
1303: $nondc_setsection_code =
1304: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1305: undef,$checkauth);
1306: }
1307: if ($checkauth) {
1308: $nondc_setsection_code .=
1309: &Apache::lonuserutils::verify_authen($formname,$context);
1310: }
1.216 raeburn 1311: }
1312: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1313: $nondc_setsection_code,$groupslist);
1314: my ($jsback,$elements) = &crumb_utilities();
1315: $js .= "\n".
1.295.2.4 raeburn 1316: '<script type="text/javascript">'."\n".
1317: '// <![CDATA['."\n".
1318: $jsback."\n".
1319: '// ]]>'."\n".
1320: '</script>'."\n";
1.216 raeburn 1321: return $js;
1322: }
1323:
1.217 raeburn 1324: sub display_existing_roles {
1325: my ($r,$ccuname,$ccdomain,$inccourses) = @_;
1326: my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1327: # Build up table of user roles to allow revocation and re-enabling of roles.
1328: my ($tmp) = keys(%rolesdump);
1329: if ($tmp !~ /^(con_lost|error)/i) {
1330: my $now=time;
1331: my %lt=&Apache::lonlocal::texthash(
1332: 'rer' => "Existing Roles",
1333: 'rev' => "Revoke",
1334: 'del' => "Delete",
1335: 'ren' => "Re-Enable",
1336: 'rol' => "Role",
1337: 'ext' => "Extent",
1338: 'sta' => "Start",
1339: 'end' => "End",
1340: );
1341: my (%roletext,%sortrole,%roleclass,%rolepriv);
1342: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1343: my $b1=join('_',(split('_',$b))[1,0]);
1344: return $a1 cmp $b1;
1345: } keys(%rolesdump)) {
1346: next if ($area =~ /^rolesdef/);
1347: my $envkey=$area;
1348: my $role = $rolesdump{$area};
1349: my $thisrole=$area;
1350: $area =~ s/\_\w\w$//;
1351: my ($role_code,$role_end_time,$role_start_time) =
1352: split(/_/,$role);
1353: # Is this a custom role? Get role owner and title.
1354: my ($croleudom,$croleuname,$croletitle)=
1355: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1356: my $allowed=0;
1357: my $delallowed=0;
1358: my $sortkey=$role_code;
1359: my $class='Unknown';
1360: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
1361: $class='Course';
1362: my ($coursedom,$coursedir) = ($1,$2);
1363: $sortkey.="\0$coursedom";
1364: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1365: my %coursedata=
1366: &Apache::lonnet::coursedescription($1.'_'.$2);
1367: my $carea;
1368: if (defined($coursedata{'description'})) {
1369: $carea=$coursedata{'description'}.
1370: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1.259 bisitz 1371: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1.217 raeburn 1372: $sortkey.="\0".$coursedata{'description'};
1373: $class=$coursedata{'type'};
1374: } else {
1375: $carea=&mt('Unavailable course').': '.$area;
1376: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1377: }
1378: $sortkey.="\0$coursedir";
1379: $inccourses->{$1.'_'.$2}=1;
1380: if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
1381: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1382: $allowed=1;
1383: }
1384: if ((&Apache::lonnet::allowed('dro',$1)) ||
1385: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1386: $delallowed=1;
1387: }
1388: # - custom role. Needs more info, too
1389: if ($croletitle) {
1390: if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
1391: $allowed=1;
1392: $thisrole.='.'.$role_code;
1393: }
1394: }
1395: # Compute the background color based on $area
1396: if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
1397: $carea.='<br />Section: '.$3;
1398: $sortkey.="\0$3";
1399: if (!$allowed) {
1400: if ($env{'request.course.sec'} eq $3) {
1401: if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
1402: $allowed = 1;
1403: }
1404: }
1405: }
1406: }
1407: $area=$carea;
1408: } else {
1409: $sortkey.="\0".$area;
1410: # Determine if current user is able to revoke privileges
1411: if ($area=~m{^/($match_domain)/}) {
1412: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1413: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1414: $allowed=1;
1415: }
1416: if (((&Apache::lonnet::allowed('dro',$1)) ||
1417: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1418: ($role_code ne 'dc')) {
1419: $delallowed=1;
1420: }
1421: } else {
1422: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1423: $allowed=1;
1424: }
1425: }
1426: if ($role_code eq 'ca' || $role_code eq 'au') {
1427: $class='Construction Space';
1428: } elsif ($role_code eq 'su') {
1429: $class='System';
1430: } else {
1431: $class='Domain';
1432: }
1433: }
1434: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1435: $area=~m{/($match_domain)/($match_username)};
1436: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1437: $allowed=1;
1438: } else {
1439: $allowed=0;
1440: }
1441: }
1442: my $row = '';
1443: $row.= '<td>';
1444: my $active=1;
1445: $active=0 if (($role_end_time) && ($now>$role_end_time));
1446: if (($active) && ($allowed)) {
1447: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1448: } else {
1449: if ($active) {
1450: $row.=' ';
1451: } else {
1452: $row.=&mt('expired or revoked');
1453: }
1454: }
1455: $row.='</td><td>';
1456: if ($allowed && !$active) {
1457: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1458: } else {
1459: $row.=' ';
1460: }
1461: $row.='</td><td>';
1462: if ($delallowed) {
1463: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1464: } else {
1465: $row.=' ';
1466: }
1467: my $plaintext='';
1468: if (!$croletitle) {
1469: $plaintext=&Apache::lonnet::plaintext($role_code,$class)
1470: } else {
1471: $plaintext=
1472: "Customrole '$croletitle'<br />defined by $croleuname\@$croleudom";
1473: }
1474: $row.= '</td><td>'.$plaintext.
1475: '</td><td>'.$area.
1.295.2.16 raeburn 1476: '</td><td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1.217 raeburn 1477: : ' ' ).
1.295.2.16 raeburn 1478: '</td><td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1.217 raeburn 1479: : ' ' )
1480: ."</td>";
1481: $sortrole{$sortkey}=$envkey;
1482: $roletext{$envkey}=$row;
1483: $roleclass{$envkey}=$class;
1484: $rolepriv{$envkey}=$allowed;
1485: #$r->print($row);
1486: } # end of foreach (table building loop)
1487: my $rolesdisplay = 0;
1488: my %output = ();
1.295.2.18 raeburn 1489: foreach my $type ('Construction Space','Course','Community','Domain','System','Unknown') {
1.217 raeburn 1490: $output{$type} = '';
1491: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1492: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1493: $output{$type}.=
1494: &Apache::loncommon::start_data_table_row().
1495: $roletext{$sortrole{$which}}.
1496: &Apache::loncommon::end_data_table_row();
1497: }
1498: }
1499: unless($output{$type} eq '') {
1500: $output{$type} = '<tr class="LC_info_row">'.
1501: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1502: $output{$type};
1503: $rolesdisplay = 1;
1504: }
1505: }
1506: if ($rolesdisplay == 1) {
1.290 bisitz 1507: my $contextrole='';
1508: if ($env{'request.course.id'}) {
1.295.2.18 raeburn 1509: my $crstype = &Apache::loncommon::course_type();
1510: $contextrole = "Existing Roles in this $crstype";
1.290 bisitz 1511: } elsif ($env{'request.role'} =~ /^au\./) {
1512: $contextrole = 'Existing Co-Author Roles in your Construction Space';
1513: } else {
1514: $contextrole = 'Existing Roles in this Domain';
1515: }
1.217 raeburn 1516: $r->print('
1517: <h3>'.$lt{'rer'}.'</h3>'.
1.290 bisitz 1518: '<div>'.&mt($contextrole).'</div>'.
1.217 raeburn 1519: &Apache::loncommon::start_data_table("LC_createuser").
1520: &Apache::loncommon::start_data_table_header_row().
1521: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
1522: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
1523: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1524: &Apache::loncommon::end_data_table_header_row());
1.295.2.18 raeburn 1525: foreach my $type ('Construction Space','Course','Community','Domain','System','Unknown') {
1.217 raeburn 1526: if ($output{$type}) {
1527: $r->print($output{$type}."\n");
1528: }
1529: }
1530: $r->print(&Apache::loncommon::end_data_table());
1531: }
1532: } # End of check for keys in rolesdump
1533: return;
1534: }
1535:
1.218 raeburn 1536: sub new_coauthor_roles {
1537: my ($r,$ccuname,$ccdomain) = @_;
1538: my $addrolesdisplay = 0;
1539: #
1540: # Co-Author
1541: #
1542: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
1543: $env{'request.role.domain'}) &&
1544: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1545: # No sense in assigning co-author role to yourself
1546: $addrolesdisplay = 1;
1547: my $cuname=$env{'user.name'};
1548: my $cudom=$env{'request.role.domain'};
1549: my %lt=&Apache::lonlocal::texthash(
1550: 'cs' => "Construction Space",
1551: 'act' => "Activate",
1552: 'rol' => "Role",
1553: 'ext' => "Extent",
1554: 'sta' => "Start",
1555: 'end' => "End",
1556: 'cau' => "Co-Author",
1557: 'caa' => "Assistant Co-Author",
1558: 'ssd' => "Set Start Date",
1559: 'sed' => "Set End Date"
1560: );
1561: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
1562: &Apache::loncommon::start_data_table()."\n".
1563: &Apache::loncommon::start_data_table_header_row()."\n".
1564: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
1565: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
1566: '<th>'.$lt{'end'}.'</th>'."\n".
1567: &Apache::loncommon::end_data_table_header_row()."\n".
1568: &Apache::loncommon::start_data_table_row().'
1569: <td>
1.291 bisitz 1570: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 1571: </td>
1572: <td>'.$lt{'cau'}.'</td>
1573: <td>'.$cudom.'_'.$cuname.'</td>
1574: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
1575: <a href=
1576: "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>
1577: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
1578: <a href=
1579: "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".
1580: &Apache::loncommon::end_data_table_row()."\n".
1581: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 1582: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 1583: <td>'.$lt{'caa'}.'</td>
1584: <td>'.$cudom.'_'.$cuname.'</td>
1585: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
1586: <a href=
1587: "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>
1588: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
1589: <a href=
1590: "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".
1591: &Apache::loncommon::end_data_table_row()."\n".
1592: &Apache::loncommon::end_data_table());
1593: } elsif ($env{'request.role'} =~ /^au\./) {
1594: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
1595: $env{'request.role.domain'}))) {
1596: $r->print('<span class="LC_error">'.
1597: &mt('You do not have privileges to assign co-author roles.').
1598: '</span>');
1599: } elsif (($env{'user.name'} eq $ccuname) &&
1600: ($env{'user.domain'} eq $ccdomain)) {
1601: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Construction Space is not permitted'));
1602: }
1603: }
1604: return $addrolesdisplay;;
1605: }
1606:
1607: sub new_domain_roles {
1608: my ($r) = @_;
1609: my $addrolesdisplay = 0;
1610: #
1611: # Domain level
1612: #
1613: my $num_domain_level = 0;
1614: my $domaintext =
1615: '<h4>'.&mt('Domain Level').'</h4>'.
1616: &Apache::loncommon::start_data_table().
1617: &Apache::loncommon::start_data_table_header_row().
1618: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
1619: &mt('Extent').'</th>'.
1620: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
1621: &Apache::loncommon::end_data_table_header_row();
1.295.2.13 raeburn 1622: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 1623: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.295.2.13 raeburn 1624: foreach my $role (@allroles) {
1625: next if ($role eq 'ad');
1.218 raeburn 1626: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1627: my $plrole=&Apache::lonnet::plaintext($role);
1628: my %lt=&Apache::lonlocal::texthash(
1629: 'ssd' => "Set Start Date",
1630: 'sed' => "Set End Date"
1631: );
1632: $num_domain_level ++;
1633: $domaintext .=
1634: &Apache::loncommon::start_data_table_row().
1.291 bisitz 1635: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 1636: <td>'.$plrole.'</td>
1637: <td>'.$thisdomain.'</td>
1638: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
1639: <a href=
1640: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1641: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
1642: <a href=
1643: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
1644: &Apache::loncommon::end_data_table_row();
1645: }
1646: }
1647: }
1648: $domaintext.= &Apache::loncommon::end_data_table();
1649: if ($num_domain_level > 0) {
1650: $r->print($domaintext);
1651: $addrolesdisplay = 1;
1652: }
1653: return $addrolesdisplay;
1654: }
1655:
1.188 raeburn 1656: sub user_authentication {
1.227 raeburn 1657: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 1658: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 1659: my $outcome;
1.188 raeburn 1660: # Check for a bad authentication type
1661: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
1662: # bad authentication scheme
1663: my %lt=&Apache::lonlocal::texthash(
1664: 'err' => "ERROR",
1665: 'uuas' => "This user has an unrecognized authentication scheme",
1666: 'adcs' => "Please alert a domain coordinator of this situation",
1667: 'sldb' => "Please specify login data below",
1668: 'ld' => "Login Data"
1669: );
1670: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 1671: &initialize_authen_forms($ccdomain,$formname);
1672:
1.190 raeburn 1673: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 1674: $outcome = <<ENDBADAUTH;
1675: <script type="text/javascript" language="Javascript">
1.295.2.4 raeburn 1676: // <![CDATA[
1.188 raeburn 1677: $loginscript
1.295.2.4 raeburn 1678: // ]]>
1.188 raeburn 1679: </script>
1680: <span class="LC_error">$lt{'err'}:
1681: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
1682: <h3>$lt{'ld'}</h3>
1683: $choices
1684: ENDBADAUTH
1685: } else {
1686: # This user is not allowed to modify the user's
1687: # authentication scheme, so just notify them of the problem
1688: $outcome = <<ENDBADAUTH;
1689: <span class="LC_error"> $lt{'err'}:
1690: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
1691: </span>
1692: ENDBADAUTH
1693: }
1694: } else { # Authentication type is valid
1.227 raeburn 1695: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 1696: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 1697: &modify_login_block($ccdomain,$currentauth);
1698: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1699: # Current user has login modification privileges
1700: my %lt=&Apache::lonlocal::texthash (
1701: 'ld' => "Login Data",
1702: 'ccld' => "Change Current Login Data",
1703: 'enld' => "Enter New Login Data"
1704: );
1705: $outcome =
1706: '<script type="text/javascript" language="Javascript">'."\n".
1.295.2.4 raeburn 1707: '// <![CDATA['."\n".
1.188 raeburn 1708: $loginscript."\n".
1.295.2.4 raeburn 1709: '// ]]>'."\n".
1.188 raeburn 1710: '</script>'."\n".
1711: '<h3>'.$lt{'ld'}.'</h3>'.
1712: &Apache::loncommon::start_data_table().
1.205 raeburn 1713: &Apache::loncommon::start_data_table_row().
1.188 raeburn 1714: '<td>'.$authformnop;
1715: if ($can_modify) {
1716: $outcome .= '</td>'."\n".
1717: &Apache::loncommon::end_data_table_row().
1718: &Apache::loncommon::start_data_table_row().
1719: '<td>'.$authformcurrent.'</td>'.
1720: &Apache::loncommon::end_data_table_row()."\n";
1721: } else {
1.200 raeburn 1722: $outcome .= ' ('.$authformcurrent.')</td>'.
1723: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 1724: }
1.205 raeburn 1725: foreach my $item (@authform_others) {
1726: $outcome .= &Apache::loncommon::start_data_table_row().
1727: '<td>'.$item.'</td>'.
1728: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 1729: }
1.205 raeburn 1730: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 1731: } else {
1732: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1733: my %lt=&Apache::lonlocal::texthash(
1734: 'ccld' => "Change Current Login Data",
1735: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
1736: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1737: );
1738: $outcome .= <<ENDNOPRIV;
1739: <h3>$lt{'ccld'}</h3>
1740: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 1741: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 1742: ENDNOPRIV
1743: }
1744: }
1745: } ## End of "check for bad authentication type" logic
1746: return $outcome;
1747: }
1748:
1.187 raeburn 1749: sub modify_login_block {
1750: my ($dom,$currentauth) = @_;
1751: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
1752: my ($authnum,%can_assign) =
1753: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 1754: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 1755: if ($currentauth=~/^krb(4|5):/) {
1756: $authformcurrent=$authformkrb;
1757: if ($can_assign{'int'}) {
1.205 raeburn 1758: push(@authform_others,$authformint);
1.187 raeburn 1759: }
1760: if ($can_assign{'loc'}) {
1.205 raeburn 1761: push(@authform_others,$authformloc);
1.187 raeburn 1762: }
1763: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1764: $show_override_msg = 1;
1765: }
1766: } elsif ($currentauth=~/^internal:/) {
1767: $authformcurrent=$authformint;
1768: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1769: push(@authform_others,$authformkrb);
1.187 raeburn 1770: }
1771: if ($can_assign{'loc'}) {
1.205 raeburn 1772: push(@authform_others,$authformloc);
1.187 raeburn 1773: }
1774: if ($can_assign{'int'}) {
1775: $show_override_msg = 1;
1776: }
1777: } elsif ($currentauth=~/^unix:/) {
1778: $authformcurrent=$authformfsys;
1779: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1780: push(@authform_others,$authformkrb);
1.187 raeburn 1781: }
1782: if ($can_assign{'int'}) {
1.205 raeburn 1783: push(@authform_others,$authformint);
1.187 raeburn 1784: }
1785: if ($can_assign{'loc'}) {
1.205 raeburn 1786: push(@authform_others,$authformloc);
1.187 raeburn 1787: }
1788: if ($can_assign{'fsys'}) {
1789: $show_override_msg = 1;
1790: }
1791: } elsif ($currentauth=~/^localauth:/) {
1792: $authformcurrent=$authformloc;
1793: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1794: push(@authform_others,$authformkrb);
1.187 raeburn 1795: }
1796: if ($can_assign{'int'}) {
1.205 raeburn 1797: push(@authform_others,$authformint);
1.187 raeburn 1798: }
1799: if ($can_assign{'loc'}) {
1800: $show_override_msg = 1;
1801: }
1802: }
1803: if ($show_override_msg) {
1.205 raeburn 1804: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
1805: '</td></tr>'."\n".
1806: '<tr><td> </td>'.
1807: '<td><b>'.&mt('Currently in use').'</b></td>'.
1808: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 1809: &mt('will override current values').
1.205 raeburn 1810: '</span></td></tr></table>';
1.187 raeburn 1811: }
1.205 raeburn 1812: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 1813: }
1814:
1.188 raeburn 1815: sub personal_data_display {
1.252 raeburn 1816: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
1.286 raeburn 1817: my ($output,$showforceid,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 1818: my @userinfo = ('firstname','middlename','lastname','generation',
1819: 'permanentemail','id');
1.252 raeburn 1820: my $rowcount = 0;
1821: my $editable = 0;
1.286 raeburn 1822: %canmodify_status =
1823: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1824: ['inststatus'],$rolesarray);
1.253 raeburn 1825: if (!$newuser) {
1.188 raeburn 1826: # Get the users information
1827: %userenv = &Apache::lonnet::get('environment',
1828: ['firstname','middlename','lastname','generation',
1.286 raeburn 1829: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 1830: %canmodify =
1831: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 1832: \@userinfo,$rolesarray);
1.257 raeburn 1833: } elsif ($context eq 'selfcreate') {
1834: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
1835: $inst_results,$rolesarray);
1.188 raeburn 1836: }
1837: my %lt=&Apache::lonlocal::texthash(
1838: 'pd' => "Personal Data",
1839: 'firstname' => "First Name",
1840: 'middlename' => "Middle Name",
1841: 'lastname' => "Last Name",
1842: 'generation' => "Generation",
1843: 'permanentemail' => "Permanent e-mail address",
1.259 bisitz 1844: 'id' => "Student/Employee ID",
1.286 raeburn 1845: 'lg' => "Login Data",
1846: 'inststatus' => "Affiliation",
1.188 raeburn 1847: );
1848: my %textboxsize = (
1849: firstname => '15',
1850: middlename => '15',
1851: lastname => '15',
1852: generation => '5',
1853: permanentemail => '25',
1854: id => '15',
1855: );
1856: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
1857: $output = '<h3>'.$lt{'pd'}.'</h3>'.
1858: &Apache::lonhtmlcommon::start_pick_box();
1859: foreach my $item (@userinfo) {
1860: my $rowtitle = $lt{$item};
1.252 raeburn 1861: my $hiderow = 0;
1.188 raeburn 1862: if ($item eq 'generation') {
1863: $rowtitle = $genhelp.$rowtitle;
1864: }
1.252 raeburn 1865: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 1866: if ($newuser) {
1.210 raeburn 1867: if (ref($inst_results) eq 'HASH') {
1868: if ($inst_results->{$item} ne '') {
1.252 raeburn 1869: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 1870: } else {
1.252 raeburn 1871: if ($context eq 'selfcreate') {
1872: if ($canmodify{$item}) {
1873: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1874: $editable ++;
1875: } else {
1876: $hiderow = 1;
1877: }
1.253 raeburn 1878: } else {
1879: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 1880: }
1.210 raeburn 1881: }
1.188 raeburn 1882: } else {
1.252 raeburn 1883: if ($context eq 'selfcreate') {
1.287 raeburn 1884: if (($item eq 'permanentemail') && ($newuser eq 'email')) {
1885: $row .= $ccuname;
1.252 raeburn 1886: } else {
1.287 raeburn 1887: if ($canmodify{$item}) {
1888: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1889: $editable ++;
1890: } else {
1891: $hiderow = 1;
1892: }
1.252 raeburn 1893: }
1.253 raeburn 1894: } else {
1895: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 1896: }
1.188 raeburn 1897: }
1898: } else {
1.219 raeburn 1899: if ($canmodify{$item}) {
1.252 raeburn 1900: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.188 raeburn 1901: } else {
1.252 raeburn 1902: $row .= $userenv{$item};
1.188 raeburn 1903: }
1.206 raeburn 1904: if ($item eq 'id') {
1.219 raeburn 1905: $showforceid = $canmodify{$item};
1906: }
1.188 raeburn 1907: }
1.252 raeburn 1908: $row .= &Apache::lonhtmlcommon::row_closure(1);
1909: if (!$hiderow) {
1910: $output .= $row;
1911: $rowcount ++;
1912: }
1.188 raeburn 1913: }
1.286 raeburn 1914: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
1915: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
1916: if (ref($types) eq 'ARRAY') {
1917: if (@{$types} > 0) {
1918: my ($hiderow,$shown);
1919: if ($canmodify_status{'inststatus'}) {
1920: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
1921: } else {
1922: $shown .= $userenv{'inststatus'};
1923: if ($userenv{'inststatus'} eq '') {
1924: $hiderow = 1;
1925: }
1926: }
1927: if (!$hiderow) {
1928: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affliations'),undef,'LC_oddrow_value')."\n".
1929: $shown.&Apache::lonhtmlcommon::row_closure(1);
1930: if ($context eq 'selfcreate') {
1931: $rowcount ++;
1932: }
1933: $output .= $row;
1934: }
1935: }
1936: }
1937: }
1.188 raeburn 1938: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 1939: if (wantarray) {
1.252 raeburn 1940: if ($context eq 'selfcreate') {
1941: return($output,$rowcount,$editable);
1942: } else {
1943: return ($output,$showforceid);
1944: }
1.206 raeburn 1945: } else {
1946: return $output;
1947: }
1.188 raeburn 1948: }
1949:
1.286 raeburn 1950: sub pick_inst_statuses {
1951: my ($curr,$usertypes,$types) = @_;
1952: my ($output,$rem,@currtypes);
1953: if ($curr ne '') {
1954: @currtypes = map { &unescape($_); } split(/:/,$curr);
1955: }
1956: my $numinrow = 2;
1957: if (ref($types) eq 'ARRAY') {
1958: $output = '<table>';
1959: my $lastcolspan;
1960: for (my $i=0; $i<@{$types}; $i++) {
1961: if (defined($usertypes->{$types->[$i]})) {
1962: my $rem = $i%($numinrow);
1963: if ($rem == 0) {
1964: if ($i<@{$types}-1) {
1965: if ($i > 0) {
1966: $output .= '</tr>';
1967: }
1968: $output .= '<tr>';
1969: }
1970: } elsif ($i==@{$types}-1) {
1971: my $colsleft = $numinrow - $rem;
1972: if ($colsleft > 1) {
1973: $lastcolspan = ' colspan="'.$colsleft.'"';
1974: }
1975: }
1976: my $check = ' ';
1977: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
1978: $check = ' checked="checked" ';
1979: }
1980: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
1981: '<span class="LC_nobreak"><label>'.
1982: '<input type="checkbox" name="inststatus" '.
1983: 'value="'.$types->[$i].'"'.$check.'/>'.
1984: $usertypes->{$types->[$i]}.'</label></span></td>';
1985: }
1986: }
1987: $output .= '</tr></table>';
1988: }
1989: return $output;
1990: }
1991:
1.257 raeburn 1992: sub selfcreate_canmodify {
1993: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
1994: if (ref($inst_results) eq 'HASH') {
1995: my @inststatuses = &get_inststatuses($inst_results);
1996: if (@inststatuses == 0) {
1997: @inststatuses = ('default');
1998: }
1999: $rolesarray = \@inststatuses;
2000: }
2001: my %canmodify =
2002: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2003: $rolesarray);
2004: return %canmodify;
2005: }
2006:
1.252 raeburn 2007: sub get_inststatuses {
2008: my ($insthashref) = @_;
2009: my @inststatuses = ();
2010: if (ref($insthashref) eq 'HASH') {
2011: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2012: @inststatuses = @{$insthashref->{'inststatus'}};
2013: }
2014: }
2015: return @inststatuses;
2016: }
2017:
1.4 www 2018: # ================================================================= Phase Three
1.42 matthew 2019: sub update_user_data {
1.295.2.18 raeburn 2020: my ($r,$context,$crstype) = @_;
1.101 albertel 2021: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2022: $env{'form.ccdomain'});
1.27 matthew 2023: # Error messages
1.188 raeburn 2024: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2025: my $end = '</span><br /><br />';
2026: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2027: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2028: &mt('Return to previous page').'</a>'.
2029: &Apache::loncommon::end_page();
2030: my $now = time;
1.40 www 2031: my $title;
1.101 albertel 2032: if (exists($env{'form.makeuser'})) {
1.40 www 2033: $title='Set Privileges for New User';
2034: } else {
2035: $title='Modify User Privileges';
2036: }
1.213 raeburn 2037: my $newuser = 0;
1.160 raeburn 2038: my ($jsback,$elements) = &crumb_utilities();
2039: my $jscript = '<script type="text/javascript">'."\n".
1.295.2.4 raeburn 2040: '// <![CDATA['."\n".
2041: $jsback."\n".
2042: '// ]]>'."\n".
2043: '</script>'."\n";
1.295.2.18 raeburn 2044: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.233 raeburn 2045: my $args;
2046: if ($env{'form.popup'}) {
2047: $args->{'no_nav_bar'} = 1;
2048: } else {
2049: $args = undef;
2050: }
2051: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.160 raeburn 2052: &Apache::lonhtmlcommon::add_breadcrumb
2053: ({href=>"javascript:backPage(document.userupdate)",
1.213 raeburn 2054: text=>$breadcrumb_text{'search'},
1.160 raeburn 2055: faq=>282,bug=>'Instructor Interface',});
2056: if ($env{'form.prevphase'} eq 'userpicked') {
2057: &Apache::lonhtmlcommon::add_breadcrumb
2058: ({href=>"javascript:backPage(document.userupdate,'get_user_info','select')",
1.213 raeburn 2059: text=>$breadcrumb_text{'userpicked'},
1.160 raeburn 2060: faq=>282,bug=>'Instructor Interface',});
2061: }
2062: &Apache::lonhtmlcommon::add_breadcrumb
2063: ({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
1.219 raeburn 2064: text=>$breadcrumb_text{'modify'},
1.160 raeburn 2065: faq=>282,bug=>'Instructor Interface',},
2066: {href=>"/adm/createuser",
2067: text=>"Result",
2068: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 2069: my $helpitem = 'Course_Change_Privileges';
2070: if ($env{'form.action'} eq 'singlestudent') {
2071: $helpitem = 'Course_Add_Student';
2072: }
2073: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
2074: $helpitem));
1.188 raeburn 2075: $r->print(&update_result_form($uhome));
1.27 matthew 2076: # Check Inputs
1.101 albertel 2077: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2078: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2079: return;
2080: }
1.138 albertel 2081: if ( $env{'form.ccuname'} ne
2082: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2083: $r->print($error.&mt('Invalid login name.').' '.
2084: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2085: $end.$rtnlink);
1.27 matthew 2086: return;
2087: }
1.101 albertel 2088: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2089: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2090: return;
2091: }
1.138 albertel 2092: if ( $env{'form.ccdomain'} ne
2093: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2094: $r->print($error.&mt('Invalid domain name.').' '.
2095: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2096: $end.$rtnlink);
1.27 matthew 2097: return;
2098: }
1.219 raeburn 2099: if ($uhome eq 'no_host') {
2100: $newuser = 1;
2101: }
1.101 albertel 2102: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2103: # Modifying an existing user, so check the validity of the name
2104: if ($uhome eq 'no_host') {
1.73 sakharuk 2105: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 2106: $env{'form.ccuname'}.&mt(' in domain ').
2107: $env{'form.ccdomain'}.'.');
1.29 matthew 2108: return;
2109: }
2110: }
1.27 matthew 2111: # Determine authentication method and password for the user being modified
2112: my $amode='';
2113: my $genpwd='';
1.101 albertel 2114: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2115: $amode='krb';
1.101 albertel 2116: $amode.=$env{'form.krbver'};
2117: $genpwd=$env{'form.krbarg'};
2118: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2119: $amode='internal';
1.101 albertel 2120: $genpwd=$env{'form.intarg'};
2121: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2122: $amode='unix';
1.101 albertel 2123: $genpwd=$env{'form.fsysarg'};
2124: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2125: $amode='localauth';
1.101 albertel 2126: $genpwd=$env{'form.locarg'};
1.27 matthew 2127: $genpwd=" " if (!$genpwd);
1.101 albertel 2128: } elsif (($env{'form.login'} eq 'nochange') ||
2129: ($env{'form.login'} eq '' )) {
1.34 matthew 2130: # There is no need to tell the user we did not change what they
2131: # did not ask us to change.
1.35 matthew 2132: # If they are creating a new user but have not specified login
2133: # information this will be caught below.
1.30 matthew 2134: } else {
1.193 raeburn 2135: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.30 matthew 2136: return;
1.27 matthew 2137: }
1.164 albertel 2138:
1.188 raeburn 2139: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
2140: $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h3>');
1.193 raeburn 2141: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.267 raeburn 2142: my @usertools = ('aboutme','blog','portfolio');
1.275 raeburn 2143: my @requestcourses = ('official','unofficial');
1.286 raeburn 2144: my ($othertitle,$usertypes,$types) =
2145: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.101 albertel 2146: if ($env{'form.makeuser'}) {
1.164 albertel 2147: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2148: # Check for the authentication mode and password
2149: if (! $amode || ! $genpwd) {
1.193 raeburn 2150: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2151: return;
1.18 albertel 2152: }
1.29 matthew 2153: # Determine desired host
1.101 albertel 2154: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2155: if (lc($desiredhost) eq 'default') {
2156: $desiredhost = undef;
2157: } else {
1.147 albertel 2158: my %home_servers =
2159: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2160: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2161: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2162: return;
2163: }
2164: }
2165: # Check ID format
2166: my %checkhash;
2167: my %checks = ('id' => 1);
2168: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2169: 'newuser' => $newuser,
1.196 raeburn 2170: 'id' => $env{'form.cid'},
1.193 raeburn 2171: );
1.196 raeburn 2172: if ($env{'form.cid'} ne '') {
2173: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2174: \%rulematch,\%inst_results,\%curr_rules);
2175: if (ref($alerts{'id'}) eq 'HASH') {
2176: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2177: my $domdesc =
2178: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2179: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2180: my $userchkmsg;
2181: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2182: $userchkmsg =
2183: &Apache::loncommon::instrule_disallow_msg('id',
2184: $domdesc,1).
2185: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2186: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2187: }
2188: $r->print($error.&mt('Invalid ID format').$end.
2189: $userchkmsg.$rtnlink);
2190: return;
2191: }
2192: }
1.29 matthew 2193: }
2194: }
1.27 matthew 2195: # Call modifyuser
2196: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2197: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2198: $amode,$genpwd,$env{'form.cfirstname'},
2199: $env{'form.cmiddlename'},$env{'form.clastname'},
2200: $env{'form.cgeneration'},undef,$desiredhost,
2201: $env{'form.cpermanentemail'});
1.77 www 2202: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2203: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2204: $env{'form.ccdomain'});
1.267 raeburn 2205: my (%changeHash,%newcustom,%changed);
2206: if ($uhome ne 'no_host') {
2207: if ($env{'form.customquota'} == 1) {
2208: if ($env{'form.portfolioquota'} eq '') {
2209: $newcustom{'quota'} = 0;
2210: } else {
2211: $newcustom{'quota'} = $env{'form.portfolioquota'};
2212: $newcustom{'quota'} =~ s/[^\d\.]//g;
2213: }
2214: $changed{'quota'} = "a_admin($newcustom{'quota'},\%changeHash);
2215: }
2216: foreach my $item (@usertools) {
2217: if ($env{'form.custom'.$item} == 1) {
2218: $newcustom{$item} = $env{'form.tools_'.$item};
1.275 raeburn 2219: $changed{$item} = &tool_admin($item,$newcustom{$item},
2220: \%changeHash,'tools');
2221: }
2222: }
1.279 raeburn 2223: foreach my $item (@requestcourses) {
1.295.2.7 raeburn 2224: $newcustom{$item} = $env{'form.crsreq_'.$item};
2225: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2226: $newcustom{$item} .= '=';
2227: unless ($env{'form.crsreq_'.$item.'_limit'} =~ /\D/) {
2228: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2229: }
2230: }
1.279 raeburn 2231: $changed{$item} = &tool_admin($item,$newcustom{$item},
2232: \%changeHash,'requestcourses');
1.232 raeburn 2233: }
1.286 raeburn 2234: if (exists($env{'form.inststatus'})) {
2235: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2236: if (@inststatuses > 0) {
2237: $changeHash{'inststatus'} = join(',',@inststatuses);
2238: $changed{'inststatus'} = $changeHash{'inststatus'};
2239: }
2240: }
1.267 raeburn 2241: if (keys(%changed)) {
1.232 raeburn 2242: $changeHash{'firstname'} = $env{'form.cfirstname'};
2243: $changeHash{'middlename'} = $env{'form.cmiddlename'};
2244: $changeHash{'lastname'} = $env{'form.clastname'};
2245: $changeHash{'generation'} = $env{'form.cgeneration'};
2246: $changeHash{'id'} = $env{'form.cid'};
2247: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1.267 raeburn 2248: my $chgresult =
2249: &Apache::lonnet::put('environment',\%changeHash,
2250: $env{'form.ccdomain'},$env{'form.ccuname'});
2251: }
1.232 raeburn 2252: }
1.219 raeburn 2253: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2254: &Apache::lonnet::hostname($uhome));
1.101 albertel 2255: } elsif (($env{'form.login'} ne 'nochange') &&
2256: ($env{'form.login'} ne '' )) {
1.27 matthew 2257: # Modify user privileges
2258: if (! $amode || ! $genpwd) {
1.193 raeburn 2259: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2260: return;
1.20 harris41 2261: }
1.27 matthew 2262: # Only allow authentification modification if the person has authority
1.101 albertel 2263: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2264: $r->print('Modifying authentication: '.
1.31 matthew 2265: &Apache::lonnet::modifyuserauth(
1.101 albertel 2266: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2267: $amode,$genpwd));
1.102 albertel 2268: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2269: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2270: } else {
1.27 matthew 2271: # Okay, this is a non-fatal error.
1.193 raeburn 2272: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
1.27 matthew 2273: }
1.28 matthew 2274: }
2275: ##
1.295.2.18 raeburn 2276: my (@userroles,%userupdate,$cnum,$cdom,$crstype,$namechanged);
1.213 raeburn 2277: if ($context eq 'course') {
2278: ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.295.2.18 raeburn 2279: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.213 raeburn 2280: }
1.101 albertel 2281: if (! $env{'form.makeuser'} ) {
1.28 matthew 2282: # Check for need to change
2283: my %userenv = &Apache::lonnet::get
1.134 raeburn 2284: ('environment',['firstname','middlename','lastname','generation',
1.267 raeburn 2285: 'id','permanentemail','portfolioquota','inststatus','tools.aboutme',
1.279 raeburn 2286: 'tools.blog','tools.portfolio','requestcourses.official',
1.295.2.3 raeburn 2287: 'requestcourses.unofficial','requestcourses.community',
2288: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2289: 'reqcrsotherdom.community'],
1.160 raeburn 2290: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2291: my ($tmp) = keys(%userenv);
2292: if ($tmp =~ /^(con_lost|error)/i) {
2293: %userenv = ();
2294: }
1.206 raeburn 2295: my $no_forceid_alert;
2296: # Check to see if user information can be changed
2297: my %domconfig =
2298: &Apache::lonnet::get_dom('configuration',['usermodification'],
2299: $env{'form.ccdomain'});
1.213 raeburn 2300: my @statuses = ('active','future');
2301: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2302: my ($auname,$audom);
1.220 raeburn 2303: if ($context eq 'author') {
1.206 raeburn 2304: $auname = $env{'user.name'};
2305: $audom = $env{'user.domain'};
2306: }
2307: foreach my $item (keys(%roles)) {
1.220 raeburn 2308: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2309: if ($context eq 'course') {
2310: if ($cnum ne '' && $cdom ne '') {
2311: if ($rolenum eq $cnum && $roledom eq $cdom) {
2312: if (!grep(/^\Q$role\E$/,@userroles)) {
2313: push(@userroles,$role);
2314: }
2315: }
2316: }
2317: } elsif ($context eq 'author') {
2318: if ($rolenum eq $auname && $roledom eq $audom) {
2319: if (!grep(/^\Q$role\E$/,@userroles)) {
2320: push(@userroles,$role);
2321: }
2322: }
2323: }
2324: }
1.220 raeburn 2325: if ($env{'form.action'} eq 'singlestudent') {
2326: if (!grep(/^st$/,@userroles)) {
2327: push(@userroles,'st');
2328: }
2329: } else {
2330: # Check for course or co-author roles being activated or re-enabled
2331: if ($context eq 'author' || $context eq 'course') {
2332: foreach my $key (keys(%env)) {
2333: if ($context eq 'author') {
2334: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2335: if (!grep(/^\Q$1\E$/,@userroles)) {
2336: push(@userroles,$1);
2337: }
2338: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2339: if (!grep(/^\Q$1\E$/,@userroles)) {
2340: push(@userroles,$1);
2341: }
1.206 raeburn 2342: }
1.220 raeburn 2343: } elsif ($context eq 'course') {
2344: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2345: if (!grep(/^\Q$1\E$/,@userroles)) {
2346: push(@userroles,$1);
2347: }
2348: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
2349: if (!grep(/^\Q$1\E$/,@userroles)) {
2350: push(@userroles,$1);
2351: }
1.206 raeburn 2352: }
2353: }
2354: }
2355: }
2356: }
2357: #Check to see if we can change personal data for the user
2358: my (@mod_disallowed,@longroles);
2359: foreach my $role (@userroles) {
2360: if ($role eq 'cr') {
2361: push(@longroles,'Custom');
2362: } else {
1.295.2.18 raeburn 2363: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 2364: }
2365: }
1.219 raeburn 2366: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
2367: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
2368: foreach my $item (@userinfo) {
1.28 matthew 2369: # Strip leading and trailing whitespace
1.203 raeburn 2370: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 2371: if (!$canmodify{$item}) {
1.207 raeburn 2372: if (defined($env{'form.c'.$item})) {
2373: if ($env{'form.c'.$item} ne $userenv{$item}) {
2374: push(@mod_disallowed,$item);
2375: }
1.206 raeburn 2376: }
2377: $env{'form.c'.$item} = $userenv{$item};
2378: }
1.28 matthew 2379: }
1.259 bisitz 2380: # Check to see if we can change the Student/Employee ID
1.196 raeburn 2381: my $forceid = $env{'form.forceid'};
2382: my $recurseid = $env{'form.recurseid'};
2383: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 2384: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
2385: $env{'form.ccuname'});
2386: if (($uidhash{$env{'form.ccuname'}}) &&
2387: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
2388: (!$forceid)) {
2389: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
2390: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 2391: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 2392: .'<br />'
2393: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
2394: .'<br />'."\n";
1.203 raeburn 2395: }
2396: }
2397: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 2398: my $checkhash;
2399: my $checks = { 'id' => 1 };
2400: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
2401: { 'newuser' => $newuser,
2402: 'id' => $env{'form.cid'},
2403: };
2404: &Apache::loncommon::user_rule_check($checkhash,$checks,
2405: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
2406: if (ref($alerts{'id'}) eq 'HASH') {
2407: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 2408: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 2409: }
2410: }
2411: }
1.286 raeburn 2412: my ($quotachanged,$oldportfolioquota,$newportfolioquota,$oldinststatus,
2413: $inststatus,$newinststatus,$oldisdefault,$newisdefault,$olddefquotatext,
2414: $newdefquotatext,%oldaccess,%oldaccesstext,%newaccess,%newaccesstext,
2415: $oldinststatuses,$newinststatuses);
1.149 raeburn 2416: my ($defquota,$settingstatus) =
2417: &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
1.295.2.3 raeburn 2418: my ($showquota,$showtools,$showrequestcourses,$showinststatus,$showreqotherdom);
1.220 raeburn 2419: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
2420: $showquota = 1;
2421: }
1.267 raeburn 2422: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
2423: $showtools = 1;
2424: }
1.275 raeburn 2425: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
2426: $showrequestcourses = 1;
1.295.2.3 raeburn 2427: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
2428: $showreqotherdom = 1;
1.275 raeburn 2429: }
1.286 raeburn 2430: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
2431: $showinststatus = 1;
2432: }
1.267 raeburn 2433: my (%changeHash,%changed);
1.286 raeburn 2434: $oldinststatus = $userenv{'inststatus'};
2435: if ($oldinststatus eq '') {
2436: $oldinststatuses = $othertitle;
2437: } else {
2438: if (ref($usertypes) eq 'HASH') {
2439: $oldinststatuses = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
2440: } else {
2441: $oldinststatuses = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
2442: }
2443: }
2444: $changeHash{'inststatus'} = $userenv{'inststatus'};
2445: my %canmodify_inststatus = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},['inststatus'],\@userroles);
2446: if ($canmodify_inststatus{'inststatus'}) {
2447: if (exists($env{'form.inststatus'})) {
2448: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2449: if (@inststatuses > 0) {
2450: $newinststatus = join(':',map { &escape($_); } @inststatuses);
2451: $changeHash{'inststatus'} = $newinststatus;
2452: if ($newinststatus ne $oldinststatus) {
2453: $changed{'inststatus'} = $newinststatus;
2454: }
2455: if (ref($usertypes) eq 'HASH') {
2456: $newinststatuses = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
2457: } else {
2458: $newinststatuses = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
2459: }
2460: } else {
2461: $newinststatus = '';
2462: $changeHash{'inststatus'} = $newinststatus;
2463: $newinststatuses = $othertitle;
2464: if ($newinststatus ne $oldinststatus) {
2465: $changed{'inststatus'} = $changeHash{'inststatus'};
2466: }
2467: }
2468: }
2469: }
1.204 raeburn 2470: $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
1.149 raeburn 2471: if ($userenv{'portfolioquota'} ne '') {
1.134 raeburn 2472: $oldportfolioquota = $userenv{'portfolioquota'};
1.149 raeburn 2473: if ($env{'form.customquota'} == 1) {
2474: if ($env{'form.portfolioquota'} eq '') {
2475: $newportfolioquota = 0;
2476: } else {
2477: $newportfolioquota = $env{'form.portfolioquota'};
2478: $newportfolioquota =~ s/[^\d\.]//g;
2479: }
1.204 raeburn 2480: if ($newportfolioquota != $oldportfolioquota) {
1.267 raeburn 2481: $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash);
1.134 raeburn 2482: }
1.149 raeburn 2483: } else {
1.267 raeburn 2484: $changed{'quota'} = "a_admin('',\%changeHash);
1.149 raeburn 2485: $newportfolioquota = $defquota;
1.284 bisitz 2486: $newisdefault = 1;
1.134 raeburn 2487: }
2488: } else {
1.204 raeburn 2489: $oldisdefault = 1;
1.149 raeburn 2490: $oldportfolioquota = $defquota;
2491: if ($env{'form.customquota'} == 1) {
2492: if ($env{'form.portfolioquota'} eq '') {
2493: $newportfolioquota = 0;
2494: } else {
2495: $newportfolioquota = $env{'form.portfolioquota'};
2496: $newportfolioquota =~ s/[^\d\.]//g;
2497: }
1.267 raeburn 2498: $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash);
1.149 raeburn 2499: } else {
2500: $newportfolioquota = $defquota;
1.204 raeburn 2501: $newisdefault = 1;
1.149 raeburn 2502: }
2503: }
1.204 raeburn 2504: if ($oldisdefault) {
2505: $olddefquotatext = &get_defaultquota_text($settingstatus);
2506: }
2507: if ($newisdefault) {
2508: $newdefquotatext = &get_defaultquota_text($settingstatus);
1.134 raeburn 2509: }
1.275 raeburn 2510: &tool_changes('tools',\@usertools,\%oldaccess,\%oldaccesstext,\%userenv,
2511: \%changeHash,\%changed,\%newaccess,\%newaccesstext);
1.295.2.3 raeburn 2512: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
2513: &tool_changes('requestcourses',\@requestcourses,\%oldaccess,\%oldaccesstext,
2514: \%userenv,\%changeHash,\%changed,\%newaccess,\%newaccesstext);
2515: } else {
2516: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldaccess,\%oldaccesstext,
2517: \%userenv,\%changeHash,\%changed,\%newaccess,\%newaccesstext);
2518: }
1.206 raeburn 2519: if ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
2520: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
2521: $env{'form.clastname'} ne $userenv{'lastname'} ||
2522: $env{'form.cgeneration'} ne $userenv{'generation'} ||
2523: $env{'form.cid'} ne $userenv{'id'} ||
2524: $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} ) {
1.134 raeburn 2525: $namechanged = 1;
2526: }
1.267 raeburn 2527: if (($namechanged) || (keys(%changed) > 0)) {
1.101 albertel 2528: $changeHash{'firstname'} = $env{'form.cfirstname'};
2529: $changeHash{'middlename'} = $env{'form.cmiddlename'};
2530: $changeHash{'lastname'} = $env{'form.clastname'};
2531: $changeHash{'generation'} = $env{'form.cgeneration'};
1.196 raeburn 2532: $changeHash{'id'} = $env{'form.cid'};
1.174 raeburn 2533: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1.267 raeburn 2534: my ($chgresult,$namechgresult);
2535: if (keys(%changed) > 0) {
2536: $chgresult =
1.204 raeburn 2537: &Apache::lonnet::put('environment',\%changeHash,
2538: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 2539: if ($chgresult eq 'ok') {
2540: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
2541: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 2542: my %newenvhash;
2543: foreach my $key (keys(%changed)) {
1.275 raeburn 2544: if (($key eq 'official') || ($key eq 'unofficial')) {
1.279 raeburn 2545: $newenvhash{'environment.requestcourses.'.$key} =
2546: $changeHash{'requestcourses.'.$key};
2547: if ($changeHash{'requestcourses.'.$key} ne '') {
1.295.2.15 raeburn 2548: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 2549: } else {
2550: $newenvhash{'environment.canrequest.'.$key} =
2551: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
2552: $key,'reload','requestcourses');
2553: }
1.275 raeburn 2554: } elsif ($key ne 'quota') {
1.270 raeburn 2555: $newenvhash{'environment.tools.'.$key} =
2556: $changeHash{'tools.'.$key};
1.279 raeburn 2557: if ($changeHash{'tools.'.$key} ne '') {
2558: $newenvhash{'environment.availabletools.'.$key} =
2559: $changeHash{'tools.'.$key};
2560: } else {
2561: $newenvhash{'environment.availabletools.'.$key} =
2562: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'}, $key,'reload','tools');
2563: }
1.270 raeburn 2564: }
2565: }
1.271 raeburn 2566: if (keys(%newenvhash)) {
2567: &Apache::lonnet::appenv(\%newenvhash);
2568: }
1.267 raeburn 2569: }
2570: }
1.204 raeburn 2571: }
2572: if ($namechanged) {
2573: # Make the change
2574: $namechgresult =
2575: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
2576: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
2577: $changeHash{'firstname'},$changeHash{'middlename'},
2578: $changeHash{'lastname'},$changeHash{'generation'},
2579: $changeHash{'id'},undef,$changeHash{'permanentemail'});
1.220 raeburn 2580: %userupdate = (
2581: lastname => $env{'form.clastname'},
2582: middlename => $env{'form.cmiddlename'},
2583: firstname => $env{'form.cfirstname'},
2584: generation => $env{'form.cgeneration'},
2585: id => $env{'form.cid'},
2586: );
1.204 raeburn 2587: }
2588: if (($namechanged && $namechgresult eq 'ok') ||
1.267 raeburn 2589: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 2590: # Tell the user we changed the name
1.73 sakharuk 2591: my %lt=&Apache::lonlocal::texthash(
1.284 bisitz 2592: 'uic' => 'User Information Changed',
2593: 'frst' => 'First Name',
2594: 'mddl' => 'Middle Name',
2595: 'lst' => 'Last Name',
2596: 'gen' => 'Generation',
2597: 'id' => 'Student/Employee ID',
2598: 'mail' => 'Permanent e-mail address',
2599: 'disk' => 'Disk space allocated to portfolio files',
2600: 'blog' => 'Blog Availability',
2601: 'aboutme' => 'Personal Information Page Availability',
2602: 'portfolio' => 'Portfolio Availability',
2603: 'official' => 'Can Request Official Courses',
2604: 'unofficial' => 'Can Request Unofficial Courses',
1.286 raeburn 2605: 'inststatus' => "Affiliation",
1.284 bisitz 2606: 'prvs' => 'Previous Value:',
2607: 'chto' => 'Changed To:'
1.73 sakharuk 2608: );
1.201 raeburn 2609: $r->print('<h4>'.$lt{'uic'}.'</h4>'.
2610: &Apache::loncommon::start_data_table().
2611: &Apache::loncommon::start_data_table_header_row());
1.28 matthew 2612: $r->print(<<"END");
1.201 raeburn 2613: <th> </th>
1.73 sakharuk 2614: <th>$lt{'frst'}</th>
2615: <th>$lt{'mddl'}</th>
2616: <th>$lt{'lst'}</th>
1.134 raeburn 2617: <th>$lt{'gen'}</th>
1.196 raeburn 2618: <th>$lt{'id'}</th>
1.173 raeburn 2619: <th>$lt{'mail'}</th>
1.201 raeburn 2620: END
1.286 raeburn 2621: if ($showinststatus) {
2622: $r->print("
2623: <th>$lt{'inststatus'}</th>\n");
2624: }
1.275 raeburn 2625: if ($showrequestcourses) {
2626: foreach my $item (@requestcourses) {
2627: $r->print("
2628: <th>$lt{$item}</th>\n");
2629: }
1.295.2.3 raeburn 2630: } elsif ($showreqotherdom) {
2631: foreach my $item (@requestcourses) {
2632: $r->print("
2633: <th>$lt{$item}</th>\n");
2634: }
1.275 raeburn 2635: }
1.220 raeburn 2636: if ($showquota) {
2637: $r->print("
2638: <th>$lt{'disk'}</th>\n");
2639: }
1.267 raeburn 2640: if ($showtools) {
2641: foreach my $item (@usertools) {
2642: $r->print("
2643: <th>$lt{$item}</th>\n");
2644: }
2645: }
1.201 raeburn 2646: $r->print(&Apache::loncommon::end_data_table_header_row().
2647: &Apache::loncommon::start_data_table_row());
2648: $r->print(<<"END");
2649: <td><b>$lt{'prvs'}</b></td>
1.28 matthew 2650: <td>$userenv{'firstname'} </td>
2651: <td>$userenv{'middlename'} </td>
2652: <td>$userenv{'lastname'} </td>
1.134 raeburn 2653: <td>$userenv{'generation'} </td>
1.196 raeburn 2654: <td>$userenv{'id'}</td>
1.160 raeburn 2655: <td>$userenv{'permanentemail'} </td>
1.201 raeburn 2656: END
1.286 raeburn 2657: if ($showinststatus) {
2658: $r->print("
2659: <td>$oldinststatuses</td>\n");
2660: }
1.275 raeburn 2661: if ($showrequestcourses) {
2662: foreach my $item (@requestcourses) {
2663: $r->print("
2664: <td>$oldaccess{$item} $oldaccesstext{$item}</td>\n");
2665: }
1.295.2.3 raeburn 2666: } elsif ($showreqotherdom) {
2667: foreach my $item (@requestcourses) {
2668: $r->print("
2669: <td>$oldaccess{$item} $oldaccesstext{$item}</td>\n");
2670: }
1.275 raeburn 2671: }
1.220 raeburn 2672: if ($showquota) {
2673: $r->print("
2674: <td>$oldportfolioquota Mb $olddefquotatext </td>\n");
2675: }
1.267 raeburn 2676: if ($showtools) {
2677: foreach my $item (@usertools) {
2678: $r->print("
2679: <td>$oldaccess{$item} $oldaccesstext{$item} </td>\n");
2680: }
2681: }
1.201 raeburn 2682: $r->print(&Apache::loncommon::end_data_table_row().
2683: &Apache::loncommon::start_data_table_row());
2684: $r->print(<<"END");
1.267 raeburn 2685: <td><span class="LC_nobreak"><b>$lt{'chto'}</b></span></td>
1.101 albertel 2686: <td>$env{'form.cfirstname'} </td>
2687: <td>$env{'form.cmiddlename'} </td>
2688: <td>$env{'form.clastname'} </td>
1.134 raeburn 2689: <td>$env{'form.cgeneration'} </td>
1.196 raeburn 2690: <td>$env{'form.cid'} </td>
1.160 raeburn 2691: <td>$env{'form.cpermanentemail'} </td>
1.28 matthew 2692: END
1.286 raeburn 2693: if ($showinststatus) {
2694: $r->print("
2695: <td>$newinststatuses</td>\n");
2696: }
1.275 raeburn 2697: if ($showrequestcourses) {
2698: foreach my $item (@requestcourses) {
2699: $r->print("
2700: <td>$newaccess{$item} $newaccesstext{$item} </td>\n");
2701: }
1.295.2.3 raeburn 2702: } elsif ($showreqotherdom) {
2703: foreach my $item (@requestcourses) {
2704: $r->print("
2705: <td>$newaccess{$item} $newaccesstext{$item} </td>\n");
2706: }
1.275 raeburn 2707: }
1.220 raeburn 2708: if ($showquota) {
2709: $r->print("
2710: <td>$newportfolioquota Mb $newdefquotatext </td>\n");
2711: }
1.267 raeburn 2712: if ($showtools) {
2713: foreach my $item (@usertools) {
2714: $r->print("
2715: <td>$newaccess{$item} $newaccesstext{$item} </td>\n");
2716: }
2717: }
1.201 raeburn 2718: $r->print(&Apache::loncommon::end_data_table_row().
1.206 raeburn 2719: &Apache::loncommon::end_data_table().'<br />');
1.203 raeburn 2720: if ($env{'form.cid'} ne $userenv{'id'}) {
2721: &Apache::lonnet::idput($env{'form.ccdomain'},
2722: ($env{'form.ccuname'} => $env{'form.cid'}));
2723: if (($recurseid) &&
2724: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
2725: my $idresult =
2726: &Apache::lonuserutils::propagate_id_change(
2727: $env{'form.ccuname'},$env{'form.ccdomain'},
2728: \%userupdate);
2729: $r->print('<br />'.$idresult.'<br />');
2730: }
1.196 raeburn 2731: }
1.149 raeburn 2732: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
2733: ($env{'form.ccuname'} eq $env{'user.name'})) {
2734: my %newenvhash;
2735: foreach my $key (keys(%changeHash)) {
2736: $newenvhash{'environment.'.$key} = $changeHash{$key};
2737: }
1.238 raeburn 2738: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 2739: }
1.28 matthew 2740: } else { # error occurred
1.188 raeburn 2741: $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
2742: $env{'form.ccuname'}.' '.&mt('in domain').' '.
1.206 raeburn 2743: $env{'form.ccdomain'}.'</span><br />');
1.28 matthew 2744: }
1.101 albertel 2745: } else { # End of if ($env ... ) logic
1.275 raeburn 2746: # They did not want to change the users name, quota, tool availability,
2747: # or ability to request creation of courses,
1.267 raeburn 2748: # but we can still tell them what the name and quota and availabilities are
1.73 sakharuk 2749: my %lt=&Apache::lonlocal::texthash(
1.275 raeburn 2750: 'id' => "Student/Employee ID",
1.284 bisitz 2751: 'mail' => "Permanent e-mail address",
1.275 raeburn 2752: 'disk' => "Disk space allocated to user's portfolio files",
2753: 'blog' => "Blog Availability",
1.285 weissno 2754: 'aboutme' => "Personal Information Page Availability",
1.275 raeburn 2755: 'portfolio' => "Portfolio Availability",
2756: 'official' => "Can Request Official Courses",
1.295.2.14 raeburn 2757: 'unofficial' => "Can Request Unofficial Courses",
1.286 raeburn 2758: 'inststatus' => "Affiliation",
1.73 sakharuk 2759: );
1.134 raeburn 2760: $r->print(<<"END");
1.196 raeburn 2761: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
1.28 matthew 2762: END
1.204 raeburn 2763: if ($userenv{'permanentemail'} ne '') {
2764: $r->print('<br />['.$lt{'mail'}.': '.
2765: $userenv{'permanentemail'}.']');
1.134 raeburn 2766: }
1.286 raeburn 2767: if ($showinststatus) {
2768: $r->print('<br />['.$lt{'inststatus'}.': '.$oldinststatuses.']');
2769: }
1.275 raeburn 2770: if ($showrequestcourses) {
2771: foreach my $item (@requestcourses) {
2772: $r->print('<br />['.$lt{$item}.': '.$newaccess{$item}.' '.
2773: $newaccesstext{$item}.']'."\n");
2774: }
1.295.2.3 raeburn 2775: } elsif ($showreqotherdom) {
2776: foreach my $item (@requestcourses) {
2777: $r->print('<br />['.$lt{$item}.': '.$newaccess{$item}.' '.
2778: $newaccesstext{$item}.']'."\n");
2779: }
1.275 raeburn 2780: }
1.267 raeburn 2781: if ($showtools) {
2782: foreach my $item (@usertools) {
2783: $r->print('<br />['.$lt{$item}.': '.$newaccess{$item}.' '.
2784: $newaccesstext{$item}.']'."\n");
2785: }
2786: }
1.220 raeburn 2787: if ($showquota) {
1.267 raeburn 2788: $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '.
1.220 raeburn 2789: $olddefquotatext.']');
2790: }
2791: $r->print('</h4>');
1.28 matthew 2792: }
1.206 raeburn 2793: if (@mod_disallowed) {
2794: my ($rolestr,$contextname);
2795: if (@longroles > 0) {
2796: $rolestr = join(', ',@longroles);
2797: } else {
2798: $rolestr = &mt('No roles');
2799: }
2800: if ($context eq 'course') {
2801: $contextname = &mt('course');
2802: } elsif ($context eq 'author') {
2803: $contextname = &mt('co-author');
2804: }
2805: $r->print(&mt('The following fields were not updated: ').'<ul>');
2806: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2807: foreach my $field (@mod_disallowed) {
2808: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
2809: }
1.207 raeburn 2810: $r->print('</ul>');
2811: if (@mod_disallowed == 1) {
2812: $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));
2813: } else {
2814: $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));
2815: }
1.292 bisitz 2816: my $helplink = 'javascript:helpMenu('."'display'".')';
2817: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
2818: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
2819: ,'<a href="'.$helplink.'">','</a>')
2820: .'<br />');
1.206 raeburn 2821: }
1.259 bisitz 2822: $r->print('<span class="LC_warning">'
2823: .$no_forceid_alert
2824: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
2825: .'</span>');
1.4 www 2826: }
1.220 raeburn 2827: if ($env{'form.action'} eq 'singlestudent') {
1.295.2.18 raeburn 2828: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype);
2829: $r->print('<p><a href="javascript:backPage(document.userupdate)">');
2830: if ($crstype eq 'Community') {
2831: $r->print(&mt('Enroll Another Member'));
2832: } else {
2833: $r->print(&mt('Enroll Another Student'));
2834: }
2835: $r->print('</a></p>');
1.220 raeburn 2836: } else {
1.239 raeburn 2837: my @rolechanges = &update_roles($r,$context);
1.225 raeburn 2838: if ($namechanged) {
1.220 raeburn 2839: if ($context eq 'course') {
2840: if (@userroles > 0) {
1.225 raeburn 2841: if ((@rolechanges == 0) ||
2842: (!(grep(/^st$/,@rolechanges)))) {
2843: if (grep(/^st$/,@userroles)) {
2844: my $classlistupdated =
2845: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 2846: $cnum,$env{'form.ccdomain'},
2847: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 2848: }
1.220 raeburn 2849: }
2850: }
2851: }
2852: }
1.226 raeburn 2853: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 2854: $env{'form.ccdomain'});
2855: if ($env{'form.popup'}) {
2856: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
2857: } else {
1.246 bisitz 2858: $r->print('<p><a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
2859: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>'
2860: .(' 'x5).'<a href="javascript:backPage(document.userupdate)">'
2861: .&mt('Create/Modify Another User').'</a></p>');
1.233 raeburn 2862: }
1.220 raeburn 2863: }
2864: $r->print(&Apache::loncommon::end_page());
2865: }
2866:
1.275 raeburn 2867: sub tool_changes {
2868: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
2869: $changed,$newaccess,$newaccesstext) = @_;
2870: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
2871: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
2872: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
2873: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
2874: return;
2875: }
1.295.2.3 raeburn 2876: if ($context eq 'reqcrsotherdom') {
1.295.2.10 raeburn 2877: my @options = ('approval','validate','autolimit');
1.295.2.3 raeburn 2878: my $optregex = join('|',@options);
2879: my %reqdisplay = &courserequest_display();
2880: my $cdom = $env{'request.role.domain'};
2881: foreach my $tool (@{$usertools}) {
1.295.2.14 raeburn 2882: $oldaccesstext->{$tool} = &mt('No');
2883: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.295.2.7 raeburn 2884: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.295.2.14 raeburn 2885: my $newop;
2886: if ($env{'form.'.$context.'_'.$tool}) {
2887: $newop = $env{'form.'.$context.'_'.$tool};
2888: if ($newop eq 'autolimit') {
2889: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
2890: $limit =~ s/\D+//g;
2891: $newop .= '='.$limit;
2892: }
2893: }
1.295.2.3 raeburn 2894: if ($userenv->{$context.'.'.$tool} eq '') {
1.295.2.14 raeburn 2895: if ($newop) {
2896: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.295.2.3 raeburn 2897: $changeHash,$context);
2898: if ($changed->{$tool}) {
1.295.2.14 raeburn 2899: $newaccesstext->{$tool} = &mt('Yes');
1.295.2.3 raeburn 2900: } else {
1.295.2.14 raeburn 2901: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
2902: }
1.295.2.3 raeburn 2903: }
2904: } else {
2905: my @curr = split(',',$userenv->{$context.'.'.$tool});
2906: my @new;
2907: my $changedoms;
1.295.2.14 raeburn 2908: foreach my $req (@curr) {
2909: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
2910: $oldaccesstext->{$tool} = &mt('Yes');
2911: my $oldop = $1;
2912: if ($oldop ne $newop) {
2913: $changedoms = 1;
2914: foreach my $item (@curr) {
2915: my ($reqdom,$option) = split(':',$item);
2916: unless ($reqdom eq $cdom) {
2917: push(@new,$item);
2918: }
1.295.2.3 raeburn 2919: }
1.295.2.14 raeburn 2920: if ($newop) {
2921: push(@new,$cdom.':'.$newop);
2922: }
2923: @new = sort(@new);
1.295.2.3 raeburn 2924: }
1.295.2.14 raeburn 2925: last;
1.295.2.3 raeburn 2926: }
1.295.2.14 raeburn 2927: }
2928: if ((!$changedoms) && ($newop)) {
1.295.2.3 raeburn 2929: $changedoms = 1;
2930: @new = sort(@curr,$cdom.':'.$newop);
2931: }
2932: if ($changedoms) {
2933: my $newdomstr;
2934: if (@new) {
2935: $newdomstr = join(',',@new);
2936: }
2937: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
2938: $context);
2939: if ($changed->{$tool}) {
2940: if ($env{'form.'.$context.'_'.$tool}) {
2941: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.295.2.14 raeburn 2942: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
2943: $limit =~ s/\D+//g;
2944: if ($limit) {
2945: $newaccesstext->{$tool} = &mt('Yes, up to limit of [quant,_1,request] per user.',$limit);
1.295.2.3 raeburn 2946: } else {
1.295.2.14 raeburn 2947: $newaccesstext->{$tool} = &mt('Yes, processed automatically');
1.295.2.3 raeburn 2948: }
2949: } else {
2950: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
2951: }
2952: } else {
2953: $newaccesstext->{$tool} = &mt('No');
2954: }
2955: }
2956: }
2957: }
2958: }
2959: return;
2960: }
1.275 raeburn 2961: foreach my $tool (@{$usertools}) {
1.295.2.7 raeburn 2962: my $newval;
2963: if ($context eq 'requestcourses') {
2964: $newval = $env{'form.crsreq_'.$tool};
2965: if ($newval eq 'autolimit') {
2966: $newval .= '='.$env{'form.crsreq_'.$tool.'_limit'};
2967: }
2968: } else {
2969: $newval = $env{'form.'.$context.'_'.$tool};
2970: }
1.275 raeburn 2971: if ($userenv->{$context.'.'.$tool} ne '') {
2972: $oldaccess->{$tool} = &mt('custom');
2973: if ($userenv->{$context.'.'.$tool}) {
2974: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
2975: } else {
2976: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
2977: }
1.279 raeburn 2978: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.275 raeburn 2979: if ($env{'form.custom'.$tool} == 1) {
1.295.2.7 raeburn 2980: if ($newval ne $userenv->{$context.'.'.$tool}) {
2981: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
2982: $context);
1.275 raeburn 2983: if ($changed->{$tool}) {
2984: $newaccess->{$tool} = &mt('custom');
1.295.2.7 raeburn 2985: if ($newval) {
1.275 raeburn 2986: $newaccesstext->{$tool} = &mt("availability set to 'on'");
2987: } else {
2988: $newaccesstext->{$tool} = &mt("availability set to 'off'");
2989: }
2990: } else {
2991: $newaccess->{$tool} = $oldaccess->{$tool};
2992: if ($userenv->{$context.'.'.$tool}) {
2993: $newaccesstext->{$tool} = &mt("availability set to 'on'");
2994: } else {
2995: $newaccesstext->{$tool} = &mt("availability set to 'off'");
2996: }
2997: }
2998: } else {
2999: $newaccess->{$tool} = $oldaccess->{$tool};
3000: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3001: }
3002: } else {
3003: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3004: if ($changed->{$tool}) {
3005: $newaccess->{$tool} = &mt('default');
3006: } else {
3007: $newaccess->{$tool} = $oldaccess->{$tool};
3008: if ($userenv->{$context.'.'.$tool}) {
1.295.2.7 raeburn 3009: $newaccesstext->{$tool} = &mt("availability set to 'on'");
1.275 raeburn 3010: } else {
1.295.2.7 raeburn 3011: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.275 raeburn 3012: }
3013: }
3014: }
3015: } else {
3016: $oldaccess->{$tool} = &mt('default');
3017: if ($env{'form.custom'.$tool} == 1) {
1.295.2.7 raeburn 3018: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3019: $context);
1.275 raeburn 3020: if ($changed->{$tool}) {
3021: $newaccess->{$tool} = &mt('custom');
1.295.2.7 raeburn 3022: if ($newval) {
1.275 raeburn 3023: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3024: } else {
3025: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3026: }
3027: } else {
3028: $newaccess->{$tool} = $oldaccess->{$tool};
3029: }
3030: } else {
3031: $newaccess->{$tool} = $oldaccess->{$tool};
3032: }
3033: }
3034: }
3035: return;
3036: }
3037:
1.220 raeburn 3038: sub update_roles {
1.239 raeburn 3039: my ($r,$context) = @_;
1.4 www 3040: my $now=time;
1.225 raeburn 3041: my @rolechanges;
1.220 raeburn 3042: my %disallowed;
1.73 sakharuk 3043: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 3044: foreach my $key (keys (%env)) {
3045: next if (! $env{$key});
1.190 raeburn 3046: next if ($key eq 'form.action');
1.27 matthew 3047: # Revoke roles
1.135 raeburn 3048: if ($key=~/^form\.rev/) {
3049: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3050: # Revoke standard role
1.170 albertel 3051: my ($scope,$role) = ($1,$2);
3052: my $result =
3053: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3054: $env{'form.ccuname'},
1.239 raeburn 3055: $scope,$role,'','',$context);
1.170 albertel 3056: $r->print(&mt('Revoking [_1] in [_2]: [_3]',
3057: $role,$scope,'<b>'.$result.'</b>').'<br />');
3058: if ($role eq 'st') {
1.202 raeburn 3059: my $result =
1.198 raeburn 3060: &Apache::lonuserutils::classlist_drop($scope,
3061: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3062: $now);
1.170 albertel 3063: $r->print($result);
1.53 www 3064: }
1.225 raeburn 3065: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3066: push(@rolechanges,$role);
3067: }
1.196 raeburn 3068: }
1.195 raeburn 3069: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3070: # Revoke custom role
1.113 raeburn 3071: $r->print(&mt('Revoking custom role:').
1.139 albertel 3072: ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
1.101 albertel 3073: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
1.239 raeburn 3074: $env{'form.ccuname'},$1,$2,$3,$4,'','',$context).
1.102 albertel 3075: '</b><br />');
1.225 raeburn 3076: if (!grep(/^cr$/,@rolechanges)) {
3077: push(@rolechanges,'cr');
3078: }
1.64 www 3079: }
1.135 raeburn 3080: } elsif ($key=~/^form\.del/) {
3081: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3082: # Delete standard role
1.170 albertel 3083: my ($scope,$role) = ($1,$2);
3084: my $result =
3085: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3086: $env{'form.ccuname'},
1.239 raeburn 3087: $scope,$role,$now,0,1,'',
3088: $context);
1.170 albertel 3089: $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
3090: '<b>'.$result.'</b>').'<br />');
3091: if ($role eq 'st') {
1.202 raeburn 3092: my $result =
1.198 raeburn 3093: &Apache::lonuserutils::classlist_drop($scope,
3094: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3095: $now);
1.170 albertel 3096: $r->print($result);
1.81 albertel 3097: }
1.225 raeburn 3098: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3099: push(@rolechanges,$role);
3100: }
1.116 raeburn 3101: }
1.139 albertel 3102: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3103: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3104: # Delete custom role
1.294 bisitz 3105: $r->print(&mt('Deleting custom role [_1] by [_2] in [_3]',
3106: $rolename,$rnam.':'.$rdom,$url).': <b>'.
1.116 raeburn 3107: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3108: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
1.240 raeburn 3109: 0,1,$context).'</b><br />');
1.225 raeburn 3110: if (!grep(/^cr$/,@rolechanges)) {
3111: push(@rolechanges,'cr');
3112: }
1.116 raeburn 3113: }
1.135 raeburn 3114: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3115: my $udom = $env{'form.ccdomain'};
3116: my $uname = $env{'form.ccuname'};
1.116 raeburn 3117: # Re-enable standard role
1.135 raeburn 3118: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3119: my $url = $1;
3120: my $role = $2;
3121: my $logmsg;
3122: my $output;
3123: if ($role eq 'st') {
1.141 albertel 3124: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.129 albertel 3125: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.220 raeburn 3126: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3127: if ($result eq 'refused' && $logmsg) {
3128: $output = $logmsg;
3129: } else {
3130: $output = "Error: $result\n";
3131: }
1.89 raeburn 3132: } else {
3133: $output = &mt('Assigning').' '.$role.' in '.$url.
3134: &mt('starting').' '.localtime($now).
3135: ': <br />'.$logmsg.'<br />'.
3136: &mt('Add to classlist').': <b>ok</b><br />';
3137: }
3138: }
3139: } else {
1.101 albertel 3140: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3141: $env{'form.ccuname'},$url,$role,0,$now,'','',
3142: $context);
1.266 bisitz 3143: $output = &mt('Re-enabling [_1] in [_2]: [_3]',
3144: $role,$url,'<b>'.$result.'</b>').'<br />';
1.27 matthew 3145: }
1.89 raeburn 3146: $r->print($output);
1.225 raeburn 3147: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3148: push(@rolechanges,$role);
3149: }
1.113 raeburn 3150: }
1.116 raeburn 3151: # Re-enable custom role
1.139 albertel 3152: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3153: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3154: my $result = &Apache::lonnet::assigncustomrole(
3155: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3156: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.294 bisitz 3157: $r->print(&mt('Re-enabling custom role [_1] by [_2] in [_3]: [_4]',
3158: $rolename,$rnam.':'.$rdom,$url,'<b>'.$result.'</b>').'<br />');
1.225 raeburn 3159: if (!grep(/^cr$/,@rolechanges)) {
3160: push(@rolechanges,'cr');
3161: }
1.116 raeburn 3162: }
1.135 raeburn 3163: } elsif ($key=~/^form\.act/) {
1.101 albertel 3164: my $udom = $env{'form.ccdomain'};
3165: my $uname = $env{'form.ccuname'};
1.141 albertel 3166: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3167: # Activate a custom role
1.83 albertel 3168: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3169: my $url='/'.$one.'/'.$two;
3170: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3171:
1.101 albertel 3172: my $start = ( $env{'form.start_'.$full} ?
3173: $env{'form.start_'.$full} :
1.88 raeburn 3174: $now );
1.101 albertel 3175: my $end = ( $env{'form.end_'.$full} ?
3176: $env{'form.end_'.$full} :
1.88 raeburn 3177: 0 );
3178:
3179: # split multiple sections
3180: my %sections = ();
1.101 albertel 3181: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3182: if ($num_sections == 0) {
1.240 raeburn 3183: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3184: } else {
1.114 albertel 3185: my %curr_groups =
1.117 raeburn 3186: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 3187: foreach my $sec (sort {$a cmp $b} keys %sections) {
3188: if (($sec eq 'none') || ($sec eq 'all') ||
3189: exists($curr_groups{$sec})) {
3190: $disallowed{$sec} = $url;
3191: next;
3192: }
3193: my $securl = $url.'/'.$sec;
1.240 raeburn 3194: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3195: }
3196: }
1.225 raeburn 3197: if (!grep(/^cr$/,@rolechanges)) {
3198: push(@rolechanges,'cr');
3199: }
1.142 raeburn 3200: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 3201: # Activate roles for sections with 3 id numbers
3202: # set start, end times, and the url for the class
1.83 albertel 3203: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 3204: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
3205: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3206: $now );
1.101 albertel 3207: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
3208: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3209: 0 );
1.83 albertel 3210: my $url='/'.$one.'/'.$two;
1.88 raeburn 3211: my $type = 'three';
3212: # split multiple sections
3213: my %sections = ();
1.101 albertel 3214: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 3215: if ($num_sections == 0) {
1.240 raeburn 3216: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 3217: } else {
1.114 albertel 3218: my %curr_groups =
1.117 raeburn 3219: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 3220: my $emptysec = 0;
3221: foreach my $sec (sort {$a cmp $b} keys %sections) {
3222: $sec =~ s/\W//g;
1.113 raeburn 3223: if ($sec ne '') {
3224: if (($sec eq 'none') || ($sec eq 'all') ||
3225: exists($curr_groups{$sec})) {
3226: $disallowed{$sec} = $url;
3227: next;
3228: }
1.88 raeburn 3229: my $securl = $url.'/'.$sec;
1.240 raeburn 3230: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context));
1.88 raeburn 3231: } else {
3232: $emptysec = 1;
3233: }
3234: }
3235: if ($emptysec) {
1.240 raeburn 3236: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 3237: }
1.225 raeburn 3238: }
3239: if (!grep(/^\Q$three\E$/,@rolechanges)) {
3240: push(@rolechanges,$three);
3241: }
1.135 raeburn 3242: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 3243: # Activate roles for sections with two id numbers
3244: # set start, end times, and the url for the class
1.101 albertel 3245: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
3246: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 3247: $now );
1.101 albertel 3248: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
3249: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 3250: 0 );
1.225 raeburn 3251: my $one = $1;
3252: my $two = $2;
3253: my $url='/'.$one.'/';
1.88 raeburn 3254: # split multiple sections
3255: my %sections = ();
1.225 raeburn 3256: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 3257: if ($num_sections == 0) {
1.240 raeburn 3258: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3259: } else {
3260: my $emptysec = 0;
3261: foreach my $sec (sort {$a cmp $b} keys %sections) {
3262: if ($sec ne '') {
3263: my $securl = $url.'/'.$sec;
1.240 raeburn 3264: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 3265: } else {
3266: $emptysec = 1;
3267: }
3268: }
3269: if ($emptysec) {
1.240 raeburn 3270: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 3271: }
3272: }
1.225 raeburn 3273: if (!grep(/^\Q$two\E$/,@rolechanges)) {
3274: push(@rolechanges,$two);
3275: }
1.64 www 3276: } else {
1.190 raeburn 3277: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 3278: }
1.113 raeburn 3279: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 3280: $r->print('<p class="LC_warning">');
1.113 raeburn 3281: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 3282: $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 3283: } else {
1.274 bisitz 3284: $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 3285: }
1.274 bisitz 3286: $r->print('</p><p>'
3287: .&mt('Please [_1]go back[_2] and choose a different section name.'
3288: ,'<a href="javascript:history.go(-1)'
3289: ,'</a>')
3290: .'</p><br />'
3291: );
1.113 raeburn 3292: }
3293: }
1.101 albertel 3294: } # End of foreach (keys(%env))
1.75 www 3295: # Flush the course logs so reverse user roles immediately updated
3296: &Apache::lonnet::flushcourselogs();
1.225 raeburn 3297: if (@rolechanges == 0) {
1.193 raeburn 3298: $r->print(&mt('No roles to modify'));
3299: }
1.225 raeburn 3300: return @rolechanges;
1.220 raeburn 3301: }
3302:
3303: sub enroll_single_student {
1.295.2.18 raeburn 3304: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype) = @_;
3305: $r->print('<h3>');
3306: if ($crstype eq 'Community') {
3307: $r->print(&mt('Enrolling Member'));
3308: } else {
3309: $r->print(&mt('Enrolling Student'));
3310: }
3311: $r->print('</h3>');
1.220 raeburn 3312:
3313: # Remove non alphanumeric values from section
3314: $env{'form.sections'}=~s/\W//g;
3315:
3316: # Clean out any old student roles the user has in this class.
3317: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
3318: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
3319: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
3320: my $enroll_result =
3321: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
3322: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
3323: $env{'form.cmiddlename'},$env{'form.clastname'},
3324: $env{'form.generation'},$env{'form.sections'},$enddate,
1.239 raeburn 3325: $startdate,'manual',undef,$env{'request.course.id'},'',$context);
1.220 raeburn 3326: if ($enroll_result =~ /^ok/) {
3327: $r->print(&mt('<b>[_1]</b> enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'}));
3328: if ($env{'form.sections'} ne '') {
3329: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
3330: }
3331: my ($showstart,$showend);
3332: if ($startdate <= $now) {
3333: $showstart = &mt('Access starts immediately');
3334: } else {
3335: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
3336: }
3337: if ($enddate == 0) {
3338: $showend = &mt('ends: no ending date');
3339: } else {
3340: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
3341: }
3342: $r->print('.<br />'.$showstart.'; '.$showend);
3343: if ($startdate <= $now && !$newuser) {
1.295.2.18 raeburn 3344: $r->print('<p> ');
3345: if ($crstype eq 'Community') {
3346: $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.'));
3347: } else {
3348: $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.'));
3349: }
3350: $r->print('</p>');
1.220 raeburn 3351: }
3352: } else {
3353: $r->print(&mt('unable to enroll').": ".$enroll_result);
3354: }
3355: return;
1.188 raeburn 3356: }
3357:
1.204 raeburn 3358: sub get_defaultquota_text {
3359: my ($settingstatus) = @_;
3360: my $defquotatext;
3361: if ($settingstatus eq '') {
3362: $defquotatext = &mt('(default)');
3363: } else {
3364: my ($usertypes,$order) =
3365: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
3366: if ($usertypes->{$settingstatus} eq '') {
3367: $defquotatext = &mt('(default)');
3368: } else {
3369: $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
3370: }
3371: }
3372: return $defquotatext;
3373: }
3374:
1.188 raeburn 3375: sub update_result_form {
3376: my ($uhome) = @_;
3377: my $outcome =
3378: '<form name="userupdate" method="post" />'."\n";
1.160 raeburn 3379: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 3380: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3381: }
1.207 raeburn 3382: if ($env{'form.origname'} ne '') {
3383: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
3384: }
1.160 raeburn 3385: foreach my $item ('sortby','seluname','seludom') {
3386: if (exists($env{'form.'.$item})) {
1.188 raeburn 3387: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 3388: }
3389: }
1.188 raeburn 3390: if ($uhome eq 'no_host') {
3391: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
3392: }
3393: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
3394: '<input type ="hidden" name="currstate" value="" />'."\n".
1.220 raeburn 3395: '<input type ="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 3396: '</form>';
3397: return $outcome;
1.4 www 3398: }
3399:
1.149 raeburn 3400: sub quota_admin {
3401: my ($setquota,$changeHash) = @_;
3402: my $quotachanged;
3403: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
3404: # Current user has quota modification privileges
1.267 raeburn 3405: if (ref($changeHash) eq 'HASH') {
3406: $quotachanged = 1;
3407: $changeHash->{'portfolioquota'} = $setquota;
3408: }
1.149 raeburn 3409: }
3410: return $quotachanged;
3411: }
3412:
1.267 raeburn 3413: sub tool_admin {
1.275 raeburn 3414: my ($tool,$settool,$changeHash,$context) = @_;
3415: my $canchange = 0;
1.279 raeburn 3416: if ($context eq 'requestcourses') {
1.275 raeburn 3417: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
3418: $canchange = 1;
3419: }
1.295.2.3 raeburn 3420: } elsif ($context eq 'reqcrsotherdom') {
3421: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
3422: $canchange = 1;
3423: }
1.275 raeburn 3424: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
3425: # Current user has quota modification privileges
3426: $canchange = 1;
3427: }
1.267 raeburn 3428: my $toolchanged;
1.275 raeburn 3429: if ($canchange) {
1.267 raeburn 3430: if (ref($changeHash) eq 'HASH') {
3431: $toolchanged = 1;
1.275 raeburn 3432: $changeHash->{$context.'.'.$tool} = $settool;
1.267 raeburn 3433: }
3434: }
3435: return $toolchanged;
3436: }
3437:
1.88 raeburn 3438: sub build_roles {
1.89 raeburn 3439: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 3440: my $num_sections = 0;
3441: if ($sectionstr=~ /,/) {
3442: my @secnums = split/,/,$sectionstr;
1.89 raeburn 3443: if ($role eq 'st') {
3444: $secnums[0] =~ s/\W//g;
3445: $$sections{$secnums[0]} = 1;
3446: $num_sections = 1;
3447: } else {
3448: foreach my $sec (@secnums) {
3449: $sec =~ ~s/\W//g;
1.150 banghart 3450: if (!($sec eq "")) {
1.89 raeburn 3451: if (exists($$sections{$sec})) {
3452: $$sections{$sec} ++;
3453: } else {
3454: $$sections{$sec} = 1;
3455: $num_sections ++;
3456: }
1.88 raeburn 3457: }
3458: }
3459: }
3460: } else {
3461: $sectionstr=~s/\W//g;
3462: unless ($sectionstr eq '') {
3463: $$sections{$sectionstr} = 1;
3464: $num_sections ++;
3465: }
3466: }
1.129 albertel 3467:
1.88 raeburn 3468: return $num_sections;
3469: }
3470:
1.58 www 3471: # ========================================================== Custom Role Editor
3472:
3473: sub custom_role_editor {
1.160 raeburn 3474: my ($r) = @_;
1.101 albertel 3475: my $rolename=$env{'form.rolename'};
1.58 www 3476:
1.59 www 3477: if ($rolename eq 'make new role') {
1.101 albertel 3478: $rolename=$env{'form.newrolename'};
1.59 www 3479: }
3480:
1.63 www 3481: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 3482:
1.190 raeburn 3483: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.58 www 3484: &print_username_entry_form($r);
3485: return;
3486: }
1.153 banghart 3487: # ------------------------------------------------------- What can be assigned?
3488: my %full=();
3489: my %courselevel=();
3490: my %courselevelcurrent=();
1.61 www 3491: my $syspriv='';
3492: my $dompriv='';
3493: my $coursepriv='';
1.153 banghart 3494: my $body_top;
1.150 banghart 3495: my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
1.59 www 3496: my ($rdummy,$roledef)=
3497: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 3498: # ------------------------------------------------------- Does this role exist?
1.153 banghart 3499: $body_top .= '<h2>';
1.59 www 3500: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 3501: $body_top .= &mt('Existing Role').' "';
1.61 www 3502: # ------------------------------------------------- Get current role privileges
3503: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 3504: } else {
1.153 banghart 3505: $body_top .= &mt('New Role').' "';
1.59 www 3506: $roledef='';
3507: }
1.153 banghart 3508: $body_top .= $rolename.'"</h2>';
1.135 raeburn 3509: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
3510: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3511: if (!$restrict) { $restrict='F'; }
1.60 www 3512: $courselevel{$priv}=$restrict;
1.61 www 3513: if ($coursepriv=~/\:$priv/) {
3514: $courselevelcurrent{$priv}=1;
3515: }
1.60 www 3516: $full{$priv}=1;
3517: }
3518: my %domainlevel=();
1.61 www 3519: my %domainlevelcurrent=();
1.135 raeburn 3520: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
3521: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3522: if (!$restrict) { $restrict='F'; }
1.60 www 3523: $domainlevel{$priv}=$restrict;
1.61 www 3524: if ($dompriv=~/\:$priv/) {
3525: $domainlevelcurrent{$priv}=1;
3526: }
1.60 www 3527: $full{$priv}=1;
3528: }
1.61 www 3529: my %systemlevel=();
3530: my %systemlevelcurrent=();
1.135 raeburn 3531: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
3532: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3533: if (!$restrict) { $restrict='F'; }
1.61 www 3534: $systemlevel{$priv}=$restrict;
3535: if ($syspriv=~/\:$priv/) {
3536: $systemlevelcurrent{$priv}=1;
3537: }
3538: $full{$priv}=1;
3539: }
1.160 raeburn 3540: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 3541: my $button_code = "\n";
1.153 banghart 3542: my $head_script = "\n";
1.295.2.4 raeburn 3543: $head_script .= '<script type="text/javascript">'."\n".
3544: '// <![CDATA['."\n";
1.295.2.18 raeburn 3545: my $crstype;
3546: if ($env{'request.course.id'}) {
3547: $crstype = &Apache::loncommon::course_type();
3548: }
3549: my @template_roles = ("in","ta","ep","st");
3550: if ($crstype eq 'Community') {
3551: unshift(@template_roles,'co');
3552: } else {
3553: unshift(@template_roles,'cc');
3554: }
1.154 banghart 3555: foreach my $role (@template_roles) {
3556: $head_script .= &make_script_template($role);
1.295.2.18 raeburn 3557: $button_code .= &make_button_code($role,$crstype).' ';
1.154 banghart 3558: }
1.295.2.4 raeburn 3559: $head_script .= "\n".$jsback."\n".
3560: '// ]]>'."\n".
3561: '</script>'."\n";
1.153 banghart 3562: $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
1.160 raeburn 3563: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 3564: ({href=>"javascript:backPage(document.form1,'pickrole','')",
3565: text=>"Pick custom role",
1.160 raeburn 3566: faq=>282,bug=>'Instructor Interface',},
3567: {href=>"javascript:backPage(document.form1,'','')",
3568: text=>"Edit custom role",
3569: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 3570: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
3571: 'Course_Editing_Custom_Roles'));
1.160 raeburn 3572:
1.153 banghart 3573: $r->print($body_top);
1.73 sakharuk 3574: my %lt=&Apache::lonlocal::texthash(
3575: 'prv' => "Privilege",
1.131 raeburn 3576: 'crl' => "Course Level",
1.73 sakharuk 3577: 'dml' => "Domain Level",
1.150 banghart 3578: 'ssl' => "System Level");
1.264 bisitz 3579:
3580: $r->print('<div>'
3581: .'<form action=""><fieldset>'
3582: .'<legend>'.&mt('Select a Template').'</legend>'
3583: .$button_code
3584: .'</fieldset></form>'
3585: .'</div>'
3586: );
3587:
1.61 www 3588: $r->print(<<ENDCCF);
1.160 raeburn 3589: <form name="form1" method="post">
1.61 www 3590: <input type="hidden" name="phase" value="set_custom_roles" />
3591: <input type="hidden" name="rolename" value="$rolename" />
3592: ENDCCF
1.135 raeburn 3593: $r->print(&Apache::loncommon::start_data_table().
3594: &Apache::loncommon::start_data_table_header_row().
3595: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
3596: '</th><th>'.$lt{'ssl'}.'</th>'.
3597: &Apache::loncommon::end_data_table_header_row());
1.119 raeburn 3598: foreach my $priv (sort keys %full) {
1.295.2.18 raeburn 3599: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
1.135 raeburn 3600: $r->print(&Apache::loncommon::start_data_table_row().
3601: '<td>'.$privtext.'</td><td>'.
1.288 bisitz 3602: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c"'.
3603: ($courselevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.61 www 3604: '</td><td>'.
1.288 bisitz 3605: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.
3606: ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.61 www 3607: '</td><td>'.
1.288 bisitz 3608: ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
3609: ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':' ').
1.135 raeburn 3610: '</td>'.
3611: &Apache::loncommon::end_data_table_row());
1.60 www 3612: }
1.135 raeburn 3613: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 3614: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 3615: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 3616: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 3617: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.282 schafran 3618: '<input type="submit" value="'.&mt('Save').'" /></form>'.
1.110 albertel 3619: &Apache::loncommon::end_page());
1.61 www 3620: }
1.153 banghart 3621: # --------------------------------------------------------
3622: sub make_script_template {
3623: my ($role) = @_;
3624: my %full_c=();
3625: my %full_d=();
3626: my %full_s=();
3627: my $return_script;
3628: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
3629: my ($priv,$restrict)=split(/\&/,$item);
3630: $full_c{$priv}=1;
3631: }
3632: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
3633: my ($priv,$restrict)=split(/\&/,$item);
3634: $full_d{$priv}=1;
3635: }
1.154 banghart 3636: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.153 banghart 3637: my ($priv,$restrict)=split(/\&/,$item);
3638: $full_s{$priv}=1;
3639: }
3640: $return_script .= 'function set_'.$role.'() {'."\n";
3641: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
3642: my %role_c;
1.155 banghart 3643: foreach my $priv (@temp) {
1.153 banghart 3644: my ($priv_item, $dummy) = split(/\&/,$priv);
3645: $role_c{$priv_item} = 1;
3646: }
1.269 raeburn 3647: my %role_d;
3648: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
3649: foreach my $priv(@temp) {
3650: my ($priv_item, $dummy) = split(/\&/,$priv);
3651: $role_d{$priv_item} = 1;
3652: }
3653: my %role_s;
3654: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
3655: foreach my $priv(@temp) {
3656: my ($priv_item, $dummy) = split(/\&/,$priv);
3657: $role_s{$priv_item} = 1;
3658: }
1.153 banghart 3659: foreach my $priv_item (keys(%full_c)) {
3660: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 3661: if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
3662: (exists($role_s{$priv}))) {
1.153 banghart 3663: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
3664: } else {
3665: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
3666: }
3667: }
1.154 banghart 3668: foreach my $priv_item (keys(%full_d)) {
3669: my ($priv, $dummy) = split(/\&/,$priv_item);
1.269 raeburn 3670: if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
1.154 banghart 3671: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
3672: } else {
3673: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
3674: }
3675: }
3676: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 3677: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 3678: if (exists($role_s{$priv})) {
3679: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
3680: } else {
3681: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
3682: }
1.153 banghart 3683: }
3684: $return_script .= '}'."\n";
1.154 banghart 3685: return ($return_script);
3686: }
3687: # ----------------------------------------------------------
3688: sub make_button_code {
1.295.2.18 raeburn 3689: my ($role,$crstype) = @_;
3690: my $label = &Apache::lonnet::plaintext($role,$crstype);
1.295.2.4 raeburn 3691: my $button_code = '<input type="button" onclick="set_'.$role.'()" value="'.$label.'" />';
1.154 banghart 3692: return ($button_code);
1.153 banghart 3693: }
1.61 www 3694: # ---------------------------------------------------------- Call to definerole
3695: sub set_custom_role {
1.240 raeburn 3696: my ($r,$context) = @_;
1.101 albertel 3697: my $rolename=$env{'form.rolename'};
1.63 www 3698: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 3699: if (!$rolename) {
1.190 raeburn 3700: &custom_role_editor($r);
1.61 www 3701: return;
3702: }
1.160 raeburn 3703: my ($jsback,$elements) = &crumb_utilities();
1.295.2.4 raeburn 3704: my $jscript = '<script type="text/javascript">'.
3705: '// <![CDATA['."\n".
3706: $jsback."\n".
3707: '// ]]>'."\n".
3708: '</script>';
1.160 raeburn 3709:
3710: $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
3711: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 3712: ({href=>"javascript:backPage(document.customresult,'pickrole','')",
3713: text=>"Pick custom role",
1.160 raeburn 3714: faq=>282,bug=>'Instructor Interface',},
3715: {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
3716: text=>"Edit custom role",
3717: faq=>282,bug=>'Instructor Interface',},
3718: {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
3719: text=>"Result",
3720: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 3721: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
3722: 'Course_Editing_Custom_Roles'));
1.160 raeburn 3723:
1.61 www 3724: my ($rdummy,$roledef)=
1.110 albertel 3725: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
3726:
1.61 www 3727: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 3728: $r->print('<h3>');
1.61 www 3729: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 3730: $r->print(&mt('Existing Role').' "');
1.61 www 3731: } else {
1.73 sakharuk 3732: $r->print(&mt('New Role').' "');
1.61 www 3733: $roledef='';
3734: }
1.188 raeburn 3735: $r->print($rolename.'"</h3>');
1.61 www 3736: # ------------------------------------------------------- What can be assigned?
3737: my $sysrole='';
3738: my $domrole='';
3739: my $courole='';
3740:
1.135 raeburn 3741: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
3742: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3743: if (!$restrict) { $restrict=''; }
3744: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 3745: $courole.=':'.$item;
1.61 www 3746: }
3747: }
3748:
1.135 raeburn 3749: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
3750: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3751: if (!$restrict) { $restrict=''; }
3752: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 3753: $domrole.=':'.$item;
1.61 www 3754: }
3755: }
3756:
1.135 raeburn 3757: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
3758: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3759: if (!$restrict) { $restrict=''; }
3760: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 3761: $sysrole.=':'.$item;
1.61 www 3762: }
3763: }
1.63 www 3764: $r->print('<br />Defining Role: '.
1.61 www 3765: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 3766: if ($env{'request.course.id'}) {
3767: my $url='/'.$env{'request.course.id'};
1.63 www 3768: $url=~s/\_/\//g;
1.73 sakharuk 3769: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 3770: &Apache::lonnet::assigncustomrole($env{'user.domain'},
3771: $env{'user.name'},
1.63 www 3772: $url,
1.101 albertel 3773: $env{'user.domain'},
3774: $env{'user.name'},
1.240 raeburn 3775: $rolename,undef,undef,undef,$context));
1.63 www 3776: }
1.190 raeburn 3777: $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 3778: $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
1.110 albertel 3779: $r->print(&Apache::loncommon::end_page());
1.58 www 3780: }
3781:
1.2 www 3782: # ================================================================ Main Handler
3783: sub handler {
3784: my $r = shift;
3785: if ($r->header_only) {
1.68 www 3786: &Apache::loncommon::content_type($r,'text/html');
1.2 www 3787: $r->send_http_header;
3788: return OK;
3789: }
1.295.2.18 raeburn 3790: my ($context,$crstype);
1.190 raeburn 3791: if ($env{'request.course.id'}) {
3792: $context = 'course';
1.295.2.18 raeburn 3793: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 3794: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 3795: $context = 'author';
1.190 raeburn 3796: } else {
3797: $context = 'domain';
3798: }
3799: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 3800: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
3801: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
1.190 raeburn 3802: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.202 raeburn 3803: if ($env{'form.action'} ne 'dateselect') {
3804: &Apache::lonhtmlcommon::add_breadcrumb
3805: ({href=>"/adm/createuser",
1.289 droeschl 3806: text=>"User Management",
3807: 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'});
1.202 raeburn 3808: }
1.289 droeschl 3809: #SD Following files not added to help, because the corresponding .tex-files seem to
3810: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 3811: my ($permission,$allowed) =
1.295.2.18 raeburn 3812: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 3813: if (!$allowed) {
3814: $env{'user.error.msg'}=
3815: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
3816: "or view user status.";
3817: return HTTP_NOT_ACCEPTABLE;
3818: }
3819:
3820: &Apache::loncommon::content_type($r,'text/html');
3821: $r->send_http_header;
3822:
3823: # Main switch on form.action and form.state, as appropriate
3824: if (! exists($env{'form.action'})) {
3825: $r->print(&header());
3826: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.295.2.18 raeburn 3827: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 3828: $r->print(&Apache::loncommon::end_page());
3829: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
3830: $r->print(&header());
3831: &Apache::lonhtmlcommon::add_breadcrumb
3832: ({href=>'/adm/createuser?action=upload&state=',
3833: text=>"Upload Users List"});
3834: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Upload Users List',
1.224 raeburn 3835: 'Course_Create_Class_List'));
1.190 raeburn 3836: $r->print('<form name="studentform" method="post" '.
3837: 'enctype="multipart/form-data" '.
3838: ' action="/adm/createuser">'."\n");
3839: if (! exists($env{'form.state'})) {
3840: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
3841: } elsif ($env{'form.state'} eq 'got_file') {
1.221 raeburn 3842: &Apache::lonuserutils::print_upload_manager_form($r,$context,
1.295.2.18 raeburn 3843: $permission,$crstype);
1.190 raeburn 3844: } elsif ($env{'form.state'} eq 'enrolling') {
3845: if ($env{'form.datatoken'}) {
1.221 raeburn 3846: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission);
1.190 raeburn 3847: }
3848: } else {
3849: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
3850: }
3851: $r->print('</form>'.&Apache::loncommon::end_page());
1.213 raeburn 3852: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
3853: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 3854: my $phase = $env{'form.phase'};
3855: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 3856: &Apache::loncreateuser::restore_prev_selections();
3857: my $srch;
3858: foreach my $item (@search) {
3859: $srch->{$item} = $env{'form.'.$item};
3860: }
1.207 raeburn 3861: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
3862: ($phase eq 'createnewuser')) {
3863: if ($env{'form.phase'} eq 'createnewuser') {
3864: my $response;
3865: if ($env{'form.srchterm'} !~ /^$match_username$/) {
3866: my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
1.221 raeburn 3867: $env{'form.phase'} = '';
1.295.2.18 raeburn 3868: &print_username_entry_form($r,$context,$response,$srch,undef,$crstype);
1.207 raeburn 3869: } else {
3870: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
3871: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
3872: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 3873: $srch,$response,$context,
1.295.2.18 raeburn 3874: $permission,$crstype);
1.207 raeburn 3875: }
3876: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 3877: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 3878: &user_search_result($context,$srch);
1.190 raeburn 3879: if ($env{'form.currstate'} eq 'modify') {
3880: $currstate = $env{'form.currstate'};
3881: }
3882: if ($currstate eq 'select') {
3883: &print_user_selection_page($r,$response,$srch,$results,
1.295.2.18 raeburn 3884: \@search,$context,undef,$crstype);
1.190 raeburn 3885: } elsif ($currstate eq 'modify') {
3886: my ($ccuname,$ccdomain);
3887: if (($srch->{'srchby'} eq 'uname') &&
3888: ($srch->{'srchtype'} eq 'exact')) {
3889: $ccuname = $srch->{'srchterm'};
3890: $ccdomain= $srch->{'srchdomain'};
3891: } else {
3892: my @matchedunames = keys(%{$results});
3893: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
3894: }
3895: $ccuname =&LONCAPA::clean_username($ccuname);
3896: $ccdomain=&LONCAPA::clean_domain($ccdomain);
3897: if ($env{'form.forcenewuser'}) {
3898: $response = '';
3899: }
3900: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 3901: $srch,$response,$context,
1.295.2.18 raeburn 3902: $permission,$crstype);
1.190 raeburn 3903: } elsif ($currstate eq 'query') {
3904: &print_user_query_page($r,'createuser');
3905: } else {
1.229 raeburn 3906: $env{'form.phase'} = '';
1.207 raeburn 3907: &print_username_entry_form($r,$context,$response,$srch,
1.295.2.18 raeburn 3908: $forcenewuser,$crstype);
1.190 raeburn 3909: }
3910: } elsif ($env{'form.phase'} eq 'userpicked') {
3911: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
3912: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 3913: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.295.2.18 raeburn 3914: $context,$permission,$crstype);
1.190 raeburn 3915: }
3916: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.295.2.18 raeburn 3917: &update_user_data($r,$context,$crstype);
1.190 raeburn 3918: } else {
1.295.2.18 raeburn 3919: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype);
1.190 raeburn 3920: }
3921: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
3922: if ($env{'form.phase'} eq 'set_custom_roles') {
1.240 raeburn 3923: &set_custom_role($r,$context);
1.190 raeburn 3924: } else {
3925: &custom_role_editor($r);
3926: }
1.207 raeburn 3927: } elsif (($env{'form.action'} eq 'listusers') &&
3928: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 3929: if ($env{'form.phase'} eq 'bulkchange') {
3930: &Apache::lonhtmlcommon::add_breadcrumb
1.221 raeburn 3931: ({href=>'/adm/createuser?action=listusers',
3932: text=>"List Users"},
3933: {href=>"/adm/createuser",
3934: text=>"Result"});
1.202 raeburn 3935: my $setting = $env{'form.roletype'};
3936: my $choice = $env{'form.bulkaction'};
3937: $r->print(&header());
1.221 raeburn 3938: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Update Users",
1.224 raeburn 3939: 'Course_View_Class_List'));
1.202 raeburn 3940: if ($permission->{'cusr'}) {
3941: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
1.221 raeburn 3942: $r->print(&Apache::loncommon::end_page());
3943: } else {
3944: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 3945: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.221 raeburn 3946: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 3947: }
3948: } else {
3949: &Apache::lonhtmlcommon::add_breadcrumb
3950: ({href=>'/adm/createuser?action=listusers',
3951: text=>"List Users"});
3952: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
3953: my $formname = 'studentform';
1.295.2.21 raeburn 3954: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
3955: ($env{'form.roletype'} eq 'community'))) {
3956: if ($env{'form.roletype'} eq 'course') {
3957: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
3958: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
3959: $formname);
3960: } elsif ($env{'form.roletype'} eq 'community') {
3961: $cb_jscript =
3962: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
3963: my %elements = (
3964: coursepick => 'radio',
3965: coursetotal => 'text',
3966: courselist => 'text',
3967: );
3968: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
3969: }
1.202 raeburn 3970: $jscript .= &verify_user_display();
3971: my $js = &add_script($jscript).$cb_jscript;
3972: my $loadcode =
3973: &Apache::lonuserutils::course_selector_loadcode($formname);
3974: if ($loadcode ne '') {
3975: $r->print(&header($js,{'onload' => $loadcode,}));
3976: } else {
3977: $r->print(&header($js));
3978: }
1.191 raeburn 3979: } else {
1.202 raeburn 3980: $r->print(&header(&add_script(&verify_user_display())));
1.191 raeburn 3981: }
1.202 raeburn 3982: $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
1.224 raeburn 3983: 'Course_View_Class_List'));
1.202 raeburn 3984: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
3985: $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
3986: $r->print(&Apache::loncommon::end_page());
1.191 raeburn 3987: }
1.213 raeburn 3988: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
3989: $r->print(&header());
1.295.2.18 raeburn 3990: my $brtext;
3991: if ($crstype eq 'Community') {
3992: $brtext = 'Drop Members';
3993: } else {
3994: $brtext = 'Drop Students';
3995: }
1.213 raeburn 3996: &Apache::lonhtmlcommon::add_breadcrumb
3997: ({href=>'/adm/createuser?action=drop',
1.295.2.19 raeburn 3998: text=>$brtext});
1.213 raeburn 3999: if (!exists($env{'form.state'})) {
4000: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
4001: 'Course_Drop_Student'));
4002:
1.295.2.18 raeburn 4003: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 4004: } elsif ($env{'form.state'} eq 'done') {
4005: &Apache::lonhtmlcommon::add_breadcrumb
4006: ({href=>'/adm/createuser?action=drop',
4007: text=>"Result"});
1.295.2.18 raeburn 4008: $r->print(&Apache::lonhtmlcommon::breadcrumbs($brtext,
1.213 raeburn 4009: 'Course_Drop_Student'));
4010: &Apache::lonuserutils::update_user_list($r,$context,undef,
4011: $env{'form.action'});
4012: }
4013: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 4014: } elsif ($env{'form.action'} eq 'dateselect') {
4015: if ($permission->{'cusr'}) {
4016: $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
1.221 raeburn 4017: &Apache::lonuserutils::date_section_selector($context,
1.295.2.18 raeburn 4018: $permission,$crstype).
1.202 raeburn 4019: &Apache::loncommon::end_page());
4020: } else {
4021: $r->print(&header().
4022: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'.
4023: &Apache::loncommon::end_page());
4024: }
1.237 raeburn 4025: } elsif ($env{'form.action'} eq 'selfenroll') {
4026: $r->print(&header());
4027: &Apache::lonhtmlcommon::add_breadcrumb
4028: ({href=>'/adm/createuser?action=selfenroll',
4029: text=>"Configure Self-enrollment"});
4030: if (!exists($env{'form.state'})) {
4031: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Configure Self-enrollment',
4032: 'Course_Self_Enrollment'));
1.241 raeburn 4033: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.237 raeburn 4034: &print_selfenroll_menu($r,$context,$permission);
4035: } elsif ($env{'form.state'} eq 'done') {
4036: &Apache::lonhtmlcommon::add_breadcrumb
4037: ({href=>'/adm/createuser?action=selfenroll',
4038: text=>"Result"});
4039: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enrollment result',
4040: 'Course_Self_Enrollment'));
1.241 raeburn 4041: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
4042: &update_selfenroll_config($r,$context,$permission);
1.237 raeburn 4043: }
4044: $r->print(&Apache::loncommon::end_page());
1.277 raeburn 4045: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
4046: $r->print(&header());
4047: &Apache::lonhtmlcommon::add_breadcrumb
4048: ({href=>'/adm/createuser?action=selfenrollqueue',
4049: text=>"Enrollment requests"});
4050: my $cid = $env{'request.course.id'};
4051: my $cdom = $env{'course.'.$cid.'.domain'};
4052: my $cnum = $env{'course.'.$cid.'.num'};
1.295.2.7 raeburn 4053: my $coursedesc = $env{'course.'.$cid.'.description'};
1.277 raeburn 4054: if (!exists($env{'form.state'})) {
4055: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment requests',
4056: 'Course_SelfEnrollment_Approval'));
4057: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
1.295.2.7 raeburn 4058: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
4059: $cdom,$cnum));
4060:
1.277 raeburn 4061: } elsif ($env{'form.state'} eq 'done') {
4062: &Apache::lonhtmlcommon::add_breadcrumb
4063: ({href=>'/adm/createuser?action=selfenrollqueue',
4064: text=>"Result"});
4065: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment result',
4066: 'Course_Self_Enrollment'));
4067: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
1.295.2.7 raeburn 4068: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
4069: $cdom,$cnum,$coursedesc));
1.277 raeburn 4070: }
4071: $r->print(&Apache::loncommon::end_page());
1.239 raeburn 4072: } elsif ($env{'form.action'} eq 'changelogs') {
4073: $r->print(&header());
4074: &Apache::lonhtmlcommon::add_breadcrumb
4075: ({href=>'/adm/createuser?action=changelogs',
4076: text=>"User Management Logs"});
4077: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Changes',
4078: 'Course_User_Logs'));
4079: &print_userchangelogs_display($r,$context,$permission);
4080: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 4081: } else {
4082: $r->print(&header());
1.202 raeburn 4083: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.295.2.18 raeburn 4084: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4085: $r->print(&Apache::loncommon::end_page());
4086: }
4087: return OK;
4088: }
4089:
4090: sub header {
1.202 raeburn 4091: my ($jscript,$loaditems,$args) = @_;
1.190 raeburn 4092: my $start_page;
4093: if (ref($loaditems) eq 'HASH') {
1.202 raeburn 4094: $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
1.190 raeburn 4095: } else {
1.202 raeburn 4096: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 4097: }
4098: return $start_page;
4099: }
1.2 www 4100:
1.191 raeburn 4101: sub add_script {
4102: my ($js) = @_;
1.295.2.4 raeburn 4103: return '<script type="text/javascript">'."\n".
4104: '// <![CDATA['."\n".
4105: "\n".$js."\n".
1.295.2.8 raeburn 4106: '// ]]>'."\n".
1.295.2.4 raeburn 4107: '</script>'."\n";
1.191 raeburn 4108: }
4109:
1.202 raeburn 4110: sub verify_user_display {
4111: my $output = <<"END";
4112:
4113: function display_update() {
4114: document.studentform.action.value = 'listusers';
4115: document.studentform.phase.value = 'display';
4116: document.studentform.submit();
4117: }
4118:
4119: END
4120: return $output;
4121:
4122: }
4123:
1.190 raeburn 4124: ###############################################################
4125: ###############################################################
4126: # Menu Phase One
4127: sub print_main_menu {
1.295.2.18 raeburn 4128: my ($permission,$context,$crstype) = @_;
4129: my $linkcontext = $context;
4130: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
4131: if (($context eq 'course') && ($crstype eq 'Community')) {
4132: $linkcontext = lc($crstype);
4133: $stuterm = 'Members';
4134: }
4135:
1.208 raeburn 4136: my %links = (
4137: domain => {
4138: upload => 'Upload a File of Users',
1.221 raeburn 4139: singleuser => 'Add/Modify a Single User',
1.208 raeburn 4140: listusers => 'Manage Multiple Users',
4141: },
4142: author => {
4143: upload => 'Upload a File of Co-authors',
1.221 raeburn 4144: singleuser => 'Add/Modify a Single Co-author',
1.208 raeburn 4145: listusers => 'Display Co-authors and Manage Multiple Users',
4146: },
4147: course => {
1.295.2.1 raeburn 4148: upload => 'Upload a File of Course Users',
4149: singleuser => 'Add/Modify a Single Course User',
4150: listusers => 'Display Class Lists and Manage Multiple Users',
1.208 raeburn 4151: },
1.295.2.18 raeburn 4152: community => {
4153: upload => 'Upload a File of Community Users',
4154: singleuser => 'Add/Modify a Community User',
4155: listusers => 'Manage Community Users',
4156: },
1.295.2.1 raeburn 4157: );
4158: my @menu =
4159: (
4160: { text => $links{$context}{'upload'},
4161: help => 'Course_Create_Class_List',
4162: action => 'upload',
4163: permission => $permission->{'cusr'},
4164: },
4165: { text => $links{$context}{'singleuser'},
4166: help => 'Course_Change_Privileges',
4167: action => 'singleuser',
4168: permission => $permission->{'cusr'},
4169: },
4170: { text => $links{$context}{'listusers'},
4171: help => 'Course_View_Class_List',
4172: action => 'listusers',
4173: permission => ($permission->{'view'} || $permission->{'cusr'}),
4174: },
4175: );
4176: if ($context eq 'domain' || $context eq 'course') {
4177: my $customlink = { text => 'Edit Custom Roles',
4178: help => 'Course_Editing_Custom_Roles',
4179: action => 'custom',
4180: permission => $permission->{'custom'},
4181: };
4182: push(@menu,$customlink);
4183: }
4184: if ($context eq 'course') {
4185: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
4186: my @courselinks =
4187: (
4188: { text => 'Enroll a Single Student',
4189: help => 'Course_Add_Student',
4190: action => 'singlestudent',
4191: permission => $permission->{'cusr'},
4192: },
4193: { text => 'Drop Students',
4194: help => 'Course_Drop_Student',
4195: action => 'drop',
4196: permission => $permission->{'cusr'},
4197: });
4198: if (!exists($permission->{'cusr_section'})) {
1.295.2.20 raeburn 4199: if ($crstype ne 'Community') {
4200: push(@courselinks,
4201: { text => 'Automated Enrollment Manager',
4202: help => 'Course_Automated_Enrollment',
4203: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
4204: && $permission->{'cusr'}),
4205: url => '/adm/populate',
4206: });
4207: }
4208: push(@courselinks,
4209: { text => 'Configure User Self-enrollment',
4210: help => 'Course_Self_Enrollment',
4211: action => 'selfenroll',
4212: permission => $permission->{'cusr'},
4213: });
1.295.2.1 raeburn 4214: }
1.295.2.2 raeburn 4215: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
4216: push(@courselinks,
4217: { text => 'Enrollment Requests',
4218: help => 'Course_Approve_Selfenroll',
4219: action => 'selfenrollqueue',
4220: permission => $permission->{'cusr'},
4221: });
4222: }
1.295.2.1 raeburn 4223: push(@courselinks,
4224: { text => 'Manage Course Groups',
4225: help => 'Course_Manage_Group',
4226: permission => $permission->{'grp_manage'},
4227: url => '/adm/coursegroups?refpage=cusr',
4228: },
4229: { text => 'View Change Logs',
4230: help => 'Course_User_Logs',
4231: action => 'changelogs',
4232: permission => $permission->{'cusr'},
4233: },);
1.250 raeburn 4234: # { text => 'View Log-in History',
4235: # help => 'Course_User_Logins',
4236: # action => 'logins',
4237: # permission => $permission->{'cusr'},
4238: # });
1.295.2.1 raeburn 4239: push(@menu,@courselinks);
4240: }
4241: my $menu_html = '';
4242: foreach my $menu_item (@menu) {
4243: next if (! $menu_item->{'permission'});
4244: $menu_html.='<p>';
4245: if (exists($menu_item->{'help'})) {
4246: $menu_html.=
4247: &Apache::loncommon::help_open_topic($menu_item->{'help'});
4248: }
4249: $menu_html.='<font size="+1">';
4250: if (exists($menu_item->{'url'})) {
4251: $menu_html.=qq{<a href="$menu_item->{'url'}">};
4252: } else {
4253: $menu_html.=
4254: qq{<a href="/adm/createuser?action=$menu_item->{'action'}">}; }
4255: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
4256: $menu_html.='</p>';
4257: }
4258: return $menu_html;
1.190 raeburn 4259: }
4260:
1.189 albertel 4261: sub restore_prev_selections {
4262: my %saveable_parameters = ('srchby' => 'scalar',
4263: 'srchin' => 'scalar',
4264: 'srchtype' => 'scalar',
4265: );
4266: &Apache::loncommon::store_settings('user','user_picker',
4267: \%saveable_parameters);
4268: &Apache::loncommon::restore_settings('user','user_picker',
4269: \%saveable_parameters);
4270: }
4271:
1.237 raeburn 4272: sub print_selfenroll_menu {
4273: my ($r,$context,$permission) = @_;
1.295.2.22! raeburn 4274: my $crstype = &Apache::loncommon::course_type();
1.237 raeburn 4275: my $formname = 'enrollstudent';
4276: my $nolink = 1;
4277: my ($row,$lt) = &get_selfenroll_titles();
4278: my $groupslist = &Apache::lonuserutils::get_groupslist();
4279: my $setsec_js =
4280: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 4281: my %alerts = &Apache::lonlocal::texthash(
4282: acto => 'Activation of self-enrollment was selected for the following domain(s)',
4283: butn => 'but no user types have been checked.',
4284: wilf => "Please uncheck 'activate' or check at least one type.",
4285: );
4286: my $selfenroll_js = <<"ENDSCRIPT";
4287: function update_types(caller,num) {
4288: var delidx = getIndexByName('selfenroll_delete');
4289: var actidx = getIndexByName('selfenroll_activate');
4290: if (caller == 'selfenroll_all') {
4291: var selall;
4292: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4293: if (document.$formname.selfenroll_all[i].checked) {
4294: selall = document.$formname.selfenroll_all[i].value;
4295: }
4296: }
4297: if (selall == 1) {
4298: if (delidx != -1) {
4299: if (document.$formname.selfenroll_delete.length) {
4300: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
4301: document.$formname.selfenroll_delete[j].checked = true;
4302: }
4303: } else {
4304: document.$formname.elements[delidx].checked = true;
4305: }
4306: }
4307: if (actidx != -1) {
4308: if (document.$formname.selfenroll_activate.length) {
4309: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4310: document.$formname.selfenroll_activate[j].checked = false;
4311: }
4312: } else {
4313: document.$formname.elements[actidx].checked = false;
4314: }
4315: }
4316: document.$formname.selfenroll_newdom.selectedIndex = 0;
4317: }
4318: }
4319: if (caller == 'selfenroll_activate') {
4320: if (document.$formname.selfenroll_activate.length) {
4321: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4322: if (document.$formname.selfenroll_activate[j].value == num) {
4323: if (document.$formname.selfenroll_activate[j].checked) {
4324: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4325: if (document.$formname.selfenroll_all[i].value == '1') {
4326: document.$formname.selfenroll_all[i].checked = false;
4327: }
4328: if (document.$formname.selfenroll_all[i].value == '0') {
4329: document.$formname.selfenroll_all[i].checked = true;
4330: }
4331: }
4332: }
4333: }
4334: }
4335: } else {
4336: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4337: if (document.$formname.selfenroll_all[i].value == '1') {
4338: document.$formname.selfenroll_all[i].checked = false;
4339: }
4340: if (document.$formname.selfenroll_all[i].value == '0') {
4341: document.$formname.selfenroll_all[i].checked = true;
4342: }
4343: }
4344: }
4345: }
4346: if (caller == 'selfenroll_delete') {
4347: if (document.$formname.selfenroll_delete.length) {
4348: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
4349: if (document.$formname.selfenroll_delete[j].value == num) {
4350: if (document.$formname.selfenroll_delete[j].checked) {
4351: var delindex = getIndexByName('selfenroll_types_'+num);
4352: if (delindex != -1) {
4353: if (document.$formname.elements[delindex].length) {
4354: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
4355: document.$formname.elements[delindex][k].checked = false;
4356: }
4357: } else {
4358: document.$formname.elements[delindex].checked = false;
4359: }
4360: }
4361: }
4362: }
4363: }
4364: } else {
4365: if (document.$formname.selfenroll_delete.checked) {
4366: var delindex = getIndexByName('selfenroll_types_'+num);
4367: if (delindex != -1) {
4368: if (document.$formname.elements[delindex].length) {
4369: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
4370: document.$formname.elements[delindex][k].checked = false;
4371: }
4372: } else {
4373: document.$formname.elements[delindex].checked = false;
4374: }
4375: }
4376: }
4377: }
4378: }
4379: return;
4380: }
4381:
4382: function validate_types(form) {
4383: var needaction = new Array();
4384: var countfail = 0;
4385: var actidx = getIndexByName('selfenroll_activate');
4386: if (actidx != -1) {
4387: if (document.$formname.selfenroll_activate.length) {
4388: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4389: var num = document.$formname.selfenroll_activate[j].value;
4390: if (document.$formname.selfenroll_activate[j].checked) {
4391: countfail = check_types(num,countfail,needaction)
4392: }
4393: }
4394: } else {
4395: if (document.$formname.selfenroll_activate.checked) {
4396: var num = document.enrollstudent.selfenroll_activate.value;
4397: countfail = check_types(num,countfail,needaction)
4398: }
4399: }
4400: }
4401: if (countfail > 0) {
4402: var msg = "$alerts{'acto'}\\n";
4403: var loopend = needaction.length -1;
4404: if (loopend > 0) {
4405: for (var m=0; m<loopend; m++) {
4406: msg += needaction[m]+", ";
4407: }
4408: }
4409: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
4410: alert(msg);
4411: return;
4412: }
4413: setSections(form);
4414: }
4415:
4416: function check_types(num,countfail,needaction) {
4417: var typeidx = getIndexByName('selfenroll_types_'+num);
4418: var count = 0;
4419: if (typeidx != -1) {
4420: if (document.$formname.elements[typeidx].length) {
4421: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
4422: if (document.$formname.elements[typeidx][k].checked) {
4423: count ++;
4424: }
4425: }
4426: } else {
4427: if (document.$formname.elements[typeidx].checked) {
4428: count ++;
4429: }
4430: }
4431: if (count == 0) {
4432: var domidx = getIndexByName('selfenroll_dom_'+num);
4433: if (domidx != -1) {
4434: var domname = document.$formname.elements[domidx].value;
4435: needaction[countfail] = domname;
4436: countfail ++;
4437: }
4438: }
4439: }
4440: return countfail;
4441: }
4442:
4443: function getIndexByName(item) {
4444: for (var i=0;i<document.$formname.elements.length;i++) {
4445: if (document.$formname.elements[i].name == item) {
4446: return i;
4447: }
4448: }
4449: return -1;
4450: }
4451: ENDSCRIPT
1.256 raeburn 4452: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4453: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4454:
1.237 raeburn 4455: my $output = '<script type="text/javascript">'."\n".
1.295.2.4 raeburn 4456: '// <![CDATA['."\n".
1.249 raeburn 4457: $setsec_js."\n".$selfenroll_js."\n".
1.295.2.4 raeburn 4458: '// ]]>'."\n".
1.237 raeburn 4459: '</script>'."\n".
1.256 raeburn 4460: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
4461: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
4462: if (ref($visactions) eq 'HASH') {
4463: if ($visible) {
1.283 bisitz 4464: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
1.256 raeburn 4465: } else {
1.283 bisitz 4466: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
4467: .$visactions->{'yous'}.
1.256 raeburn 4468: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
4469: if (ref($vismsgs) eq 'ARRAY') {
4470: $output .= '<br />'.$visactions->{'make'}.'<ul>';
4471: foreach my $item (@{$vismsgs}) {
4472: $output .= '<li>'.$visactions->{$item}.'</li>';
4473: }
4474: $output .= '</ul>';
4475: }
4476: $output .= '</p>';
4477: }
4478: }
4479: $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
4480: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 4481: if (ref($row) eq 'ARRAY') {
4482: foreach my $item (@{$row}) {
4483: my $title = $item;
4484: if (ref($lt) eq 'HASH') {
4485: $title = $lt->{$item};
4486: }
4487: $output .=
4488: &Apache::lonhtmlcommon::row_title($title,
4489: 'LC_selfenroll_pick_box_title','LC_oddrow_value')."\n";
4490: if ($item eq 'types') {
4491: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 4492: my $showdomdesc = 1;
4493: my $includeempty = 1;
4494: my $num = 0;
4495: $output .= &Apache::loncommon::start_data_table().
4496: &Apache::loncommon::start_data_table_row()
4497: .'<td colspan="2"><span class="LC_nobreak"><label>'
4498: .&mt('Any user in any domain:')
4499: .' <input type="radio" name="selfenroll_all" value="1" ';
4500: if ($curr_types eq '*') {
4501: $output .= ' checked="checked" ';
4502: }
1.249 raeburn 4503: $output .= 'onchange="javascript:update_types('.
4504: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
4505: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 4506: if ($curr_types ne '*') {
4507: $output .= ' checked="checked" ';
4508: }
1.249 raeburn 4509: $output .= ' onchange="javascript:update_types('.
4510: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
4511: &Apache::loncommon::end_data_table_row().
4512: &Apache::loncommon::end_data_table().
4513: &mt('Or').'<br />'.
4514: &Apache::loncommon::start_data_table();
1.241 raeburn 4515: my %currdoms;
1.249 raeburn 4516: if ($curr_types eq '') {
1.241 raeburn 4517: $output .= &new_selfenroll_dom_row($cdom,'0');
4518: } elsif ($curr_types ne '*') {
4519: my @entries = split(/;/,$curr_types);
4520: if (@entries > 0) {
4521: foreach my $entry (@entries) {
4522: my ($currdom,$typestr) = split(/:/,$entry);
4523: $currdoms{$currdom} = 1;
4524: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 4525: my @currinsttypes = split(',',$typestr);
1.241 raeburn 4526: $output .= &Apache::loncommon::start_data_table_row()
4527: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
4528: .' '.$domdesc.' ('.$currdom.')'
4529: .'</b><input type="hidden" name="selfenroll_dom_'.$num
4530: .'" value="'.$currdom.'" /></span><br />'
4531: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 4532: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 4533: .&mt('Delete').'</label></span></td>';
1.249 raeburn 4534: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 4535: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
4536: .&Apache::loncommon::end_data_table_row();
4537: $num ++;
4538: }
4539: }
4540: }
1.249 raeburn 4541: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 4542: if ($curr_types eq '*') {
1.249 raeburn 4543: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 4544: } elsif ($curr_types eq '') {
1.249 raeburn 4545: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 4546: }
4547: $output .= &Apache::loncommon::start_data_table_row()
4548: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
4549: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
4550: $includeempty,$showdomdesc)
4551: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
4552: .'</td>'.&Apache::loncommon::end_data_table_row()
4553: .&Apache::loncommon::end_data_table();
1.237 raeburn 4554: } elsif ($item eq 'registered') {
4555: my ($regon,$regoff);
4556: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
4557: $regon = ' checked="checked" ';
4558: $regoff = ' ';
4559: } else {
4560: $regon = ' ';
4561: $regoff = ' checked="checked" ';
4562: }
4563: $output .= '<label>'.
1.245 raeburn 4564: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 4565: &mt('Yes').'</label> <label>'.
1.245 raeburn 4566: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 4567: &mt('No').'</label>';
1.237 raeburn 4568: } elsif ($item eq 'enroll_dates') {
4569: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
4570: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
4571: if ($starttime eq '') {
4572: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
4573: }
4574: if ($endtime eq '') {
4575: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
4576: }
4577: my $startform =
4578: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
4579: undef,undef,undef,undef,undef,undef,undef,$nolink);
4580: my $endform =
4581: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
4582: undef,undef,undef,undef,undef,undef,undef,$nolink);
4583: $output .= &selfenroll_date_forms($startform,$endform);
4584: } elsif ($item eq 'access_dates') {
4585: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
4586: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
4587: if ($starttime eq '') {
4588: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
4589: }
4590: if ($endtime eq '') {
4591: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
4592: }
4593: my $startform =
4594: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
4595: undef,undef,undef,undef,undef,undef,undef,$nolink);
4596: my $endform =
4597: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
4598: undef,undef,undef,undef,undef,undef,undef,$nolink);
4599: $output .= &selfenroll_date_forms($startform,$endform);
4600: } elsif ($item eq 'section') {
4601: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
4602: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
4603: my $newsecval;
4604: if ($currsec ne 'none' && $currsec ne '') {
4605: if (!defined($sections_count{$currsec})) {
4606: $newsecval = $currsec;
4607: }
4608: }
4609: my $sections_select =
4610: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
4611: $output .= '<table class="LC_createuser">'."\n".
4612: '<tr class="LC_section_row">'."\n".
4613: '<td align="center">'.&mt('Existing sections')."\n".
4614: '<br />'.$sections_select.'</td><td align="center">'.
4615: &mt('New section').'<br />'."\n".
4616: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
4617: '<input type="hidden" name="sections" value="" />'."\n".
4618: '<input type="hidden" name="state" value="done" />'."\n".
4619: '</td></tr></table>'."\n";
1.276 raeburn 4620: } elsif ($item eq 'approval') {
4621: my ($appon,$appoff);
4622: my $cid = $env{'request.course.id'};
4623: my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
4624: if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) {
4625: $appon = ' checked="checked" ';
4626: $appoff = ' ';
4627: } else {
4628: $appon = ' ';
4629: $appoff = ' checked="checked" ';
4630: }
4631: $output .= '<label>'.
4632: '<input type="radio" name="selfenroll_approval" value="1"'.$appon.'/>'.
4633: &mt('Yes').'</label> <label>'.
4634: '<input type="radio" name="selfenroll_approval" value="0"'.$appoff.'/>'.
4635: &mt('No').'</label>';
4636: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
4637: my (@ccs,%notified);
1.295.2.22! raeburn 4638: my $ccrole = 'cc';
! 4639: if ($crstype eq 'Community') {
! 4640: $ccrole = 'co';
! 4641: }
! 4642: if ($advhash{$ccrole}) {
! 4643: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 4644: }
4645: if ($currnotified) {
4646: foreach my $current (split(/,/,$currnotified)) {
4647: $notified{$current} = 1;
4648: if (!grep(/^\Q$current\E$/,@ccs)) {
4649: push(@ccs,$current);
4650: }
4651: }
4652: }
4653: if (@ccs) {
1.277 raeburn 4654: $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 4655: &Apache::loncommon::start_data_table_row();
4656: my $count = 0;
4657: my $numcols = 4;
4658: foreach my $cc (sort(@ccs)) {
4659: my $notifyon;
4660: my ($ccuname,$ccudom) = split(/:/,$cc);
4661: if ($notified{$cc}) {
4662: $notifyon = ' checked="checked" ';
4663: }
4664: if ($count && !$count%$numcols) {
4665: $output .= &Apache::loncommon::end_data_table_row().
4666: &Apache::loncommon::start_data_table_row()
4667: }
4668: $output .= '<td><span class="LC_nobreak"><label>'.
4669: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
4670: &Apache::loncommon::plainname($ccuname,$ccudom).
4671: '</label></span></td>';
4672: $count;
4673: }
4674: my $rem = $count%$numcols;
4675: if ($rem) {
4676: my $emptycols = $numcols - $rem;
4677: for (my $i=0; $i<$emptycols; $i++) {
4678: $output .= '<td> </td>';
4679: }
4680: }
4681: $output .= &Apache::loncommon::end_data_table_row().
4682: &Apache::loncommon::end_data_table();
4683: }
4684: } elsif ($item eq 'limit') {
4685: my ($crslimit,$selflimit,$nolimit);
4686: my $cid = $env{'request.course.id'};
4687: my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'};
4688: my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
4689: my $nolimit = ' checked="checked" ';
4690: if ($currlim eq 'allstudents') {
4691: $crslimit = ' checked="checked" ';
4692: $selflimit = ' ';
4693: $nolimit = ' ';
4694: } elsif ($currlim eq 'selfenrolled') {
4695: $crslimit = ' ';
4696: $selflimit = ' checked="checked" ';
4697: $nolimit = ' ';
4698: } else {
4699: $crslimit = ' ';
4700: $selflimit = ' ';
4701: }
4702: $output .= '<table><tr><td><label>'.
1.278 raeburn 4703: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 4704: &mt('No limit').'</label></td><td><label>'.
4705: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
4706: &mt('Limit by total students').'</label></td><td><label>'.
4707: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
4708: &mt('Limit by total self-enrolled students').
4709: '</td></tr><tr>'.
4710: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
4711: (' 'x3).&mt('Maximum number allowed: ').
4712: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 4713: }
4714: $output .= &Apache::lonhtmlcommon::row_closure(1);
4715: }
4716: }
4717: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 4718: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 4719: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.241 raeburn 4720: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 4721: $r->print($output);
4722: return;
4723: }
4724:
1.256 raeburn 4725: sub visible_in_cat {
4726: my ($cdom,$cnum) = @_;
4727: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
4728: my ($cathash,%settable,@vismsgs,$cansetvis);
4729: my %visactions = &Apache::lonlocal::texthash(
1.295.2.17 raeburn 4730: vis => 'Your course/community currently appears in the Course/Community Catalog for this domain.',
1.256 raeburn 4731: 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.295.2.17 raeburn 4732: miss => 'Your course/community does not currently appear in the Course/Community Catalog for this domain.',
1.256 raeburn 4733: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
4734: 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 4735: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
1.256 raeburn 4736: take => 'Take the following action to ensure the course appears in the Catalog:',
4737: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
4738: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
4739: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
4740: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
4741: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
4742: 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',
4743: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
4744: );
1.261 raeburn 4745: $visactions{'unhide'} = &mt('Use [_1]Set course environment[_2] to change the "Exclude from course catalog" setting.','"<a href="/adm/parmset?action=crsenv">','</a>"');
4746: $visactions{'chgcat'} = &mt('Use [_1]Set course environment[_2] to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','"<a href="/adm/parmset?action=crsenv">','</a>"');
4747: $visactions{'addcat'} = &mt('Use [_1]Set course environment[_2] to assign a category to the course.','"<a href="/adm/parmset?action=crsenv">','</a>"');
1.256 raeburn 4748: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4749: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
4750: $settable{'togglecats'} = 1;
4751: }
4752: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
4753: $settable{'categorize'} = 1;
4754: }
4755: $cathash = $domconf{'coursecategories'}{'cats'};
4756: }
1.260 raeburn 4757: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 4758: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
4759: } elsif ($settable{'togglecats'}) {
4760: $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 4761: } elsif ($settable{'categorize'}) {
1.256 raeburn 4762: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
4763: } else {
4764: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
4765: }
4766:
4767: my %currsettings =
4768: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
4769: $cdom,$cnum);
4770: my $visible = 0;
4771: if ($currsettings{'internal.coursecode'} ne '') {
4772: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4773: $cathash = $domconf{'coursecategories'}{'cats'};
4774: if (ref($cathash) eq 'HASH') {
4775: if ($cathash->{'instcode::0'} eq '') {
4776: push(@vismsgs,'dc_addinst');
4777: } else {
4778: $visible = 1;
4779: }
4780: } else {
4781: $visible = 1;
4782: }
4783: } else {
4784: $visible = 1;
4785: }
4786: } else {
4787: if (ref($cathash) eq 'HASH') {
4788: if ($cathash->{'instcode::0'} ne '') {
4789: push(@vismsgs,'dc_instcode');
4790: }
4791: } else {
4792: push(@vismsgs,'dc_instcode');
4793: }
4794: }
4795: if ($currsettings{'categories'} ne '') {
4796: my $cathash;
4797: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4798: $cathash = $domconf{'coursecategories'}{'cats'};
4799: if (ref($cathash) eq 'HASH') {
4800: if (keys(%{$cathash}) == 0) {
4801: push(@vismsgs,'dc_catalog');
4802: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
4803: push(@vismsgs,'dc_categories');
4804: } else {
4805: my @currcategories = split('&',$currsettings{'categories'});
4806: my $matched = 0;
4807: foreach my $cat (@currcategories) {
4808: if ($cathash->{$cat} ne '') {
4809: $visible = 1;
4810: $matched = 1;
4811: last;
4812: }
4813: }
4814: if (!$matched) {
1.260 raeburn 4815: if ($settable{'categorize'}) {
1.256 raeburn 4816: push(@vismsgs,'chgcat');
4817: } else {
4818: push(@vismsgs,'dc_chgcat');
4819: }
4820: }
4821: }
4822: }
4823: }
4824: } else {
4825: if (ref($cathash) eq 'HASH') {
4826: if ((keys(%{$cathash}) > 1) ||
4827: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 4828: if ($settable{'categorize'}) {
1.256 raeburn 4829: push(@vismsgs,'addcat');
4830: } else {
4831: push(@vismsgs,'dc_addcat');
4832: }
4833: }
4834: }
4835: }
4836: if ($currsettings{'hidefromcat'} eq 'yes') {
4837: $visible = 0;
4838: if ($settable{'togglecats'}) {
4839: unshift(@vismsgs,'unhide');
4840: } else {
4841: unshift(@vismsgs,'dc_unhide')
4842: }
4843: }
4844: return ($visible,$cansetvis,\@vismsgs,\%visactions);
4845: }
4846:
1.241 raeburn 4847: sub new_selfenroll_dom_row {
4848: my ($newdom,$num) = @_;
4849: my $domdesc = &Apache::lonnet::domain($newdom);
4850: my $output;
4851: if ($domdesc ne '') {
4852: $output .= &Apache::loncommon::start_data_table_row()
4853: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
4854: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 4855: .'" value="'.$newdom.'" /></span><br />'
4856: .'<span class="LC_nobreak"><label><input type="checkbox" '
4857: .'name="selfenroll_activate" value="'.$num.'" '
4858: .'onchange="javascript:update_types('
4859: ."'selfenroll_activate','$num'".');" />'
4860: .&mt('Activate').'</label></span></td>';
1.241 raeburn 4861: my @currinsttypes;
4862: $output .= '<td>'.&mt('User types:').'<br />'
4863: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
4864: .&Apache::loncommon::end_data_table_row();
4865: }
4866: return $output;
4867: }
4868:
4869: sub selfenroll_inst_types {
4870: my ($num,$currdom,$currinsttypes) = @_;
4871: my $output;
4872: my $numinrow = 4;
4873: my $count = 0;
4874: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 4875: my $othervalue = 'any';
1.241 raeburn 4876: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 4877: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 4878: $othervalue = 'other';
4879: }
1.241 raeburn 4880: $output .= '<table><tr>';
4881: foreach my $type (@{$types}) {
4882: if (($count > 0) && ($count%$numinrow == 0)) {
4883: $output .= '</tr><tr>';
4884: }
4885: if (defined($usertypes->{$type})) {
1.257 raeburn 4886: my $esc_type = &escape($type);
1.241 raeburn 4887: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 4888: $esc_type.'" ';
1.241 raeburn 4889: if (ref($currinsttypes) eq 'ARRAY') {
4890: if (@{$currinsttypes} > 0) {
1.249 raeburn 4891: if (grep(/^any$/,@{$currinsttypes})) {
4892: $output .= 'checked="checked"';
1.257 raeburn 4893: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 4894: $output .= 'checked="checked"';
4895: }
1.249 raeburn 4896: } else {
4897: $output .= 'checked="checked"';
1.241 raeburn 4898: }
4899: }
4900: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
4901: }
4902: $count ++;
4903: }
4904: if (($count > 0) && ($count%$numinrow == 0)) {
4905: $output .= '</tr><tr>';
4906: }
1.249 raeburn 4907: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 4908: if (ref($currinsttypes) eq 'ARRAY') {
4909: if (@{$currinsttypes} > 0) {
1.249 raeburn 4910: if (grep(/^any$/,@{$currinsttypes})) {
4911: $output .= ' checked="checked"';
4912: } elsif ($othervalue eq 'other') {
4913: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
4914: $output .= ' checked="checked"';
4915: }
1.241 raeburn 4916: }
1.249 raeburn 4917: } else {
4918: $output .= ' checked="checked"';
1.241 raeburn 4919: }
1.249 raeburn 4920: } else {
4921: $output .= ' checked="checked"';
1.241 raeburn 4922: }
4923: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
4924: }
4925: return $output;
4926: }
4927:
1.237 raeburn 4928: sub selfenroll_date_forms {
4929: my ($startform,$endform) = @_;
4930: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 4931: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 4932: 'LC_oddrow_value')."\n".
4933: $startform."\n".
4934: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 4935: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 4936: 'LC_oddrow_value')."\n".
4937: $endform."\n".
4938: &Apache::lonhtmlcommon::row_closure(1).
4939: &Apache::lonhtmlcommon::end_pick_box();
4940: return $output;
4941: }
4942:
1.239 raeburn 4943: sub print_userchangelogs_display {
4944: my ($r,$context,$permission) = @_;
4945: my $formname = 'roleslog';
4946: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4947: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.295.2.18 raeburn 4948: my $crstype = &Apache::loncommon::course_type();
1.239 raeburn 4949: my %roleslog=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
4950: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
4951:
4952: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
4953: my %saveable_parameters = ('show' => 'scalar',);
4954: &Apache::loncommon::store_course_settings('roles_log',
4955: \%saveable_parameters);
4956: &Apache::loncommon::restore_course_settings('roles_log',
4957: \%saveable_parameters);
4958: # set defaults
4959: my $now = time();
4960: my $defstart = $now - (7*24*3600); #7 days ago
4961: my %defaults = (
4962: page => '1',
4963: show => '10',
4964: role => 'any',
4965: chgcontext => 'any',
4966: rolelog_start_date => $defstart,
4967: rolelog_end_date => $now,
4968: );
4969: my $more_records = 0;
4970:
4971: # set current
4972: my %curr;
4973: foreach my $item ('show','page','role','chgcontext') {
4974: $curr{$item} = $env{'form.'.$item};
4975: }
4976: my ($startdate,$enddate) =
4977: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
4978: $curr{'rolelog_start_date'} = $startdate;
4979: $curr{'rolelog_end_date'} = $enddate;
4980: foreach my $key (keys(%defaults)) {
4981: if ($curr{$key} eq '') {
4982: $curr{$key} = $defaults{$key};
4983: }
4984: }
1.248 raeburn 4985: my (%whodunit,%changed,$version);
4986: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.295.2.18 raeburn 4987: $r->print(&role_display_filter($formname,$cdom,$cnum,\%curr,$version,$crstype));
1.239 raeburn 4988: my $showntablehdr = 0;
4989: my $tablehdr = &Apache::loncommon::start_data_table().
4990: &Apache::loncommon::start_data_table_header_row().
4991: '<th> </th><th>'.&mt('When').'</th><th>'.&mt('Who made the change').
4992: '</th><th>'.&mt('Changed User').'</th><th>'.&mt('Role').'</th><th>'.&mt('Section').'</th><th>'.
4993: &mt('Context').'</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
4994: &Apache::loncommon::end_data_table_header_row();
4995: my ($minshown,$maxshown);
1.255 raeburn 4996: $minshown = 1;
1.239 raeburn 4997: my $count = 0;
4998: if ($curr{'show'} ne &mt('all')) {
4999: $maxshown = $curr{'page'} * $curr{'show'};
5000: if ($curr{'page'} > 1) {
5001: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
5002: }
5003: }
5004: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
5005: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
5006: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
5007: if ($curr{'show'} ne &mt('all')) {
5008: if ($count >= $curr{'page'} * $curr{'show'}) {
5009: $more_records = 1;
5010: last;
5011: }
5012: }
5013: if ($curr{'role'} ne 'any') {
5014: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
5015: }
5016: if ($curr{'chgcontext'} ne 'any') {
5017: if ($curr{'chgcontext'} eq 'selfenroll') {
5018: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
5019: } else {
5020: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
5021: }
5022: }
5023: $count ++;
5024: next if ($count < $minshown);
5025: if (!$showntablehdr) {
5026: $r->print($tablehdr);
5027: $showntablehdr = 1;
5028: }
5029: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
5030: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
5031: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
5032: }
5033: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
5034: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
5035: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
5036: }
5037: my $sec = $roleslog{$id}{'logentry'}{'section'};
5038: if ($sec eq '') {
5039: $sec = &mt('None');
5040: }
5041: my ($rolestart,$roleend);
5042: if ($roleslog{$id}{'delflag'}) {
5043: $rolestart = &mt('deleted');
5044: $roleend = &mt('deleted');
5045: } else {
5046: $rolestart = $roleslog{$id}{'logentry'}{'start'};
5047: $roleend = $roleslog{$id}{'logentry'}{'end'};
5048: if ($rolestart eq '' || $rolestart == 0) {
5049: $rolestart = &mt('No start date');
5050: } else {
5051: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
5052: }
5053: if ($roleend eq '' || $roleend == 0) {
5054: $roleend = &mt('No end date');
5055: } else {
5056: $roleend = &Apache::lonlocal::locallocaltime($roleend);
5057: }
5058: }
5059: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
5060: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
5061: $chgcontext = 'selfenroll';
5062: }
1.295.2.18 raeburn 5063: my %lt = &rolechg_contexts($crstype);
1.239 raeburn 5064: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
5065: $chgcontext = $lt{$chgcontext};
5066: }
1.295.2.18 raeburn 5067: $r->print(&Apache::loncommon::start_data_table_row().'<td>'.$count.'</td><td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td><td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td><td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td><td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td><td>'.$sec.'</td><td>'.$chgcontext.'</td><td>'.$rolestart.'</td><td>'.$roleend.'</td>'.&Apache::loncommon::end_data_table_row()."\n");
1.239 raeburn 5068: }
5069: if ($showntablehdr) {
5070: $r->print(&Apache::loncommon::end_data_table().'<br />');
5071: if (($curr{'page'} > 1) || ($more_records)) {
5072: $r->print('<table><tr>');
5073: if ($curr{'page'} > 1) {
5074: $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
5075: }
5076: if ($more_records) {
5077: $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
5078: }
5079: $r->print('</tr></table>');
5080: $r->print(<<"ENDSCRIPT");
5081: <script type="text/javascript">
1.295.2.4 raeburn 5082: // <![CDATA[
1.239 raeburn 5083: function chgPage(caller) {
5084: if (caller == 'previous') {
5085: document.$formname.page.value --;
5086: }
5087: if (caller == 'next') {
5088: document.$formname.page.value ++;
5089: }
5090: document.$formname.submit();
5091: return;
5092: }
1.295.2.4 raeburn 5093: // ]]>
1.239 raeburn 5094: </script>
5095: ENDSCRIPT
5096: }
5097: } else {
1.295.2.4 raeburn 5098: $r->print('<p class="LC_info">'.
5099: &mt('There are no records to display').
5100: '</p>');
1.239 raeburn 5101: }
5102: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
5103: '<input type="hidden" name="action" value="changelogs" /></form>');
5104: return;
5105: }
5106:
5107: sub role_display_filter {
1.295.2.18 raeburn 5108: my ($formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
1.239 raeburn 5109: my $context = 'course';
1.295.2.18 raeburn 5110: my $lctype = lc($crstype);
1.239 raeburn 5111: my $nolink = 1;
5112: my $output = '<table><tr><td valign="top">'.
1.295.2.4 raeburn 5113: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 5114: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
5115: (&mt('all'),5,10,20,50,100,1000,10000)).
5116: '</td><td> </td>';
5117: my $startform =
5118: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
5119: $curr->{'rolelog_start_date'},undef,
5120: undef,undef,undef,undef,undef,undef,$nolink);
5121: my $endform =
5122: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
5123: $curr->{'rolelog_end_date'},undef,
5124: undef,undef,undef,undef,undef,undef,$nolink);
1.295.2.18 raeburn 5125: my %lt = &rolechg_contexts($crstype);
1.239 raeburn 5126: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br /><table><tr><td>'.&mt('After:').
5127: '</td><td>'.$startform.'</td></tr><tr><td>'.&mt('Before:').'</td><td>'.
5128: $endform.'</td></tr></table></td><td> </td>'.
5129: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
5130: '<select name="role"><option value="any"';
5131: if ($curr->{'role'} eq 'any') {
5132: $output .= ' selected="selected"';
5133: }
5134: $output .= '>'.&mt('Any').'</option>'."\n";
1.295.2.18 raeburn 5135: my @roles = &Apache::lonuserutils::course_roles($context,undef,1,$lctype);
1.239 raeburn 5136: foreach my $role (@roles) {
5137: my $plrole;
5138: if ($role eq 'cr') {
5139: $plrole = &mt('Custom Role');
5140: } else {
1.295.2.18 raeburn 5141: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 5142: }
5143: my $selstr = '';
5144: if ($role eq $curr->{'role'}) {
5145: $selstr = ' selected="selected"';
5146: }
5147: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
5148: }
5149: $output .= '</select></td><td> </td><td valign="top"><b>'.
5150: &mt('Context:').'</b><br /><select name="chgcontext">';
1.295.2.18 raeburn 5151: foreach my $chgtype ('any','auto','updatenow','createcourse','course','domain','selfenroll','requestcourses') {
1.239 raeburn 5152: my $selstr = '';
5153: if ($curr->{'chgcontext'} eq $chgtype) {
1.295.2.4 raeburn 5154: $selstr = ' selected="selected"';
1.239 raeburn 5155: }
5156: if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) {
5157: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
5158: }
5159: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 5160: }
1.295.2.7 raeburn 5161: $output .= '</select></td>'
5162: .'</tr></table>';
5163:
5164: # Update Display button
5165: $output .= '<p>'
5166: .'<input type="submit" value="'.&mt('Update Display').'" />'
5167: .'</p>';
5168:
5169: # Server version info
5170: $output .= '<p style="font-size: smaller;" class="LC_info">'
5171: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
5172: ,'2.6.99.0');
1.248 raeburn 5173: if ($version) {
1.295.2.7 raeburn 5174: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
5175: }
5176: $output .= '</p><hr /><br />';
1.239 raeburn 5177: return $output;
5178: }
5179:
5180: sub rolechg_contexts {
1.295.2.18 raeburn 5181: my ($crstype) = @_;
1.239 raeburn 5182: my %lt = &Apache::lonlocal::texthash (
5183: any => 'Any',
5184: auto => 'Automated enrollment',
5185: updatenow => 'Roster Update',
5186: createcourse => 'Course Creation',
5187: course => 'User Management in course',
5188: domain => 'User Management in domain',
1.295.2.13 raeburn 5189: selfenroll => 'Self-enrolled',
5190: requestcourses => 'Course Request',
1.239 raeburn 5191: );
1.295.2.18 raeburn 5192: if ($crstype eq 'Community') {
5193: $lt{'createcourse'} = &mt('Community Creation');
5194: $lt{'course'} = &mt('User Management in community');
5195: $lt{'requestcourses'} = &mt('Community Request');
5196: }
1.239 raeburn 5197: return %lt;
5198: }
5199:
1.27 matthew 5200: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 5201: sub user_search_result {
1.221 raeburn 5202: my ($context,$srch) = @_;
1.160 raeburn 5203: my %allhomes;
5204: my %inst_matches;
5205: my %srch_results;
1.181 raeburn 5206: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 5207: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 5208: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 5209: $response = &mt('Invalid search.');
5210: }
5211: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
5212: $response = &mt('Invalid search.');
5213: }
1.177 raeburn 5214: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 5215: $response = &mt('Invalid search.');
5216: }
5217: if ($srch->{'srchterm'} eq '') {
5218: $response = &mt('You must enter a search term.');
5219: }
1.183 raeburn 5220: if ($srch->{'srchterm'} =~ /^\s+$/) {
5221: $response = &mt('Your search term must contain more than just spaces.');
5222: }
1.160 raeburn 5223: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
5224: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 5225: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 5226: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
5227: }
5228: }
5229: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
5230: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 5231: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 5232: my $unamecheck = $srch->{'srchterm'};
5233: if ($srch->{'srchtype'} eq 'contains') {
5234: if ($unamecheck !~ /^\w/) {
5235: $unamecheck = 'a'.$unamecheck;
5236: }
5237: }
5238: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 5239: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
5240: }
1.160 raeburn 5241: }
5242: }
1.180 raeburn 5243: if ($response ne '') {
5244: $response = '<span class="LC_warning">'.$response.'</span>';
5245: }
1.160 raeburn 5246: if ($srch->{'srchin'} eq 'instd') {
5247: my $instd_chk = &directorysrch_check($srch);
5248: if ($instd_chk ne 'ok') {
1.180 raeburn 5249: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
5250: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 5251: }
5252: }
5253: if ($response ne '') {
1.180 raeburn 5254: return ($currstate,$response);
1.160 raeburn 5255: }
5256: if ($srch->{'srchby'} eq 'uname') {
5257: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
5258: if ($env{'form.forcenew'}) {
5259: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
5260: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
5261: if ($uhome eq 'no_host') {
5262: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 5263: my $showdom = &display_domain_info($env{'request.role.domain'});
5264: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 5265: } else {
1.179 raeburn 5266: $currstate = 'modify';
1.160 raeburn 5267: }
5268: } else {
1.179 raeburn 5269: $currstate = 'modify';
1.160 raeburn 5270: }
5271: } else {
5272: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 5273: if ($srch->{'srchtype'} eq 'exact') {
5274: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
5275: if ($uhome eq 'no_host') {
1.179 raeburn 5276: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5277: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 5278: } else {
1.179 raeburn 5279: $currstate = 'modify';
1.295.2.11 raeburn 5280: my $uname = $srch->{'srchterm'};
5281: my $udom = $srch->{'srchdomain'};
5282: $srch_results{$uname.':'.$udom} =
5283: { &Apache::lonnet::get('environment',
5284: ['firstname',
5285: 'lastname',
5286: 'permanentemail'],
5287: $udom,$uname)
5288: };
1.162 raeburn 5289: }
5290: } else {
5291: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 5292: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5293: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5294: }
5295: } else {
1.167 albertel 5296: my $courseusers = &get_courseusers();
1.162 raeburn 5297: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 5298: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 5299: $currstate = 'modify';
1.162 raeburn 5300: } else {
1.179 raeburn 5301: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5302: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 5303: }
1.160 raeburn 5304: } else {
1.167 albertel 5305: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 5306: my ($cuname,$cudomain) = split(/:/,$user);
5307: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 5308: my $matched = 0;
5309: if ($srch->{'srchtype'} eq 'begins') {
5310: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
5311: $matched = 1;
5312: }
5313: } else {
5314: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
5315: $matched = 1;
5316: }
5317: }
5318: if ($matched) {
1.167 albertel 5319: $srch_results{$user} =
5320: {&Apache::lonnet::get('environment',
5321: ['firstname',
5322: 'lastname',
1.194 albertel 5323: 'permanentemail'],
5324: $cudomain,$cuname)};
1.162 raeburn 5325: }
5326: }
5327: }
1.179 raeburn 5328: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5329: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5330: }
5331: }
5332: }
5333: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 5334: $currstate = 'query';
1.160 raeburn 5335: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 5336: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
5337: if ($dirsrchres eq 'ok') {
5338: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5339: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 5340: } else {
5341: my $showdom = &display_domain_info($srch->{'srchdomain'});
5342: $response = '<span class="LC_warning">'.
5343: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
5344: '</span><br />'.
5345: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
5346: '<br /><br />';
5347: }
1.160 raeburn 5348: }
5349: } else {
5350: if ($srch->{'srchin'} eq 'dom') {
5351: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 5352: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5353: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5354: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 5355: my $courseusers = &get_courseusers();
5356: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 5357: my ($uname,$udom) = split(/:/,$user);
5358: my %names = &Apache::loncommon::getnames($uname,$udom);
5359: my %emails = &Apache::loncommon::getemails($uname,$udom);
5360: if ($srch->{'srchby'} eq 'lastname') {
5361: if ((($srch->{'srchtype'} eq 'exact') &&
5362: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 5363: (($srch->{'srchtype'} eq 'begins') &&
5364: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 5365: (($srch->{'srchtype'} eq 'contains') &&
5366: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
5367: $srch_results{$user} = {firstname => $names{'firstname'},
5368: lastname => $names{'lastname'},
5369: permanentemail => $emails{'permanentemail'},
5370: };
5371: }
5372: } elsif ($srch->{'srchby'} eq 'lastfirst') {
5373: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 5374: $srchlast =~ s/\s+$//;
5375: $srchfirst =~ s/^\s+//;
1.160 raeburn 5376: if ($srch->{'srchtype'} eq 'exact') {
5377: if (($names{'lastname'} eq $srchlast) &&
5378: ($names{'firstname'} eq $srchfirst)) {
5379: $srch_results{$user} = {firstname => $names{'firstname'},
5380: lastname => $names{'lastname'},
5381: permanentemail => $emails{'permanentemail'},
5382:
5383: };
5384: }
1.177 raeburn 5385: } elsif ($srch->{'srchtype'} eq 'begins') {
5386: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
5387: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
5388: $srch_results{$user} = {firstname => $names{'firstname'},
5389: lastname => $names{'lastname'},
5390: permanentemail => $emails{'permanentemail'},
5391: };
5392: }
5393: } else {
1.160 raeburn 5394: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
5395: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
5396: $srch_results{$user} = {firstname => $names{'firstname'},
5397: lastname => $names{'lastname'},
5398: permanentemail => $emails{'permanentemail'},
5399: };
5400: }
5401: }
5402: }
5403: }
1.179 raeburn 5404: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5405: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5406: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 5407: $currstate = 'query';
1.160 raeburn 5408: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 5409: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
5410: if ($dirsrchres eq 'ok') {
5411: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5412: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 5413: } else {
5414: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
5415: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
5416: '</span><br />'.
5417: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
5418: '<br /><br />';
5419: }
1.160 raeburn 5420: }
5421: }
1.179 raeburn 5422: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 5423: }
5424:
5425: sub directorysrch_check {
5426: my ($srch) = @_;
5427: my $can_search = 0;
5428: my $response;
5429: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
5430: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 5431: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 5432: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
5433: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 5434: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 5435: }
5436: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
5437: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 5438: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 5439: }
5440: my @usertypes = split(/:/,$env{'environment.inststatus'});
5441: if (!@usertypes) {
5442: push(@usertypes,'default');
5443: }
5444: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
5445: foreach my $type (@usertypes) {
5446: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
5447: $can_search = 1;
5448: last;
5449: }
5450: }
5451: }
5452: if (!$can_search) {
5453: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
5454: my @longtypes;
5455: foreach my $item (@usertypes) {
1.229 raeburn 5456: if (defined($insttypes->{$item})) {
5457: push (@longtypes,$insttypes->{$item});
5458: } elsif ($item eq 'default') {
5459: push (@longtypes,&mt('other'));
5460: }
1.160 raeburn 5461: }
5462: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 5463: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 5464: }
1.160 raeburn 5465: } else {
5466: $can_search = 1;
5467: }
5468: } else {
1.180 raeburn 5469: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 5470: }
5471: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 5472: uname => 'username',
1.160 raeburn 5473: lastfirst => 'last name, first name',
1.167 albertel 5474: lastname => 'last name',
1.172 raeburn 5475: contains => 'contains',
1.178 raeburn 5476: exact => 'as exact match to',
5477: begins => 'begins with',
1.160 raeburn 5478: );
5479: if ($can_search) {
5480: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
5481: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 5482: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 5483: }
5484: } else {
1.180 raeburn 5485: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 5486: }
5487: }
5488: if ($can_search) {
1.178 raeburn 5489: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
5490: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
5491: return 'ok';
5492: } else {
1.180 raeburn 5493: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 5494: }
5495: } else {
5496: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
5497: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
5498: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
5499: return 'ok';
5500: } else {
1.180 raeburn 5501: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 5502: }
1.160 raeburn 5503: }
5504: }
5505: }
5506:
5507: sub get_courseusers {
5508: my %advhash;
1.167 albertel 5509: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 5510: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
5511: foreach my $role (sort(keys(%coursepersonnel))) {
5512: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 5513: if (!exists($classlist->{$user})) {
5514: $classlist->{$user} = [];
5515: }
1.160 raeburn 5516: }
5517: }
1.167 albertel 5518: return $classlist;
1.160 raeburn 5519: }
5520:
5521: sub build_search_response {
1.221 raeburn 5522: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 5523: my ($currstate,$response,$forcenewuser);
1.160 raeburn 5524: my %names = (
5525: 'uname' => 'username',
5526: 'lastname' => 'last name',
5527: 'lastfirst' => 'last name, first name',
5528: 'crs' => 'this course',
1.180 raeburn 5529: 'dom' => 'LON-CAPA domain: ',
5530: 'instd' => 'the institutional directory for domain: ',
1.160 raeburn 5531: );
5532:
5533: my %single = (
1.180 raeburn 5534: begins => 'A match',
1.160 raeburn 5535: contains => 'A match',
1.180 raeburn 5536: exact => 'An exact match',
1.160 raeburn 5537: );
5538: my %nomatch = (
1.180 raeburn 5539: begins => 'No match',
1.160 raeburn 5540: contains => 'No match',
1.180 raeburn 5541: exact => 'No exact match',
1.160 raeburn 5542: );
5543: if (keys(%srch_results) > 1) {
1.179 raeburn 5544: $currstate = 'select';
1.160 raeburn 5545: } else {
5546: if (keys(%srch_results) == 1) {
1.179 raeburn 5547: $currstate = 'modify';
1.180 raeburn 5548: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
5549: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
5550: $response .= &display_domain_info($srch->{'srchdomain'});
5551: }
1.160 raeburn 5552: } else {
1.180 raeburn 5553: $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
5554: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
5555: $response .= &display_domain_info($srch->{'srchdomain'});
5556: }
5557: $response .= '</span>';
1.160 raeburn 5558: if ($srch->{'srchin'} ne 'alc') {
5559: $forcenewuser = 1;
5560: my $cansrchinst = 0;
5561: if ($srch->{'srchdomain'}) {
5562: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
5563: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
5564: if ($domconfig{'directorysrch'}{'available'}) {
5565: $cansrchinst = 1;
5566: }
5567: }
5568: }
1.180 raeburn 5569: if ((($srch->{'srchby'} eq 'lastfirst') ||
5570: ($srch->{'srchby'} eq 'lastname')) &&
5571: ($srch->{'srchin'} eq 'dom')) {
5572: if ($cansrchinst) {
5573: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 5574: }
5575: }
1.180 raeburn 5576: if ($srch->{'srchin'} eq 'crs') {
5577: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
5578: }
5579: }
1.295.2.6 raeburn 5580: my $createdom = $env{'request.role.domain'};
5581: if ($context eq 'requestcrs') {
5582: if ($env{'form.coursedom'} ne '') {
5583: $createdom = $env{'form.coursedom'};
5584: }
5585: }
5586: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $createdom)) {
1.221 raeburn 5587: my $cancreate =
1.295.2.7 raeburn 5588: &Apache::lonuserutils::can_create_user($createdom,$context);
5589: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 5590: if ($cancreate) {
1.295.2.6 raeburn 5591: my $showdom = &display_domain_info($createdom);
1.266 bisitz 5592: $response .= '<br /><br />'
5593: .'<b>'.&mt('To add a new user:').'</b>'
1.295.2.6 raeburn 5594: .'<br />';
5595: if ($context eq 'requestcrs') {
1.295.2.7 raeburn 5596: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
1.295.2.6 raeburn 5597: } else {
1.295.2.7 raeburn 5598: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
5599: }
1.295.2.6 raeburn 5600: $response .= '<ul><li>'
1.266 bisitz 5601: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
5602: .'</li><li>'
5603: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
5604: .'</li><li>'
5605: .&mt('Provide the proposed username')
5606: .'</li><li>'
5607: .&mt("Click 'Search'")
5608: .'</li></ul><br />';
1.221 raeburn 5609: } else {
5610: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.295.2.6 raeburn 5611: $response .= '<br /><br />';
5612: if ($context eq 'requestcrs') {
1.295.2.7 raeburn 5613: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.295.2.6 raeburn 5614: } else {
5615: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
5616: }
5617: $response .= '<br />'
1.292 bisitz 5618: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 5619: ,' <a'.$helplink.'>'
5620: ,'</a>')
5621: .'<br /><br />';
1.221 raeburn 5622: }
1.160 raeburn 5623: }
5624: }
5625: }
1.179 raeburn 5626: return ($currstate,$response,$forcenewuser);
1.160 raeburn 5627: }
5628:
1.180 raeburn 5629: sub display_domain_info {
5630: my ($dom) = @_;
5631: my $output = $dom;
5632: if ($dom ne '') {
5633: my $domdesc = &Apache::lonnet::domain($dom,'description');
5634: if ($domdesc ne '') {
5635: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
5636: }
5637: }
5638: return $output;
5639: }
5640:
1.160 raeburn 5641: sub crumb_utilities {
5642: my %elements = (
5643: crtuser => {
5644: srchterm => 'text',
1.172 raeburn 5645: srchin => 'selectbox',
1.160 raeburn 5646: srchby => 'selectbox',
5647: srchtype => 'selectbox',
5648: srchdomain => 'selectbox',
5649: },
1.207 raeburn 5650: crtusername => {
5651: srchterm => 'text',
5652: srchdomain => 'selectbox',
5653: },
1.160 raeburn 5654: docustom => {
5655: rolename => 'selectbox',
5656: newrolename => 'textbox',
5657: },
1.179 raeburn 5658: studentform => {
5659: srchterm => 'text',
5660: srchin => 'selectbox',
5661: srchby => 'selectbox',
5662: srchtype => 'selectbox',
5663: srchdomain => 'selectbox',
5664: },
1.160 raeburn 5665: );
5666:
5667: my $jsback .= qq|
5668: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 5669: if (typeof prevphase == 'undefined') {
5670: formname.phase.value = '';
5671: }
5672: else {
5673: formname.phase.value = prevphase;
5674: }
5675: if (typeof prevstate == 'undefined') {
5676: formname.currstate.value = '';
5677: }
5678: else {
5679: formname.currstate.value = prevstate;
5680: }
1.160 raeburn 5681: formname.submit();
5682: }
5683: |;
5684: return ($jsback,\%elements);
5685: }
5686:
1.26 matthew 5687: sub course_level_table {
1.89 raeburn 5688: my (%inccourses) = @_;
1.26 matthew 5689: my $table = '';
1.62 www 5690: # Custom Roles?
5691:
1.190 raeburn 5692: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 5693: my %lt=&Apache::lonlocal::texthash(
5694: 'exs' => "Existing sections",
5695: 'new' => "Define new section",
5696: 'ssd' => "Set Start Date",
5697: 'sed' => "Set End Date",
1.131 raeburn 5698: 'crl' => "Course Level",
1.89 raeburn 5699: 'act' => "Activate",
5700: 'rol' => "Role",
5701: 'ext' => "Extent",
1.113 raeburn 5702: 'grs' => "Section",
1.89 raeburn 5703: 'sta' => "Start",
5704: 'end' => "End"
5705: );
1.62 www 5706:
1.135 raeburn 5707: foreach my $protectedcourse (sort( keys(%inccourses))) {
5708: my $thiscourse=$protectedcourse;
1.26 matthew 5709: $thiscourse=~s:_:/:g;
5710: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
5711: my $area=$coursedata{'description'};
1.295.2.19 raeburn 5712: my $crstype=$coursedata{'type'};
1.135 raeburn 5713: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 5714: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 5715: my %sections_count;
1.101 albertel 5716: if (defined($env{'request.course.id'})) {
5717: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 5718: %sections_count =
5719: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 5720: }
5721: }
1.295.2.21 raeburn 5722: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 5723: foreach my $role (@roles) {
1.295.2.18 raeburn 5724: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.135 raeburn 5725: if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
1.221 raeburn 5726: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5727: $plrole,\%sections_count,\%lt);
5728: } elsif ($env{'request.course.sec'} ne '') {
5729: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
5730: $env{'request.course.sec'})) {
5731: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5732: $plrole,\%sections_count,\%lt);
1.26 matthew 5733: }
5734: }
5735: }
1.221 raeburn 5736: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
5737: foreach my $cust (sort keys %customroles) {
5738: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
5739: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5740: $cust,\%sections_count,\%lt);
5741: }
1.62 www 5742: }
1.26 matthew 5743: }
5744: return '' if ($table eq ''); # return nothing if there is nothing
5745: # in the table
1.188 raeburn 5746: my $result;
5747: if (!$env{'request.course.id'}) {
5748: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
5749: }
5750: $result .=
1.136 raeburn 5751: &Apache::loncommon::start_data_table().
5752: &Apache::loncommon::start_data_table_header_row().
5753: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
5754: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
5755: &Apache::loncommon::end_data_table_header_row().
5756: $table.
5757: &Apache::loncommon::end_data_table();
1.26 matthew 5758: return $result;
5759: }
1.88 raeburn 5760:
1.221 raeburn 5761: sub course_level_row {
5762: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_;
1.222 raeburn 5763: my $row = &Apache::loncommon::start_data_table_row().
5764: ' <td><input type="checkbox" name="act_'.
5765: $protectedcourse.'_'.$role.'" /></td>'."\n".
5766: ' <td>'.$plrole.'</td>'."\n".
5767: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.295.2.22! raeburn 5768: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 5769: $row .= '<td> </td>';
1.221 raeburn 5770: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 5771: $row .= ' <td><input type="hidden" value="'.
5772: $env{'request.course.sec'}.'" '.
5773: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
5774: $env{'request.course.sec'}.'</td>';
1.221 raeburn 5775: } else {
5776: if (ref($sections_count) eq 'HASH') {
5777: my $currsec =
5778: &Apache::lonuserutils::course_sections($sections_count,
5779: $protectedcourse.'_'.$role);
1.222 raeburn 5780: $row .= '<td><table class="LC_createuser">'."\n".
5781: '<tr class="LC_section_row">'."\n".
5782: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
5783: $currsec.'</td>'."\n".
5784: ' <td> </td>'."\n".
5785: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 5786: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
5787: '" value="" />'.
5788: '<input type="hidden" '.
5789: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 5790: '</tr></table></td>'."\n";
1.221 raeburn 5791: } else {
1.222 raeburn 5792: $row .= '<td><input type="text" size="10" '.
5793: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 5794: }
5795: }
1.222 raeburn 5796: $row .= <<ENDTIMEENTRY;
5797: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 5798: <a href=
5799: "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 5800: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 5801: <a href=
5802: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
5803: ENDTIMEENTRY
1.222 raeburn 5804: $row .= &Apache::loncommon::end_data_table_row();
5805: return $row;
1.221 raeburn 5806: }
5807:
1.88 raeburn 5808: sub course_level_dc {
5809: my ($dcdom) = @_;
1.190 raeburn 5810: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 5811: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 5812: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
5813: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 5814: '<input type="hidden" name="dccourse" value="" />';
1.88 raeburn 5815: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.131 raeburn 5816: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
1.295.2.19 raeburn 5817: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser');
1.88 raeburn 5818: my %lt=&Apache::lonlocal::texthash(
5819: 'rol' => "Role",
1.113 raeburn 5820: 'grs' => "Section",
1.88 raeburn 5821: 'exs' => "Existing sections",
5822: 'new' => "Define new section",
5823: 'sta' => "Start",
5824: 'end' => "End",
5825: 'ssd' => "Set Start Date",
5826: 'sed' => "Set End Date"
5827: );
1.131 raeburn 5828: my $header = '<h4>'.&mt('Course Level').'</h4>'.
1.136 raeburn 5829: &Apache::loncommon::start_data_table().
5830: &Apache::loncommon::start_data_table_header_row().
1.143 raeburn 5831: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 5832: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 5833: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.295.2.4 raeburn 5834: '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1.88 raeburn 5835: '<td><select name="role">'."\n";
1.213 raeburn 5836: foreach my $role (@roles) {
1.135 raeburn 5837: my $plrole=&Apache::lonnet::plaintext($role);
5838: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 5839: }
5840: if ( keys %customroles > 0) {
1.135 raeburn 5841: foreach my $cust (sort keys %customroles) {
1.101 albertel 5842: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 5843: '_'.$env{'user.name'}.'_'.$cust;
5844: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 5845: }
5846: }
5847: $otheritems .= '</select></td><td>'.
5848: '<table border="0" cellspacing="0" cellpadding="0">'.
5849: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
5850: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
5851: '<td> </td>'.
5852: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 5853: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 5854: '<input type="hidden" name="section" value="" />'.
1.113 raeburn 5855: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 5856: '</tr></table></td>';
5857: $otheritems .= <<ENDTIMEENTRY;
1.169 albertel 5858: <td><input type="hidden" name="start" value='' />
1.88 raeburn 5859: <a href=
5860: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 5861: <td><input type="hidden" name="end" value='' />
1.88 raeburn 5862: <a href=
5863: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
5864: ENDTIMEENTRY
1.136 raeburn 5865: $otheritems .= &Apache::loncommon::end_data_table_row().
5866: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 5867: return $cb_jscript.$header.$hiddenitems.$otheritems;
5868: }
5869:
1.237 raeburn 5870: sub update_selfenroll_config {
1.241 raeburn 5871: my ($r,$context,$permission) = @_;
1.237 raeburn 5872: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 5873: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 5874: my (%changes,%warning);
5875: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5876: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 5877: my $curr_types;
1.237 raeburn 5878: if (ref($row) eq 'ARRAY') {
5879: foreach my $item (@{$row}) {
5880: if ($item eq 'enroll_dates') {
5881: my (%currenrolldate,%newenrolldate);
5882: foreach my $type ('start','end') {
5883: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
5884: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
5885: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
5886: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
5887: }
5888: }
5889: } elsif ($item eq 'access_dates') {
5890: my (%currdate,%newdate);
5891: foreach my $type ('start','end') {
5892: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
5893: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
5894: if ($newdate{$type} ne $currdate{$type}) {
5895: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
5896: }
5897: }
1.241 raeburn 5898: } elsif ($item eq 'types') {
5899: $curr_types =
5900: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
5901: if ($env{'form.selfenroll_all'}) {
5902: if ($curr_types ne '*') {
5903: $changes{'internal.selfenroll_types'} = '*';
5904: } else {
5905: next;
5906: }
5907: } else {
1.249 raeburn 5908: my %currdoms;
1.241 raeburn 5909: my @entries = split(/;/,$curr_types);
5910: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 5911: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 5912: my $newnum = 0;
1.249 raeburn 5913: my @latesttypes;
5914: foreach my $num (@activations) {
5915: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
5916: if (@types > 0) {
1.241 raeburn 5917: @types = sort(@types);
5918: my $typestr = join(',',@types);
1.249 raeburn 5919: my $typedom = $env{'form.selfenroll_dom_'.$num};
5920: $latesttypes[$newnum] = $typedom.':'.$typestr;
5921: $currdoms{$typedom} = 1;
1.241 raeburn 5922: $newnum ++;
5923: }
5924: }
1.249 raeburn 5925: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) { if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
5926: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
5927: if (@types > 0) {
5928: @types = sort(@types);
5929: my $typestr = join(',',@types);
5930: my $typedom = $env{'form.selfenroll_dom_'.$j};
5931: $latesttypes[$newnum] = $typedom.':'.$typestr;
5932: $currdoms{$typedom} = 1;
5933: $newnum ++;
5934: }
5935: }
5936: }
5937: if ($env{'form.selfenroll_newdom'} ne '') {
5938: my $typedom = $env{'form.selfenroll_newdom'};
5939: if ((!defined($currdoms{$typedom})) &&
5940: (&Apache::lonnet::domain($typedom) ne '')) {
5941: my $typestr;
5942: my ($othertitle,$usertypes,$types) =
5943: &Apache::loncommon::sorted_inst_types($typedom);
5944: my $othervalue = 'any';
5945: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5946: if (@{$types} > 0) {
1.257 raeburn 5947: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 5948: $othervalue = 'other';
1.258 raeburn 5949: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 5950: }
5951: $typestr = $othervalue;
5952: } else {
5953: $typestr = $othervalue;
5954: }
5955: $latesttypes[$newnum] = $typedom.':'.$typestr;
5956: $newnum ++ ;
5957: }
5958: }
1.241 raeburn 5959: my $selfenroll_types = join(';',@latesttypes);
5960: if ($selfenroll_types ne $curr_types) {
5961: $changes{'internal.selfenroll_types'} = $selfenroll_types;
5962: }
5963: }
1.276 raeburn 5964: } elsif ($item eq 'limit') {
5965: my $newlimit = $env{'form.selfenroll_limit'};
5966: my $newcap = $env{'form.selfenroll_cap'};
5967: $newcap =~s/\s+//g;
5968: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
5969: $currlimit = 'none' if ($currlimit eq '');
5970: my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
5971: if ($newlimit ne $currlimit) {
5972: if ($newlimit ne 'none') {
5973: if ($newcap =~ /^\d+$/) {
5974: if ($newcap ne $currcap) {
5975: $changes{'internal.selfenroll_cap'} = $newcap;
5976: }
5977: $changes{'internal.selfenroll_limit'} = $newlimit;
5978: } else {
5979: $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.');
5980: }
5981: } elsif ($currcap ne '') {
5982: $changes{'internal.selfenroll_cap'} = '';
5983: $changes{'internal.selfenroll_limit'} = $newlimit;
5984: }
5985: } elsif ($currlimit ne 'none') {
5986: if ($newcap =~ /^\d+$/) {
5987: if ($newcap ne $currcap) {
5988: $changes{'internal.selfenroll_cap'} = $newcap;
5989: }
5990: } else {
5991: $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.');
5992: }
5993: }
5994: } elsif ($item eq 'approval') {
5995: my (@currnotified,@newnotified);
5996: my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
5997: my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
5998: if ($currnotifylist ne '') {
5999: @currnotified = split(/,/,$currnotifylist);
6000: @currnotified = sort(@currnotified);
6001: }
6002: my $newapproval = $env{'form.selfenroll_approval'};
6003: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
6004: @newnotified = sort(@newnotified);
6005: if ($newapproval ne $currapproval) {
6006: $changes{'internal.selfenroll_approval'} = $newapproval;
6007: if (!$newapproval) {
6008: if ($currnotifylist ne '') {
6009: $changes{'internal.selfenroll_notifylist'} = '';
6010: }
6011: } else {
6012: my @differences =
1.295 raeburn 6013: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 6014: if (@differences > 0) {
6015: if (@newnotified > 0) {
6016: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6017: } else {
6018: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6019: }
6020: }
6021: }
6022: } else {
1.295 raeburn 6023: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 6024: if (@differences > 0) {
6025: if (@newnotified > 0) {
6026: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6027: } else {
6028: $changes{'internal.selfenroll_notifylist'} = '';
6029: }
6030: }
6031: }
1.237 raeburn 6032: } else {
6033: my $curr_val =
6034: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
6035: my $newval = $env{'form.selfenroll_'.$item};
6036: if ($item eq 'section') {
6037: $newval = $env{'form.sections'};
1.241 raeburn 6038: if (defined($curr_groups{$newval})) {
1.237 raeburn 6039: $newval = $curr_val;
6040: $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');
6041: } elsif ($newval eq 'all') {
6042: $newval = $curr_val;
1.274 bisitz 6043: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 6044: }
6045: if ($newval eq '') {
6046: $newval = 'none';
6047: }
6048: }
6049: if ($newval ne $curr_val) {
6050: $changes{'internal.selfenroll_'.$item} = $newval;
6051: }
1.241 raeburn 6052: }
1.237 raeburn 6053: }
6054: if (keys(%warning) > 0) {
6055: foreach my $item (@{$row}) {
6056: if (exists($warning{$item})) {
6057: $r->print($warning{$item}.'<br />');
6058: }
6059: }
6060: }
6061: if (keys(%changes) > 0) {
6062: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
6063: if ($putresult eq 'ok') {
6064: if ((exists($changes{'internal.selfenroll_types'})) ||
6065: (exists($changes{'internal.selfenroll_start_date'})) ||
6066: (exists($changes{'internal.selfenroll_end_date'}))) {
6067: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
6068: $cnum,undef,undef,'Course');
6069: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
6070: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
6071: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
6072: if (exists($changes{'internal.'.$item})) {
6073: $crsinfo{$env{'request.course.id'}}{$item} =
6074: $changes{'internal.'.$item};
6075: }
6076: }
6077: my $crsputresult =
6078: &Apache::lonnet::courseidput($cdom,\%crsinfo,
6079: $chome,'notime');
6080: }
6081: }
6082: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
6083: foreach my $item (@{$row}) {
6084: my $title = $item;
6085: if (ref($lt) eq 'HASH') {
6086: $title = $lt->{$item};
6087: }
6088: if ($item eq 'enroll_dates') {
6089: foreach my $type ('start','end') {
6090: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
6091: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 6092: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 6093: $title,$type,$newdate).'</li>');
6094: }
6095: }
6096: } elsif ($item eq 'access_dates') {
6097: foreach my $type ('start','end') {
6098: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
6099: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 6100: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 6101: $title,$type,$newdate).'</li>');
6102: }
6103: }
1.276 raeburn 6104: } elsif ($item eq 'limit') {
6105: if ((exists($changes{'internal.selfenroll_limit'})) ||
6106: (exists($changes{'internal.selfenroll_cap'}))) {
6107: my ($newval,$newcap);
6108: if ($changes{'internal.selfenroll_cap'} ne '') {
6109: $newcap = $changes{'internal.selfenroll_cap'}
6110: } else {
6111: $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
6112: }
6113: if ($changes{'internal.selfenroll_limit'} eq 'none') {
6114: $newval = &mt('No limit');
6115: } elsif ($changes{'internal.selfenroll_limit'} eq
6116: 'allstudents') {
6117: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
6118: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
6119: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
6120: } else {
6121: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
6122: if ($currlimit eq 'allstudents') {
6123: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
6124: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.295.2.9 raeburn 6125: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 6126: }
6127: }
6128: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
6129: }
6130: } elsif ($item eq 'approval') {
6131: if ((exists($changes{'internal.selfenroll_approval'})) ||
6132: (exists($changes{'internal.selfenroll_notifylist'}))) {
6133: my ($newval,$newnotify);
6134: if (exists($changes{'internal.selfenroll_notifylist'})) {
6135: $newnotify = $changes{'internal.selfenroll_notifylist'};
6136: } else {
6137: $newnotify = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
6138: }
6139: if ($changes{'internal.selfenroll_approval'}) {
6140: $newval = &mt('Yes');
6141: } elsif ($changes{'internal.selfenroll_approval'} eq '0') {
6142: $newval = &mt('No');
6143: } else {
6144: my $currapproval =
6145: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
6146: if ($currapproval) {
6147: $newval = &mt('Yes');
6148: } else {
6149: $newval = &mt('No');
6150: }
6151: }
6152: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
6153: if ($newnotify) {
1.277 raeburn 6154: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 6155: } else {
1.277 raeburn 6156: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 6157: }
6158: $r->print('</li>'."\n");
6159: }
1.237 raeburn 6160: } else {
6161: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 6162: my $newval = $changes{'internal.selfenroll_'.$item};
6163: if ($item eq 'types') {
6164: if ($newval eq '') {
6165: $newval = &mt('None');
6166: } elsif ($newval eq '*') {
6167: $newval = &mt('Any user in any domain');
6168: }
1.245 raeburn 6169: } elsif ($item eq 'registered') {
6170: if ($newval eq '1') {
6171: $newval = &mt('Yes');
6172: } elsif ($newval eq '0') {
6173: $newval = &mt('No');
6174: }
1.241 raeburn 6175: }
1.244 bisitz 6176: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 6177: }
6178: }
6179: }
6180: $r->print('</ul>');
6181: my %newenvhash;
6182: foreach my $key (keys(%changes)) {
6183: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
6184: }
1.238 raeburn 6185: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 6186: } else {
6187: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
6188: }
6189: } else {
1.249 raeburn 6190: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 6191: }
6192: } else {
1.249 raeburn 6193: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 6194: }
1.256 raeburn 6195: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
6196: if (ref($visactions) eq 'HASH') {
6197: if (!$visible) {
6198: $r->print('<br />'.$visactions->{'miss'}.'<br />'.$visactions->{'yous'}.
6199: '<br />');
6200: if (ref($vismsgs) eq 'ARRAY') {
6201: $r->print('<br />'.$visactions->{'take'}.'<ul>');
6202: foreach my $item (@{$vismsgs}) {
6203: $r->print('<li>'.$visactions->{$item}.'</li>');
6204: }
6205: $r->print('</ul>');
6206: }
6207: $r->print($cansetvis);
6208: }
6209: }
1.237 raeburn 6210: return;
6211: }
6212:
6213: sub get_selfenroll_titles {
1.276 raeburn 6214: my @row = ('types','registered','enroll_dates','access_dates','section',
6215: 'approval','limit');
1.237 raeburn 6216: my %lt = &Apache::lonlocal::texthash (
6217: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 6218: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 6219: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 6220: access_dates => 'Course access dates assigned to self-enrolling users',
6221: section => 'Section assigned to self-enrolling users',
1.276 raeburn 6222: approval => 'Self-enrollment requests need approval?',
6223: limit => 'Enrollment limit',
1.237 raeburn 6224: );
6225: return (\@row,\%lt);
6226: }
6227:
1.27 matthew 6228: #---------------------------------------------- end functions for &phase_two
1.29 matthew 6229:
6230: #--------------------------------- functions for &phase_two and &phase_three
6231:
6232: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 6233:
6234: 1;
6235: __END__
1.2 www 6236:
6237:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>