2010-12-16 09:29:49 +00:00
|
|
|
<?php
|
|
|
|
// MyDMS. Document Management System
|
|
|
|
// Copyright (C) 2002-2005 Markus Westphal
|
2010-10-29 13:19:51 +00:00
|
|
|
// Copyright (C) 2006-2008 Malcolm Cowe
|
2010-12-16 09:29:49 +00:00
|
|
|
// Copyright (C) 2010 Matteo Lucarelli
|
|
|
|
//
|
|
|
|
// 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.
|
2010-10-29 13:19:51 +00:00
|
|
|
|
2013-02-14 11:10:53 +00:00
|
|
|
/* deprecated! use SeedDMS_Core_File::format_filesize() instead */
|
2010-12-16 09:29:49 +00:00
|
|
|
function formatted_size($size_bytes) { /* {{{ */
|
2010-10-29 13:19:51 +00:00
|
|
|
if ($size_bytes>1000000000) return number_format($size_bytes/1000000000,1,".","")." GBytes";
|
|
|
|
else if ($size_bytes>1000000) return number_format($size_bytes/1000000,1,".","")." MBytes";
|
|
|
|
else if ($size_bytes>1000) return number_format($size_bytes/1000,1,".","")." KBytes";
|
|
|
|
return number_format($size_bytes,0,"","")." Bytes";
|
2010-12-16 09:29:49 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
function getReadableDate($timestamp) {
|
2013-12-17 10:18:45 +00:00
|
|
|
return date("Y-m-d", $timestamp);
|
2010-10-29 13:19:51 +00:00
|
|
|
}
|
|
|
|
|
2010-12-16 09:29:49 +00:00
|
|
|
function getLongReadableDate($timestamp) {
|
2013-12-17 10:18:45 +00:00
|
|
|
return date("Y-m-d H:i:s", $timestamp);
|
2010-10-29 13:19:51 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 19:22:30 +00:00
|
|
|
/*
|
|
|
|
* Converts a date/time string into a timestamp
|
|
|
|
*
|
|
|
|
* @param $date string date in form Y-m-d H:i:s
|
|
|
|
* @return integer/boolean unix timestamp or false in case of an error
|
|
|
|
*/
|
|
|
|
function makeTsFromLongDate($date) { /* }}} */
|
|
|
|
$tmp = explode(' ', $date);
|
|
|
|
if(count($tmp) != 2)
|
|
|
|
return false;
|
|
|
|
$tarr = explode(':', $tmp[1]);
|
|
|
|
$darr = explode('-', $tmp[0]);
|
|
|
|
if(count($tarr) != 3 || count($darr) != 3)
|
|
|
|
return false;
|
|
|
|
$ts = mktime($tarr[0], $tarr[1], $tarr[2], $darr[1], $darr[2], $darr[0]);
|
|
|
|
return $ts;
|
|
|
|
} /* }}} */
|
|
|
|
|
2013-01-24 08:34:59 +00:00
|
|
|
function getReadableDuration($secs) {
|
|
|
|
$s = "";
|
|
|
|
foreach ( getReadableDurationArray($secs) as $k => $v ) {
|
|
|
|
if ( $v ) $s .= $v." ".($v==1? substr($k,0,-1) : $k).", ";
|
|
|
|
}
|
|
|
|
|
|
|
|
return substr($s, 0, -2);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getReadableDurationArray($secs) {
|
|
|
|
$units = array(
|
2014-11-14 19:22:30 +00:00
|
|
|
getMLText("weeks") => 7*24*3600,
|
|
|
|
getMLText("days") => 24*3600,
|
|
|
|
getMLText("hours") => 3600,
|
|
|
|
getMLText("minutes") => 60,
|
|
|
|
getMLText("seconds") => 1,
|
2013-01-24 08:34:59 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach ( $units as &$unit ) {
|
|
|
|
$quot = intval($secs / $unit);
|
|
|
|
$secs -= $quot * $unit;
|
|
|
|
$unit = $quot;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $units;
|
|
|
|
}
|
|
|
|
|
2010-12-16 09:29:49 +00:00
|
|
|
//
|
|
|
|
// The original string sanitizer, kept for reference.
|
|
|
|
//function sanitizeString($string) {
|
|
|
|
// $string = str_replace("'", "'", $string);
|
|
|
|
// $string = str_replace("--", "", $string);
|
|
|
|
// $string = str_replace("<", "<", $string);
|
|
|
|
// $string = str_replace(">", ">", $string);
|
|
|
|
// $string = str_replace("/*", "", $string);
|
|
|
|
// $string = str_replace("*/", "", $string);
|
|
|
|
// $string = str_replace("\"", """, $string);
|
|
|
|
//
|
|
|
|
// return $string;
|
|
|
|
//}
|
|
|
|
|
2012-12-19 10:08:06 +00:00
|
|
|
/* Deprecated, do not use anymore */
|
2010-12-16 09:29:49 +00:00
|
|
|
function sanitizeString($string) { /* {{{ */
|
|
|
|
|
|
|
|
$string = (string) $string;
|
|
|
|
if (get_magic_quotes_gpc()) {
|
|
|
|
$string = stripslashes($string);
|
|
|
|
}
|
|
|
|
|
2011-12-02 09:13:07 +00:00
|
|
|
// The following three are against sql injection. They are not
|
|
|
|
// needed anymore because strings are quoted propperly when saved into
|
|
|
|
// the database.
|
|
|
|
// $string = str_replace("\\", "\\\\", $string);
|
|
|
|
// $string = str_replace("--", "\-\-", $string);
|
|
|
|
// $string = str_replace(";", "\;", $string);
|
2010-12-16 09:29:49 +00:00
|
|
|
// Use HTML entities to represent the other characters that have special
|
|
|
|
// meaning in SQL. These can be easily converted back to ASCII / UTF-8
|
|
|
|
// with a decode function if need be.
|
|
|
|
$string = str_replace("&", "&", $string);
|
|
|
|
$string = str_replace("%", "%", $string); // percent
|
|
|
|
$string = str_replace("\"", """, $string); // double quote
|
|
|
|
$string = str_replace("/*", "/*", $string); // start of comment
|
|
|
|
$string = str_replace("*/", "*/", $string); // end of comment
|
|
|
|
$string = str_replace("<", "<", $string);
|
|
|
|
$string = str_replace(">", ">", $string);
|
|
|
|
$string = str_replace("=", "=", $string);
|
|
|
|
$string = str_replace(")", ")", $string);
|
|
|
|
$string = str_replace("(", "(", $string);
|
|
|
|
$string = str_replace("'", "'", $string);
|
|
|
|
$string = str_replace("+", "+", $string);
|
|
|
|
|
|
|
|
return trim($string);
|
|
|
|
} /* }}} */
|
|
|
|
|
2013-02-20 08:46:08 +00:00
|
|
|
/* Deprecated, do not use anymore, but keep it for upgrading
|
|
|
|
* older versions
|
|
|
|
*/
|
2010-12-16 09:29:49 +00:00
|
|
|
function mydmsDecodeString($string) { /* {{{ */
|
|
|
|
|
|
|
|
$string = (string)$string;
|
|
|
|
|
|
|
|
$string = str_replace("&", "&", $string);
|
|
|
|
$string = str_replace("%", "%", $string); // percent
|
|
|
|
$string = str_replace(""", "\"", $string); // double quote
|
|
|
|
$string = str_replace("/*", "/*", $string); // start of comment
|
|
|
|
$string = str_replace("*/", "*/", $string); // end of comment
|
|
|
|
$string = str_replace("<", "<", $string);
|
|
|
|
$string = str_replace(">", ">", $string);
|
|
|
|
$string = str_replace("=", "=", $string);
|
|
|
|
$string = str_replace(")", ")", $string);
|
|
|
|
$string = str_replace("(", "(", $string);
|
|
|
|
$string = str_replace("'", "'", $string);
|
|
|
|
$string = str_replace("+", "+", $string);
|
|
|
|
|
|
|
|
return $string;
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
function createVersionigFile($document) { /* {{{ */
|
|
|
|
global $settings, $dms;
|
2010-10-29 13:19:51 +00:00
|
|
|
|
|
|
|
// if directory has been removed recreate it
|
2011-01-28 07:41:26 +00:00
|
|
|
if (!file_exists($dms->contentDir . $document->getDir()))
|
2013-02-14 11:10:53 +00:00
|
|
|
if (!SeedDMS_Core_File::makeDir($dms->contentDir . $document->getDir())) return false;
|
2010-10-29 13:19:51 +00:00
|
|
|
|
2011-01-28 07:41:26 +00:00
|
|
|
$handle = fopen($dms->contentDir . $document->getDir() .$settings-> _versioningFileName , "wb");
|
2010-10-29 13:19:51 +00:00
|
|
|
|
|
|
|
if (is_bool($handle)&&!$handle) return false;
|
|
|
|
|
2014-02-21 10:05:49 +00:00
|
|
|
$tmp = $document->getName()." (ID ".$document->getID().")\n\n";
|
2010-10-29 13:19:51 +00:00
|
|
|
fwrite($handle, $tmp);
|
|
|
|
|
|
|
|
$owner = $document->getOwner();
|
|
|
|
$tmp = getMLText("owner")." = ".$owner->getFullName()." <".$owner->getEmail().">\n";
|
|
|
|
fwrite($handle, $tmp);
|
|
|
|
|
2010-12-16 09:29:49 +00:00
|
|
|
$tmp = getMLText("creation_date")." = ".getLongReadableDate($document->getDate())."\n";
|
2010-10-29 13:19:51 +00:00
|
|
|
fwrite($handle, $tmp);
|
|
|
|
|
|
|
|
$latestContent = $document->getLatestContent();
|
|
|
|
$tmp = "\n### ".getMLText("current_version")." ###\n\n";
|
|
|
|
fwrite($handle, $tmp);
|
|
|
|
|
|
|
|
$tmp = getMLText("version")." = ".$latestContent->getVersion()."\n";
|
|
|
|
fwrite($handle, $tmp);
|
2010-12-16 09:29:49 +00:00
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
$tmp = getMLText("file")." = ".$latestContent->getOriginalFileName()." (".$latestContent->getMimeType().")\n";
|
|
|
|
fwrite($handle, $tmp);
|
2010-12-16 09:29:49 +00:00
|
|
|
|
2011-12-05 14:52:05 +00:00
|
|
|
$tmp = getMLText("comment")." = ". $latestContent->getComment()."\n";
|
2010-10-29 13:19:51 +00:00
|
|
|
fwrite($handle, $tmp);
|
|
|
|
|
2010-12-16 09:29:49 +00:00
|
|
|
$status = $latestContent->getStatus();
|
2010-10-29 13:19:51 +00:00
|
|
|
$tmp = getMLText("status")." = ".getOverallStatusText($status["status"])."\n";
|
|
|
|
fwrite($handle, $tmp);
|
|
|
|
|
|
|
|
$reviewStatus = $latestContent->getReviewStatus();
|
|
|
|
$tmp = "\n### ".getMLText("reviewers")." ###\n";
|
|
|
|
fwrite($handle, $tmp);
|
|
|
|
|
|
|
|
foreach ($reviewStatus as $r) {
|
|
|
|
|
2010-12-16 09:29:49 +00:00
|
|
|
switch ($r["type"]) {
|
|
|
|
case 0: // Reviewer is an individual.
|
|
|
|
$required = $dms->getUser($r["required"]);
|
|
|
|
if (!is_object($required)) $reqName = getMLText("unknown_user")." = ".$r["required"];
|
|
|
|
else $reqName = getMLText("user")." = ".$required->getFullName();
|
|
|
|
break;
|
|
|
|
case 1: // Reviewer is a group.
|
|
|
|
$required = $dms->getGroup($r["required"]);
|
|
|
|
if (!is_object($required)) $reqName = getMLText("unknown_group")." = ".$r["required"];
|
|
|
|
else $reqName = getMLText("group")." = ".$required->getName();
|
2010-10-29 13:19:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tmp = "\n".$reqName."\n";
|
|
|
|
fwrite($handle, $tmp);
|
2010-12-16 09:29:49 +00:00
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
$tmp = getMLText("status")." = ".getReviewStatusText($r["status"])."\n";
|
|
|
|
fwrite($handle, $tmp);
|
2010-12-16 09:29:49 +00:00
|
|
|
|
2011-12-05 14:52:05 +00:00
|
|
|
$tmp = getMLText("comment")." = ". $r["comment"]."\n";
|
2010-10-29 13:19:51 +00:00
|
|
|
fwrite($handle, $tmp);
|
2010-12-16 09:29:49 +00:00
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
$tmp = getMLText("last_update")." = ".$r["date"]."\n";
|
|
|
|
fwrite($handle, $tmp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-12-16 09:29:49 +00:00
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
$approvalStatus = $latestContent->getApprovalStatus();
|
|
|
|
$tmp = "\n### ".getMLText("approvers")." ###\n";
|
|
|
|
fwrite($handle, $tmp);
|
|
|
|
|
|
|
|
foreach ($approvalStatus as $r) {
|
|
|
|
|
2010-12-16 09:29:49 +00:00
|
|
|
switch ($r["type"]) {
|
|
|
|
case 0: // Reviewer is an individual.
|
|
|
|
$required = $dms->getUser($r["required"]);
|
|
|
|
if (!is_object($required)) $reqName = getMLText("unknown_user")." = ".$r["required"];
|
|
|
|
else $reqName = getMLText("user")." = ".$required->getFullName();
|
|
|
|
break;
|
|
|
|
case 1: // Reviewer is a group.
|
|
|
|
$required = $dms->getGroup($r["required"]);
|
|
|
|
if (!is_object($required)) $reqName = getMLText("unknown_group")." = ".$r["required"];
|
|
|
|
else $reqName = getMLText("group")." = ".$required->getName();
|
2010-10-29 13:19:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tmp = "\n".$reqName."\n";
|
|
|
|
fwrite($handle, $tmp);
|
2010-12-16 09:29:49 +00:00
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
$tmp = getMLText("status")." = ".getApprovalStatusText($r["status"])."\n";
|
|
|
|
fwrite($handle, $tmp);
|
2010-12-16 09:29:49 +00:00
|
|
|
|
2011-12-05 14:52:05 +00:00
|
|
|
$tmp = getMLText("comment")." = ". $r["comment"]."\n";
|
2010-10-29 13:19:51 +00:00
|
|
|
fwrite($handle, $tmp);
|
2010-12-16 09:29:49 +00:00
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
$tmp = getMLText("last_update")." = ".$r["date"]."\n";
|
|
|
|
fwrite($handle, $tmp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$versions = $document->getContent();
|
|
|
|
$tmp = "\n### ".getMLText("previous_versions")." ###\n";
|
|
|
|
fwrite($handle, $tmp);
|
2010-12-16 09:29:49 +00:00
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
for ($i = count($versions)-2; $i >= 0; $i--){
|
|
|
|
|
2010-12-16 09:29:49 +00:00
|
|
|
$version = $versions[$i];
|
2010-10-29 13:19:51 +00:00
|
|
|
$status = $version->getStatus();
|
|
|
|
|
|
|
|
$tmp = "\n".getMLText("version")." = ".$version->getVersion()."\n";
|
|
|
|
fwrite($handle, $tmp);
|
2010-12-16 09:29:49 +00:00
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
$tmp = getMLText("file")." = ".$version->getOriginalFileName()." (".$version->getMimeType().")\n";
|
|
|
|
fwrite($handle, $tmp);
|
2010-12-16 09:29:49 +00:00
|
|
|
|
2011-12-05 14:52:05 +00:00
|
|
|
$tmp = getMLText("comment")." = ". $version->getComment()."\n";
|
2010-10-29 13:19:51 +00:00
|
|
|
fwrite($handle, $tmp);
|
|
|
|
|
2010-12-16 09:29:49 +00:00
|
|
|
$status = $latestContent->getStatus();
|
2010-10-29 13:19:51 +00:00
|
|
|
$tmp = getMLText("status")." = ".getOverallStatusText($status["status"])."\n";
|
|
|
|
fwrite($handle, $tmp);
|
|
|
|
|
|
|
|
}
|
2010-12-16 09:29:49 +00:00
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
fclose($handle);
|
|
|
|
return true;
|
2010-12-16 09:29:49 +00:00
|
|
|
} /* }}} */
|
2010-10-29 13:19:51 +00:00
|
|
|
|
2014-05-16 10:48:37 +00:00
|
|
|
/**
|
|
|
|
* Calculate disk space of file or directory
|
|
|
|
*
|
|
|
|
* original funcion by shalless at rubix dot net dot au (php.net)
|
|
|
|
* stat() replace by filesize() to make it work on all platforms.
|
|
|
|
*
|
|
|
|
* @param string $dir directory or filename
|
|
|
|
* @return integer number of bytes
|
|
|
|
*/
|
2012-12-13 21:32:05 +00:00
|
|
|
function dskspace($dir) { /* {{{ */
|
2014-05-16 10:48:37 +00:00
|
|
|
$space = 0;
|
|
|
|
if(is_file($dir)) {
|
|
|
|
$space = filesize($dir);
|
|
|
|
} elseif (is_dir($dir)) {
|
|
|
|
$dh = opendir($dir);
|
|
|
|
while (($file = readdir($dh)) !== false)
|
|
|
|
if ($file != "." and $file != "..")
|
|
|
|
$space += dskspace($dir."/".$file);
|
|
|
|
closedir($dh);
|
|
|
|
}
|
|
|
|
return $space;
|
2012-12-13 21:32:05 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
2010-12-16 09:29:49 +00:00
|
|
|
function add_log_line($msg="") { /* {{{ */
|
2011-05-16 15:44:59 +00:00
|
|
|
global $logger, $user;
|
|
|
|
|
|
|
|
if(!$logger) return;
|
2013-02-07 16:59:41 +00:00
|
|
|
|
|
|
|
if($user)
|
|
|
|
$logger->log($user->getLogin()." (".$_SERVER['REMOTE_ADDR'].") ".basename($_SERVER["REQUEST_URI"], ".php").$msg);
|
|
|
|
else
|
|
|
|
$logger->log("-- (".$_SERVER['REMOTE_ADDR'].") ".basename($_SERVER["REQUEST_URI"], ".php").$msg);
|
2011-05-16 15:44:59 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
function _add_log_line($msg="") { /* {{{ */
|
2010-10-29 13:19:51 +00:00
|
|
|
global $settings,$user;
|
|
|
|
|
|
|
|
if ($settings->_logFileEnable!=TRUE) return;
|
|
|
|
|
|
|
|
if ($settings->_logFileRotation=="h") $logname=date("YmdH", time());
|
|
|
|
else if ($settings->_logFileRotation=="d") $logname=date("Ymd", time());
|
|
|
|
else $logname=date("Ym", time());
|
|
|
|
|
|
|
|
if($h = fopen($settings->_contentDir.$logname.".log", "a")) {
|
|
|
|
fwrite($h,date("Y/m/d H:i", time())." ".$user->getLogin()." (".$_SERVER['REMOTE_ADDR'].") ".basename($_SERVER["REQUEST_URI"], ".php").$msg."\n");
|
|
|
|
fclose($h);
|
|
|
|
}
|
2010-12-16 09:29:49 +00:00
|
|
|
} /* }}} */
|
2010-10-29 13:19:51 +00:00
|
|
|
|
2012-12-13 21:32:05 +00:00
|
|
|
function getFolderPathHTML($folder, $tagAll=false, $document=null) { /* {{{ */
|
2010-12-22 08:50:57 +00:00
|
|
|
$path = $folder->getPath();
|
|
|
|
$txtpath = "";
|
|
|
|
for ($i = 0; $i < count($path); $i++) {
|
|
|
|
if ($i +1 < count($path)) {
|
|
|
|
$txtpath .= "<a href=\"../out/out.ViewFolder.php?folderid=".$path[$i]->getID()."&showtree=".showtree()."\">".
|
2011-12-03 11:08:26 +00:00
|
|
|
htmlspecialchars($path[$i]->getName())."</a> / ";
|
2010-12-22 08:50:57 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$txtpath .= ($tagAll ? "<a href=\"../out/out.ViewFolder.php?folderid=".$path[$i]->getID()."&showtree=".showtree()."\">".
|
2011-12-03 11:08:26 +00:00
|
|
|
htmlspecialchars($path[$i]->getName())."</a>" : htmlspecialchars($path[$i]->getName()));
|
2010-12-22 08:50:57 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-13 21:32:05 +00:00
|
|
|
if($document)
|
|
|
|
$txtpath .= " / <a href=\"../out/out.ViewDocument.php?documentid=".$document->getId()."\">".htmlspecialchars($document->getName())."</a>";
|
|
|
|
|
2010-12-22 08:50:57 +00:00
|
|
|
return $txtpath;
|
|
|
|
} /* }}} */
|
|
|
|
|
2010-12-16 09:29:49 +00:00
|
|
|
function showtree() { /* {{{ */
|
2010-10-29 13:19:51 +00:00
|
|
|
global $settings;
|
|
|
|
|
2012-08-28 06:39:15 +00:00
|
|
|
if (isset($_GET["showtree"])) return intval($_GET["showtree"]);
|
2010-11-12 22:47:41 +00:00
|
|
|
else if ($settings->_enableFolderTree==0) return 0;
|
2010-10-29 13:19:51 +00:00
|
|
|
|
|
|
|
return 1;
|
2010-12-16 09:29:49 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
2012-08-29 20:49:42 +00:00
|
|
|
/**
|
|
|
|
* Create a unique key which is used for form validation to prevent
|
|
|
|
* CSRF attacks. The key is added to a any form that has to be secured
|
|
|
|
* as a hidden field. Once the form is submitted the key is compared
|
|
|
|
* to the current key in the session and the request is only executed
|
|
|
|
* if both are equal. The key is derived from the session id, a configurable
|
|
|
|
* encryption key and form identifierer.
|
|
|
|
*
|
|
|
|
* @param string $formid individual form identifier
|
|
|
|
* @return string session key
|
|
|
|
*/
|
|
|
|
function createFormKey($formid='') { /* {{{ */
|
|
|
|
global $settings, $session;
|
|
|
|
|
|
|
|
if($id = $session->getId()) {
|
|
|
|
return md5($id.$settings->_encryptionKey.$formid);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a hidden field with the name 'formtoken' and set its value
|
|
|
|
* to the key returned by createFormKey()
|
|
|
|
*
|
|
|
|
* @param string $formid individual form identifier
|
|
|
|
* @return string input field for html formular
|
|
|
|
*/
|
|
|
|
function createHiddenFieldWithKey($formid='') { /* {{{ */
|
|
|
|
return '<input type="hidden" name="formtoken" value="'.createFormKey($formid).'" />';
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
/**
|
2012-08-31 07:43:43 +00:00
|
|
|
* Check if the form key in the POST or GET request variable 'formtoken'
|
|
|
|
* has the value of key returned by createFormKey(). Request to modify
|
|
|
|
* data in the DMS should always use POST because it is harder to run
|
|
|
|
* CSRF attacks using POST than GET.
|
2012-08-29 20:49:42 +00:00
|
|
|
*
|
|
|
|
* @param string $formid individual form identifier
|
2012-08-31 07:43:43 +00:00
|
|
|
* @param string $method defines if the form data is pass via GET or
|
|
|
|
* POST (default)
|
2012-08-29 20:49:42 +00:00
|
|
|
* @return boolean true if key matches otherwise false
|
|
|
|
*/
|
2012-08-31 07:43:43 +00:00
|
|
|
function checkFormKey($formid='', $method='POST') { /* {{{ */
|
|
|
|
switch($method) {
|
|
|
|
case 'GET':
|
|
|
|
if(isset($_GET['formtoken']) && $_GET['formtoken'] == createFormKey($formid))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if(isset($_POST['formtoken']) && $_POST['formtoken'] == createFormKey($formid))
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-29 20:49:42 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
} /* }}} */
|
2012-12-19 10:08:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check disk usage of currently logged in user
|
|
|
|
*
|
|
|
|
* @return boolean/integer true if no quota is set, number of bytes until
|
|
|
|
* quota is reached. Negative values indicate a disk usage above quota.
|
|
|
|
*/
|
2014-05-20 04:31:12 +00:00
|
|
|
function checkQuota($user) { /* {{{ */
|
|
|
|
global $settings, $dms;
|
|
|
|
|
|
|
|
/* check if quota is turn off system wide */
|
|
|
|
if($settings->_quota == 0)
|
|
|
|
return true;
|
2012-12-19 10:08:06 +00:00
|
|
|
|
|
|
|
$quota = 0;
|
|
|
|
$uquota = $user->getQuota();
|
|
|
|
if($uquota > 0)
|
|
|
|
$quota = $uquota;
|
2014-05-20 04:31:12 +00:00
|
|
|
elseif($settings->_quota > 0) {
|
2012-12-19 10:08:06 +00:00
|
|
|
$quota = $settings->_quota;
|
2014-05-20 04:31:12 +00:00
|
|
|
}
|
2012-12-19 10:08:06 +00:00
|
|
|
|
|
|
|
if($quota == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return ($quota - $user->getUsedDiskSpace());
|
|
|
|
} /* }}} */
|
2010-12-16 09:29:49 +00:00
|
|
|
?>
|