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