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