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