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