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