[LON-CAPA-cvs] cvs: loncom /interface londocs.pm

raeburn raeburn at source.lon-capa.org
Sun Mar 10 21:46:47 EDT 2013


raeburn		Mon Mar 11 01:46:47 2013 EDT

  Modified files:              
    /loncom/interface	londocs.pm 
  Log:
  - More options when pasting templated pages (simplepage/bulletin board) and  
    uploaded documents cut from same course.
    - Can choose to either "copy" or "move" (copy will create a new instance,
      move will use existing instance).  
    - Bug 6634.
      - If a copied folder contains a simple page or bulletin board, a new
        templated item is created, and the contents are copied to the new
        instance.
    - &newmap_suffix() renamed as &new_timebased_suffix() and supports 
      creation of unique time-based suffix for simplepage/bulletin board as
      well as maps.
  
  
-------------- next part --------------
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.532 loncom/interface/londocs.pm:1.533
--- loncom/interface/londocs.pm:1.532	Mon Jan 14 20:32:04 2013
+++ loncom/interface/londocs.pm	Mon Mar 11 01:46:47 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.532 2013/01/14 20:32:04 raeburn Exp $
+# $Id: londocs.pm,v 1.533 2013/03/11 01:46:47 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -335,7 +335,8 @@
                           removefrommap => \%removefrommap,
                           removeparam   => \%removeparam,
                       );
-        &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
+        my ($result,$msgsarray,$lockerror) = 
+            &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
         if (keys(%import_errors) > 0) {
             $fixuperrors =
                 '<p span class="LC_warning">'."\n".
@@ -346,6 +347,18 @@
             }
             $fixuperrors .= '</ul></p>'."\n";
         }
+        if (ref($msgsarray) eq 'ARRAY') {
+            if (@{$msgsarray} > 0) {
+                $fixuperrors .= '<p class="LC_info">'.
+                                join('<br />',@{$msgsarray}).
+                                '</p>';
+            }
+        }
+        if ($lockerror) {
+            $fixuperrors .= '<p class="LC_error">'.
+                            $lockerror.
+                            '</p>';
+        }
     }
     my ($errtext,$fatal) =
         &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
@@ -735,7 +748,7 @@
         $buffer = $type.': '.
                   &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.
                   &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')';
