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