Annotation of loncom/interface/loncreateuser.pm, revision 1.258
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.258 ! raeburn 4: # $Id: loncreateuser.pm,v 1.257 2008/07/17 20:05:14 raeburn Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
36: Apache::loncreateuser - handler to create users and custom roles
37:
38: =head1 SYNOPSIS
39:
40: Apache::loncreateuser provides an Apache handler for creating users,
41: editing their login parameters, roles, and removing roles, and
42: also creating and assigning custom roles.
43:
44: =head1 OVERVIEW
45:
46: =head2 Custom Roles
47:
48: In LON-CAPA, roles are actually collections of privileges. "Teaching
49: Assistant", "Course Coordinator", and other such roles are really just
50: collection of privileges that are useful in many circumstances.
51:
52: Creating custom roles can be done by the Domain Coordinator through
53: the Create User functionality. That screen will show all privileges
54: that can be assigned to users. For a complete list of privileges,
55: please see C</home/httpd/lonTabs/rolesplain.tab>.
56:
57: Custom role definitions are stored in the C<roles.db> file of the role
58: author.
59:
60: =cut
1.1 www 61:
62: use strict;
63: use Apache::Constants qw(:common :http);
64: use Apache::lonnet;
1.54 bowersj2 65: use Apache::loncommon;
1.68 www 66: use Apache::lonlocal;
1.117 raeburn 67: use Apache::longroup;
1.190 raeburn 68: use Apache::lonuserutils;
1.139 albertel 69: use LONCAPA qw(:DEFAULT :match);
1.1 www 70:
1.20 harris41 71: my $loginscript; # piece of javascript used in two separate instances
72: my $authformnop;
73: my $authformkrb;
74: my $authformint;
75: my $authformfsys;
76: my $authformloc;
77:
1.94 matthew 78: sub initialize_authen_forms {
1.227 raeburn 79: my ($dom,$formname,$curr_authtype,$mode) = @_;
80: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
81: my %param = ( formname => $formname,
1.187 raeburn 82: kerb_def_dom => $krbdefdom,
1.227 raeburn 83: kerb_def_auth => $krbdef,
1.187 raeburn 84: domain => $dom,
85: );
1.188 raeburn 86: my %abv_auth = &auth_abbrev();
1.227 raeburn 87: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 88: my $long_auth = $1;
1.227 raeburn 89: my $curr_autharg = $2;
1.188 raeburn 90: my %abv_auth = &auth_abbrev();
91: $param{'curr_authtype'} = $abv_auth{$long_auth};
92: if ($long_auth =~ /^krb(4|5)$/) {
93: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 94: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 95: }
1.205 raeburn 96: if ($mode eq 'modifyuser') {
97: $param{'mode'} = $mode;
98: }
1.187 raeburn 99: }
1.227 raeburn 100: $loginscript = &Apache::loncommon::authform_header(%param);
101: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 102: $authformnop = &Apache::loncommon::authform_nochange(%param);
103: $authformint = &Apache::loncommon::authform_internal(%param);
104: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
105: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 106: }
107:
1.188 raeburn 108: sub auth_abbrev {
109: my %abv_auth = (
110: krb4 => 'krb',
111: internal => 'int',
112: localuth => 'loc',
113: unix => 'fsys',
114: );
115: return %abv_auth;
116: }
1.43 www 117:
1.134 raeburn 118: # ====================================================
119:
120: sub portfolio_quota {
121: my ($ccuname,$ccdomain) = @_;
122: my %lt = &Apache::lonlocal::texthash(
123: 'disk' => "Disk space allocated to user's portfolio files",
1.149 raeburn 124: 'cuqu' => "Current quota",
125: 'cust' => "Custom quota",
126: 'defa' => "Default",
127: 'chqu' => "Change quota",
1.134 raeburn 128: );
1.149 raeburn 129: my ($currquota,$quotatype,$inststatus,$defquota) =
130: &Apache::loncommon::get_user_quota($ccuname,$ccdomain);
131: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
132: my ($longinsttype,$showquota,$custom_on,$custom_off,$defaultinfo);
133: if ($inststatus ne '') {
134: if ($usertypes->{$inststatus} ne '') {
135: $longinsttype = $usertypes->{$inststatus};
136: }
137: }
138: $custom_on = ' ';
139: $custom_off = ' checked="checked" ';
140: my $quota_javascript = <<"END_SCRIPT";
141: <script type="text/javascript">
142: function quota_changes(caller) {
143: if (caller == "custom") {
144: if (document.cu.customquota[0].checked) {
145: document.cu.portfolioquota.value = "";
146: }
147: }
148: if (caller == "quota") {
149: document.cu.customquota[1].checked = true;
150: }
151: }
152: </script>
153: END_SCRIPT
154: if ($quotatype eq 'custom') {
155: $custom_on = $custom_off;
156: $custom_off = ' ';
157: $showquota = $currquota;
158: if ($longinsttype eq '') {
1.230 bisitz 159: $defaultinfo = &mt('For this user, the default quota would be [_1]'
160: .' Mb.',$defquota);
1.149 raeburn 161: } else {
1.231 raeburn 162: $defaultinfo = &mt("For this user, the default quota would be [_1]".
163: " Mb, as determined by the user's institutional".
164: " affiliation ([_2]).",$defquota,$longinsttype);
1.149 raeburn 165: }
166: } else {
167: if ($longinsttype eq '') {
1.230 bisitz 168: $defaultinfo = &mt('For this user, the default quota is [_1]'
169: .' Mb.',$defquota);
1.149 raeburn 170: } else {
1.231 raeburn 171: $defaultinfo = &mt("For this user, the default quota of [_1]".
172: " Mb, is determined by the user's institutional".
173: " affiliation ([_2]).",$defquota,$longinsttype);
1.149 raeburn 174: }
175: }
176: my $output = $quota_javascript.
177: '<h3>'.$lt{'disk'}.'</h3>'.
1.188 raeburn 178: &Apache::loncommon::start_data_table().
179: &Apache::loncommon::start_data_table_row().
180: '<td>'.$lt{'cuqu'}.': '.$currquota.' Mb. '.
181: $defaultinfo.'</td>'.
182: &Apache::loncommon::end_data_table_row().
183: &Apache::loncommon::start_data_table_row().
184: '<td><span class="LC_nobreak">'.$lt{'chqu'}.
1.149 raeburn 185: ': <label>'.
186: '<input type="radio" name="customquota" value="0" '.
187: $custom_off.' onchange="javascript:quota_changes('."'custom'".')"
188: />'.$lt{'defa'}.' ('.$defquota.' Mb).</label> '.
189: ' <label><input type="radio" name="customquota" value="1" '.
190: $custom_on.' onchange="javascript:quota_changes('."'custom'".')" />'.
191: $lt{'cust'}.':</label> '.
1.134 raeburn 192: '<input type="text" name="portfolioquota" size ="5" value="'.
1.149 raeburn 193: $showquota.'" onfocus="javascript:quota_changes('."'quota'".')" '.
1.188 raeburn 194: '/> Mb</span></td>'.
195: &Apache::loncommon::end_data_table_row().
196: &Apache::loncommon::end_data_table();
1.134 raeburn 197: return $output;
198: }
199:
1.2 www 200: # =================================================================== Phase one
1.1 www 201:
1.42 matthew 202: sub print_username_entry_form {
1.207 raeburn 203: my ($r,$context,$response,$srch,$forcenewuser) = @_;
1.101 albertel 204: my $defdom=$env{'request.role.domain'};
1.160 raeburn 205: my $formtoset = 'crtuser';
206: if (exists($env{'form.startrolename'})) {
207: $formtoset = 'docustom';
208: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 209: } elsif ($env{'form.origform'} eq 'crtusername') {
210: $formtoset = $env{'form.origform'};
1.160 raeburn 211: }
212:
213: my ($jsback,$elements) = &crumb_utilities();
214:
215: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 216: '<script type="text/javascript">'."\n".
1.160 raeburn 217: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset}).
1.162 raeburn 218: '</script>'."\n";
1.160 raeburn 219:
220: my %loaditems = (
221: 'onload' => "javascript:setFormElements(document.$formtoset)",
222: );
1.229 raeburn 223: my %breadcrumb_text = &singleuser_breadcrumb();
1.110 albertel 224: my $start_page =
1.190 raeburn 225: &Apache::loncommon::start_page('User Management',
1.160 raeburn 226: $jscript,{'add_entries' => \%loaditems,});
1.214 raeburn 227: if ($env{'form.action'} eq 'custom') {
228: &Apache::lonhtmlcommon::add_breadcrumb
229: ({href=>"javascript:backPage(document.crtuser)",
230: text=>"Pick custom role",});
231: } else {
1.190 raeburn 232: &Apache::lonhtmlcommon::add_breadcrumb
233: ({href=>"javascript:backPage(document.crtuser)",
1.229 raeburn 234: text=>$breadcrumb_text{'search'},
1.190 raeburn 235: faq=>282,bug=>'Instructor Interface',});
236: }
1.224 raeburn 237: my $helpitem = 'Course_Change_Privileges';
238: if ($env{'form.action'} eq 'custom') {
239: $helpitem = 'Course_Editing_Custom_Roles';
240: } elsif ($env{'form.action'} eq 'singlestudent') {
241: $helpitem = 'Course_Add_Student';
242: }
243: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
244: $helpitem);
1.190 raeburn 245: my %existingroles=&Apache::lonuserutils::my_custom_roles();
1.59 www 246: my $choice=&Apache::loncommon::select_form('make new role','rolename',
247: ('make new role' => 'Generate new role ...',%existingroles));
1.71 sakharuk 248: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 249: 'srst' => 'Search for a user and enroll as a student',
250: 'srad' => 'Search for a user and modify/add user information or roles',
1.71 sakharuk 251: 'usr' => "Username",
252: 'dom' => "Domain",
253: 'ecrp' => "Edit Custom Role Privileges",
1.72 sakharuk 254: 'nr' => "Name of Role",
1.160 raeburn 255: 'cre' => "Custom Role Editor",
1.71 sakharuk 256: );
1.190 raeburn 257: $r->print($start_page."\n".$crumbs);
1.214 raeburn 258: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 259: if (&Apache::lonnet::allowed('mcr','/')) {
260: $r->print(<<ENDCUSTOM);
1.58 www 261: <form action="/adm/createuser" method="post" name="docustom">
1.190 raeburn 262: <input type="hidden" name="action" value="$env{'form.action'}" />
1.157 albertel 263: <input type="hidden" name="phase" value="selected_custom_edit" />
1.224 raeburn 264: <h3>$lt{'ecrp'}</h3>
1.72 sakharuk 265: $lt{'nr'}: $choice <input type="text" size="15" name="newrolename" /><br />
1.71 sakharuk 266: <input name="customeditor" type="submit" value="$lt{'cre'}" />
1.107 www 267: </form>
1.106 www 268: ENDCUSTOM
1.190 raeburn 269: }
1.213 raeburn 270: } else {
1.229 raeburn 271: my $actiontext = $lt{'srad'};
1.213 raeburn 272: if ($env{'form.action'} eq 'singlestudent') {
1.229 raeburn 273: $actiontext = $lt{'srst'};
1.213 raeburn 274: }
275: $r->print("
1.229 raeburn 276: <h3>$actiontext</h3>");
1.213 raeburn 277: if ($env{'form.origform'} ne 'crtusername') {
278: $r->print("\n".$response);
279: }
280: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response));
1.107 www 281: }
1.110 albertel 282: $r->print(&Apache::loncommon::end_page());
283: }
284:
1.160 raeburn 285: sub entry_form {
1.214 raeburn 286: my ($dom,$srch,$forcenewuser,$context,$responsemsg) = @_;
1.207 raeburn 287: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
1.229 raeburn 288: my ($usertype,$inexact);
1.214 raeburn 289: if (ref($srch) eq 'HASH') {
290: if (($srch->{'srchin'} eq 'dom') &&
291: ($srch->{'srchby'} eq 'uname') &&
292: ($srch->{'srchtype'} eq 'exact') &&
293: ($srch->{'srchdomain'} ne '') &&
294: ($srch->{'srchterm'} ne '')) {
295: my ($rules,$ruleorder) =
296: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
297: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules);
1.229 raeburn 298: } else {
299: $inexact = 1;
1.214 raeburn 300: }
1.207 raeburn 301: }
1.214 raeburn 302: my $cancreate =
303: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.160 raeburn 304: my $userpicker =
1.179 raeburn 305: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.214 raeburn 306: 'document.crtuser',$cancreate,$usertype);
1.160 raeburn 307: my $srchbutton = &mt('Search');
1.229 raeburn 308: if ($env{'form.action'} eq 'singlestudent') {
309: $srchbutton = &mt('Search and Enroll');
310: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
311: $srchbutton = &mt('Search or Add New User');
312: }
1.207 raeburn 313: my $output = <<"ENDBLOCK";
1.160 raeburn 314: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 315: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 316: <input type="hidden" name="phase" value="get_user_info" />
317: $userpicker
1.179 raeburn 318: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 319: </form>
1.207 raeburn 320: ENDBLOCK
1.229 raeburn 321: if ($env{'form.phase'} eq '') {
1.207 raeburn 322: my $defdom=$env{'request.role.domain'};
323: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
324: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 325: 'enro' => 'Enroll one student',
326: 'admo' => 'Add/modify a single user',
327: 'crea' => 'create new user if required',
328: 'uskn' => "username is known",
1.207 raeburn 329: 'crnu' => 'Create a new user',
330: 'usr' => 'Username',
331: 'dom' => 'in domain',
1.229 raeburn 332: 'enrl' => 'Enroll',
333: 'cram' => 'Create/Modify user',
1.207 raeburn 334: );
1.229 raeburn 335: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
336: my ($title,$buttontext,$showresponse);
337: if ($env{'form.action'} eq 'singlestudent') {
338: $title = $lt{'enro'};
339: $buttontext = $lt{'enrl'};
340: } else {
341: $title = $lt{'admo'};
342: $buttontext = $lt{'cram'};
343: }
344: if ($cancreate) {
345: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
346: } else {
347: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
348: }
349: if ($env{'form.origform'} eq 'crtusername') {
350: $showresponse = $responsemsg;
351: }
1.207 raeburn 352: $output .= <<"ENDDOCUMENT";
1.229 raeburn 353: <br />
1.207 raeburn 354: <form action="/adm/createuser" method="post" name="crtusername">
355: <input type="hidden" name="action" value="$env{'form.action'}" />
356: <input type="hidden" name="phase" value="createnewuser" />
357: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 358: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 359: <input type="hidden" name="srchin" value="dom" />
360: <input type="hidden" name="forcenewuser" value="1" />
361: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 362: <h3>$title</h3>
363: $showresponse
1.207 raeburn 364: <table>
365: <tr>
366: <td>$lt{'usr'}:</td>
367: <td><input type="text" size="15" name="srchterm" /></td>
368: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 369: <td> $sellink </td>
370: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 371: </tr>
372: </table>
373: </form>
1.160 raeburn 374: ENDDOCUMENT
1.207 raeburn 375: }
1.160 raeburn 376: return $output;
377: }
1.110 albertel 378:
379: sub user_modification_js {
1.113 raeburn 380: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
381:
1.110 albertel 382: return <<END;
383: <script type="text/javascript" language="Javascript">
384:
385: function pclose() {
386: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
387: "height=350,width=350,scrollbars=no,menubar=no");
388: parmwin.close();
389: }
390:
391: $pjump_def
392: $dc_setcourse_code
393:
394: function dateset() {
395: eval("document.cu."+document.cu.pres_marker.value+
396: ".value=document.cu.pres_value.value");
397: pclose();
398: }
399:
1.113 raeburn 400: $nondc_setsection_code
401:
1.110 albertel 402: </script>
403: END
1.2 www 404: }
405:
406: # =================================================================== Phase two
1.160 raeburn 407: sub print_user_selection_page {
1.229 raeburn 408: my ($r,$response,$srch,$srch_results,$srcharray,$context) = @_;
1.160 raeburn 409: my @fields = ('username','domain','lastname','firstname','permanentemail');
410: my $sortby = $env{'form.sortby'};
411:
412: if (!grep(/^\Q$sortby\E$/,@fields)) {
413: $sortby = 'lastname';
414: }
415:
416: my ($jsback,$elements) = &crumb_utilities();
417:
418: my $jscript = (<<ENDSCRIPT);
419: <script type="text/javascript">
420: function pickuser(uname,udom) {
421: document.usersrchform.seluname.value=uname;
422: document.usersrchform.seludom.value=udom;
423: document.usersrchform.phase.value="userpicked";
424: document.usersrchform.submit();
425: }
426:
427: $jsback
428: </script>
429: ENDSCRIPT
430:
431: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 432: 'usrch' => "User Search to add/modify roles",
433: 'stusrch' => "User Search to enroll student",
434: 'usel' => "Select a user to add/modify roles",
435: 'stusel' => "Select a user to enroll as a student",
1.160 raeburn 436: 'username' => "username",
437: 'domain' => "domain",
438: 'lastname' => "last name",
439: 'firstname' => "first name",
440: 'permanentemail' => "permanent e-mail",
441: );
1.214 raeburn 442: $r->print(&Apache::loncommon::start_page('User Management',$jscript));
1.229 raeburn 443:
444: my %breadcrumb_text = &singleuser_breadcrumb();
445: &Apache::lonhtmlcommon::add_breadcrumb
446: ({href=>"javascript:backPage(document.usersrchform,'','')",
447: text=>$breadcrumb_text{'search'},
448: faq=>282,bug=>'Instructor Interface',},
449: {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
450: text=>$breadcrumb_text{'userpicked'},
451: faq=>282,bug=>'Instructor Interface',});
452: if ($env{'form.action'} eq 'singleuser') {
1.224 raeburn 453: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
454: 'Course_Change_Privileges'));
1.179 raeburn 455: $r->print("<b>$lt{'usrch'}</b><br />");
1.207 raeburn 456: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
1.179 raeburn 457: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1.229 raeburn 458: } elsif ($env{'form.action'} eq 'singlestudent') {
1.224 raeburn 459: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
460: 'Course_Add_Student'));
1.179 raeburn 461: $r->print($jscript."<b>$lt{'stusrch'}</b><br />");
1.214 raeburn 462: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
1.179 raeburn 463: $r->print('</form><h3>'.$lt{'stusel'}.'</h3>');
464: }
1.160 raeburn 465: $r->print('<form name="usersrchform" method="post">'.
466: &Apache::loncommon::start_data_table()."\n".
467: &Apache::loncommon::start_data_table_header_row()."\n".
468: ' <th> </th>'."\n");
469: foreach my $field (@fields) {
470: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
471: "'".$field."'".';document.usersrchform.submit();">'.
472: $lt{$field}.'</a></th>'."\n");
473: }
474: $r->print(&Apache::loncommon::end_data_table_header_row());
475:
476: my @sorted_users = sort {
1.167 albertel 477: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 478: ||
1.167 albertel 479: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 480: ||
481: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 482: ||
483: lc($a) cmp lc($b)
1.160 raeburn 484: } (keys(%$srch_results));
485:
486: foreach my $user (@sorted_users) {
487: my ($uname,$udom) = split(/:/,$user);
488: $r->print(&Apache::loncommon::start_data_table_row().
489: '<td><input type="button" name="seluser" value="'.&mt('Select').'" onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".')" /></td>'.
490: '<td><tt>'.$uname.'</tt></td>'.
491: '<td><tt>'.$udom.'</tt></td>');
492: foreach my $field ('lastname','firstname','permanentemail') {
493: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
494: }
495: $r->print(&Apache::loncommon::end_data_table_row());
496: }
497: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 498: if (ref($srcharray) eq 'ARRAY') {
499: foreach my $item (@{$srcharray}) {
500: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
501: }
502: }
1.160 raeburn 503: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
504: ' <input type="hidden" name="seluname" value="" />'."\n".
505: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 506: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 507: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 508: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
509: $r->print($response.'</form>'.&Apache::loncommon::end_page());
1.160 raeburn 510: }
511:
512: sub print_user_query_page {
1.179 raeburn 513: my ($r,$caller) = @_;
1.160 raeburn 514: # FIXME - this is for a network-wide name search (similar to catalog search)
515: # To use frames with similar behavior to catalog/portfolio search.
516: # To be implemented.
517: return;
518: }
519:
1.42 matthew 520: sub print_user_modification_page {
1.215 raeburn 521: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission) = @_;
1.185 raeburn 522: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 523: my $usermsg = &mt('No username and/or domain provided.');
524: $env{'form.phase'} = '';
1.207 raeburn 525: &print_username_entry_form($r,$context,$usermsg);
1.58 www 526: return;
527: }
1.213 raeburn 528: my ($form,$formname);
529: if ($env{'form.action'} eq 'singlestudent') {
530: $form = 'document.enrollstudent';
531: $formname = 'enrollstudent';
532: } else {
533: $form = 'document.cu';
534: $formname = 'cu';
535: }
1.188 raeburn 536: my %abv_auth = &auth_abbrev();
1.227 raeburn 537: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 538: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
539: if ($uhome eq 'no_host') {
1.215 raeburn 540: my $usertype;
541: my ($rules,$ruleorder) =
542: &Apache::lonnet::inst_userrules($ccdomain,'username');
543: $usertype =
544: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules);
545: my $cancreate =
546: &Apache::lonuserutils::can_create_user($ccdomain,$context,
547: $usertype);
548: if (!$cancreate) {
549: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
550: my %usertypetext = (
551: official => 'institutional',
552: unofficial => 'non-institutional',
553: );
554: my $response;
555: if ($env{'form.origform'} eq 'crtusername') {
556: $response = '<span class="LC_warning">'.&mt('No match was found for the username ([_1]) in LON-CAPA domain: [_2]',$ccuname,$ccdomain).
557: '</span><br />';
558: }
559: $response .= '<span class="LC_warning">'.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the <a[_1]>helpdesk</a> for assistance.',$helplink).'</span><br /><br />';
560: $env{'form.phase'} = '';
561: &print_username_entry_form($r,$context,$response);
562: return;
563: }
1.188 raeburn 564: $newuser = 1;
1.193 raeburn 565: my $checkhash;
566: my $checks = { 'username' => 1 };
1.196 raeburn 567: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 568: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 569: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
570: if (ref($alerts{'username'}) eq 'HASH') {
571: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
572: my $domdesc =
1.193 raeburn 573: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 574: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
575: my $userchkmsg;
576: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
577: $userchkmsg =
578: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 579: $domdesc,1).
580: &Apache::loncommon::user_rule_formats($ccdomain,
581: $domdesc,$curr_rules{$ccdomain}{'username'},
582: 'username');
1.196 raeburn 583: }
1.215 raeburn 584: $env{'form.phase'} = '';
1.207 raeburn 585: &print_username_entry_form($r,$context,$userchkmsg);
1.196 raeburn 586: return;
1.215 raeburn 587: }
1.193 raeburn 588: }
1.185 raeburn 589: }
1.187 raeburn 590: } else {
1.188 raeburn 591: $newuser = 0;
1.185 raeburn 592: }
1.160 raeburn 593: if ($response) {
1.215 raeburn 594: $response = '<br />'.$response;
1.160 raeburn 595: }
1.149 raeburn 596:
1.52 matthew 597: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 598: my $dc_setcourse_code = '';
1.119 raeburn 599: my $nondc_setsection_code = '';
1.112 albertel 600: my %loaditem;
1.114 albertel 601:
1.216 raeburn 602: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 603:
1.216 raeburn 604: my $js = &validation_javascript($context,$ccdomain,$pjump_def,
605: $groupslist,$newuser,$formname,\%loaditem);
1.233 raeburn 606: my $args = {'add_entries' => \%loaditem};
607: if ($env{'form.popup'}) {
608: $args->{'no_nav_bar'} = 1;
609: }
1.110 albertel 610: my $start_page =
1.233 raeburn 611: &Apache::loncommon::start_page('User Management',$js,$args);
1.216 raeburn 612: my %breadcrumb_text = &singleuser_breadcrumb();
1.160 raeburn 613: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 614: ({href=>"javascript:backPage($form)",
615: text=>$breadcrumb_text{'search'},
1.160 raeburn 616: faq=>282,bug=>'Instructor Interface',});
617:
618: if ($env{'form.phase'} eq 'userpicked') {
619: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 620: ({href=>"javascript:backPage($form,'get_user_info','select')",
621: text=>$breadcrumb_text{'userpicked'},
1.160 raeburn 622: faq=>282,bug=>'Instructor Interface',});
623: }
624: &Apache::lonhtmlcommon::add_breadcrumb
1.216 raeburn 625: ({href=>"javascript:backPage($form,'$env{'form.phase'}','modify')",
626: text=>$breadcrumb_text{'modify'},
1.160 raeburn 627: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 628: my $helpitem = 'Course_Change_Privileges';
629: if ($env{'form.action'} eq 'singlestudent') {
630: $helpitem = 'Course_Add_Student';
631: }
632: my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
633: $helpitem);
1.3 www 634:
1.25 matthew 635: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 636: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 637: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 638: <input type="hidden" name="ccuname" value="$ccuname" />
639: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 640: <input type="hidden" name="pres_value" value="" />
641: <input type="hidden" name="pres_type" value="" />
642: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 643: ENDFORMINFO
1.2 www 644: my %inccourses;
1.135 raeburn 645: foreach my $key (keys(%env)) {
1.139 albertel 646: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1.2 www 647: $inccourses{$1.'_'.$2}=1;
648: }
1.24 matthew 649: }
1.216 raeburn 650: if ($newuser) {
1.134 raeburn 651: my $portfolioform;
652: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
653: # Current user has quota modification privileges
1.188 raeburn 654: $portfolioform = '<br />'.&portfolio_quota($ccuname,$ccdomain);
1.134 raeburn 655: }
1.227 raeburn 656: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 657: my %lt=&Apache::lonlocal::texthash(
658: 'cnu' => 'Create New User',
1.213 raeburn 659: 'ast' => 'as a student',
1.188 raeburn 660: 'ind' => 'in domain',
661: 'lg' => 'Login Data',
1.190 raeburn 662: 'hs' => "Home Server",
1.188 raeburn 663: );
1.185 raeburn 664: $r->print(<<ENDTITLE);
1.110 albertel 665: $start_page
1.160 raeburn 666: $crumbs
667: $response
1.25 matthew 668: $forminfo
1.31 matthew 669: <script type="text/javascript" language="Javascript">
1.20 harris41 670: $loginscript
1.31 matthew 671: </script>
1.20 harris41 672: <input type='hidden' name='makeuser' value='1' />
1.216 raeburn 673: <h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain
1.185 raeburn 674: ENDTITLE
1.213 raeburn 675: if ($env{'form.action'} eq 'singlestudent') {
676: $r->print(' ('.$lt{'ast'}.')');
677: }
678: $r->print('</h2>'."\n".'<div class="LC_left_float">');
1.206 raeburn 679: my $personal_table =
1.210 raeburn 680: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
681: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 682: $r->print($personal_table);
1.187 raeburn 683: my ($home_server_pick,$numlib) =
684: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
685: 'default','hide');
686: if ($numlib > 1) {
687: $r->print("
1.185 raeburn 688: <br />
1.187 raeburn 689: $lt{'hs'}: $home_server_pick
690: <br />");
691: } else {
692: $r->print($home_server_pick);
693: }
1.188 raeburn 694: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
695: $lt{'lg'}.'</h3>');
1.185 raeburn 696: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 697: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
698: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
699: my ($rules,$ruleorder) =
700: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 701: if (ref($rules) eq 'HASH') {
1.193 raeburn 702: if (ref($rules->{$matchedrule}) eq 'HASH') {
703: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 704: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 705: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 706: } else {
1.193 raeburn 707: my $authparm = $rules->{$matchedrule}{'authparm'};
1.185 raeburn 708: if ($authtype =~ /^krb(4|5)$/) {
709: my $ver = $1;
710: if ($authparm ne '') {
711: $fixedauth = <<"KERB";
712: <input type="hidden" name="login" value="krb" />
713: <input type="hidden" name="krbver" value="$ver" />
714: <input type="hidden" name="krbarg" value="$authparm" />
715: KERB
1.193 raeburn 716: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 717: }
718: } else {
719: $fixedauth =
720: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 721: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 722: $fixedauth .=
723: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
724: } else {
725: $varauth =
726: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
727: }
728: }
729: }
730: } else {
1.190 raeburn 731: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 732: }
733: }
734: if ($authmsg) {
735: $r->print(<<ENDAUTH);
736: $fixedauth
737: $authmsg
738: $varauth
739: ENDAUTH
740: }
741: } else {
1.190 raeburn 742: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 743: }
1.215 raeburn 744: $r->print($portfolioform);
745: if ($env{'form.action'} eq 'singlestudent') {
746: $r->print(&date_sections_select($context,$newuser,$formname,
747: $permission));
748: }
749: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 750: } else { # user already exists
1.79 albertel 751: my %lt=&Apache::lonlocal::texthash(
1.191 raeburn 752: 'cup' => "Modify existing user: ",
1.213 raeburn 753: 'ens' => "Enroll one student: ",
1.72 sakharuk 754: 'id' => "in domain",
755: );
1.26 matthew 756: $r->print(<<ENDCHANGEUSER);
1.110 albertel 757: $start_page
1.160 raeburn 758: $crumbs
1.25 matthew 759: $forminfo
1.213 raeburn 760: <h2>
1.26 matthew 761: ENDCHANGEUSER
1.213 raeburn 762: if ($env{'form.action'} eq 'singlestudent') {
763: $r->print($lt{'ens'});
764: } else {
765: $r->print($lt{'cup'});
766: }
767: $r->print(' "'.$ccuname.'" '.$lt{'id'}.' "'.$ccdomain.'"</h2>'.
768: "\n".'<div class="LC_left_float">');
1.206 raeburn 769: my ($personal_table,$showforceid) =
1.210 raeburn 770: &personal_data_display($ccuname,$ccdomain,$newuser,$context,
771: $inst_results{$ccuname.':'.$ccdomain});
1.206 raeburn 772: $r->print($personal_table);
773: if ($showforceid) {
1.203 raeburn 774: $r->print(&Apache::lonuserutils::forceid_change($context));
1.199 raeburn 775: }
776: $r->print('</div>');
1.227 raeburn 777: my $user_auth_text = &user_authentication($ccuname,$ccdomain,$formname);
1.188 raeburn 778: my $user_quota_text;
779: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
780: # Current user has quota modification privileges
781: $user_quota_text = &portfolio_quota($ccuname,$ccdomain);
782: } elsif (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
783: # Get the user's portfolio information
784: my %portq = &Apache::lonnet::get('environment',['portfolioquota'],
785: $ccdomain,$ccuname);
786:
787: my %lt=&Apache::lonlocal::texthash(
788: 'dska' => "Disk space allocated to user's portfolio files",
789: 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
790: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
791: );
792: $user_quota_text = <<ENDNOPORTPRIV;
793: <h3>$lt{'dska'}</h3>
794: $lt{'youd'} $lt{'ichr'}: $ccdomain
795: ENDNOPORTPRIV
796: }
797: if ($user_auth_text ne '') {
798: $r->print('<div class="LC_left_float">'.$user_auth_text);
799: if ($user_quota_text ne '') {
800: $r->print($user_quota_text);
801: }
1.213 raeburn 802: if ($env{'form.action'} eq 'singlestudent') {
803: $r->print(&date_sections_select($context,$newuser,$formname));
804: }
1.188 raeburn 805: } elsif ($user_quota_text ne '') {
1.213 raeburn 806: $r->print('<div class="LC_left_float">'.$user_quota_text);
807: if ($env{'form.action'} eq 'singlestudent') {
808: $r->print(&date_sections_select($context,$newuser,$formname));
809: }
810: } else {
811: if ($env{'form.action'} eq 'singlestudent') {
812: $r->print('<div class="LC_left_float">'.
813: &date_sections_select($context,$newuser,$formname));
814: }
1.188 raeburn 815: }
1.213 raeburn 816: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.217 raeburn 817: if ($env{'form.action'} ne 'singlestudent') {
818: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses);
819: }
1.25 matthew 820: } ## End of new user/old user logic
1.218 raeburn 821:
822: if ($env{'form.action'} eq 'singlestudent') {
823: $r->print('<br /><input type="button" value="'.&mt('Enroll Student').'" onClick="setSections(this.form)" />'."\n");
824: } else {
825: $r->print('<h3>'.&mt('Add Roles').'</h3>');
826: my $addrolesdisplay = 0;
827: if ($context eq 'domain' || $context eq 'author') {
828: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
829: }
830: if ($context eq 'domain') {
831: my $add_domainroles = &new_domain_roles($r);
832: if (!$addrolesdisplay) {
833: $addrolesdisplay = $add_domainroles;
1.2 www 834: }
1.218 raeburn 835: $r->print(&course_level_dc($env{'request.role.domain'},'Course'));
836: $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()" />'."\n");
837: } elsif ($context eq 'author') {
838: if ($addrolesdisplay) {
839: $r->print('<br /><input type="button" value="'.&mt('Modify User').'"');
840: if ($newuser) {
1.227 raeburn 841: $r->print(' onClick="auth_check()" \>'."\n");
1.218 raeburn 842: } else {
843: $r->print('onClick="this.form.submit()" \>'."\n");
844: }
1.188 raeburn 845: } else {
1.218 raeburn 846: $r->print('<br /><a href="javascript:backPage(document.cu)">'.
847: &mt('Back to previous page').'</a>');
1.188 raeburn 848: }
849: } else {
1.218 raeburn 850: $r->print(&course_level_table(%inccourses));
851: $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setSections(this.form)" />'."\n");
1.188 raeburn 852: }
1.88 raeburn 853: }
1.188 raeburn 854: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 855: $r->print('<input type="hidden" name="currstate" value="" />');
1.160 raeburn 856: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />');
1.110 albertel 857: $r->print("</form>".&Apache::loncommon::end_page());
1.218 raeburn 858: return;
1.2 www 859: }
1.1 www 860:
1.213 raeburn 861: sub singleuser_breadcrumb {
862: my %breadcrumb_text;
863: if ($env{'form.action'} eq 'singlestudent') {
864: $breadcrumb_text{'search'} = 'Enroll a student';
865: $breadcrumb_text{'userpicked'} = 'Select a user',
866: $breadcrumb_text{'modify'} = 'Set section/dates',
867: } else {
1.229 raeburn 868: $breadcrumb_text{'search'} = 'Create/modify a user';
1.213 raeburn 869: $breadcrumb_text{'userpicked'} = 'Select a user',
870: $breadcrumb_text{'modify'} = 'Set user role',
871: }
872: return %breadcrumb_text;
873: }
874:
875: sub date_sections_select {
876: my ($context,$newuser,$formname,$permission) = @_;
877: my $cid = $env{'request.course.id'};
878: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
879: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
880: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
881: undef,$formname,$permission);
882: my $rowtitle = 'Section';
883: my $secbox = '<h3>'.&mt('Section').'</h3>'."\n".
884: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
885: $permission);
886: my $output = $date_table.$secbox;
887: return $output;
888: }
889:
1.216 raeburn 890: sub validation_javascript {
891: my ($context,$ccdomain,$pjump_def,$groupslist,$newuser,$formname,
892: $loaditem) = @_;
893: my $dc_setcourse_code = '';
894: my $nondc_setsection_code = '';
895: if ($context eq 'domain') {
896: my $dcdom = $env{'request.role.domain'};
897: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 898: $dc_setcourse_code =
899: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 900: } else {
1.227 raeburn 901: my $checkauth;
902: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
903: $checkauth = 1;
904: }
905: if ($context eq 'course') {
906: $nondc_setsection_code =
907: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
908: undef,$checkauth);
909: }
910: if ($checkauth) {
911: $nondc_setsection_code .=
912: &Apache::lonuserutils::verify_authen($formname,$context);
913: }
1.216 raeburn 914: }
915: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
916: $nondc_setsection_code,$groupslist);
917: my ($jsback,$elements) = &crumb_utilities();
918: $js .= "\n".
1.227 raeburn 919: '<script type="text/javascript">'."\n".$jsback."\n".'</script>';
1.216 raeburn 920: return $js;
921: }
922:
1.217 raeburn 923: sub display_existing_roles {
924: my ($r,$ccuname,$ccdomain,$inccourses) = @_;
925: my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
926: # Build up table of user roles to allow revocation and re-enabling of roles.
927: my ($tmp) = keys(%rolesdump);
928: if ($tmp !~ /^(con_lost|error)/i) {
929: my $now=time;
930: my %lt=&Apache::lonlocal::texthash(
931: 'rer' => "Existing Roles",
932: 'rev' => "Revoke",
933: 'del' => "Delete",
934: 'ren' => "Re-Enable",
935: 'rol' => "Role",
936: 'ext' => "Extent",
937: 'sta' => "Start",
938: 'end' => "End",
939: );
940: my (%roletext,%sortrole,%roleclass,%rolepriv);
941: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
942: my $b1=join('_',(split('_',$b))[1,0]);
943: return $a1 cmp $b1;
944: } keys(%rolesdump)) {
945: next if ($area =~ /^rolesdef/);
946: my $envkey=$area;
947: my $role = $rolesdump{$area};
948: my $thisrole=$area;
949: $area =~ s/\_\w\w$//;
950: my ($role_code,$role_end_time,$role_start_time) =
951: split(/_/,$role);
952: # Is this a custom role? Get role owner and title.
953: my ($croleudom,$croleuname,$croletitle)=
954: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
955: my $allowed=0;
956: my $delallowed=0;
957: my $sortkey=$role_code;
958: my $class='Unknown';
959: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
960: $class='Course';
961: my ($coursedom,$coursedir) = ($1,$2);
962: $sortkey.="\0$coursedom";
963: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
964: my %coursedata=
965: &Apache::lonnet::coursedescription($1.'_'.$2);
966: my $carea;
967: if (defined($coursedata{'description'})) {
968: $carea=$coursedata{'description'}.
969: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
970: &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
971: $sortkey.="\0".$coursedata{'description'};
972: $class=$coursedata{'type'};
973: } else {
974: $carea=&mt('Unavailable course').': '.$area;
975: $sortkey.="\0".&mt('Unavailable course').': '.$area;
976: }
977: $sortkey.="\0$coursedir";
978: $inccourses->{$1.'_'.$2}=1;
979: if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
980: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
981: $allowed=1;
982: }
983: if ((&Apache::lonnet::allowed('dro',$1)) ||
984: (&Apache::lonnet::allowed('dro',$ccdomain))) {
985: $delallowed=1;
986: }
987: # - custom role. Needs more info, too
988: if ($croletitle) {
989: if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
990: $allowed=1;
991: $thisrole.='.'.$role_code;
992: }
993: }
994: # Compute the background color based on $area
995: if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
996: $carea.='<br />Section: '.$3;
997: $sortkey.="\0$3";
998: if (!$allowed) {
999: if ($env{'request.course.sec'} eq $3) {
1000: if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
1001: $allowed = 1;
1002: }
1003: }
1004: }
1005: }
1006: $area=$carea;
1007: } else {
1008: $sortkey.="\0".$area;
1009: # Determine if current user is able to revoke privileges
1010: if ($area=~m{^/($match_domain)/}) {
1011: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1012: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1013: $allowed=1;
1014: }
1015: if (((&Apache::lonnet::allowed('dro',$1)) ||
1016: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1017: ($role_code ne 'dc')) {
1018: $delallowed=1;
1019: }
1020: } else {
1021: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1022: $allowed=1;
1023: }
1024: }
1025: if ($role_code eq 'ca' || $role_code eq 'au') {
1026: $class='Construction Space';
1027: } elsif ($role_code eq 'su') {
1028: $class='System';
1029: } else {
1030: $class='Domain';
1031: }
1032: }
1033: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1034: $area=~m{/($match_domain)/($match_username)};
1035: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1036: $allowed=1;
1037: } else {
1038: $allowed=0;
1039: }
1040: }
1041: my $row = '';
1042: $row.= '<td>';
1043: my $active=1;
1044: $active=0 if (($role_end_time) && ($now>$role_end_time));
1045: if (($active) && ($allowed)) {
1046: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1047: } else {
1048: if ($active) {
1049: $row.=' ';
1050: } else {
1051: $row.=&mt('expired or revoked');
1052: }
1053: }
1054: $row.='</td><td>';
1055: if ($allowed && !$active) {
1056: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1057: } else {
1058: $row.=' ';
1059: }
1060: $row.='</td><td>';
1061: if ($delallowed) {
1062: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1063: } else {
1064: $row.=' ';
1065: }
1066: my $plaintext='';
1067: if (!$croletitle) {
1068: $plaintext=&Apache::lonnet::plaintext($role_code,$class)
1069: } else {
1070: $plaintext=
1071: "Customrole '$croletitle'<br />defined by $croleuname\@$croleudom";
1072: }
1073: $row.= '</td><td>'.$plaintext.
1074: '</td><td>'.$area.
1075: '</td><td>'.($role_start_time?localtime($role_start_time)
1076: : ' ' ).
1077: '</td><td>'.($role_end_time ?localtime($role_end_time)
1078: : ' ' )
1079: ."</td>";
1080: $sortrole{$sortkey}=$envkey;
1081: $roletext{$envkey}=$row;
1082: $roleclass{$envkey}=$class;
1083: $rolepriv{$envkey}=$allowed;
1084: #$r->print($row);
1085: } # end of foreach (table building loop)
1086: my $rolesdisplay = 0;
1087: my %output = ();
1088: foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
1089: $output{$type} = '';
1090: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1091: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1092: $output{$type}.=
1093: &Apache::loncommon::start_data_table_row().
1094: $roletext{$sortrole{$which}}.
1095: &Apache::loncommon::end_data_table_row();
1096: }
1097: }
1098: unless($output{$type} eq '') {
1099: $output{$type} = '<tr class="LC_info_row">'.
1100: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1101: $output{$type};
1102: $rolesdisplay = 1;
1103: }
1104: }
1105: if ($rolesdisplay == 1) {
1106: $r->print('
1107: <h3>'.$lt{'rer'}.'</h3>'.
1108: &Apache::loncommon::start_data_table("LC_createuser").
1109: &Apache::loncommon::start_data_table_header_row().
1110: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
1111: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
1112: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1113: &Apache::loncommon::end_data_table_header_row());
1114: foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
1115: if ($output{$type}) {
1116: $r->print($output{$type}."\n");
1117: }
1118: }
1119: $r->print(&Apache::loncommon::end_data_table());
1120: }
1121: } # End of check for keys in rolesdump
1122: return;
1123: }
1124:
1.218 raeburn 1125: sub new_coauthor_roles {
1126: my ($r,$ccuname,$ccdomain) = @_;
1127: my $addrolesdisplay = 0;
1128: #
1129: # Co-Author
1130: #
1131: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
1132: $env{'request.role.domain'}) &&
1133: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1134: # No sense in assigning co-author role to yourself
1135: $addrolesdisplay = 1;
1136: my $cuname=$env{'user.name'};
1137: my $cudom=$env{'request.role.domain'};
1138: my %lt=&Apache::lonlocal::texthash(
1139: 'cs' => "Construction Space",
1140: 'act' => "Activate",
1141: 'rol' => "Role",
1142: 'ext' => "Extent",
1143: 'sta' => "Start",
1144: 'end' => "End",
1145: 'cau' => "Co-Author",
1146: 'caa' => "Assistant Co-Author",
1147: 'ssd' => "Set Start Date",
1148: 'sed' => "Set End Date"
1149: );
1150: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
1151: &Apache::loncommon::start_data_table()."\n".
1152: &Apache::loncommon::start_data_table_header_row()."\n".
1153: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
1154: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
1155: '<th>'.$lt{'end'}.'</th>'."\n".
1156: &Apache::loncommon::end_data_table_header_row()."\n".
1157: &Apache::loncommon::start_data_table_row().'
1158: <td>
1159: <input type=checkbox name="act_'.$cudom.'_'.$cuname.'_ca" />
1160: </td>
1161: <td>'.$lt{'cau'}.'</td>
1162: <td>'.$cudom.'_'.$cuname.'</td>
1163: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
1164: <a href=
1165: "javascript:pjump('."'date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1166: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
1167: <a href=
1168: "javascript:pjump('."'date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
1169: &Apache::loncommon::end_data_table_row()."\n".
1170: &Apache::loncommon::start_data_table_row()."\n".
1171: '<td><input type=checkbox name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1172: <td>'.$lt{'caa'}.'</td>
1173: <td>'.$cudom.'_'.$cuname.'</td>
1174: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
1175: <a href=
1176: "javascript:pjump('."'date_start','Start Date Assistant Co-Author',document.cu.start_$cudom\_$cuname\_aa.value,'start_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1177: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
1178: <a href=
1179: "javascript:pjump('."'date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
1180: &Apache::loncommon::end_data_table_row()."\n".
1181: &Apache::loncommon::end_data_table());
1182: } elsif ($env{'request.role'} =~ /^au\./) {
1183: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
1184: $env{'request.role.domain'}))) {
1185: $r->print('<span class="LC_error">'.
1186: &mt('You do not have privileges to assign co-author roles.').
1187: '</span>');
1188: } elsif (($env{'user.name'} eq $ccuname) &&
1189: ($env{'user.domain'} eq $ccdomain)) {
1190: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Construction Space is not permitted'));
1191: }
1192: }
1193: return $addrolesdisplay;;
1194: }
1195:
1196: sub new_domain_roles {
1197: my ($r) = @_;
1198: my $addrolesdisplay = 0;
1199: #
1200: # Domain level
1201: #
1202: my $num_domain_level = 0;
1203: my $domaintext =
1204: '<h4>'.&mt('Domain Level').'</h4>'.
1205: &Apache::loncommon::start_data_table().
1206: &Apache::loncommon::start_data_table_header_row().
1207: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
1208: &mt('Extent').'</th>'.
1209: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
1210: &Apache::loncommon::end_data_table_header_row();
1211: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1212: foreach my $role ('dc','li','dg','au','sc') {
1213: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1214: my $plrole=&Apache::lonnet::plaintext($role);
1215: my %lt=&Apache::lonlocal::texthash(
1216: 'ssd' => "Set Start Date",
1217: 'sed' => "Set End Date"
1218: );
1219: $num_domain_level ++;
1220: $domaintext .=
1221: &Apache::loncommon::start_data_table_row().
1222: '<td><input type=checkbox name="act_'.$thisdomain.'_'.$role.'" /></td>
1223: <td>'.$plrole.'</td>
1224: <td>'.$thisdomain.'</td>
1225: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
1226: <a href=
1227: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
1228: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
1229: <a href=
1230: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
1231: &Apache::loncommon::end_data_table_row();
1232: }
1233: }
1234: }
1235: $domaintext.= &Apache::loncommon::end_data_table();
1236: if ($num_domain_level > 0) {
1237: $r->print($domaintext);
1238: $addrolesdisplay = 1;
1239: }
1240: return $addrolesdisplay;
1241: }
1242:
1.188 raeburn 1243: sub user_authentication {
1.227 raeburn 1244: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 1245: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 1246: my $outcome;
1.188 raeburn 1247: # Check for a bad authentication type
1248: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
1249: # bad authentication scheme
1250: my %lt=&Apache::lonlocal::texthash(
1251: 'err' => "ERROR",
1252: 'uuas' => "This user has an unrecognized authentication scheme",
1253: 'adcs' => "Please alert a domain coordinator of this situation",
1254: 'sldb' => "Please specify login data below",
1255: 'ld' => "Login Data"
1256: );
1257: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 1258: &initialize_authen_forms($ccdomain,$formname);
1259:
1.190 raeburn 1260: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 1261: $outcome = <<ENDBADAUTH;
1262: <script type="text/javascript" language="Javascript">
1263: $loginscript
1264: </script>
1265: <span class="LC_error">$lt{'err'}:
1266: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
1267: <h3>$lt{'ld'}</h3>
1268: $choices
1269: ENDBADAUTH
1270: } else {
1271: # This user is not allowed to modify the user's
1272: # authentication scheme, so just notify them of the problem
1273: $outcome = <<ENDBADAUTH;
1274: <span class="LC_error"> $lt{'err'}:
1275: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
1276: </span>
1277: ENDBADAUTH
1278: }
1279: } else { # Authentication type is valid
1.227 raeburn 1280: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 1281: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 1282: &modify_login_block($ccdomain,$currentauth);
1283: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1284: # Current user has login modification privileges
1285: my %lt=&Apache::lonlocal::texthash (
1286: 'ld' => "Login Data",
1287: 'ccld' => "Change Current Login Data",
1288: 'enld' => "Enter New Login Data"
1289: );
1290: $outcome =
1291: '<script type="text/javascript" language="Javascript">'."\n".
1292: $loginscript."\n".
1293: '</script>'."\n".
1294: '<h3>'.$lt{'ld'}.'</h3>'.
1295: &Apache::loncommon::start_data_table().
1.205 raeburn 1296: &Apache::loncommon::start_data_table_row().
1.188 raeburn 1297: '<td>'.$authformnop;
1298: if ($can_modify) {
1299: $outcome .= '</td>'."\n".
1300: &Apache::loncommon::end_data_table_row().
1301: &Apache::loncommon::start_data_table_row().
1302: '<td>'.$authformcurrent.'</td>'.
1303: &Apache::loncommon::end_data_table_row()."\n";
1304: } else {
1.200 raeburn 1305: $outcome .= ' ('.$authformcurrent.')</td>'.
1306: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 1307: }
1.205 raeburn 1308: foreach my $item (@authform_others) {
1309: $outcome .= &Apache::loncommon::start_data_table_row().
1310: '<td>'.$item.'</td>'.
1311: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 1312: }
1.205 raeburn 1313: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 1314: } else {
1315: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1316: my %lt=&Apache::lonlocal::texthash(
1317: 'ccld' => "Change Current Login Data",
1318: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
1319: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1320: );
1321: $outcome .= <<ENDNOPRIV;
1322: <h3>$lt{'ccld'}</h3>
1323: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 1324: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 1325: ENDNOPRIV
1326: }
1327: }
1328: } ## End of "check for bad authentication type" logic
1329: return $outcome;
1330: }
1331:
1.187 raeburn 1332: sub modify_login_block {
1333: my ($dom,$currentauth) = @_;
1334: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
1335: my ($authnum,%can_assign) =
1336: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 1337: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 1338: if ($currentauth=~/^krb(4|5):/) {
1339: $authformcurrent=$authformkrb;
1340: if ($can_assign{'int'}) {
1.205 raeburn 1341: push(@authform_others,$authformint);
1.187 raeburn 1342: }
1343: if ($can_assign{'loc'}) {
1.205 raeburn 1344: push(@authform_others,$authformloc);
1.187 raeburn 1345: }
1346: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1347: $show_override_msg = 1;
1348: }
1349: } elsif ($currentauth=~/^internal:/) {
1350: $authformcurrent=$authformint;
1351: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1352: push(@authform_others,$authformkrb);
1.187 raeburn 1353: }
1354: if ($can_assign{'loc'}) {
1.205 raeburn 1355: push(@authform_others,$authformloc);
1.187 raeburn 1356: }
1357: if ($can_assign{'int'}) {
1358: $show_override_msg = 1;
1359: }
1360: } elsif ($currentauth=~/^unix:/) {
1361: $authformcurrent=$authformfsys;
1362: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1363: push(@authform_others,$authformkrb);
1.187 raeburn 1364: }
1365: if ($can_assign{'int'}) {
1.205 raeburn 1366: push(@authform_others,$authformint);
1.187 raeburn 1367: }
1368: if ($can_assign{'loc'}) {
1.205 raeburn 1369: push(@authform_others,$authformloc);
1.187 raeburn 1370: }
1371: if ($can_assign{'fsys'}) {
1372: $show_override_msg = 1;
1373: }
1374: } elsif ($currentauth=~/^localauth:/) {
1375: $authformcurrent=$authformloc;
1376: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 1377: push(@authform_others,$authformkrb);
1.187 raeburn 1378: }
1379: if ($can_assign{'int'}) {
1.205 raeburn 1380: push(@authform_others,$authformint);
1.187 raeburn 1381: }
1382: if ($can_assign{'loc'}) {
1383: $show_override_msg = 1;
1384: }
1385: }
1386: if ($show_override_msg) {
1.205 raeburn 1387: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
1388: '</td></tr>'."\n".
1389: '<tr><td> </td>'.
1390: '<td><b>'.&mt('Currently in use').'</b></td>'.
1391: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 1392: &mt('will override current values').
1.205 raeburn 1393: '</span></td></tr></table>';
1.187 raeburn 1394: }
1.205 raeburn 1395: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 1396: }
1397:
1.188 raeburn 1398: sub personal_data_display {
1.252 raeburn 1399: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
1.257 raeburn 1400: my ($output,$showforceid,%userenv,%canmodify);
1.219 raeburn 1401: my @userinfo = ('firstname','middlename','lastname','generation',
1402: 'permanentemail','id');
1.252 raeburn 1403: my $rowcount = 0;
1404: my $editable = 0;
1.253 raeburn 1405: if (!$newuser) {
1.188 raeburn 1406: # Get the users information
1407: %userenv = &Apache::lonnet::get('environment',
1408: ['firstname','middlename','lastname','generation',
1409: 'permanentemail','id'],$ccdomain,$ccuname);
1.219 raeburn 1410: %canmodify =
1411: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 1412: \@userinfo,$rolesarray);
1.257 raeburn 1413: } elsif ($context eq 'selfcreate') {
1414: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
1415: $inst_results,$rolesarray);
1.188 raeburn 1416: }
1417: my %lt=&Apache::lonlocal::texthash(
1418: 'pd' => "Personal Data",
1419: 'firstname' => "First Name",
1420: 'middlename' => "Middle Name",
1421: 'lastname' => "Last Name",
1422: 'generation' => "Generation",
1423: 'permanentemail' => "Permanent e-mail address",
1424: 'id' => "ID/Student Number",
1425: 'lg' => "Login Data"
1426: );
1427: my %textboxsize = (
1428: firstname => '15',
1429: middlename => '15',
1430: lastname => '15',
1431: generation => '5',
1432: permanentemail => '25',
1433: id => '15',
1434: );
1435: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
1436: $output = '<h3>'.$lt{'pd'}.'</h3>'.
1437: &Apache::lonhtmlcommon::start_pick_box();
1438: foreach my $item (@userinfo) {
1439: my $rowtitle = $lt{$item};
1.252 raeburn 1440: my $hiderow = 0;
1.188 raeburn 1441: if ($item eq 'generation') {
1442: $rowtitle = $genhelp.$rowtitle;
1443: }
1.252 raeburn 1444: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 1445: if ($newuser) {
1.210 raeburn 1446: if (ref($inst_results) eq 'HASH') {
1447: if ($inst_results->{$item} ne '') {
1.252 raeburn 1448: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 1449: } else {
1.252 raeburn 1450: if ($context eq 'selfcreate') {
1451: if ($canmodify{$item}) {
1452: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1453: $editable ++;
1454: } else {
1455: $hiderow = 1;
1456: }
1.253 raeburn 1457: } else {
1458: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 1459: }
1.210 raeburn 1460: }
1.188 raeburn 1461: } else {
1.252 raeburn 1462: if ($context eq 'selfcreate') {
1463: if ($canmodify{$item}) {
1464: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1465: $editable ++;
1466: } else {
1467: $hiderow = 1;
1468: }
1.253 raeburn 1469: } else {
1470: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 1471: }
1.188 raeburn 1472: }
1473: } else {
1.219 raeburn 1474: if ($canmodify{$item}) {
1.252 raeburn 1475: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.188 raeburn 1476: } else {
1.252 raeburn 1477: $row .= $userenv{$item};
1.188 raeburn 1478: }
1.206 raeburn 1479: if ($item eq 'id') {
1.219 raeburn 1480: $showforceid = $canmodify{$item};
1481: }
1.188 raeburn 1482: }
1.252 raeburn 1483: $row .= &Apache::lonhtmlcommon::row_closure(1);
1484: if (!$hiderow) {
1485: $output .= $row;
1486: $rowcount ++;
1487: }
1.188 raeburn 1488: }
1489: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 1490: if (wantarray) {
1.252 raeburn 1491: if ($context eq 'selfcreate') {
1492: return($output,$rowcount,$editable);
1493: } else {
1494: return ($output,$showforceid);
1495: }
1.206 raeburn 1496: } else {
1497: return $output;
1498: }
1.188 raeburn 1499: }
1500:
1.257 raeburn 1501: sub selfcreate_canmodify {
1502: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
1503: if (ref($inst_results) eq 'HASH') {
1504: my @inststatuses = &get_inststatuses($inst_results);
1505: if (@inststatuses == 0) {
1506: @inststatuses = ('default');
1507: }
1508: $rolesarray = \@inststatuses;
1509: }
1510: my %canmodify =
1511: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
1512: $rolesarray);
1513: return %canmodify;
1514: }
1515:
1.252 raeburn 1516: sub get_inststatuses {
1517: my ($insthashref) = @_;
1518: my @inststatuses = ();
1519: if (ref($insthashref) eq 'HASH') {
1520: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
1521: @inststatuses = @{$insthashref->{'inststatus'}};
1522: }
1523: }
1524: return @inststatuses;
1525: }
1526:
1.4 www 1527: # ================================================================= Phase Three
1.42 matthew 1528: sub update_user_data {
1.206 raeburn 1529: my ($r,$context) = @_;
1.101 albertel 1530: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
1531: $env{'form.ccdomain'});
1.27 matthew 1532: # Error messages
1.188 raeburn 1533: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 1534: my $end = '</span><br /><br />';
1535: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 1536: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 1537: &mt('Return to previous page').'</a>'.
1538: &Apache::loncommon::end_page();
1539: my $now = time;
1.40 www 1540: my $title;
1.101 albertel 1541: if (exists($env{'form.makeuser'})) {
1.40 www 1542: $title='Set Privileges for New User';
1543: } else {
1544: $title='Modify User Privileges';
1545: }
1.213 raeburn 1546: my $newuser = 0;
1.160 raeburn 1547: my ($jsback,$elements) = &crumb_utilities();
1548: my $jscript = '<script type="text/javascript">'."\n".
1549: $jsback."\n".'</script>'."\n";
1.213 raeburn 1550: my %breadcrumb_text = &singleuser_breadcrumb();
1.233 raeburn 1551: my $args;
1552: if ($env{'form.popup'}) {
1553: $args->{'no_nav_bar'} = 1;
1554: } else {
1555: $args = undef;
1556: }
1557: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.160 raeburn 1558: &Apache::lonhtmlcommon::add_breadcrumb
1559: ({href=>"javascript:backPage(document.userupdate)",
1.213 raeburn 1560: text=>$breadcrumb_text{'search'},
1.160 raeburn 1561: faq=>282,bug=>'Instructor Interface',});
1562: if ($env{'form.prevphase'} eq 'userpicked') {
1563: &Apache::lonhtmlcommon::add_breadcrumb
1564: ({href=>"javascript:backPage(document.userupdate,'get_user_info','select')",
1.213 raeburn 1565: text=>$breadcrumb_text{'userpicked'},
1.160 raeburn 1566: faq=>282,bug=>'Instructor Interface',});
1567: }
1568: &Apache::lonhtmlcommon::add_breadcrumb
1569: ({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
1.219 raeburn 1570: text=>$breadcrumb_text{'modify'},
1.160 raeburn 1571: faq=>282,bug=>'Instructor Interface',},
1572: {href=>"/adm/createuser",
1573: text=>"Result",
1574: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 1575: my $helpitem = 'Course_Change_Privileges';
1576: if ($env{'form.action'} eq 'singlestudent') {
1577: $helpitem = 'Course_Add_Student';
1578: }
1579: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
1580: $helpitem));
1.188 raeburn 1581: $r->print(&update_result_form($uhome));
1.27 matthew 1582: # Check Inputs
1.101 albertel 1583: if (! $env{'form.ccuname'} ) {
1.193 raeburn 1584: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 1585: return;
1586: }
1.138 albertel 1587: if ( $env{'form.ccuname'} ne
1588: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.73 sakharuk 1589: $r->print($error.&mt('Invalid login name').'. '.
1.160 raeburn 1590: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid').'.'.
1.193 raeburn 1591: $end.$rtnlink);
1.27 matthew 1592: return;
1593: }
1.101 albertel 1594: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 1595: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 1596: return;
1597: }
1.138 albertel 1598: if ( $env{'form.ccdomain'} ne
1599: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.73 sakharuk 1600: $r->print($error.&mt ('Invalid domain name').'. '.
1.138 albertel 1601: &mt('Only letters, numbers, periods, dashes, and underscores are valid').'.'.
1.193 raeburn 1602: $end.$rtnlink);
1.27 matthew 1603: return;
1604: }
1.219 raeburn 1605: if ($uhome eq 'no_host') {
1606: $newuser = 1;
1607: }
1.101 albertel 1608: if (! exists($env{'form.makeuser'})) {
1.29 matthew 1609: # Modifying an existing user, so check the validity of the name
1610: if ($uhome eq 'no_host') {
1.73 sakharuk 1611: $r->print($error.&mt('Unable to determine home server for ').
1.101 albertel 1612: $env{'form.ccuname'}.&mt(' in domain ').
1613: $env{'form.ccdomain'}.'.');
1.29 matthew 1614: return;
1615: }
1616: }
1.27 matthew 1617: # Determine authentication method and password for the user being modified
1618: my $amode='';
1619: my $genpwd='';
1.101 albertel 1620: if ($env{'form.login'} eq 'krb') {
1.41 albertel 1621: $amode='krb';
1.101 albertel 1622: $amode.=$env{'form.krbver'};
1623: $genpwd=$env{'form.krbarg'};
1624: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 1625: $amode='internal';
1.101 albertel 1626: $genpwd=$env{'form.intarg'};
1627: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 1628: $amode='unix';
1.101 albertel 1629: $genpwd=$env{'form.fsysarg'};
1630: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 1631: $amode='localauth';
1.101 albertel 1632: $genpwd=$env{'form.locarg'};
1.27 matthew 1633: $genpwd=" " if (!$genpwd);
1.101 albertel 1634: } elsif (($env{'form.login'} eq 'nochange') ||
1635: ($env{'form.login'} eq '' )) {
1.34 matthew 1636: # There is no need to tell the user we did not change what they
1637: # did not ask us to change.
1.35 matthew 1638: # If they are creating a new user but have not specified login
1639: # information this will be caught below.
1.30 matthew 1640: } else {
1.193 raeburn 1641: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.30 matthew 1642: return;
1.27 matthew 1643: }
1.164 albertel 1644:
1.188 raeburn 1645: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1646: $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h3>');
1.193 raeburn 1647: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.101 albertel 1648: if ($env{'form.makeuser'}) {
1.164 albertel 1649: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 1650: # Check for the authentication mode and password
1651: if (! $amode || ! $genpwd) {
1.193 raeburn 1652: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 1653: return;
1.18 albertel 1654: }
1.29 matthew 1655: # Determine desired host
1.101 albertel 1656: my $desiredhost = $env{'form.hserver'};
1.29 matthew 1657: if (lc($desiredhost) eq 'default') {
1658: $desiredhost = undef;
1659: } else {
1.147 albertel 1660: my %home_servers =
1661: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 1662: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 1663: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
1664: return;
1665: }
1666: }
1667: # Check ID format
1668: my %checkhash;
1669: my %checks = ('id' => 1);
1670: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 1671: 'newuser' => $newuser,
1.196 raeburn 1672: 'id' => $env{'form.cid'},
1.193 raeburn 1673: );
1.196 raeburn 1674: if ($env{'form.cid'} ne '') {
1675: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
1676: \%rulematch,\%inst_results,\%curr_rules);
1677: if (ref($alerts{'id'}) eq 'HASH') {
1678: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1679: my $domdesc =
1680: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
1681: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
1682: my $userchkmsg;
1683: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
1684: $userchkmsg =
1685: &Apache::loncommon::instrule_disallow_msg('id',
1686: $domdesc,1).
1687: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
1688: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
1689: }
1690: $r->print($error.&mt('Invalid ID format').$end.
1691: $userchkmsg.$rtnlink);
1692: return;
1693: }
1694: }
1.29 matthew 1695: }
1696: }
1.27 matthew 1697: # Call modifyuser
1698: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 1699: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 1700: $amode,$genpwd,$env{'form.cfirstname'},
1701: $env{'form.cmiddlename'},$env{'form.clastname'},
1702: $env{'form.cgeneration'},undef,$desiredhost,
1703: $env{'form.cpermanentemail'});
1.77 www 1704: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 1705: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 1706: $env{'form.ccdomain'});
1.232 raeburn 1707: if (($uhome ne 'no_host') && ($env{'form.customquota'} == 1)) {
1708: my (%changeHash,$newportfolioquota);
1709: if ($env{'form.portfolioquota'} eq '') {
1710: $newportfolioquota = 0;
1711: } else {
1712: $newportfolioquota = $env{'form.portfolioquota'};
1713: $newportfolioquota =~ s/[^\d\.]//g;
1714: }
1715: my $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1716: if ($quotachanged) {
1717: $changeHash{'firstname'} = $env{'form.cfirstname'};
1718: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1719: $changeHash{'lastname'} = $env{'form.clastname'};
1720: $changeHash{'generation'} = $env{'form.cgeneration'};
1721: $changeHash{'id'} = $env{'form.cid'};
1722: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1723: my $quotachgresult =
1724: &Apache::lonnet::put('environment',\%changeHash,
1725: $env{'form.ccdomain'},$env{'form.ccuname'});
1726: }
1727: }
1.219 raeburn 1728: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
1729: &Apache::lonnet::hostname($uhome));
1.101 albertel 1730: } elsif (($env{'form.login'} ne 'nochange') &&
1731: ($env{'form.login'} ne '' )) {
1.27 matthew 1732: # Modify user privileges
1733: if (! $amode || ! $genpwd) {
1.193 raeburn 1734: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 1735: return;
1.20 harris41 1736: }
1.27 matthew 1737: # Only allow authentification modification if the person has authority
1.101 albertel 1738: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 1739: $r->print('Modifying authentication: '.
1.31 matthew 1740: &Apache::lonnet::modifyuserauth(
1.101 albertel 1741: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 1742: $amode,$genpwd));
1.102 albertel 1743: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 1744: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 1745: } else {
1.27 matthew 1746: # Okay, this is a non-fatal error.
1.193 raeburn 1747: $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
1.27 matthew 1748: }
1.28 matthew 1749: }
1750: ##
1.213 raeburn 1751: my (@userroles,%userupdate,$cnum,$cdom,$namechanged);
1752: if ($context eq 'course') {
1753: ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1754: }
1.101 albertel 1755: if (! $env{'form.makeuser'} ) {
1.28 matthew 1756: # Check for need to change
1757: my %userenv = &Apache::lonnet::get
1.134 raeburn 1758: ('environment',['firstname','middlename','lastname','generation',
1.196 raeburn 1759: 'id','permanentemail','portfolioquota','inststatus'],
1.160 raeburn 1760: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 1761: my ($tmp) = keys(%userenv);
1762: if ($tmp =~ /^(con_lost|error)/i) {
1763: %userenv = ();
1764: }
1.206 raeburn 1765: my $no_forceid_alert;
1766: # Check to see if user information can be changed
1767: my %domconfig =
1768: &Apache::lonnet::get_dom('configuration',['usermodification'],
1769: $env{'form.ccdomain'});
1.213 raeburn 1770: my @statuses = ('active','future');
1771: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
1772: my ($auname,$audom);
1.220 raeburn 1773: if ($context eq 'author') {
1.206 raeburn 1774: $auname = $env{'user.name'};
1775: $audom = $env{'user.domain'};
1776: }
1777: foreach my $item (keys(%roles)) {
1.220 raeburn 1778: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 1779: if ($context eq 'course') {
1780: if ($cnum ne '' && $cdom ne '') {
1781: if ($rolenum eq $cnum && $roledom eq $cdom) {
1782: if (!grep(/^\Q$role\E$/,@userroles)) {
1783: push(@userroles,$role);
1784: }
1785: }
1786: }
1787: } elsif ($context eq 'author') {
1788: if ($rolenum eq $auname && $roledom eq $audom) {
1789: if (!grep(/^\Q$role\E$/,@userroles)) {
1790: push(@userroles,$role);
1791: }
1792: }
1793: }
1794: }
1.220 raeburn 1795: if ($env{'form.action'} eq 'singlestudent') {
1796: if (!grep(/^st$/,@userroles)) {
1797: push(@userroles,'st');
1798: }
1799: } else {
1800: # Check for course or co-author roles being activated or re-enabled
1801: if ($context eq 'author' || $context eq 'course') {
1802: foreach my $key (keys(%env)) {
1803: if ($context eq 'author') {
1804: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
1805: if (!grep(/^\Q$1\E$/,@userroles)) {
1806: push(@userroles,$1);
1807: }
1808: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
1809: if (!grep(/^\Q$1\E$/,@userroles)) {
1810: push(@userroles,$1);
1811: }
1.206 raeburn 1812: }
1.220 raeburn 1813: } elsif ($context eq 'course') {
1814: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
1815: if (!grep(/^\Q$1\E$/,@userroles)) {
1816: push(@userroles,$1);
1817: }
1818: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
1819: if (!grep(/^\Q$1\E$/,@userroles)) {
1820: push(@userroles,$1);
1821: }
1.206 raeburn 1822: }
1823: }
1824: }
1825: }
1826: }
1827: #Check to see if we can change personal data for the user
1828: my (@mod_disallowed,@longroles);
1829: foreach my $role (@userroles) {
1830: if ($role eq 'cr') {
1831: push(@longroles,'Custom');
1832: } else {
1833: push(@longroles,&Apache::lonnet::plaintext($role));
1834: }
1835: }
1.219 raeburn 1836: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1837: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
1838: foreach my $item (@userinfo) {
1.28 matthew 1839: # Strip leading and trailing whitespace
1.203 raeburn 1840: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 1841: if (!$canmodify{$item}) {
1.207 raeburn 1842: if (defined($env{'form.c'.$item})) {
1843: if ($env{'form.c'.$item} ne $userenv{$item}) {
1844: push(@mod_disallowed,$item);
1845: }
1.206 raeburn 1846: }
1847: $env{'form.c'.$item} = $userenv{$item};
1848: }
1.28 matthew 1849: }
1.196 raeburn 1850: # Check to see if we can change the ID/student number
1851: my $forceid = $env{'form.forceid'};
1852: my $recurseid = $env{'form.recurseid'};
1853: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 1854: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
1855: $env{'form.ccuname'});
1856: if (($uidhash{$env{'form.ccuname'}}) &&
1857: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
1858: (!$forceid)) {
1859: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
1860: $env{'form.cid'} = $userenv{'id'};
1.206 raeburn 1861: $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 1862: }
1863: }
1864: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 1865: my $checkhash;
1866: my $checks = { 'id' => 1 };
1867: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
1868: { 'newuser' => $newuser,
1869: 'id' => $env{'form.cid'},
1870: };
1871: &Apache::loncommon::user_rule_check($checkhash,$checks,
1872: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
1873: if (ref($alerts{'id'}) eq 'HASH') {
1874: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 1875: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 1876: }
1877: }
1878: }
1.213 raeburn 1879: my ($quotachanged,$oldportfolioquota,$newportfolioquota,
1.204 raeburn 1880: $inststatus,$oldisdefault,$newisdefault,$olddefquotatext,
1881: $newdefquotatext);
1.149 raeburn 1882: my ($defquota,$settingstatus) =
1883: &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
1.220 raeburn 1884: my $showquota;
1885: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1886: $showquota = 1;
1887: }
1.134 raeburn 1888: my %changeHash;
1.204 raeburn 1889: $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
1.149 raeburn 1890: if ($userenv{'portfolioquota'} ne '') {
1.134 raeburn 1891: $oldportfolioquota = $userenv{'portfolioquota'};
1.149 raeburn 1892: if ($env{'form.customquota'} == 1) {
1893: if ($env{'form.portfolioquota'} eq '') {
1894: $newportfolioquota = 0;
1895: } else {
1896: $newportfolioquota = $env{'form.portfolioquota'};
1897: $newportfolioquota =~ s/[^\d\.]//g;
1898: }
1.204 raeburn 1899: if ($newportfolioquota != $oldportfolioquota) {
1.149 raeburn 1900: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1.134 raeburn 1901: }
1.149 raeburn 1902: } else {
1903: $quotachanged = "a_admin('',\%changeHash);
1904: $newportfolioquota = $defquota;
1.204 raeburn 1905: $newisdefault = 1;
1.134 raeburn 1906: }
1907: } else {
1.204 raeburn 1908: $oldisdefault = 1;
1.149 raeburn 1909: $oldportfolioquota = $defquota;
1910: if ($env{'form.customquota'} == 1) {
1911: if ($env{'form.portfolioquota'} eq '') {
1912: $newportfolioquota = 0;
1913: } else {
1914: $newportfolioquota = $env{'form.portfolioquota'};
1915: $newportfolioquota =~ s/[^\d\.]//g;
1916: }
1917: $quotachanged = "a_admin($newportfolioquota,\%changeHash);
1918: } else {
1919: $newportfolioquota = $defquota;
1.204 raeburn 1920: $newisdefault = 1;
1.149 raeburn 1921: }
1922: }
1.204 raeburn 1923: if ($oldisdefault) {
1924: $olddefquotatext = &get_defaultquota_text($settingstatus);
1925: }
1926: if ($newisdefault) {
1927: $newdefquotatext = &get_defaultquota_text($settingstatus);
1.134 raeburn 1928: }
1.206 raeburn 1929: if ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
1930: $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
1931: $env{'form.clastname'} ne $userenv{'lastname'} ||
1932: $env{'form.cgeneration'} ne $userenv{'generation'} ||
1933: $env{'form.cid'} ne $userenv{'id'} ||
1934: $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} ) {
1.134 raeburn 1935: $namechanged = 1;
1936: }
1.204 raeburn 1937: if ($namechanged || $quotachanged) {
1.101 albertel 1938: $changeHash{'firstname'} = $env{'form.cfirstname'};
1939: $changeHash{'middlename'} = $env{'form.cmiddlename'};
1940: $changeHash{'lastname'} = $env{'form.clastname'};
1941: $changeHash{'generation'} = $env{'form.cgeneration'};
1.196 raeburn 1942: $changeHash{'id'} = $env{'form.cid'};
1.174 raeburn 1943: $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
1.204 raeburn 1944: my ($quotachgresult,$namechgresult);
1945: if ($quotachanged) {
1946: $quotachgresult =
1947: &Apache::lonnet::put('environment',\%changeHash,
1948: $env{'form.ccdomain'},$env{'form.ccuname'});
1949: }
1950: if ($namechanged) {
1951: # Make the change
1952: $namechgresult =
1953: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
1954: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
1955: $changeHash{'firstname'},$changeHash{'middlename'},
1956: $changeHash{'lastname'},$changeHash{'generation'},
1957: $changeHash{'id'},undef,$changeHash{'permanentemail'});
1.220 raeburn 1958: %userupdate = (
1959: lastname => $env{'form.clastname'},
1960: middlename => $env{'form.cmiddlename'},
1961: firstname => $env{'form.cfirstname'},
1962: generation => $env{'form.cgeneration'},
1963: id => $env{'form.cid'},
1964: );
1.204 raeburn 1965: }
1966: if (($namechanged && $namechgresult eq 'ok') ||
1967: ($quotachanged && $quotachgresult eq 'ok')) {
1.28 matthew 1968: # Tell the user we changed the name
1.73 sakharuk 1969: my %lt=&Apache::lonlocal::texthash(
1970: 'uic' => "User Information Changed",
1971: 'frst' => "first",
1972: 'mddl' => "middle",
1973: 'lst' => "last",
1974: 'gen' => "generation",
1.196 raeburn 1975: 'id' => "ID/Student number",
1.160 raeburn 1976: 'mail' => "permanent e-mail",
1.134 raeburn 1977: 'disk' => "disk space allocated to portfolio files",
1.73 sakharuk 1978: 'prvs' => "Previous",
1979: 'chto' => "Changed To"
1980: );
1.201 raeburn 1981: $r->print('<h4>'.$lt{'uic'}.'</h4>'.
1982: &Apache::loncommon::start_data_table().
1983: &Apache::loncommon::start_data_table_header_row());
1.28 matthew 1984: $r->print(<<"END");
1.201 raeburn 1985: <th> </th>
1.73 sakharuk 1986: <th>$lt{'frst'}</th>
1987: <th>$lt{'mddl'}</th>
1988: <th>$lt{'lst'}</th>
1.134 raeburn 1989: <th>$lt{'gen'}</th>
1.196 raeburn 1990: <th>$lt{'id'}</th>
1.173 raeburn 1991: <th>$lt{'mail'}</th>
1.201 raeburn 1992: END
1.220 raeburn 1993: if ($showquota) {
1994: $r->print("
1995: <th>$lt{'disk'}</th>\n");
1996: }
1.201 raeburn 1997: $r->print(&Apache::loncommon::end_data_table_header_row().
1998: &Apache::loncommon::start_data_table_row());
1999: $r->print(<<"END");
2000: <td><b>$lt{'prvs'}</b></td>
1.28 matthew 2001: <td>$userenv{'firstname'} </td>
2002: <td>$userenv{'middlename'} </td>
2003: <td>$userenv{'lastname'} </td>
1.134 raeburn 2004: <td>$userenv{'generation'} </td>
1.196 raeburn 2005: <td>$userenv{'id'}</td>
1.160 raeburn 2006: <td>$userenv{'permanentemail'} </td>
1.201 raeburn 2007: END
1.220 raeburn 2008: if ($showquota) {
2009: $r->print("
2010: <td>$oldportfolioquota Mb $olddefquotatext </td>\n");
2011: }
1.201 raeburn 2012: $r->print(&Apache::loncommon::end_data_table_row().
2013: &Apache::loncommon::start_data_table_row());
2014: $r->print(<<"END");
2015: <td><b>$lt{'chto'}</b></td>
1.101 albertel 2016: <td>$env{'form.cfirstname'} </td>
2017: <td>$env{'form.cmiddlename'} </td>
2018: <td>$env{'form.clastname'} </td>
1.134 raeburn 2019: <td>$env{'form.cgeneration'} </td>
1.196 raeburn 2020: <td>$env{'form.cid'} </td>
1.160 raeburn 2021: <td>$env{'form.cpermanentemail'} </td>
1.28 matthew 2022: END
1.220 raeburn 2023: if ($showquota) {
2024: $r->print("
2025: <td>$newportfolioquota Mb $newdefquotatext </td>\n");
2026: }
1.201 raeburn 2027: $r->print(&Apache::loncommon::end_data_table_row().
1.206 raeburn 2028: &Apache::loncommon::end_data_table().'<br />');
1.203 raeburn 2029: if ($env{'form.cid'} ne $userenv{'id'}) {
2030: &Apache::lonnet::idput($env{'form.ccdomain'},
2031: ($env{'form.ccuname'} => $env{'form.cid'}));
2032: if (($recurseid) &&
2033: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
2034: my $idresult =
2035: &Apache::lonuserutils::propagate_id_change(
2036: $env{'form.ccuname'},$env{'form.ccdomain'},
2037: \%userupdate);
2038: $r->print('<br />'.$idresult.'<br />');
2039: }
1.196 raeburn 2040: }
1.149 raeburn 2041: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
2042: ($env{'form.ccuname'} eq $env{'user.name'})) {
2043: my %newenvhash;
2044: foreach my $key (keys(%changeHash)) {
2045: $newenvhash{'environment.'.$key} = $changeHash{$key};
2046: }
1.238 raeburn 2047: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 2048: }
1.28 matthew 2049: } else { # error occurred
1.188 raeburn 2050: $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
2051: $env{'form.ccuname'}.' '.&mt('in domain').' '.
1.206 raeburn 2052: $env{'form.ccdomain'}.'</span><br />');
1.28 matthew 2053: }
1.101 albertel 2054: } else { # End of if ($env ... ) logic
1.204 raeburn 2055: # They did not want to change the users name or quota but we can
2056: # still tell them what the name and quota are
1.73 sakharuk 2057: my %lt=&Apache::lonlocal::texthash(
1.196 raeburn 2058: 'id' => "ID/Student number",
1.160 raeburn 2059: 'mail' => "Permanent e-mail",
1.134 raeburn 2060: 'disk' => "Disk space allocated to user's portfolio files",
1.73 sakharuk 2061: );
1.134 raeburn 2062: $r->print(<<"END");
1.196 raeburn 2063: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
1.28 matthew 2064: END
1.204 raeburn 2065: if ($userenv{'permanentemail'} ne '') {
2066: $r->print('<br />['.$lt{'mail'}.': '.
2067: $userenv{'permanentemail'}.']');
1.134 raeburn 2068: }
1.220 raeburn 2069: if ($showquota) {
2070: $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '.
2071: $olddefquotatext.']');
2072: }
2073: $r->print('</h4>');
1.28 matthew 2074: }
1.206 raeburn 2075: if (@mod_disallowed) {
2076: my ($rolestr,$contextname);
2077: if (@longroles > 0) {
2078: $rolestr = join(', ',@longroles);
2079: } else {
2080: $rolestr = &mt('No roles');
2081: }
2082: if ($context eq 'course') {
2083: $contextname = &mt('course');
2084: } elsif ($context eq 'author') {
2085: $contextname = &mt('co-author');
2086: }
2087: $r->print(&mt('The following fields were not updated: ').'<ul>');
2088: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2089: foreach my $field (@mod_disallowed) {
2090: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
2091: }
1.207 raeburn 2092: $r->print('</ul>');
2093: if (@mod_disallowed == 1) {
2094: $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));
2095: } else {
2096: $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));
2097: }
2098: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'.
2099: &mt('Contact your <a href="[_1]">helpdesk</a> for more information.',"javascript:helpMenu('display')").'<br />');
1.206 raeburn 2100: }
2101: $r->print($no_forceid_alert.
1.239 raeburn 2102: &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules));
1.4 www 2103: }
1.220 raeburn 2104: if ($env{'form.action'} eq 'singlestudent') {
1.239 raeburn 2105: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context);
2106: $r->print('<p><a href="javascript:backPage(document.userupdate)">'.
2107: &mt('Enroll Another Student').'</a></p>');
1.220 raeburn 2108: } else {
1.239 raeburn 2109: my @rolechanges = &update_roles($r,$context);
1.225 raeburn 2110: if ($namechanged) {
1.220 raeburn 2111: if ($context eq 'course') {
2112: if (@userroles > 0) {
1.225 raeburn 2113: if ((@rolechanges == 0) ||
2114: (!(grep(/^st$/,@rolechanges)))) {
2115: if (grep(/^st$/,@userroles)) {
2116: my $classlistupdated =
2117: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 2118: $cnum,$env{'form.ccdomain'},
2119: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 2120: }
1.220 raeburn 2121: }
2122: }
2123: }
2124: }
1.226 raeburn 2125: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 2126: $env{'form.ccdomain'});
2127: if ($env{'form.popup'}) {
2128: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
2129: } else {
1.246 bisitz 2130: $r->print('<p><a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
2131: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>'
2132: .(' 'x5).'<a href="javascript:backPage(document.userupdate)">'
2133: .&mt('Create/Modify Another User').'</a></p>');
1.233 raeburn 2134: }
1.220 raeburn 2135: }
2136: $r->print(&Apache::loncommon::end_page());
2137: }
2138:
2139: sub update_roles {
1.239 raeburn 2140: my ($r,$context) = @_;
1.4 www 2141: my $now=time;
1.225 raeburn 2142: my @rolechanges;
1.220 raeburn 2143: my %disallowed;
1.73 sakharuk 2144: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.135 raeburn 2145: foreach my $key (keys (%env)) {
2146: next if (! $env{$key});
1.190 raeburn 2147: next if ($key eq 'form.action');
1.27 matthew 2148: # Revoke roles
1.135 raeburn 2149: if ($key=~/^form\.rev/) {
2150: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 2151: # Revoke standard role
1.170 albertel 2152: my ($scope,$role) = ($1,$2);
2153: my $result =
2154: &Apache::lonnet::revokerole($env{'form.ccdomain'},
2155: $env{'form.ccuname'},
1.239 raeburn 2156: $scope,$role,'','',$context);
1.170 albertel 2157: $r->print(&mt('Revoking [_1] in [_2]: [_3]',
2158: $role,$scope,'<b>'.$result.'</b>').'<br />');
2159: if ($role eq 'st') {
1.202 raeburn 2160: my $result =
1.198 raeburn 2161: &Apache::lonuserutils::classlist_drop($scope,
2162: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 2163: $now);
1.170 albertel 2164: $r->print($result);
1.53 www 2165: }
1.225 raeburn 2166: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2167: push(@rolechanges,$role);
2168: }
1.196 raeburn 2169: }
1.195 raeburn 2170: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 2171: # Revoke custom role
1.113 raeburn 2172: $r->print(&mt('Revoking custom role:').
1.139 albertel 2173: ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
1.101 albertel 2174: &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
1.239 raeburn 2175: $env{'form.ccuname'},$1,$2,$3,$4,'','',$context).
1.102 albertel 2176: '</b><br />');
1.225 raeburn 2177: if (!grep(/^cr$/,@rolechanges)) {
2178: push(@rolechanges,'cr');
2179: }
1.64 www 2180: }
1.135 raeburn 2181: } elsif ($key=~/^form\.del/) {
2182: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 2183: # Delete standard role
1.170 albertel 2184: my ($scope,$role) = ($1,$2);
2185: my $result =
2186: &Apache::lonnet::assignrole($env{'form.ccdomain'},
2187: $env{'form.ccuname'},
1.239 raeburn 2188: $scope,$role,$now,0,1,'',
2189: $context);
1.170 albertel 2190: $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
2191: '<b>'.$result.'</b>').'<br />');
2192: if ($role eq 'st') {
1.202 raeburn 2193: my $result =
1.198 raeburn 2194: &Apache::lonuserutils::classlist_drop($scope,
2195: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 2196: $now);
1.170 albertel 2197: $r->print($result);
1.81 albertel 2198: }
1.225 raeburn 2199: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2200: push(@rolechanges,$role);
2201: }
1.116 raeburn 2202: }
1.139 albertel 2203: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 2204: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
2205: # Delete custom role
1.170 albertel 2206: $r->print(&mt('Deleting custom role [_1] by [_2]:[_3] in [_4]',
1.116 raeburn 2207: $rolename,$rnam,$rdom,$url).': <b>'.
2208: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
2209: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
1.240 raeburn 2210: 0,1,$context).'</b><br />');
1.225 raeburn 2211: if (!grep(/^cr$/,@rolechanges)) {
2212: push(@rolechanges,'cr');
2213: }
1.116 raeburn 2214: }
1.135 raeburn 2215: } elsif ($key=~/^form\.ren/) {
1.101 albertel 2216: my $udom = $env{'form.ccdomain'};
2217: my $uname = $env{'form.ccuname'};
1.116 raeburn 2218: # Re-enable standard role
1.135 raeburn 2219: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 2220: my $url = $1;
2221: my $role = $2;
2222: my $logmsg;
2223: my $output;
2224: if ($role eq 'st') {
1.141 albertel 2225: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.129 albertel 2226: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
1.220 raeburn 2227: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 2228: if ($result eq 'refused' && $logmsg) {
2229: $output = $logmsg;
2230: } else {
2231: $output = "Error: $result\n";
2232: }
1.89 raeburn 2233: } else {
2234: $output = &mt('Assigning').' '.$role.' in '.$url.
2235: &mt('starting').' '.localtime($now).
2236: ': <br />'.$logmsg.'<br />'.
2237: &mt('Add to classlist').': <b>ok</b><br />';
2238: }
2239: }
2240: } else {
1.101 albertel 2241: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 2242: $env{'form.ccuname'},$url,$role,0,$now,'','',
2243: $context);
1.116 raeburn 2244: $output = &mt('Re-enabling [_1] in [_2]: <b>[_3]</b>',
1.89 raeburn 2245: $role,$url,$result).'<br />';
1.27 matthew 2246: }
1.89 raeburn 2247: $r->print($output);
1.225 raeburn 2248: if (!grep(/^\Q$role\E$/,@rolechanges)) {
2249: push(@rolechanges,$role);
2250: }
1.113 raeburn 2251: }
1.116 raeburn 2252: # Re-enable custom role
1.139 albertel 2253: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 2254: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
2255: my $result = &Apache::lonnet::assigncustomrole(
2256: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 2257: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.116 raeburn 2258: $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : <b>[_5]</b>',
2259: $rolename,$rnam,$rdom,$url,$result).'<br />');
1.225 raeburn 2260: if (!grep(/^cr$/,@rolechanges)) {
2261: push(@rolechanges,'cr');
2262: }
1.116 raeburn 2263: }
1.135 raeburn 2264: } elsif ($key=~/^form\.act/) {
1.101 albertel 2265: my $udom = $env{'form.ccdomain'};
2266: my $uname = $env{'form.ccuname'};
1.141 albertel 2267: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 2268: # Activate a custom role
1.83 albertel 2269: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
2270: my $url='/'.$one.'/'.$two;
2271: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 2272:
1.101 albertel 2273: my $start = ( $env{'form.start_'.$full} ?
2274: $env{'form.start_'.$full} :
1.88 raeburn 2275: $now );
1.101 albertel 2276: my $end = ( $env{'form.end_'.$full} ?
2277: $env{'form.end_'.$full} :
1.88 raeburn 2278: 0 );
2279:
2280: # split multiple sections
2281: my %sections = ();
1.101 albertel 2282: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 2283: if ($num_sections == 0) {
1.240 raeburn 2284: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 2285: } else {
1.114 albertel 2286: my %curr_groups =
1.117 raeburn 2287: &Apache::longroup::coursegroups($one,$two);
1.113 raeburn 2288: foreach my $sec (sort {$a cmp $b} keys %sections) {
2289: if (($sec eq 'none') || ($sec eq 'all') ||
2290: exists($curr_groups{$sec})) {
2291: $disallowed{$sec} = $url;
2292: next;
2293: }
2294: my $securl = $url.'/'.$sec;
1.240 raeburn 2295: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 2296: }
2297: }
1.225 raeburn 2298: if (!grep(/^cr$/,@rolechanges)) {
2299: push(@rolechanges,'cr');
2300: }
1.142 raeburn 2301: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 2302: # Activate roles for sections with 3 id numbers
2303: # set start, end times, and the url for the class
1.83 albertel 2304: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 2305: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
2306: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 2307: $now );
1.101 albertel 2308: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
2309: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 2310: 0 );
1.83 albertel 2311: my $url='/'.$one.'/'.$two;
1.88 raeburn 2312: my $type = 'three';
2313: # split multiple sections
2314: my %sections = ();
1.101 albertel 2315: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.88 raeburn 2316: if ($num_sections == 0) {
1.240 raeburn 2317: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 2318: } else {
1.114 albertel 2319: my %curr_groups =
1.117 raeburn 2320: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 2321: my $emptysec = 0;
2322: foreach my $sec (sort {$a cmp $b} keys %sections) {
2323: $sec =~ s/\W//g;
1.113 raeburn 2324: if ($sec ne '') {
2325: if (($sec eq 'none') || ($sec eq 'all') ||
2326: exists($curr_groups{$sec})) {
2327: $disallowed{$sec} = $url;
2328: next;
2329: }
1.88 raeburn 2330: my $securl = $url.'/'.$sec;
1.240 raeburn 2331: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context));
1.88 raeburn 2332: } else {
2333: $emptysec = 1;
2334: }
2335: }
2336: if ($emptysec) {
1.240 raeburn 2337: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
1.88 raeburn 2338: }
1.225 raeburn 2339: }
2340: if (!grep(/^\Q$three\E$/,@rolechanges)) {
2341: push(@rolechanges,$three);
2342: }
1.135 raeburn 2343: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 2344: # Activate roles for sections with two id numbers
2345: # set start, end times, and the url for the class
1.101 albertel 2346: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
2347: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 2348: $now );
1.101 albertel 2349: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
2350: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 2351: 0 );
1.225 raeburn 2352: my $one = $1;
2353: my $two = $2;
2354: my $url='/'.$one.'/';
1.88 raeburn 2355: # split multiple sections
2356: my %sections = ();
1.225 raeburn 2357: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 2358: if ($num_sections == 0) {
1.240 raeburn 2359: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 2360: } else {
2361: my $emptysec = 0;
2362: foreach my $sec (sort {$a cmp $b} keys %sections) {
2363: if ($sec ne '') {
2364: my $securl = $url.'/'.$sec;
1.240 raeburn 2365: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 2366: } else {
2367: $emptysec = 1;
2368: }
2369: }
2370: if ($emptysec) {
1.240 raeburn 2371: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 2372: }
2373: }
1.225 raeburn 2374: if (!grep(/^\Q$two\E$/,@rolechanges)) {
2375: push(@rolechanges,$two);
2376: }
1.64 www 2377: } else {
1.190 raeburn 2378: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 2379: }
1.113 raeburn 2380: foreach my $key (sort(keys(%disallowed))) {
2381: if (($key eq 'none') || ($key eq 'all')) {
2382: $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
2383: } else {
2384: $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));
2385: }
2386: $r->print(' '.&mt('Please <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />');
2387: }
2388: }
1.101 albertel 2389: } # End of foreach (keys(%env))
1.75 www 2390: # Flush the course logs so reverse user roles immediately updated
2391: &Apache::lonnet::flushcourselogs();
1.225 raeburn 2392: if (@rolechanges == 0) {
1.193 raeburn 2393: $r->print(&mt('No roles to modify'));
2394: }
1.225 raeburn 2395: return @rolechanges;
1.220 raeburn 2396: }
2397:
2398: sub enroll_single_student {
1.239 raeburn 2399: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context) = @_;
1.220 raeburn 2400: $r->print('<h3>'.&mt('Enrolling Student').'</h3>');
2401:
2402: # Remove non alphanumeric values from section
2403: $env{'form.sections'}=~s/\W//g;
2404:
2405: # Clean out any old student roles the user has in this class.
2406: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
2407: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
2408: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
2409: my $enroll_result =
2410: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
2411: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
2412: $env{'form.cmiddlename'},$env{'form.clastname'},
2413: $env{'form.generation'},$env{'form.sections'},$enddate,
1.239 raeburn 2414: $startdate,'manual',undef,$env{'request.course.id'},'',$context);
1.220 raeburn 2415: if ($enroll_result =~ /^ok/) {
2416: $r->print(&mt('<b>[_1]</b> enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'}));
2417: if ($env{'form.sections'} ne '') {
2418: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
2419: }
2420: my ($showstart,$showend);
2421: if ($startdate <= $now) {
2422: $showstart = &mt('Access starts immediately');
2423: } else {
2424: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
2425: }
2426: if ($enddate == 0) {
2427: $showend = &mt('ends: no ending date');
2428: } else {
2429: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
2430: }
2431: $r->print('.<br />'.$showstart.'; '.$showend);
2432: if ($startdate <= $now && !$newuser) {
2433: $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>");
2434: }
2435: } else {
2436: $r->print(&mt('unable to enroll').": ".$enroll_result);
2437: }
2438: return;
1.188 raeburn 2439: }
2440:
1.204 raeburn 2441: sub get_defaultquota_text {
2442: my ($settingstatus) = @_;
2443: my $defquotatext;
2444: if ($settingstatus eq '') {
2445: $defquotatext = &mt('(default)');
2446: } else {
2447: my ($usertypes,$order) =
2448: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
2449: if ($usertypes->{$settingstatus} eq '') {
2450: $defquotatext = &mt('(default)');
2451: } else {
2452: $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
2453: }
2454: }
2455: return $defquotatext;
2456: }
2457:
1.188 raeburn 2458: sub update_result_form {
2459: my ($uhome) = @_;
2460: my $outcome =
2461: '<form name="userupdate" method="post" />'."\n";
1.160 raeburn 2462: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 2463: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2464: }
1.207 raeburn 2465: if ($env{'form.origname'} ne '') {
2466: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
2467: }
1.160 raeburn 2468: foreach my $item ('sortby','seluname','seludom') {
2469: if (exists($env{'form.'.$item})) {
1.188 raeburn 2470: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 2471: }
2472: }
1.188 raeburn 2473: if ($uhome eq 'no_host') {
2474: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
2475: }
2476: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
2477: '<input type ="hidden" name="currstate" value="" />'."\n".
1.220 raeburn 2478: '<input type ="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 2479: '</form>';
2480: return $outcome;
1.4 www 2481: }
2482:
1.149 raeburn 2483: sub quota_admin {
2484: my ($setquota,$changeHash) = @_;
2485: my $quotachanged;
2486: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
2487: # Current user has quota modification privileges
2488: $quotachanged = 1;
2489: $changeHash->{'portfolioquota'} = $setquota;
2490: }
2491: return $quotachanged;
2492: }
2493:
1.88 raeburn 2494: sub build_roles {
1.89 raeburn 2495: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 2496: my $num_sections = 0;
2497: if ($sectionstr=~ /,/) {
2498: my @secnums = split/,/,$sectionstr;
1.89 raeburn 2499: if ($role eq 'st') {
2500: $secnums[0] =~ s/\W//g;
2501: $$sections{$secnums[0]} = 1;
2502: $num_sections = 1;
2503: } else {
2504: foreach my $sec (@secnums) {
2505: $sec =~ ~s/\W//g;
1.150 banghart 2506: if (!($sec eq "")) {
1.89 raeburn 2507: if (exists($$sections{$sec})) {
2508: $$sections{$sec} ++;
2509: } else {
2510: $$sections{$sec} = 1;
2511: $num_sections ++;
2512: }
1.88 raeburn 2513: }
2514: }
2515: }
2516: } else {
2517: $sectionstr=~s/\W//g;
2518: unless ($sectionstr eq '') {
2519: $$sections{$sectionstr} = 1;
2520: $num_sections ++;
2521: }
2522: }
1.129 albertel 2523:
1.88 raeburn 2524: return $num_sections;
2525: }
2526:
1.58 www 2527: # ========================================================== Custom Role Editor
2528:
2529: sub custom_role_editor {
1.160 raeburn 2530: my ($r) = @_;
1.101 albertel 2531: my $rolename=$env{'form.rolename'};
1.58 www 2532:
1.59 www 2533: if ($rolename eq 'make new role') {
1.101 albertel 2534: $rolename=$env{'form.newrolename'};
1.59 www 2535: }
2536:
1.63 www 2537: $rolename=~s/[^A-Za-z0-9]//gs;
1.58 www 2538:
1.190 raeburn 2539: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.58 www 2540: &print_username_entry_form($r);
2541: return;
2542: }
1.153 banghart 2543: # ------------------------------------------------------- What can be assigned?
2544: my %full=();
2545: my %courselevel=();
2546: my %courselevelcurrent=();
1.61 www 2547: my $syspriv='';
2548: my $dompriv='';
2549: my $coursepriv='';
1.153 banghart 2550: my $body_top;
1.150 banghart 2551: my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
1.59 www 2552: my ($rdummy,$roledef)=
2553: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
1.60 www 2554: # ------------------------------------------------------- Does this role exist?
1.153 banghart 2555: $body_top .= '<h2>';
1.59 www 2556: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.153 banghart 2557: $body_top .= &mt('Existing Role').' "';
1.61 www 2558: # ------------------------------------------------- Get current role privileges
2559: ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
1.59 www 2560: } else {
1.153 banghart 2561: $body_top .= &mt('New Role').' "';
1.59 www 2562: $roledef='';
2563: }
1.153 banghart 2564: $body_top .= $rolename.'"</h2>';
1.135 raeburn 2565: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2566: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2567: if (!$restrict) { $restrict='F'; }
1.60 www 2568: $courselevel{$priv}=$restrict;
1.61 www 2569: if ($coursepriv=~/\:$priv/) {
2570: $courselevelcurrent{$priv}=1;
2571: }
1.60 www 2572: $full{$priv}=1;
2573: }
2574: my %domainlevel=();
1.61 www 2575: my %domainlevelcurrent=();
1.135 raeburn 2576: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2577: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2578: if (!$restrict) { $restrict='F'; }
1.60 www 2579: $domainlevel{$priv}=$restrict;
1.61 www 2580: if ($dompriv=~/\:$priv/) {
2581: $domainlevelcurrent{$priv}=1;
2582: }
1.60 www 2583: $full{$priv}=1;
2584: }
1.61 www 2585: my %systemlevel=();
2586: my %systemlevelcurrent=();
1.135 raeburn 2587: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2588: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2589: if (!$restrict) { $restrict='F'; }
1.61 www 2590: $systemlevel{$priv}=$restrict;
2591: if ($syspriv=~/\:$priv/) {
2592: $systemlevelcurrent{$priv}=1;
2593: }
2594: $full{$priv}=1;
2595: }
1.160 raeburn 2596: my ($jsback,$elements) = &crumb_utilities();
1.154 banghart 2597: my $button_code = "\n";
1.153 banghart 2598: my $head_script = "\n";
2599: $head_script .= '<script type="text/javascript">'."\n";
1.154 banghart 2600: my @template_roles = ("cc","in","ta","ep","st");
2601: foreach my $role (@template_roles) {
2602: $head_script .= &make_script_template($role);
2603: $button_code .= &make_button_code($role);
2604: }
1.160 raeburn 2605: $head_script .= "\n".$jsback."\n".'</script>'."\n";
1.153 banghart 2606: $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
1.160 raeburn 2607: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 2608: ({href=>"javascript:backPage(document.form1,'pickrole','')",
2609: text=>"Pick custom role",
1.160 raeburn 2610: faq=>282,bug=>'Instructor Interface',},
2611: {href=>"javascript:backPage(document.form1,'','')",
2612: text=>"Edit custom role",
2613: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 2614: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
2615: 'Course_Editing_Custom_Roles'));
1.160 raeburn 2616:
1.153 banghart 2617: $r->print($body_top);
1.73 sakharuk 2618: my %lt=&Apache::lonlocal::texthash(
2619: 'prv' => "Privilege",
1.131 raeburn 2620: 'crl' => "Course Level",
1.73 sakharuk 2621: 'dml' => "Domain Level",
1.150 banghart 2622: 'ssl' => "System Level");
1.236 bisitz 2623: $r->print(&mt('Select a Template').'<br />');
1.154 banghart 2624: $r->print('<form action="">');
2625: $r->print($button_code);
2626: $r->print('</form>');
1.61 www 2627: $r->print(<<ENDCCF);
1.160 raeburn 2628: <form name="form1" method="post">
1.61 www 2629: <input type="hidden" name="phase" value="set_custom_roles" />
2630: <input type="hidden" name="rolename" value="$rolename" />
2631: ENDCCF
1.135 raeburn 2632: $r->print(&Apache::loncommon::start_data_table().
2633: &Apache::loncommon::start_data_table_header_row().
2634: '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
2635: '</th><th>'.$lt{'ssl'}.'</th>'.
2636: &Apache::loncommon::end_data_table_header_row());
1.119 raeburn 2637: foreach my $priv (sort keys %full) {
2638: my $privtext = &Apache::lonnet::plaintext($priv);
1.135 raeburn 2639: $r->print(&Apache::loncommon::start_data_table_row().
2640: '<td>'.$privtext.'</td><td>'.
1.150 banghart 2641: ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c" '.
1.119 raeburn 2642: ($courselevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2643: '</td><td>'.
1.150 banghart 2644: ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d" '.
1.119 raeburn 2645: ($domainlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.61 www 2646: '</td><td>'.
1.150 banghart 2647: ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s" '.
1.119 raeburn 2648: ($systemlevelcurrent{$priv}?'checked="1"':'').' />':' ').
1.135 raeburn 2649: '</td>'.
2650: &Apache::loncommon::end_data_table_row());
1.60 www 2651: }
1.135 raeburn 2652: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 2653: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 2654: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 2655: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 2656: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
2657: '<input type="submit" value="'.&mt('Define Role').'" /></form>'.
1.110 albertel 2658: &Apache::loncommon::end_page());
1.61 www 2659: }
1.153 banghart 2660: # --------------------------------------------------------
2661: sub make_script_template {
2662: my ($role) = @_;
2663: my %full_c=();
2664: my %full_d=();
2665: my %full_s=();
2666: my $return_script;
2667: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2668: my ($priv,$restrict)=split(/\&/,$item);
2669: $full_c{$priv}=1;
2670: }
2671: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2672: my ($priv,$restrict)=split(/\&/,$item);
2673: $full_d{$priv}=1;
2674: }
1.154 banghart 2675: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
1.153 banghart 2676: my ($priv,$restrict)=split(/\&/,$item);
2677: $full_s{$priv}=1;
2678: }
2679: $return_script .= 'function set_'.$role.'() {'."\n";
2680: my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
2681: my %role_c;
1.155 banghart 2682: foreach my $priv (@temp) {
1.153 banghart 2683: my ($priv_item, $dummy) = split(/\&/,$priv);
2684: $role_c{$priv_item} = 1;
2685: }
2686: foreach my $priv_item (keys(%full_c)) {
2687: my ($priv, $dummy) = split(/\&/,$priv_item);
2688: if (exists($role_c{$priv})) {
2689: $return_script .= "document.form1.$priv"."_c.checked = true;\n";
2690: } else {
2691: $return_script .= "document.form1.$priv"."_c.checked = false;\n";
2692: }
2693: }
1.154 banghart 2694: my %role_d;
2695: @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
2696: foreach my $priv(@temp) {
2697: my ($priv_item, $dummy) = split(/\&/,$priv);
2698: $role_d{$priv_item} = 1;
2699: }
2700: foreach my $priv_item (keys(%full_d)) {
2701: my ($priv, $dummy) = split(/\&/,$priv_item);
2702: if (exists($role_d{$priv})) {
2703: $return_script .= "document.form1.$priv"."_d.checked = true;\n";
2704: } else {
2705: $return_script .= "document.form1.$priv"."_d.checked = false;\n";
2706: }
2707: }
2708: my %role_s;
2709: @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
2710: foreach my $priv(@temp) {
2711: my ($priv_item, $dummy) = split(/\&/,$priv);
2712: $role_s{$priv_item} = 1;
2713: }
2714: foreach my $priv_item (keys(%full_s)) {
1.153 banghart 2715: my ($priv, $dummy) = split(/\&/,$priv_item);
1.154 banghart 2716: if (exists($role_s{$priv})) {
2717: $return_script .= "document.form1.$priv"."_s.checked = true;\n";
2718: } else {
2719: $return_script .= "document.form1.$priv"."_s.checked = false;\n";
2720: }
1.153 banghart 2721: }
2722: $return_script .= '}'."\n";
1.154 banghart 2723: return ($return_script);
2724: }
2725: # ----------------------------------------------------------
2726: sub make_button_code {
2727: my ($role) = @_;
2728: my $label = &Apache::lonnet::plaintext($role);
2729: my $button_code = '<input type="button" onClick="set_'.$role.'()" value="'.$label.'" />';
2730: return ($button_code);
1.153 banghart 2731: }
1.61 www 2732: # ---------------------------------------------------------- Call to definerole
2733: sub set_custom_role {
1.240 raeburn 2734: my ($r,$context) = @_;
1.101 albertel 2735: my $rolename=$env{'form.rolename'};
1.63 www 2736: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 2737: if (!$rolename) {
1.190 raeburn 2738: &custom_role_editor($r);
1.61 www 2739: return;
2740: }
1.160 raeburn 2741: my ($jsback,$elements) = &crumb_utilities();
2742: my $jscript = '<script type="text/javascript">'.$jsback."\n".'</script>';
2743:
2744: $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
2745: &Apache::lonhtmlcommon::add_breadcrumb
1.190 raeburn 2746: ({href=>"javascript:backPage(document.customresult,'pickrole','')",
2747: text=>"Pick custom role",
1.160 raeburn 2748: faq=>282,bug=>'Instructor Interface',},
2749: {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
2750: text=>"Edit custom role",
2751: faq=>282,bug=>'Instructor Interface',},
2752: {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
2753: text=>"Result",
2754: faq=>282,bug=>'Instructor Interface',});
1.224 raeburn 2755: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
2756: 'Course_Editing_Custom_Roles'));
1.160 raeburn 2757:
1.61 www 2758: my ($rdummy,$roledef)=
1.110 albertel 2759: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
2760:
1.61 www 2761: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 2762: $r->print('<h3>');
1.61 www 2763: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 2764: $r->print(&mt('Existing Role').' "');
1.61 www 2765: } else {
1.73 sakharuk 2766: $r->print(&mt('New Role').' "');
1.61 www 2767: $roledef='';
2768: }
1.188 raeburn 2769: $r->print($rolename.'"</h3>');
1.61 www 2770: # ------------------------------------------------------- What can be assigned?
2771: my $sysrole='';
2772: my $domrole='';
2773: my $courole='';
2774:
1.135 raeburn 2775: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
2776: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2777: if (!$restrict) { $restrict=''; }
2778: if ($env{'form.'.$priv.'_c'}) {
1.135 raeburn 2779: $courole.=':'.$item;
1.61 www 2780: }
2781: }
2782:
1.135 raeburn 2783: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
2784: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2785: if (!$restrict) { $restrict=''; }
2786: if ($env{'form.'.$priv.'_d'}) {
1.135 raeburn 2787: $domrole.=':'.$item;
1.61 www 2788: }
2789: }
2790:
1.135 raeburn 2791: foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
2792: my ($priv,$restrict)=split(/\&/,$item);
1.150 banghart 2793: if (!$restrict) { $restrict=''; }
2794: if ($env{'form.'.$priv.'_s'}) {
1.135 raeburn 2795: $sysrole.=':'.$item;
1.61 www 2796: }
2797: }
1.63 www 2798: $r->print('<br />Defining Role: '.
1.61 www 2799: &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
1.101 albertel 2800: if ($env{'request.course.id'}) {
2801: my $url='/'.$env{'request.course.id'};
1.63 www 2802: $url=~s/\_/\//g;
1.73 sakharuk 2803: $r->print('<br />'.&mt('Assigning Role to Self').': '.
1.101 albertel 2804: &Apache::lonnet::assigncustomrole($env{'user.domain'},
2805: $env{'user.name'},
1.63 www 2806: $url,
1.101 albertel 2807: $env{'user.domain'},
2808: $env{'user.name'},
1.240 raeburn 2809: $rolename,undef,undef,undef,$context));
1.63 www 2810: }
1.190 raeburn 2811: $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 2812: $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>');
1.110 albertel 2813: $r->print(&Apache::loncommon::end_page());
1.58 www 2814: }
2815:
1.2 www 2816: # ================================================================ Main Handler
2817: sub handler {
2818: my $r = shift;
2819: if ($r->header_only) {
1.68 www 2820: &Apache::loncommon::content_type($r,'text/html');
1.2 www 2821: $r->send_http_header;
2822: return OK;
2823: }
1.190 raeburn 2824: my $context;
2825: if ($env{'request.course.id'}) {
2826: $context = 'course';
2827: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 2828: $context = 'author';
1.190 raeburn 2829: } else {
2830: $context = 'domain';
2831: }
2832: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 2833: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
2834: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
1.190 raeburn 2835: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.202 raeburn 2836: if ($env{'form.action'} ne 'dateselect') {
2837: &Apache::lonhtmlcommon::add_breadcrumb
2838: ({href=>"/adm/createuser",
2839: text=>"User Management"});
2840: }
1.209 raeburn 2841: my ($permission,$allowed) =
2842: &Apache::lonuserutils::get_permission($context);
1.190 raeburn 2843: if (!$allowed) {
2844: $env{'user.error.msg'}=
2845: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
2846: "or view user status.";
2847: return HTTP_NOT_ACCEPTABLE;
2848: }
2849:
2850: &Apache::loncommon::content_type($r,'text/html');
2851: $r->send_http_header;
2852:
2853: # Main switch on form.action and form.state, as appropriate
2854: if (! exists($env{'form.action'})) {
2855: $r->print(&header());
2856: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.208 raeburn 2857: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 2858: $r->print(&Apache::loncommon::end_page());
2859: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
2860: $r->print(&header());
2861: &Apache::lonhtmlcommon::add_breadcrumb
2862: ({href=>'/adm/createuser?action=upload&state=',
2863: text=>"Upload Users List"});
2864: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Upload Users List',
1.224 raeburn 2865: 'Course_Create_Class_List'));
1.190 raeburn 2866: $r->print('<form name="studentform" method="post" '.
2867: 'enctype="multipart/form-data" '.
2868: ' action="/adm/createuser">'."\n");
2869: if (! exists($env{'form.state'})) {
2870: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
2871: } elsif ($env{'form.state'} eq 'got_file') {
1.221 raeburn 2872: &Apache::lonuserutils::print_upload_manager_form($r,$context,
2873: $permission);
1.190 raeburn 2874: } elsif ($env{'form.state'} eq 'enrolling') {
2875: if ($env{'form.datatoken'}) {
1.221 raeburn 2876: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission);
1.190 raeburn 2877: }
2878: } else {
2879: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
2880: }
2881: $r->print('</form>'.&Apache::loncommon::end_page());
1.213 raeburn 2882: } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
2883: eq 'singlestudent')) && ($permission->{'cusr'})) {
1.190 raeburn 2884: my $phase = $env{'form.phase'};
2885: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 2886: &Apache::loncreateuser::restore_prev_selections();
2887: my $srch;
2888: foreach my $item (@search) {
2889: $srch->{$item} = $env{'form.'.$item};
2890: }
1.207 raeburn 2891: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
2892: ($phase eq 'createnewuser')) {
2893: if ($env{'form.phase'} eq 'createnewuser') {
2894: my $response;
2895: if ($env{'form.srchterm'} !~ /^$match_username$/) {
2896: my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
1.221 raeburn 2897: $env{'form.phase'} = '';
1.207 raeburn 2898: &print_username_entry_form($r,$context,$response,$srch);
2899: } else {
2900: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
2901: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
2902: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 2903: $srch,$response,$context,
2904: $permission);
1.207 raeburn 2905: }
2906: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 2907: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 2908: &user_search_result($context,$srch);
1.190 raeburn 2909: if ($env{'form.currstate'} eq 'modify') {
2910: $currstate = $env{'form.currstate'};
2911: }
2912: if ($currstate eq 'select') {
2913: &print_user_selection_page($r,$response,$srch,$results,
1.229 raeburn 2914: \@search,$context);
1.190 raeburn 2915: } elsif ($currstate eq 'modify') {
2916: my ($ccuname,$ccdomain);
2917: if (($srch->{'srchby'} eq 'uname') &&
2918: ($srch->{'srchtype'} eq 'exact')) {
2919: $ccuname = $srch->{'srchterm'};
2920: $ccdomain= $srch->{'srchdomain'};
2921: } else {
2922: my @matchedunames = keys(%{$results});
2923: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
2924: }
2925: $ccuname =&LONCAPA::clean_username($ccuname);
2926: $ccdomain=&LONCAPA::clean_domain($ccdomain);
2927: if ($env{'form.forcenewuser'}) {
2928: $response = '';
2929: }
2930: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 2931: $srch,$response,$context,
2932: $permission);
1.190 raeburn 2933: } elsif ($currstate eq 'query') {
2934: &print_user_query_page($r,'createuser');
2935: } else {
1.229 raeburn 2936: $env{'form.phase'} = '';
1.207 raeburn 2937: &print_username_entry_form($r,$context,$response,$srch,
1.190 raeburn 2938: $forcenewuser);
2939: }
2940: } elsif ($env{'form.phase'} eq 'userpicked') {
2941: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
2942: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.196 raeburn 2943: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
1.221 raeburn 2944: $context,$permission);
1.190 raeburn 2945: }
2946: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.206 raeburn 2947: &update_user_data($r,$context);
1.190 raeburn 2948: } else {
1.207 raeburn 2949: &print_username_entry_form($r,$context,undef,$srch);
1.190 raeburn 2950: }
2951: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
2952: if ($env{'form.phase'} eq 'set_custom_roles') {
1.240 raeburn 2953: &set_custom_role($r,$context);
1.190 raeburn 2954: } else {
2955: &custom_role_editor($r);
2956: }
1.207 raeburn 2957: } elsif (($env{'form.action'} eq 'listusers') &&
2958: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 2959: if ($env{'form.phase'} eq 'bulkchange') {
2960: &Apache::lonhtmlcommon::add_breadcrumb
1.221 raeburn 2961: ({href=>'/adm/createuser?action=listusers',
2962: text=>"List Users"},
2963: {href=>"/adm/createuser",
2964: text=>"Result"});
1.202 raeburn 2965: my $setting = $env{'form.roletype'};
2966: my $choice = $env{'form.bulkaction'};
2967: $r->print(&header());
1.221 raeburn 2968: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Update Users",
1.224 raeburn 2969: 'Course_View_Class_List'));
1.202 raeburn 2970: if ($permission->{'cusr'}) {
2971: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
1.221 raeburn 2972: $r->print(&Apache::loncommon::end_page());
2973: } else {
2974: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 2975: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.221 raeburn 2976: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 2977: }
2978: } else {
2979: &Apache::lonhtmlcommon::add_breadcrumb
2980: ({href=>'/adm/createuser?action=listusers',
2981: text=>"List Users"});
2982: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
2983: my $formname = 'studentform';
2984: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
2985: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
2986: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
2987: $formname);
2988: $jscript .= &verify_user_display();
2989: my $js = &add_script($jscript).$cb_jscript;
2990: my $loadcode =
2991: &Apache::lonuserutils::course_selector_loadcode($formname);
2992: if ($loadcode ne '') {
2993: $r->print(&header($js,{'onload' => $loadcode,}));
2994: } else {
2995: $r->print(&header($js));
2996: }
1.191 raeburn 2997: } else {
1.202 raeburn 2998: $r->print(&header(&add_script(&verify_user_display())));
1.191 raeburn 2999: }
1.202 raeburn 3000: $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
1.224 raeburn 3001: 'Course_View_Class_List'));
1.202 raeburn 3002: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
3003: $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
3004: $r->print(&Apache::loncommon::end_page());
1.191 raeburn 3005: }
1.213 raeburn 3006: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
3007: $r->print(&header());
3008: &Apache::lonhtmlcommon::add_breadcrumb
3009: ({href=>'/adm/createuser?action=drop',
3010: text=>"Drop Students"});
3011: if (!exists($env{'form.state'})) {
3012: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
3013: 'Course_Drop_Student'));
3014:
3015: &Apache::lonuserutils::print_drop_menu($r,$context,$permission);
3016: } elsif ($env{'form.state'} eq 'done') {
3017: &Apache::lonhtmlcommon::add_breadcrumb
3018: ({href=>'/adm/createuser?action=drop',
3019: text=>"Result"});
3020: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
3021: 'Course_Drop_Student'));
3022: &Apache::lonuserutils::update_user_list($r,$context,undef,
3023: $env{'form.action'});
3024: }
3025: $r->print(&Apache::loncommon::end_page());
1.202 raeburn 3026: } elsif ($env{'form.action'} eq 'dateselect') {
3027: if ($permission->{'cusr'}) {
3028: $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
1.221 raeburn 3029: &Apache::lonuserutils::date_section_selector($context,
3030: $permission).
1.202 raeburn 3031: &Apache::loncommon::end_page());
3032: } else {
3033: $r->print(&header().
3034: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'.
3035: &Apache::loncommon::end_page());
3036: }
1.237 raeburn 3037: } elsif ($env{'form.action'} eq 'selfenroll') {
3038: $r->print(&header());
3039: &Apache::lonhtmlcommon::add_breadcrumb
3040: ({href=>'/adm/createuser?action=selfenroll',
3041: text=>"Configure Self-enrollment"});
3042: if (!exists($env{'form.state'})) {
3043: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Configure Self-enrollment',
3044: 'Course_Self_Enrollment'));
1.241 raeburn 3045: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.237 raeburn 3046: &print_selfenroll_menu($r,$context,$permission);
3047: } elsif ($env{'form.state'} eq 'done') {
3048: &Apache::lonhtmlcommon::add_breadcrumb
3049: ({href=>'/adm/createuser?action=selfenroll',
3050: text=>"Result"});
3051: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enrollment result',
3052: 'Course_Self_Enrollment'));
1.241 raeburn 3053: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
3054: &update_selfenroll_config($r,$context,$permission);
1.237 raeburn 3055: }
3056: $r->print(&Apache::loncommon::end_page());
1.239 raeburn 3057: } elsif ($env{'form.action'} eq 'changelogs') {
3058: $r->print(&header());
3059: &Apache::lonhtmlcommon::add_breadcrumb
3060: ({href=>'/adm/createuser?action=changelogs',
3061: text=>"User Management Logs"});
3062: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Changes',
3063: 'Course_User_Logs'));
3064: &print_userchangelogs_display($r,$context,$permission);
3065: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 3066: } else {
3067: $r->print(&header());
1.202 raeburn 3068: $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
1.207 raeburn 3069: $r->print(&print_main_menu($permission,$context));
1.190 raeburn 3070: $r->print(&Apache::loncommon::end_page());
3071: }
3072: return OK;
3073: }
3074:
3075: sub header {
1.202 raeburn 3076: my ($jscript,$loaditems,$args) = @_;
1.190 raeburn 3077: my $start_page;
3078: if (ref($loaditems) eq 'HASH') {
1.202 raeburn 3079: $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
1.190 raeburn 3080: } else {
1.202 raeburn 3081: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 3082: }
3083: return $start_page;
3084: }
1.2 www 3085:
1.191 raeburn 3086: sub add_script {
3087: my ($js) = @_;
3088: return '<script type="text/javascript">'."\n".$js."\n".'</script>';
3089: }
3090:
1.202 raeburn 3091: sub verify_user_display {
3092: my $output = <<"END";
3093:
3094: function display_update() {
3095: document.studentform.action.value = 'listusers';
3096: document.studentform.phase.value = 'display';
3097: document.studentform.submit();
3098: }
3099:
3100: END
3101: return $output;
3102:
3103: }
3104:
1.190 raeburn 3105: ###############################################################
3106: ###############################################################
3107: # Menu Phase One
3108: sub print_main_menu {
1.208 raeburn 3109: my ($permission,$context) = @_;
3110: my %links = (
3111: domain => {
3112: upload => 'Upload a File of Users',
1.221 raeburn 3113: singleuser => 'Add/Modify a Single User',
1.208 raeburn 3114: listusers => 'Manage Multiple Users',
3115: },
3116: author => {
3117: upload => 'Upload a File of Co-authors',
1.221 raeburn 3118: singleuser => 'Add/Modify a Single Co-author',
1.208 raeburn 3119: listusers => 'Display Co-authors and Manage Multiple Users',
3120: },
3121: course => {
3122: upload => 'Upload a File of Course Users',
1.221 raeburn 3123: singleuser => 'Add/Modify a Single Course User',
1.208 raeburn 3124: listusers => 'Display Class Lists and Manage Multiple Users',
3125: },
3126: );
1.190 raeburn 3127: my @menu =
3128: (
1.208 raeburn 3129: { text => $links{$context}{'upload'},
1.224 raeburn 3130: help => 'Course_Create_Class_List',
1.190 raeburn 3131: action => 'upload',
3132: permission => $permission->{'cusr'},
3133: },
1.208 raeburn 3134: { text => $links{$context}{'singleuser'},
1.224 raeburn 3135: help => 'Course_Change_Privileges',
1.190 raeburn 3136: action => 'singleuser',
3137: permission => $permission->{'cusr'},
3138: },
1.208 raeburn 3139: { text => $links{$context}{'listusers'},
1.224 raeburn 3140: help => 'Course_View_Class_List',
1.191 raeburn 3141: action => 'listusers',
1.208 raeburn 3142: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.190 raeburn 3143: },
3144: );
1.208 raeburn 3145: if ($context eq 'domain' || $context eq 'course') {
3146: my $customlink = { text => 'Edit Custom Roles',
1.224 raeburn 3147: help => 'Course_Editing_Custom_Roles',
1.208 raeburn 3148: action => 'custom',
3149: permission => $permission->{'custom'},
3150: };
3151: push(@menu,$customlink);
3152: }
3153: if ($context eq 'course') {
1.213 raeburn 3154: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
3155: my @courselinks =
1.208 raeburn 3156: (
1.213 raeburn 3157: { text => 'Enroll a Single Student',
1.224 raeburn 3158: help => 'Course_Add_Student',
1.213 raeburn 3159: action => 'singlestudent',
3160: permission => $permission->{'cusr'},
3161: },
3162: { text => 'Drop Students',
3163: help => 'Course_Drop_Student',
3164: action => 'drop',
3165: permission => $permission->{'cusr'},
3166: });
3167: if (!exists($permission->{'cusr_section'})) {
3168: push(@courselinks,
1.242 bisitz 3169: { text => 'Automated Enrollment Manager',
1.228 raeburn 3170: help => 'Course_Automated_Enrollment',
1.208 raeburn 3171: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
3172: && $permission->{'cusr'}),
3173: url => '/adm/populate',
1.237 raeburn 3174: },
3175: { text => 'Configure User Self-enrollment',
3176: help => 'Course_Self_Enrollment',
3177: action => 'selfenroll',
3178: permission => $permission->{'cusr'},
3179: });
1.213 raeburn 3180: }
3181: push(@courselinks,
1.208 raeburn 3182: { text => 'Manage Course Groups',
3183: help => 'Course_Manage_Group',
3184: permission => $permission->{'grp_manage'},
3185: url => '/adm/coursegroups?refpage=cusr',
1.239 raeburn 3186: },
1.240 raeburn 3187: { text => 'View Change Logs',
3188: help => 'Course_User_Logs',
3189: action => 'changelogs',
3190: permission => $permission->{'cusr'},
1.250 raeburn 3191: },);
3192: # { text => 'View Log-in History',
3193: # help => 'Course_User_Logins',
3194: # action => 'logins',
3195: # permission => $permission->{'cusr'},
3196: # });
1.208 raeburn 3197: push(@menu,@courselinks);
3198: }
1.190 raeburn 3199: my $menu_html = '';
3200: foreach my $menu_item (@menu) {
3201: next if (! $menu_item->{'permission'});
3202: $menu_html.='<p>';
1.234 raeburn 3203: if (exists($menu_item->{'help'})) {
3204: $menu_html.=
3205: &Apache::loncommon::help_open_topic($menu_item->{'help'});
3206: }
1.190 raeburn 3207: $menu_html.='<font size="+1">';
3208: if (exists($menu_item->{'url'})) {
3209: $menu_html.=qq{<a href="$menu_item->{'url'}">};
3210: } else {
3211: $menu_html.=
3212: qq{<a href="/adm/createuser?action=$menu_item->{'action'}">};
3213: }
3214: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
3215: $menu_html.='</p>';
3216: }
3217: return $menu_html;
3218: }
3219:
1.189 albertel 3220: sub restore_prev_selections {
3221: my %saveable_parameters = ('srchby' => 'scalar',
3222: 'srchin' => 'scalar',
3223: 'srchtype' => 'scalar',
3224: );
3225: &Apache::loncommon::store_settings('user','user_picker',
3226: \%saveable_parameters);
3227: &Apache::loncommon::restore_settings('user','user_picker',
3228: \%saveable_parameters);
3229: }
3230:
1.237 raeburn 3231: sub print_selfenroll_menu {
3232: my ($r,$context,$permission) = @_;
3233: my $formname = 'enrollstudent';
3234: my $nolink = 1;
3235: my ($row,$lt) = &get_selfenroll_titles();
3236: my $groupslist = &Apache::lonuserutils::get_groupslist();
3237: my $setsec_js =
3238: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 3239: my %alerts = &Apache::lonlocal::texthash(
3240: acto => 'Activation of self-enrollment was selected for the following domain(s)',
3241: butn => 'but no user types have been checked.',
3242: wilf => "Please uncheck 'activate' or check at least one type.",
3243: );
3244: my $selfenroll_js = <<"ENDSCRIPT";
3245: function update_types(caller,num) {
3246: var delidx = getIndexByName('selfenroll_delete');
3247: var actidx = getIndexByName('selfenroll_activate');
3248: if (caller == 'selfenroll_all') {
3249: var selall;
3250: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
3251: if (document.$formname.selfenroll_all[i].checked) {
3252: selall = document.$formname.selfenroll_all[i].value;
3253: }
3254: }
3255: if (selall == 1) {
3256: if (delidx != -1) {
3257: if (document.$formname.selfenroll_delete.length) {
3258: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
3259: document.$formname.selfenroll_delete[j].checked = true;
3260: }
3261: } else {
3262: document.$formname.elements[delidx].checked = true;
3263: }
3264: }
3265: if (actidx != -1) {
3266: if (document.$formname.selfenroll_activate.length) {
3267: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
3268: document.$formname.selfenroll_activate[j].checked = false;
3269: }
3270: } else {
3271: document.$formname.elements[actidx].checked = false;
3272: }
3273: }
3274: document.$formname.selfenroll_newdom.selectedIndex = 0;
3275: }
3276: }
3277: if (caller == 'selfenroll_activate') {
3278: if (document.$formname.selfenroll_activate.length) {
3279: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
3280: if (document.$formname.selfenroll_activate[j].value == num) {
3281: if (document.$formname.selfenroll_activate[j].checked) {
3282: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
3283: if (document.$formname.selfenroll_all[i].value == '1') {
3284: document.$formname.selfenroll_all[i].checked = false;
3285: }
3286: if (document.$formname.selfenroll_all[i].value == '0') {
3287: document.$formname.selfenroll_all[i].checked = true;
3288: }
3289: }
3290: }
3291: }
3292: }
3293: } else {
3294: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
3295: if (document.$formname.selfenroll_all[i].value == '1') {
3296: document.$formname.selfenroll_all[i].checked = false;
3297: }
3298: if (document.$formname.selfenroll_all[i].value == '0') {
3299: document.$formname.selfenroll_all[i].checked = true;
3300: }
3301: }
3302: }
3303: }
3304: if (caller == 'selfenroll_delete') {
3305: if (document.$formname.selfenroll_delete.length) {
3306: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
3307: if (document.$formname.selfenroll_delete[j].value == num) {
3308: if (document.$formname.selfenroll_delete[j].checked) {
3309: var delindex = getIndexByName('selfenroll_types_'+num);
3310: if (delindex != -1) {
3311: if (document.$formname.elements[delindex].length) {
3312: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
3313: document.$formname.elements[delindex][k].checked = false;
3314: }
3315: } else {
3316: document.$formname.elements[delindex].checked = false;
3317: }
3318: }
3319: }
3320: }
3321: }
3322: } else {
3323: if (document.$formname.selfenroll_delete.checked) {
3324: var delindex = getIndexByName('selfenroll_types_'+num);
3325: if (delindex != -1) {
3326: if (document.$formname.elements[delindex].length) {
3327: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
3328: document.$formname.elements[delindex][k].checked = false;
3329: }
3330: } else {
3331: document.$formname.elements[delindex].checked = false;
3332: }
3333: }
3334: }
3335: }
3336: }
3337: return;
3338: }
3339:
3340: function validate_types(form) {
3341: var needaction = new Array();
3342: var countfail = 0;
3343: var actidx = getIndexByName('selfenroll_activate');
3344: if (actidx != -1) {
3345: if (document.$formname.selfenroll_activate.length) {
3346: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
3347: var num = document.$formname.selfenroll_activate[j].value;
3348: if (document.$formname.selfenroll_activate[j].checked) {
3349: countfail = check_types(num,countfail,needaction)
3350: }
3351: }
3352: } else {
3353: if (document.$formname.selfenroll_activate.checked) {
3354: var num = document.enrollstudent.selfenroll_activate.value;
3355: countfail = check_types(num,countfail,needaction)
3356: }
3357: }
3358: }
3359: if (countfail > 0) {
3360: var msg = "$alerts{'acto'}\\n";
3361: var loopend = needaction.length -1;
3362: if (loopend > 0) {
3363: for (var m=0; m<loopend; m++) {
3364: msg += needaction[m]+", ";
3365: }
3366: }
3367: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
3368: alert(msg);
3369: return;
3370: }
3371: setSections(form);
3372: }
3373:
3374: function check_types(num,countfail,needaction) {
3375: var typeidx = getIndexByName('selfenroll_types_'+num);
3376: var count = 0;
3377: if (typeidx != -1) {
3378: if (document.$formname.elements[typeidx].length) {
3379: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
3380: if (document.$formname.elements[typeidx][k].checked) {
3381: count ++;
3382: }
3383: }
3384: } else {
3385: if (document.$formname.elements[typeidx].checked) {
3386: count ++;
3387: }
3388: }
3389: if (count == 0) {
3390: var domidx = getIndexByName('selfenroll_dom_'+num);
3391: if (domidx != -1) {
3392: var domname = document.$formname.elements[domidx].value;
3393: needaction[countfail] = domname;
3394: countfail ++;
3395: }
3396: }
3397: }
3398: return countfail;
3399: }
3400:
3401: function getIndexByName(item) {
3402: for (var i=0;i<document.$formname.elements.length;i++) {
3403: if (document.$formname.elements[i].name == item) {
3404: return i;
3405: }
3406: }
3407: return -1;
3408: }
3409: ENDSCRIPT
1.256 raeburn 3410: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3411: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3412:
1.237 raeburn 3413: my $output = '<script type="text/javascript">'."\n".
1.249 raeburn 3414: $setsec_js."\n".$selfenroll_js."\n".
1.237 raeburn 3415: '</script>'."\n".
1.256 raeburn 3416: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
3417: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
3418: if (ref($visactions) eq 'HASH') {
3419: if ($visible) {
3420: $output .= '<p>'.$visactions->{'vis'}.'</p>';
3421: } else {
3422: $output .= $visactions->{'miss'}.'<br />'.$visactions->{'yous'}.
3423: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
3424: if (ref($vismsgs) eq 'ARRAY') {
3425: $output .= '<br />'.$visactions->{'make'}.'<ul>';
3426: foreach my $item (@{$vismsgs}) {
3427: $output .= '<li>'.$visactions->{$item}.'</li>';
3428: }
3429: $output .= '</ul>';
3430: }
3431: $output .= '</p>';
3432: }
3433: }
3434: $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
3435: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 3436: if (ref($row) eq 'ARRAY') {
3437: foreach my $item (@{$row}) {
3438: my $title = $item;
3439: if (ref($lt) eq 'HASH') {
3440: $title = $lt->{$item};
3441: }
3442: $output .=
3443: &Apache::lonhtmlcommon::row_title($title,
3444: 'LC_selfenroll_pick_box_title','LC_oddrow_value')."\n";
3445: if ($item eq 'types') {
3446: my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
1.241 raeburn 3447: my $showdomdesc = 1;
3448: my $includeempty = 1;
3449: my $num = 0;
3450: $output .= &Apache::loncommon::start_data_table().
3451: &Apache::loncommon::start_data_table_row()
3452: .'<td colspan="2"><span class="LC_nobreak"><label>'
3453: .&mt('Any user in any domain:')
3454: .' <input type="radio" name="selfenroll_all" value="1" ';
3455: if ($curr_types eq '*') {
3456: $output .= ' checked="checked" ';
3457: }
1.249 raeburn 3458: $output .= 'onchange="javascript:update_types('.
3459: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
3460: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 3461: if ($curr_types ne '*') {
3462: $output .= ' checked="checked" ';
3463: }
1.249 raeburn 3464: $output .= ' onchange="javascript:update_types('.
3465: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
3466: &Apache::loncommon::end_data_table_row().
3467: &Apache::loncommon::end_data_table().
3468: &mt('Or').'<br />'.
3469: &Apache::loncommon::start_data_table();
1.241 raeburn 3470: my %currdoms;
1.249 raeburn 3471: if ($curr_types eq '') {
1.241 raeburn 3472: $output .= &new_selfenroll_dom_row($cdom,'0');
3473: } elsif ($curr_types ne '*') {
3474: my @entries = split(/;/,$curr_types);
3475: if (@entries > 0) {
3476: foreach my $entry (@entries) {
3477: my ($currdom,$typestr) = split(/:/,$entry);
3478: $currdoms{$currdom} = 1;
3479: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 3480: my @currinsttypes = split(',',$typestr);
1.241 raeburn 3481: $output .= &Apache::loncommon::start_data_table_row()
3482: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
3483: .' '.$domdesc.' ('.$currdom.')'
3484: .'</b><input type="hidden" name="selfenroll_dom_'.$num
3485: .'" value="'.$currdom.'" /></span><br />'
3486: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 3487: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 3488: .&mt('Delete').'</label></span></td>';
1.249 raeburn 3489: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 3490: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
3491: .&Apache::loncommon::end_data_table_row();
3492: $num ++;
3493: }
3494: }
3495: }
1.249 raeburn 3496: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 3497: if ($curr_types eq '*') {
1.249 raeburn 3498: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 3499: } elsif ($curr_types eq '') {
1.249 raeburn 3500: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 3501: }
3502: $output .= &Apache::loncommon::start_data_table_row()
3503: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
3504: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
3505: $includeempty,$showdomdesc)
3506: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
3507: .'</td>'.&Apache::loncommon::end_data_table_row()
3508: .&Apache::loncommon::end_data_table();
1.237 raeburn 3509: } elsif ($item eq 'registered') {
3510: my ($regon,$regoff);
3511: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
3512: $regon = ' checked="checked" ';
3513: $regoff = ' ';
3514: } else {
3515: $regon = ' ';
3516: $regoff = ' checked="checked" ';
3517: }
3518: $output .= '<label>'.
1.245 raeburn 3519: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 3520: &mt('Yes').'</label> <label>'.
1.245 raeburn 3521: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 3522: &mt('No').'</label>';
1.237 raeburn 3523: } elsif ($item eq 'enroll_dates') {
3524: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
3525: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
3526: if ($starttime eq '') {
3527: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
3528: }
3529: if ($endtime eq '') {
3530: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
3531: }
3532: my $startform =
3533: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
3534: undef,undef,undef,undef,undef,undef,undef,$nolink);
3535: my $endform =
3536: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
3537: undef,undef,undef,undef,undef,undef,undef,$nolink);
3538: $output .= &selfenroll_date_forms($startform,$endform);
3539: } elsif ($item eq 'access_dates') {
3540: my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
3541: my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
3542: if ($starttime eq '') {
3543: $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
3544: }
3545: if ($endtime eq '') {
3546: $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
3547: }
3548: my $startform =
3549: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
3550: undef,undef,undef,undef,undef,undef,undef,$nolink);
3551: my $endform =
3552: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
3553: undef,undef,undef,undef,undef,undef,undef,$nolink);
3554: $output .= &selfenroll_date_forms($startform,$endform);
3555: } elsif ($item eq 'section') {
3556: my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'};
3557: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
3558: my $newsecval;
3559: if ($currsec ne 'none' && $currsec ne '') {
3560: if (!defined($sections_count{$currsec})) {
3561: $newsecval = $currsec;
3562: }
3563: }
3564: my $sections_select =
3565: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
3566: $output .= '<table class="LC_createuser">'."\n".
3567: '<tr class="LC_section_row">'."\n".
3568: '<td align="center">'.&mt('Existing sections')."\n".
3569: '<br />'.$sections_select.'</td><td align="center">'.
3570: &mt('New section').'<br />'."\n".
3571: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
3572: '<input type="hidden" name="sections" value="" />'."\n".
3573: '<input type="hidden" name="state" value="done" />'."\n".
3574: '</td></tr></table>'."\n";
3575: }
3576: $output .= &Apache::lonhtmlcommon::row_closure(1);
3577: }
3578: }
3579: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 3580: '<br /><input type="button" name="selfenrollconf" value="'
1.249 raeburn 3581: .&mt('Save changes').'" onclick="validate_types(this.form);" />'
1.241 raeburn 3582: .'<input type="hidden" name="action" value="selfenroll" /></form>';
1.237 raeburn 3583: $r->print($output);
3584: return;
3585: }
3586:
1.256 raeburn 3587: sub visible_in_cat {
3588: my ($cdom,$cnum) = @_;
3589: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
3590: my ($cathash,%settable,@vismsgs,$cansetvis);
3591: my %visactions = &Apache::lonlocal::texthash(
3592: vis => 'Your course currently appears in the Course Catalog for this domain.',
3593: gen => 'Courses can be both self-cataloging, based on an institutional code (e.g., fs08phy231), or can be assigned categories from a hierarchy defined for the domain.',
3594: miss => 'Your course does not currently appear in the Course Catalog for this domain.',
3595: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
3596: coca => 'Courses can be absent from the Catalog, because they do not have an institutional code, have no assigned category, or have been specifically excluded.',
3597: make => 'Make any changes to self-enrollment settings below, click "Save changes", then take action to include the course in the Catalog:',
3598: take => 'Take the following action to ensure the course appears in the Catalog:',
3599: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
3600: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
3601: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
3602: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
3603: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
3604: dc_chgcat => 'Ask a domain coordinator to change the category assigned to the course, as the one currently assigned is no longer used in the domain',
3605: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
3606: );
3607: $visactions{'unhide'} = &mt('Use [_1]Set course environment[_2] to change the "Exclude from course catalog" setting.','<a href="/adm/parmset?action=crsenv">','</a>');
3608: $visactions{'chgcat'} = &mt('Use [_1]Set course environment[_2] to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','<a href="/adm/parmset?action=crsenv">','</a>');
3609: $visactions{'addcat'} = &mt('Use [_1]Set course environment[_2] to assign a category to the course.','<a href="/adm/parmset?action=crsenv">','</a>');
3610: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3611: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
3612: $settable{'togglecats'} = 1;
3613: }
3614: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
3615: $settable{'categorize'} = 1;
3616: }
3617: $cathash = $domconf{'coursecategories'}{'cats'};
3618: }
3619: if ($settable{'togglecats'} && $settable{'categories'}) {
3620: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
3621: } elsif ($settable{'togglecats'}) {
3622: $cansetvis = &mt('You are able to choose to exclude this course from the catalog, but only a Domain Coordinator may assign a course category.');
3623: } elsif ($settable{'categories'}) {
3624: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
3625: } else {
3626: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
3627: }
3628:
3629: my %currsettings =
3630: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
3631: $cdom,$cnum);
3632: my $visible = 0;
3633: if ($currsettings{'internal.coursecode'} ne '') {
3634: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3635: $cathash = $domconf{'coursecategories'}{'cats'};
3636: if (ref($cathash) eq 'HASH') {
3637: if ($cathash->{'instcode::0'} eq '') {
3638: push(@vismsgs,'dc_addinst');
3639: } else {
3640: $visible = 1;
3641: }
3642: } else {
3643: $visible = 1;
3644: }
3645: } else {
3646: $visible = 1;
3647: }
3648: } else {
3649: if (ref($cathash) eq 'HASH') {
3650: if ($cathash->{'instcode::0'} ne '') {
3651: push(@vismsgs,'dc_instcode');
3652: }
3653: } else {
3654: push(@vismsgs,'dc_instcode');
3655: }
3656: }
3657: if ($currsettings{'categories'} ne '') {
3658: my $cathash;
3659: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3660: $cathash = $domconf{'coursecategories'}{'cats'};
3661: if (ref($cathash) eq 'HASH') {
3662: if (keys(%{$cathash}) == 0) {
3663: push(@vismsgs,'dc_catalog');
3664: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
3665: push(@vismsgs,'dc_categories');
3666: } else {
3667: my @currcategories = split('&',$currsettings{'categories'});
3668: my $matched = 0;
3669: foreach my $cat (@currcategories) {
3670: if ($cathash->{$cat} ne '') {
3671: $visible = 1;
3672: $matched = 1;
3673: last;
3674: }
3675: }
3676: if (!$matched) {
3677: if ($settable{'categories'}) {
3678: push(@vismsgs,'chgcat');
3679: } else {
3680: push(@vismsgs,'dc_chgcat');
3681: }
3682: }
3683: }
3684: }
3685: }
3686: } else {
3687: if (ref($cathash) eq 'HASH') {
3688: if ((keys(%{$cathash}) > 1) ||
3689: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
3690: if ($settable{'categories'}) {
3691: push(@vismsgs,'addcat');
3692: } else {
3693: push(@vismsgs,'dc_addcat');
3694: }
3695: }
3696: }
3697: }
3698: if ($currsettings{'hidefromcat'} eq 'yes') {
3699: $visible = 0;
3700: if ($settable{'togglecats'}) {
3701: unshift(@vismsgs,'unhide');
3702: } else {
3703: unshift(@vismsgs,'dc_unhide')
3704: }
3705: }
3706: return ($visible,$cansetvis,\@vismsgs,\%visactions);
3707: }
3708:
1.241 raeburn 3709: sub new_selfenroll_dom_row {
3710: my ($newdom,$num) = @_;
3711: my $domdesc = &Apache::lonnet::domain($newdom);
3712: my $output;
3713: if ($domdesc ne '') {
3714: $output .= &Apache::loncommon::start_data_table_row()
3715: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
3716: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 3717: .'" value="'.$newdom.'" /></span><br />'
3718: .'<span class="LC_nobreak"><label><input type="checkbox" '
3719: .'name="selfenroll_activate" value="'.$num.'" '
3720: .'onchange="javascript:update_types('
3721: ."'selfenroll_activate','$num'".');" />'
3722: .&mt('Activate').'</label></span></td>';
1.241 raeburn 3723: my @currinsttypes;
3724: $output .= '<td>'.&mt('User types:').'<br />'
3725: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
3726: .&Apache::loncommon::end_data_table_row();
3727: }
3728: return $output;
3729: }
3730:
3731: sub selfenroll_inst_types {
3732: my ($num,$currdom,$currinsttypes) = @_;
3733: my $output;
3734: my $numinrow = 4;
3735: my $count = 0;
3736: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 3737: my $othervalue = 'any';
1.241 raeburn 3738: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 3739: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 3740: $othervalue = 'other';
3741: }
1.241 raeburn 3742: $output .= '<table><tr>';
3743: foreach my $type (@{$types}) {
3744: if (($count > 0) && ($count%$numinrow == 0)) {
3745: $output .= '</tr><tr>';
3746: }
3747: if (defined($usertypes->{$type})) {
1.257 raeburn 3748: my $esc_type = &escape($type);
1.241 raeburn 3749: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 3750: $esc_type.'" ';
1.241 raeburn 3751: if (ref($currinsttypes) eq 'ARRAY') {
3752: if (@{$currinsttypes} > 0) {
1.249 raeburn 3753: if (grep(/^any$/,@{$currinsttypes})) {
3754: $output .= 'checked="checked"';
1.257 raeburn 3755: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 3756: $output .= 'checked="checked"';
3757: }
1.249 raeburn 3758: } else {
3759: $output .= 'checked="checked"';
1.241 raeburn 3760: }
3761: }
3762: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
3763: }
3764: $count ++;
3765: }
3766: if (($count > 0) && ($count%$numinrow == 0)) {
3767: $output .= '</tr><tr>';
3768: }
1.249 raeburn 3769: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 3770: if (ref($currinsttypes) eq 'ARRAY') {
3771: if (@{$currinsttypes} > 0) {
1.249 raeburn 3772: if (grep(/^any$/,@{$currinsttypes})) {
3773: $output .= ' checked="checked"';
3774: } elsif ($othervalue eq 'other') {
3775: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
3776: $output .= ' checked="checked"';
3777: }
1.241 raeburn 3778: }
1.249 raeburn 3779: } else {
3780: $output .= ' checked="checked"';
1.241 raeburn 3781: }
1.249 raeburn 3782: } else {
3783: $output .= ' checked="checked"';
1.241 raeburn 3784: }
3785: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
3786: }
3787: return $output;
3788: }
3789:
1.237 raeburn 3790: sub selfenroll_date_forms {
3791: my ($startform,$endform) = @_;
3792: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 3793: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 3794: 'LC_oddrow_value')."\n".
3795: $startform."\n".
3796: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 3797: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 3798: 'LC_oddrow_value')."\n".
3799: $endform."\n".
3800: &Apache::lonhtmlcommon::row_closure(1).
3801: &Apache::lonhtmlcommon::end_pick_box();
3802: return $output;
3803: }
3804:
1.239 raeburn 3805: sub print_userchangelogs_display {
3806: my ($r,$context,$permission) = @_;
3807: my $formname = 'roleslog';
3808: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3809: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3810: my %roleslog=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
3811: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
3812:
3813: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
3814: my %saveable_parameters = ('show' => 'scalar',);
3815: &Apache::loncommon::store_course_settings('roles_log',
3816: \%saveable_parameters);
3817: &Apache::loncommon::restore_course_settings('roles_log',
3818: \%saveable_parameters);
3819: # set defaults
3820: my $now = time();
3821: my $defstart = $now - (7*24*3600); #7 days ago
3822: my %defaults = (
3823: page => '1',
3824: show => '10',
3825: role => 'any',
3826: chgcontext => 'any',
3827: rolelog_start_date => $defstart,
3828: rolelog_end_date => $now,
3829: );
3830: my $more_records = 0;
3831:
3832: # set current
3833: my %curr;
3834: foreach my $item ('show','page','role','chgcontext') {
3835: $curr{$item} = $env{'form.'.$item};
3836: }
3837: my ($startdate,$enddate) =
3838: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
3839: $curr{'rolelog_start_date'} = $startdate;
3840: $curr{'rolelog_end_date'} = $enddate;
3841: foreach my $key (keys(%defaults)) {
3842: if ($curr{$key} eq '') {
3843: $curr{$key} = $defaults{$key};
3844: }
3845: }
1.248 raeburn 3846: my (%whodunit,%changed,$version);
3847: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
3848: $r->print(&role_display_filter($formname,$cdom,$cnum,\%curr,$version));
1.239 raeburn 3849: my $showntablehdr = 0;
3850: my $tablehdr = &Apache::loncommon::start_data_table().
3851: &Apache::loncommon::start_data_table_header_row().
3852: '<th> </th><th>'.&mt('When').'</th><th>'.&mt('Who made the change').
3853: '</th><th>'.&mt('Changed User').'</th><th>'.&mt('Role').'</th><th>'.&mt('Section').'</th><th>'.
3854: &mt('Context').'</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
3855: &Apache::loncommon::end_data_table_header_row();
3856: my ($minshown,$maxshown);
1.255 raeburn 3857: $minshown = 1;
1.239 raeburn 3858: my $count = 0;
3859: if ($curr{'show'} ne &mt('all')) {
3860: $maxshown = $curr{'page'} * $curr{'show'};
3861: if ($curr{'page'} > 1) {
3862: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
3863: }
3864: }
3865: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
3866: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
3867: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
3868: if ($curr{'show'} ne &mt('all')) {
3869: if ($count >= $curr{'page'} * $curr{'show'}) {
3870: $more_records = 1;
3871: last;
3872: }
3873: }
3874: if ($curr{'role'} ne 'any') {
3875: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
3876: }
3877: if ($curr{'chgcontext'} ne 'any') {
3878: if ($curr{'chgcontext'} eq 'selfenroll') {
3879: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
3880: } else {
3881: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
3882: }
3883: }
3884: $count ++;
3885: next if ($count < $minshown);
3886: if (!$showntablehdr) {
3887: $r->print($tablehdr);
3888: $showntablehdr = 1;
3889: }
3890: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
3891: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
3892: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
3893: }
3894: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
3895: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
3896: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
3897: }
3898: my $sec = $roleslog{$id}{'logentry'}{'section'};
3899: if ($sec eq '') {
3900: $sec = &mt('None');
3901: }
3902: my ($rolestart,$roleend);
3903: if ($roleslog{$id}{'delflag'}) {
3904: $rolestart = &mt('deleted');
3905: $roleend = &mt('deleted');
3906: } else {
3907: $rolestart = $roleslog{$id}{'logentry'}{'start'};
3908: $roleend = $roleslog{$id}{'logentry'}{'end'};
3909: if ($rolestart eq '' || $rolestart == 0) {
3910: $rolestart = &mt('No start date');
3911: } else {
3912: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
3913: }
3914: if ($roleend eq '' || $roleend == 0) {
3915: $roleend = &mt('No end date');
3916: } else {
3917: $roleend = &Apache::lonlocal::locallocaltime($roleend);
3918: }
3919: }
3920: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
3921: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
3922: $chgcontext = 'selfenroll';
3923: }
3924: my %lt = &rolechg_contexts();
3925: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
3926: $chgcontext = $lt{$chgcontext};
3927: }
3928: $r->print(&Apache::loncommon::start_data_table_row().'<td>'.$count.'</td><td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td><td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td><td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td><td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'}).'</td><td>'.$sec.'</td><td>'.$chgcontext.'</td><td>'.$rolestart.'</td><td>'.$roleend.'</td>'.&Apache::loncommon::end_data_table_row()."\n");
3929: }
3930: if ($showntablehdr) {
3931: $r->print(&Apache::loncommon::end_data_table().'<br />');
3932: if (($curr{'page'} > 1) || ($more_records)) {
3933: $r->print('<table><tr>');
3934: if ($curr{'page'} > 1) {
3935: $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
3936: }
3937: if ($more_records) {
3938: $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
3939: }
3940: $r->print('</tr></table>');
3941: $r->print(<<"ENDSCRIPT");
3942: <script type="text/javascript">
3943: function chgPage(caller) {
3944: if (caller == 'previous') {
3945: document.$formname.page.value --;
3946: }
3947: if (caller == 'next') {
3948: document.$formname.page.value ++;
3949: }
3950: document.$formname.submit();
3951: return;
3952: }
3953: </script>
3954: ENDSCRIPT
3955: }
3956: } else {
3957: $r->print(&mt('There are no records to display'));
3958: }
3959: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
3960: '<input type="hidden" name="action" value="changelogs" /></form>');
3961: return;
3962: }
3963:
3964: sub role_display_filter {
1.248 raeburn 3965: my ($formname,$cdom,$cnum,$curr,$version) = @_;
1.239 raeburn 3966: my $context = 'course';
3967: my $nolink = 1;
3968: my $output = '<table><tr><td valign="top">'.
3969: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b><br />'.
3970: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
3971: (&mt('all'),5,10,20,50,100,1000,10000)).
3972: '</td><td> </td>';
3973: my $startform =
3974: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
3975: $curr->{'rolelog_start_date'},undef,
3976: undef,undef,undef,undef,undef,undef,$nolink);
3977: my $endform =
3978: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
3979: $curr->{'rolelog_end_date'},undef,
3980: undef,undef,undef,undef,undef,undef,$nolink);
3981: my %lt = &rolechg_contexts();
3982: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br /><table><tr><td>'.&mt('After:').
3983: '</td><td>'.$startform.'</td></tr><tr><td>'.&mt('Before:').'</td><td>'.
3984: $endform.'</td></tr></table></td><td> </td>'.
3985: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
3986: '<select name="role"><option value="any"';
3987: if ($curr->{'role'} eq 'any') {
3988: $output .= ' selected="selected"';
3989: }
3990: $output .= '>'.&mt('Any').'</option>'."\n";
3991: my @roles = &Apache::lonuserutils::course_roles($context,undef,1);
3992: foreach my $role (@roles) {
3993: my $plrole;
3994: if ($role eq 'cr') {
3995: $plrole = &mt('Custom Role');
3996: } else {
3997: $plrole=&Apache::lonnet::plaintext($role);
3998: }
3999: my $selstr = '';
4000: if ($role eq $curr->{'role'}) {
4001: $selstr = ' selected="selected"';
4002: }
4003: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
4004: }
4005: $output .= '</select></td><td> </td><td valign="top"><b>'.
4006: &mt('Context:').'</b><br /><select name="chgcontext">';
4007: foreach my $chgtype ('any','auto','updatenow','createcourse','course','domain','selfenroll') {
4008: my $selstr = '';
4009: if ($curr->{'chgcontext'} eq $chgtype) {
4010: $output .= $selstr = ' selected="selected"';
4011: }
4012: if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) {
4013: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
4014: }
4015: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 4016: }
1.239 raeburn 4017: $output .= '</select></td><td> </td><td valign="middle"><input type="submit" value="'.
1.248 raeburn 4018: &mt('Update Display').'" /></tr></table>'.
4019: '<span class="LC_roleslog_note">'.
4020: &mt('[_1]Note:[_2] Only changes made from servers running LON-CAPA 2.6.99.0 or later are displayed.');
4021: if ($version) {
4022: $output .= ' '.&mt('This server is version [_3].','<b>','</b>',$version); }
4023: $output .= '</span><hr noshade><br />';
1.239 raeburn 4024: return $output;
4025: }
4026:
4027: sub rolechg_contexts {
4028: my %lt = &Apache::lonlocal::texthash (
4029: any => 'Any',
4030: auto => 'Automated enrollment',
4031: updatenow => 'Roster Update',
4032: createcourse => 'Course Creation',
4033: course => 'User Management in course',
4034: domain => 'User Management in domain',
4035: selfenroll => 'Self-enrolled',
4036: );
4037: return %lt;
4038: }
4039:
1.27 matthew 4040: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 4041: sub user_search_result {
1.221 raeburn 4042: my ($context,$srch) = @_;
1.160 raeburn 4043: my %allhomes;
4044: my %inst_matches;
4045: my %srch_results;
1.181 raeburn 4046: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 4047: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 4048: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 4049: $response = &mt('Invalid search.');
4050: }
4051: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
4052: $response = &mt('Invalid search.');
4053: }
1.177 raeburn 4054: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 4055: $response = &mt('Invalid search.');
4056: }
4057: if ($srch->{'srchterm'} eq '') {
4058: $response = &mt('You must enter a search term.');
4059: }
1.183 raeburn 4060: if ($srch->{'srchterm'} =~ /^\s+$/) {
4061: $response = &mt('Your search term must contain more than just spaces.');
4062: }
1.160 raeburn 4063: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
4064: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 4065: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 4066: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
4067: }
4068: }
4069: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
4070: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 4071: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 4072: my $unamecheck = $srch->{'srchterm'};
4073: if ($srch->{'srchtype'} eq 'contains') {
4074: if ($unamecheck !~ /^\w/) {
4075: $unamecheck = 'a'.$unamecheck;
4076: }
4077: }
4078: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 4079: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
4080: }
1.160 raeburn 4081: }
4082: }
1.180 raeburn 4083: if ($response ne '') {
4084: $response = '<span class="LC_warning">'.$response.'</span>';
4085: }
1.160 raeburn 4086: if ($srch->{'srchin'} eq 'instd') {
4087: my $instd_chk = &directorysrch_check($srch);
4088: if ($instd_chk ne 'ok') {
1.180 raeburn 4089: $response = '<span class="LC_warning">'.$instd_chk.'</span>'.
4090: '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />';
1.160 raeburn 4091: }
4092: }
4093: if ($response ne '') {
1.180 raeburn 4094: return ($currstate,$response);
1.160 raeburn 4095: }
4096: if ($srch->{'srchby'} eq 'uname') {
4097: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
4098: if ($env{'form.forcenew'}) {
4099: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
4100: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
4101: if ($uhome eq 'no_host') {
4102: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 4103: my $showdom = &display_domain_info($env{'request.role.domain'});
4104: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 4105: } else {
1.179 raeburn 4106: $currstate = 'modify';
1.160 raeburn 4107: }
4108: } else {
1.179 raeburn 4109: $currstate = 'modify';
1.160 raeburn 4110: }
4111: } else {
4112: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 4113: if ($srch->{'srchtype'} eq 'exact') {
4114: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
4115: if ($uhome eq 'no_host') {
1.179 raeburn 4116: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4117: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 4118: } else {
1.179 raeburn 4119: $currstate = 'modify';
1.162 raeburn 4120: }
4121: } else {
4122: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 4123: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4124: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 4125: }
4126: } else {
1.167 albertel 4127: my $courseusers = &get_courseusers();
1.162 raeburn 4128: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 4129: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 4130: $currstate = 'modify';
1.162 raeburn 4131: } else {
1.179 raeburn 4132: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4133: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 4134: }
1.160 raeburn 4135: } else {
1.167 albertel 4136: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 4137: my ($cuname,$cudomain) = split(/:/,$user);
4138: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 4139: my $matched = 0;
4140: if ($srch->{'srchtype'} eq 'begins') {
4141: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
4142: $matched = 1;
4143: }
4144: } else {
4145: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
4146: $matched = 1;
4147: }
4148: }
4149: if ($matched) {
1.167 albertel 4150: $srch_results{$user} =
4151: {&Apache::lonnet::get('environment',
4152: ['firstname',
4153: 'lastname',
1.194 albertel 4154: 'permanentemail'],
4155: $cudomain,$cuname)};
1.162 raeburn 4156: }
4157: }
4158: }
1.179 raeburn 4159: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4160: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 4161: }
4162: }
4163: }
4164: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 4165: $currstate = 'query';
1.160 raeburn 4166: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 4167: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
4168: if ($dirsrchres eq 'ok') {
4169: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4170: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 4171: } else {
4172: my $showdom = &display_domain_info($srch->{'srchdomain'});
4173: $response = '<span class="LC_warning">'.
4174: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
4175: '</span><br />'.
4176: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
4177: '<br /><br />';
4178: }
1.160 raeburn 4179: }
4180: } else {
4181: if ($srch->{'srchin'} eq 'dom') {
4182: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 4183: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4184: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 4185: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 4186: my $courseusers = &get_courseusers();
4187: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 4188: my ($uname,$udom) = split(/:/,$user);
4189: my %names = &Apache::loncommon::getnames($uname,$udom);
4190: my %emails = &Apache::loncommon::getemails($uname,$udom);
4191: if ($srch->{'srchby'} eq 'lastname') {
4192: if ((($srch->{'srchtype'} eq 'exact') &&
4193: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 4194: (($srch->{'srchtype'} eq 'begins') &&
4195: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 4196: (($srch->{'srchtype'} eq 'contains') &&
4197: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
4198: $srch_results{$user} = {firstname => $names{'firstname'},
4199: lastname => $names{'lastname'},
4200: permanentemail => $emails{'permanentemail'},
4201: };
4202: }
4203: } elsif ($srch->{'srchby'} eq 'lastfirst') {
4204: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 4205: $srchlast =~ s/\s+$//;
4206: $srchfirst =~ s/^\s+//;
1.160 raeburn 4207: if ($srch->{'srchtype'} eq 'exact') {
4208: if (($names{'lastname'} eq $srchlast) &&
4209: ($names{'firstname'} eq $srchfirst)) {
4210: $srch_results{$user} = {firstname => $names{'firstname'},
4211: lastname => $names{'lastname'},
4212: permanentemail => $emails{'permanentemail'},
4213:
4214: };
4215: }
1.177 raeburn 4216: } elsif ($srch->{'srchtype'} eq 'begins') {
4217: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
4218: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
4219: $srch_results{$user} = {firstname => $names{'firstname'},
4220: lastname => $names{'lastname'},
4221: permanentemail => $emails{'permanentemail'},
4222: };
4223: }
4224: } else {
1.160 raeburn 4225: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
4226: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
4227: $srch_results{$user} = {firstname => $names{'firstname'},
4228: lastname => $names{'lastname'},
4229: permanentemail => $emails{'permanentemail'},
4230: };
4231: }
4232: }
4233: }
4234: }
1.179 raeburn 4235: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4236: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 4237: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 4238: $currstate = 'query';
1.160 raeburn 4239: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 4240: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
4241: if ($dirsrchres eq 'ok') {
4242: ($currstate,$response,$forcenewuser) =
1.221 raeburn 4243: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 4244: } else {
4245: my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
4246: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
4247: '</span><br />'.
4248: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
4249: '<br /><br />';
4250: }
1.160 raeburn 4251: }
4252: }
1.179 raeburn 4253: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 4254: }
4255:
4256: sub directorysrch_check {
4257: my ($srch) = @_;
4258: my $can_search = 0;
4259: my $response;
4260: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
4261: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 4262: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 4263: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
4264: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 4265: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 4266: }
4267: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
4268: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 4269: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 4270: }
4271: my @usertypes = split(/:/,$env{'environment.inststatus'});
4272: if (!@usertypes) {
4273: push(@usertypes,'default');
4274: }
4275: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
4276: foreach my $type (@usertypes) {
4277: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
4278: $can_search = 1;
4279: last;
4280: }
4281: }
4282: }
4283: if (!$can_search) {
4284: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
4285: my @longtypes;
4286: foreach my $item (@usertypes) {
1.229 raeburn 4287: if (defined($insttypes->{$item})) {
4288: push (@longtypes,$insttypes->{$item});
4289: } elsif ($item eq 'default') {
4290: push (@longtypes,&mt('other'));
4291: }
1.160 raeburn 4292: }
4293: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 4294: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 4295: }
1.160 raeburn 4296: } else {
4297: $can_search = 1;
4298: }
4299: } else {
1.180 raeburn 4300: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 4301: }
4302: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 4303: uname => 'username',
1.160 raeburn 4304: lastfirst => 'last name, first name',
1.167 albertel 4305: lastname => 'last name',
1.172 raeburn 4306: contains => 'contains',
1.178 raeburn 4307: exact => 'as exact match to',
4308: begins => 'begins with',
1.160 raeburn 4309: );
4310: if ($can_search) {
4311: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
4312: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 4313: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 4314: }
4315: } else {
1.180 raeburn 4316: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 4317: }
4318: }
4319: if ($can_search) {
1.178 raeburn 4320: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
4321: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
4322: return 'ok';
4323: } else {
1.180 raeburn 4324: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 4325: }
4326: } else {
4327: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
4328: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
4329: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
4330: return 'ok';
4331: } else {
1.180 raeburn 4332: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 4333: }
1.160 raeburn 4334: }
4335: }
4336: }
4337:
4338: sub get_courseusers {
4339: my %advhash;
1.167 albertel 4340: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 4341: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
4342: foreach my $role (sort(keys(%coursepersonnel))) {
4343: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 4344: if (!exists($classlist->{$user})) {
4345: $classlist->{$user} = [];
4346: }
1.160 raeburn 4347: }
4348: }
1.167 albertel 4349: return $classlist;
1.160 raeburn 4350: }
4351:
4352: sub build_search_response {
1.221 raeburn 4353: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 4354: my ($currstate,$response,$forcenewuser);
1.160 raeburn 4355: my %names = (
4356: 'uname' => 'username',
4357: 'lastname' => 'last name',
4358: 'lastfirst' => 'last name, first name',
4359: 'crs' => 'this course',
1.180 raeburn 4360: 'dom' => 'LON-CAPA domain: ',
4361: 'instd' => 'the institutional directory for domain: ',
1.160 raeburn 4362: );
4363:
4364: my %single = (
1.180 raeburn 4365: begins => 'A match',
1.160 raeburn 4366: contains => 'A match',
1.180 raeburn 4367: exact => 'An exact match',
1.160 raeburn 4368: );
4369: my %nomatch = (
1.180 raeburn 4370: begins => 'No match',
1.160 raeburn 4371: contains => 'No match',
1.180 raeburn 4372: exact => 'No exact match',
1.160 raeburn 4373: );
4374: if (keys(%srch_results) > 1) {
1.179 raeburn 4375: $currstate = 'select';
1.160 raeburn 4376: } else {
4377: if (keys(%srch_results) == 1) {
1.179 raeburn 4378: $currstate = 'modify';
1.180 raeburn 4379: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
4380: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
4381: $response .= &display_domain_info($srch->{'srchdomain'});
4382: }
1.160 raeburn 4383: } else {
1.180 raeburn 4384: $response = '<span class="LC_warning">'.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
4385: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
4386: $response .= &display_domain_info($srch->{'srchdomain'});
4387: }
4388: $response .= '</span>';
1.160 raeburn 4389: if ($srch->{'srchin'} ne 'alc') {
4390: $forcenewuser = 1;
4391: my $cansrchinst = 0;
4392: if ($srch->{'srchdomain'}) {
4393: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
4394: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
4395: if ($domconfig{'directorysrch'}{'available'}) {
4396: $cansrchinst = 1;
4397: }
4398: }
4399: }
1.180 raeburn 4400: if ((($srch->{'srchby'} eq 'lastfirst') ||
4401: ($srch->{'srchby'} eq 'lastname')) &&
4402: ($srch->{'srchin'} eq 'dom')) {
4403: if ($cansrchinst) {
4404: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 4405: }
4406: }
1.180 raeburn 4407: if ($srch->{'srchin'} eq 'crs') {
4408: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
4409: }
4410: }
4411: if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {
1.221 raeburn 4412: my $cancreate =
4413: &Apache::lonuserutils::can_create_user($env{'request.role.domain'},$context);
4414: if ($cancreate) {
4415: my $showdom = &display_domain_info($env{'request.role.domain'});
1.229 raeburn 4416: $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 4417: } else {
4418: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
4419: $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 />';
4420: }
1.160 raeburn 4421: }
4422: }
4423: }
1.179 raeburn 4424: return ($currstate,$response,$forcenewuser);
1.160 raeburn 4425: }
4426:
1.180 raeburn 4427: sub display_domain_info {
4428: my ($dom) = @_;
4429: my $output = $dom;
4430: if ($dom ne '') {
4431: my $domdesc = &Apache::lonnet::domain($dom,'description');
4432: if ($domdesc ne '') {
4433: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
4434: }
4435: }
4436: return $output;
4437: }
4438:
1.160 raeburn 4439: sub crumb_utilities {
4440: my %elements = (
4441: crtuser => {
4442: srchterm => 'text',
1.172 raeburn 4443: srchin => 'selectbox',
1.160 raeburn 4444: srchby => 'selectbox',
4445: srchtype => 'selectbox',
4446: srchdomain => 'selectbox',
4447: },
1.207 raeburn 4448: crtusername => {
4449: srchterm => 'text',
4450: srchdomain => 'selectbox',
4451: },
1.160 raeburn 4452: docustom => {
4453: rolename => 'selectbox',
4454: newrolename => 'textbox',
4455: },
1.179 raeburn 4456: studentform => {
4457: srchterm => 'text',
4458: srchin => 'selectbox',
4459: srchby => 'selectbox',
4460: srchtype => 'selectbox',
4461: srchdomain => 'selectbox',
4462: },
1.160 raeburn 4463: );
4464:
4465: my $jsback .= qq|
4466: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 4467: if (typeof prevphase == 'undefined') {
4468: formname.phase.value = '';
4469: }
4470: else {
4471: formname.phase.value = prevphase;
4472: }
4473: if (typeof prevstate == 'undefined') {
4474: formname.currstate.value = '';
4475: }
4476: else {
4477: formname.currstate.value = prevstate;
4478: }
1.160 raeburn 4479: formname.submit();
4480: }
4481: |;
4482: return ($jsback,\%elements);
4483: }
4484:
1.26 matthew 4485: sub course_level_table {
1.89 raeburn 4486: my (%inccourses) = @_;
1.26 matthew 4487: my $table = '';
1.62 www 4488: # Custom Roles?
4489:
1.190 raeburn 4490: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 4491: my %lt=&Apache::lonlocal::texthash(
4492: 'exs' => "Existing sections",
4493: 'new' => "Define new section",
4494: 'ssd' => "Set Start Date",
4495: 'sed' => "Set End Date",
1.131 raeburn 4496: 'crl' => "Course Level",
1.89 raeburn 4497: 'act' => "Activate",
4498: 'rol' => "Role",
4499: 'ext' => "Extent",
1.113 raeburn 4500: 'grs' => "Section",
1.89 raeburn 4501: 'sta' => "Start",
4502: 'end' => "End"
4503: );
1.62 www 4504:
1.135 raeburn 4505: foreach my $protectedcourse (sort( keys(%inccourses))) {
4506: my $thiscourse=$protectedcourse;
1.26 matthew 4507: $thiscourse=~s:_:/:g;
4508: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
4509: my $area=$coursedata{'description'};
1.119 raeburn 4510: my $type=$coursedata{'type'};
1.135 raeburn 4511: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 4512: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 4513: my %sections_count;
1.101 albertel 4514: if (defined($env{'request.course.id'})) {
4515: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 4516: %sections_count =
4517: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 4518: }
4519: }
1.213 raeburn 4520: my @roles = &Apache::lonuserutils::roles_by_context('course');
4521: foreach my $role (@roles) {
1.221 raeburn 4522: my $plrole=&Apache::lonnet::plaintext($role);
1.135 raeburn 4523: if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
1.221 raeburn 4524: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
4525: $plrole,\%sections_count,\%lt);
4526: } elsif ($env{'request.course.sec'} ne '') {
4527: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
4528: $env{'request.course.sec'})) {
4529: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
4530: $plrole,\%sections_count,\%lt);
1.26 matthew 4531: }
4532: }
4533: }
1.221 raeburn 4534: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
4535: foreach my $cust (sort keys %customroles) {
4536: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
4537: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
4538: $cust,\%sections_count,\%lt);
4539: }
1.62 www 4540: }
1.26 matthew 4541: }
4542: return '' if ($table eq ''); # return nothing if there is nothing
4543: # in the table
1.188 raeburn 4544: my $result;
4545: if (!$env{'request.course.id'}) {
4546: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
4547: }
4548: $result .=
1.136 raeburn 4549: &Apache::loncommon::start_data_table().
4550: &Apache::loncommon::start_data_table_header_row().
4551: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>
4552: <th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
4553: &Apache::loncommon::end_data_table_header_row().
4554: $table.
4555: &Apache::loncommon::end_data_table();
1.26 matthew 4556: return $result;
4557: }
1.88 raeburn 4558:
1.221 raeburn 4559: sub course_level_row {
4560: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_;
1.222 raeburn 4561: my $row = &Apache::loncommon::start_data_table_row().
4562: ' <td><input type="checkbox" name="act_'.
4563: $protectedcourse.'_'.$role.'" /></td>'."\n".
4564: ' <td>'.$plrole.'</td>'."\n".
4565: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.221 raeburn 4566: if ($role eq 'cc') {
1.222 raeburn 4567: $row .= '<td> </td>';
1.221 raeburn 4568: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 4569: $row .= ' <td><input type="hidden" value="'.
4570: $env{'request.course.sec'}.'" '.
4571: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
4572: $env{'request.course.sec'}.'</td>';
1.221 raeburn 4573: } else {
4574: if (ref($sections_count) eq 'HASH') {
4575: my $currsec =
4576: &Apache::lonuserutils::course_sections($sections_count,
4577: $protectedcourse.'_'.$role);
1.222 raeburn 4578: $row .= '<td><table class="LC_createuser">'."\n".
4579: '<tr class="LC_section_row">'."\n".
4580: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
4581: $currsec.'</td>'."\n".
4582: ' <td> </td>'."\n".
4583: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 4584: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
4585: '" value="" />'.
4586: '<input type="hidden" '.
4587: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 4588: '</tr></table></td>'."\n";
1.221 raeburn 4589: } else {
1.222 raeburn 4590: $row .= '<td><input type="text" size="10" '.
4591: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 4592: }
4593: }
1.222 raeburn 4594: $row .= <<ENDTIMEENTRY;
4595: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 4596: <a href=
4597: "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 4598: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 4599: <a href=
4600: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
4601: ENDTIMEENTRY
1.222 raeburn 4602: $row .= &Apache::loncommon::end_data_table_row();
4603: return $row;
1.221 raeburn 4604: }
4605:
1.88 raeburn 4606: sub course_level_dc {
4607: my ($dcdom) = @_;
1.190 raeburn 4608: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 4609: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 4610: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
4611: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 4612: '<input type="hidden" name="dccourse" value="" />';
1.88 raeburn 4613: my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.131 raeburn 4614: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
4615: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
1.88 raeburn 4616: my %lt=&Apache::lonlocal::texthash(
4617: 'rol' => "Role",
1.113 raeburn 4618: 'grs' => "Section",
1.88 raeburn 4619: 'exs' => "Existing sections",
4620: 'new' => "Define new section",
4621: 'sta' => "Start",
4622: 'end' => "End",
4623: 'ssd' => "Set Start Date",
4624: 'sed' => "Set End Date"
4625: );
1.131 raeburn 4626: my $header = '<h4>'.&mt('Course Level').'</h4>'.
1.136 raeburn 4627: &Apache::loncommon::start_data_table().
4628: &Apache::loncommon::start_data_table_header_row().
1.143 raeburn 4629: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.136 raeburn 4630: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 4631: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.131 raeburn 4632: '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1.88 raeburn 4633: '<td><select name="role">'."\n";
1.213 raeburn 4634: foreach my $role (@roles) {
1.135 raeburn 4635: my $plrole=&Apache::lonnet::plaintext($role);
4636: $otheritems .= ' <option value="'.$role.'">'.$plrole;
1.88 raeburn 4637: }
4638: if ( keys %customroles > 0) {
1.135 raeburn 4639: foreach my $cust (sort keys %customroles) {
1.101 albertel 4640: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 4641: '_'.$env{'user.name'}.'_'.$cust;
4642: $otheritems .= ' <option value="'.$custrole.'">'.$cust;
1.88 raeburn 4643: }
4644: }
4645: $otheritems .= '</select></td><td>'.
4646: '<table border="0" cellspacing="0" cellpadding="0">'.
4647: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
4648: ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
4649: '<td> </td>'.
4650: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 4651: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 4652: '<input type="hidden" name="section" value="" />'.
1.113 raeburn 4653: '<input type="hidden" name="groups" value="" /></td>'.
1.88 raeburn 4654: '</tr></table></td>';
4655: $otheritems .= <<ENDTIMEENTRY;
1.169 albertel 4656: <td><input type="hidden" name="start" value='' />
1.88 raeburn 4657: <a href=
4658: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.169 albertel 4659: <td><input type="hidden" name="end" value='' />
1.88 raeburn 4660: <a href=
4661: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
4662: ENDTIMEENTRY
1.136 raeburn 4663: $otheritems .= &Apache::loncommon::end_data_table_row().
4664: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 4665: return $cb_jscript.$header.$hiddenitems.$otheritems;
4666: }
4667:
1.237 raeburn 4668: sub update_selfenroll_config {
1.241 raeburn 4669: my ($r,$context,$permission) = @_;
1.237 raeburn 4670: my ($row,$lt) = &get_selfenroll_titles();
1.241 raeburn 4671: my %curr_groups = &Apache::longroup::coursegroups();
1.237 raeburn 4672: my (%changes,%warning);
4673: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4674: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.241 raeburn 4675: my $curr_types;
1.237 raeburn 4676: if (ref($row) eq 'ARRAY') {
4677: foreach my $item (@{$row}) {
4678: if ($item eq 'enroll_dates') {
4679: my (%currenrolldate,%newenrolldate);
4680: foreach my $type ('start','end') {
4681: $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
4682: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
4683: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
4684: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
4685: }
4686: }
4687: } elsif ($item eq 'access_dates') {
4688: my (%currdate,%newdate);
4689: foreach my $type ('start','end') {
4690: $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
4691: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
4692: if ($newdate{$type} ne $currdate{$type}) {
4693: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
4694: }
4695: }
1.241 raeburn 4696: } elsif ($item eq 'types') {
4697: $curr_types =
4698: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
4699: if ($env{'form.selfenroll_all'}) {
4700: if ($curr_types ne '*') {
4701: $changes{'internal.selfenroll_types'} = '*';
4702: } else {
4703: next;
4704: }
4705: } else {
1.249 raeburn 4706: my %currdoms;
1.241 raeburn 4707: my @entries = split(/;/,$curr_types);
4708: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 4709: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 4710: my $newnum = 0;
1.249 raeburn 4711: my @latesttypes;
4712: foreach my $num (@activations) {
4713: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
4714: if (@types > 0) {
1.241 raeburn 4715: @types = sort(@types);
4716: my $typestr = join(',',@types);
1.249 raeburn 4717: my $typedom = $env{'form.selfenroll_dom_'.$num};
4718: $latesttypes[$newnum] = $typedom.':'.$typestr;
4719: $currdoms{$typedom} = 1;
1.241 raeburn 4720: $newnum ++;
4721: }
4722: }
1.249 raeburn 4723: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) { if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
4724: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
4725: if (@types > 0) {
4726: @types = sort(@types);
4727: my $typestr = join(',',@types);
4728: my $typedom = $env{'form.selfenroll_dom_'.$j};
4729: $latesttypes[$newnum] = $typedom.':'.$typestr;
4730: $currdoms{$typedom} = 1;
4731: $newnum ++;
4732: }
4733: }
4734: }
4735: if ($env{'form.selfenroll_newdom'} ne '') {
4736: my $typedom = $env{'form.selfenroll_newdom'};
4737: if ((!defined($currdoms{$typedom})) &&
4738: (&Apache::lonnet::domain($typedom) ne '')) {
4739: my $typestr;
4740: my ($othertitle,$usertypes,$types) =
4741: &Apache::loncommon::sorted_inst_types($typedom);
4742: my $othervalue = 'any';
4743: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4744: if (@{$types} > 0) {
1.257 raeburn 4745: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 4746: $othervalue = 'other';
1.258 ! raeburn 4747: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 4748: }
4749: $typestr = $othervalue;
4750: } else {
4751: $typestr = $othervalue;
4752: }
4753: $latesttypes[$newnum] = $typedom.':'.$typestr;
4754: $newnum ++ ;
4755: }
4756: }
1.241 raeburn 4757: my $selfenroll_types = join(';',@latesttypes);
4758: if ($selfenroll_types ne $curr_types) {
4759: $changes{'internal.selfenroll_types'} = $selfenroll_types;
4760: }
4761: }
1.237 raeburn 4762: } else {
4763: my $curr_val =
4764: $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
4765: my $newval = $env{'form.selfenroll_'.$item};
4766: if ($item eq 'section') {
4767: $newval = $env{'form.sections'};
1.241 raeburn 4768: if (defined($curr_groups{$newval})) {
1.237 raeburn 4769: $newval = $curr_val;
4770: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.&mt('Group names and section names must be distinct');
4771: } elsif ($newval eq 'all') {
4772: $newval = $curr_val;
4773: $warning{$item} = &mt("Section for self-enrolled users unchanged, as 'all' is a reserved section name.");
4774: }
4775: if ($newval eq '') {
4776: $newval = 'none';
4777: }
4778: }
4779: if ($newval ne $curr_val) {
4780: $changes{'internal.selfenroll_'.$item} = $newval;
4781: }
1.241 raeburn 4782: }
1.237 raeburn 4783: }
4784: if (keys(%warning) > 0) {
4785: foreach my $item (@{$row}) {
4786: if (exists($warning{$item})) {
4787: $r->print($warning{$item}.'<br />');
4788: }
4789: }
4790: }
4791: if (keys(%changes) > 0) {
4792: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
4793: if ($putresult eq 'ok') {
4794: if ((exists($changes{'internal.selfenroll_types'})) ||
4795: (exists($changes{'internal.selfenroll_start_date'})) ||
4796: (exists($changes{'internal.selfenroll_end_date'}))) {
4797: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
4798: $cnum,undef,undef,'Course');
4799: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
4800: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
4801: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
4802: if (exists($changes{'internal.'.$item})) {
4803: $crsinfo{$env{'request.course.id'}}{$item} =
4804: $changes{'internal.'.$item};
4805: }
4806: }
4807: my $crsputresult =
4808: &Apache::lonnet::courseidput($cdom,\%crsinfo,
4809: $chome,'notime');
4810: }
4811: }
4812: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
4813: foreach my $item (@{$row}) {
4814: my $title = $item;
4815: if (ref($lt) eq 'HASH') {
4816: $title = $lt->{$item};
4817: }
4818: if ($item eq 'enroll_dates') {
4819: foreach my $type ('start','end') {
4820: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
4821: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 4822: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 4823: $title,$type,$newdate).'</li>');
4824: }
4825: }
4826: } elsif ($item eq 'access_dates') {
4827: foreach my $type ('start','end') {
4828: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
4829: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 4830: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 4831: $title,$type,$newdate).'</li>');
4832: }
4833: }
4834: } else {
4835: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 4836: my $newval = $changes{'internal.selfenroll_'.$item};
4837: if ($item eq 'types') {
4838: if ($newval eq '') {
4839: $newval = &mt('None');
4840: } elsif ($newval eq '*') {
4841: $newval = &mt('Any user in any domain');
4842: }
1.245 raeburn 4843: } elsif ($item eq 'registered') {
4844: if ($newval eq '1') {
4845: $newval = &mt('Yes');
4846: } elsif ($newval eq '0') {
4847: $newval = &mt('No');
4848: }
1.241 raeburn 4849: }
1.244 bisitz 4850: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 4851: }
4852: }
4853: }
4854: $r->print('</ul>');
4855: my %newenvhash;
4856: foreach my $key (keys(%changes)) {
4857: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
4858: }
1.238 raeburn 4859: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 4860: } else {
4861: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
4862: }
4863: } else {
1.249 raeburn 4864: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 4865: }
4866: } else {
1.249 raeburn 4867: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 4868: }
1.256 raeburn 4869: my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
4870: if (ref($visactions) eq 'HASH') {
4871: if (!$visible) {
4872: $r->print('<br />'.$visactions->{'miss'}.'<br />'.$visactions->{'yous'}.
4873: '<br />');
4874: if (ref($vismsgs) eq 'ARRAY') {
4875: $r->print('<br />'.$visactions->{'take'}.'<ul>');
4876: foreach my $item (@{$vismsgs}) {
4877: $r->print('<li>'.$visactions->{$item}.'</li>');
4878: }
4879: $r->print('</ul>');
4880: }
4881: $r->print($cansetvis);
4882: }
4883: }
1.237 raeburn 4884: return;
4885: }
4886:
4887: sub get_selfenroll_titles {
4888: my @row = ('types','registered','enroll_dates','access_dates','section');
4889: my %lt = &Apache::lonlocal::texthash (
4890: types => 'Users allowed to self-enroll in this course',
1.245 raeburn 4891: registered => 'Restrict self-enrollment to students officially registered for the course',
1.237 raeburn 4892: enroll_dates => 'Dates self-enrollment available',
1.256 raeburn 4893: access_dates => 'Course access dates assigned to self-enrolling users',
4894: section => 'Section assigned to self-enrolling users',
1.237 raeburn 4895: );
4896: return (\@row,\%lt);
4897: }
4898:
1.27 matthew 4899: #---------------------------------------------- end functions for &phase_two
1.29 matthew 4900:
4901: #--------------------------------- functions for &phase_two and &phase_three
4902:
4903: #--------------------------end of functions for &phase_two and &phase_three
1.1 www 4904:
4905: 1;
4906: __END__
1.2 www 4907:
4908:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>