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