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