mirror of
				https://git.code.sf.net/p/seeddms/code
				synced 2025-10-30 20:51:22 +00:00 
			
		
		
		
	edit document versions online
This commit is contained in:
		
							parent
							
								
									adcd6d7002
								
							
						
					
					
						commit
						cbb9317619
					
				
							
								
								
									
										67
									
								
								op/op.EditOnline.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								op/op.EditOnline.php
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,67 @@ | |||
| <?php | ||||
| //    MyDMS. Document Management System
 | ||||
| //    Copyright (C) 2002-2005  Markus Westphal
 | ||||
| //    Copyright (C) 2006-2008 Malcolm Cowe
 | ||||
| //
 | ||||
| //    This program is free software; you can redistribute it and/or modify
 | ||||
| //    it under the terms of the GNU General Public License as published by
 | ||||
| //    the Free Software Foundation; either version 2 of the License, or
 | ||||
| //    (at your option) any later version.
 | ||||
| //
 | ||||
| //    This program is distributed in the hope that it will be useful,
 | ||||
| //    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | ||||
| //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | ||||
| //    GNU General Public License for more details.
 | ||||
| //
 | ||||
| //    You should have received a copy of the GNU General Public License
 | ||||
| //    along with this program; if not, write to the Free Software
 | ||||
| //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 | ||||
| 
 | ||||
| include("../inc/inc.Settings.php"); | ||||
| include("../inc/inc.LogInit.php"); | ||||
| include("../inc/inc.Utils.php"); | ||||
| include("../inc/inc.DBInit.php"); | ||||
| include("../inc/inc.Language.php"); | ||||
| include("../inc/inc.ClassUI.php"); | ||||
| include("../inc/inc.Authentication.php"); | ||||
| 
 | ||||
| if (!isset($_POST["documentid"]) || !is_numeric($_POST["documentid"]) || intval($_POST["documentid"])<1) { | ||||
| 	UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id")); | ||||
| } | ||||
| 
 | ||||
| $documentid = $_POST["documentid"]; | ||||
| $document = $dms->getDocument($documentid); | ||||
| 
 | ||||
| if (!is_object($document)) { | ||||
| 	UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id")); | ||||
| } | ||||
| 
 | ||||
| $folder = $document->getFolder(); | ||||
| $docPathHTML = getFolderPathHTML($folder, true). " / <a href=\"../out/out.ViewDocument.php?documentid=".$documentid."\">".$document->getName()."</a>"; | ||||
| 
 | ||||
| if ($document->getAccessMode($user) < M_READWRITE) { | ||||
| 	UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("access_denied")); | ||||
| } | ||||
| 
 | ||||
