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