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