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