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