Annotation of loncom/interface/loncreateuser.pm, revision 1.233
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.233 ! raeburn 4: # $Id: loncreateuser.pm,v 1.232 2008/01/20 01:40:37 raeburn Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
36: Apache::loncreateuser - handler to create users and custom roles
37:
38: =head1 SYNOPSIS
39:
40: Apache::loncreateuser provides an Apache handler for creating users,
41: editing their login parameters, roles, and removing roles, and
42: also creating and assigning custom roles.
43:
44: =head1 OVERVIEW
45:
46: =head2 Custom Roles
47:
48: In LON-CAPA, roles are actually collections of privileges. "Teaching
49: Assistant", "Course Coordinator", and other such roles are really just
50: collection of privileges that are useful in many circumstances.
51:
52: Creating custom roles can be done by the Domain Coordinator through
53: the Create User functionality. That screen will show all privileges
54: that can be assigned to users. For a complete list of privileges,
55: please see C</home/httpd/lonTabs/rolesplain.tab>.
56:
57: Custom role definitions are stored in the C<roles.db> file of the role
58: author.
59:
60: =cut
1.1 www 61:
62: use strict;
63: use Apache::Constants qw(:common :http);
64: use Apache::lonnet;
1.54 bowersj2 65: use Apache::loncommon;
1.68 www 66: use Apache::lonlocal;
1.117 raeburn 67: use Apache::longroup;
1.190 raeburn 68: use Apache::lonuserutils;
1.139 albertel 69: use LONCAPA qw(:DEFAULT :match);
1.1 www 70:
1.20 harris41 71: my $loginscript; # piece of javascript used in two separate instances
72: my $authformnop;
73: my $authformkrb;
74: my $authformint;
75: my $authformfsys;
76: my $authformloc;
77:
1.94 matthew 78: sub initialize_authen_forms {
1.227 raeburn 79: my ($dom,$formname,$curr_authtype,$mode) = @_;
80: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
81: my %param = ( formname => $formname,
1.187 raeburn 82: kerb_def_dom => $krbdefdom,
1.227 raeburn 83: kerb_def_auth => $krbdef,
1.187 raeburn 84: domain => $dom,
85: );
1.188 raeburn 86: my %abv_auth = &auth_abbrev();
1.227 raeburn 87: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 88: my $long_auth = $1;
1.227 raeburn 89: my $curr_autharg = $2;
1.188 raeburn 90: my %abv_auth = &auth_abbrev();
91: $param{'curr_authtype'} = $abv_auth{$long_auth};
92: if ($long_auth =~ /^krb(4|5)$/) {
93: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 94: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 95: }
1.205 raeburn 96: if ($mode eq 'modifyuser') {
97: $param{'mode'} = $mode;
98: }
1.187 raeburn 99: }
1.227 raeburn 100: $loginscript = &Apache::loncommon::authform_header(%param);
101: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 102: $authformnop = &Apache::loncommon::authform_nochange(%param);
103: $authformint = &Apache::loncommon::authform_internal(%param);
104: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
105: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 106: }
107:
1.188 raeburn 108: sub auth_abbrev {
109: my %abv_auth = (
110: krb4 => 'krb',
111: internal => 'int',
112: localuth => 'loc',
113: unix => 'fsys',
114: );
115: return %abv_auth;
116: }
1.43 www 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 '') {
1.230 bisitz 159: $defaultinfo = &mt('For this user, the default quota would be [_1]'
160: .' Mb.',$defquota);
1.149 raeburn 161: } else {
1.231 raeburn 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);
1.149 raeburn 165: }
166: } else {
167: if ($longinsttype eq '') {
1.230 bisitz 168: $defaultinfo = &mt('For this user, the default quota is [_1]'
169: .' Mb.',$defquota);
1.149 raeburn 170: } else {
1.231 raeburn 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);
1.149 raeburn 174: }
175: }
176: my $output = $quota_javascript.
177: '<h3>'.$lt{'disk'}.'</h3>'.
1.188 raeburn 178: &Apache::loncommon::start_data_table().
179: &Apache::loncommon::start_data_table_row().
180: '<td>'.$lt{'cuqu'}.': '.$currquota.' Mb. '.
181: $defaultinfo.'</td>'.
182: &Apache::loncommon::end_data_table_row().
183: &Apache::loncommon::start_data_table_row().
184: '<td><span class="LC_nobreak">'.$lt{'chqu'}.
1.149 raeburn 185: ': <label>'.
186: '<input type="radio" name="customquota" value="0" '.
187: $custom_off.' onchange="javascript:quota_changes('."'custom'".')"
188: />'.$lt{'defa'}.' ('.$defquota.' Mb).</label> '.
189: ' <label><input type="radio" name="customquota" value="1" '.
190: $custom_on.' onchange="javascript:quota_changes('."'custom'".')" />'.
191: $lt{'cust'}.':</label> '.
1.134 raeburn 192: '<input type="text" name="portfolioquota" size ="5" value="'.
1.149 raeburn 193: $showquota.'" onfocus="javascript:quota_changes('."'quota'".')" '.
1.188 raeburn 194: '/> Mb</span></td>'.
195: &Apache::loncommon::end_data_table_row().
196: &Apache::loncommon::end_data_table();
1.134 raeburn 197: return $output;
198: }
199:
1.2 www 200: # =================================================================== Phase one
1.1 www 201:
1.42 matthew 202: sub print_username_entry_form {
1.207 raeburn 203: my ($r,$context,$response,$srch,$forcenewuser) = @_;
1.101 albertel 204: my $defdom=$env{'request.role.domain'};
1.160 raeburn 205: my $formtoset = 'crtuser';
206: if (exists($env{'form.startrolename'})) {
207: $formtoset = 'docustom';
208: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 209: } elsif ($env{'form.origform'} eq 'crtusername') {
210: $formtoset = $env{'form.origform'};
1.160 raeburn 211: }
212:
213: my ($jsback,$elements) = &crumb_utilities();
214:
215: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 216: '<script type="text/javascript">'."\n".
1.160 raeburn 217: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset}).
1.162 raeburn 218: '</script>'."\n";
1.160 raeburn 219:
220: my %loaditems = (
221: 'onload' => "javascript:setFormElements(document.$formtoset)",
222: );
1.229 raeburn 223: my %breadcrumb_text = &singleuser_breadcrumb();
1.110 albertel 224: my $start_page =
1.190 raeburn 225: &Apache::loncommon::start_page('User Management',
1.160 raeburn 226: $jscript,{'add_entries' => \%loaditems,});
1.214 raeburn 227: if ($env{'form.action'} eq 'custom') {
228: &Apache::lonhtmlcommon::add_breadcrumb
229: ({href=>"javascript:backPage(document.crtuser)",
230: text=>"Pick custom role",});
231: } else {
1.190 raeburn 232: &Apache::lonhtmlcommon::add_breadcrumb
233: ({href=>"javascript:backPage(document.crtuser)",
1.229 raeburn 234: text=>$breadcrumb_text{'search'},
1.190 raeburn 235: faq=>282,bug=>'Instructor Interface',});
236: }
1.224 raeburn 237: my $helpitem = 'Course_Change_Privileges';
238: if ($env{'form.action'} eq 'custom') {
239: $helpitem = 'Course_Editing_Custom_Roles';
240: } elsif ($env{'form.action'} eq 'singlestudent') {
241: $helpitem = 'Course_Add_Student';
242: }
243: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
244: $helpitem);
1.190 raeburn 245: my %existingroles=&Apache::lonuserutils::my_custom_roles();
1.59 www 246: my $choice=&Apache::loncommon::select_form('make new role','rolename',
247: ('make new role' => 'Generate new role ...',%existingroles));
1.71 sakharuk 248: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 249: 'srst' => 'Search for a user and enroll as a student',
250: 'srad' => 'Search for a user and modify/add user information or roles',
1.71 sakharuk 251: 'usr' => "Username",
252: 'dom' => "Domain",
253: 'ecrp' => "Edit Custom Role Privileges",
1.72 sakharuk 254: 'nr' => "Name of Role",
1.160 raeburn 255: 'cre' => "Custom Role Editor",
1.71 sakharuk 256: );
1.190 raeburn 257: $r->print($start_page."\n".$crumbs);
1.214 raeburn 258: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 259: if (&Apache::lonnet::allowed('mcr','/')) {
260: $r->print(<<ENDCUSTOM);
1.58 www 261: <form action="/adm/createuser" method="post" name="docustom">
1.190 raeburn 262: <input type="hidden" name="action" value="$env{'form.action'}" />
1.157 albertel 263: <input type="hidden" name="phase" value="selected_custom_edit" />
1.224 raeburn 264: <h3>$lt{'ecrp'}</h3>
1.72 sakharuk 265: $lt{'nr'}: $choice <input type="text" size="15" name="newrolename" /><br />
1.71 sakharuk 266: <input name="customeditor" type="submit" value="$lt{'cre'}" />
1.107 www 267: </form>
1.106 www 268: ENDCUSTOM
1.190 raeburn 269: }
1.213 raeburn 270: } else {
1.229 raeburn 271: my $actiontext = $lt{'srad'};
1.213 raeburn 272: if ($env{'form.action'} eq 'singlestudent') {
1.229 raeburn 273: $actiontext = $lt{'srst'};
1.213 raeburn 274: }
275: $r->print("
1.229 raeburn 276: <h3>$actiontext</h3>");
1.213 raeburn 277: if ($env{'form.origform'} ne 'crtusername') {
278: $r->print("\n".$response);
279: }
280: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response));
1.107 www 281: }
1.110 albertel 282: $r->print(&Apache::loncommon::end_page());
283: }
284:
1.160 raeburn 285: sub entry_form {
1.214 raeburn 286: my ($dom,$srch,$forcenewuser,$context,$responsemsg) = @_;
1.207 raeburn 287: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
1.229 raeburn 288: my ($usertype,$inexact);
1.214 raeburn 289: if (ref($srch) eq 'HASH') {
290: if (($srch->{'srchin'} eq 'dom') &&
291: ($srch->{'srchby'} eq 'uname') &&
292: ($srch->{'srchtype'} eq 'exact') &&
293: ($srch->{'srchdomain'} ne '') &&
294: ($srch->{'srchterm'} ne '')) {
295: my ($rules,$ruleorder) =
296: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
297: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules);
1.229 raeburn 298: } else {
299: $inexact = 1;
1.214 raeburn 300: }
1.207 raeburn 301: }
1.214 raeburn 302: my $cancreate =
303: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.160 raeburn 304: my $userpicker =
1.179 raeburn 305: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.214 raeburn 306: 'document.crtuser',$cancreate,$usertype);
1.160 raeburn 307: my $srchbutton = &mt('Search');
1.229 raeburn 308: if ($env{'form.action'} eq 'singlestudent') {
309: $srchbutton = &mt('Search and Enroll');
310: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
311: $srchbutton = &mt('Search or Add New User');
312: }
1.207 raeburn 313: my $output = <<"ENDBLOCK";
1.160 raeburn 314: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 315: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 316: <input type="hidden" name="phase" value="get_user_info" />
317: $userpicker
1.179 raeburn 318: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 319: </form>
1.207 raeburn 320: ENDBLOCK
1.229 raeburn 321: if ($env{'form.phase'} eq '') {
1.207 raeburn 322: my $defdom=$env{'request.role.domain'};
323: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
324: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 325: 'enro' => 'Enroll one student',
326: 'admo' => 'Add/modify a single user',
327: 'crea' => 'create new user if required',
328: 'uskn' => "username is known",
1.207 raeburn 329: 'crnu' => 'Create a new user',
330: 'usr' => 'Username',
331: 'dom' => 'in domain',
1.229 raeburn 332: 'enrl' => 'Enroll',
333: 'cram' => 'Create/Modify user',
1.207 raeburn 334: );
1.229 raeburn 335: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
336: my ($title,$buttontext,$showresponse);
337: if ($env{'form.action'} eq 'singlestudent') {
338: $title = $lt{'enro'};
339: $buttontext = $lt{'enrl'};
340: } else {
341: $title = $lt{'admo'};
342: $buttontext = $lt{'cram'};
343: }
344: if ($cancreate) {
345: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
346: } else {
347: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
348: }
349: if ($env{'form.origform'} eq 'crtusername') {
350: $showresponse = $responsemsg;
351: }
1.207 raeburn 352: $output .= <<"ENDDOCUMENT";
1.229 raeburn 353: <br />
1.207 raeburn 354: <form action="/adm/createuser" method="post" name="crtusername">
355: <input type="hidden" name="action" value="$env{'form.action'}" />
356: <input type="hidden" name="phase" value="createnewuser" />
357: <input type="hidden" name="srchtype" value="exact" />
1.233 ! raeburn 358: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 359: <input type="hidden" name="srchin" value="dom" />
360: <input type="hidden" name="forcenewuser" value="1" />
361: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 362: <h3>$title</h3>
363: $showresponse
1.207 raeburn 364: <table>
365: <tr>
366: <td>$lt{'usr'}:</td>
367: <td><input type="text" size="15" name="srchterm" /></td>
368: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 369: <td> $sellink </td>
370: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 371: </tr>
372: </table>
373: </form>
1.160 raeburn 374: ENDDOCUMENT
1.207 raeburn 375: }
1.160 raeburn 376: return $output;
377: }
1.110 albertel 378:
379: sub user_modification_js {
1.113 raeburn 380: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
381:
1.110 albertel 382: return <<END;
383: <script type="text/javascript" language="Javascript">
384:
385: function pclose() {
386: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
387: "height=350,width=350,scrollbars=no,menubar=no");
388: parmwin.close();
389: }
390:
391: $pjump_def
392: $dc_setcourse_code
393:
394: function dateset() {
395: eval("document.cu."+document.cu.pres_marker.value+
396: ".value=document.cu.pres_value.value");
397: pclose();
398: }
399:
1.113 raeburn 400: $nondc_setsection_code
401:
1.110 albertel 402: </script>
403: END
1.2 www 404: }
405:
406: # =================================================================== Phase two
1.160 raeburn 407: sub print_user_selection_page {
1.229 raeburn 408: my ($r,$response,$srch,$srch_results,$srcharray,$context) = @_;
1.160 raeburn 409: my @fields = ('username','domain','lastname','firstname','permanentemail');
410: my $sortby = $env{'form.sortby'};
411:
412: if (!grep(/^\Q$sortby\E$/,@fields)) {
413: $sortby = 'lastname';
414: }
415:
416: my ($jsback,$elements) = &crumb_utilities();
417:
418: my $jscript = (<<ENDSCRIPT);
419: <script type="text/javascript">
420: function pickuser(uname,udom) {
421: document.usersrchform.seluname.value=uname;
422: document.usersrchform.seludom.value=udom;
423: document.usersrchform.phase.value="userpicked";
424: document.usersrchform.submit();
425: }
426:
427: $jsback
428: </script>
429: ENDSCRIPT
430:
431: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 432: 'usrch' => "User Search to add/modify roles",
433: 'stusrch' => "User Search to enroll student",
434: 'usel' => "Select a user to add/modify roles",
435: 'stusel' => "Select a user to enroll as a student",
1.160 raeburn 436: 'username' => "username",
437: 'domain' => "domain",
438: 'lastname' => "last name",
439: 'firstname' => "first name",
440: 'permanentemail' => "permanent e-mail",
441: );
1.214 raeburn 442: $r->print(&Apache::loncommon::start_page('User Management',$jscript));
1.229 raeburn 443:
444: my %breadcrumb_text = &singleuser_breadcrumb();
445: &Apache::lonhtmlcommon::add_breadcrumb
446: ({href=>"javascript:backPage(document.usersrchform,'','')",
447: text=>$breadcrumb_text{'search'},
448: faq=>282,bug=>'Instructor Interface',},
449: {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
450: text=>$breadcrumb_text{'userpicked'},
451: faq=>282,bug=>'Instructor Interface',});
452: if ($env{'form.action'} eq 'singleuser') {
1.224 raeburn 453: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
454: 'Course_Change_Privileges'));
1.179 raeburn 455: $r->print("<b>$lt{'usrch'}</b><br />");
1.207 raeburn 456: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
1.179 raeburn 457: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1.229 raeburn 458: } elsif ($env{'form.action'} eq 'singlestudent') {
1.224 raeburn 459: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
460: 'Course_Add_Student'));
1.179 raeburn 461: $r->print($jscript."<b>$lt{'stusrch'}</b><br />");
1.214 raeburn 462: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
1.179 raeburn 463: $r->print('</form><h3>'.$lt{'stusel'}.'</h3>');
464: }
1.160 raeburn 465: $r->print('<form name="usersrchform" method="post">'.
466: &Apache::loncommon::start_data_table()."\n".
467: &Apache::loncommon::start_data_table_header_row()."\n".
468: ' <th> </th>'."\n");
469: foreach my $field (@fields) {
470: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
471: "'".$field."'".';document.usersrchform.submit();">'.
472: $lt{$field}.'</a></th>'."\n");
473: }
474: $r->print(&Apache::loncommon::end_data_table_header_row());
475:
476: my @sorted_users = sort {
1.167 albertel 477: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 478: ||
1.167 albertel 479: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 480: ||
481: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 482: ||
483: lc($a) cmp lc($b)
1.160 raeburn 484: } (keys(%$srch_results));
485:
486: foreach my $user (@sorted_users) {
487: my ($uname,$udom) = split(/:/,$user);
488: $r->print(&Apache::loncommon::start_data_table_row().
489: '<td><input type="button" name="seluser" value="'.&mt('Select').'" onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".')" /></td>'.
490: '<td><tt>'.$uname.'</tt></td>'.
491: '<td><tt>'.$udom.'</tt></td>');
492: foreach my $field ('lastname','firstname','permanentemail') {
493: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
494: }
495: $r->print(&Apache::loncommon::end_data_table_row());
496: }
497: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 498: if (ref($srcharray) eq 'ARRAY') {
499: foreach my $item (@{$srcharray}) {
500: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
501: }
502: }
1.160 raeburn 503: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
504: ' <input type="hidden" name="seluname" value="" />'."\n".
505: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 506: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 507: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 508: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
509: $r->print($response.'</form>'.&Apache::loncommon::end_page());
1.160 raeburn 510: }
511:
512: sub print_user_query_page {
1.179 raeburn 513: my ($r,$caller) = @_;
1.160 raeburn 514: # FIXME - this is for a network-wide name search (similar to catalog search)
515: # To use frames with similar behavior to catalog/portfolio search.
516: # To be implemented.
517: return;
518: }
519:
1.42 matthew 520: sub print_user_modification_page {
1.215 raeburn 521: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission) = @_;
1.185 raeburn 522: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 523: my $usermsg = &mt('No username and/or domain provided.');
524: $env{'form.phase'} = '';
1.207 raeburn 525: &print_username_entry_form($r,$context,$usermsg);
1.58 www 526: return;
527: }
1.213 raeburn 528: my ($form,$formname);
529: if ($env{'form.action'} eq 'singlestudent') {
530: $form = 'document.enrollstudent';
531: $formname = 'enrollstudent';
532: } else {
533: $form = 'document.cu';
534: $formname = 'cu';
535: }
1.188 raeburn 536: my %abv_auth = &auth_abbrev();
1.227 raeburn 537: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 538: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
539: if ($uhome eq 'no_host') {
1.215 raeburn 540: my $usertype;
541: my ($rules,$ruleorder) =
542: &Apache::lonnet::inst_userrules($ccdomain,'username');
543: $usertype =
544: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules);
545: my $cancreate =
546: &Apache::lonuserutils::can_create_user($ccdomain,$context,
547: $usertype);
548: if (!$cancreate) {
549: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
550: my %usertypetext = (
551: official => 'institutional',
552: unofficial => 'non-institutional',
553: );
554: my $response;
555: if ($env{'form.origform'} eq 'crtusername') {
556: $response = '<span class="LC_warning">'.&mt('No match was found for the username ([_1]) in LON-CAPA domain: [_2]',$ccuname,$ccdomain).
557: '</span><br />';
558: }
559: $response .= '<span class="LC_warning">'.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the <a[_1]>helpdesk</a> for assistance.',$helplink).'</span><br /><br />';
560: $env{'form.phase'} = '';
561: &print_username_entry_form($r,$context,$response);
562: return;
563: }
1.188 raeburn 564: $newuser = 1;
1.193 raeburn 565: my $checkhash;
566: my $checks = { 'username' => 1 };
1.196 raeburn 567: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 568: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 569: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
570: if (ref($alerts{'username'}) eq 'HASH') {
571: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
572: my $domdesc =
1.193 raeburn 573: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 574: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
575: my $userchkmsg;
576: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
577: $userchkmsg =
578: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 579: $domdesc,1).
580: &Apache::loncommon::user_rule_formats($ccdomain,
581: $domdesc,$curr_rules{$ccdomain}{'username'},
582: 'username');
1.196 raeburn 583: }
1.215 raeburn 584: $env{'form.phase'} = '';
1.207 raeburn 585: &print_username_entry_form($r,$context,$userchkmsg);
1.196 raeburn 586: return;
1.215 raeburn 587: }
1.193 raeburn 588: }
1.185 raeburn 589: }
1.187 raeburn 590: } else {
1.188 raeburn 591: $newuser = 0;
1.185 raeburn 592: }
1.160 raeburn 593: if ($response) {
1.215 raeburn 594: $response = '<br />'.$response;
1.160 raeburn 595: }
1.149 raeburn 596:
1.52 matthew 597: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 598: my $dc_setcourse_code = '';
1.119 raeburn 599: my $nondc_setsection_code = '';
1.112 albertel 600: my %loaditem;
1.114 albertel 601:
1.216 raeburn 602: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 603:
1.216 raeburn 604: my $js = &validation_javascript($context,$ccdomain,$pjump_def,
605: $groupslist,$newuser,$formname,\%loaditem);
1.233 ! raeburn 606: my $args = {'add_entries' => \%loaditem};
! 607: if ($env{'form.popup'}) {
! 608: $args->{'no_nav_bar'} = 1;
! 609: }
1.110 albertel 610: my $start_page =
1.233 ! raeburn 611: &Apache::loncommon::start_page('User Management',$js,$args);
1.216 raeburn 612: my %breadcrumb_text = &singleuser_breadcrumb();
1.160 raeburn 613: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 614: ({href=>"javascript:backPage($form)",
615: text=>$breadcrumb_text{'search'},
1.160 raeburn 616: faq=>282,bug=>'Instructor Interface',});
617:
618: if ($env{'form.phase'} eq 'userpicked') {
619: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 620: ({href=>"javascript:backPage($form,'get_user_info','select')",
621: text=>$breadcrumb_text{'userpicked'},
1.160 raeburn 622: faq=>282,bug=>'Instructor Interface',});
623: }
624: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 625: ({href=>"javascript:backPage($form,'$env{'form.phase'}','modify')",
626: text=>$breadcrumb_text{'modify'},
1.160 raeburn 627: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 628: my $helpitem = 'Course_Change_Privileges';
629: if ($env{'form.action'} eq 'singlestudent') {
630: $helpitem = 'Course_Add_Student';
631: }
632: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
633: $helpitem);
1.3 www 634:
1.25 matthew 635: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 636: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 637: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 638: <input type="hidden" name="ccuname" value="$ccuname" />
639: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 640: <input type="hidden" name="pres_value" value="" />
641: <input type="hidden" name="pres_type" value="" />
642: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 643: ENDFORMINFO
1.2 www 644: my %inccourses;
1.135 raeburn 645: foreach my $key (keys(%env)) {
1.139 albertel 646: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1.2 www 647: $inccourses{$1.'_'.$2}=1;
648: }
1.24 matthew 649: }
1.216 raeburn 650: if ($newuser) {
1.134 raeburn 651: my $portfolioform;
652: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
653: # Current user has quota modification privileges
1.188 raeburn 654: $portfolioform = '<br />'.&portfolio_quota($ccuname,$ccdomain);
1.134 raeburn 655: }
1.227 raeburn 656: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 657: my %lt=&Apache::lonlocal::texthash(
658: 'cnu' => 'Create New User',
1.213 raeburn 659: 'ast' => 'as a student',
1.188 raeburn 660: 'ind' => 'in domain',
661: 'lg' => 'Login Data',
1.190 raeburn 662: 'hs' => "Home Server",
1.188 raeburn 663: );
1.185 raeburn 664: $r->print(<<ENDTITLE);
1.110 albertel 665: $start_page
1.160 raeburn 666: $crumbs
667: $response
1.25 matthew 668: $forminfo
1.31 matthew 669: <script type="text/javascript" language="Javascript">
1.20 harris41 670: $loginscript
1.31 matthew 671: </script>
1.20 harris41 672: <input type='hidden' name='makeuser' value='1' />
1.216 raeburn 673: <h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain
1.185 raeburn 674: ENDTITLE
1.213 raeburn 675: if ($env{'form.action'} eq 'singlestudent') {
676: $r->print(' ('.$lt{'ast'}.')');
677: }
678: $r->print('</h2>'."\n".'<div class="LC_left_float">');
1.206 raeburn 679: my $personal_table =
1.210 raeburn 680: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
681: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 682: $r->print($personal_table);
1.187 raeburn 683: my ($home_server_pick,$numlib) =
684: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
685: 'default','hide');
686: if ($numlib > 1) {
687: $r->print("
1.185 raeburn 688: <br />
1.187 raeburn 689: $lt{'hs'}: $home_server_pick
690: <br />");
691: } else {
692: $r->print($home_server_pick);
693: }
1.188 raeburn 694: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
695: $lt{'lg'}.'</h3>');
1.185 raeburn 696: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 697: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
698: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
699: my ($rules,$ruleorder) =
700: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 701: if (ref($rules) eq 'HASH') {
1.193 raeburn 702: if (ref($rules->{$matchedrule}) eq 'HASH') {
703: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 704: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 705: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 706: } else {
1.193 raeburn 707: my $authparm = $rules->{$matchedrule}{'authparm'};
1.185 raeburn 708: if ($authtype =~ /^krb(4|5)$/) {
709: my $ver = $1;
710: if ($authparm ne '') {
711: $fixedauth = <<"KERB";
712: <input type="hidden" name="login" value="krb" />
713: <input type="hidden" name="krbver" value="$ver" />
714: <input type="hidden" name="krbarg" value="$authparm" />
715: KERB
1.193 raeburn 716: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 717: }
718: } else {
719: $fixedauth =
720: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 721: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 722: $fixedauth .=
723: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
724: } else {
725: $varauth =
726: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
727: }
728: }
729: }
730: } else {
1.190 raeburn 731: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 732: }
733: }
734: if ($authmsg) {
735: $r->print(<<ENDAUTH);
736: $fixedauth
737: $authmsg
738: $varauth
739: ENDAUTH
740: }
741: } else {
1.190 raeburn 742: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 743: }
1.215 raeburn 744: $r->print($portfolioform);
745: if ($env{'form.action'} eq 'singlestudent') {
746: $r->print(&date_sections_select($context,$newuser,$formname,
747: $permission));
748: }
749: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 750: } else { # user already exists
1.79 albertel 751: my %lt=&Apache::lonlocal::texthash(
1.191 raeburn 752: 'cup' => "Modify existing user: ",
1.213 raeburn 753: 'ens' => "Enroll one student: ",
1.72 sakharuk 754: 'id' => "in domain",
755: );
1.26 matthew 756: $r->print(<<ENDCHANGEUSER);
1.110 albertel 757: $start_page
1.160 raeburn 758: $crumbs
1.25 matthew 759: $forminfo
1.213 raeburn 760: <h2>
1.26 matthew 761: ENDCHANGEUSER
1.213 raeburn 762: if ($env{'form.action'} eq 'singlestudent') {
763: $r->print($lt{'ens'});
764: } else {
765: $r->print($lt{'cup'});
766: }
767: $r->print(' "'.$ccuname.'" '.$lt{'id'}.' "'.$ccdomain.'"</h2>'.
768: "\n".'<div class="LC_left_float">');
1.206 raeburn 769: my ($personal_table,$showforceid) =
1.210 raeburn 770: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
771: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 772: $r->print($personal_table);
773: if ($showforceid) {
1.203 raeburn 774: $r->print(&Apache::lonuserutils::forceid_change($context));
1.199 raeburn 775: }
776: $r->print('</div>');
1.227 raeburn 777: my $user_auth_text = &user_authentication($ccuname,$ccdomain,$formname);
1.188 raeburn 778: my $user_quota_text;
779: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
780: # Current user has quota modification privileges
781: $user_quota_text = &portfolio_quota($ccuname,$ccdomain);
782: } elsif (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
783: # Get the user's portfolio information
784: my %portq = &Apache::lonnet::get('environment',['portfolioquota'],
785: $ccdomain,$ccuname);
786:
787: my %lt=&Apache::lonlocal::texthash(
788: 'dska' => "Disk space allocated to user's portfolio files",
789: 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
790: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
791: );
792: $user_quota_text = <<ENDNOPORTPRIV;
793: <h3>$lt{'dska'}</h3>
794: $lt{'youd'} $lt{'ichr'}: $ccdomain
795: ENDNOPORTPRIV
796: }
797: if ($user_auth_text ne '') {
798: $r->print('<div class="LC_left_float">'.$user_auth_text);
799: if ($user_quota_text ne '') {
800: $r->print($user_quota_text);
801: }
1.213 raeburn 802: if ($env{'form.action'} eq 'singlestudent') {
803: $r->print(&date_sections_select($context,$newuser,$formname));
804: }
1.188 raeburn 805: } elsif ($user_quota_text ne '') {
1.213 raeburn 806: $r->print('<div class="LC_left_float">'.$user_quota_text);
807: if ($env{'form.action'} eq 'singlestudent') {
808: $r->print(&date_sections_select($context,$newuser,$formname));
809: }
810: } else {
811: if ($env{'form.action'} eq 'singlestudent') {
812: $r->print('<div class="LC_left_float">'.
813: &date_sections_select($context,$newuser,$formname));
814: }
1.188 raeburn 815: }
1.213 raeburn 816: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.217 raeburn 817: if ($env{'form.action'} ne 'singlestudent') {
818: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses);
819: }
1.25 matthew 820: } ## End of new user/old user logic
1.218 raeburn 821:
822: if ($env{'form.action'} eq 'singlestudent') {
823: $r->print('<br /><input type="button" value="'.&mt('Enroll Student').'" onClick="setSections(this.form)" />'."\n");
824: } else {
825: $r->print('<h3>'.&mt('Add Roles').'</h3>');
826: my $addrolesdisplay = 0;
827: if ($context eq 'domain' || $context eq 'author') {
828: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
829: }
830: if ($context eq 'domain') {
831: my $add_domainroles = &new_domain_roles($r);
832: if (!$addrolesdisplay) {
833: $addrolesdisplay = $add_domainroles;
1.2 www 834: }
1.218 raeburn 835: $r->print(&course_level_dc($env{'request.role.domain'},'Course'));
836: $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()" />'."\n");
837: } elsif ($context eq 'author') {
838: if ($addrolesdisplay) {
839: $r->print('<br /><input type="button" value="'.&mt('Modify User').'"');
840: if ($newuser) {
1.227 raeburn 841: $r->print(' onClick="auth_check()" \>'."\n");
1.218 raeburn 842: } else {
843: $r->print('onClick="this.form.submit()" \>'."\n");
844: }
1.188 raeburn 845: } else {
1.218 raeburn 846: $r->print('<br /><a href="javascript:backPage(document.cu)">'.
847: &mt('Back to previous page').'</a>');
1.188 raeburn 848: }
849: } else {
1.218 raeburn 850: $r->print(&course_level_table(%inccourses));
851: $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setSections(this.form)" />'."\n");
1.188 raeburn 852: }
1.88 raeburn 853: }
1.188 raeburn 854: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 855: $r->print('<input type="hidden" name="currstate" value="" />');
1.160 raeburn 856: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />');
1.110 albertel 857: $r->print("</form>".&Apache::loncommon::end_page());
1.218 raeburn 858: return;
1.2 www 859: }
1.1 www 860:
1.213 raeburn 861: sub singleuser_breadcrumb {
862: my %breadcrumb_text;
863: if ($env{'form.action'} eq 'singlestudent') {
864: $breadcrumb_text{'search'} = 'Enroll a student';
865: $breadcrumb_text{'userpicked'} = 'Select a user',
866: $breadcrumb_text{'modify'} = 'Set section/dates',
867: } else {
1.229 raeburn 868: $breadcrumb_text{'search'} = 'Create/modify a user';
1.213 raeburn 869: $breadcrumb_text{'userpicked'} = 'Select a user',
870: $breadcrumb_text{'modify'} = 'Set user role',
871: }
872: return %breadcrumb_text;
873: }
874:
875: sub date_sections_select {
876: my ($context,$newuser,$formname,$permission) = @_;
877: my $cid = $env{'request.course.id'};
878: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
879: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
880: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
881: undef,$formname,$permission);
882: my $rowtitle = 'Section';
883: my $secbox = '<h3>'.&mt('Section').'</h3>'."\n".
884: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
885: $permission);
886: my $output = $date_table.$secbox;
887: return $output;
888: }
889:
1.216 raeburn 890: sub validation_javascript {
891: my ($context,$ccdomain,$pjump_def,$groupslist,$newuser,$formname,
892: $loaditem) = @_;
893: my $dc_setcourse_code = '';
894: my $nondc_setsection_code = '';
895: if ($context eq 'domain') {
896: my $dcdom = $env{'request.role.domain'};
897: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 898: $dc_setcourse_code =
899: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 900: } else {
1.227 raeburn 901: my $checkauth;
902: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
903: $checkauth = 1;
904: }
905: if ($context eq 'course') {
906: $nondc_setsection_code =
907: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
908: undef,$checkauth);
909: }
910: if ($checkauth) {
911: $nondc_setsection_code .=
912: &Apache::lonuserutils::verify_authen($formname,$context);
913: }
1.216 raeburn 914: }
915: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
916: $nondc_setsection_code,$groupslist);
917: my ($jsback,$elements) = &crumb_utilities();
918: $js .= "\n".
1.227 raeburn 919: '<script type="text/javascript">'."\n".$jsback."\n".'</script>';
1.216 raeburn 920: return $js;
921: }
922:
1.217 raeburn 923: sub display_existing_roles {
924: my ($r,$ccuname,$ccdomain,$inccourses) = @_;
925: my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
926: # Build up table of user roles to allow revocation and re-enabling of roles.
927: my ($tmp) = keys(%rolesdump);
928: if ($tmp !~ /^(con_lost|error)/i) {
929: my $now=time;
930: my %lt=&Apache::lonlocal::texthash(
931: 'rer' => "Existing Roles",
932: 'rev' => "Revoke",
933: 'del' => "Delete",
934: 'ren' => "Re-Enable",
935: 'rol' => "Role",
936: 'ext' => "Extent",
937: 'sta' => "Start",
938: 'end' => "End",
939: );
940: my (%roletext,%sortrole,%roleclass,%rolepriv);
941: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
942: my $b1=join('_',(split('_',$b))[1,0]);
943: return $a1 cmp $b1;
944: } keys(%rolesdump)) {
945: next if ($area =~ /^rolesdef/);
946: my $envkey=$area;
947: my $role = $rolesdump{$area};
948: my $thisrole=$area;
949: $area =~ s/\_\w\w$//;
950: my ($role_code,$role_end_time,$role_start_time) =
951: split(/_/,$role);
952: # Is this a custom role? Get role owner and title.
953: my ($croleudom,$croleuname,$croletitle)=
954: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
955: my $allowed=0;
956: my $delallowed=0;
957: my $sortkey=$role_code;
958: my $class='Unknown';
959: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
960: $class='Course';
961: my ($coursedom,$coursedir) = ($1,$2);
962: $sortkey.="\0$coursedom";
963: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
964: my %coursedata=
965: &Apache::lonnet::coursedescription($1.'_'.$2);
966: my $carea;
967: if (defined($coursedata{'description'})) {
968: $carea=$coursedata{'description'}.
969: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
970: &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
971: $sortkey.="\0".$coursedata{'description'};
972: $class=$coursedata{'type'};
973: } else {
974: $carea=&mt('Unavailable course').': '.$area;
975: $sortkey.="\0".&mt('Unavailable course').': '.$area;
976: }
977: $sortkey.="\0$coursedir";
978: $inccourses->{$1.'_'.$2}=1;
979: if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
980: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
981: $allowed=1;
982: }
983: if ((&Apache::lonnet::allowed('dro',$1)) ||
984: (&Apache::lonnet::allowed('dro',$ccdomain))) {
985: $delallowed=1;
986: }
987: # - custom role. Needs more info, too
988: if ($croletitle) {
989: if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
990: $allowed=1;
991: $thisrole.='.'.$role_code;
992: }
993: }
994: # Compute the background color based on $area
995: if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
996: $carea.='<br />Section: '.$3;
997: $sortkey.="\0$3";
998: if (!$allowed) {
999: if ($env{'request.course.sec'} eq $3) {
1000: if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
1001: $allowed = 1;
1002: }
1003: }
1004: }
1005: }
1006: $area=$carea;
1007: } else {
1008: $sortkey.="\0".$area;
1009: # Determine if current user is able to revoke privileges
1010: if ($area=~m{^/($match_domain)/}) {
1011: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1012: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1013: $allowed=1;
1014: }
1015: if (((&Apache::lonnet::allowed('dro',$1)) ||
1016: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1017: ($role_code ne 'dc')) {
1018: $delallowed=1;
1019: }
1020: } else {
1021: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1022: $allowed=1;
1023: }
1024: }
1025: if ($role_code eq 'ca' || $role_code eq 'au') {
1026: $class='Construction Space';
1027: } elsif ($role_code eq 'su') {
1028: $class='System';
1029: } else {
1030: $class='Domain';
1031: }
1032: }
1033: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1034: $area=~m{/($match_domain)/($match_username)};
1035: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1036: $allowed=1;
1037: } else {
1038: $allowed=0;
1039: }
1040: }
1041: my $row = '';
1042: $row.= '<td>';
1043: my $active=1;
1044: $active=0 if (($role_end_time) && ($now>$role_end_time));
1045: if (($active) && ($allowed)) {
1046: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1047: } else {
1048: if ($active) {
1049: $row.=' ';
1050: } else {
1051: $row.=&mt('expired or revoked');
1052: }
1053: }
1054: $row.='</td><td>';
1055: if ($allowed && !$active) {
1056: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1057: } else {
1058: $row.=' ';
1059: }
1060: $row.='</td><td>';
1061: if ($delallowed) {
1062: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1063: } else {
1064: $row.=' ';
1065: }
1066: my $plaintext='';
1067: if (!$croletitle) {
1068: $plaintext=&Apache::lonnet::plaintext($role_code,$class)
1069: } else {
1070: $plaintext=
1071: "Customrole '$croletitle'<br />defined by $croleuname\@$croleudom";
1072: }
1073: $row.= '</td><td>'.$plaintext.
1074: '</td><td>'.$area.
1075: '</td><td>'.($role_start_time?localtime($role_start_time)
1076: : ' ' ).
1077: '</td><td>'.($role_end_time ?localtime($role_end_time)
1078: : ' ' )
1079: ."</td>";
1080: $sortrole{$sortkey}=$envkey;
1081: $roletext{$envkey}=$row;
1082: $roleclass{$envkey}=$class;
1083: $rolepriv{$envkey}=$allowed;
1084: #$r->print($row);
1085: } # end of foreach (table building loop)
1086: my $rolesdisplay = 0;
1087: my %output = ();
1088: foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
1089: $output{$type} = '';
1090: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1091: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1092: $output{$type}.=
1093: &Apache::loncommon::start_data_table_row().
1094: $roletext{$sortrole{$which}}.
1095: &Apache::loncommon::end_data_table_row();
1096: }
1097: }
1098: unless($output{$type} eq '') {
1099: $output{$type} = '<tr class="LC_info_row">'.
1100: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1101: $output{$type};
1102: $rolesdisplay = 1;
1103: }
1104: }
1105: if ($rolesdisplay == 1) {
1106: $r->print('
1107: <h3>'.$lt{'rer'}.'</h3>'.
1108: &Apache::loncommon::start_data_table("LC_createuser").
1109: &Apache::loncommon::start_data_table_header_row().
1110: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
1111: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
1112: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1113: &Apache::loncommon::end_data_table_header_row());
1114: foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
1115: if ($output{$type}) {
1116: $r->print($output{$type}."\n");
1117: }
1118: }
1119: $r->print(&Apache::loncommon::end_data_table());
1120: }
1121: } # End of check for keys in rolesdump
1122: return;
1123: }
1124:
1.218 raeburn 1125: sub new_coauthor_roles {
1126: my ($r,$ccuname,$ccdomain) = @_;
1127: my $addrolesdisplay = 0;
1128: #
1129: # Co-Author
1130: #
1131: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
1132: $env{'request.role.domain'}) &&
1133: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1134: # No sense in assigning co-author role to yourself
1135: $addrolesdisplay = 1;
1136: my $cuname=$env{'user.name'};
1137: my $cudom=$env{'request.role.domain'};
1138: my %lt=&Apache::lonlocal::texthash(
1139: 'cs' => "Construction Space",
1140: 'act' => "Activate",
1141: 'rol' => "Role",
1142: 'ext' => "Extent",
1143: 'sta' => "Start",
1144: 'end' => "End",
1145: 'cau' => "Co-Author",
1146: 'caa' => "Assistant Co-Author",
1147: 'ssd' => "Set Start Date",
1148: 'sed' => "Set End Date"
1149: );
1150: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
1151: &Apache::loncommon::start_data_table()."\n".
1152: &Apache::loncommon::start_data_table_header_row()."\n".
1153: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
1154: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
1155: '<th>'.$lt{'end'}.'</th>'."\n".
1156: &Apache::loncommon::end_data_table_header_row()."\n".
1157: &Apache::loncommon::start_data_table_row().'
1158: <td>
1159: <input type=checkbox name="act_'.$cudom.'_'.$cuname.'_ca" />
1160: </td>
1161: <td>'.$lt{'cau'}.'</td>
1162: <td>'.$cudom.'_'.$cuname.'</td>
1163: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
1164: <a href=
1165: "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>
1166: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
1167: <a href=
1168: "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".
1169: &Apache::loncommon::end_data_table_row()."\n".
1170: &Apache::loncommon::start_data_table_row()."\n".
1171: '<td><input type=checkbox name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1172: <td>'.$lt{'caa'}.'</td>
1173: <td>'.$cudom.'_'.$cuname.'</td>
1174: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
1175: <a href=
1176: "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>
1177: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
1178: <a href=
1179: "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".
1180: &Apache::loncommon::end_data_table_row()."\n".
1181: &Apache::loncommon::end_data_table());
1182: } elsif ($env{'request.role'} =~ /^au\./) {
1183: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
1184: $env{'request.role.domain'}))) {
1185: $r->print('<span class="LC_error">'.
1186: &mt('You do not have privileges to assign co-author roles.').
1187: '</span>');
1188: } elsif (($env{'user.name'} eq $ccuname) &&
1189: ($env{'user.domain'} eq $ccdomain)) {
1190: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Construction Space is not permitted'));
1191: }
1192: }
1193: return $addrolesdisplay;;
1194: }
1195:
1196: sub new_domain_roles {
1197: my ($r) = @_;
1198: my $addrolesdisplay = 0;
1199: #
1200: # Domain level
1201: #
1202: my $num_domain_level = 0;
1203: my $domaintext =
1204: '<h4>'.&mt('Domain Level').'</h4>'.
1205: &Apache::loncommon::start_data_table().
1206: &Apache::loncommon::start_data_table_header_row().
1207: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
1208: &mt('Extent').'</th>'.
1209: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
1210: &Apache::loncommon::end_data_table_header_row();
1211: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1212: foreach my $role ('dc','li','dg','au','sc') {
1213: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1214: my $plrole=&Apache::lonnet::plaintext($role);
1215: my %lt=&Apache::lonlocal::texthash(
1216: 'ssd' => "Set Start Date",
1217: 'sed' => "Set End Date"
1218: );
1219: $num_domain_level ++;
1220: $domaintext .=
1221: &Apache::loncommon::start_data_table_row().
1222: '<td><input type=checkbox name="act_'.$thisdomain.'_'.$role.'" /></td>
1223: <td>'.$plrole.'</td>
1224: <td>'.$thisdomain.'</td>
1225: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
1226: <a href=
1227: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1228: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
1229: <a href=
1230: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
1231: &Apache::loncommon::end_data_table_row();
1232: }
1233: }
1234: }
1235: $domaintext.= &Apache::loncommon::end_data_table();
1236: if ($num_domain_level > 0) {
1237: $r->print($domaintext);
1238: $addrolesdisplay = 1;
1239: }
1240: return $addrolesdisplay;
1241: }
1242:
1.188 raeburn 1243: sub user_authentication {
1.227 raeburn 1244: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 1245: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 1246: my $outcome;
1.188 raeburn 1247: # Check for a bad authentication type
1248: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
1249: # bad authentication scheme
1250: my %lt=&Apache::lonlocal::texthash(
1251: 'err' => "ERROR",
1252: 'uuas' => "This user has an unrecognized authentication scheme",
1253: 'adcs' => "Please alert a domain coordinator of this situation",
1254: 'sldb' => "Please specify login data below",
1255: 'ld' => "Login Data"
1256: );
1257: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 1258: &initialize_authen_forms($ccdomain,$formname);
1259:
1.190 raeburn 1260: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 1261: $outcome = <<ENDBADAUTH;
1262: <script type="text/javascript" language="Javascript">
1263: $loginscript
1264: </script>
1265: <span class="LC_error">$lt{'err'}:
1266: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
1267: <h3>$lt{'ld'}</h3>
1268: $choices
1269: ENDBADAUTH
1270: } else {
1271: # This user is not allowed to modify the user's
1272: # authentication scheme, so just notify them of the problem
1273: $outcome = <<ENDBADAUTH;
1274: <span class="LC_error"> $lt{'err'}:
1275: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
1276: </span>
1277: ENDBADAUTH
1278: }
1279: } else { # Authentication type is valid
1.227 raeburn 1280: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 1281: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 1282: &modify_login_block($ccdomain,$currentauth);
1283: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1284: # Current user has login modification privileges
1285: my %lt=&Apache::lonlocal::texthash (
1286: 'ld' => "Login Data",
1287: 'ccld' => "Change Current Login Data",
1288: 'enld' => "Enter New Login Data"
1289: );
1290: $outcome =
1291: '<script type="text/javascript" language="Javascript">'."\n".
1292: $loginscript."\n".
1293: '</script>'."\n".
1294: '<h3>'.$lt{'ld'}.'</h3>'.
1295: &Apache::loncommon::start_data_table().
1.205 raeburn 1296: &Apache::loncommon::start_data_table_row().
1.188 raeburn 1297: '<td>'.$authformnop;
1298: if ($can_modify) {
1299: $outcome .= '</td>'."\n".
1300: &Apache::loncommon::end_data_table_row().
1301: &Apache::loncommon::start_data_table_row().
1302: '<td>'.$authformcurrent.'</td>'.
1303: &Apache::loncommon::end_data_table_row()."\n";
1304: } else {
1.200 raeburn 1305: $outcome .= ' ('.$authformcurrent.')</td>'.
1306: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 1307: }
1.205 raeburn 1308: foreach my $item (@authform_others) {
1309: $outcome .= &Apache::loncommon::start_data_table_row().
1310: '<td>'.$item.'</td>'.
1311: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 1312: }
1.205 raeburn 1313: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 1314: } else {
1315: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1316: my %lt=&Apache::lonlocal::texthash(
1317: 'ccld' => "Change Current Login Data",
1318: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
1319: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1320: );
1321: $outcome .= <<ENDNOPRIV;
1322: <h3>$lt{'ccld'}</h3>
1323: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1324: ENDNOPRIV
1325: }
1326: }
1327: } ## End of "check for bad authentication type" logic
1328: return $outcome;
1329: }
1330:
1.187 raeburn 1331: sub modify_login_block {
1332: my ($dom,$currentauth) = @_;
1333: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
1334: my ($authnum,%can_assign) =
1335: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 1336: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 1337: if ($currentauth=~/^krb(4|5):/) {
1338: $authformcurrent=$authformkrb;
1339: if ($can_assign{'int'}) {
1.205 raeburn 1340: push(@authform_others,$authformint);
1.187 raeburn 1341: }
1342: if ($can_assign{'loc'}) {
1.205 raeburn 1343: push(@authform_others,$authformloc);
1.187 raeburn 1344: }
1345: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1346: $show_override_msg = 1;
1347: }
1348: } elsif ($currentauth=~/^internal:/) {
1349: $authformcurrent=$authformint;
1350: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1351: push(@authform_others,$authformkrb);
1.187 raeburn 1352: }
1353: if ($can_assign{'loc'}) {
1.205 raeburn 1354: push(@authform_others,$authformloc);
1.187 raeburn 1355: }
1356: if ($can_assign{'int'}) {
1357: $show_override_msg = 1;
1358: }
1359: } elsif ($currentauth=~/^unix:/) {
1360: $authformcurrent=$authformfsys;
1361: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1362: push(@authform_others,$authformkrb);
1.187 raeburn 1363: }
1364: if ($can_assign{'int'}) {
1.205 raeburn 1365: push(@authform_others,$authformint);
1.187 raeburn 1366: }
1367: if ($can_assign{'loc'}) {
1.205 raeburn 1368: push(@authform_others,$authformloc);
1.187 raeburn 1369: }
1370: if ($can_assign{'fsys'}) {
1371: $show_override_msg = 1;
1372: }
1373: } elsif ($currentauth=~/^localauth:/) {
1374: $authformcurrent=$authformloc;
1375: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1376: push(@authform_others,$authformkrb);
1.187 raeburn 1377: }
1378: if ($can_assign{'int'}) {
1.205 raeburn 1379: push(@authform_others,$authformint);
1.187 raeburn 1380: }
1381: if ($can_assign{'loc'}) {
1382: $show_override_msg = 1;
1383: }
1384: }
1385: if ($show_override_msg) {
1.205 raeburn 1386: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
1387: '</td></tr>'."\n".
1388: '<tr><td> </td>'.
1389: '<td><b>'.&mt('Currently in use').'</b></td>'.
1390: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 1391: &mt('will override current values').
1.205 raeburn 1392: '</span></td></tr></table>';
1.187 raeburn 1393: }
1.205 raeburn 1394: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 1395: }
1396:
1.188 raeburn 1397: sub personal_data_display {
1.210 raeburn 1398: my ($ccuname,$ccdomain,$newuser,$context,$inst_results) = @_;
1.219 raeburn 1399: my ($output,$showforceid,%userenv,%canmodify);
1400: my @userinfo = ('firstname','middlename','lastname','generation',
1401: 'permanentemail','id');
1.188 raeburn 1402: if (!$newuser) {
1403: # Get the users information
1404: %userenv = &Apache::lonnet::get('environment',
1405: ['firstname','middlename','lastname','generation',
1406: 'permanentemail','id'],$ccdomain,$ccuname);
1.219 raeburn 1407: %canmodify =
1408: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1409: \@userinfo);
1.188 raeburn 1410: }
1411: my %lt=&Apache::lonlocal::texthash(
1412: 'pd' => "Personal Data",
1413: 'firstname' => "First Name",
1414: 'middlename' => "Middle Name",
1415: 'lastname' => "Last Name",
1416: 'generation' => "Generation",
1417: 'permanentemail' => "Permanent e-mail address",
1418: 'id' => "ID/Student Number",
1419: 'lg' => "Login Data"
1420: );
1421: my %textboxsize = (
1422: firstname => '15',
1423: middlename => '15',
1424: lastname => '15',
1425: generation => '5',
1426: permanentemail => '25',
1427: id => '15',
1428: );
1429: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
1430: $output = '<h3>'.$lt{'pd'}.'</h3>'.
1431: &Apache::lonhtmlcommon::start_pick_box();
1432: foreach my $item (@userinfo) {
1433: my $rowtitle = $lt{$item};
1434: if ($item eq 'generation') {
1435: $rowtitle = $genhelp.$rowtitle;
1436: }
1437: $output .= &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1438: if ($newuser) {
1.210 raeburn 1439: if (ref($inst_results) eq 'HASH') {
1440: if ($inst_results->{$item} ne '') {
1441: $output .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1442: } else {
1443: $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1444: }
1.188 raeburn 1445: } else {
1446: $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1447: }
1448: } else {
1.219 raeburn 1449: if ($canmodify{$item}) {
1.188 raeburn 1450: $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1451: } else {
1452: $output .= $userenv{$item};
1453: }
1.206 raeburn 1454: if ($item eq 'id') {
1.219 raeburn 1455: $showforceid = $canmodify{$item};
1456: }
1.188 raeburn 1457: }
1458: $output .= &Apache::lonhtmlcommon::row_closure(1);
1459: }
1460: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 1461: if (wantarray) {
1462: return ($output,$showforceid);
1463: } else {
1464: return $output;
1465: }
1.188 raeburn 1466: }
1467:
1.4 www 1468: # ================================================================= Phase Three
1.42 matthew 1469: sub update_user_data {
1.206 raeburn 1470: my ($r,$context) = @_;
1.101 albertel 1471: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
1472: $env{'form.ccdomain'});
1.27 matthew 1473: # Error messages
1.188 raeburn 1474: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 1475: my $end = '</span><br /><br />';
1476: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 1477: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 1478: &mt('Return to previous page').'</a>'.
1479: &Apache::loncommon::end_page();
1480: my $now = time;
1.40 www 1481: my $title;
1.101 albertel 1482: if (exists($env{'form.makeuser'})) {
1.40 www 1483: $title='Set Privileges for New User';
1484: } else {
1485: $title='Modify User Privileges';
1486: }
1.213 raeburn 1487: my $newuser = 0;
1.160 raeburn 1488: my ($jsback,$elements) = &crumb_utilities();
1489: my $jscript = '<script type="text/javascript">'."\n".
1490: $jsback."\n".'</script>'."\n";
1.213 raeburn 1491: my %breadcrumb_text = &singleuser_breadcrumb();
1.233 ! raeburn 1492: my $args;
! 1493: if ($env{'form.popup'}) {
! 1494: $args->{'no_nav_bar'} = 1;
! 1495: } else {
! 1496: $args = undef;
! 1497: }
! 1498: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.160 raeburn 1499: &Apache::lonhtmlcommon::add_breadcrumb
1500: ({href=>"javascript:backPage(document.userupdate)",
1.213 raeburn 1501: text=>$breadcrumb_text{'search'},
1.160 raeburn 1502: faq=>282,bug=>'Instructor Interface',});
1503: if ($env{'form.prevphase'} eq 'userpicked') {
1504: &Apache::lonhtmlcommon::add_breadcrumb
1505: ({href=>"javascript:backPage(document.userupdate,'get_user_info','select')",
1.213 raeburn 1506: text=>$breadcrumb_text{'userpicked'},
1.160 raeburn 1507: faq=>282,bug=>'Instructor Interface',});
1508: }
1509: &Apache::lonhtmlcommon::add_breadcrumb
1510: ({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
1.219 raeburn 1511: text=>$breadcrumb_text{'modify'},
1.160 raeburn 1512: faq=>282,bug=>'Instructor Interface',},
1513: {href=>"/adm/createuser",
1514: text=>"Result",
1515: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 1516: my $helpitem = 'Course_Change_Privileges';
1517: if ($env{'form.action'} eq 'singlestudent') {
1518: $helpitem = 'Course_Add_Student';
1519: }
1520: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
1521: $helpitem));
1.188 raeburn 1522: $r->print(&update_result_form($uhome));
1.27 matthew 1523: # Check Inputs
1.101 albertel 1524: if (! $env{'form.ccuname'} ) {
1.193 raeburn 1525: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 1526: return;
1527: }
1.138 albertel 1528: if ( $env{'form.ccuname'} ne
1529: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.73 sakharuk 1530: $r->print($error.&mt('Invalid login name').'. '.
1.160 raeburn 1531: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid').'.'.
1.193 raeburn 1532: $end.$rtnlink);
1.27 matthew 1533: return;
1534: }
1.101 albertel 1535: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 1536: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 1537: return;
1538: }
1.138 albertel 1539: if ( $env{'form.ccdomain'} ne
1540: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.73 sakharuk 1541: $r->print($error.&mt ('Invalid domain name').'. '.
1.138 albertel 1542: &mt('Only letters, numbers, periods, dashes, and underscores are valid').'.'.
1.193 raeburn 1543: $end.$rtnlink);
1.27 matthew 1544: return;
1545: }
1.219 raeburn 1546: if ($uhome eq 'no_host') {
1547: $newuser = 1;
1548: }
1.101 albertel 1549: if (! exists($env{'form.makeuser'})) {
1.29 matthew 1550: # Modifying an existing user, so check the validity of the name
1551: if ($uhome eq 'no_host') {
1.73 sakharuk 1552: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 1553: $env{'form.ccuname'}.&mt(' in domain ').
1554: $env{'form.ccdomain'}.'.');
1.29 matthew 1555: return;
1556: }
1557: }
1.27 matthew 1558: # Determine authentication method and password for the user being modified
1559: my $amode='';
1560: my $genpwd='';
1.101 albertel 1561: if ($env{'form.login'} eq 'krb') {
1.41 albertel 1562: $amode='krb';
1.101 albertel 1563: $amode.=$env{'form.krbver'};
1564: $genpwd=$env{'form.krbarg'};
1565: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 1566: $amode='internal';
1.101 albertel 1567: $genpwd=$env{'form.intarg'};
1568: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 1569: $amode='unix';
1.101 albertel 1570: $genpwd=$env{'form.fsysarg'};
1571: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 1572: $amode='localauth';
1.101 albertel 1573: $genpwd=$env{'form.locarg'};
1.27 matthew 1574: $genpwd=" " if (!$genpwd);
1.101 albertel 1575: } elsif (($env{'form.login'} eq 'nochange') ||
1576: ($env{'form.login'} eq '' )) {
1.34 matthew 1577: # There is no need to tell the user we did not change what they
1578: # did not ask us to change.
1.35 matthew 1579: # If they are creating a new user but have not specified login
1580: # information this will be caught below.
1.30 matthew 1581: } else {
1.193 raeburn 1582: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.30 matthew 1583: return;
1.27 matthew 1584: }
1.164 albertel 1585:
1.188 raeburn 1586: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1587: $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h3>');
1.193 raeburn 1588: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.101 albertel 1589: if ($env{'form.makeuser'}) {
1.164 albertel 1590: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 1591: # Check for the authentication mode and password
1592: if (! $amode || ! $genpwd) {
1.193 raeburn 1593: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 1594: return;
1.18 albertel 1595: }
1.29 matthew 1596: # Determine desired host
1.101 albertel 1597: my $desiredhost = $env{'form.hserver'};
1.29 matthew 1598: if (lc($desiredhost) eq 'default') {
1599: $desiredhost = undef;
1600: } else {
1.147 albertel 1601: my %home_servers =
1602: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 1603: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 1604: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
1605: return;
1606: }
1607: }
1608: # Check ID format
1609: my %checkhash;
1610: my %checks = ('id' => 1);
1611: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 1612: 'newuser' => $newuser,
1.196 raeburn 1613: 'id' => $env{'form.cid'},
1.193 raeburn 1614: );
1.196 raeburn 1615: if ($env{'form.cid'} ne '') {
1616: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
1617: \%rulematch,\%inst_results,\%curr_rules);
1618: if (ref($alerts{'id'}) eq 'HASH') {
1619: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1620: my $domdesc =
1621: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
1622: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
1623: my $userchkmsg;
1624: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
1625: $userchkmsg =
1626: &Apache::loncommon::instrule_disallow_msg('id',
1627: $domdesc,1).
1628: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
1629: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
1630: }
1631: $r->print($error.&mt('Invalid ID format').$end.
1632: $userchkmsg.$rtnlink);
1633: return;
1634: }
1635: }
1.29 matthew 1636: }
1637: }
1.27 matthew 1638: # Call modifyuser
1639: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 1640: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 1641: $amode,$genpwd,$env{'form.cfirstname'},
1642: $env{'form.cmiddlename'},$env{'form.clastname'},
1643: $env{'form.cgeneration'},undef,$desiredhost,
1644: $env{'form.cpermanentemail'});
1.77 www 1645: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 1646: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 1647: $env{'form.ccdomain'});
1.232 raeburn 1648: if (($uhome ne 'no_host') && ($env{'form.customquota'} == 1)) {
1649: my (%changeHash,$newportfolioquota);
1650: if ($env{'form.portfolioquota'} eq '') {
1651: $newportfolioquota = 0;
1652: } else {
1653: $newportfolioquota = $env{'form.portfolioquota'};
1654: $newportfolioquota =~ s/[^\d\.]//g;
1655: }
1656: my $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1657: if ($quotachanged) {
1658: $changeHash{'firstname'} = $env{'form.cfirstname'};
1659: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1660: $changeHash{'lastname'} = $env{'form.clastname'};
1661: $changeHash{'generation'} = $env{'form.cgeneration'};
1662: $changeHash{'id'} = $env{'form.cid'};
1663: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1664: my $quotachgresult =
1665: &Apache::lonnet::put('environment',\%changeHash,
1666: $env{'form.ccdomain'},$env{'form.ccuname'});
1667: }
1668: }
1.219 raeburn 1669: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
1670: &Apache::lonnet::hostname($uhome));
1.101 albertel 1671: } elsif (($env{'form.login'} ne 'nochange') &&
1672: ($env{'form.login'} ne '' )) {
1.27 matthew 1673: # Modify user privileges
1674: if (! $amode || ! $genpwd) {
1.193 raeburn 1675: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 1676: return;
1.20 harris41 1677: }
1.27 matthew 1678: # Only allow authentification modification if the person has authority
1.101 albertel 1679: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 1680: $r->print('Modifying authentication: '.
1.31 matthew 1681: &Apache::lonnet::modifyuserauth(
1.101 albertel 1682: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 1683: $amode,$genpwd));
1.102 albertel 1684: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 1685: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 1686: } else {
1.27 matthew 1687: # Okay, this is a non-fatal error.
1.193 raeburn 1688: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
1.27 matthew 1689: }
1.28 matthew 1690: }
1691: ##
1.213 raeburn 1692: my (@userroles,%userupdate,$cnum,$cdom,$namechanged);
1693: if ($context eq 'course') {
1694: ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1695: }
1.101 albertel 1696: if (! $env{'form.makeuser'} ) {
1.28 matthew 1697: # Check for need to change
1698: my %userenv = &Apache::lonnet::get
1.134 raeburn 1699: ('environment',['firstname','middlename','lastname','generation',
1.196 raeburn 1700: 'id','permanentemail','portfolioquota','inststatus'],
1.160 raeburn 1701: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 1702: my ($tmp) = keys(%userenv);
1703: if ($tmp =~ /^(con_lost|error)/i) {
1704: %userenv = ();
1705: }
1.206 raeburn 1706: my $no_forceid_alert;
1707: # Check to see if user information can be changed
1708: my %domconfig =
1709: &Apache::lonnet::get_dom('configuration',['usermodification'],
1710: $env{'form.ccdomain'});
1.213 raeburn 1711: my @statuses = ('active','future');
1712: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
1713: my ($auname,$audom);
1.220 raeburn 1714: if ($context eq 'author') {
1.206 raeburn 1715: $auname = $env{'user.name'};
1716: $audom = $env{'user.domain'};
1717: }
1718: foreach my $item (keys(%roles)) {
1.220 raeburn 1719: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 1720: if ($context eq 'course') {
1721: if ($cnum ne '' && $cdom ne '') {
1722: if ($rolenum eq $cnum && $roledom eq $cdom) {
1723: if (!grep(/^\Q$role\E$/,@userroles)) {
1724: push(@userroles,$role);
1725: }
1726: }
1727: }
1728: } elsif ($context eq 'author') {
1729: if ($rolenum eq $auname && $roledom eq $audom) {
1730: if (!grep(/^\Q$role\E$/,@userroles)) {
1731: push(@userroles,$role);
1732: }
1733: }
1734: }
1735: }
1.220 raeburn 1736: if ($env{'form.action'} eq 'singlestudent') {
1737: if (!grep(/^st$/,@userroles)) {
1738: push(@userroles,'st');
1739: }
1740: } else {
1741: # Check for course or co-author roles being activated or re-enabled
1742: if ($context eq 'author' || $context eq 'course') {
1743: foreach my $key (keys(%env)) {
1744: if ($context eq 'author') {
1745: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
1746: if (!grep(/^\Q$1\E$/,@userroles)) {
1747: push(@userroles,$1);
1748: }
1749: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
1750: if (!grep(/^\Q$1\E$/,@userroles)) {
1751: push(@userroles,$1);
1752: }
1.206 raeburn 1753: }
1.220 raeburn 1754: } elsif ($context eq 'course') {
1755: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
1756: if (!grep(/^\Q$1\E$/,@userroles)) {
1757: push(@userroles,$1);
1758: }
1759: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
1760: if (!grep(/^\Q$1\E$/,@userroles)) {
1761: push(@userroles,$1);
1762: }
1.206 raeburn 1763: }
1764: }
1765: }
1766: }
1767: }
1768: #Check to see if we can change personal data for the user
1769: my (@mod_disallowed,@longroles);
1770: foreach my $role (@userroles) {
1771: if ($role eq 'cr') {
1772: push(@longroles,'Custom');
1773: } else {
1774: push(@longroles,&Apache::lonnet::plaintext($role));
1775: }
1776: }
1.219 raeburn 1777: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1778: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
1779: foreach my $item (@userinfo) {
1.28 matthew 1780: # Strip leading and trailing whitespace
1.203 raeburn 1781: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 1782: if (!$canmodify{$item}) {
1.207 raeburn 1783: if (defined($env{'form.c'.$item})) {
1784: if ($env{'form.c'.$item} ne $userenv{$item}) {
1785: push(@mod_disallowed,$item);
1786: }
1.206 raeburn 1787: }
1788: $env{'form.c'.$item} = $userenv{$item};
1789: }
1.28 matthew 1790: }
1.196 raeburn 1791: # Check to see if we can change the ID/student number
1792: my $forceid = $env{'form.forceid'};
1793: my $recurseid = $env{'form.recurseid'};
1794: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 1795: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
1796: $env{'form.ccuname'});
1797: if (($uidhash{$env{'form.ccuname'}}) &&
1798: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
1799: (!$forceid)) {
1800: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
1801: $env{'form.cid'} = $userenv{'id'};
1.206 raeburn 1802: $no_forceid_alert = &mt('New student/employeeID does not match existing ID for this user.').'<br />'.&mt('Change is not permitted without checking the \'Force ID change\' checkbox on the previous page.').'<br />'."\n";
1.203 raeburn 1803: }
1804: }
1805: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 1806: my $checkhash;
1807: my $checks = { 'id' => 1 };
1808: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
1809: { 'newuser' => $newuser,
1810: 'id' => $env{'form.cid'},
1811: };
1812: &Apache::loncommon::user_rule_check($checkhash,$checks,
1813: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
1814: if (ref($alerts{'id'}) eq 'HASH') {
1815: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 1816: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 1817: }
1818: }
1819: }
1.213 raeburn 1820: my ($quotachanged,$oldportfolioquota,$newportfolioquota,
1.204 raeburn 1821: $inststatus,$oldisdefault,$newisdefault,$olddefquotatext,
1822: $newdefquotatext);
1.149 raeburn 1823: my ($defquota,$settingstatus) =
1824: &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
1.220 raeburn 1825: my $showquota;
1826: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1827: $showquota = 1;
1828: }
1.134 raeburn 1829: my %changeHash;
1.204 raeburn 1830: $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
1.149 raeburn 1831: if ($userenv{'portfolioquota'} ne '') {
1.134 raeburn 1832: $oldportfolioquota = $userenv{'portfolioquota'};
1.149 raeburn 1833: if ($env{'form.customquota'} == 1) {
1834: if ($env{'form.portfolioquota'} eq '') {
1835: $newportfolioquota = 0;
1836: } else {
1837: $newportfolioquota = $env{'form.portfolioquota'};
1838: $newportfolioquota =~ s/[^\d\.]//g;
1839: }
1.204 raeburn 1840: if ($newportfolioquota != $oldportfolioquota) {
1.149 raeburn 1841: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1.134 raeburn 1842: }
1.149 raeburn 1843: } else {
1844: $quotachanged = "a_admin('',\%changeHash);
1845: $newportfolioquota = $defquota;
1.204 raeburn 1846: $newisdefault = 1;
1.134 raeburn 1847: }
1848: } else {
1.204 raeburn 1849: $oldisdefault = 1;
1.149 raeburn 1850: $oldportfolioquota = $defquota;
1851: if ($env{'form.customquota'} == 1) {
1852: if ($env{'form.portfolioquota'} eq '') {
1853: $newportfolioquota = 0;
1854: } else {
1855: $newportfolioquota = $env{'form.portfolioquota'};
1856: $newportfolioquota =~ s/[^\d\.]//g;
1857: }
1858: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1859: } else {
1860: $newportfolioquota = $defquota;
1.204 raeburn 1861: $newisdefault = 1;
1.149 raeburn 1862: }
1863: }
1.204 raeburn 1864: if ($oldisdefault) {
1865: $olddefquotatext = &get_defaultquota_text($settingstatus);
1866: }
1867: if ($newisdefault) {
1868: $newdefquotatext = &get_defaultquota_text($settingstatus);
1.134 raeburn 1869: }
1.206 raeburn 1870: if ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
1871: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
1872: $env{'form.clastname'} ne $userenv{'lastname'} ||
1873: $env{'form.cgeneration'} ne $userenv{'generation'} ||
1874: $env{'form.cid'} ne $userenv{'id'} ||
1875: $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} ) {
1.134 raeburn 1876: $namechanged = 1;
1877: }
1.204 raeburn 1878: if ($namechanged || $quotachanged) {
1.101 albertel 1879: $changeHash{'firstname'} = $env{'form.cfirstname'};
1880: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1881: $changeHash{'lastname'} = $env{'form.clastname'};
1882: $changeHash{'generation'} = $env{'form.cgeneration'};
1.196 raeburn 1883: $changeHash{'id'} = $env{'form.cid'};
1.174 raeburn 1884: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1.204 raeburn 1885: my ($quotachgresult,$namechgresult);
1886: if ($quotachanged) {
1887: $quotachgresult =
1888: &Apache::lonnet::put('environment',\%changeHash,
1889: $env{'form.ccdomain'},$env{'form.ccuname'});
1890: }
1891: if ($namechanged) {
1892: # Make the change
1893: $namechgresult =
1894: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
1895: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
1896: $changeHash{'firstname'},$changeHash{'middlename'},
1897: $changeHash{'lastname'},$changeHash{'generation'},
1898: $changeHash{'id'},undef,$changeHash{'permanentemail'});
1.220 raeburn 1899: %userupdate = (
1900: lastname => $env{'form.clastname'},
1901: middlename => $env{'form.cmiddlename'},
1902: firstname => $env{'form.cfirstname'},
1903: generation => $env{'form.cgeneration'},
1904: id => $env{'form.cid'},
1905: );
1.204 raeburn 1906: }
1907: if (($namechanged && $namechgresult eq 'ok') ||
1908: ($quotachanged && $quotachgresult eq 'ok')) {
1.28 matthew 1909: # Tell the user we changed the name
1.73 sakharuk 1910: my %lt=&Apache::lonlocal::texthash(
1911: 'uic' => "User Information Changed",
1912: 'frst' => "first",
1913: 'mddl' => "middle",
1914: 'lst' => "last",
1915: 'gen' => "generation",
1.196 raeburn 1916: 'id' => "ID/Student number",
1.160 raeburn 1917: 'mail' => "permanent e-mail",
1.134 raeburn 1918: 'disk' => "disk space allocated to portfolio files",
1.73 sakharuk 1919: 'prvs' => "Previous",
1920: 'chto' => "Changed To"
1921: );
1.201 raeburn 1922: $r->print('<h4>'.$lt{'uic'}.'</h4>'.
1923: &Apache::loncommon::start_data_table().
1924: &Apache::loncommon::start_data_table_header_row());
1.28 matthew 1925: $r->print(<<"END");
1.201 raeburn 1926: <th> </th>
1.73 sakharuk 1927: <th>$lt{'frst'}</th>
1928: <th>$lt{'mddl'}</th>
1929: <th>$lt{'lst'}</th>
1.134 raeburn 1930: <th>$lt{'gen'}</th>
1.196 raeburn 1931: <th>$lt{'id'}</th>
1.173 raeburn 1932: <th>$lt{'mail'}</th>
1.201 raeburn 1933: END
1.220 raeburn 1934: if ($showquota) {
1935: $r->print("
1936: <th>$lt{'disk'}</th>\n");
1937: }
1.201 raeburn 1938: $r->print(&Apache::loncommon::end_data_table_header_row().
1939: &Apache::loncommon::start_data_table_row());
1940: $r->print(<<"END");
1941: <td><b>$lt{'prvs'}</b></td>
1.28 matthew 1942: <td>$userenv{'firstname'} </td>
1943: <td>$userenv{'middlename'} </td>
1944: <td>$userenv{'lastname'} </td>
1.134 raeburn 1945: <td>$userenv{'generation'} </td>
1.196 raeburn 1946: <td>$userenv{'id'}</td>
1.160 raeburn 1947: <td>$userenv{'permanentemail'} </td>
1.201 raeburn 1948: END
1.220 raeburn 1949: if ($showquota) {
1950: $r->print("
1951: <td>$oldportfolioquota Mb $olddefquotatext </td>\n");
1952: }
1.201 raeburn 1953: $r->print(&Apache::loncommon::end_data_table_row().
1954: &Apache::loncommon::start_data_table_row());
1955: $r->print(<<"END");
1956: <td><b>$lt{'chto'}</b></td>
1.101 albertel 1957: <td>$env{'form.cfirstname'} </td>
1958: <td>$env{'form.cmiddlename'} </td>
1959: <td>$env{'form.clastname'} </td>
1.134 raeburn 1960: <td>$env{'form.cgeneration'} </td>
1.196 raeburn 1961: <td>$env{'form.cid'} </td>
1.160 raeburn 1962: <td>$env{'form.cpermanentemail'} </td>
1.28 matthew 1963: END
1.220 raeburn 1964: if ($showquota) {
1965: $r->print("
1966: <td>$newportfolioquota Mb $newdefquotatext </td>\n");
1967: }
1.201 raeburn 1968: $r->print(&Apache::loncommon::end_data_table_row().
1.206 raeburn 1969: &Apache::loncommon::end_data_table().'<br />');
1.203 raeburn 1970: if ($env{'form.cid'} ne $userenv{'id'}) {
1971: &Apache::lonnet::idput($env{'form.ccdomain'},
1972: ($env{'form.ccuname'} => $env{'form.cid'}));
1973: if (($recurseid) &&
1974: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
1975: my $idresult =
1976: &Apache::lonuserutils::propagate_id_change(
1977: $env{'form.ccuname'},$env{'form.ccdomain'},
1978: \%userupdate);
1979: $r->print('<br />'.$idresult.'<br />');
1980: }
1.196 raeburn 1981: }
1.149 raeburn 1982: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
1983: ($env{'form.ccuname'} eq $env{'user.name'})) {
1984: my %newenvhash;
1985: foreach my $key (keys(%changeHash)) {
1986: $newenvhash{'environment.'.$key} = $changeHash{$key};
1987: }
1988: &Apache::lonnet::appenv(%newenvhash);
1989: }
1.28 matthew 1990: } else { # error occurred
1.188 raeburn 1991: $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
1992: $env{'form.ccuname'}.' '.&mt('in domain').' '.
1.206 raeburn 1993: $env{'form.ccdomain'}.'</span><br />');
1.28 matthew 1994: }
1.101 albertel 1995: } else { # End of if ($env ... ) logic
1.204 raeburn 1996: # They did not want to change the users name or quota but we can
1997: # still tell them what the name and quota are
1.73 sakharuk 1998: my %lt=&Apache::lonlocal::texthash(
1.196 raeburn 1999: 'id' => "ID/Student number",
1.160 raeburn 2000: 'mail' => "Permanent e-mail",
1.134 raeburn 2001: 'disk' => "Disk space allocated to user's portfolio files",
1.73 sakharuk 2002: );
1.134 raeburn 2003: $r->print(<<"END");
1.196 raeburn 2004: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
1.28 matthew 2005: END
1.204 raeburn 2006: if ($userenv{'permanentemail'} ne '') {
2007: $r->print('<br />['.$lt{'mail'}.': '.
2008: $userenv{'permanentemail'}.']');
1.134 raeburn 2009: }
1.220 raeburn 2010: if ($showquota) {
2011: $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '.
2012: $olddefquotatext.']');
2013: }
2014: $r->print('</h4>');
1.28 matthew 2015: }
1.206 raeburn 2016: if (@mod_disallowed) {
2017: my ($rolestr,$contextname);
2018: if (@longroles > 0) {
2019: $rolestr = join(', ',@longroles);
2020: } else {
2021: $rolestr = &mt('No roles');
2022: }
2023: if ($context eq 'course') {
2024: $contextname = &mt('course');
2025: } elsif ($context eq 'author') {
2026: $contextname = &mt('co-author');
2027: }
2028: $r->print(&mt('The following fields were not updated: ').'<ul>');
2029: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2030: foreach my $field (@mod_disallowed) {
2031: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
2032: }
1.207 raeburn 2033: $r->print('</ul>');
2034: if (@mod_disallowed == 1) {
2035: $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future [_1] roles:",$contextname));
2036: } else {
2037: $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future [_1] roles:",$contextname));
2038: }
2039: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'.
2040: &mt('Contact your <a href="[_1]">helpdesk</a> for more information.',"javascript:helpMenu('display')").'<br />');
1.206 raeburn 2041: }
2042: $r->print($no_forceid_alert.
2043: &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts, \%curr_rules));
1.4 www 2044: }
1.220 raeburn 2045: if ($env{'form.action'} eq 'singlestudent') {
2046: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser);
1.226 raeburn 2047: $r->print('<p><a href="javascript:backPage(document.userupdate)">'. &mt('Enroll Another Student').'</a></p>');
1.220 raeburn 2048: } else {
1.225 raeburn 2049: my @rolechanges = &update_roles($r);
2050: if ($namechanged) {
1.220 raeburn 2051: if ($context eq 'course') {
2052: if (@userroles > 0) {
1.225 raeburn 2053: if ((@rolechanges == 0) ||
2054: (!(grep(/^st$/,@rolechanges)))) {
2055: if (grep(/^st$/,@userroles)) {
2056: my $classlistupdated =
2057: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 2058: $cnum,$env{'form.ccdomain'},
2059: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 2060: }
1.220 raeburn 2061: }
2062: }
2063: }
2064: }
1.226 raeburn 2065: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 ! raeburn 2066: $env{'form.ccdomain'});
! 2067: if ($env{'form.popup'}) {
! 2068: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
! 2069: } else {
! 2070: $r->print('<p><a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'.&mt('Modify this user: <span class="LC_cusr_emph">([_1])</span>',$userinfo).'</a>'.(' 'x5).'<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a></p>');
! 2071: }
1.220 raeburn 2072: }
2073: $r->print(&Apache::loncommon::end_page());
2074: }
2075:
2076: sub update_roles {
2077: my ($r) = @_;
1.4 www 2078: my $now=time;
1.225 raeburn 2079: my @rolechanges;
1.220 raeburn 2080: my %disallowed;
1.73 sakharuk 2081: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 2082: foreach my $key (keys (%env)) {
2083: next if (! $env{$key});
1.190 raeburn 2084: next if ($key eq 'form.action');
1.27 matthew 2085: # Revoke roles
1.135 raeburn 2086: if ($key=~/^form\.rev/) {
2087: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 2088: # Revoke standard role
1.170 albertel 2089: my ($scope,$role) = ($1,$2);
2090: my $result =
2091: &Apache::lonnet::revokerole($env{'form.ccdomain'},
2092: $env{'form.ccuname'},
2093: $scope,$role);
2094: $r->print(&mt('Revoking [_1] in [_2]: [_3]',
2095: $role,$scope,'<b>'.$result.'</b>').'<br />');
2096: if ($role eq 'st') {
1.202 raeburn 2097: my $result =
1.198 raeburn 2098: &Apache::lonuserutils::classlist_drop($scope,
2099: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 2100: $now);
1.170 albertel 2101: $r->print($result);
1.53 www 2102: }
1.225 raeburn 2103: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2104: push(@rolechanges,$role);
2105: }
1.196 raeburn 2106: }
1.195 raeburn 2107: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 2108: # Revoke custom role
1.113 raeburn 2109: $r->print(&mt('Revoking custom role:').
1.139 albertel 2110: ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
1.101 albertel 2111: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
2112: $env{'form.ccuname'},$1,$2,$3,$4).
1.102 albertel 2113: '</b><br />');
1.225 raeburn 2114: if (!grep(/^cr$/,@rolechanges)) {
2115: push(@rolechanges,'cr');
2116: }
1.64 www 2117: }
1.135 raeburn 2118: } elsif ($key=~/^form\.del/) {
2119: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 2120: # Delete standard role
1.170 albertel 2121: my ($scope,$role) = ($1,$2);
2122: my $result =
2123: &Apache::lonnet::assignrole($env{'form.ccdomain'},
2124: $env{'form.ccuname'},
2125: $scope,$role,$now,0,1);
2126: $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
2127: '<b>'.$result.'</b>').'<br />');
2128: if ($role eq 'st') {
1.202 raeburn 2129: my $result =
1.198 raeburn 2130: &Apache::lonuserutils::classlist_drop($scope,
2131: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 2132: $now);
1.170 albertel 2133: $r->print($result);
1.81 albertel 2134: }
1.225 raeburn 2135: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2136: push(@rolechanges,$role);
2137: }
1.116 raeburn 2138: }
1.139 albertel 2139: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 2140: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
2141: # Delete custom role
1.170 albertel 2142: $r->print(&mt('Deleting custom role [_1] by [_2]:[_3] in [_4]',
1.116 raeburn 2143: $rolename,$rnam,$rdom,$url).': <b>'.
2144: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
2145: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
2146: 0,1).'</b><br />');
1.225 raeburn 2147: if (!grep(/^cr$/,@rolechanges)) {
2148: push(@rolechanges,'cr');
2149: }
1.116 raeburn 2150: }
1.135 raeburn 2151: } elsif ($key=~/^form\.ren/) {
1.101 albertel 2152: my $udom = $env{'form.ccdomain'};
2153: my $uname = $env{'form.ccuname'};
1.116 raeburn 2154: # Re-enable standard role
1.135 raeburn 2155: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 2156: my $url = $1;
2157: my $role = $2;
2158: my $logmsg;
2159: my $output;
2160: if ($role eq 'st') {
1.141 albertel 2161: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.129 albertel 2162: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.220 raeburn 2163: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 2164: if ($result eq 'refused' && $logmsg) {
2165: $output = $logmsg;
2166: } else {
2167: $output = "Error: $result\n";
2168: }
1.89 raeburn 2169: } else {
2170: $output = &mt('Assigning').' '.$role.' in '.$url.
2171: &mt('starting').' '.localtime($now).
2172: ': <br />'.$logmsg.'<br />'.
2173: &mt('Add to classlist').': <b>ok</b><br />';
2174: }
2175: }
2176: } else {
1.101 albertel 2177: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
2178: $env{'form.ccuname'},$url,$role,0,$now);
1.116 raeburn 2179: $output = &mt('Re-enabling [_1] in [_2]: <b>[_3]</b>',
1.89 raeburn 2180: $role,$url,$result).'<br />';
1.27 matthew 2181: }
1.89 raeburn 2182: $r->print($output);
1.225 raeburn 2183: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2184: push(@rolechanges,$role);
2185: }
1.113 raeburn 2186: }
1.116 raeburn 2187: # Re-enable custom role
1.139 albertel 2188: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 2189: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
2190: my $result = &Apache::lonnet::assigncustomrole(
2191: $env{'form.ccdomain'}, $env{'form.ccuname'},
2192: $url,$rdom,$rnam,$rolename,0,$now);
2193: $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : <b>[_5]</b>',
2194: $rolename,$rnam,$rdom,$url,$result).'<br />');
1.225 raeburn 2195: if (!grep(/^cr$/,@rolechanges)) {
2196: push(@rolechanges,'cr');
2197: }
1.116 raeburn 2198: }
1.135 raeburn 2199: } elsif ($key=~/^form\.act/) {
1.101 albertel 2200: my $udom = $env{'form.ccdomain'};
2201: my $uname = $env{'form.ccuname'};
1.141 albertel 2202: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 2203: # Activate a custom role
1.83 albertel 2204: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
2205: my $url='/'.$one.'/'.$two;
2206: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 2207:
1.101 albertel 2208: my $start = ( $env{'form.start_'.$full} ?
2209: $env{'form.start_'.$full} :
1.88 raeburn 2210: $now );
1.101 albertel 2211: my $end = ( $env{'form.end_'.$full} ?
2212: $env{'form.end_'.$full} :
1.88 raeburn 2213: 0 );
2214:
2215: # split multiple sections
2216: my %sections = ();
1.101 albertel 2217: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 2218: if ($num_sections == 0) {
1.129 albertel 2219: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
1.88 raeburn 2220: } else {
1.114 albertel 2221: my %curr_groups =
1.117 raeburn 2222: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 2223: foreach my $sec (sort {$a cmp $b} keys %sections) {
2224: if (($sec eq 'none') || ($sec eq 'all') ||
2225: exists($curr_groups{$sec})) {
2226: $disallowed{$sec} = $url;
2227: next;
2228: }
2229: my $securl = $url.'/'.$sec;
1.129 albertel 2230: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
1.88 raeburn 2231: }
2232: }
1.225 raeburn 2233: if (!grep(/^cr$/,@rolechanges)) {
2234: push(@rolechanges,'cr');
2235: }
1.142 raeburn 2236: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 2237: # Activate roles for sections with 3 id numbers
2238: # set start, end times, and the url for the class
1.83 albertel 2239: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 2240: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
2241: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 2242: $now );
1.101 albertel 2243: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
2244: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 2245: 0 );
1.83 albertel 2246: my $url='/'.$one.'/'.$two;
1.88 raeburn 2247: my $type = 'three';
2248: # split multiple sections
2249: my %sections = ();
1.101 albertel 2250: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 2251: if ($num_sections == 0) {
1.129 albertel 2252: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 2253: } else {
1.114 albertel 2254: my %curr_groups =
1.117 raeburn 2255: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 2256: my $emptysec = 0;
2257: foreach my $sec (sort {$a cmp $b} keys %sections) {
2258: $sec =~ s/\W//g;
1.113 raeburn 2259: if ($sec ne '') {
2260: if (($sec eq 'none') || ($sec eq 'all') ||
2261: exists($curr_groups{$sec})) {
2262: $disallowed{$sec} = $url;
2263: next;
2264: }
1.88 raeburn 2265: my $securl = $url.'/'.$sec;
1.129 albertel 2266: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
1.88 raeburn 2267: } else {
2268: $emptysec = 1;
2269: }
2270: }
2271: if ($emptysec) {
1.129 albertel 2272: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 2273: }
1.225 raeburn 2274: }
2275: if (!grep(/^\Q$three\E$/,@rolechanges)) {
2276: push(@rolechanges,$three);
2277: }
1.135 raeburn 2278: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 2279: # Activate roles for sections with two id numbers
2280: # set start, end times, and the url for the class
1.101 albertel 2281: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
2282: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 2283: $now );
1.101 albertel 2284: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
2285: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 2286: 0 );
1.225 raeburn 2287: my $one = $1;
2288: my $two = $2;
2289: my $url='/'.$one.'/';
1.88 raeburn 2290: # split multiple sections
2291: my %sections = ();
1.225 raeburn 2292: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 2293: if ($num_sections == 0) {
1.225 raeburn 2294: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,''));
1.88 raeburn 2295: } else {
2296: my $emptysec = 0;
2297: foreach my $sec (sort {$a cmp $b} keys %sections) {
2298: if ($sec ne '') {
2299: my $securl = $url.'/'.$sec;
1.225 raeburn 2300: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec));
1.88 raeburn 2301: } else {
2302: $emptysec = 1;
2303: }
2304: }
2305: if ($emptysec) {
1.225 raeburn 2306: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,''));
1.88 raeburn 2307: }
2308: }
1.225 raeburn 2309: if (!grep(/^\Q$two\E$/,@rolechanges)) {
2310: push(@rolechanges,$two);
2311: }
1.64 www 2312: } else {
1.190 raeburn 2313: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 2314: }
1.113 raeburn 2315: foreach my $key (sort(keys(%disallowed))) {
2316: if (($key eq 'none') || ($key eq 'all')) {
2317: $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
2318: } else {
2319: $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));
2320: }
2321: $r->print(' '.&mt('Please <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />');
2322: }
2323: }
1.101 albertel 2324: } # End of foreach (keys(%env))
1.75 www 2325: # Flush the course logs so reverse user roles immediately updated
2326: &Apache::lonnet::flushcourselogs();
1.225 raeburn 2327: if (@rolechanges == 0) {
1.193 raeburn 2328: $r->print(&mt('No roles to modify'));
2329: }
1.225 raeburn 2330: return @rolechanges;
1.220 raeburn 2331: }
2332:
2333: sub enroll_single_student {
2334: my ($r,$uhome,$amode,$genpwd,$now,$newuser) = @_;
2335: $r->print('<h3>'.&mt('Enrolling Student').'</h3>');
2336:
2337: # Remove non alphanumeric values from section
2338: $env{'form.sections'}=~s/\W//g;
2339:
2340: # Clean out any old student roles the user has in this class.
2341: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
2342: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
2343: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
2344: my $enroll_result =
2345: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
2346: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
2347: $env{'form.cmiddlename'},$env{'form.clastname'},
2348: $env{'form.generation'},$env{'form.sections'},$enddate,
2349: $startdate,'manual',undef,$env{'request.course.id'});
2350: if ($enroll_result =~ /^ok/) {
2351: $r->print(&mt('<b>[_1]</b> enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'}));
2352: if ($env{'form.sections'} ne '') {
2353: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
2354: }
2355: my ($showstart,$showend);
2356: if ($startdate <= $now) {
2357: $showstart = &mt('Access starts immediately');
2358: } else {
2359: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
2360: }
2361: if ($enddate == 0) {
2362: $showend = &mt('ends: no ending date');
2363: } else {
2364: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
2365: }
2366: $r->print('.<br />'.$showstart.'; '.$showend);
2367: if ($startdate <= $now && !$newuser) {
2368: $r->print("<p> ".&mt('If the student is currently logged-in to LON-CAPA, the new role will be available when the student next logs in.')."</p>");
2369: }
2370: } else {
2371: $r->print(&mt('unable to enroll').": ".$enroll_result);
2372: }
2373: return;
1.188 raeburn 2374: }
2375:
1.204 raeburn 2376: sub get_defaultquota_text {
2377: my ($settingstatus) = @_;
2378: my $defquotatext;
2379: if ($settingstatus eq '') {
2380: $defquotatext = &mt('(default)');
2381: } else {
2382: my ($usertypes,$order) =
2383: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
2384: if ($usertypes->{$settingstatus} eq '') {
2385: $defquotatext = &mt('(default)');
2386: } else {
2387: $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
2388: }
2389: }
2390: return $defquotatext;
2391: }
2392:
1.188 raeburn 2393: sub update_result_form {
2394: my ($uhome) = @_;
2395: my $outcome =
2396: '<form name="userupdate" method="post" />'."\n";
1.160 raeburn 2397: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 2398: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2399: }
1.207 raeburn 2400: if ($env{'form.origname'} ne '') {
2401: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
2402: }
1.160 raeburn 2403: foreach my $item ('sortby','seluname','seludom') {
2404: if (exists($env{'form.'.$item})) {
1.188 raeburn 2405: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2406: }
2407: }
1.188 raeburn 2408: if ($uhome eq 'no_host') {
2409: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
2410: }
2411: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
2412: '<input type ="hidden" name="currstate" value="" />'."\n".
1.220 raeburn 2413: '<input type ="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 2414: '</form>';
2415: return $outcome;
1.4 www 2416: }
2417:
1.149 raeburn 2418: sub quota_admin {
2419: my ($setquota,$changeHash) = @_;
2420: my $quotachanged;
2421: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
2422: # Current user has quota modification privileges
2423: $quotachanged = 1;
2424: $changeHash->{'portfolioquota'} = $setquota;
2425: }
2426: return $quotachanged;
2427: }
2428:
1.88 raeburn 2429: sub build_roles {
1.89 raeburn 2430: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 2431: my $num_sections = 0;
2432: if ($sectionstr=~ /,/) {
2433: my @secnums = split/,/,$sectionstr;
1.89 raeburn 2434: if ($role eq 'st') {
2435: $secnums[0] =~ s/\W//g;
2436: $$sections{$secnums[0]} = 1;
2437: $num_sections = 1;
2438: } else {
2439: foreach my $sec (@secnums) {
2440: $sec =~ ~s/\W//g;
1.150 banghart 2441: if (!($sec eq "")) {
1.89 raeburn 2442: if (exists($$sections{$sec})) {
2443: $$sections{$sec} ++;
2444: } else {
2445: $$sections{$sec} = 1;
2446: $num_sections ++;
2447: }
1.88 raeburn 2448: }
2449: }
2450: }
2451: } else {
2452: $sectionstr=~s/\W//g;
2453: unless ($sectionstr eq '') {
2454: $$sections{$sectionstr} = 1;
2455: $num_sections ++;
2456: }
2457: }
1.129 albertel 2458:
1.88 raeburn 2459: return $num_sections;
2460: }
2461:
1.58 www 2462: # ========================================================== Custom Role Editor
2463:
2464: sub custom_role_editor {
1.160 raeburn 2465: my ($r) = @_;
1.101 albertel 2466: my $rolename=$env{'form.rolename'};
1.58 www 2467:
1.59 www 2468: if ($rolename eq 'make new role') {
1.101 albertel 2469: $rolename=$env{'form.newrolename'};
1.59 www 2470: }
2471:
1.63 www 2472: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 2473:
1.190 raeburn 2474: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.58 www 2475: &print_username_entry_form($r);
2476: return;
2477: }
1.153 banghart 2478: # ------------------------------------------------------- What can be assigned?
2479: my %full=();
2480: my %courselevel=();
2481: my %courselevelcurrent=();
1.61 www 2482: my $syspriv='';
2483: my $dompriv='';
2484: my $coursepriv='';
1.153 banghart 2485: my $body_top;
1.150 banghart 2486: my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
1.59 www 2487: my ($rdummy,$roledef)=
2488: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 2489: # ------------------------------------------------------- Does this role exist?
1.153 banghart 2490: $body_top .= '<h2>';
1.59 www 2491: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 2492: $body_top .= &mt('Existing Role').' "';
1.61 www 2493: # ------------------------------------------------- Get current role privileges
2494: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 2495: } else {
1.153 banghart 2496: $body_top .= &mt('New Role').' "';
1.59 www 2497: $roledef='';
2498: }
1.153 banghart 2499: $body_top .= $rolename.'"</h2>';
1.135 raeburn 2500: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2501: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2502: if (!$restrict) { $restrict='F'; }
1.60 www 2503: $courselevel{$priv}=$restrict;
1.61 www 2504: if ($coursepriv=~/\:$priv/) {
2505: $courselevelcurrent{$priv}=1;
2506: }
1.60 www 2507: $full{$priv}=1;
2508: }
2509: my %domainlevel=();
1.61 www 2510: my %domainlevelcurrent=();
1.135 raeburn 2511: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2512: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2513: if (!$restrict) { $restrict='F'; }
1.60 www 2514: $domainlevel{$priv}=$restrict;
1.61 www 2515: if ($dompriv=~/\:$priv/) {
2516: $domainlevelcurrent{$priv}=1;
2517: }
1.60 www 2518: $full{$priv}=1;
2519: }
1.61 www 2520: my %systemlevel=();
2521: my %systemlevelcurrent=();
1.135 raeburn 2522: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2523: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2524: if (!$restrict) { $restrict='F'; }
1.61 www 2525: $systemlevel{$priv}=$restrict;
2526: if ($syspriv=~/\:$priv/) {
2527: $systemlevelcurrent{$priv}=1;
2528: }
2529: $full{$priv}=1;
2530: }
1.160 raeburn 2531: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 2532: my $button_code = "\n";
1.153 banghart 2533: my $head_script = "\n";
2534: $head_script .= '<script type="text/javascript">'."\n";
1.154 banghart 2535: my @template_roles = ("cc","in","ta","ep","st");
2536: foreach my $role (@template_roles) {
2537: $head_script .= &make_script_template($role);
2538: $button_code .= &make_button_code($role);
2539: }
1.160 raeburn 2540: $head_script .= "\n".$jsback."\n".'</script>'."\n";
1.153 banghart 2541: $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
1.160 raeburn 2542: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 2543: ({href=>"javascript:backPage(document.form1,'pickrole','')",
2544: text=>"Pick custom role",
1.160 raeburn 2545: faq=>282,bug=>'Instructor Interface',},
2546: {href=>"javascript:backPage(document.form1,'','')",
2547: text=>"Edit custom role",
2548: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 2549: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
2550: 'Course_Editing_Custom_Roles'));
1.160 raeburn 2551:
1.153 banghart 2552: $r->print($body_top);
1.73 sakharuk 2553: my %lt=&Apache::lonlocal::texthash(
2554: 'prv' => "Privilege",
1.131 raeburn 2555: 'crl' => "Course Level",
1.73 sakharuk 2556: 'dml' => "Domain Level",
1.150 banghart 2557: 'ssl' => "System Level");
1.152 banghart 2558: $r->print('Select a Template<br />');
1.154 banghart 2559: $r->print('<form action="">');
2560: $r->print($button_code);
2561: $r->print('</form>');
1.61 www 2562: $r->print(<<ENDCCF);
1.160 raeburn 2563: <form name="form1" method="post">
1.61 www 2564: <input type="hidden" name="phase" value="set_custom_roles" />
2565: <input type="hidden" name="rolename" value="$rolename" />
2566: ENDCCF
1.135 raeburn 2567: $r->print(&Apache::loncommon::start_data_table().
2568: &Apache::loncommon::start_data_table_header_row().
2569: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
2570: '</th><th>'.$lt{'ssl'}.'</th>'.
2571: &Apache::loncommon::end_data_table_header_row());
1.119 raeburn 2572: foreach my $priv (sort keys %full) {
2573: my $privtext = &Apache::lonnet::plaintext($priv);
1.135 raeburn 2574: $r->print(&Apache::loncommon::start_data_table_row().
2575: '<td>'.$privtext.'</td><td>'.
1.150 banghart 2576: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c" '.
1.119 raeburn 2577: ($courselevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2578: '</td><td>'.
1.150 banghart 2579: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d" '.
1.119 raeburn 2580: ($domainlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2581: '</td><td>'.
1.150 banghart 2582: ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s" '.
1.119 raeburn 2583: ($systemlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.135 raeburn 2584: '</td>'.
2585: &Apache::loncommon::end_data_table_row());
1.60 www 2586: }
1.135 raeburn 2587: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 2588: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 2589: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 2590: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 2591: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
2592: '<input type="submit" value="'.&mt('Define Role').'" /></form>'.
1.110 albertel 2593: &Apache::loncommon::end_page());
1.61 www 2594: }
1.153 banghart 2595: # --------------------------------------------------------
2596: sub make_script_template {
2597: my ($role) = @_;
2598: my %full_c=();
2599: my %full_d=();
2600: my %full_s=();
2601: my $return_script;
2602: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2603: my ($priv,$restrict)=split(/\&/,$item);
2604: $full_c{$priv}=1;
2605: }
2606: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2607: my ($priv,$restrict)=split(/\&/,$item);
2608: $full_d{$priv}=1;
2609: }
1.154 banghart 2610: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.153 banghart 2611: my ($priv,$restrict)=split(/\&/,$item);
2612: $full_s{$priv}=1;
2613: }
2614: $return_script .= 'function set_'.$role.'() {'."\n";
2615: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
2616: my %role_c;
1.155 banghart 2617: foreach my $priv (@temp) {
1.153 banghart 2618: my ($priv_item, $dummy) = split(/\&/,$priv);
2619: $role_c{$priv_item} = 1;
2620: }
2621: foreach my $priv_item (keys(%full_c)) {
2622: my ($priv, $dummy) = split(/\&/,$priv_item);
2623: if (exists($role_c{$priv})) {
2624: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
2625: } else {
2626: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
2627: }
2628: }
1.154 banghart 2629: my %role_d;
2630: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
2631: foreach my $priv(@temp) {
2632: my ($priv_item, $dummy) = split(/\&/,$priv);
2633: $role_d{$priv_item} = 1;
2634: }
2635: foreach my $priv_item (keys(%full_d)) {
2636: my ($priv, $dummy) = split(/\&/,$priv_item);
2637: if (exists($role_d{$priv})) {
2638: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
2639: } else {
2640: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
2641: }
2642: }
2643: my %role_s;
2644: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
2645: foreach my $priv(@temp) {
2646: my ($priv_item, $dummy) = split(/\&/,$priv);
2647: $role_s{$priv_item} = 1;
2648: }
2649: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 2650: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 2651: if (exists($role_s{$priv})) {
2652: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
2653: } else {
2654: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
2655: }
1.153 banghart 2656: }
2657: $return_script .= '}'."\n";
1.154 banghart 2658: return ($return_script);
2659: }
2660: # ----------------------------------------------------------
2661: sub make_button_code {
2662: my ($role) = @_;
2663: my $label = &Apache::lonnet::plaintext($role);
2664: my $button_code = '<input type="button" onClick="set_'.$role.'()" value="'.$label.'" />';
2665: return ($button_code);
1.153 banghart 2666: }
1.61 www 2667: # ---------------------------------------------------------- Call to definerole
2668: sub set_custom_role {
1.110 albertel 2669: my ($r) = @_;
1.101 albertel 2670: my $rolename=$env{'form.rolename'};
1.63 www 2671: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 2672: if (!$rolename) {
1.190 raeburn 2673: &custom_role_editor($r);
1.61 www 2674: return;
2675: }
1.160 raeburn 2676: my ($jsback,$elements) = &crumb_utilities();
2677: my $jscript = '<script type="text/javascript">'.$jsback."\n".'</script>';
2678:
2679: $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
2680: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 2681: ({href=>"javascript:backPage(document.customresult,'pickrole','')",
2682: text=>"Pick custom role",
1.160 raeburn 2683: faq=>282,bug=>'Instructor Interface',},
2684: {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
2685: text=>"Edit custom role",
2686: faq=>282,bug=>'Instructor Interface',},
2687: {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
2688: text=>"Result",
2689: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 2690: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
2691: 'Course_Editing_Custom_Roles'));
1.160 raeburn 2692:
1.61 www 2693: my ($rdummy,$roledef)=
1.110 albertel 2694: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
2695:
1.61 www 2696: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 2697: $r->print('<h3>');
1.61 www 2698: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 2699: $r->print(&mt('Existing Role').' "');
1.61 www 2700: } else {
1.73 sakharuk 2701: $r->print(&mt('New Role').' "');
1.61 www 2702: $roledef='';
2703: }
1.188 raeburn 2704: $r->print($rolename.'"</h3>');
1.61 www 2705: # ------------------------------------------------------- What can be assigned?
2706: my $sysrole='';
2707: my $domrole='';
2708: my $courole='';
2709:
1.135 raeburn 2710: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2711: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2712: if (!$restrict) { $restrict=''; }
2713: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 2714: $courole.=':'.$item;
1.61 www 2715: }
2716: }
2717:
1.135 raeburn 2718: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2719: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2720: if (!$restrict) { $restrict=''; }
2721: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 2722: $domrole.=':'.$item;
1.61 www 2723: }
2724: }
2725:
1.135 raeburn 2726: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2727: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2728: if (!$restrict) { $restrict=''; }
2729: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 2730: $sysrole.=':'.$item;
1.61 www 2731: }
2732: }
1.63 www 2733: $r->print('<br />Defining Role: '.
1.61 www 2734: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 2735: if ($env{'request.course.id'}) {
2736: my $url='/'.$env{'request.course.id'};
1.63 www 2737: $url=~s/\_/\//g;
1.73 sakharuk 2738: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 2739: &Apache::lonnet::assigncustomrole($env{'user.domain'},
2740: $env{'user.name'},
1.63 www 2741: $url,
1.101 albertel 2742: $env{'user.domain'},
2743: $env{'user.name'},
1.63 www 2744: $rolename));
2745: }
1.190 raeburn 2746: $r->print('<p><a href="javascript:backPage(document.customresult,'."'pickrole'".')">'.&mt('Create or edit another custom role').'</a></p><form name="customresult" method="post">');
1.160 raeburn 2747: $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
1.110 albertel 2748: $r->print(&Apache::loncommon::end_page());
1.58 www 2749: }
2750:
1.2 www 2751: # ================================================================ Main Handler
2752: sub handler {
2753: my $r = shift;
2754: if ($r->header_only) {
1.68 www 2755: &Apache::loncommon::content_type($r,'text/html');
1.2 www 2756: $r->send_http_header;
2757: return OK;
2758: }
1.190 raeburn 2759: my $context;
2760: if ($env{'request.course.id'}) {
2761: $context = 'course';
2762: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 2763: $context = 'author';
1.190 raeburn 2764: } else {
2765: $context = 'domain';
2766: }
2767: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 ! raeburn 2768: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
! 2769: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
1.190 raeburn 2770: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.202 raeburn 2771: if ($env{'form.action'} ne 'dateselect') {
2772: &Apache::lonhtmlcommon::add_breadcrumb
2773: ({href=>"/adm/createuser",
2774: text=>"User Management"});
2775: }
1.209 raeburn 2776: my ($permission,$allowed) =
2777: &Apache::lonuserutils::get_permission($context);
1.190 raeburn 2778: if (!$allowed) {
2779: $env{'user.error.msg'}=
2780: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
2781: "or view user status.";
2782: return HTTP_NOT_ACCEPTABLE;
2783: }
2784:
2785: &Apache::loncommon::content_type($r,'text/html');
2786: $r->send_http_header;
2787:
2788: # Main switch on form.action and form.state, as appropriate
2789: if (! exists($env{'form.action'})) {
2790: $r->print(&header());
2791: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.208 raeburn 2792: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 2793: $r->print(&Apache::loncommon::end_page());
2794: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
2795: $r->print(&header());
2796: &Apache::lonhtmlcommon::add_breadcrumb
2797: ({href=>'/adm/createuser?action=upload&state=',
2798: text=>"Upload Users List"});
2799: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Upload Users List',
1.224 raeburn 2800: 'Course_Create_Class_List'));
1.190 raeburn 2801: $r->print('<form name="studentform" method="post" '.
2802: 'enctype="multipart/form-data" '.
2803: ' action="/adm/createuser">'."\n");
2804: if (! exists($env{'form.state'})) {
2805: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
2806: } elsif ($env{'form.state'} eq 'got_file') {
1.221 raeburn 2807: &Apache::lonuserutils::print_upload_manager_form($r,$context,
2808: $permission);
1.190 raeburn 2809: } elsif ($env{'form.state'} eq 'enrolling') {
2810: if ($env{'form.datatoken'}) {
1.221 raeburn 2811: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission);
1.190 raeburn 2812: }
2813: } else {
2814: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
2815: }
2816: $r->print('</form>'.&Apache::loncommon::end_page());
1.213 raeburn 2817: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
2818: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 2819: my $phase = $env{'form.phase'};
2820: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 2821: &Apache::loncreateuser::restore_prev_selections();
2822: my $srch;
2823: foreach my $item (@search) {
2824: $srch->{$item} = $env{'form.'.$item};
2825: }
1.207 raeburn 2826: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
2827: ($phase eq 'createnewuser')) {
2828: if ($env{'form.phase'} eq 'createnewuser') {
2829: my $response;
2830: if ($env{'form.srchterm'} !~ /^$match_username$/) {
2831: my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
1.221 raeburn 2832: $env{'form.phase'} = '';
1.207 raeburn 2833: &print_username_entry_form($r,$context,$response,$srch);
2834: } else {
2835: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
2836: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
2837: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 2838: $srch,$response,$context,
2839: $permission);
1.207 raeburn 2840: }
2841: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 2842: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 2843: &user_search_result($context,$srch);
1.190 raeburn 2844: if ($env{'form.currstate'} eq 'modify') {
2845: $currstate = $env{'form.currstate'};
2846: }
2847: if ($currstate eq 'select') {
2848: &print_user_selection_page($r,$response,$srch,$results,
1.229 raeburn 2849: \@search,$context);
1.190 raeburn 2850: } elsif ($currstate eq 'modify') {
2851: my ($ccuname,$ccdomain);
2852: if (($srch->{'srchby'} eq 'uname') &&
2853: ($srch->{'srchtype'} eq 'exact')) {
2854: $ccuname = $srch->{'srchterm'};
2855: $ccdomain= $srch->{'srchdomain'};
2856: } else {
2857: my @matchedunames = keys(%{$results});
2858: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
2859: }
2860: $ccuname =&LONCAPA::clean_username($ccuname);
2861: $ccdomain=&LONCAPA::clean_domain($ccdomain);
2862: if ($env{'form.forcenewuser'}) {
2863: $response = '';
2864: }
2865: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 2866: $srch,$response,$context,
2867: $permission);
1.190 raeburn 2868: } elsif ($currstate eq 'query') {
2869: &print_user_query_page($r,'createuser');
2870: } else {
1.229 raeburn 2871: $env{'form.phase'} = '';
1.207 raeburn 2872: &print_username_entry_form($r,$context,$response,$srch,
1.190 raeburn 2873: $forcenewuser);
2874: }
2875: } elsif ($env{'form.phase'} eq 'userpicked') {
2876: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
2877: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 2878: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.221 raeburn 2879: $context,$permission);
1.190 raeburn 2880: }
2881: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.206 raeburn 2882: &update_user_data($r,$context);
1.190 raeburn 2883: } else {
1.207 raeburn 2884: &print_username_entry_form($r,$context,undef,$srch);
1.190 raeburn 2885: }
2886: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
2887: if ($env{'form.phase'} eq 'set_custom_roles') {
2888: &set_custom_role($r);
2889: } else {
2890: &custom_role_editor($r);
2891: }
1.207 raeburn 2892: } elsif (($env{'form.action'} eq 'listusers') &&
2893: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 2894: if ($env{'form.phase'} eq 'bulkchange') {
2895: &Apache::lonhtmlcommon::add_breadcrumb
1.221 raeburn 2896: ({href=>'/adm/createuser?action=listusers',
2897: text=>"List Users"},
2898: {href=>"/adm/createuser",
2899: text=>"Result"});
1.202 raeburn 2900: my $setting = $env{'form.roletype'};
2901: my $choice = $env{'form.bulkaction'};
2902: $r->print(&header());
1.221 raeburn 2903: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Update Users",
1.224 raeburn 2904: 'Course_View_Class_List'));
1.202 raeburn 2905: if ($permission->{'cusr'}) {
2906: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
1.221 raeburn 2907: $r->print(&Apache::loncommon::end_page());
2908: } else {
2909: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 2910: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.221 raeburn 2911: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 2912: }
2913: } else {
2914: &Apache::lonhtmlcommon::add_breadcrumb
2915: ({href=>'/adm/createuser?action=listusers',
2916: text=>"List Users"});
2917: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
2918: my $formname = 'studentform';
2919: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
2920: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
2921: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
2922: $formname);
2923: $jscript .= &verify_user_display();
2924: my $js = &add_script($jscript).$cb_jscript;
2925: my $loadcode =
2926: &Apache::lonuserutils::course_selector_loadcode($formname);
2927: if ($loadcode ne '') {
2928: $r->print(&header($js,{'onload' => $loadcode,}));
2929: } else {
2930: $r->print(&header($js));
2931: }
1.191 raeburn 2932: } else {
1.202 raeburn 2933: $r->print(&header(&add_script(&verify_user_display())));
1.191 raeburn 2934: }
1.202 raeburn 2935: $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
1.224 raeburn 2936: 'Course_View_Class_List'));
1.202 raeburn 2937: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
2938: $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
2939: $r->print(&Apache::loncommon::end_page());
1.191 raeburn 2940: }
1.213 raeburn 2941: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
2942: $r->print(&header());
2943: &Apache::lonhtmlcommon::add_breadcrumb
2944: ({href=>'/adm/createuser?action=drop',
2945: text=>"Drop Students"});
2946: if (!exists($env{'form.state'})) {
2947: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
2948: 'Course_Drop_Student'));
2949:
2950: &Apache::lonuserutils::print_drop_menu($r,$context,$permission);
2951: } elsif ($env{'form.state'} eq 'done') {
2952: &Apache::lonhtmlcommon::add_breadcrumb
2953: ({href=>'/adm/createuser?action=drop',
2954: text=>"Result"});
2955: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
2956: 'Course_Drop_Student'));
2957: &Apache::lonuserutils::update_user_list($r,$context,undef,
2958: $env{'form.action'});
2959: }
2960: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 2961: } elsif ($env{'form.action'} eq 'dateselect') {
2962: if ($permission->{'cusr'}) {
2963: $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
1.221 raeburn 2964: &Apache::lonuserutils::date_section_selector($context,
2965: $permission).
1.202 raeburn 2966: &Apache::loncommon::end_page());
2967: } else {
2968: $r->print(&header().
2969: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'.
2970: &Apache::loncommon::end_page());
2971: }
1.190 raeburn 2972: } else {
2973: $r->print(&header());
1.202 raeburn 2974: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.207 raeburn 2975: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 2976: $r->print(&Apache::loncommon::end_page());
2977: }
2978: return OK;
2979: }
2980:
2981: sub header {
1.202 raeburn 2982: my ($jscript,$loaditems,$args) = @_;
1.190 raeburn 2983: my $start_page;
2984: if (ref($loaditems) eq 'HASH') {
1.202 raeburn 2985: $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
1.190 raeburn 2986: } else {
1.202 raeburn 2987: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 2988: }
2989: return $start_page;
2990: }
1.2 www 2991:
1.191 raeburn 2992: sub add_script {
2993: my ($js) = @_;
2994: return '<script type="text/javascript">'."\n".$js."\n".'</script>';
2995: }
2996:
1.202 raeburn 2997: sub verify_user_display {
2998: my $output = <<"END";
2999:
3000: function display_update() {
3001: document.studentform.action.value = 'listusers';
3002: document.studentform.phase.value = 'display';
3003: document.studentform.submit();
3004: }
3005:
3006: END
3007: return $output;
3008:
3009: }
3010:
1.190 raeburn 3011: ###############################################################
3012: ###############################################################
3013: # Menu Phase One
3014: sub print_main_menu {
1.208 raeburn 3015: my ($permission,$context) = @_;
3016: my %links = (
3017: domain => {
3018: upload => 'Upload a File of Users',
1.221 raeburn 3019: singleuser => 'Add/Modify a Single User',
1.208 raeburn 3020: listusers => 'Manage Multiple Users',
3021: },
3022: author => {
3023: upload => 'Upload a File of Co-authors',
1.221 raeburn 3024: singleuser => 'Add/Modify a Single Co-author',
1.208 raeburn 3025: listusers => 'Display Co-authors and Manage Multiple Users',
3026: },
3027: course => {
3028: upload => 'Upload a File of Course Users',
1.221 raeburn 3029: singleuser => 'Add/Modify a Single Course User',
1.208 raeburn 3030: listusers => 'Display Class Lists and Manage Multiple Users',
3031: },
3032: );
1.190 raeburn 3033: my @menu =
3034: (
1.208 raeburn 3035: { text => $links{$context}{'upload'},
1.224 raeburn 3036: help => 'Course_Create_Class_List',
1.190 raeburn 3037: action => 'upload',
3038: permission => $permission->{'cusr'},
3039: },
1.208 raeburn 3040: { text => $links{$context}{'singleuser'},
1.224 raeburn 3041: help => 'Course_Change_Privileges',
1.190 raeburn 3042: action => 'singleuser',
3043: permission => $permission->{'cusr'},
3044: },
1.208 raeburn 3045: { text => $links{$context}{'listusers'},
1.224 raeburn 3046: help => 'Course_View_Class_List',
1.191 raeburn 3047: action => 'listusers',
1.208 raeburn 3048: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.190 raeburn 3049: },
3050: );
1.208 raeburn 3051: if ($context eq 'domain' || $context eq 'course') {
3052: my $customlink = { text => 'Edit Custom Roles',
1.224 raeburn 3053: help => 'Course_Editing_Custom_Roles',
1.208 raeburn 3054: action => 'custom',
3055: permission => $permission->{'custom'},
3056: };
3057: push(@menu,$customlink);
3058: }
3059: if ($context eq 'course') {
1.213 raeburn 3060: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
3061: my @courselinks =
1.208 raeburn 3062: (
1.213 raeburn 3063: { text => 'Enroll a Single Student',
1.224 raeburn 3064: help => 'Course_Add_Student',
1.213 raeburn 3065: action => 'singlestudent',
3066: permission => $permission->{'cusr'},
3067: },
3068: { text => 'Drop Students',
3069: help => 'Course_Drop_Student',
3070: action => 'drop',
3071: permission => $permission->{'cusr'},
3072: });
3073: if (!exists($permission->{'cusr_section'})) {
3074: push(@courselinks,
3075: { text => 'Automated Student Enrollment Manager',
1.228 raeburn 3076: help => 'Course_Automated_Enrollment',
1.208 raeburn 3077: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
3078: && $permission->{'cusr'}),
3079: url => '/adm/populate',
1.213 raeburn 3080: });
3081: }
3082: push(@courselinks,
1.208 raeburn 3083: { text => 'Manage Course Groups',
3084: help => 'Course_Manage_Group',
3085: permission => $permission->{'grp_manage'},
3086: url => '/adm/coursegroups?refpage=cusr',
1.213 raeburn 3087: });
1.208 raeburn 3088: push(@menu,@courselinks);
3089: }
1.190 raeburn 3090: my $menu_html = '';
3091: foreach my $menu_item (@menu) {
3092: next if (! $menu_item->{'permission'});
3093: $menu_html.='<p>';
3094: $menu_html.='<font size="+1">';
3095: if (exists($menu_item->{'url'})) {
3096: $menu_html.=qq{<a href="$menu_item->{'url'}">};
3097: } else {
3098: $menu_html.=
3099: qq{<a href="/adm/createuser?action=$menu_item->{'action'}">};
3100: }
3101: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
3102: if (exists($menu_item->{'help'})) {
3103: $menu_html.=
3104: &Apache::loncommon::help_open_topic($menu_item->{'help'});
3105: }
3106: $menu_html.='</p>';
3107: }
3108: return $menu_html;
3109: }
3110:
1.189 albertel 3111: sub restore_prev_selections {
3112: my %saveable_parameters = ('srchby' => 'scalar',
3113: 'srchin' => 'scalar',
3114: 'srchtype' => 'scalar',
3115: );
3116: &Apache::loncommon::store_settings('user','user_picker',
3117: \%saveable_parameters);
3118: &Apache::loncommon::restore_settings('user','user_picker',
3119: \%saveable_parameters);
3120: }
3121:
1.27 matthew 3122: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 3123: sub user_search_result {
1.221 raeburn 3124: my ($context,$srch) = @_;
1.160 raeburn 3125: my %allhomes;
3126: my %inst_matches;
3127: my %srch_results;
1.181 raeburn 3128: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 3129: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 3130: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 3131: $response = &mt('Invalid search.');
3132: }
3133: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
3134: $response = &mt('Invalid search.');
3135: }
1.177 raeburn 3136: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 3137: $response = &mt('Invalid search.');
3138: }
3139: if ($srch->{'srchterm'} eq '') {
3140: $response = &mt('You must enter a search term.');
3141: }
1.183 raeburn 3142: if ($srch->{'srchterm'} =~ /^\s+$/) {
3143: $response = &mt('Your search term must contain more than just spaces.');
3144: }
1.160 raeburn 3145: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
3146: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 3147: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 3148: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
3149: }
3150: }
3151: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
3152: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 3153: if ($srch->{'srchby'} eq 'uname') {
3154: if ($srch->{'srchterm'} !~ /^$match_username$/) {
3155: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
3156: }
1.160 raeburn 3157: }
3158: }
1.180 raeburn 3159: if ($response ne '') {
3160: $response = '<span class="LC_warning">'.$response.'</span>';
3161: }
1.160 raeburn 3162: if ($srch->{'srchin'} eq 'instd') {
3163: my $instd_chk = &directorysrch_check($srch);
3164: if ($instd_chk ne 'ok') {
1.180 raeburn 3165: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
3166: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 3167: }
3168: }
3169: if ($response ne '') {
1.180 raeburn 3170: return ($currstate,$response);
1.160 raeburn 3171: }
3172: if ($srch->{'srchby'} eq 'uname') {
3173: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
3174: if ($env{'form.forcenew'}) {
3175: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
3176: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
3177: if ($uhome eq 'no_host') {
3178: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 3179: my $showdom = &display_domain_info($env{'request.role.domain'});
3180: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 3181: } else {
1.179 raeburn 3182: $currstate = 'modify';
1.160 raeburn 3183: }
3184: } else {
1.179 raeburn 3185: $currstate = 'modify';
1.160 raeburn 3186: }
3187: } else {
3188: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 3189: if ($srch->{'srchtype'} eq 'exact') {
3190: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
3191: if ($uhome eq 'no_host') {
1.179 raeburn 3192: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3193: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 3194: } else {
1.179 raeburn 3195: $currstate = 'modify';
1.162 raeburn 3196: }
3197: } else {
3198: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 3199: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3200: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 3201: }
3202: } else {
1.167 albertel 3203: my $courseusers = &get_courseusers();
1.162 raeburn 3204: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 3205: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 3206: $currstate = 'modify';
1.162 raeburn 3207: } else {
1.179 raeburn 3208: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3209: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 3210: }
1.160 raeburn 3211: } else {
1.167 albertel 3212: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 3213: my ($cuname,$cudomain) = split(/:/,$user);
3214: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 3215: my $matched = 0;
3216: if ($srch->{'srchtype'} eq 'begins') {
3217: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
3218: $matched = 1;
3219: }
3220: } else {
3221: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
3222: $matched = 1;
3223: }
3224: }
3225: if ($matched) {
1.167 albertel 3226: $srch_results{$user} =
3227: {&Apache::lonnet::get('environment',
3228: ['firstname',
3229: 'lastname',
1.194 albertel 3230: 'permanentemail'],
3231: $cudomain,$cuname)};
1.162 raeburn 3232: }
3233: }
3234: }
1.179 raeburn 3235: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3236: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 3237: }
3238: }
3239: }
3240: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 3241: $currstate = 'query';
1.160 raeburn 3242: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 3243: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
3244: if ($dirsrchres eq 'ok') {
3245: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3246: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 3247: } else {
3248: my $showdom = &display_domain_info($srch->{'srchdomain'});
3249: $response = '<span class="LC_warning">'.
3250: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
3251: '</span><br />'.
3252: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
3253: '<br /><br />';
3254: }
1.160 raeburn 3255: }
3256: } else {
3257: if ($srch->{'srchin'} eq 'dom') {
3258: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 3259: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3260: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 3261: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 3262: my $courseusers = &get_courseusers();
3263: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 3264: my ($uname,$udom) = split(/:/,$user);
3265: my %names = &Apache::loncommon::getnames($uname,$udom);
3266: my %emails = &Apache::loncommon::getemails($uname,$udom);
3267: if ($srch->{'srchby'} eq 'lastname') {
3268: if ((($srch->{'srchtype'} eq 'exact') &&
3269: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 3270: (($srch->{'srchtype'} eq 'begins') &&
3271: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 3272: (($srch->{'srchtype'} eq 'contains') &&
3273: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
3274: $srch_results{$user} = {firstname => $names{'firstname'},
3275: lastname => $names{'lastname'},
3276: permanentemail => $emails{'permanentemail'},
3277: };
3278: }
3279: } elsif ($srch->{'srchby'} eq 'lastfirst') {
3280: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 3281: $srchlast =~ s/\s+$//;
3282: $srchfirst =~ s/^\s+//;
1.160 raeburn 3283: if ($srch->{'srchtype'} eq 'exact') {
3284: if (($names{'lastname'} eq $srchlast) &&
3285: ($names{'firstname'} eq $srchfirst)) {
3286: $srch_results{$user} = {firstname => $names{'firstname'},
3287: lastname => $names{'lastname'},
3288: permanentemail => $emails{'permanentemail'},
3289:
3290: };
3291: }
1.177 raeburn 3292: } elsif ($srch->{'srchtype'} eq 'begins') {
3293: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
3294: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
3295: $srch_results{$user} = {firstname => $names{'firstname'},
3296: lastname => $names{'lastname'},
3297: permanentemail => $emails{'permanentemail'},
3298: };
3299: }
3300: } else {
1.160 raeburn 3301: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
3302: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
3303: $srch_results{$user} = {firstname => $names{'firstname'},
3304: lastname => $names{'lastname'},
3305: permanentemail => $emails{'permanentemail'},
3306: };
3307: }
3308: }
3309: }
3310: }
1.179 raeburn 3311: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3312: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 3313: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 3314: $currstate = 'query';
1.160 raeburn 3315: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 3316: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
3317: if ($dirsrchres eq 'ok') {
3318: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3319: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 3320: } else {
3321: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
3322: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
3323: '</span><br />'.
3324: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
3325: '<br /><br />';
3326: }
1.160 raeburn 3327: }
3328: }
1.179 raeburn 3329: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 3330: }
3331:
3332: sub directorysrch_check {
3333: my ($srch) = @_;
3334: my $can_search = 0;
3335: my $response;
3336: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
3337: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 3338: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 3339: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
3340: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 3341: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 3342: }
3343: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
3344: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 3345: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 3346: }
3347: my @usertypes = split(/:/,$env{'environment.inststatus'});
3348: if (!@usertypes) {
3349: push(@usertypes,'default');
3350: }
3351: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
3352: foreach my $type (@usertypes) {
3353: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
3354: $can_search = 1;
3355: last;
3356: }
3357: }
3358: }
3359: if (!$can_search) {
3360: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
3361: my @longtypes;
3362: foreach my $item (@usertypes) {
1.229 raeburn 3363: if (defined($insttypes->{$item})) {
3364: push (@longtypes,$insttypes->{$item});
3365: } elsif ($item eq 'default') {
3366: push (@longtypes,&mt('other'));
3367: }
1.160 raeburn 3368: }
3369: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 3370: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 3371: }
1.160 raeburn 3372: } else {
3373: $can_search = 1;
3374: }
3375: } else {
1.180 raeburn 3376: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 3377: }
3378: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 3379: uname => 'username',
1.160 raeburn 3380: lastfirst => 'last name, first name',
1.167 albertel 3381: lastname => 'last name',
1.172 raeburn 3382: contains => 'contains',
1.178 raeburn 3383: exact => 'as exact match to',
3384: begins => 'begins with',
1.160 raeburn 3385: );
3386: if ($can_search) {
3387: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
3388: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 3389: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 3390: }
3391: } else {
1.180 raeburn 3392: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 3393: }
3394: }
3395: if ($can_search) {
1.178 raeburn 3396: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
3397: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
3398: return 'ok';
3399: } else {
1.180 raeburn 3400: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 3401: }
3402: } else {
3403: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
3404: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
3405: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
3406: return 'ok';
3407: } else {
1.180 raeburn 3408: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 3409: }
1.160 raeburn 3410: }
3411: }
3412: }
3413:
3414: sub get_courseusers {
3415: my %advhash;
1.167 albertel 3416: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 3417: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
3418: foreach my $role (sort(keys(%coursepersonnel))) {
3419: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 3420: if (!exists($classlist->{$user})) {
3421: $classlist->{$user} = [];
3422: }
1.160 raeburn 3423: }
3424: }
1.167 albertel 3425: return $classlist;
1.160 raeburn 3426: }
3427:
3428: sub build_search_response {
1.221 raeburn 3429: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 3430: my ($currstate,$response,$forcenewuser);
1.160 raeburn 3431: my %names = (
3432: 'uname' => 'username',
3433: 'lastname' => 'last name',
3434: 'lastfirst' => 'last name, first name',
3435: 'crs' => 'this course',
1.180 raeburn 3436: 'dom' => 'LON-CAPA domain: ',
3437: 'instd' => 'the institutional directory for domain: ',
1.160 raeburn 3438: );
3439:
3440: my %single = (
1.180 raeburn 3441: begins => 'A match',
1.160 raeburn 3442: contains => 'A match',
1.180 raeburn 3443: exact => 'An exact match',
1.160 raeburn 3444: );
3445: my %nomatch = (
1.180 raeburn 3446: begins => 'No match',
1.160 raeburn 3447: contains => 'No match',
1.180 raeburn 3448: exact => 'No exact match',
1.160 raeburn 3449: );
3450: if (keys(%srch_results) > 1) {
1.179 raeburn 3451: $currstate = 'select';
1.160 raeburn 3452: } else {
3453: if (keys(%srch_results) == 1) {
1.179 raeburn 3454: $currstate = 'modify';
1.180 raeburn 3455: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
3456: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
3457: $response .= &display_domain_info($srch->{'srchdomain'});
3458: }
1.160 raeburn 3459: } else {
1.180 raeburn 3460: $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
3461: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
3462: $response .= &display_domain_info($srch->{'srchdomain'});
3463: }
3464: $response .= '</span>';
1.160 raeburn 3465: if ($srch->{'srchin'} ne 'alc') {
3466: $forcenewuser = 1;
3467: my $cansrchinst = 0;
3468: if ($srch->{'srchdomain'}) {
3469: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
3470: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
3471: if ($domconfig{'directorysrch'}{'available'}) {
3472: $cansrchinst = 1;
3473: }
3474: }
3475: }
1.180 raeburn 3476: if ((($srch->{'srchby'} eq 'lastfirst') ||
3477: ($srch->{'srchby'} eq 'lastname')) &&
3478: ($srch->{'srchin'} eq 'dom')) {
3479: if ($cansrchinst) {
3480: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 3481: }
3482: }
1.180 raeburn 3483: if ($srch->{'srchin'} eq 'crs') {
3484: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
3485: }
3486: }
3487: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {
1.221 raeburn 3488: my $cancreate =
3489: &Apache::lonuserutils::can_create_user($env{'request.role.domain'},$context);
3490: if ($cancreate) {
3491: my $showdom = &display_domain_info($env{'request.role.domain'});
1.229 raeburn 3492: $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.221 raeburn 3493: } else {
3494: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
3495: $response .= '<br /><br />'.&mt("You are not authorized to create new users in your current role's domain - <span class=\"LC_cusr_emph\">[_1]</span>.",$env{'request.role.domain'}).'<br />'.&mt('Contact the <a[_1]>helpdesk</a> if you need to create a new user.',$helplink).'<br /><br />';
3496: }
1.160 raeburn 3497: }
3498: }
3499: }
1.179 raeburn 3500: return ($currstate,$response,$forcenewuser);
1.160 raeburn 3501: }
3502:
1.180 raeburn 3503: sub display_domain_info {
3504: my ($dom) = @_;
3505: my $output = $dom;
3506: if ($dom ne '') {
3507: my $domdesc = &Apache::lonnet::domain($dom,'description');
3508: if ($domdesc ne '') {
3509: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
3510: }
3511: }
3512: return $output;
3513: }
3514:
1.160 raeburn 3515: sub crumb_utilities {
3516: my %elements = (
3517: crtuser => {
3518: srchterm => 'text',
1.172 raeburn 3519: srchin => 'selectbox',
1.160 raeburn 3520: srchby => 'selectbox',
3521: srchtype => 'selectbox',
3522: srchdomain => 'selectbox',
3523: },
1.207 raeburn 3524: crtusername => {
3525: srchterm => 'text',
3526: srchdomain => 'selectbox',
3527: },
1.160 raeburn 3528: docustom => {
3529: rolename => 'selectbox',
3530: newrolename => 'textbox',
3531: },
1.179 raeburn 3532: studentform => {
3533: srchterm => 'text',
3534: srchin => 'selectbox',
3535: srchby => 'selectbox',
3536: srchtype => 'selectbox',
3537: srchdomain => 'selectbox',
3538: },
1.160 raeburn 3539: );
3540:
3541: my $jsback .= qq|
3542: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 3543: if (typeof prevphase == 'undefined') {
3544: formname.phase.value = '';
3545: }
3546: else {
3547: formname.phase.value = prevphase;
3548: }
3549: if (typeof prevstate == 'undefined') {
3550: formname.currstate.value = '';
3551: }
3552: else {
3553: formname.currstate.value = prevstate;
3554: }
1.160 raeburn 3555: formname.submit();
3556: }
3557: |;
3558: return ($jsback,\%elements);
3559: }
3560:
1.26 matthew 3561: sub course_level_table {
1.89 raeburn 3562: my (%inccourses) = @_;
1.26 matthew 3563: my $table = '';
1.62 www 3564: # Custom Roles?
3565:
1.190 raeburn 3566: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 3567: my %lt=&Apache::lonlocal::texthash(
3568: 'exs' => "Existing sections",
3569: 'new' => "Define new section",
3570: 'ssd' => "Set Start Date",
3571: 'sed' => "Set End Date",
1.131 raeburn 3572: 'crl' => "Course Level",
1.89 raeburn 3573: 'act' => "Activate",
3574: 'rol' => "Role",
3575: 'ext' => "Extent",
1.113 raeburn 3576: 'grs' => "Section",
1.89 raeburn 3577: 'sta' => "Start",
3578: 'end' => "End"
3579: );
1.62 www 3580:
1.135 raeburn 3581: foreach my $protectedcourse (sort( keys(%inccourses))) {
3582: my $thiscourse=$protectedcourse;
1.26 matthew 3583: $thiscourse=~s:_:/:g;
3584: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
3585: my $area=$coursedata{'description'};
1.119 raeburn 3586: my $type=$coursedata{'type'};
1.135 raeburn 3587: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 3588: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 3589: my %sections_count;
1.101 albertel 3590: if (defined($env{'request.course.id'})) {
3591: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 3592: %sections_count =
3593: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 3594: }
3595: }
1.213 raeburn 3596: my @roles = &Apache::lonuserutils::roles_by_context('course');
3597: foreach my $role (@roles) {
1.221 raeburn 3598: my $plrole=&Apache::lonnet::plaintext($role);
1.135 raeburn 3599: if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
1.221 raeburn 3600: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
3601: $plrole,\%sections_count,\%lt);
3602: } elsif ($env{'request.course.sec'} ne '') {
3603: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
3604: $env{'request.course.sec'})) {
3605: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
3606: $plrole,\%sections_count,\%lt);
1.26 matthew 3607: }
3608: }
3609: }
1.221 raeburn 3610: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
3611: foreach my $cust (sort keys %customroles) {
3612: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
3613: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
3614: $cust,\%sections_count,\%lt);
3615: }
1.62 www 3616: }
1.26 matthew 3617: }
3618: return '' if ($table eq ''); # return nothing if there is nothing
3619: # in the table
1.188 raeburn 3620: my $result;
3621: if (!$env{'request.course.id'}) {
3622: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
3623: }
3624: $result .=
1.136 raeburn 3625: &Apache::loncommon::start_data_table().
3626: &Apache::loncommon::start_data_table_header_row().
3627: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
3628: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
3629: &Apache::loncommon::end_data_table_header_row().
3630: $table.
3631: &Apache::loncommon::end_data_table();
1.26 matthew 3632: return $result;
3633: }
1.88 raeburn 3634:
1.221 raeburn 3635: sub course_level_row {
3636: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_;
1.222 raeburn 3637: my $row = &Apache::loncommon::start_data_table_row().
3638: ' <td><input type="checkbox" name="act_'.
3639: $protectedcourse.'_'.$role.'" /></td>'."\n".
3640: ' <td>'.$plrole.'</td>'."\n".
3641: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.221 raeburn 3642: if ($role eq 'cc') {
1.222 raeburn 3643: $row .= '<td> </td>';
1.221 raeburn 3644: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 3645: $row .= ' <td><input type="hidden" value="'.
3646: $env{'request.course.sec'}.'" '.
3647: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
3648: $env{'request.course.sec'}.'</td>';
1.221 raeburn 3649: } else {
3650: if (ref($sections_count) eq 'HASH') {
3651: my $currsec =
3652: &Apache::lonuserutils::course_sections($sections_count,
3653: $protectedcourse.'_'.$role);
1.222 raeburn 3654: $row .= '<td><table class="LC_createuser">'."\n".
3655: '<tr class="LC_section_row">'."\n".
3656: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
3657: $currsec.'</td>'."\n".
3658: ' <td> </td>'."\n".
3659: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 3660: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
3661: '" value="" />'.
3662: '<input type="hidden" '.
3663: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 3664: '</tr></table></td>'."\n";
1.221 raeburn 3665: } else {
1.222 raeburn 3666: $row .= '<td><input type="text" size="10" '.
3667: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 3668: }
3669: }
1.222 raeburn 3670: $row .= <<ENDTIMEENTRY;
3671: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 3672: <a href=
3673: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$role.value,'start_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'ssd'}</a></td>
1.222 raeburn 3674: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 3675: <a href=
3676: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
3677: ENDTIMEENTRY
1.222 raeburn 3678: $row .= &Apache::loncommon::end_data_table_row();
3679: return $row;
1.221 raeburn 3680: }
3681:
1.88 raeburn 3682: sub course_level_dc {
3683: my ($dcdom) = @_;
1.190 raeburn 3684: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 3685: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 3686: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
3687: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 3688: '<input type="hidden" name="dccourse" value="" />';
1.88 raeburn 3689: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.131 raeburn 3690: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
3691: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
1.88 raeburn 3692: my %lt=&Apache::lonlocal::texthash(
3693: 'rol' => "Role",
1.113 raeburn 3694: 'grs' => "Section",
1.88 raeburn 3695: 'exs' => "Existing sections",
3696: 'new' => "Define new section",
3697: 'sta' => "Start",
3698: 'end' => "End",
3699: 'ssd' => "Set Start Date",
3700: 'sed' => "Set End Date"
3701: );
1.131 raeburn 3702: my $header = '<h4>'.&mt('Course Level').'</h4>'.
1.136 raeburn 3703: &Apache::loncommon::start_data_table().
3704: &Apache::loncommon::start_data_table_header_row().
1.143 raeburn 3705: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 3706: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 3707: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.131 raeburn 3708: '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1.88 raeburn 3709: '<td><select name="role">'."\n";
1.213 raeburn 3710: foreach my $role (@roles) {
1.135 raeburn 3711: my $plrole=&Apache::lonnet::plaintext($role);
3712: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 3713: }
3714: if ( keys %customroles > 0) {
1.135 raeburn 3715: foreach my $cust (sort keys %customroles) {
1.101 albertel 3716: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 3717: '_'.$env{'user.name'}.'_'.$cust;
3718: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 3719: }
3720: }
3721: $otheritems .= '</select></td><td>'.
3722: '<table border="0" cellspacing="0" cellpadding="0">'.
3723: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
3724: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
3725: '<td> </td>'.
3726: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 3727: '<input type="text" name="newsec" value="" />'.
1.221 raeburn 3728: '<input type="hidden" name="sections" value="" />'.
1.113 raeburn 3729: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 3730: '</tr></table></td>';
3731: $otheritems .= <<ENDTIMEENTRY;
1.169 albertel 3732: <td><input type="hidden" name="start" value='' />
1.88 raeburn 3733: <a href=
3734: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 3735: <td><input type="hidden" name="end" value='' />
1.88 raeburn 3736: <a href=
3737: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
3738: ENDTIMEENTRY
1.136 raeburn 3739: $otheritems .= &Apache::loncommon::end_data_table_row().
3740: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 3741: return $cb_jscript.$header.$hiddenitems.$otheritems;
3742: }
3743:
1.27 matthew 3744: #---------------------------------------------- end functions for &phase_two
1.29 matthew 3745:
3746: #--------------------------------- functions for &phase_two and &phase_three
3747:
3748: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 3749:
3750: 1;
3751: __END__
1.2 www 3752:
3753:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>