[LON-CAPA-cvs] cvs: loncom /imspackages imsimportdocs.pm /interface londocs.pm lonhtmlcommon.pm lonmenu.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Wed Oct 31 08:54:24 EDT 2012


raeburn		Wed Oct 31 12:54:24 2012 EDT

  Modified files:              
    /loncom/interface	londocs.pm lonmenu.pm lonhtmlcommon.pm 
    /loncom/imspackages	imsimportdocs.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Determine whether user can edit a particular resource in a course
    moved from lonmenu.pm to lonnet::can_edit_resource() to facilitate reuse
  - is_course_upload() moved from lonmenu.pm to lonnet.pm
  - file input elements for Upload File and IMS Import moved to fieldsets,
    toggle display by clicking icon/link
  - Discontinue use of static extpickframe.html and extpickcode.html for
    External Resource
  - Edit link to right of resource title in Course Editor added for uploaded
    html, css, js, txt, and for published resources which user has rights to  
    edit 
  - IMS import directly into course -- first page moved from pop-up to 
    inline fieldset; other routines re-named to reflect change in phases
    supported in pop-up window.
  
  
-------------- next part --------------
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.500 loncom/interface/londocs.pm:1.501
--- loncom/interface/londocs.pm:1.500	Wed Oct 31 05:10:16 2012
+++ loncom/interface/londocs.pm	Wed Oct 31 12:54:13 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.500 2012/10/31 05:10:16 raeburn Exp $
+# $Id: londocs.pm,v 1.501 2012/10/31 12:54:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1743,7 +1743,7 @@
 
 sub editor {
     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
-        $supplementalflag,$orderhash,$iconpath)=@_;
+        $supplementalflag,$orderhash,$iconpath,$uploadtag)=@_;
     my $container= ($env{'form.pagepath'}) ? 'page'
 		                           : 'sequence';
 
@@ -1899,7 +1899,8 @@
         unless ($name) {  $name=(split(/\//,$url))[-1]; }
         unless ($name) { $idx++; next; }
         $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
-                              $coursenum,$crstype);
+                              $coursenum,$coursedom,$crstype,
+                              $uploadtag,$supplementalflag);
         $idx++;
         $shown++;
     }
@@ -2116,7 +2117,8 @@
 # --------------------------------------------------------------- An entry line
 
 sub entryline {
-    my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$crstype)=@_;
+    my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
+        $crstype,$uploadtag,$supplementalflag)=@_;
     my ($foldertitle,$pagetitle,$renametitle);
     if (&is_supplemental_title($title)) {
 	($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
@@ -2130,7 +2132,6 @@
 
     my $orderidx=$LONCAPA::map::order[$index];
 
-
     $renametitle=~s/\\/\\\\/g;
     $renametitle=~s/\&quot\;/\\\"/g;
     $renametitle=~s/ /%20/g;
@@ -2149,8 +2150,18 @@
         $type = $container = 'page';
         $esc_path=&escape($env{'form.pagepath'});
 	$path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
-        $symb=&escape($env{'form.pagesymb'});
     }
+    if (!$supplementalflag && $residx) {
+        my $currurl = $url;
+        $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
+        my $path = 'uploaded/'.
+                   $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
+                   $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
+        $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
+                                             $residx,
+                                             &Apache::lonnet::declutter($currurl));
+    }
+    my %lt;
     if ($allowed) {
 	my $incindex=$index+1;
 	my $selectbox='';
@@ -2173,13 +2184,20 @@
 	    }
 	    $selectbox.='</select>';
 	}
-	my %lt=&Apache::lonlocal::texthash(
+	%lt=&Apache::lonlocal::texthash(
                 'up' => 'Move Up',
 		'dw' => 'Move Down',
 		'rm' => 'Remove',
                 'ct' => 'Cut',
 		'rn' => 'Rename',
-		'cp' => 'Copy');
+		'cp' => 'Copy',
+                'ex' => 'External Resource',
+                'ed' => 'Edit',
+                'pr' => 'Preview',
+                'sv' => 'Save',
+                'ul' => 'URL',
+                'ti' => 'Title', 
+                );
 	my $nocopy=0;
         my $nocut=0;
         my $noremove=0;
@@ -2285,12 +2303,12 @@
 <td>
 <div class="LC_docs_entry_move">
   <a href='/adm/coursedocs?cmd=up_$index&${type}path=$esc_path&${type}symb=$symb'>
-    <img src="${iconpath}move_up.gif" alt='$lt{'up'}' class="LC_icon" />
+    <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
   </a>
 </div>
 <div class="LC_docs_entry_move">
   <a href='/adm/coursedocs?cmd=down_$index&${type}path=$esc_path&${type}symb=$symb'>
-    <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' class="LC_icon" />
+    <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
   </a>
 </div>
 </td>
@@ -2341,43 +2359,37 @@
 	}
     }
 
+    my $editlink;
     my $orig_url = $url;
     $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
     my $external = ($url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/});
