Annotation of loncom/interface/loncreateuser.pm, revision 1.119
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.119 ! raeburn 4: # $Id: loncreateuser.pm,v 1.118 2006/05/30 12:46:09 www 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.118 www 68: use lib '/home/httpd/lib/perl/';
69: use LONCAPA;
1.1 www 70:
1.20 harris41 71: my $loginscript; # piece of javascript used in two separate instances
72: my $generalrule;
73: my $authformnop;
74: my $authformkrb;
75: my $authformint;
76: my $authformfsys;
77: my $authformloc;
78:
1.94 matthew 79: sub initialize_authen_forms {
80: my ($krbdefdom)=( $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/);
81: $krbdefdom= uc($krbdefdom);
1.31 matthew 82: my %param = ( formname => 'document.cu',
83: kerb_def_dom => $krbdefdom
84: );
1.48 albertel 85: # no longer static due to configurable kerberos defaults
86: # $loginscript = &Apache::loncommon::authform_header(%param);
1.31 matthew 87: $generalrule = &Apache::loncommon::authform_authorwarning(%param);
88: $authformnop = &Apache::loncommon::authform_nochange(%param);
1.48 albertel 89: # no longer static due to configurable kerberos defaults
90: # $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 91: $authformint = &Apache::loncommon::authform_internal(%param);
92: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
93: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 94: }
95:
1.43 www 96:
1.59 www 97: # ======================================================= Existing Custom Roles
98:
99: sub my_custom_roles {
100: my %returnhash=();
101: my %rolehash=&Apache::lonnet::dump('roles');
102: foreach (keys %rolehash) {
103: if ($_=~/^rolesdef\_(\w+)$/) {
1.61 www 104: $returnhash{$1}=$1;
1.59 www 105: }
106: }
107: return %returnhash;
108: }
1.43 www 109:
110: # ==================================================== Figure out author access
111:
112: sub authorpriv {
113: my ($auname,$audom)=@_;
1.105 www 114: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
115: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; }
1.43 www 116: return 1;
117: }
118:
1.2 www 119: # =================================================================== Phase one
1.1 www 120:
1.42 matthew 121: sub print_username_entry_form {
1.110 albertel 122: my ($r) = @_;
1.101 albertel 123: my $defdom=$env{'request.role.domain'};
1.33 matthew 124: my @domains = &Apache::loncommon::get_domains();
125: my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
1.46 www 126: my $selscript=&Apache::loncommon::studentbrowser_javascript();
1.110 albertel 127: my $start_page =
128: &Apache::loncommon::start_page('Create Users, Change User Privileges',
129: $selscript);
130:
1.46 www 131: my $sellink=&Apache::loncommon::selectstudent_link
132: ('crtuser','ccuname','ccdomain');
1.59 www 133: my %existingroles=&my_custom_roles();
134: my $choice=&Apache::loncommon::select_form('make new role','rolename',
135: ('make new role' => 'Generate new role ...',%existingroles));
1.71 sakharuk 136: my %lt=&Apache::lonlocal::texthash(
137: 'siur' => "Set Individual User Roles",
138: 'usr' => "Username",
139: 'dom' => "Domain",
140: 'usrr' => "User Roles",
141: 'ecrp' => "Edit Custom Role Privileges",
1.72 sakharuk 142: 'nr' => "Name of Role",
1.71 sakharuk 143: 'cre' => "Custom Role Editor"
144: );
1.110 albertel 145: my $help = &Apache::loncommon::help_open_menu('',undef,undef,'',282,'Instructor Interface');
1.76 www 146: my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
147: my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
1.33 matthew 148: $r->print(<<"ENDDOCUMENT");
1.111 albertel 149: $start_page
1.46 www 150: <form action="/adm/createuser" method="post" name="crtuser">
1.42 matthew 151: <input type="hidden" name="phase" value="get_user_info">
1.76 www 152: <h2>$lt{siur}$helpsiur</h2>
1.43 www 153: <table>
1.71 sakharuk 154: <tr><td>$lt{usr}:</td><td><input type="text" size="15" name="ccuname">
1.46 www 155: </td><td rowspan="2">$sellink</td></tr><tr><td>
1.71 sakharuk 156: $lt{'dom'}:</td><td>$domform</td></tr>
1.58 www 157: </table>
1.71 sakharuk 158: <input name="userrole" type="submit" value="$lt{usrr}" />
1.2 www 159: </form>
1.106 www 160: ENDDOCUMENT
161: if (&Apache::lonnet::allowed('mcr','/')) {
162: $r->print(<<ENDCUSTOM);
1.58 www 163: <form action="/adm/createuser" method="post" name="docustom">
164: <input type="hidden" name="phase" value="selected_custom_edit">
1.76 www 165: <h2>$lt{'ecrp'}$helpecpr</h2>
1.72 sakharuk 166: $lt{'nr'}: $choice <input type="text" size="15" name="newrolename" /><br />
1.71 sakharuk 167: <input name="customeditor" type="submit" value="$lt{'cre'}" />
1.107 www 168: </form>
1.106 www 169: ENDCUSTOM
1.107 www 170: }
1.110 albertel 171: $r->print(&Apache::loncommon::end_page());
172: }
173:
174:
175: sub user_modification_js {
1.113 raeburn 176: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
177:
1.110 albertel 178: return <<END;
179: <script type="text/javascript" language="Javascript">
180:
181: function pclose() {
182: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
183: "height=350,width=350,scrollbars=no,menubar=no");
184: parmwin.close();
185: }
186:
187: $pjump_def
188: $dc_setcourse_code
189:
190: function dateset() {
191: eval("document.cu."+document.cu.pres_marker.value+
192: ".value=document.cu.pres_value.value");
193: pclose();
194: }
195:
1.113 raeburn 196: $nondc_setsection_code
197:
1.110 albertel 198: </script>
199: END
1.2 www 200: }
201:
202: # =================================================================== Phase two
1.42 matthew 203: sub print_user_modification_page {
1.2 www 204: my $r=shift;
1.101 albertel 205: my $ccuname=$env{'form.ccuname'};
206: my $ccdomain=$env{'form.ccdomain'};
1.4 www 207:
1.98 albertel 208: $ccuname=~s/\W//g;
209: $ccdomain=~s/\W//g;
1.58 www 210:
211: unless (($ccuname) && ($ccdomain)) {
212: &print_username_entry_form($r);
213: return;
214: }
215:
1.101 albertel 216: my $defdom=$env{'request.role.domain'};
1.48 albertel 217:
218: my ($krbdef,$krbdefdom) =
219: &Apache::loncommon::get_kerberos_defaults($defdom);
220:
1.31 matthew 221: my %param = ( formname => 'document.cu',
1.48 albertel 222: kerb_def_dom => $krbdefdom,
223: kerb_def_auth => $krbdef
1.31 matthew 224: );
225: $loginscript = &Apache::loncommon::authform_header(%param);
1.48 albertel 226: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.4 www 227:
1.2 www 228: $ccuname=~s/\W//g;
229: $ccdomain=~s/\W//g;
1.52 matthew 230: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 231: my $dc_setcourse_code = '';
1.119 ! raeburn 232: my $nondc_setsection_code = '';
! 233:
1.112 albertel 234: my %loaditem;
1.114 albertel 235:
236: my $groupslist;
1.117 raeburn 237: my %curr_groups = &Apache::longroup::coursegroups();
1.114 albertel 238: if (%curr_groups) {
1.113 raeburn 239: $groupslist = join('","',sort(keys(%curr_groups)));
240: $groupslist = '"'.$groupslist.'"';
241: }
1.114 albertel 242:
1.101 albertel 243: if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {
1.88 raeburn 244: my $dcdom = $1;
1.119 ! raeburn 245: $loaditem{'onload'} = "document.cu.coursedesc.value='';";
! 246: my @rolevals = ('st','ta','ep','in','cc');
! 247: my (@crsroles,@grproles);
! 248: for (my $i=0; $i<@rolevals; $i++) {
! 249: $crsroles[$i]=&Apache::lonnet::plaintext($rolevals[$i]);
! 250: $grproles[$i]=&Apache::loncommon::convert_role($crsroles[$i],'Group');
! 251: }
! 252: my $rolevalslist = join('","',@rolevals);
! 253: my $crsrolenameslist = join('","',@crsroles);
! 254: my $grprolenameslist = join('","',@grproles);
! 255: my $pickcrsfirst = '<--'.&mt('Pick course first');
! 256: my $pickgrpfirst = '<--'.&mt('Pick group first');
1.88 raeburn 257: $dc_setcourse_code = <<"ENDSCRIPT";
258: function setCourse() {
259: var course = document.cu.dccourse.value;
260: if (course != "") {
261: if (document.cu.dcdomain.value != document.cu.origdom.value) {
262: alert("You must select a course in the current domain");
263: return;
264: }
265: var userrole = document.cu.role.options[document.cu.role.selectedIndex].value
1.91 raeburn 266: var section="";
1.88 raeburn 267: var numsections = 0;
1.116 raeburn 268: var newsecs = new Array();
1.89 raeburn 269: for (var i=0; i<document.cu.currsec.length; i++) {
270: if (document.cu.currsec.options[i].selected == true ) {
271: if (document.cu.currsec.options[i].value != "" && document.cu.currsec.options[i].value != null) {
272: if (numsections == 0) {
273: section = document.cu.currsec.options[i].value
274: numsections = 1;
275: }
276: else {
277: section = section + "," + document.cu.currsec.options[i].value
278: numsections ++;
1.88 raeburn 279: }
280: }
281: }
1.89 raeburn 282: }
283: if (document.cu.newsec.value != "" && document.cu.newsec.value != null) {
284: if (numsections == 0) {
285: section = document.cu.newsec.value
286: }
287: else {
288: section = section + "," + document.cu.newsec.value
1.88 raeburn 289: }
1.116 raeburn 290: newsecs = document.cu.newsec.value.split(/,/g);
291: numsections = numsections + newsecs.length;
1.89 raeburn 292: }
293: if ((userrole == 'st') && (numsections > 1)) {
294: 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.")
295: return;
296: }
1.116 raeburn 297: for (var j=0; j<newsecs.length; j++) {
298: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
299: 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 300: return;
301: }
302: if (document.cu.groups.value != '') {
303: var groups = document.cu.groups.value.split(/,/g);
304: for (var k=0; k<groups.length; k++) {
1.116 raeburn 305: if (newsecs[j] == groups[k]) {
306: 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 307: return;
308: }
309: }
310: }
311: }
1.89 raeburn 312: if ((userrole == 'cc') && (numsections > 0)) {
313: alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
314: section = "";
1.88 raeburn 315: }
316: var numcourse = getIndex(document.cu.dccourse);
317: if (numcourse == "-1") {
318: alert("There was a problem with your course selection");
319: return
320: }
321: else {
322: var coursename = "_$dcdom"+"_"+course+"_"+userrole
323: document.cu.elements[numcourse].name = "act"+coursename
1.119 ! raeburn 324: document.cu.elements[numcourse+5].name = "sec"+coursename
! 325: document.cu.elements[numcourse+5].value = section
! 326: document.cu.elements[numcourse+7].name = "start"+coursename
! 327: document.cu.elements[numcourse+8].name = "end"+coursename
1.88 raeburn 328: }
329: }
330: document.cu.submit();
331: }
332:
333: function getIndex(caller) {
334: for (var i=0;i<document.cu.elements.length;i++) {
335: if (document.cu.elements[i] == caller) {
336: return i;
337: }
338: }
339: return -1;
340: }
1.119 ! raeburn 341:
! 342: function setType() {
! 343: var crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
! 344: rolevals = new Array("$rolevalslist");
! 345: if (crstype == 'Group') {
! 346: if (document.cu.currsec.options[0].text == "$pickcrsfirst") {
! 347: document.cu.currsec.options[0].text = "$pickgrpfirst";
! 348: }
! 349: grprolenames = new Array("$grprolenameslist");
! 350: for (var i=0; i<rolevals.length; i++) {
! 351: if (document.cu.role.selectedIndex == i) {
! 352: document.cu.role.options[i] = new Option(grprolenames[i],rolevals[i],true,false);
! 353: } else {
! 354: document.cu.role.options[i] = new Option(grprolenames[i],rolevals[i],false,false);
! 355: }
! 356: }
! 357: } else {
! 358: if (document.cu.currsec.options[0].text == "$pickgrpfirst") {
! 359: document.cu.currsec.options[0].text = "$pickcrsfirst";
! 360: }
! 361: crsrolenames = new Array("$crsrolenameslist");
! 362: for (var i=0; i<rolevals.length; i++) {
! 363: if (document.cu.role.selectedIndex == i) {
! 364: document.cu.role.options[i] = new Option(crsrolenames[i],rolevals[i],true,false);
! 365: } else {
! 366: document.cu.role.options[i] = new Option(crsrolenames[i],rolevals[i],false,false);
! 367: }
! 368: }
! 369: }
! 370: }
1.88 raeburn 371: ENDSCRIPT
1.113 raeburn 372: } else {
373: $nondc_setsection_code = <<"ENDSECCODE";
374: function setSections() {
375: var re1 = /^currsec_/;
376: var groups = new Array($groupslist);
377: for (var i=0;i<document.cu.elements.length;i++) {
378: var str = document.cu.elements[i].name;
379: var checkcurr = str.match(re1);
380: if (checkcurr != null) {
381: var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/;
382: if (document.cu.elements[i-1].checked == true) {
383: var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/;
384: match = re2.exec(str);
385: var role = match[1];
386: if (role == 'cc') {
387: alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
388: }
389: else {
390: var sections = '';
391: var numsec = 0;
392: var sections;
393: for (var j=0; j<document.cu.elements[i].length; j++) {
394: if (document.cu.elements[i].options[j].selected == true ) {
395: if (document.cu.elements[i].options[j].value != "") {
396: if (numsec == 0) {
397: if (document.cu.elements[i].options[j].value != "") {
398: sections = document.cu.elements[i].options[j].value;
399: numsec ++;
400: }
401: }
402: else {
403: sections = sections + "," + document.cu.elements[i].options[j].value
404: numsec ++;
405: }
406: }
407: }
408: }
409: if (numsec > 0) {
410: if (document.cu.elements[i+1].value != "" && document.cu.elements[i+1].value != null) {
411: sections = sections + "," + document.cu.elements[i+1].value;
412: }
413: }
414: else {
415: sections = document.cu.elements[i+1].value;
416: }
417: var newsecs = document.cu.elements[i+1].value;
418: if (newsecs != null && newsecs != "") {
419: var numsplit = newsecs.split(/,/g);
420: numsec = numsec + numsplit.length;
421: }
422: if ((role == 'st') && (numsec > 1)) {
423: 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.")
424: return;
425: }
426: else {
427: for (var j=0; j<numsplit.length; j++) {
428: if ((numsplit[j] == 'all') ||
429: (numsplit[j] == 'none')) {
430: 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.");
431: return;
432: }
433: for (var k=0; k<groups.length; k++) {
434: if (numsplit[j] == groups[k]) {
435: 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.");
436: return;
437: }
438: }
439: }
440: document.cu.elements[i+2].value = sections;
441: }
442: }
443: }
444: }
445: }
446: document.cu.submit();
447: }
448: ENDSECCODE
1.88 raeburn 449: }
1.113 raeburn 450: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
451: $nondc_setsection_code,$groupslist);
1.110 albertel 452: my $start_page =
453: &Apache::loncommon::start_page('Create Users, Change User Privileges',
1.112 albertel 454: $js,{'add_entries' => \%loaditem,});
1.3 www 455:
1.25 matthew 456: my $forminfo =<<"ENDFORMINFO";
457: <form action="/adm/createuser" method="post" name="cu">
1.42 matthew 458: <input type="hidden" name="phase" value="update_user_data">
1.25 matthew 459: <input type="hidden" name="ccuname" value="$ccuname">
460: <input type="hidden" name="ccdomain" value="$ccdomain">
461: <input type="hidden" name="pres_value" value="" >
462: <input type="hidden" name="pres_type" value="" >
463: <input type="hidden" name="pres_marker" value="" >
464: ENDFORMINFO
1.2 www 465: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
466: my %incdomains;
467: my %inccourses;
1.49 albertel 468: foreach (values(%Apache::lonnet::hostdom)) {
1.13 www 469: $incdomains{$_}=1;
1.24 matthew 470: }
1.101 albertel 471: foreach (keys(%env)) {
1.2 www 472: if ($_=~/^user\.priv\.cm\.\/(\w+)\/(\w+)/) {
473: $inccourses{$1.'_'.$2}=1;
474: }
1.24 matthew 475: }
1.2 www 476: if ($uhome eq 'no_host') {
1.29 matthew 477: my $home_server_list=
1.32 matthew 478: '<option value="default" selected>default</option>'."\n".
479: &Apache::loncommon::home_server_option_list($ccdomain);
480:
1.79 albertel 481: my %lt=&Apache::lonlocal::texthash(
1.72 sakharuk 482: 'cnu' => "Create New User",
483: 'nu' => "New User",
484: 'id' => "in domain",
485: 'pd' => "Personal Data",
486: 'fn' => "First Name",
487: 'mn' => "Middle Name",
488: 'ln' => "Last Name",
489: 'gen' => "Generation",
490: 'idsn' => "ID/Student Number",
491: 'hs' => "Home Server",
492: 'lg' => "Login Data"
493: );
1.78 www 494: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
1.94 matthew 495: &initialize_authen_forms();
1.26 matthew 496: $r->print(<<ENDNEWUSER);
1.110 albertel 497: $start_page
1.72 sakharuk 498: <h1>$lt{'cnu'}</h1>
1.25 matthew 499: $forminfo
1.72 sakharuk 500: <h2>$lt{'nu'} "$ccuname" $lt{'id'} $ccdomain</h2>
1.31 matthew 501: <script type="text/javascript" language="Javascript">
1.20 harris41 502: $loginscript
1.31 matthew 503: </script>
1.20 harris41 504: <input type='hidden' name='makeuser' value='1' />
1.72 sakharuk 505: <h3>$lt{'pd'}</h3>
1.25 matthew 506: <p>
507: <table>
1.72 sakharuk 508: <tr><td>$lt{'fn'} </td>
1.25 matthew 509: <td><input type='text' name='cfirst' size='15' /></td></tr>
1.72 sakharuk 510: <tr><td>$lt{'mn'} </td>
1.25 matthew 511: <td><input type='text' name='cmiddle' size='15' /></td></tr>
1.72 sakharuk 512: <tr><td>$lt{'ln'} </td>
1.25 matthew 513: <td><input type='text' name='clast' size='15' /></td></tr>
1.78 www 514: <tr><td>$lt{'gen'}$genhelp</td>
1.25 matthew 515: <td><input type='text' name='cgen' size='5' /></td></tr>
516: </table>
1.72 sakharuk 517: $lt{'idsn'} <input type='text' name='cstid' size='15' /></p>
1.74 sakharuk 518: $lt{'hs'}: <select name="hserver" size="1"> $home_server_list </select>
1.25 matthew 519: <hr />
1.72 sakharuk 520: <h3>$lt{'lg'}</h3>
1.31 matthew 521: <p>$generalrule </p>
522: <p>$authformkrb </p>
523: <p>$authformint </p>
524: <p>$authformfsys</p>
525: <p>$authformloc </p>
1.26 matthew 526: ENDNEWUSER
1.25 matthew 527: } else { # user already exists
1.79 albertel 528: my %lt=&Apache::lonlocal::texthash(
1.72 sakharuk 529: 'cup' => "Change User Privileges",
530: 'usr' => "User",
531: 'id' => "in domain",
532: 'fn' => "first name",
533: 'mn' => "middle name",
534: 'ln' => "last name",
535: 'gen' => "generation"
536: );
1.26 matthew 537: $r->print(<<ENDCHANGEUSER);
1.110 albertel 538: $start_page
1.72 sakharuk 539: <h1>$lt{'cup'}</h1>
1.25 matthew 540: $forminfo
1.72 sakharuk 541: <h2>$lt{'usr'} "$ccuname" $lt{'id'} "$ccdomain"</h2>
1.26 matthew 542: ENDCHANGEUSER
1.28 matthew 543: # Get the users information
544: my %userenv = &Apache::lonnet::get('environment',
545: ['firstname','middlename','lastname','generation'],
546: $ccdomain,$ccuname);
547: my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
548: $r->print(<<END);
549: <hr />
550: <table border="2">
551: <tr>
1.72 sakharuk 552: <th>$lt{'fn'}</th><th>$lt{'mn'}</th><th>$lt{'ln'}</th><th>$lt{'gen'}</th>
1.28 matthew 553: </tr>
554: <tr>
555: END
556: foreach ('firstname','middlename','lastname','generation') {
557: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
558: $r->print(<<"END");
1.53 www 559: <td><input type="text" name="c$_" value="$userenv{$_}" size="15" /></td>
1.28 matthew 560: END
561: } else {
562: $r->print('<td>'.$userenv{$_}.'</td>');
563: }
564: }
1.72 sakharuk 565: $r->print(<<END);
1.28 matthew 566: </tr>
567: </table>
568: END
1.25 matthew 569: # Build up table of user roles to allow revocation of a role.
1.28 matthew 570: my ($tmp) = keys(%rolesdump);
571: unless ($tmp =~ /^(con_lost|error)/i) {
1.2 www 572: my $now=time;
1.72 sakharuk 573: my %lt=&Apache::lonlocal::texthash(
574: 'rer' => "Revoke Existing Roles",
575: 'rev' => "Revoke",
576: 'del' => "Delete",
1.81 albertel 577: 'ren' => "Re-Enable",
1.72 sakharuk 578: 'rol' => "Role",
579: 'ext' => "Extent",
580: 'sta' => "Start",
581: 'end' => "End"
582: );
1.89 raeburn 583: my (%roletext,%sortrole,%roleclass,%rolepriv);
1.67 albertel 584: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
585: my $b1=join('_',(split('_',$b))[1,0]);
586: return $a1 cmp $b1;
587: } keys(%rolesdump)) {
1.37 matthew 588: next if ($area =~ /^rolesdef/);
1.79 albertel 589: my $envkey=$area;
1.37 matthew 590: my $role = $rolesdump{$area};
591: my $thisrole=$area;
592: $area =~ s/\_\w\w$//;
593: my ($role_code,$role_end_time,$role_start_time) =
594: split(/_/,$role);
1.64 www 595: # Is this a custom role? Get role owner and title.
596: my ($croleudom,$croleuname,$croletitle)=
597: ($role_code=~/^cr\/(\w+)\/(\w+)\/(\w+)$/);
1.37 matthew 598: my $bgcol='ffffff';
599: my $allowed=0;
1.53 www 600: my $delallowed=0;
1.79 albertel 601: my $sortkey=$role_code;
602: my $class='Unknown';
1.37 matthew 603: if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {
1.79 albertel 604: $class='Course';
1.57 matthew 605: my ($coursedom,$coursedir) = ($1,$2);
1.79 albertel 606: $sortkey.="\0$1";
1.57 matthew 607: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.37 matthew 608: my %coursedata=
609: &Apache::lonnet::coursedescription($1.'_'.$2);
1.51 albertel 610: my $carea;
611: if (defined($coursedata{'description'})) {
1.79 albertel 612: $carea=$coursedata{'description'}.
1.72 sakharuk 613: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1.57 matthew 614: &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
1.79 albertel 615: $sortkey.="\0".$coursedata{'description'};
1.119 ! raeburn 616: $class=$coursedata{'type'};
1.51 albertel 617: } else {
1.72 sakharuk 618: $carea=&mt('Unavailable course').': '.$area;
1.86 albertel 619: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1.51 albertel 620: }
1.37 matthew 621: $inccourses{$1.'_'.$2}=1;
1.53 www 622: if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
623: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1.37 matthew 624: $allowed=1;
625: }
1.53 www 626: if ((&Apache::lonnet::allowed('dro',$1)) ||
627: (&Apache::lonnet::allowed('dro',$ccdomain))) {
628: $delallowed=1;
629: }
1.64 www 630: # - custom role. Needs more info, too
631: if ($croletitle) {
632: if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
633: $allowed=1;
634: $thisrole.='.'.$role_code;
635: }
636: }
1.37 matthew 637: # Compute the background color based on $area
638: $bgcol=$1.'_'.$2;
1.62 www 639: $bgcol=~s/[^7-9a-e]//g;
640: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
1.37 matthew 641: if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
1.113 raeburn 642: $carea.='<br />Section: '.$3;
1.87 albertel 643: $sortkey.="\0$3";
1.37 matthew 644: }
645: $area=$carea;
646: } else {
1.79 albertel 647: $sortkey.="\0".$area;
1.37 matthew 648: # Determine if current user is able to revoke privileges
649: if ($area=~ /^\/(\w+)\//) {
1.53 www 650: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
651: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1.37 matthew 652: $allowed=1;
653: }
1.53 www 654: if (((&Apache::lonnet::allowed('dro',$1)) ||
655: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
656: ($role_code ne 'dc')) {
657: $delallowed=1;
658: }
1.37 matthew 659: } else {
660: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
661: $allowed=1;
662: }
663: }
1.79 albertel 664: if ($role_code eq 'ca' || $role_code eq 'au') {
665: $class='Construction Space';
666: } elsif ($role_code eq 'su') {
667: $class='System';
668: } else {
669: $class='Domain';
670: }
1.37 matthew 671: }
1.105 www 672: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1.43 www 673: $area=~/\/(\w+)\/(\w+)/;
674: if (&authorpriv($2,$1)) {
675: $allowed=1;
676: } else {
677: $allowed=0;
1.37 matthew 678: }
679: }
1.79 albertel 680: $bgcol='77FF77';
1.37 matthew 681: my $row = '';
1.62 www 682: $row.='<tr bgcolor="#'.$bgcol.'"><td>';
1.37 matthew 683: my $active=1;
684: $active=0 if (($role_end_time) && ($now>$role_end_time));
685: if (($active) && ($allowed)) {
686: $row.= '<input type="checkbox" name="rev:'.$thisrole.'">';
687: } else {
1.56 www 688: if ($active) {
689: $row.=' ';
690: } else {
1.72 sakharuk 691: $row.=&mt('expired or revoked');
1.56 www 692: }
1.37 matthew 693: }
1.53 www 694: $row.='</td><td>';
1.81 albertel 695: if ($allowed && !$active) {
696: $row.= '<input type="checkbox" name="ren:'.$thisrole.'">';
697: } else {
698: $row.=' ';
699: }
700: $row.='</td><td>';
1.53 www 701: if ($delallowed) {
702: $row.= '<input type="checkbox" name="del:'.$thisrole.'">';
703: } else {
704: $row.=' ';
705: }
1.64 www 706: my $plaintext='';
707: unless ($croletitle) {
708: $plaintext=&Apache::lonnet::plaintext($role_code);
1.119 ! raeburn 709: if ($class eq 'Group') {
! 710: $plaintext = &Apache::loncommon::convert_role($plaintext,$class);
! 711: }
1.64 www 712: } else {
713: $plaintext=
714: "Customrole '$croletitle' defined by $croleuname\@$croleudom";
715: }
716: $row.= '</td><td>'.$plaintext.
1.37 matthew 717: '</td><td>'.$area.
718: '</td><td>'.($role_start_time?localtime($role_start_time)
719: : ' ' ).
720: '</td><td>'.($role_end_time ?localtime($role_end_time)
721: : ' ' )
722: ."</td></tr>\n";
1.79 albertel 723: $sortrole{$sortkey}=$envkey;
724: $roletext{$envkey}=$row;
725: $roleclass{$envkey}=$class;
1.89 raeburn 726: $rolepriv{$envkey}=$allowed;
1.79 albertel 727: #$r->print($row);
1.28 matthew 728: } # end of foreach (table building loop)
1.89 raeburn 729: my $rolesdisplay = 0;
730: my %output = ();
1.119 ! raeburn 731: foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
1.89 raeburn 732: $output{$type} = '';
1.79 albertel 733: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1.89 raeburn 734: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
735: $output{$type}.=$roletext{$sortrole{$which}};
1.79 albertel 736: }
737: }
1.89 raeburn 738: unless($output{$type} eq '') {
739: $output{$type} = "<tr bgcolor='#BBffBB'>".
740: "<td align='center' colspan='7'>".&mt($type)."</td>".
741: $output{$type};
742: $rolesdisplay = 1;
1.79 albertel 743: }
744: }
1.89 raeburn 745: if ($rolesdisplay == 1) {
746: $r->print(<<END);
747: <hr />
748: <h3>$lt{'rer'}</h3>
749: <table>
750: <tr><th>$lt{'rev'}</th><th>$lt{'ren'}</th><th>$lt{'del'}</th><th>$lt{'rol'}</th><th>$lt{'e
751: xt'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th>
752: END
1.119 ! raeburn 753: foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
1.89 raeburn 754: if ($output{$type}) {
755: $r->print($output{$type}."\n");
756: }
757: }
758: $r->print('</table>');
759: }
1.28 matthew 760: } # End of unless
1.20 harris41 761: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.41 albertel 762: if ($currentauth=~/^krb(4|5):/) {
763: $currentauth=~/^krb(4|5):(.*)/;
1.108 albertel 764: my $krbdefdom=$2;
1.31 matthew 765: my %param = ( formname => 'document.cu',
766: kerb_def_dom => $krbdefdom
767: );
768: $loginscript = &Apache::loncommon::authform_header(%param);
1.20 harris41 769: }
1.26 matthew 770: # Check for a bad authentication type
1.41 albertel 771: unless ($currentauth=~/^krb(4|5):/ or
1.20 harris41 772: $currentauth=~/^unix:/ or
773: $currentauth=~/^internal:/ or
774: $currentauth=~/^localauth:/
1.26 matthew 775: ) { # bad authentication scheme
1.101 albertel 776: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.94 matthew 777: &initialize_authen_forms();
1.73 sakharuk 778: my %lt=&Apache::lonlocal::texthash(
779: 'err' => "ERROR",
780: 'uuas' => "This user has an unrecognized authentication scheme",
781: 'sldb' => "Please specify login data below",
782: 'ld' => "Login Data"
783: );
1.26 matthew 784: $r->print(<<ENDBADAUTH);
1.21 harris41 785: <hr />
1.31 matthew 786: <script type="text/javascript" language="Javascript">
1.21 harris41 787: $loginscript
1.31 matthew 788: </script>
1.73 sakharuk 789: <font color='#ff0000'>$lt{'err'}:</font>
790: $lt{'uuas'} ($currentauth). $lt{'sldb'}.
791: <h3>$lt{'ld'}</h3>
1.31 matthew 792: <p>$generalrule</p>
793: <p>$authformkrb</p>
794: <p>$authformint</p>
795: <p>$authformfsys</p>
796: <p>$authformloc</p>
1.26 matthew 797: ENDBADAUTH
798: } else {
799: # This user is not allowed to modify the users
800: # authentication scheme, so just notify them of the problem
1.73 sakharuk 801: my %lt=&Apache::lonlocal::texthash(
802: 'err' => "ERROR",
803: 'uuas' => "This user has an unrecognized authentication scheme",
804: 'adcs' => "Please alert a domain coordinator of this situation"
805: );
1.26 matthew 806: $r->print(<<ENDBADAUTH);
807: <hr />
1.31 matthew 808: <script type="text/javascript" language="Javascript">
1.26 matthew 809: $loginscript
1.31 matthew 810: </script>
1.73 sakharuk 811: <font color="#ff0000"> $lt{'err'}: </font>
812: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
1.26 matthew 813: <hr />
814: ENDBADAUTH
815: }
816: } else { # Authentication type is valid
1.20 harris41 817: my $authformcurrent='';
1.26 matthew 818: my $authform_other='';
1.94 matthew 819: &initialize_authen_forms();
1.41 albertel 820: if ($currentauth=~/^krb(4|5):/) {
1.20 harris41 821: $authformcurrent=$authformkrb;
1.31 matthew 822: $authform_other="<p>$authformint</p>\n".
823: "<p>$authformfsys</p><p>$authformloc</p>";
1.20 harris41 824: }
825: elsif ($currentauth=~/^internal:/) {
826: $authformcurrent=$authformint;
1.31 matthew 827: $authform_other="<p>$authformkrb</p>".
828: "<p>$authformfsys</p><p>$authformloc</p>";
1.20 harris41 829: }
830: elsif ($currentauth=~/^unix:/) {
831: $authformcurrent=$authformfsys;
1.31 matthew 832: $authform_other="<p>$authformkrb</p>".
833: "<p>$authformint</p><p>$authformloc;</p>";
1.20 harris41 834: }
835: elsif ($currentauth=~/^localauth:/) {
836: $authformcurrent=$authformloc;
1.31 matthew 837: $authform_other="<p>$authformkrb</p>".
838: "<p>$authformint</p><p>$authformfsys</p>";
1.20 harris41 839: }
1.53 www 840: $authformcurrent.=' <i>(will override current values)</i><br />';
1.101 albertel 841: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.26 matthew 842: # Current user has login modification privileges
1.73 sakharuk 843: my %lt=&Apache::lonlocal::texthash(
844: 'ccld' => "Change Current Login Data",
845: 'enld' => "Enter New Login Data"
846: );
1.26 matthew 847: $r->print(<<ENDOTHERAUTHS);
1.21 harris41 848: <hr />
1.31 matthew 849: <script type="text/javascript" language="Javascript">
1.21 harris41 850: $loginscript
1.31 matthew 851: </script>
1.73 sakharuk 852: <h3>$lt{'ccld'}</h3>
1.31 matthew 853: <p>$generalrule</p>
854: <p>$authformnop</p>
855: <p>$authformcurrent</p>
1.73 sakharuk 856: <h3>$lt{'enld'}</h3>
1.26 matthew 857: $authform_other
858: ENDOTHERAUTHS
859: }
860: } ## End of "check for bad authentication type" logic
1.25 matthew 861: } ## End of new user/old user logic
1.72 sakharuk 862: $r->print('<hr /><h3>'.&mt('Add Roles').'</h3>');
1.17 www 863: #
864: # Co-Author
865: #
1.101 albertel 866: if (&authorpriv($env{'user.name'},$env{'request.role.domain'}) &&
867: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1.44 matthew 868: # No sense in assigning co-author role to yourself
1.101 albertel 869: my $cuname=$env{'user.name'};
870: my $cudom=$env{'request.role.domain'};
1.72 sakharuk 871: my %lt=&Apache::lonlocal::texthash(
872: 'cs' => "Construction Space",
873: 'act' => "Activate",
874: 'rol' => "Role",
875: 'ext' => "Extent",
876: 'sta' => "Start",
1.80 www 877: 'end' => "End",
1.72 sakharuk 878: 'cau' => "Co-Author",
1.105 www 879: 'caa' => "Assistant Co-Author",
1.72 sakharuk 880: 'ssd' => "Set Start Date",
881: 'sed' => "Set End Date"
882: );
1.17 www 883: $r->print(<<ENDCOAUTH);
1.72 sakharuk 884: <h4>$lt{'cs'}</h4>
1.74 sakharuk 885: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
1.72 sakharuk 886: <th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
1.17 www 887: <tr>
1.80 www 888: <td><input type=checkbox name="act_$cudom\_$cuname\_ca" /></td>
1.72 sakharuk 889: <td>$lt{'cau'}</td>
1.17 www 890: <td>$cudom\_$cuname</td>
1.80 www 891: <td><input type=hidden name="start_$cudom\_$cuname\_ca" value='' />
1.17 www 892: <a href=
1.72 sakharuk 893: "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.80 www 894: <td><input type=hidden name="end_$cudom\_$cuname\_ca" value='' />
1.17 www 895: <a href=
1.72 sakharuk 896: "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>
1.17 www 897: </tr>
1.105 www 898: <tr>
899: <td><input type=checkbox name="act_$cudom\_$cuname\_aa" /></td>
900: <td>$lt{'caa'}</td>
901: <td>$cudom\_$cuname</td>
902: <td><input type=hidden name="start_$cudom\_$cuname\_aa" value='' />
903: <a href=
904: "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>
905: <td><input type=hidden name="end_$cudom\_$cuname\_aa" value='' />
906: <a href=
907: "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>
908: </tr>
1.17 www 909: </table>
910: ENDCOAUTH
911: }
1.8 www 912: #
913: # Domain level
914: #
1.89 raeburn 915: my $num_domain_level = 0;
916: my $domaintext =
917: '<h4>'.&mt('Domain Level').'</h4>'.
1.73 sakharuk 918: '<table border=2><tr><th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.&mt('Extent').'</th>'.
1.89 raeburn 919: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th></tr>';
1.24 matthew 920: foreach ( sort( keys(%incdomains))) {
1.2 www 921: my $thisdomain=$_;
1.69 albertel 922: foreach ('dc','li','dg','au','sc') {
1.2 www 923: if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
1.8 www 924: my $plrole=&Apache::lonnet::plaintext($_);
1.72 sakharuk 925: my %lt=&Apache::lonlocal::texthash(
926: 'ssd' => "Set Start Date",
927: 'sed' => "Set End Date"
928: );
1.89 raeburn 929: $num_domain_level ++;
930: $domaintext .= <<"ENDDROW";
1.8 www 931: <tr>
932: <td><input type=checkbox name="act_$thisdomain\_$_"></td>
933: <td>$plrole</td>
934: <td>$thisdomain</td>
935: <td><input type=hidden name="start_$thisdomain\_$_" value=''>
936: <a href=
1.72 sakharuk 937: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.8 www 938: <td><input type=hidden name="end_$thisdomain\_$_" value=''>
939: <a href=
1.72 sakharuk 940: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
1.8 www 941: </tr>
942: ENDDROW
1.2 www 943: }
1.24 matthew 944: }
945: }
1.89 raeburn 946: $domaintext.='</table>';
947: if ($num_domain_level > 0) {
948: $r->print($domaintext);
949: }
1.8 www 950: #
1.119 ! raeburn 951: # Course and group levels
1.8 www 952: #
1.88 raeburn 953:
1.101 albertel 954: if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {
1.119 ! raeburn 955: $r->print(&course_level_dc($1,'Course'));
1.88 raeburn 956: $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()">'."\n");
957: } else {
958: $r->print(&course_level_table(%inccourses));
1.89 raeburn 959: $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setSections()">'."\n");
1.88 raeburn 960: }
1.110 albertel 961: $r->print("</form>".&Apache::loncommon::end_page());
1.2 www 962: }
1.1 www 963:
1.4 www 964: # ================================================================= Phase Three
1.42 matthew 965: sub update_user_data {
1.4 www 966: my $r=shift;
1.101 albertel 967: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
968: $env{'form.ccdomain'});
1.27 matthew 969: # Error messages
1.73 sakharuk 970: my $error = '<font color="#ff0000">'.&mt('Error').':</font>';
1.110 albertel 971: my $end = &Apache::loncommon::end_page();
972:
1.40 www 973: my $title;
1.101 albertel 974: if (exists($env{'form.makeuser'})) {
1.40 www 975: $title='Set Privileges for New User';
976: } else {
977: $title='Modify User Privileges';
978: }
1.110 albertel 979: $r->print(&Apache::loncommon::start_page($title));
1.113 raeburn 980: my %disallowed;
1.27 matthew 981: # Check Inputs
1.101 albertel 982: if (! $env{'form.ccuname'} ) {
1.73 sakharuk 983: $r->print($error.&mt('No login name specified').'.'.$end);
1.27 matthew 984: return;
985: }
1.101 albertel 986: if ( $env{'form.ccuname'} =~/\W/) {
1.73 sakharuk 987: $r->print($error.&mt('Invalid login name').'. '.
988: &mt('Only letters, numbers, and underscores are valid').'.'.
1.27 matthew 989: $end);
990: return;
991: }
1.101 albertel 992: if (! $env{'form.ccdomain'} ) {
1.73 sakharuk 993: $r->print($error.&mt('No domain specified').'.'.$end);
1.27 matthew 994: return;
995: }
1.101 albertel 996: if ( $env{'form.ccdomain'} =~/\W/) {
1.73 sakharuk 997: $r->print($error.&mt ('Invalid domain name').'. '.
998: &mt('Only letters, numbers, and underscores are valid').'.'.
1.27 matthew 999: $end);
1000: return;
1001: }
1.101 albertel 1002: if (! exists($env{'form.makeuser'})) {
1.29 matthew 1003: # Modifying an existing user, so check the validity of the name
1004: if ($uhome eq 'no_host') {
1.73 sakharuk 1005: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 1006: $env{'form.ccuname'}.&mt(' in domain ').
1007: $env{'form.ccdomain'}.'.');
1.29 matthew 1008: return;
1009: }
1010: }
1.27 matthew 1011: # Determine authentication method and password for the user being modified
1012: my $amode='';
1013: my $genpwd='';
1.101 albertel 1014: if ($env{'form.login'} eq 'krb') {
1.41 albertel 1015: $amode='krb';
1.101 albertel 1016: $amode.=$env{'form.krbver'};
1017: $genpwd=$env{'form.krbarg'};
1018: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 1019: $amode='internal';
1.101 albertel 1020: $genpwd=$env{'form.intarg'};
1021: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 1022: $amode='unix';
1.101 albertel 1023: $genpwd=$env{'form.fsysarg'};
1024: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 1025: $amode='localauth';
1.101 albertel 1026: $genpwd=$env{'form.locarg'};
1.27 matthew 1027: $genpwd=" " if (!$genpwd);
1.101 albertel 1028: } elsif (($env{'form.login'} eq 'nochange') ||
1029: ($env{'form.login'} eq '' )) {
1.34 matthew 1030: # There is no need to tell the user we did not change what they
1031: # did not ask us to change.
1.35 matthew 1032: # If they are creating a new user but have not specified login
1033: # information this will be caught below.
1.30 matthew 1034: } else {
1.73 sakharuk 1035: $r->print($error.&mt('Invalid login mode or password').$end);
1.30 matthew 1036: return;
1.27 matthew 1037: }
1.101 albertel 1038: if ($env{'form.makeuser'}) {
1.27 matthew 1039: # Create a new user
1.73 sakharuk 1040: my %lt=&Apache::lonlocal::texthash(
1041: 'cru' => "Creating user",
1042: 'id' => "in domain"
1043: );
1.27 matthew 1044: $r->print(<<ENDNEWUSERHEAD);
1.101 albertel 1045: <h3>$lt{'cru'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h3>
1.27 matthew 1046: ENDNEWUSERHEAD
1047: # Check for the authentication mode and password
1048: if (! $amode || ! $genpwd) {
1.73 sakharuk 1049: $r->print($error.&mt('Invalid login mode or password').$end);
1.27 matthew 1050: return;
1.18 albertel 1051: }
1.29 matthew 1052: # Determine desired host
1.101 albertel 1053: my $desiredhost = $env{'form.hserver'};
1.29 matthew 1054: if (lc($desiredhost) eq 'default') {
1055: $desiredhost = undef;
1056: } else {
1.39 matthew 1057: my %home_servers = &Apache::loncommon::get_library_servers
1.101 albertel 1058: ($env{'form.ccdomain'});
1.29 matthew 1059: if (! exists($home_servers{$desiredhost})) {
1.73 sakharuk 1060: $r->print($error.&mt('Invalid home server specified'));
1.29 matthew 1061: return;
1062: }
1063: }
1.27 matthew 1064: # Call modifyuser
1065: my $result = &Apache::lonnet::modifyuser
1.101 albertel 1066: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cstid'},
1067: $amode,$genpwd,$env{'form.cfirst'},
1068: $env{'form.cmiddle'},$env{'form.clast'},$env{'form.cgen'},
1.29 matthew 1069: undef,$desiredhost
1.27 matthew 1070: );
1.77 www 1071: $r->print(&mt('Generating user').': '.$result);
1.101 albertel 1072: my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},
1073: $env{'form.ccdomain'});
1.77 www 1074: $r->print('<br />'.&mt('Home server').': '.$home.' '.
1.29 matthew 1075: $Apache::lonnet::libserv{$home});
1.101 albertel 1076: } elsif (($env{'form.login'} ne 'nochange') &&
1077: ($env{'form.login'} ne '' )) {
1.27 matthew 1078: # Modify user privileges
1.73 sakharuk 1079: my %lt=&Apache::lonlocal::texthash(
1080: 'usr' => "User",
1081: 'id' => "in domain"
1082: );
1.27 matthew 1083: $r->print(<<ENDMODIFYUSERHEAD);
1.101 albertel 1084: <h2>$lt{'usr'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h2>
1.27 matthew 1085: ENDMODIFYUSERHEAD
1086: if (! $amode || ! $genpwd) {
1087: $r->print($error.'Invalid login mode or password'.$end);
1088: return;
1.20 harris41 1089: }
1.27 matthew 1090: # Only allow authentification modification if the person has authority
1.101 albertel 1091: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 1092: $r->print('Modifying authentication: '.
1.31 matthew 1093: &Apache::lonnet::modifyuserauth(
1.101 albertel 1094: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 1095: $amode,$genpwd));
1.102 albertel 1096: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 1097: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 1098: } else {
1.27 matthew 1099: # Okay, this is a non-fatal error.
1.73 sakharuk 1100: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.');
1.27 matthew 1101: }
1.28 matthew 1102: }
1103: ##
1.101 albertel 1104: if (! $env{'form.makeuser'} ) {
1.28 matthew 1105: # Check for need to change
1106: my %userenv = &Apache::lonnet::get
1107: ('environment',['firstname','middlename','lastname','generation'],
1.101 albertel 1108: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 1109: my ($tmp) = keys(%userenv);
1110: if ($tmp =~ /^(con_lost|error)/i) {
1111: %userenv = ();
1112: }
1113: # Check to see if we need to change user information
1114: foreach ('firstname','middlename','lastname','generation') {
1115: # Strip leading and trailing whitespace
1.101 albertel 1116: $env{'form.c'.$_} =~ s/(\s+$|^\s+)//g;
1.28 matthew 1117: }
1.101 albertel 1118: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) &&
1119: ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
1120: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
1121: $env{'form.clastname'} ne $userenv{'lastname'} ||
1122: $env{'form.cgeneration'} ne $userenv{'generation'} )) {
1.28 matthew 1123: # Make the change
1124: my %changeHash;
1.101 albertel 1125: $changeHash{'firstname'} = $env{'form.cfirstname'};
1126: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1127: $changeHash{'lastname'} = $env{'form.clastname'};
1128: $changeHash{'generation'} = $env{'form.cgeneration'};
1.28 matthew 1129: my $putresult = &Apache::lonnet::put
1130: ('environment',\%changeHash,
1.101 albertel 1131: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 1132: if ($putresult eq 'ok') {
1133: # Tell the user we changed the name
1.73 sakharuk 1134: my %lt=&Apache::lonlocal::texthash(
1135: 'uic' => "User Information Changed",
1136: 'frst' => "first",
1137: 'mddl' => "middle",
1138: 'lst' => "last",
1139: 'gen' => "generation",
1140: 'prvs' => "Previous",
1141: 'chto' => "Changed To"
1142: );
1.28 matthew 1143: $r->print(<<"END");
1144: <table border="2">
1.73 sakharuk 1145: <caption>$lt{'uic'}</caption>
1.28 matthew 1146: <tr><th> </th>
1.73 sakharuk 1147: <th>$lt{'frst'}</th>
1148: <th>$lt{'mddl'}</th>
1149: <th>$lt{'lst'}</th>
1150: <th>$lt{'gen'}</th></tr>
1151: <tr><td>$lt{'prvs'}</td>
1.28 matthew 1152: <td>$userenv{'firstname'} </td>
1153: <td>$userenv{'middlename'} </td>
1154: <td>$userenv{'lastname'} </td>
1155: <td>$userenv{'generation'} </td></tr>
1.73 sakharuk 1156: <tr><td>$lt{'chto'}</td>
1.101 albertel 1157: <td>$env{'form.cfirstname'} </td>
1158: <td>$env{'form.cmiddlename'} </td>
1159: <td>$env{'form.clastname'} </td>
1160: <td>$env{'form.cgeneration'} </td></tr>
1.28 matthew 1161: </table>
1162: END
1163: } else { # error occurred
1.73 sakharuk 1164: $r->print("<h2>".&mt('Unable to successfully change environment for')." ".
1.101 albertel 1165: $env{'form.ccuname'}." ".&mt('in domain')." ".
1166: $env{'form.ccdomain'}."</h2>");
1.28 matthew 1167: }
1.101 albertel 1168: } else { # End of if ($env ... ) logic
1.28 matthew 1169: # They did not want to change the users name but we can
1170: # still tell them what the name is
1.73 sakharuk 1171: my %lt=&Apache::lonlocal::texthash(
1172: 'usr' => "User",
1173: 'id' => "in domain",
1174: 'gen' => "Generation"
1175: );
1.28 matthew 1176: $r->print(<<"END");
1.101 albertel 1177: <h2>$lt{'usr'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h2>
1.28 matthew 1178: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
1.73 sakharuk 1179: <h4>$lt{'gen'}: $userenv{'generation'}</h4>
1.28 matthew 1180: END
1181: }
1.4 www 1182: }
1.27 matthew 1183: ##
1.4 www 1184: my $now=time;
1.73 sakharuk 1185: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.101 albertel 1186: foreach (keys (%env)) {
1187: next if (! $env{$_});
1.27 matthew 1188: # Revoke roles
1189: if ($_=~/^form\.rev/) {
1.64 www 1190: if ($_=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1191: # Revoke standard role
1.73 sakharuk 1192: $r->print(&mt('Revoking').' '.$2.' in '.$1.': <b>'.
1.101 albertel 1193: &Apache::lonnet::revokerole($env{'form.ccdomain'},
1.102 albertel 1194: $env{'form.ccuname'},$1,$2).'</b><br />');
1.53 www 1195: if ($2 eq 'st') {
1196: $1=~/^\/(\w+)\/(\w+)/;
1197: my $cid=$1.'_'.$2;
1.73 sakharuk 1198: $r->print(&mt('Drop from classlist').': <b>'.
1.53 www 1199: &Apache::lonnet::critical('put:'.
1.101 albertel 1200: $env{'course.'.$cid.'.domain'}.':'.
1201: $env{'course.'.$cid.'.num'}.':classlist:'.
1.118 www 1202: &escape($env{'form.ccuname'}.':'.
1.101 albertel 1203: $env{'form.ccdomain'}).'='.
1.118 www 1204: &escape($now.':'),
1.102 albertel 1205: $env{'course.'.$cid.'.home'}).'</b><br />');
1.53 www 1206: }
1207: }
1.64 www 1208: if ($_=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
1209: # Revoke custom role
1.113 raeburn 1210: $r->print(&mt('Revoking custom role:').
1.73 sakharuk 1211: ' '.$4.' by '.$3.'@'.$2.' in '.$1.': <b>'.
1.101 albertel 1212: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
1213: $env{'form.ccuname'},$1,$2,$3,$4).
1.102 albertel 1214: '</b><br />');
1.64 www 1215: }
1.53 www 1216: } elsif ($_=~/^form\.del/) {
1.116 raeburn 1217: if ($_=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1218: # Delete standard role
1.73 sakharuk 1219: $r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
1.101 albertel 1220: &Apache::lonnet::assignrole($env{'form.ccdomain'},
1.102 albertel 1221: $env{'form.ccuname'},$1,$2,$now,0,1).'<br />');
1.27 matthew 1222: if ($2 eq 'st') {
1223: $1=~/^\/(\w+)\/(\w+)/;
1224: my $cid=$1.'_'.$2;
1.73 sakharuk 1225: $r->print(&mt('Drop from classlist').': <b>'.
1.27 matthew 1226: &Apache::lonnet::critical('put:'.
1.101 albertel 1227: $env{'course.'.$cid.'.domain'}.':'.
1228: $env{'course.'.$cid.'.num'}.':classlist:'.
1.118 www 1229: &escape($env{'form.ccuname'}.':'.
1.101 albertel 1230: $env{'form.ccdomain'}).'='.
1.118 www 1231: &escape($now.':'),
1.102 albertel 1232: $env{'course.'.$cid.'.home'}).'</b><br />');
1.81 albertel 1233: }
1.116 raeburn 1234: }
1235: if ($_=~/^form\.del\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
1236: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1237: # Delete custom role
1238: $r->print(&mt('Deleting custom role [_1] by [_2]@[_3] in [_4]',
1239: $rolename,$rnam,$rdom,$url).': <b>'.
1240: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
1241: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
1242: 0,1).'</b><br />');
1243: }
1.81 albertel 1244: } elsif ($_=~/^form\.ren/) {
1.101 albertel 1245: my $udom = $env{'form.ccdomain'};
1246: my $uname = $env{'form.ccuname'};
1.116 raeburn 1247: # Re-enable standard role
1248: if ($_=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 1249: my $url = $1;
1250: my $role = $2;
1251: my $logmsg;
1252: my $output;
1253: if ($role eq 'st') {
1254: if ($url =~ m-^/(\w+)/(\w+)/?(\w*)$-) {
1.99 raeburn 1255: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.89 raeburn 1256: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
1257: $output = "Error: $result\n";
1258: } else {
1259: $output = &mt('Assigning').' '.$role.' in '.$url.
1260: &mt('starting').' '.localtime($now).
1261: ': <br />'.$logmsg.'<br />'.
1262: &mt('Add to classlist').': <b>ok</b><br />';
1263: }
1264: }
1265: } else {
1.101 albertel 1266: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1267: $env{'form.ccuname'},$url,$role,0,$now);
1.116 raeburn 1268: $output = &mt('Re-enabling [_1] in [_2]: <b>[_3]</b>',
1.89 raeburn 1269: $role,$url,$result).'<br />';
1.27 matthew 1270: }
1.89 raeburn 1271: $r->print($output);
1.113 raeburn 1272: }
1.116 raeburn 1273: # Re-enable custom role
1274: if ($_=~/^form\.ren\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
1275: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1276: my $result = &Apache::lonnet::assigncustomrole(
1277: $env{'form.ccdomain'}, $env{'form.ccuname'},
1278: $url,$rdom,$rnam,$rolename,0,$now);
1279: $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : <b>[_5]</b>',
1280: $rolename,$rnam,$rdom,$url,$result).'<br />');
1281: }
1.27 matthew 1282: } elsif ($_=~/^form\.act/) {
1.101 albertel 1283: my $udom = $env{'form.ccdomain'};
1284: my $uname = $env{'form.ccuname'};
1.83 albertel 1285: if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) {
1.65 www 1286: # Activate a custom role
1.83 albertel 1287: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
1288: my $url='/'.$one.'/'.$two;
1289: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 1290:
1.101 albertel 1291: my $start = ( $env{'form.start_'.$full} ?
1292: $env{'form.start_'.$full} :
1.88 raeburn 1293: $now );
1.101 albertel 1294: my $end = ( $env{'form.end_'.$full} ?
1295: $env{'form.end_'.$full} :
1.88 raeburn 1296: 0 );
1297:
1298: # split multiple sections
1299: my %sections = ();
1.101 albertel 1300: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 1301: if ($num_sections == 0) {
1.99 raeburn 1302: $r->print(&commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
1.88 raeburn 1303: } else {
1.114 albertel 1304: my %curr_groups =
1.117 raeburn 1305: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 1306: foreach my $sec (sort {$a cmp $b} keys %sections) {
1307: if (($sec eq 'none') || ($sec eq 'all') ||
1308: exists($curr_groups{$sec})) {
1309: $disallowed{$sec} = $url;
1310: next;
1311: }
1312: my $securl = $url.'/'.$sec;
1.99 raeburn 1313: $r->print(&commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
1.88 raeburn 1314: }
1315: }
1.98 albertel 1316: } elsif ($_=~/^form\.act\_([^\_]+)\_(\w+)\_([^\_]+)$/) {
1.27 matthew 1317: # Activate roles for sections with 3 id numbers
1318: # set start, end times, and the url for the class
1.83 albertel 1319: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 1320: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
1321: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 1322: $now );
1.101 albertel 1323: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1324: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 1325: 0 );
1.83 albertel 1326: my $url='/'.$one.'/'.$two;
1.88 raeburn 1327: my $type = 'three';
1328: # split multiple sections
1329: my %sections = ();
1.101 albertel 1330: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 1331: if ($num_sections == 0) {
1.99 raeburn 1332: $r->print(&commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 1333: } else {
1.114 albertel 1334: my %curr_groups =
1.117 raeburn 1335: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 1336: my $emptysec = 0;
1337: foreach my $sec (sort {$a cmp $b} keys %sections) {
1338: $sec =~ s/\W//g;
1.113 raeburn 1339: if ($sec ne '') {
1340: if (($sec eq 'none') || ($sec eq 'all') ||
1341: exists($curr_groups{$sec})) {
1342: $disallowed{$sec} = $url;
1343: next;
1344: }
1.88 raeburn 1345: my $securl = $url.'/'.$sec;
1.99 raeburn 1346: $r->print(&commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
1.88 raeburn 1347: } else {
1348: $emptysec = 1;
1349: }
1350: }
1351: if ($emptysec) {
1.99 raeburn 1352: $r->print(&commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 1353: }
1354: }
1.27 matthew 1355: } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1356: # Activate roles for sections with two id numbers
1357: # set start, end times, and the url for the class
1.101 albertel 1358: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
1359: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 1360: $now );
1.101 albertel 1361: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1362: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 1363: 0 );
1364: my $url='/'.$1.'/';
1.88 raeburn 1365: # split multiple sections
1366: my %sections = ();
1.101 albertel 1367: my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);
1.88 raeburn 1368: if ($num_sections == 0) {
1.99 raeburn 1369: $r->print(&commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88 raeburn 1370: } else {
1371: my $emptysec = 0;
1372: foreach my $sec (sort {$a cmp $b} keys %sections) {
1373: if ($sec ne '') {
1374: my $securl = $url.'/'.$sec;
1.99 raeburn 1375: $r->print(&commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
1.88 raeburn 1376: } else {
1377: $emptysec = 1;
1378: }
1379: }
1380: if ($emptysec) {
1.99 raeburn 1381: $r->print(&commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88 raeburn 1382: }
1383: }
1.64 www 1384: } else {
1.102 albertel 1385: $r->print('<p>'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$_.'</tt></p><br />');
1.64 www 1386: }
1.113 raeburn 1387: foreach my $key (sort(keys(%disallowed))) {
1388: if (($key eq 'none') || ($key eq 'all')) {
1389: $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
1390: } else {
1391: $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));
1392: }
1393: $r->print(' '.&mt('Please <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />');
1394: }
1395: }
1.101 albertel 1396: } # End of foreach (keys(%env))
1.75 www 1397: # Flush the course logs so reverse user roles immediately updated
1398: &Apache::lonnet::flushcourselogs();
1.103 albertel 1399: $r->print('<p><a href="/adm/createuser">Create/Modify Another User</a></p>');
1.110 albertel 1400: $r->print(&Apache::loncommon::end_page());
1.4 www 1401: }
1402:
1.88 raeburn 1403: sub commit_customrole {
1.99 raeburn 1404: my ($udom,$uname,$url,$three,$four,$five,$start,$end) = @_;
1.88 raeburn 1405: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
1406: ($start?', '.&mt('starting').' '.localtime($start):'').
1407: ($end?', ending '.localtime($end):'').': <b>'.
1408: &Apache::lonnet::assigncustomrole(
1.99 raeburn 1409: $udom,$uname,$url,$three,$four,$five,$end,$start).
1.102 albertel 1410: '</b><br />';
1.88 raeburn 1411: return $output;
1412: }
1413:
1414: sub commit_standardrole {
1.99 raeburn 1415: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
1.89 raeburn 1416: my $output;
1417: my $logmsg;
1418: if ($three eq 'st') {
1.99 raeburn 1419: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec);
1.89 raeburn 1420: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
1421: $output = "Error: $result\n";
1422: } else {
1423: $output = &mt('Assigning').' '.$three.' in '.$url.
1424: ($start?', '.&mt('starting').' '.localtime($start):'').
1425: ($end?', '.&mt('ending').' '.localtime($end):'').
1426: ': <b>'.$result.'</b><br />'.
1427: &mt('Add to classlist').': <b>ok</b><br />';
1428: }
1429: } else {
1.92 raeburn 1430: $output = &mt('Assigning').' '.$three.' in '.$url.
1.89 raeburn 1431: ($start?', '.&mt('starting').' '.localtime($start):'').
1432: ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
1433: &Apache::lonnet::assignrole(
1.99 raeburn 1434: $udom,$uname,$url,$three,$end,$start).
1.102 albertel 1435: '</b><br />';
1.88 raeburn 1436: }
1437: return $output;
1438: }
1439:
1.89 raeburn 1440: sub commit_studentrole {
1.99 raeburn 1441: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
1.89 raeburn 1442: my $linefeed = '<br />'."\n";
1443: my $result;
1444: if (defined($one) && defined($two)) {
1445: my $cid=$one.'_'.$two;
1446: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
1447: my $secchange = 0;
1448: my $expire_role_result;
1449: my $modify_section_result;
1450: unless ($oldsec eq '-1') {
1451: unless ($sec eq $oldsec) {
1452: $secchange = 1;
1453: my $uurl='/'.$cid;
1454: $uurl=~s/\_/\//g;
1455: if ($oldsec) {
1456: $uurl.='/'.$oldsec;
1457: }
1458: $expire_role_result = &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',time);
1459: $result = $expire_role_result;
1460: }
1461: }
1462: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1463: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid);
1464: if ($modify_section_result =~ /^ok/) {
1465: if ($secchange == 1) {
1466: $$logmsg .= "Section for $uname switched from old section: $oldsec to new section: $sec".$linefeed;
1467: } elsif ($oldsec eq '-1') {
1468: $$logmsg .= "New student role for $uname in section $sec in course $cid".$linefeed;
1469: } else {
1470: $$logmsg .= "Student $uname assigned to unchanged section $sec in course $cid".$linefeed;
1471: }
1472: } else {
1473: $$logmsg .= "Error when attempting section change for $uname from old section $oldsec to new section: $sec in course $cid -error: $modify_section_result".$linefeed;
1474: }
1475: $result = $modify_section_result;
1476: } elsif ($secchange == 1) {
1477: $$logmsg .= "Error when attempting to expire role for $uname in old section $oldsec in course $cid -error: $expire_role_result".$linefeed;
1478: }
1479: } else {
1480: $$logmsg .= "Incomplete course id defined. Addition of user $uname from domain $udom to course $one\_$two, section $sec not completed.$linefeed";
1.113 raeburn 1481: $result = "error: incomplete course id\n";
1.89 raeburn 1482: }
1483: return $result;
1484: }
1.88 raeburn 1485:
1486: sub build_roles {
1.89 raeburn 1487: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 1488: my $num_sections = 0;
1489: if ($sectionstr=~ /,/) {
1490: my @secnums = split/,/,$sectionstr;
1.89 raeburn 1491: if ($role eq 'st') {
1492: $secnums[0] =~ s/\W//g;
1493: $$sections{$secnums[0]} = 1;
1494: $num_sections = 1;
1495: } else {
1496: foreach my $sec (@secnums) {
1497: $sec =~ ~s/\W//g;
1498: unless ($sec eq "") {
1499: if (exists($$sections{$sec})) {
1500: $$sections{$sec} ++;
1501: } else {
1502: $$sections{$sec} = 1;
1503: $num_sections ++;
1504: }
1.88 raeburn 1505: }
1506: }
1507: }
1508: } else {
1509: $sectionstr=~s/\W//g;
1510: unless ($sectionstr eq '') {
1511: $$sections{$sectionstr} = 1;
1512: $num_sections ++;
1513: }
1514: }
1515:
1516: return $num_sections;
1517: }
1518:
1.58 www 1519: # ========================================================== Custom Role Editor
1520:
1521: sub custom_role_editor {
1522: my $r=shift;
1.101 albertel 1523: my $rolename=$env{'form.rolename'};
1.58 www 1524:
1.59 www 1525: if ($rolename eq 'make new role') {
1.101 albertel 1526: $rolename=$env{'form.newrolename'};
1.59 www 1527: }
1528:
1.63 www 1529: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 1530:
1531: unless ($rolename) {
1532: &print_username_entry_form($r);
1533: return;
1534: }
1535:
1.110 albertel 1536: $r->print(&Apache::loncommon::start_page('Custom Role Editor'));
1.61 www 1537: my $syspriv='';
1538: my $dompriv='';
1539: my $coursepriv='';
1.59 www 1540: my ($rdummy,$roledef)=
1541: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 1542: # ------------------------------------------------------- Does this role exist?
1.110 albertel 1543: $r->print('<h2>');
1.59 www 1544: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 1545: $r->print(&mt('Existing Role').' "');
1.61 www 1546: # ------------------------------------------------- Get current role privileges
1547: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 1548: } else {
1.73 sakharuk 1549: $r->print(&mt('New Role').' "');
1.59 www 1550: $roledef='';
1551: }
1552: $r->print($rolename.'"</h2>');
1.60 www 1553: # ------------------------------------------------------- What can be assigned?
1554: my %full=();
1555: my %courselevel=();
1.61 www 1556: my %courselevelcurrent=();
1.60 www 1557: foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1558: my ($priv,$restrict)=split(/\&/,$_);
1559: unless ($restrict) { $restrict='F'; }
1560: $courselevel{$priv}=$restrict;
1.61 www 1561: if ($coursepriv=~/\:$priv/) {
1562: $courselevelcurrent{$priv}=1;
1563: }
1.60 www 1564: $full{$priv}=1;
1565: }
1566: my %domainlevel=();
1.61 www 1567: my %domainlevelcurrent=();
1.60 www 1568: foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1569: my ($priv,$restrict)=split(/\&/,$_);
1570: unless ($restrict) { $restrict='F'; }
1571: $domainlevel{$priv}=$restrict;
1.61 www 1572: if ($dompriv=~/\:$priv/) {
1573: $domainlevelcurrent{$priv}=1;
1574: }
1.60 www 1575: $full{$priv}=1;
1576: }
1.61 www 1577: my %systemlevel=();
1578: my %systemlevelcurrent=();
1579: foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1580: my ($priv,$restrict)=split(/\&/,$_);
1581: unless ($restrict) { $restrict='F'; }
1582: $systemlevel{$priv}=$restrict;
1583: if ($syspriv=~/\:$priv/) {
1584: $systemlevelcurrent{$priv}=1;
1585: }
1586: $full{$priv}=1;
1587: }
1.73 sakharuk 1588: my %lt=&Apache::lonlocal::texthash(
1589: 'prv' => "Privilege",
1.119 ! raeburn 1590: 'crl' => "Course/Group Level",
1.73 sakharuk 1591: 'dml' => "Domain Level",
1592: 'ssl' => "System Level"
1593: );
1.61 www 1594: $r->print(<<ENDCCF);
1595: <form method="post">
1596: <input type="hidden" name="phase" value="set_custom_roles" />
1597: <input type="hidden" name="rolename" value="$rolename" />
1598: <table border="2">
1.73 sakharuk 1599: <tr><th>$lt{'prv'}</th><th>$lt{'crl'}</th><th>$lt{'dml'}</th>
1600: <th>$lt{'ssl'}</th></tr>
1.61 www 1601: ENDCCF
1.119 ! raeburn 1602: foreach my $priv (sort keys %full) {
! 1603: my $privtext = &Apache::lonnet::plaintext($priv);
! 1604: if ($env{'course.'.$env{'request.course.id'}.'.type'}) {
! 1605: $privtext =~ s/Student/Member/;
! 1606: $privtext =~ s/student/member/;
! 1607: $privtext =~ s/course/group/;
! 1608: }
! 1609: $r->print('<tr><td>'.$privtext.'</td><td>'.
! 1610: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.':c" '.
! 1611: ($courselevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 1612: '</td><td>'.
1.119 ! raeburn 1613: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.':d" '.
! 1614: ($domainlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 1615: '</td><td>'.
1.119 ! raeburn 1616: ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.':s" '.
! 1617: ($systemlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 1618: '</td></tr>');
1.60 www 1619: }
1.61 www 1620: $r->print(
1.110 albertel 1621: '<table><input type="submit" value="'.&mt('Define Role').'" /></form>'.
1622: &Apache::loncommon::end_page());
1.61 www 1623: }
1624:
1625: # ---------------------------------------------------------- Call to definerole
1626: sub set_custom_role {
1.110 albertel 1627: my ($r) = @_;
1.61 www 1628:
1.101 albertel 1629: my $rolename=$env{'form.rolename'};
1.61 www 1630:
1.63 www 1631: $rolename=~s/[^A-Za-z0-9]//gs;
1.61 www 1632:
1633: unless ($rolename) {
1634: &print_username_entry_form($r);
1635: return;
1636: }
1637:
1.110 albertel 1638: $r->print(&Apache::loncommon::start_page('Save Custom Role').'<h2>');
1.61 www 1639: my ($rdummy,$roledef)=
1.110 albertel 1640: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1641:
1.61 www 1642: # ------------------------------------------------------- Does this role exist?
1643: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 1644: $r->print(&mt('Existing Role').' "');
1.61 www 1645: } else {
1.73 sakharuk 1646: $r->print(&mt('New Role').' "');
1.61 www 1647: $roledef='';
1648: }
1649: $r->print($rolename.'"</h2>');
1650: # ------------------------------------------------------- What can be assigned?
1651: my $sysrole='';
1652: my $domrole='';
1653: my $courole='';
1654:
1655: foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1656: my ($priv,$restrict)=split(/\&/,$_);
1657: unless ($restrict) { $restrict=''; }
1.101 albertel 1658: if ($env{'form.'.$priv.':c'}) {
1.61 www 1659: $courole.=':'.$_;
1660: }
1661: }
1662:
1663: foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1664: my ($priv,$restrict)=split(/\&/,$_);
1665: unless ($restrict) { $restrict=''; }
1.101 albertel 1666: if ($env{'form.'.$priv.':d'}) {
1.61 www 1667: $domrole.=':'.$_;
1668: }
1669: }
1670:
1671: foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1672: my ($priv,$restrict)=split(/\&/,$_);
1673: unless ($restrict) { $restrict=''; }
1.101 albertel 1674: if ($env{'form.'.$priv.':s'}) {
1.61 www 1675: $sysrole.=':'.$_;
1676: }
1677: }
1.63 www 1678: $r->print('<br />Defining Role: '.
1.61 www 1679: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 1680: if ($env{'request.course.id'}) {
1681: my $url='/'.$env{'request.course.id'};
1.63 www 1682: $url=~s/\_/\//g;
1.73 sakharuk 1683: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 1684: &Apache::lonnet::assigncustomrole($env{'user.domain'},
1685: $env{'user.name'},
1.63 www 1686: $url,
1.101 albertel 1687: $env{'user.domain'},
1688: $env{'user.name'},
1.63 www 1689: $rolename));
1690: }
1.109 albertel 1691: $r->print('<p><a href="/adm/createuser">Create another role, or Create/Modify a user.</a></p>');
1.110 albertel 1692: $r->print(&Apache::loncommon::end_page());
1.58 www 1693: }
1694:
1.2 www 1695: # ================================================================ Main Handler
1696: sub handler {
1697: my $r = shift;
1698:
1699: if ($r->header_only) {
1.68 www 1700: &Apache::loncommon::content_type($r,'text/html');
1.2 www 1701: $r->send_http_header;
1702: return OK;
1703: }
1704:
1.101 albertel 1705: if ((&Apache::lonnet::allowed('cta',$env{'request.course.id'})) ||
1706: (&Apache::lonnet::allowed('cin',$env{'request.course.id'})) ||
1707: (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) ||
1708: (&Apache::lonnet::allowed('cep',$env{'request.course.id'})) ||
1.104 albertel 1709: (&authorpriv($env{'user.name'},$env{'request.role.domain'})) ||
1.101 albertel 1710: (&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) {
1.68 www 1711: &Apache::loncommon::content_type($r,'text/html');
1.2 www 1712: $r->send_http_header;
1.101 albertel 1713: unless ($env{'form.phase'}) {
1.42 matthew 1714: &print_username_entry_form($r);
1.2 www 1715: }
1.101 albertel 1716: if ($env{'form.phase'} eq 'get_user_info') {
1.42 matthew 1717: &print_user_modification_page($r);
1.101 albertel 1718: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.42 matthew 1719: &update_user_data($r);
1.101 albertel 1720: } elsif ($env{'form.phase'} eq 'selected_custom_edit') {
1.58 www 1721: &custom_role_editor($r);
1.101 albertel 1722: } elsif ($env{'form.phase'} eq 'set_custom_roles') {
1.61 www 1723: &set_custom_role($r);
1.2 www 1724: }
1.1 www 1725: } else {
1.101 albertel 1726: $env{'user.error.msg'}=
1.9 albertel 1727: "/adm/createuser:mau:0:0:Cannot modify user data";
1.1 www 1728: return HTTP_NOT_ACCEPTABLE;
1729: }
1730: return OK;
1731: }
1.26 matthew 1732:
1.27 matthew 1733: #-------------------------------------------------- functions for &phase_two
1.26 matthew 1734: sub course_level_table {
1.89 raeburn 1735: my (%inccourses) = @_;
1.26 matthew 1736: my $table = '';
1.62 www 1737: # Custom Roles?
1738:
1739: my %customroles=&my_custom_roles();
1.89 raeburn 1740: my %lt=&Apache::lonlocal::texthash(
1741: 'exs' => "Existing sections",
1742: 'new' => "Define new section",
1743: 'ssd' => "Set Start Date",
1744: 'sed' => "Set End Date",
1.119 ! raeburn 1745: 'crl' => "Course/Group Level",
1.89 raeburn 1746: 'act' => "Activate",
1747: 'rol' => "Role",
1748: 'ext' => "Extent",
1.113 raeburn 1749: 'grs' => "Section",
1.89 raeburn 1750: 'sta' => "Start",
1751: 'end' => "End"
1752: );
1.62 www 1753:
1.26 matthew 1754: foreach (sort( keys(%inccourses))) {
1755: my $thiscourse=$_;
1756: my $protectedcourse=$_;
1757: $thiscourse=~s:_:/:g;
1758: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1759: my $area=$coursedata{'description'};
1.119 ! raeburn 1760: my $type=$coursedata{'type'};
1.72 sakharuk 1761: if (!defined($area)) { $area=&mt('Unavailable course').': '.$_; }
1.26 matthew 1762: my $bgcol=$thiscourse;
1.62 www 1763: $bgcol=~s/[^7-9a-e]//g;
1764: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
1.89 raeburn 1765: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 1766: my %sections_count;
1.101 albertel 1767: if (defined($env{'request.course.id'})) {
1768: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 1769: %sections_count =
1770: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 1771: }
1772: }
1.119 ! raeburn 1773: foreach ('st','ta','ep','in','cc') {
1.26 matthew 1774: if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
1775: my $plrole=&Apache::lonnet::plaintext($_);
1.119 ! raeburn 1776: if ($type eq 'Group') {
! 1777: $plrole = &Apache::loncommon::convert_role($plrole,$type);
! 1778: }
1.26 matthew 1779: $table .= <<ENDEXTENT;
1780: <tr bgcolor="#$bgcol">
1781: <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
1782: <td>$plrole</td>
1.82 albertel 1783: <td>$area<br />Domain: $domain</td>
1.26 matthew 1784: ENDEXTENT
1785: if ($_ ne 'cc') {
1.115 albertel 1786: if (%sections_count) {
1787: my $currsec = &course_sections(\%sections_count,$protectedcourse.'_'.$_);
1.89 raeburn 1788: $table .=
1789: '<td><table border="0" cellspacing="0" cellpadding="0">'.
1790: '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
1791: $currsec.'</td>'.
1792: '<td> </td>'.
1793: '<td valign="top"> '.$lt{'new'}.'<br />'.
1794: '<input type="text" name="newsec_'.$protectedcourse.'_'.$_.'" value="" /></td>'.
1795: '<input type="hidden" '.
1796: 'name="sec_'.$protectedcourse.'_'.$_.'"></td>'.
1797: '</tr></table></td>';
1798: } else {
1799: $table .= '<td><input type="text" size="10" '.
1800: 'name="sec_'.$protectedcourse.'_'.$_.'"></td>';
1801: }
1.26 matthew 1802: } else {
1.89 raeburn 1803: $table .= '<td> </td>';
1.26 matthew 1804: }
1805: $table .= <<ENDTIMEENTRY;
1806: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
1807: <a href=
1.73 sakharuk 1808: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.26 matthew 1809: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
1810: <a href=
1.73 sakharuk 1811: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">$lt{'sed'}</a></td>
1.26 matthew 1812: ENDTIMEENTRY
1813: $table.= "</tr>\n";
1814: }
1815: }
1.62 www 1816: foreach (sort keys %customroles) {
1.65 www 1817: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1818: my $plrole=$_;
1.101 albertel 1819: my $customrole=$protectedcourse.'_cr_cr_'.$env{'user.domain'}.
1820: '_'.$env{'user.name'}.'_'.$plrole;
1.89 raeburn 1821: $table .= <<END;
1.62 www 1822: <tr bgcolor="#$bgcol">
1.65 www 1823: <td><input type="checkbox" name="act_$customrole"></td>
1.62 www 1824: <td>$plrole</td>
1825: <td>$area</td>
1.89 raeburn 1826: END
1.115 albertel 1827: if (%sections_count) {
1828: my $currsec = &course_sections(\%sections_count,$customrole);
1.89 raeburn 1829: $table.=
1830: '<td><table border="0" cellspacing="0" cellpadding="0">'.
1831: '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
1832: $currsec.'</td>'.
1833: '<td> </td>'.
1834: '<td valign="top"> '.$lt{'new'}.'<br />'.
1835: '<input type="text" name="newsec_'.$customrole.'" value="" /></td>'.
1836: '<input type="hidden" '.
1837: 'name="sec_'.$customrole.'"></td>'.
1838: '</tr></table></td>';
1839: } else {
1840: $table .= '<td><input type="text" size="10" '.
1841: 'name="sec_'.$customrole.'"></td>';
1842: }
1843: $table .= <<ENDENTRY;
1.65 www 1844: <td><input type=hidden name="start_$customrole" value=''>
1.62 www 1845: <a href=
1.73 sakharuk 1846: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.65 www 1847: <td><input type=hidden name="end_$customrole" value=''>
1.62 www 1848: <a href=
1.73 sakharuk 1849: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">$lt{'sed'}</a></td></tr>
1.62 www 1850: ENDENTRY
1.65 www 1851: }
1.62 www 1852: }
1.26 matthew 1853: }
1854: return '' if ($table eq ''); # return nothing if there is nothing
1855: # in the table
1856: my $result = <<ENDTABLE;
1.73 sakharuk 1857: <h4>$lt{'crl'}</h4>
1858: <table border=2><tr><th>$lt{'act'}</th><th>$lt{'rol'}</th><th>$lt{'ext'}</th>
1859: <th>$lt{'grs'}</th><th>$lt{'sta'}</th><th>$lt{'end'}</th></tr>
1.26 matthew 1860: $table
1861: </table>
1862: ENDTABLE
1863: return $result;
1864: }
1.88 raeburn 1865:
1.89 raeburn 1866: sub course_sections {
1.115 albertel 1867: my ($sections_count,$role) = @_;
1.89 raeburn 1868: my $output = '';
1869: my @sections = (sort {$a <=> $b} keys %{$sections_count});
1.115 albertel 1870: if (scalar(@sections) == 1) {
1.92 raeburn 1871: $output = '<select name="currsec_'.$role.'" >'."\n".
1872: ' <option value="">Select</option>'."\n".
1.93 raeburn 1873: ' <option value="">No section</option>'."\n".
1.92 raeburn 1874: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1875: } else {
1876: $output = '<select name="currsec_'.$role.'" ';
1877: my $multiple = 4;
1.115 albertel 1878: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1.95 albertel 1879: $output .= '"multiple" size="'.$multiple.'">'."\n";
1.92 raeburn 1880: foreach (@sections) {
1881: $output .= '<option value="'.$_.'">'.$_."</option>\n";
1882: }
1.89 raeburn 1883: }
1884: $output .= '</select>';
1885: return $output;
1886: }
1887:
1.88 raeburn 1888: sub course_level_dc {
1889: my ($dcdom) = @_;
1890: my %customroles=&my_custom_roles();
1891: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
1892: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1893: '<input type="hidden" name="dccourse" value="" />';
1894: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.119 ! raeburn 1895: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course/Group').'</b>';
! 1896: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom);
1.88 raeburn 1897: my %lt=&Apache::lonlocal::texthash(
1.119 ! raeburn 1898: 'typ' => "Type",
1.88 raeburn 1899: 'rol' => "Role",
1.113 raeburn 1900: 'grs' => "Section",
1.88 raeburn 1901: 'exs' => "Existing sections",
1902: 'new' => "Define new section",
1903: 'sta' => "Start",
1904: 'end' => "End",
1905: 'ssd' => "Set Start Date",
1906: 'sed' => "Set End Date"
1907: );
1.119 ! raeburn 1908: my $header = '<h4>'.&mt('Course/Group Level').'</h4>'.
! 1909: '<table border="2"><tr><th>'.$lt{'typ'}.'</th><th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th></tr>';
! 1910: my $otheritems = '<tr><td><select name="crstype" onChange="javascript:setType();">'."\n".
! 1911: ' <option value="">'.&mt('Please select')."\n".
! 1912: ' <option value="Course">'.&mt('Course')."\n".
! 1913: ' <option value="Group">'.&mt('Group')."\n".
! 1914: '</select>'."\n".
! 1915: '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','".')" /></td>'."\n".
1.88 raeburn 1916: '<td><select name="role">'."\n";
1.119 ! raeburn 1917: foreach ('st','ta','ep','in','cc') {
1.88 raeburn 1918: my $plrole=&Apache::lonnet::plaintext($_);
1919: $otheritems .= ' <option value="'.$_.'">'.$plrole;
1920: }
1921: if ( keys %customroles > 0) {
1922: foreach (sort keys %customroles) {
1.101 albertel 1923: my $custrole='cr_cr_'.$env{'user.domain'}.
1924: '_'.$env{'user.name'}.'_'.$_;
1.88 raeburn 1925: $otheritems .= ' <option value="'.$custrole.'">'.$_;
1926: }
1927: }
1928: $otheritems .= '</select></td><td>'.
1929: '<table border="0" cellspacing="0" cellpadding="0">'.
1930: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1931: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
1932: '<td> </td>'.
1933: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 1934: '<input type="text" name="newsec" value="" />'.
1935: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 1936: '</tr></table></td>';
1937: $otheritems .= <<ENDTIMEENTRY;
1938: <td><input type=hidden name="start" value=''>
1939: <a href=
1940: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1941: <td><input type=hidden name="end" value=''>
1942: <a href=
1943: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
1944: ENDTIMEENTRY
1945: $otheritems .= "</tr></table>\n";
1946: return $cb_jscript.$header.$hiddenitems.$otheritems;
1947: }
1948:
1.27 matthew 1949: #---------------------------------------------- end functions for &phase_two
1.29 matthew 1950:
1951: #--------------------------------- functions for &phase_two and &phase_three
1952:
1953: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 1954:
1955: 1;
1956: __END__
1.2 www 1957:
1958:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>