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