-    if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
-	my $symb=&Apache::lonnet::symbclean(
-          &Apache::lonnet::declutter('uploaded/'.
-           $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
-           $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
-           '.sequence').
-           '___'.$residx.'___'.
-	   &Apache::lonnet::declutter($url));
-	(undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
-	$url=&Apache::lonnet::clutter($url);
-	if ($url=~/^\/*uploaded\//) {
-	    $url=~/\.(\w+)$/;
-	    my $embstyle=&Apache::loncommon::fileembstyle($1);
-	    if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
-		$url='/adm/wrapper'.$url;
-	    } elsif ($embstyle eq 'ssi') {
-		#do nothing with these
-	    } elsif ($url!~/\.(sequence|page)$/) {
-		$url='/adm/coursedocs/showdoc'.$url;
+    if (!$supplementalflag && $residx && $symb) {
+        if ($container eq 'page') {
+            $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
+            $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
+        } 
+        if ((!$isfolder) && (!$ispage)) {
+	    (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
+	    $url=&Apache::lonnet::clutter($url);
+	    if ($url=~/^\/*uploaded\//) {
+	        $url=~/\.(\w+)$/;
+	        my $embstyle=&Apache::loncommon::fileembstyle($1);
+	        if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
+		    $url='/adm/wrapper'.$url;
+	        } elsif ($embstyle eq 'ssi') {
+		    #do nothing with these
+	        } elsif ($url!~/\.(sequence|page)$/) {
+		    $url='/adm/coursedocs/showdoc'.$url;
+	        }
+	    } elsif ($url=~m|^/ext/|) {
+	        $url='/adm/wrapper'.$url;
+	        $external = 1;
 	    }
-	} elsif ($url=~m|^/ext/|) {
-	    $url='/adm/wrapper'.$url;
-	    $external = 1;
-	}
-        if (&Apache::lonnet::symbverify($symb,$url)) {
-	    $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
-        } else {
-            $url='';
-        }
-	if ($container eq 'page') {
-	    my $symb=$env{'form.pagesymb'};
-
-	    $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
-	    $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
+            if (&Apache::lonnet::symbverify($symb,$url)) {
+	        $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
+            } else {
+                $url='';
+            }
 	}
     }
     my ($rand_pick_text,$rand_order_text);
@@ -2424,23 +2436,50 @@
         my $folderpath=$env{'form.folderpath'};
         if ($folderpath) { $pagepath = $folderpath.'&' };
         $pagepath.=$pagearg.'&'.$pagename;
-	my $symb=$env{'form.pagesymb'};
-	if (!$symb) {
-	    my $path='uploaded/'.
-		$env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
-		$env{'course.'.$env{'request.course.id'}.'.num'}.'/';
-	    $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
-					       $residx,
-					       $path.$pagearg.'.page');
-	}
 	$url.='pagepath='.&escape($pagepath).
 	    '&pagesymb='.&escape($symb);
     }
-    if (($external) && ($allowed)) {
-	my $form = ($folder =~ /^default/)? 'newext' : 'supnewext';
-	$external = ' <a class="LC_docs_ext_edit" href="javascript:edittext(\''.$form.'\',\''.$residx.'\',\''.&escape($title).'\',\''.&escape($orig_url).'\');" >'.&mt('Edit').'</a>';
-    } else {
-	undef($external);
+    if ($allowed) {
+        my $fileloc = 
+            &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
+
+        if ($external) {
+	    $editlink = <<"EXTLNK";
+             
+            <a class="LC_docs_ext_edit" href="javascript:editext('$residx');">
+            $lt{'ed'}</a>
+            <form action="/adm/coursedocs" method="post" name="editext_$residx">
+            <fieldset id="uploadext$residx" style="display: none;" />
+            <input type="hidden" name="active" value="aa" />
+            <span class="LC_nobreak">
+            <span class="LC_docs_ext_edit">$lt{'ul'} </span>
+            <input type="text" size="40" name="exturl" id="exturl_$residx" value="$orig_url" /> 
+            <a class="LC_docs_ext_edit" href="javascript:extUrlPreview('exturl_$residx');">$lt{'pr'}</a></span>
+            </span><br />
+            <span class="LC_nobreak">
+            <span class="LC_docs_ext_edit">$lt{'ti'} </span>
+            <input type="text" size="40" name="exttitle" value="$title" />
+            $uploadtag
+            <input type="hidden" name="importdetail" value="" />
+            <input type="button" value="$lt{'sv'}" onclick="javascript:setExternal(this.form,'$residx')" />
+            </span>
+            </fieldset>
+            </form>
+EXTLNK
+        } else { 
+            my ($cfile,$home,$switchserver,$uploaded) = 
+                &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom);
+            if (($cfile ne '') && ($symb ne '')) {
+                my $jscall = 
+                    &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
+                                                            $switchserver,
+                                                            $uploaded,$symb);
+                if ($jscall) {
+                    $editlink = ' <a class="LC_docs_ext_edit" href="javascript:'.
+                                $jscall.'" >'.&mt('Edit').'</a>';
+                }
+            }
+        }
     }
     my $reinit;
     if ($crstype eq 'Community') {
@@ -2466,7 +2505,7 @@
     } else {
        $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
     }
-    $line.=$external."</td>";
+    $line.=$editlink."</td>";
     $rand_pick_text = ' ' if ($rand_pick_text eq '');
     $rand_order_text = ' ' if ($rand_order_text eq '');
     if (($allowed) && ($folder!~/^supplemental/)) {
@@ -3029,9 +3068,9 @@
 sub create_list_elements {
    my @formarr = @_;
    my $list = '';
-   for my $button (@formarr){
-        for my $picture(keys %$button) {
-            $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text'});
+   foreach my $button (@formarr){
+        foreach my $picture (keys(%{$button})) {
+            $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
         }
    }
    return $list;
@@ -3101,7 +3140,8 @@
 	               'Adding_External_Resource','Navigate_Content',
 	               'Adding_Folders','Docs_Overview', 'Load_Map',
 	               'Supplemental','Score_Upload_Form','Adding_Pages',
-	               'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
+	               'Importing_LON-CAPA_Resource','Importing_IMS_Course',
+                       'Uploading_From_Harddrive',
 	               'Check_Resource_Versions','Verify_Content') {
 	$help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
     }
@@ -3395,6 +3435,10 @@
         if ($env{'docs.markedcopy_url'}) {
             $script .= &paste_popup_js(); 
         }
+        my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
+                             &mt('Switch server?');
+        
+
     }
 # -------------------------------------------------------------------- Body tag
     $script = '<script type="text/javascript">'."\n"
@@ -3487,7 +3531,8 @@
                 'upls' => 'Upload a new supplemental '.lc($crstype).' document',
                 'impp' => 'Import a document',
 		'copm' => 'All documents out of a published map into this folder',
-                'upld' => 'Import Document',
+                'upfi' => 'Upload File',
+                'upld' => 'Import Content',
                 'srch' => 'Search',
                 'impo' => 'Import',
 		'lnks' => 'Import from Stored Links',
@@ -3510,9 +3555,14 @@
 				'abou' => 'Personal Information Page for a User',
                 'imsf' => 'IMS Import',
                 'imsl' => 'Import IMS package',
+                'cms'  => 'Origin of IMS package',
+                'se'   => 'Select',
                 'file' =>  'File',
                 'title' => 'Title',
                 'comment' => 'Comment',
+                'url'  => 'URL',
+                'prev' => 'Preview',
+                'lnk'  => 'Add Link', 
                 'parse' => 'Upload embedded images/multimedia files if HTML file',
 		'nd' => 'Upload Document',
 		'pm' => 'Published Map',
@@ -3533,10 +3583,41 @@
 	<input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
 	</label>
 CHBO
+        my $imsfolder = $env{'form.folder'};
+        if ($imsfolder eq '') {
+            $imsfolder = 'default';  
+        }
+        my $imspform=(<<IMSFORM);
+        <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
+        $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
+        <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
+        <fieldset id="uploadimsform" style="display: none;" />
+        <legend>$lt{'imsf'}</legend>
+        $fileupload
+        <br />
+        <p>
+        $lt{'cms'}:  
+        <select name="source">
+        <option value="-1" selected="selected">$lt{'se'}</option>
+        <option value="bb5">Blackboard 5</option>
+        <option value="bb6">Blackboard 6</option>
+        <option value="angel5">ANGEL 5.5</option>
+        <option value="webctce4">WebCT 4 Campus Edition</option>
+        </select>
+        <input type="hidden" name="folder" value="$imsfolder" />
+        </p>
+        <input type="hidden" name="phase" value="one" />
+        <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" />
+        </fieldset>
+        </form>
+IMSFORM
 
-    my $fileuploada = "<br clear='all' /><input type='submit' value='".$lt{'upld'}."' /> $help{'Uploading_From_Harddrive'}";
 	my $fileuploadform=(<<FUFORM);
-	<form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
+        <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
+        $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
+        <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
+        <fieldset id="uploaddocform" style="display: none;" />
+        <legend>$lt{'upfi'}</legend>
 	<input type="hidden" name="active" value="aa" />
 	$fileupload
 	<br />
@@ -3548,8 +3629,11 @@
 	<span class="LC_nobreak" style="float:left">
 	$checkbox
 	</span>
+        <br clear="all" />
+        <input type="submit" value="$lt{'upld'}" />
+        </fieldset>
+        </form>
 FUFORM
-    $fileuploadform .= $fileuploada.'</form>';
 
 	my $simpleeditdefaultform=(<<SEDFFORM);
 	<form action="/adm/coursedocs" method="post" name="simpleeditdefault">
@@ -3573,10 +3657,21 @@
 SEDFFORM
 
       my $extresourcesform=(<<ERFORM);
+      <a class="LC_menubuttons_link" href="javascript:toggleUpload('ext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
       <form action="/adm/coursedocs" method="post" name="newext">
+      <fieldset id="uploadextform" style="display: none;" />
+      <legend>$lt{'extr'}</legend>
+      <input type="hidden" name="active" value="aa" />
+      $lt{'url'}:<br />
+      <input type="text" size="60" name="exturl" id="exturl" value="http://" />
+      <input type="button" name="view" value="$lt{'prev'}" onclick="javascript:extUrlPreview('exturl');" /><br />
+      $lt{'title'}:<br />
+      <input type="text" size="60" name="exttitle" value="$lt{'extr'}" />
       $uploadtag
+      <br />
       <input type="hidden" name="importdetail" value="" />
-      <a class="LC_menubuttons_link" href="javascript:makenewext('newext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
+      <input type="button" value="$lt{'lnk'}" onclick="javascript:setExternal(this.form,0)" />
+      </fieldset>
       </form>
 ERFORM
 
@@ -3645,13 +3740,6 @@
 	}
 	my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
 
-	my $imspform=(<<IMSPFORM);
-	<form action="/adm/imsimportdocs" method="post" name="ims">
-	<input type="hidden" name="folder" value="$folder" />
-	<a class="LC_menubuttons_link" href="javascript:makeims();">$lt{'imsf'}</a>
-	</form>
-IMSPFORM
-
 	my $newnavform=(<<NNFORM);
 	<form action="/adm/coursedocs" method="post" name="newnav">
 	<input type="hidden" name="active" value="cc" />
@@ -3807,9 +3895,11 @@
 
 
         my @importdoc = (
-        {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'newext\');" />'=>$extresourcesform},
-        {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:makeims();" />'=>$imspform},);
-        $fileuploadform =  &create_form_ul(&create_list_elements(@importdoc)) . '<hr id="cc_hrule" style="width:0px;text-align:left;margin-left:0" />' . $fileuploadform;
+        {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform},
+        {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform},
+        {'<img class="LC_noBorder_LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform,
+        });
+        $fileuploadform =  &create_form_ul(&create_list_elements(@importdoc));
 
         @gradingforma=(
         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
@@ -3842,7 +3932,7 @@
  $hadchanges=0;
        unless (($supplementalflag || $toolsflag)) {
           my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
-                              $supplementalflag,\%orderhash,$iconpath);
+                              $supplementalflag,\%orderhash,$iconpath,$uploadtag);
           if ($error) {
              $r->print('<p><span class="LC_error">'.$error.'</span></p>');
           }
@@ -3874,9 +3964,12 @@
 
 	   my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
 
-	my $supupdocformbtn = "<input type='submit' value='".$lt{'upld'}."' />$help{'Uploading_From_Harddrive'}";
 	my $supupdocform=(<<SUPDOCFORM);
+        <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
+        $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
 	<form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
+        <fieldset id="uploadsuppdocform" style="display: none;" />
+        <legend>$lt{'upfi'}</legend>
 	<input type="hidden" name="active" value="ee" />	
 	$fileupload
 	<br />
@@ -3890,8 +3983,9 @@
 	<br />
 	<input type="hidden" name="folderpath" value="$path" />
 	<input type="hidden" name="cmd" value="upload_supplemental" />
+        <input type='submit' value="$lt{'upld'}" />
+        </form>
 SUPDOCFORM
-	$supupdocform .=  &create_form_ul(&Apache::lonhtmlcommon::htmltag('li',$supupdocformbtn,{class => 'LC_menubuttons_inline_text'}))."</form>";
 
 	my $supnewfolderform=(<<SNFFORM);
 	<form action="/adm/coursedocs" method="post" name="supnewfolder">
@@ -3903,15 +3997,24 @@
 	</form>
 SNFFORM
 	
-
-	my $supnewextform=(<<SNEFORM);
-	<form action="/adm/coursedocs" method="post" name="supnewext">
-	<input type="hidden" name="active" value="ff" />
-	<input type="hidden" name="folderpath" value="$path" />
-	<input type="hidden" name="importdetail" value="" />
-	<a class="LC_menubuttons_link" href="javascript:makenewext('supnewext');">$lt{'extr'}</a> $help{'Adding_External_Resource'}
-	</form>
-SNEFORM
+        my $supextform=(<<ERFORM);
+        <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
+        <form action="/adm/coursedocs" method="post" name="newsuppext">
+        <fieldset id="uploadsuppextform" style="display: none;" />
+        <legend>$lt{'extr'}</legend>
+        <input type="hidden" name="active" value="ee" />
+        $lt{'url'}:<br />
+        <input type="text" size="60" name="exturl" id="exturl" value="http://" />
+        <input type="button" name="view" value="$lt{'prev'}" onclick="javascript:extUrlPreview('exturl');" /><br />
+        $lt{'title'}:<br />
+        <input type="text" size="60" name="exttitle" value="$lt{'extr'}" />
+        $uploadtag
+        <br />
+        <input type="hidden" name="importdetail" value="" />
+        <input type="button" value="$lt{'lnk'}" onclick="javascript:setExternal(this.form,0)" />
+        </fieldset>
+        </form>
+ERFORM
 
 	my $supnewsylform=(<<SNSFORM);
 	<form action="/adm/coursedocs" method="post" name="supnewsyl">
@@ -3943,10 +4046,13 @@
             =>$supnewaboutmeform},
 		);
 my @supimportdoc = (
-		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'supnewext\');" />'
-            =>$supnewextform},
-        );
-$supupdocform =  &create_form_ul(&create_list_elements(@supimportdoc)) . '<hr id="ee_hrule" style="width:0px;text-align:left;margin-left:0" />' . $supupdocform;
+		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'suppext\')" />'
+            =>$supextform},
+                {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
+            =>$supupdocform},
+                   );
+
+$supupdocform =  &create_form_ul(&create_list_elements(@supimportdoc));
 my %suporderhash = (
 		'00' => ['Supnewfolder', $supnewfolderform],
                 'ee' => ['Import Content',$supupdocform],
@@ -3954,14 +4060,14 @@
                 );
         if ($supplementalflag) {
            my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
-                               $supplementalflag,\%suporderhash,$iconpath);
+                               $supplementalflag,\%suporderhash,$iconpath,$uploadtag);
            if ($error) {
               $r->print('<p><span class="LC_error">'.$error.'</span></p>');
            }
         }
     } elsif ($supplementalflag) {
         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
-                            $supplementalflag,'',$iconpath);
+                            $supplementalflag,'',$iconpath,$uploadtag);
         if ($error) {
             $r->print('<p><span class="LC_error">'.$error.'</span></p>');
         }
@@ -4317,6 +4423,10 @@
                                           p_ctr2a => 'Cut[_98]',
                                           p_ctr2b => '?[_98]',
                                           rpck    => 'Enter number to pick (e.g., 3)',
+                                          imsfile => 'You must choose an IMS package for import',
+                                          imscms  => 'You must select which Course Management System was the source of the IMS package',
+                                          invurl  => 'Invalid URL',
+                                          titbl   => 'Title is blank',
                                         );
 
     my $crstype = &Apache::loncommon::course_type();
@@ -4336,6 +4446,15 @@
         $backtourl = '/adm/supplemental';
     }
 
+    my $fieldsets = "'ext','doc','ims'";
+    if ($supplementalflag) {
+        $fieldsets = "'suppext','suppdoc'";
+    }
+
+    my $urlregexp = <<'ENDREGEXP';
+/^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|!
 @)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i
+ENDREGEXP
+
     return <<ENDNEWSCRIPT;
 function makenewfolder(targetform,folderseq) {
     var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
@@ -4353,20 +4472,18 @@
     }
 }
 
-function makenewext(targetname) {
-    this.document.forms.extimport.useform.value=targetname;
-    this.document.forms.extimport.title.value='';
-    this.document.forms.extimport.url.value='';
-    this.document.forms.extimport.residx.value='';
-    window.open('/adm/rat/extpickframe.html');
-}
-
-function edittext(targetname,residx,title,url) {
-    this.document.forms.extimport.useform.value=targetname;
-    this.document.forms.extimport.residx.value=residx;
-    this.document.forms.extimport.url.value=url;
-    this.document.forms.extimport.title.value=title;
-    window.open('/adm/rat/extpickframe.html');
+function editext(residx) {
+    if (document.getElementById('uploadext'+residx)) {
+        var curr = document.getElementById('uploadext'+residx).style.display;
+        if (curr == 'none') {
+            disp = 'block';
+        } else {
+            disp = 'none';
+        }
+        document.getElementById('uploadext'+residx).style.display=disp;
+    }
+    resize_scrollbox('contentscroll','1','1');
+    return;
 }
 
 function makeexamupload() {
@@ -4433,19 +4550,70 @@
 }
 }
 
-function makeims() {
-var caller = document.forms.ims.folder.value;
-var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
-newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
-newWindow.location.href = newlocation;
+function toggleUpload(caller) {
+    var blocks = Array($fieldsets);
+    for (var i=0; i<blocks.length; i++) {
+        var disp = 'none';
+        if (caller == blocks[i]) {
+            var curr = document.getElementById('upload'+caller+'form').style.display;
+            if (curr == 'none') {
+                disp='block';
+            }
+        }
+        document.getElementById('upload'+blocks[i]+'form').style.display=disp;
+    }
+    resize_scrollbox('contentscroll','1','0');
+    return;
 }
 
-function finishpick() {
-var title=this.document.forms.extimport.title.value;
-var url=this.document.forms.extimport.url.value;
-var form=this.document.forms.extimport.useform.value;
-var residx=this.document.forms.extimport.residx.value;
-eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
+function extUrlPreview(caller) {
+    if (document.getElementById(caller)) {
+        var url = document.getElementById(caller).value;
+        var regexp = $urlregexp;
+        if (regexp.test(url)) {
+            openMyModal(url,500,400,'yes');
+        } else {
+            alert("$lt{'invurl'}");
+        }
+    }
+}
+
+function makeims(imsform) {
+    if ((imsform.uploaddoc.value == '')  || (!imsform.uploaddoc.value)) {
+        alert("$lt{'imsfile'}");
+        return;
+    }
+    if (imsform.source.selectedIndex == 0) {
+        alert("$lt{'imscms'}");
+        return;
+    }
+    newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
+    imsform.submit();
+}
+
+function setExternal(extform,residx) {
+    var title=extform.exttitle.value;
+    if (!String.trim) {
+        String.prototype.trim = function() {return this.replace(\/^\\s+|\\s+$\/g, "");};    }
+    var url=extform.exturl.value;
+    var regexp = $urlregexp;
+    if (title == null || title.trim()=="") {
+        alert("$lt{'titbl'}");
+        extform.exttitle.focus();
+        return;
+    }
+    if (regexp.test(url)) {
+        url = escape(url);
+        if (residx > 0) {
+            eval("extform.importdetail.value=title+'='+url+'='+residx;extform.submit();");
+        } else {
+            eval("extform.importdetail.value=title+'='+url;extform.submit();");
+        }
+    } else {
+        alert("$lt{'invurl'}");
+        extform.exturl.focus();
+        return;
+    }
 }
 
 function changename(folderpath,index,oldtitle,container,pagesymb) {
@@ -4599,6 +4767,7 @@
 	currentData = document.getElementById(pageId);
 	currentData.style.display = 'block';
         activeTab = pageId;
+        toggleUpload();
         if (nav == 'mainnav') {
             var storedpath = "$docs_folderpath";
             if (storedpath == '') {
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.388 loncom/interface/lonmenu.pm:1.389
--- loncom/interface/lonmenu.pm:1.388	Mon Oct 29 17:38:56 2012
+++ loncom/interface/lonmenu.pm	Wed Oct 31 12:54:13 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.388 2012/10/29 17:38:56 raeburn Exp $
+# $Id: lonmenu.pm,v 1.389 2012/10/31 12:54:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -523,7 +523,7 @@
         ###
         my $editbutton = '';
         my $noeditbutton = 1;
-        my ($cnum,$cdom);
+        my ($cnum,$cdom,$cfile,$switchserver,$home,$uploaded);
         if ($env{'request.course.id'}) {
             $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
@@ -555,95 +555,50 @@
                 my $home = &Apache::lonnet::homeserver($caname,$cadom);
 		my $allowed=0;
 		my @ids=&Apache::lonnet::current_machine_ids();
-		foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
-		if (!$allowed) {
+		if (($home ne 'no_host') && (grep(/^\Q$home\E$/, at ids))) {
 		    $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
-                    $noeditbutton = 0;
                 }
-            }
+            } else {
 #
 # We are an author for some stuff, but currently do not have the role of author.
 # Figure out if we have authoring privileges for the resource we are looking at.
-# This should maybe become a privilege check in lonnet
 #
-            ##
-            ## Determine if user can edit url.
-            ##
-            my $cfile='';
-            my $cfuname='';
-            my $cfudom='';
-            my $uploaded;
-            my $switchserver='';
-            my $home;
-            if ($env{'request.filename'}) {
-                my $file=&Apache::lonnet::declutter($env{'request.filename'});
-                if (defined($cnum) && defined($cdom)) {
-                    $uploaded = &is_course_upload($file,$cnum,$cdom);
-                }
-                if (!$uploaded) {
-
-                    $file=~s{^(priv/$match_domain/$match_username)}{/$1};
-                    $file=~s{^($match_domain/$match_username)}{/priv/$1};
-
-                    # Check that the user has permission to edit this resource
-                    my $setpriv = 1;
-                    ($cfuname,$cfudom)=&Apache::lonnet::constructaccess($file,$setpriv);
-                    if (defined($cfudom)) {
-		        $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
-		        my $allowed=0;
-		        my @ids=&Apache::lonnet::current_machine_ids();
-		        foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
-		        if ($allowed) {
-                            $cfile=$file;
-                        } else {
-                            $switchserver=$file;
+                my ($cfile,$switchserver,$home,$uploaded);
+                if ($env{'request.filename'}) {
+                    my $file=&Apache::lonnet::declutter($env{'request.filename'});
+                    ##
+                    ## Determine if user can edit url.
+                    ##
+                    ($cfile,$home,$switchserver,$uploaded) =
+                        &Apache::lonnet::can_edit_resource($file,$cnum,$cdom);
+                }
+                # Turn the button on or off
+                if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
+                    my $nocrsedit;
+                    # Suppress display where CC has switched to student role.
+                    if ($env{'request.course.id'}) {
+                        unless(&Apache::lonnet::allowed('mdc',
+                                                        $env{'request.course.id'})) {
+                            $nocrsedit = 1;
                         }
                     }
-                }
-            }
-            # Finally, turn the button on or off
-            if (($cfile || $switchserver) && !$const_space) {
-                my $nocrsedit;
-                # Suppress display where CC has switched to student role.
-                if ($env{'request.course.id'}) {
-                    unless(&Apache::lonnet::allowed('mdc',
-                                                    $env{'request.course.id'})) {
-                        $nocrsedit = 1;
+                    if ($nocrsedit) {
+                        $editbutton=&clear(6,1);
+                    } else {
+                        $editbutton = &get_editbutton($cfile,$home,$switchserver,$uploaded);
                     }
-                }
-                if ($nocrsedit) {
+                } elsif ($editbutton eq '') {
                     $editbutton=&clear(6,1);
-                } else {
-                    my $bot = "go('$cfile')";
-                    if ($switchserver) {
-                        if ( $env{'request.symb'} && $env{'request.course.id'} ) {
-                            $cfile = '/adm/switchserver?otherserver='.$home.'&role='.
-                                     &HTML::Entities::encode($env{'request.role'},'"<>&').'&symb='.
-                                     &HTML::Entities::encode($env{'request.symb'},'"<>&');
-                            $bot = "need_switchserver('$cfile');";
-                        }
-                    }
-                    $editbutton=&switch
-                       ('','',6,1,'pcstr.png','Edit','resource[_2]',
-                        $bot,"Edit this resource");
-                    $noeditbutton = 0;
                 }
-            } elsif ($editbutton eq '') {
-                $editbutton=&clear(6,1);
             }
-        }
-        if (($noeditbutton) && ($env{'request.filename'})) { 
+        } elsif (($env{'request.filename'}) && $env{'request.course.id'}) {
             if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
-                if (defined($cnum) && defined($cdom)) {
-                    if (&is_course_upload($file,$cnum,$cdom)) {
-                        my $cfile = &edit_course_upload($file,$cnum,$cdom);
-                        if ($cfile) {
-                            $editbutton=&switch
-                                        ('','',6,1,'pcstr.png','Edit',
-                                         'resource[_2]',"go('".$cfile."');",
-                                         'Edit this resource');
-                        }
+                if (($cnum =~ /$match_courseid/) && ($cdom =~ /$match_domain/)) {
+                    my ($cfile,$home,$switchserver,$uploaded) =
+                        &Apache::lonnet::can_edit_resource($file,$cnum,$cdom);
+                    if (($uploaded) && ($cfile ne '')) {
+                        $editbutton = &get_editbutton($cfile,$home,$switchserver,$uploaded);
                     }
                 }
             }
@@ -829,40 +784,14 @@
            . &Apache::lonhtmlcommon::scripttag('', 'end');
 }
 
-sub is_course_upload {
-    my ($file,$cnum,$cdom) = @_;
-    my $uploadpath = &LONCAPA::propath($cdom,$cnum);
-    $uploadpath =~ s{^\/}{};
-    if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
-        ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
-        return 1;
-    }
-    return;
-}
-
-sub edit_course_upload {
-    my ($file,$cnum,$cdom) = @_;
-    my $cfile;
-    if ($file =~/\.(htm|html|css|js|txt)$/) {
-        my $ext = $1;
-        my $url = &Apache::lonnet::hreflocation('',$file);
-        my $home = &Apache::lonnet::homeserver($cnum,$cdom);
-        my @ids=&Apache::lonnet::current_machine_ids();
-        my $dest;
-        if ($home && grep(/^\Q$home\E$/, at ids)) {
-            $dest = $url.'?forceedit=1';
-        } else {
-            unless (&Apache::lonnet::get_locks()) {
-                $dest = '/adm/switchserver?otherserver='.
-                        $home.'&role='.$env{'request.role'}.
-                        '&url='.$url.'&forceedit=1';
-            }
-        }
-        if ($dest) {
-            $cfile = &HTML::Entities::encode($dest,'"<>&');
-        }
+sub get_editbutton {
+    my ($cfile,$home,$switchserver,$uploaded) = @_;
+    my $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
+                                                         $uploaded,$env{'request.symb'});
+    if ($jscall) {
+        return &switch('','',6,1,'pcstr.png','Edit','resource[_2]',
+                       $jscall,"Edit this resource");
     }
-    return $cfile;
 }
 
 # ================================================================== Raw Config
@@ -1264,8 +1193,7 @@
     my $end_page_annotate = 
         &Apache::loncommon::end_page({'js_ready' => 1});
 
-    my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
-                         &mt('Switch server?');
+    my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
 
     my $esc_url=&escape($currenturl);
     my $esc_symb=&escape($currentsymb);
@@ -1280,22 +1208,7 @@
 
 $dc_popup_cid
 
-function go(url) {
-   if (url!='' && url!= null) {
-       currentURL = null;
-       currentSymb= null;
-       window.location.href=url;
-   }
-}
-
-function need_switchserver(url) {
-    if (url!='' && url!= null) {
-        if (confirm("$confirm_switch")) {
-            go(url); 
-        }
-    }
-    return;
-}
+$jumptores
 
 function gopost(url,postdata) {
    if (url!='') {
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.327 loncom/interface/lonhtmlcommon.pm:1.328
--- loncom/interface/lonhtmlcommon.pm:1.327	Mon Oct  8 10:47:34 2012
+++ loncom/interface/lonhtmlcommon.pm	Wed Oct 31 12:54:13 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.327 2012/10/08 10:47:34 foxr Exp $
+# $Id: lonhtmlcommon.pm,v 1.328 2012/10/31 12:54:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3011,6 +3011,56 @@
     return $output;
 }
 
+##############################################
+##############################################
+
+sub javascript_jumpto_resource {
+    my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
+                         &mt('Switch server?');
+    return (<<ENDUTILITY)
+
+function go(url) {
+   if (url!='' && url!= null) {
+       currentURL = null;
+       currentSymb= null;
+       window.location.href=url;
+   }
+}
+
+function need_switchserver(url) {
+    if (url!='' && url!= null) {
+        if (confirm("$confirm_switch")) {
+            go(url);
+        }
+    }
+    return;
+}
+
+ENDUTILITY
+
+}
+
+sub jump_to_editres {
+    my ($cfile,$home,$switchserver,$uploaded,$symb) = @_;
+    my $jscall;
+    if ($switchserver) {
+        if ($symb && $home) {
+            $cfile = '/adm/switchserver?otherserver='.$home.'&role='.
+                     &HTML::Entities::encode($env{'request.role'},'"<>&').'&'.
+                    'symb='.&HTML::Entities::encode($env{'request.symb'},'"<>&');
+            if ($uploaded) {
+                $cfile .= '&forceedit=1';
+            }
+            $jscall = "need_switchserver('$cfile');";
+        }
+    } else {
+        if ($uploaded) {
+            $cfile .= '?forceedit=1';
+        }
+        $jscall = "go('$cfile')";
+    }
+    return $jscall;
+}
 
 ##############################################
 ##############################################
Index: loncom/imspackages/imsimportdocs.pm
diff -u loncom/imspackages/imsimportdocs.pm:1.29 loncom/imspackages/imsimportdocs.pm:1.30
--- loncom/imspackages/imsimportdocs.pm:1.29	Fri Nov 20 18:25:34 2009
+++ loncom/imspackages/imsimportdocs.pm	Wed Oct 31 12:54:17 2012
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: imsimportdocs.pm,v 1.29 2009/11/20 18:25:34 bisitz Exp $
+# $Id: imsimportdocs.pm,v 1.30 2012/10/31 12:54:17 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -33,7 +33,6 @@
 use Apache::loncommon;
 use Apache::lonlocal;
 use Apache::imsprocessor;
-use LONCAPA::Configuration;
 use LONCAPA::map();
 use lib '/home/httpd/lib/perl/';
 use LONCAPA;
@@ -41,54 +40,41 @@
 use strict;
 
 sub jscript_one {
-    my $javascript = shift;
-    $$javascript = qq#
-function verify() {
- if ((document.forms.pickcms.uploadname.value == '')  || (!document.forms.pickcms.uploadname.value)) {
-   alert("You must provide the name of the IMS package to be imported")
-   return false
- }
- if (document.forms.pickcms.source.selectedIndex == 0) {
-   alert("You must choose the Course Management System from which the IMS package was exported");
-   return false
- }
- return true
-}
-
-function nextPage() {
- if (verify()) {
-   document.forms.pickcms.submit()
- }
-}
-#;
- 
-}
-
-sub jscript_two {
-    my $javascript = shift;
-    $$javascript = qq#
+    my %lt = &Apache::lonlocal::texthash(
+               se => 'Select',
+               to => 'Import topics only',
+               tp => 'Import topics + posts (with author)',
+               tn => 'Import topics + posts (no author)',
+               es => 'Enroll students only',
+               ea => 'Enroll all users',
+               nr => 'Not required',
+               id => 'You must select one of the additional options when importing Disussion Boards',
+               ie => 'You must select one of the additional options when importing Enrollment',
+               ct => 'You must check at least one Content Type', 
+    );
+    return <<"ENDJS";
 function setOptions(caller,itemnum) {
   var opForm = document.forms.pickoptions
   var menu = 1 + itemnum*2
   opForm.elements[menu].length = 0
   if (opForm.elements[itemnum*2].checked == true) {
     if (caller == "board") {
-      opForm.elements[menu].options[0] = new Option("Select","-1",true,true)
-      opForm.elements[menu].options[1] = new Option("Import topics only","topics",true,true)
-      opForm.elements[menu].options[2] = new Option("Import topics + posts (with author)","allpost",true,true)
-      opForm.elements[menu].options[3] = new Option("Import topics + posts (no author)","allanon",true,true)
+      opForm.elements[menu].options[0] = new Option("$lt{'se'}","-1",true,true)
+      opForm.elements[menu].options[1] = new Option("$lt{'to'}","topics",true,true)
+      opForm.elements[menu].options[2] = new Option("$lt{'tp'}","allpost",true,true)
+      opForm.elements[menu].options[3] = new Option("$lt{'tn'}","allanon",true,true)
     }
     else { 
       if (caller == "users") {
         opForm.elements[menu].length = 0
-        opForm.elements[menu].options[0] = new Option("Select","-1",true,true)
-        opForm.elements[menu].options[1] = new Option("Enroll students only","students",true,true)
-        opForm.elements[menu].options[2] = new Option("Enroll all users","all",true,true)
+        opForm.elements[menu].options[0] = new Option("$lt{'se'}","-1",true,true)
+        opForm.elements[menu].options[1] = new Option("$lt{'es'}","students",true,true)
+        opForm.elements[menu].options[2] = new Option("$lt{'ea'}","all",true,true)
       }
     }
   }
   else {
-    opForm.elements[menu].options[0] = new Option("Not required","0",true,true)
+    opForm.elements[menu].options[0] = new Option("$lt{'nr'}","0",true,true)
   }
   opForm.elements[menu].selectedIndex = 0
 }
@@ -101,20 +87,20 @@
       totcheck ++
       if (opForm.elements[2*i].name == "board") { 
         if (opForm.elements[2*i+1].selectedIndex == 0) {     
-          alert("You must select one of the additional options when importing Discussion Boards ")
+          alert("$lt{'id'}")
           return false
         }
       }
       if (opForm.elements[2*i].name == "users") {
         if (opForm.elements[2*i+1].selectedIndex == 0) {     
-          alert("You must select one of the additional options when importing Enrollment")
+          alert("$lt{'ie'}")
           return false
         }
       }
     }
   }
   if (totcheck == 0) {
-    alert("You must check the Checkbox for at least one Content Type");
+    alert("$lt{'ct'}");
     return false
   }
   return true
@@ -125,22 +111,23 @@
    document.forms.pickoptions.submit()
  }
 }
-#;
+
+ENDJS
+
 }
 
-sub jscript_three {
-    my $javascript = shift;
-    $$javascript = qq|
+sub jscript_two {
+    return <<"ENDJS";
 function init(tf) {
     setTimeout("self.close()",3000)
     tf.submit();   
 }
-    |;
+ 
+ENDJS
 }
 
 sub handler {
     my $r = shift;
-    my $javascript = '';
     &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;
     return OK if $r->header_only;
@@ -177,15 +164,11 @@
         return OK;
     }
 
-    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
-       ['phase']);
-
-    if ($env{'form.phase'} eq 'one') {    
-        &jscript_one(\$javascript);
+    my $javascript;
+    if ($env{'form.phase'} eq 'one') {
+        $javascript = &jscript_one();
     } elsif ($env{'form.phase'} eq 'two') {
-        &jscript_two(\$javascript);
-    } elsif ($env{'form.phase'} eq 'three') {
-        &jscript_three(\$javascript);
+        $javascript = &jscript_two();
     }
 
     $javascript = 
@@ -200,69 +183,16 @@
     $r->print($start_page);
 
     if ($env{'form.phase'} eq 'one') {
-        &display_one($r);       
+        &display_one($r,$coursenum,\@areas,\%areaname,%cmsmap);
     } elsif ($env{'form.phase'} eq 'two') {
-        &display_two($r,$coursenum,\@areas,\%areaname,%cmsmap);
-    } elsif ($env{'form.phase'} eq 'three') {
-        &display_three($r,$coursenum,$coursedom,$uname,$udom,\@areas,%cmsmap);
+        &display_two($r,$coursenum,$coursedom,$uname,$udom,\@areas,%cmsmap);
     }   
     $r->print(&Apache::loncommon::end_page());
     return OK;
-} 
-
-
-sub display_one {
-    my ($r) = @_;
-    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']);
-
-    $r->print(
-        '<form action="/adm/imsimportdocs" method="post"'
-       .' enctype="multipart/form-data" name="pickcms">'
-    );
-
-    # Step 1
-    $r->print(
-       &Apache::lonhtmlcommon::topic_bar(
-            1,&mt('Specify the Course Management system used to create the package'))
-       .&mt('Please choose the CMS used to create your IMS content package:').' '
-       .'<select name="source">'
-       .'<option value="-1" selected="selected">'.&mt('Please select').'</option>'
-       .'<option value="bb5">Blackboard 5</option>'
-       .'<option value="bb6">Blackboard 6</option>'
-       .'<option value="angel5">ANGEL 5.5</option>'
-       .'<option value="webctce4">WebCT 4 Campus Edition</option>'
-       .'</select>'
-    );
-
-    # Step 2
-    $r->print(
-       &Apache::lonhtmlcommon::topic_bar(
-           2,&mt('Locate the IMS content package you wish to upload'))
-      .'<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'
-      .'<input type="hidden" name="phase" value="two" />'
-      .&mt('File:')
-      .' <input type="file" name="uploadname" size="40" />'
-    );
-
-    # Buttons
-    $r->print(
-       '<hr />'
-      .'<p>'
-      .'<input type="button" name="exitpage" value="'.&mt('Cancel').'"'
-      .' onclick="javascript:self.close()" />'
-      .' '
-      .'<input type="button" name="nextpage" value="'.&mt('Upload IMS package').'"'
-      .' onclick="javascript:nextPage()" />'
-      .'</p>'
-    );
-
-    $r->print('</form>');
 }
 
-
-sub display_two {
+sub display_one {
     my ($r,$crs,$areasref,$areaname,%cmsmap) = @_;
-    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder','source']);
     my $cms = $env{'form.source'};
     my $timenow = time;
     my $tempdir = &Apache::imsprocessor::create_tempdir('DOCS',$crs,$timenow);
@@ -345,12 +275,12 @@
     }
 
 
-    # Start output: Step 3 and step 4
+    # Start output: Step 1 and step 2
 
     $r->print(
         '<form name="pickoptions" method="post" action="">'
        .&Apache::lonhtmlcommon::topic_bar(
-            3,&mt('Choose which content types you wish to import'))
+            1,&mt('Choose which content types you wish to import'))
        .'<p>'
        .&mt('Check the checkboxes for all areas you wish to import from the IMS package:')
        .'</p>'
@@ -420,7 +350,7 @@
 
     $r->print(
         &Apache::lonhtmlcommon::topic_bar(
-            4,&mt('Choose display options for listing of contents of top level of package'))
+            2,&mt('Choose display options for listing of contents of top level of package'))
        .'<p>'
        .&mt('Select a display option for the package content:')
        .'</p>'
@@ -443,7 +373,7 @@
         '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'
        .'<input type="hidden" name="source" value="'.$cms.'" />'
        .'<input type="hidden" name="tempdir" value="'.$tempdir.'" />'
-       .'<input type="hidden" name="phase" value="three" />'
+       .'<input type="hidden" name="phase" value="two" />'
     );
     $r->print(
         '<hr />'
@@ -459,8 +389,7 @@
    $r->print('</form>');
 }
 
-
-sub display_three {
+sub display_two {
     my ($r,$crs,$cdom,$uname,$udom,$areas,%cmsmap) = @_;
     my $folder = $env{'form.folder'};
     my $cms = $env{'form.source'};
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1192 loncom/lonnet/perl/lonnet.pm:1.1193
--- loncom/lonnet/perl/lonnet.pm:1.1192	Mon Oct 29 17:39:02 2012
+++ loncom/lonnet/perl/lonnet.pm	Wed Oct 31 12:54:23 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1192 2012/10/29 17:39:02 raeburn Exp $
+# $Id: lonnet.pm,v 1.1193 2012/10/31 12:54:23 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2645,6 +2645,68 @@
     &Apache::lonnet::appenv(\%httpref);
 }
 
+#
+# Determine if the current user should be able to edit a particular resource,
+# when viewing in course context.
+# (a) When viewing resource used to determine if "Edit" item is included in 
+#     Functions.
+# (b) When displaying folder contents in course editor, used to determine if
+#     "Edit" link will be displayed alongside resource.
+#
+#  input: 3 args -- filename (decluttered), course number and course domain.
+#  output: array of four scalars -- 
+#          $cfile -- url for file editing if editable on current server
+#          $home -- homeserver of resource (i.e., for author if published,
+#                                           or course if uploaded.).
+#          $switchserver --  1 if server switch will be needed.
+#          $uploaded -- 1 if resource is a file uploaded to a course.
+#
+
+sub can_edit_resource {
+    my ($file,$cnum,$cdom) = @_;
+    my ($cfile,$home,$switchserver,$uploaded);
+    if ($file ne '') {
+        if (($cnum =~ /$match_courseid/) && ($cdom =~ /$match_domain/)) {
+            $uploaded = &is_course_upload($file,$cnum,$cdom);
+            if ($uploaded) {
+                $home=&homeserver($cnum,$cdom);
+                if ($file =~/\.(htm|html|css|js|txt)$/) {
+                    $cfile = &hreflocation('',$file);
+                }
+            }
+        }
+        unless ($uploaded) {
+            $file=~s{^(priv/$match_domain/$match_username)}{/$1};
+            $file=~s{^($match_domain/$match_username)}{/priv/$1};
+            # Check that the user has permission to edit this resource
+            my $setpriv = 1;
+            my ($cfuname,$cfudom)=&constructaccess($file,$setpriv);
+            if (defined($cfudom)) {
+                $home=&homeserver($cfuname,$cfudom);
+                $cfile=$file;
+            }
+        }
+        if (($cfile ne '') && (($home ne '') && ($home ne 'no_host'))) {
+            my @ids=&current_machine_ids();
+            unless (grep(/^\Q$home\E$/, at ids)) {
+                $switchserver=1;
+            }
+        }
+    }
+    return ($cfile,$home,$switchserver,$uploaded);
+}
+
+sub is_course_upload {
+    my ($file,$cnum,$cdom) = @_;
+    my $uploadpath = &LONCAPA::propath($cdom,$cnum);
+    $uploadpath =~ s{^\/}{};
+    if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
+        ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
+        return 1;
+    }
+    return;
+}
+
 # --------- File operations in /home/httpd/html/userfiles/$domain/1/2/3/$course
 # input: action, courseID, current domain, intended
 #        path to file, source of file, instruction to parse file for objects,


More information about the LON-CAPA-cvs mailing list