-    }  else {
+    } else {
         my $icon = &Apache::loncommon::icon($extension);
         if ($extension eq 'sequence' &&
             $env{'docs.markedcopy_url'} =~ m{/default_\d+\.sequence$ }x) {
@@ -747,19 +760,36 @@
     }
     if ($canpaste) {
         $r->print('<form name="pasteform" action="/adm/coursedocs" method="post">'.$buffer);
-        if (($is_uploaded_map) && (!$areachange)) {
-            if ((!$othercourse) && ($env{'docs.markedcopy_cmd'} eq 'cut')) {
+        if ((!$areachange) && (!$othercourse) &&
+            ($env{'docs.markedcopy_cmd'} eq 'cut')) {
+            if (($is_uploaded_map) || 
+                ($env{'docs.markedcopy_url'} =~ /(bulletinboard|smppg)$/) ||
+                ($env{'docs.markedcopy_url'} =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
+                my ($copytext,$movetext);
+                if ($is_uploaded_map) {
+                    $copytext = &mt('Copy to new folder');
+                    $movetext = &mt('Move old folder');
+                } elsif ($env{'docs.markedcopy_url'} =~ /bulletinboard$/) {
+                    $copytext = &mt('Copy to new bulletin board (not posts)');
+                    $movetext = &mt('Move old bulletin board (not posts)');
+                } elsif ($env{'docs.markedcopy_url'} =~ /smppg$/) {
+                    $copytext = &mt('Copy to new simple page');
+                    $movetext = &mt('Move old simple page');
+                } else {
+                    $copytext = &mt('Copy to new uploaded document');
+                    $movetext = &mt('Move old uploaded document');
+                }
                 $r->print((' 'x 4).'<span id="pasteoptionstext">'.
                           '<a href="javascript:showPasteOptions();" class="LC_menubuttons_link">'.
                           &mt('Show Paste Options').'</a></span><br />'.
                           '<div id="pasteoptions" class="LC_dccid">'.(' 'x 4).
                           '<label>'.
                           '<input type="radio" name="docs.markedcopy_options" value="new" checked="checked" />'.
-                          &mt('Copy to new folder').'</label>'.(' ' x2).
+                          $copytext.'</label>'.(' ' x2).
                           '<label>'.   
                           '<input type="radio" name="docs.markedcopy_options" value="move" />'.
-                          &mt('Move old folder').'</label><br />');
-                if ($env{'docs.markedcopy_nested'}) {
+                          $movetext.'</label><br />');
+                if (($is_uploaded_map) && ($env{'docs.markedcopy_nested'})) {
                     $r->print('<br />'.&mt('Folder to paste contains sub-folders').
                               '<br /><table border="0">');
                     my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested'});
@@ -965,15 +995,17 @@
             }
             if (($srcdom ne $coursedom) || ($srcnum ne $coursenum) || ($prefixchg) ||
                 (($newurl ne '') && ($newurl ne $url))) {
-                unless (&url_paste_fixups($url,$folder,$prefixchg,$coursedom,$coursenum,
-                                          $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
+                unless (&url_paste_fixups($url,$folder,$prefixchg,$coursedom,
+                                          $coursenum,$srcdom,$srcnum,$allmaps,
+                                          \%rewrites,\%retitles,\%copies,\%dbcopies,
                                           \%zombies,\%params,\%mapmoves,\%mapchanges,\%tomove,
                                           \%newsubdir,\%newurls)) {
                     $mapmoves{$url} = 1;
                 }
                 $url = $newurl;
             } elsif ($env{'docs.markedcopy_nested'}) {
-                &url_paste_fixups($url,$folder,$prefixchg,$coursedom,$coursenum,$allmaps,\%rewrites,
+                &url_paste_fixups($url,$folder,$prefixchg,$coursedom,$coursenum,
+                                  $srcdom,$srcnum,$allmaps,\%rewrites,
                                   \%retitles,\%copies,\%dbcopies,\%zombies,\%params,\%mapmoves,
                                   \%mapchanges,\%tomove,\%newsubdir,\%newurls); 
             }
@@ -988,22 +1020,34 @@
             }
         }
     }
-    if ($url=~ m{/smppg$}) {
-	my $db_name = &Apache::lonsimplepage::get_db_name($url);
-	if ($db_name =~ /^smppage_/) {
-	    #simple pages, need to copy the db contents to a new one.
-	    my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum);
-	    my $now = time();
-	    $db_name =~ s{_\d*$ }{_$now}x;
-	    my $dbresult=&Apache::lonnet::put($db_name,\%contents,
-					    $coursedom,$coursenum);
-            if ($dbresult eq 'ok') {
-                $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
+    my $lockerrors;
+    if ($url=~ m{/(bulletinboard|smppg)$}) {
+        my $prefix = $1;
+        #need to copy the db contents to a new one, unless this is a move.
+        my %info = (
+                     src  => $url,
+                     cdom => $coursedom,
+                     cnum => $coursenum,
+        );
+        my (%lockerr,$msg);
+        unless ($env{'form.docs.markedcopy_options'} eq 'move') {
+            my ($newurl,$result,$errtext) =
+                &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
+            if ($result eq 'ok') {
+                $url = $newurl;
                 $title=&mt('Copy of').' '.$title;
             } else {
-                return (&mt('Paste failed: An error occurred when copying the simple page.'));
+                if ($prefix eq 'smppg') {
+                    $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
+                } elsif ($prefix eq 'bulletinboard') {
+                    $msg = &mt('Paste failed: An error occurred when copying the bulletin board.').' '.$errtext;
+                }
+                return ($result,undef,[$msg],$lockerr{$prefix});
+	    }
+            if ($lockerr{$prefix}) {
+                $lockerrors = $lockerr{$prefix};  
             }
-	}
+        }
     }
     $title = &LONCAPA::map::qtunescape($title);
     my $ext='false';
@@ -1030,7 +1074,9 @@
                 if ($newdocsdir eq '') {
                     $newdocsdir = 'default';
                 }
-                if (($prefixchg) || ($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
+                if (($prefixchg) || 
+                    ($srcdom ne $coursedom) || ($srcnum ne $coursenum) ||
+                    ($env{'form.docs.markedcopy_options'} ne 'move')) {
                     my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
                     $url =
                         &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
@@ -1067,14 +1113,15 @@
                    docmoves => \%docmoves,
                    mapmoves => \%mapmoves,
                 );
-    $result =
+    ($result,my $msgsarray,my $lockerror) =
         &apply_fixups($folder,$is_map,$coursedom,$coursenum,$errors,
                       \%updated,\%info,\%moves,$prefixchg,$oldurl,$url,'paste');
+    $lockerrors .= $lockerror;
     if ($result eq 'ok') {
         if ($is_map) { 
             my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                                             $folder.'.'.$container);
-            return $errtext if ($fatal);
+            return ($errtext,$save_err,$msgsarray,$lockerrors) if ($fatal);
 
             if ($#LONCAPA::map::order<1) {
                 my $idx=&LONCAPA::map::getresidx();
@@ -1105,13 +1152,13 @@
             $save_err = $errtext;
         }
     }
-   
+
     if ($env{'form.docs.markedcopy_options'} eq 'move') {
         &Apache::lonnet::delenv('docs.markedcopy');
         &Apache::lonnet::delenv('docs.markedcopy_nested');
         &Apache::lonnet::delenv('docs.markedcopy_nestednames');
     }
-    return ($result,$save_err);
+    return ($result,$save_err,$msgsarray,$lockerrors);
 }
 
 sub get_newmap_url {
@@ -1175,20 +1222,96 @@
 }
 
 sub dbcopy {
-    my ($url,$coursedom,$coursenum) = @_;
-    if ($url=~ m{/smppg$}) {
-        my $db_name = &Apache::lonsimplepage::get_db_name($url);
-        if ($db_name =~ /^smppage_/) {
-            #simple pages, need to copy the db contents to a new one.
-            my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum);
-            my $now = time();
-            $db_name =~ s{_\d*$ }{_$now}x;
-            my $result=&Apache::lonnet::put($db_name,\%contents,
-                                            $coursedom,$coursenum);
-            $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
+    my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
+    my ($url,$result,$errtext);
+    my $url = $dbref->{'src'};
+    if (ref($dbref) eq 'HASH') {
+        if ($url =~ m{/(smppg|bulletinboard)$}) {
+            my $prefix = $1;
+            if (($dbref->{'cdom'} =~ /^$match_domain$/) && 
+                ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
+                my $db_name;
+                my $marker = (split(m{/},$url))[4];
+                $marker=~s/\D//g;
+                if ($dbref->{'src'} =~ m{/smppg$}) {
+                    $db_name =
+                        &Apache::lonsimplepage::get_db_name($url,$marker,
+                                                            $dbref->{'cdom'},
+                                                            $dbref->{'cnum'});
+                } else {
+                    $db_name = 'bulletinpage_'.$marker;
+                }
+                my ($suffix,$freedlock,$error) =
+                    &Apache::lonnet::get_timebased_id($prefix,'num','templated',
+                                                      $coursedom,$coursenum,
+                                                      'concat');
+                if (!$suffix) {
+                    if ($prefix eq 'smppg') {
+                        $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
+                    } else {
+                        $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a bulletin board [_1].',$url);
+                    }
+                    if ($error) {
+                        $errtext .= '<br />'.$error;
+                    }
+                } else {
+                    #need to copy the db contents to a new one.
+                    my %contents=&Apache::lonnet::dump($db_name,
+                                                       $dbref->{'cdom'},
+                                                       $dbref->{'cnum'});
+                    if (exists($contents{'uploaded.photourl'})) {
+                        my $photo = $contents{'uploaded.photourl'};
+                        my ($subdir,$fname) =
+                            ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
+                        my $newphoto; 
+                        if ($fname ne '') {
+                            my $content = &Apache::lonnet::getfile($photo);
+                            unless ($content eq '-1') {
+                                $env{'form.'.$suffix.'.photourl'} = $content;
+                                $newphoto = 
+                                    &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
+                                delete($env{'form.'.$suffix.'.photourl'});
+                            }
+                        }
+                        if ($newphoto =~ m{^/uploaded/}) {
+                            $contents{'uploaded.photourl'} = $newphoto;
+                        }
+                    }
+                    $db_name =~ s{_\d*$ }{_$suffix}x;
+                    $result=&Apache::lonnet::put($db_name,\%contents,
+                                                 $coursedom,$coursenum);
+                    if ($result eq 'ok') {
+                        $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
+                    }
+                }
+                if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
+                    $lockerrorsref->{$prefix} = 
+                        '<div class="LC_error">'.
+                        &mt('There was a problem removing a lockfile.');
+                    if ($prefix eq 'smppg') {
+                        $lockerrorsref->{$prefix} .= 
+                            &mt('This will prevent creation of additional simple pages in this course.');
+                    } else {
+                        $lockerrorsref->{$prefix} .= &mt('This will prevent creation of additional bulletin boards in this course.');
+                    }
+                    $lockerrorsref->{$prefix} .= &mt('Please contact the domain coordinator for your LON-CAPA domain.').'</div>';
+                }
+            }
+        } elsif ($url =~ m{/syllabus$}) {
+            if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
+                ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
+                if (($dbref->{'cdom'} ne $coursedom) ||
+                    ($dbref->{'cnum'} ne $coursenum)) {
+                    my %contents=&Apache::lonnet::dump('syllabus',
+                                                       $dbref->{'cdom'},
+                                                       $dbref->{'cnum'});
+                    $result=&Apache::lonnet::put('syllabus',\%contents,
+                                                 $coursedom,$coursenum);
+                }
+            }
         }
     }
-    return $url;
+    return ($url,$result,$errtext);
 }
 
 sub uniqueness_check {
@@ -1254,8 +1377,9 @@
 }
 
 sub url_paste_fixups {
-    my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$allmaps,$rewrites,$retitles,$copies,
-        $dbcopies,$zombies,$params,$mapmoves,$mapchanges,$tomove,$newsubdir,$newurls) = @_;
+    my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
+        $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
+        $mapchanges,$tomove,$newsubdir,$newurls) = @_;
     my $checktitle;
     if (($prefixchg) &&
         ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
@@ -1300,10 +1424,11 @@
                     my $prefix = $1;
                     $mapname = $prefix.$2;
                     if ($tomove->{$mapname}) {
-                        &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,$allmaps,
-                                          $rewrites,$retitles,$copies,$dbcopies,$zombies,
-                                          $params,$mapmoves,$mapchanges,$tomove,$newsubdir,
-                                          $newurls);
+                        &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
+                                          $srcdom,$srcnum,$allmaps,$rewrites,
+                                          $retitles,$copies,$dbcopies,$zombies,
+                                          $params,$mapmoves,$mapchanges,$tomove,
+                                          $newsubdir,$newurls);
                         next;
                     } else {
                         ($newurl,my $error) =
@@ -1323,10 +1448,11 @@
                     if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
                         $rewrites->{$oldurl}{$id} = $ressrc;
                         $mapchanges->{$ressrc} = 1;
-                        unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,$allmaps,
-                                                  $rewrites,$retitles,$copies,$dbcopies,$zombies,
-                                                  $params,$mapmoves,$mapchanges,$tomove,$newsubdir,
-                                                  $newurls)) {
+                        unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
+                                                  $cnum,$srcdom,$srcnum,$allmaps,
+                                                  $rewrites,$retitles,$copies,$dbcopies,
+                                                  $zombies,$params,$mapmoves,$mapchanges,
+                                                  $tomove,$newsubdir,$newurls)) {
                             $mapmoves->{$ressrc} = 1;
                         }
                         $changed = 1;
@@ -1336,13 +1462,23 @@
                         $changed = 1;
                     }
                 }
-            } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
-                next if ($skip);  
+            } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
+                next if ($skip);
                 my $srcdom = $1;
                 my $srcnum = $2;
                 if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
                     $rewrites->{$oldurl}{$id} = $ressrc;
