version 1.60, 2003/07/18 13:45:14
|
version 1.63, 2003/07/19 00:51:05
|
Line 25
|
Line 25
|
# |
# |
# http://www.lon-capa.org/ |
# http://www.lon-capa.org/ |
# |
# |
# (Create a course |
|
# (My Desk |
|
# |
|
# (Internal Server Error Handler |
|
# |
|
# (Login Screen |
|
# 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14, |
|
# 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer) |
|
# |
|
# YEAR=2001 |
|
# 3/1/1 Gerd Kortemeyer) |
|
# |
|
# 3/1 Gerd Kortemeyer) |
|
# |
|
# 2/14 Gerd Kortemeyer) |
|
# |
|
# 2/14,2/17,2/19,2/20,2/21,2/22,2/23,3/2,3/17,3/24,04/12 Gerd Kortemeyer |
|
# April Guy Albertelli |
|
# 05/10,10/16 Gerd Kortemeyer |
|
# 02/11/02 Matthew Hall |
|
# |
|
# $Id$ |
|
### |
### |
|
|
package Apache::loncreateuser; |
package Apache::loncreateuser; |
Line 90 sub my_custom_roles {
|
Line 68 sub my_custom_roles {
|
my %rolehash=&Apache::lonnet::dump('roles'); |
my %rolehash=&Apache::lonnet::dump('roles'); |
foreach (keys %rolehash) { |
foreach (keys %rolehash) { |
if ($_=~/^rolesdef\_(\w+)$/) { |
if ($_=~/^rolesdef\_(\w+)$/) { |
$returnhash{$_}=$_; |
$returnhash{$1}=$1; |
} |
} |
} |
} |
return %returnhash; |
return %returnhash; |
Line 336 END
|
Line 314 END
|
} |
} |
# Compute the background color based on $area |
# Compute the background color based on $area |
$bgcol=$1.'_'.$2; |
$bgcol=$1.'_'.$2; |
$bgcol=~s/[^8-9b-e]//g; |
$bgcol=~s/[^7-9a-e]//g; |
$bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6); |
$bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6); |
if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) { |
if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) { |
$carea.='<br>Section/Group: '.$3; |
$carea.='<br>Section/Group: '.$3; |
} |
} |
Line 369 END
|
Line 347 END
|
} |
} |
} |
} |
my $row = ''; |
my $row = ''; |
$row.='<tr bgcolor=#"'.$bgcol.'"><td>'; |
$row.='<tr bgcolor="#'.$bgcol.'"><td>'; |
my $active=1; |
my $active=1; |
$active=0 if (($role_end_time) && ($now>$role_end_time)); |
$active=0 if (($role_end_time) && ($now>$role_end_time)); |
if (($active) && ($allowed)) { |
if (($active) && ($allowed)) { |
Line 864 sub custom_role_editor {
|
Line 842 sub custom_role_editor {
|
$rolename=$ENV{'form.newrolename'}; |
$rolename=$ENV{'form.newrolename'}; |
} |
} |
|
|
$rolename=~s/\W//gs; |
$rolename=~s/[^A-Za-z0-9]//gs; |
|
|
unless ($rolename) { |
unless ($rolename) { |
&print_username_entry_form($r); |
&print_username_entry_form($r); |
Line 873 sub custom_role_editor {
|
Line 851 sub custom_role_editor {
|
|
|
$r->print(&Apache::loncommon::bodytag( |
$r->print(&Apache::loncommon::bodytag( |
'Create Users, Change User Privileges').'<h2>'); |
'Create Users, Change User Privileges').'<h2>'); |
|
my $syspriv=''; |
|
my $dompriv=''; |
|
my $coursepriv=''; |
my ($rdummy,$roledef)= |
my ($rdummy,$roledef)= |
&Apache::lonnet::get('roles',["rolesdef_$rolename"]); |
&Apache::lonnet::get('roles',["rolesdef_$rolename"]); |
# ------------------------------------------------------- Does this role exist? |
# ------------------------------------------------------- Does this role exist? |
if (($rdummy ne 'con_lost') && ($roledef ne '')) { |
if (($rdummy ne 'con_lost') && ($roledef ne '')) { |
$r->print('Existing Role "'); |
$r->print('Existing Role "'); |
|
# ------------------------------------------------- Get current role privileges |
|
($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef); |
} else { |
} else { |
$r->print('New Role "'); |
$r->print('New Role "'); |
$roledef=''; |
$roledef=''; |
Line 886 sub custom_role_editor {
|
Line 869 sub custom_role_editor {
|
# ------------------------------------------------------- What can be assigned? |
# ------------------------------------------------------- What can be assigned? |
my %full=(); |
my %full=(); |
my %courselevel=(); |
my %courselevel=(); |
|
my %courselevelcurrent=(); |
foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) { |
foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) { |
my ($priv,$restrict)=split(/\&/,$_); |
my ($priv,$restrict)=split(/\&/,$_); |
unless ($restrict) { $restrict='F'; } |
unless ($restrict) { $restrict='F'; } |
$courselevel{$priv}=$restrict; |
$courselevel{$priv}=$restrict; |
|
if ($coursepriv=~/\:$priv/) { |
|
$courselevelcurrent{$priv}=1; |
|
} |
$full{$priv}=1; |
$full{$priv}=1; |
} |
} |
my %domainlevel=(); |
my %domainlevel=(); |
|
my %domainlevelcurrent=(); |
foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) { |
foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) { |
my ($priv,$restrict)=split(/\&/,$_); |
my ($priv,$restrict)=split(/\&/,$_); |
unless ($restrict) { $restrict='F'; } |
unless ($restrict) { $restrict='F'; } |
$domainlevel{$priv}=$restrict; |
$domainlevel{$priv}=$restrict; |
|
if ($dompriv=~/\:$priv/) { |
|
$domainlevelcurrent{$priv}=1; |
|
} |
$full{$priv}=1; |
$full{$priv}=1; |
} |
} |
$r->print('<table border="2"><tr><th>Privilege</th><th>Course Level</th><th>Domain Level</th></tr>'); |
my %systemlevel=(); |
|
my %systemlevelcurrent=(); |
|
foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) { |
|
my ($priv,$restrict)=split(/\&/,$_); |
|
unless ($restrict) { $restrict='F'; } |
|
$systemlevel{$priv}=$restrict; |
|
if ($syspriv=~/\:$priv/) { |
|
$systemlevelcurrent{$priv}=1; |
|
} |
|
$full{$priv}=1; |
|
} |
|
$r->print(<<ENDCCF); |
|
<form method="post"> |
|
<input type="hidden" name="phase" value="set_custom_roles" /> |
|
<input type="hidden" name="rolename" value="$rolename" /> |
|
<table border="2"> |
|
<tr><th>Privilege</th><th>Course Level</th><th>Domain Level</th> |
|
<th>System Level</th></tr> |
|
ENDCCF |
foreach (sort keys %full) { |
foreach (sort keys %full) { |
$r->print('<tr><td>'.&Apache::lonnet::plaintext($_).'</td><td>'. |
$r->print('<tr><td>'.&Apache::lonnet::plaintext($_).'</td><td>'. |
$courselevel{$_}.'</td><td>'.$domainlevel{$_}.'</td></tr>'); |
($courselevel{$_}?'<input type="checkbox" name="'.$_.':c" '. |
|
($courselevelcurrent{$_}?'checked="1"':'').' />':' '). |
|
'</td><td>'. |
|
($domainlevel{$_}?'<input type="checkbox" name="'.$_.':d" '. |
|
($domainlevelcurrent{$_}?'checked="1"':'').' />':' '). |
|
'</td><td>'. |
|
($systemlevel{$_}?'<input type="checkbox" name="'.$_.':s" '. |
|
($systemlevelcurrent{$_}?'checked="1"':'').' />':' '). |
|
'</td></tr>'); |
} |
} |
$r->print('</table>'); |
$r->print( |
$r->print('Not yet implemented.'); |
'<table><input type="submit" value="Define Role" /></form></body></html>'); |
|
} |
|
|
|
# ---------------------------------------------------------- Call to definerole |
|
sub set_custom_role { |
|
my $r=shift; |
|
|
|
my $rolename=$ENV{'form.rolename'}; |
|
|
|
$rolename=~s/[^A-Za-z0-9]//gs; |
|
|
|
unless ($rolename) { |
|
&print_username_entry_form($r); |
|
return; |
|
} |
|
|
|
$r->print(&Apache::loncommon::bodytag( |
|
'Create Users, Change User Privileges').'<h2>'); |
|
my ($rdummy,$roledef)= |
|
&Apache::lonnet::get('roles',["rolesdef_$rolename"]); |
|
# ------------------------------------------------------- Does this role exist? |
|
if (($rdummy ne 'con_lost') && ($roledef ne '')) { |
|
$r->print('Existing Role "'); |
|
} else { |
|
$r->print('New Role "'); |
|
$roledef=''; |
|
} |
|
$r->print($rolename.'"</h2>'); |
|
# ------------------------------------------------------- What can be assigned? |
|
my $sysrole=''; |
|
my $domrole=''; |
|
my $courole=''; |
|
|
|
foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) { |
|
my ($priv,$restrict)=split(/\&/,$_); |
|
unless ($restrict) { $restrict=''; } |
|
if ($ENV{'form.'.$priv.':c'}) { |
|
$courole.=':'.$_; |
|
} |
|
} |
|
|
|
foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) { |
|
my ($priv,$restrict)=split(/\&/,$_); |
|
unless ($restrict) { $restrict=''; } |
|
if ($ENV{'form.'.$priv.':d'}) { |
|
$domrole.=':'.$_; |
|
} |
|
} |
|
|
|
foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) { |
|
my ($priv,$restrict)=split(/\&/,$_); |
|
unless ($restrict) { $restrict=''; } |
|
if ($ENV{'form.'.$priv.':s'}) { |
|
$sysrole.=':'.$_; |
|
} |
|
} |
|
$r->print('<br />Defining Role: '. |
|
&Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole)); |
|
if ($ENV{'request.course.id'}) { |
|
my $url='/'.$ENV{'request.course.id'}; |
|
$url=~s/\_/\//g; |
|
$r->print('<br />Assigning Role to Self: '. |
|
&Apache::lonnet::assigncustomrole($ENV{'user.domain'}, |
|
$ENV{'user.name'}, |
|
$url, |
|
$ENV{'user.domain'}, |
|
$ENV{'user.name'}, |
|
$rolename)); |
|
} |
|
$r->print('</body></html>'); |
} |
} |
|
|
# ================================================================ Main Handler |
# ================================================================ Main Handler |
Line 935 sub handler {
|
Line 1021 sub handler {
|
&update_user_data($r); |
&update_user_data($r); |
} elsif ($ENV{'form.phase'} eq 'selected_custom_edit') { |
} elsif ($ENV{'form.phase'} eq 'selected_custom_edit') { |
&custom_role_editor($r); |
&custom_role_editor($r); |
|
} elsif ($ENV{'form.phase'} eq 'set_custom_roles') { |
|
&set_custom_role($r); |
} |
} |
} else { |
} else { |
$ENV{'user.error.msg'}= |
$ENV{'user.error.msg'}= |
Line 948 sub handler {
|
Line 1036 sub handler {
|
sub course_level_table { |
sub course_level_table { |
my %inccourses = @_; |
my %inccourses = @_; |
my $table = ''; |
my $table = ''; |
|
# Custom Roles? |
|
|
|
my %customroles=&my_custom_roles(); |
|
|
foreach (sort( keys(%inccourses))) { |
foreach (sort( keys(%inccourses))) { |
my $thiscourse=$_; |
my $thiscourse=$_; |
my $protectedcourse=$_; |
my $protectedcourse=$_; |
Line 956 sub course_level_table {
|
Line 1048 sub course_level_table {
|
my $area=$coursedata{'description'}; |
my $area=$coursedata{'description'}; |
if (!defined($area)) { $area='Unavailable course: '.$_; } |
if (!defined($area)) { $area='Unavailable course: '.$_; } |
my $bgcol=$thiscourse; |
my $bgcol=$thiscourse; |
$bgcol=~s/[^8-9b-e]//g; |
$bgcol=~s/[^7-9a-e]//g; |
$bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6); |
$bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6); |
foreach ('st','ta','ep','ad','in','cc') { |
foreach ('st','ta','ep','ad','in','cc') { |
if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) { |
if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) { |
my $plrole=&Apache::lonnet::plaintext($_); |
my $plrole=&Apache::lonnet::plaintext($_); |
Line 987 ENDTIMEENTRY
|
Line 1079 ENDTIMEENTRY
|
$table.= "</tr>\n"; |
$table.= "</tr>\n"; |
} |
} |
} |
} |
|
foreach (sort keys %customroles) { |
|
my $plrole=$_; |
|
$table .= <<ENDENTRY; |
|
<tr bgcolor="#$bgcol"> |
|
<td><input type="checkbox" name="act_$protectedcourse\_$_"></td> |
|
<td>$plrole</td> |
|
<td>$area</td> |
|
<td><input type="text" size="5" name="sec_$protectedcourse\_$_"></td> |
|
<td><input type=hidden name="start_$protectedcourse\_$_" value=''> |
|
<a href= |
|
"javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">Set Start Date</a></td> |
|
<td><input type=hidden name="end_$protectedcourse\_$_" value=''> |
|
<a href= |
|
"javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">Set End Date</a></td></tr> |
|
ENDENTRY |
|
} |
} |
} |
return '' if ($table eq ''); # return nothing if there is nothing |
return '' if ($table eq ''); # return nothing if there is nothing |
# in the table |
# in the table |