--- docman.php 2000/08/03 20:54:27 1.4 +++ docman.php 2000/08/04 11:23:07 1.10 @@ -65,9 +65,7 @@ TODO: mixed file/directory output (add type to each entry, real support for links) - add more content-management (like cms.sourceforge.net): - check-out/check-in/reserve - comments to files + retrieve old versions of files (overwritten) */ ////////////////////////////////////////////////////////////////// @@ -184,7 +182,7 @@ - - - [logout] + [?relogin=">logout]
ANYPORTAL(php) Site Manager
@@ -194,7 +192,7 @@


- +

" ; - echo htmlentities($tstr) . "

" . $tstr ; + if ( !$file_lock && strstr(join(" ",$gblImages),$ext) ) { + $info = getimagesize($fsPath) ; + $tstr = "\""" ; +// echo htmlentities($tstr) . "

" . $tstr ; + echo $tstr ; } + ?>
@@ -309,6 +310,17 @@
+
+ +OK TO FORCE LOCK REMOVAL ON "" HELD BY ? + + + +
NOTE FOR "": @@ -343,20 +358,33 @@ -" ; + - $logname=dirname("$fsDir/$fn")."/.log/".basename("$fsDir/$fn"); +
CHANGES TO THIS FILE
\n"; $log=fopen($logname,"r"); $cl1=" class=lst"; $cl2=""; + $logarr = array(); while($line = fgetcsv($log,255,"\t")) { $cl=$cl1; $cl1=$cl2; $cl2=$cl; - print "$line[0]$line[1]$line[2]$line[3]\n"; + array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3])); } fclose($log); + print "

CHANGES TO THIS FILE
\n"; + $bakcount = 0; // start from 0, skip fist backup (it's current) + while ($e = array_shift($logarr)) { + if (strstr($e[4],"upload")) { + if (file_exists("$bakdir/$bakcount/$name")) { + $e[4]="$e[4]"; + } + $bakcount++; + } + print "$e[1]$e[2]$e[3]$e[4]\n"; + } print "
"; } @@ -590,10 +618,13 @@ $d = "blank.gif" ; break ; case "checkout": - $d = "down.gif"; + $d = "box2.gif"; break; case "checkin": - $d = "up.gif"; + $d = "hand.up.gif"; + break; + case "locked": + $d = "screw2.gif"; break; case "note": $d = "quill.gif"; @@ -655,7 +686,7 @@ // start navigation page $text = "Use this page to add, delete"; if (! isset($show_deleted)) { - $text .= ", undelete"; + $text .= ", undelete"; } $text .= " or revise files on this web site." ; StartHTML("(Navigate)",$text) ; @@ -702,7 +733,7 @@
DOCUMENT NAME - + NOTE LAST UPDATEFILE SIZE @@ -729,26 +760,52 @@ $a .= " than 30 days\"> * " ; } - $tstr = $webRoot . $relDir . "/" . $file ; - $tstr = "" ; + $file_lock=CheckLock($path); + + $file_url_html="" ; if (substr($file,0,5) != ".del/") { - $tstr .= $file . "" . $a ; + $file_url_html .= $file . "" . $a ; } else { - $tstr .= substr($file,5,strlen($file)-5) . " deleted "; + $file_url_html .= substr($file,5,strlen($file)-5) . " deleted "; } -// $b = $gblIcon("checkout"); -// $b .= $gblIcon("checkin"); + $note_html="".$gblIcon("note")."".ReadNote($path); $ext = strtolower(strrchr($file,".")) ; - if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) { - $b .= "" ; - $b .= $gblIcon("view") . "" ; + + if ($file_lock) { + if ($file_lock == $GLOBALS[gblUserName]) { + $b.="" ; + $file_url_html=$b; + $b.=$gblIcon("checkin")."" ; + $b.= $gblIcon("blank"); + $file_url_html.="$file $a"; + $note_html = $gblIcon("blank")."Please check-in (update) this file"; + } else { + $b = $gblIcon("locked"); + $b.= $gblIcon("blank"); + $note_html = $gblIcon("blank")."File locked by $file_lock"; + $file_url_html = "$file $a"; + } } else { - $b .= $gblIcon("blank"); + $b.="" ; + $b.=$gblIcon("checkout")."" ; + + if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) { + $b.="" ; + $b.=$gblIcon("view")."" ; + } else { + $b.= $gblIcon("blank"); + } } @@ -757,9 +814,9 @@ - + - + Bytes @@ -785,6 +842,16 @@
+ +To just view file without editing, select it's filename (don't edit files which are opened this way!)
+To edit file select to check-out +and edit it locally. After editing is over, select filename or to check-in (update copy of file on server).
+If you select icon left from filename, you will get detailed information +about file, as well as delete, rename and annotation options. + + +
+
CREATE NEW DIRECTORY -OR- @@ -793,8 +860,7 @@ - OR UPLOAD A FILE + OR UPLOAD A FILE
@@ -806,7 +872,7 @@ ////////////////////////////////////////////////////////////////// -function UploadPage($fsRoot, $relDir) { +function UploadPage($fsRoot, $relDir, $filename) { $self = $GLOBALS["PHP_SELF"] ; if ($relDir == "") $relDir = "/" ; @@ -816,6 +882,10 @@
DESTINATION DIRECTORY: + +
DESTINATION FILE: + +

PATHNAME OF LOCAL FILE
@@ -943,7 +1013,7 @@ $msg=fgets($note,4096); fclose($note); } - return $msg; + return StripSlashes($msg); } @@ -962,6 +1032,72 @@ ////////////////////////////////////////////////////////////////// +function Lock($target) { + + $dir=dirname($target); + if (! file_exists($dir."/.lock")) { + mkdir($dir."/.lock",0700); + } + $file=basename($target); + + if (file_exists("$dir/.lock/$file")) { + Logit($target,"attempt to locked allready locked file!"); + } else { + $lock=fopen("$dir/.lock/$file","w"); + fputs($lock,"$GLOBALS[gblUserName]\n"); + fclose($lock); + + Logit($target,"file locked"); + } + +} + +function CheckLock($target) { + + $dir=dirname($target); + $file=basename($target); + $msg=0; + if (file_exists($dir."/.lock/$file")) { + $lock=fopen("$dir/.lock/$file","r"); + $msg=fgets($lock,4096); + fclose($lock); + } + return chop($msg); + +} + +function Unlock($target) { + + $dir=dirname($target); + $file=basename($target); + if (file_exists($dir."/.lock/$file")) { + unlink("$dir/.lock/$file"); + Logit($target,"file unlocked"); + } else { + Logit($target,"attempt to unlocked non-locked file!"); + } + +} + +////////////////////////////////////////////////////////////////// + +function urlpath($url) { + $url=urlencode(StripSlashes("$url")); + $url=str_replace("%2F","/",$url); + $url=str_replace("+","%20",$url); + return($url); +} + +////////////////////////////////////////////////////////////////// + +function safe_rename($from,$to) { + if (file_exists($from) && is_writable(dirname($to))) { + rename($from,$to); + } +} + +////////////////////////////////////////////////////////////////// + // MAIN PROGRAM // ============ // query parameters: capital letters @@ -1028,7 +1164,11 @@ // TODO : should rather check for escapeshellcmds // but maybe RFC 18xx asserts safe filenames .... $source = $FN ; - $target = $fsDir . "/" . $FN_name ; + if (! isset($FILENAME)) { // from update file + $target = "$fsDir/$FN_name" ; + } else { + $target = "$fsDir/$FILENAME"; + } // backup old files first $dir=dirname($target); @@ -1042,12 +1182,15 @@ for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) { MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/"); } - MoveTo($target,$dir."/.bak/1/".$file); + MoveTo($target,$dir."/.bak/1/"); copy($source,$target) ; chmod($target,$gblFilePerms) ; clearstatcache() ; Logit($target,"uploaded"); + if (isset($FILENAME)) { + Unlock($target); + } break ; case "SAVE" : @@ -1073,19 +1216,27 @@ $relPath = $relDir . "/" . $FN ; switch ( $T ) { case "D" : // create a directory - if ( ! @mkdir($path,$gblDirPerms) ) - Error("Mkdir failed",$relPath) ; // eg. if it exists - clearstatcache() ; - break ; + if ( ! @mkdir($path,$gblDirPerms) ) + Error("Mkdir failed",$relPath) ; // eg. if it exists + clearstatcache() ; + break ; case "F" : // create a new file // this functionality is doubled in DetailView(). // better keep it here altogether // chmod perms to $gblFilePerms - if ( file_exists($path) && !is_writable($path) ) - Error("File not writable", $relPath) ; - $tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ; - header("Location: " . $tstr) ; - exit ; + if ( file_exists($path) && !is_writable($path) ) + Error("File not writable", $relPath) ; + $fh = fopen($path, "w+") ; + if ($fh) { + fputs($fh,"\n"); + fclose($fh) ; + LogIt($path,"file created"); + } else { + Error("Creation of file $relPath failed -- $path"); + } + $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ; + header("Location: " . $tstr) ; + exit ; } break ; @@ -1111,11 +1262,9 @@ exit ; } else { Logit($path,"file deleted"); - if (! file_exists("$dir/.del/.log")) { - mkdir("$dir/.del/.log",0700); - } MoveTo("$dir/.log/$file","$dir/.del/.log/"); MoveTo("$dir/.note/$file","$dir/.del/.note/"); + MoveTo("$dir/.lock/$file","$dir/.del/.lock/"); } } else { // delete directory @@ -1138,6 +1287,7 @@ MoveTo("$fsDir/.del/$file","$fsDir/"); MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/"); MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/"); + MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/"); break ; @@ -1145,8 +1295,10 @@ if ( $CONFIRM != "on" ) break ; Logit("$fsDir/$FN","renamed $FN to $NEWNAME"); - rename("$fsDir/$FN","$fsDir/$NEWNAME"); - rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME"); + safe_rename("$fsDir/$FN","$fsDir/$NEWNAME"); + safe_rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME"); + safe_rename("$fsDir/.note/$FN","$fsDir/.note/$NEWNAME"); + safe_rename("$fsDir/.lock/$FN","$fsDir/.lock/$NEWNAME"); break ; @@ -1154,6 +1306,11 @@ WriteNote("$fsDir/$FN","$NOTE"); break ; + case "UNLOCK" : + if ( $CONFIRM != "on" ) break ; + Unlock("$fsDir/$FN"); + break ; + default : // user hit "CANCEL" or undefined action } @@ -1169,6 +1326,9 @@ // $A=U : upload to path given in $D // $A=E : display detail of file $D/$F and edit // $A=C : display code in file $D/$F + // $A=Co : checkout file $D/$F + // $A=Ci : checkin file $D/$F + // $A=V : view file (do nothing except log) // default : display directory $D switch ($A) { @@ -1190,6 +1350,26 @@ // listing of $relDir/$F DisplayCode($gblFsRoot, $relDir, $F) ; exit ; + case "Co" : + // checkout + Lock("$gblFsRoot/$relDir/$F"); + Header("Location: ".urlpath("$relDir/$F")); + exit; + case "Ci" : + // upload && update to $relDir + if (!is_writeable($gblFsRoot . $relDir)) + Error("Write access denied",$relDir) ; + $text = "Use this page to update a single " ; + $text .= "file to $SERVER_NAME." ; + StartHTML("(Update file Page)", $text) ; + UploadPage($gblFsRoot, $relDir, $F) ; + EndHTML() ; + exit ; + case "V" : + // view + LogIt("$gblFsRoot/$relDir/$F","viewed"); + Header("Location: ".urlpath("$relDir/$F")); + exit; } // default: display directory $relDir