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