Diff for /loncom/interface/loncreateuser.pm between versions 1.295.2.23 and 1.295.2.24

version 1.295.2.23, 2010/01/19 21:29:50 version 1.295.2.24, 2010/01/19 22:41:02
Line 51  In LON-CAPA, roles are actually collecti Line 51  In LON-CAPA, roles are actually collecti
 Assistant", "Course Coordinator", and other such roles are really just  Assistant", "Course Coordinator", and other such roles are really just
 collection of privileges that are useful in many circumstances.  collection of privileges that are useful in many circumstances.
   
 Creating custom roles can be done by the Domain Coordinator through  Custom roles can be defined by a Domain Coordinator, Course Coordinator
 the Create User functionality. That screen will show all privileges  or Community Coordinator via the Manage User functionality.
 that can be assigned to users. For a complete list of privileges,  The custom role editor screen will show all privileges which can be
 please see C</home/httpd/lonTabs/rolesplain.tab>.  assigned to users. For a complete list of privileges, please see 
   C</home/httpd/lonTabs/rolesplain.tab>.
   
 Custom role definitions are stored in the C<roles.db> file of the role  Custom role definitions are stored in the C<roles.db> file of the creator
 author.  of the role.
   
 =cut  =cut
   
Line 485  sub print_username_entry_form { Line 486  sub print_username_entry_form {
         '// ]]>'."\n".          '// ]]>'."\n".
         '</script>'."\n";          '</script>'."\n";
   
       my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
       if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
           && (&Apache::lonnet::allowed('mcr','/'))) {
           $jscript .= &customrole_javascript();
       }
     my %loaditems = (      my %loaditems = (
                 'onload' => "javascript:setFormElements(document.$formtoset)",                  'onload' => "javascript:setFormElements(document.$formtoset)",
                     );                      );
Line 510  sub print_username_entry_form { Line 516  sub print_username_entry_form {
     }      }
     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',      my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
                                                      $helpitem);                                                       $helpitem);
     my %existingroles=&Apache::lonuserutils::my_custom_roles();  
     my $choice=&Apache::loncommon::select_form('make new role','rolename',  
  ('make new role' => 'Generate new role ...',%existingroles));  
     my %lt=&Apache::lonlocal::texthash(      my %lt=&Apache::lonlocal::texthash(
                     'srst' => 'Search for a user and enroll as a student',                      'srst' => 'Search for a user and enroll as a student',
                     'srme' => 'Search for a user and enroll as a member',                      'srme' => 'Search for a user and enroll as a member',
Line 520  sub print_username_entry_form { Line 523  sub print_username_entry_form {
                     'srad' => 'Search for a user and modify/add user information or roles',                      'srad' => 'Search for a user and modify/add user information or roles',
     'usr'  => "Username",      'usr'  => "Username",
                     'dom'  => "Domain",                      'dom'  => "Domain",
                     'ecrp' => "Edit Custom Role Privileges",                      'ecrp' => "Define or Edit Custom Role",
                     'nr'   => "Name of Role",                      'nr'   => "role name",
                     'cre'  => "Next",                      'cre'  => "Next",
        );         );
     $r->print($start_page."\n".$crumbs);      $r->print($start_page."\n".$crumbs);
     if ($env{'form.action'} eq 'custom') {      if ($env{'form.action'} eq 'custom') {
         if (&Apache::lonnet::allowed('mcr','/')) {          if (&Apache::lonnet::allowed('mcr','/')) {
             $r->print(<<ENDCUSTOM);              my $newroletext = &mt('Define new custom role:');
 <form action="/adm/createuser" method="post" name="docustom">              $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
 <input type="hidden" name="action" value="$env{'form.action'}" />                        '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
 <input type="hidden" name="phase" value="selected_custom_edit" />                        '<input type="hidden" name="phase" value="selected_custom_edit" />'.
 <h3>$lt{'ecrp'}</h3>                        '<h3>'.$lt{'ecrp'}.'</h3>'.
 $choice $lt{'nr'}: <input type="text" size="15" name="newrolename" /><br />                        &Apache::loncommon::start_data_table().
 <input name="customeditor" type="submit" value="$lt{'cre'}" />                        &Apache::loncommon::start_data_table_row().
 </form>                        '<td>');
 ENDCUSTOM              if (keys(%existingroles) > 0) {
                   $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
               } else {
                   $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
               }
               $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
                         &Apache::loncommon::end_data_table_row());
               if (keys(%existingroles) > 0) {
                   $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
                             '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
                             &mt('View/Modify existing role:').'</b></label></td>'.
                             '<td align="center"><br />'.
                             '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
                             '<option value="" selected="selected">'.
                             &mt('Select'));
                   foreach my $role (sort(keys(%existingroles))) {
                       $r->print('<option value="'.$role.'">'.$role.'</option>');
                   }
                   $r->print('</select>'.
                             '</td>'.
                             &Apache::loncommon::end_data_table_row());
               }
               $r->print(&Apache::loncommon::end_data_table().'<p>'.
                         '<input name="customeditor" type="submit" value="'.
                         $lt{'cre'}.'" /></p>'.
                         '</form>');
         }          }
     } else {      } else {
         my $actiontext = $lt{'srad'};          my $actiontext = $lt{'srad'};
Line 555  ENDCUSTOM Line 583  ENDCUSTOM
     $r->print(&Apache::loncommon::end_page());      $r->print(&Apache::loncommon::end_page());
 }  }
   
   sub customrole_javascript {
       my $js = <<"END";
   <script type="text/javascript">
   // <![CDATA[
   
   function setCustomFields() {
       if (document.docustom.customroleaction.length > 0) {
           for (var i=0; i<document.docustom.customroleaction.length; i++) {
               if (document.docustom.customroleaction[i].checked) {
                   if (document.docustom.customroleaction[i].value == 'new') {
                       document.docustom.rolename.selectedIndex = 0;
                   } else {
                       document.docustom.newrolename.value = '';
                   }
               }
           }
       }
       return;
   }
   
   function setCustomAction(caller) {
       if (document.docustom.customroleaction.length > 0) {
           for (var i=0; i<document.docustom.customroleaction.length; i++) {
               if (document.docustom.customroleaction[i].value == caller) {
                   document.docustom.customroleaction[i].checked = true;
               }
           }
       }
       setCustomFields();
       return;
   }
   
   // ]]>
   </script>
   END
       return $js;
   }
   
 sub entry_form {  sub entry_form {
     my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype) = @_;      my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype) = @_;
     my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);      my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
