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