-                    $dbcopies->{$oldurl}{$ressrc} = $id;
+                    $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
+                    $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
+                    $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
+                    $changed = 1;
+                }
+            } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
+                if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
+                    ($env{'form.docs.markedcopy_options'} ne 'move')) {
+                    $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
+                    $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
+                    $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
                     $changed = 1;
                 }
             } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
@@ -1350,8 +1486,9 @@
                 my $srcdom = $1;
                 my $srcnum = $2;
                 if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
-                    $rewrites->{$oldurl}{$id} = $ressrc;
-                    $dbcopies->{$oldurl}{$ressrc} = $id;
+                    $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
+                    $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
+                    $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                     $changed = 1;
                 }
             }
@@ -1374,7 +1511,8 @@
     my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
         $oldurl,$url,$caller) = @_;
     my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
-        %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves);
+        %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves, at msgs,
+        %lockerrors,$lockmsg);
     if (ref($updated) eq 'HASH') {
         if (ref($updated->{'rewrites'}) eq 'HASH') {
             %rewrites = %{$updated->{'rewrites'}};
@@ -1531,8 +1669,17 @@
                 %zombie = %{$zombies{$key}};
             }
             if (ref($dbcopies{$key}) eq 'HASH') {
-                foreach my $item (keys(%{$dbcopies{$key}})) {
-                    $newdb{$item} = &dbcopy($item);
+                foreach my $idx (keys(%{$dbcopies{$key}})) {
+                    if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
+                        my ($newurl,$result,$errtext) =
+                            &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
+                        if ($result eq 'ok') {
+                            $newdb{$idx} = $newurl;
+                        } elsif (ref($errors) eq 'HASH') {
+                            $errors->{$key} = 1;
+                        }
+                        push(@msgs,$errtext);
+                    }
                 }
             }
             if (ref($params{$key}) eq 'HASH') {
@@ -1540,7 +1687,7 @@
             }
             my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
             if ($fatal) {
-                return $errtext;
+                return ($errtext);
             }
             for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
                 if (defined($LONCAPA::map::zombies[$i])) {
@@ -1589,8 +1736,8 @@
                             }
                         }
                         $changed = 1;