Line 3472  sub build_roles { Line 3538  sub build_roles {
   
 sub custom_role_editor {  sub custom_role_editor {
     my ($r) = @_;      my ($r) = @_;
     my $rolename=$env{'form.rolename'};      my $action = $env{'form.customroleaction'};
       my $rolename;
     if ($rolename eq 'make new role') {      if ($action eq 'new') {
  $rolename=$env{'form.newrolename'};          $rolename=$env{'form.newrolename'};
       } else {
           $rolename=$env{'form.rolename'};
     }      }
   
     $rolename=~s/[^A-Za-z0-9]//gs;      $rolename=~s/[^A-Za-z0-9]//gs;
   
     if (!$rolename || $env{'form.phase'} eq 'pickrole') {      if (!$rolename || $env{'form.phase'} eq 'pickrole') {
  &print_username_entry_form($r);   &print_username_entry_form($r);
         return;          return;
     }      }
       my ($crstype,$context);
       if ($env{'request.course.id'}) {
           $crstype = &Apache::loncommon::course_type();
           $context = 'course';
       } else {
           $context = 'domain';
           $crstype = $env{'form.templatecrstype'};
       }
 # ------------------------------------------------------- What can be assigned?  # ------------------------------------------------------- What can be assigned?
     my %full=();      my %full=();
     my %courselevel=();      my %courselevel=();
Line 3501  sub custom_role_editor { Line 3576  sub custom_role_editor {
  $body_top .= &mt('Existing Role').' "';   $body_top .= &mt('Existing Role').' "';
 # ------------------------------------------------- Get current role privileges  # ------------------------------------------------- Get current role privileges
  ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);   ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
           if ($crstype eq 'Community') {
               $syspriv =~ s/bre\&S//;
           }
     } else {      } else {
  $body_top .= &mt('New Role').' "';   $body_top .= &mt('New Role').' "';
  $roledef='';   $roledef='';
Line 3542  sub custom_role_editor { Line 3620  sub custom_role_editor {
     my $head_script = "\n";      my $head_script = "\n";
     $head_script .= '<script type="text/javascript">'."\n".      $head_script .= '<script type="text/javascript">'."\n".
                     '// <![CDATA['."\n";                      '// <![CDATA['."\n";
     my $crstype;      my @template_roles = ("in","ta","ep");
     if ($env{'request.course.id'}) {      if ($context eq 'domain') {
         $crstype = &Apache::loncommon::course_type();          push(@template_roles,"ad");
     }      }
     my @template_roles = ("in","ta","ep","st");      push(@template_roles,"st");
     if ($crstype eq 'Community') {      if ($crstype eq 'Community') {
         unshift(@template_roles,'co');          unshift(@template_roles,'co');
     } else {      } else {
         unshift(@template_roles,'cc');          unshift(@template_roles,'cc');
     }      }
     foreach my $role (@template_roles) {      foreach my $role (@template_roles) {
         $head_script .= &make_script_template($role);          $head_script .= &make_script_template($role,$crstype);
         $button_code .= &make_button_code($role,$crstype).' ';          $button_code .= &make_button_code($role,$crstype).' ';
     }      }
       my $context_code;
       if ($context eq 'domain') {
           my $checkedCommunity = '';
           my $checkedCourse = ' checked="checked"';
           if ($env{'form.templatecrstype'} eq 'Community') {
               $checkedCommunity = $checkedCourse;
               $checkedCourse = '';
           }
           $context_code = '<label>'.
                           '<input type="radio" name="templatecrstype" value="Course"'.$checkedCourse.' onclick="this.form.submit();">'.
                           &mt('Course').
                           '</label>'.('&nbsp;' x2).
                           '<label>'.
                           '<input type="radio" name="templatecrstype" value="Community"'.$checkedCommunity.' onclick="this.form.submit();">'.
                           &mt('Community').
                           '</label>'.
                           '</fieldset>'.
                           '<input type="hidden" name="customroleaction" value="'.
                           $action.'" />';
           if ($env{'form.customroleaction'} eq 'new') {
               $context_code .= '<input type="hidden" name="newrolename" value="'.
                                $rolename.'" />';
           } else {
               $context_code .= '<input type="hidden" name="rolename" value="'.
                                $rolename.'" />';
           }
           $context_code .= '<input type="hidden" name="action" value="custom" />'.
                            '<input type="hidden" name="phase" value="selected_custom_edit" />';
       }
     $head_script .= "\n".$jsback."\n".      $head_script .= "\n".$jsback."\n".
                     '// ]]>'."\n".                      '// ]]>'."\n".
                     '</script>'."\n";                      '</script>'."\n";
     $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));      $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
    &Apache::lonhtmlcommon::add_breadcrumb      &Apache::lonhtmlcommon::add_breadcrumb
      ({href=>"javascript:backPage(document.form1,'pickrole','')",       ({href=>"javascript:backPage(document.form1,'pickrole','')",
        text=>"Pick custom role",         text=>"Pick custom role",
        faq=>282,bug=>'Instructor Interface',},         faq=>282,bug=>'Instructor Interface',},
Line 3577  sub custom_role_editor { Line 3684  sub custom_role_editor {
                     'dml'  => "Domain Level",                      'dml'  => "Domain Level",
                     'ssl'  => "System Level");                      'ssl'  => "System Level");
   
     $r->print('<div>'      $r->print('<div class="LC_left_float">'
              .'<form action=""><fieldset>'               .'<form action=""><fieldset>'
              .'<legend>'.&mt('Select a Template').'</legend>'               .'<legend>'.&mt('Select a Template').'</legend>'
              .$button_code               .$button_code
              .'</fieldset></form>'               .'</fieldset></form></div>');
              .'</div>'      if ($context_code) {
     );          $r->print('<div class="LC_left_float">'
                    .'<form action="/adm/createuser" method="post"><fieldset>'
                    .'<legend>'.&mt('Context').'</legend>'
                    .$context_code
                    .'</form>'
                    .'</div>'
           );
       }
       $r->print('<br clear="all" />');
   
     $r->print(<<ENDCCF);      $r->print(<<ENDCCF);
 <form name="form1" method="post">  <form name="form1" method="post">
Line 3604  ENDCCF Line 3719  ENDCCF
     '</td><td>'.      '</td><td>'.
     ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.      ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.
     ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':'&nbsp;').      ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':'&nbsp;').
     '</td><td>'.      '</td><td>');
     ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.          if ($priv eq 'bre' && $crstype eq 'Community') {
     ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':'&nbsp;').              $r->print('&nbsp;');
     '</td>'.          } else {
              &Apache::loncommon::end_data_table_row());              $r->print($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
                         ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':'&nbsp;');
           }
           $r->print('</td>'.
                     &Apache::loncommon::end_data_table_row());
     }      }
     $r->print(&Apache::loncommon::end_data_table().      $r->print(&Apache::loncommon::end_data_table().
    '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.     '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
Line 3620  ENDCCF Line 3739  ENDCCF
 }  }
 # --------------------------------------------------------  # --------------------------------------------------------
 sub make_script_template {  sub make_script_template {
     my ($role) = @_;      my ($role,$crstype) = @_;
     my %full_c=();      my %full_c=();
     my %full_d=();      my %full_d=();
     my %full_s=();      my %full_s=();
Line 3634  sub make_script_template { Line 3753  sub make_script_template {
         $full_d{$priv}=1;          $full_d{$priv}=1;
     }      }
     foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {      foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
           next if (($crstype eq 'Community') && ($item eq 'bre&S'));
         my ($priv,$restrict)=split(/\&/,$item);          my ($priv,$restrict)=split(/\&/,$item);
         $full_s{$priv}=1;          $full_s{$priv}=1;
     }      }
Line 5734  sub course_level_table { Line 5854  sub course_level_table {
             }              }
         }          }
         if (&Apache::lonnet::allowed('ccr',$thiscourse)) {          if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
             foreach my $cust (sort keys %customroles) {              foreach my $cust (sort(keys(%customroles))) {
                   next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
                 my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;                  my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
                 $table .= &course_level_row($protectedcourse,$role,$area,$domain,                  $table .= &course_level_row($protectedcourse,$role,$area,$domain,
                                             $cust,\%sections_count,\%lt);                                              $cust,\%sections_count,\%lt);

Removed from v.1.295.2.23  
changed lines
  Added in v.1.295.2.24


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>