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