-                    } elsif ($newdb{$src} ne '') {
-                        $src = $newdb{$src};
+                    } elsif ($newdb{$idx} ne '') {
+                        $src = $newdb{$idx};
                         $changed = 1;
                     }
                     if ($changed) {
@@ -1605,6 +1752,9 @@
                     }
                 }
             }
+            if (values(%lockerrors) > 0) {
+                $lockmsg = join('<br />',values(%lockerrors));
+            }
             my $storefn;
             if ($key eq $oldurl) {
                 $storefn = $url;
@@ -1627,12 +1777,12 @@
                 &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
             if ($errtext) {
                 if ($caller eq 'paste') {
-                    return &mt('Paste failed: an error occurred saving the folder or page.');
+                    return (&mt('Paste failed: an error occurred saving the folder or page.'));
                 }
             }
         }
     }
-    return 'ok';
+    return ('ok',\@msgs,$lockmsg);
 }
 
 sub copy_dependencies {
@@ -1820,9 +1970,22 @@
 
 	if ($env{'form.pastemarked'}) {
             my %paste_errors;
-            my ($paste_res,$save_error) =
+            my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
                 &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
                                       \%paste_errors);
+                if (ref($pastemsgarray) eq 'ARRAY') {
+                    if (@{$pastemsgarray} > 0) {
+                          
+                        $r->print('<p class="LC_info">'.
+                                  join('<br />',@{$pastemsgarray}).
+                                  '</p>');
+                    }
+                }
+                if ($lockerror) {
+                    $r->print('<p class="LC_error">'.
+                              $lockerror.
+                              '</p>');
+                }
                 if ($save_error ne '') {
                     return $save_error; 
                 }
@@ -1856,10 +2019,10 @@
 	    foreach my $item (split(/\&/,$env{'form.importdetail'})) {
 		if (defined($item)) {
 		    my ($name,$url,$residx)=
-			map {&unescape($_)} split(/\=/,$item);
-                    if ($url=~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
-                        my ($suffix,$errortxt,$locknotfreed) = 
-                            &newmap_suffix($1,$2,$coursedom,$coursenum);
+			map { &unescape($_); } split(/\=/,$item);
+                    if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
+                        my ($suffix,$errortxt,$locknotfreed) =
+                            &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
                         if ($locknotfreed) {
                             $r->print($locknotfreed);
                         }
@@ -1868,6 +2031,18 @@
                         } else {
                             return $errortxt;
                         }
+                    } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
+                        my $type = $1;
+                        my ($suffix,$errortxt,$locknotfreed) =
+                            &new_timebased_suffix($coursedom,$coursenum,$type);
+                        if ($locknotfreed) {
+                            $r->print($locknotfreed);
+                        }
+                        if ($suffix) {
+                            $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
+                        } else {
+                            return $errortxt;
+                        }
                     }
 		    push(@imports, [$name, $url, $residx]);
 		}
