--- rat/lonratedt.pm 2002/05/13 14:33:50 1.11 +++ rat/lonratedt.pm 2002/05/14 15:19:13 1.16 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Edit Handler for RAT Maps # -# $Id: lonratedt.pm,v 1.11 2002/05/13 14:33:50 www Exp $ +# $Id: lonratedt.pm,v 1.16 2002/05/14 15:19:13 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -126,6 +126,48 @@ sub mapread { return $errtext; } +# ---------------------------------------------- Read a map as well as possible + +sub attemptread { + my $fn=shift; + + my @links; + undef @links; + my @theseres; + undef @theseres; + + my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,''); + if ($errtext) { return @theseres } + +# -------------------------------------------------------------------- Read map + foreach (split(/\<\&\>/,$outtext)) { + my ($command,$number,$content)=split(/\<\:\>/,$_); + if ($command eq 'objcont') { + $theseres[$number]=$content; + } + if ($command eq 'objlinks') { + $links[$number]=$content; + } + } + +# --------------------------------------------------------------- Sort, sort of + + my $startidx=0; + my $endidx=0; + for (my $i=0; $i<=$#theseres; $i++) { + if (defined($theseres[$i])) { + my ($title,$url,$ext,$type)=split(/\:/,$theseres[$i]); + if ($type eq 'start') { $startidx=$i; } + if ($type eq 'finish') { $endidx=$i; } + } + } + + + return @theseres; + +} + + # --------------------------------------------------------- Build up RAT screen sub ratedt { my ($r,$url)=@_; @@ -166,10 +208,109 @@ sub buttons { sub smpedt { my ($r,$errtext)=@_; my $buttons=&buttons(2); + +# ---------------------------------------------------------- Process form input + + my @importselect=(); + my @targetselect=(); + undef @importselect; + undef @targetselect; + if (defined($ENV{'form.import'})) { + if (ref($ENV{'form.import'})) { + @importselect=sort($ENV->{'form.import'}); + } else { + @importselect=($ENV{'form.import'}); + } + } + if (defined($ENV{'form.target'})) { + if (ref($ENV{'form.target'})) { + @targetselect=sort($ENV->{'form.target'}); + } else { + @targetselect=($ENV{'form.target'}); + } + } +# ============================================================ Process commands + + my $targetdetail=$ENV{'form.targetdetail'}; + my $importdetail=$ENV{'form.curimpdetail'}; + +# ---------------------------------------------------- Importing from groupsort + if (($ENV{'form.importdetail'}) && (!$ENV{'form.impfortarget'})) { + + $importdetail=''; + my @curimport=split(/\&/,$ENV{'form.curimpdetail'}); + + my $lastsel; + + if (defined($importselect[-1])) { + $lastsel=$importselect[-1]; + } else { + $lastsel=$#curimport; + } + + for (my $i=0;$i<=$lastsel;$i++) { + my ($name,$url)=split(/\=/,$curimport[$i]); + if ($url) { + $importdetail.='&'.&Apache::lonnet::escape($name).'='. + &Apache::lonnet::escape($url); + } + } + + $importdetail.='&'.$ENV{'form.importdetail'}; + + for (my $i=$lastsel+1;$i<=$#curimport;$i++) { + my ($name,$url)=split(/\=/,$curimport[$i]); + if ($url) { + $importdetail.='&'.&Apache::lonnet::escape($name).'='. + &Apache::lonnet::escape($url); + } + } + $importdetail=~s/\&+/\&/g; + $importdetail=~s/^\&//; + +# ------------------------------------------------------------------- Clear all + } elsif ($ENV{'form.clear'}) { + $importdetail=''; +# ------------------------------------------------------------ Discard selected + } elsif ($ENV{'form.discard'}) { + $importdetail=''; + my @curimport=split(/\&/,$ENV{'form.curimpdetail'}); + foreach (@importselect) { + $curimport[$_]=''; + } + for (my $i=0;$i<=$#curimport;$i++) { + my ($name,$url)=split(/\=/,$curimport[$i]); + if ($url) { + $importdetail.='&'.&Apache::lonnet::escape($name).'='. + &Apache::lonnet::escape($url); + } + } +# --------------------------- + } + +# ------------------------------------------------------------ Assemble windows + + my $idx=-1; + my $importwindow=join("\n",map { + $idx++; + if ($_) { + my ($name,$url)=split(/\=/,$_); + unless ($name) { $name=(split(/\//,$url))[-1]; } + unless ($name) { $name='EMPTY'; } + ''; + } + } split(/\&/,$importdetail)); + + $idx=0; my $targetwindow=join("\n",map { - my ($name)=split(/\:/,$resources[$_]); - unless ($name) { $name='UNKNOWN'; } - ''; + my ($name,$url)=split(/\:/,$resources[$_]); + unless ($name) { $name=(split(/\//,$url))[-1]; } + unless ($name) { $name='EMPTY'; } + $targetdetail.='&'.&Apache::lonnet::escape($name).'='. + &Apache::lonnet::escape($url); + $idx++; + ''; } @order); # ----------------------------------------------------- Start simple RAT screen @@ -255,31 +396,86 @@ function idxcheck(mode) { } idx.focus(); } + + + var editbrowser; + function openbrowser(formname,elementname,only,omit) { + var url = '/res/?'; + if (editbrowser == null) { + url += 'launch=1&'; + } + url += 'catalogmode=interactive&'; + url += 'mode=edit&'; + url += 'form=' + formname + '&'; + if (only != null) { + url += 'only=' + only + '&'; + } + if (omit != null) { + url += 'omit=' + omit + '&'; + } + url += 'element=' + elementname + ''; + var title = 'Browser'; + var options = 'scrollbars=1,resizable=1,menubar=0'; + options += ',width=700,height=600'; + editbrowser = open(url,title,options,'1'); + editbrowser.focus(); + } $buttons $errtext -
+ - - - + + + + + - -
Import Target
-Group Search -Group Import -   
+
Import Target
+ + +after selected +
+ +
+ + + + +
  + + + +after selected +
+
+ +Cut selected

+


+Paste after selected
+
+ + + + +
+ ENDSMPHEAD - - $r->print(''); } # ----------------------------------------------------------------- No such dir @@ -308,7 +504,8 @@ sub viewmap { my ($title,$url)=split(/\:/,$_); $title=~s/\&colon\;/\:/g; $url=~s/\&colon\;/\:/g; - unless ($title) { $title='Unknown'; } + unless ($title) { $title=(split(/\//,$url))[-1] }; + unless ($title) { $title='Empty'; } if ($url) { $r->print(''); }