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

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 03 Aug 2004 20:44:34 -0000


albertel		Tue Aug  3 16:44:34 2004 EDT

  Modified files:              
    /loncom/interface	londocs.pm 
  Log:
  - keeps the re-init button up as long as it is needed, does this by creating
    the element 'old' in the "bighash", and it checks this to see if it needs to 
    display the warning or not.
  - also 'versions' are listed in numerical order.
  
  
  
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.135 loncom/interface/londocs.pm:1.136
--- loncom/interface/londocs.pm:1.135	Thu Jul  8 15:58:29 2004
+++ loncom/interface/londocs.pm	Tue Aug  3 16:44:33 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.135 2004/07/08 19:58:29 albertel Exp $
+# $Id: londocs.pm,v 1.136 2004/08/03 20:44:33 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -650,12 +650,20 @@
 # ---------------------------------------------------------------- tie the hash
 
 sub tiehash {
+    my ($mode)=@_;
     $hashtied=0;
     if ($ENV{'request.course.fn'}) {
-        if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
-            &GDBM_READER(),0640)) {
+	if ($mode eq 'write') {
+	    if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
+		    &GDBM_WRCREAT(),0640)) {
+                $hashtied=2;
+	    }
+	} else {
+	    if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
+		    &GDBM_READER(),0640)) {
                 $hashtied=1;
-        }
+	    }
+	}
     }    
 }
 
@@ -821,8 +829,9 @@
 	} else {
 	    $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Store your Version Settings').'</font></h1>');
 	}
-	&changewarning($r,'');
+	&mark_hash_old();
     }
+    &changewarning($r,'');
     if ($ENV{'form.timerange'} eq 'all') {
 # show all documents
 	$header=&mt('All Documents in Course');
@@ -942,7 +951,9 @@
 # Set version
 	    $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
 						      'set_version_'.$linkurl,
-						      ('' => '',
+						      ('select_form_order' =>
+						       ['',1..$currentversion,'mostrecent'],
+						       '' => '',
 						       'mostrecent' => 'most recent',
 						       map {$_,$_} (1..$currentversion))));
 	    $r->print('</nobr></td></tr><tr><td></td>');
@@ -1003,8 +1014,32 @@
     &untiehash();
 }
 
+sub mark_hash_old {
+    my $retie_hash=0;
+    if ($hashtied) {
+	$retie_hash=1;
+	&untiehash();
+    }
+    &tiehash('write');
+    $hash{'old'}=1;
+    &untiehash();
+    if ($retie_hash) { &tiehash(); }
+}
+
+sub is_hash_old {
+    my $untie_hash=0;
+    if (!$hashtied) {
+	$untie_hash=1;
+	&tiehash();
+    }
+    my $return=$hash{'old'};
+    if ($untie_hash) { &untiehash(); }
+    return $return;
+}
+
 sub changewarning {
     my ($r,$postexec)=@_;
+    if (!&is_hash_old()) { return; }
     $r->print(
 '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'. 
 '<form method="post" action="/adm/roles" target="loncapaclient">'.
@@ -1313,8 +1348,9 @@
        $hadchanges=0;
        &editor($r,$coursenum,$coursedom,$folder,$allowed);
        if ($hadchanges) {
-	   &changewarning($r,$postexec);
+	   &mark_hash_old()
        }
+       &changewarning($r,$postexec);
        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
                      '.sequence';
        $r->print(<<ENDFORM);