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