--- docman.php 2000/08/03 20:54:27 1.4 +++ docman.php 2000/08/04 10:07:04 1.6 @@ -184,7 +184,7 @@ - - - [logout] + [?relogin=">logout]
ANYPORTAL(php) Site Manager
@@ -240,6 +240,7 @@ $ext = strtolower(strrchr($relPath,".")) ; $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ; $writable = is_writeable($fsPath) ; + $file_lock = CheckLock($fsPath); if (!$editable && !$exists) Error("Creation unsupported for type",$relPath) ; @@ -268,7 +269,7 @@ } - if ( $editable && ($writable || !$exists) ) { + if ( $editable && ($writable || !$exists) && !$file_lock ) { $fh = fopen($fsPath,"a+") ; rewind($fh) ; $fstr = fread($fh,filesize($fsPath)) ; @@ -293,14 +294,14 @@ " ; + echo htmlentities($tstr) . "

" . $tstr ; } - else if ( strstr( join(" ",$gblImages), $ext ) ) { - $info = getimagesize($fsPath) ; - $tstr = "\""" ; - echo htmlentities($tstr) . "

" . $tstr ; - } + ?>
@@ -309,6 +310,17 @@
+
+ +OK TO FORCE LOCK REMOVAL ON "" HELD BY ? + + + +
NOTE FOR "": @@ -343,9 +358,10 @@ + + " ; + $logname=dirname("$fsDir/$fn")."/.log/".basename("$fsDir/$fn"); if (file_exists($logname)) { @@ -590,10 +606,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 +674,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 +721,7 @@
DOCUMENT NAME - + NOTE LAST UPDATEFILE SIZE @@ -729,26 +748,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 +802,9 @@ - + - + Bytes @@ -785,6 +830,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- @@ -806,7 +861,7 @@ ////////////////////////////////////////////////////////////////// -function UploadPage($fsRoot, $relDir) { +function UploadPage($fsRoot, $relDir, $filename) { $self = $GLOBALS["PHP_SELF"] ; if ($relDir == "") $relDir = "/" ; @@ -816,6 +871,10 @@ DESTINATION DIRECTORY: + +
DESTINATION FILE: + +

PATHNAME OF LOCAL FILE
@@ -943,7 +1002,7 @@ $msg=fgets($note,4096); fclose($note); } - return $msg; + return StripSlashes($msg); } @@ -962,6 +1021,55 @@ ////////////////////////////////////////////////////////////////// +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!"); + } + +} + +////////////////////////////////////////////////////////////////// + // MAIN PROGRAM // ============ // query parameters: capital letters @@ -1028,7 +1136,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 +1154,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 +1188,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 +1234,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 +1259,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 ; @@ -1147,6 +1269,8 @@ Logit("$fsDir/$FN","renamed $FN to $NEWNAME"); rename("$fsDir/$FN","$fsDir/$NEWNAME"); rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME"); + rename("$fsDir/.note/$FN","$fsDir/.note/$NEWNAME"); + rename("$fsDir/.lock/$FN","$fsDir/.lock/$NEWNAME"); break ; @@ -1154,6 +1278,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 +1298,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 +1322,28 @@ // listing of $relDir/$F DisplayCode($gblFsRoot, $relDir, $F) ; exit ; + case "Co" : + // checkout + Lock("$gblFsRoot/$relDir/$F"); + $url="$relDir/$F"; $url=str_replace(" ","%20",$url); + Header("Location: $url"); + 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 + Log("viewed"); + $url="$relDir/$F"; $url=str_replace(" ","%20",$url); + Header("Location: $url"); + exit; } // default: display directory $relDir