1: # The LearningOnline Network with CAPA
2: # Create a user
3: #
4: # $Id: loncreateuser.pm,v 1.169 2007/08/10 23:00:13 albertel Exp $
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: #
28: ###
29:
30: package Apache::loncreateuser;
31:
32: =pod
33:
34: =head1 NAME
35:
36: Apache::loncreateuser - handler to create users and custom roles
37:
38: =head1 SYNOPSIS
39:
40: Apache::loncreateuser provides an Apache handler for creating users,
41: editing their login parameters, roles, and removing roles, and
42: also creating and assigning custom roles.
43:
44: =head1 OVERVIEW
45:
46: =head2 Custom Roles
47:
48: In LON-CAPA, roles are actually collections of privileges. "Teaching
49: Assistant", "Course Coordinator", and other such roles are really just
50: collection of privileges that are useful in many circumstances.
51:
52: Creating custom roles can be done by the Domain Coordinator through
53: the Create User functionality. That screen will show all privileges
54: that can be assigned to users. For a complete list of privileges,
55: please see C</home/httpd/lonTabs/rolesplain.tab>.
56:
57: Custom role definitions are stored in the C<roles.db> file of the role
58: author.
59:
60: =cut
61:
62: use strict;
63: use Apache::Constants qw(:common :http);
64: use Apache::lonnet;
65: use Apache::loncommon;
66: use Apache::lonlocal;
67: use Apache::longroup;
68: use LONCAPA qw(:DEFAULT :match);
69:
70: my $loginscript; # piece of javascript used in two separate instances
71: my $generalrule;
72: my $authformnop;
73: my $authformkrb;
74: my $authformint;
75: my $authformfsys;
76: my $authformloc;
77:
78: sub initialize_authen_forms {
79: my ($krbdefdom)=( $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/);
80: $krbdefdom= uc($krbdefdom);
81: my %param = ( formname => 'document.cu',
82: kerb_def_dom => $krbdefdom
83: );
84: # no longer static due to configurable kerberos defaults
85: # $loginscript = &Apache::loncommon::authform_header(%param);
86: $generalrule = &Apache::loncommon::authform_authorwarning(%param);
87: $authformnop = &Apache::loncommon::authform_nochange(%param);
88: # no longer static due to configurable kerberos defaults
89: # $authformkrb = &Apache::loncommon::authform_kerberos(%param);
90: $authformint = &Apache::loncommon::authform_internal(%param);
91: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
92: $authformloc = &Apache::loncommon::authform_local(%param);
93: }
94:
95:
96: # ======================================================= Existing Custom Roles
97:
98: sub my_custom_roles {
99: my %returnhash=();
100: my %rolehash=&Apache::lonnet::dump('roles');
101: foreach my $key (keys %rolehash) {
102: if ($key=~/^rolesdef\_(\w+)$/) {
103: $returnhash{$1}=$1;
104: }
105: }
106: return %returnhash;
107: }
108:
109: # ==================================================== Figure out author access
110:
111: sub authorpriv {
112: my ($auname,$audom)=@_;
113: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
114: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; }
115: return 1;
116: }
117:
118: # ====================================================
119:
120: sub portfolio_quota {
121: my ($ccuname,$ccdomain) = @_;
122: my %lt = &Apache::lonlocal::texthash(
123: 'disk' => "Disk space allocated to user's portfolio files",
124: 'cuqu' => "Current quota",
125: 'cust' => "Custom quota",
126: 'defa' => "Default",
127: 'chqu' => "Change quota",
128: );
129: my ($currquota,$quotatype,$inststatus,$defquota) =
130: &Apache::loncommon::get_user_quota($ccuname,$ccdomain);
131: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
132: my ($longinsttype,$showquota,$custom_on,$custom_off,$defaultinfo);
133: if ($inststatus ne '') {
134: if ($usertypes->{$inststatus} ne '') {
135: $longinsttype = $usertypes->{$inststatus};
136: }
137: }
138: $custom_on = ' ';
139: $custom_off = ' checked="checked" ';
140: my $quota_javascript = <<"END_SCRIPT";
141: <script type="text/javascript">
142: function quota_changes(caller) {
143: if (caller == "custom") {
144: if (document.cu.customquota[0].checked) {
145: document.cu.portfolioquota.value = "";
146: }
147: }
148: if (caller == "quota") {
149: document.cu.customquota[1].checked = true;
150: }
151: }
152: </script>
153: END_SCRIPT
154: if ($quotatype eq 'custom') {
155: $custom_on = $custom_off;
156: $custom_off = ' ';
157: $showquota = $currquota;
158: if ($longinsttype eq '') {
159: $defaultinfo = &mt('For this user, the default quota would be [_1]
160: Mb.',$defquota);
161: } else {
162: $defaultinfo = &mt("For this user, the default quota would be [_1]
163: Mb, as determined by the user's institutional
164: affiliation ([_2]).",$defquota,$longinsttype);
165: }
166: } else {
167: if ($longinsttype eq '') {
168: $defaultinfo = &mt('For this user, the default quota is [_1]
169: Mb.',$defquota);
170: } else {
171: $defaultinfo = &mt("For this user, the default quota of [_1]
172: Mb, is determined by the user's institutional
173: affiliation ([_2]).",$defquota,$longinsttype);
174: }
175: }
176: my $output = $quota_javascript.
177: '<h3>'.$lt{'disk'}.'</h3>'.
178: $lt{'cuqu'}.': '.$currquota.' Mb. '.
179: $defaultinfo.'<br /><span class="LC_nobreak">'.$lt{'chqu'}.
180: ': <label>'.
181: '<input type="radio" name="customquota" value="0" '.
182: $custom_off.' onchange="javascript:quota_changes('."'custom'".')"
183: />'.$lt{'defa'}.' ('.$defquota.' Mb).</label> '.
184: ' <label><input type="radio" name="customquota" value="1" '.
185: $custom_on.' onchange="javascript:quota_changes('."'custom'".')" />'.
186: $lt{'cust'}.':</label> '.
187: '<input type="text" name="portfolioquota" size ="5" value="'.
188: $showquota.'" onfocus="javascript:quota_changes('."'quota'".')" '.
189: '/> Mb';
190: return $output;
191: }
192:
193: # =================================================================== Phase one
194:
195: sub print_username_entry_form {
196: my ($r,$response,$srch,$forcenewuser) = @_;
197: my $defdom=$env{'request.role.domain'};
198: my $formtoset = 'crtuser';
199: if (exists($env{'form.startrolename'})) {
200: $formtoset = 'docustom';
201: $env{'form.rolename'} = $env{'form.startrolename'};
202: }
203:
204: my ($jsback,$elements) = &crumb_utilities();
205:
206: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
207: '<script type="text/javascript">'."\n".
208: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset}).
209: '</script>'."\n";
210:
211: my %loaditems = (
212: 'onload' => "javascript:setFormElements(document.$formtoset)",
213: );
214: my $start_page =
215: &Apache::loncommon::start_page('Create Users, Change User Privileges',
216: $jscript,{'add_entries' => \%loaditems,});
217: &Apache::lonhtmlcommon::add_breadcrumb
218: ({href=>"javascript:backPage(document.crtuser)",
219: text=>"User modify/custom role",
220: faq=>282,bug=>'Instructor Interface',});
221:
222: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management');
223: my %existingroles=&my_custom_roles();
224: my $choice=&Apache::loncommon::select_form('make new role','rolename',
225: ('make new role' => 'Generate new role ...',%existingroles));
226: my %lt=&Apache::lonlocal::texthash(
227: 'srch' => "User Search",
228: or => "or",
229: 'siur' => "Set Individual User Roles",
230: 'usr' => "Username",
231: 'dom' => "Domain",
232: 'ecrp' => "Edit Custom Role Privileges",
233: 'nr' => "Name of Role",
234: 'cre' => "Custom Role Editor",
235: 'mod' => "to add/modify roles",
236: );
237: my $help = &Apache::loncommon::help_open_menu(undef,undef,282,'Instructor Interface');
238: my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
239: my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
240: my $sellink=&Apache::loncommon::selectstudent_link('crtuser','srchterm','srchdomain');
241: if ($sellink) {
242: $sellink = "$lt{'or'} ".$sellink;
243: }
244: $r->print("
245: $start_page
246: $crumbs
247: <h2>$lt{siur}$helpsiur</h2>
248: <h3>$lt{'srch'} $sellink $lt{'mod'}</h3>
249: $response");
250: $r->print(&entry_form($defdom,$srch,$forcenewuser));
251: if (&Apache::lonnet::allowed('mcr','/')) {
252: $r->print(<<ENDCUSTOM);
253: <form action="/adm/createuser" method="post" name="docustom">
254: <input type="hidden" name="phase" value="selected_custom_edit" />
255: <h2>$lt{'ecrp'}$helpecpr</h2>
256: $lt{'nr'}: $choice <input type="text" size="15" name="newrolename" /><br />
257: <input name="customeditor" type="submit" value="$lt{'cre'}" />
258: </form>
259: ENDCUSTOM
260: }
261: $r->print(&Apache::loncommon::end_page());
262: }
263:
264: sub entry_form {
265: my ($dom,$srch,$forcenewuser) = @_;
266: my $userpicker =
267: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser);
268: my $srchbutton = &mt('Search');
269: my $output = <<"ENDDOCUMENT";
270: <form action="/adm/createuser" method="post" name="crtuser">
271: <input type="hidden" name="phase" value="get_user_info" />
272: $userpicker
273: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry()" />
274: </form>
275: ENDDOCUMENT
276: return $output;
277: }
278:
279: sub user_modification_js {
280: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
281:
282: return <<END;
283: <script type="text/javascript" language="Javascript">
284:
285: function pclose() {
286: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
287: "height=350,width=350,scrollbars=no,menubar=no");
288: parmwin.close();
289: }
290:
291: $pjump_def
292: $dc_setcourse_code
293:
294: function dateset() {
295: eval("document.cu."+document.cu.pres_marker.value+
296: ".value=document.cu.pres_value.value");
297: pclose();
298: }
299:
300: $nondc_setsection_code
301:
302: </script>
303: END
304: }
305:
306: # =================================================================== Phase two
307: sub print_user_selection_page {
308: my ($r,$response,$srch,$srch_results) = @_;
309: my @fields = ('username','domain','lastname','firstname','permanentemail');
310: my $sortby = $env{'form.sortby'};
311:
312: if (!grep(/^\Q$sortby\E$/,@fields)) {
313: $sortby = 'lastname';
314: }
315:
316: my ($jsback,$elements) = &crumb_utilities();
317:
318: my $jscript = (<<ENDSCRIPT);
319: <script type="text/javascript">
320: function pickuser(uname,udom) {
321: document.usersrchform.seluname.value=uname;
322: document.usersrchform.seludom.value=udom;
323: document.usersrchform.phase.value="userpicked";
324: document.usersrchform.submit();
325: }
326:
327: $jsback
328: </script>
329: ENDSCRIPT
330:
331: my %lt=&Apache::lonlocal::texthash(
332: 'srch' => "User Search to add/modify roles of",
333: 'username' => "username",
334: 'domain' => "domain",
335: 'lastname' => "last name",
336: 'firstname' => "first name",
337: 'permanentemail' => "permanent e-mail",
338: );
339: $r->print(&Apache::loncommon::start_page('Create Users, Change User Privileges',$jscript));
340: &Apache::lonhtmlcommon::add_breadcrumb
341: ({href=>"javascript:backPage(document.usersrchform,'','')",
342: text=>"User modify/custom role edit",
343: faq=>282,bug=>'Instructor Interface',},
344: {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
345: text=>"Select User",
346: faq=>282,bug=>'Instructor Interface',});
347: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
348: $r->print("<b>$lt{'srch'}</b><br />");
349: $r->print(&entry_form($srch->{'srchdomain'},$srch));
350: $r->print('<h3>'.&mt('Select a user to add/modify roles of').'</h3>');
351: $r->print('<form name="usersrchform" method="post">'.
352: &Apache::loncommon::start_data_table()."\n".
353: &Apache::loncommon::start_data_table_header_row()."\n".
354: ' <th> </th>'."\n");
355: foreach my $field (@fields) {
356: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
357: "'".$field."'".';document.usersrchform.submit();">'.
358: $lt{$field}.'</a></th>'."\n");
359: }
360: $r->print(&Apache::loncommon::end_data_table_header_row());
361:
362: my @sorted_users = sort {
363: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
364: ||
365: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
366: ||
367: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
368: ||
369: lc($a) cmp lc($b)
370: } (keys(%$srch_results));
371:
372: foreach my $user (@sorted_users) {
373: my ($uname,$udom) = split(/:/,$user);
374: $r->print(&Apache::loncommon::start_data_table_row().
375: '<td><input type="button" name="seluser" value="'.&mt('Select').'" onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".')" /></td>'.
376: '<td><tt>'.$uname.'</tt></td>'.
377: '<td><tt>'.$udom.'</tt></td>');
378: foreach my $field ('lastname','firstname','permanentemail') {
379: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
380: }
381: $r->print(&Apache::loncommon::end_data_table_row());
382: }
383: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
384: $r->print(&Apache::lonhtmlcommon::echo_form_input(['sortby','seluname','seludom','state','phase']));
385: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
386: ' <input type="hidden" name="seluname" value="" />'."\n".
387: ' <input type="hidden" name="seludom" value="" />'."\n".
388: ' <input type="hidden" name="state" value="select" />'."\n".
389: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
390: '</form>');
391: $r->print($response);
392: $r->print(&Apache::loncommon::end_page());
393: }
394:
395: sub print_user_query_page {
396: my ($r) = @_;
397: # FIXME - this is for a network-wide name search (similar to catalog search)
398: # To use frames with similar behavior to catalog/portfolio search.
399: # To be implemented.
400: return;
401: }
402:
403: sub print_user_modification_page {
404: my ($r,$ccuname,$ccdomain,$srch,$response) = @_;
405: unless (($ccuname) && ($ccdomain)) {
406: &print_username_entry_form($r);
407: return;
408: }
409: if ($response) {
410: $response = '<br />'.$response
411: }
412: my $defdom=$env{'request.role.domain'};
413:
414: my ($krbdef,$krbdefdom) =
415: &Apache::loncommon::get_kerberos_defaults($defdom);
416:
417: my %param = ( formname => 'document.cu',
418: kerb_def_dom => $krbdefdom,
419: kerb_def_auth => $krbdef
420: );
421: $loginscript = &Apache::loncommon::authform_header(%param);
422: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
423:
424: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
425: my $dc_setcourse_code = '';
426: my $nondc_setsection_code = '';
427:
428: my %loaditem;
429:
430: my $groupslist;
431: my %curr_groups = &Apache::longroup::coursegroups();
432: if (%curr_groups) {
433: $groupslist = join('","',sort(keys(%curr_groups)));
434: $groupslist = '"'.$groupslist.'"';
435: }
436:
437: if ($env{'request.role'} =~ m-^dc\./($match_domain)/$-) {
438: my $dcdom = $1;
439: $loaditem{'onload'} = "document.cu.coursedesc.value='';";
440: my @rolevals = ('st','ta','ep','in','cc');
441: my (@crsroles,@grproles);
442: for (my $i=0; $i<@rolevals; $i++) {
443: $crsroles[$i]=&Apache::lonnet::plaintext($rolevals[$i],'Course');
444: $grproles[$i]=&Apache::lonnet::plaintext($rolevals[$i],'Group');
445: }
446: my $rolevalslist = join('","',@rolevals);
447: my $crsrolenameslist = join('","',@crsroles);
448: my $grprolenameslist = join('","',@grproles);
449: my $pickcrsfirst = '<--'.&mt('Pick course first');
450: my $pickgrpfirst = '<--'.&mt('Pick group first');
451: $dc_setcourse_code = <<"ENDSCRIPT";
452: function setCourse() {
453: var course = document.cu.dccourse.value;
454: if (course != "") {
455: if (document.cu.dcdomain.value != document.cu.origdom.value) {
456: alert("You must select a course in the current domain");
457: return;
458: }
459: var userrole = document.cu.role.options[document.cu.role.selectedIndex].value
460: var section="";
461: var numsections = 0;
462: var newsecs = new Array();
463: for (var i=0; i<document.cu.currsec.length; i++) {
464: if (document.cu.currsec.options[i].selected == true ) {
465: if (document.cu.currsec.options[i].value != "" && document.cu.currsec.options[i].value != null) {
466: if (numsections == 0) {
467: section = document.cu.currsec.options[i].value
468: numsections = 1;
469: }
470: else {
471: section = section + "," + document.cu.currsec.options[i].value
472: numsections ++;
473: }
474: }
475: }
476: }
477: if (document.cu.newsec.value != "" && document.cu.newsec.value != null) {
478: if (numsections == 0) {
479: section = document.cu.newsec.value
480: }
481: else {
482: section = section + "," + document.cu.newsec.value
483: }
484: newsecs = document.cu.newsec.value.split(/,/g);
485: numsections = numsections + newsecs.length;
486: }
487: if ((userrole == 'st') && (numsections > 1)) {
488: alert("In each course, each user may only have one student role at a time. You had selected "+numsections+" sections.\\nPlease modify your selections so they include no more than one section.")
489: return;
490: }
491: for (var j=0; j<newsecs.length; j++) {
492: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
493: alert("'"+newsecs[j]+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
494: return;
495: }
496: if (document.cu.groups.value != '') {
497: var groups = document.cu.groups.value.split(/,/g);
498: for (var k=0; k<groups.length; k++) {
499: if (newsecs[j] == groups[k]) {
500: alert("'"+newsecs[j]+"' may not be used as the name for a section, as it is the name of a course group.\\nSection names and group names must be distinct. Please choose a different section name.");
501: return;
502: }
503: }
504: }
505: }
506: if ((userrole == 'cc') && (numsections > 0)) {
507: alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
508: section = "";
509: }
510: var coursename = "_$dcdom"+"_"+course+"_"+userrole
511: var numcourse = getIndex(document.cu.dccourse);
512: if (numcourse == "-1") {
513: alert("There was a problem with your course selection");
514: return
515: }
516: else {
517: document.cu.elements[numcourse].name = "act"+coursename;
518: var numnewsec = getIndex(document.cu.newsec);
519: if (numnewsec != "-1") {
520: document.cu.elements[numnewsec].name = "sec"+coursename;
521: document.cu.elements[numnewsec].value = section;
522: }
523: var numstart = getIndex(document.cu.start);
524: if (numstart != "-1") {
525: document.cu.elements[numstart].name = "start"+coursename;
526: }
527: var numend = getIndex(document.cu.end);
528: if (numend != "-1") {
529: document.cu.elements[numend].name = "end"+coursename
530: }
531: }
532: }
533: document.cu.submit();
534: }
535:
536: function getIndex(caller) {
537: for (var i=0;i<document.cu.elements.length;i++) {
538: if (document.cu.elements[i] == caller) {
539: return i;
540: }
541: }
542: return -1;
543: }
544: ENDSCRIPT
545: } else {
546: $nondc_setsection_code = <<"ENDSECCODE";
547: function setSections() {
548: var re1 = /^currsec_/;
549: var groups = new Array($groupslist);
550: for (var i=0;i<document.cu.elements.length;i++) {
551: var str = document.cu.elements[i].name;
552: var checkcurr = str.match(re1);
553: if (checkcurr != null) {
554: if (document.cu.elements[i-1].checked == true) {
555: var match = str.split('_');
556: var role = match[3];
557: if (role == 'cc') {
558: alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
559: }
560: else {
561: var sections = '';
562: var numsec = 0;
563: var sections;
564: for (var j=0; j<document.cu.elements[i].length; j++) {
565: if (document.cu.elements[i].options[j].selected == true ) {
566: if (document.cu.elements[i].options[j].value != "") {
567: if (numsec == 0) {
568: if (document.cu.elements[i].options[j].value != "") {
569: sections = document.cu.elements[i].options[j].value;
570: numsec ++;
571: }
572: }
573: else {
574: sections = sections + "," + document.cu.elements[i].options[j].value
575: numsec ++;
576: }
577: }
578: }
579: }
580: if (numsec > 0) {
581: if (document.cu.elements[i+1].value != "" && document.cu.elements[i+1].value != null) {
582: sections = sections + "," + document.cu.elements[i+1].value;
583: }
584: }
585: else {
586: sections = document.cu.elements[i+1].value;
587: }
588: var newsecs = document.cu.elements[i+1].value;
589: var numsplit;
590: if (newsecs != null && newsecs != "") {
591: numsplit = newsecs.split(/,/g);
592: numsec = numsec + numsplit.length;
593: }
594:
595: if ((role == 'st') && (numsec > 1)) {
596: alert("In each course, each user may only have one student role at a time. You had selected "+numsec+" sections.\\nPlease modify your selections so they include no more than one section.")
597: return;
598: }
599: else if (numsplit != null) {
600: for (var j=0; j<numsplit.length; j++) {
601: if ((numsplit[j] == 'all') ||
602: (numsplit[j] == 'none')) {
603: alert("'"+numsplit[j]+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
604: return;
605: }
606: for (var k=0; k<groups.length; k++) {
607: if (numsplit[j] == groups[k]) {
608: alert("'"+numsplit[j]+"' may not be used as a section name, as it is the name of a course group.\\nSection names and group names must be distinct. Please choose a different section name.");
609: return;
610: }
611: }
612: }
613: }
614: document.cu.elements[i+2].value = sections;
615: }
616: }
617: }
618: }
619: document.cu.submit();
620: }
621: ENDSECCODE
622: }
623: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
624: $nondc_setsection_code,$groupslist);
625:
626: my ($jsback,$elements) = &crumb_utilities();
627:
628: $js .= "\n".
629: '<script type="text/javascript">'."\n".$jsback."\n".'</script>';
630:
631: my $start_page =
632: &Apache::loncommon::start_page('Create Users, Change User Privileges',
633: $js,{'add_entries' => \%loaditem,});
634: &Apache::lonhtmlcommon::add_breadcrumb
635: ({href=>"javascript:backPage(document.cu)",
636: text=>"User modify/custom role edit",
637: faq=>282,bug=>'Instructor Interface',});
638:
639: if ($env{'form.phase'} eq 'userpicked') {
640: &Apache::lonhtmlcommon::add_breadcrumb
641: ({href=>"javascript:backPage(document.cu,'get_user_info','select')",
642: text=>"Select a user",
643: faq=>282,bug=>'Instructor Interface',});
644: }
645: &Apache::lonhtmlcommon::add_breadcrumb
646: ({href=>"javascript:backPage(document.cu,'$env{'form.phase'}','modify')",
647: text=>"Set user role",
648: faq=>282,bug=>'Instructor Interface',});
649: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management');
650:
651: my $forminfo =<<"ENDFORMINFO";
652: <form action="/adm/createuser" method="post" name="cu">
653: <input type="hidden" name="phase" value="update_user_data" />
654: <input type="hidden" name="ccuname" value="$ccuname" />
655: <input type="hidden" name="ccdomain" value="$ccdomain" />
656: <input type="hidden" name="pres_value" value="" />
657: <input type="hidden" name="pres_type" value="" />
658: <input type="hidden" name="pres_marker" value="" />
659: ENDFORMINFO
660: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
661: my %inccourses;
662: foreach my $key (keys(%env)) {
663: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
664: $inccourses{$1.'_'.$2}=1;
665: }
666: }
667: if ($uhome eq 'no_host') {
668: my $newuser;
669: my $instsrch = {
670: srchin => 'instd',
671: srchby => 'uname',
672: srchtype => 'exact',
673: };
674: if ($env{'form.phase'} eq 'userpicked') {
675: $instsrch->{'srchterm'} = $env{'form.seluname'};
676: $instsrch->{'srchdomain'} = $env{'form.seludom'};
677: } else {
678: $instsrch->{'srchterm'} = $ccuname;
679: $instsrch->{'srchdomain'} = $ccdomain,
680: }
681: if (($instsrch->{'srchterm'} ne '') && ($instsrch->{'srchdomain'} ne '')) {
682: $newuser = $instsrch->{'srchterm'}.':'.$instsrch->{'srchdomain'};
683: }
684: my (%dirsrch_results,%inst_results);
685: if ($newuser) {
686: if (&directorysrch_check($instsrch) eq 'ok') {
687: %dirsrch_results = &Apache::lonnet::inst_directory_query($instsrch);
688: if (ref($dirsrch_results{$newuser}) eq 'HASH') {
689: %inst_results = %{$dirsrch_results{$newuser}};
690: }
691: }
692: }
693: my $home_server_list=
694: '<option value="default" selected>default</option>'."\n".
695: &Apache::loncommon::home_server_option_list($ccdomain);
696:
697: my %lt=&Apache::lonlocal::texthash(
698: 'cnu' => "Create New User",
699: 'nu' => "New User",
700: 'id' => "in domain",
701: 'pd' => "Personal Data",
702: 'fn' => "First Name",
703: 'mn' => "Middle Name",
704: 'ln' => "Last Name",
705: 'gen' => "Generation",
706: 'mail' => "Permanent e-mail address",
707: 'idsn' => "ID/Student Number",
708: 'hs' => "Home Server",
709: 'lg' => "Login Data"
710: );
711: my $portfolioform;
712: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
713: # Current user has quota modification privileges
714: $portfolioform = &portfolio_quota($ccuname,$ccdomain);
715: }
716: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
717: &initialize_authen_forms();
718: $r->print(<<ENDNEWUSER);
719: $start_page
720: $crumbs
721: <h1>$lt{'cnu'}</h1>
722: $response
723: $forminfo
724: <h2>$lt{'nu'} "$ccuname" $lt{'id'} $ccdomain</h2>
725: <script type="text/javascript" language="Javascript">
726: $loginscript
727: </script>
728: <input type='hidden' name='makeuser' value='1' />
729: <h3>$lt{'pd'}</h3>
730: <p>
731: <table>
732: <tr><td>$lt{'fn'} </td>
733: <td><input type="text" name="cfirst" size="15" value="$inst_results{'firstname'}" /></td></tr>
734: <tr><td>$lt{'mn'} </td>
735: <td><input type="text" name="cmiddle" size="15" value="$inst_results{'middlename'}" /></td></tr>
736: <tr><td>$lt{'ln'} </td>
737: <td><input type="text" name="clast" size="15" value="$inst_results{'lastname'}" /></td></tr>
738: <tr><td>$lt{'gen'}$genhelp</td>
739: <td><input type="text" name="cgen" size="5" value="$inst_results{'generation'}" /></td></tr>
740: <tr><td>$lt{'mail'}</td>
741: <td><input type="text" name="cemail" size="20" value="$inst_results{'permanentemail'}" /></td></tr>
742: </table>
743: $lt{'idsn'} <input type="text" name="cstid" size="15" value="$inst_results{'id'}" /></p>
744: $lt{'hs'}: <select name="hserver" size="1"> $home_server_list </select>
745: <hr />
746: <h3>$lt{'lg'}</h3>
747: <p>$generalrule </p>
748: <p>$authformkrb </p>
749: <p>$authformint </p>
750: <p>$authformfsys</p>
751: <p>$authformloc </p>
752: <hr />
753: $portfolioform
754: ENDNEWUSER
755: } else { # user already exists
756: my %lt=&Apache::lonlocal::texthash(
757: 'cup' => "Change User Privileges",
758: 'usr' => "User",
759: 'id' => "in domain",
760: 'fn' => "first name",
761: 'mn' => "middle name",
762: 'ln' => "last name",
763: 'gen' => "generation",
764: 'email' => "permanent e-mail",
765: );
766: $r->print(<<ENDCHANGEUSER);
767: $start_page
768: $crumbs
769: <h1>$lt{'cup'}</h1>
770: $forminfo
771: <h2>$lt{'usr'} "$ccuname" $lt{'id'} "$ccdomain"</h2>
772: ENDCHANGEUSER
773: # Get the users information
774: my %userenv =
775: &Apache::lonnet::get('environment',
776: ['firstname','middlename','lastname','generation',
777: 'permanentemail','portfolioquota'],$ccdomain,$ccuname);
778: my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
779: $r->print('
780: <hr />'.
781: &Apache::loncommon::start_data_table().
782: &Apache::loncommon::start_data_table_header_row().
783: '<th>'.$lt{'fn'}.'</th><th>'.$lt{'mn'}.'</th><th>'.$lt{'ln'}.'</th><th>'.$lt{'gen'}.'</th><th>'.$lt{'email'}.'</th>'.
784: &Apache::loncommon::end_data_table_header_row().
785: &Apache::loncommon::start_data_table_row());
786: foreach my $item ('firstname','middlename','lastname','generation','permenanentemail') {
787: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
788: $r->print(<<"END");
789: <td><input type="text" name="c$item" value="$userenv{$item}" size="15" /></td>
790: END
791: } else {
792: $r->print('<td>'.$userenv{$item}.'</td>');
793: }
794: }
795: $r->print(&Apache::loncommon::end_data_table_row().
796: &Apache::loncommon::end_data_table());
797: # Build up table of user roles to allow revocation of a role.
798: my ($tmp) = keys(%rolesdump);
799: unless ($tmp =~ /^(con_lost|error)/i) {
800: my $now=time;
801: my %lt=&Apache::lonlocal::texthash(
802: 'rer' => "Revoke Existing Roles",
803: 'rev' => "Revoke",
804: 'del' => "Delete",
805: 'ren' => "Re-Enable",
806: 'rol' => "Role",
807: 'ext' => "Extent",
808: 'sta' => "Start",
809: 'end' => "End"
810: );
811: my (%roletext,%sortrole,%roleclass,%rolepriv);
812: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
813: my $b1=join('_',(split('_',$b))[1,0]);
814: return $a1 cmp $b1;
815: } keys(%rolesdump)) {
816: next if ($area =~ /^rolesdef/);
817: my $envkey=$area;
818: my $role = $rolesdump{$area};
819: my $thisrole=$area;
820: $area =~ s/\_\w\w$//;
821: my ($role_code,$role_end_time,$role_start_time) =
822: split(/_/,$role);
823: # Is this a custom role? Get role owner and title.
824: my ($croleudom,$croleuname,$croletitle)=
825: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
826: my $allowed=0;
827: my $delallowed=0;
828: my $sortkey=$role_code;
829: my $class='Unknown';
830: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
831: $class='Course';
832: my ($coursedom,$coursedir) = ($1,$2);
833: $sortkey.="\0$coursedom";
834: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
835: my %coursedata=
836: &Apache::lonnet::coursedescription($1.'_'.$2);
837: my $carea;
838: if (defined($coursedata{'description'})) {
839: $carea=$coursedata{'description'}.
840: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
841: &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
842: $sortkey.="\0".$coursedata{'description'};
843: $class=$coursedata{'type'};
844: } else {
845: $carea=&mt('Unavailable course').': '.$area;
846: $sortkey.="\0".&mt('Unavailable course').': '.$area;
847: }
848: $sortkey.="\0$coursedir";
849: $inccourses{$1.'_'.$2}=1;
850: if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
851: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
852: $allowed=1;
853: }
854: if ((&Apache::lonnet::allowed('dro',$1)) ||
855: (&Apache::lonnet::allowed('dro',$ccdomain))) {
856: $delallowed=1;
857: }
858: # - custom role. Needs more info, too
859: if ($croletitle) {
860: if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
861: $allowed=1;
862: $thisrole.='.'.$role_code;
863: }
864: }
865: # Compute the background color based on $area
866: if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
867: $carea.='<br />Section: '.$3;
868: $sortkey.="\0$3";
869: }
870: $area=$carea;
871: } else {
872: $sortkey.="\0".$area;
873: # Determine if current user is able to revoke privileges
874: if ($area=~m{^/($match_domain)/}) {
875: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
876: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
877: $allowed=1;
878: }
879: if (((&Apache::lonnet::allowed('dro',$1)) ||
880: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
881: ($role_code ne 'dc')) {
882: $delallowed=1;
883: }
884: } else {
885: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
886: $allowed=1;
887: }
888: }
889: if ($role_code eq 'ca' || $role_code eq 'au') {
890: $class='Construction Space';
891: } elsif ($role_code eq 'su') {
892: $class='System';
893: } else {
894: $class='Domain';
895: }
896: }
897: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
898: $area=~m{/($match_domain)/($match_username)};
899: if (&authorpriv($2,$1)) {
900: $allowed=1;
901: } else {
902: $allowed=0;
903: }
904: }
905: my $row = '';
906: $row.= '<td>';
907: my $active=1;
908: $active=0 if (($role_end_time) && ($now>$role_end_time));
909: if (($active) && ($allowed)) {
910: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
911: } else {
912: if ($active) {
913: $row.=' ';
914: } else {
915: $row.=&mt('expired or revoked');
916: }
917: }
918: $row.='</td><td>';
919: if ($allowed && !$active) {
920: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
921: } else {
922: $row.=' ';
923: }
924: $row.='</td><td>';
925: if ($delallowed) {
926: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
927: } else {
928: $row.=' ';
929: }
930: my $plaintext='';
931: if (!$croletitle) {
932: $plaintext=&Apache::lonnet::plaintext($role_code,$class)
933: } else {
934: $plaintext=
935: "Customrole '$croletitle' defined by $croleuname\@$croleudom";
936: }
937: $row.= '</td><td>'.$plaintext.
938: '</td><td>'.$area.
939: '</td><td>'.($role_start_time?localtime($role_start_time)
940: : ' ' ).
941: '</td><td>'.($role_end_time ?localtime($role_end_time)
942: : ' ' )
943: ."</td>";
944: $sortrole{$sortkey}=$envkey;
945: $roletext{$envkey}=$row;
946: $roleclass{$envkey}=$class;
947: $rolepriv{$envkey}=$allowed;
948: #$r->print($row);
949: } # end of foreach (table building loop)
950: my $rolesdisplay = 0;
951: my %output = ();
952: foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
953: $output{$type} = '';
954: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
955: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
956: $output{$type}.=
957: &Apache::loncommon::start_data_table_row().
958: $roletext{$sortrole{$which}}.
959: &Apache::loncommon::end_data_table_row();
960: }
961: }
962: unless($output{$type} eq '') {
963: $output{$type} = '<tr class="LC_info_row">'.
964: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
965: $output{$type};
966: $rolesdisplay = 1;
967: }
968: }
969: if ($rolesdisplay == 1) {
970: $r->print('
971: <hr />
972: <h3>'.$lt{'rer'}.'</h3>'.
973: &Apache::loncommon::start_data_table("LC_createuser").
974: &Apache::loncommon::start_data_table_header_row().
975: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
976: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
977: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
978: &Apache::loncommon::end_data_table_header_row());
979: foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
980: if ($output{$type}) {
981: $r->print($output{$type}."\n");
982: }
983: }
984: $r->print(&Apache::loncommon::end_data_table());
985: }
986: } # End of unless
987: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
988: if ($currentauth=~/^krb(4|5):/) {
989: $currentauth=~/^krb(4|5):(.*)/;
990: my $krbdefdom=$2;
991: my %param = ( formname => 'document.cu',
992: kerb_def_dom => $krbdefdom
993: );
994: $loginscript = &Apache::loncommon::authform_header(%param);
995: }
996: # Check for a bad authentication type
997: unless ($currentauth=~/^krb(4|5):/ or
998: $currentauth=~/^unix:/ or
999: $currentauth=~/^internal:/ or
1000: $currentauth=~/^localauth:/
1001: ) { # bad authentication scheme
1002: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1003: &initialize_authen_forms();
1004: my %lt=&Apache::lonlocal::texthash(
1005: 'err' => "ERROR",
1006: 'uuas' => "This user has an unrecognized authentication scheme",
1007: 'sldb' => "Please specify login data below",
1008: 'ld' => "Login Data"
1009: );
1010: $r->print(<<ENDBADAUTH);
1011: <hr />
1012: <script type="text/javascript" language="Javascript">
1013: $loginscript
1014: </script>
1015: <font color='#ff0000'>$lt{'err'}:</font>
1016: $lt{'uuas'} ($currentauth). $lt{'sldb'}.
1017: <h3>$lt{'ld'}</h3>
1018: <p>$generalrule</p>
1019: <p>$authformkrb</p>
1020: <p>$authformint</p>
1021: <p>$authformfsys</p>
1022: <p>$authformloc</p>
1023: ENDBADAUTH
1024: } else {
1025: # This user is not allowed to modify the user's
1026: # authentication scheme, so just notify them of the problem
1027: my %lt=&Apache::lonlocal::texthash(
1028: 'err' => "ERROR",
1029: 'uuas' => "This user has an unrecognized authentication scheme",
1030: 'adcs' => "Please alert a domain coordinator of this situation"
1031: );
1032: $r->print(<<ENDBADAUTH);
1033: <hr />
1034: <font color="#ff0000"> $lt{'err'}: </font>
1035: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
1036: <hr />
1037: ENDBADAUTH
1038: }
1039: } else { # Authentication type is valid
1040: my $authformcurrent='';
1041: my $authform_other='';
1042: &initialize_authen_forms();
1043: if ($currentauth=~/^krb(4|5):/) {
1044: $authformcurrent=$authformkrb;
1045: $authform_other="<p>$authformint</p>\n".
1046: "<p>$authformfsys</p><p>$authformloc</p>";
1047: }
1048: elsif ($currentauth=~/^internal:/) {
1049: $authformcurrent=$authformint;
1050: $authform_other="<p>$authformkrb</p>".
1051: "<p>$authformfsys</p><p>$authformloc</p>";
1052: }
1053: elsif ($currentauth=~/^unix:/) {
1054: $authformcurrent=$authformfsys;
1055: $authform_other="<p>$authformkrb</p>".
1056: "<p>$authformint</p><p>$authformloc;</p>";
1057: }
1058: elsif ($currentauth=~/^localauth:/) {
1059: $authformcurrent=$authformloc;
1060: $authform_other="<p>$authformkrb</p>".
1061: "<p>$authformint</p><p>$authformfsys</p>";
1062: }
1063: $authformcurrent.=' <i>(will override current values)</i><br />';
1064: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1065: # Current user has login modification privileges
1066: my %lt=&Apache::lonlocal::texthash(
1067: 'ccld' => "Change Current Login Data",
1068: 'enld' => "Enter New Login Data"
1069: );
1070: $r->print(<<ENDOTHERAUTHS);
1071: <hr />
1072: <script type="text/javascript" language="Javascript">
1073: $loginscript
1074: </script>
1075: <h3>$lt{'ccld'}</h3>
1076: <p>$generalrule</p>
1077: <p>$authformnop</p>
1078: <p>$authformcurrent</p>
1079: <h3>$lt{'enld'}</h3>
1080: $authform_other
1081: ENDOTHERAUTHS
1082: } else {
1083: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1084: my %lt=&Apache::lonlocal::texthash(
1085: 'ccld' => "Change Current Login Data",
1086: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
1087: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1088: );
1089: $r->print(<<ENDNOPRIV);
1090: <hr />
1091: <h3>$lt{'ccld'}</h3>
1092: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1093: ENDNOPRIV
1094: }
1095: }
1096: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1097: # Current user has quota modification privileges
1098: $r->print(&portfolio_quota($ccuname,$ccdomain));
1099: }
1100: } ## End of "check for bad authentication type" logic
1101: } ## End of new user/old user logic
1102: $r->print('<hr /><h3>'.&mt('Add Roles').'</h3>');
1103: #
1104: # Co-Author
1105: #
1106: if (&authorpriv($env{'user.name'},$env{'request.role.domain'}) &&
1107: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1108: # No sense in assigning co-author role to yourself
1109: my $cuname=$env{'user.name'};
1110: my $cudom=$env{'request.role.domain'};
1111: my %lt=&Apache::lonlocal::texthash(
1112: 'cs' => "Construction Space",
1113: 'act' => "Activate",
1114: 'rol' => "Role",
1115: 'ext' => "Extent",
1116: 'sta' => "Start",
1117: 'end' => "End",
1118: 'cau' => "Co-Author",
1119: 'caa' => "Assistant Co-Author",
1120: 'ssd' => "Set Start Date",
1121: 'sed' => "Set End Date"
1122: );
1123: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
1124: &Apache::loncommon::start_data_table()."\n".
1125: &Apache::loncommon::start_data_table_header_row()."\n".
1126: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
1127: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
1128: '<th>'.$lt{'end'}.'</th>'."\n".
1129: &Apache::loncommon::end_data_table_header_row()."\n".
1130: &Apache::loncommon::start_data_table_row()."\n".
1131: '<td>
1132: <input type=checkbox name="act_'.$cudom.'_'.$cuname.'_ca" />
1133: </td>
1134: <td>'.$lt{'cau'}.'</td>
1135: <td>'.$cudom.'_'.$cuname.'</td>
1136: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
1137: <a href=
1138: "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>
1139: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
1140: <a href=
1141: "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".
1142: &Apache::loncommon::end_data_table_row()."\n".
1143: &Apache::loncommon::start_data_table_row()."\n".
1144: '<td><input type=checkbox name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1145: <td>'.$lt{'caa'}.'</td>
1146: <td>'.$cudom.'_'.$cuname.'</td>
1147: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
1148: <a href=
1149: "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>
1150: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
1151: <a href=
1152: "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".
1153: &Apache::loncommon::end_data_table_row()."\n".
1154: &Apache::loncommon::end_data_table());
1155: }
1156: #
1157: # Domain level
1158: #
1159: my $num_domain_level = 0;
1160: my $domaintext =
1161: '<h4>'.&mt('Domain Level').'</h4>'.
1162: &Apache::loncommon::start_data_table().
1163: &Apache::loncommon::start_data_table_header_row().
1164: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
1165: &mt('Extent').'</th>'.
1166: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
1167: &Apache::loncommon::end_data_table_header_row();
1168: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1169: foreach my $role ('dc','li','dg','au','sc') {
1170: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1171: my $plrole=&Apache::lonnet::plaintext($role);
1172: my %lt=&Apache::lonlocal::texthash(
1173: 'ssd' => "Set Start Date",
1174: 'sed' => "Set End Date"
1175: );
1176: $num_domain_level ++;
1177: $domaintext .=
1178: &Apache::loncommon::start_data_table_row().
1179: '<td><input type=checkbox name="act_'.$thisdomain.'_'.$role.'" /></td>
1180: <td>'.$plrole.'</td>
1181: <td>'.$thisdomain.'</td>
1182: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
1183: <a href=
1184: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1185: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
1186: <a href=
1187: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
1188: &Apache::loncommon::end_data_table_row();
1189: }
1190: }
1191: }
1192: $domaintext.= &Apache::loncommon::end_data_table();
1193: if ($num_domain_level > 0) {
1194: $r->print($domaintext);
1195: }
1196: #
1197: # Course and group levels
1198: #
1199:
1200: if ($env{'request.role'} =~ m{^dc\./($match_domain)/$}) {
1201: $r->print(&course_level_dc($1,'Course'));
1202: $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()" />'."\n");
1203: } else {
1204: $r->print(&course_level_table(%inccourses));
1205: $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setSections()" />'."\n");
1206: }
1207: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','state']));
1208: $r->print('<input type="hidden" name="state" value="" />');
1209: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />');
1210: $r->print("</form>".&Apache::loncommon::end_page());
1211: }
1212:
1213: # ================================================================= Phase Three
1214: sub update_user_data {
1215: my ($r) = @_;
1216: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
1217: $env{'form.ccdomain'});
1218: # Error messages
1219: my $error = '<font color="#ff0000">'.&mt('Error').':</font>';
1220: my $end = &Apache::loncommon::end_page();
1221:
1222: my $title;
1223: if (exists($env{'form.makeuser'})) {
1224: $title='Set Privileges for New User';
1225: } else {
1226: $title='Modify User Privileges';
1227: }
1228:
1229: my ($jsback,$elements) = &crumb_utilities();
1230: my $jscript = '<script type="text/javascript">'."\n".
1231: $jsback."\n".'</script>'."\n";
1232:
1233: $r->print(&Apache::loncommon::start_page($title,$jscript));
1234: &Apache::lonhtmlcommon::add_breadcrumb
1235: ({href=>"javascript:backPage(document.userupdate)",
1236: text=>"User modify/custom role edit",
1237: faq=>282,bug=>'Instructor Interface',});
1238: if ($env{'form.prevphase'} eq 'userpicked') {
1239: &Apache::lonhtmlcommon::add_breadcrumb
1240: ({href=>"javascript:backPage(document.userupdate,'get_user_info','select')",
1241: text=>"Select a user",
1242: faq=>282,bug=>'Instructor Interface',});
1243: }
1244: &Apache::lonhtmlcommon::add_breadcrumb
1245: ({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
1246: text=>"Set user role",
1247: faq=>282,bug=>'Instructor Interface',},
1248: {href=>"/adm/createuser",
1249: text=>"Result",
1250: faq=>282,bug=>'Instructor Interface',});
1251: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1252:
1253: my %disallowed;
1254: # Check Inputs
1255: if (! $env{'form.ccuname'} ) {
1256: $r->print($error.&mt('No login name specified').'.'.$end);
1257: return;
1258: }
1259: if ( $env{'form.ccuname'} ne
1260: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1261: $r->print($error.&mt('Invalid login name').'. '.
1262: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid').'.'.
1263: $end);
1264: return;
1265: }
1266: if (! $env{'form.ccdomain'} ) {
1267: $r->print($error.&mt('No domain specified').'.'.$end);
1268: return;
1269: }
1270: if ( $env{'form.ccdomain'} ne
1271: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1272: $r->print($error.&mt ('Invalid domain name').'. '.
1273: &mt('Only letters, numbers, periods, dashes, and underscores are valid').'.'.
1274: $end);
1275: return;
1276: }
1277: if (! exists($env{'form.makeuser'})) {
1278: # Modifying an existing user, so check the validity of the name
1279: if ($uhome eq 'no_host') {
1280: $r->print($error.&mt('Unable to determine home server for ').
1281: $env{'form.ccuname'}.&mt(' in domain ').
1282: $env{'form.ccdomain'}.'.');
1283: return;
1284: }
1285: }
1286: # Determine authentication method and password for the user being modified
1287: my $amode='';
1288: my $genpwd='';
1289: if ($env{'form.login'} eq 'krb') {
1290: $amode='krb';
1291: $amode.=$env{'form.krbver'};
1292: $genpwd=$env{'form.krbarg'};
1293: } elsif ($env{'form.login'} eq 'int') {
1294: $amode='internal';
1295: $genpwd=$env{'form.intarg'};
1296: } elsif ($env{'form.login'} eq 'fsys') {
1297: $amode='unix';
1298: $genpwd=$env{'form.fsysarg'};
1299: } elsif ($env{'form.login'} eq 'loc') {
1300: $amode='localauth';
1301: $genpwd=$env{'form.locarg'};
1302: $genpwd=" " if (!$genpwd);
1303: } elsif (($env{'form.login'} eq 'nochange') ||
1304: ($env{'form.login'} eq '' )) {
1305: # There is no need to tell the user we did not change what they
1306: # did not ask us to change.
1307: # If they are creating a new user but have not specified login
1308: # information this will be caught below.
1309: } else {
1310: $r->print($error.&mt('Invalid login mode or password').$end);
1311: return;
1312: }
1313:
1314:
1315: $r->print('<h2>'.&mt('User [_1] in domain [_2]',
1316: $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h2>');
1317:
1318: if ($env{'form.makeuser'}) {
1319: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1320: # Check for the authentication mode and password
1321: if (! $amode || ! $genpwd) {
1322: $r->print($error.&mt('Invalid login mode or password').$end);
1323: return;
1324: }
1325: # Determine desired host
1326: my $desiredhost = $env{'form.hserver'};
1327: if (lc($desiredhost) eq 'default') {
1328: $desiredhost = undef;
1329: } else {
1330: my %home_servers =
1331: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1332: if (! exists($home_servers{$desiredhost})) {
1333: $r->print($error.&mt('Invalid home server specified'));
1334: return;
1335: }
1336: }
1337: # Call modifyuser
1338: my $result = &Apache::lonnet::modifyuser
1339: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cstid'},
1340: $amode,$genpwd,$env{'form.cfirst'},
1341: $env{'form.cmiddle'},$env{'form.clast'},$env{'form.cgen'},
1342: undef,$desiredhost
1343: );
1344: $r->print(&mt('Generating user').': '.$result);
1345: my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},
1346: $env{'form.ccdomain'});
1347: $r->print('<br />'.&mt('Home server').': '.$home.' '.
1348: &Apache::lonnet::hostname($home));
1349: } elsif (($env{'form.login'} ne 'nochange') &&
1350: ($env{'form.login'} ne '' )) {
1351: # Modify user privileges
1352: if (! $amode || ! $genpwd) {
1353: $r->print($error.'Invalid login mode or password'.$end);
1354: return;
1355: }
1356: # Only allow authentification modification if the person has authority
1357: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1358: $r->print('Modifying authentication: '.
1359: &Apache::lonnet::modifyuserauth(
1360: $env{'form.ccdomain'},$env{'form.ccuname'},
1361: $amode,$genpwd));
1362: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1363: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1364: } else {
1365: # Okay, this is a non-fatal error.
1366: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.');
1367: }
1368: }
1369: ##
1370: if (! $env{'form.makeuser'} ) {
1371: # Check for need to change
1372: my %userenv = &Apache::lonnet::get
1373: ('environment',['firstname','middlename','lastname','generation',
1374: 'permanentemail','portfolioquota','inststatus'],
1375: $env{'form.ccdomain'},$env{'form.ccuname'});
1376: my ($tmp) = keys(%userenv);
1377: if ($tmp =~ /^(con_lost|error)/i) {
1378: %userenv = ();
1379: }
1380: # Check to see if we need to change user information
1381: foreach my $item ('firstname','middlename','lastname','generation','permanentemail') {
1382: # Strip leading and trailing whitespace
1383: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1384: }
1385: my ($quotachanged,$namechanged,$oldportfolioquota,$newportfolioquota,
1386: $inststatus,$isdefault,$defquotatext);
1387: my ($defquota,$settingstatus) =
1388: &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
1389: my %changeHash;
1390: if ($userenv{'portfolioquota'} ne '') {
1391: $oldportfolioquota = $userenv{'portfolioquota'};
1392: if ($env{'form.customquota'} == 1) {
1393: if ($env{'form.portfolioquota'} eq '') {
1394: $newportfolioquota = 0;
1395: } else {
1396: $newportfolioquota = $env{'form.portfolioquota'};
1397: $newportfolioquota =~ s/[^\d\.]//g;
1398: }
1399: if ($newportfolioquota != $userenv{'portfolioquota'}) {
1400: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1401: }
1402: } else {
1403: $quotachanged = "a_admin('',\%changeHash);
1404: $newportfolioquota = $defquota;
1405: $isdefault = 1;
1406: }
1407: } else {
1408: $oldportfolioquota = $defquota;
1409: if ($env{'form.customquota'} == 1) {
1410: if ($env{'form.portfolioquota'} eq '') {
1411: $newportfolioquota = 0;
1412: } else {
1413: $newportfolioquota = $env{'form.portfolioquota'};
1414: $newportfolioquota =~ s/[^\d\.]//g;
1415: }
1416: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1417: } else {
1418: $newportfolioquota = $defquota;
1419: $isdefault = 1;
1420: }
1421: }
1422: if ($isdefault) {
1423: if ($settingstatus eq '') {
1424: $defquotatext = &mt('(default)');
1425: } else {
1426: my ($usertypes,$order) =
1427: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
1428: if ($usertypes->{$settingstatus} eq '') {
1429: $defquotatext = &mt('(default)');
1430: } else {
1431: $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
1432: }
1433: }
1434: }
1435: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) &&
1436: ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
1437: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
1438: $env{'form.clastname'} ne $userenv{'lastname'} ||
1439: $env{'form.cgeneration'} ne $userenv{'generation'} ||
1440: $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} )) {
1441: $namechanged = 1;
1442: }
1443: if ($namechanged) {
1444: # Make the change
1445: $changeHash{'firstname'} = $env{'form.cfirstname'};
1446: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1447: $changeHash{'lastname'} = $env{'form.clastname'};
1448: $changeHash{'generation'} = $env{'form.cgeneration'};
1449: $changeHash{'permanentemail'} = $env{'form.permanentemail'};
1450: my $putresult = &Apache::lonnet::put
1451: ('environment',\%changeHash,
1452: $env{'form.ccdomain'},$env{'form.ccuname'});
1453: if ($putresult eq 'ok') {
1454: # Tell the user we changed the name
1455: my %lt=&Apache::lonlocal::texthash(
1456: 'uic' => "User Information Changed",
1457: 'frst' => "first",
1458: 'mddl' => "middle",
1459: 'lst' => "last",
1460: 'gen' => "generation",
1461: 'mail' => "permanent e-mail",
1462: 'disk' => "disk space allocated to portfolio files",
1463: 'prvs' => "Previous",
1464: 'chto' => "Changed To"
1465: );
1466: $r->print(<<"END");
1467: <table border="2">
1468: <caption>$lt{'uic'}</caption>
1469: <tr><th> </th>
1470: <th>$lt{'frst'}</th>
1471: <th>$lt{'mddl'}</th>
1472: <th>$lt{'lst'}</th>
1473: <th>$lt{'gen'}</th>
1474: <th>$lt{'disk'}<th></tr>
1475: <tr><td>$lt{'prvs'}</td>
1476: <td>$userenv{'firstname'} </td>
1477: <td>$userenv{'middlename'} </td>
1478: <td>$userenv{'lastname'} </td>
1479: <td>$userenv{'generation'} </td>
1480: <td>$userenv{'permanentemail'} </td>
1481: <td>$oldportfolioquota Mb</td>
1482: </tr>
1483: <tr><td>$lt{'chto'}</td>
1484: <td>$env{'form.cfirstname'} </td>
1485: <td>$env{'form.cmiddlename'} </td>
1486: <td>$env{'form.clastname'} </td>
1487: <td>$env{'form.cgeneration'} </td>
1488: <td>$env{'form.cpermanentemail'} </td>
1489: <td>$newportfolioquota Mb $defquotatext </td></tr>
1490: </table>
1491: END
1492: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
1493: ($env{'form.ccuname'} eq $env{'user.name'})) {
1494: my %newenvhash;
1495: foreach my $key (keys(%changeHash)) {
1496: $newenvhash{'environment.'.$key} = $changeHash{$key};
1497: }
1498: &Apache::lonnet::appenv(%newenvhash);
1499: }
1500: } else { # error occurred
1501: $r->print("<h2>".&mt('Unable to successfully change environment for')." ".
1502: $env{'form.ccuname'}." ".&mt('in domain')." ".
1503: $env{'form.ccdomain'}."</h2>");
1504: }
1505: } else { # End of if ($env ... ) logic
1506: my $putresult;
1507: if ($quotachanged) {
1508: $putresult = &Apache::lonnet::put
1509: ('environment',\%changeHash,
1510: $env{'form.ccdomain'},$env{'form.ccuname'});
1511: }
1512: # They did not want to change the users name but we can
1513: # still tell them what the name is
1514: my %lt=&Apache::lonlocal::texthash(
1515: 'mail' => "Permanent e-mail",
1516: 'disk' => "Disk space allocated to user's portfolio files",
1517: );
1518: $r->print(<<"END");
1519: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}</h4>
1520: <h4>$lt{'mail'}: $userenv{'permanentemail'}</h4>
1521: END
1522: if ($putresult eq 'ok') {
1523: if ($oldportfolioquota != $newportfolioquota) {
1524: $r->print('<h4>'.$lt{'disk'}.': '.$newportfolioquota.' Mb '.
1525: $defquotatext.'</h4>');
1526: &Apache::lonnet::appenv('environment.portfolioquota' => $changeHash{'portfolioquota'});
1527: }
1528: }
1529: }
1530: }
1531: ##
1532: my $now=time;
1533: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1534: foreach my $key (keys (%env)) {
1535: next if (! $env{$key});
1536: # Revoke roles
1537: if ($key=~/^form\.rev/) {
1538: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1539: # Revoke standard role
1540: $r->print(&mt('Revoking').' '.$2.' in '.$1.': <b>'.
1541: &Apache::lonnet::revokerole($env{'form.ccdomain'},
1542: $env{'form.ccuname'},$1,$2).'</b><br />');
1543: if ($2 eq 'st') {
1544: $1=~m{^/($match_domain)/($match_courseid)};
1545: my $cid=$1.'_'.$2;
1546: my $user = $env{'form.ccuname'}.':'.$env{'form.ccdomain'};
1547: my $result =
1548: &Apache::lonnet::cput('classlist',
1549: { $user => $now },
1550: $env{'course.'.$cid.'.domain'},
1551: $env{'course.'.$cid.'.num'});
1552: $r->print(&mt('Drop from classlist: [_1]',
1553: '<b>'.$result.'</b>').'<br />');
1554: }
1555: }
1556: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1557: # Revoke custom role
1558: $r->print(&mt('Revoking custom role:').
1559: ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
1560: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
1561: $env{'form.ccuname'},$1,$2,$3,$4).
1562: '</b><br />');
1563: }
1564: } elsif ($key=~/^form\.del/) {
1565: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1566: # Delete standard role
1567: $r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
1568: &Apache::lonnet::assignrole($env{'form.ccdomain'},
1569: $env{'form.ccuname'},$1,$2,$now,0,1).'<br />');
1570: if ($2 eq 'st') {
1571: $1=~m{^/($match_domain)/($match_courseid)};
1572: my $cid=$1.'_'.$2;
1573: my $user = $env{'form.ccuname'}.':'.$env{'form.ccdomain'};
1574: my $result =
1575: &Apache::lonnet::cput('classlist',
1576: { $user => $now },
1577: $env{'course.'.$cid.'.domain'},
1578: $env{'course.'.$cid.'.num'});
1579: $r->print(&mt('Drop from classlist: [_1]',
1580: '<b>'.$result.'</b>').'<br />');
1581: }
1582: }
1583: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1584: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1585: # Delete custom role
1586: $r->print(&mt('Deleting custom role [_1] by [_2]@[_3] in [_4]',
1587: $rolename,$rnam,$rdom,$url).': <b>'.
1588: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
1589: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
1590: 0,1).'</b><br />');
1591: }
1592: } elsif ($key=~/^form\.ren/) {
1593: my $udom = $env{'form.ccdomain'};
1594: my $uname = $env{'form.ccuname'};
1595: # Re-enable standard role
1596: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1597: my $url = $1;
1598: my $role = $2;
1599: my $logmsg;
1600: my $output;
1601: if ($role eq 'st') {
1602: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1603: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1604: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
1605: $output = "Error: $result\n";
1606: } else {
1607: $output = &mt('Assigning').' '.$role.' in '.$url.
1608: &mt('starting').' '.localtime($now).
1609: ': <br />'.$logmsg.'<br />'.
1610: &mt('Add to classlist').': <b>ok</b><br />';
1611: }
1612: }
1613: } else {
1614: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1615: $env{'form.ccuname'},$url,$role,0,$now);
1616: $output = &mt('Re-enabling [_1] in [_2]: <b>[_3]</b>',
1617: $role,$url,$result).'<br />';
1618: }
1619: $r->print($output);
1620: }
1621: # Re-enable custom role
1622: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1623: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1624: my $result = &Apache::lonnet::assigncustomrole(
1625: $env{'form.ccdomain'}, $env{'form.ccuname'},
1626: $url,$rdom,$rnam,$rolename,0,$now);
1627: $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : <b>[_5]</b>',
1628: $rolename,$rnam,$rdom,$url,$result).'<br />');
1629: }
1630: } elsif ($key=~/^form\.act/) {
1631: my $udom = $env{'form.ccdomain'};
1632: my $uname = $env{'form.ccuname'};
1633: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1634: # Activate a custom role
1635: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
1636: my $url='/'.$one.'/'.$two;
1637: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1638:
1639: my $start = ( $env{'form.start_'.$full} ?
1640: $env{'form.start_'.$full} :
1641: $now );
1642: my $end = ( $env{'form.end_'.$full} ?
1643: $env{'form.end_'.$full} :
1644: 0 );
1645:
1646: # split multiple sections
1647: my %sections = ();
1648: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1649: if ($num_sections == 0) {
1650: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
1651: } else {
1652: my %curr_groups =
1653: &Apache::longroup::coursegroups($one,$two);
1654: foreach my $sec (sort {$a cmp $b} keys %sections) {
1655: if (($sec eq 'none') || ($sec eq 'all') ||
1656: exists($curr_groups{$sec})) {
1657: $disallowed{$sec} = $url;
1658: next;
1659: }
1660: my $securl = $url.'/'.$sec;
1661: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
1662: }
1663: }
1664: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1665: # Activate roles for sections with 3 id numbers
1666: # set start, end times, and the url for the class
1667: my ($one,$two,$three)=($1,$2,$3);
1668: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
1669: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1670: $now );
1671: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1672: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1673: 0 );
1674: my $url='/'.$one.'/'.$two;
1675: my $type = 'three';
1676: # split multiple sections
1677: my %sections = ();
1678: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1679: if ($num_sections == 0) {
1680: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1681: } else {
1682: my %curr_groups =
1683: &Apache::longroup::coursegroups($one,$two);
1684: my $emptysec = 0;
1685: foreach my $sec (sort {$a cmp $b} keys %sections) {
1686: $sec =~ s/\W//g;
1687: if ($sec ne '') {
1688: if (($sec eq 'none') || ($sec eq 'all') ||
1689: exists($curr_groups{$sec})) {
1690: $disallowed{$sec} = $url;
1691: next;
1692: }
1693: my $securl = $url.'/'.$sec;
1694: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
1695: } else {
1696: $emptysec = 1;
1697: }
1698: }
1699: if ($emptysec) {
1700: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1701: }
1702: }
1703: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1704: # Activate roles for sections with two id numbers
1705: # set start, end times, and the url for the class
1706: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
1707: $env{'form.start_'.$1.'_'.$2} :
1708: $now );
1709: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1710: $env{'form.end_'.$1.'_'.$2} :
1711: 0 );
1712: my $url='/'.$1.'/';
1713: # split multiple sections
1714: my %sections = ();
1715: my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);
1716: if ($num_sections == 0) {
1717: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1718: } else {
1719: my $emptysec = 0;
1720: foreach my $sec (sort {$a cmp $b} keys %sections) {
1721: if ($sec ne '') {
1722: my $securl = $url.'/'.$sec;
1723: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
1724: } else {
1725: $emptysec = 1;
1726: }
1727: }
1728: if ($emptysec) {
1729: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1730: }
1731: }
1732: } else {
1733: $r->print('<p>'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></p><br />');
1734: }
1735: foreach my $key (sort(keys(%disallowed))) {
1736: if (($key eq 'none') || ($key eq 'all')) {
1737: $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
1738: } else {
1739: $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));
1740: }
1741: $r->print(' '.&mt('Please <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />');
1742: }
1743: }
1744: } # End of foreach (keys(%env))
1745: # Flush the course logs so reverse user roles immediately updated
1746: &Apache::lonnet::flushcourselogs();
1747: $r->print('<p><a href="/adm/createuser">'.&mt('Create/Modify Another User').'</a></p>');
1748: $r->print('<form name="userupdate" method="post" />'."\n");
1749: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1750: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1751: }
1752: foreach my $item ('sortby','seluname','seludom') {
1753: if (exists($env{'form.'.$item})) {
1754: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1755: }
1756: }
1757: $r->print('<input type="hidden" name="phase" value="" />'."\n".
1758: '<input type ="hidden" name="state" value="" />'."\n".
1759: '</form>');
1760: $r->print(&Apache::loncommon::end_page());
1761: }
1762:
1763: sub quota_admin {
1764: my ($setquota,$changeHash) = @_;
1765: my $quotachanged;
1766: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1767: # Current user has quota modification privileges
1768: $quotachanged = 1;
1769: $changeHash->{'portfolioquota'} = $setquota;
1770: }
1771: return $quotachanged;
1772: }
1773:
1774: sub build_roles {
1775: my ($sectionstr,$sections,$role) = @_;
1776: my $num_sections = 0;
1777: if ($sectionstr=~ /,/) {
1778: my @secnums = split/,/,$sectionstr;
1779: if ($role eq 'st') {
1780: $secnums[0] =~ s/\W//g;
1781: $$sections{$secnums[0]} = 1;
1782: $num_sections = 1;
1783: } else {
1784: foreach my $sec (@secnums) {
1785: $sec =~ ~s/\W//g;
1786: if (!($sec eq "")) {
1787: if (exists($$sections{$sec})) {
1788: $$sections{$sec} ++;
1789: } else {
1790: $$sections{$sec} = 1;
1791: $num_sections ++;
1792: }
1793: }
1794: }
1795: }
1796: } else {
1797: $sectionstr=~s/\W//g;
1798: unless ($sectionstr eq '') {
1799: $$sections{$sectionstr} = 1;
1800: $num_sections ++;
1801: }
1802: }
1803:
1804: return $num_sections;
1805: }
1806:
1807: # ========================================================== Custom Role Editor
1808:
1809: sub custom_role_editor {
1810: my ($r) = @_;
1811: my $rolename=$env{'form.rolename'};
1812:
1813: if ($rolename eq 'make new role') {
1814: $rolename=$env{'form.newrolename'};
1815: }
1816:
1817: $rolename=~s/[^A-Za-z0-9]//gs;
1818:
1819: if (!$rolename) {
1820: &print_username_entry_form($r);
1821: return;
1822: }
1823: # ------------------------------------------------------- What can be assigned?
1824: my %full=();
1825: my %courselevel=();
1826: my %courselevelcurrent=();
1827: my $syspriv='';
1828: my $dompriv='';
1829: my $coursepriv='';
1830: my $body_top;
1831: my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
1832: my ($rdummy,$roledef)=
1833: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1834: # ------------------------------------------------------- Does this role exist?
1835: $body_top .= '<h2>';
1836: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1837: $body_top .= &mt('Existing Role').' "';
1838: # ------------------------------------------------- Get current role privileges
1839: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1840: } else {
1841: $body_top .= &mt('New Role').' "';
1842: $roledef='';
1843: }
1844: $body_top .= $rolename.'"</h2>';
1845: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1846: my ($priv,$restrict)=split(/\&/,$item);
1847: if (!$restrict) { $restrict='F'; }
1848: $courselevel{$priv}=$restrict;
1849: if ($coursepriv=~/\:$priv/) {
1850: $courselevelcurrent{$priv}=1;
1851: }
1852: $full{$priv}=1;
1853: }
1854: my %domainlevel=();
1855: my %domainlevelcurrent=();
1856: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1857: my ($priv,$restrict)=split(/\&/,$item);
1858: if (!$restrict) { $restrict='F'; }
1859: $domainlevel{$priv}=$restrict;
1860: if ($dompriv=~/\:$priv/) {
1861: $domainlevelcurrent{$priv}=1;
1862: }
1863: $full{$priv}=1;
1864: }
1865: my %systemlevel=();
1866: my %systemlevelcurrent=();
1867: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1868: my ($priv,$restrict)=split(/\&/,$item);
1869: if (!$restrict) { $restrict='F'; }
1870: $systemlevel{$priv}=$restrict;
1871: if ($syspriv=~/\:$priv/) {
1872: $systemlevelcurrent{$priv}=1;
1873: }
1874: $full{$priv}=1;
1875: }
1876: my ($jsback,$elements) = &crumb_utilities();
1877: my $button_code = "\n";
1878: my $head_script = "\n";
1879: $head_script .= '<script type="text/javascript">'."\n";
1880: my @template_roles = ("cc","in","ta","ep","st");
1881: foreach my $role (@template_roles) {
1882: $head_script .= &make_script_template($role);
1883: $button_code .= &make_button_code($role);
1884: }
1885: $head_script .= "\n".$jsback."\n".'</script>'."\n";
1886: $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
1887: &Apache::lonhtmlcommon::add_breadcrumb
1888: ({href=>"javascript:backPage(document.form1,'','')",
1889: text=>"User modify/custom role edit",
1890: faq=>282,bug=>'Instructor Interface',},
1891: {href=>"javascript:backPage(document.form1,'','')",
1892: text=>"Edit custom role",
1893: faq=>282,bug=>'Instructor Interface',});
1894: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1895:
1896: $r->print($body_top);
1897: my %lt=&Apache::lonlocal::texthash(
1898: 'prv' => "Privilege",
1899: 'crl' => "Course Level",
1900: 'dml' => "Domain Level",
1901: 'ssl' => "System Level");
1902: $r->print('Select a Template<br />');
1903: $r->print('<form action="">');
1904: $r->print($button_code);
1905: $r->print('</form>');
1906: $r->print(<<ENDCCF);
1907: <form name="form1" method="post">
1908: <input type="hidden" name="phase" value="set_custom_roles" />
1909: <input type="hidden" name="rolename" value="$rolename" />
1910: ENDCCF
1911: $r->print(&Apache::loncommon::start_data_table().
1912: &Apache::loncommon::start_data_table_header_row().
1913: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
1914: '</th><th>'.$lt{'ssl'}.'</th>'.
1915: &Apache::loncommon::end_data_table_header_row());
1916: foreach my $priv (sort keys %full) {
1917: my $privtext = &Apache::lonnet::plaintext($priv);
1918: $r->print(&Apache::loncommon::start_data_table_row().
1919: '<td>'.$privtext.'</td><td>'.
1920: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c" '.
1921: ($courselevelcurrent{$priv}?'checked="1"':'').' />':' ').
1922: '</td><td>'.
1923: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d" '.
1924: ($domainlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1925: '</td><td>'.
1926: ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s" '.
1927: ($systemlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1928: '</td>'.
1929: &Apache::loncommon::end_data_table_row());
1930: }
1931: $r->print(&Apache::loncommon::end_data_table().
1932: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1933: '" />'."\n".'<input type="hidden" name="state" value="" />'."\n".
1934: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1935: '<input type="submit" value="'.&mt('Define Role').'" /></form>'.
1936: &Apache::loncommon::end_page());
1937: }
1938: # --------------------------------------------------------
1939: sub make_script_template {
1940: my ($role) = @_;
1941: my %full_c=();
1942: my %full_d=();
1943: my %full_s=();
1944: my $return_script;
1945: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1946: my ($priv,$restrict)=split(/\&/,$item);
1947: $full_c{$priv}=1;
1948: }
1949: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1950: my ($priv,$restrict)=split(/\&/,$item);
1951: $full_d{$priv}=1;
1952: }
1953: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1954: my ($priv,$restrict)=split(/\&/,$item);
1955: $full_s{$priv}=1;
1956: }
1957: $return_script .= 'function set_'.$role.'() {'."\n";
1958: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
1959: my %role_c;
1960: foreach my $priv (@temp) {
1961: my ($priv_item, $dummy) = split(/\&/,$priv);
1962: $role_c{$priv_item} = 1;
1963: }
1964: foreach my $priv_item (keys(%full_c)) {
1965: my ($priv, $dummy) = split(/\&/,$priv_item);
1966: if (exists($role_c{$priv})) {
1967: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
1968: } else {
1969: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
1970: }
1971: }
1972: my %role_d;
1973: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
1974: foreach my $priv(@temp) {
1975: my ($priv_item, $dummy) = split(/\&/,$priv);
1976: $role_d{$priv_item} = 1;
1977: }
1978: foreach my $priv_item (keys(%full_d)) {
1979: my ($priv, $dummy) = split(/\&/,$priv_item);
1980: if (exists($role_d{$priv})) {
1981: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
1982: } else {
1983: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
1984: }
1985: }
1986: my %role_s;
1987: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
1988: foreach my $priv(@temp) {
1989: my ($priv_item, $dummy) = split(/\&/,$priv);
1990: $role_s{$priv_item} = 1;
1991: }
1992: foreach my $priv_item (keys(%full_s)) {
1993: my ($priv, $dummy) = split(/\&/,$priv_item);
1994: if (exists($role_s{$priv})) {
1995: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
1996: } else {
1997: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
1998: }
1999: }
2000: $return_script .= '}'."\n";
2001: return ($return_script);
2002: }
2003: # ----------------------------------------------------------
2004: sub make_button_code {
2005: my ($role) = @_;
2006: my $label = &Apache::lonnet::plaintext($role);
2007: my $button_code = '<input type="button" onClick="set_'.$role.'()" value="'.$label.'" />';
2008: return ($button_code);
2009: }
2010: # ---------------------------------------------------------- Call to definerole
2011: sub set_custom_role {
2012: my ($r) = @_;
2013:
2014: my $rolename=$env{'form.rolename'};
2015:
2016: $rolename=~s/[^A-Za-z0-9]//gs;
2017:
2018: if (!$rolename) {
2019: &print_username_entry_form($r);
2020: return;
2021: }
2022:
2023: my ($jsback,$elements) = &crumb_utilities();
2024: my $jscript = '<script type="text/javascript">'.$jsback."\n".'</script>';
2025:
2026: $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
2027: &Apache::lonhtmlcommon::add_breadcrumb
2028: ({href=>"javascript:backPage(document.customresult,'','')",
2029: text=>"User modify/custom role edit",
2030: faq=>282,bug=>'Instructor Interface',},
2031: {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
2032: text=>"Edit custom role",
2033: faq=>282,bug=>'Instructor Interface',},
2034: {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
2035: text=>"Result",
2036: faq=>282,bug=>'Instructor Interface',});
2037: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
2038:
2039: my ($rdummy,$roledef)=
2040: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
2041:
2042: # ------------------------------------------------------- Does this role exist?
2043: $r->print('<h2>');
2044: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
2045: $r->print(&mt('Existing Role').' "');
2046: } else {
2047: $r->print(&mt('New Role').' "');
2048: $roledef='';
2049: }
2050: $r->print($rolename.'"</h2>');
2051: # ------------------------------------------------------- What can be assigned?
2052: my $sysrole='';
2053: my $domrole='';
2054: my $courole='';
2055:
2056: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2057: my ($priv,$restrict)=split(/\&/,$item);
2058: if (!$restrict) { $restrict=''; }
2059: if ($env{'form.'.$priv.'_c'}) {
2060: $courole.=':'.$item;
2061: }
2062: }
2063:
2064: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2065: my ($priv,$restrict)=split(/\&/,$item);
2066: if (!$restrict) { $restrict=''; }
2067: if ($env{'form.'.$priv.'_d'}) {
2068: $domrole.=':'.$item;
2069: }
2070: }
2071:
2072: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2073: my ($priv,$restrict)=split(/\&/,$item);
2074: if (!$restrict) { $restrict=''; }
2075: if ($env{'form.'.$priv.'_s'}) {
2076: $sysrole.=':'.$item;
2077: }
2078: }
2079: $r->print('<br />Defining Role: '.
2080: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
2081: if ($env{'request.course.id'}) {
2082: my $url='/'.$env{'request.course.id'};
2083: $url=~s/\_/\//g;
2084: $r->print('<br />'.&mt('Assigning Role to Self').': '.
2085: &Apache::lonnet::assigncustomrole($env{'user.domain'},
2086: $env{'user.name'},
2087: $url,
2088: $env{'user.domain'},
2089: $env{'user.name'},
2090: $rolename));
2091: }
2092: $r->print('<p><a href="/adm/createuser">Create another role, or Create/Modify a user.</a></p><form name="customresult" method="post">');
2093: $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
2094: $r->print(&Apache::loncommon::end_page());
2095: }
2096:
2097: # ================================================================ Main Handler
2098: sub handler {
2099: my $r = shift;
2100:
2101: if ($r->header_only) {
2102: &Apache::loncommon::content_type($r,'text/html');
2103: $r->send_http_header;
2104: return OK;
2105: }
2106:
2107: if ((&Apache::lonnet::allowed('cta',$env{'request.course.id'})) ||
2108: (&Apache::lonnet::allowed('cin',$env{'request.course.id'})) ||
2109: (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) ||
2110: (&Apache::lonnet::allowed('cep',$env{'request.course.id'})) ||
2111: (&authorpriv($env{'user.name'},$env{'request.role.domain'})) ||
2112: (&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) {
2113: &Apache::loncommon::content_type($r,'text/html');
2114: $r->send_http_header;
2115: &Apache::lonhtmlcommon::clear_breadcrumbs();
2116:
2117: my $phase = $env{'form.phase'};
2118: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
2119:
2120: if (($phase eq 'get_user_info') || ($phase eq 'userpicked')) {
2121: my $srch;
2122: foreach my $item (@search) {
2123: $srch->{$item} = $env{'form.'.$item};
2124: }
2125: if ($env{'form.phase'} eq 'get_user_info') {
2126: my ($state,$response,$forcenewuser,$results) =
2127: &user_search_result($srch);
2128: if ($state eq 'select') {
2129: &print_user_selection_page($r,$response,$srch,$results);
2130: } elsif ($state eq 'modify') {
2131: my ($ccuname,$ccdomain);
2132: if (($srch->{'srchby'} eq 'uname') &&
2133: ($srch->{'srchtype'} eq 'exact')) {
2134: $ccuname = $srch->{'srchterm'};
2135: $ccdomain= $srch->{'srchdomain'};
2136: } else {
2137: my @matchedunames = keys(%{$results});
2138: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
2139: }
2140: $ccuname =&LONCAPA::clean_username($ccuname);
2141: $ccdomain=&LONCAPA::clean_domain($ccdomain);
2142: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,
2143: $response);
2144: } elsif ($state eq 'query') {
2145: &print_user_query_page($r);
2146: } else {
2147: &print_username_entry_form($r,$response,$srch,$forcenewuser);
2148: }
2149: } elsif ($env{'form.phase'} eq 'userpicked') {
2150: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
2151: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
2152: &print_user_modification_page($r,$ccuname,$ccdomain,$srch);
2153: }
2154: } elsif ($env{'form.phase'} eq 'update_user_data') {
2155: &update_user_data($r);
2156: } elsif ($env{'form.phase'} eq 'selected_custom_edit') {
2157: &custom_role_editor($r);
2158: } elsif ($env{'form.phase'} eq 'set_custom_roles') {
2159: &set_custom_role($r);
2160: } else {
2161: &print_username_entry_form($r);
2162: }
2163: } else {
2164: $env{'user.error.msg'}=
2165: "/adm/createuser:mau:0:0:Cannot modify user data";
2166: return HTTP_NOT_ACCEPTABLE;
2167: }
2168: return OK;
2169: }
2170:
2171: #-------------------------------------------------- functions for &phase_two
2172: sub user_search_result {
2173: my ($srch) = @_;
2174: my %allhomes;
2175: my %inst_matches;
2176: my %srch_results;
2177: my ($response,$state,$forcenewuser);
2178:
2179: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
2180: $response = &mt('Invalid search.');
2181: }
2182: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
2183: $response = &mt('Invalid search.');
2184: }
2185: if ($srch->{'srchtype'} !~ /^(exact|contains)$/) {
2186: $response = &mt('Invalid search.');
2187: }
2188: if ($srch->{'srchterm'} eq '') {
2189: $response = &mt('You must enter a search term.');
2190: }
2191: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
2192: if (($srch->{'srchdomain'} eq '') ||
2193: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
2194: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
2195: }
2196: }
2197: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
2198: ($srch->{'srchin'} eq 'alc')) {
2199: if ($srch->{'srchterm'} !~ /^$match_username$/) {
2200: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
2201: }
2202: }
2203: if ($srch->{'srchin'} eq 'instd') {
2204: my $instd_chk = &directorysrch_check($srch);
2205: if ($instd_chk ne 'ok') {
2206: $response = $instd_chk;
2207: }
2208: }
2209: if ($response ne '') {
2210: return ($state,'<span class="LC_warning">'.$response.'</span>');
2211: }
2212: if ($srch->{'srchby'} eq 'uname') {
2213: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
2214: if ($env{'form.forcenew'}) {
2215: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
2216: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
2217: if ($uhome eq 'no_host') {
2218: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
2219: $response = &mt('New users can only be created in the domain to which you current role belongs - [_1].',$env{'request.role.domain'}.' ('.$domdesc.')');
2220: } else {
2221: $state = 'modify';
2222: }
2223: } else {
2224: $state = 'modify';
2225: }
2226: } else {
2227: if ($srch->{'srchin'} eq 'dom') {
2228: if ($srch->{'srchtype'} eq 'exact') {
2229: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
2230: if ($uhome eq 'no_host') {
2231: ($state,$response,$forcenewuser) =
2232: &build_search_response($srch,%srch_results);
2233: } else {
2234: $state = 'modify';
2235: }
2236: } else {
2237: %srch_results = &Apache::lonnet::usersearch($srch);
2238: ($state,$response,$forcenewuser) =
2239: &build_search_response($srch,%srch_results);
2240: }
2241: } else {
2242: my $courseusers = &get_courseusers();
2243: if ($srch->{'srchtype'} eq 'exact') {
2244: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
2245: $state = 'modify';
2246: } else {
2247: ($state,$response,$forcenewuser) =
2248: &build_search_response($srch,%srch_results);
2249: }
2250: } else {
2251: foreach my $user (keys(%$courseusers)) {
2252: my ($cuname,$cudomain) = split(/:/,$user);
2253: if ($cudomain eq $srch->{'srchdomain'}) {
2254: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
2255: $srch_results{$user} =
2256: {&Apache::lonnet::get('environment',
2257: ['firstname',
2258: 'lastname',
2259: 'permanentemail'])};
2260: }
2261: }
2262: }
2263: ($state,$response,$forcenewuser) =
2264: &build_search_response($srch,%srch_results);
2265: }
2266: }
2267: }
2268: } elsif ($srch->{'srchin'} eq 'alc') {
2269: $state = 'query';
2270: } elsif ($srch->{'srchin'} eq 'instd') {
2271: %srch_results = &Apache::lonnet::inst_directory_query($srch);
2272: ($state,$response,$forcenewuser) =
2273: &build_search_response($srch,%srch_results);
2274: }
2275: } else {
2276: if ($srch->{'srchin'} eq 'dom') {
2277: %srch_results = &Apache::lonnet::usersearch($srch);
2278: ($state,$response,$forcenewuser) =
2279: &build_search_response($srch,%srch_results);
2280: } elsif ($srch->{'srchin'} eq 'crs') {
2281: my $courseusers = &get_courseusers();
2282: foreach my $user (keys(%$courseusers)) {
2283: my ($uname,$udom) = split(/:/,$user);
2284: my %names = &Apache::loncommon::getnames($uname,$udom);
2285: my %emails = &Apache::loncommon::getemails($uname,$udom);
2286: if ($srch->{'srchby'} eq 'lastname') {
2287: if ((($srch->{'srchtype'} eq 'exact') &&
2288: ($names{'lastname'} eq $srch->{'srchterm'})) ||
2289: (($srch->{'srchtype'} eq 'contains') &&
2290: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
2291: $srch_results{$user} = {firstname => $names{'firstname'},
2292: lastname => $names{'lastname'},
2293: permanentemail => $emails{'permanentemail'},
2294: };
2295: }
2296: } elsif ($srch->{'srchby'} eq 'lastfirst') {
2297: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
2298: if ($srch->{'srchtype'} eq 'exact') {
2299: if (($names{'lastname'} eq $srchlast) &&
2300: ($names{'firstname'} eq $srchfirst)) {
2301: $srch_results{$user} = {firstname => $names{'firstname'},
2302: lastname => $names{'lastname'},
2303: permanentemail => $emails{'permanentemail'},
2304:
2305: };
2306: }
2307: } elsif ($srch->{'srchtype'} eq 'contains') {
2308: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
2309: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
2310: $srch_results{$user} = {firstname => $names{'firstname'},
2311: lastname => $names{'lastname'},
2312: permanentemail => $emails{'permanentemail'},
2313: };
2314: }
2315: }
2316: }
2317: }
2318: ($state,$response,$forcenewuser) =
2319: &build_search_response($srch,%srch_results);
2320: } elsif ($srch->{'srchin'} eq 'alc') {
2321: $state = 'query';
2322: } elsif ($srch->{'srchin'} eq 'instd') {
2323: %srch_results = &Apache::lonnet::inst_directory_query($srch);
2324: ($state,$response,$forcenewuser) =
2325: &build_search_response($srch,%srch_results);
2326: }
2327: }
2328: return ($state,$response,$forcenewuser,\%srch_results);
2329: }
2330:
2331: sub directorysrch_check {
2332: my ($srch) = @_;
2333: my $can_search = 0;
2334: my $response;
2335: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
2336: ['directorysrch'],$srch->{'srchdomain'});
2337: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
2338: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
2339: return &mt('Institutional directory search unavailable in domain: [_1]',$srch->{'srchdomain'});
2340: }
2341: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
2342: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
2343: return &mt('Insitutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$srch->{'srchdomain'});
2344: }
2345: my @usertypes = split(/:/,$env{'environment.inststatus'});
2346: if (!@usertypes) {
2347: push(@usertypes,'default');
2348: }
2349: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
2350: foreach my $type (@usertypes) {
2351: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
2352: $can_search = 1;
2353: last;
2354: }
2355: }
2356: }
2357: if (!$can_search) {
2358: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
2359: my @longtypes;
2360: foreach my $item (@usertypes) {
2361: push (@longtypes,$insttypes->{$item});
2362: }
2363: my $insttype_str = join(', ',@longtypes);
2364: return &mt('Directory search in domain: [_1] is unavailable to your user type: ',$srch->{'srchdomain'}).$insttype_str;
2365: }
2366: } else {
2367: $can_search = 1;
2368: }
2369: } else {
2370: return &mt('Directory search has not been configured for domain: [_1]',$srch->{'srchdomain'});
2371: }
2372: my %longtext = &Apache::lonlocal::texthash (
2373: uname => 'username',
2374: lastfirst => 'last name, first name',
2375: lastname => 'last name',
2376: contains => 'is contained in',
2377: exact => 'as exact match to'
2378: );
2379: if ($can_search) {
2380: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
2381: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
2382: return &mt('Directory search in domain: [_1] is not available for searching by [_2]',$srch->{'srchdomain'},$longtext{$srch->{'srchby'}});
2383: }
2384: } else {
2385: return &mt('Directory search in domain: [_1] is not available.', $srch->{'srchdomain'});
2386: }
2387: }
2388: if ($can_search) {
2389: if (($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') ||
2390: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
2391: return 'ok';
2392: } else {
2393: return &mt('Directory search in domain [_1] is not available for the requested search type: [_2]',$srch->{'srchdomain'},$longtext{$srch->{'srchtype'}});
2394: }
2395: }
2396: }
2397:
2398:
2399: sub get_courseusers {
2400: my %advhash;
2401: my $classlist = &Apache::loncoursedata::get_classlist();
2402: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
2403: foreach my $role (sort(keys(%coursepersonnel))) {
2404: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
2405: if (!exists($classlist->{$user})) {
2406: $classlist->{$user} = [];
2407: }
2408: }
2409: }
2410: return $classlist;
2411: }
2412:
2413: sub build_search_response {
2414: my ($srch,%srch_results) = @_;
2415: my ($state,$response,$forcenewuser);
2416: my %names = (
2417: 'uname' => 'username',
2418: 'lastname' => 'last name',
2419: 'lastfirst' => 'last name, first name',
2420: 'crs' => 'this course',
2421: 'dom' => 'this domain',
2422: 'instd' => "your institution's directory",
2423: );
2424:
2425: my %single = (
2426: contains => 'A match',
2427: exact => 'An exact match',
2428: );
2429: my %nomatch = (
2430: contains => 'No match',
2431: exact => 'No exact match',
2432: );
2433: if (keys(%srch_results) > 1) {
2434: $state = 'select';
2435: } else {
2436: if (keys(%srch_results) == 1) {
2437: $state = 'modify';
2438: $response = &mt("$single{$srch->{'srchtype'}} was found for this $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
2439: } else {
2440: $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} found for this $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'}).'</span>';
2441: if ($srch->{'srchin'} ne 'alc') {
2442: $forcenewuser = 1;
2443: my $cansrchinst = 0;
2444: if ($srch->{'srchdomain'}) {
2445: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
2446: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
2447: if ($domconfig{'directorysrch'}{'available'}) {
2448: $cansrchinst = 1;
2449: }
2450: }
2451: }
2452: if (($srch->{'srchby'} eq 'lastfirst') ||
2453: ($srch->{'srchby'} eq 'lastname')) {
2454: if ($srch->{'srchin'} eq 'crs') {
2455: $response .= '<br />'.&mt('You may want to broaden your search to the whole domain.');
2456: } elsif ($srch->{'srchin'} eq 'dom') {
2457: if ($cansrchinst) {
2458: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for this domain.');
2459: }
2460: }
2461: }
2462: }
2463: }
2464: }
2465: return ($state,$response,$forcenewuser);
2466: }
2467:
2468: sub crumb_utilities {
2469: my %elements = (
2470: crtuser => {
2471: srchterm => 'text',
2472: srchin => 'radio',
2473: srchby => 'selectbox',
2474: srchtype => 'selectbox',
2475: srchdomain => 'selectbox',
2476: },
2477: docustom => {
2478: rolename => 'selectbox',
2479: newrolename => 'textbox',
2480: },
2481: );
2482:
2483: my $jsback .= qq|
2484: function backPage(formname,prevphase,prevstate) {
2485: formname.phase.value = prevphase;
2486: formname.state.value = prevstate;
2487: formname.submit();
2488: }
2489: |;
2490: return ($jsback,\%elements);
2491: }
2492:
2493: sub course_level_table {
2494: my (%inccourses) = @_;
2495: my $table = '';
2496: # Custom Roles?
2497:
2498: my %customroles=&my_custom_roles();
2499: my %lt=&Apache::lonlocal::texthash(
2500: 'exs' => "Existing sections",
2501: 'new' => "Define new section",
2502: 'ssd' => "Set Start Date",
2503: 'sed' => "Set End Date",
2504: 'crl' => "Course Level",
2505: 'act' => "Activate",
2506: 'rol' => "Role",
2507: 'ext' => "Extent",
2508: 'grs' => "Section",
2509: 'sta' => "Start",
2510: 'end' => "End"
2511: );
2512:
2513: foreach my $protectedcourse (sort( keys(%inccourses))) {
2514: my $thiscourse=$protectedcourse;
2515: $thiscourse=~s:_:/:g;
2516: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
2517: my $area=$coursedata{'description'};
2518: my $type=$coursedata{'type'};
2519: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
2520: my ($domain,$cnum)=split(/\//,$thiscourse);
2521: my %sections_count;
2522: if (defined($env{'request.course.id'})) {
2523: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
2524: %sections_count =
2525: &Apache::loncommon::get_sections($domain,$cnum);
2526: }
2527: }
2528: foreach my $role ('st','ta','ep','in','cc') {
2529: if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
2530: my $plrole=&Apache::lonnet::plaintext($role);
2531: $table .= &Apache::loncommon::start_data_table_row().
2532: '<td><input type="checkbox" name="act_'.$protectedcourse.'_'.$role.'" /></td>
2533: <td>'.$plrole.'</td>
2534: <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
2535: if ($role ne 'cc') {
2536: if (%sections_count) {
2537: my $currsec = &course_sections(\%sections_count,$protectedcourse.'_'.$role);
2538: $table .=
2539: '<td><table class="LC_createuser">'.
2540: '<tr class="LC_section_row">
2541: <td valign="top">'.$lt{'exs'}.'<br />'.
2542: $currsec.'</td>'.
2543: '<td> </td>'.
2544: '<td valign="top"> '.$lt{'new'}.'<br />'.
2545: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.'" value="" />'.
2546: '<input type="hidden" '.
2547: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'.
2548: '</tr></table></td>';
2549: } else {
2550: $table .= '<td><input type="text" size="10" '.
2551: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>';
2552: }
2553: } else {
2554: $table .= '<td> </td>';
2555: }
2556: $table .= <<ENDTIMEENTRY;
2557: <td><input type="hidden" name="start_$protectedcourse\_$role" value='' />
2558: <a href=
2559: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$role.value,'start_$protectedcourse\_$role','cu.pres','dateset')">$lt{'ssd'}</a></td>
2560: <td><input type="hidden" name="end_$protectedcourse\_$role" value='' />
2561: <a href=
2562: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt{'sed'}</a></td>
2563: ENDTIMEENTRY
2564: $table.= &Apache::loncommon::end_data_table_row();
2565: }
2566: }
2567: foreach my $cust (sort keys %customroles) {
2568: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
2569: my $plrole=$cust;
2570: my $customrole=$protectedcourse.'_cr_cr_'.$env{'user.domain'}.
2571: '_'.$env{'user.name'}.'_'.$plrole;
2572: $table .= &Apache::loncommon::start_data_table_row().
2573: '<td><input type="checkbox" name="act_'.$customrole.'" /></td>
2574: <td>'.$plrole.'</td>
2575: <td>'.$area.'</td>'."\n";
2576: if (%sections_count) {
2577: my $currsec = &course_sections(\%sections_count,$customrole);
2578: $table.=
2579: '<td><table border="0" cellspacing="0" cellpadding="0">'.
2580: '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
2581: $currsec.'</td>'.
2582: '<td> </td>'.
2583: '<td valign="top"> '.$lt{'new'}.'<br />'.
2584: '<input type="text" name="newsec_'.$customrole.'" value="" /></td>'.
2585: '<input type="hidden" '.
2586: 'name="sec_'.$customrole.'" /></td>'.
2587: '</tr></table></td>';
2588: } else {
2589: $table .= '<td><input type="text" size="10" '.
2590: 'name="sec_'.$customrole.'" /></td>';
2591: }
2592: $table .= <<ENDENTRY;
2593: <td><input type="hidden" name="start_$customrole" value='' />
2594: <a href=
2595: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
2596: <td><input type="hidden" name="end_$customrole" value='' />
2597: <a href=
2598: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">$lt{'sed'}</a></td>
2599: ENDENTRY
2600: $table .= &Apache::loncommon::end_data_table_row();
2601: }
2602: }
2603: }
2604: return '' if ($table eq ''); # return nothing if there is nothing
2605: # in the table
2606: my $result = '
2607: <h4>'.$lt{'crl'}.'</h4>'.
2608: &Apache::loncommon::start_data_table().
2609: &Apache::loncommon::start_data_table_header_row().
2610: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
2611: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
2612: &Apache::loncommon::end_data_table_header_row().
2613: $table.
2614: &Apache::loncommon::end_data_table();
2615: return $result;
2616: }
2617:
2618: sub course_sections {
2619: my ($sections_count,$role) = @_;
2620: my $output = '';
2621: my @sections = (sort {$a <=> $b} keys %{$sections_count});
2622: if (scalar(@sections) == 1) {
2623: $output = '<select name="currsec_'.$role.'" >'."\n".
2624: ' <option value="">Select</option>'."\n".
2625: ' <option value="">No section</option>'."\n".
2626: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
2627: } else {
2628: $output = '<select name="currsec_'.$role.'" ';
2629: my $multiple = 4;
2630: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
2631: $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
2632: foreach my $sec (@sections) {
2633: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
2634: }
2635: }
2636: $output .= '</select>';
2637: return $output;
2638: }
2639:
2640: sub course_level_dc {
2641: my ($dcdom) = @_;
2642: my %customroles=&my_custom_roles();
2643: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
2644: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
2645: '<input type="hidden" name="dccourse" value="" />';
2646: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
2647: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
2648: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
2649: my %lt=&Apache::lonlocal::texthash(
2650: 'rol' => "Role",
2651: 'grs' => "Section",
2652: 'exs' => "Existing sections",
2653: 'new' => "Define new section",
2654: 'sta' => "Start",
2655: 'end' => "End",
2656: 'ssd' => "Set Start Date",
2657: 'sed' => "Set End Date"
2658: );
2659: my $header = '<h4>'.&mt('Course Level').'</h4>'.
2660: &Apache::loncommon::start_data_table().
2661: &Apache::loncommon::start_data_table_header_row().
2662: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
2663: &Apache::loncommon::end_data_table_header_row();
2664: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
2665: '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
2666: '<td><select name="role">'."\n";
2667: foreach my $role ('st','ta','ep','in','cc') {
2668: my $plrole=&Apache::lonnet::plaintext($role);
2669: $otheritems .= ' <option value="'.$role.'">'.$plrole;
2670: }
2671: if ( keys %customroles > 0) {
2672: foreach my $cust (sort keys %customroles) {
2673: my $custrole='cr_cr_'.$env{'user.domain'}.
2674: '_'.$env{'user.name'}.'_'.$cust;
2675: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
2676: }
2677: }
2678: $otheritems .= '</select></td><td>'.
2679: '<table border="0" cellspacing="0" cellpadding="0">'.
2680: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
2681: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
2682: '<td> </td>'.
2683: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
2684: '<input type="text" name="newsec" value="" />'.
2685: '<input type="hidden" name="groups" value="" /></td>'.
2686: '</tr></table></td>';
2687: $otheritems .= <<ENDTIMEENTRY;
2688: <td><input type="hidden" name="start" value='' />
2689: <a href=
2690: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
2691: <td><input type="hidden" name="end" value='' />
2692: <a href=
2693: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
2694: ENDTIMEENTRY
2695: $otheritems .= &Apache::loncommon::end_data_table_row().
2696: &Apache::loncommon::end_data_table()."\n";
2697: return $cb_jscript.$header.$hiddenitems.$otheritems;
2698: }
2699:
2700: #---------------------------------------------- end functions for &phase_two
2701:
2702: #--------------------------------- functions for &phase_two and &phase_three
2703:
2704: #--------------------------end of functions for &phase_two and &phase_three
2705:
2706: 1;
2707: __END__
2708:
2709:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>