Annotation of loncom/interface/loncreateuser.pm, revision 1.3

1.1       www         1: # The LearningOnline Network
                      2: # Create a user
                      3: #
                      4: # (Create a course
                      5: # (My Desk
                      6: #
                      7: # (Internal Server Error Handler
                      8: #
                      9: # (Login Screen
                     10: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
                     11: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
                     12: #
                     13: # 3/1/1 Gerd Kortemeyer)
                     14: #
                     15: # 3/1 Gerd Kortemeyer)
                     16: #
                     17: # 2/14 Gerd Kortemeyer)
                     18: #
1.3     ! www        19: # 2/14,2/17,2/19,2/20,2/21 Gerd Kortemeyer
1.1       www        20: #
                     21: package Apache::loncreateuser;
                     22: 
                     23: use strict;
                     24: use Apache::Constants qw(:common :http);
                     25: use Apache::lonnet;
                     26: 
1.2       www        27: # =================================================================== Phase one
1.1       www        28: 
1.2       www        29: sub phase_one {
                     30:     my $r=shift;
                     31:     my $defdom=$ENV{'user.domain'};
1.1       www        32:     $r->print(<<ENDDOCUMENT);
                     33: <html>
                     34: <head>
                     35: <title>The LearningOnline Network with CAPA</title>
                     36: </head>
                     37: <body bgcolor="#FFFFFF">
                     38: <h1>Create User, Change User Privileges</h1>
1.2       www        39: <form action=/adm/createuser method=post>
                     40: <input type=hidden name=phase value=two>
                     41: Username: <input type=text size=15 name=ccuname><br>
                     42: Domain: <input type=text size=15 name=ccdomain value=$defdom><p>
                     43: <input type=submit value="Continue">
                     44: </form>
1.1       www        45: </body>
                     46: </html>
                     47: ENDDOCUMENT
1.2       www        48: }
                     49: 
                     50: # =================================================================== Phase two
                     51: 
                     52: sub phase_two {
                     53:     my $r=shift;
                     54:     my $ccuname=$ENV{'form.ccuname'};
                     55:     my $ccdomain=$ENV{'form.ccdomain'};
                     56:     $ccuname=~s/\W//g;
                     57:     $ccdomain=~s/\W//g;
                     58:     $r->print(<<ENDENHEAD);
                     59: <html>
                     60: <head>
                     61: <title>The LearningOnline Network with CAPA</title>
1.3     ! www        62: <script>
        !            63: 
        !            64:     function pclose() {
        !            65:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
        !            66:                  "height=350,width=350,scrollbars=no,menubar=no");
        !            67:         parmwin.close();
        !            68:     }
        !            69: 
        !            70:     function pjump(type,dis,value,marker,ret,call) {
        !            71:         parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
        !            72:                  +"&value="+escape(value)+"&marker="+escape(marker)
        !            73:                  +"&return="+escape(ret)
        !            74:                  +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
        !            75:                  "height=350,width=350,scrollbars=no,menubar=no");
        !            76: 
        !            77:     }
        !            78: 
        !            79:     function dateset() {
        !            80:         eval("document.cu."+document.cu.pres_marker.value+
        !            81:             ".value=document.cu.pres_value.value");
        !            82:         pclose();
        !            83:     }
        !            84: 
        !            85: </script>
1.2       www        86: </head>
                     87: <body bgcolor="#FFFFFF">
                     88: <img align=right src=/adm/lonIcons/lonlogos.gif>
                     89: <h1>Create User, Change User Privileges</h1>
1.3     ! www        90: <form action=/adm/createuser method=post name=cu>
1.2       www        91: <input type=hidden name=phase value=three>
                     92: <input type=hidden name=ccuname value=$ccuname>
                     93: <input type=hidden name=ccdomain value=$ccdomain>
1.3     ! www        94: <input type="hidden" value='' name="pres_value">
        !            95: <input type="hidden" value='' name="pres_type">
        !            96: <input type="hidden" value='' name="pres_marker">
        !            97: 