@@ -2598,26 +2773,52 @@
     return $line;
 }
 
-sub newmap_suffix {
-    my ($area,$container,$coursedom,$coursenum) = @_;
-    my ($prefix,$idtype,$errtext,$locknotfreed);
-    $prefix = 'docs';
-    if ($area eq 'supplemental') {
-        $prefix = 'supp';
+sub new_timebased_suffix {
+    my ($coursedom,$coursenum,$type,$area,$container) = @_;
+    my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
+    if ($type eq 'map') {
+        $prefix = 'docs';
+        if ($area eq 'supplemental') {
+            $prefix = 'supp';
+        }
+        $prefix .= $container;
+        $namespace = 'uploadedmaps';
+    } else {
+        $prefix = $type;
+        $namespace = 'templated';
     }
-    $prefix .= $container;
     $idtype = 'concat';
     my ($suffix,$freedlock,$error) =
-        &Apache::lonnet::get_timebased_id($prefix,'num','uploadedmaps',
+        &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,
                                           $coursedom,$coursenum);
     if (!$suffix) {
-        $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
+        if ($type eq 'map') {
+            $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
+        } elsif ($type eq 'smppg') {
+            $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
+        } else {
+            $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new bulletin board.');
+        }
         if ($error) {
             $errtext .= '<br />'.$error;
         }
     }
     if ($freedlock ne 'ok') {
-        $locknotfreed = '<div class="LC_error">'.&mt('There was a problem removing a lockfile. This will prevent creation of additional folders or composite pages in this course.  Please contact the domain coordinator for your LON-CAPA domain.').'</div>';
+        $locknotfreed = 
+            '<div class="LC_error">'.
+            &mt('There was a problem removing a lockfile.').' ';
+        if ($type eq 'map') {
+            &mt('This will prevent creation of additional folders or composite pages in this course.');
+        } elsif ($type eq 'smppg') {
+            $locknotfreed .=
+                &mt('This will prevent creation of additional simple pages in this course.');
+        } else {
+            $locknotfreed .=
+                &mt('This will prevent creation of additional bulletin boards in this course.');
+        }
+        $locknotfreed .=
+            ' '.&mt('Please contact the domain coordinator for your LON-CAPA domain.').
+            '</div>';
     }
     return ($suffix,$errtext,$locknotfreed);
 }
@@ -4377,7 +4578,6 @@
 
 sub editing_js {
     my ($udom,$uname,$supplementalflag) = @_;
-    my $now = time();
     my %lt = &Apache::lonlocal::texthash(
                                           p_mnf => 'Name of New Folder',
                                           t_mnf => 'New Folder',
@@ -4475,7 +4675,7 @@
    var title=prompt('$lt{"p_msp"}');
    if (title) {
     this.document.forms.newsmppg.importdetail.value=
-	escape(title)+'=/adm/$udom/$uname/$now/smppg';
+	escape(title)+'=/adm/$udom/$uname/new/smppg';
     this.document.forms.newsmppg.submit();
    }
 }
@@ -4502,7 +4702,7 @@
    var title=prompt('$lt{"p_mbb"}');
    if (title) {
     this.document.forms.newbul.importdetail.value=
-	escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
+	escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
     this.document.forms.newbul.submit();
    }
 }


More information about the LON-CAPA-cvs mailing list