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