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