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