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