[LON-CAPA-cvs] cvs: loncom /interface loncreateuser.pm
banghart
lon-capa-cvs-allow@mail.lon-capa.org
Mon, 11 Jun 2007 19:41:37 -0000
banghart Mon Jun 11 15:41:37 2007 EDT
Modified files:
/loncom/interface loncreateuser.pm
Log:
Saving work in progress. Generalized role template.
Need to include the buttons in the routine, and complete
domain and system role privileges. Also need to add
more role templates.
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.152 loncom/interface/loncreateuser.pm:1.153
--- loncom/interface/loncreateuser.pm:1.152 Thu Jun 7 19:11:05 2007
+++ loncom/interface/loncreateuser.pm Mon Jun 11 15:41:35 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.152 2007/06/07 23:11:05 banghart Exp $
+# $Id: loncreateuser.pm,v 1.153 2007/06/11 19:41:35 banghart Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1611,47 +1611,29 @@
&print_username_entry_form($r);
return;
}
- my $head_script = "\n";
- $head_script .= '<script type="text/javascript">'."\n";
- $head_script .= 'function set_ta() {'."\n";
- my @ta_c = split(/:/,$Apache::lonnet::pr{'ta:c'});
- foreach my $priv_item (@ta_c) {
- my ($priv, $dummy) = split(/\&/,$priv_item);
- $head_script .= "document.form1.$priv"."_c.checked = true;\n";
- }
- my @ta_d = split(/:/,$Apache::lonnet::pr{'ta:d'});
- foreach my $priv_item (@ta_d) {
- my ($priv, $dummy) = split(/\&/,$priv_item);
- $head_script .= "document.form1.$priv"."_d.checked = true;\n";
- }
-
- $head_script .= '}'."\n";
- $head_script .= '</script>'."\n";
- $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
+# ------------------------------------------------------- What can be assigned?
+ my %full=();
+ my %courselevel=();
+ my %courselevelcurrent=();
my $syspriv='';
my $dompriv='';
my $coursepriv='';
+ my $body_top;
my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
my ($rdummy,$roledef)=
&Apache::lonnet::get('roles',["rolesdef_$rolename"]);
# ------------------------------------------------------- Does this role exist?
- $r->print('<h2>');
+ $body_top .= '<h2>';
if (($rdummy ne 'con_lost') && ($roledef ne '')) {
- $r->print(&mt('Existing Role').' "');
+ $body_top .= &mt('Existing Role').' "';
# ------------------------------------------------- Get current role privileges
($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
} else {
- $r->print(&mt('New Role').' "');
+ $body_top .= &mt('New Role').' "';
$roledef='';
}
- $r->print($rolename.'"</h2>');
-# ------------------------------------------------------- What can be assigned?
- my %full=();
- my %courselevel=();
- my %courselevelcurrent=();
- my @roles = ("ta:c","ta:d","ta:s");
+ $body_top .= $rolename.'"</h2>';
foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
-
my ($priv,$restrict)=split(/\&/,$item);
if (!$restrict) { $restrict='F'; }
$courselevel{$priv}=$restrict;
@@ -1682,6 +1664,13 @@
}
$full{$priv}=1;
}
+
+ my $head_script = "\n";
+ $head_script .= '<script type="text/javascript">'."\n";
+ $head_script .= &make_script_template('ta');
+ $head_script .= '</script>'."\n";
+ $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
+ $r->print($body_top);
my %lt=&Apache::lonlocal::texthash(
'prv' => "Privilege",
'crl' => "Course Level",
@@ -1718,6 +1707,49 @@
'<input type="submit" value="'.&mt('Define Role').'" /></form>'.
&Apache::loncommon::end_page());
}
+# --------------------------------------------------------
+sub make_script_template {
+ my ($role) = @_;
+ my %full_c=();
+ my %full_d=();
+ my %full_s=();
+ my $return_script;
+ foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
+ my ($priv,$restrict)=split(/\&/,$item);
+ $full_c{$priv}=1;
+ }
+ foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
+ my ($priv,$restrict)=split(/\&/,$item);
+ $full_d{$priv}=1;
+ }
+ foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
+ my ($priv,$restrict)=split(/\&/,$item);
+ $full_s{$priv}=1;
+ }
+ $return_script .= 'function set_'.$role.'() {'."\n";
+ my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'});
+ my %role_c;
+ foreach my $priv(@temp) {
+ my ($priv_item, $dummy) = split(/\&/,$priv);
+ $role_c{$priv_item} = 1;
+ }
+ foreach my $priv_item (keys(%full_c)) {
+ my ($priv, $dummy) = split(/\&/,$priv_item);
+ if (exists($role_c{$priv})) {
+ $return_script .= "document.form1.$priv"."_c.checked = true;\n";
+ } else {
+ $return_script .= "document.form1.$priv"."_c.checked = false;\n";
+ }
+ }
+ my @role_d = split(/:/,$Apache::lonnet::pr{$role.':d'});
+ foreach my $priv_item (@role_d) {
+ my ($priv, $dummy) = split(/\&/,$priv_item);
+ $return_script .= "document.form1.$priv"."_d.checked = true;\n";
+ }
+
+ $return_script .= '}'."\n";
+ return $return_script;
+}
# ---------------------------------------------------------- Call to definerole
sub set_custom_role {