Annotation of loncom/interface/loncreateuser.pm, revision 1.231
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.231 ! raeburn 4: # $Id: loncreateuser.pm,v 1.230 2008/01/15 14:34:35 bisitz 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.219 raeburn 1639: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
1640: &Apache::lonnet::hostname($uhome));
1.101 albertel 1641: } elsif (($env{'form.login'} ne 'nochange') &&
1642: ($env{'form.login'} ne '' )) {
1.27 matthew 1643: # Modify user privileges
1644: if (! $amode || ! $genpwd) {
1.193 raeburn 1645: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 1646: return;
1.20 harris41 1647: }
1.27 matthew 1648: # Only allow authentification modification if the person has authority
1.101 albertel 1649: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 1650: $r->print('Modifying authentication: '.
1.31 matthew 1651: &Apache::lonnet::modifyuserauth(
1.101 albertel 1652: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 1653: $amode,$genpwd));
1.102 albertel 1654: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 1655: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 1656: } else {
1.27 matthew 1657: # Okay, this is a non-fatal error.
1.193 raeburn 1658: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
1.27 matthew 1659: }
1.28 matthew 1660: }
1661: ##
1.213 raeburn 1662: my (@userroles,%userupdate,$cnum,$cdom,$namechanged);
1663: if ($context eq 'course') {
1664: ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1665: }
1.101 albertel 1666: if (! $env{'form.makeuser'} ) {
1.28 matthew 1667: # Check for need to change
1668: my %userenv = &Apache::lonnet::get
1.134 raeburn 1669: ('environment',['firstname','middlename','lastname','generation',
1.196 raeburn 1670: 'id','permanentemail','portfolioquota','inststatus'],
1.160 raeburn 1671: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 1672: my ($tmp) = keys(%userenv);
1673: if ($tmp =~ /^(con_lost|error)/i) {
1674: %userenv = ();
1675: }
1.206 raeburn 1676: my $no_forceid_alert;
1677: # Check to see if user information can be changed
1678: my %domconfig =
1679: &Apache::lonnet::get_dom('configuration',['usermodification'],
1680: $env{'form.ccdomain'});
1.213 raeburn 1681: my @statuses = ('active','future');
1682: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
1683: my ($auname,$audom);
1.220 raeburn 1684: if ($context eq 'author') {
1.206 raeburn 1685: $auname = $env{'user.name'};
1686: $audom = $env{'user.domain'};
1687: }
1688: foreach my $item (keys(%roles)) {
1.220 raeburn 1689: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 1690: if ($context eq 'course') {
1691: if ($cnum ne '' && $cdom ne '') {
1692: if ($rolenum eq $cnum && $roledom eq $cdom) {
1693: if (!grep(/^\Q$role\E$/,@userroles)) {
1694: push(@userroles,$role);
1695: }
1696: }
1697: }
1698: } elsif ($context eq 'author') {
1699: if ($rolenum eq $auname && $roledom eq $audom) {
1700: if (!grep(/^\Q$role\E$/,@userroles)) {
1701: push(@userroles,$role);
1702: }
1703: }
1704: }
1705: }
1.220 raeburn 1706: if ($env{'form.action'} eq 'singlestudent') {
1707: if (!grep(/^st$/,@userroles)) {
1708: push(@userroles,'st');
1709: }
1710: } else {
1711: # Check for course or co-author roles being activated or re-enabled
1712: if ($context eq 'author' || $context eq 'course') {
1713: foreach my $key (keys(%env)) {
1714: if ($context eq 'author') {
1715: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
1716: if (!grep(/^\Q$1\E$/,@userroles)) {
1717: push(@userroles,$1);
1718: }
1719: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
1720: if (!grep(/^\Q$1\E$/,@userroles)) {
1721: push(@userroles,$1);
1722: }
1.206 raeburn 1723: }
1.220 raeburn 1724: } elsif ($context eq 'course') {
1725: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
1726: if (!grep(/^\Q$1\E$/,@userroles)) {
1727: push(@userroles,$1);
1728: }
1729: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
1730: if (!grep(/^\Q$1\E$/,@userroles)) {
1731: push(@userroles,$1);
1732: }
1.206 raeburn 1733: }
1734: }
1735: }
1736: }
1737: }
1738: #Check to see if we can change personal data for the user
1739: my (@mod_disallowed,@longroles);
1740: foreach my $role (@userroles) {
1741: if ($role eq 'cr') {
1742: push(@longroles,'Custom');
1743: } else {
1744: push(@longroles,&Apache::lonnet::plaintext($role));
1745: }
1746: }
1.219 raeburn 1747: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1748: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
1749: foreach my $item (@userinfo) {
1.28 matthew 1750: # Strip leading and trailing whitespace
1.203 raeburn 1751: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 1752: if (!$canmodify{$item}) {
1.207 raeburn 1753: if (defined($env{'form.c'.$item})) {
1754: if ($env{'form.c'.$item} ne $userenv{$item}) {
1755: push(@mod_disallowed,$item);
1756: }
1.206 raeburn 1757: }
1758: $env{'form.c'.$item} = $userenv{$item};
1759: }
1.28 matthew 1760: }
1.196 raeburn 1761: # Check to see if we can change the ID/student number
1762: my $forceid = $env{'form.forceid'};
1763: my $recurseid = $env{'form.recurseid'};
1764: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 1765: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
1766: $env{'form.ccuname'});
1767: if (($uidhash{$env{'form.ccuname'}}) &&
1768: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
1769: (!$forceid)) {
1770: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
1771: $env{'form.cid'} = $userenv{'id'};
1.206 raeburn 1772: $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 1773: }
1774: }
1775: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 1776: my $checkhash;
1777: my $checks = { 'id' => 1 };
1778: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
1779: { 'newuser' => $newuser,
1780: 'id' => $env{'form.cid'},
1781: };
1782: &Apache::loncommon::user_rule_check($checkhash,$checks,
1783: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
1784: if (ref($alerts{'id'}) eq 'HASH') {
1785: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 1786: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 1787: }
1788: }
1789: }
1.213 raeburn 1790: my ($quotachanged,$oldportfolioquota,$newportfolioquota,
1.204 raeburn 1791: $inststatus,$oldisdefault,$newisdefault,$olddefquotatext,
1792: $newdefquotatext);
1.149 raeburn 1793: my ($defquota,$settingstatus) =
1794: &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
1.220 raeburn 1795: my $showquota;
1796: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1797: $showquota = 1;
1798: }
1.134 raeburn 1799: my %changeHash;
1.204 raeburn 1800: $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
1.149 raeburn 1801: if ($userenv{'portfolioquota'} ne '') {
1.134 raeburn 1802: $oldportfolioquota = $userenv{'portfolioquota'};
1.149 raeburn 1803: if ($env{'form.customquota'} == 1) {
1804: if ($env{'form.portfolioquota'} eq '') {
1805: $newportfolioquota = 0;
1806: } else {
1807: $newportfolioquota = $env{'form.portfolioquota'};
1808: $newportfolioquota =~ s/[^\d\.]//g;
1809: }
1.204 raeburn 1810: if ($newportfolioquota != $oldportfolioquota) {
1.149 raeburn 1811: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1.134 raeburn 1812: }
1.149 raeburn 1813: } else {
1814: $quotachanged = "a_admin('',\%changeHash);
1815: $newportfolioquota = $defquota;
1.204 raeburn 1816: $newisdefault = 1;
1.134 raeburn 1817: }
1818: } else {
1.204 raeburn 1819: $oldisdefault = 1;
1.149 raeburn 1820: $oldportfolioquota = $defquota;
1821: if ($env{'form.customquota'} == 1) {
1822: if ($env{'form.portfolioquota'} eq '') {
1823: $newportfolioquota = 0;
1824: } else {
1825: $newportfolioquota = $env{'form.portfolioquota'};
1826: $newportfolioquota =~ s/[^\d\.]//g;
1827: }
1828: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1829: } else {
1830: $newportfolioquota = $defquota;
1.204 raeburn 1831: $newisdefault = 1;
1.149 raeburn 1832: }
1833: }
1.204 raeburn 1834: if ($oldisdefault) {
1835: $olddefquotatext = &get_defaultquota_text($settingstatus);
1836: }
1837: if ($newisdefault) {
1838: $newdefquotatext = &get_defaultquota_text($settingstatus);
1.134 raeburn 1839: }
1.206 raeburn 1840: if ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
1841: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
1842: $env{'form.clastname'} ne $userenv{'lastname'} ||
1843: $env{'form.cgeneration'} ne $userenv{'generation'} ||
1844: $env{'form.cid'} ne $userenv{'id'} ||
1845: $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} ) {
1.134 raeburn 1846: $namechanged = 1;
1847: }
1.204 raeburn 1848: if ($namechanged || $quotachanged) {
1.101 albertel 1849: $changeHash{'firstname'} = $env{'form.cfirstname'};
1850: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1851: $changeHash{'lastname'} = $env{'form.clastname'};
1852: $changeHash{'generation'} = $env{'form.cgeneration'};
1.196 raeburn 1853: $changeHash{'id'} = $env{'form.cid'};
1.174 raeburn 1854: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1.204 raeburn 1855: my ($quotachgresult,$namechgresult);
1856: if ($quotachanged) {
1857: $quotachgresult =
1858: &Apache::lonnet::put('environment',\%changeHash,
1859: $env{'form.ccdomain'},$env{'form.ccuname'});
1860: }
1861: if ($namechanged) {
1862: # Make the change
1863: $namechgresult =
1864: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
1865: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
1866: $changeHash{'firstname'},$changeHash{'middlename'},
1867: $changeHash{'lastname'},$changeHash{'generation'},
1868: $changeHash{'id'},undef,$changeHash{'permanentemail'});
1.220 raeburn 1869: %userupdate = (
1870: lastname => $env{'form.clastname'},
1871: middlename => $env{'form.cmiddlename'},
1872: firstname => $env{'form.cfirstname'},
1873: generation => $env{'form.cgeneration'},
1874: id => $env{'form.cid'},
1875: );
1.204 raeburn 1876: }
1877: if (($namechanged && $namechgresult eq 'ok') ||
1878: ($quotachanged && $quotachgresult eq 'ok')) {
1.28 matthew 1879: # Tell the user we changed the name
1.73 sakharuk 1880: my %lt=&Apache::lonlocal::texthash(
1881: 'uic' => "User Information Changed",
1882: 'frst' => "first",
1883: 'mddl' => "middle",
1884: 'lst' => "last",
1885: 'gen' => "generation",
1.196 raeburn 1886: 'id' => "ID/Student number",
1.160 raeburn 1887: 'mail' => "permanent e-mail",
1.134 raeburn 1888: 'disk' => "disk space allocated to portfolio files",
1.73 sakharuk 1889: 'prvs' => "Previous",
1890: 'chto' => "Changed To"
1891: );
1.201 raeburn 1892: $r->print('<h4>'.$lt{'uic'}.'</h4>'.
1893: &Apache::loncommon::start_data_table().
1894: &Apache::loncommon::start_data_table_header_row());
1.28 matthew 1895: $r->print(<<"END");
1.201 raeburn 1896: <th> </th>
1.73 sakharuk 1897: <th>$lt{'frst'}</th>
1898: <th>$lt{'mddl'}</th>
1899: <th>$lt{'lst'}</th>
1.134 raeburn 1900: <th>$lt{'gen'}</th>
1.196 raeburn 1901: <th>$lt{'id'}</th>
1.173 raeburn 1902: <th>$lt{'mail'}</th>
1.201 raeburn 1903: END
1.220 raeburn 1904: if ($showquota) {
1905: $r->print("
1906: <th>$lt{'disk'}</th>\n");
1907: }
1.201 raeburn 1908: $r->print(&Apache::loncommon::end_data_table_header_row().
1909: &Apache::loncommon::start_data_table_row());
1910: $r->print(<<"END");
1911: <td><b>$lt{'prvs'}</b></td>
1.28 matthew 1912: <td>$userenv{'firstname'} </td>
1913: <td>$userenv{'middlename'} </td>
1914: <td>$userenv{'lastname'} </td>
1.134 raeburn 1915: <td>$userenv{'generation'} </td>
1.196 raeburn 1916: <td>$userenv{'id'}</td>
1.160 raeburn 1917: <td>$userenv{'permanentemail'} </td>
1.201 raeburn 1918: END
1.220 raeburn 1919: if ($showquota) {
1920: $r->print("
1921: <td>$oldportfolioquota Mb $olddefquotatext </td>\n");
1922: }
1.201 raeburn 1923: $r->print(&Apache::loncommon::end_data_table_row().
1924: &Apache::loncommon::start_data_table_row());
1925: $r->print(<<"END");
1926: <td><b>$lt{'chto'}</b></td>
1.101 albertel 1927: <td>$env{'form.cfirstname'} </td>
1928: <td>$env{'form.cmiddlename'} </td>
1929: <td>$env{'form.clastname'} </td>
1.134 raeburn 1930: <td>$env{'form.cgeneration'} </td>
1.196 raeburn 1931: <td>$env{'form.cid'} </td>
1.160 raeburn 1932: <td>$env{'form.cpermanentemail'} </td>
1.28 matthew 1933: END
1.220 raeburn 1934: if ($showquota) {
1935: $r->print("
1936: <td>$newportfolioquota Mb $newdefquotatext </td>\n");
1937: }
1.201 raeburn 1938: $r->print(&Apache::loncommon::end_data_table_row().
1.206 raeburn 1939: &Apache::loncommon::end_data_table().'<br />');
1.203 raeburn 1940: if ($env{'form.cid'} ne $userenv{'id'}) {
1941: &Apache::lonnet::idput($env{'form.ccdomain'},
1942: ($env{'form.ccuname'} => $env{'form.cid'}));
1943: if (($recurseid) &&
1944: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
1945: my $idresult =
1946: &Apache::lonuserutils::propagate_id_change(
1947: $env{'form.ccuname'},$env{'form.ccdomain'},
1948: \%userupdate);
1949: $r->print('<br />'.$idresult.'<br />');
1950: }
1.196 raeburn 1951: }
1.149 raeburn 1952: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
1953: ($env{'form.ccuname'} eq $env{'user.name'})) {
1954: my %newenvhash;
1955: foreach my $key (keys(%changeHash)) {
1956: $newenvhash{'environment.'.$key} = $changeHash{$key};
1957: }
1958: &Apache::lonnet::appenv(%newenvhash);
1959: }
1.28 matthew 1960: } else { # error occurred
1.188 raeburn 1961: $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
1962: $env{'form.ccuname'}.' '.&mt('in domain').' '.
1.206 raeburn 1963: $env{'form.ccdomain'}.'</span><br />');
1.28 matthew 1964: }
1.101 albertel 1965: } else { # End of if ($env ... ) logic
1.204 raeburn 1966: # They did not want to change the users name or quota but we can
1967: # still tell them what the name and quota are
1.73 sakharuk 1968: my %lt=&Apache::lonlocal::texthash(
1.196 raeburn 1969: 'id' => "ID/Student number",
1.160 raeburn 1970: 'mail' => "Permanent e-mail",
1.134 raeburn 1971: 'disk' => "Disk space allocated to user's portfolio files",
1.73 sakharuk 1972: );
1.134 raeburn 1973: $r->print(<<"END");
1.196 raeburn 1974: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
1.28 matthew 1975: END
1.204 raeburn 1976: if ($userenv{'permanentemail'} ne '') {
1977: $r->print('<br />['.$lt{'mail'}.': '.
1978: $userenv{'permanentemail'}.']');
1.134 raeburn 1979: }
1.220 raeburn 1980: if ($showquota) {
1981: $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '.
1982: $olddefquotatext.']');
1983: }
1984: $r->print('</h4>');
1.28 matthew 1985: }
1.206 raeburn 1986: if (@mod_disallowed) {
1987: my ($rolestr,$contextname);
1988: if (@longroles > 0) {
1989: $rolestr = join(', ',@longroles);
1990: } else {
1991: $rolestr = &mt('No roles');
1992: }
1993: if ($context eq 'course') {
1994: $contextname = &mt('course');
1995: } elsif ($context eq 'author') {
1996: $contextname = &mt('co-author');
1997: }
1998: $r->print(&mt('The following fields were not updated: ').'<ul>');
1999: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2000: foreach my $field (@mod_disallowed) {
2001: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
2002: }
1.207 raeburn 2003: $r->print('</ul>');
2004: if (@mod_disallowed == 1) {
2005: $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));
2006: } else {
2007: $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));
2008: }
2009: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'.
2010: &mt('Contact your <a href="[_1]">helpdesk</a> for more information.',"javascript:helpMenu('display')").'<br />');
1.206 raeburn 2011: }
2012: $r->print($no_forceid_alert.
2013: &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts, \%curr_rules));
1.4 www 2014: }
1.220 raeburn 2015: if ($env{'form.action'} eq 'singlestudent') {
2016: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser);
1.226 raeburn 2017: $r->print('<p><a href="javascript:backPage(document.userupdate)">'. &mt('Enroll Another Student').'</a></p>');
1.220 raeburn 2018: } else {
1.225 raeburn 2019: my @rolechanges = &update_roles($r);
2020: if ($namechanged) {
1.220 raeburn 2021: if ($context eq 'course') {
2022: if (@userroles > 0) {
1.225 raeburn 2023: if ((@rolechanges == 0) ||
2024: (!(grep(/^st$/,@rolechanges)))) {
2025: if (grep(/^st$/,@userroles)) {
2026: my $classlistupdated =
2027: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 2028: $cnum,$env{'form.ccdomain'},
2029: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 2030: }
1.220 raeburn 2031: }
2032: }
2033: }
2034: }
1.226 raeburn 2035: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
2036: $env{'form.ccdomain'});
2037: $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 2038: }
2039: $r->print(&Apache::loncommon::end_page());
2040: }
2041:
2042: sub update_roles {
2043: my ($r) = @_;
1.4 www 2044: my $now=time;
1.225 raeburn 2045: my @rolechanges;
1.220 raeburn 2046: my %disallowed;
1.73 sakharuk 2047: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 2048: foreach my $key (keys (%env)) {
2049: next if (! $env{$key});
1.190 raeburn 2050: next if ($key eq 'form.action');
1.27 matthew 2051: # Revoke roles
1.135 raeburn 2052: if ($key=~/^form\.rev/) {
2053: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 2054: # Revoke standard role
1.170 albertel 2055: my ($scope,$role) = ($1,$2);
2056: my $result =
2057: &Apache::lonnet::revokerole($env{'form.ccdomain'},
2058: $env{'form.ccuname'},
2059: $scope,$role);
2060: $r->print(&mt('Revoking [_1] in [_2]: [_3]',
2061: $role,$scope,'<b>'.$result.'</b>').'<br />');
2062: if ($role eq 'st') {
1.202 raeburn 2063: my $result =
1.198 raeburn 2064: &Apache::lonuserutils::classlist_drop($scope,
2065: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 2066: $now);
1.170 albertel 2067: $r->print($result);
1.53 www 2068: }
1.225 raeburn 2069: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2070: push(@rolechanges,$role);
2071: }
1.196 raeburn 2072: }
1.195 raeburn 2073: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 2074: # Revoke custom role
1.113 raeburn 2075: $r->print(&mt('Revoking custom role:').
1.139 albertel 2076: ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
1.101 albertel 2077: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
2078: $env{'form.ccuname'},$1,$2,$3,$4).
1.102 albertel 2079: '</b><br />');
1.225 raeburn 2080: if (!grep(/^cr$/,@rolechanges)) {
2081: push(@rolechanges,'cr');
2082: }
1.64 www 2083: }
1.135 raeburn 2084: } elsif ($key=~/^form\.del/) {
2085: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 2086: # Delete standard role
1.170 albertel 2087: my ($scope,$role) = ($1,$2);
2088: my $result =
2089: &Apache::lonnet::assignrole($env{'form.ccdomain'},
2090: $env{'form.ccuname'},
2091: $scope,$role,$now,0,1);
2092: $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
2093: '<b>'.$result.'</b>').'<br />');
2094: if ($role eq 'st') {
1.202 raeburn 2095: my $result =
1.198 raeburn 2096: &Apache::lonuserutils::classlist_drop($scope,
2097: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 2098: $now);
1.170 albertel 2099: $r->print($result);
1.81 albertel 2100: }
1.225 raeburn 2101: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2102: push(@rolechanges,$role);
2103: }
1.116 raeburn 2104: }
1.139 albertel 2105: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 2106: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
2107: # Delete custom role
1.170 albertel 2108: $r->print(&mt('Deleting custom role [_1] by [_2]:[_3] in [_4]',
1.116 raeburn 2109: $rolename,$rnam,$rdom,$url).': <b>'.
2110: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
2111: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
2112: 0,1).'</b><br />');
1.225 raeburn 2113: if (!grep(/^cr$/,@rolechanges)) {
2114: push(@rolechanges,'cr');
2115: }
1.116 raeburn 2116: }
1.135 raeburn 2117: } elsif ($key=~/^form\.ren/) {
1.101 albertel 2118: my $udom = $env{'form.ccdomain'};
2119: my $uname = $env{'form.ccuname'};
1.116 raeburn 2120: # Re-enable standard role
1.135 raeburn 2121: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 2122: my $url = $1;
2123: my $role = $2;
2124: my $logmsg;
2125: my $output;
2126: if ($role eq 'st') {
1.141 albertel 2127: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.129 albertel 2128: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.220 raeburn 2129: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 2130: if ($result eq 'refused' && $logmsg) {
2131: $output = $logmsg;
2132: } else {
2133: $output = "Error: $result\n";
2134: }
1.89 raeburn 2135: } else {
2136: $output = &mt('Assigning').' '.$role.' in '.$url.
2137: &mt('starting').' '.localtime($now).
2138: ': <br />'.$logmsg.'<br />'.
2139: &mt('Add to classlist').': <b>ok</b><br />';
2140: }
2141: }
2142: } else {
1.101 albertel 2143: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
2144: $env{'form.ccuname'},$url,$role,0,$now);
1.116 raeburn 2145: $output = &mt('Re-enabling [_1] in [_2]: <b>[_3]</b>',
1.89 raeburn 2146: $role,$url,$result).'<br />';
1.27 matthew 2147: }
1.89 raeburn 2148: $r->print($output);
1.225 raeburn 2149: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2150: push(@rolechanges,$role);
2151: }
1.113 raeburn 2152: }
1.116 raeburn 2153: # Re-enable custom role
1.139 albertel 2154: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 2155: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
2156: my $result = &Apache::lonnet::assigncustomrole(
2157: $env{'form.ccdomain'}, $env{'form.ccuname'},
2158: $url,$rdom,$rnam,$rolename,0,$now);
2159: $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : <b>[_5]</b>',
2160: $rolename,$rnam,$rdom,$url,$result).'<br />');
1.225 raeburn 2161: if (!grep(/^cr$/,@rolechanges)) {
2162: push(@rolechanges,'cr');
2163: }
1.116 raeburn 2164: }
1.135 raeburn 2165: } elsif ($key=~/^form\.act/) {
1.101 albertel 2166: my $udom = $env{'form.ccdomain'};
2167: my $uname = $env{'form.ccuname'};
1.141 albertel 2168: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 2169: # Activate a custom role
1.83 albertel 2170: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
2171: my $url='/'.$one.'/'.$two;
2172: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 2173:
1.101 albertel 2174: my $start = ( $env{'form.start_'.$full} ?
2175: $env{'form.start_'.$full} :
1.88 raeburn 2176: $now );
1.101 albertel 2177: my $end = ( $env{'form.end_'.$full} ?
2178: $env{'form.end_'.$full} :
1.88 raeburn 2179: 0 );
2180:
2181: # split multiple sections
2182: my %sections = ();
1.101 albertel 2183: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 2184: if ($num_sections == 0) {
1.129 albertel 2185: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
1.88 raeburn 2186: } else {
1.114 albertel 2187: my %curr_groups =
1.117 raeburn 2188: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 2189: foreach my $sec (sort {$a cmp $b} keys %sections) {
2190: if (($sec eq 'none') || ($sec eq 'all') ||
2191: exists($curr_groups{$sec})) {
2192: $disallowed{$sec} = $url;
2193: next;
2194: }
2195: my $securl = $url.'/'.$sec;
1.129 albertel 2196: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
1.88 raeburn 2197: }
2198: }
1.225 raeburn 2199: if (!grep(/^cr$/,@rolechanges)) {
2200: push(@rolechanges,'cr');
2201: }
1.142 raeburn 2202: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 2203: # Activate roles for sections with 3 id numbers
2204: # set start, end times, and the url for the class
1.83 albertel 2205: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 2206: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
2207: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 2208: $now );
1.101 albertel 2209: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
2210: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 2211: 0 );
1.83 albertel 2212: my $url='/'.$one.'/'.$two;
1.88 raeburn 2213: my $type = 'three';
2214: # split multiple sections
2215: my %sections = ();
1.101 albertel 2216: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 2217: if ($num_sections == 0) {
1.129 albertel 2218: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 2219: } else {
1.114 albertel 2220: my %curr_groups =
1.117 raeburn 2221: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 2222: my $emptysec = 0;
2223: foreach my $sec (sort {$a cmp $b} keys %sections) {
2224: $sec =~ s/\W//g;
1.113 raeburn 2225: if ($sec ne '') {
2226: if (($sec eq 'none') || ($sec eq 'all') ||
2227: exists($curr_groups{$sec})) {
2228: $disallowed{$sec} = $url;
2229: next;
2230: }
1.88 raeburn 2231: my $securl = $url.'/'.$sec;
1.129 albertel 2232: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
1.88 raeburn 2233: } else {
2234: $emptysec = 1;
2235: }
2236: }
2237: if ($emptysec) {
1.129 albertel 2238: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
1.88 raeburn 2239: }
1.225 raeburn 2240: }
2241: if (!grep(/^\Q$three\E$/,@rolechanges)) {
2242: push(@rolechanges,$three);
2243: }
1.135 raeburn 2244: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 2245: # Activate roles for sections with two id numbers
2246: # set start, end times, and the url for the class
1.101 albertel 2247: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
2248: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 2249: $now );
1.101 albertel 2250: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
2251: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 2252: 0 );
1.225 raeburn 2253: my $one = $1;
2254: my $two = $2;
2255: my $url='/'.$one.'/';
1.88 raeburn 2256: # split multiple sections
2257: my %sections = ();
1.225 raeburn 2258: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 2259: if ($num_sections == 0) {
1.225 raeburn 2260: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,''));
1.88 raeburn 2261: } else {
2262: my $emptysec = 0;
2263: foreach my $sec (sort {$a cmp $b} keys %sections) {
2264: if ($sec ne '') {
2265: my $securl = $url.'/'.$sec;
1.225 raeburn 2266: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec));
1.88 raeburn 2267: } else {
2268: $emptysec = 1;
2269: }
2270: }
2271: if ($emptysec) {
1.225 raeburn 2272: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,''));
1.88 raeburn 2273: }
2274: }
1.225 raeburn 2275: if (!grep(/^\Q$two\E$/,@rolechanges)) {
2276: push(@rolechanges,$two);
2277: }
1.64 www 2278: } else {
1.190 raeburn 2279: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 2280: }
1.113 raeburn 2281: foreach my $key (sort(keys(%disallowed))) {
2282: if (($key eq 'none') || ($key eq 'all')) {
2283: $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
2284: } else {
2285: $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));
2286: }
2287: $r->print(' '.&mt('Please <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />');
2288: }
2289: }
1.101 albertel 2290: } # End of foreach (keys(%env))
1.75 www 2291: # Flush the course logs so reverse user roles immediately updated
2292: &Apache::lonnet::flushcourselogs();
1.225 raeburn 2293: if (@rolechanges == 0) {
1.193 raeburn 2294: $r->print(&mt('No roles to modify'));
2295: }
1.225 raeburn 2296: return @rolechanges;
1.220 raeburn 2297: }
2298:
2299: sub enroll_single_student {
2300: my ($r,$uhome,$amode,$genpwd,$now,$newuser) = @_;
2301: $r->print('<h3>'.&mt('Enrolling Student').'</h3>');
2302:
2303: # Remove non alphanumeric values from section
2304: $env{'form.sections'}=~s/\W//g;
2305:
2306: # Clean out any old student roles the user has in this class.
2307: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
2308: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
2309: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
2310: my $enroll_result =
2311: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
2312: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
2313: $env{'form.cmiddlename'},$env{'form.clastname'},
2314: $env{'form.generation'},$env{'form.sections'},$enddate,
2315: $startdate,'manual',undef,$env{'request.course.id'});
2316: if ($enroll_result =~ /^ok/) {
2317: $r->print(&mt('<b>[_1]</b> enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'}));
2318: if ($env{'form.sections'} ne '') {
2319: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
2320: }
2321: my ($showstart,$showend);
2322: if ($startdate <= $now) {
2323: $showstart = &mt('Access starts immediately');
2324: } else {
2325: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
2326: }
2327: if ($enddate == 0) {
2328: $showend = &mt('ends: no ending date');
2329: } else {
2330: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
2331: }
2332: $r->print('.<br />'.$showstart.'; '.$showend);
2333: if ($startdate <= $now && !$newuser) {
2334: $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>");
2335: }
2336: } else {
2337: $r->print(&mt('unable to enroll').": ".$enroll_result);
2338: }
2339: return;
1.188 raeburn 2340: }
2341:
1.204 raeburn 2342: sub get_defaultquota_text {
2343: my ($settingstatus) = @_;
2344: my $defquotatext;
2345: if ($settingstatus eq '') {
2346: $defquotatext = &mt('(default)');
2347: } else {
2348: my ($usertypes,$order) =
2349: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
2350: if ($usertypes->{$settingstatus} eq '') {
2351: $defquotatext = &mt('(default)');
2352: } else {
2353: $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
2354: }
2355: }
2356: return $defquotatext;
2357: }
2358:
1.188 raeburn 2359: sub update_result_form {
2360: my ($uhome) = @_;
2361: my $outcome =
2362: '<form name="userupdate" method="post" />'."\n";
1.160 raeburn 2363: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 2364: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2365: }
1.207 raeburn 2366: if ($env{'form.origname'} ne '') {
2367: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
2368: }
1.160 raeburn 2369: foreach my $item ('sortby','seluname','seludom') {
2370: if (exists($env{'form.'.$item})) {
1.188 raeburn 2371: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2372: }
2373: }
1.188 raeburn 2374: if ($uhome eq 'no_host') {
2375: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
2376: }
2377: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
2378: '<input type ="hidden" name="currstate" value="" />'."\n".
1.220 raeburn 2379: '<input type ="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 2380: '</form>';
2381: return $outcome;
1.4 www 2382: }
2383:
1.149 raeburn 2384: sub quota_admin {
2385: my ($setquota,$changeHash) = @_;
2386: my $quotachanged;
2387: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
2388: # Current user has quota modification privileges
2389: $quotachanged = 1;
2390: $changeHash->{'portfolioquota'} = $setquota;
2391: }
2392: return $quotachanged;
2393: }
2394:
1.88 raeburn 2395: sub build_roles {
1.89 raeburn 2396: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 2397: my $num_sections = 0;
2398: if ($sectionstr=~ /,/) {
2399: my @secnums = split/,/,$sectionstr;
1.89 raeburn 2400: if ($role eq 'st') {
2401: $secnums[0] =~ s/\W//g;
2402: $$sections{$secnums[0]} = 1;
2403: $num_sections = 1;
2404: } else {
2405: foreach my $sec (@secnums) {
2406: $sec =~ ~s/\W//g;
1.150 banghart 2407: if (!($sec eq "")) {
1.89 raeburn 2408: if (exists($$sections{$sec})) {
2409: $$sections{$sec} ++;
2410: } else {
2411: $$sections{$sec} = 1;
2412: $num_sections ++;
2413: }
1.88 raeburn 2414: }
2415: }
2416: }
2417: } else {
2418: $sectionstr=~s/\W//g;
2419: unless ($sectionstr eq '') {
2420: $$sections{$sectionstr} = 1;
2421: $num_sections ++;
2422: }
2423: }
1.129 albertel 2424:
1.88 raeburn 2425: return $num_sections;
2426: }
2427:
1.58 www 2428: # ========================================================== Custom Role Editor
2429:
2430: sub custom_role_editor {
1.160 raeburn 2431: my ($r) = @_;
1.101 albertel 2432: my $rolename=$env{'form.rolename'};
1.58 www 2433:
1.59 www 2434: if ($rolename eq 'make new role') {
1.101 albertel 2435: $rolename=$env{'form.newrolename'};
1.59 www 2436: }
2437:
1.63 www 2438: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 2439:
1.190 raeburn 2440: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.58 www 2441: &print_username_entry_form($r);
2442: return;
2443: }
1.153 banghart 2444: # ------------------------------------------------------- What can be assigned?
2445: my %full=();
2446: my %courselevel=();
2447: my %courselevelcurrent=();
1.61 www 2448: my $syspriv='';
2449: my $dompriv='';
2450: my $coursepriv='';
1.153 banghart 2451: my $body_top;
1.150 banghart 2452: my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
1.59 www 2453: my ($rdummy,$roledef)=
2454: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 2455: # ------------------------------------------------------- Does this role exist?
1.153 banghart 2456: $body_top .= '<h2>';
1.59 www 2457: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 2458: $body_top .= &mt('Existing Role').' "';
1.61 www 2459: # ------------------------------------------------- Get current role privileges
2460: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 2461: } else {
1.153 banghart 2462: $body_top .= &mt('New Role').' "';
1.59 www 2463: $roledef='';
2464: }
1.153 banghart 2465: $body_top .= $rolename.'"</h2>';
1.135 raeburn 2466: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2467: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2468: if (!$restrict) { $restrict='F'; }
1.60 www 2469: $courselevel{$priv}=$restrict;
1.61 www 2470: if ($coursepriv=~/\:$priv/) {
2471: $courselevelcurrent{$priv}=1;
2472: }
1.60 www 2473: $full{$priv}=1;
2474: }
2475: my %domainlevel=();
1.61 www 2476: my %domainlevelcurrent=();
1.135 raeburn 2477: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2478: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2479: if (!$restrict) { $restrict='F'; }
1.60 www 2480: $domainlevel{$priv}=$restrict;
1.61 www 2481: if ($dompriv=~/\:$priv/) {
2482: $domainlevelcurrent{$priv}=1;
2483: }
1.60 www 2484: $full{$priv}=1;
2485: }
1.61 www 2486: my %systemlevel=();
2487: my %systemlevelcurrent=();
1.135 raeburn 2488: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2489: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2490: if (!$restrict) { $restrict='F'; }
1.61 www 2491: $systemlevel{$priv}=$restrict;
2492: if ($syspriv=~/\:$priv/) {
2493: $systemlevelcurrent{$priv}=1;
2494: }
2495: $full{$priv}=1;
2496: }
1.160 raeburn 2497: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 2498: my $button_code = "\n";
1.153 banghart 2499: my $head_script = "\n";
2500: $head_script .= '<script type="text/javascript">'."\n";
1.154 banghart 2501: my @template_roles = ("cc","in","ta","ep","st");
2502: foreach my $role (@template_roles) {
2503: $head_script .= &make_script_template($role);
2504: $button_code .= &make_button_code($role);
2505: }
1.160 raeburn 2506: $head_script .= "\n".$jsback."\n".'</script>'."\n";
1.153 banghart 2507: $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
1.160 raeburn 2508: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 2509: ({href=>"javascript:backPage(document.form1,'pickrole','')",
2510: text=>"Pick custom role",
1.160 raeburn 2511: faq=>282,bug=>'Instructor Interface',},
2512: {href=>"javascript:backPage(document.form1,'','')",
2513: text=>"Edit custom role",
2514: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 2515: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
2516: 'Course_Editing_Custom_Roles'));
1.160 raeburn 2517:
1.153 banghart 2518: $r->print($body_top);
1.73 sakharuk 2519: my %lt=&Apache::lonlocal::texthash(
2520: 'prv' => "Privilege",
1.131 raeburn 2521: 'crl' => "Course Level",
1.73 sakharuk 2522: 'dml' => "Domain Level",
1.150 banghart 2523: 'ssl' => "System Level");
1.152 banghart 2524: $r->print('Select a Template<br />');
1.154 banghart 2525: $r->print('<form action="">');
2526: $r->print($button_code);
2527: $r->print('</form>');
1.61 www 2528: $r->print(<<ENDCCF);
1.160 raeburn 2529: <form name="form1" method="post">
1.61 www 2530: <input type="hidden" name="phase" value="set_custom_roles" />
2531: <input type="hidden" name="rolename" value="$rolename" />
2532: ENDCCF
1.135 raeburn 2533: $r->print(&Apache::loncommon::start_data_table().
2534: &Apache::loncommon::start_data_table_header_row().
2535: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
2536: '</th><th>'.$lt{'ssl'}.'</th>'.
2537: &Apache::loncommon::end_data_table_header_row());
1.119 raeburn 2538: foreach my $priv (sort keys %full) {
2539: my $privtext = &Apache::lonnet::plaintext($priv);
1.135 raeburn 2540: $r->print(&Apache::loncommon::start_data_table_row().
2541: '<td>'.$privtext.'</td><td>'.
1.150 banghart 2542: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c" '.
1.119 raeburn 2543: ($courselevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2544: '</td><td>'.
1.150 banghart 2545: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d" '.
1.119 raeburn 2546: ($domainlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2547: '</td><td>'.
1.150 banghart 2548: ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s" '.
1.119 raeburn 2549: ($systemlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.135 raeburn 2550: '</td>'.
2551: &Apache::loncommon::end_data_table_row());
1.60 www 2552: }
1.135 raeburn 2553: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 2554: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 2555: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 2556: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 2557: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
2558: '<input type="submit" value="'.&mt('Define Role').'" /></form>'.
1.110 albertel 2559: &Apache::loncommon::end_page());
1.61 www 2560: }
1.153 banghart 2561: # --------------------------------------------------------
2562: sub make_script_template {
2563: my ($role) = @_;
2564: my %full_c=();
2565: my %full_d=();
2566: my %full_s=();
2567: my $return_script;
2568: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2569: my ($priv,$restrict)=split(/\&/,$item);
2570: $full_c{$priv}=1;
2571: }
2572: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2573: my ($priv,$restrict)=split(/\&/,$item);
2574: $full_d{$priv}=1;
2575: }
1.154 banghart 2576: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.153 banghart 2577: my ($priv,$restrict)=split(/\&/,$item);
2578: $full_s{$priv}=1;
2579: }
2580: $return_script .= 'function set_'.$role.'() {'."\n";
2581: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
2582: my %role_c;
1.155 banghart 2583: foreach my $priv (@temp) {
1.153 banghart 2584: my ($priv_item, $dummy) = split(/\&/,$priv);
2585: $role_c{$priv_item} = 1;
2586: }
2587: foreach my $priv_item (keys(%full_c)) {
2588: my ($priv, $dummy) = split(/\&/,$priv_item);
2589: if (exists($role_c{$priv})) {
2590: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
2591: } else {
2592: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
2593: }
2594: }
1.154 banghart 2595: my %role_d;
2596: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
2597: foreach my $priv(@temp) {
2598: my ($priv_item, $dummy) = split(/\&/,$priv);
2599: $role_d{$priv_item} = 1;
2600: }
2601: foreach my $priv_item (keys(%full_d)) {
2602: my ($priv, $dummy) = split(/\&/,$priv_item);
2603: if (exists($role_d{$priv})) {
2604: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
2605: } else {
2606: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
2607: }
2608: }
2609: my %role_s;
2610: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
2611: foreach my $priv(@temp) {
2612: my ($priv_item, $dummy) = split(/\&/,$priv);
2613: $role_s{$priv_item} = 1;
2614: }
2615: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 2616: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 2617: if (exists($role_s{$priv})) {
2618: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
2619: } else {
2620: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
2621: }
1.153 banghart 2622: }
2623: $return_script .= '}'."\n";
1.154 banghart 2624: return ($return_script);
2625: }
2626: # ----------------------------------------------------------
2627: sub make_button_code {
2628: my ($role) = @_;
2629: my $label = &Apache::lonnet::plaintext($role);
2630: my $button_code = '<input type="button" onClick="set_'.$role.'()" value="'.$label.'" />';
2631: return ($button_code);
1.153 banghart 2632: }
1.61 www 2633: # ---------------------------------------------------------- Call to definerole
2634: sub set_custom_role {
1.110 albertel 2635: my ($r) = @_;
1.101 albertel 2636: my $rolename=$env{'form.rolename'};
1.63 www 2637: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 2638: if (!$rolename) {
1.190 raeburn 2639: &custom_role_editor($r);
1.61 www 2640: return;
2641: }
1.160 raeburn 2642: my ($jsback,$elements) = &crumb_utilities();
2643: my $jscript = '<script type="text/javascript">'.$jsback."\n".'</script>';
2644:
2645: $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
2646: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 2647: ({href=>"javascript:backPage(document.customresult,'pickrole','')",
2648: text=>"Pick custom role",
1.160 raeburn 2649: faq=>282,bug=>'Instructor Interface',},
2650: {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
2651: text=>"Edit custom role",
2652: faq=>282,bug=>'Instructor Interface',},
2653: {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
2654: text=>"Result",
2655: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 2656: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
2657: 'Course_Editing_Custom_Roles'));
1.160 raeburn 2658:
1.61 www 2659: my ($rdummy,$roledef)=
1.110 albertel 2660: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
2661:
1.61 www 2662: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 2663: $r->print('<h3>');
1.61 www 2664: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 2665: $r->print(&mt('Existing Role').' "');
1.61 www 2666: } else {
1.73 sakharuk 2667: $r->print(&mt('New Role').' "');
1.61 www 2668: $roledef='';
2669: }
1.188 raeburn 2670: $r->print($rolename.'"</h3>');
1.61 www 2671: # ------------------------------------------------------- What can be assigned?
2672: my $sysrole='';
2673: my $domrole='';
2674: my $courole='';
2675:
1.135 raeburn 2676: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2677: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2678: if (!$restrict) { $restrict=''; }
2679: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 2680: $courole.=':'.$item;
1.61 www 2681: }
2682: }
2683:
1.135 raeburn 2684: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2685: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2686: if (!$restrict) { $restrict=''; }
2687: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 2688: $domrole.=':'.$item;
1.61 www 2689: }
2690: }
2691:
1.135 raeburn 2692: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2693: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2694: if (!$restrict) { $restrict=''; }
2695: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 2696: $sysrole.=':'.$item;
1.61 www 2697: }
2698: }
1.63 www 2699: $r->print('<br />Defining Role: '.
1.61 www 2700: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 2701: if ($env{'request.course.id'}) {
2702: my $url='/'.$env{'request.course.id'};
1.63 www 2703: $url=~s/\_/\//g;
1.73 sakharuk 2704: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 2705: &Apache::lonnet::assigncustomrole($env{'user.domain'},
2706: $env{'user.name'},
1.63 www 2707: $url,
1.101 albertel 2708: $env{'user.domain'},
2709: $env{'user.name'},
1.63 www 2710: $rolename));
2711: }
1.190 raeburn 2712: $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 2713: $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
1.110 albertel 2714: $r->print(&Apache::loncommon::end_page());
1.58 www 2715: }
2716:
1.2 www 2717: # ================================================================ Main Handler
2718: sub handler {
2719: my $r = shift;
2720: if ($r->header_only) {
1.68 www 2721: &Apache::loncommon::content_type($r,'text/html');
1.2 www 2722: $r->send_http_header;
2723: return OK;
2724: }
1.190 raeburn 2725: my $context;
2726: if ($env{'request.course.id'}) {
2727: $context = 'course';
2728: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 2729: $context = 'author';
1.190 raeburn 2730: } else {
2731: $context = 'domain';
2732: }
2733: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.202 raeburn 2734: ['action','state','callingform','roletype','showrole','bulkaction']);
1.190 raeburn 2735: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.202 raeburn 2736: if ($env{'form.action'} ne 'dateselect') {
2737: &Apache::lonhtmlcommon::add_breadcrumb
2738: ({href=>"/adm/createuser",
2739: text=>"User Management"});
2740: }
1.209 raeburn 2741: my ($permission,$allowed) =
2742: &Apache::lonuserutils::get_permission($context);
1.190 raeburn 2743: if (!$allowed) {
2744: $env{'user.error.msg'}=
2745: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
2746: "or view user status.";
2747: return HTTP_NOT_ACCEPTABLE;
2748: }
2749:
2750: &Apache::loncommon::content_type($r,'text/html');
2751: $r->send_http_header;
2752:
2753: # Main switch on form.action and form.state, as appropriate
2754: if (! exists($env{'form.action'})) {
2755: $r->print(&header());
2756: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.208 raeburn 2757: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 2758: $r->print(&Apache::loncommon::end_page());
2759: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
2760: $r->print(&header());
2761: &Apache::lonhtmlcommon::add_breadcrumb
2762: ({href=>'/adm/createuser?action=upload&state=',
2763: text=>"Upload Users List"});
2764: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Upload Users List',
1.224 raeburn 2765: 'Course_Create_Class_List'));
1.190 raeburn 2766: $r->print('<form name="studentform" method="post" '.
2767: 'enctype="multipart/form-data" '.
2768: ' action="/adm/createuser">'."\n");
2769: if (! exists($env{'form.state'})) {
2770: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
2771: } elsif ($env{'form.state'} eq 'got_file') {
1.221 raeburn 2772: &Apache::lonuserutils::print_upload_manager_form($r,$context,
2773: $permission);
1.190 raeburn 2774: } elsif ($env{'form.state'} eq 'enrolling') {
2775: if ($env{'form.datatoken'}) {
1.221 raeburn 2776: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission);
1.190 raeburn 2777: }
2778: } else {
2779: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
2780: }
2781: $r->print('</form>'.&Apache::loncommon::end_page());
1.213 raeburn 2782: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
2783: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 2784: my $phase = $env{'form.phase'};
2785: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 2786: &Apache::loncreateuser::restore_prev_selections();
2787: my $srch;
2788: foreach my $item (@search) {
2789: $srch->{$item} = $env{'form.'.$item};
2790: }
1.207 raeburn 2791: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
2792: ($phase eq 'createnewuser')) {
2793: if ($env{'form.phase'} eq 'createnewuser') {
2794: my $response;
2795: if ($env{'form.srchterm'} !~ /^$match_username$/) {
2796: my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
1.221 raeburn 2797: $env{'form.phase'} = '';
1.207 raeburn 2798: &print_username_entry_form($r,$context,$response,$srch);
2799: } else {
2800: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
2801: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
2802: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 2803: $srch,$response,$context,
2804: $permission);
1.207 raeburn 2805: }
2806: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 2807: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 2808: &user_search_result($context,$srch);
1.190 raeburn 2809: if ($env{'form.currstate'} eq 'modify') {
2810: $currstate = $env{'form.currstate'};
2811: }
2812: if ($currstate eq 'select') {
2813: &print_user_selection_page($r,$response,$srch,$results,
1.229 raeburn 2814: \@search,$context);
1.190 raeburn 2815: } elsif ($currstate eq 'modify') {
2816: my ($ccuname,$ccdomain);
2817: if (($srch->{'srchby'} eq 'uname') &&
2818: ($srch->{'srchtype'} eq 'exact')) {
2819: $ccuname = $srch->{'srchterm'};
2820: $ccdomain= $srch->{'srchdomain'};
2821: } else {
2822: my @matchedunames = keys(%{$results});
2823: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
2824: }
2825: $ccuname =&LONCAPA::clean_username($ccuname);
2826: $ccdomain=&LONCAPA::clean_domain($ccdomain);
2827: if ($env{'form.forcenewuser'}) {
2828: $response = '';
2829: }
2830: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 2831: $srch,$response,$context,
2832: $permission);
1.190 raeburn 2833: } elsif ($currstate eq 'query') {
2834: &print_user_query_page($r,'createuser');
2835: } else {
1.229 raeburn 2836: $env{'form.phase'} = '';
1.207 raeburn 2837: &print_username_entry_form($r,$context,$response,$srch,
1.190 raeburn 2838: $forcenewuser);
2839: }
2840: } elsif ($env{'form.phase'} eq 'userpicked') {
2841: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
2842: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 2843: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.221 raeburn 2844: $context,$permission);
1.190 raeburn 2845: }
2846: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.206 raeburn 2847: &update_user_data($r,$context);
1.190 raeburn 2848: } else {
1.207 raeburn 2849: &print_username_entry_form($r,$context,undef,$srch);
1.190 raeburn 2850: }
2851: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
2852: if ($env{'form.phase'} eq 'set_custom_roles') {
2853: &set_custom_role($r);
2854: } else {
2855: &custom_role_editor($r);
2856: }
1.207 raeburn 2857: } elsif (($env{'form.action'} eq 'listusers') &&
2858: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 2859: if ($env{'form.phase'} eq 'bulkchange') {
2860: &Apache::lonhtmlcommon::add_breadcrumb
1.221 raeburn 2861: ({href=>'/adm/createuser?action=listusers',
2862: text=>"List Users"},
2863: {href=>"/adm/createuser",
2864: text=>"Result"});
1.202 raeburn 2865: my $setting = $env{'form.roletype'};
2866: my $choice = $env{'form.bulkaction'};
2867: $r->print(&header());
1.221 raeburn 2868: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Update Users",
1.224 raeburn 2869: 'Course_View_Class_List'));
1.202 raeburn 2870: if ($permission->{'cusr'}) {
2871: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
1.221 raeburn 2872: $r->print(&Apache::loncommon::end_page());
2873: } else {
2874: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 2875: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.221 raeburn 2876: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 2877: }
2878: } else {
2879: &Apache::lonhtmlcommon::add_breadcrumb
2880: ({href=>'/adm/createuser?action=listusers',
2881: text=>"List Users"});
2882: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
2883: my $formname = 'studentform';
2884: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
2885: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
2886: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
2887: $formname);
2888: $jscript .= &verify_user_display();
2889: my $js = &add_script($jscript).$cb_jscript;
2890: my $loadcode =
2891: &Apache::lonuserutils::course_selector_loadcode($formname);
2892: if ($loadcode ne '') {
2893: $r->print(&header($js,{'onload' => $loadcode,}));
2894: } else {
2895: $r->print(&header($js));
2896: }
1.191 raeburn 2897: } else {
1.202 raeburn 2898: $r->print(&header(&add_script(&verify_user_display())));
1.191 raeburn 2899: }
1.202 raeburn 2900: $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
1.224 raeburn 2901: 'Course_View_Class_List'));
1.202 raeburn 2902: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
2903: $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
2904: $r->print(&Apache::loncommon::end_page());
1.191 raeburn 2905: }
1.213 raeburn 2906: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
2907: $r->print(&header());
2908: &Apache::lonhtmlcommon::add_breadcrumb
2909: ({href=>'/adm/createuser?action=drop',
2910: text=>"Drop Students"});
2911: if (!exists($env{'form.state'})) {
2912: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
2913: 'Course_Drop_Student'));
2914:
2915: &Apache::lonuserutils::print_drop_menu($r,$context,$permission);
2916: } elsif ($env{'form.state'} eq 'done') {
2917: &Apache::lonhtmlcommon::add_breadcrumb
2918: ({href=>'/adm/createuser?action=drop',
2919: text=>"Result"});
2920: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
2921: 'Course_Drop_Student'));
2922: &Apache::lonuserutils::update_user_list($r,$context,undef,
2923: $env{'form.action'});
2924: }
2925: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 2926: } elsif ($env{'form.action'} eq 'dateselect') {
2927: if ($permission->{'cusr'}) {
2928: $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
1.221 raeburn 2929: &Apache::lonuserutils::date_section_selector($context,
2930: $permission).
1.202 raeburn 2931: &Apache::loncommon::end_page());
2932: } else {
2933: $r->print(&header().
2934: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'.
2935: &Apache::loncommon::end_page());
2936: }
1.190 raeburn 2937: } else {
2938: $r->print(&header());
1.202 raeburn 2939: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.207 raeburn 2940: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 2941: $r->print(&Apache::loncommon::end_page());
2942: }
2943: return OK;
2944: }
2945:
2946: sub header {
1.202 raeburn 2947: my ($jscript,$loaditems,$args) = @_;
1.190 raeburn 2948: my $start_page;
2949: if (ref($loaditems) eq 'HASH') {
1.202 raeburn 2950: $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
1.190 raeburn 2951: } else {
1.202 raeburn 2952: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 2953: }
2954: return $start_page;
2955: }
1.2 www 2956:
1.191 raeburn 2957: sub add_script {
2958: my ($js) = @_;
2959: return '<script type="text/javascript">'."\n".$js."\n".'</script>';
2960: }
2961:
1.202 raeburn 2962: sub verify_user_display {
2963: my $output = <<"END";
2964:
2965: function display_update() {
2966: document.studentform.action.value = 'listusers';
2967: document.studentform.phase.value = 'display';
2968: document.studentform.submit();
2969: }
2970:
2971: END
2972: return $output;
2973:
2974: }
2975:
1.190 raeburn 2976: ###############################################################
2977: ###############################################################
2978: # Menu Phase One
2979: sub print_main_menu {
1.208 raeburn 2980: my ($permission,$context) = @_;
2981: my %links = (
2982: domain => {
2983: upload => 'Upload a File of Users',
1.221 raeburn 2984: singleuser => 'Add/Modify a Single User',
1.208 raeburn 2985: listusers => 'Manage Multiple Users',
2986: },
2987: author => {
2988: upload => 'Upload a File of Co-authors',
1.221 raeburn 2989: singleuser => 'Add/Modify a Single Co-author',
1.208 raeburn 2990: listusers => 'Display Co-authors and Manage Multiple Users',
2991: },
2992: course => {
2993: upload => 'Upload a File of Course Users',
1.221 raeburn 2994: singleuser => 'Add/Modify a Single Course User',
1.208 raeburn 2995: listusers => 'Display Class Lists and Manage Multiple Users',
2996: },
2997: );
1.190 raeburn 2998: my @menu =
2999: (
1.208 raeburn 3000: { text => $links{$context}{'upload'},
1.224 raeburn 3001: help => 'Course_Create_Class_List',
1.190 raeburn 3002: action => 'upload',
3003: permission => $permission->{'cusr'},
3004: },
1.208 raeburn 3005: { text => $links{$context}{'singleuser'},
1.224 raeburn 3006: help => 'Course_Change_Privileges',
1.190 raeburn 3007: action => 'singleuser',
3008: permission => $permission->{'cusr'},
3009: },
1.208 raeburn 3010: { text => $links{$context}{'listusers'},
1.224 raeburn 3011: help => 'Course_View_Class_List',
1.191 raeburn 3012: action => 'listusers',
1.208 raeburn 3013: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.190 raeburn 3014: },
3015: );
1.208 raeburn 3016: if ($context eq 'domain' || $context eq 'course') {
3017: my $customlink = { text => 'Edit Custom Roles',
1.224 raeburn 3018: help => 'Course_Editing_Custom_Roles',
1.208 raeburn 3019: action => 'custom',
3020: permission => $permission->{'custom'},
3021: };
3022: push(@menu,$customlink);
3023: }
3024: if ($context eq 'course') {
1.213 raeburn 3025: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
3026: my @courselinks =
1.208 raeburn 3027: (
1.213 raeburn 3028: { text => 'Enroll a Single Student',
1.224 raeburn 3029: help => 'Course_Add_Student',
1.213 raeburn 3030: action => 'singlestudent',
3031: permission => $permission->{'cusr'},
3032: },
3033: { text => 'Drop Students',
3034: help => 'Course_Drop_Student',
3035: action => 'drop',
3036: permission => $permission->{'cusr'},
3037: });
3038: if (!exists($permission->{'cusr_section'})) {
3039: push(@courselinks,
3040: { text => 'Automated Student Enrollment Manager',
1.228 raeburn 3041: help => 'Course_Automated_Enrollment',
1.208 raeburn 3042: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
3043: && $permission->{'cusr'}),
3044: url => '/adm/populate',
1.213 raeburn 3045: });
3046: }
3047: push(@courselinks,
1.208 raeburn 3048: { text => 'Manage Course Groups',
3049: help => 'Course_Manage_Group',
3050: permission => $permission->{'grp_manage'},
3051: url => '/adm/coursegroups?refpage=cusr',
1.213 raeburn 3052: });
1.208 raeburn 3053: push(@menu,@courselinks);
3054: }
1.190 raeburn 3055: my $menu_html = '';
3056: foreach my $menu_item (@menu) {
3057: next if (! $menu_item->{'permission'});
3058: $menu_html.='<p>';
3059: $menu_html.='<font size="+1">';
3060: if (exists($menu_item->{'url'})) {
3061: $menu_html.=qq{<a href="$menu_item->{'url'}">};
3062: } else {
3063: $menu_html.=
3064: qq{<a href="/adm/createuser?action=$menu_item->{'action'}">};
3065: }
3066: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
3067: if (exists($menu_item->{'help'})) {
3068: $menu_html.=
3069: &Apache::loncommon::help_open_topic($menu_item->{'help'});
3070: }
3071: $menu_html.='</p>';
3072: }
3073: return $menu_html;
3074: }
3075:
1.189 albertel 3076: sub restore_prev_selections {
3077: my %saveable_parameters = ('srchby' => 'scalar',
3078: 'srchin' => 'scalar',
3079: 'srchtype' => 'scalar',
3080: );
3081: &Apache::loncommon::store_settings('user','user_picker',
3082: \%saveable_parameters);
3083: &Apache::loncommon::restore_settings('user','user_picker',
3084: \%saveable_parameters);
3085: }
3086:
1.27 matthew 3087: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 3088: sub user_search_result {
1.221 raeburn 3089: my ($context,$srch) = @_;
1.160 raeburn 3090: my %allhomes;
3091: my %inst_matches;
3092: my %srch_results;
1.181 raeburn 3093: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 3094: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 3095: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 3096: $response = &mt('Invalid search.');
3097: }
3098: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
3099: $response = &mt('Invalid search.');
3100: }
1.177 raeburn 3101: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 3102: $response = &mt('Invalid search.');
3103: }
3104: if ($srch->{'srchterm'} eq '') {
3105: $response = &mt('You must enter a search term.');
3106: }
1.183 raeburn 3107: if ($srch->{'srchterm'} =~ /^\s+$/) {
3108: $response = &mt('Your search term must contain more than just spaces.');
3109: }
1.160 raeburn 3110: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
3111: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 3112: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 3113: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
3114: }
3115: }
3116: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
3117: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 3118: if ($srch->{'srchby'} eq 'uname') {
3119: if ($srch->{'srchterm'} !~ /^$match_username$/) {
3120: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
3121: }
1.160 raeburn 3122: }
3123: }
1.180 raeburn 3124: if ($response ne '') {
3125: $response = '<span class="LC_warning">'.$response.'</span>';
3126: }
1.160 raeburn 3127: if ($srch->{'srchin'} eq 'instd') {
3128: my $instd_chk = &directorysrch_check($srch);
3129: if ($instd_chk ne 'ok') {
1.180 raeburn 3130: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
3131: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 3132: }
3133: }
3134: if ($response ne '') {
1.180 raeburn 3135: return ($currstate,$response);
1.160 raeburn 3136: }
3137: if ($srch->{'srchby'} eq 'uname') {
3138: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
3139: if ($env{'form.forcenew'}) {
3140: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
3141: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
3142: if ($uhome eq 'no_host') {
3143: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 3144: my $showdom = &display_domain_info($env{'request.role.domain'});
3145: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 3146: } else {
1.179 raeburn 3147: $currstate = 'modify';
1.160 raeburn 3148: }
3149: } else {
1.179 raeburn 3150: $currstate = 'modify';
1.160 raeburn 3151: }
3152: } else {
3153: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 3154: if ($srch->{'srchtype'} eq 'exact') {
3155: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
3156: if ($uhome eq 'no_host') {
1.179 raeburn 3157: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3158: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 3159: } else {
1.179 raeburn 3160: $currstate = 'modify';
1.162 raeburn 3161: }
3162: } else {
3163: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 3164: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3165: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 3166: }
3167: } else {
1.167 albertel 3168: my $courseusers = &get_courseusers();
1.162 raeburn 3169: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 3170: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 3171: $currstate = 'modify';
1.162 raeburn 3172: } else {
1.179 raeburn 3173: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3174: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 3175: }
1.160 raeburn 3176: } else {
1.167 albertel 3177: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 3178: my ($cuname,$cudomain) = split(/:/,$user);
3179: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 3180: my $matched = 0;
3181: if ($srch->{'srchtype'} eq 'begins') {
3182: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
3183: $matched = 1;
3184: }
3185: } else {
3186: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
3187: $matched = 1;
3188: }
3189: }
3190: if ($matched) {
1.167 albertel 3191: $srch_results{$user} =
3192: {&Apache::lonnet::get('environment',
3193: ['firstname',
3194: 'lastname',
1.194 albertel 3195: 'permanentemail'],
3196: $cudomain,$cuname)};
1.162 raeburn 3197: }
3198: }
3199: }
1.179 raeburn 3200: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3201: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 3202: }
3203: }
3204: }
3205: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 3206: $currstate = 'query';
1.160 raeburn 3207: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 3208: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
3209: if ($dirsrchres eq 'ok') {
3210: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3211: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 3212: } else {
3213: my $showdom = &display_domain_info($srch->{'srchdomain'});
3214: $response = '<span class="LC_warning">'.
3215: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
3216: '</span><br />'.
3217: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
3218: '<br /><br />';
3219: }
1.160 raeburn 3220: }
3221: } else {
3222: if ($srch->{'srchin'} eq 'dom') {
3223: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 3224: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3225: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 3226: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 3227: my $courseusers = &get_courseusers();
3228: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 3229: my ($uname,$udom) = split(/:/,$user);
3230: my %names = &Apache::loncommon::getnames($uname,$udom);
3231: my %emails = &Apache::loncommon::getemails($uname,$udom);
3232: if ($srch->{'srchby'} eq 'lastname') {
3233: if ((($srch->{'srchtype'} eq 'exact') &&
3234: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 3235: (($srch->{'srchtype'} eq 'begins') &&
3236: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 3237: (($srch->{'srchtype'} eq 'contains') &&
3238: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
3239: $srch_results{$user} = {firstname => $names{'firstname'},
3240: lastname => $names{'lastname'},
3241: permanentemail => $emails{'permanentemail'},
3242: };
3243: }
3244: } elsif ($srch->{'srchby'} eq 'lastfirst') {
3245: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 3246: $srchlast =~ s/\s+$//;
3247: $srchfirst =~ s/^\s+//;
1.160 raeburn 3248: if ($srch->{'srchtype'} eq 'exact') {
3249: if (($names{'lastname'} eq $srchlast) &&
3250: ($names{'firstname'} eq $srchfirst)) {
3251: $srch_results{$user} = {firstname => $names{'firstname'},
3252: lastname => $names{'lastname'},
3253: permanentemail => $emails{'permanentemail'},
3254:
3255: };
3256: }
1.177 raeburn 3257: } elsif ($srch->{'srchtype'} eq 'begins') {
3258: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
3259: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
3260: $srch_results{$user} = {firstname => $names{'firstname'},
3261: lastname => $names{'lastname'},
3262: permanentemail => $emails{'permanentemail'},
3263: };
3264: }
3265: } else {
1.160 raeburn 3266: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
3267: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
3268: $srch_results{$user} = {firstname => $names{'firstname'},
3269: lastname => $names{'lastname'},
3270: permanentemail => $emails{'permanentemail'},
3271: };
3272: }
3273: }
3274: }
3275: }
1.179 raeburn 3276: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3277: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 3278: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 3279: $currstate = 'query';
1.160 raeburn 3280: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 3281: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
3282: if ($dirsrchres eq 'ok') {
3283: ($currstate,$response,$forcenewuser) =
1.221 raeburn 3284: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 3285: } else {
3286: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
3287: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
3288: '</span><br />'.
3289: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
3290: '<br /><br />';
3291: }
1.160 raeburn 3292: }
3293: }
1.179 raeburn 3294: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 3295: }
3296:
3297: sub directorysrch_check {
3298: my ($srch) = @_;
3299: my $can_search = 0;
3300: my $response;
3301: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
3302: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 3303: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 3304: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
3305: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 3306: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 3307: }
3308: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
3309: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 3310: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 3311: }
3312: my @usertypes = split(/:/,$env{'environment.inststatus'});
3313: if (!@usertypes) {
3314: push(@usertypes,'default');
3315: }
3316: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
3317: foreach my $type (@usertypes) {
3318: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
3319: $can_search = 1;
3320: last;
3321: }
3322: }
3323: }
3324: if (!$can_search) {
3325: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
3326: my @longtypes;
3327: foreach my $item (@usertypes) {
1.229 raeburn 3328: if (defined($insttypes->{$item})) {
3329: push (@longtypes,$insttypes->{$item});
3330: } elsif ($item eq 'default') {
3331: push (@longtypes,&mt('other'));
3332: }
1.160 raeburn 3333: }
3334: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 3335: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 3336: }
1.160 raeburn 3337: } else {
3338: $can_search = 1;
3339: }
3340: } else {
1.180 raeburn 3341: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 3342: }
3343: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 3344: uname => 'username',
1.160 raeburn 3345: lastfirst => 'last name, first name',
1.167 albertel 3346: lastname => 'last name',
1.172 raeburn 3347: contains => 'contains',
1.178 raeburn 3348: exact => 'as exact match to',
3349: begins => 'begins with',
1.160 raeburn 3350: );
3351: if ($can_search) {
3352: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
3353: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 3354: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 3355: }
3356: } else {
1.180 raeburn 3357: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 3358: }
3359: }
3360: if ($can_search) {
1.178 raeburn 3361: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
3362: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
3363: return 'ok';
3364: } else {
1.180 raeburn 3365: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 3366: }
3367: } else {
3368: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
3369: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
3370: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
3371: return 'ok';
3372: } else {
1.180 raeburn 3373: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 3374: }
1.160 raeburn 3375: }
3376: }
3377: }
3378:
3379: sub get_courseusers {
3380: my %advhash;
1.167 albertel 3381: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 3382: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
3383: foreach my $role (sort(keys(%coursepersonnel))) {
3384: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 3385: if (!exists($classlist->{$user})) {
3386: $classlist->{$user} = [];
3387: }
1.160 raeburn 3388: }
3389: }
1.167 albertel 3390: return $classlist;
1.160 raeburn 3391: }
3392:
3393: sub build_search_response {
1.221 raeburn 3394: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 3395: my ($currstate,$response,$forcenewuser);
1.160 raeburn 3396: my %names = (
3397: 'uname' => 'username',
3398: 'lastname' => 'last name',
3399: 'lastfirst' => 'last name, first name',
3400: 'crs' => 'this course',
1.180 raeburn 3401: 'dom' => 'LON-CAPA domain: ',
3402: 'instd' => 'the institutional directory for domain: ',
1.160 raeburn 3403: );
3404:
3405: my %single = (
1.180 raeburn 3406: begins => 'A match',
1.160 raeburn 3407: contains => 'A match',
1.180 raeburn 3408: exact => 'An exact match',
1.160 raeburn 3409: );
3410: my %nomatch = (
1.180 raeburn 3411: begins => 'No match',
1.160 raeburn 3412: contains => 'No match',
1.180 raeburn 3413: exact => 'No exact match',
1.160 raeburn 3414: );
3415: if (keys(%srch_results) > 1) {
1.179 raeburn 3416: $currstate = 'select';
1.160 raeburn 3417: } else {
3418: if (keys(%srch_results) == 1) {
1.179 raeburn 3419: $currstate = 'modify';
1.180 raeburn 3420: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
3421: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
3422: $response .= &display_domain_info($srch->{'srchdomain'});
3423: }
1.160 raeburn 3424: } else {
1.180 raeburn 3425: $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
3426: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
3427: $response .= &display_domain_info($srch->{'srchdomain'});
3428: }
3429: $response .= '</span>';
1.160 raeburn 3430: if ($srch->{'srchin'} ne 'alc') {
3431: $forcenewuser = 1;
3432: my $cansrchinst = 0;
3433: if ($srch->{'srchdomain'}) {
3434: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
3435: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
3436: if ($domconfig{'directorysrch'}{'available'}) {
3437: $cansrchinst = 1;
3438: }
3439: }
3440: }
1.180 raeburn 3441: if ((($srch->{'srchby'} eq 'lastfirst') ||
3442: ($srch->{'srchby'} eq 'lastname')) &&
3443: ($srch->{'srchin'} eq 'dom')) {
3444: if ($cansrchinst) {
3445: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 3446: }
3447: }
1.180 raeburn 3448: if ($srch->{'srchin'} eq 'crs') {
3449: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
3450: }
3451: }
3452: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {
1.221 raeburn 3453: my $cancreate =
3454: &Apache::lonuserutils::can_create_user($env{'request.role.domain'},$context);
3455: if ($cancreate) {
3456: my $showdom = &display_domain_info($env{'request.role.domain'});
1.229 raeburn 3457: $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 3458: } else {
3459: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
3460: $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 />';
3461: }
1.160 raeburn 3462: }
3463: }
3464: }
1.179 raeburn 3465: return ($currstate,$response,$forcenewuser);
1.160 raeburn 3466: }
3467:
1.180 raeburn 3468: sub display_domain_info {
3469: my ($dom) = @_;
3470: my $output = $dom;
3471: if ($dom ne '') {
3472: my $domdesc = &Apache::lonnet::domain($dom,'description');
3473: if ($domdesc ne '') {
3474: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
3475: }
3476: }
3477: return $output;
3478: }
3479:
1.160 raeburn 3480: sub crumb_utilities {
3481: my %elements = (
3482: crtuser => {
3483: srchterm => 'text',
1.172 raeburn 3484: srchin => 'selectbox',
1.160 raeburn 3485: srchby => 'selectbox',
3486: srchtype => 'selectbox',
3487: srchdomain => 'selectbox',
3488: },
1.207 raeburn 3489: crtusername => {
3490: srchterm => 'text',
3491: srchdomain => 'selectbox',
3492: },
1.160 raeburn 3493: docustom => {
3494: rolename => 'selectbox',
3495: newrolename => 'textbox',
3496: },
1.179 raeburn 3497: studentform => {
3498: srchterm => 'text',
3499: srchin => 'selectbox',
3500: srchby => 'selectbox',
3501: srchtype => 'selectbox',
3502: srchdomain => 'selectbox',
3503: },
1.160 raeburn 3504: );
3505:
3506: my $jsback .= qq|
3507: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 3508: if (typeof prevphase == 'undefined') {
3509: formname.phase.value = '';
3510: }
3511: else {
3512: formname.phase.value = prevphase;
3513: }
3514: if (typeof prevstate == 'undefined') {
3515: formname.currstate.value = '';
3516: }
3517: else {
3518: formname.currstate.value = prevstate;
3519: }
1.160 raeburn 3520: formname.submit();
3521: }
3522: |;
3523: return ($jsback,\%elements);
3524: }
3525:
1.26 matthew 3526: sub course_level_table {
1.89 raeburn 3527: my (%inccourses) = @_;
1.26 matthew 3528: my $table = '';
1.62 www 3529: # Custom Roles?
3530:
1.190 raeburn 3531: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 3532: my %lt=&Apache::lonlocal::texthash(
3533: 'exs' => "Existing sections",
3534: 'new' => "Define new section",
3535: 'ssd' => "Set Start Date",
3536: 'sed' => "Set End Date",
1.131 raeburn 3537: 'crl' => "Course Level",
1.89 raeburn 3538: 'act' => "Activate",
3539: 'rol' => "Role",
3540: 'ext' => "Extent",
1.113 raeburn 3541: 'grs' => "Section",
1.89 raeburn 3542: 'sta' => "Start",
3543: 'end' => "End"
3544: );
1.62 www 3545:
1.135 raeburn 3546: foreach my $protectedcourse (sort( keys(%inccourses))) {
3547: my $thiscourse=$protectedcourse;
1.26 matthew 3548: $thiscourse=~s:_:/:g;
3549: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
3550: my $area=$coursedata{'description'};
1.119 raeburn 3551: my $type=$coursedata{'type'};
1.135 raeburn 3552: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 3553: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 3554: my %sections_count;
1.101 albertel 3555: if (defined($env{'request.course.id'})) {
3556: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 3557: %sections_count =
3558: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 3559: }
3560: }
1.213 raeburn 3561: my @roles = &Apache::lonuserutils::roles_by_context('course');
3562: foreach my $role (@roles) {
1.221 raeburn 3563: my $plrole=&Apache::lonnet::plaintext($role);
1.135 raeburn 3564: if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
1.221 raeburn 3565: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
3566: $plrole,\%sections_count,\%lt);
3567: } elsif ($env{'request.course.sec'} ne '') {
3568: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
3569: $env{'request.course.sec'})) {
3570: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
3571: $plrole,\%sections_count,\%lt);
1.26 matthew 3572: }
3573: }
3574: }
1.221 raeburn 3575: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
3576: foreach my $cust (sort keys %customroles) {
3577: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
3578: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
3579: $cust,\%sections_count,\%lt);
3580: }
1.62 www 3581: }
1.26 matthew 3582: }
3583: return '' if ($table eq ''); # return nothing if there is nothing
3584: # in the table
1.188 raeburn 3585: my $result;
3586: if (!$env{'request.course.id'}) {
3587: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
3588: }
3589: $result .=
1.136 raeburn 3590: &Apache::loncommon::start_data_table().
3591: &Apache::loncommon::start_data_table_header_row().
3592: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
3593: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
3594: &Apache::loncommon::end_data_table_header_row().
3595: $table.
3596: &Apache::loncommon::end_data_table();
1.26 matthew 3597: return $result;
3598: }
1.88 raeburn 3599:
1.221 raeburn 3600: sub course_level_row {
3601: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_;
1.222 raeburn 3602: my $row = &Apache::loncommon::start_data_table_row().
3603: ' <td><input type="checkbox" name="act_'.
3604: $protectedcourse.'_'.$role.'" /></td>'."\n".
3605: ' <td>'.$plrole.'</td>'."\n".
3606: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.221 raeburn 3607: if ($role eq 'cc') {
1.222 raeburn 3608: $row .= '<td> </td>';
1.221 raeburn 3609: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 3610: $row .= ' <td><input type="hidden" value="'.
3611: $env{'request.course.sec'}.'" '.
3612: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
3613: $env{'request.course.sec'}.'</td>';
1.221 raeburn 3614: } else {
3615: if (ref($sections_count) eq 'HASH') {
3616: my $currsec =
3617: &Apache::lonuserutils::course_sections($sections_count,
3618: $protectedcourse.'_'.$role);
1.222 raeburn 3619: $row .= '<td><table class="LC_createuser">'."\n".
3620: '<tr class="LC_section_row">'."\n".
3621: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
3622: $currsec.'</td>'."\n".
3623: ' <td> </td>'."\n".
3624: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 3625: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
3626: '" value="" />'.
3627: '<input type="hidden" '.
3628: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 3629: '</tr></table></td>'."\n";
1.221 raeburn 3630: } else {
1.222 raeburn 3631: $row .= '<td><input type="text" size="10" '.
3632: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 3633: }
3634: }
1.222 raeburn 3635: $row .= <<ENDTIMEENTRY;
3636: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 3637: <a href=
3638: "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 3639: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 3640: <a href=
3641: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
3642: ENDTIMEENTRY
1.222 raeburn 3643: $row .= &Apache::loncommon::end_data_table_row();
3644: return $row;
1.221 raeburn 3645: }
3646:
1.88 raeburn 3647: sub course_level_dc {
3648: my ($dcdom) = @_;
1.190 raeburn 3649: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 3650: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 3651: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
3652: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 3653: '<input type="hidden" name="dccourse" value="" />';
1.88 raeburn 3654: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.131 raeburn 3655: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
3656: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
1.88 raeburn 3657: my %lt=&Apache::lonlocal::texthash(
3658: 'rol' => "Role",
1.113 raeburn 3659: 'grs' => "Section",
1.88 raeburn 3660: 'exs' => "Existing sections",
3661: 'new' => "Define new section",
3662: 'sta' => "Start",
3663: 'end' => "End",
3664: 'ssd' => "Set Start Date",
3665: 'sed' => "Set End Date"
3666: );
1.131 raeburn 3667: my $header = '<h4>'.&mt('Course Level').'</h4>'.
1.136 raeburn 3668: &Apache::loncommon::start_data_table().
3669: &Apache::loncommon::start_data_table_header_row().
1.143 raeburn 3670: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 3671: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 3672: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.131 raeburn 3673: '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1.88 raeburn 3674: '<td><select name="role">'."\n";
1.213 raeburn 3675: foreach my $role (@roles) {
1.135 raeburn 3676: my $plrole=&Apache::lonnet::plaintext($role);
3677: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 3678: }
3679: if ( keys %customroles > 0) {
1.135 raeburn 3680: foreach my $cust (sort keys %customroles) {
1.101 albertel 3681: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 3682: '_'.$env{'user.name'}.'_'.$cust;
3683: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 3684: }
3685: }
3686: $otheritems .= '</select></td><td>'.
3687: '<table border="0" cellspacing="0" cellpadding="0">'.
3688: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
3689: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
3690: '<td> </td>'.
3691: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 3692: '<input type="text" name="newsec" value="" />'.
1.221 raeburn 3693: '<input type="hidden" name="sections" value="" />'.
1.113 raeburn 3694: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 3695: '</tr></table></td>';
3696: $otheritems .= <<ENDTIMEENTRY;
1.169 albertel 3697: <td><input type="hidden" name="start" value='' />
1.88 raeburn 3698: <a href=
3699: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 3700: <td><input type="hidden" name="end" value='' />
1.88 raeburn 3701: <a href=
3702: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
3703: ENDTIMEENTRY
1.136 raeburn 3704: $otheritems .= &Apache::loncommon::end_data_table_row().
3705: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 3706: return $cb_jscript.$header.$hiddenitems.$otheritems;
3707: }
3708:
1.27 matthew 3709: #---------------------------------------------- end functions for &phase_two
1.29 matthew 3710:
3711: #--------------------------------- functions for &phase_two and &phase_three
3712:
3713: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 3714:
3715: 1;
3716: __END__
1.2 www 3717:
3718:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>