Diff for /rat/lonratedt.pm between versions 1.55 and 1.65

version 1.55, 2004/04/24 15:05:16 version 1.65, 2005/04/07 06:56:27
Line 187  sub mapread { Line 187  sub mapread {
     undef @links;      undef @links;
     undef @resources;      undef @resources;
     undef @order;      undef @order;
       undef @resparms;
     @resources=('');      @resources=('');
     @order=();      @order=();
       @resparms=();
   
     my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');      my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
     if ($errtext) { return ($errtext,2); }      if ($errtext) { return ($errtext,2); }
Line 391  sub attemptread { Line 393  sub attemptread {
 # --------------------------------------------------------- Build up RAT screen  # --------------------------------------------------------- Build up RAT screen
 sub ratedt {  sub ratedt {
   my ($r,$url)=@_;    my ($r,$url)=@_;
     my $frameset = '<frameset rows="1,70,*" border="0">';
     if ($env{'environment.remote'} eq 'off') {
         $frameset = '<frameset rows="1,250,*" border="0">';
     }
   $r->print(<<ENDDOCUMENT);    $r->print(<<ENDDOCUMENT);
   
 <html>  <html>
Line 399  sub ratedt { Line 405  sub ratedt {
     var flag=0;      var flag=0;
 </script>  </script>
 </head>  </head>
 <frameset rows="1,50,*" border=0>  $frameset
 <frame name=server src="$url/loadonly/ratserver" noresize noscroll>  <frame name=server src="$url/loadonly/ratserver" noresize noscroll>
 <frame name=code src="/adm/rat/code.html">  <frame name=code src="$url/loadonly/adveditmenu">
 <frame name=mapout src="/adm/rat/map.html">  <frame name=mapout src="/adm/rat/map.html">
 </frameset>  </frameset>
 </html>  </html>
Line 531  sub storemap { Line 537  sub storemap {
         }          }
     }      }
     $output=~s/http\&colon\;\/\///g;      $output=~s/http\&colon\;\/\///g;
     $ENV{'form.output'}=$output;      $env{'form.output'}=$output;
     return       return 
      &Apache::lonratsrv::loadmap($fn,&Apache::lonratsrv::savemap($fn,''));       &Apache::lonratsrv::loadmap($fn,&Apache::lonratsrv::savemap($fn,''));
 }  }
   
   # ------------------------------------------ Store and get parameters in global
   
   sub storeparameter {
       my ($to,$name,$value,$ptype)=@_;
       my $newentry='';
       my $nametype='';
       foreach (split('&&&',$resparms[$to])) {
    my ($thistype,$thisname,$thisvalue)=split('___',$_);
    if ($thisname) {
       unless ($thisname eq $name) {
    $newentry.=$_.'&&&';
       } else {
    $nametype=$thistype;
       }
    }
       }
       unless ($ptype) { $ptype=$nametype; }
       unless ($ptype) { $ptype='string'; }
       $newentry.=$ptype.'___'.$name.'___'.$value;
       $resparms[$to]=$newentry;
   }
   
   sub delparameter {
       my ($to,$name)=@_;
       my $newentry='';
       my $nametype='';
       foreach (split('&&&',$resparms[$to])) {
    my ($thistype,$thisname,$thisvalue)=split('___',$_);
    if ($thisname) {
       unless ($thisname eq $name) {
    $newentry.=$_.'&&&';
       }
    }
       }
       $resparms[$to]=$newentry;
   }
   
   sub getparameter {
       my ($to,$name)=@_;
       my $value=undef;
       my $ptype=undef;
       foreach (split('&&&',$resparms[$to])) {
    my ($thistype,$thisname,$thisvalue)=split('___',$_);
    if ($thisname eq $name) {
       $value=$thisvalue;
       $ptype=$thistype;
    }
       }
       return ($value,$ptype);
   }
   
   # ----------------------------------------------------------------- Edit script
 sub editscript {  sub editscript {
     my $mode=shift;      my $mode=shift;
     my $resurl=&Apache::loncommon::lastresurl();      my $resurl=&Apache::loncommon::lastresurl();
Line 651  sub smpedt { Line 709  sub smpedt {
    my $buttons=&buttons(2);     my $buttons=&buttons(2);
    my $tmpfn=&Apache::lonnet::filelocation('',$url).'.tmp';     my $tmpfn=&Apache::lonnet::filelocation('',$url).'.tmp';
    my $targetmsg='';     my $targetmsg='';
    if ($ENV{'form.save'}) {     if ($env{'form.save'}) {
        $targetmsg='<b>Saving ...</b><br>';  
        copy($tmpfn,&Apache::lonnet::filelocation('',$url));         copy($tmpfn,&Apache::lonnet::filelocation('',$url));
        unlink($tmpfn);         unlink($tmpfn);
        my ($errtext,$fatal)=         my ($errtext,$fatal)=
                            &mapread(&Apache::lonnet::filelocation('',$url),'');                             &mapread(&Apache::lonnet::filelocation('',$url),'');
          unless ($fatal) {
      $targetmsg='<b>'.&mt('Saved.').'</b><br />';
          } else {
      $targetmsg='<b>'.&mt('An error occured while saving.').'</b><br />';
          }
    }     }
    if ($ENV{'form.revert'}) {     if ($env{'form.revert'}) {
        $targetmsg='<b>Reverting ...</b><br>';         $targetmsg='<b>'.&mt('Reverted.').'</b><br />';
        unlink($tmpfn);         unlink($tmpfn);
        my ($errtext,$fatal)=         my ($errtext,$fatal)=
                            &mapread(&Apache::lonnet::filelocation('',$url),'');                             &mapread(&Apache::lonnet::filelocation('',$url),'');
Line 675  sub smpedt { Line 737  sub smpedt {
    my @targetselect=();     my @targetselect=();
    undef @importselect;     undef @importselect;
    undef @targetselect;     undef @targetselect;
    if (defined($ENV{'form.importsel'})) {     if (defined($env{'form.importsel'})) {
        if (ref($ENV{'form.importsel'})) {         if (ref($env{'form.importsel'})) {
    @importselect=sort(@{$ENV{'form.importsel'}});     @importselect=sort(@{$env{'form.importsel'}});
        } else {         } else {
            @importselect=($ENV{'form.importsel'});             @importselect=($env{'form.importsel'});
        }         }
    }     }
    if (defined($ENV{'form.target'})) {     if (defined($env{'form.target'})) {
        if (ref($ENV{'form.target'})) {         if (ref($env{'form.target'})) {
    @targetselect=sort(@{$ENV{'form.target'}});     @targetselect=sort(@{$env{'form.target'}});
        } else {         } else {
            @targetselect=($ENV{'form.target'});             @targetselect=($env{'form.target'});
        }         }
    }     }
 # ============================================================ Process commands  # ============================================================ Process commands
   
    my $targetdetail=$ENV{'form.targetdetail'};     my $targetdetail=$env{'form.targetdetail'};
    my $importdetail=$ENV{'form.curimpdetail'};     my $importdetail=$env{'form.curimpdetail'};
   
 # ---------------------------------------------------- Importing from groupsort  # ---------------------------------------------------- Importing from groupsort
    if (($ENV{'form.importdetail'}) && (!$ENV{'form.impfortarget'})) {     if (($env{'form.importdetail'}) && (!$env{'form.impfortarget'})) {
   
        $importdetail='';         $importdetail='';
        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});         my @curimport=split(/\&/,$env{'form.curimpdetail'});
   
        my $lastsel;         my $lastsel;
   
Line 715  sub smpedt { Line 777  sub smpedt {
    }     }
        }         }
   
       $importdetail.='&'.$ENV{'form.importdetail'};        $importdetail.='&'.$env{'form.importdetail'};
   
        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {         for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
            my ($name,$url)=split(/\=/,$curimport[$i]);             my ($name,$url)=split(/\=/,$curimport[$i]);
Line 727  sub smpedt { Line 789  sub smpedt {
        $importdetail=~s/^\&//;         $importdetail=~s/^\&//;
   
 # ------------------------------------------------------------------- Clear all  # ------------------------------------------------------------------- Clear all
    } elsif ($ENV{'form.clear'}) {     } elsif ($env{'form.clear'}) {
        $importdetail='';         $importdetail='';
 # ------------------------------------------------------------ Discard selected  # ------------------------------------------------------------ Discard selected
    } elsif ($ENV{'form.discard'}) {     } elsif ($env{'form.discard'}) {
        $importdetail='';         $importdetail='';
        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});         my @curimport=split(/\&/,$env{'form.curimpdetail'});
        foreach (@importselect) {         foreach (@importselect) {
    $curimport[$_]='';     $curimport[$_]='';
        }         }
Line 743  sub smpedt { Line 805  sub smpedt {
    }     }
        }         }
 # --------------------------------------------------------- Loading another map  # --------------------------------------------------------- Loading another map
    } elsif ($ENV{'form.loadmap'}) {     } elsif ($env{'form.loadmap'}) {
        $importdetail='';         $importdetail='';
        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});         my @curimport=split(/\&/,$env{'form.curimpdetail'});
   
        my $lastsel;         my $lastsel;
   
Line 763  sub smpedt { Line 825  sub smpedt {
        }         }
   
        foreach (         foreach (
     &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {      &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
    my ($name,$url)=split(/\:/,$_);     my ($name,$url)=split(/\:/,$_);
            if ($url) {             if ($url) {
               $importdetail.='&'.&Apache::lonnet::escape($name).'='.                $importdetail.='&'.&Apache::lonnet::escape($name).'='.
Line 781  sub smpedt { Line 843  sub smpedt {
        $importdetail=~s/^\&//;         $importdetail=~s/^\&//;
   
 # ------------------------------------------------ Groupimport/search to target  # ------------------------------------------------ Groupimport/search to target
    } elsif ($ENV{'form.importdetail'}) {     } elsif ($env{'form.importdetail'}) {
        my $lastsel;         my $lastsel;
        if (defined($targetselect[-1])) {         if (defined($targetselect[-1])) {
    $lastsel=$targetselect[-1];     $lastsel=$targetselect[-1];
        } else {         } else {
            $lastsel=$#order+1;             $lastsel=$#order+1;
        }         }
        &pastetarget($lastsel,split(/\&/,$ENV{'form.importdetail'}));         &pastetarget($lastsel,split(/\&/,$env{'form.importdetail'}));
        &storemap(&Apache::lonnet::filelocation('',$url));         &storemap(&Apache::lonnet::filelocation('',$url));
 # ------------------------------------------------------------------------- Cut  # ------------------------------------------------------------------------- Cut
    } elsif (($ENV{'form.cut'}) || ($ENV{'form.copy'})) {     } elsif (($env{'form.cut'}) || ($env{'form.copy'})) {
        $importdetail='';         $importdetail='';
        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});         my @curimport=split(/\&/,$env{'form.curimpdetail'});
   
        my $lastsel;         my $lastsel;
   
Line 827  sub smpedt { Line 889  sub smpedt {
        $importdetail=~s/\&+/\&/g;         $importdetail=~s/\&+/\&/g;
        $importdetail=~s/^\&//;         $importdetail=~s/^\&//;
   
        if ($ENV{'form.cut'}) {         if ($env{'form.cut'}) {
            my @neworder=();             my @neworder=();
            for (my $i=0;$i<=$#order;$i++) {             for (my $i=0;$i<=$#order;$i++) {
                my $include=1;                 my $include=1;
Line 841  sub smpedt { Line 903  sub smpedt {
        }         }
   
 # ----------------------------------------------------------------------- Paste  # ----------------------------------------------------------------------- Paste
    } elsif ($ENV{'form.paste'}) {     } elsif ($env{'form.paste'}) {
        my $lastsel;         my $lastsel;
        if (defined($targetselect[-1])) {         if (defined($targetselect[-1])) {
    $lastsel=$targetselect[-1];     $lastsel=$targetselect[-1];
Line 849  sub smpedt { Line 911  sub smpedt {
            $lastsel=$#order+1;             $lastsel=$#order+1;
        }         }
        my @newsequence;         my @newsequence;
        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});         my @curimport=split(/\&/,$env{'form.curimpdetail'});
        foreach (@importselect) {         foreach (@importselect) {
           $newsequence[$#newsequence+1]=$curimport[$_];            $newsequence[$#newsequence+1]=$curimport[$_];
        }         }
        &pastetarget($lastsel,@newsequence);         &pastetarget($lastsel,@newsequence);
        &storemap(&Apache::lonnet::filelocation('',$url));         &storemap(&Apache::lonnet::filelocation('',$url));
 # -------------------------------------------------------------------- Move up   # -------------------------------------------------------------------- Move up 
    } elsif ($ENV{'form.moveup'}) {     } elsif ($env{'form.moveup'}) {
        foreach (sort @targetselect) {         foreach (sort @targetselect) {
            if ($_-1>0) {             if ($_-1>0) {
               my $movethis=$order[$_-1];                my $movethis=$order[$_-1];
Line 866  sub smpedt { Line 928  sub smpedt {
        }         }
        &storemap(&Apache::lonnet::filelocation('',$url));         &storemap(&Apache::lonnet::filelocation('',$url));
 # ------------------------------------------------------------------ Move down  # ------------------------------------------------------------------ Move down
    } elsif ($ENV{'form.movedown'}) {     } elsif ($env{'form.movedown'}) {
        foreach (reverse sort @targetselect) {         foreach (reverse sort @targetselect) {
            if ($_-1<$#order) {             if ($_-1<$#order) {
               my $movethis=$order[$_-1];                my $movethis=$order[$_-1];
Line 876  sub smpedt { Line 938  sub smpedt {
        }         }
        &storemap(&Apache::lonnet::filelocation('',$url));         &storemap(&Apache::lonnet::filelocation('',$url));
 # --------------------------------------------------------------------- Rename  # --------------------------------------------------------------------- Rename
    } elsif ($ENV{'form.renameres'}) {     } elsif ($env{'form.renameres'}) {
        my $residx=$Apache::lonratedt::order[$ENV{'form.renameidx'}-1];         my $residx=$Apache::lonratedt::order[$env{'form.renameidx'}-1];
        my ($name,@resrest)=split(/\:/,$Apache::lonratedt::resources[$residx]);         my ($name,@resrest)=split(/\:/,$Apache::lonratedt::resources[$residx]);
        $name=$ENV{'form.renametitle'};         $name=$env{'form.renametitle'};
        $name=~s/\:/\&colon\;/g;         $name=~s/\:/\&colon\;/g;
        $Apache::lonratedt::resources[$residx]=$name.':'.join(':',@resrest);         $Apache::lonratedt::resources[$residx]=$name.':'.join(':',@resrest);
        &storemap(&Apache::lonnet::filelocation('',$url));         &storemap(&Apache::lonnet::filelocation('',$url));
Line 919  sub smpedt { Line 981  sub smpedt {
   
 # ----------------------------------------------------- Start simple RAT screen  # ----------------------------------------------------- Start simple RAT screen
    my $editscript=&editscript('simple');     my $editscript=&editscript('simple');
    my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1).     my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,
        &Apache::loncommon::help_open_topic('Sequence_Simple_Editor_Creation').   ($env{'environment.remote'} ne 'off')).
        &Apache::loncommon::help_open_faq(6).         &Apache::loncommon::help_open_menu('','Sequence_Simple_Editor_Creation','Sequence_Simple_Editor_Creation','',6,'RAT');
        &Apache::loncommon::help_open_bug('RAT');  
    my %lt=&Apache::lonlocal::texthash(     my %lt=&Apache::lonlocal::texthash(
       'sa' => 'Save',        'sa' => 'Save',
       'nt' => 'New Title',        'nt' => 'New Title',
Line 1078  sub viewmap { Line 1139  sub viewmap {
     my ($r,$url,$adv,$errtext)=@_;      my ($r,$url,$adv,$errtext)=@_;
     $r->print('<html>'.      $r->print('<html>'.
      &Apache::loncommon::bodytag('Edit Content of a Map').       &Apache::loncommon::bodytag('Edit Content of a Map').
       &Apache::loncommon::help_open_faq(6).        &Apache::loncommon::help_open_menu('','','','',6,'RAT').
       &Apache::loncommon::help_open_bug('RAT').  
       &buttons($adv));        &buttons($adv));
     if ($errtext) {      if ($errtext) {
  $r->print($errtext.'<hr />');   $r->print($errtext.'<hr />');
Line 1089  sub viewmap { Line 1149  sub viewmap {
     if ($adv) {      if ($adv) {
  $r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');   $r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');
     }      }
       $r->print( '<table border="0" cellspacing="2" cellpadding="4">'.
                  '<tr bgcolor="#DDDDDD"><th>'.&mt('Type').'</th>'.
                  '<th>'.&mt('Title in map').'</th>'.
                  '<th>'.&mt('Filename of resource').'</th>'.
                  '<th>'.&mt('Link to published resource').'</th>'.
                  '<th>'.&mt('Link to resource in Construction Space').'</th>'.
                  '</tr>');
       my @backgroundColors = ("#FFFFFF", "#F6F6F6");
     foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {      foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
  if (defined($_)) {   if (defined($_)) {
             $idx++;              $idx++;
     my ($title,$url)=split(/\:/,$_);      my ($title,$url,$cond)=split(/\:/,$_);
       if ($cond eq 'cond') { next; }
             $title=~s/\&colon\;/\:/g;              $title=~s/\&colon\;/\:/g;
             $url=~s/\&colon\;/\:/g;              $url=~s/\&colon\;/\:/g;
             unless ($title) { $title=(split(/\//,$url))[-1] };              unless ($title) { $title=(split(/\//,$url))[-1] };
             unless ($title) { $title='<i>Empty</i>'; }              unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }
               my $resurl = &Apache::lonratsrv::qtescape($url);
               my $resfilepath = $Apache::lonnet::perlvar{'lonDocRoot'}.$resurl;
               my $filename; 
               if ($resurl =~ m#/([^/]+)$#) {
                   $filename = $1;
               }
               my $cstrurl = $resurl;
               $cstrurl =~ s#^/res/[^/]+/([^/]+)/#/priv/$1/#;
               my $bgcol = $idx%2; 
               $r->print('<tr bgcolor='.$backgroundColors[$bgcol].'><td>'.
                         '<img src="'.&Apache::loncommon::icon($resfilepath).
                         '" /></td><td>'.&Apache::lonratsrv::qtescape($title).
                         '</td><td>'.$filename.'</td><td>');
               if ($url) {
                   if (-e $resfilepath) {
       $r->print('<a href="'.$resurl.'">'.&mt('Resource space').'</a>');
                   } else {
                       $r->print(&mt('unpublished'));
                   }
               }
               $r->print('</td><td>');
             if ($url) {              if ($url) {
  $r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');                 $r->print('<a href="'.$cstrurl.'">'.
                            &mt('Construction space').'</a>');
             }              }
             $r->print(&Apache::lonratsrv::qtescape($title));              $r->print('</td></tr>'."\n");
             if ($url) { $r->print('</a>'); }  
     $r->print('<br>');  
         }          }
     }      }
       $r->print('</table>');
     $r->print('</body></html>');      $r->print('</body></html>');
 }  }
   
Line 1116  sub handler { Line 1206  sub handler {
   $r->send_http_header;    $r->send_http_header;
   
   return OK if $r->header_only;    return OK if $r->header_only;
   my $target = $ENV{'form.grade_target'};    my $target = $env{'form.grade_target'};
   if ($target eq 'meta') {    if ($target eq 'meta') {
       &Apache::loncommon::content_type($r,'text/html');        &Apache::loncommon::content_type($r,'text/html');
       $r->send_http_header;        $r->send_http_header;
Line 1135  sub handler { Line 1225  sub handler {
 # ------------------------------------------- Determine which tools can be used  # ------------------------------------------- Determine which tools can be used
   my $adv=0;    my $adv=0;
   
   unless ($ENV{'form.forcesmp'}) {    unless ($env{'form.forcesmp'}) {
      if ($ENV{'form.forceadv'}) {       if ($env{'form.forceadv'}) {
         $adv=1;          $adv=1;
      } elsif (my $fh=Apache::File->new($fn)) {       } elsif (my $fh=Apache::File->new($fn)) {
  my $allmap=join('',<$fh>);   my $allmap=join('',<$fh>);
Line 1154  sub handler { Line 1244  sub handler {
   
 # ----------------------------------- adv==1 now means "graphical MUST be used"  # ----------------------------------- adv==1 now means "graphical MUST be used"
   
   if ($ENV{'form.forceadv'}) {    if ($env{'form.forceadv'}) {
       &ratedt($r,$url);        &ratedt($r,$url);
   } elsif ($ENV{'form.forcesmp'}) {    } elsif ($env{'form.forcesmp'}) {
       &smpedt($r,$url,$errtext);        &smpedt($r,$url,$errtext);
   } else {    } else {
       &viewmap($r,$url,$adv,$errtext);        &viewmap($r,$url,$adv,$errtext);

Removed from v.1.55  
changed lines
  Added in v.1.65


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