1.2       www        98: ENDENHEAD
                     99:     my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
                    100:     my %incdomains; 
                    101:     my %inccourses;
                    102:     $incdomains{$ENV{'user.domain'}}=1;
                    103:     map {
                    104: 	if ($_=~/^user\.priv\.cm\.\/(\w+)\/(\w+)/) {
                    105: 	    $inccourses{$1.'_'.$2}=1;
                    106:         }
                    107:     } %ENV;
                    108:     if ($uhome eq 'no_host') {
                    109: 	$r->print('<h3>New user '.$ccuname.' at '.$ccdomain.'</h3>');
                    110:     } else {
                    111: 	$r->print('<h3>Existing user '.$ccuname.' at '.$ccdomain.'</h3>');
                    112:         my $rolesdump=&Apache::lonnet::reply(
                    113:                                   "dump:$ccdomain:$ccuname:roles",$uhome);
                    114:         unless ($rolesdump eq 'con_lost') { 
                    115:            my $now=time;
                    116:            $r->print('<h4>Revoke Existing Roles</h4>'.
                    117:              '<table border=2><tr><th>Revoke</th><th>Role</th><th>Extent</th>'.
                    118: 		     '<th>Start</th><th>End</th>');
                    119:            map {
                    120:              if ($_!~/^rolesdef\&/) {
                    121: 
                    122:               my ($area,$role)=split(/=/,$_);
                    123:               my $thisrole=$area;
                    124:               $area=~s/\_\w\w$//;
                    125:               my ($trole,$tend,$tstart)=split(/_/,$role);
1.3     ! www       126:               my $bgcol='ffffff';
1.2       www       127:               my $allows=0;
                    128:               if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
                    129:                  my %coursedata=&Apache::lonnet::coursedescription($1.'_'.$2);
                    130:                  $area='Course: '.
                    131:                           $coursedata{'description'}.'<br>Section/Group: '.$3;
                    132:                  $inccourses{$1.'_'.$2}=1;
                    133:                  if (&Apache::lonnet::allowed('c'.$trole,$1.'_'.$2)) {
                    134: 		     $allows=1;
                    135:                  }
1.3     ! www       136:                  $bgcol=$1.'_'.$2;
        !           137:                  $bgcol=~s/[^8-9b-e]//g;
        !           138:                  $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
1.2       www       139: 	      } else {
                    140:                  if ($1) {
                    141: 		     $incdomains{$1}=1;
                    142:                      if (&Apache::lonnet::allowed('c'.$trole,$1)) {
                    143: 			 $allows=1;
                    144:                      }
                    145:                  }
                    146: 	      }
                    147: 
                    148:               my $active=1;
                    149:               if (($tend) && ($now>$tend)) { $active=0; }
                    150: 
1.3     ! www       151:               $r->print('<tr bgcolor=#'.$bgcol.'><td>');
1.2       www       152:               if ($active) {
                    153:                   if ($allows) {
                    154: 		     $r->print(
                    155:                              '<input type=checkbox name="rev:'.$thisrole.'">');
                    156: 		 } else {
                    157:                      $r->print('&nbsp;');
                    158:                  }
                    159:               } else {
                    160:                   $r->print('&nbsp;');
                    161:               }
                    162:               $r->print('</td><td>'.&Apache::lonnet::plaintext($trole).
                    163:                         '</td><td>'.$area.'</td><td>'.
                    164:                         ($tstart?localtime($tstart):'&nbsp;').'</td><td>'.
                    165:                         ($tend?localtime($tend):'&nbsp;')."</td></tr>\n");
                    166: 	     }
                    167: 	   } split(/&/,$rolesdump);
                    168: 	   $r->print('</table>');
                    169:          }   
                    170:     }
                    171:     $r->print('<hr><h4>Add Roles</h4><h5>System Level</h5>');
                    172:     $r->print('<h5>Domain Level</h5>');
                    173:     map {
                    174: 	my $thisdomain=$_;
                    175:         map {
                    176:             if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
                    177: 		$r->print($_.' - '.$thisdomain.'<br>');
                    178:             }
                    179:         } ('dc','cc','li','dg','au');
                    180:     } sort keys %incdomains;
1.3     ! www       181:     $r->print('<h5>Course Level</h5>'.
        !           182:     '<table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>'.
        !           183:     '<th>Group/Section</th><th>Start</th><th>End</th></tr>');
1.2       www       184:     map {
                    185: 	my $thiscourse=$_;
1.3     ! www       186:         my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
        !           187:         my $area=$coursedata{'description'};
        !           188:         my $bgcol=$thiscourse;
        !           189:         $bgcol=~s/[^8-9b-e]//g;
        !           190:         $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
1.2       www       191:         map {
                    192:             if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
1.3     ! www       193:                my $plrole=&Apache::lonnet::plaintext($_);
        !           194:                $r->print(<<ENDROW);
        !           195: <tr bgcolor=#$bgcol>
        !           196: <td><input type=checkbox name="act_$thiscourse\_$_"></td>
        !           197: <td>$plrole</td>
        !           198: <td>$area</td>
        !           199: <td><input type=text size=5 name="sec_$thiscourse\_$_"></td>
        !           200: <td><input type=hidden name="start_$thiscourse\_$_" value=''>
        !           201: <a href=
        !           202: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thiscourse\_$_.value,'start_$thiscourse\_$_','cu.pres','dateset')">Set Start Date</a></td>
        !           203: <td><input type=hidden name="end_$thiscourse\_$_" value=''>
        !           204: <a href=
        !           205: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thiscourse\_$_.value,'end_$thiscourse\_$_','cu.pres','dateset')">Set End Date</a></td>
        !           206: </tr>
        !           207: ENDROW
        !           208: 
1.2       www       209:             }
                    210:         } ('st','ta','ep','ad','in');
                    211:     } sort keys %inccourses;
1.3     ! www       212:     $r->print('</table>');
1.2       www       213:     $r->print('</form></body></html>');
                    214: }
1.1       www       215: 
1.2       www       216: # ================================================================ Main Handler
                    217: sub handler {
                    218:     my $r = shift;
                    219: 
                    220:     if ($r->header_only) {
                    221:        $r->content_type('text/html');
                    222:        $r->send_http_header;
                    223:        return OK;
                    224:     }
                    225: 
                    226:     if ((&Apache::lonnet::allowed('cta',$ENV{'request.course.id'})) ||
                    227:         (&Apache::lonnet::allowed('cin',$ENV{'request.course.id'})) || 
                    228:         (&Apache::lonnet::allowed('ccr',$ENV{'request.course.id'})) || 
                    229:         (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) ||
                    230:         (&Apache::lonnet::allowed('mau',$ENV{'user.domain'}))) {
                    231:        $r->content_type('text/html');
                    232:        $r->send_http_header;
                    233:        unless ($ENV{'form.phase'}) {
                    234: 	   &phase_one($r);
                    235:        }
                    236:        if ($ENV{'form.phase'} eq 'two') {
                    237:            &phase_two($r);
                    238:        }
1.1       www       239:    } else {
                    240:       $ENV{'user.error.msg'}=
1.2       www       241:         "/adm/createcourse:mau:0:0:Cannot modify user data";
1.1       www       242:       return HTTP_NOT_ACCEPTABLE; 
                    243:    }
                    244:    return OK;
                    245: } 
                    246: 
                    247: 1;
                    248: __END__
1.2       www       249: 
                    250: 

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