| if($document->isLocked()) { | ||||
| 	$lockingUser = $document->getLockingUser(); | ||||
| 	if (($lockingUser->getID() != $user->getID()) && ($document->getAccessMode($user) != M_ALL)) { | ||||
| 		UI::exitError(getMLText("document_title", array("documentname" => htmlspecialchars($document->getName()))),getMLText("lock_message", array("email" => $lockingUser->getEmail(), "username" => htmlspecialchars($lockingUser->getFullName())))); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| $tmpfname = tempnam(sys_get_temp_dir(), 'FOO'); | ||||
| file_put_contents($tmpfname, $_POST['data']); | ||||
| 
 | ||||
| /* Check if the uploaded file is identical to last version */ | ||||
| $lc = $document->getLatestContent(); | ||||
| if($lc->getChecksum() == SeedDMS_Core_File::checksum($tmpfname)) { | ||||
| 	echo json_encode(array('success'=>false, 'message'=>getMLText('identical_version'))); | ||||
| } else { | ||||
| 	if($document->replaceContent(0, $user, $tmpfname, $lc->getOriginalFileName(), $lc->getFileType(), $lc->getMimeType())) { | ||||
| 		echo json_encode(array('success'=>true, 'message'=>getMLText('splash_saved_file'))); | ||||
| 	} else { | ||||
| 		echo json_encode(array('success'=>false, 'message'=>getMLText('splash_error_saving_file'))); | ||||
| 	} | ||||
| } | ||||
| unlink($tmpfname); | ||||
							
								
								
									
										94
									
								
								out/out.EditOnline.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								out/out.EditOnline.php
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,94 @@ | |||
| <?php | ||||
| //    MyDMS. Document Management System
 | ||||
| //    Copyright (C) 2002-2005  Markus Westphal
 | ||||
| //    Copyright (C) 2006-2008 Malcolm Cowe
 | ||||
| //    Copyright (C) 2011 Uwe Steinmann
 | ||||
| //
 | ||||
| //    This program is free software; you can redistribute it and/or modify
 | ||||
| //    it under the terms of the GNU General Public License as published by
 | ||||
| //    the Free Software Foundation; either version 2 of the License, or
 | ||||
| //    (at your option) any later version.
 | ||||
| //
 | ||||
| //    This program is distributed in the hope that it will be useful,
 | ||||
| //    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | ||||
| //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | ||||
| //    GNU General Public License for more details.
 | ||||
| //
 | ||||
| //    You should have received a copy of the GNU General Public License
 | ||||
| //    along with this program; if not, write to the Free Software
 | ||||
| //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 | ||||
| 
 | ||||
| include("../inc/inc.Settings.php"); | ||||
| include("../inc/inc.LogInit.php"); | ||||
| include("../inc/inc.DBInit.php"); | ||||
| include("../inc/inc.Language.php"); | ||||
| include("../inc/inc.ClassUI.php"); | ||||
| include("../inc/inc.ClassAccessOperation.php"); | ||||
| include("../inc/inc.Authentication.php"); | ||||
| 
 | ||||
| $documentid = $_GET["documentid"]; | ||||
| 
 | ||||
| if (!isset($documentid) || !is_numeric($documentid) || intval($documentid)<1) { | ||||
| 	UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id")); | ||||
| } | ||||
| 
 | ||||
| $document = $dms->getDocument($documentid); | ||||
| 
 | ||||
| if (!is_object($document)) { | ||||
| 	UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id")); | ||||
| } | ||||
| 
 | ||||
| if ($document->getAccessMode($user) < M_READWRITE) { | ||||
| 	UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("access_denied")); | ||||
| } | ||||
| 
 | ||||
| if(isset($_GET["version"])) { | ||||
| 	$version = $_GET["version"]; | ||||
| 
 | ||||
| 	if (!is_numeric($version)) { | ||||
| 		UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_version")); | ||||
| 	} | ||||
| 	 | ||||
| 	$content = $document->getContentByVersion($version); | ||||
| 	$lc = $document->getLatestContent(); | ||||
| 
 | ||||
| }	else { | ||||
| 	$content = $document->getLatestContent(); | ||||
| 	$lc = $document->getLatestContent(); | ||||
| } | ||||
| 
 | ||||
| if (!is_object($content)) { | ||||
| 	UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_version")); | ||||
| } | ||||
| 
 | ||||
| /* Only the latest version may be edited */ | ||||
| if($content->getVersion() != $lc->getVersion()) { | ||||
| 	UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_version")); | ||||
| } | ||||
| 
 | ||||
| /* | ||||
| if (!isset($settings->_editOnlineFileTypes) || !is_array($settings->_editOnlineFileTypes) || !in_array(strtolower($content->getFileType()), $settings->_editOnlineFileTypes)) { | ||||
| 	UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_version")); | ||||
| } | ||||
|  */ | ||||
| 
 | ||||
| /* Create object for checking access to certain operations */ | ||||
| $accessop = new SeedDMS_AccessOperation($dms, $user, $settings); | ||||
| 
 | ||||
| $folder = $document->getFolder(); | ||||
| 
 | ||||
| $tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME'])); | ||||
| $view = UI::factory($theme, $tmp[1], array('dms'=>$dms, 'user'=>$user)); | ||||
| if($view) { | ||||
| 	$view->setParam('document', $document); | ||||
| 	$view->setParam('version', $content); | ||||
| 	$view->setParam('folder', $folder); | ||||
| 	$view->setParam('accessobject', $accessop); | ||||
| 	$view->setParam('cachedir', $settings->_cacheDir); | ||||
| 	$view->setParam('previewWidthList', $settings->_previewWidthList); | ||||
| 	$view->setParam('previewWidthDetail', $settings->_previewWidthDetail); | ||||
| 	$view->setParam('timeout', $settings->_cmdTimeout); | ||||
| 	$view($_GET); | ||||
| 	exit; | ||||
| } | ||||
| 
 | ||||
							
								
								
									
										138
									
								
								views/bootstrap/class.EditOnline.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										138
									
								
								views/bootstrap/class.EditOnline.php
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,138 @@ | |||
| <?php | ||||
| /** | ||||
|  * Implementation of EditOnline view | ||||
|  * | ||||
|  * @category   DMS | ||||
|  * @package    SeedDMS | ||||
|  * @license    GPL 2 | ||||
|  * @version    @version@ | ||||
|  * @author     Uwe Steinmann <uwe@steinmann.cx> | ||||
|  * @copyright  Copyright (C) 2002-2005 Markus Westphal, | ||||
|  *             2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli, | ||||
|  *             2010-2012 Uwe Steinmann | ||||
|  * @version    Release: @package_version@ | ||||
|  */ | ||||
| 
 | ||||
| /** | ||||
|  * Include parent class | ||||
|  */ | ||||
| require_once("class.Bootstrap.php"); | ||||
| 
 | ||||
| /** | ||||
|  * Class which outputs the html page for EditOnline view | ||||
|  * | ||||
|  * @category   DMS | ||||
|  * @package    SeedDMS | ||||
|  * @author     Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx> | ||||
|  * @copyright  Copyright (C) 2002-2005 Markus Westphal, | ||||
|  *             2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli, | ||||
|  *             2010-2012 Uwe Steinmann | ||||
|  * @version    Release: @package_version@ | ||||
|  */ | ||||
| class SeedDMS_View_EditOnline extends SeedDMS_Bootstrap_Style { | ||||
| 	var $dms; | ||||
| 	var $folder_count; | ||||
| 	var $document_count; | ||||
| 	var $file_count; | ||||
| 	var $storage_size; | ||||
| 
 | ||||
| 	function preview() { /* {{{ */ | ||||
| 		$dms = $this->params['dms']; | ||||
| 		$document = $this->params['document']; | ||||
| 		$version = $this->params['version']; | ||||
| ?>
 | ||||
| 		<ul class="nav nav-tabs" id="preview-tab"> | ||||
| 		  <li class="active"><a data-target="#preview_markdown" data-toggle="tab"><?php printMLText('preview_markdown'); ?></a></li>
 | ||||
| 		  <li><a data-target="#preview_plain" data-toggle="tab"><?php printMLText('preview_plain'); ?></a></li>
 | ||||
| 		</ul> | ||||
| 		<div class="tab-content"> | ||||
| 		  <div class="tab-pane active" id="preview_markdown"> | ||||
| <?php | ||||
| 		require_once('parsedown/Parsedown.php'); | ||||
| 		$Parsedown = new Parsedown(); | ||||
| 		echo $Parsedown->text(file_get_contents($dms->contentDir . $version->getPath())); | ||||
| ?>
 | ||||
| 			</div> | ||||
| 		  <div class="tab-pane" id="preview_plain"> | ||||
| <?php | ||||
| 		echo "<pre>".htmlspecialchars(file_get_contents($dms->contentDir . $version->getPath()))."</pre>"; | ||||
| ?>
 | ||||
| 			</div> | ||||
| 		</div> | ||||
| <?php | ||||
| 	} /* }}} */ | ||||
| 
 | ||||
| 	function show() { /* {{{ */ | ||||
| 		$dms = $this->params['dms']; | ||||
| 		$user = $this->params['user']; | ||||
| 		$document = $this->params['document']; | ||||
| 		$version = $this->params['version']; | ||||
| 		$cachedir = $this->params['cachedir']; | ||||
| 		$previewwidthlist = $this->params['previewWidthList']; | ||||
| 		$previewwidthdetail = $this->params['previewWidthDetail']; | ||||
| 
 | ||||
| 		$set = 'markdown'; //default or markdown
 | ||||
| 		$skin = 'simple'; // simple or markitup
 | ||||
| 		$this->htmlAddHeader('<link href="../styles/'.$this->theme.'/markitup/skins/'.$skin.'/style.css" rel="stylesheet">'."\n", 'css'); | ||||
| 		$this->htmlAddHeader('<link href="../styles/'.$this->theme.'/markitup/sets/'.$set.'/style.css" rel="stylesheet">'."\n", 'css'); | ||||
| 		$this->htmlAddHeader('<script type="text/javascript" src="../styles/'.$this->theme.'/markitup/jquery.markitup.js"></script>'."\n", 'js'); | ||||
| 		$this->htmlAddHeader('<script type="text/javascript" src="../styles/'.$this->theme.'/markitup/sets/'.$set.'/set.js"></script>'."\n", 'js'); | ||||
| 
 | ||||
| 		$this->htmlStartPage(getMLText("edit_online")); | ||||
| 		$this->globalNavigation(); | ||||
| 		$this->contentStart(); | ||||
| 		$folder = $document->getFolder(); | ||||
| 		$this->pageNavigation($this->getFolderPathHTML($folder, true, $document), "view_document", $document); | ||||
| ?>
 | ||||
| 
 | ||||
| <?php | ||||
| echo "<div class=\"row-fluid\">\n"; | ||||
| 
 | ||||
| echo "<div class=\"span6\">\n"; | ||||
| $this->contentHeading(getMLText("content")); | ||||
| ?>
 | ||||
| <script language="javascript"> | ||||
| $(document).ready(function()	{ | ||||
| 	$('#markdown').markItUp(mySettings); | ||||
| 
 | ||||
| 	$('#update').click(function(event) { | ||||
| 		event.preventDefault(); | ||||
| 		$.post("../op/op.EditOnline.php", $('#form1').serialize(), function(response) { | ||||
| 			noty({ | ||||
| 				text: response.message, | ||||
| 				type: response.success === true ? 'success' : 'error', | ||||
| 				dismissQueue: true, | ||||
| 				layout: 'topRight', | ||||
| 				theme: 'defaultTheme', | ||||
| 				timeout: 1500, | ||||
| 			}); | ||||
| 			$('div.ajax').trigger('update', {documentid: <?= $document->getId() ?>});
 | ||||
| 		}, "json"); | ||||
| 		return false; | ||||
| 	}); | ||||
| }); | ||||
| </script> | ||||
| <form action="../op/op.EditOnline.php" id="form1" method="post"> | ||||
| <input type="hidden" name="documentid" value="<?= $document->getId() ?>" /> | ||||
| <textarea id="markdown" name="data" width="100%" rows="20"> | ||||
| <?php | ||||
| 	echo htmlspecialchars(file_get_contents($dms->contentDir . $version->getPath())); | ||||
| ?>
 | ||||
| </textarea> | ||||
| <button id="update" type="submit" class="btn btn-primary"><i class="icon-save"></i> <?php printMLText("save"); ?></button>
 | ||||
| </form> | ||||
| <?php | ||||
| echo "</div>\n"; | ||||
| 
 | ||||
| echo "<div class=\"span6\">\n"; | ||||
| $this->contentHeading(getMLText("preview")); | ||||
| echo "<div class=\"ajax\" data-view=\"EditOnline\" data-action=\"preview\" data-query=\"documentid=".$document->getId()."\"></div>"; | ||||
| echo "</div>\n"; | ||||
| 
 | ||||
| echo "</div>\n"; | ||||
| 
 | ||||
| $this->contentContainerEnd(); | ||||
| $this->htmlEndPage(); | ||||
| 	} /* }}} */ | ||||
| } | ||||
| ?>
 | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Uwe Steinmann
						Uwe Steinmann