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