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