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