Annotation of loncom/interface/loncreateuser.pm, revision 1.268.2.5
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.268.2.5! raeburn 4: # $Id: loncreateuser.pm,v 1.268.2.4 2008/12/28 22:13:27 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.2.5! raeburn 772: } else {
1.193 raeburn 773: my $authparm = $rules->{$matchedrule}{'authparm'};
1.268.2.5! 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.2.5! 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.2.5! 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') {
1564: if ($canmodify{$item}) {
1565: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1566: $editable ++;
1567: } else {
1568: $hiderow = 1;
1569: }
1.253 raeburn 1570: } else {
1571: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 1572: }
1.188 raeburn 1573: }
1574: } else {
1.219 raeburn 1575: if ($canmodify{$item}) {
1.252 raeburn 1576: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.188 raeburn 1577: } else {
1.252 raeburn 1578: $row .= $userenv{$item};
1.188 raeburn 1579: }
1.206 raeburn 1580: if ($item eq 'id') {
1.219 raeburn 1581: $showforceid = $canmodify{$item};
1582: }
1.188 raeburn 1583: }
1.252 raeburn 1584: $row .= &Apache::lonhtmlcommon::row_closure(1);
1585: if (!$hiderow) {
1586: $output .= $row;
1587: $rowcount ++;
1588: }
1.188 raeburn 1589: }
1590: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 1591: if (wantarray) {
1.252 raeburn 1592: if ($context eq 'selfcreate') {
1593: return($output,$rowcount,$editable);
1594: } else {
1595: return ($output,$showforceid);
1596: }
1.206 raeburn 1597: } else {
1598: return $output;
1599: }
1.188 raeburn 1600: }
1601:
1.257 raeburn 1602: sub selfcreate_canmodify {
1603: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
1604: if (ref($inst_results) eq 'HASH') {
1605: my @inststatuses = &get_inststatuses($inst_results);
1606: if (@inststatuses == 0) {
1607: @inststatuses = ('default');
1608: }
1609: $rolesarray = \@inststatuses;
1610: }
1611: my %canmodify =
1612: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
1613: $rolesarray);
1614: return %canmodify;
1615: }
1616:
1.252 raeburn 1617: sub get_inststatuses {
1618: my ($insthashref) = @_;
1619: my @inststatuses = ();
1620: if (ref($insthashref) eq 'HASH') {
1621: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
1622: @inststatuses = @{$insthashref->{'inststatus'}};
1623: }
1624: }
1625: return @inststatuses;
1626: }
1627:
1.4 www 1628: # ================================================================= Phase Three
1.42 matthew 1629: sub update_user_data {
1.206 raeburn 1630: my ($r,$context) = @_;
1.101 albertel 1631: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
1632: $env{'form.ccdomain'});
1.27 matthew 1633: # Error messages
1.188 raeburn 1634: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 1635: my $end = '</span><br /><br />';
1636: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 1637: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 1638: &mt('Return to previous page').'</a>'.
1639: &Apache::loncommon::end_page();
1640: my $now = time;
1.40 www 1641: my $title;
1.101 albertel 1642: if (exists($env{'form.makeuser'})) {
1.40 www 1643: $title='Set Privileges for New User';
1644: } else {
1645: $title='Modify User Privileges';
1646: }
1.213 raeburn 1647: my $newuser = 0;
1.160 raeburn 1648: my ($jsback,$elements) = &crumb_utilities();
1649: my $jscript = '<script type="text/javascript">'."\n".
1650: $jsback."\n".'</script>'."\n";
1.213 raeburn 1651: my %breadcrumb_text = &singleuser_breadcrumb();
1.233 raeburn 1652: my $args;
1653: if ($env{'form.popup'}) {
1654: $args->{'no_nav_bar'} = 1;
1655: } else {
1656: $args = undef;
1657: }
1658: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.160 raeburn 1659: &Apache::lonhtmlcommon::add_breadcrumb
1660: ({href=>"javascript:backPage(document.userupdate)",
1.213 raeburn 1661: text=>$breadcrumb_text{'search'},
1.160 raeburn 1662: faq=>282,bug=>'Instructor Interface',});
1663: if ($env{'form.prevphase'} eq 'userpicked') {
1664: &Apache::lonhtmlcommon::add_breadcrumb
1665: ({href=>"javascript:backPage(document.userupdate,'get_user_info','select')",
1.213 raeburn 1666: text=>$breadcrumb_text{'userpicked'},
1.160 raeburn 1667: faq=>282,bug=>'Instructor Interface',});
1668: }
1669: &Apache::lonhtmlcommon::add_breadcrumb
1670: ({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
1.219 raeburn 1671: text=>$breadcrumb_text{'modify'},
1.160 raeburn 1672: faq=>282,bug=>'Instructor Interface',},
1673: {href=>"/adm/createuser",
1674: text=>"Result",
1675: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 1676: my $helpitem = 'Course_Change_Privileges';
1677: if ($env{'form.action'} eq 'singlestudent') {
1678: $helpitem = 'Course_Add_Student';
1679: }
1680: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
1681: $helpitem));
1.188 raeburn 1682: $r->print(&update_result_form($uhome));
1.27 matthew 1683: # Check Inputs
1.101 albertel 1684: if (! $env{'form.ccuname'} ) {
1.193 raeburn 1685: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 1686: return;
1687: }
1.138 albertel 1688: if ( $env{'form.ccuname'} ne
1689: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.73 sakharuk 1690: $r->print($error.&mt('Invalid login name').'. '.
1.160 raeburn 1691: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid').'.'.
1.193 raeburn 1692: $end.$rtnlink);
1.27 matthew 1693: return;
1694: }
1.101 albertel 1695: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 1696: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 1697: return;
1698: }
1.138 albertel 1699: if ( $env{'form.ccdomain'} ne
1700: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.73 sakharuk 1701: $r->print($error.&mt ('Invalid domain name').'. '.
1.138 albertel 1702: &mt('Only letters, numbers, periods, dashes, and underscores are valid').'.'.
1.193 raeburn 1703: $end.$rtnlink);
1.27 matthew 1704: return;
1705: }
1.219 raeburn 1706: if ($uhome eq 'no_host') {
1707: $newuser = 1;
1708: }
1.101 albertel 1709: if (! exists($env{'form.makeuser'})) {
1.29 matthew 1710: # Modifying an existing user, so check the validity of the name
1711: if ($uhome eq 'no_host') {
1.73 sakharuk 1712: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 1713: $env{'form.ccuname'}.&mt(' in domain ').
1714: $env{'form.ccdomain'}.'.');
1.29 matthew 1715: return;
1716: }
1717: }
1.27 matthew 1718: # Determine authentication method and password for the user being modified
1719: my $amode='';
1720: my $genpwd='';
1.101 albertel 1721: if ($env{'form.login'} eq 'krb') {
1.41 albertel 1722: $amode='krb';
1.101 albertel 1723: $amode.=$env{'form.krbver'};
1724: $genpwd=$env{'form.krbarg'};
1725: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 1726: $amode='internal';
1.101 albertel 1727: $genpwd=$env{'form.intarg'};
1728: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 1729: $amode='unix';
1.101 albertel 1730: $genpwd=$env{'form.fsysarg'};
1731: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 1732: $amode='localauth';
1.101 albertel 1733: $genpwd=$env{'form.locarg'};
1.27 matthew 1734: $genpwd=" " if (!$genpwd);
1.101 albertel 1735: } elsif (($env{'form.login'} eq 'nochange') ||
1736: ($env{'form.login'} eq '' )) {
1.34 matthew 1737: # There is no need to tell the user we did not change what they
1738: # did not ask us to change.
1.35 matthew 1739: # If they are creating a new user but have not specified login
1740: # information this will be caught below.
1.30 matthew 1741: } else {
1.193 raeburn 1742: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.30 matthew 1743: return;
1.27 matthew 1744: }
1.164 albertel 1745:
1.188 raeburn 1746: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1747: $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h3>');
1.193 raeburn 1748: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.267 raeburn 1749: my @usertools = ('aboutme','blog','portfolio');
1.101 albertel 1750: if ($env{'form.makeuser'}) {
1.164 albertel 1751: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 1752: # Check for the authentication mode and password
1753: if (! $amode || ! $genpwd) {
1.193 raeburn 1754: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 1755: return;
1.18 albertel 1756: }
1.29 matthew 1757: # Determine desired host
1.101 albertel 1758: my $desiredhost = $env{'form.hserver'};
1.29 matthew 1759: if (lc($desiredhost) eq 'default') {
1760: $desiredhost = undef;
1761: } else {
1.147 albertel 1762: my %home_servers =
1763: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 1764: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 1765: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
1766: return;
1767: }
1768: }
1769: # Check ID format
1770: my %checkhash;
1771: my %checks = ('id' => 1);
1772: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 1773: 'newuser' => $newuser,
1.196 raeburn 1774: 'id' => $env{'form.cid'},
1.193 raeburn 1775: );
1.196 raeburn 1776: if ($env{'form.cid'} ne '') {
1777: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
1778: \%rulematch,\%inst_results,\%curr_rules);
1779: if (ref($alerts{'id'}) eq 'HASH') {
1780: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1781: my $domdesc =
1782: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
1783: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
1784: my $userchkmsg;
1785: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
1786: $userchkmsg =
1787: &Apache::loncommon::instrule_disallow_msg('id',
1788: $domdesc,1).
1789: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
1790: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
1791: }
1792: $r->print($error.&mt('Invalid ID format').$end.
1793: $userchkmsg.$rtnlink);
1794: return;
1795: }
1796: }
1.29 matthew 1797: }
1798: }
1.27 matthew 1799: # Call modifyuser
1800: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 1801: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 1802: $amode,$genpwd,$env{'form.cfirstname'},
1803: $env{'form.cmiddlename'},$env{'form.clastname'},
1804: $env{'form.cgeneration'},undef,$desiredhost,
1805: $env{'form.cpermanentemail'});
1.77 www 1806: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 1807: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 1808: $env{'form.ccdomain'});
1.267 raeburn 1809: my (%changeHash,%newcustom,%changed);
1810: if ($uhome ne 'no_host') {
1811: if ($env{'form.customquota'} == 1) {
1812: if ($env{'form.portfolioquota'} eq '') {
1813: $newcustom{'quota'} = 0;
1814: } else {
1815: $newcustom{'quota'} = $env{'form.portfolioquota'};
1816: $newcustom{'quota'} =~ s/[^\d\.]//g;
1817: }
1818: $changed{'quota'} = "a_admin($newcustom{'quota'},\%changeHash);
1819: }
1820: foreach my $item (@usertools) {
1821: if ($env{'form.custom'.$item} == 1) {
1822: $newcustom{$item} = $env{'form.tools_'.$item};
1823: $changed{$item} = &tool_admin($item,$newcustom{$item},\%changeHash);
1824: }
1.232 raeburn 1825: }
1.267 raeburn 1826: if (keys(%changed)) {
1.232 raeburn 1827: $changeHash{'firstname'} = $env{'form.cfirstname'};
1828: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1829: $changeHash{'lastname'} = $env{'form.clastname'};
1830: $changeHash{'generation'} = $env{'form.cgeneration'};
1831: $changeHash{'id'} = $env{'form.cid'};
1832: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1.267 raeburn 1833: my $chgresult =
1834: &Apache::lonnet::put('environment',\%changeHash,
1835: $env{'form.ccdomain'},$env{'form.ccuname'});
1836: }
1.232 raeburn 1837: }
1.219 raeburn 1838: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
1839: &Apache::lonnet::hostname($uhome));
1.101 albertel 1840: } elsif (($env{'form.login'} ne 'nochange') &&
1841: ($env{'form.login'} ne '' )) {
1.27 matthew 1842: # Modify user privileges
1843: if (! $amode || ! $genpwd) {
1.193 raeburn 1844: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 1845: return;
1.20 harris41 1846: }
1.27 matthew 1847: # Only allow authentification modification if the person has authority
1.101 albertel 1848: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 1849: $r->print('Modifying authentication: '.
1.31 matthew 1850: &Apache::lonnet::modifyuserauth(
1.101 albertel 1851: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 1852: $amode,$genpwd));
1.102 albertel 1853: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 1854: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 1855: } else {
1.27 matthew 1856: # Okay, this is a non-fatal error.
1.193 raeburn 1857: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
1.27 matthew 1858: }
1.28 matthew 1859: }
1860: ##
1.213 raeburn 1861: my (@userroles,%userupdate,$cnum,$cdom,$namechanged);
1862: if ($context eq 'course') {
1863: ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1864: }
1.101 albertel 1865: if (! $env{'form.makeuser'} ) {
1.28 matthew 1866: # Check for need to change
1867: my %userenv = &Apache::lonnet::get
1.134 raeburn 1868: ('environment',['firstname','middlename','lastname','generation',
1.267 raeburn 1869: 'id','permanentemail','portfolioquota','inststatus','tools.aboutme',
1870: 'tools.blog','tools.portfolio'],
1.160 raeburn 1871: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 1872: my ($tmp) = keys(%userenv);
1873: if ($tmp =~ /^(con_lost|error)/i) {
1874: %userenv = ();
1875: }
1.206 raeburn 1876: my $no_forceid_alert;
1877: # Check to see if user information can be changed
1878: my %domconfig =
1879: &Apache::lonnet::get_dom('configuration',['usermodification'],
1880: $env{'form.ccdomain'});
1.213 raeburn 1881: my @statuses = ('active','future');
1882: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
1883: my ($auname,$audom);
1.220 raeburn 1884: if ($context eq 'author') {
1.206 raeburn 1885: $auname = $env{'user.name'};
1886: $audom = $env{'user.domain'};
1887: }
1888: foreach my $item (keys(%roles)) {
1.220 raeburn 1889: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 1890: if ($context eq 'course') {
1891: if ($cnum ne '' && $cdom ne '') {
1892: if ($rolenum eq $cnum && $roledom eq $cdom) {
1893: if (!grep(/^\Q$role\E$/,@userroles)) {
1894: push(@userroles,$role);
1895: }
1896: }
1897: }
1898: } elsif ($context eq 'author') {
1899: if ($rolenum eq $auname && $roledom eq $audom) {
1900: if (!grep(/^\Q$role\E$/,@userroles)) {
1901: push(@userroles,$role);
1902: }
1903: }
1904: }
1905: }
1.220 raeburn 1906: if ($env{'form.action'} eq 'singlestudent') {
1907: if (!grep(/^st$/,@userroles)) {
1908: push(@userroles,'st');
1909: }
1910: } else {
1911: # Check for course or co-author roles being activated or re-enabled
1912: if ($context eq 'author' || $context eq 'course') {
1913: foreach my $key (keys(%env)) {
1914: if ($context eq 'author') {
1915: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
1916: if (!grep(/^\Q$1\E$/,@userroles)) {
1917: push(@userroles,$1);
1918: }
1919: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
1920: if (!grep(/^\Q$1\E$/,@userroles)) {
1921: push(@userroles,$1);
1922: }
1.206 raeburn 1923: }
1.220 raeburn 1924: } elsif ($context eq 'course') {
1925: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
1926: if (!grep(/^\Q$1\E$/,@userroles)) {
1927: push(@userroles,$1);
1928: }
1929: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
1930: if (!grep(/^\Q$1\E$/,@userroles)) {
1931: push(@userroles,$1);
1932: }
1.206 raeburn 1933: }
1934: }
1935: }
1936: }
1937: }
1938: #Check to see if we can change personal data for the user
1939: my (@mod_disallowed,@longroles);
1940: foreach my $role (@userroles) {
1941: if ($role eq 'cr') {
1942: push(@longroles,'Custom');
1943: } else {
1944: push(@longroles,&Apache::lonnet::plaintext($role));
1945: }
1946: }
1.219 raeburn 1947: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1948: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
1949: foreach my $item (@userinfo) {
1.28 matthew 1950: # Strip leading and trailing whitespace
1.203 raeburn 1951: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 1952: if (!$canmodify{$item}) {
1.207 raeburn 1953: if (defined($env{'form.c'.$item})) {
1954: if ($env{'form.c'.$item} ne $userenv{$item}) {
1955: push(@mod_disallowed,$item);
1956: }
1.206 raeburn 1957: }
1958: $env{'form.c'.$item} = $userenv{$item};
1959: }
1.28 matthew 1960: }
1.259 bisitz 1961: # Check to see if we can change the Student/Employee ID
1.196 raeburn 1962: my $forceid = $env{'form.forceid'};
1963: my $recurseid = $env{'form.recurseid'};
1964: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 1965: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
1966: $env{'form.ccuname'});
1967: if (($uidhash{$env{'form.ccuname'}}) &&
1968: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
1969: (!$forceid)) {
1970: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
1971: $env{'form.cid'} = $userenv{'id'};
1.259 bisitz 1972: $no_forceid_alert = &mt('New Student/Employee ID does not match existing ID for this user.')
1973: .'<br />'
1974: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
1975: .'<br />'."\n";
1.203 raeburn 1976: }
1977: }
1978: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 1979: my $checkhash;
1980: my $checks = { 'id' => 1 };
1981: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
1982: { 'newuser' => $newuser,
1983: 'id' => $env{'form.cid'},
1984: };
1985: &Apache::loncommon::user_rule_check($checkhash,$checks,
1986: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
1987: if (ref($alerts{'id'}) eq 'HASH') {
1988: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 1989: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 1990: }
1991: }
1992: }
1.213 raeburn 1993: my ($quotachanged,$oldportfolioquota,$newportfolioquota,
1.204 raeburn 1994: $inststatus,$oldisdefault,$newisdefault,$olddefquotatext,
1.267 raeburn 1995: $newdefquotatext,%oldaccess,%oldaccesstext,%newaccess,%newaccesstext);
1.149 raeburn 1996: my ($defquota,$settingstatus) =
1997: &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
1.267 raeburn 1998: my ($showquota,$showtools);
1.220 raeburn 1999: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
2000: $showquota = 1;
2001: }
1.267 raeburn 2002: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
2003: $showtools = 1;
2004: }
2005: my (%changeHash,%changed);
1.204 raeburn 2006: $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
1.149 raeburn 2007: if ($userenv{'portfolioquota'} ne '') {
1.134 raeburn 2008: $oldportfolioquota = $userenv{'portfolioquota'};
1.149 raeburn 2009: if ($env{'form.customquota'} == 1) {
2010: if ($env{'form.portfolioquota'} eq '') {
2011: $newportfolioquota = 0;
2012: } else {
2013: $newportfolioquota = $env{'form.portfolioquota'};
2014: $newportfolioquota =~ s/[^\d\.]//g;
2015: }
1.204 raeburn 2016: if ($newportfolioquota != $oldportfolioquota) {
1.267 raeburn 2017: $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash);
1.134 raeburn 2018: }
1.149 raeburn 2019: } else {
1.267 raeburn 2020: $changed{'quota'} = "a_admin('',\%changeHash);
1.149 raeburn 2021: $newportfolioquota = $defquota;
1.204 raeburn 2022: $newisdefault = 1;
1.134 raeburn 2023: }
2024: } else {
1.204 raeburn 2025: $oldisdefault = 1;
1.149 raeburn 2026: $oldportfolioquota = $defquota;
2027: if ($env{'form.customquota'} == 1) {
2028: if ($env{'form.portfolioquota'} eq '') {
2029: $newportfolioquota = 0;
2030: } else {
2031: $newportfolioquota = $env{'form.portfolioquota'};
2032: $newportfolioquota =~ s/[^\d\.]//g;
2033: }
1.267 raeburn 2034: $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash);
1.149 raeburn 2035: } else {
2036: $newportfolioquota = $defquota;
1.204 raeburn 2037: $newisdefault = 1;
1.149 raeburn 2038: }
2039: }
1.204 raeburn 2040: if ($oldisdefault) {
2041: $olddefquotatext = &get_defaultquota_text($settingstatus);
2042: }
2043: if ($newisdefault) {
2044: $newdefquotatext = &get_defaultquota_text($settingstatus);
1.134 raeburn 2045: }
1.267 raeburn 2046:
2047: foreach my $tool (@usertools) {
2048: if ($userenv{'tools.'.$tool} ne '') {
2049: $oldaccess{$tool} = &mt('custom');
2050: if ($userenv{'tools_'.$tool}) {
2051: $oldaccesstext{$tool} = &mt("availability set to 'on'");
2052: } else {
2053: $oldaccesstext{$tool} = &mt("availability set to 'off'");
2054: }
2055: $changeHash{'tools.'.$tool} = $userenv{'tools.'.$tool};
2056: if ($env{'form.custom'.$tool} == 1) {
2057: if ($env{'form.tools_'.$tool} ne $userenv{'tools.'.$tool}) {
2058: $changed{$tool} = &tool_admin($tool,$env{'form.tools_'.$tool},
2059: \%changeHash);
2060: if ($changed{$tool}) {
2061: $newaccess{$tool} = &mt('custom');
2062: if ($env{'form.tools_'.$tool}) {
2063: $newaccesstext{$tool} = &mt("availability set to 'on'");
2064: } else {
2065: $newaccesstext{$tool} = &mt("availability set to 'off'");
2066: }
2067: } else {
2068: $newaccess{$tool} = $oldaccess{$tool};
2069: if ($userenv{'tools.'.$tool}) {
2070: $newaccesstext{$tool} = &mt("availability set to 'on'");
2071: } else {
2072: $newaccesstext{$tool} = &mt("availability set to 'off'");
2073: }
2074: }
2075: } else {
2076: $newaccess{$tool} = $oldaccess{$tool};
2077: $newaccesstext{$tool} = $oldaccesstext{$tool};
2078: }
2079: } else {
2080: $changed{$tool} = &tool_admin($tool,'',\%changeHash);
2081: if ($changed{$tool}) {
2082: $newaccess{$tool} = &mt('default');
2083: } else {
2084: $newaccess{$tool} = $oldaccess{$tool};
2085: if ($userenv{'tools.'.$tool}) {
2086: $newaccesstext{$tool} = &mt("availability set to 'on'");
2087: } else {
2088: $newaccesstext{$tool} = &mt("availability set to 'off'");
2089: }
2090: }
2091: }
2092: } else {
2093: $oldaccess{$tool} = &mt('default');
2094: if ($env{'form.custom'.$tool} == 1) {
2095: $changed{$tool} = &tool_admin($tool,$env{'form.tools_'.$tool},
2096: \%changeHash);
2097: if ($changed{$tool}) {
2098: $newaccess{$tool} = &mt('custom');
2099: if ($env{'form.tools_'.$tool}) {
2100: $newaccesstext{$tool} = &mt("availability set to 'on'");
2101: } else {
2102: $newaccesstext{$tool} = &mt("availability set to 'off'");
2103: }
2104: } else {
2105: $newaccess{$tool} = $oldaccess{$tool};
2106: }
2107: } else {
2108: $newaccess{$tool} = $oldaccess{$tool};
2109: }
2110: }
2111: }
2112:
1.206 raeburn 2113: if ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
2114: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
2115: $env{'form.clastname'} ne $userenv{'lastname'} ||
2116: $env{'form.cgeneration'} ne $userenv{'generation'} ||
2117: $env{'form.cid'} ne $userenv{'id'} ||
2118: $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} ) {
1.134 raeburn 2119: $namechanged = 1;
2120: }
1.267 raeburn 2121: if (($namechanged) || (keys(%changed) > 0)) {
1.101 albertel 2122: $changeHash{'firstname'} = $env{'form.cfirstname'};
2123: $changeHash{'middlename'} = $env{'form.cmiddlename'};
2124: $changeHash{'lastname'} = $env{'form.clastname'};
2125: $changeHash{'generation'} = $env{'form.cgeneration'};
1.196 raeburn 2126: $changeHash{'id'} = $env{'form.cid'};
1.174 raeburn 2127: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1.267 raeburn 2128: my ($chgresult,$namechgresult);
2129: if (keys(%changed) > 0) {
2130: $chgresult =
1.204 raeburn 2131: &Apache::lonnet::put('environment',\%changeHash,
2132: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 2133: if ($chgresult eq 'ok') {
2134: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
2135: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.268.2.3 raeburn 2136: my %newenvhash;
2137: foreach my $key (keys(%changed)) {
2138: if ($key ne 'quota') {
2139: $newenvhash{'environment.tools.'.$key} =
2140: $changeHash{'tools.'.$key};
2141: $newenvhash{'environment.availabletools.'.$key} =
2142: $changeHash{'tools.'.$key};
2143: }
2144: }
2145: if (keys(%newenvhash)) {
2146: &Apache::lonnet::appenv(\%newenvhash);
2147: }
1.267 raeburn 2148: }
2149: }
1.204 raeburn 2150: }
2151: if ($namechanged) {
2152: # Make the change
2153: $namechgresult =
2154: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
2155: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
2156: $changeHash{'firstname'},$changeHash{'middlename'},
2157: $changeHash{'lastname'},$changeHash{'generation'},
2158: $changeHash{'id'},undef,$changeHash{'permanentemail'});
1.220 raeburn 2159: %userupdate = (
2160: lastname => $env{'form.clastname'},
2161: middlename => $env{'form.cmiddlename'},
2162: firstname => $env{'form.cfirstname'},
2163: generation => $env{'form.cgeneration'},
2164: id => $env{'form.cid'},
2165: );
1.204 raeburn 2166: }
2167: if (($namechanged && $namechgresult eq 'ok') ||
1.267 raeburn 2168: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 2169: # Tell the user we changed the name
1.73 sakharuk 2170: my %lt=&Apache::lonlocal::texthash(
1.267 raeburn 2171: 'uic' => "User Information Changed",
2172: 'frst' => "First",
2173: 'mddl' => "Middle",
2174: 'lst' => "Last",
2175: 'gen' => "Generation",
2176: 'id' => "Student/Employee ID",
2177: 'mail' => "Permanent E-mail",
2178: 'disk' => "Disk space allocated to portfolio files",
2179: 'blog' => "Blog Availability",
2180: 'aboutme' => "Home Page Availability",
2181: 'portfolio' => "Portfolio Availability",
2182: 'prvs' => "Previous",
2183: 'chto' => "Changed To"
1.73 sakharuk 2184: );
1.201 raeburn 2185: $r->print('<h4>'.$lt{'uic'}.'</h4>'.
2186: &Apache::loncommon::start_data_table().
2187: &Apache::loncommon::start_data_table_header_row());
1.28 matthew 2188: $r->print(<<"END");
1.201 raeburn 2189: <th> </th>
1.73 sakharuk 2190: <th>$lt{'frst'}</th>
2191: <th>$lt{'mddl'}</th>
2192: <th>$lt{'lst'}</th>
1.134 raeburn 2193: <th>$lt{'gen'}</th>
1.196 raeburn 2194: <th>$lt{'id'}</th>
1.173 raeburn 2195: <th>$lt{'mail'}</th>
1.201 raeburn 2196: END
1.220 raeburn 2197: if ($showquota) {
2198: $r->print("
2199: <th>$lt{'disk'}</th>\n");
2200: }
1.267 raeburn 2201: if ($showtools) {
2202: foreach my $item (@usertools) {
2203: $r->print("
2204: <th>$lt{$item}</th>\n");
2205: }
2206: }
1.201 raeburn 2207: $r->print(&Apache::loncommon::end_data_table_header_row().
2208: &Apache::loncommon::start_data_table_row());
2209: $r->print(<<"END");
2210: <td><b>$lt{'prvs'}</b></td>
1.28 matthew 2211: <td>$userenv{'firstname'} </td>
2212: <td>$userenv{'middlename'} </td>
2213: <td>$userenv{'lastname'} </td>
1.134 raeburn 2214: <td>$userenv{'generation'} </td>
1.196 raeburn 2215: <td>$userenv{'id'}</td>
1.160 raeburn 2216: <td>$userenv{'permanentemail'} </td>
1.201 raeburn 2217: END
1.220 raeburn 2218: if ($showquota) {
2219: $r->print("
2220: <td>$oldportfolioquota Mb $olddefquotatext </td>\n");
2221: }
1.267 raeburn 2222: if ($showtools) {
2223: foreach my $item (@usertools) {
2224: $r->print("
2225: <td>$oldaccess{$item} $oldaccesstext{$item} </td>\n");
2226: }
2227: }
1.201 raeburn 2228: $r->print(&Apache::loncommon::end_data_table_row().
2229: &Apache::loncommon::start_data_table_row());
2230: $r->print(<<"END");
1.267 raeburn 2231: <td><span class="LC_nobreak"><b>$lt{'chto'}</b></span></td>
1.101 albertel 2232: <td>$env{'form.cfirstname'} </td>
2233: <td>$env{'form.cmiddlename'} </td>
2234: <td>$env{'form.clastname'} </td>
1.134 raeburn 2235: <td>$env{'form.cgeneration'} </td>
1.196 raeburn 2236: <td>$env{'form.cid'} </td>
1.160 raeburn 2237: <td>$env{'form.cpermanentemail'} </td>
1.28 matthew 2238: END
1.220 raeburn 2239: if ($showquota) {
2240: $r->print("
2241: <td>$newportfolioquota Mb $newdefquotatext </td>\n");
2242: }
1.267 raeburn 2243: if ($showtools) {
2244: foreach my $item (@usertools) {
2245: $r->print("
2246: <td>$newaccess{$item} $newaccesstext{$item} </td>\n");
2247: }
2248: }
1.201 raeburn 2249: $r->print(&Apache::loncommon::end_data_table_row().
1.206 raeburn 2250: &Apache::loncommon::end_data_table().'<br />');
1.203 raeburn 2251: if ($env{'form.cid'} ne $userenv{'id'}) {
2252: &Apache::lonnet::idput($env{'form.ccdomain'},
2253: ($env{'form.ccuname'} => $env{'form.cid'}));
2254: if (($recurseid) &&
2255: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
2256: my $idresult =
2257: &Apache::lonuserutils::propagate_id_change(
2258: $env{'form.ccuname'},$env{'form.ccdomain'},
2259: \%userupdate);
2260: $r->print('<br />'.$idresult.'<br />');
2261: }
1.196 raeburn 2262: }
1.149 raeburn 2263: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
2264: ($env{'form.ccuname'} eq $env{'user.name'})) {
2265: my %newenvhash;
2266: foreach my $key (keys(%changeHash)) {
2267: $newenvhash{'environment.'.$key} = $changeHash{$key};
2268: }
1.238 raeburn 2269: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 2270: }
1.28 matthew 2271: } else { # error occurred
1.188 raeburn 2272: $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
2273: $env{'form.ccuname'}.' '.&mt('in domain').' '.
1.206 raeburn 2274: $env{'form.ccdomain'}.'</span><br />');
1.28 matthew 2275: }
1.101 albertel 2276: } else { # End of if ($env ... ) logic
1.267 raeburn 2277: # They did not want to change the users name, quota or tool availability,
2278: # but we can still tell them what the name and quota and availabilities are
1.73 sakharuk 2279: my %lt=&Apache::lonlocal::texthash(
1.267 raeburn 2280: 'id' => "Student/Employee ID",
2281: 'mail' => "Permanent e-mail",
2282: 'disk' => "Disk space allocated to user's portfolio files",
2283: 'blog' => "Blog Availability",
2284: 'aboutme' => "Home Page Availability",
2285: 'portfolio' => "Portfolio Availability",
1.73 sakharuk 2286: );
1.134 raeburn 2287: $r->print(<<"END");
1.196 raeburn 2288: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
1.28 matthew 2289: END
1.204 raeburn 2290: if ($userenv{'permanentemail'} ne '') {
2291: $r->print('<br />['.$lt{'mail'}.': '.
2292: $userenv{'permanentemail'}.']');
1.134 raeburn 2293: }
1.267 raeburn 2294: if ($showtools) {
2295: foreach my $item (@usertools) {
2296: $r->print('<br />['.$lt{$item}.': '.$newaccess{$item}.' '.
2297: $newaccesstext{$item}.']'."\n");
2298: }
2299: }
1.220 raeburn 2300: if ($showquota) {
1.267 raeburn 2301: $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '.
1.220 raeburn 2302: $olddefquotatext.']');
2303: }
2304: $r->print('</h4>');
1.28 matthew 2305: }
1.206 raeburn 2306: if (@mod_disallowed) {
2307: my ($rolestr,$contextname);
2308: if (@longroles > 0) {
2309: $rolestr = join(', ',@longroles);
2310: } else {
2311: $rolestr = &mt('No roles');
2312: }
2313: if ($context eq 'course') {
2314: $contextname = &mt('course');
2315: } elsif ($context eq 'author') {
2316: $contextname = &mt('co-author');
2317: }
2318: $r->print(&mt('The following fields were not updated: ').'<ul>');
2319: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2320: foreach my $field (@mod_disallowed) {
2321: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
2322: }
1.207 raeburn 2323: $r->print('</ul>');
2324: if (@mod_disallowed == 1) {
2325: $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));
2326: } else {
2327: $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));
2328: }
2329: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'.
2330: &mt('Contact your <a href="[_1]">helpdesk</a> for more information.',"javascript:helpMenu('display')").'<br />');
1.206 raeburn 2331: }
1.259 bisitz 2332: $r->print('<span class="LC_warning">'
2333: .$no_forceid_alert
2334: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
2335: .'</span>');
1.4 www 2336: }
1.220 raeburn 2337: if ($env{'form.action'} eq 'singlestudent') {
1.239 raeburn 2338: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context);
2339: $r->print('<p><a href="javascript:backPage(document.userupdate)">'.
2340: &mt('Enroll Another Student').'</a></p>');
1.220 raeburn 2341: } else {
1.239 raeburn 2342: my @rolechanges = &update_roles($r,$context);
1.225 raeburn 2343: if ($namechanged) {
1.220 raeburn 2344: if ($context eq 'course') {
2345: if (@userroles > 0) {
1.225 raeburn 2346: if ((@rolechanges == 0) ||
2347: (!(grep(/^st$/,@rolechanges)))) {
2348: if (grep(/^st$/,@userroles)) {
2349: my $classlistupdated =
2350: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 2351: $cnum,$env{'form.ccdomain'},
2352: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 2353: }
1.220 raeburn 2354: }
2355: }
2356: }
2357: }
1.226 raeburn 2358: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 2359: $env{'form.ccdomain'});
2360: if ($env{'form.popup'}) {
2361: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
2362: } else {
1.246 bisitz 2363: $r->print('<p><a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
2364: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>'
2365: .(' 'x5).'<a href="javascript:backPage(document.userupdate)">'
2366: .&mt('Create/Modify Another User').'</a></p>');
1.233 raeburn 2367: }
1.220 raeburn 2368: }
2369: $r->print(&Apache::loncommon::end_page());
2370: }
2371:
2372: sub update_roles {
1.239 raeburn 2373: my ($r,$context) = @_;
1.4 www 2374: my $now=time;
1.225 raeburn 2375: my @rolechanges;
1.220 raeburn 2376: my %disallowed;
1.73 sakharuk 2377: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 2378: foreach my $key (keys (%env)) {
2379: next if (! $env{$key});
1.190 raeburn 2380: next if ($key eq 'form.action');
1.27 matthew 2381: # Revoke roles
1.135 raeburn 2382: if ($key=~/^form\.rev/) {
2383: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 2384: # Revoke standard role
1.170 albertel 2385: my ($scope,$role) = ($1,$2);
2386: my $result =
2387: &Apache::lonnet::revokerole($env{'form.ccdomain'},
2388: $env{'form.ccuname'},
1.239 raeburn 2389: $scope,$role,'','',$context);
1.170 albertel 2390: $r->print(&mt('Revoking [_1] in [_2]: [_3]',
2391: $role,$scope,'<b>'.$result.'</b>').'<br />');
2392: if ($role eq 'st') {
1.202 raeburn 2393: my $result =
1.198 raeburn 2394: &Apache::lonuserutils::classlist_drop($scope,
2395: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 2396: $now);
1.170 albertel 2397: $r->print($result);
1.53 www 2398: }
1.225 raeburn 2399: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2400: push(@rolechanges,$role);
2401: }
1.196 raeburn 2402: }
1.195 raeburn 2403: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 2404: # Revoke custom role
1.113 raeburn 2405: $r->print(&mt('Revoking custom role:').
1.139 albertel 2406: ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
1.101 albertel 2407: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
1.239 raeburn 2408: $env{'form.ccuname'},$1,$2,$3,$4,'','',$context).
1.102 albertel 2409: '</b><br />');
1.225 raeburn 2410: if (!grep(/^cr$/,@rolechanges)) {
2411: push(@rolechanges,'cr');
2412: }
1.64 www 2413: }
1.135 raeburn 2414: } elsif ($key=~/^form\.del/) {
2415: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 2416: # Delete standard role
1.170 albertel 2417: my ($scope,$role) = ($1,$2);
2418: my $result =
2419: &Apache::lonnet::assignrole($env{'form.ccdomain'},
2420: $env{'form.ccuname'},
1.239 raeburn 2421: $scope,$role,$now,0,1,'',
2422: $context);
1.170 albertel 2423: $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
2424: '<b>'.$result.'</b>').'<br />');
2425: if ($role eq 'st') {
1.202 raeburn 2426: my $result =
1.198 raeburn 2427: &Apache::lonuserutils::classlist_drop($scope,
2428: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 2429: $now);
1.170 albertel 2430: $r->print($result);
1.81 albertel 2431: }
1.225 raeburn 2432: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2433: push(@rolechanges,$role);
2434: }
1.116 raeburn 2435: }
1.139 albertel 2436: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 2437: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
2438: # Delete custom role
1.170 albertel 2439: $r->print(&mt('Deleting custom role [_1] by [_2]:[_3] in [_4]',
1.116 raeburn 2440: $rolename,$rnam,$rdom,$url).': <b>'.
2441: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
2442: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
1.240 raeburn 2443: 0,1,$context).'</b><br />');
1.225 raeburn 2444: if (!grep(/^cr$/,@rolechanges)) {
2445: push(@rolechanges,'cr');
2446: }
1.116 raeburn 2447: }
1.135 raeburn 2448: } elsif ($key=~/^form\.ren/) {
1.101 albertel 2449: my $udom = $env{'form.ccdomain'};
2450: my $uname = $env{'form.ccuname'};
1.116 raeburn 2451: # Re-enable standard role
1.135 raeburn 2452: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 2453: my $url = $1;
2454: my $role = $2;
2455: my $logmsg;
2456: my $output;
2457: if ($role eq 'st') {
1.141 albertel 2458: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.129 albertel 2459: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.220 raeburn 2460: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 2461: if ($result eq 'refused' && $logmsg) {
2462: $output = $logmsg;
2463: } else {
2464: $output = "Error: $result\n";
2465: }
1.89 raeburn 2466: } else {
2467: $output = &mt('Assigning').' '.$role.' in '.$url.
2468: &mt('starting').' '.localtime($now).
2469: ': <br />'.$logmsg.'<br />'.
2470: &mt('Add to classlist').': <b>ok</b><br />';
2471: }
2472: }
2473: } else {
1.101 albertel 2474: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 2475: $env{'form.ccuname'},$url,$role,0,$now,'','',
2476: $context);
1.266 bisitz 2477: $output = &mt('Re-enabling [_1] in [_2]: [_3]',
2478: $role,$url,'<b>'.$result.'</b>').'<br />';
1.27 matthew 2479: }
1.89 raeburn 2480: $r->print($output);
1.225 raeburn 2481: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2482: push(@rolechanges,$role);
2483: }
1.113 raeburn 2484: }
1.116 raeburn 2485: # Re-enable custom role
1.139 albertel 2486: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 2487: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
2488: my $result = &Apache::lonnet::assigncustomrole(
2489: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 2490: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.268 raeburn 2491: $r->print(&mt('Re-enabling custom role [_1] by [_2]:[_3] in [_4] : [_5]',
1.266 bisitz 2492: $rolename,$rnam,$rdom,$url,'<b>'.$result.'</b>').'<br />');
1.225 raeburn 2493: if (!grep(/^cr$/,@rolechanges)) {
2494: push(@rolechanges,'cr');
2495: }
1.116 raeburn 2496: }
1.135 raeburn 2497: } elsif ($key=~/^form\.act/) {
1.101 albertel 2498: my $udom = $env{'form.ccdomain'};
2499: my $uname = $env{'form.ccuname'};
1.141 albertel 2500: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 2501: # Activate a custom role
1.83 albertel 2502: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
2503: my $url='/'.$one.'/'.$two;
2504: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 2505:
1.101 albertel 2506: my $start = ( $env{'form.start_'.$full} ?
2507: $env{'form.start_'.$full} :
1.88 raeburn 2508: $now );
1.101 albertel 2509: my $end = ( $env{'form.end_'.$full} ?
2510: $env{'form.end_'.$full} :
1.88 raeburn 2511: 0 );
2512:
2513: # split multiple sections
2514: my %sections = ();
1.101 albertel 2515: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 2516: if ($num_sections == 0) {
1.240 raeburn 2517: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 2518: } else {
1.114 albertel 2519: my %curr_groups =
1.117 raeburn 2520: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 2521: foreach my $sec (sort {$a cmp $b} keys %sections) {
2522: if (($sec eq 'none') || ($sec eq 'all') ||
2523: exists($curr_groups{$sec})) {
2524: $disallowed{$sec} = $url;
2525: next;
2526: }
2527: my $securl = $url.'/'.$sec;
1.240 raeburn 2528: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 2529: }
2530: }
1.225 raeburn 2531: if (!grep(/^cr$/,@rolechanges)) {
2532: push(@rolechanges,'cr');
2533: }
1.142 raeburn 2534: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 2535: # Activate roles for sections with 3 id numbers
2536: # set start, end times, and the url for the class
1.83 albertel 2537: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 2538: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
2539: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 2540: $now );
1.101 albertel 2541: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
2542: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 2543: 0 );
1.83 albertel 2544: my $url='/'.$one.'/'.$two;
1.88 raeburn 2545: my $type = 'three';
2546: # split multiple sections
2547: my %sections = ();
1.101 albertel 2548: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 2549: if ($num_sections == 0) {
1.240 raeburn 2550: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 2551: } else {
1.114 albertel 2552: my %curr_groups =
1.117 raeburn 2553: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 2554: my $emptysec = 0;
2555: foreach my $sec (sort {$a cmp $b} keys %sections) {
2556: $sec =~ s/\W//g;
1.113 raeburn 2557: if ($sec ne '') {
2558: if (($sec eq 'none') || ($sec eq 'all') ||
2559: exists($curr_groups{$sec})) {
2560: $disallowed{$sec} = $url;
2561: next;
2562: }
1.88 raeburn 2563: my $securl = $url.'/'.$sec;
1.240 raeburn 2564: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context));
1.88 raeburn 2565: } else {
2566: $emptysec = 1;
2567: }
2568: }
2569: if ($emptysec) {
1.240 raeburn 2570: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 2571: }
1.225 raeburn 2572: }
2573: if (!grep(/^\Q$three\E$/,@rolechanges)) {
2574: push(@rolechanges,$three);
2575: }
1.135 raeburn 2576: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 2577: # Activate roles for sections with two id numbers
2578: # set start, end times, and the url for the class
1.101 albertel 2579: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
2580: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 2581: $now );
1.101 albertel 2582: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
2583: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 2584: 0 );
1.225 raeburn 2585: my $one = $1;
2586: my $two = $2;
2587: my $url='/'.$one.'/';
1.88 raeburn 2588: # split multiple sections
2589: my %sections = ();
1.225 raeburn 2590: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 2591: if ($num_sections == 0) {
1.240 raeburn 2592: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 2593: } else {
2594: my $emptysec = 0;
2595: foreach my $sec (sort {$a cmp $b} keys %sections) {
2596: if ($sec ne '') {
2597: my $securl = $url.'/'.$sec;
1.240 raeburn 2598: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 2599: } else {
2600: $emptysec = 1;
2601: }
2602: }
2603: if ($emptysec) {
1.240 raeburn 2604: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 2605: }
2606: }
1.225 raeburn 2607: if (!grep(/^\Q$two\E$/,@rolechanges)) {
2608: push(@rolechanges,$two);
2609: }
1.64 www 2610: } else {
1.190 raeburn 2611: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 2612: }
1.113 raeburn 2613: foreach my $key (sort(keys(%disallowed))) {
2614: if (($key eq 'none') || ($key eq 'all')) {
2615: $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
2616: } else {
2617: $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));
2618: }
2619: $r->print(' '.&mt('Please <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />');
2620: }
2621: }
1.101 albertel 2622: } # End of foreach (keys(%env))
1.75 www 2623: # Flush the course logs so reverse user roles immediately updated
2624: &Apache::lonnet::flushcourselogs();
1.225 raeburn 2625: if (@rolechanges == 0) {
1.193 raeburn 2626: $r->print(&mt('No roles to modify'));
2627: }
1.225 raeburn 2628: return @rolechanges;
1.220 raeburn 2629: }
2630:
2631: sub enroll_single_student {
1.239 raeburn 2632: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context) = @_;
1.220 raeburn 2633: $r->print('<h3>'.&mt('Enrolling Student').'</h3>');
2634:
2635: # Remove non alphanumeric values from section
2636: $env{'form.sections'}=~s/\W//g;
2637:
2638: # Clean out any old student roles the user has in this class.
2639: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
2640: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
2641: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
2642: my $enroll_result =
2643: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
2644: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
2645: $env{'form.cmiddlename'},$env{'form.clastname'},
2646: $env{'form.generation'},$env{'form.sections'},$enddate,
1.239 raeburn 2647: $startdate,'manual',undef,$env{'request.course.id'},'',$context);
1.220 raeburn 2648: if ($enroll_result =~ /^ok/) {
2649: $r->print(&mt('<b>[_1]</b> enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'}));
2650: if ($env{'form.sections'} ne '') {
2651: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
2652: }
2653: my ($showstart,$showend);
2654: if ($startdate <= $now) {
2655: $showstart = &mt('Access starts immediately');
2656: } else {
2657: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
2658: }
2659: if ($enddate == 0) {
2660: $showend = &mt('ends: no ending date');
2661: } else {
2662: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
2663: }
2664: $r->print('.<br />'.$showstart.'; '.$showend);
2665: if ($startdate <= $now && !$newuser) {
2666: $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>");
2667: }
2668: } else {
2669: $r->print(&mt('unable to enroll').": ".$enroll_result);
2670: }
2671: return;
1.188 raeburn 2672: }
2673:
1.204 raeburn 2674: sub get_defaultquota_text {
2675: my ($settingstatus) = @_;
2676: my $defquotatext;
2677: if ($settingstatus eq '') {
2678: $defquotatext = &mt('(default)');
2679: } else {
2680: my ($usertypes,$order) =
2681: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
2682: if ($usertypes->{$settingstatus} eq '') {
2683: $defquotatext = &mt('(default)');
2684: } else {
2685: $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
2686: }
2687: }
2688: return $defquotatext;
2689: }
2690:
1.188 raeburn 2691: sub update_result_form {
2692: my ($uhome) = @_;
2693: my $outcome =
2694: '<form name="userupdate" method="post" />'."\n";
1.160 raeburn 2695: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 2696: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2697: }
1.207 raeburn 2698: if ($env{'form.origname'} ne '') {
2699: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
2700: }
1.160 raeburn 2701: foreach my $item ('sortby','seluname','seludom') {
2702: if (exists($env{'form.'.$item})) {
1.188 raeburn 2703: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2704: }
2705: }
1.188 raeburn 2706: if ($uhome eq 'no_host') {
2707: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
2708: }
2709: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
2710: '<input type ="hidden" name="currstate" value="" />'."\n".
1.220 raeburn 2711: '<input type ="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 2712: '</form>';
2713: return $outcome;
1.4 www 2714: }
2715:
1.149 raeburn 2716: sub quota_admin {
2717: my ($setquota,$changeHash) = @_;
2718: my $quotachanged;
2719: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
2720: # Current user has quota modification privileges
1.267 raeburn 2721: if (ref($changeHash) eq 'HASH') {
2722: $quotachanged = 1;
2723: $changeHash->{'portfolioquota'} = $setquota;
2724: }
1.149 raeburn 2725: }
2726: return $quotachanged;
2727: }
2728:
1.267 raeburn 2729: sub tool_admin {
2730: my ($tool,$settool,$changeHash) = @_;
2731: my $toolchanged;
2732: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
2733: # Current user has quota modification privileges
2734: if (ref($changeHash) eq 'HASH') {
2735: $toolchanged = 1;
2736: $changeHash->{'tools.'.$tool} = $settool;
2737: }
2738: }
2739: return $toolchanged;
2740: }
2741:
1.88 raeburn 2742: sub build_roles {
1.89 raeburn 2743: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 2744: my $num_sections = 0;
2745: if ($sectionstr=~ /,/) {
2746: my @secnums = split/,/,$sectionstr;
1.89 raeburn 2747: if ($role eq 'st') {
2748: $secnums[0] =~ s/\W//g;
2749: $$sections{$secnums[0]} = 1;
2750: $num_sections = 1;
2751: } else {
2752: foreach my $sec (@secnums) {
2753: $sec =~ ~s/\W//g;
1.150 banghart 2754: if (!($sec eq "")) {
1.89 raeburn 2755: if (exists($$sections{$sec})) {
2756: $$sections{$sec} ++;
2757: } else {
2758: $$sections{$sec} = 1;
2759: $num_sections ++;
2760: }
1.88 raeburn 2761: }
2762: }
2763: }
2764: } else {
2765: $sectionstr=~s/\W//g;
2766: unless ($sectionstr eq '') {
2767: $$sections{$sectionstr} = 1;
2768: $num_sections ++;
2769: }
2770: }
1.129 albertel 2771:
1.88 raeburn 2772: return $num_sections;
2773: }
2774:
1.58 www 2775: # ========================================================== Custom Role Editor
2776:
2777: sub custom_role_editor {
1.160 raeburn 2778: my ($r) = @_;
1.101 albertel 2779: my $rolename=$env{'form.rolename'};
1.58 www 2780:
1.59 www 2781: if ($rolename eq 'make new role') {
1.101 albertel 2782: $rolename=$env{'form.newrolename'};
1.59 www 2783: }
2784:
1.63 www 2785: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 2786:
1.190 raeburn 2787: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.58 www 2788: &print_username_entry_form($r);
2789: return;
2790: }
1.153 banghart 2791: # ------------------------------------------------------- What can be assigned?
2792: my %full=();
2793: my %courselevel=();
2794: my %courselevelcurrent=();
1.61 www 2795: my $syspriv='';
2796: my $dompriv='';
2797: my $coursepriv='';
1.153 banghart 2798: my $body_top;
1.150 banghart 2799: my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
1.59 www 2800: my ($rdummy,$roledef)=
2801: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 2802: # ------------------------------------------------------- Does this role exist?
1.153 banghart 2803: $body_top .= '<h2>';
1.59 www 2804: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 2805: $body_top .= &mt('Existing Role').' "';
1.61 www 2806: # ------------------------------------------------- Get current role privileges
2807: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 2808: } else {
1.153 banghart 2809: $body_top .= &mt('New Role').' "';
1.59 www 2810: $roledef='';
2811: }
1.153 banghart 2812: $body_top .= $rolename.'"</h2>';
1.135 raeburn 2813: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2814: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2815: if (!$restrict) { $restrict='F'; }
1.60 www 2816: $courselevel{$priv}=$restrict;
1.61 www 2817: if ($coursepriv=~/\:$priv/) {
2818: $courselevelcurrent{$priv}=1;
2819: }
1.60 www 2820: $full{$priv}=1;
2821: }
2822: my %domainlevel=();
1.61 www 2823: my %domainlevelcurrent=();
1.135 raeburn 2824: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2825: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2826: if (!$restrict) { $restrict='F'; }
1.60 www 2827: $domainlevel{$priv}=$restrict;
1.61 www 2828: if ($dompriv=~/\:$priv/) {
2829: $domainlevelcurrent{$priv}=1;
2830: }
1.60 www 2831: $full{$priv}=1;
2832: }
1.61 www 2833: my %systemlevel=();
2834: my %systemlevelcurrent=();
1.135 raeburn 2835: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2836: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2837: if (!$restrict) { $restrict='F'; }
1.61 www 2838: $systemlevel{$priv}=$restrict;
2839: if ($syspriv=~/\:$priv/) {
2840: $systemlevelcurrent{$priv}=1;
2841: }
2842: $full{$priv}=1;
2843: }
1.160 raeburn 2844: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 2845: my $button_code = "\n";
1.153 banghart 2846: my $head_script = "\n";
2847: $head_script .= '<script type="text/javascript">'."\n";
1.154 banghart 2848: my @template_roles = ("cc","in","ta","ep","st");
2849: foreach my $role (@template_roles) {
2850: $head_script .= &make_script_template($role);
1.264 bisitz 2851: $button_code .= &make_button_code($role).' ';
1.154 banghart 2852: }
1.160 raeburn 2853: $head_script .= "\n".$jsback."\n".'</script>'."\n";
1.153 banghart 2854: $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
1.160 raeburn 2855: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 2856: ({href=>"javascript:backPage(document.form1,'pickrole','')",
2857: text=>"Pick custom role",
1.160 raeburn 2858: faq=>282,bug=>'Instructor Interface',},
2859: {href=>"javascript:backPage(document.form1,'','')",
2860: text=>"Edit custom role",
2861: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 2862: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
2863: 'Course_Editing_Custom_Roles'));
1.160 raeburn 2864:
1.153 banghart 2865: $r->print($body_top);
1.73 sakharuk 2866: my %lt=&Apache::lonlocal::texthash(
2867: 'prv' => "Privilege",
1.131 raeburn 2868: 'crl' => "Course Level",
1.73 sakharuk 2869: 'dml' => "Domain Level",
1.150 banghart 2870: 'ssl' => "System Level");
1.264 bisitz 2871:
2872: $r->print('<div>'
2873: .'<form action=""><fieldset>'
2874: .'<legend>'.&mt('Select a Template').'</legend>'
2875: .$button_code
2876: .'</fieldset></form>'
2877: .'</div>'
2878: );
2879:
1.61 www 2880: $r->print(<<ENDCCF);
1.160 raeburn 2881: <form name="form1" method="post">
1.61 www 2882: <input type="hidden" name="phase" value="set_custom_roles" />
2883: <input type="hidden" name="rolename" value="$rolename" />
2884: ENDCCF
1.135 raeburn 2885: $r->print(&Apache::loncommon::start_data_table().
2886: &Apache::loncommon::start_data_table_header_row().
2887: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
2888: '</th><th>'.$lt{'ssl'}.'</th>'.
2889: &Apache::loncommon::end_data_table_header_row());
1.119 raeburn 2890: foreach my $priv (sort keys %full) {
2891: my $privtext = &Apache::lonnet::plaintext($priv);
1.135 raeburn 2892: $r->print(&Apache::loncommon::start_data_table_row().
2893: '<td>'.$privtext.'</td><td>'.
1.150 banghart 2894: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c" '.
1.119 raeburn 2895: ($courselevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2896: '</td><td>'.
1.150 banghart 2897: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d" '.
1.119 raeburn 2898: ($domainlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2899: '</td><td>'.
1.150 banghart 2900: ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s" '.
1.119 raeburn 2901: ($systemlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.135 raeburn 2902: '</td>'.
2903: &Apache::loncommon::end_data_table_row());
1.60 www 2904: }
1.135 raeburn 2905: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 2906: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 2907: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 2908: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 2909: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
2910: '<input type="submit" value="'.&mt('Define Role').'" /></form>'.
1.110 albertel 2911: &Apache::loncommon::end_page());
1.61 www 2912: }
1.153 banghart 2913: # --------------------------------------------------------
2914: sub make_script_template {
2915: my ($role) = @_;
2916: my %full_c=();
2917: my %full_d=();
2918: my %full_s=();
2919: my $return_script;
2920: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2921: my ($priv,$restrict)=split(/\&/,$item);
2922: $full_c{$priv}=1;
2923: }
2924: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2925: my ($priv,$restrict)=split(/\&/,$item);
2926: $full_d{$priv}=1;
2927: }
1.154 banghart 2928: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.153 banghart 2929: my ($priv,$restrict)=split(/\&/,$item);
2930: $full_s{$priv}=1;
2931: }
2932: $return_script .= 'function set_'.$role.'() {'."\n";
2933: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
2934: my %role_c;
1.155 banghart 2935: foreach my $priv (@temp) {
1.153 banghart 2936: my ($priv_item, $dummy) = split(/\&/,$priv);
2937: $role_c{$priv_item} = 1;
2938: }
1.268.2.2 raeburn 2939: my %role_d;
2940: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
2941: foreach my $priv(@temp) {
2942: my ($priv_item, $dummy) = split(/\&/,$priv);
2943: $role_d{$priv_item} = 1;
2944: }
2945: my %role_s;
2946: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
2947: foreach my $priv(@temp) {
2948: my ($priv_item, $dummy) = split(/\&/,$priv);
2949: $role_s{$priv_item} = 1;
2950: }
1.153 banghart 2951: foreach my $priv_item (keys(%full_c)) {
2952: my ($priv, $dummy) = split(/\&/,$priv_item);
1.268.2.2 raeburn 2953: if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
2954: (exists($role_s{$priv}))) {
1.153 banghart 2955: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
2956: } else {
2957: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
2958: }
2959: }
1.154 banghart 2960: foreach my $priv_item (keys(%full_d)) {
2961: my ($priv, $dummy) = split(/\&/,$priv_item);
1.268.2.2 raeburn 2962: if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
1.154 banghart 2963: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
2964: } else {
2965: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
2966: }
2967: }
2968: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 2969: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 2970: if (exists($role_s{$priv})) {
2971: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
2972: } else {
2973: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
2974: }
1.153 banghart 2975: }
2976: $return_script .= '}'."\n";
1.154 banghart 2977: return ($return_script);
2978: }
2979: # ----------------------------------------------------------
2980: sub make_button_code {
2981: my ($role) = @_;
2982: my $label = &Apache::lonnet::plaintext($role);
1.264 bisitz 2983: my $button_code = '<input type="button" onClick="set_'.$role.'()" value="'.$label.'" />';
1.154 banghart 2984: return ($button_code);
1.153 banghart 2985: }
1.61 www 2986: # ---------------------------------------------------------- Call to definerole
2987: sub set_custom_role {
1.240 raeburn 2988: my ($r,$context) = @_;
1.101 albertel 2989: my $rolename=$env{'form.rolename'};
1.63 www 2990: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 2991: if (!$rolename) {
1.190 raeburn 2992: &custom_role_editor($r);
1.61 www 2993: return;
2994: }
1.160 raeburn 2995: my ($jsback,$elements) = &crumb_utilities();
2996: my $jscript = '<script type="text/javascript">'.$jsback."\n".'</script>';
2997:
2998: $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
2999: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 3000: ({href=>"javascript:backPage(document.customresult,'pickrole','')",
3001: text=>"Pick custom role",
1.160 raeburn 3002: faq=>282,bug=>'Instructor Interface',},
3003: {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
3004: text=>"Edit custom role",
3005: faq=>282,bug=>'Instructor Interface',},
3006: {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
3007: text=>"Result",
3008: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 3009: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
3010: 'Course_Editing_Custom_Roles'));
1.160 raeburn 3011:
1.61 www 3012: my ($rdummy,$roledef)=
1.110 albertel 3013: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
3014:
1.61 www 3015: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 3016: $r->print('<h3>');
1.61 www 3017: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 3018: $r->print(&mt('Existing Role').' "');
1.61 www 3019: } else {
1.73 sakharuk 3020: $r->print(&mt('New Role').' "');
1.61 www 3021: $roledef='';
3022: }
1.188 raeburn 3023: $r->print($rolename.'"</h3>');
1.61 www 3024: # ------------------------------------------------------- What can be assigned?
3025: my $sysrole='';
3026: my $domrole='';
3027: my $courole='';
3028:
1.135 raeburn 3029: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
3030: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3031: if (!$restrict) { $restrict=''; }
3032: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 3033: $courole.=':'.$item;
1.61 www 3034: }
3035: }
3036:
1.135 raeburn 3037: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
3038: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3039: if (!$restrict) { $restrict=''; }
3040: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 3041: $domrole.=':'.$item;
1.61 www 3042: }
3043: }
3044:
1.135 raeburn 3045: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
3046: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 3047: if (!$restrict) { $restrict=''; }
3048: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 3049: $sysrole.=':'.$item;
1.61 www 3050: }
3051: }
1.63 www 3052: $r->print('<br />Defining Role: '.
1.61 www 3053: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 3054: if ($env{'request.course.id'}) {
3055: my $url='/'.$env{'request.course.id'};
1.63 www 3056: $url=~s/\_/\//g;
1.73 sakharuk 3057: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 3058: &Apache::lonnet::assigncustomrole($env{'user.domain'},
3059: $env{'user.name'},
1.63 www 3060: $url,
1.101 albertel 3061: $env{'user.domain'},
3062: $env{'user.name'},
1.240 raeburn 3063: $rolename,undef,undef,undef,$context));
1.63 www 3064: }
1.190 raeburn 3065: $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 3066: $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
1.110 albertel 3067: $r->print(&Apache::loncommon::end_page());
1.58 www 3068: }
3069:
1.2 www 3070: # ================================================================ Main Handler
3071: sub handler {
3072: my $r = shift;
3073: if ($r->header_only) {
1.68 www 3074: &Apache::loncommon::content_type($r,'text/html');
1.2 www 3075: $r->send_http_header;
3076: return OK;
3077: }
1.190 raeburn 3078: my $context;
3079: if ($env{'request.course.id'}) {
3080: $context = 'course';
3081: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 3082: $context = 'author';
1.190 raeburn 3083: } else {
3084: $context = 'domain';
3085: }
3086: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 3087: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
3088: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
1.190 raeburn 3089: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.202 raeburn 3090: if ($env{'form.action'} ne 'dateselect') {
3091: &Apache::lonhtmlcommon::add_breadcrumb
3092: ({href=>"/adm/createuser",
3093: text=>"User Management"});
3094: }
1.209 raeburn 3095: my ($permission,$allowed) =
3096: &Apache::lonuserutils::get_permission($context);
1.190 raeburn 3097: if (!$allowed) {
3098: $env{'user.error.msg'}=
3099: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
3100: "or view user status.";
3101: return HTTP_NOT_ACCEPTABLE;
3102: }
3103:
3104: &Apache::loncommon::content_type($r,'text/html');
3105: $r->send_http_header;
3106:
3107: # Main switch on form.action and form.state, as appropriate
3108: if (! exists($env{'form.action'})) {
3109: $r->print(&header());
3110: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.208 raeburn 3111: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 3112: $r->print(&Apache::loncommon::end_page());
3113: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
3114: $r->print(&header());
3115: &Apache::lonhtmlcommon::add_breadcrumb
3116: ({href=>'/adm/createuser?action=upload&state=',
3117: text=>"Upload Users List"});
3118: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Upload Users List',
1.224 raeburn 3119: 'Course_Create_Class_List'));
1.190 raeburn 3120: $r->print('<form name="studentform" method="post" '.
3121: 'enctype="multipart/form-data" '.
3122: ' action="/adm/createuser">'."\n");
3123: if (! exists($env{'form.state'})) {
3124: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
3125: } elsif ($env{'form.state'} eq 'got_file') {
1.221 raeburn 3126: &Apache::lonuserutils::print_upload_manager_form($r,$context,
3127: $permission);
1.190 raeburn 3128: } elsif ($env{'form.state'} eq 'enrolling') {
3129: if ($env{'form.datatoken'}) {
1.221 raeburn 3130: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission);
1.190 raeburn 3131: }
3132: } else {
3133: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
3134: }
3135: $r->print('</form>'.&Apache::loncommon::end_page());
1.213 raeburn 3136: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
3137: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 3138: my $phase = $env{'form.phase'};
3139: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 3140: &Apache::loncreateuser::restore_prev_selections();
3141: my $srch;
3142: foreach my $item (@search) {
3143: $srch->{$item} = $env{'form.'.$item};
3144: }
1.207 raeburn 3145: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
3146: ($phase eq 'createnewuser')) {
3147: if ($env{'form.phase'} eq 'createnewuser') {
3148: my $response;
3149: if ($env{'form.srchterm'} !~ /^$match_username$/) {
3150: my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
1.221 raeburn 3151: $env{'form.phase'} = '';
1.207 raeburn 3152: &print_username_entry_form($r,$context,$response,$srch);
3153: } else {
3154: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
3155: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
3156: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 3157: $srch,$response,$context,
3158: $permission);
1.207 raeburn 3159: }
3160: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 3161: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 3162: &user_search_result($context,$srch);
1.190 raeburn 3163: if ($env{'form.currstate'} eq 'modify') {
3164: $currstate = $env{'form.currstate'};
3165: }
3166: if ($currstate eq 'select') {
3167: &print_user_selection_page($r,$response,$srch,$results,
1.229 raeburn 3168: \@search,$context);
1.190 raeburn 3169: } elsif ($currstate eq 'modify') {
3170: my ($ccuname,$ccdomain);
3171: if (($srch->{'srchby'} eq 'uname') &&
3172: ($srch->{'srchtype'} eq 'exact')) {
3173: $ccuname = $srch->{'srchterm'};
3174: $ccdomain= $srch->{'srchdomain'};
3175: } else {
3176: my @matchedunames = keys(%{$results});
3177: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
3178: }
3179: $ccuname =&LONCAPA::clean_username($ccuname);
3180: $ccdomain=&LONCAPA::clean_domain($ccdomain);
3181: if ($env{'form.forcenewuser'}) {
3182: $response = '';
3183: }
3184: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 3185: $srch,$response,$context,
3186: $permission);
1.190 raeburn 3187: } elsif ($currstate eq 'query') {
3188: &print_user_query_page($r,'createuser');
3189: } else {
1.229 raeburn 3190: $env{'form.phase'} = '';
1.207 raeburn 3191: &print_username_entry_form($r,$context,$response,$srch,
1.190 raeburn 3192: $forcenewuser);
3193: }
3194: } elsif ($env{'form.phase'} eq 'userpicked') {
3195: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
3196: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 3197: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.221 raeburn 3198: $context,$permission);
1.190 raeburn 3199: }
3200: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.206 raeburn 3201: &update_user_data($r,$context);
1.190 raeburn 3202: } else {
1.207 raeburn 3203: &print_username_entry_form($r,$context,undef,$srch);
1.190 raeburn 3204: }
3205: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
3206: if ($env{'form.phase'} eq 'set_custom_roles') {
1.240 raeburn 3207: &set_custom_role($r,$context);
1.190 raeburn 3208: } else {
3209: &custom_role_editor($r);
3210: }
1.207 raeburn 3211: } elsif (($env{'form.action'} eq 'listusers') &&
3212: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 3213: if ($env{'form.phase'} eq 'bulkchange') {
3214: &Apache::lonhtmlcommon::add_breadcrumb
1.221 raeburn 3215: ({href=>'/adm/createuser?action=listusers',
3216: text=>"List Users"},
3217: {href=>"/adm/createuser",
3218: text=>"Result"});
1.202 raeburn 3219: my $setting = $env{'form.roletype'};
3220: my $choice = $env{'form.bulkaction'};
3221: $r->print(&header());
1.221 raeburn 3222: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Update Users",
1.224 raeburn 3223: 'Course_View_Class_List'));
1.202 raeburn 3224: if ($permission->{'cusr'}) {
3225: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
1.221 raeburn 3226: $r->print(&Apache::loncommon::end_page());
3227: } else {
3228: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 3229: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.221 raeburn 3230: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 3231: }
3232: } else {
3233: &Apache::lonhtmlcommon::add_breadcrumb
3234: ({href=>'/adm/createuser?action=listusers',
3235: text=>"List Users"});
3236: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
3237: my $formname = 'studentform';
3238: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
3239: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
3240: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
3241: $formname);
3242: $jscript .= &verify_user_display();
3243: my $js = &add_script($jscript).$cb_jscript;
3244: my $loadcode =
3245: &Apache::lonuserutils::course_selector_loadcode($formname);
3246: if ($loadcode ne '') {
3247: $r->print(&header($js,{'onload' => $loadcode,}));
3248: } else {
3249: $r->print(&header($js));
3250: }
1.191 raeburn 3251: } else {
1.202 raeburn 3252: $r->print(&header(&add_script(&verify_user_display())));
1.191 raeburn 3253: }
1.202 raeburn 3254: $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
1.224 raeburn 3255: 'Course_View_Class_List'));
1.202 raeburn 3256: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
3257: $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
3258: $r->print(&Apache::loncommon::end_page());
1.191 raeburn 3259: }
1.213 raeburn 3260: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
3261: $r->print(&header());
3262: &Apache::lonhtmlcommon::add_breadcrumb
3263: ({href=>'/adm/createuser?action=drop',
3264: text=>"Drop Students"});
3265: if (!exists($env{'form.state'})) {
3266: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
3267: 'Course_Drop_Student'));
3268:
3269: &Apache::lonuserutils::print_drop_menu($r,$context,$permission);
3270: } elsif ($env{'form.state'} eq 'done') {
3271: &Apache::lonhtmlcommon::add_breadcrumb
3272: ({href=>'/adm/createuser?action=drop',
3273: text=>"Result"});
3274: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
3275: 'Course_Drop_Student'));
3276: &Apache::lonuserutils::update_user_list($r,$context,undef,
3277: $env{'form.action'});
3278: }
3279: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 3280: } elsif ($env{'form.action'} eq 'dateselect') {
3281: if ($permission->{'cusr'}) {
3282: $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
1.221 raeburn 3283: &Apache::lonuserutils::date_section_selector($context,
3284: $permission).
1.202 raeburn 3285: &Apache::loncommon::end_page());
3286: } else {
3287: $r->print(&header().
3288: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'.
3289: &Apache::loncommon::end_page());
3290: }
1.237 raeburn 3291: } elsif ($env{'form.action'} eq 'selfenroll') {
3292: $r->print(&header());
3293: &Apache::lonhtmlcommon::add_breadcrumb
3294: ({href=>'/adm/createuser?action=selfenroll',
3295: text=>"Configure Self-enrollment"});
3296: if (!exists($env{'form.state'})) {
3297: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Configure Self-enrollment',
3298: 'Course_Self_Enrollment'));
1.241 raeburn 3299: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.237 raeburn 3300: &print_selfenroll_menu($r,$context,$permission);
3301: } elsif ($env{'form.state'} eq 'done') {
3302: &Apache::lonhtmlcommon::add_breadcrumb
3303: ({href=>'/adm/createuser?action=selfenroll',
3304: text=>"Result"});
3305: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enrollment result',
3306: 'Course_Self_Enrollment'));
1.241 raeburn 3307: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
3308: &update_selfenroll_config($r,$context,$permission);
1.237 raeburn 3309: }
3310: $r->print(&Apache::loncommon::end_page());
1.239 raeburn 3311: } elsif ($env{'form.action'} eq 'changelogs') {
3312: $r->print(&header());
3313: &Apache::lonhtmlcommon::add_breadcrumb
3314: ({href=>'/adm/createuser?action=changelogs',
3315: text=>"User Management Logs"});
3316: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Changes',
3317: 'Course_User_Logs'));
3318: &print_userchangelogs_display($r,$context,$permission);
3319: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 3320: } else {
3321: $r->print(&header());
1.202 raeburn 3322: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.207 raeburn 3323: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 3324: $r->print(&Apache::loncommon::end_page());
3325: }
3326: return OK;
3327: }
3328:
3329: sub header {
1.202 raeburn 3330: my ($jscript,$loaditems,$args) = @_;
1.190 raeburn 3331: my $start_page;
3332: if (ref($loaditems) eq 'HASH') {
1.202 raeburn 3333: $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
1.190 raeburn 3334: } else {
1.202 raeburn 3335: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 3336: }
3337: return $start_page;
3338: }
1.2 www 3339:
1.191 raeburn 3340: sub add_script {
3341: my ($js) = @_;
3342: return '<script type="text/javascript">'."\n".$js."\n".'</script>';
3343: }
3344:
1.202 raeburn 3345: sub verify_user_display {
3346: my $output = <<"END";
3347:
3348: function display_update() {
3349: document.studentform.action.value = 'listusers';
3350: document.studentform.phase.value = 'display';
3351: document.studentform.submit();
3352: }
3353:
3354: END
3355: return $output;
3356:
3357: }
3358:
1.190 raeburn 3359: ###############################################################
3360: ###############################################################
3361: # Menu Phase One
3362: sub print_main_menu {
1.208 raeburn 3363: my ($permission,$context) = @_;
3364: my %links = (
3365: domain => {
3366: upload => 'Upload a File of Users',
1.221 raeburn 3367: singleuser => 'Add/Modify a Single User',
1.208 raeburn 3368: listusers => 'Manage Multiple Users',
3369: },
3370: author => {
3371: upload => 'Upload a File of Co-authors',
1.221 raeburn 3372: singleuser => 'Add/Modify a Single Co-author',
1.208 raeburn 3373: listusers => 'Display Co-authors and Manage Multiple Users',
3374: },
3375: course => {
1.268.2.1 raeburn 3376: upload => 'Upload a File of Course Users',
3377: singleuser => 'Add/Modify a Single Course User',
3378: listusers => 'Display Class Lists and Manage Multiple Users',
1.208 raeburn 3379: },
3380: );
1.268.2.1 raeburn 3381: my @menu =
3382: (
3383: { text => $links{$context}{'upload'},
3384: help => 'Course_Create_Class_List',
3385: action => 'upload',
3386: permission => $permission->{'cusr'},
3387: },
3388: { text => $links{$context}{'singleuser'},
3389: help => 'Course_Change_Privileges',
3390: action => 'singleuser',
3391: permission => $permission->{'cusr'},
3392: },
3393: { text => $links{$context}{'listusers'},
3394: help => 'Course_View_Class_List',
3395: action => 'listusers',
3396: permission => ($permission->{'view'} || $permission->{'cusr'}),
3397: },
3398: );
3399: if ($context eq 'domain' || $context eq 'course') {
3400: my $customlink = { text => 'Edit Custom Roles',
3401: help => 'Course_Editing_Custom_Roles',
3402: action => 'custom',
3403: permission => $permission->{'custom'},
3404: };
3405: push(@menu,$customlink);
3406: }
3407: if ($context eq 'course') {
3408: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
3409: my @courselinks =
3410: (
3411: { text => 'Enroll a Single Student',
3412: help => 'Course_Add_Student',
3413: action => 'singlestudent',
3414: permission => $permission->{'cusr'},
3415: },
3416: { text => 'Drop Students',
3417: help => 'Course_Drop_Student',
3418: action => 'drop',
3419: permission => $permission->{'cusr'},
3420: });
3421: if (!exists($permission->{'cusr_section'})) {
3422: push(@courselinks,
3423: { text => 'Automated Enrollment Manager',
3424: help => 'Course_Automated_Enrollment',
3425: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
3426: && $permission->{'cusr'}),
3427: url => '/adm/populate',
3428: },
3429: { text => 'Configure User Self-enrollment',
3430: help => 'Course_Self_Enrollment',
3431: action => 'selfenroll',
3432: permission => $permission->{'cusr'},
3433: });
3434: }
3435: push(@courselinks,
3436: { text => 'Manage Course Groups',
3437: help => 'Course_Manage_Group',
3438: permission => $permission->{'grp_manage'},
3439: url => '/adm/coursegroups?refpage=cusr',
3440: },
3441: { text => 'View Change Logs',
3442: help => 'Course_User_Logs',
3443: action => 'changelogs',
3444: permission => $permission->{'cusr'},
3445: },);
1.250 raeburn 3446: # { text => 'View Log-in History',
3447: # help => 'Course_User_Logins',
3448: # action => 'logins',
3449: # permission => $permission->{'cusr'},
3450: # });
1.268.2.1 raeburn 3451: push(@menu,@courselinks);
3452: }
3453: my $menu_html = '';
3454: foreach my $menu_item (@menu) {
3455: next if (! $menu_item->{'permission'});
3456: $menu_html.='<p>';
3457: if (exists($menu_item->{'help'})) {
3458: $menu_html.=
3459: &Apache::loncommon::help_open_topic($menu_item->{'help'});
3460: }
3461: $menu_html.='<font size="+1">';
3462: if (exists($menu_item->{'url'})) {
3463: $menu_html.=qq{<a href="$menu_item->{'url'}">};
3464: } else {
3465: $menu_html.=
3466: qq{<a href="/adm/createuser?action=$menu_item->{'action'}">}; }
3467: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
3468: $menu_html.='</p>';
3469: }
3470: return $menu_html;
1.190 raeburn 3471: }
3472:
1.189 albertel 3473: sub restore_prev_selections {
3474: my %saveable_parameters = ('srchby' => 'scalar',
3475: 'srchin' => 'scalar',
3476: 'srchtype' => 'scalar',
3477: );
3478: &Apache::loncommon::store_settings('user','user_picker',
3479: \%saveable_parameters);
3480: &Apache::loncommon::restore_settings('user','user_picker',
3481: \%saveable_parameters);
3482: }
3483:
1.237 raeburn 3484: sub print_selfenroll_menu {
3485: my ($r,$context,$permission) = @_;
3486: my $formname = 'enrollstudent';
3487: my $nolink = 1;
3488: my ($row,$lt) = &get_selfenroll_titles();
3489: my $groupslist = &Apache::lonuserutils::get_groupslist();
3490: my $setsec_js =
3491: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 3492: my %alerts = &Apache::lonlocal::texthash(
3493: acto => 'Activation of self-enrollment was selected for the following domain(s)',
3494: butn => 'but no user types have been checked.',
3495: wilf => "Please uncheck 'activate' or check at least one type.",
3496: );
3497: my $selfenroll_js = <<"ENDSCRIPT";
3498: function update_types(caller,num) {
3499: var delidx = getIndexByName('selfenroll_delete');
3500: var actidx = getIndexByName('selfenroll_activate');
3501: if (caller == 'selfenroll_all') {
3502: var selall;
3503: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
3504: if (document.$formname.selfenroll_all[i].checked) {
3505: selall = document.$formname.selfenroll_all[i].value;
3506: }
3507: }
3508: if (selall == 1) {
3509: if (delidx != -1) {
3510: if (document.$formname.selfenroll_delete.length) {
3511: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
3512: document.$formname.selfenroll_delete[j].checked = true;
3513: }
3514: } else {
3515: document.$formname.elements[delidx].checked = true;
3516: }
3517: }
3518: if (actidx != -1) {
3519: if (document.$formname.selfenroll_activate.length) {
3520: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
3521: document.$formname.selfenroll_activate[j].checked = false;
3522: }
3523: } else {
3524: document.$formname.elements[actidx].checked = false;
3525: }
3526: }
3527: document.$formname.selfenroll_newdom.selectedIndex = 0;
3528: }
3529: }
3530: if (caller == 'selfenroll_activate') {
3531: if (document.$formname.selfenroll_activate.length) {
3532: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
3533: if (document.$formname.selfenroll_activate[j].value == num) {
3534: if (document.$formname.selfenroll_activate[j].checked) {
3535: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
3536: if (document.$formname.selfenroll_all[i].value == '1') {
3537: document.$formname.selfenroll_all[i].checked = false;
3538: }
3539: if (document.$formname.selfenroll_all[i].value == '0') {
3540: document.$formname.selfenroll_all[i].checked = true;
3541: }
3542: }
3543: }
3544: }
3545: }
3546: } else {
3547: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
3548: if (document.$formname.selfenroll_all[i].value == '1') {
3549: document.$formname.selfenroll_all[i].checked = false;
3550: }
3551: if (document.$formname.selfenroll_all[i].value == '0') {
3552: document.$formname.selfenroll_all[i].checked = true;
3553: }
3554: }
3555: }
3556: }
3557: if (caller == 'selfenroll_delete') {
3558: if (document.$formname.selfenroll_delete.length) {
3559: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
3560: if (document.$formname.selfenroll_delete[j].value == num) {
3561: if (document.$formname.selfenroll_delete[j].checked) {
3562: var delindex = getIndexByName('selfenroll_types_'+num);
3563: if (delindex != -1) {
3564: if (document.$formname.elements[delindex].length) {
3565: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
3566: document.$formname.elements[delindex][k].checked = false;
3567: }
3568: } else {
3569: document.$formname.elements[delindex].checked = false;
3570: }
3571: }
3572: }
3573: }
3574: }
3575: } else {
3576: if (document.$formname.selfenroll_delete.checked) {
3577: var delindex = getIndexByName('selfenroll_types_'+num);
3578: if (delindex != -1) {
3579: if (document.$formname.elements[delindex].length) {
3580: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
3581: document.$formname.elements[delindex][k].checked = false;
3582: }
3583: } else {
3584: document.$formname.elements[delindex].checked = false;
3585: }
3586: }
3587: }
3588: }
3589: }
3590: return;
3591: }
3592:
3593: function validate_types(form) {
3594: var needaction = new Array();
3595: var countfail = 0;
3596: var actidx = getIndexByName('selfenroll_activate');
3597: if (actidx != -1) {
3598: if (document.$formname.selfenroll_activate.length) {
3599: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
3600: var num = document.$formname.selfenroll_activate[j].value;
3601: if (document.$formname.selfenroll_activate[j].checked) {
3602: countfail = check_types(num,countfail,needaction)
3603: }
3604: }
3605: } else {
3606: if (document.$formname.selfenroll_activate.checked) {
3607: var num = document.enrollstudent.selfenroll_activate.value;
3608: countfail = check_types(num,countfail,needaction)
3609: }
3610: }
3611: }
3612: if (countfail > 0) {
3613: var msg = "$alerts{'acto'}\\n";
3614: var loopend = needaction.length -1;
3615: if (loopend > 0) {
3616: for (var m=0; m<loopend; m++) {
3617: msg += needaction[m]+", ";
3618: }
3619: }
3620: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
3621: alert(msg);
3622: return;
3623: }
3624: setSections(form);
3625: }
3626:
3627: function check_types(num,countfail,needaction) {
3628: var typeidx = getIndexByName('selfenroll_types_'+num);
3629: var count = 0;
3630: if (typeidx != -1) {
3631: if (document.$formname.elements[typeidx].length) {
3632: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
3633: if (document.$formname.elements[typeidx][k].checked) {
3634: count ++;
3635: }
3636: }
3637: } else {
3638: if (document.$formname.elements[typeidx].checked) {
3639: count ++;
3640: }
3641: }
3642: if (count == 0) {
3643: var domidx = getIndexByName('selfenroll_dom_'+num);
3644: if (domidx != -1) {
3645: var domname = document.$formname.elements[domidx].value;
3646: needaction[countfail] = domname;
3647: countfail ++;
3648: }
3649: }
3650: }
3651: return countfail;
3652: }
3653:
3654: function getIndexByName(item) {
3655: for (var i=0;i<document.$formname.elements.length;i++) {
3656: if (document.$formname.elements[i].name == item) {
3657: return i;
3658: }
3659: }
3660: return -1;
3661: }
3662: ENDSCRIPT
1.256 raeburn 3663: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3664: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3665:
1.237 raeburn 3666: my $output = '<script type="text/javascript">'."\n".
1.249 raeburn 3667: $setsec_js."\n".$selfenroll_js."\n".
1.237 raeburn 3668: '</script>'."\n".
1.256 raeburn 3669: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
3670: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
3671: if (ref($visactions) eq 'HASH') {
3672: if ($visible) {
3673: $output .= '<p>'.$visactions->{'vis'}.'</p>';
3674: } else {
3675: $output .= $visactions->{'miss'}.'<br />'.$visactions->{'yous'}.
3676: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
3677: if (ref($vismsgs) eq 'ARRAY') {
3678: $output .= '<br />'.$visactions->{'make'}.'<ul>';
3679: foreach my $item (@{$vismsgs}) {
3680: $output .= '<li>'.$visactions->{$item}.'</li>';
3681: }
3682: $output .= '</ul>';
3683: }
3684: $output .= '</p>';
3685: }
3686: }
3687: $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
3688: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 3689: if (ref($row) eq 'ARRAY') {
3690: foreach my $item (@{$row}) {
3691: my $title = $item;
3692: if (ref($lt) eq 'HASH') {
3693: $title = $lt->{$item};
3694: }
3695: $output .=
3696: &Apache::lonhtmlcommon::row_title($title,
3697: 'LC_selfenroll_pick_box_title','LC_oddrow_value')."\n";
3698: if ($item eq 'types') {
3699: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 3700: my $showdomdesc = 1;
3701: my $includeempty = 1;
3702: my $num = 0;
3703: $output .= &Apache::loncommon::start_data_table().
3704: &Apache::loncommon::start_data_table_row()
3705: .'<td colspan="2"><span class="LC_nobreak"><label>'
3706: .&mt('Any user in any domain:')
3707: .' <input type="radio" name="selfenroll_all" value="1" ';
3708: if ($curr_types eq '*') {
3709: $output .= ' checked="checked" ';
3710: }
1.249 raeburn 3711: $output .= 'onchange="javascript:update_types('.
3712: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
3713: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 3714: if ($curr_types ne '*') {
3715: $output .= ' checked="checked" ';
3716: }
1.249 raeburn 3717: $output .= ' onchange="javascript:update_types('.
3718: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
3719: &Apache::loncommon::end_data_table_row().
3720: &Apache::loncommon::end_data_table().
3721: &mt('Or').'<br />'.
3722: &Apache::loncommon::start_data_table();
1.241 raeburn 3723: my %currdoms;
1.249 raeburn 3724: if ($curr_types eq '') {
1.241 raeburn 3725: $output .= &new_selfenroll_dom_row($cdom,'0');
3726: } elsif ($curr_types ne '*') {
3727: my @entries = split(/;/,$curr_types);
3728: if (@entries > 0) {
3729: foreach my $entry (@entries) {
3730: my ($currdom,$typestr) = split(/:/,$entry);
3731: $currdoms{$currdom} = 1;
3732: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 3733: my @currinsttypes = split(',',$typestr);
1.241 raeburn 3734: $output .= &Apache::loncommon::start_data_table_row()
3735: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
3736: .' '.$domdesc.' ('.$currdom.')'
3737: .'</b><input type="hidden" name="selfenroll_dom_'.$num
3738: .'" value="'.$currdom.'" /></span><br />'
3739: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 3740: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 3741: .&mt('Delete').'</label></span></td>';
1.249 raeburn 3742: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 3743: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
3744: .&Apache::loncommon::end_data_table_row();
3745: $num ++;
3746: }
3747: }
3748: }
1.249 raeburn 3749: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 3750: if ($curr_types eq '*') {
1.249 raeburn 3751: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 3752: } elsif ($curr_types eq '') {
1.249 raeburn 3753: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 3754: }
3755: $output .= &Apache::loncommon::start_data_table_row()
3756: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
3757: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
3758: $includeempty,$showdomdesc)
3759: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
3760: .'</td>'.&Apache::loncommon::end_data_table_row()
3761: .&Apache::loncommon::end_data_table();
1.237 raeburn 3762: } elsif ($item eq 'registered') {
3763: my ($regon,$regoff);
3764: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
3765: $regon = ' checked="checked" ';
3766: $regoff = ' ';
3767: } else {
3768: $regon = ' ';
3769: $regoff = ' checked="checked" ';
3770: }
3771: $output .= '<label>'.
1.245 raeburn 3772: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 3773: &mt('Yes').'</label> <label>'.
1.245 raeburn 3774: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 3775: &mt('No').'</label>';
1.237 raeburn 3776: } elsif ($item eq 'enroll_dates') {
3777: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
3778: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
3779: if ($starttime eq '') {
3780: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
3781: }
3782: if ($endtime eq '') {
3783: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
3784: }
3785: my $startform =
3786: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
3787: undef,undef,undef,undef,undef,undef,undef,$nolink);
3788: my $endform =
3789: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
3790: undef,undef,undef,undef,undef,undef,undef,$nolink);
3791: $output .= &selfenroll_date_forms($startform,$endform);
3792: } elsif ($item eq 'access_dates') {
3793: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
3794: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
3795: if ($starttime eq '') {
3796: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
3797: }
3798: if ($endtime eq '') {
3799: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
3800: }
3801: my $startform =
3802: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
3803: undef,undef,undef,undef,undef,undef,undef,$nolink);
3804: my $endform =
3805: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
3806: undef,undef,undef,undef,undef,undef,undef,$nolink);
3807: $output .= &selfenroll_date_forms($startform,$endform);
3808: } elsif ($item eq 'section') {
3809: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
3810: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
3811: my $newsecval;
3812: if ($currsec ne 'none' && $currsec ne '') {
3813: if (!defined($sections_count{$currsec})) {
3814: $newsecval = $currsec;
3815: }
3816: }
3817: my $sections_select =
3818: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
3819: $output .= '<table class="LC_createuser">'."\n".
3820: '<tr class="LC_section_row">'."\n".
3821: '<td align="center">'.&mt('Existing sections')."\n".
3822: '<br />'.$sections_select.'</td><td align="center">'.
3823: &mt('New section').'<br />'."\n".
3824: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
3825: '<input type="hidden" name="sections" value="" />'."\n".
3826: '<input type="hidden" name="state" value="done" />'."\n".
3827: '</td></tr></table>'."\n";
3828: }
3829: $output .= &Apache::lonhtmlcommon::row_closure(1);
3830: }
3831: }
3832: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 3833: '<br /><input type="button" name="selfenrollconf" value="'
1.249 raeburn 3834: .&mt('Save changes').'" onclick="validate_types(this.form);" />'
1.241 raeburn 3835: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 3836: $r->print($output);
3837: return;
3838: }
3839:
1.256 raeburn 3840: sub visible_in_cat {
3841: my ($cdom,$cnum) = @_;
3842: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
3843: my ($cathash,%settable,@vismsgs,$cansetvis);
3844: my %visactions = &Apache::lonlocal::texthash(
3845: vis => 'Your course currently appears in the Course Catalog for this domain.',
3846: 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.',
3847: miss => 'Your course does not currently appear in the Course Catalog for this domain.',
3848: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
3849: 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.',
3850: make => 'Make any changes to self-enrollment settings below, click "Save changes", then take action to include the course in the Catalog:',
3851: take => 'Take the following action to ensure the course appears in the Catalog:',
3852: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
3853: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
3854: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
3855: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
3856: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
3857: 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',
3858: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
3859: );
1.261 raeburn 3860: $visactions{'unhide'} = &mt('Use [_1]Set course environment[_2] to change the "Exclude from course catalog" setting.','"<a href="/adm/parmset?action=crsenv">','</a>"');
3861: $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>"');
3862: $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 3863: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3864: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
3865: $settable{'togglecats'} = 1;
3866: }
3867: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
3868: $settable{'categorize'} = 1;
3869: }
3870: $cathash = $domconf{'coursecategories'}{'cats'};
3871: }
1.260 raeburn 3872: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 3873: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
3874: } elsif ($settable{'togglecats'}) {
3875: $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 3876: } elsif ($settable{'categorize'}) {
1.256 raeburn 3877: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
3878: } else {
3879: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
3880: }
3881:
3882: my %currsettings =
3883: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
3884: $cdom,$cnum);
3885: my $visible = 0;
3886: if ($currsettings{'internal.coursecode'} ne '') {
3887: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3888: $cathash = $domconf{'coursecategories'}{'cats'};
3889: if (ref($cathash) eq 'HASH') {
3890: if ($cathash->{'instcode::0'} eq '') {
3891: push(@vismsgs,'dc_addinst');
3892: } else {
3893: $visible = 1;
3894: }
3895: } else {
3896: $visible = 1;
3897: }
3898: } else {
3899: $visible = 1;
3900: }
3901: } else {
3902: if (ref($cathash) eq 'HASH') {
3903: if ($cathash->{'instcode::0'} ne '') {
3904: push(@vismsgs,'dc_instcode');
3905: }
3906: } else {
3907: push(@vismsgs,'dc_instcode');
3908: }
3909: }
3910: if ($currsettings{'categories'} ne '') {
3911: my $cathash;
3912: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3913: $cathash = $domconf{'coursecategories'}{'cats'};
3914: if (ref($cathash) eq 'HASH') {
3915: if (keys(%{$cathash}) == 0) {
3916: push(@vismsgs,'dc_catalog');
3917: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
3918: push(@vismsgs,'dc_categories');
3919: } else {
3920: my @currcategories = split('&',$currsettings{'categories'});
3921: my $matched = 0;
3922: foreach my $cat (@currcategories) {
3923: if ($cathash->{$cat} ne '') {
3924: $visible = 1;
3925: $matched = 1;
3926: last;
3927: }
3928: }
3929: if (!$matched) {
1.260 raeburn 3930: if ($settable{'categorize'}) {
1.256 raeburn 3931: push(@vismsgs,'chgcat');
3932: } else {
3933: push(@vismsgs,'dc_chgcat');
3934: }
3935: }
3936: }
3937: }
3938: }
3939: } else {
3940: if (ref($cathash) eq 'HASH') {
3941: if ((keys(%{$cathash}) > 1) ||
3942: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 3943: if ($settable{'categorize'}) {
1.256 raeburn 3944: push(@vismsgs,'addcat');
3945: } else {
3946: push(@vismsgs,'dc_addcat');
3947: }
3948: }
3949: }
3950: }
3951: if ($currsettings{'hidefromcat'} eq 'yes') {
3952: $visible = 0;
3953: if ($settable{'togglecats'}) {
3954: unshift(@vismsgs,'unhide');
3955: } else {
3956: unshift(@vismsgs,'dc_unhide')
3957: }
3958: }
3959: return ($visible,$cansetvis,\@vismsgs,\%visactions);
3960: }
3961:
1.241 raeburn 3962: sub new_selfenroll_dom_row {
3963: my ($newdom,$num) = @_;
3964: my $domdesc = &Apache::lonnet::domain($newdom);
3965: my $output;
3966: if ($domdesc ne '') {
3967: $output .= &Apache::loncommon::start_data_table_row()
3968: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
3969: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 3970: .'" value="'.$newdom.'" /></span><br />'
3971: .'<span class="LC_nobreak"><label><input type="checkbox" '
3972: .'name="selfenroll_activate" value="'.$num.'" '
3973: .'onchange="javascript:update_types('
3974: ."'selfenroll_activate','$num'".');" />'
3975: .&mt('Activate').'</label></span></td>';
1.241 raeburn 3976: my @currinsttypes;
3977: $output .= '<td>'.&mt('User types:').'<br />'
3978: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
3979: .&Apache::loncommon::end_data_table_row();
3980: }
3981: return $output;
3982: }
3983:
3984: sub selfenroll_inst_types {
3985: my ($num,$currdom,$currinsttypes) = @_;
3986: my $output;
3987: my $numinrow = 4;
3988: my $count = 0;
3989: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 3990: my $othervalue = 'any';
1.241 raeburn 3991: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 3992: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 3993: $othervalue = 'other';
3994: }
1.241 raeburn 3995: $output .= '<table><tr>';
3996: foreach my $type (@{$types}) {
3997: if (($count > 0) && ($count%$numinrow == 0)) {
3998: $output .= '</tr><tr>';
3999: }
4000: if (defined($usertypes->{$type})) {
1.257 raeburn 4001: my $esc_type = &escape($type);
1.241 raeburn 4002: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 4003: $esc_type.'" ';
1.241 raeburn 4004: if (ref($currinsttypes) eq 'ARRAY') {
4005: if (@{$currinsttypes} > 0) {
1.249 raeburn 4006: if (grep(/^any$/,@{$currinsttypes})) {
4007: $output .= 'checked="checked"';
1.257 raeburn 4008: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 4009: $output .= 'checked="checked"';
4010: }
1.249 raeburn 4011: } else {
4012: $output .= 'checked="checked"';
1.241 raeburn 4013: }
4014: }
4015: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
4016: }
4017: $count ++;
4018: }
4019: if (($count > 0) && ($count%$numinrow == 0)) {
4020: $output .= '</tr><tr>';
4021: }
1.249 raeburn 4022: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 4023: if (ref($currinsttypes) eq 'ARRAY') {
4024: if (@{$currinsttypes} > 0) {
1.249 raeburn 4025: if (grep(/^any$/,@{$currinsttypes})) {
4026: $output .= ' checked="checked"';
4027: } elsif ($othervalue eq 'other') {
4028: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
4029: $output .= ' checked="checked"';
4030: }
1.241 raeburn 4031: }
1.249 raeburn 4032: } else {
4033: $output .= ' checked="checked"';
1.241 raeburn 4034: }
1.249 raeburn 4035: } else {
4036: $output .= ' checked="checked"';
1.241 raeburn 4037: }
4038: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
4039: }
4040: return $output;
4041: }
4042:
1.237 raeburn 4043: sub selfenroll_date_forms {
4044: my ($startform,$endform) = @_;
4045: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 4046: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 4047: 'LC_oddrow_value')."\n".
4048: $startform."\n".
4049: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 4050: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 4051: 'LC_oddrow_value')."\n".
4052: $endform."\n".
4053: &Apache::lonhtmlcommon::row_closure(1).
4054: &Apache::lonhtmlcommon::end_pick_box();
4055: return $output;
4056: }
4057:
1.239 raeburn 4058: sub print_userchangelogs_display {
4059: my ($r,$context,$permission) = @_;
4060: my $formname = 'roleslog';
4061: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4062: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4063: my %roleslog=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
4064: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
4065:
4066: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
4067: my %saveable_parameters = ('show' => 'scalar',);
4068: &Apache::loncommon::store_course_settings('roles_log',
4069: \%saveable_parameters);
4070: &Apache::loncommon::restore_course_settings('roles_log',
4071: \%saveable_parameters);
4072: # set defaults
4073: my $now = time();
4074: my $defstart = $now - (7*24*3600); #7 days ago
4075: my %defaults = (
4076: page => '1',
4077: show => '10',
4078: role => 'any',
4079: chgcontext => 'any',
4080: rolelog_start_date => $defstart,
4081: rolelog_end_date => $now,
4082: );
4083: my $more_records = 0;
4084:
4085: # set current
4086: my %curr;
4087: foreach my $item ('show','page','role','chgcontext') {
4088: $curr{$item} = $env{'form.'.$item};
4089: }
4090: my ($startdate,$enddate) =
4091: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
4092: $curr{'rolelog_start_date'} = $startdate;
4093: $curr{'rolelog_end_date'} = $enddate;
4094: foreach my $key (keys(%defaults)) {
4095: if ($curr{$key} eq '') {
4096: $curr{$key} = $defaults{$key};
4097: }
4098: }
1.248 raeburn 4099: my (%whodunit,%changed,$version);
4100: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
4101: $r->print(&role_display_filter($formname,$cdom,$cnum,\%curr,$version));
1.239 raeburn 4102: my $showntablehdr = 0;
4103: my $tablehdr = &Apache::loncommon::start_data_table().
4104: &Apache::loncommon::start_data_table_header_row().
4105: '<th> </th><th>'.&mt('When').'</th><th>'.&mt('Who made the change').
4106: '</th><th>'.&mt('Changed User').'</th><th>'.&mt('Role').'</th><th>'.&mt('Section').'</th><th>'.
4107: &mt('Context').'</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
4108: &Apache::loncommon::end_data_table_header_row();
4109: my ($minshown,$maxshown);
1.255 raeburn 4110: $minshown = 1;
1.239 raeburn 4111: my $count = 0;
4112: if ($curr{'show'} ne &mt('all')) {
4113: $maxshown = $curr{'page'} * $curr{'show'};
4114: if ($curr{'page'} > 1) {
4115: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
4116: }
4117: }
4118: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
4119: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
4120: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
4121: if ($curr{'show'} ne &mt('all')) {
4122: if ($count >= $curr{'page'} * $curr{'show'}) {
4123: $more_records = 1;
4124: last;
4125: }
4126: }
4127: if ($curr{'role'} ne 'any') {
4128: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
4129: }
4130: if ($curr{'chgcontext'} ne 'any') {
4131: if ($curr{'chgcontext'} eq 'selfenroll') {
4132: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
4133: } else {
4134: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
4135: }
4136: }
4137: $count ++;
4138: next if ($count < $minshown);
4139: if (!$showntablehdr) {
4140: $r->print($tablehdr);
4141: $showntablehdr = 1;
4142: }
4143: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
4144: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
4145: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
4146: }
4147: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
4148: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
4149: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
4150: }
4151: my $sec = $roleslog{$id}{'logentry'}{'section'};
4152: if ($sec eq '') {
4153: $sec = &mt('None');
4154: }
4155: my ($rolestart,$roleend);
4156: if ($roleslog{$id}{'delflag'}) {
4157: $rolestart = &mt('deleted');
4158: $roleend = &mt('deleted');
4159: } else {
4160: $rolestart = $roleslog{$id}{'logentry'}{'start'};
4161: $roleend = $roleslog{$id}{'logentry'}{'end'};
4162: if ($rolestart eq '' || $rolestart == 0) {
4163: $rolestart = &mt('No start date');
4164: } else {
4165: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
4166: }
4167: if ($roleend eq '' || $roleend == 0) {
4168: $roleend = &mt('No end date');
4169: } else {
4170: $roleend = &Apache::lonlocal::locallocaltime($roleend);
4171: }
4172: }
4173: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
4174: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
4175: $chgcontext = 'selfenroll';
4176: }
4177: my %lt = &rolechg_contexts();
4178: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
4179: $chgcontext = $lt{$chgcontext};
4180: }
4181: $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");
4182: }
4183: if ($showntablehdr) {
4184: $r->print(&Apache::loncommon::end_data_table().'<br />');
4185: if (($curr{'page'} > 1) || ($more_records)) {
4186: $r->print('<table><tr>');
4187: if ($curr{'page'} > 1) {
4188: $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
4189: }
4190: if ($more_records) {
4191: $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
4192: }
4193: $r->print('</tr></table>');
4194: $r->print(<<"ENDSCRIPT");
4195: <script type="text/javascript">
4196: function chgPage(caller) {
4197: if (caller == 'previous') {
4198: document.$formname.page.value --;
4199: }
4200: if (caller == 'next') {
4201: document.$formname.page.value ++;
4202: }
4203: document.$formname.submit();
4204: return;
4205: }
4206: </script>
4207: ENDSCRIPT
4208: }
4209: } else {
4210: $r->print(&mt('There are no records to display'));
4211: }
4212: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
4213: '<input type="hidden" name="action" value="changelogs" /></form>');
4214: return;
4215: }
4216:
4217: sub role_display_filter {
1.248 raeburn 4218: my ($formname,$cdom,$cnum,$curr,$version) = @_;
1.239 raeburn 4219: my $context = 'course';
4220: my $nolink = 1;
4221: my $output = '<table><tr><td valign="top">'.
4222: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b><br />'.
4223: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
4224: (&mt('all'),5,10,20,50,100,1000,10000)).
4225: '</td><td> </td>';
4226: my $startform =
4227: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
4228: $curr->{'rolelog_start_date'},undef,
4229: undef,undef,undef,undef,undef,undef,$nolink);
4230: my $endform =
4231: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
4232: $curr->{'rolelog_end_date'},undef,
4233: undef,undef,undef,undef,undef,undef,$nolink);
4234: my %lt = &rolechg_contexts();
4235: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br /><table><tr><td>'.&mt('After:').
4236: '</td><td>'.$startform.'</td></tr><tr><td>'.&mt('Before:').'</td><td>'.
4237: $endform.'</td></tr></table></td><td> </td>'.
4238: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
4239: '<select name="role"><option value="any"';
4240: if ($curr->{'role'} eq 'any') {
4241: $output .= ' selected="selected"';
4242: }
4243: $output .= '>'.&mt('Any').'</option>'."\n";
4244: my @roles = &Apache::lonuserutils::course_roles($context,undef,1);
4245: foreach my $role (@roles) {
4246: my $plrole;
4247: if ($role eq 'cr') {
4248: $plrole = &mt('Custom Role');
4249: } else {
4250: $plrole=&Apache::lonnet::plaintext($role);
4251: }
4252: my $selstr = '';
4253: if ($role eq $curr->{'role'}) {
4254: $selstr = ' selected="selected"';
4255: }
4256: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
4257: }
4258: $output .= '</select></td><td> </td><td valign="top"><b>'.
4259: &mt('Context:').'</b><br /><select name="chgcontext">';
4260: foreach my $chgtype ('any','auto','updatenow','createcourse','course','domain','selfenroll') {
4261: my $selstr = '';
4262: if ($curr->{'chgcontext'} eq $chgtype) {
4263: $output .= $selstr = ' selected="selected"';
4264: }
4265: if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) {
4266: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
4267: }
4268: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 4269: }
1.239 raeburn 4270: $output .= '</select></td><td> </td><td valign="middle"><input type="submit" value="'.
1.248 raeburn 4271: &mt('Update Display').'" /></tr></table>'.
4272: '<span class="LC_roleslog_note">'.
4273: &mt('[_1]Note:[_2] Only changes made from servers running LON-CAPA 2.6.99.0 or later are displayed.');
4274: if ($version) {
4275: $output .= ' '.&mt('This server is version [_3].','<b>','</b>',$version); }
4276: $output .= '</span><hr noshade><br />';
1.239 raeburn 4277: return $output;
4278: }
4279:
4280: sub rolechg_contexts {
4281: my %lt = &Apache::lonlocal::texthash (
4282: any => 'Any',
4283: auto => 'Automated enrollment',
4284: updatenow => 'Roster Update',
4285: createcourse => 'Course Creation',
4286: course => 'User Management in course',
4287: domain => 'User Management in domain',
4288: selfenroll => 'Self-enrolled',
4289: );
4290: return %lt;
4291: }
4292:
1.27 matthew 4293: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 4294: sub user_search_result {
1.221 raeburn 4295: my ($context,$srch) = @_;
1.160 raeburn 4296: my %allhomes;
4297: my %inst_matches;
4298: my %srch_results;
1.181 raeburn 4299: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 4300: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 4301: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 4302: $response = &mt('Invalid search.');
4303: }
4304: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
4305: $response = &mt('Invalid search.');
4306: }
1.177 raeburn 4307: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 4308: $response = &mt('Invalid search.');
4309: }
4310: if ($srch->{'srchterm'} eq '') {
4311: $response = &mt('You must enter a search term.');
4312: }
1.183 raeburn 4313: if ($srch->{'srchterm'} =~ /^\s+$/) {
4314: $response = &mt('Your search term must contain more than just spaces.');
4315: }
1.160 raeburn 4316: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
4317: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 4318: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 4319: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
4320: }
4321: }
4322: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
4323: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 4324: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 4325: my $unamecheck = $srch->{'srchterm'};
4326: if ($srch->{'srchtype'} eq 'contains') {
4327: if ($unamecheck !~ /^\w/) {
4328: $unamecheck = 'a'.$unamecheck;
4329: }
4330: }
4331: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 4332: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
4333: }
1.160 raeburn 4334: }
4335: }
1.180 raeburn 4336: if ($response ne '') {
4337: $response = '<span class="LC_warning">'.$response.'</span>';
4338: }
1.160 raeburn 4339: if ($srch->{'srchin'} eq 'instd') {
4340: my $instd_chk = &directorysrch_check($srch);
4341: if ($instd_chk ne 'ok') {
1.180 raeburn 4342: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
4343: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 4344: }
4345: }
4346: if ($response ne '') {
1.180 raeburn 4347: return ($currstate,$response);
1.160 raeburn 4348: }
4349: if ($srch->{'srchby'} eq 'uname') {
4350: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
4351: if ($env{'form.forcenew'}) {
4352: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
4353: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
4354: if ($uhome eq 'no_host') {
4355: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 4356: my $showdom = &display_domain_info($env{'request.role.domain'});
4357: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 4358: } else {
1.179 raeburn 4359: $currstate = 'modify';
1.160 raeburn 4360: }
4361: } else {
1.179 raeburn 4362: $currstate = 'modify';
1.160 raeburn 4363: }
4364: } else {
4365: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 4366: if ($srch->{'srchtype'} eq 'exact') {
4367: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
4368: if ($uhome eq 'no_host') {
1.179 raeburn 4369: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4370: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 4371: } else {
1.179 raeburn 4372: $currstate = 'modify';
1.162 raeburn 4373: }
4374: } else {
4375: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 4376: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4377: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 4378: }
4379: } else {
1.167 albertel 4380: my $courseusers = &get_courseusers();
1.162 raeburn 4381: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 4382: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 4383: $currstate = 'modify';
1.162 raeburn 4384: } else {
1.179 raeburn 4385: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4386: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 4387: }
1.160 raeburn 4388: } else {
1.167 albertel 4389: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 4390: my ($cuname,$cudomain) = split(/:/,$user);
4391: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 4392: my $matched = 0;
4393: if ($srch->{'srchtype'} eq 'begins') {
4394: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
4395: $matched = 1;
4396: }
4397: } else {
4398: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
4399: $matched = 1;
4400: }
4401: }
4402: if ($matched) {
1.167 albertel 4403: $srch_results{$user} =
4404: {&Apache::lonnet::get('environment',
4405: ['firstname',
4406: 'lastname',
1.194 albertel 4407: 'permanentemail'],
4408: $cudomain,$cuname)};
1.162 raeburn 4409: }
4410: }
4411: }
1.179 raeburn 4412: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4413: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 4414: }
4415: }
4416: }
4417: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 4418: $currstate = 'query';
1.160 raeburn 4419: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 4420: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
4421: if ($dirsrchres eq 'ok') {
4422: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4423: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 4424: } else {
4425: my $showdom = &display_domain_info($srch->{'srchdomain'});
4426: $response = '<span class="LC_warning">'.
4427: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
4428: '</span><br />'.
4429: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
4430: '<br /><br />';
4431: }
1.160 raeburn 4432: }
4433: } else {
4434: if ($srch->{'srchin'} eq 'dom') {
4435: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 4436: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4437: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 4438: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 4439: my $courseusers = &get_courseusers();
4440: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 4441: my ($uname,$udom) = split(/:/,$user);
4442: my %names = &Apache::loncommon::getnames($uname,$udom);
4443: my %emails = &Apache::loncommon::getemails($uname,$udom);
4444: if ($srch->{'srchby'} eq 'lastname') {
4445: if ((($srch->{'srchtype'} eq 'exact') &&
4446: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 4447: (($srch->{'srchtype'} eq 'begins') &&
4448: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 4449: (($srch->{'srchtype'} eq 'contains') &&
4450: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
4451: $srch_results{$user} = {firstname => $names{'firstname'},
4452: lastname => $names{'lastname'},
4453: permanentemail => $emails{'permanentemail'},
4454: };
4455: }
4456: } elsif ($srch->{'srchby'} eq 'lastfirst') {
4457: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 4458: $srchlast =~ s/\s+$//;
4459: $srchfirst =~ s/^\s+//;
1.160 raeburn 4460: if ($srch->{'srchtype'} eq 'exact') {
4461: if (($names{'lastname'} eq $srchlast) &&
4462: ($names{'firstname'} eq $srchfirst)) {
4463: $srch_results{$user} = {firstname => $names{'firstname'},
4464: lastname => $names{'lastname'},
4465: permanentemail => $emails{'permanentemail'},
4466:
4467: };
4468: }
1.177 raeburn 4469: } elsif ($srch->{'srchtype'} eq 'begins') {
4470: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
4471: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
4472: $srch_results{$user} = {firstname => $names{'firstname'},
4473: lastname => $names{'lastname'},
4474: permanentemail => $emails{'permanentemail'},
4475: };
4476: }
4477: } else {
1.160 raeburn 4478: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
4479: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
4480: $srch_results{$user} = {firstname => $names{'firstname'},
4481: lastname => $names{'lastname'},
4482: permanentemail => $emails{'permanentemail'},
4483: };
4484: }
4485: }
4486: }
4487: }
1.179 raeburn 4488: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4489: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 4490: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 4491: $currstate = 'query';
1.160 raeburn 4492: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 4493: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
4494: if ($dirsrchres eq 'ok') {
4495: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4496: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 4497: } else {
4498: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
4499: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
4500: '</span><br />'.
4501: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
4502: '<br /><br />';
4503: }
1.160 raeburn 4504: }
4505: }
1.179 raeburn 4506: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 4507: }
4508:
4509: sub directorysrch_check {
4510: my ($srch) = @_;
4511: my $can_search = 0;
4512: my $response;
4513: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
4514: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 4515: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 4516: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
4517: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 4518: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 4519: }
4520: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
4521: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 4522: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 4523: }
4524: my @usertypes = split(/:/,$env{'environment.inststatus'});
4525: if (!@usertypes) {
4526: push(@usertypes,'default');
4527: }
4528: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
4529: foreach my $type (@usertypes) {
4530: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
4531: $can_search = 1;
4532: last;
4533: }
4534: }
4535: }
4536: if (!$can_search) {
4537: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
4538: my @longtypes;
4539: foreach my $item (@usertypes) {
1.229 raeburn 4540: if (defined($insttypes->{$item})) {
4541: push (@longtypes,$insttypes->{$item});
4542: } elsif ($item eq 'default') {
4543: push (@longtypes,&mt('other'));
4544: }
1.160 raeburn 4545: }
4546: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 4547: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 4548: }
1.160 raeburn 4549: } else {
4550: $can_search = 1;
4551: }
4552: } else {
1.180 raeburn 4553: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 4554: }
4555: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 4556: uname => 'username',
1.160 raeburn 4557: lastfirst => 'last name, first name',
1.167 albertel 4558: lastname => 'last name',
1.172 raeburn 4559: contains => 'contains',
1.178 raeburn 4560: exact => 'as exact match to',
4561: begins => 'begins with',
1.160 raeburn 4562: );
4563: if ($can_search) {
4564: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
4565: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 4566: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 4567: }
4568: } else {
1.180 raeburn 4569: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 4570: }
4571: }
4572: if ($can_search) {
1.178 raeburn 4573: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
4574: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
4575: return 'ok';
4576: } else {
1.180 raeburn 4577: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 4578: }
4579: } else {
4580: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
4581: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
4582: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
4583: return 'ok';
4584: } else {
1.180 raeburn 4585: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 4586: }
1.160 raeburn 4587: }
4588: }
4589: }
4590:
4591: sub get_courseusers {
4592: my %advhash;
1.167 albertel 4593: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 4594: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
4595: foreach my $role (sort(keys(%coursepersonnel))) {
4596: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 4597: if (!exists($classlist->{$user})) {
4598: $classlist->{$user} = [];
4599: }
1.160 raeburn 4600: }
4601: }
1.167 albertel 4602: return $classlist;
1.160 raeburn 4603: }
4604:
4605: sub build_search_response {
1.221 raeburn 4606: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 4607: my ($currstate,$response,$forcenewuser);
1.160 raeburn 4608: my %names = (
4609: 'uname' => 'username',
4610: 'lastname' => 'last name',
4611: 'lastfirst' => 'last name, first name',
4612: 'crs' => 'this course',
1.180 raeburn 4613: 'dom' => 'LON-CAPA domain: ',
4614: 'instd' => 'the institutional directory for domain: ',
1.160 raeburn 4615: );
4616:
4617: my %single = (
1.180 raeburn 4618: begins => 'A match',
1.160 raeburn 4619: contains => 'A match',
1.180 raeburn 4620: exact => 'An exact match',
1.160 raeburn 4621: );
4622: my %nomatch = (
1.180 raeburn 4623: begins => 'No match',
1.160 raeburn 4624: contains => 'No match',
1.180 raeburn 4625: exact => 'No exact match',
1.160 raeburn 4626: );
4627: if (keys(%srch_results) > 1) {
1.179 raeburn 4628: $currstate = 'select';
1.160 raeburn 4629: } else {
4630: if (keys(%srch_results) == 1) {
1.179 raeburn 4631: $currstate = 'modify';
1.180 raeburn 4632: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
4633: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
4634: $response .= &display_domain_info($srch->{'srchdomain'});
4635: }
1.160 raeburn 4636: } else {
1.180 raeburn 4637: $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} 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: }
4641: $response .= '</span>';
1.160 raeburn 4642: if ($srch->{'srchin'} ne 'alc') {
4643: $forcenewuser = 1;
4644: my $cansrchinst = 0;
4645: if ($srch->{'srchdomain'}) {
4646: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
4647: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
4648: if ($domconfig{'directorysrch'}{'available'}) {
4649: $cansrchinst = 1;
4650: }
4651: }
4652: }
1.180 raeburn 4653: if ((($srch->{'srchby'} eq 'lastfirst') ||
4654: ($srch->{'srchby'} eq 'lastname')) &&
4655: ($srch->{'srchin'} eq 'dom')) {
4656: if ($cansrchinst) {
4657: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 4658: }
4659: }
1.180 raeburn 4660: if ($srch->{'srchin'} eq 'crs') {
4661: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
4662: }
4663: }
4664: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {
1.221 raeburn 4665: my $cancreate =
4666: &Apache::lonuserutils::can_create_user($env{'request.role.domain'},$context);
4667: if ($cancreate) {
4668: my $showdom = &display_domain_info($env{'request.role.domain'});
1.266 bisitz 4669: $response .= '<br /><br />'
4670: .'<b>'.&mt('To add a new user:').'</b>'
4671: .'<br />'
4672: .&mt("(You can only create new users in your current role's domain - [_1])"
4673: ,'<span class="LC_cusr_emph">'.$env{'request.role.domain'}.'</span>')
4674: .'<ul><li>'
4675: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
4676: .'</li><li>'
4677: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
4678: .'</li><li>'
4679: .&mt('Provide the proposed username')
4680: .'</li><li>'
4681: .&mt("Click 'Search'")
4682: .'</li></ul><br />';
1.221 raeburn 4683: } else {
4684: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.266 bisitz 4685: $response .= '<br /><br />'
4686: .&mt("You are not authorized to create new users in your current role's domain - [_1]."
4687: ,'<span class="LC_cusr_emph">'.$env{'request.role.domain'}.'</span>')
4688: .'<br />'
4689: .&mt('Contact the [_1]helpdesk[_2] if you need to create a new user.'
4690: ,' <a'.$helplink.'>'
4691: ,'</a>')
4692: .'<br /><br />';
1.221 raeburn 4693: }
1.160 raeburn 4694: }
4695: }
4696: }
1.179 raeburn 4697: return ($currstate,$response,$forcenewuser);
1.160 raeburn 4698: }
4699:
1.180 raeburn 4700: sub display_domain_info {
4701: my ($dom) = @_;
4702: my $output = $dom;
4703: if ($dom ne '') {
4704: my $domdesc = &Apache::lonnet::domain($dom,'description');
4705: if ($domdesc ne '') {
4706: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
4707: }
4708: }
4709: return $output;
4710: }
4711:
1.160 raeburn 4712: sub crumb_utilities {
4713: my %elements = (
4714: crtuser => {
4715: srchterm => 'text',
1.172 raeburn 4716: srchin => 'selectbox',
1.160 raeburn 4717: srchby => 'selectbox',
4718: srchtype => 'selectbox',
4719: srchdomain => 'selectbox',
4720: },
1.207 raeburn 4721: crtusername => {
4722: srchterm => 'text',
4723: srchdomain => 'selectbox',
4724: },
1.160 raeburn 4725: docustom => {
4726: rolename => 'selectbox',
4727: newrolename => 'textbox',
4728: },
1.179 raeburn 4729: studentform => {
4730: srchterm => 'text',
4731: srchin => 'selectbox',
4732: srchby => 'selectbox',
4733: srchtype => 'selectbox',
4734: srchdomain => 'selectbox',
4735: },
1.160 raeburn 4736: );
4737:
4738: my $jsback .= qq|
4739: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 4740: if (typeof prevphase == 'undefined') {
4741: formname.phase.value = '';
4742: }
4743: else {
4744: formname.phase.value = prevphase;
4745: }
4746: if (typeof prevstate == 'undefined') {
4747: formname.currstate.value = '';
4748: }
4749: else {
4750: formname.currstate.value = prevstate;
4751: }
1.160 raeburn 4752: formname.submit();
4753: }
4754: |;
4755: return ($jsback,\%elements);
4756: }
4757:
1.26 matthew 4758: sub course_level_table {
1.89 raeburn 4759: my (%inccourses) = @_;
1.26 matthew 4760: my $table = '';
1.62 www 4761: # Custom Roles?
4762:
1.190 raeburn 4763: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 4764: my %lt=&Apache::lonlocal::texthash(
4765: 'exs' => "Existing sections",
4766: 'new' => "Define new section",
4767: 'ssd' => "Set Start Date",
4768: 'sed' => "Set End Date",
1.131 raeburn 4769: 'crl' => "Course Level",
1.89 raeburn 4770: 'act' => "Activate",
4771: 'rol' => "Role",
4772: 'ext' => "Extent",
1.113 raeburn 4773: 'grs' => "Section",
1.89 raeburn 4774: 'sta' => "Start",
4775: 'end' => "End"
4776: );
1.62 www 4777:
1.135 raeburn 4778: foreach my $protectedcourse (sort( keys(%inccourses))) {
4779: my $thiscourse=$protectedcourse;
1.26 matthew 4780: $thiscourse=~s:_:/:g;
4781: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
4782: my $area=$coursedata{'description'};
1.119 raeburn 4783: my $type=$coursedata{'type'};
1.135 raeburn 4784: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 4785: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 4786: my %sections_count;
1.101 albertel 4787: if (defined($env{'request.course.id'})) {
4788: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 4789: %sections_count =
4790: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 4791: }
4792: }
1.213 raeburn 4793: my @roles = &Apache::lonuserutils::roles_by_context('course');
4794: foreach my $role (@roles) {
1.221 raeburn 4795: my $plrole=&Apache::lonnet::plaintext($role);
1.135 raeburn 4796: if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
1.221 raeburn 4797: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
4798: $plrole,\%sections_count,\%lt);
4799: } elsif ($env{'request.course.sec'} ne '') {
4800: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
4801: $env{'request.course.sec'})) {
4802: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
4803: $plrole,\%sections_count,\%lt);
1.26 matthew 4804: }
4805: }
4806: }
1.221 raeburn 4807: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
4808: foreach my $cust (sort keys %customroles) {
4809: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
4810: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
4811: $cust,\%sections_count,\%lt);
4812: }
1.62 www 4813: }
1.26 matthew 4814: }
4815: return '' if ($table eq ''); # return nothing if there is nothing
4816: # in the table
1.188 raeburn 4817: my $result;
4818: if (!$env{'request.course.id'}) {
4819: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
4820: }
4821: $result .=
1.136 raeburn 4822: &Apache::loncommon::start_data_table().
4823: &Apache::loncommon::start_data_table_header_row().
4824: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
4825: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
4826: &Apache::loncommon::end_data_table_header_row().
4827: $table.
4828: &Apache::loncommon::end_data_table();
1.26 matthew 4829: return $result;
4830: }
1.88 raeburn 4831:
1.221 raeburn 4832: sub course_level_row {
4833: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_;
1.222 raeburn 4834: my $row = &Apache::loncommon::start_data_table_row().
4835: ' <td><input type="checkbox" name="act_'.
4836: $protectedcourse.'_'.$role.'" /></td>'."\n".
4837: ' <td>'.$plrole.'</td>'."\n".
4838: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.221 raeburn 4839: if ($role eq 'cc') {
1.222 raeburn 4840: $row .= '<td> </td>';
1.221 raeburn 4841: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 4842: $row .= ' <td><input type="hidden" value="'.
4843: $env{'request.course.sec'}.'" '.
4844: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
4845: $env{'request.course.sec'}.'</td>';
1.221 raeburn 4846: } else {
4847: if (ref($sections_count) eq 'HASH') {
4848: my $currsec =
4849: &Apache::lonuserutils::course_sections($sections_count,
4850: $protectedcourse.'_'.$role);
1.222 raeburn 4851: $row .= '<td><table class="LC_createuser">'."\n".
4852: '<tr class="LC_section_row">'."\n".
4853: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
4854: $currsec.'</td>'."\n".
4855: ' <td> </td>'."\n".
4856: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 4857: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
4858: '" value="" />'.
4859: '<input type="hidden" '.
4860: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 4861: '</tr></table></td>'."\n";
1.221 raeburn 4862: } else {
1.222 raeburn 4863: $row .= '<td><input type="text" size="10" '.
4864: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 4865: }
4866: }
1.222 raeburn 4867: $row .= <<ENDTIMEENTRY;
4868: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 4869: <a href=
4870: "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 4871: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 4872: <a href=
4873: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
4874: ENDTIMEENTRY
1.222 raeburn 4875: $row .= &Apache::loncommon::end_data_table_row();
4876: return $row;
1.221 raeburn 4877: }
4878:
1.88 raeburn 4879: sub course_level_dc {
4880: my ($dcdom) = @_;
1.190 raeburn 4881: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 4882: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 4883: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
4884: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 4885: '<input type="hidden" name="dccourse" value="" />';
1.88 raeburn 4886: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.131 raeburn 4887: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
4888: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
1.88 raeburn 4889: my %lt=&Apache::lonlocal::texthash(
4890: 'rol' => "Role",
1.113 raeburn 4891: 'grs' => "Section",
1.88 raeburn 4892: 'exs' => "Existing sections",
4893: 'new' => "Define new section",
4894: 'sta' => "Start",
4895: 'end' => "End",
4896: 'ssd' => "Set Start Date",
4897: 'sed' => "Set End Date"
4898: );
1.131 raeburn 4899: my $header = '<h4>'.&mt('Course Level').'</h4>'.
1.136 raeburn 4900: &Apache::loncommon::start_data_table().
4901: &Apache::loncommon::start_data_table_header_row().
1.143 raeburn 4902: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 4903: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 4904: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.131 raeburn 4905: '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1.88 raeburn 4906: '<td><select name="role">'."\n";
1.213 raeburn 4907: foreach my $role (@roles) {
1.135 raeburn 4908: my $plrole=&Apache::lonnet::plaintext($role);
4909: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 4910: }
4911: if ( keys %customroles > 0) {
1.135 raeburn 4912: foreach my $cust (sort keys %customroles) {
1.101 albertel 4913: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 4914: '_'.$env{'user.name'}.'_'.$cust;
4915: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 4916: }
4917: }
4918: $otheritems .= '</select></td><td>'.
4919: '<table border="0" cellspacing="0" cellpadding="0">'.
4920: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
4921: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
4922: '<td> </td>'.
4923: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 4924: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 4925: '<input type="hidden" name="section" value="" />'.
1.113 raeburn 4926: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 4927: '</tr></table></td>';
4928: $otheritems .= <<ENDTIMEENTRY;
1.169 albertel 4929: <td><input type="hidden" name="start" value='' />
1.88 raeburn 4930: <a href=
4931: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 4932: <td><input type="hidden" name="end" value='' />
1.88 raeburn 4933: <a href=
4934: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
4935: ENDTIMEENTRY
1.136 raeburn 4936: $otheritems .= &Apache::loncommon::end_data_table_row().
4937: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 4938: return $cb_jscript.$header.$hiddenitems.$otheritems;
4939: }
4940:
1.237 raeburn 4941: sub update_selfenroll_config {
1.241 raeburn 4942: my ($r,$context,$permission) = @_;
1.237 raeburn 4943: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 4944: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 4945: my (%changes,%warning);
4946: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4947: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 4948: my $curr_types;
1.237 raeburn 4949: if (ref($row) eq 'ARRAY') {
4950: foreach my $item (@{$row}) {
4951: if ($item eq 'enroll_dates') {
4952: my (%currenrolldate,%newenrolldate);
4953: foreach my $type ('start','end') {
4954: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
4955: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
4956: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
4957: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
4958: }
4959: }
4960: } elsif ($item eq 'access_dates') {
4961: my (%currdate,%newdate);
4962: foreach my $type ('start','end') {
4963: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
4964: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
4965: if ($newdate{$type} ne $currdate{$type}) {
4966: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
4967: }
4968: }
1.241 raeburn 4969: } elsif ($item eq 'types') {
4970: $curr_types =
4971: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
4972: if ($env{'form.selfenroll_all'}) {
4973: if ($curr_types ne '*') {
4974: $changes{'internal.selfenroll_types'} = '*';
4975: } else {
4976: next;
4977: }
4978: } else {
1.249 raeburn 4979: my %currdoms;
1.241 raeburn 4980: my @entries = split(/;/,$curr_types);
4981: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 4982: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 4983: my $newnum = 0;
1.249 raeburn 4984: my @latesttypes;
4985: foreach my $num (@activations) {
4986: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
4987: if (@types > 0) {
1.241 raeburn 4988: @types = sort(@types);
4989: my $typestr = join(',',@types);
1.249 raeburn 4990: my $typedom = $env{'form.selfenroll_dom_'.$num};
4991: $latesttypes[$newnum] = $typedom.':'.$typestr;
4992: $currdoms{$typedom} = 1;
1.241 raeburn 4993: $newnum ++;
4994: }
4995: }
1.249 raeburn 4996: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) { if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
4997: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
4998: if (@types > 0) {
4999: @types = sort(@types);
5000: my $typestr = join(',',@types);
5001: my $typedom = $env{'form.selfenroll_dom_'.$j};
5002: $latesttypes[$newnum] = $typedom.':'.$typestr;
5003: $currdoms{$typedom} = 1;
5004: $newnum ++;
5005: }
5006: }
5007: }
5008: if ($env{'form.selfenroll_newdom'} ne '') {
5009: my $typedom = $env{'form.selfenroll_newdom'};
5010: if ((!defined($currdoms{$typedom})) &&
5011: (&Apache::lonnet::domain($typedom) ne '')) {
5012: my $typestr;
5013: my ($othertitle,$usertypes,$types) =
5014: &Apache::loncommon::sorted_inst_types($typedom);
5015: my $othervalue = 'any';
5016: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5017: if (@{$types} > 0) {
1.257 raeburn 5018: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 5019: $othervalue = 'other';
1.258 raeburn 5020: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 5021: }
5022: $typestr = $othervalue;
5023: } else {
5024: $typestr = $othervalue;
5025: }
5026: $latesttypes[$newnum] = $typedom.':'.$typestr;
5027: $newnum ++ ;
5028: }
5029: }
1.241 raeburn 5030: my $selfenroll_types = join(';',@latesttypes);
5031: if ($selfenroll_types ne $curr_types) {
5032: $changes{'internal.selfenroll_types'} = $selfenroll_types;
5033: }
5034: }
1.237 raeburn 5035: } else {
5036: my $curr_val =
5037: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
5038: my $newval = $env{'form.selfenroll_'.$item};
5039: if ($item eq 'section') {
5040: $newval = $env{'form.sections'};
1.241 raeburn 5041: if (defined($curr_groups{$newval})) {
1.237 raeburn 5042: $newval = $curr_val;
5043: $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');
5044: } elsif ($newval eq 'all') {
5045: $newval = $curr_val;
5046: $warning{$item} = &mt("Section for self-enrolled users unchanged, as 'all' is a reserved section name.");
5047: }
5048: if ($newval eq '') {
5049: $newval = 'none';
5050: }
5051: }
5052: if ($newval ne $curr_val) {
5053: $changes{'internal.selfenroll_'.$item} = $newval;
5054: }
1.241 raeburn 5055: }
1.237 raeburn 5056: }
5057: if (keys(%warning) > 0) {
5058: foreach my $item (@{$row}) {
5059: if (exists($warning{$item})) {
5060: $r->print($warning{$item}.'<br />');
5061: }
5062: }
5063: }
5064: if (keys(%changes) > 0) {
5065: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
5066: if ($putresult eq 'ok') {
5067: if ((exists($changes{'internal.selfenroll_types'})) ||
5068: (exists($changes{'internal.selfenroll_start_date'})) ||
5069: (exists($changes{'internal.selfenroll_end_date'}))) {
5070: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
5071: $cnum,undef,undef,'Course');
5072: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
5073: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
5074: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
5075: if (exists($changes{'internal.'.$item})) {
5076: $crsinfo{$env{'request.course.id'}}{$item} =
5077: $changes{'internal.'.$item};
5078: }
5079: }
5080: my $crsputresult =
5081: &Apache::lonnet::courseidput($cdom,\%crsinfo,
5082: $chome,'notime');
5083: }
5084: }
5085: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
5086: foreach my $item (@{$row}) {
5087: my $title = $item;
5088: if (ref($lt) eq 'HASH') {
5089: $title = $lt->{$item};
5090: }
5091: if ($item eq 'enroll_dates') {
5092: foreach my $type ('start','end') {
5093: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
5094: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 5095: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 5096: $title,$type,$newdate).'</li>');
5097: }
5098: }
5099: } elsif ($item eq 'access_dates') {
5100: foreach my $type ('start','end') {
5101: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
5102: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 5103: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 5104: $title,$type,$newdate).'</li>');
5105: }
5106: }
5107: } else {
5108: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 5109: my $newval = $changes{'internal.selfenroll_'.$item};
5110: if ($item eq 'types') {
5111: if ($newval eq '') {
5112: $newval = &mt('None');
5113: } elsif ($newval eq '*') {
5114: $newval = &mt('Any user in any domain');
5115: }
1.245 raeburn 5116: } elsif ($item eq 'registered') {
5117: if ($newval eq '1') {
5118: $newval = &mt('Yes');
5119: } elsif ($newval eq '0') {
5120: $newval = &mt('No');
5121: }
1.241 raeburn 5122: }
1.244 bisitz 5123: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 5124: }
5125: }
5126: }
5127: $r->print('</ul>');
5128: my %newenvhash;
5129: foreach my $key (keys(%changes)) {
5130: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
5131: }
1.238 raeburn 5132: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 5133: } else {
5134: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
5135: }
5136: } else {
1.249 raeburn 5137: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 5138: }
5139: } else {
1.249 raeburn 5140: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 5141: }
1.256 raeburn 5142: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
5143: if (ref($visactions) eq 'HASH') {
5144: if (!$visible) {
5145: $r->print('<br />'.$visactions->{'miss'}.'<br />'.$visactions->{'yous'}.
5146: '<br />');
5147: if (ref($vismsgs) eq 'ARRAY') {
5148: $r->print('<br />'.$visactions->{'take'}.'<ul>');
5149: foreach my $item (@{$vismsgs}) {
5150: $r->print('<li>'.$visactions->{$item}.'</li>');
5151: }
5152: $r->print('</ul>');
5153: }
5154: $r->print($cansetvis);
5155: }
5156: }
1.237 raeburn 5157: return;
5158: }
5159:
5160: sub get_selfenroll_titles {
5161: my @row = ('types','registered','enroll_dates','access_dates','section');
5162: my %lt = &Apache::lonlocal::texthash (
5163: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 5164: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 5165: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 5166: access_dates => 'Course access dates assigned to self-enrolling users',
5167: section => 'Section assigned to self-enrolling users',
1.237 raeburn 5168: );
5169: return (\@row,\%lt);
5170: }
5171:
1.27 matthew 5172: #---------------------------------------------- end functions for &phase_two
1.29 matthew 5173:
5174: #--------------------------------- functions for &phase_two and &phase_three
5175:
5176: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 5177:
5178: 1;
5179: __END__
1.2 www 5180:
5181:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>