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