Annotation of loncom/interface/loncreateuser.pm, revision 1.185
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.185 ! raeburn 4: # $Id: loncreateuser.pm,v 1.184 2007/09/12 23:26:25 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.41 albertel 1073: unless ($currentauth=~/^krb(4|5):/ or
1.20 harris41 1074: $currentauth=~/^unix:/ or
1075: $currentauth=~/^internal:/ or
1076: $currentauth=~/^localauth:/
1.26 matthew 1077: ) { # bad authentication scheme
1.132 raeburn 1078: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.94 matthew 1079: &initialize_authen_forms();
1.73 sakharuk 1080: my %lt=&Apache::lonlocal::texthash(
1081: 'err' => "ERROR",
1082: 'uuas' => "This user has an unrecognized authentication scheme",
1083: 'sldb' => "Please specify login data below",
1084: 'ld' => "Login Data"
1085: );
1.26 matthew 1086: $r->print(<<ENDBADAUTH);
1.21 harris41 1087: <hr />
1.31 matthew 1088: <script type="text/javascript" language="Javascript">
1.21 harris41 1089: $loginscript
1.31 matthew 1090: </script>
1.73 sakharuk 1091: <font color='#ff0000'>$lt{'err'}:</font>
1092: $lt{'uuas'} ($currentauth). $lt{'sldb'}.
1093: <h3>$lt{'ld'}</h3>
1.31 matthew 1094: <p>$generalrule</p>
1095: <p>$authformkrb</p>
1096: <p>$authformint</p>
1097: <p>$authformfsys</p>
1098: <p>$authformloc</p>
1.26 matthew 1099: ENDBADAUTH
1100: } else {
1.132 raeburn 1101: # This user is not allowed to modify the user's
1.26 matthew 1102: # authentication scheme, so just notify them of the problem
1.73 sakharuk 1103: my %lt=&Apache::lonlocal::texthash(
1104: 'err' => "ERROR",
1105: 'uuas' => "This user has an unrecognized authentication scheme",
1106: 'adcs' => "Please alert a domain coordinator of this situation"
1107: );
1.26 matthew 1108: $r->print(<<ENDBADAUTH);
1109: <hr />
1.73 sakharuk 1110: <font color="#ff0000"> $lt{'err'}: </font>
1111: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
1.26 matthew 1112: <hr />
1113: ENDBADAUTH
1114: }
1115: } else { # Authentication type is valid
1.20 harris41 1116: my $authformcurrent='';
1.26 matthew 1117: my $authform_other='';
1.94 matthew 1118: &initialize_authen_forms();
1.41 albertel 1119: if ($currentauth=~/^krb(4|5):/) {
1.20 harris41 1120: $authformcurrent=$authformkrb;
1.31 matthew 1121: $authform_other="<p>$authformint</p>\n".
1122: "<p>$authformfsys</p><p>$authformloc</p>";
1.20 harris41 1123: }
1124: elsif ($currentauth=~/^internal:/) {
1125: $authformcurrent=$authformint;
1.31 matthew 1126: $authform_other="<p>$authformkrb</p>".
1127: "<p>$authformfsys</p><p>$authformloc</p>";
1.20 harris41 1128: }
1129: elsif ($currentauth=~/^unix:/) {
1130: $authformcurrent=$authformfsys;
1.31 matthew 1131: $authform_other="<p>$authformkrb</p>".
1132: "<p>$authformint</p><p>$authformloc;</p>";
1.20 harris41 1133: }
1134: elsif ($currentauth=~/^localauth:/) {
1135: $authformcurrent=$authformloc;
1.31 matthew 1136: $authform_other="<p>$authformkrb</p>".
1137: "<p>$authformint</p><p>$authformfsys</p>";
1.20 harris41 1138: }
1.53 www 1139: $authformcurrent.=' <i>(will override current values)</i><br />';
1.132 raeburn 1140: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.26 matthew 1141: # Current user has login modification privileges
1.73 sakharuk 1142: my %lt=&Apache::lonlocal::texthash(
1143: 'ccld' => "Change Current Login Data",
1144: 'enld' => "Enter New Login Data"
1145: );
1.26 matthew 1146: $r->print(<<ENDOTHERAUTHS);
1.21 harris41 1147: <hr />
1.31 matthew 1148: <script type="text/javascript" language="Javascript">
1.21 harris41 1149: $loginscript
1.31 matthew 1150: </script>
1.73 sakharuk 1151: <h3>$lt{'ccld'}</h3>
1.31 matthew 1152: <p>$generalrule</p>
1153: <p>$authformnop</p>
1154: <p>$authformcurrent</p>
1.73 sakharuk 1155: <h3>$lt{'enld'}</h3>
1.26 matthew 1156: $authform_other
1157: ENDOTHERAUTHS
1.132 raeburn 1158: } else {
1159: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1160: my %lt=&Apache::lonlocal::texthash(
1161: 'ccld' => "Change Current Login Data",
1162: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
1163: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1164: );
1165: $r->print(<<ENDNOPRIV);
1166: <hr />
1167: <h3>$lt{'ccld'}</h3>
1168: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1169: ENDNOPRIV
1170: }
1.26 matthew 1171: }
1.134 raeburn 1172: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1173: # Current user has quota modification privileges
1174: $r->print(&portfolio_quota($ccuname,$ccdomain));
1175: }
1.26 matthew 1176: } ## End of "check for bad authentication type" logic
1.25 matthew 1177: } ## End of new user/old user logic
1.72 sakharuk 1178: $r->print('<hr /><h3>'.&mt('Add Roles').'</h3>');
1.17 www 1179: #
1180: # Co-Author
1181: #
1.101 albertel 1182: if (&authorpriv($env{'user.name'},$env{'request.role.domain'}) &&
1183: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1.44 matthew 1184: # No sense in assigning co-author role to yourself
1.101 albertel 1185: my $cuname=$env{'user.name'};
1186: my $cudom=$env{'request.role.domain'};
1.72 sakharuk 1187: my %lt=&Apache::lonlocal::texthash(
1188: 'cs' => "Construction Space",
1189: 'act' => "Activate",
1190: 'rol' => "Role",
1191: 'ext' => "Extent",
1192: 'sta' => "Start",
1.80 www 1193: 'end' => "End",
1.72 sakharuk 1194: 'cau' => "Co-Author",
1.105 www 1195: 'caa' => "Assistant Co-Author",
1.72 sakharuk 1196: 'ssd' => "Set Start Date",
1197: 'sed' => "Set End Date"
1198: );
1.135 raeburn 1199: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
1200: &Apache::loncommon::start_data_table()."\n".
1201: &Apache::loncommon::start_data_table_header_row()."\n".
1202: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
1203: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
1204: '<th>'.$lt{'end'}.'</th>'."\n".
1205: &Apache::loncommon::end_data_table_header_row()."\n".
1206: &Apache::loncommon::start_data_table_row()."\n".
1207: '<td>
1208: <input type=checkbox name="act_'.$cudom.'_'.$cuname.'_ca" />
1209: </td>
1210: <td>'.$lt{'cau'}.'</td>
1211: <td>'.$cudom.'_'.$cuname.'</td>
1212: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
1213: <a href=
1214: "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 1215: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
1.17 www 1216: <a href=
1.135 raeburn 1217: "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".
1218: &Apache::loncommon::end_data_table_row()."\n".
1219: &Apache::loncommon::start_data_table_row()."\n".
1220: '<td><input type=checkbox name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1221: <td>'.$lt{'caa'}.'</td>
1222: <td>'.$cudom.'_'.$cuname.'</td>
1.169 albertel 1223: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
1.17 www 1224: <a href=
1.135 raeburn 1225: "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 1226: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
1.105 www 1227: <a href=
1.135 raeburn 1228: "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".
1229: &Apache::loncommon::end_data_table_row()."\n".
1230: &Apache::loncommon::end_data_table());
1.17 www 1231: }
1.8 www 1232: #
1233: # Domain level
1234: #
1.89 raeburn 1235: my $num_domain_level = 0;
1236: my $domaintext =
1237: '<h4>'.&mt('Domain Level').'</h4>'.
1.135 raeburn 1238: &Apache::loncommon::start_data_table().
1239: &Apache::loncommon::start_data_table_header_row().
1240: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
1241: &mt('Extent').'</th>'.
1242: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
1243: &Apache::loncommon::end_data_table_header_row();
1.146 albertel 1244: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.135 raeburn 1245: foreach my $role ('dc','li','dg','au','sc') {
1246: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1247: my $plrole=&Apache::lonnet::plaintext($role);
1.72 sakharuk 1248: my %lt=&Apache::lonlocal::texthash(
1249: 'ssd' => "Set Start Date",
1250: 'sed' => "Set End Date"
1251: );
1.89 raeburn 1252: $num_domain_level ++;
1.135 raeburn 1253: $domaintext .=
1254: &Apache::loncommon::start_data_table_row().
1.157 albertel 1255: '<td><input type=checkbox name="act_'.$thisdomain.'_'.$role.'" /></td>
1.135 raeburn 1256: <td>'.$plrole.'</td>
1257: <td>'.$thisdomain.'</td>
1.169 albertel 1258: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
1.8 www 1259: <a href=
1.135 raeburn 1260: "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 1261: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
1.8 www 1262: <a href=
1.135 raeburn 1263: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
1264: &Apache::loncommon::end_data_table_row();
1.2 www 1265: }
1.24 matthew 1266: }
1267: }
1.135 raeburn 1268: $domaintext.= &Apache::loncommon::end_data_table();
1.89 raeburn 1269: if ($num_domain_level > 0) {
1270: $r->print($domaintext);
1271: }
1.8 www 1272: #
1.119 raeburn 1273: # Course and group levels
1.8 www 1274: #
1.88 raeburn 1275:
1.139 albertel 1276: if ($env{'request.role'} =~ m{^dc\./($match_domain)/$}) {
1.119 raeburn 1277: $r->print(&course_level_dc($1,'Course'));
1.157 albertel 1278: $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()" />'."\n");
1.88 raeburn 1279: } else {
1280: $r->print(&course_level_table(%inccourses));
1.157 albertel 1281: $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setSections()" />'."\n");
1.88 raeburn 1282: }
1.179 raeburn 1283: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate']));
1284: $r->print('<input type="hidden" name="currstate" value="" />');
1.160 raeburn 1285: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />');
1.110 albertel 1286: $r->print("</form>".&Apache::loncommon::end_page());
1.2 www 1287: }
1.1 www 1288:
1.185 ! raeburn 1289: sub set_login {
! 1290: my $response = (<<ENDAUTH);
! 1291: <p>$generalrule </p>
! 1292: <p>$authformkrb </p>
! 1293: <p>$authformint </p>
! 1294: <p>$authformfsys</p>
! 1295: <p>$authformloc </p>
! 1296: ENDAUTH
! 1297: return $response;
! 1298: }
! 1299:
1.4 www 1300: # ================================================================= Phase Three
1.42 matthew 1301: sub update_user_data {
1.160 raeburn 1302: my ($r) = @_;
1.101 albertel 1303: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
1304: $env{'form.ccdomain'});
1.27 matthew 1305: # Error messages
1.73 sakharuk 1306: my $error = '<font color="#ff0000">'.&mt('Error').':</font>';
1.110 albertel 1307: my $end = &Apache::loncommon::end_page();
1308:
1.40 www 1309: my $title;
1.101 albertel 1310: if (exists($env{'form.makeuser'})) {
1.40 www 1311: $title='Set Privileges for New User';
1312: } else {
1313: $title='Modify User Privileges';
1314: }
1.160 raeburn 1315:
1316: my ($jsback,$elements) = &crumb_utilities();
1317: my $jscript = '<script type="text/javascript">'."\n".
1318: $jsback."\n".'</script>'."\n";
1319:
1320: $r->print(&Apache::loncommon::start_page($title,$jscript));
1321: &Apache::lonhtmlcommon::add_breadcrumb
1322: ({href=>"javascript:backPage(document.userupdate)",
1.166 albertel 1323: text=>"User modify/custom role edit",
1.160 raeburn 1324: faq=>282,bug=>'Instructor Interface',});
1325: if ($env{'form.prevphase'} eq 'userpicked') {
1326: &Apache::lonhtmlcommon::add_breadcrumb
1327: ({href=>"javascript:backPage(document.userupdate,'get_user_info','select')",
1328: text=>"Select a user",
1329: faq=>282,bug=>'Instructor Interface',});
1330: }
1331: &Apache::lonhtmlcommon::add_breadcrumb
1332: ({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
1333: text=>"Set user role",
1334: faq=>282,bug=>'Instructor Interface',},
1335: {href=>"/adm/createuser",
1336: text=>"Result",
1337: faq=>282,bug=>'Instructor Interface',});
1338: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1339:
1.113 raeburn 1340: my %disallowed;
1.27 matthew 1341: # Check Inputs
1.101 albertel 1342: if (! $env{'form.ccuname'} ) {
1.73 sakharuk 1343: $r->print($error.&mt('No login name specified').'.'.$end);
1.27 matthew 1344: return;
1345: }
1.138 albertel 1346: if ( $env{'form.ccuname'} ne
1347: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.73 sakharuk 1348: $r->print($error.&mt('Invalid login name').'. '.
1.160 raeburn 1349: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid').'.'.
1.27 matthew 1350: $end);
1351: return;
1352: }
1.101 albertel 1353: if (! $env{'form.ccdomain'} ) {
1.73 sakharuk 1354: $r->print($error.&mt('No domain specified').'.'.$end);
1.27 matthew 1355: return;
1356: }
1.138 albertel 1357: if ( $env{'form.ccdomain'} ne
1358: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.73 sakharuk 1359: $r->print($error.&mt ('Invalid domain name').'. '.
1.138 albertel 1360: &mt('Only letters, numbers, periods, dashes, and underscores are valid').'.'.
1.27 matthew 1361: $end);
1362: return;
1363: }
1.101 albertel 1364: if (! exists($env{'form.makeuser'})) {
1.29 matthew 1365: # Modifying an existing user, so check the validity of the name
1366: if ($uhome eq 'no_host') {
1.73 sakharuk 1367: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 1368: $env{'form.ccuname'}.&mt(' in domain ').
1369: $env{'form.ccdomain'}.'.');
1.29 matthew 1370: return;
1371: }
1372: }
1.27 matthew 1373: # Determine authentication method and password for the user being modified
1374: my $amode='';
1375: my $genpwd='';
1.101 albertel 1376: if ($env{'form.login'} eq 'krb') {
1.41 albertel 1377: $amode='krb';
1.101 albertel 1378: $amode.=$env{'form.krbver'};
1379: $genpwd=$env{'form.krbarg'};
1380: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 1381: $amode='internal';
1.101 albertel 1382: $genpwd=$env{'form.intarg'};
1383: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 1384: $amode='unix';
1.101 albertel 1385: $genpwd=$env{'form.fsysarg'};
1386: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 1387: $amode='localauth';
1.101 albertel 1388: $genpwd=$env{'form.locarg'};
1.27 matthew 1389: $genpwd=" " if (!$genpwd);
1.101 albertel 1390: } elsif (($env{'form.login'} eq 'nochange') ||
1391: ($env{'form.login'} eq '' )) {
1.34 matthew 1392: # There is no need to tell the user we did not change what they
1393: # did not ask us to change.
1.35 matthew 1394: # If they are creating a new user but have not specified login
1395: # information this will be caught below.
1.30 matthew 1396: } else {
1.73 sakharuk 1397: $r->print($error.&mt('Invalid login mode or password').$end);
1.30 matthew 1398: return;
1.27 matthew 1399: }
1.164 albertel 1400:
1401:
1402: $r->print('<h2>'.&mt('User [_1] in domain [_2]',
1403: $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h2>');
1404:
1.101 albertel 1405: if ($env{'form.makeuser'}) {
1.164 albertel 1406: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 1407: # Check for the authentication mode and password
1408: if (! $amode || ! $genpwd) {
1.73 sakharuk 1409: $r->print($error.&mt('Invalid login mode or password').$end);
1.27 matthew 1410: return;
1.18 albertel 1411: }
1.29 matthew 1412: # Determine desired host
1.101 albertel 1413: my $desiredhost = $env{'form.hserver'};
1.29 matthew 1414: if (lc($desiredhost) eq 'default') {
1415: $desiredhost = undef;
1416: } else {
1.147 albertel 1417: my %home_servers =
1418: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 1419: if (! exists($home_servers{$desiredhost})) {
1.73 sakharuk 1420: $r->print($error.&mt('Invalid home server specified'));
1.29 matthew 1421: return;
1422: }
1423: }
1.27 matthew 1424: # Call modifyuser
1425: my $result = &Apache::lonnet::modifyuser
1.101 albertel 1426: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cstid'},
1427: $amode,$genpwd,$env{'form.cfirst'},
1428: $env{'form.cmiddle'},$env{'form.clast'},$env{'form.cgen'},
1.184 raeburn 1429: undef,$desiredhost,$env{'form.cemail'}
1.27 matthew 1430: );
1.77 www 1431: $r->print(&mt('Generating user').': '.$result);
1.101 albertel 1432: my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},
1433: $env{'form.ccdomain'});
1.77 www 1434: $r->print('<br />'.&mt('Home server').': '.$home.' '.
1.148 albertel 1435: &Apache::lonnet::hostname($home));
1.101 albertel 1436: } elsif (($env{'form.login'} ne 'nochange') &&
1437: ($env{'form.login'} ne '' )) {
1.27 matthew 1438: # Modify user privileges
1439: if (! $amode || ! $genpwd) {
1440: $r->print($error.'Invalid login mode or password'.$end);
1441: return;
1.20 harris41 1442: }
1.27 matthew 1443: # Only allow authentification modification if the person has authority
1.101 albertel 1444: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 1445: $r->print('Modifying authentication: '.
1.31 matthew 1446: &Apache::lonnet::modifyuserauth(
1.101 albertel 1447: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 1448: $amode,$genpwd));
1.102 albertel 1449: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 1450: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 1451: } else {
1.27 matthew 1452: # Okay, this is a non-fatal error.
1.73 sakharuk 1453: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.');
1.27 matthew 1454: }
1.28 matthew 1455: }
1456: ##
1.101 albertel 1457: if (! $env{'form.makeuser'} ) {
1.28 matthew 1458: # Check for need to change
1459: my %userenv = &Apache::lonnet::get
1.134 raeburn 1460: ('environment',['firstname','middlename','lastname','generation',
1.160 raeburn 1461: 'permanentemail','portfolioquota','inststatus'],
1462: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 1463: my ($tmp) = keys(%userenv);
1464: if ($tmp =~ /^(con_lost|error)/i) {
1465: %userenv = ();
1466: }
1467: # Check to see if we need to change user information
1.160 raeburn 1468: foreach my $item ('firstname','middlename','lastname','generation','permanentemail') {
1.28 matthew 1469: # Strip leading and trailing whitespace
1.135 raeburn 1470: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.28 matthew 1471: }
1.149 raeburn 1472: my ($quotachanged,$namechanged,$oldportfolioquota,$newportfolioquota,
1473: $inststatus,$isdefault,$defquotatext);
1474: my ($defquota,$settingstatus) =
1475: &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
1.134 raeburn 1476: my %changeHash;
1.149 raeburn 1477: if ($userenv{'portfolioquota'} ne '') {
1.134 raeburn 1478: $oldportfolioquota = $userenv{'portfolioquota'};
1.149 raeburn 1479: if ($env{'form.customquota'} == 1) {
1480: if ($env{'form.portfolioquota'} eq '') {
1481: $newportfolioquota = 0;
1482: } else {
1483: $newportfolioquota = $env{'form.portfolioquota'};
1484: $newportfolioquota =~ s/[^\d\.]//g;
1485: }
1486: if ($newportfolioquota != $userenv{'portfolioquota'}) {
1487: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1.134 raeburn 1488: }
1.149 raeburn 1489: } else {
1490: $quotachanged = "a_admin('',\%changeHash);
1491: $newportfolioquota = $defquota;
1492: $isdefault = 1;
1.134 raeburn 1493: }
1494: } else {
1.149 raeburn 1495: $oldportfolioquota = $defquota;
1496: if ($env{'form.customquota'} == 1) {
1497: if ($env{'form.portfolioquota'} eq '') {
1498: $newportfolioquota = 0;
1499: } else {
1500: $newportfolioquota = $env{'form.portfolioquota'};
1501: $newportfolioquota =~ s/[^\d\.]//g;
1502: }
1503: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1504: } else {
1505: $newportfolioquota = $defquota;
1506: $isdefault = 1;
1507: }
1508: }
1509: if ($isdefault) {
1510: if ($settingstatus eq '') {
1511: $defquotatext = &mt('(default)');
1512: } else {
1513: my ($usertypes,$order) =
1514: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
1515: if ($usertypes->{$settingstatus} eq '') {
1516: $defquotatext = &mt('(default)');
1517: } else {
1518: $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
1519: }
1520: }
1.134 raeburn 1521: }
1.101 albertel 1522: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) &&
1523: ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
1524: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
1525: $env{'form.clastname'} ne $userenv{'lastname'} ||
1.160 raeburn 1526: $env{'form.cgeneration'} ne $userenv{'generation'} ||
1527: $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} )) {
1.134 raeburn 1528: $namechanged = 1;
1529: }
1530: if ($namechanged) {
1.28 matthew 1531: # Make the change
1.101 albertel 1532: $changeHash{'firstname'} = $env{'form.cfirstname'};
1533: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1534: $changeHash{'lastname'} = $env{'form.clastname'};
1535: $changeHash{'generation'} = $env{'form.cgeneration'};
1.174 raeburn 1536: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1.28 matthew 1537: my $putresult = &Apache::lonnet::put
1538: ('environment',\%changeHash,
1.101 albertel 1539: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 1540: if ($putresult eq 'ok') {
1541: # Tell the user we changed the name
1.73 sakharuk 1542: my %lt=&Apache::lonlocal::texthash(
1543: 'uic' => "User Information Changed",
1544: 'frst' => "first",
1545: 'mddl' => "middle",
1546: 'lst' => "last",
1547: 'gen' => "generation",
1.160 raeburn 1548: 'mail' => "permanent e-mail",
1.134 raeburn 1549: 'disk' => "disk space allocated to portfolio files",
1.73 sakharuk 1550: 'prvs' => "Previous",
1551: 'chto' => "Changed To"
1552: );
1.28 matthew 1553: $r->print(<<"END");
1554: <table border="2">
1.73 sakharuk 1555: <caption>$lt{'uic'}</caption>
1.28 matthew 1556: <tr><th> </th>
1.73 sakharuk 1557: <th>$lt{'frst'}</th>
1558: <th>$lt{'mddl'}</th>
1559: <th>$lt{'lst'}</th>
1.134 raeburn 1560: <th>$lt{'gen'}</th>
1.173 raeburn 1561: <th>$lt{'mail'}</th>
1.175 raeburn 1562: <th>$lt{'disk'}</th></tr>
1.73 sakharuk 1563: <tr><td>$lt{'prvs'}</td>
1.28 matthew 1564: <td>$userenv{'firstname'} </td>
1565: <td>$userenv{'middlename'} </td>
1566: <td>$userenv{'lastname'} </td>
1.134 raeburn 1567: <td>$userenv{'generation'} </td>
1.160 raeburn 1568: <td>$userenv{'permanentemail'} </td>
1.149 raeburn 1569: <td>$oldportfolioquota Mb</td>
1.134 raeburn 1570: </tr>
1.73 sakharuk 1571: <tr><td>$lt{'chto'}</td>
1.101 albertel 1572: <td>$env{'form.cfirstname'} </td>
1573: <td>$env{'form.cmiddlename'} </td>
1574: <td>$env{'form.clastname'} </td>
1.134 raeburn 1575: <td>$env{'form.cgeneration'} </td>
1.160 raeburn 1576: <td>$env{'form.cpermanentemail'} </td>
1.149 raeburn 1577: <td>$newportfolioquota Mb $defquotatext </td></tr>
1.28 matthew 1578: </table>
1579: END
1.149 raeburn 1580: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
1581: ($env{'form.ccuname'} eq $env{'user.name'})) {
1582: my %newenvhash;
1583: foreach my $key (keys(%changeHash)) {
1584: $newenvhash{'environment.'.$key} = $changeHash{$key};
1585: }
1586: &Apache::lonnet::appenv(%newenvhash);
1587: }
1.28 matthew 1588: } else { # error occurred
1.73 sakharuk 1589: $r->print("<h2>".&mt('Unable to successfully change environment for')." ".
1.101 albertel 1590: $env{'form.ccuname'}." ".&mt('in domain')." ".
1591: $env{'form.ccdomain'}."</h2>");
1.28 matthew 1592: }
1.101 albertel 1593: } else { # End of if ($env ... ) logic
1.134 raeburn 1594: my $putresult;
1595: if ($quotachanged) {
1596: $putresult = &Apache::lonnet::put
1597: ('environment',\%changeHash,
1598: $env{'form.ccdomain'},$env{'form.ccuname'});
1599: }
1.28 matthew 1600: # They did not want to change the users name but we can
1601: # still tell them what the name is
1.73 sakharuk 1602: my %lt=&Apache::lonlocal::texthash(
1.160 raeburn 1603: 'mail' => "Permanent e-mail",
1.134 raeburn 1604: 'disk' => "Disk space allocated to user's portfolio files",
1.73 sakharuk 1605: );
1.134 raeburn 1606: $r->print(<<"END");
1.164 albertel 1607: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}</h4>
1.160 raeburn 1608: <h4>$lt{'mail'}: $userenv{'permanentemail'}</h4>
1.28 matthew 1609: END
1.134 raeburn 1610: if ($putresult eq 'ok') {
1.149 raeburn 1611: if ($oldportfolioquota != $newportfolioquota) {
1612: $r->print('<h4>'.$lt{'disk'}.': '.$newportfolioquota.' Mb '.
1613: $defquotatext.'</h4>');
1614: &Apache::lonnet::appenv('environment.portfolioquota' => $changeHash{'portfolioquota'});
1.134 raeburn 1615: }
1616: }
1.28 matthew 1617: }
1.4 www 1618: }
1.27 matthew 1619: ##
1.4 www 1620: my $now=time;
1.73 sakharuk 1621: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 1622: foreach my $key (keys (%env)) {
1623: next if (! $env{$key});
1.27 matthew 1624: # Revoke roles
1.135 raeburn 1625: if ($key=~/^form\.rev/) {
1626: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 1627: # Revoke standard role
1.170 albertel 1628: my ($scope,$role) = ($1,$2);
1629: my $result =
1630: &Apache::lonnet::revokerole($env{'form.ccdomain'},
1631: $env{'form.ccuname'},
1632: $scope,$role);
1633: $r->print(&mt('Revoking [_1] in [_2]: [_3]',
1634: $role,$scope,'<b>'.$result.'</b>').'<br />');
1635: if ($role eq 'st') {
1636: my $result = &classlist_drop($scope,$env{'form.ccuname'},
1637: $env{'form.ccdomain'},$now);
1638: $r->print($result);
1.53 www 1639: }
1640: }
1.170 albertel 1641: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$ }s) {
1.64 www 1642: # Revoke custom role
1.113 raeburn 1643: $r->print(&mt('Revoking custom role:').
1.139 albertel 1644: ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
1.101 albertel 1645: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
1646: $env{'form.ccuname'},$1,$2,$3,$4).
1.102 albertel 1647: '</b><br />');
1.64 www 1648: }
1.135 raeburn 1649: } elsif ($key=~/^form\.del/) {
1650: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 1651: # Delete standard role
1.170 albertel 1652: my ($scope,$role) = ($1,$2);
1653: my $result =
1654: &Apache::lonnet::assignrole($env{'form.ccdomain'},
1655: $env{'form.ccuname'},
1656: $scope,$role,$now,0,1);
1657: $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
1658: '<b>'.$result.'</b>').'<br />');
1659: if ($role eq 'st') {
1660: my $result = &classlist_drop($scope,$env{'form.ccuname'},
1661: $env{'form.ccdomain'},$now);
1662: $r->print($result);
1.81 albertel 1663: }
1.116 raeburn 1664: }
1.139 albertel 1665: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 1666: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1667: # Delete custom role
1.170 albertel 1668: $r->print(&mt('Deleting custom role [_1] by [_2]:[_3] in [_4]',
1.116 raeburn 1669: $rolename,$rnam,$rdom,$url).': <b>'.
1670: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
1671: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
1672: 0,1).'</b><br />');
1673: }
1.135 raeburn 1674: } elsif ($key=~/^form\.ren/) {
1.101 albertel 1675: my $udom = $env{'form.ccdomain'};
1676: my $uname = $env{'form.ccuname'};
1.116 raeburn 1677: # Re-enable standard role
1.135 raeburn 1678: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 1679: my $url = $1;
1680: my $role = $2;
1681: my $logmsg;
1682: my $output;
1683: if ($role eq 'st') {
1.141 albertel 1684: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.129 albertel 1685: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.89 raeburn 1686: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
1687: $output = "Error: $result\n";
1688: } else {
1689: $output = &mt('Assigning').' '.$role.' in '.$url.
1690: &mt('starting').' '.localtime($now).
1691: ': <br />'.$logmsg.'<br />'.
1692: &mt('Add to classlist').': <b>ok</b><br />';
1693: }
1694: }
1695: } else {
1.101 albertel 1696: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1697: $env{'form.ccuname'},$url,$role,0,$now);
1.116 raeburn 1698: $output = &mt('Re-enabling [_1] in [_2]: <b>[_3]</b>',
1.89 raeburn 1699: $role,$url,$result).'<br />';
1.27 matthew 1700: }
1.89 raeburn 1701: $r->print($output);
1.113 raeburn 1702: }
1.116 raeburn 1703: # Re-enable custom role
1.139 albertel 1704: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 1705: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1706: my $result = &Apache::lonnet::assigncustomrole(
1707: $env{'form.ccdomain'}, $env{'form.ccuname'},
1708: $url,$rdom,$rnam,$rolename,0,$now);
1709: $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : <b>[_5]</b>',
1710: $rolename,$rnam,$rdom,$url,$result).'<br />');
1711: }
1.135 raeburn 1712: } elsif ($key=~/^form\.act/) {
1.101 albertel 1713: my $udom = $env{'form.ccdomain'};
1714: my $uname = $env{'form.ccuname'};
1.141 albertel 1715: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 1716: # Activate a custom role
1.83 albertel 1717: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
1718: my $url='/'.$one.'/'.$two;
1719: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 1720:
1.101 albertel 1721: my $start = ( $env{'form.start_'.$full} ?
1722: $env{'form.start_'.$full} :
1.88 raeburn 1723: $now );
1.101 albertel 1724: my $end = ( $env{'form.end_'.$full} ?
1725: $env{'form.end_'.$full} :
1.88 raeburn 1726: 0 );
1727:
1728: # split multiple sections
1729: my %sections = ();
1.101 albertel 1730: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 1731: if ($num_sections == 0) {
1.129 albertel 1732: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
1.88 raeburn 1733: } else {
1.114 albertel 1734: my %curr_groups =
1.117 raeburn 1735: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 1736: foreach my $sec (sort {$a cmp $b} keys %sections) {
1737: if (($sec eq 'none') || ($sec eq 'all') ||
1738: exists($curr_groups{$sec})) {
1739: $disallowed{$sec} = $url;
1740: next;
1741: }
1742: my $securl = $url.'/'.$sec;
1.129 albertel 1743: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
1.88 raeburn 1744: }
1745: }
1.142 raeburn 1746: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 1747: # Activate roles for sections with 3 id numbers
1748: # set start, end times, and the url for the class
1.83 albertel 1749: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 1750: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
1751: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 1752: $now );
1.101 albertel 1753: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1754: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 1755: 0 );
1.83 albertel 1756: my $url='/'.$one.'/'.$two;
1.88 raeburn 1757: my $type = 'three';
1758: # split multiple sections
1759: my %sections = ();
1.101 albertel 1760: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 1761: if ($num_sections == 0) {
1.129 albertel 1762: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 1763: } else {
1.114 albertel 1764: my %curr_groups =
1.117 raeburn 1765: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 1766: my $emptysec = 0;
1767: foreach my $sec (sort {$a cmp $b} keys %sections) {
1768: $sec =~ s/\W//g;
1.113 raeburn 1769: if ($sec ne '') {
1770: if (($sec eq 'none') || ($sec eq 'all') ||
1771: exists($curr_groups{$sec})) {
1772: $disallowed{$sec} = $url;
1773: next;
1774: }
1.88 raeburn 1775: my $securl = $url.'/'.$sec;
1.129 albertel 1776: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
1.88 raeburn 1777: } else {
1778: $emptysec = 1;
1779: }
1780: }
1781: if ($emptysec) {
1.129 albertel 1782: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 1783: }
1784: }
1.135 raeburn 1785: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 1786: # Activate roles for sections with two id numbers
1787: # set start, end times, and the url for the class
1.101 albertel 1788: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
1789: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 1790: $now );
1.101 albertel 1791: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1792: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 1793: 0 );
1794: my $url='/'.$1.'/';
1.88 raeburn 1795: # split multiple sections
1796: my %sections = ();
1.101 albertel 1797: my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);
1.88 raeburn 1798: if ($num_sections == 0) {
1.129 albertel 1799: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88 raeburn 1800: } else {
1801: my $emptysec = 0;
1802: foreach my $sec (sort {$a cmp $b} keys %sections) {
1803: if ($sec ne '') {
1804: my $securl = $url.'/'.$sec;
1.129 albertel 1805: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
1.88 raeburn 1806: } else {
1807: $emptysec = 1;
1808: }
1809: }
1810: if ($emptysec) {
1.129 albertel 1811: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
1.88 raeburn 1812: }
1813: }
1.64 www 1814: } else {
1.135 raeburn 1815: $r->print('<p>'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></p><br />');
1.64 www 1816: }
1.113 raeburn 1817: foreach my $key (sort(keys(%disallowed))) {
1818: if (($key eq 'none') || ($key eq 'all')) {
1819: $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
1820: } else {
1821: $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));
1822: }
1823: $r->print(' '.&mt('Please <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />');
1824: }
1825: }
1.101 albertel 1826: } # End of foreach (keys(%env))
1.75 www 1827: # Flush the course logs so reverse user roles immediately updated
1828: &Apache::lonnet::flushcourselogs();
1.163 albertel 1829: $r->print('<p><a href="/adm/createuser">'.&mt('Create/Modify Another User').'</a></p>');
1.160 raeburn 1830: $r->print('<form name="userupdate" method="post" />'."\n");
1831: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1832: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1833: }
1834: foreach my $item ('sortby','seluname','seludom') {
1835: if (exists($env{'form.'.$item})) {
1836: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1837: }
1838: }
1839: $r->print('<input type="hidden" name="phase" value="" />'."\n".
1.179 raeburn 1840: '<input type ="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 1841: '</form>');
1.110 albertel 1842: $r->print(&Apache::loncommon::end_page());
1.4 www 1843: }
1844:
1.170 albertel 1845: sub classlist_drop {
1846: my ($scope,$uname,$udom,$now) = @_;
1847: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
1848: my $cid=$cdom.'_'.$cnum;
1849: my $user = $uname.':'.$udom;
1850: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
1851: my $result =
1852: &Apache::lonnet::cput('classlist',
1853: { $user => $now },
1854: $env{'course.'.$cid.'.domain'},
1855: $env{'course.'.$cid.'.num'});
1856: return &mt('Drop from classlist: [_1]',
1857: '<b>'.$result.'</b>').'<br />';
1858: }
1859: }
1860:
1.171 albertel 1861: sub active_student_roles {
1.170 albertel 1862: my ($cnum,$cdom,$uname,$udom) = @_;
1863: my %roles =
1864: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
1865: ['future','active'],['st']);
1866: return exists($roles{"$cnum:$cdom:st"});
1867: }
1868:
1.149 raeburn 1869: sub quota_admin {
1870: my ($setquota,$changeHash) = @_;
1871: my $quotachanged;
1872: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1873: # Current user has quota modification privileges
1874: $quotachanged = 1;
1875: $changeHash->{'portfolioquota'} = $setquota;
1876: }
1877: return $quotachanged;
1878: }
1879:
1.88 raeburn 1880: sub build_roles {
1.89 raeburn 1881: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 1882: my $num_sections = 0;
1883: if ($sectionstr=~ /,/) {
1884: my @secnums = split/,/,$sectionstr;
1.89 raeburn 1885: if ($role eq 'st') {
1886: $secnums[0] =~ s/\W//g;
1887: $$sections{$secnums[0]} = 1;
1888: $num_sections = 1;
1889: } else {
1890: foreach my $sec (@secnums) {
1891: $sec =~ ~s/\W//g;
1.150 banghart 1892: if (!($sec eq "")) {
1.89 raeburn 1893: if (exists($$sections{$sec})) {
1894: $$sections{$sec} ++;
1895: } else {
1896: $$sections{$sec} = 1;
1897: $num_sections ++;
1898: }
1.88 raeburn 1899: }
1900: }
1901: }
1902: } else {
1903: $sectionstr=~s/\W//g;
1904: unless ($sectionstr eq '') {
1905: $$sections{$sectionstr} = 1;
1906: $num_sections ++;
1907: }
1908: }
1.129 albertel 1909:
1.88 raeburn 1910: return $num_sections;
1911: }
1912:
1.58 www 1913: # ========================================================== Custom Role Editor
1914:
1915: sub custom_role_editor {
1.160 raeburn 1916: my ($r) = @_;
1.101 albertel 1917: my $rolename=$env{'form.rolename'};
1.58 www 1918:
1.59 www 1919: if ($rolename eq 'make new role') {
1.101 albertel 1920: $rolename=$env{'form.newrolename'};
1.59 www 1921: }
1922:
1.63 www 1923: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 1924:
1.150 banghart 1925: if (!$rolename) {
1.58 www 1926: &print_username_entry_form($r);
1927: return;
1928: }
1.153 banghart 1929: # ------------------------------------------------------- What can be assigned?
1930: my %full=();
1931: my %courselevel=();
1932: my %courselevelcurrent=();
1.61 www 1933: my $syspriv='';
1934: my $dompriv='';
1935: my $coursepriv='';
1.153 banghart 1936: my $body_top;
1.150 banghart 1937: my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
1.59 www 1938: my ($rdummy,$roledef)=
1939: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 1940: # ------------------------------------------------------- Does this role exist?
1.153 banghart 1941: $body_top .= '<h2>';
1.59 www 1942: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 1943: $body_top .= &mt('Existing Role').' "';
1.61 www 1944: # ------------------------------------------------- Get current role privileges
1945: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 1946: } else {
1.153 banghart 1947: $body_top .= &mt('New Role').' "';
1.59 www 1948: $roledef='';
1949: }
1.153 banghart 1950: $body_top .= $rolename.'"</h2>';
1.135 raeburn 1951: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
1952: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 1953: if (!$restrict) { $restrict='F'; }
1.60 www 1954: $courselevel{$priv}=$restrict;
1.61 www 1955: if ($coursepriv=~/\:$priv/) {
1956: $courselevelcurrent{$priv}=1;
1957: }
1.60 www 1958: $full{$priv}=1;
1959: }
1960: my %domainlevel=();
1.61 www 1961: my %domainlevelcurrent=();
1.135 raeburn 1962: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
1963: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 1964: if (!$restrict) { $restrict='F'; }
1.60 www 1965: $domainlevel{$priv}=$restrict;
1.61 www 1966: if ($dompriv=~/\:$priv/) {
1967: $domainlevelcurrent{$priv}=1;
1968: }
1.60 www 1969: $full{$priv}=1;
1970: }
1.61 www 1971: my %systemlevel=();
1972: my %systemlevelcurrent=();
1.135 raeburn 1973: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1974: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 1975: if (!$restrict) { $restrict='F'; }
1.61 www 1976: $systemlevel{$priv}=$restrict;
1977: if ($syspriv=~/\:$priv/) {
1978: $systemlevelcurrent{$priv}=1;
1979: }
1980: $full{$priv}=1;
1981: }
1.160 raeburn 1982: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 1983: my $button_code = "\n";
1.153 banghart 1984: my $head_script = "\n";
1985: $head_script .= '<script type="text/javascript">'."\n";
1.154 banghart 1986: my @template_roles = ("cc","in","ta","ep","st");
1987: foreach my $role (@template_roles) {
1988: $head_script .= &make_script_template($role);
1989: $button_code .= &make_button_code($role);
1990: }
1.160 raeburn 1991: $head_script .= "\n".$jsback."\n".'</script>'."\n";
1.153 banghart 1992: $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
1.160 raeburn 1993: &Apache::lonhtmlcommon::add_breadcrumb
1994: ({href=>"javascript:backPage(document.form1,'','')",
1.166 albertel 1995: text=>"User modify/custom role edit",
1.160 raeburn 1996: faq=>282,bug=>'Instructor Interface',},
1997: {href=>"javascript:backPage(document.form1,'','')",
1998: text=>"Edit custom role",
1999: faq=>282,bug=>'Instructor Interface',});
2000: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
2001:
1.153 banghart 2002: $r->print($body_top);
1.73 sakharuk 2003: my %lt=&Apache::lonlocal::texthash(
2004: 'prv' => "Privilege",
1.131 raeburn 2005: 'crl' => "Course Level",
1.73 sakharuk 2006: 'dml' => "Domain Level",
1.150 banghart 2007: 'ssl' => "System Level");
1.152 banghart 2008: $r->print('Select a Template<br />');
1.154 banghart 2009: $r->print('<form action="">');
2010: $r->print($button_code);
2011: $r->print('</form>');
1.61 www 2012: $r->print(<<ENDCCF);
1.160 raeburn 2013: <form name="form1" method="post">
1.61 www 2014: <input type="hidden" name="phase" value="set_custom_roles" />
2015: <input type="hidden" name="rolename" value="$rolename" />
2016: ENDCCF
1.135 raeburn 2017: $r->print(&Apache::loncommon::start_data_table().
2018: &Apache::loncommon::start_data_table_header_row().
2019: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
2020: '</th><th>'.$lt{'ssl'}.'</th>'.
2021: &Apache::loncommon::end_data_table_header_row());
1.119 raeburn 2022: foreach my $priv (sort keys %full) {
2023: my $privtext = &Apache::lonnet::plaintext($priv);
1.135 raeburn 2024: $r->print(&Apache::loncommon::start_data_table_row().
2025: '<td>'.$privtext.'</td><td>'.
1.150 banghart 2026: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c" '.
1.119 raeburn 2027: ($courselevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2028: '</td><td>'.
1.150 banghart 2029: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d" '.
1.119 raeburn 2030: ($domainlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2031: '</td><td>'.
1.150 banghart 2032: ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s" '.
1.119 raeburn 2033: ($systemlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.135 raeburn 2034: '</td>'.
2035: &Apache::loncommon::end_data_table_row());
1.60 www 2036: }
1.135 raeburn 2037: $r->print(&Apache::loncommon::end_data_table().
1.160 raeburn 2038: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 2039: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 2040: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
2041: '<input type="submit" value="'.&mt('Define Role').'" /></form>'.
1.110 albertel 2042: &Apache::loncommon::end_page());
1.61 www 2043: }
1.153 banghart 2044: # --------------------------------------------------------
2045: sub make_script_template {
2046: my ($role) = @_;
2047: my %full_c=();
2048: my %full_d=();
2049: my %full_s=();
2050: my $return_script;
2051: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2052: my ($priv,$restrict)=split(/\&/,$item);
2053: $full_c{$priv}=1;
2054: }
2055: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2056: my ($priv,$restrict)=split(/\&/,$item);
2057: $full_d{$priv}=1;
2058: }
1.154 banghart 2059: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.153 banghart 2060: my ($priv,$restrict)=split(/\&/,$item);
2061: $full_s{$priv}=1;
2062: }
2063: $return_script .= 'function set_'.$role.'() {'."\n";
2064: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
2065: my %role_c;
1.155 banghart 2066: foreach my $priv (@temp) {
1.153 banghart 2067: my ($priv_item, $dummy) = split(/\&/,$priv);
2068: $role_c{$priv_item} = 1;
2069: }
2070: foreach my $priv_item (keys(%full_c)) {
2071: my ($priv, $dummy) = split(/\&/,$priv_item);
2072: if (exists($role_c{$priv})) {
2073: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
2074: } else {
2075: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
2076: }
2077: }
1.154 banghart 2078: my %role_d;
2079: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
2080: foreach my $priv(@temp) {
2081: my ($priv_item, $dummy) = split(/\&/,$priv);
2082: $role_d{$priv_item} = 1;
2083: }
2084: foreach my $priv_item (keys(%full_d)) {
2085: my ($priv, $dummy) = split(/\&/,$priv_item);
2086: if (exists($role_d{$priv})) {
2087: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
2088: } else {
2089: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
2090: }
2091: }
2092: my %role_s;
2093: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
2094: foreach my $priv(@temp) {
2095: my ($priv_item, $dummy) = split(/\&/,$priv);
2096: $role_s{$priv_item} = 1;
2097: }
2098: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 2099: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 2100: if (exists($role_s{$priv})) {
2101: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
2102: } else {
2103: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
2104: }
1.153 banghart 2105: }
2106: $return_script .= '}'."\n";
1.154 banghart 2107: return ($return_script);
2108: }
2109: # ----------------------------------------------------------
2110: sub make_button_code {
2111: my ($role) = @_;
2112: my $label = &Apache::lonnet::plaintext($role);
2113: my $button_code = '<input type="button" onClick="set_'.$role.'()" value="'.$label.'" />';
2114: return ($button_code);
1.153 banghart 2115: }
1.61 www 2116: # ---------------------------------------------------------- Call to definerole
2117: sub set_custom_role {
1.110 albertel 2118: my ($r) = @_;
1.61 www 2119:
1.101 albertel 2120: my $rolename=$env{'form.rolename'};
1.61 www 2121:
1.63 www 2122: $rolename=~s/[^A-Za-z0-9]//gs;
1.61 www 2123:
1.150 banghart 2124: if (!$rolename) {
1.61 www 2125: &print_username_entry_form($r);
2126: return;
2127: }
2128:
1.160 raeburn 2129: my ($jsback,$elements) = &crumb_utilities();
2130: my $jscript = '<script type="text/javascript">'.$jsback."\n".'</script>';
2131:
2132: $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
2133: &Apache::lonhtmlcommon::add_breadcrumb
2134: ({href=>"javascript:backPage(document.customresult,'','')",
1.166 albertel 2135: text=>"User modify/custom role edit",
1.160 raeburn 2136: faq=>282,bug=>'Instructor Interface',},
2137: {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
2138: text=>"Edit custom role",
2139: faq=>282,bug=>'Instructor Interface',},
2140: {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
2141: text=>"Result",
2142: faq=>282,bug=>'Instructor Interface',});
2143: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
2144:
1.61 www 2145: my ($rdummy,$roledef)=
1.110 albertel 2146: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
2147:
1.61 www 2148: # ------------------------------------------------------- Does this role exist?
1.160 raeburn 2149: $r->print('<h2>');
1.61 www 2150: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 2151: $r->print(&mt('Existing Role').' "');
1.61 www 2152: } else {
1.73 sakharuk 2153: $r->print(&mt('New Role').' "');
1.61 www 2154: $roledef='';
2155: }
2156: $r->print($rolename.'"</h2>');
2157: # ------------------------------------------------------- What can be assigned?
2158: my $sysrole='';
2159: my $domrole='';
2160: my $courole='';
2161:
1.135 raeburn 2162: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2163: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2164: if (!$restrict) { $restrict=''; }
2165: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 2166: $courole.=':'.$item;
1.61 www 2167: }
2168: }
2169:
1.135 raeburn 2170: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2171: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2172: if (!$restrict) { $restrict=''; }
2173: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 2174: $domrole.=':'.$item;
1.61 www 2175: }
2176: }
2177:
1.135 raeburn 2178: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2179: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2180: if (!$restrict) { $restrict=''; }
2181: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 2182: $sysrole.=':'.$item;
1.61 www 2183: }
2184: }
1.63 www 2185: $r->print('<br />Defining Role: '.
1.61 www 2186: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 2187: if ($env{'request.course.id'}) {
2188: my $url='/'.$env{'request.course.id'};
1.63 www 2189: $url=~s/\_/\//g;
1.73 sakharuk 2190: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 2191: &Apache::lonnet::assigncustomrole($env{'user.domain'},
2192: $env{'user.name'},
1.63 www 2193: $url,
1.101 albertel 2194: $env{'user.domain'},
2195: $env{'user.name'},
1.63 www 2196: $rolename));
2197: }
1.160 raeburn 2198: $r->print('<p><a href="/adm/createuser">Create another role, or Create/Modify a user.</a></p><form name="customresult" method="post">');
2199: $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
1.110 albertel 2200: $r->print(&Apache::loncommon::end_page());
1.58 www 2201: }
2202:
1.2 www 2203: # ================================================================ Main Handler
2204: sub handler {
2205: my $r = shift;
2206:
2207: if ($r->header_only) {
1.68 www 2208: &Apache::loncommon::content_type($r,'text/html');
1.2 www 2209: $r->send_http_header;
2210: return OK;
2211: }
2212:
1.101 albertel 2213: if ((&Apache::lonnet::allowed('cta',$env{'request.course.id'})) ||
2214: (&Apache::lonnet::allowed('cin',$env{'request.course.id'})) ||
2215: (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) ||
2216: (&Apache::lonnet::allowed('cep',$env{'request.course.id'})) ||
1.104 albertel 2217: (&authorpriv($env{'user.name'},$env{'request.role.domain'})) ||
1.101 albertel 2218: (&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) {
1.68 www 2219: &Apache::loncommon::content_type($r,'text/html');
1.2 www 2220: $r->send_http_header;
1.160 raeburn 2221: &Apache::lonhtmlcommon::clear_breadcrumbs();
2222:
2223: my $phase = $env{'form.phase'};
2224: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
2225:
2226: if (($phase eq 'get_user_info') || ($phase eq 'userpicked')) {
2227: my $srch;
2228: foreach my $item (@search) {
2229: $srch->{$item} = $env{'form.'.$item};
2230: }
2231: if ($env{'form.phase'} eq 'get_user_info') {
1.179 raeburn 2232: my ($currstate,$response,$forcenewuser,$results) =
1.160 raeburn 2233: &user_search_result($srch);
1.179 raeburn 2234: if ($currstate eq 'select') {
2235: &print_user_selection_page($r,$response,$srch,$results,'createuser',\@search);
2236: } elsif ($currstate eq 'modify') {
1.160 raeburn 2237: my ($ccuname,$ccdomain);
1.162 raeburn 2238: if (($srch->{'srchby'} eq 'uname') &&
2239: ($srch->{'srchtype'} eq 'exact')) {
1.160 raeburn 2240: $ccuname = $srch->{'srchterm'};
2241: $ccdomain= $srch->{'srchdomain'};
2242: } else {
2243: my @matchedunames = keys(%{$results});
2244: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
2245: }
2246: $ccuname =&LONCAPA::clean_username($ccuname);
2247: $ccdomain=&LONCAPA::clean_domain($ccdomain);
2248: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,
2249: $response);
1.179 raeburn 2250: } elsif ($currstate eq 'query') {
2251: &print_user_query_page($r,'createuser');
1.160 raeburn 2252: } else {
2253: &print_username_entry_form($r,$response,$srch,$forcenewuser);
2254: }
2255: } elsif ($env{'form.phase'} eq 'userpicked') {
2256: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
2257: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
2258: &print_user_modification_page($r,$ccuname,$ccdomain,$srch);
2259: }
1.101 albertel 2260: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.42 matthew 2261: &update_user_data($r);
1.101 albertel 2262: } elsif ($env{'form.phase'} eq 'selected_custom_edit') {
1.58 www 2263: &custom_role_editor($r);
1.101 albertel 2264: } elsif ($env{'form.phase'} eq 'set_custom_roles') {
1.61 www 2265: &set_custom_role($r);
1.160 raeburn 2266: } else {
2267: &print_username_entry_form($r);
1.2 www 2268: }
1.1 www 2269: } else {
1.101 albertel 2270: $env{'user.error.msg'}=
1.9 albertel 2271: "/adm/createuser:mau:0:0:Cannot modify user data";
1.1 www 2272: return HTTP_NOT_ACCEPTABLE;
2273: }
2274: return OK;
1.160 raeburn 2275: }
1.26 matthew 2276:
1.27 matthew 2277: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 2278: sub user_search_result {
2279: my ($srch) = @_;
2280: my %allhomes;
2281: my %inst_matches;
2282: my %srch_results;
1.181 raeburn 2283: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 2284: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 2285: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 2286: $response = &mt('Invalid search.');
2287: }
2288: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
2289: $response = &mt('Invalid search.');
2290: }
1.177 raeburn 2291: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 2292: $response = &mt('Invalid search.');
2293: }
2294: if ($srch->{'srchterm'} eq '') {
2295: $response = &mt('You must enter a search term.');
2296: }
1.183 raeburn 2297: if ($srch->{'srchterm'} =~ /^\s+$/) {
2298: $response = &mt('Your search term must contain more than just spaces.');
2299: }
1.160 raeburn 2300: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
2301: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 2302: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 2303: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
2304: }
2305: }
2306: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
2307: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 2308: if ($srch->{'srchby'} eq 'uname') {
2309: if ($srch->{'srchterm'} !~ /^$match_username$/) {
2310: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
2311: }
1.160 raeburn 2312: }
2313: }
1.180 raeburn 2314: if ($response ne '') {
2315: $response = '<span class="LC_warning">'.$response.'</span>';
2316: }
1.160 raeburn 2317: if ($srch->{'srchin'} eq 'instd') {
2318: my $instd_chk = &directorysrch_check($srch);
2319: if ($instd_chk ne 'ok') {
1.180 raeburn 2320: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
2321: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 2322: }
2323: }
2324: if ($response ne '') {
1.180 raeburn 2325: return ($currstate,$response);
1.160 raeburn 2326: }
2327: if ($srch->{'srchby'} eq 'uname') {
2328: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
2329: if ($env{'form.forcenew'}) {
2330: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
2331: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
2332: if ($uhome eq 'no_host') {
2333: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 2334: my $showdom = &display_domain_info($env{'request.role.domain'});
2335: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 2336: } else {
1.179 raeburn 2337: $currstate = 'modify';
1.160 raeburn 2338: }
2339: } else {
1.179 raeburn 2340: $currstate = 'modify';
1.160 raeburn 2341: }
2342: } else {
2343: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 2344: if ($srch->{'srchtype'} eq 'exact') {
2345: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
2346: if ($uhome eq 'no_host') {
1.179 raeburn 2347: ($currstate,$response,$forcenewuser) =
1.162 raeburn 2348: &build_search_response($srch,%srch_results);
2349: } else {
1.179 raeburn 2350: $currstate = 'modify';
1.162 raeburn 2351: }
2352: } else {
2353: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 2354: ($currstate,$response,$forcenewuser) =
1.160 raeburn 2355: &build_search_response($srch,%srch_results);
2356: }
2357: } else {
1.167 albertel 2358: my $courseusers = &get_courseusers();
1.162 raeburn 2359: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 2360: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 2361: $currstate = 'modify';
1.162 raeburn 2362: } else {
1.179 raeburn 2363: ($currstate,$response,$forcenewuser) =
1.162 raeburn 2364: &build_search_response($srch,%srch_results);
2365: }
1.160 raeburn 2366: } else {
1.167 albertel 2367: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 2368: my ($cuname,$cudomain) = split(/:/,$user);
2369: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 2370: my $matched = 0;
2371: if ($srch->{'srchtype'} eq 'begins') {
2372: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
2373: $matched = 1;
2374: }
2375: } else {
2376: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
2377: $matched = 1;
2378: }
2379: }
2380: if ($matched) {
1.167 albertel 2381: $srch_results{$user} =
2382: {&Apache::lonnet::get('environment',
2383: ['firstname',
2384: 'lastname',
2385: 'permanentemail'])};
1.162 raeburn 2386: }
2387: }
2388: }
1.179 raeburn 2389: ($currstate,$response,$forcenewuser) =
1.160 raeburn 2390: &build_search_response($srch,%srch_results);
2391: }
2392: }
2393: }
2394: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 2395: $currstate = 'query';
1.160 raeburn 2396: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 2397: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
2398: if ($dirsrchres eq 'ok') {
2399: ($currstate,$response,$forcenewuser) =
2400: &build_search_response($srch,%srch_results);
2401: } else {
2402: my $showdom = &display_domain_info($srch->{'srchdomain'});
2403: $response = '<span class="LC_warning">'.
2404: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
2405: '</span><br />'.
2406: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
2407: '<br /><br />';
2408: }
1.160 raeburn 2409: }
2410: } else {
2411: if ($srch->{'srchin'} eq 'dom') {
2412: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 2413: ($currstate,$response,$forcenewuser) =
1.160 raeburn 2414: &build_search_response($srch,%srch_results);
2415: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 2416: my $courseusers = &get_courseusers();
2417: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 2418: my ($uname,$udom) = split(/:/,$user);
2419: my %names = &Apache::loncommon::getnames($uname,$udom);
2420: my %emails = &Apache::loncommon::getemails($uname,$udom);
2421: if ($srch->{'srchby'} eq 'lastname') {
2422: if ((($srch->{'srchtype'} eq 'exact') &&
2423: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 2424: (($srch->{'srchtype'} eq 'begins') &&
2425: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 2426: (($srch->{'srchtype'} eq 'contains') &&
2427: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
2428: $srch_results{$user} = {firstname => $names{'firstname'},
2429: lastname => $names{'lastname'},
2430: permanentemail => $emails{'permanentemail'},
2431: };
2432: }
2433: } elsif ($srch->{'srchby'} eq 'lastfirst') {
2434: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 2435: $srchlast =~ s/\s+$//;
2436: $srchfirst =~ s/^\s+//;
1.160 raeburn 2437: if ($srch->{'srchtype'} eq 'exact') {
2438: if (($names{'lastname'} eq $srchlast) &&
2439: ($names{'firstname'} eq $srchfirst)) {
2440: $srch_results{$user} = {firstname => $names{'firstname'},
2441: lastname => $names{'lastname'},
2442: permanentemail => $emails{'permanentemail'},
2443:
2444: };
2445: }
1.177 raeburn 2446: } elsif ($srch->{'srchtype'} eq 'begins') {
2447: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
2448: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
2449: $srch_results{$user} = {firstname => $names{'firstname'},
2450: lastname => $names{'lastname'},
2451: permanentemail => $emails{'permanentemail'},
2452: };
2453: }
2454: } else {
1.160 raeburn 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: }
2463: }
2464: }
1.179 raeburn 2465: ($currstate,$response,$forcenewuser) =
1.160 raeburn 2466: &build_search_response($srch,%srch_results);
2467: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 2468: $currstate = 'query';
1.160 raeburn 2469: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 2470: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
2471: if ($dirsrchres eq 'ok') {
2472: ($currstate,$response,$forcenewuser) =
2473: &build_search_response($srch,%srch_results);
2474: } else {
2475: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
2476: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
2477: '</span><br />'.
2478: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
2479: '<br /><br />';
2480: }
1.160 raeburn 2481: }
2482: }
1.179 raeburn 2483: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 2484: }
2485:
2486: sub directorysrch_check {
2487: my ($srch) = @_;
2488: my $can_search = 0;
2489: my $response;
2490: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
2491: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 2492: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 2493: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
2494: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 2495: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 2496: }
2497: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
2498: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 2499: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 2500: }
2501: my @usertypes = split(/:/,$env{'environment.inststatus'});
2502: if (!@usertypes) {
2503: push(@usertypes,'default');
2504: }
2505: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
2506: foreach my $type (@usertypes) {
2507: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
2508: $can_search = 1;
2509: last;
2510: }
2511: }
2512: }
2513: if (!$can_search) {
2514: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
2515: my @longtypes;
2516: foreach my $item (@usertypes) {
2517: push (@longtypes,$insttypes->{$item});
2518: }
2519: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 2520: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.160 raeburn 2521: }
2522: } else {
2523: $can_search = 1;
2524: }
2525: } else {
1.180 raeburn 2526: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 2527: }
2528: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 2529: uname => 'username',
1.160 raeburn 2530: lastfirst => 'last name, first name',
1.167 albertel 2531: lastname => 'last name',
1.172 raeburn 2532: contains => 'contains',
1.178 raeburn 2533: exact => 'as exact match to',
2534: begins => 'begins with',
1.160 raeburn 2535: );
2536: if ($can_search) {
2537: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
2538: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 2539: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 2540: }
2541: } else {
1.180 raeburn 2542: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 2543: }
2544: }
2545: if ($can_search) {
1.178 raeburn 2546: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
2547: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
2548: return 'ok';
2549: } else {
1.180 raeburn 2550: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 2551: }
2552: } else {
2553: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
2554: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
2555: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
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: }
1.160 raeburn 2560: }
2561: }
2562: }
2563:
2564: sub get_courseusers {
2565: my %advhash;
1.167 albertel 2566: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 2567: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
2568: foreach my $role (sort(keys(%coursepersonnel))) {
2569: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 2570: if (!exists($classlist->{$user})) {
2571: $classlist->{$user} = [];
2572: }
1.160 raeburn 2573: }
2574: }
1.167 albertel 2575: return $classlist;
1.160 raeburn 2576: }
2577:
2578: sub build_search_response {
2579: my ($srch,%srch_results) = @_;
1.179 raeburn 2580: my ($currstate,$response,$forcenewuser);
1.160 raeburn 2581: my %names = (
2582: 'uname' => 'username',
2583: 'lastname' => 'last name',
2584: 'lastfirst' => 'last name, first name',
2585: 'crs' => 'this course',
1.180 raeburn 2586: 'dom' => 'LON-CAPA domain: ',
2587: 'instd' => 'the institutional directory for domain: ',
1.160 raeburn 2588: );
2589:
2590: my %single = (
1.180 raeburn 2591: begins => 'A match',
1.160 raeburn 2592: contains => 'A match',
1.180 raeburn 2593: exact => 'An exact match',
1.160 raeburn 2594: );
2595: my %nomatch = (
1.180 raeburn 2596: begins => 'No match',
1.160 raeburn 2597: contains => 'No match',
1.180 raeburn 2598: exact => 'No exact match',
1.160 raeburn 2599: );
2600: if (keys(%srch_results) > 1) {
1.179 raeburn 2601: $currstate = 'select';
1.160 raeburn 2602: } else {
2603: if (keys(%srch_results) == 1) {
1.179 raeburn 2604: $currstate = 'modify';
1.180 raeburn 2605: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
2606: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
2607: $response .= &display_domain_info($srch->{'srchdomain'});
2608: }
1.160 raeburn 2609: } else {
1.180 raeburn 2610: $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
2611: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
2612: $response .= &display_domain_info($srch->{'srchdomain'});
2613: }
2614: $response .= '</span>';
1.160 raeburn 2615: if ($srch->{'srchin'} ne 'alc') {
2616: $forcenewuser = 1;
2617: my $cansrchinst = 0;
2618: if ($srch->{'srchdomain'}) {
2619: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
2620: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
2621: if ($domconfig{'directorysrch'}{'available'}) {
2622: $cansrchinst = 1;
2623: }
2624: }
2625: }
1.180 raeburn 2626: if ((($srch->{'srchby'} eq 'lastfirst') ||
2627: ($srch->{'srchby'} eq 'lastname')) &&
2628: ($srch->{'srchin'} eq 'dom')) {
2629: if ($cansrchinst) {
2630: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 2631: }
2632: }
1.180 raeburn 2633: if ($srch->{'srchin'} eq 'crs') {
2634: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
2635: }
2636: }
2637: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {
1.182 raeburn 2638: my $showdom = &display_domain_info($env{'request.role.domain'});
2639: $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 2640: }
2641: }
2642: }
1.179 raeburn 2643: return ($currstate,$response,$forcenewuser);
1.160 raeburn 2644: }
2645:
1.180 raeburn 2646: sub display_domain_info {
2647: my ($dom) = @_;
2648: my $output = $dom;
2649: if ($dom ne '') {
2650: my $domdesc = &Apache::lonnet::domain($dom,'description');
2651: if ($domdesc ne '') {
2652: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
2653: }
2654: }
2655: return $output;
2656: }
2657:
1.160 raeburn 2658: sub crumb_utilities {
2659: my %elements = (
2660: crtuser => {
2661: srchterm => 'text',
1.172 raeburn 2662: srchin => 'selectbox',
1.160 raeburn 2663: srchby => 'selectbox',
2664: srchtype => 'selectbox',
2665: srchdomain => 'selectbox',
2666: },
2667: docustom => {
2668: rolename => 'selectbox',
2669: newrolename => 'textbox',
2670: },
1.179 raeburn 2671: studentform => {
2672: srchterm => 'text',
2673: srchin => 'selectbox',
2674: srchby => 'selectbox',
2675: srchtype => 'selectbox',
2676: srchdomain => 'selectbox',
2677: },
1.160 raeburn 2678: );
2679:
2680: my $jsback .= qq|
2681: function backPage(formname,prevphase,prevstate) {
2682: formname.phase.value = prevphase;
1.179 raeburn 2683: formname.currstate.value = prevstate;
1.160 raeburn 2684: formname.submit();
2685: }
2686: |;
2687: return ($jsback,\%elements);
2688: }
2689:
1.26 matthew 2690: sub course_level_table {
1.89 raeburn 2691: my (%inccourses) = @_;
1.26 matthew 2692: my $table = '';
1.62 www 2693: # Custom Roles?
2694:
2695: my %customroles=&my_custom_roles();
1.89 raeburn 2696: my %lt=&Apache::lonlocal::texthash(
2697: 'exs' => "Existing sections",
2698: 'new' => "Define new section",
2699: 'ssd' => "Set Start Date",
2700: 'sed' => "Set End Date",
1.131 raeburn 2701: 'crl' => "Course Level",
1.89 raeburn 2702: 'act' => "Activate",
2703: 'rol' => "Role",
2704: 'ext' => "Extent",
1.113 raeburn 2705: 'grs' => "Section",
1.89 raeburn 2706: 'sta' => "Start",
2707: 'end' => "End"
2708: );
1.62 www 2709:
1.135 raeburn 2710: foreach my $protectedcourse (sort( keys(%inccourses))) {
2711: my $thiscourse=$protectedcourse;
1.26 matthew 2712: $thiscourse=~s:_:/:g;
2713: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
2714: my $area=$coursedata{'description'};
1.119 raeburn 2715: my $type=$coursedata{'type'};
1.135 raeburn 2716: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 2717: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 2718: my %sections_count;
1.101 albertel 2719: if (defined($env{'request.course.id'})) {
2720: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 2721: %sections_count =
2722: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 2723: }
2724: }
1.135 raeburn 2725: foreach my $role ('st','ta','ep','in','cc') {
2726: if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
2727: my $plrole=&Apache::lonnet::plaintext($role);
1.136 raeburn 2728: $table .= &Apache::loncommon::start_data_table_row().
1.157 albertel 2729: '<td><input type="checkbox" name="act_'.$protectedcourse.'_'.$role.'" /></td>
1.136 raeburn 2730: <td>'.$plrole.'</td>
2731: <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.135 raeburn 2732: if ($role ne 'cc') {
1.115 albertel 2733: if (%sections_count) {
1.135 raeburn 2734: my $currsec = &course_sections(\%sections_count,$protectedcourse.'_'.$role);
1.89 raeburn 2735: $table .=
1.137 raeburn 2736: '<td><table class="LC_createuser">'.
2737: '<tr class="LC_section_row">
2738: <td valign="top">'.$lt{'exs'}.'<br />'.
1.89 raeburn 2739: $currsec.'</td>'.
2740: '<td> </td>'.
2741: '<td valign="top"> '.$lt{'new'}.'<br />'.
1.157 albertel 2742: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.'" value="" />'.
1.89 raeburn 2743: '<input type="hidden" '.
1.157 albertel 2744: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'.
1.89 raeburn 2745: '</tr></table></td>';
2746: } else {
2747: $table .= '<td><input type="text" size="10" '.
1.157 albertel 2748: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>';
1.89 raeburn 2749: }
1.26 matthew 2750: } else {
1.89 raeburn 2751: $table .= '<td> </td>';
1.26 matthew 2752: }
2753: $table .= <<ENDTIMEENTRY;
1.169 albertel 2754: <td><input type="hidden" name="start_$protectedcourse\_$role" value='' />
1.26 matthew 2755: <a href=
1.135 raeburn 2756: "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 2757: <td><input type="hidden" name="end_$protectedcourse\_$role" value='' />
1.26 matthew 2758: <a href=
1.135 raeburn 2759: "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 2760: ENDTIMEENTRY
1.136 raeburn 2761: $table.= &Apache::loncommon::end_data_table_row();
1.26 matthew 2762: }
2763: }
1.135 raeburn 2764: foreach my $cust (sort keys %customroles) {
1.65 www 2765: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.135 raeburn 2766: my $plrole=$cust;
1.101 albertel 2767: my $customrole=$protectedcourse.'_cr_cr_'.$env{'user.domain'}.
2768: '_'.$env{'user.name'}.'_'.$plrole;
1.136 raeburn 2769: $table .= &Apache::loncommon::start_data_table_row().
1.157 albertel 2770: '<td><input type="checkbox" name="act_'.$customrole.'" /></td>
1.136 raeburn 2771: <td>'.$plrole.'</td>
2772: <td>'.$area.'</td>'."\n";
1.115 albertel 2773: if (%sections_count) {
2774: my $currsec = &course_sections(\%sections_count,$customrole);
1.89 raeburn 2775: $table.=
2776: '<td><table border="0" cellspacing="0" cellpadding="0">'.
2777: '<tr><td valign="top">'.$lt{'exs'}.'<br />'.
2778: $currsec.'</td>'.
2779: '<td> </td>'.
2780: '<td valign="top"> '.$lt{'new'}.'<br />'.
2781: '<input type="text" name="newsec_'.$customrole.'" value="" /></td>'.
2782: '<input type="hidden" '.
1.157 albertel 2783: 'name="sec_'.$customrole.'" /></td>'.
1.89 raeburn 2784: '</tr></table></td>';
2785: } else {
2786: $table .= '<td><input type="text" size="10" '.
1.157 albertel 2787: 'name="sec_'.$customrole.'" /></td>';
1.89 raeburn 2788: }
2789: $table .= <<ENDENTRY;
1.169 albertel 2790: <td><input type="hidden" name="start_$customrole" value='' />
1.62 www 2791: <a href=
1.73 sakharuk 2792: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 2793: <td><input type="hidden" name="end_$customrole" value='' />
1.62 www 2794: <a href=
1.136 raeburn 2795: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">$lt{'sed'}</a></td>
1.62 www 2796: ENDENTRY
1.136 raeburn 2797: $table .= &Apache::loncommon::end_data_table_row();
1.65 www 2798: }
1.62 www 2799: }
1.26 matthew 2800: }
2801: return '' if ($table eq ''); # return nothing if there is nothing
2802: # in the table
1.136 raeburn 2803: my $result = '
2804: <h4>'.$lt{'crl'}.'</h4>'.
2805: &Apache::loncommon::start_data_table().
2806: &Apache::loncommon::start_data_table_header_row().
2807: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
2808: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
2809: &Apache::loncommon::end_data_table_header_row().
2810: $table.
2811: &Apache::loncommon::end_data_table();
1.26 matthew 2812: return $result;
2813: }
1.88 raeburn 2814:
1.89 raeburn 2815: sub course_sections {
1.115 albertel 2816: my ($sections_count,$role) = @_;
1.89 raeburn 2817: my $output = '';
2818: my @sections = (sort {$a <=> $b} keys %{$sections_count});
1.115 albertel 2819: if (scalar(@sections) == 1) {
1.92 raeburn 2820: $output = '<select name="currsec_'.$role.'" >'."\n".
2821: ' <option value="">Select</option>'."\n".
1.93 raeburn 2822: ' <option value="">No section</option>'."\n".
1.92 raeburn 2823: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
2824: } else {
2825: $output = '<select name="currsec_'.$role.'" ';
2826: my $multiple = 4;
1.115 albertel 2827: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1.145 raeburn 2828: $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
1.135 raeburn 2829: foreach my $sec (@sections) {
2830: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
1.92 raeburn 2831: }
1.89 raeburn 2832: }
2833: $output .= '</select>';
2834: return $output;
2835: }
2836:
1.88 raeburn 2837: sub course_level_dc {
2838: my ($dcdom) = @_;
2839: my %customroles=&my_custom_roles();
2840: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
2841: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 2842: '<input type="hidden" name="dccourse" value="" />';
1.88 raeburn 2843: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.131 raeburn 2844: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
2845: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
1.88 raeburn 2846: my %lt=&Apache::lonlocal::texthash(
2847: 'rol' => "Role",
1.113 raeburn 2848: 'grs' => "Section",
1.88 raeburn 2849: 'exs' => "Existing sections",
2850: 'new' => "Define new section",
2851: 'sta' => "Start",
2852: 'end' => "End",
2853: 'ssd' => "Set Start Date",
2854: 'sed' => "Set End Date"
2855: );
1.131 raeburn 2856: my $header = '<h4>'.&mt('Course Level').'</h4>'.
1.136 raeburn 2857: &Apache::loncommon::start_data_table().
2858: &Apache::loncommon::start_data_table_header_row().
1.143 raeburn 2859: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 2860: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 2861: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.131 raeburn 2862: '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1.88 raeburn 2863: '<td><select name="role">'."\n";
1.135 raeburn 2864: foreach my $role ('st','ta','ep','in','cc') {
2865: my $plrole=&Apache::lonnet::plaintext($role);
2866: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 2867: }
2868: if ( keys %customroles > 0) {
1.135 raeburn 2869: foreach my $cust (sort keys %customroles) {
1.101 albertel 2870: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 2871: '_'.$env{'user.name'}.'_'.$cust;
2872: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 2873: }
2874: }
2875: $otheritems .= '</select></td><td>'.
2876: '<table border="0" cellspacing="0" cellpadding="0">'.
2877: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
2878: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
2879: '<td> </td>'.
2880: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 2881: '<input type="text" name="newsec" value="" />'.
2882: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 2883: '</tr></table></td>';
2884: $otheritems .= <<ENDTIMEENTRY;
1.169 albertel 2885: <td><input type="hidden" name="start" value='' />
1.88 raeburn 2886: <a href=
2887: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 2888: <td><input type="hidden" name="end" value='' />
1.88 raeburn 2889: <a href=
2890: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
2891: ENDTIMEENTRY
1.136 raeburn 2892: $otheritems .= &Apache::loncommon::end_data_table_row().
2893: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 2894: return $cb_jscript.$header.$hiddenitems.$otheritems;
2895: }
2896:
1.27 matthew 2897: #---------------------------------------------- end functions for &phase_two
1.29 matthew 2898:
2899: #--------------------------------- functions for &phase_two and &phase_three
2900:
2901: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 2902:
2903: 1;
2904: __END__
1.2 www 2905:
2906:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>