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