File:  [LON-CAPA] / loncom / interface / loncreateuser.pm
Revision 1.61: download - view: text, annotated - select for diffs
Fri Jul 18 19:50:28 2003 UTC (20 years, 11 months ago) by www
Branches: MAIN
CVS tags: HEAD
Work on bug #795

    1: # The LearningOnline Network with CAPA
    2: # Create a user
    3: #
    4: # $Id: loncreateuser.pm,v 1.61 2003/07/18 19:50:28 www Exp $
    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: #
   28: ###
   29: 
   30: package Apache::loncreateuser;
   31: 
   32: use strict;
   33: use Apache::Constants qw(:common :http);
   34: use Apache::lonnet;
   35: use Apache::loncommon;
   36: 
   37: my $loginscript; # piece of javascript used in two separate instances
   38: my $generalrule;
   39: my $authformnop;
   40: my $authformkrb;
   41: my $authformint;
   42: my $authformfsys;
   43: my $authformloc;
   44: 
   45: BEGIN {
   46:     $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
   47:     my $krbdefdom=$1;
   48:     $krbdefdom=~tr/a-z/A-Z/;
   49:     my %param = ( formname => 'document.cu',
   50:                   kerb_def_dom => $krbdefdom 
   51:                   );
   52: # no longer static due to configurable kerberos defaults
   53: #    $loginscript  = &Apache::loncommon::authform_header(%param);
   54:     $generalrule  = &Apache::loncommon::authform_authorwarning(%param);
   55:     $authformnop  = &Apache::loncommon::authform_nochange(%param);
   56: # no longer static due to configurable kerberos defaults
   57: #    $authformkrb  = &Apache::loncommon::authform_kerberos(%param);
   58:     $authformint  = &Apache::loncommon::authform_internal(%param);
   59:     $authformfsys = &Apache::loncommon::authform_filesystem(%param);
   60:     $authformloc  = &Apache::loncommon::authform_local(%param);
   61: }
   62: 
   63: 
   64: # ======================================================= Existing Custom Roles
   65: 
   66: sub my_custom_roles {
   67:     my %returnhash=();
   68:     my %rolehash=&Apache::lonnet::dump('roles');
   69:     foreach (keys %rolehash) {
   70: 	if ($_=~/^rolesdef\_(\w+)$/) {
   71: 	    $returnhash{$1}=$1;
   72: 	}
   73:     }
   74:     return %returnhash;
   75: }
   76: 
   77: # ==================================================== Figure out author access
   78: 
   79: sub authorpriv {
   80:     my ($auname,$audom)=@_;
   81:     if (($auname ne $ENV{'user.name'}) ||
   82:         (($audom ne $ENV{'user.domain'}) &&
   83:          ($audom ne $ENV{'request.role.domain'}))) { return ''; }
   84:     unless (&Apache::lonnet::allowed('cca',$audom)) { return ''; }
   85:     return 1;
   86: }
   87: 
   88: # =================================================================== Phase one
   89: 
   90: sub print_username_entry_form {
   91:     my $r=shift;
   92:     my $defdom=$ENV{'request.role.domain'};
   93:     my @domains = &Apache::loncommon::get_domains();
   94:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
   95:     my $bodytag =&Apache::loncommon::bodytag(
   96:                                   'Create Users, Change User Privileges');
   97:     my $selscript=&Apache::loncommon::studentbrowser_javascript();
   98:     my $sellink=&Apache::loncommon::selectstudent_link
   99:                                         ('crtuser','ccuname','ccdomain');
  100:     my %existingroles=&my_custom_roles();
  101:     my $choice=&Apache::loncommon::select_form('make new role','rolename',
  102: 		('make new role' => 'Generate new role ...',%existingroles));
  103:     $r->print(<<"ENDDOCUMENT");
  104: <html>
  105: <head>
  106: <title>The LearningOnline Network with CAPA</title>
  107: $selscript
  108: </head>
  109: $bodytag
  110: <form action="/adm/createuser" method="post" name="crtuser">
  111: <input type="hidden" name="phase" value="get_user_info">
  112: <h2>Set Individual User Roles</h2>
  113: <table>
  114: <tr><td>Username:</td><td><input type="text" size="15" name="ccuname">
  115: </td><td rowspan="2">$sellink</td></tr><tr><td>
  116: Domain:</td><td>$domform</td></tr>
  117: </table>
  118: <input name="userrole" type="submit" value="User Roles" />
  119: </form>
  120: <form action="/adm/createuser" method="post" name="docustom">
  121: <input type="hidden" name="phase" value="selected_custom_edit">
  122: <h2>Edit Custom Role Privileges</h2>
  123: Name of Role: $choice <input type="text" size="15" name="newrolename" /><br />
  124: <input name="customeditor" type="submit" value="Custom Role Editor" />
  125: </body>
  126: </html>
  127: ENDDOCUMENT
  128: }
  129: 
  130: # =================================================================== Phase two
  131: sub print_user_modification_page {
  132:     my $r=shift;
  133:     my $ccuname=$ENV{'form.ccuname'};
  134:     my $ccdomain=$ENV{'form.ccdomain'};
  135: 
  136:     $ccuname=~s/\W//gs;
  137:     $ccdomain=~s/\W//gs;
  138: 
  139:     unless (($ccuname) && ($ccdomain)) {
  140: 	&print_username_entry_form($r);
  141:         return;
  142:     }
  143: 
  144:     my $defdom=$ENV{'request.role.domain'};
  145: 
  146:     my ($krbdef,$krbdefdom) =
  147:        &Apache::loncommon::get_kerberos_defaults($defdom);
  148: 
  149:     my %param = ( formname => 'document.cu',
  150:                   kerb_def_dom => $krbdefdom,
  151:                   kerb_def_auth => $krbdef
  152:                   );
  153:     $loginscript  = &Apache::loncommon::authform_header(%param);
  154:     $authformkrb  = &Apache::loncommon::authform_kerberos(%param);
  155: 
  156:     $ccuname=~s/\W//g;
  157:     $ccdomain=~s/\W//g;
  158:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  159:     my $dochead =<<"ENDDOCHEAD";
  160: <html>
  161: <head>
  162: <title>The LearningOnline Network with CAPA</title>
  163: <script type="text/javascript" language="Javascript">
  164: 
  165:     function pclose() {
  166:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
  167:                  "height=350,width=350,scrollbars=no,menubar=no");
  168:         parmwin.close();
  169:     }
  170: 
  171:     $pjump_def
  172: 
  173:     function dateset() {
  174:         eval("document.cu."+document.cu.pres_marker.value+
  175:             ".value=document.cu.pres_value.value");
  176:         pclose();
  177:     }
  178: 
  179: </script>
  180: </head>
  181: ENDDOCHEAD
  182:     $r->print(&Apache::loncommon::bodytag(
  183:                                      'Create Users, Change User Privileges'));
  184:     my $forminfo =<<"ENDFORMINFO";
  185: <form action="/adm/createuser" method="post" name="cu">
  186: <input type="hidden" name="phase"       value="update_user_data">
  187: <input type="hidden" name="ccuname"     value="$ccuname">
  188: <input type="hidden" name="ccdomain"    value="$ccdomain">
  189: <input type="hidden" name="pres_value"  value="" >
  190: <input type="hidden" name="pres_type"   value="" >
  191: <input type="hidden" name="pres_marker" value="" >
  192: ENDFORMINFO
  193:     my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
  194:     my %incdomains; 
  195:     my %inccourses;
  196:     foreach (values(%Apache::lonnet::hostdom)) {
  197:        $incdomains{$_}=1;
  198:     }
  199:     foreach (keys(%ENV)) {
  200: 	if ($_=~/^user\.priv\.cm\.\/(\w+)\/(\w+)/) {
  201: 	    $inccourses{$1.'_'.$2}=1;
  202:         }
  203:     }
  204:     if ($uhome eq 'no_host') {
  205:         my $home_server_list=
  206:             '<option value="default" selected>default</option>'."\n".
  207:                 &Apache::loncommon::home_server_option_list($ccdomain);
  208:         
  209: 	$r->print(<<ENDNEWUSER);
  210: $dochead
  211: <h1>Create New User</h1>
  212: $forminfo
  213: <h2>New user "$ccuname" in domain $ccdomain</h2>
  214: <script type="text/javascript" language="Javascript">
  215: $loginscript
  216: </script>
  217: <input type='hidden' name='makeuser' value='1' />
  218: <h3>Personal Data</h3>
  219: <p>
  220: <table>
  221: <tr><td>First Name  </td>
  222:     <td><input type='text' name='cfirst'  size='15' /></td></tr>
  223: <tr><td>Middle Name </td> 
  224:     <td><input type='text' name='cmiddle' size='15' /></td></tr>
  225: <tr><td>Last Name   </td>
  226:     <td><input type='text' name='clast'   size='15' /></td></tr>
  227: <tr><td>Generation  </td>
  228:     <td><input type='text' name='cgen'    size='5'  /></td></tr>
  229: </table>
  230: ID/Student Number <input type='text' name='cstid'   size='15' /></p>
  231: Home Server: <select name="hserver" size="1"> $home_server_list </select>
  232: <hr />
  233: <h3>Login Data</h3>
  234: <p>$generalrule </p>
  235: <p>$authformkrb </p>
  236: <p>$authformint </p>
  237: <p>$authformfsys</p>
  238: <p>$authformloc </p>
  239: ENDNEWUSER
  240:     } else { # user already exists
  241: 	$r->print(<<ENDCHANGEUSER);
  242: $dochead
  243: <h1>Change User Privileges</h1>
  244: $forminfo
  245: <h2>User "$ccuname" in domain "$ccdomain"</h2>
  246: ENDCHANGEUSER
  247:         # Get the users information
  248:         my %userenv = &Apache::lonnet::get('environment',
  249:                           ['firstname','middlename','lastname','generation'],
  250:                           $ccdomain,$ccuname);
  251:         my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
  252:         $r->print(<<END);
  253: <hr />
  254: <table border="2">
  255: <tr>
  256: <th>first name</th><th>middle name</th><th>last name</th><th>generation</th>
  257: </tr>
  258: <tr>
  259: END
  260:         foreach ('firstname','middlename','lastname','generation') {
  261:            if (&Apache::lonnet::allowed('mau',$ccdomain)) {
  262:               $r->print(<<"END");            
  263: <td><input type="text" name="c$_" value="$userenv{$_}" size="15" /></td>
  264: END
  265:            } else {
  266:                $r->print('<td>'.$userenv{$_}.'</td>');
  267:            }
  268:         }
  269:         $r->print(<<END);
  270: </tr>
  271: </table>
  272: END
  273:         # Build up table of user roles to allow revocation of a role.
  274:         my ($tmp) = keys(%rolesdump);
  275:         unless ($tmp =~ /^(con_lost|error)/i) {
  276:            my $now=time;
  277:            $r->print(<<END);
  278: <hr />
  279: <h3>Revoke Existing Roles</h3>
  280: <table border=2>
  281: <tr><th>Revoke</th><th>Delete</th><th>Role</th><th>Extent</th><th>Start</th><th>End</th>
  282: END
  283: 	   foreach my $area (keys(%rolesdump)) {
  284:                next if ($area =~ /^rolesdef/);
  285:                my $role = $rolesdump{$area};
  286:                my $thisrole=$area;
  287:                $area =~ s/\_\w\w$//;
  288:                my ($role_code,$role_end_time,$role_start_time) = 
  289:                    split(/_/,$role);
  290:                my $bgcol='ffffff';
  291:                my $allowed=0;
  292:                my $delallowed=0;
  293:                if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {
  294:                    my ($coursedom,$coursedir) = ($1,$2);
  295:                    # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
  296:                    my %coursedata=
  297:                        &Apache::lonnet::coursedescription($1.'_'.$2);
  298: 		   my $carea;
  299: 		   if (defined($coursedata{'description'})) {
  300: 		       $carea='Course: '.$coursedata{'description'}.
  301:                            '<br />Domain: '.$coursedom.('&nbsp;'x8).
  302:      &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
  303: 		   } else {
  304: 		       $carea='Unavailable course: '.$area;
  305: 		   }
  306:                    $inccourses{$1.'_'.$2}=1;
  307:                    if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
  308:                        (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
  309:                        $allowed=1;
  310:                    }
  311:                    if ((&Apache::lonnet::allowed('dro',$1)) ||
  312:                        (&Apache::lonnet::allowed('dro',$ccdomain))) {
  313:                        $delallowed=1;
  314:                    }
  315:                    # Compute the background color based on $area
  316:                    $bgcol=$1.'_'.$2;
  317:                    $bgcol=~s/[^8-9b-e]//g;
  318:                    $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
  319:                    if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
  320:                        $carea.='<br>Section/Group: '.$3;
  321:                    }
  322:                    $area=$carea;
  323:                } else {
  324:                    # Determine if current user is able to revoke privileges
  325:                    if ($area=~ /^\/(\w+)\//) {
  326:                        if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
  327:                        (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
  328:                            $allowed=1;
  329:                        }
  330:                        if (((&Apache::lonnet::allowed('dro',$1))  ||
  331:                             (&Apache::lonnet::allowed('dro',$ccdomain))) &&
  332:                            ($role_code ne 'dc')) {
  333:                            $delallowed=1;
  334:                        }
  335:                    } else {
  336:                        if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
  337:                            $allowed=1;
  338:                        }
  339:                    }
  340:                }
  341:                if ($role_code eq 'ca') {
  342:                    $area=~/\/(\w+)\/(\w+)/;
  343: 		   if (&authorpriv($2,$1)) {
  344: 		       $allowed=1;
  345:                    } else {
  346:                        $allowed=0;
  347:                    }
  348:                }
  349:                my $row = '';
  350:                $row.='<tr bgcolor=#"'.$bgcol.'"><td>';
  351:                my $active=1;
  352:                $active=0 if (($role_end_time) && ($now>$role_end_time));
  353:                if (($active) && ($allowed)) {
  354:                    $row.= '<input type="checkbox" name="rev:'.$thisrole.'">';
  355:                } else {
  356:                    if ($active) {
  357:                       $row.='&nbsp;';
  358: 		   } else {
  359:                       $row.='expired or revoked';
  360: 		   }
  361:                }
  362: 	       $row.='</td><td>';
  363:                if ($delallowed) {
  364:                    $row.= '<input type="checkbox" name="del:'.$thisrole.'">';
  365:                } else {
  366:                    $row.='&nbsp;';
  367:                }
  368:                $row.= '</td><td>'.&Apache::lonnet::plaintext($role_code).
  369:                       '</td><td>'.$area.
  370:                       '</td><td>'.($role_start_time?localtime($role_start_time)
  371:                                                    : '&nbsp;' ).
  372:                       '</td><td>'.($role_end_time  ?localtime($role_end_time)
  373:                                                    : '&nbsp;' )
  374:                       ."</td></tr>\n";
  375:                $r->print($row);
  376:            } # end of foreach        (table building loop)
  377: 	   $r->print('</table>');
  378:         }  # End of unless
  379: 	my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
  380: 	if ($currentauth=~/^krb(4|5):/) {
  381: 	    $currentauth=~/^krb(4|5):(.*)/;
  382: 	    my $krbdefdom=$1;
  383:             my %param = ( formname => 'document.cu',
  384:                           kerb_def_dom => $krbdefdom 
  385:                           );
  386:             $loginscript  = &Apache::loncommon::authform_header(%param);
  387: 	}
  388: 	# Check for a bad authentication type
  389:         unless ($currentauth=~/^krb(4|5):/ or
  390: 		$currentauth=~/^unix:/ or
  391: 		$currentauth=~/^internal:/ or
  392: 		$currentauth=~/^localauth:/
  393: 		) { # bad authentication scheme
  394: 	    if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
  395: 		$r->print(<<ENDBADAUTH);
  396: <hr />
  397: <script type="text/javascript" language="Javascript">
  398: $loginscript
  399: </script>
  400: <font color='#ff0000'>ERROR:</font>
  401: This user has an unrecognized authentication scheme ($currentauth).
  402: Please specify login data below.
  403: <h3>Login Data</h3>
  404: <p>$generalrule</p>
  405: <p>$authformkrb</p>
  406: <p>$authformint</p>
  407: <p>$authformfsys</p>
  408: <p>$authformloc</p>
  409: ENDBADAUTH
  410:             } else { 
  411:                 # This user is not allowed to modify the users 
  412:                 # authentication scheme, so just notify them of the problem
  413: 		$r->print(<<ENDBADAUTH);
  414: <hr />
  415: <script type="text/javascript" language="Javascript">
  416: $loginscript
  417: </script>
  418: <font color="#ff0000"> ERROR: </font>
  419: This user has an unrecognized authentication scheme ($currentauth).
  420: Please alert a domain coordinator of this situation.
  421: <hr />
  422: ENDBADAUTH
  423:             }
  424:         } else { # Authentication type is valid
  425: 	    my $authformcurrent='';
  426: 	    my $authform_other='';
  427: 	    if ($currentauth=~/^krb(4|5):/) {
  428: 		$authformcurrent=$authformkrb;
  429: 		$authform_other="<p>$authformint</p>\n".
  430:                     "<p>$authformfsys</p><p>$authformloc</p>";
  431: 	    }
  432: 	    elsif ($currentauth=~/^internal:/) {
  433: 		$authformcurrent=$authformint;
  434: 		$authform_other="<p>$authformkrb</p>".
  435:                     "<p>$authformfsys</p><p>$authformloc</p>";
  436: 	    }
  437: 	    elsif ($currentauth=~/^unix:/) {
  438: 		$authformcurrent=$authformfsys;
  439: 		$authform_other="<p>$authformkrb</p>".
  440:                     "<p>$authformint</p><p>$authformloc;</p>";
  441: 	    }
  442: 	    elsif ($currentauth=~/^localauth:/) {
  443: 		$authformcurrent=$authformloc;
  444: 		$authform_other="<p>$authformkrb</p>".
  445:                     "<p>$authformint</p><p>$authformfsys</p>";
  446: 	    }
  447:             $authformcurrent.=' <i>(will override current values)</i><br />';
  448:             if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
  449: 		# Current user has login modification privileges
  450: 		$r->print(<<ENDOTHERAUTHS);
  451: <hr />
  452: <script type="text/javascript" language="Javascript">
  453: $loginscript
  454: </script>
  455: <h3>Change Current Login Data</h3>
  456: <p>$generalrule</p>
  457: <p>$authformnop</p>
  458: <p>$authformcurrent</p>
  459: <h3>Enter New Login Data</h3>
  460: $authform_other
  461: ENDOTHERAUTHS
  462:             }
  463:         }  ## End of "check for bad authentication type" logic
  464:     } ## End of new user/old user logic
  465:     $r->print('<hr /><h3>Add Roles</h3>');
  466: #
  467: # Co-Author
  468: # 
  469:     if (&authorpriv($ENV{'user.name'},$ENV{'request.role.domain'}) &&
  470:         ($ENV{'user.name'} ne $ccuname || $ENV{'user.domain'} ne $ccdomain)) {
  471:         # No sense in assigning co-author role to yourself
  472: 	my $cuname=$ENV{'user.name'};
  473:         my $cudom=$ENV{'request.role.domain'};
  474:        $r->print(<<ENDCOAUTH);
  475: <h4>Construction Space</h4>
  476: <table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>
  477: <th>Start</th><th>End</th></tr>
  478: <tr>
  479: <td><input type=checkbox name="act_$cudom\_$cuname\_ca"></td>
  480: <td>Co-Author</td>
  481: <td>$cudom\_$cuname</td>
  482: <td><input type=hidden name="start_$cudom\_$cuname\_ca" value=''>
  483: <a href=
  484: "javascript:pjump('date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset')">Set Start Date</a></td>
  485: <td><input type=hidden name="end_$cudom\_$cuname\_ca" value=''>
  486: <a href=
  487: "javascript:pjump('date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset')">Set End Date</a></td>
  488: </tr>
  489: </table>
  490: ENDCOAUTH
  491:     }
  492: #
  493: # Domain level
  494: #
  495:     $r->print('<h4>Domain Level</h4>'.
  496:     '<table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>'.
  497:     '<th>Start</th><th>End</th></tr>');
  498:     foreach ( sort( keys(%incdomains))) {
  499: 	my $thisdomain=$_;
  500:         foreach ('dc','li','dg','au') {
  501:             if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
  502:                my $plrole=&Apache::lonnet::plaintext($_);
  503:                $r->print(<<ENDDROW);
  504: <tr>
  505: <td><input type=checkbox name="act_$thisdomain\_$_"></td>
  506: <td>$plrole</td>
  507: <td>$thisdomain</td>
  508: <td><input type=hidden name="start_$thisdomain\_$_" value=''>
  509: <a href=
  510: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">Set Start Date</a></td>
  511: <td><input type=hidden name="end_$thisdomain\_$_" value=''>
  512: <a href=
  513: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">Set End Date</a></td>
  514: </tr>
  515: ENDDROW
  516:             }
  517:         } 
  518:     }
  519:     $r->print('</table>');
  520: #
  521: # Course level
  522: #
  523:     $r->print(&course_level_table(%inccourses));
  524:     $r->print("<hr /><input type=submit value=\"Modify User\">\n");
  525:     $r->print("</form></body></html>");
  526: }
  527: 
  528: # ================================================================= Phase Three
  529: sub update_user_data {
  530:     my $r=shift;
  531:     my $uhome=&Apache::lonnet::homeserver($ENV{'form.ccuname'},
  532:                                           $ENV{'form.ccdomain'});
  533:     # Error messages
  534:     my $error     = '<font color="#ff0000">Error:</font>';
  535:     my $end       = '</body></html>';
  536:     # Print header
  537:     $r->print(<<ENDTHREEHEAD);
  538: <html>
  539: <head>
  540: <title>The LearningOnline Network with CAPA</title>
  541: </head>
  542: ENDTHREEHEAD
  543:     my $title;
  544:     if (exists($ENV{'form.makeuser'})) {
  545: 	$title='Set Privileges for New User';
  546:     } else {
  547:         $title='Modify User Privileges';
  548:     }
  549:     $r->print(&Apache::loncommon::bodytag($title));
  550:     # Check Inputs
  551:     if (! $ENV{'form.ccuname'} ) {
  552: 	$r->print($error.'No login name specified.'.$end);
  553: 	return;
  554:     }
  555:     if (  $ENV{'form.ccuname'}  =~/\W/) {
  556: 	$r->print($error.'Invalid login name.  '.
  557: 		  'Only letters, numbers, and underscores are valid.'.
  558: 		  $end);
  559: 	return;
  560:     }
  561:     if (! $ENV{'form.ccdomain'}       ) {
  562: 	$r->print($error.'No domain specified.'.$end);
  563: 	return;
  564:     }
  565:     if (  $ENV{'form.ccdomain'} =~/\W/) {
  566: 	$r->print($error.'Invalid domain name.  '.
  567: 		  'Only letters, numbers, and underscores are valid.'.
  568: 		  $end);
  569: 	return;
  570:     }
  571:     if (! exists($ENV{'form.makeuser'})) {
  572:         # Modifying an existing user, so check the validity of the name
  573:         if ($uhome eq 'no_host') {
  574:             $r->print($error.'Unable to determine home server for '.
  575:                       $ENV{'form.ccuname'}.' in domain '.
  576:                       $ENV{'form.ccdomain'}.'.');
  577:             return;
  578:         }
  579:     }
  580:     # Determine authentication method and password for the user being modified
  581:     my $amode='';
  582:     my $genpwd='';
  583:     if ($ENV{'form.login'} eq 'krb') {
  584: 	$amode='krb';
  585: 	$amode.=$ENV{'form.krbver'};
  586: 	$genpwd=$ENV{'form.krbarg'};
  587:     } elsif ($ENV{'form.login'} eq 'int') {
  588: 	$amode='internal';
  589: 	$genpwd=$ENV{'form.intarg'};
  590:     } elsif ($ENV{'form.login'} eq 'fsys') {
  591: 	$amode='unix';
  592: 	$genpwd=$ENV{'form.fsysarg'};
  593:     } elsif ($ENV{'form.login'} eq 'loc') {
  594: 	$amode='localauth';
  595: 	$genpwd=$ENV{'form.locarg'};
  596: 	$genpwd=" " if (!$genpwd);
  597:     } elsif (($ENV{'form.login'} eq 'nochange') ||
  598:              ($ENV{'form.login'} eq ''        )) { 
  599:         # There is no need to tell the user we did not change what they
  600:         # did not ask us to change.
  601:         # If they are creating a new user but have not specified login
  602:         # information this will be caught below.
  603:     } else {
  604: 	    $r->print($error.'Invalid login mode or password'.$end);    
  605: 	    return;
  606:     }
  607:     if ($ENV{'form.makeuser'}) {
  608:         # Create a new user
  609: 	$r->print(<<ENDNEWUSERHEAD);
  610: <h3>Creating user "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"</h2>
  611: ENDNEWUSERHEAD
  612:         # Check for the authentication mode and password
  613:         if (! $amode || ! $genpwd) {
  614: 	    $r->print($error.'Invalid login mode or password'.$end);    
  615: 	    return;
  616: 	}
  617:         # Determine desired host
  618:         my $desiredhost = $ENV{'form.hserver'};
  619:         if (lc($desiredhost) eq 'default') {
  620:             $desiredhost = undef;
  621:         } else {
  622:             my %home_servers = &Apache::loncommon::get_library_servers
  623:                 ($ENV{'form.ccdomain'});  
  624:             if (! exists($home_servers{$desiredhost})) {
  625:                 $r->print($error.'Invalid home server specified');
  626:                 return;
  627:             }
  628:         }
  629: 	# Call modifyuser
  630: 	my $result = &Apache::lonnet::modifyuser
  631: 	    ($ENV{'form.ccdomain'},$ENV{'form.ccuname'},$ENV{'form.cstid'},
  632:              $amode,$genpwd,$ENV{'form.cfirst'},
  633:              $ENV{'form.cmiddle'},$ENV{'form.clast'},$ENV{'form.cgen'},
  634:              undef,$desiredhost
  635: 	     );
  636: 	$r->print('Generating user: '.$result);
  637:         my $home = &Apache::lonnet::homeserver($ENV{'form.ccuname'},
  638:                                                $ENV{'form.ccdomain'});
  639:         $r->print('<br>Home server: '.$home.' '.
  640:                   $Apache::lonnet::libserv{$home});
  641:     } elsif (($ENV{'form.login'} ne 'nochange') &&
  642:              ($ENV{'form.login'} ne ''        )) {
  643: 	# Modify user privileges
  644: 	$r->print(<<ENDMODIFYUSERHEAD);
  645: <h2>User "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"</h2>
  646: ENDMODIFYUSERHEAD
  647:         if (! $amode || ! $genpwd) {
  648: 	    $r->print($error.'Invalid login mode or password'.$end);    
  649: 	    return;
  650: 	}
  651: 	# Only allow authentification modification if the person has authority
  652: 	if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'})) {
  653: 	    $r->print('Modifying authentication: '.
  654:                       &Apache::lonnet::modifyuserauth(
  655: 		       $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
  656:                        $amode,$genpwd));
  657:             $r->print('<br>Home server: '.&Apache::lonnet::homeserver
  658: 		  ($ENV{'form.ccuname'},$ENV{'form.ccdomain'}));
  659: 	} else {
  660: 	    # Okay, this is a non-fatal error.
  661: 	    $r->print($error.'You do not have the authority to modify '.
  662: 		      'this users authentification information.');    
  663: 	}
  664:     }
  665:     ##
  666:     if (! $ENV{'form.makeuser'} ) {
  667:         # Check for need to change
  668:         my %userenv = &Apache::lonnet::get
  669:             ('environment',['firstname','middlename','lastname','generation'],
  670:              $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
  671:         my ($tmp) = keys(%userenv);
  672:         if ($tmp =~ /^(con_lost|error)/i) { 
  673:             %userenv = ();
  674:         }
  675:         # Check to see if we need to change user information
  676:         foreach ('firstname','middlename','lastname','generation') {
  677:             # Strip leading and trailing whitespace
  678:             $ENV{'form.c'.$_} =~ s/(\s+$|^\s+)//g; 
  679:         }
  680:         if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'}) && 
  681:             ($ENV{'form.cfirstname'}  ne $userenv{'firstname'}  ||
  682:              $ENV{'form.cmiddlename'} ne $userenv{'middlename'} ||
  683:              $ENV{'form.clastname'}   ne $userenv{'lastname'}   ||
  684:              $ENV{'form.cgeneration'} ne $userenv{'generation'} )) {
  685:             # Make the change
  686:             my %changeHash;
  687:             $changeHash{'firstname'}  = $ENV{'form.cfirstname'};
  688:             $changeHash{'middlename'} = $ENV{'form.cmiddlename'};
  689:             $changeHash{'lastname'}   = $ENV{'form.clastname'};
  690:             $changeHash{'generation'} = $ENV{'form.cgeneration'};
  691:             my $putresult = &Apache::lonnet::put
  692:                 ('environment',\%changeHash,
  693:                  $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
  694:             if ($putresult eq 'ok') {
  695:             # Tell the user we changed the name
  696:                 $r->print(<<"END");
  697: <table border="2">
  698: <caption>User Information Changed</caption>
  699: <tr><th>&nbsp;</th>
  700:     <th>first</th>
  701:     <th>middle</th>
  702:     <th>last</th>
  703:     <th>generation</th></tr>
  704: <tr><td>Previous</td>
  705:     <td>$userenv{'firstname'}  </td>
  706:     <td>$userenv{'middlename'} </td>
  707:     <td>$userenv{'lastname'}   </td>
  708:     <td>$userenv{'generation'} </td></tr>
  709: <tr><td>Changed To</td>
  710:     <td>$ENV{'form.cfirstname'}  </td>
  711:     <td>$ENV{'form.cmiddlename'} </td>
  712:     <td>$ENV{'form.clastname'}   </td>
  713:     <td>$ENV{'form.cgeneration'} </td></tr>
  714: </table>
  715: END
  716:             } else { # error occurred
  717:                 $r->print("<h2>Unable to successfully change environment for ".
  718:                       $ENV{'form.ccuname'}." in domain ".
  719:                       $ENV{'form.ccdomain'}."</h2>");
  720:             }
  721:         }  else { # End of if ($ENV ... ) logic
  722:             # They did not want to change the users name but we can
  723:             # still tell them what the name is
  724:                 $r->print(<<"END");
  725: <h2>User "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"</h2>
  726: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
  727: <h4>Generation: $userenv{'generation'}</h4>
  728: END
  729:         }
  730:     }
  731:     ##
  732:     my $now=time;
  733:     $r->print('<h3>Modifying Roles</h3>');
  734:     foreach (keys (%ENV)) {
  735: 	next if (! $ENV{$_});
  736: 	# Revoke roles
  737: 	if ($_=~/^form\.rev/) {
  738: 	    if ($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) {
  739: 	        $r->print('Revoking '.$2.' in '.$1.': <b>'.
  740:                      &Apache::lonnet::assignrole($ENV{'form.ccdomain'},
  741:                      $ENV{'form.ccuname'},$1,$2,$now).'</b><br>');
  742: 		if ($2 eq 'st') {
  743: 		    $1=~/^\/(\w+)\/(\w+)/;
  744: 		    my $cid=$1.'_'.$2;
  745: 		    $r->print('Drop from classlist: <b>'.
  746: 			 &Apache::lonnet::critical('put:'.
  747:                              $ENV{'course.'.$cid.'.domain'}.':'.
  748: 	                     $ENV{'course.'.$cid.'.num'}.':classlist:'.
  749:                          &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
  750:                              $ENV{'form.ccdomain'}).'='.
  751:                          &Apache::lonnet::escape($now.':'),
  752: 	                     $ENV{'course.'.$cid.'.home'}).'</b><br>');
  753: 		}
  754: 	    } 
  755: 	} elsif ($_=~/^form\.del/) {
  756: 	    if ($_=~/^form\.del\:([^\_]+)\_([^\_]+)$/) {
  757: 	        $r->print('Deleting '.$2.' in '.$1.': '.
  758:                      &Apache::lonnet::assignrole($ENV{'form.ccdomain'},
  759:                      $ENV{'form.ccuname'},$1,$2,$now,0,1).'<br>');
  760: 		if ($2 eq 'st') {
  761: 		    $1=~/^\/(\w+)\/(\w+)/;
  762: 		    my $cid=$1.'_'.$2;
  763: 		    $r->print('Drop from classlist: <b>'.
  764: 			 &Apache::lonnet::critical('put:'.
  765:                              $ENV{'course.'.$cid.'.domain'}.':'.
  766: 	                     $ENV{'course.'.$cid.'.num'}.':classlist:'.
  767:                          &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
  768:                              $ENV{'form.ccdomain'}).'='.
  769:                          &Apache::lonnet::escape($now.':'),
  770: 	                     $ENV{'course.'.$cid.'.home'}).'</b><br>');
  771: 		}
  772: 	    } 
  773: 	} elsif ($_=~/^form\.act/) {
  774: 	    if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) {
  775: 		# Activate roles for sections with 3 id numbers
  776: 		# set start, end times, and the url for the class
  777: 
  778: 		my $start = ( $ENV{'form.start_'.$1.'_'.$2.'_'.$3} ? 
  779: 			      $ENV{'form.start_'.$1.'_'.$2.'_'.$3} : 
  780: 			      $now );
  781: 		my $end   = ( $ENV{'form.end_'.$1.'_'.$2.'_'.$3} ? 
  782: 			      $ENV{'form.end_'.$1.'_'.$2.'_'.$3} :
  783: 			      0 );
  784: 		my $url='/'.$1.'/'.$2;
  785: 		if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) {
  786: 		    $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3};
  787: 		}
  788: 		# Assign the role and report it
  789: 		$r->print('Assigning: '.$3.' in '.$url.
  790:                          ($start?', starting '.localtime($start):'').
  791:                          ($end?', ending '.localtime($end):'').': <b>'.
  792:                           &Apache::lonnet::assignrole(
  793:                               $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
  794:                               $url,$3,$end,$start).
  795: 			  '</b><br>');
  796: 		# Handle students differently
  797: 		if ($3 eq 'st') {
  798: 		    $url=~/^\/(\w+)\/(\w+)/;
  799: 		    my $cid=$1.'_'.$2;
  800: 		    $r->print('Add to classlist: <b>'.
  801: 			      &Apache::lonnet::critical(
  802: 				  'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
  803: 	                           $ENV{'course.'.$cid.'.num'}.':classlist:'.
  804:                                    &Apache::lonnet::escape(
  805:                                        $ENV{'form.ccuname'}.':'.
  806:                                        $ENV{'form.ccdomain'} ).'='.
  807:                                    &Apache::lonnet::escape($end.':'.$start),
  808: 				       $ENV{'course.'.$cid.'.home'})
  809: 			      .'</b><br>');
  810: 		}
  811: 	    } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
  812: 		# Activate roles for sections with two id numbers
  813: 		# set start, end times, and the url for the class
  814: 		my $start = ( $ENV{'form.start_'.$1.'_'.$2} ? 
  815: 			      $ENV{'form.start_'.$1.'_'.$2} : 
  816: 			      $now );
  817: 		my $end   = ( $ENV{'form.end_'.$1.'_'.$2} ? 
  818: 			      $ENV{'form.end_'.$1.'_'.$2} :
  819: 			      0 );
  820: 		my $url='/'.$1.'/';
  821: 		# Assign the role and report it.
  822: 		$r->print('Assigning: '.$2.' in '.$url.': '.
  823:                          ($start?', starting '.localtime($start):'').
  824:                          ($end?', ending '.localtime($end):'').': <b>'.
  825:                           &Apache::lonnet::assignrole(
  826:                               $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
  827:                               $url,$2,$end,$start)
  828: 			  .'</b><br>');
  829: 	    }
  830: 	} 
  831:     } # End of foreach (keys(%ENV))
  832:     $r->print('</body></html>');
  833: }
  834: 
  835: # ========================================================== Custom Role Editor
  836: 
  837: sub custom_role_editor {
  838:     my $r=shift;
  839:     my $rolename=$ENV{'form.rolename'};
  840: 
  841:     if ($rolename eq 'make new role') {
  842: 	$rolename=$ENV{'form.newrolename'};
  843:     }
  844: 
  845:     $rolename=~s/\W//gs;
  846: 
  847:     unless ($rolename) {
  848: 	&print_username_entry_form($r);
  849:         return;
  850:     }
  851: 
  852:     $r->print(&Apache::loncommon::bodytag(
  853:                      'Create Users, Change User Privileges').'<h2>');
  854:     my $syspriv='';
  855:     my $dompriv='';
  856:     my $coursepriv='';
  857:     my ($rdummy,$roledef)=
  858: 			 &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
  859: # ------------------------------------------------------- Does this role exist?
  860:     if (($rdummy ne 'con_lost') && ($roledef ne '')) {
  861: 	$r->print('Existing Role "');
  862: # ------------------------------------------------- Get current role privileges
  863: 	($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
  864: 	$r->print($syspriv.' '.$dompriv.' '.$coursepriv);
  865:     } else {
  866: 	$r->print('New Role "');
  867: 	$roledef='';
  868:     }
  869:     $r->print($rolename.'"</h2>');
  870: # ------------------------------------------------------- What can be assigned?
  871:     my %full=();
  872:     my %courselevel=();
  873:     my %courselevelcurrent=();
  874:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
  875: 	my ($priv,$restrict)=split(/\&/,$_);
  876:         unless ($restrict) { $restrict='F'; }
  877:         $courselevel{$priv}=$restrict;
  878:         if ($coursepriv=~/\:$priv/) {
  879: 	    $courselevelcurrent{$priv}=1;
  880: 	}
  881: 	$full{$priv}=1;
  882:     }
  883:     my %domainlevel=();
  884:     my %domainlevelcurrent=();
  885:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
  886: 	my ($priv,$restrict)=split(/\&/,$_);
  887:         unless ($restrict) { $restrict='F'; }
  888:         $domainlevel{$priv}=$restrict;
  889:         if ($dompriv=~/\:$priv/) {
  890: 	    $domainlevelcurrent{$priv}=1;
  891: 	}
  892: 	$full{$priv}=1;
  893:     }
  894:     my %systemlevel=();
  895:     my %systemlevelcurrent=();
  896:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
  897: 	my ($priv,$restrict)=split(/\&/,$_);
  898:         unless ($restrict) { $restrict='F'; }
  899:         $systemlevel{$priv}=$restrict;
  900:         if ($syspriv=~/\:$priv/) {
  901: 	    $systemlevelcurrent{$priv}=1;
  902: 	}
  903: 	$full{$priv}=1;
  904:     }
  905:     $r->print(<<ENDCCF);
  906: <form method="post">
  907: <input type="hidden" name="phase" value="set_custom_roles" />
  908: <input type="hidden" name="rolename" value="$rolename" />
  909: <table border="2">
  910: <tr><th>Privilege</th><th>Course Level</th><th>Domain Level</th>
  911: <th>System Level</th></tr>
  912: ENDCCF
  913:     foreach (sort keys %full) {
  914: 	$r->print('<tr><td>'.&Apache::lonnet::plaintext($_).'</td><td>'.
  915:     ($courselevel{$_}?'<input type="checkbox" name="'.$_.':c" '.
  916:     ($courselevelcurrent{$_}?'checked="1"':'').' />':'&nbsp;').
  917:     '</td><td>'.
  918:     ($domainlevel{$_}?'<input type="checkbox" name="'.$_.':d" '.
  919:     ($domainlevelcurrent{$_}?'checked="1"':'').' />':'&nbsp;').
  920:     '</td><td>'.
  921:     ($systemlevel{$_}?'<input type="checkbox" name="'.$_.':s" '.
  922:     ($systemlevelcurrent{$_}?'checked="1"':'').' />':'&nbsp;').
  923:     '</td></tr>');
  924:     }
  925:     $r->print(
  926:    '<table><input type="submit" value="Define Role" /></form></body></html>');
  927: }
  928: 
  929: # ---------------------------------------------------------- Call to definerole
  930: sub set_custom_role {
  931:     my $r=shift;
  932: 
  933:     my $rolename=$ENV{'form.rolename'};
  934: 
  935:     $rolename=~s/\W//gs;
  936: 
  937:     unless ($rolename) {
  938: 	&print_username_entry_form($r);
  939:         return;
  940:     }
  941: 
  942:     $r->print(&Apache::loncommon::bodytag(
  943:                      'Create Users, Change User Privileges').'<h2>');
  944:     my ($rdummy,$roledef)=
  945: 			 &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
  946: # ------------------------------------------------------- Does this role exist?
  947:     if (($rdummy ne 'con_lost') && ($roledef ne '')) {
  948: 	$r->print('Existing Role "');
  949:     } else {
  950: 	$r->print('New Role "');
  951: 	$roledef='';
  952:     }
  953:     $r->print($rolename.'"</h2>');
  954: # ------------------------------------------------------- What can be assigned?
  955:     my $sysrole='';
  956:     my $domrole='';
  957:     my $courole='';
  958: 
  959:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
  960: 	my ($priv,$restrict)=split(/\&/,$_);
  961:         unless ($restrict) { $restrict=''; }
  962:         if ($ENV{'form.'.$priv.':c'}) {
  963: 	    $courole.=':'.$_;
  964: 	}
  965:     }
  966: 
  967:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
  968: 	my ($priv,$restrict)=split(/\&/,$_);
  969:         unless ($restrict) { $restrict=''; }
  970:         if ($ENV{'form.'.$priv.':d'}) {
  971: 	    $domrole.=':'.$_;
  972: 	}
  973:     }
  974: 
  975:     foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
  976: 	my ($priv,$restrict)=split(/\&/,$_);
  977:         unless ($restrict) { $restrict=''; }
  978:         if ($ENV{'form.'.$priv.':s'}) {
  979: 	    $sysrole.=':'.$_;
  980: 	}
  981:     }
  982:     $r->print('Defining Role: '.
  983: 	   &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
  984:     $r->print('</body></html>');
  985: }
  986: 
  987: # ================================================================ Main Handler
  988: sub handler {
  989:     my $r = shift;
  990: 
  991:     if ($r->header_only) {
  992:        $r->content_type('text/html');
  993:        $r->send_http_header;
  994:        return OK;
  995:     }
  996: 
  997:     if ((&Apache::lonnet::allowed('cta',$ENV{'request.course.id'})) ||
  998:         (&Apache::lonnet::allowed('cin',$ENV{'request.course.id'})) || 
  999:         (&Apache::lonnet::allowed('ccr',$ENV{'request.course.id'})) || 
 1000:         (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) ||
 1001:         (&Apache::lonnet::allowed('cca',$ENV{'request.role.domain'})) ||
 1002:         (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'}))) {
 1003:        $r->content_type('text/html');
 1004:        $r->send_http_header;
 1005:        unless ($ENV{'form.phase'}) {
 1006: 	   &print_username_entry_form($r);
 1007:        }
 1008:        if ($ENV{'form.phase'} eq 'get_user_info') {
 1009:            &print_user_modification_page($r);
 1010:        } elsif ($ENV{'form.phase'} eq 'update_user_data') {
 1011:            &update_user_data($r);
 1012:        } elsif ($ENV{'form.phase'} eq 'selected_custom_edit') {
 1013:            &custom_role_editor($r);
 1014:        } elsif ($ENV{'form.phase'} eq 'set_custom_roles') {
 1015: 	   &set_custom_role($r);
 1016:        }
 1017:    } else {
 1018:       $ENV{'user.error.msg'}=
 1019:         "/adm/createuser:mau:0:0:Cannot modify user data";
 1020:       return HTTP_NOT_ACCEPTABLE; 
 1021:    }
 1022:    return OK;
 1023: } 
 1024: 
 1025: #-------------------------------------------------- functions for &phase_two
 1026: sub course_level_table {
 1027:     my %inccourses = @_;
 1028:     my $table = '';
 1029:     foreach (sort( keys(%inccourses))) {
 1030: 	my $thiscourse=$_;
 1031: 	my $protectedcourse=$_;
 1032: 	$thiscourse=~s:_:/:g;
 1033: 	my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
 1034: 	my $area=$coursedata{'description'};
 1035: 	if (!defined($area)) { $area='Unavailable course: '.$_; }
 1036: 	my $bgcol=$thiscourse;
 1037: 	$bgcol=~s/[^8-9b-e]//g;
 1038: 	$bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
 1039: 	foreach  ('st','ta','ep','ad','in','cc') {
 1040: 	    if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
 1041: 		my $plrole=&Apache::lonnet::plaintext($_);
 1042: 		$table .= <<ENDEXTENT;
 1043: <tr bgcolor="#$bgcol">
 1044: <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
 1045: <td>$plrole</td>
 1046: <td>$area</td>
 1047: ENDEXTENT
 1048: 	        if ($_ ne 'cc') {
 1049: 		    $table .= <<ENDSECTION;
 1050: <td><input type="text" size="5" name="sec_$protectedcourse\_$_"></td>
 1051: ENDSECTION
 1052:                 } else { 
 1053: 		    $table .= <<ENDSECTION;
 1054: <td>&nbsp</td> 
 1055: ENDSECTION
 1056:                 }
 1057: 		$table .= <<ENDTIMEENTRY;
 1058: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
 1059: <a href=
 1060: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">Set Start Date</a></td>
 1061: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
 1062: <a href=
 1063: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">Set End Date</a></td>
 1064: ENDTIMEENTRY
 1065:                 $table.= "</tr>\n";
 1066:             }
 1067:         }
 1068:     }
 1069:     return '' if ($table eq ''); # return nothing if there is nothing 
 1070:                                  # in the table
 1071:     my $result = <<ENDTABLE;
 1072: <h4>Course Level</h4>
 1073: <table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>
 1074: <th>Group/Section</th><th>Start</th><th>End</th></tr>
 1075: $table
 1076: </table>
 1077: ENDTABLE
 1078:     return $result;
 1079: }
 1080: #---------------------------------------------- end functions for &phase_two
 1081: 
 1082: #--------------------------------- functions for &phase_two and &phase_three
 1083: 
 1084: #--------------------------end of functions for &phase_two and &phase_three
 1085: 
 1086: 1;
 1087: __END__
 1088: 
 1089: 

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