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