Diff for /loncom/xml/lonxml.pm between versions 1.114 and 1.126

version 1.114, 2001/08/15 15:49:14 version 1.126, 2001/08/23 22:12:24
Line 13 Line 13
 # 6/12,6/13 H. K. Ng  # 6/12,6/13 H. K. Ng
 # 6/16 Gerd Kortemeyer  # 6/16 Gerd Kortemeyer
 # 7/27 H. K. Ng  # 7/27 H. K. Ng
 # 8/7,8/9,8/10,8/11,8/15 Gerd Kortemeyer  # 8/7,8/9,8/10,8/11,8/15,8/16,8/17,8/18,8/20,8/23 Gerd Kortemeyer
   
 package Apache::lonxml;   package Apache::lonxml; 
 use vars   use vars 
Line 152  sub xmlend { Line 152  sub xmlend {
     return $discussion.'</html>';      return $discussion.'</html>';
 }  }
   
 sub checkout {  sub tokeninputfield {
     my ($target,$symb,$tuname,$tudom,$tcrsid)=@_;      my $defhost=$Apache::lonnet::perlvar{'lonHostID'};
       $defhost=~tr/a-z/A-Z/;
       return (<<ENDINPUTFIELD)
   <script>
       function updatetoken() {
    var comp=new Array;
           var barcode=unescape(document.tokeninput.barcode.value);
           comp=barcode.split('*');
           if (typeof(comp[0])!="undefined") {
       document.tokeninput.codeone.value=comp[0];
    }
           if (typeof(comp[1])!="undefined") {
       document.tokeninput.codetwo.value=comp[1];
    }
           if (typeof(comp[2])!="undefined") {
               comp[2]=comp[2].toUpperCase();
       document.tokeninput.codethree.value=comp[2];
    }
           document.tokeninput.barcode.value='';
       }  
   </script>
   <form method="post" name="tokeninput">
   <table border="2" bgcolor="#FFFFBB">
   <tr><th>DocID Checkin</th></tr>
   <tr><td>
   <table>
   <tr>
   <td>Scan in Barcode</td>
   <td><input type="text" size="22" name="barcode" 
   onChange="updatetoken()"/></td>
   </tr>
   <tr><td><i>or</i> Type in DocID</td>
   <td>
   <input type="text" size="5" name="codeone" />
   <b><font size="+2">*</font></b>
   <input type="text" size="5" name="codetwo" />
   <b><font size="+2">*</font></b>
   <input type="text" size="10" name="codethree" value="$defhost" 
   onChange="this.value=this.value.toUpperCase()" />
   </td></tr>
   </table>
   </td></tr>
   <tr><td><input type="submit" value="Check in DocID" /></td></tr>
   </table>
   </form>
   ENDINPUTFIELD
   }
   
   sub maketoken {
       my ($symb,$tuname,$tudom,$tcrsid)=@_;
     unless ($symb) {      unless ($symb) {
  $symb=&Apache::lonnet::symbread();   $symb=&Apache::lonnet::symbread();
     }      }
Line 162  sub checkout { Line 211  sub checkout {
         $tudom=$ENV{'user.domain'};          $tudom=$ENV{'user.domain'};
         $tcrsid=$ENV{'request.course.id'};          $tcrsid=$ENV{'request.course.id'};
     }      }
     my $now=time;  
     my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};      return &Apache::lonnet::checkout($symb,$tuname,$tudom,$tcrsid);
     my $infostr=&Apache::lonnet::escape(  }
                  $tuname.'&'.  
                  $tudom.'&'.  sub printtokenheader {
                  $tcrsid.'&'.      my ($target,$token,$symb,$tuname,$tudom,$tcrsid)=@_;
                  $symb.'&'.      unless ($token) { return ''; }
  $now.'&'.$ENV{'REMOTE_ADDR'});  
     my $token=Apache::lonnet::reply('tmpput:'.$infostr,$lonhost);      unless ($symb) {
     if ($token=~/^error\:/) { return ''; }   $symb=&Apache::lonnet::symbread();
     $token=~s/^(\d+)\_.*\_(\d+)$/$1\*$2\*$lonhost/;      }
     $token=~tr/a-z/A-Z/;      unless ($tuname) {
    $tuname=$ENV{'user.name'};
     my %infohash=('token' => $token,          $tudom=$ENV{'user.domain'};
                   'checktime' => $now,          $tcrsid=$ENV{'request.course.id'};
                   'remote' => $ENV{'REMOTE_ADDR'});  
   
     unless (  
   &Apache::lonnet::cstore(\%infohash,$symb,$tcrsid,$tudom,$tuname) eq 'ok') {  
        return '';  
     }      
   
     if (&Apache::lonnet::log($tudom,$tuname,  
                          &Apache::lonnet::homeserver($tuname,$tudom),  
                          &Apache::lonnet::escape('Checkout '.$infostr.' - '.  
                                                  $token)) ne 'ok') {  
  return '';  
     }      }
   
     my %reply=&Apache::lonnet::get('environment',      my %reply=&Apache::lonnet::get('environment',
Line 200  sub checkout { Line 237  sub checkout {
   $reply{'generation'};    $reply{'generation'};
   
     if ($target eq 'web') {      if ($target eq 'web') {
  return 'Checked out for '.$plainname.   return 
    '<img align="right" src="/cgi-bin/barcode.gif?encode='.$token.'" />'.
                  'Checked out for '.$plainname.
                '<br />User: '.$tuname.' at '.$tudom.                 '<br />User: '.$tuname.' at '.$tudom.
        '<br />CourseID: '.$tcrsid.')'.         '<br />CourseID: '.$tcrsid.
                '<br />DocID: '.$token.                 '<br />DocID: '.$token.
                '<br />Time: '.localtime($now).                 '<br />Time: '.localtime().'<hr />';
  '<img align="right" src="/cgi-bin/barcode.gif?encode='.$token.'" /><hr />';  
     } else {      } else {
         return $token;                                   return $token;
     }      }
 }  }
   
Line 284  ENDPARM Line 322  ENDPARM
     function LONCAPAstale() {      function LONCAPAstale() {
   menu=window.open("","LONCAPAmenu");    menu=window.open("","LONCAPAmenu");
           menu.currentStale=1;            menu.currentStale=1;
           menu.switchbutton            //menu.clearbut(7,1);
             (3,1,'reload.gif','return','location','go(currentURL)');            //menu.clearbut(7,2);
           menu.clearbut(7,1);            //menu.clearbut(7,3);
           menu.clearbut(7,2);  
           menu.clearbut(7,3);  
           menu.menucltim=menu.setTimeout(            menu.menucltim=menu.setTimeout(
  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+   'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
  'clearbut(9,1);clearbut(9,2);clearbut(9,3);clearbut(6,3)',   'clearbut(9,1);clearbut(9,2);clearbut(9,3);clearbut(6,3)',
Line 370  sub xmlparse { Line 406  sub xmlparse {
   
  my $finaloutput = &inner_xmlparse($target,\@stack,\@parstack,\@pars,   my $finaloutput = &inner_xmlparse($target,\@stack,\@parstack,\@pars,
    $safeeval,\%style_for_target);     $safeeval,\%style_for_target);
    if ($ENV{'request.uri'}) {
       &writeallows($ENV{'request.uri'});
    }
  return $finaloutput;   return $finaloutput;
 }  }
   
Line 397  sub htmlclean { Line 435  sub htmlclean {
   
 sub inner_xmlparse {  sub inner_xmlparse {
   my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target)=@_;    my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target)=@_;
   &Apache::lonxml::debug('Reentrant parser starting, again?');  
   my $finaloutput = '';    my $finaloutput = '';
   my $result;    my $result;
   my $token;    my $token;
Line 619  sub setup_globals { Line 656  sub setup_globals {
   my ($target)=@_;    my ($target)=@_;
   $Apache::lonxml::registered = 0;    $Apache::lonxml::registered = 0;
   @Apache::lonxml::pwd=();    @Apache::lonxml::pwd=();
     @Apache::lonxml::extlinks=();
   if ($target eq 'meta') {    if ($target eq 'meta') {
     $Apache::lonxml::redirection = 0;      $Apache::lonxml::redirection = 0;
     $Apache::lonxml::metamode = 1;      $Apache::lonxml::metamode = 1;
Line 700  sub init_safespace { Line 738  sub init_safespace {
 #need to inspect this class of ops  #need to inspect this class of ops
 # $safeeval->deny(":base_orig");  # $safeeval->deny(":base_orig");
   $safeinit .= ';$external::target="'.$target.'";';    $safeinit .= ';$external::target="'.$target.'";';
   $safeinit .= ';$external::randomseed='.&Apache::lonnet::rndseed().';';    my $rndseed;
     my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
     $rndseed=&Apache::lonnet::rndseed($symb,$courseid,$domain,$name);
     $safeinit .= ';$external::randomseed='.$rndseed.';';
   &Apache::run::run($safeinit,$safeeval);    &Apache::run::run($safeinit,$safeeval);
 }  }
   
Line 835  sub parstring { Line 876  sub parstring {
 }  }
   
 sub writeallows {  sub writeallows {
       unless ($#extlinks>=0) { return; }
     my $thisurl='/res/'.&Apache::lonnet::declutter(shift);      my $thisurl='/res/'.&Apache::lonnet::declutter(shift);
     if ($ENV{'httpref.'.$thisurl}) {      if ($ENV{'httpref.'.$thisurl}) {
  $thisurl=$ENV{'httpref.'.$thisurl};   $thisurl=$ENV{'httpref.'.$thisurl};
Line 844  sub writeallows { Line 886  sub writeallows {
     my %httpref=();      my %httpref=();
     map {      map {
        $httpref{'httpref.'.         $httpref{'httpref.'.
          &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl;              } @extlinks;           &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl;
       } @extlinks;
       @extlinks=();
     &Apache::lonnet::appenv(%httpref);      &Apache::lonnet::appenv(%httpref);
 }  }
   
Line 993  ENDNOTFOUND Line 1037  ENDNOTFOUND
   unless ($ENV{'request.state'} eq 'published') {    unless ($ENV{'request.state'} eq 'published') {
       $result=&inserteditinfo($result,$filecontents);        $result=&inserteditinfo($result,$filecontents);
   }    }
     
     writeallows($request->uri);
   
   $request->print($result);    $request->print($result);
   
   writeallows($request->uri);  
   return OK;    return OK;
 }  }
     
Line 1081  sub description { Line 1126  sub description {
   my ($token)=@_;    my ($token)=@_;
   return $insertlist{$insertlist{"$token->[1].num"}.'.description'};    return $insertlist{$insertlist{"$token->[1].num"}.'.description'};
 }  }
   
   # ----------------------------------------------------------------- whichuser
   # returns a list of $symb, $courseid, $domain, $name that is correct for
   # calls to lonnet functions for this setup.
   # - looks for form.grade_ parameters
   sub whichuser {
     my $symb=&Apache::lonnet::symbread();
     my $courseid=$ENV{'request.course.id'};
     my $domain=$ENV{'user.domain'};
     my $name=$ENV{'user.name'};
     if (defined($ENV{'form.grade_symb'})) {
       my $tmp_courseid=$ENV{'form.grade_courseid'};
       my $allowed=&Apache::lonnet::allowed('mgr',$tmp_courseid);
       if ($allowed) {
         $symb=$ENV{'form.grade_symb'};
         $courseid=$ENV{'form.grade_courseid'};
         $domain=$ENV{'form.grade_domain'};
         $name=$ENV{'form.grade_username'};
       }
     }
     return ($symb,$courseid,$domain,$name);
   }
   
 1;  1;
 __END__  __END__
   

Removed from v.1.114  
changed lines
  Added in v.1.126


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