Annotation of loncom/interface/loncreateuser.pm, revision 1.295.2.21
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.295.2.21! raeburn 4: # $Id: loncreateuser.pm,v 1.295.2.20 2010/01/19 20:31:37 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) = @_;
4274: my $formname = 'enrollstudent';
4275: my $nolink = 1;
4276: my ($row,$lt) = &get_selfenroll_titles();
4277: my $groupslist = &Apache::lonuserutils::get_groupslist();
4278: my $setsec_js =
4279: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 4280: my %alerts = &Apache::lonlocal::texthash(
4281: acto => 'Activation of self-enrollment was selected for the following domain(s)',
4282: butn => 'but no user types have been checked.',
4283: wilf => "Please uncheck 'activate' or check at least one type.",
4284: );
4285: my $selfenroll_js = <<"ENDSCRIPT";
4286: function update_types(caller,num) {
4287: var delidx = getIndexByName('selfenroll_delete');
4288: var actidx = getIndexByName('selfenroll_activate');
4289: if (caller == 'selfenroll_all') {
4290: var selall;
4291: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4292: if (document.$formname.selfenroll_all[i].checked) {
4293: selall = document.$formname.selfenroll_all[i].value;
4294: }
4295: }
4296: if (selall == 1) {
4297: if (delidx != -1) {
4298: if (document.$formname.selfenroll_delete.length) {
4299: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
4300: document.$formname.selfenroll_delete[j].checked = true;
4301: }
4302: } else {
4303: document.$formname.elements[delidx].checked = true;
4304: }
4305: }
4306: if (actidx != -1) {
4307: if (document.$formname.selfenroll_activate.length) {
4308: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4309: document.$formname.selfenroll_activate[j].checked = false;
4310: }
4311: } else {
4312: document.$formname.elements[actidx].checked = false;
4313: }
4314: }
4315: document.$formname.selfenroll_newdom.selectedIndex = 0;
4316: }
4317: }
4318: if (caller == 'selfenroll_activate') {
4319: if (document.$formname.selfenroll_activate.length) {
4320: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4321: if (document.$formname.selfenroll_activate[j].value == num) {
4322: if (document.$formname.selfenroll_activate[j].checked) {
4323: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4324: if (document.$formname.selfenroll_all[i].value == '1') {
4325: document.$formname.selfenroll_all[i].checked = false;
4326: }
4327: if (document.$formname.selfenroll_all[i].value == '0') {
4328: document.$formname.selfenroll_all[i].checked = true;
4329: }
4330: }
4331: }
4332: }
4333: }
4334: } else {
4335: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
4336: if (document.$formname.selfenroll_all[i].value == '1') {
4337: document.$formname.selfenroll_all[i].checked = false;
4338: }
4339: if (document.$formname.selfenroll_all[i].value == '0') {
4340: document.$formname.selfenroll_all[i].checked = true;
4341: }
4342: }
4343: }
4344: }
4345: if (caller == 'selfenroll_delete') {
4346: if (document.$formname.selfenroll_delete.length) {
4347: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
4348: if (document.$formname.selfenroll_delete[j].value == num) {
4349: if (document.$formname.selfenroll_delete[j].checked) {
4350: var delindex = getIndexByName('selfenroll_types_'+num);
4351: if (delindex != -1) {
4352: if (document.$formname.elements[delindex].length) {
4353: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
4354: document.$formname.elements[delindex][k].checked = false;
4355: }
4356: } else {
4357: document.$formname.elements[delindex].checked = false;
4358: }
4359: }
4360: }
4361: }
4362: }
4363: } else {
4364: if (document.$formname.selfenroll_delete.checked) {
4365: var delindex = getIndexByName('selfenroll_types_'+num);
4366: if (delindex != -1) {
4367: if (document.$formname.elements[delindex].length) {
4368: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
4369: document.$formname.elements[delindex][k].checked = false;
4370: }
4371: } else {
4372: document.$formname.elements[delindex].checked = false;
4373: }
4374: }
4375: }
4376: }
4377: }
4378: return;
4379: }
4380:
4381: function validate_types(form) {
4382: var needaction = new Array();
4383: var countfail = 0;
4384: var actidx = getIndexByName('selfenroll_activate');
4385: if (actidx != -1) {
4386: if (document.$formname.selfenroll_activate.length) {
4387: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
4388: var num = document.$formname.selfenroll_activate[j].value;
4389: if (document.$formname.selfenroll_activate[j].checked) {
4390: countfail = check_types(num,countfail,needaction)
4391: }
4392: }
4393: } else {
4394: if (document.$formname.selfenroll_activate.checked) {
4395: var num = document.enrollstudent.selfenroll_activate.value;
4396: countfail = check_types(num,countfail,needaction)
4397: }
4398: }
4399: }
4400: if (countfail > 0) {
4401: var msg = "$alerts{'acto'}\\n";
4402: var loopend = needaction.length -1;
4403: if (loopend > 0) {
4404: for (var m=0; m<loopend; m++) {
4405: msg += needaction[m]+", ";
4406: }
4407: }
4408: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
4409: alert(msg);
4410: return;
4411: }
4412: setSections(form);
4413: }
4414:
4415: function check_types(num,countfail,needaction) {
4416: var typeidx = getIndexByName('selfenroll_types_'+num);
4417: var count = 0;
4418: if (typeidx != -1) {
4419: if (document.$formname.elements[typeidx].length) {
4420: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
4421: if (document.$formname.elements[typeidx][k].checked) {
4422: count ++;
4423: }
4424: }
4425: } else {
4426: if (document.$formname.elements[typeidx].checked) {
4427: count ++;
4428: }
4429: }
4430: if (count == 0) {
4431: var domidx = getIndexByName('selfenroll_dom_'+num);
4432: if (domidx != -1) {
4433: var domname = document.$formname.elements[domidx].value;
4434: needaction[countfail] = domname;
4435: countfail ++;
4436: }
4437: }
4438: }
4439: return countfail;
4440: }
4441:
4442: function getIndexByName(item) {
4443: for (var i=0;i<document.$formname.elements.length;i++) {
4444: if (document.$formname.elements[i].name == item) {
4445: return i;
4446: }
4447: }
4448: return -1;
4449: }
4450: ENDSCRIPT
1.256 raeburn 4451: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4452: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4453:
1.237 raeburn 4454: my $output = '<script type="text/javascript">'."\n".
1.295.2.4 raeburn 4455: '// <![CDATA['."\n".
1.249 raeburn 4456: $setsec_js."\n".$selfenroll_js."\n".
1.295.2.4 raeburn 4457: '// ]]>'."\n".
1.237 raeburn 4458: '</script>'."\n".
1.256 raeburn 4459: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
4460: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
4461: if (ref($visactions) eq 'HASH') {
4462: if ($visible) {
1.283 bisitz 4463: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
1.256 raeburn 4464: } else {
1.283 bisitz 4465: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
4466: .$visactions->{'yous'}.
1.256 raeburn 4467: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
4468: if (ref($vismsgs) eq 'ARRAY') {
4469: $output .= '<br />'.$visactions->{'make'}.'<ul>';
4470: foreach my $item (@{$vismsgs}) {
4471: $output .= '<li>'.$visactions->{$item}.'</li>';
4472: }
4473: $output .= '</ul>';
4474: }
4475: $output .= '</p>';
4476: }
4477: }
4478: $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
4479: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 4480: if (ref($row) eq 'ARRAY') {
4481: foreach my $item (@{$row}) {
4482: my $title = $item;
4483: if (ref($lt) eq 'HASH') {
4484: $title = $lt->{$item};
4485: }
4486: $output .=
4487: &Apache::lonhtmlcommon::row_title($title,
4488: 'LC_selfenroll_pick_box_title','LC_oddrow_value')."\n";
4489: if ($item eq 'types') {
4490: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 4491: my $showdomdesc = 1;
4492: my $includeempty = 1;
4493: my $num = 0;
4494: $output .= &Apache::loncommon::start_data_table().
4495: &Apache::loncommon::start_data_table_row()
4496: .'<td colspan="2"><span class="LC_nobreak"><label>'
4497: .&mt('Any user in any domain:')
4498: .' <input type="radio" name="selfenroll_all" value="1" ';
4499: if ($curr_types eq '*') {
4500: $output .= ' checked="checked" ';
4501: }
1.249 raeburn 4502: $output .= 'onchange="javascript:update_types('.
4503: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
4504: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 4505: if ($curr_types ne '*') {
4506: $output .= ' checked="checked" ';
4507: }
1.249 raeburn 4508: $output .= ' onchange="javascript:update_types('.
4509: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
4510: &Apache::loncommon::end_data_table_row().
4511: &Apache::loncommon::end_data_table().
4512: &mt('Or').'<br />'.
4513: &Apache::loncommon::start_data_table();
1.241 raeburn 4514: my %currdoms;
1.249 raeburn 4515: if ($curr_types eq '') {
1.241 raeburn 4516: $output .= &new_selfenroll_dom_row($cdom,'0');
4517: } elsif ($curr_types ne '*') {
4518: my @entries = split(/;/,$curr_types);
4519: if (@entries > 0) {
4520: foreach my $entry (@entries) {
4521: my ($currdom,$typestr) = split(/:/,$entry);
4522: $currdoms{$currdom} = 1;
4523: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 4524: my @currinsttypes = split(',',$typestr);
1.241 raeburn 4525: $output .= &Apache::loncommon::start_data_table_row()
4526: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
4527: .' '.$domdesc.' ('.$currdom.')'
4528: .'</b><input type="hidden" name="selfenroll_dom_'.$num
4529: .'" value="'.$currdom.'" /></span><br />'
4530: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 4531: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 4532: .&mt('Delete').'</label></span></td>';
1.249 raeburn 4533: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 4534: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
4535: .&Apache::loncommon::end_data_table_row();
4536: $num ++;
4537: }
4538: }
4539: }
1.249 raeburn 4540: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 4541: if ($curr_types eq '*') {
1.249 raeburn 4542: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 4543: } elsif ($curr_types eq '') {
1.249 raeburn 4544: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 4545: }
4546: $output .= &Apache::loncommon::start_data_table_row()
4547: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
4548: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
4549: $includeempty,$showdomdesc)
4550: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
4551: .'</td>'.&Apache::loncommon::end_data_table_row()
4552: .&Apache::loncommon::end_data_table();
1.237 raeburn 4553: } elsif ($item eq 'registered') {
4554: my ($regon,$regoff);
4555: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
4556: $regon = ' checked="checked" ';
4557: $regoff = ' ';
4558: } else {
4559: $regon = ' ';
4560: $regoff = ' checked="checked" ';
4561: }
4562: $output .= '<label>'.
1.245 raeburn 4563: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 4564: &mt('Yes').'</label> <label>'.
1.245 raeburn 4565: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 4566: &mt('No').'</label>';
1.237 raeburn 4567: } elsif ($item eq 'enroll_dates') {
4568: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
4569: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
4570: if ($starttime eq '') {
4571: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
4572: }
4573: if ($endtime eq '') {
4574: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
4575: }
4576: my $startform =
4577: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
4578: undef,undef,undef,undef,undef,undef,undef,$nolink);
4579: my $endform =
4580: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
4581: undef,undef,undef,undef,undef,undef,undef,$nolink);
4582: $output .= &selfenroll_date_forms($startform,$endform);
4583: } elsif ($item eq 'access_dates') {
4584: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
4585: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
4586: if ($starttime eq '') {
4587: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
4588: }
4589: if ($endtime eq '') {
4590: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
4591: }
4592: my $startform =
4593: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
4594: undef,undef,undef,undef,undef,undef,undef,$nolink);
4595: my $endform =
4596: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
4597: undef,undef,undef,undef,undef,undef,undef,$nolink);
4598: $output .= &selfenroll_date_forms($startform,$endform);
4599: } elsif ($item eq 'section') {
4600: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
4601: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
4602: my $newsecval;
4603: if ($currsec ne 'none' && $currsec ne '') {
4604: if (!defined($sections_count{$currsec})) {
4605: $newsecval = $currsec;
4606: }
4607: }
4608: my $sections_select =
4609: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
4610: $output .= '<table class="LC_createuser">'."\n".
4611: '<tr class="LC_section_row">'."\n".
4612: '<td align="center">'.&mt('Existing sections')."\n".
4613: '<br />'.$sections_select.'</td><td align="center">'.
4614: &mt('New section').'<br />'."\n".
4615: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
4616: '<input type="hidden" name="sections" value="" />'."\n".
4617: '<input type="hidden" name="state" value="done" />'."\n".
4618: '</td></tr></table>'."\n";
1.276 raeburn 4619: } elsif ($item eq 'approval') {
4620: my ($appon,$appoff);
4621: my $cid = $env{'request.course.id'};
4622: my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
4623: if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) {
4624: $appon = ' checked="checked" ';
4625: $appoff = ' ';
4626: } else {
4627: $appon = ' ';
4628: $appoff = ' checked="checked" ';
4629: }
4630: $output .= '<label>'.
4631: '<input type="radio" name="selfenroll_approval" value="1"'.$appon.'/>'.
4632: &mt('Yes').'</label> <label>'.
4633: '<input type="radio" name="selfenroll_approval" value="0"'.$appoff.'/>'.
4634: &mt('No').'</label>';
4635: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
4636: my (@ccs,%notified);
4637: if ($advhash{'cc'}) {
4638: @ccs = split(/,/,$advhash{'cc'});
4639: }
4640: if ($currnotified) {
4641: foreach my $current (split(/,/,$currnotified)) {
4642: $notified{$current} = 1;
4643: if (!grep(/^\Q$current\E$/,@ccs)) {
4644: push(@ccs,$current);
4645: }
4646: }
4647: }
4648: if (@ccs) {
1.277 raeburn 4649: $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 4650: &Apache::loncommon::start_data_table_row();
4651: my $count = 0;
4652: my $numcols = 4;
4653: foreach my $cc (sort(@ccs)) {
4654: my $notifyon;
4655: my ($ccuname,$ccudom) = split(/:/,$cc);
4656: if ($notified{$cc}) {
4657: $notifyon = ' checked="checked" ';
4658: }
4659: if ($count && !$count%$numcols) {
4660: $output .= &Apache::loncommon::end_data_table_row().
4661: &Apache::loncommon::start_data_table_row()
4662: }
4663: $output .= '<td><span class="LC_nobreak"><label>'.
4664: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
4665: &Apache::loncommon::plainname($ccuname,$ccudom).
4666: '</label></span></td>';
4667: $count;
4668: }
4669: my $rem = $count%$numcols;
4670: if ($rem) {
4671: my $emptycols = $numcols - $rem;
4672: for (my $i=0; $i<$emptycols; $i++) {
4673: $output .= '<td> </td>';
4674: }
4675: }
4676: $output .= &Apache::loncommon::end_data_table_row().
4677: &Apache::loncommon::end_data_table();
4678: }
4679: } elsif ($item eq 'limit') {
4680: my ($crslimit,$selflimit,$nolimit);
4681: my $cid = $env{'request.course.id'};
4682: my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'};
4683: my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
4684: my $nolimit = ' checked="checked" ';
4685: if ($currlim eq 'allstudents') {
4686: $crslimit = ' checked="checked" ';
4687: $selflimit = ' ';
4688: $nolimit = ' ';
4689: } elsif ($currlim eq 'selfenrolled') {
4690: $crslimit = ' ';
4691: $selflimit = ' checked="checked" ';
4692: $nolimit = ' ';
4693: } else {
4694: $crslimit = ' ';
4695: $selflimit = ' ';
4696: }
4697: $output .= '<table><tr><td><label>'.
1.278 raeburn 4698: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 4699: &mt('No limit').'</label></td><td><label>'.
4700: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
4701: &mt('Limit by total students').'</label></td><td><label>'.
4702: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
4703: &mt('Limit by total self-enrolled students').
4704: '</td></tr><tr>'.
4705: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
4706: (' 'x3).&mt('Maximum number allowed: ').
4707: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 4708: }
4709: $output .= &Apache::lonhtmlcommon::row_closure(1);
4710: }
4711: }
4712: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 4713: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 4714: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.241 raeburn 4715: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 4716: $r->print($output);
4717: return;
4718: }
4719:
1.256 raeburn 4720: sub visible_in_cat {
4721: my ($cdom,$cnum) = @_;
4722: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
4723: my ($cathash,%settable,@vismsgs,$cansetvis);
4724: my %visactions = &Apache::lonlocal::texthash(
1.295.2.17 raeburn 4725: vis => 'Your course/community currently appears in the Course/Community Catalog for this domain.',
1.256 raeburn 4726: 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 4727: miss => 'Your course/community does not currently appear in the Course/Community Catalog for this domain.',
1.256 raeburn 4728: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
4729: 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 4730: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
1.256 raeburn 4731: take => 'Take the following action to ensure the course appears in the Catalog:',
4732: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
4733: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
4734: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
4735: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
4736: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
4737: 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',
4738: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
4739: );
1.261 raeburn 4740: $visactions{'unhide'} = &mt('Use [_1]Set course environment[_2] to change the "Exclude from course catalog" setting.','"<a href="/adm/parmset?action=crsenv">','</a>"');
4741: $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>"');
4742: $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 4743: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4744: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
4745: $settable{'togglecats'} = 1;
4746: }
4747: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
4748: $settable{'categorize'} = 1;
4749: }
4750: $cathash = $domconf{'coursecategories'}{'cats'};
4751: }
1.260 raeburn 4752: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 4753: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
4754: } elsif ($settable{'togglecats'}) {
4755: $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 4756: } elsif ($settable{'categorize'}) {
1.256 raeburn 4757: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
4758: } else {
4759: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
4760: }
4761:
4762: my %currsettings =
4763: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
4764: $cdom,$cnum);
4765: my $visible = 0;
4766: if ($currsettings{'internal.coursecode'} ne '') {
4767: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4768: $cathash = $domconf{'coursecategories'}{'cats'};
4769: if (ref($cathash) eq 'HASH') {
4770: if ($cathash->{'instcode::0'} eq '') {
4771: push(@vismsgs,'dc_addinst');
4772: } else {
4773: $visible = 1;
4774: }
4775: } else {
4776: $visible = 1;
4777: }
4778: } else {
4779: $visible = 1;
4780: }
4781: } else {
4782: if (ref($cathash) eq 'HASH') {
4783: if ($cathash->{'instcode::0'} ne '') {
4784: push(@vismsgs,'dc_instcode');
4785: }
4786: } else {
4787: push(@vismsgs,'dc_instcode');
4788: }
4789: }
4790: if ($currsettings{'categories'} ne '') {
4791: my $cathash;
4792: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4793: $cathash = $domconf{'coursecategories'}{'cats'};
4794: if (ref($cathash) eq 'HASH') {
4795: if (keys(%{$cathash}) == 0) {
4796: push(@vismsgs,'dc_catalog');
4797: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
4798: push(@vismsgs,'dc_categories');
4799: } else {
4800: my @currcategories = split('&',$currsettings{'categories'});
4801: my $matched = 0;
4802: foreach my $cat (@currcategories) {
4803: if ($cathash->{$cat} ne '') {
4804: $visible = 1;
4805: $matched = 1;
4806: last;
4807: }
4808: }
4809: if (!$matched) {
1.260 raeburn 4810: if ($settable{'categorize'}) {
1.256 raeburn 4811: push(@vismsgs,'chgcat');
4812: } else {
4813: push(@vismsgs,'dc_chgcat');
4814: }
4815: }
4816: }
4817: }
4818: }
4819: } else {
4820: if (ref($cathash) eq 'HASH') {
4821: if ((keys(%{$cathash}) > 1) ||
4822: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 4823: if ($settable{'categorize'}) {
1.256 raeburn 4824: push(@vismsgs,'addcat');
4825: } else {
4826: push(@vismsgs,'dc_addcat');
4827: }
4828: }
4829: }
4830: }
4831: if ($currsettings{'hidefromcat'} eq 'yes') {
4832: $visible = 0;
4833: if ($settable{'togglecats'}) {
4834: unshift(@vismsgs,'unhide');
4835: } else {
4836: unshift(@vismsgs,'dc_unhide')
4837: }
4838: }
4839: return ($visible,$cansetvis,\@vismsgs,\%visactions);
4840: }
4841:
1.241 raeburn 4842: sub new_selfenroll_dom_row {
4843: my ($newdom,$num) = @_;
4844: my $domdesc = &Apache::lonnet::domain($newdom);
4845: my $output;
4846: if ($domdesc ne '') {
4847: $output .= &Apache::loncommon::start_data_table_row()
4848: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
4849: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 4850: .'" value="'.$newdom.'" /></span><br />'
4851: .'<span class="LC_nobreak"><label><input type="checkbox" '
4852: .'name="selfenroll_activate" value="'.$num.'" '
4853: .'onchange="javascript:update_types('
4854: ."'selfenroll_activate','$num'".');" />'
4855: .&mt('Activate').'</label></span></td>';
1.241 raeburn 4856: my @currinsttypes;
4857: $output .= '<td>'.&mt('User types:').'<br />'
4858: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
4859: .&Apache::loncommon::end_data_table_row();
4860: }
4861: return $output;
4862: }
4863:
4864: sub selfenroll_inst_types {
4865: my ($num,$currdom,$currinsttypes) = @_;
4866: my $output;
4867: my $numinrow = 4;
4868: my $count = 0;
4869: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 4870: my $othervalue = 'any';
1.241 raeburn 4871: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 4872: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 4873: $othervalue = 'other';
4874: }
1.241 raeburn 4875: $output .= '<table><tr>';
4876: foreach my $type (@{$types}) {
4877: if (($count > 0) && ($count%$numinrow == 0)) {
4878: $output .= '</tr><tr>';
4879: }
4880: if (defined($usertypes->{$type})) {
1.257 raeburn 4881: my $esc_type = &escape($type);
1.241 raeburn 4882: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 4883: $esc_type.'" ';
1.241 raeburn 4884: if (ref($currinsttypes) eq 'ARRAY') {
4885: if (@{$currinsttypes} > 0) {
1.249 raeburn 4886: if (grep(/^any$/,@{$currinsttypes})) {
4887: $output .= 'checked="checked"';
1.257 raeburn 4888: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 4889: $output .= 'checked="checked"';
4890: }
1.249 raeburn 4891: } else {
4892: $output .= 'checked="checked"';
1.241 raeburn 4893: }
4894: }
4895: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
4896: }
4897: $count ++;
4898: }
4899: if (($count > 0) && ($count%$numinrow == 0)) {
4900: $output .= '</tr><tr>';
4901: }
1.249 raeburn 4902: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 4903: if (ref($currinsttypes) eq 'ARRAY') {
4904: if (@{$currinsttypes} > 0) {
1.249 raeburn 4905: if (grep(/^any$/,@{$currinsttypes})) {
4906: $output .= ' checked="checked"';
4907: } elsif ($othervalue eq 'other') {
4908: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
4909: $output .= ' checked="checked"';
4910: }
1.241 raeburn 4911: }
1.249 raeburn 4912: } else {
4913: $output .= ' checked="checked"';
1.241 raeburn 4914: }
1.249 raeburn 4915: } else {
4916: $output .= ' checked="checked"';
1.241 raeburn 4917: }
4918: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
4919: }
4920: return $output;
4921: }
4922:
1.237 raeburn 4923: sub selfenroll_date_forms {
4924: my ($startform,$endform) = @_;
4925: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 4926: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 4927: 'LC_oddrow_value')."\n".
4928: $startform."\n".
4929: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 4930: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 4931: 'LC_oddrow_value')."\n".
4932: $endform."\n".
4933: &Apache::lonhtmlcommon::row_closure(1).
4934: &Apache::lonhtmlcommon::end_pick_box();
4935: return $output;
4936: }
4937:
1.239 raeburn 4938: sub print_userchangelogs_display {
4939: my ($r,$context,$permission) = @_;
4940: my $formname = 'roleslog';
4941: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4942: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.295.2.18 raeburn 4943: my $crstype = &Apache::loncommon::course_type();
1.239 raeburn 4944: my %roleslog=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
4945: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
4946:
4947: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
4948: my %saveable_parameters = ('show' => 'scalar',);
4949: &Apache::loncommon::store_course_settings('roles_log',
4950: \%saveable_parameters);
4951: &Apache::loncommon::restore_course_settings('roles_log',
4952: \%saveable_parameters);
4953: # set defaults
4954: my $now = time();
4955: my $defstart = $now - (7*24*3600); #7 days ago
4956: my %defaults = (
4957: page => '1',
4958: show => '10',
4959: role => 'any',
4960: chgcontext => 'any',
4961: rolelog_start_date => $defstart,
4962: rolelog_end_date => $now,
4963: );
4964: my $more_records = 0;
4965:
4966: # set current
4967: my %curr;
4968: foreach my $item ('show','page','role','chgcontext') {
4969: $curr{$item} = $env{'form.'.$item};
4970: }
4971: my ($startdate,$enddate) =
4972: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
4973: $curr{'rolelog_start_date'} = $startdate;
4974: $curr{'rolelog_end_date'} = $enddate;
4975: foreach my $key (keys(%defaults)) {
4976: if ($curr{$key} eq '') {
4977: $curr{$key} = $defaults{$key};
4978: }
4979: }
1.248 raeburn 4980: my (%whodunit,%changed,$version);
4981: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.295.2.18 raeburn 4982: $r->print(&role_display_filter($formname,$cdom,$cnum,\%curr,$version,$crstype));
1.239 raeburn 4983: my $showntablehdr = 0;
4984: my $tablehdr = &Apache::loncommon::start_data_table().
4985: &Apache::loncommon::start_data_table_header_row().
4986: '<th> </th><th>'.&mt('When').'</th><th>'.&mt('Who made the change').
4987: '</th><th>'.&mt('Changed User').'</th><th>'.&mt('Role').'</th><th>'.&mt('Section').'</th><th>'.
4988: &mt('Context').'</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
4989: &Apache::loncommon::end_data_table_header_row();
4990: my ($minshown,$maxshown);
1.255 raeburn 4991: $minshown = 1;
1.239 raeburn 4992: my $count = 0;
4993: if ($curr{'show'} ne &mt('all')) {
4994: $maxshown = $curr{'page'} * $curr{'show'};
4995: if ($curr{'page'} > 1) {
4996: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
4997: }
4998: }
4999: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
5000: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
5001: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
5002: if ($curr{'show'} ne &mt('all')) {
5003: if ($count >= $curr{'page'} * $curr{'show'}) {
5004: $more_records = 1;
5005: last;
5006: }
5007: }
5008: if ($curr{'role'} ne 'any') {
5009: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
5010: }
5011: if ($curr{'chgcontext'} ne 'any') {
5012: if ($curr{'chgcontext'} eq 'selfenroll') {
5013: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
5014: } else {
5015: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
5016: }
5017: }
5018: $count ++;
5019: next if ($count < $minshown);
5020: if (!$showntablehdr) {
5021: $r->print($tablehdr);
5022: $showntablehdr = 1;
5023: }
5024: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
5025: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
5026: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
5027: }
5028: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
5029: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
5030: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
5031: }
5032: my $sec = $roleslog{$id}{'logentry'}{'section'};
5033: if ($sec eq '') {
5034: $sec = &mt('None');
5035: }
5036: my ($rolestart,$roleend);
5037: if ($roleslog{$id}{'delflag'}) {
5038: $rolestart = &mt('deleted');
5039: $roleend = &mt('deleted');
5040: } else {
5041: $rolestart = $roleslog{$id}{'logentry'}{'start'};
5042: $roleend = $roleslog{$id}{'logentry'}{'end'};
5043: if ($rolestart eq '' || $rolestart == 0) {
5044: $rolestart = &mt('No start date');
5045: } else {
5046: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
5047: }
5048: if ($roleend eq '' || $roleend == 0) {
5049: $roleend = &mt('No end date');
5050: } else {
5051: $roleend = &Apache::lonlocal::locallocaltime($roleend);
5052: }
5053: }
5054: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
5055: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
5056: $chgcontext = 'selfenroll';
5057: }
1.295.2.18 raeburn 5058: my %lt = &rolechg_contexts($crstype);
1.239 raeburn 5059: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
5060: $chgcontext = $lt{$chgcontext};
5061: }
1.295.2.18 raeburn 5062: $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 5063: }
5064: if ($showntablehdr) {
5065: $r->print(&Apache::loncommon::end_data_table().'<br />');
5066: if (($curr{'page'} > 1) || ($more_records)) {
5067: $r->print('<table><tr>');
5068: if ($curr{'page'} > 1) {
5069: $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
5070: }
5071: if ($more_records) {
5072: $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
5073: }
5074: $r->print('</tr></table>');
5075: $r->print(<<"ENDSCRIPT");
5076: <script type="text/javascript">
1.295.2.4 raeburn 5077: // <![CDATA[
1.239 raeburn 5078: function chgPage(caller) {
5079: if (caller == 'previous') {
5080: document.$formname.page.value --;
5081: }
5082: if (caller == 'next') {
5083: document.$formname.page.value ++;
5084: }
5085: document.$formname.submit();
5086: return;
5087: }
1.295.2.4 raeburn 5088: // ]]>
1.239 raeburn 5089: </script>
5090: ENDSCRIPT
5091: }
5092: } else {
1.295.2.4 raeburn 5093: $r->print('<p class="LC_info">'.
5094: &mt('There are no records to display').
5095: '</p>');
1.239 raeburn 5096: }
5097: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
5098: '<input type="hidden" name="action" value="changelogs" /></form>');
5099: return;
5100: }
5101:
5102: sub role_display_filter {
1.295.2.18 raeburn 5103: my ($formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
1.239 raeburn 5104: my $context = 'course';
1.295.2.18 raeburn 5105: my $lctype = lc($crstype);
1.239 raeburn 5106: my $nolink = 1;
5107: my $output = '<table><tr><td valign="top">'.
1.295.2.4 raeburn 5108: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 5109: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
5110: (&mt('all'),5,10,20,50,100,1000,10000)).
5111: '</td><td> </td>';
5112: my $startform =
5113: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
5114: $curr->{'rolelog_start_date'},undef,
5115: undef,undef,undef,undef,undef,undef,$nolink);
5116: my $endform =
5117: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
5118: $curr->{'rolelog_end_date'},undef,
5119: undef,undef,undef,undef,undef,undef,$nolink);
1.295.2.18 raeburn 5120: my %lt = &rolechg_contexts($crstype);
1.239 raeburn 5121: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br /><table><tr><td>'.&mt('After:').
5122: '</td><td>'.$startform.'</td></tr><tr><td>'.&mt('Before:').'</td><td>'.
5123: $endform.'</td></tr></table></td><td> </td>'.
5124: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
5125: '<select name="role"><option value="any"';
5126: if ($curr->{'role'} eq 'any') {
5127: $output .= ' selected="selected"';
5128: }
5129: $output .= '>'.&mt('Any').'</option>'."\n";
1.295.2.18 raeburn 5130: my @roles = &Apache::lonuserutils::course_roles($context,undef,1,$lctype);
1.239 raeburn 5131: foreach my $role (@roles) {
5132: my $plrole;
5133: if ($role eq 'cr') {
5134: $plrole = &mt('Custom Role');
5135: } else {
1.295.2.18 raeburn 5136: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 5137: }
5138: my $selstr = '';
5139: if ($role eq $curr->{'role'}) {
5140: $selstr = ' selected="selected"';
5141: }
5142: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
5143: }
5144: $output .= '</select></td><td> </td><td valign="top"><b>'.
5145: &mt('Context:').'</b><br /><select name="chgcontext">';
1.295.2.18 raeburn 5146: foreach my $chgtype ('any','auto','updatenow','createcourse','course','domain','selfenroll','requestcourses') {
1.239 raeburn 5147: my $selstr = '';
5148: if ($curr->{'chgcontext'} eq $chgtype) {
1.295.2.4 raeburn 5149: $selstr = ' selected="selected"';
1.239 raeburn 5150: }
5151: if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) {
5152: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
5153: }
5154: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 5155: }
1.295.2.7 raeburn 5156: $output .= '</select></td>'
5157: .'</tr></table>';
5158:
5159: # Update Display button
5160: $output .= '<p>'
5161: .'<input type="submit" value="'.&mt('Update Display').'" />'
5162: .'</p>';
5163:
5164: # Server version info
5165: $output .= '<p style="font-size: smaller;" class="LC_info">'
5166: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
5167: ,'2.6.99.0');
1.248 raeburn 5168: if ($version) {
1.295.2.7 raeburn 5169: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
5170: }
5171: $output .= '</p><hr /><br />';
1.239 raeburn 5172: return $output;
5173: }
5174:
5175: sub rolechg_contexts {
1.295.2.18 raeburn 5176: my ($crstype) = @_;
1.239 raeburn 5177: my %lt = &Apache::lonlocal::texthash (
5178: any => 'Any',
5179: auto => 'Automated enrollment',
5180: updatenow => 'Roster Update',
5181: createcourse => 'Course Creation',
5182: course => 'User Management in course',
5183: domain => 'User Management in domain',
1.295.2.13 raeburn 5184: selfenroll => 'Self-enrolled',
5185: requestcourses => 'Course Request',
1.239 raeburn 5186: );
1.295.2.18 raeburn 5187: if ($crstype eq 'Community') {
5188: $lt{'createcourse'} = &mt('Community Creation');
5189: $lt{'course'} = &mt('User Management in community');
5190: $lt{'requestcourses'} = &mt('Community Request');
5191: }
1.239 raeburn 5192: return %lt;
5193: }
5194:
1.27 matthew 5195: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 5196: sub user_search_result {
1.221 raeburn 5197: my ($context,$srch) = @_;
1.160 raeburn 5198: my %allhomes;
5199: my %inst_matches;
5200: my %srch_results;
1.181 raeburn 5201: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 5202: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 5203: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 5204: $response = &mt('Invalid search.');
5205: }
5206: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
5207: $response = &mt('Invalid search.');
5208: }
1.177 raeburn 5209: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 5210: $response = &mt('Invalid search.');
5211: }
5212: if ($srch->{'srchterm'} eq '') {
5213: $response = &mt('You must enter a search term.');
5214: }
1.183 raeburn 5215: if ($srch->{'srchterm'} =~ /^\s+$/) {
5216: $response = &mt('Your search term must contain more than just spaces.');
5217: }
1.160 raeburn 5218: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
5219: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 5220: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 5221: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
5222: }
5223: }
5224: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
5225: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 5226: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 5227: my $unamecheck = $srch->{'srchterm'};
5228: if ($srch->{'srchtype'} eq 'contains') {
5229: if ($unamecheck !~ /^\w/) {
5230: $unamecheck = 'a'.$unamecheck;
5231: }
5232: }
5233: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 5234: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
5235: }
1.160 raeburn 5236: }
5237: }
1.180 raeburn 5238: if ($response ne '') {
5239: $response = '<span class="LC_warning">'.$response.'</span>';
5240: }
1.160 raeburn 5241: if ($srch->{'srchin'} eq 'instd') {
5242: my $instd_chk = &directorysrch_check($srch);
5243: if ($instd_chk ne 'ok') {
1.180 raeburn 5244: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
5245: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 5246: }
5247: }
5248: if ($response ne '') {
1.180 raeburn 5249: return ($currstate,$response);
1.160 raeburn 5250: }
5251: if ($srch->{'srchby'} eq 'uname') {
5252: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
5253: if ($env{'form.forcenew'}) {
5254: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
5255: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
5256: if ($uhome eq 'no_host') {
5257: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 5258: my $showdom = &display_domain_info($env{'request.role.domain'});
5259: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 5260: } else {
1.179 raeburn 5261: $currstate = 'modify';
1.160 raeburn 5262: }
5263: } else {
1.179 raeburn 5264: $currstate = 'modify';
1.160 raeburn 5265: }
5266: } else {
5267: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 5268: if ($srch->{'srchtype'} eq 'exact') {
5269: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
5270: if ($uhome eq 'no_host') {
1.179 raeburn 5271: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5272: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 5273: } else {
1.179 raeburn 5274: $currstate = 'modify';
1.295.2.11 raeburn 5275: my $uname = $srch->{'srchterm'};
5276: my $udom = $srch->{'srchdomain'};
5277: $srch_results{$uname.':'.$udom} =
5278: { &Apache::lonnet::get('environment',
5279: ['firstname',
5280: 'lastname',
5281: 'permanentemail'],
5282: $udom,$uname)
5283: };
1.162 raeburn 5284: }
5285: } else {
5286: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 5287: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5288: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5289: }
5290: } else {
1.167 albertel 5291: my $courseusers = &get_courseusers();
1.162 raeburn 5292: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 5293: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 5294: $currstate = 'modify';
1.162 raeburn 5295: } else {
1.179 raeburn 5296: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5297: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 5298: }
1.160 raeburn 5299: } else {
1.167 albertel 5300: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 5301: my ($cuname,$cudomain) = split(/:/,$user);
5302: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 5303: my $matched = 0;
5304: if ($srch->{'srchtype'} eq 'begins') {
5305: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
5306: $matched = 1;
5307: }
5308: } else {
5309: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
5310: $matched = 1;
5311: }
5312: }
5313: if ($matched) {
1.167 albertel 5314: $srch_results{$user} =
5315: {&Apache::lonnet::get('environment',
5316: ['firstname',
5317: 'lastname',
1.194 albertel 5318: 'permanentemail'],
5319: $cudomain,$cuname)};
1.162 raeburn 5320: }
5321: }
5322: }
1.179 raeburn 5323: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5324: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5325: }
5326: }
5327: }
5328: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 5329: $currstate = 'query';
1.160 raeburn 5330: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 5331: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
5332: if ($dirsrchres eq 'ok') {
5333: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5334: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 5335: } else {
5336: my $showdom = &display_domain_info($srch->{'srchdomain'});
5337: $response = '<span class="LC_warning">'.
5338: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
5339: '</span><br />'.
5340: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
5341: '<br /><br />';
5342: }
1.160 raeburn 5343: }
5344: } else {
5345: if ($srch->{'srchin'} eq 'dom') {
5346: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 5347: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5348: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5349: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 5350: my $courseusers = &get_courseusers();
5351: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 5352: my ($uname,$udom) = split(/:/,$user);
5353: my %names = &Apache::loncommon::getnames($uname,$udom);
5354: my %emails = &Apache::loncommon::getemails($uname,$udom);
5355: if ($srch->{'srchby'} eq 'lastname') {
5356: if ((($srch->{'srchtype'} eq 'exact') &&
5357: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 5358: (($srch->{'srchtype'} eq 'begins') &&
5359: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 5360: (($srch->{'srchtype'} eq 'contains') &&
5361: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
5362: $srch_results{$user} = {firstname => $names{'firstname'},
5363: lastname => $names{'lastname'},
5364: permanentemail => $emails{'permanentemail'},
5365: };
5366: }
5367: } elsif ($srch->{'srchby'} eq 'lastfirst') {
5368: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 5369: $srchlast =~ s/\s+$//;
5370: $srchfirst =~ s/^\s+//;
1.160 raeburn 5371: if ($srch->{'srchtype'} eq 'exact') {
5372: if (($names{'lastname'} eq $srchlast) &&
5373: ($names{'firstname'} eq $srchfirst)) {
5374: $srch_results{$user} = {firstname => $names{'firstname'},
5375: lastname => $names{'lastname'},
5376: permanentemail => $emails{'permanentemail'},
5377:
5378: };
5379: }
1.177 raeburn 5380: } elsif ($srch->{'srchtype'} eq 'begins') {
5381: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
5382: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
5383: $srch_results{$user} = {firstname => $names{'firstname'},
5384: lastname => $names{'lastname'},
5385: permanentemail => $emails{'permanentemail'},
5386: };
5387: }
5388: } else {
1.160 raeburn 5389: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
5390: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
5391: $srch_results{$user} = {firstname => $names{'firstname'},
5392: lastname => $names{'lastname'},
5393: permanentemail => $emails{'permanentemail'},
5394: };
5395: }
5396: }
5397: }
5398: }
1.179 raeburn 5399: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5400: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 5401: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 5402: $currstate = 'query';
1.160 raeburn 5403: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 5404: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
5405: if ($dirsrchres eq 'ok') {
5406: ($currstate,$response,$forcenewuser) =
1.221 raeburn 5407: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 5408: } else {
5409: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
5410: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
5411: '</span><br />'.
5412: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
5413: '<br /><br />';
5414: }
1.160 raeburn 5415: }
5416: }
1.179 raeburn 5417: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 5418: }
5419:
5420: sub directorysrch_check {
5421: my ($srch) = @_;
5422: my $can_search = 0;
5423: my $response;
5424: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
5425: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 5426: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 5427: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
5428: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 5429: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 5430: }
5431: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
5432: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 5433: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 5434: }
5435: my @usertypes = split(/:/,$env{'environment.inststatus'});
5436: if (!@usertypes) {
5437: push(@usertypes,'default');
5438: }
5439: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
5440: foreach my $type (@usertypes) {
5441: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
5442: $can_search = 1;
5443: last;
5444: }
5445: }
5446: }
5447: if (!$can_search) {
5448: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
5449: my @longtypes;
5450: foreach my $item (@usertypes) {
1.229 raeburn 5451: if (defined($insttypes->{$item})) {
5452: push (@longtypes,$insttypes->{$item});
5453: } elsif ($item eq 'default') {
5454: push (@longtypes,&mt('other'));
5455: }
1.160 raeburn 5456: }
5457: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 5458: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 5459: }
1.160 raeburn 5460: } else {
5461: $can_search = 1;
5462: }
5463: } else {
1.180 raeburn 5464: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 5465: }
5466: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 5467: uname => 'username',
1.160 raeburn 5468: lastfirst => 'last name, first name',
1.167 albertel 5469: lastname => 'last name',
1.172 raeburn 5470: contains => 'contains',
1.178 raeburn 5471: exact => 'as exact match to',
5472: begins => 'begins with',
1.160 raeburn 5473: );
5474: if ($can_search) {
5475: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
5476: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 5477: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 5478: }
5479: } else {
1.180 raeburn 5480: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 5481: }
5482: }
5483: if ($can_search) {
1.178 raeburn 5484: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
5485: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
5486: return 'ok';
5487: } else {
1.180 raeburn 5488: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 5489: }
5490: } else {
5491: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
5492: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
5493: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
5494: return 'ok';
5495: } else {
1.180 raeburn 5496: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 5497: }
1.160 raeburn 5498: }
5499: }
5500: }
5501:
5502: sub get_courseusers {
5503: my %advhash;
1.167 albertel 5504: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 5505: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
5506: foreach my $role (sort(keys(%coursepersonnel))) {
5507: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 5508: if (!exists($classlist->{$user})) {
5509: $classlist->{$user} = [];
5510: }
1.160 raeburn 5511: }
5512: }
1.167 albertel 5513: return $classlist;
1.160 raeburn 5514: }
5515:
5516: sub build_search_response {
1.221 raeburn 5517: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 5518: my ($currstate,$response,$forcenewuser);
1.160 raeburn 5519: my %names = (
5520: 'uname' => 'username',
5521: 'lastname' => 'last name',
5522: 'lastfirst' => 'last name, first name',
5523: 'crs' => 'this course',
1.180 raeburn 5524: 'dom' => 'LON-CAPA domain: ',
5525: 'instd' => 'the institutional directory for domain: ',
1.160 raeburn 5526: );
5527:
5528: my %single = (
1.180 raeburn 5529: begins => 'A match',
1.160 raeburn 5530: contains => 'A match',
1.180 raeburn 5531: exact => 'An exact match',
1.160 raeburn 5532: );
5533: my %nomatch = (
1.180 raeburn 5534: begins => 'No match',
1.160 raeburn 5535: contains => 'No match',
1.180 raeburn 5536: exact => 'No exact match',
1.160 raeburn 5537: );
5538: if (keys(%srch_results) > 1) {
1.179 raeburn 5539: $currstate = 'select';
1.160 raeburn 5540: } else {
5541: if (keys(%srch_results) == 1) {
1.179 raeburn 5542: $currstate = 'modify';
1.180 raeburn 5543: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
5544: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
5545: $response .= &display_domain_info($srch->{'srchdomain'});
5546: }
1.160 raeburn 5547: } else {
1.180 raeburn 5548: $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} 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: }
5552: $response .= '</span>';
1.160 raeburn 5553: if ($srch->{'srchin'} ne 'alc') {
5554: $forcenewuser = 1;
5555: my $cansrchinst = 0;
5556: if ($srch->{'srchdomain'}) {
5557: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
5558: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
5559: if ($domconfig{'directorysrch'}{'available'}) {
5560: $cansrchinst = 1;
5561: }
5562: }
5563: }
1.180 raeburn 5564: if ((($srch->{'srchby'} eq 'lastfirst') ||
5565: ($srch->{'srchby'} eq 'lastname')) &&
5566: ($srch->{'srchin'} eq 'dom')) {
5567: if ($cansrchinst) {
5568: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 5569: }
5570: }
1.180 raeburn 5571: if ($srch->{'srchin'} eq 'crs') {
5572: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
5573: }
5574: }
1.295.2.6 raeburn 5575: my $createdom = $env{'request.role.domain'};
5576: if ($context eq 'requestcrs') {
5577: if ($env{'form.coursedom'} ne '') {
5578: $createdom = $env{'form.coursedom'};
5579: }
5580: }
5581: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $createdom)) {
1.221 raeburn 5582: my $cancreate =
1.295.2.7 raeburn 5583: &Apache::lonuserutils::can_create_user($createdom,$context);
5584: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 5585: if ($cancreate) {
1.295.2.6 raeburn 5586: my $showdom = &display_domain_info($createdom);
1.266 bisitz 5587: $response .= '<br /><br />'
5588: .'<b>'.&mt('To add a new user:').'</b>'
1.295.2.6 raeburn 5589: .'<br />';
5590: if ($context eq 'requestcrs') {
1.295.2.7 raeburn 5591: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
1.295.2.6 raeburn 5592: } else {
1.295.2.7 raeburn 5593: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
5594: }
1.295.2.6 raeburn 5595: $response .= '<ul><li>'
1.266 bisitz 5596: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
5597: .'</li><li>'
5598: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
5599: .'</li><li>'
5600: .&mt('Provide the proposed username')
5601: .'</li><li>'
5602: .&mt("Click 'Search'")
5603: .'</li></ul><br />';
1.221 raeburn 5604: } else {
5605: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.295.2.6 raeburn 5606: $response .= '<br /><br />';
5607: if ($context eq 'requestcrs') {
1.295.2.7 raeburn 5608: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.295.2.6 raeburn 5609: } else {
5610: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
5611: }
5612: $response .= '<br />'
1.292 bisitz 5613: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 5614: ,' <a'.$helplink.'>'
5615: ,'</a>')
5616: .'<br /><br />';
1.221 raeburn 5617: }
1.160 raeburn 5618: }
5619: }
5620: }
1.179 raeburn 5621: return ($currstate,$response,$forcenewuser);
1.160 raeburn 5622: }
5623:
1.180 raeburn 5624: sub display_domain_info {
5625: my ($dom) = @_;
5626: my $output = $dom;
5627: if ($dom ne '') {
5628: my $domdesc = &Apache::lonnet::domain($dom,'description');
5629: if ($domdesc ne '') {
5630: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
5631: }
5632: }
5633: return $output;
5634: }
5635:
1.160 raeburn 5636: sub crumb_utilities {
5637: my %elements = (
5638: crtuser => {
5639: srchterm => 'text',
1.172 raeburn 5640: srchin => 'selectbox',
1.160 raeburn 5641: srchby => 'selectbox',
5642: srchtype => 'selectbox',
5643: srchdomain => 'selectbox',
5644: },
1.207 raeburn 5645: crtusername => {
5646: srchterm => 'text',
5647: srchdomain => 'selectbox',
5648: },
1.160 raeburn 5649: docustom => {
5650: rolename => 'selectbox',
5651: newrolename => 'textbox',
5652: },
1.179 raeburn 5653: studentform => {
5654: srchterm => 'text',
5655: srchin => 'selectbox',
5656: srchby => 'selectbox',
5657: srchtype => 'selectbox',
5658: srchdomain => 'selectbox',
5659: },
1.160 raeburn 5660: );
5661:
5662: my $jsback .= qq|
5663: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 5664: if (typeof prevphase == 'undefined') {
5665: formname.phase.value = '';
5666: }
5667: else {
5668: formname.phase.value = prevphase;
5669: }
5670: if (typeof prevstate == 'undefined') {
5671: formname.currstate.value = '';
5672: }
5673: else {
5674: formname.currstate.value = prevstate;
5675: }
1.160 raeburn 5676: formname.submit();
5677: }
5678: |;
5679: return ($jsback,\%elements);
5680: }
5681:
1.26 matthew 5682: sub course_level_table {
1.89 raeburn 5683: my (%inccourses) = @_;
1.26 matthew 5684: my $table = '';
1.62 www 5685: # Custom Roles?
5686:
1.190 raeburn 5687: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 5688: my %lt=&Apache::lonlocal::texthash(
5689: 'exs' => "Existing sections",
5690: 'new' => "Define new section",
5691: 'ssd' => "Set Start Date",
5692: 'sed' => "Set End Date",
1.131 raeburn 5693: 'crl' => "Course Level",
1.89 raeburn 5694: 'act' => "Activate",
5695: 'rol' => "Role",
5696: 'ext' => "Extent",
1.113 raeburn 5697: 'grs' => "Section",
1.89 raeburn 5698: 'sta' => "Start",
5699: 'end' => "End"
5700: );
1.62 www 5701:
1.135 raeburn 5702: foreach my $protectedcourse (sort( keys(%inccourses))) {
5703: my $thiscourse=$protectedcourse;
1.26 matthew 5704: $thiscourse=~s:_:/:g;
5705: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
5706: my $area=$coursedata{'description'};
1.295.2.19 raeburn 5707: my $crstype=$coursedata{'type'};
1.135 raeburn 5708: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 5709: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 5710: my %sections_count;
1.101 albertel 5711: if (defined($env{'request.course.id'})) {
5712: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 5713: %sections_count =
5714: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 5715: }
5716: }
1.295.2.21! raeburn 5717: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 5718: foreach my $role (@roles) {
1.295.2.18 raeburn 5719: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.135 raeburn 5720: if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
1.221 raeburn 5721: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5722: $plrole,\%sections_count,\%lt);
5723: } elsif ($env{'request.course.sec'} ne '') {
5724: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
5725: $env{'request.course.sec'})) {
5726: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5727: $plrole,\%sections_count,\%lt);
1.26 matthew 5728: }
5729: }
5730: }
1.221 raeburn 5731: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
5732: foreach my $cust (sort keys %customroles) {
5733: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
5734: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
5735: $cust,\%sections_count,\%lt);
5736: }
1.62 www 5737: }
1.26 matthew 5738: }
5739: return '' if ($table eq ''); # return nothing if there is nothing
5740: # in the table
1.188 raeburn 5741: my $result;
5742: if (!$env{'request.course.id'}) {
5743: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
5744: }
5745: $result .=
1.136 raeburn 5746: &Apache::loncommon::start_data_table().
5747: &Apache::loncommon::start_data_table_header_row().
5748: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
5749: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
5750: &Apache::loncommon::end_data_table_header_row().
5751: $table.
5752: &Apache::loncommon::end_data_table();
1.26 matthew 5753: return $result;
5754: }
1.88 raeburn 5755:
1.221 raeburn 5756: sub course_level_row {
5757: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_;
1.222 raeburn 5758: my $row = &Apache::loncommon::start_data_table_row().
5759: ' <td><input type="checkbox" name="act_'.
5760: $protectedcourse.'_'.$role.'" /></td>'."\n".
5761: ' <td>'.$plrole.'</td>'."\n".
5762: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.221 raeburn 5763: if ($role eq 'cc') {
1.222 raeburn 5764: $row .= '<td> </td>';
1.221 raeburn 5765: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 5766: $row .= ' <td><input type="hidden" value="'.
5767: $env{'request.course.sec'}.'" '.
5768: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
5769: $env{'request.course.sec'}.'</td>';
1.221 raeburn 5770: } else {
5771: if (ref($sections_count) eq 'HASH') {
5772: my $currsec =
5773: &Apache::lonuserutils::course_sections($sections_count,
5774: $protectedcourse.'_'.$role);
1.222 raeburn 5775: $row .= '<td><table class="LC_createuser">'."\n".
5776: '<tr class="LC_section_row">'."\n".
5777: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
5778: $currsec.'</td>'."\n".
5779: ' <td> </td>'."\n".
5780: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 5781: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
5782: '" value="" />'.
5783: '<input type="hidden" '.
5784: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 5785: '</tr></table></td>'."\n";
1.221 raeburn 5786: } else {
1.222 raeburn 5787: $row .= '<td><input type="text" size="10" '.
5788: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 5789: }
5790: }
1.222 raeburn 5791: $row .= <<ENDTIMEENTRY;
5792: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 5793: <a href=
5794: "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 5795: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 5796: <a href=
5797: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
5798: ENDTIMEENTRY
1.222 raeburn 5799: $row .= &Apache::loncommon::end_data_table_row();
5800: return $row;
1.221 raeburn 5801: }
5802:
1.88 raeburn 5803: sub course_level_dc {
5804: my ($dcdom) = @_;
1.190 raeburn 5805: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 5806: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 5807: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
5808: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 5809: '<input type="hidden" name="dccourse" value="" />';
1.88 raeburn 5810: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.131 raeburn 5811: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
1.295.2.19 raeburn 5812: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser');
1.88 raeburn 5813: my %lt=&Apache::lonlocal::texthash(
5814: 'rol' => "Role",
1.113 raeburn 5815: 'grs' => "Section",
1.88 raeburn 5816: 'exs' => "Existing sections",
5817: 'new' => "Define new section",
5818: 'sta' => "Start",
5819: 'end' => "End",
5820: 'ssd' => "Set Start Date",
5821: 'sed' => "Set End Date"
5822: );
1.131 raeburn 5823: my $header = '<h4>'.&mt('Course Level').'</h4>'.
1.136 raeburn 5824: &Apache::loncommon::start_data_table().
5825: &Apache::loncommon::start_data_table_header_row().
1.143 raeburn 5826: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 5827: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 5828: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.295.2.4 raeburn 5829: '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1.88 raeburn 5830: '<td><select name="role">'."\n";
1.213 raeburn 5831: foreach my $role (@roles) {
1.135 raeburn 5832: my $plrole=&Apache::lonnet::plaintext($role);
5833: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 5834: }
5835: if ( keys %customroles > 0) {
1.135 raeburn 5836: foreach my $cust (sort keys %customroles) {
1.101 albertel 5837: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 5838: '_'.$env{'user.name'}.'_'.$cust;
5839: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 5840: }
5841: }
5842: $otheritems .= '</select></td><td>'.
5843: '<table border="0" cellspacing="0" cellpadding="0">'.
5844: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
5845: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
5846: '<td> </td>'.
5847: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 5848: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 5849: '<input type="hidden" name="section" value="" />'.
1.113 raeburn 5850: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 5851: '</tr></table></td>';
5852: $otheritems .= <<ENDTIMEENTRY;
1.169 albertel 5853: <td><input type="hidden" name="start" value='' />
1.88 raeburn 5854: <a href=
5855: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 5856: <td><input type="hidden" name="end" value='' />
1.88 raeburn 5857: <a href=
5858: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
5859: ENDTIMEENTRY
1.136 raeburn 5860: $otheritems .= &Apache::loncommon::end_data_table_row().
5861: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 5862: return $cb_jscript.$header.$hiddenitems.$otheritems;
5863: }
5864:
1.237 raeburn 5865: sub update_selfenroll_config {
1.241 raeburn 5866: my ($r,$context,$permission) = @_;
1.237 raeburn 5867: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 5868: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 5869: my (%changes,%warning);
5870: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5871: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 5872: my $curr_types;
1.237 raeburn 5873: if (ref($row) eq 'ARRAY') {
5874: foreach my $item (@{$row}) {
5875: if ($item eq 'enroll_dates') {
5876: my (%currenrolldate,%newenrolldate);
5877: foreach my $type ('start','end') {
5878: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
5879: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
5880: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
5881: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
5882: }
5883: }
5884: } elsif ($item eq 'access_dates') {
5885: my (%currdate,%newdate);
5886: foreach my $type ('start','end') {
5887: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
5888: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
5889: if ($newdate{$type} ne $currdate{$type}) {
5890: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
5891: }
5892: }
1.241 raeburn 5893: } elsif ($item eq 'types') {
5894: $curr_types =
5895: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
5896: if ($env{'form.selfenroll_all'}) {
5897: if ($curr_types ne '*') {
5898: $changes{'internal.selfenroll_types'} = '*';
5899: } else {
5900: next;
5901: }
5902: } else {
1.249 raeburn 5903: my %currdoms;
1.241 raeburn 5904: my @entries = split(/;/,$curr_types);
5905: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 5906: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 5907: my $newnum = 0;
1.249 raeburn 5908: my @latesttypes;
5909: foreach my $num (@activations) {
5910: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
5911: if (@types > 0) {
1.241 raeburn 5912: @types = sort(@types);
5913: my $typestr = join(',',@types);
1.249 raeburn 5914: my $typedom = $env{'form.selfenroll_dom_'.$num};
5915: $latesttypes[$newnum] = $typedom.':'.$typestr;
5916: $currdoms{$typedom} = 1;
1.241 raeburn 5917: $newnum ++;
5918: }
5919: }
1.249 raeburn 5920: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) { if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
5921: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
5922: if (@types > 0) {
5923: @types = sort(@types);
5924: my $typestr = join(',',@types);
5925: my $typedom = $env{'form.selfenroll_dom_'.$j};
5926: $latesttypes[$newnum] = $typedom.':'.$typestr;
5927: $currdoms{$typedom} = 1;
5928: $newnum ++;
5929: }
5930: }
5931: }
5932: if ($env{'form.selfenroll_newdom'} ne '') {
5933: my $typedom = $env{'form.selfenroll_newdom'};
5934: if ((!defined($currdoms{$typedom})) &&
5935: (&Apache::lonnet::domain($typedom) ne '')) {
5936: my $typestr;
5937: my ($othertitle,$usertypes,$types) =
5938: &Apache::loncommon::sorted_inst_types($typedom);
5939: my $othervalue = 'any';
5940: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5941: if (@{$types} > 0) {
1.257 raeburn 5942: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 5943: $othervalue = 'other';
1.258 raeburn 5944: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 5945: }
5946: $typestr = $othervalue;
5947: } else {
5948: $typestr = $othervalue;
5949: }
5950: $latesttypes[$newnum] = $typedom.':'.$typestr;
5951: $newnum ++ ;
5952: }
5953: }
1.241 raeburn 5954: my $selfenroll_types = join(';',@latesttypes);
5955: if ($selfenroll_types ne $curr_types) {
5956: $changes{'internal.selfenroll_types'} = $selfenroll_types;
5957: }
5958: }
1.276 raeburn 5959: } elsif ($item eq 'limit') {
5960: my $newlimit = $env{'form.selfenroll_limit'};
5961: my $newcap = $env{'form.selfenroll_cap'};
5962: $newcap =~s/\s+//g;
5963: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
5964: $currlimit = 'none' if ($currlimit eq '');
5965: my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
5966: if ($newlimit ne $currlimit) {
5967: if ($newlimit ne 'none') {
5968: if ($newcap =~ /^\d+$/) {
5969: if ($newcap ne $currcap) {
5970: $changes{'internal.selfenroll_cap'} = $newcap;
5971: }
5972: $changes{'internal.selfenroll_limit'} = $newlimit;
5973: } else {
5974: $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.');
5975: }
5976: } elsif ($currcap ne '') {
5977: $changes{'internal.selfenroll_cap'} = '';
5978: $changes{'internal.selfenroll_limit'} = $newlimit;
5979: }
5980: } elsif ($currlimit ne 'none') {
5981: if ($newcap =~ /^\d+$/) {
5982: if ($newcap ne $currcap) {
5983: $changes{'internal.selfenroll_cap'} = $newcap;
5984: }
5985: } else {
5986: $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.');
5987: }
5988: }
5989: } elsif ($item eq 'approval') {
5990: my (@currnotified,@newnotified);
5991: my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
5992: my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
5993: if ($currnotifylist ne '') {
5994: @currnotified = split(/,/,$currnotifylist);
5995: @currnotified = sort(@currnotified);
5996: }
5997: my $newapproval = $env{'form.selfenroll_approval'};
5998: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
5999: @newnotified = sort(@newnotified);
6000: if ($newapproval ne $currapproval) {
6001: $changes{'internal.selfenroll_approval'} = $newapproval;
6002: if (!$newapproval) {
6003: if ($currnotifylist ne '') {
6004: $changes{'internal.selfenroll_notifylist'} = '';
6005: }
6006: } else {
6007: my @differences =
1.295 raeburn 6008: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 6009: if (@differences > 0) {
6010: if (@newnotified > 0) {
6011: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6012: } else {
6013: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6014: }
6015: }
6016: }
6017: } else {
1.295 raeburn 6018: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 6019: if (@differences > 0) {
6020: if (@newnotified > 0) {
6021: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
6022: } else {
6023: $changes{'internal.selfenroll_notifylist'} = '';
6024: }
6025: }
6026: }
1.237 raeburn 6027: } else {
6028: my $curr_val =
6029: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
6030: my $newval = $env{'form.selfenroll_'.$item};
6031: if ($item eq 'section') {
6032: $newval = $env{'form.sections'};
1.241 raeburn 6033: if (defined($curr_groups{$newval})) {
1.237 raeburn 6034: $newval = $curr_val;
6035: $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');
6036: } elsif ($newval eq 'all') {
6037: $newval = $curr_val;
1.274 bisitz 6038: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 6039: }
6040: if ($newval eq '') {
6041: $newval = 'none';
6042: }
6043: }
6044: if ($newval ne $curr_val) {
6045: $changes{'internal.selfenroll_'.$item} = $newval;
6046: }
1.241 raeburn 6047: }
1.237 raeburn 6048: }
6049: if (keys(%warning) > 0) {
6050: foreach my $item (@{$row}) {
6051: if (exists($warning{$item})) {
6052: $r->print($warning{$item}.'<br />');
6053: }
6054: }
6055: }
6056: if (keys(%changes) > 0) {
6057: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
6058: if ($putresult eq 'ok') {
6059: if ((exists($changes{'internal.selfenroll_types'})) ||
6060: (exists($changes{'internal.selfenroll_start_date'})) ||
6061: (exists($changes{'internal.selfenroll_end_date'}))) {
6062: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
6063: $cnum,undef,undef,'Course');
6064: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
6065: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
6066: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
6067: if (exists($changes{'internal.'.$item})) {
6068: $crsinfo{$env{'request.course.id'}}{$item} =
6069: $changes{'internal.'.$item};
6070: }
6071: }
6072: my $crsputresult =
6073: &Apache::lonnet::courseidput($cdom,\%crsinfo,
6074: $chome,'notime');
6075: }
6076: }
6077: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
6078: foreach my $item (@{$row}) {
6079: my $title = $item;
6080: if (ref($lt) eq 'HASH') {
6081: $title = $lt->{$item};
6082: }
6083: if ($item eq 'enroll_dates') {
6084: foreach my $type ('start','end') {
6085: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
6086: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 6087: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 6088: $title,$type,$newdate).'</li>');
6089: }
6090: }
6091: } elsif ($item eq 'access_dates') {
6092: foreach my $type ('start','end') {
6093: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
6094: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 6095: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 6096: $title,$type,$newdate).'</li>');
6097: }
6098: }
1.276 raeburn 6099: } elsif ($item eq 'limit') {
6100: if ((exists($changes{'internal.selfenroll_limit'})) ||
6101: (exists($changes{'internal.selfenroll_cap'}))) {
6102: my ($newval,$newcap);
6103: if ($changes{'internal.selfenroll_cap'} ne '') {
6104: $newcap = $changes{'internal.selfenroll_cap'}
6105: } else {
6106: $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
6107: }
6108: if ($changes{'internal.selfenroll_limit'} eq 'none') {
6109: $newval = &mt('No limit');
6110: } elsif ($changes{'internal.selfenroll_limit'} eq
6111: 'allstudents') {
6112: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
6113: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
6114: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
6115: } else {
6116: my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
6117: if ($currlimit eq 'allstudents') {
6118: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
6119: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.295.2.9 raeburn 6120: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 6121: }
6122: }
6123: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
6124: }
6125: } elsif ($item eq 'approval') {
6126: if ((exists($changes{'internal.selfenroll_approval'})) ||
6127: (exists($changes{'internal.selfenroll_notifylist'}))) {
6128: my ($newval,$newnotify);
6129: if (exists($changes{'internal.selfenroll_notifylist'})) {
6130: $newnotify = $changes{'internal.selfenroll_notifylist'};
6131: } else {
6132: $newnotify = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
6133: }
6134: if ($changes{'internal.selfenroll_approval'}) {
6135: $newval = &mt('Yes');
6136: } elsif ($changes{'internal.selfenroll_approval'} eq '0') {
6137: $newval = &mt('No');
6138: } else {
6139: my $currapproval =
6140: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
6141: if ($currapproval) {
6142: $newval = &mt('Yes');
6143: } else {
6144: $newval = &mt('No');
6145: }
6146: }
6147: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
6148: if ($newnotify) {
1.277 raeburn 6149: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 6150: } else {
1.277 raeburn 6151: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 6152: }
6153: $r->print('</li>'."\n");
6154: }
1.237 raeburn 6155: } else {
6156: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 6157: my $newval = $changes{'internal.selfenroll_'.$item};
6158: if ($item eq 'types') {
6159: if ($newval eq '') {
6160: $newval = &mt('None');
6161: } elsif ($newval eq '*') {
6162: $newval = &mt('Any user in any domain');
6163: }
1.245 raeburn 6164: } elsif ($item eq 'registered') {
6165: if ($newval eq '1') {
6166: $newval = &mt('Yes');
6167: } elsif ($newval eq '0') {
6168: $newval = &mt('No');
6169: }
1.241 raeburn 6170: }
1.244 bisitz 6171: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 6172: }
6173: }
6174: }
6175: $r->print('</ul>');
6176: my %newenvhash;
6177: foreach my $key (keys(%changes)) {
6178: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
6179: }
1.238 raeburn 6180: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 6181: } else {
6182: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
6183: }
6184: } else {
1.249 raeburn 6185: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 6186: }
6187: } else {
1.249 raeburn 6188: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 6189: }
1.256 raeburn 6190: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
6191: if (ref($visactions) eq 'HASH') {
6192: if (!$visible) {
6193: $r->print('<br />'.$visactions->{'miss'}.'<br />'.$visactions->{'yous'}.
6194: '<br />');
6195: if (ref($vismsgs) eq 'ARRAY') {
6196: $r->print('<br />'.$visactions->{'take'}.'<ul>');
6197: foreach my $item (@{$vismsgs}) {
6198: $r->print('<li>'.$visactions->{$item}.'</li>');
6199: }
6200: $r->print('</ul>');
6201: }
6202: $r->print($cansetvis);
6203: }
6204: }
1.237 raeburn 6205: return;
6206: }
6207:
6208: sub get_selfenroll_titles {
1.276 raeburn 6209: my @row = ('types','registered','enroll_dates','access_dates','section',
6210: 'approval','limit');
1.237 raeburn 6211: my %lt = &Apache::lonlocal::texthash (
6212: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 6213: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 6214: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 6215: access_dates => 'Course access dates assigned to self-enrolling users',
6216: section => 'Section assigned to self-enrolling users',
1.276 raeburn 6217: approval => 'Self-enrollment requests need approval?',
6218: limit => 'Enrollment limit',
1.237 raeburn 6219: );
6220: return (\@row,\%lt);
6221: }
6222:
1.27 matthew 6223: #---------------------------------------------- end functions for &phase_two
1.29 matthew 6224:
6225: #--------------------------------- functions for &phase_two and &phase_three
6226:
6227: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 6228:
6229: 1;
6230: __END__
1.2 www 6231:
6232:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>