2012-08-28 08:48:56 +00:00
|
|
|
<?php
|
|
|
|
// MyDMS. Document Management System
|
2016-08-09 05:34:30 +00:00
|
|
|
// Copyright (C) 2010-2016 Uwe Steinmann
|
2012-08-28 08:48:56 +00:00
|
|
|
//
|
|
|
|
// 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");
|
2014-07-11 10:36:22 +00:00
|
|
|
include("../inc/inc.Utils.php");
|
2016-03-09 16:57:38 +00:00
|
|
|
include("../inc/inc.ClassNotificationService.php");
|
2015-11-25 15:49:09 +00:00
|
|
|
include("../inc/inc.ClassEmailNotify.php");
|
2012-08-28 08:48:56 +00:00
|
|
|
include("../inc/inc.DBInit.php");
|
2013-06-18 16:14:41 +00:00
|
|
|
include("../inc/inc.Language.php");
|
|
|
|
include("../inc/inc.ClassUI.php");
|
2012-08-28 08:48:56 +00:00
|
|
|
|
|
|
|
require_once("../inc/inc.Utils.php");
|
|
|
|
require_once("../inc/inc.ClassSession.php");
|
|
|
|
include("../inc/inc.ClassPasswordStrength.php");
|
|
|
|
include("../inc/inc.ClassPasswordHistoryManager.php");
|
|
|
|
|
|
|
|
/* Load session */
|
2013-01-29 13:12:12 +00:00
|
|
|
if (isset($_COOKIE["mydms_session"])) {
|
|
|
|
$dms_session = $_COOKIE["mydms_session"];
|
2013-02-14 11:10:53 +00:00
|
|
|
$session = new SeedDMS_Session($db);
|
2013-01-29 13:12:12 +00:00
|
|
|
if(!$resArr = $session->load($dms_session)) {
|
|
|
|
echo json_encode(array('error'=>1));
|
|
|
|
exit;
|
|
|
|
}
|
2012-08-28 08:48:56 +00:00
|
|
|
|
2014-05-22 04:39:54 +00:00
|
|
|
/* Update last access time */
|
|
|
|
$session->updateAccess($dms_session);
|
|
|
|
|
2013-01-29 13:12:12 +00:00
|
|
|
/* Load user data */
|
|
|
|
$user = $dms->getUser($resArr["userID"]);
|
|
|
|
if (!is_object($user)) {
|
|
|
|
echo json_encode(array('error'=>1));
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
$dms->setUser($user);
|
2013-05-24 15:30:02 +00:00
|
|
|
if($user->isAdmin()) {
|
|
|
|
if($resArr["su"]) {
|
|
|
|
$user = $dms->getUser($resArr["su"]);
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 16:57:38 +00:00
|
|
|
$notifier = new SeedDMS_NotificationService();
|
2014-07-11 10:36:22 +00:00
|
|
|
if($settings->_enableEmail) {
|
2016-03-09 16:57:38 +00:00
|
|
|
$notifier->addService(new SeedDMS_EmailNotify($dms));
|
2014-07-11 10:36:22 +00:00
|
|
|
}
|
2014-03-06 10:33:31 +00:00
|
|
|
include $settings->_rootDir . "languages/" . $resArr["language"] . "/lang.inc";
|
2013-01-29 13:12:12 +00:00
|
|
|
} else {
|
|
|
|
$user = null;
|
2012-08-28 08:48:56 +00:00
|
|
|
}
|
2013-01-29 13:12:12 +00:00
|
|
|
|
2013-09-03 06:19:59 +00:00
|
|
|
$command = $_REQUEST["command"];
|
2012-08-28 08:48:56 +00:00
|
|
|
switch($command) {
|
2014-04-08 08:41:53 +00:00
|
|
|
case 'checkpwstrength': /* {{{ */
|
2012-08-28 08:48:56 +00:00
|
|
|
$ps = new Password_Strength();
|
2013-09-03 06:19:59 +00:00
|
|
|
$ps->set_password($_REQUEST["pwd"]);
|
2012-08-28 08:48:56 +00:00
|
|
|
if($settings->_passwordStrengthAlgorithm == 'simple')
|
|
|
|
$ps->simple_calculate();
|
|
|
|
else
|
|
|
|
$ps->calculate();
|
|
|
|
$score = $ps->get_score();
|
|
|
|
if($settings->_passwordStrength) {
|
2012-12-17 18:30:08 +00:00
|
|
|
if($score >= $settings->_passwordStrength) {
|
2012-12-14 07:57:03 +00:00
|
|
|
echo json_encode(array('error'=>0, 'strength'=>$score, 'score'=>$score/$settings->_passwordStrength, 'ok'=>1));
|
2012-08-28 08:48:56 +00:00
|
|
|
} else {
|
2012-12-14 07:57:03 +00:00
|
|
|
echo json_encode(array('error'=>0, 'strength'=>$score, 'score'=>$score/$settings->_passwordStrength, 'ok'=>0));
|
2012-08-28 08:48:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
echo json_encode(array('error'=>0, 'strength'=>$score));
|
|
|
|
}
|
2014-04-08 08:41:53 +00:00
|
|
|
break; /* }}} */
|
2012-08-28 08:48:56 +00:00
|
|
|
|
2014-03-06 10:33:31 +00:00
|
|
|
case 'sessioninfo': /* {{{ */
|
|
|
|
if($user) {
|
|
|
|
echo json_encode($resArr);
|
|
|
|
}
|
|
|
|
break; /* }}} */
|
|
|
|
|
2013-06-18 16:14:41 +00:00
|
|
|
case 'searchdocument': /* {{{ */
|
2013-01-29 13:12:12 +00:00
|
|
|
if($user) {
|
|
|
|
$query = $_GET['query'];
|
2013-01-28 10:12:07 +00:00
|
|
|
|
2013-01-29 13:12:12 +00:00
|
|
|
$hits = $dms->search($query, $limit=0, $offset=0, $logicalmode='AND', $searchin=array(), $startFolder=null, $owner=null, $status = array(), $creationstartdate=array(), $creationenddate=array(), $modificationstartdate=array(), $modificationenddate=array(), $categories=array(), $attributes=array(), $mode=0x1, $expirationstartdate=array(), $expirationenddate=array());
|
|
|
|
if($hits) {
|
|
|
|
$result = array();
|
|
|
|
foreach($hits['docs'] as $hit) {
|
|
|
|
$result[] = $hit->getID().'#'.$hit->getName();
|
|
|
|
}
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
echo json_encode($result);
|
2013-01-28 10:12:07 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-18 16:14:41 +00:00
|
|
|
break; /* }}} */
|
2013-01-28 10:12:07 +00:00
|
|
|
|
2013-06-18 16:14:41 +00:00
|
|
|
case 'searchfolder': /* {{{ */
|
2013-01-29 13:12:12 +00:00
|
|
|
if($user) {
|
|
|
|
$query = $_GET['query'];
|
2013-01-28 10:12:07 +00:00
|
|
|
|
2013-01-29 13:12:12 +00:00
|
|
|
$hits = $dms->search($query, $limit=0, $offset=0, $logicalmode='AND', $searchin=array(), $startFolder=null, $owner=null, $status = array(), $creationstartdate=array(), $creationenddate=array(), $modificationstartdate=array(), $modificationenddate=array(), $categories=array(), $attributes=array(), $mode=0x2, $expirationstartdate=array(), $expirationenddate=array());
|
|
|
|
if($hits) {
|
|
|
|
$result = array();
|
|
|
|
foreach($hits['folders'] as $hit) {
|
|
|
|
$result[] = $hit->getID().'#'.$hit->getName();
|
|
|
|
}
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
echo json_encode($result);
|
2013-01-28 10:12:07 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-18 16:14:41 +00:00
|
|
|
break; /* }}} */
|
2013-05-24 15:30:02 +00:00
|
|
|
|
2013-06-18 16:14:41 +00:00
|
|
|
case 'subtree': /* {{{ */
|
2014-03-06 10:33:31 +00:00
|
|
|
if($user) {
|
|
|
|
if(empty($_GET['node']))
|
|
|
|
$nodeid = $settings->_rootFolderID;
|
|
|
|
else
|
|
|
|
$nodeid = (int) $_GET['node'];
|
|
|
|
if(empty($_GET['showdocs']))
|
|
|
|
$showdocs = false;
|
|
|
|
else
|
|
|
|
$showdocs = true;
|
2014-03-14 14:10:29 +00:00
|
|
|
if(empty($_GET['orderby']))
|
|
|
|
$orderby = $settings->_sortFoldersDefault;
|
|
|
|
else
|
|
|
|
$orderby = $_GET['orderby'];
|
2013-05-24 15:30:02 +00:00
|
|
|
|
2014-03-06 10:33:31 +00:00
|
|
|
$folder = $dms->getFolder($nodeid);
|
|
|
|
if (!is_object($folder)) return '';
|
|
|
|
|
2014-03-14 14:10:29 +00:00
|
|
|
$subfolders = $folder->getSubFolders($orderby);
|
2014-03-06 10:33:31 +00:00
|
|
|
$subfolders = SeedDMS_Core_DMS::filterAccess($subfolders, $user, M_READ);
|
|
|
|
$tree = array();
|
|
|
|
foreach($subfolders as $subfolder) {
|
2014-03-24 09:39:02 +00:00
|
|
|
$loadondemand = $subfolder->hasSubFolders() || ($subfolder->hasDocuments() && $showdocs);
|
|
|
|
$level = array('label'=>$subfolder->getName(), 'id'=>$subfolder->getID(), 'load_on_demand'=>$loadondemand, 'is_folder'=>true);
|
2014-03-06 10:33:31 +00:00
|
|
|
if(!$subfolder->hasSubFolders())
|
|
|
|
$level['children'] = array();
|
2013-05-24 15:30:02 +00:00
|
|
|
$tree[] = $level;
|
|
|
|
}
|
2014-03-06 10:33:31 +00:00
|
|
|
if($showdocs) {
|
2014-03-14 14:10:29 +00:00
|
|
|
$documents = $folder->getDocuments($orderby);
|
2014-03-06 10:33:31 +00:00
|
|
|
$documents = SeedDMS_Core_DMS::filterAccess($documents, $user, M_READ);
|
|
|
|
foreach($documents as $document) {
|
|
|
|
$level = array('label'=>$document->getName(), 'id'=>$document->getID(), 'load_on_demand'=>false, 'is_folder'=>false);
|
|
|
|
$tree[] = $level;
|
|
|
|
}
|
|
|
|
}
|
2013-05-24 15:30:02 +00:00
|
|
|
|
2014-03-06 10:33:31 +00:00
|
|
|
echo json_encode($tree);
|
|
|
|
// echo json_encode(array(array('label'=>'test1', 'id'=>1, 'load_on_demand'=> true), array('label'=>'test2', 'id'=>2, 'load_on_demand'=> true)));
|
|
|
|
}
|
2013-06-18 16:14:41 +00:00
|
|
|
break; /* }}} */
|
|
|
|
|
|
|
|
case 'addtoclipboard': /* {{{ */
|
2014-03-06 10:33:31 +00:00
|
|
|
if($user) {
|
|
|
|
if (isset($_GET["id"]) && is_numeric($_GET["id"]) && isset($_GET['type'])) {
|
|
|
|
switch($_GET['type']) {
|
|
|
|
case "folder":
|
|
|
|
$session->addToClipboard($dms->getFolder($_GET['id']));
|
|
|
|
break;
|
|
|
|
case "document":
|
|
|
|
$session->addToClipboard($dms->getDocument($_GET['id']));
|
|
|
|
break;
|
|
|
|
}
|
2014-06-05 13:00:44 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-07-11 10:02:41 +00:00
|
|
|
echo json_encode(array('success'=>true, 'message'=>getMLText('splash_added_to_clipboard')));
|
2014-06-05 13:00:44 +00:00
|
|
|
} else {
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('error')));
|
2014-03-06 10:33:31 +00:00
|
|
|
}
|
2014-06-05 13:00:44 +00:00
|
|
|
}
|
|
|
|
break; /* }}} */
|
|
|
|
|
|
|
|
case 'removefromclipboard': /* {{{ */
|
|
|
|
if($user) {
|
|
|
|
if (isset($_GET["id"]) && is_numeric($_GET["id"]) && isset($_GET['type'])) {
|
|
|
|
switch($_GET['type']) {
|
|
|
|
case "folder":
|
|
|
|
$session->removeFromClipboard($dms->getFolder($_GET['id']));
|
|
|
|
break;
|
|
|
|
case "document":
|
|
|
|
$session->removeFromClipboard($dms->getDocument($_GET['id']));
|
|
|
|
break;
|
|
|
|
}
|
2014-03-06 10:33:31 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-06-05 13:00:44 +00:00
|
|
|
echo json_encode(array('success'=>true));
|
2014-03-06 10:33:31 +00:00
|
|
|
} else {
|
2014-06-05 13:00:44 +00:00
|
|
|
header('Content-Type: application/json');
|
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('error')));
|
2013-06-18 16:14:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break; /* }}} */
|
2014-02-21 20:25:26 +00:00
|
|
|
|
|
|
|
case 'movefolder': /* {{{ */
|
|
|
|
if($user) {
|
2014-06-04 17:17:08 +00:00
|
|
|
if(!checkFormKey('movefolder', 'GET')) {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-06-04 17:17:08 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_request_token'), 'data'=>''));
|
|
|
|
} else {
|
|
|
|
$mfolder = $dms->getFolder($_REQUEST['folderid']);
|
|
|
|
if($mfolder) {
|
|
|
|
if ($mfolder->getAccessMode($user) >= M_READ) {
|
|
|
|
if($folder = $dms->getFolder($_REQUEST['targetfolderid'])) {
|
|
|
|
if($folder->getAccessMode($user) >= M_READWRITE) {
|
|
|
|
if($mfolder->setParent($folder)) {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>true, 'message'=>getMLText('splash_move_folder'), 'data'=>''));
|
2014-06-04 17:17:08 +00:00
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-06-04 17:17:08 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>'Error moving folder', 'data'=>''));
|
|
|
|
}
|
2014-02-21 20:25:26 +00:00
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('access_denied'), 'data'=>''));
|
2014-02-21 20:25:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_folder_id'), 'data'=>''));
|
2014-02-21 20:25:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('access_denied'), 'data'=>''));
|
2014-02-21 20:25:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_folder_id'), 'data'=>''));
|
2014-02-21 20:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break; /* }}} */
|
|
|
|
|
|
|
|
case 'movedocument': /* {{{ */
|
|
|
|
if($user) {
|
2014-06-04 17:15:28 +00:00
|
|
|
if(!checkFormKey('movedocument', 'GET')) {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-06-04 17:15:28 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_request_token'), 'data'=>''));
|
|
|
|
} else {
|
|
|
|
$mdocument = $dms->getDocument($_REQUEST['docid']);
|
|
|
|
if($mdocument) {
|
|
|
|
if ($mdocument->getAccessMode($user) >= M_READ) {
|
|
|
|
if($folder = $dms->getFolder($_REQUEST['targetfolderid'])) {
|
|
|
|
if($folder->getAccessMode($user) >= M_READWRITE) {
|
|
|
|
if($mdocument->setFolder($folder)) {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 09:37:57 +00:00
|
|
|
echo json_encode(array('success'=>true, 'message'=>getMLText('splash_move_document'), 'data'=>''));
|
2014-06-04 17:15:28 +00:00
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>'Error moving document', 'data'=>''));
|
2014-06-04 17:15:28 +00:00
|
|
|
}
|
2014-02-21 20:25:26 +00:00
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('access_denied'), 'data'=>''));
|
2014-02-21 20:25:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_folder_id'), 'data'=>''));
|
2014-02-21 20:25:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('access_denied'), 'data'=>''));
|
2014-06-05 07:48:45 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_doc_id'), 'data'=>''));
|
2014-06-05 07:48:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break; /* }}} */
|
|
|
|
|
|
|
|
case 'deletefolder': /* {{{ */
|
|
|
|
if($user) {
|
|
|
|
if(!checkFormKey('removefolder', 'GET')) {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-06-05 07:48:45 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_request_token'), 'data'=>''));
|
|
|
|
} else {
|
|
|
|
$folder = $dms->getFolder($_REQUEST['id']);
|
|
|
|
if($folder) {
|
|
|
|
if ($folder->getAccessMode($user) >= M_READWRITE) {
|
2016-03-13 07:32:46 +00:00
|
|
|
$parent=$folder->getParent();
|
2016-03-18 14:41:21 +00:00
|
|
|
$nl = $folder->getNotifyList();
|
2016-03-13 07:32:46 +00:00
|
|
|
$foldername = $folder->getName();
|
2014-06-05 07:48:45 +00:00
|
|
|
if($folder->remove()) {
|
2016-03-08 16:23:07 +00:00
|
|
|
if ($notifier) {
|
|
|
|
$subject = "folder_deleted_email_subject";
|
|
|
|
$message = "folder_deleted_email_body";
|
|
|
|
$params = array();
|
|
|
|
$params['name'] = $foldername;
|
|
|
|
$params['folder_path'] = $parent->getFolderPathPlain();
|
|
|
|
$params['username'] = $user->getFullName();
|
|
|
|
$params['sitename'] = $settings->_siteName;
|
|
|
|
$params['http_root'] = $settings->_httpRoot;
|
|
|
|
$params['url'] = "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.ViewFolder.php?folderid=".$parent->getID();
|
|
|
|
$notifier->toList($user, $nl["users"], $subject, $message, $params);
|
|
|
|
foreach ($nl["groups"] as $grp) {
|
|
|
|
$notifier->toGroup($user, $grp, $subject, $message, $params);
|
|
|
|
}
|
|
|
|
}
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-06-06 11:59:12 +00:00
|
|
|
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>''));
|
2014-06-05 07:48:45 +00:00
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-06-05 07:48:45 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>'Error removing folder', 'data'=>''));
|
|
|
|
}
|
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('access_denied'), 'data'=>''));
|
2014-02-21 20:25:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_folder_id'), 'data'=>''));
|
2014-02-21 20:25:26 +00:00
|
|
|
}
|
2014-06-04 17:15:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break; /* }}} */
|
|
|
|
|
|
|
|
case 'deletedocument': /* {{{ */
|
|
|
|
if($user) {
|
|
|
|
if(!checkFormKey('removedocument', 'GET')) {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-06-04 17:15:28 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_request_token'), 'data'=>''));
|
|
|
|
} else {
|
|
|
|
$document = $dms->getDocument($_REQUEST['id']);
|
|
|
|
if($document) {
|
|
|
|
if ($document->getAccessMode($user) >= M_READWRITE) {
|
2015-11-26 12:01:20 +00:00
|
|
|
$folder = $document->getFolder();
|
|
|
|
/* Get the notify list before removing the document */
|
|
|
|
$dnl = $document->getNotifyList();
|
|
|
|
$fnl = $folder->getNotifyList();
|
|
|
|
$nl = array(
|
|
|
|
'users'=>array_merge($dnl['users'], $fnl['users']),
|
|
|
|
'groups'=>array_merge($dnl['groups'], $fnl['groups'])
|
|
|
|
);
|
|
|
|
$docname = $document->getName();
|
2014-06-04 17:15:28 +00:00
|
|
|
if($document->remove()) {
|
2015-08-10 19:43:15 +00:00
|
|
|
/* Remove the document from the fulltext index */
|
|
|
|
if($settings->_enableFullSearch) {
|
|
|
|
$index = $indexconf['Indexer']::open($settings->_luceneDir);
|
|
|
|
if($index) {
|
|
|
|
$lucenesearch = new $indexconf['Search']($index);
|
|
|
|
if($hit = $lucenesearch->getDocument($_REQUEST['id'])) {
|
|
|
|
$index->delete($hit->id);
|
|
|
|
$index->commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-26 12:01:20 +00:00
|
|
|
|
|
|
|
if ($notifier){
|
|
|
|
$subject = "document_deleted_email_subject";
|
|
|
|
$message = "document_deleted_email_body";
|
|
|
|
$params = array();
|
|
|
|
$params['name'] = $docname;
|
|
|
|
$params['folder_path'] = $folder->getFolderPathPlain();
|
|
|
|
$params['username'] = $user->getFullName();
|
|
|
|
$params['sitename'] = $settings->_siteName;
|
|
|
|
$params['http_root'] = $settings->_httpRoot;
|
|
|
|
$notifier->toList($user, $nl["users"], $subject, $message, $params);
|
|
|
|
foreach ($nl["groups"] as $grp) {
|
|
|
|
$notifier->toGroup($user, $grp, $subject, $message, $params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-06-06 11:59:12 +00:00
|
|
|
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>''));
|
2014-06-04 17:15:28 +00:00
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-06-04 17:15:28 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>'Error removing document', 'data'=>''));
|
|
|
|
}
|
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('access_denied'), 'data'=>''));
|
2014-06-04 17:15:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_doc_id'), 'data'=>''));
|
2014-06-04 17:15:28 +00:00
|
|
|
}
|
2014-02-21 20:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break; /* }}} */
|
|
|
|
|
2014-06-06 11:59:12 +00:00
|
|
|
case 'tooglelockdocument': /* {{{ */
|
|
|
|
if($user) {
|
|
|
|
$document = $dms->getDocument($_REQUEST['id']);
|
|
|
|
if($document) {
|
|
|
|
if ($document->getAccessMode($user) >= M_READWRITE) {
|
|
|
|
if ($document->isLocked()) {
|
|
|
|
$lockingUser = $document->getLockingUser();
|
|
|
|
if (($lockingUser->getID() == $user->getID()) || ($document->getAccessMode($user) == M_ALL)) {
|
|
|
|
if (!$document->setLocked(false)) {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-06-06 11:59:12 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>'Error unlocking document', 'data'=>''));
|
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>true, 'message'=>getMLText('splash_document_unlocked'), 'data'=>''));
|
2014-06-06 11:59:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('access_denied'), 'data'=>''));
|
2014-06-06 11:59:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!$document->setLocked($user)) {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-06-06 11:59:12 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>'Error locking document', 'data'=>''));
|
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>true, 'message'=>getMLText('splash_document_locked'), 'data'=>''));
|
2014-06-06 11:59:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('access_denied'), 'data'=>''));
|
2014-06-06 11:59:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2016-03-08 16:23:07 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_doc_id'), 'data'=>''));
|
2014-06-06 11:59:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break; /* }}} */
|
|
|
|
|
2014-04-08 08:41:53 +00:00
|
|
|
case 'submittranslation': /* {{{ */
|
2014-04-08 08:43:59 +00:00
|
|
|
if($settings->_showMissingTranslations) {
|
|
|
|
if($user && !empty($_POST['phrase'])) {
|
|
|
|
if($fp = fopen('/tmp/newtranslations.txt', 'a+')) {
|
|
|
|
fputcsv($fp, array(date('Y-m-d H:i:s'), $user->getLogin(), $_POST['key'], $_POST['lang'], $_POST['phrase']));
|
|
|
|
fclose($fp);
|
|
|
|
}
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-04-08 08:43:59 +00:00
|
|
|
echo json_encode(array('success'=>true, 'message'=>'Thank you for your contribution', 'data'=>''));
|
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-04-08 08:43:59 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>'Missing translation', 'data'=>''));
|
2014-04-08 08:41:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break; /* }}} */
|
|
|
|
|
2014-06-05 13:00:44 +00:00
|
|
|
case 'view': /* {{{ */
|
|
|
|
require_once("SeedDMS/Preview.php");
|
|
|
|
$view = UI::factory($theme, '', array('dms'=>$dms, 'user'=>$user));
|
|
|
|
if($view) {
|
|
|
|
$view->setParam('refferer', '');
|
|
|
|
$view->setParam('cachedir', $settings->_cacheDir);
|
|
|
|
}
|
2014-06-06 11:59:12 +00:00
|
|
|
$content = '';
|
2014-06-05 13:00:44 +00:00
|
|
|
$viewname = $_REQUEST["view"];
|
|
|
|
switch($viewname) {
|
|
|
|
case 'menuclipboard':
|
|
|
|
$content = $view->menuClipboard($session->getClipboard());
|
|
|
|
break;
|
|
|
|
case 'mainclipboard':
|
|
|
|
$content = $view->mainClipboard($session->getClipboard());
|
|
|
|
break;
|
2014-06-06 11:59:12 +00:00
|
|
|
case 'documentlistrow':
|
|
|
|
$document = $dms->getDocument($_REQUEST['id']);
|
|
|
|
if($document) {
|
|
|
|
if ($document->getAccessMode($user) >= M_READ) {
|
|
|
|
$previewer = new SeedDMS_Preview_Previewer($settings->_cacheDir, $settings->_previewWidthList);
|
|
|
|
$view->setParam('previewWidthList', $settings->_previewWidthList);
|
|
|
|
$view->setParam('showtree', showtree());
|
|
|
|
$content = $view->documentListRow($document, $previewer, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-06-05 13:00:44 +00:00
|
|
|
default:
|
|
|
|
$content = '';
|
|
|
|
}
|
|
|
|
echo $content;
|
|
|
|
|
|
|
|
break; /* }}} */
|
2014-07-11 06:38:26 +00:00
|
|
|
|
|
|
|
case 'uploaddocument': /* {{{ */
|
|
|
|
if($user) {
|
|
|
|
if(checkFormKey('adddocument')) {
|
|
|
|
if (!isset($_POST["folderid"]) || !is_numeric($_POST["folderid"]) || intval($_POST["folderid"])<1) {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-07-11 06:38:26 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText("invalid_folder_id")));
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$folderid = $_POST["folderid"];
|
|
|
|
$folder = $dms->getFolder($folderid);
|
|
|
|
|
|
|
|
if (!is_object($folder)) {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-07-11 06:38:26 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText("invalid_folder_id")));
|
|
|
|
exit;
|
|
|
|
}
|
2014-11-11 14:42:07 +00:00
|
|
|
|
|
|
|
if ($folder->getAccessMode($user) < M_READWRITE) {
|
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText("access_denied")));
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($settings->_quota > 0) {
|
|
|
|
$remain = checkQuota($user);
|
|
|
|
if ($remain < 0) {
|
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText("quota_exceeded", array('bytes'=>SeedDMS_Core_File::format_filesize(abs($remain))))));
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-11 06:38:26 +00:00
|
|
|
if (!is_uploaded_file($_FILES["userfile"]["tmp_name"]) || $_FILES['userfile']['error']!=0){
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-07-11 06:38:26 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText("uploading_failed")));
|
|
|
|
exit;
|
|
|
|
}
|
2014-07-11 09:14:27 +00:00
|
|
|
if ($_FILES["userfile"]["size"]==0) {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-07-11 09:14:27 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText("uploading_zerosize")));
|
|
|
|
exit;
|
|
|
|
}
|
2014-07-11 06:38:26 +00:00
|
|
|
|
|
|
|
$userfiletmp = $_FILES["userfile"]["tmp_name"];
|
|
|
|
$userfiletype = $_FILES["userfile"]["type"];
|
|
|
|
$userfilename = $_FILES["userfile"]["name"];
|
|
|
|
|
|
|
|
$fileType = ".".pathinfo($userfilename, PATHINFO_EXTENSION);
|
|
|
|
|
2015-06-23 05:45:18 +00:00
|
|
|
if($settings->_overrideMimeType) {
|
|
|
|
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
|
|
|
$userfiletype = finfo_file($finfo, $userfiletmp);
|
|
|
|
}
|
|
|
|
|
2014-07-11 10:36:22 +00:00
|
|
|
if (!empty($_POST["name"]))
|
2014-07-11 06:38:26 +00:00
|
|
|
$name = $_POST["name"];
|
|
|
|
else
|
|
|
|
$name = basename($userfilename);
|
|
|
|
|
|
|
|
/* Check if name already exists in the folder */
|
|
|
|
if(!$settings->_enableDuplicateDocNames) {
|
|
|
|
if($folder->hasDocumentByName($name)) {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-07-11 06:38:26 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText("document_duplicate_name")));
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-11 10:36:22 +00:00
|
|
|
// Get the list of reviewers and approvers for this document.
|
|
|
|
$reviewers = array();
|
|
|
|
$approvers = array();
|
|
|
|
$reviewers["i"] = array();
|
|
|
|
$reviewers["g"] = array();
|
|
|
|
$approvers["i"] = array();
|
|
|
|
$approvers["g"] = array();
|
|
|
|
|
|
|
|
// add mandatory reviewers/approvers
|
|
|
|
$docAccess = $folder->getReadAccessList($settings->_enableAdminRevApp, $settings->_enableOwnerRevApp);
|
|
|
|
$res=$user->getMandatoryReviewers();
|
|
|
|
foreach ($res as $r){
|
|
|
|
|
|
|
|
if ($r['reviewerUserID']!=0){
|
|
|
|
foreach ($docAccess["users"] as $usr)
|
|
|
|
if ($usr->getID()==$r['reviewerUserID']){
|
|
|
|
$reviewers["i"][] = $r['reviewerUserID'];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ($r['reviewerGroupID']!=0){
|
|
|
|
foreach ($docAccess["groups"] as $grp)
|
|
|
|
if ($grp->getID()==$r['reviewerGroupID']){
|
|
|
|
$reviewers["g"][] = $r['reviewerGroupID'];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$res=$user->getMandatoryApprovers();
|
|
|
|
foreach ($res as $r){
|
|
|
|
|
|
|
|
if ($r['approverUserID']!=0){
|
|
|
|
foreach ($docAccess["users"] as $usr)
|
|
|
|
if ($usr->getID()==$r['approverUserID']){
|
|
|
|
$approvers["i"][] = $r['approverUserID'];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ($r['approverGroupID']!=0){
|
|
|
|
foreach ($docAccess["groups"] as $grp)
|
|
|
|
if ($grp->getID()==$r['approverGroupID']){
|
|
|
|
$approvers["g"][] = $r['approverGroupID'];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$workflow = $user->getMandatoryWorkflow();
|
|
|
|
|
2015-01-29 16:28:40 +00:00
|
|
|
$expires = false;
|
|
|
|
if($settings->_presetExpirationDate) {
|
|
|
|
$expires = strtotime($settings->_presetExpirationDate);
|
|
|
|
}
|
|
|
|
|
2014-07-11 06:38:26 +00:00
|
|
|
$cats = array();
|
|
|
|
|
2015-01-29 16:28:40 +00:00
|
|
|
$res = $folder->addDocument($name, '', $expires, $user, '',
|
2014-07-11 06:38:26 +00:00
|
|
|
array(), $userfiletmp, basename($userfilename),
|
|
|
|
$fileType, $userfiletype, 0,
|
2014-07-11 10:36:22 +00:00
|
|
|
$reviewers, $approvers, 1,
|
|
|
|
'', array(), array(), $workflow);
|
2014-07-11 06:38:26 +00:00
|
|
|
|
|
|
|
if (is_bool($res) && !$res) {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-07-11 06:38:26 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText("error_occured")));
|
|
|
|
exit;
|
|
|
|
} else {
|
|
|
|
$document = $res[0];
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['postAddDocument'])) {
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['postAddDocument'] as $hookObj) {
|
|
|
|
if (method_exists($hookObj, 'postAddDocument')) {
|
|
|
|
$hookObj->postAddDocument($document);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($settings->_enableFullSearch) {
|
|
|
|
if(!empty($settings->_luceneClassDir))
|
|
|
|
require_once($settings->_luceneClassDir.'/Lucene.php');
|
|
|
|
else
|
|
|
|
require_once('SeedDMS/Lucene.php');
|
|
|
|
|
|
|
|
$index = SeedDMS_Lucene_Indexer::open($settings->_luceneDir);
|
|
|
|
if($index) {
|
|
|
|
SeedDMS_Lucene_Indexer::init($settings->_stopWordsFile);
|
2015-05-02 06:04:41 +00:00
|
|
|
$index->addDocument(new SeedDMS_Lucene_IndexedDocument($dms, $document, isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null, true));
|
2014-07-11 06:38:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a default notification for the owner of the document */
|
|
|
|
if($settings->_enableOwnerNotification) {
|
|
|
|
$res = $document->addNotify($user->getID(), true);
|
|
|
|
}
|
|
|
|
// Send notification to subscribers of folder.
|
|
|
|
if($notifier) {
|
|
|
|
$notifyList = $folder->getNotifyList();
|
|
|
|
if($settings->_enableNotificationAppRev) {
|
|
|
|
/* Reviewers and approvers will be informed about the new document */
|
|
|
|
foreach($reviewers['i'] as $reviewerid) {
|
|
|
|
$notifyList['users'][] = $dms->getUser($reviewerid);
|
|
|
|
}
|
|
|
|
foreach($approvers['i'] as $approverid) {
|
|
|
|
$notifyList['users'][] = $dms->getUser($approverid);
|
|
|
|
}
|
|
|
|
foreach($reviewers['g'] as $reviewergrpid) {
|
|
|
|
$notifyList['groups'][] = $dms->getGroup($reviewergrpid);
|
|
|
|
}
|
|
|
|
foreach($approvers['g'] as $approvergrpid) {
|
|
|
|
$notifyList['groups'][] = $dms->getGroup($approvergrpid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$subject = "new_document_email_subject";
|
|
|
|
$message = "new_document_email_body";
|
|
|
|
$params = array();
|
|
|
|
$params['name'] = $name;
|
|
|
|
$params['folder_name'] = $folder->getName();
|
|
|
|
$params['folder_path'] = $folder->getFolderPathPlain();
|
|
|
|
$params['username'] = $user->getFullName();
|
2014-07-11 10:36:22 +00:00
|
|
|
$params['comment'] = '';
|
|
|
|
$params['version_comment'] = '';
|
2014-07-11 06:38:26 +00:00
|
|
|
$params['url'] = "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.ViewDocument.php?documentid=".$document->getID();
|
|
|
|
$params['sitename'] = $settings->_siteName;
|
|
|
|
$params['http_root'] = $settings->_httpRoot;
|
|
|
|
$notifier->toList($user, $notifyList["users"], $subject, $message, $params);
|
|
|
|
foreach ($notifyList["groups"] as $grp) {
|
|
|
|
$notifier->toGroup($user, $grp, $subject, $message, $params);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-07-11 09:14:27 +00:00
|
|
|
echo json_encode(array('success'=>true, 'message'=>getMLText('splash_document_added'), 'data'=>$document->getID()));
|
2014-07-11 06:38:26 +00:00
|
|
|
} else {
|
2015-10-22 11:36:23 +00:00
|
|
|
header('Content-Type: application/json');
|
2014-07-11 06:38:26 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_request_token'), 'data'=>''));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break; /* }}} */
|
|
|
|
|
2012-08-28 08:48:56 +00:00
|
|
|
}
|
2014-11-14 09:06:25 +00:00
|
|
|
add_log_line();
|
2012-08-28 08:48:56 +00:00
|
|
|
?>
|