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