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