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