summaryrefslogtreecommitdiff
path: root/backend
authorJosh <jokajak@gmail.com>2011-10-05 20:40:29 (UTC)
committer Josh <jokajak@gmail.com>2011-10-06 01:58:00 (UTC)
commita26b219b6f4f3fee727d9b23d8cd374f6b32a4fa (patch) (side-by-side diff)
tree3ca0b96e843f5820f0bee7dede1847b014bba1e6 /backend
parent6ba274c79e60e417132b260bd0117c5a68121387 (diff)
downloadclipperz-a26b219b6f4f3fee727d9b23d8cd374f6b32a4fa.zip
clipperz-a26b219b6f4f3fee727d9b23d8cd374f6b32a4fa.tar.gz
clipperz-a26b219b6f4f3fee727d9b23d8cd374f6b32a4fa.tar.bz2
Fix timestamps on records
- update the access and update date when a record is saved - set the creation date when a record is created
Diffstat (limited to 'backend') (more/less context) (ignore whitespace changes)
-rw-r--r--backend/php/src/index.php7
-rw-r--r--backend/php/src/objects/class.record.php13
-rw-r--r--backend/php/src/objects/class.recordversion.php4
3 files changed, 19 insertions, 5 deletions
diff --git a/backend/php/src/index.php b/backend/php/src/index.php
index 58c10a9..3d23e7a 100644
--- a/backend/php/src/index.php
+++ b/backend/php/src/index.php
@@ -186,384 +186,391 @@ function resetOTP(&$otp, $status) {
function fixOTPStatusTable() {
$otpStatus = new onetimepasswordstatus();
$otpStatusList = $otpStatus->GetList();
if (count($otpStatusList) != 4) {
$otpStatus->DeleteList();
$otpStatus->code = "ACTIVE"; $otpStatus->name = "Active"; $otpStatus->description = "Active"; $otpStatus->SaveNew();
$otpStatus->code = "REQUESTED"; $otpStatus->name = "Requested"; $otpStatus->description = "Requested"; $otpStatus->SaveNew();
$otpStatus->code = "USED"; $otpStatus->name = "Used"; $otpStatus->description = "Used"; $otpStatus->SaveNew();
$otpStatus->code = "DISABLED"; $otpStatus->name = "Disabled"; $otpStatus->description = "Disabled"; $otpStatus->SaveNew();
}
}
//-----------------------------------------------------------------------------
function arrayContainsValue($array, $value) {
$object = NULL;
for ($i=0; $i<count($array); $i++) {
if ($array[$i] == $value) {
$object = $value;
}
}
return !is_null($object);
}
//-----------------------------------------------------------------------------
$result = Array();
session_start();
$method = $_POST['method'];
if (get_magic_quotes_gpc()) {
$parameters = json_decode(stripslashes($_POST['parameters']), true);
} else {
$parameters = json_decode($_POST['parameters'], true);
}
$parameters = $parameters["parameters"];
switch($method) {
case "registration":
error_log("registration");
$message = $parameters["message"];
if ($message == "completeRegistration") {
$user = new user();
updateUserCredentials($parameters["credentials"], $user);
updateUserData($parameters["user"], $user);
$user->Save();
$result["lock"] = $user->lock;
$result["result"] = "done";
}
break;
case "handshake":
error_log("handshake");
$srp_g = "2";
$srp_n = base2dec("115b8b692e0e045692cf280b436735c77a5a9e8a9e7ed56c965f87db5b2a2ece3", 16);
$message = $parameters["message"];
//=============================================================
if ($message == "connect") {
$user= new user();
$_SESSION["C"] = $parameters["parameters"]["C"];
$_SESSION["A"] = $parameters["parameters"]["A"];
$userList = $user->GetList(array(array("username", "=", $_SESSION["C"])));
if (count($userList) == 1) {
$currentUser = $userList[ 0 ];
if (array_key_exists("otpId", $_SESSION)) {
$otp = new onetimepassword();
$otp = $otp->Get($_SESSION["otpId"]);
if ($otp->GetUser()->userId != $currentUser->userId) {
throw new Exception("User missmatch between the current session and 'One Time Password' user");
} else if ($otp->GetOnetimepasswordstatus()->code != "REQUESTED") {
throw new Exception("Tring to use an 'One Time Password' in the wrong state");
}
resetOTP($otp, "USED");
$result["oneTimePassword"] = $otp->reference;
}
$_SESSION["s"] = $currentUser->srp_s;
$_SESSION["v"] = $currentUser->srp_v;
$_SESSION["userId"] = $currentUser->userId;
} else {
$_SESSION["s"] = "112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00";
$_SESSION["v"] = "112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00";
}
$_SESSION["b"] = clipperz_randomSeed();
// $_SESSION["b"] = "5761e6c84d22ea3c5649de01702d60f674ccfe79238540eb34c61cd020230c53";
$_SESSION["B"] = dec2base(bcadd(base2dec($_SESSION["v"], 16), bcpowmod($srp_g, base2dec($_SESSION["b"], 16), $srp_n)), 16);
$result["s"] = $_SESSION["s"];
$result["B"] = $_SESSION["B"];
//=============================================================
} else if ($message == "credentialCheck") {
error_log("credentialCheck");
$u = clipperz_hash(base2dec($_SESSION["B"],16));
$A = base2dec($_SESSION["A"], 16);
$S = bcpowmod(bcmul($A, bcpowmod(base2dec($_SESSION["v"], 16), base2dec($u, 16), $srp_n)), base2dec($_SESSION["b"], 16), $srp_n);
$K = clipperz_hash($S);
$M1 = clipperz_hash($A.base2dec($_SESSION["B"],16).$K);
//$result["B"] = $_SESSION["B"];
//$result["u"] = $u;
//$result["A"] = $A;
//$result["S"] = $S;
//$result["K"] = $K;
//$result["M1"] = $M1;
//$result["_M1"] = $parameters["parameters"]["M1"];
if ($M1 == $parameters["parameters"]["M1"]) {
$_SESSION["K"] = $K;
$M2 = clipperz_hash($A.$M1.$K);
$result["M2"] = $M2;
$result["connectionId"] = "";
$result["loginInfo"] = array();
$result["loginInfo"]["latest"] = array();
$result["loginInfo"]["current"] = array();
$result["offlineCopyNeeded"] = "false";
$result["lock"] = "----";
} else {
$result["error"] = "?";
}
//=============================================================
} else if ($message == "oneTimePassword") {
error_log("oneTimePassword");
//{
// "message":"oneTimePassword",
// "version":"0.2",
// "parameters":{
// "oneTimePasswordKey":"06dfa7f428081f8b2af98b0895e14e18af90b0ef2ff32828e55cc2ac6b24d29b",
// "oneTimePasswordKeyChecksum":"60bcba3f72e56f6bb3f0ff88509b9a0e5ec730dfa71daa4c1e892dbd1b0c360d"
// }
//}
$otp = new onetimepassword();
$otpList = $otp->GetList(array(array("key", "=", $parameters["parameters"]["oneTimePasswordKey"])));
if (count($otpList) == 1) {
$currentOtp = $otpList[0];
if ($currentOtp->GetOnetimepasswordstatus()->code == "ACTIVE") {
if ($currentOtp->key_checksum == $parameters["parameters"]["oneTimePasswordKeyChecksum"]) {
$_SESSION["userId"] = $currentOtp->GetUser()->userId;
$_SESSION["otpId"] = $currentOtp->onetimepasswordId;
$result["data"] = $currentOtp->data;
$result["version"] = $currentOtp->version;
resetOTP($currentOtp, "REQUESTED");
} else {
resetOTP($currentOtp, "DISABLED");
throw new Exception("The requested One Time Password has been disabled, due to a wrong keyChecksum");
}
} else {
throw new Exception("The requested One Time Password was not active");
}
} else {
throw new Exception("The requested One Time Password has not been found");
}
//=============================================================
}
break;
case "message":
error_log("message");
if ($parameters["srpSharedSecret"] == $_SESSION["K"]) {
$message = $parameters["message"];
//=============================================================
if ($message == "getUserDetails") {
//{"message":"getUserDetails", "srpSharedSecret":"f18e5cf7c3a83b67d4db9444af813ee48c13daf4f8f6635397d593e52ba89a08", "parameters":{}}
$user = new user();
$user = $user->Get($_SESSION["userId"]);
$result["header"] = $user->header;
+ $records = $user->GetRecordList();
+ foreach ($records as $record)
+ {
+ $recordStats["updateDate"] = $record->update_date;
+ $recordsStats[$record->reference] = $recordStats;
+ }
+ $result["recordsStats"] = $recordsStats;
$result["statistics"] = $user->statistics;
$result["version"] = $user->version;
//=============================================================
} else if ($message == "addNewRecords") {
/*
//{
// "message":"addNewRecords",
// "srpSharedSecret":"b58fdf62acebbcb67f63d28c0437f166069f45690c648cd4376a792ae7a325f7",
// "parameters":{
// "records":[
// {
// "record":{
// "reference":"fda703707fee1fff42443124cd0e705f5bea0ac601758d81b2e832705339a610",
// "data":"OBSGtcb6blXq/xaYG.....4EqlQqgAvITN",
// "version":"0.3"
// },
// "currentRecordVersion":{
// "reference":"83ad301525c18f2afd72b6ac82c0a713382e1ef70ac69935ca7e2869dd4ff980",
// "recordReference":"fda703707fee1fff42443124cd0e705f5bea0ac601758d81b2e832705339a610",
// "data":"NXJ5jiZhkd0CMiwwntAq....1TjjF+SGfE=",
// "version":"0.3",
// "previousVersion":"3e174a86afc322271d8af28bc062b0f1bfd7344fad01212cd08b2757c4b199c4",
// "previousVersionKey":"kozaaGCzXWr71LbOKu6Z3nz520V..5U85tSBvb+u44twttv54Kw=="
// }
// }
// ],
// "user":{
// "header":"{\"reco...ersion\":\"0.1\"}",
// "statistics":"rKI6nR6iqggygQJ3SQ58bFUX",
// "version":"0.3",
// "lock":"----"
// }
// }
//}
*/
$user = new user();
$record = new record();
$recordVersion = new recordversion();
$user = $user->Get($_SESSION["userId"]);
updateUserData($parameters["parameters"]["user"], $user);
$recordParameterList = $parameters["parameters"]["records"];
$c = count($recordParameterList);
for ($i=0; $i<$c; $i++) {
updateRecordData($recordParameterList[$i], $record, $recordVersion);
$record->SaveNew();
$recordVersion->SaveNew();
$record->AddRecordversion($recordVersion);
$user->AddRecord($record);
$record->Save();
$recordVersion->Save();
}
$user->Save();
$result["lock"] = $user->lock;
$result["result"] = "done";
//=============================================================
} else if ($message == "getRecordDetail") {
//{
// "message":"getRecordDetail",
// "srpSharedSecret":"4c00dcb66a9f2aea41a87e4707c526874e2eb29cc72d2c7086837e53d6bf2dfe",
// "parameters":{
// "reference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50"
// }
//}
//
// result = {
// currentVersion:{
// reference:"88943d709c3ea2442d4f58eaaec6409276037e5a37e0a6d167b9dad9e947e854",
// accessDate:"Wed, 13 February 2008 14:25:12 UTC",
// creationDate:"Tue, 17 April 2007 17:17:52 UTC",
// version:"0.2",
// data:"xI3WXddQLFtL......EGyKnnAVik",
// updateDate:"Tue, 17 April 2007 17:17:52 UTC",
// header:"####"
// }
// reference:"13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551",
// oldestUsedEncryptedVersion:"0.2",
// accessDate:"Wed, 13 February 2008 14:25:12 UTC",
// creationDate:"Wed, 14 March 2007 13:53:11 UTC",
// version:"0.2",
// updatedDate:"Tue, 17 April 2007 17:17:52 UTC",
// data:"0/BjzyY6jeh71h...pAw2++NEyylGhMC5C5f5m8pBApYziN84s4O3JQ3khW/1UttQl4="
// }
$record = new record();
$recordList = $record->GetList(array(array("reference", "=", $parameters["parameters"]["reference"])));
$currentRecord = $recordList[0];
$currentRecordVersions = $currentRecord->GetRecordversionList();
$currentVersion = $currentRecordVersions[0];
$result["currentVersion"] = array();
$result["currentVersion"]["reference"] = $currentVersion->reference;
$result["currentVersion"]["data"] = $currentVersion->data;
$result["currentVersion"]["header"] = $currentVersion->header;
$result["currentVersion"]["version"] = $currentVersion->version;
$result["currentVersion"]["creationDate"] = $currentVersion->creation_date;
$result["currentVersion"]["updateDate"] = $currentVersion->update_date;
$result["currentVersion"]["accessDate"] = $currentVersion->access_date;
$result["reference"] = $currentRecord->reference;
$result["data"] = $currentRecord->data;
$result["version"] = $currentRecord->version;
$result["creationDate"] = $currentRecord->creation_date;
$result["updateDate"] = $currentRecord->update_date;
$result["accessDate"] = $currentRecord->access_date;
$result["oldestUsedEncryptedVersion"] = "---";
//=============================================================
} else if ($message == "updateData") {
//{
// "message":"updateData",
// "srpSharedSecret":"4e4aadb1d64513ec4dd42f5e8d5b2d4363de75e4424b6bcf178c9d6a246356c5",
// "parameters":{
// "records":[
// {
// "record":{
// "reference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50",
// "data":"8hgR0Z+JDrUa812polDJ....JnZUKXNEqKI",
// "version":"0.3"
// },
// "currentRecordVersion":{
// "reference":"b1d82aeb9a0c4f6584bea68ba80839f43dd6ede79791549e29a1860554b144ee",
// "recordReference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50",
// "data":"2d/UgKxxV+kBPV9GRUE.....VGonDoW0tqefxOJo=",
// "version":"0.3",
// "previousVersion":"55904195249037394316d3be3f5e78f08073170103bf0e7ab49a911c159cb0be",
// "previousVersionKey":"YWiaZeMIVHaIl96OWW+2e8....6d6nHbn6cr2NA/dbQRuC2w=="
// }
// }
// ],
// "user":{
// "header":"{\"rec.....sion\":\"0.1\"}",
// "statistics":"tt3uU9hWBy8rNnMckgCnxMJh",
// "version":"0.3",
// "lock":"----"
// }
// }
//}
$user = new user();
$user = $user->Get($_SESSION["userId"]);
updateUserData($parameters["parameters"]["user"], $user);
$user->Save();
$recordParameterList = $parameters["parameters"]["records"];
$c = count($recordParameterList);
for ($i=0; $i<$c; $i++) {
$recordList = $user->GetRecordList(array(array("reference", "=", $recordParameterList[$i]["record"]["reference"])));
$currentRecord = $recordList[0];
$currentRecordVersions = $currentRecord->GetRecordversionList();
$currentVersion = $currentRecordVersions[0];
updateRecordData($recordParameterList[$i], $currentRecord, $currentVersion);
$currentRecord->Save();
$currentVersion->Save();
}
$result["lock"] = $user->lock;
$result["result"] = "done";
//=============================================================
} else if ($message == "deleteRecords") {
//{
// "message":"deleteRecords",
// "srpSharedSecret":"4a64982f7ee366954ec50b9efea62a902a097ef111410c2aa7c4d5343bd1cdd1",
// "parameters":{
// "recordReferences":["46494c81d10b80ab190d41e6806ef63869cfcc7a0ab8fe98cc3f93de4729bb9a"],
// "user":{
// "header":"{\"rec...rsion\":\"0.1\"}",
// "statistics":"44kOOda0xYZjbcugJBdagBQx",
// "version":"0.3",
// "lock":"----"
// }
// }
//}
$user = new user();
$user = $user->Get($_SESSION["userId"]);
$recordReferenceList = $parameters["parameters"]["recordReferences"];
$recordList = array();
$c = count($recordReferenceList);
diff --git a/backend/php/src/objects/class.record.php b/backend/php/src/objects/class.record.php
index a269e75..37a9702 100644
--- a/backend/php/src/objects/class.record.php
+++ b/backend/php/src/objects/class.record.php
@@ -1,436 +1,441 @@
<?php
/*
This SQL query will create the table to store your object.
CREATE TABLE `record` (
`recordid` int(11) NOT NULL auto_increment,
`userid` int(11) NOT NULL,
`reference` VARCHAR(255) NOT NULL,
`data` LONGTEXT NOT NULL,
`version` VARCHAR(255) NOT NULL,
`creation_date` TIMESTAMP NOT NULL,
- `update_date` TIMESTAMP NOT NULL,
+ `update_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`access_date` TIMESTAMP NOT NULL, INDEX(`userid`), PRIMARY KEY (`recordid`)) ENGINE=MyISAM;
*/
/**
* <b>record</b> class with integrated CRUD methods.
* @author Php Object Generator
* @version POG 3.0e / PHP5.1 MYSQL
* @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql
* @copyright Free for personal & commercial use. (Offered under the BSD license)
* @link http://www.phpobjectgenerator.com/?language=php5.1&wrapper=pdo&pdoDriver=mysql&objectName=record&attributeList=array+%28%0A++0+%3D%3E+%27user%27%2C%0A++1+%3D%3E+%27recordversion%27%2C%0A++2+%3D%3E+%27reference%27%2C%0A++3+%3D%3E+%27data%27%2C%0A++4+%3D%3E+%27version%27%2C%0A++5+%3D%3E+%27creation_date%27%2C%0A++6+%3D%3E+%27update_date%27%2C%0A++7+%3D%3E+%27access_date%27%2C%0A%29&typeList=array%2B%2528%250A%2B%2B0%2B%253D%253E%2B%2527BELONGSTO%2527%252C%250A%2B%2B1%2B%253D%253E%2B%2527HASMANY%2527%252C%250A%2B%2B2%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B3%2B%253D%253E%2B%2527LONGTEXT%2527%252C%250A%2B%2B4%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B5%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2B%2B6%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2B%2B7%2B%253D%253E%2B%2527TIMESTAMP%2527%252C%250A%2529
*/
include_once('class.pog_base.php');
class record extends POG_Base
{
public $recordId = '';
/**
* @var INT(11)
*/
public $userId;
/**
* @var private array of recordversion objects
*/
private $_recordversionList = array();
/**
* @var VARCHAR(255)
*/
public $reference;
/**
* @var LONGTEXT
*/
public $data;
/**
* @var VARCHAR(255)
*/
public $version;
/**
* @var TIMESTAMP
*/
public $creation_date;
/**
* @var TIMESTAMP
*/
public $update_date;
/**
* @var TIMESTAMP
*/
public $access_date;
public $pog_attribute_type = array(
"recordId" => array('db_attributes' => array("NUMERIC", "INT")),
"user" => array('db_attributes' => array("OBJECT", "BELONGSTO")),
"recordversion" => array('db_attributes' => array("OBJECT", "HASMANY")),
"reference" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
"data" => array('db_attributes' => array("TEXT", "LONGTEXT")),
"version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
"creation_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
"update_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
"access_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
);
public $pog_query;
/**
* Getter for some private attributes
* @return mixed $attribute
*/
public function __get($attribute)
{
if (isset($this->{"_".$attribute}))
{
return $this->{"_".$attribute};
}
else
{
return false;
}
}
function record($reference='', $data='', $version='', $creation_date='', $update_date='', $access_date='')
{
$this->_recordversionList = array();
$this->reference = $reference;
$this->data = $data;
$this->version = $version;
$this->creation_date = $creation_date;
$this->update_date = $update_date;
$this->access_date = $access_date;
}
/**
* Gets object from database
* @param integer $recordId
* @return object $record
*/
function Get($recordId)
{
$connection = Database::Connect();
$this->pog_query = "select * from `record` where `recordid`='".intval($recordId)."' LIMIT 1";
$cursor = Database::Reader($this->pog_query, $connection);
while ($row = Database::Read($cursor))
{
$this->recordId = $row['recordid'];
$this->userId = $row['userid'];
$this->reference = $this->Unescape($row['reference']);
$this->data = $this->Unescape($row['data']);
$this->version = $this->Unescape($row['version']);
$this->creation_date = $row['creation_date'];
- $this->update_date = $row['update_date'];
+ $oDate = strtotime($row['update_date']);
+ $this->update_date = date('r', $oDate);
$this->access_date = $row['access_date'];
}
return $this;
}
/**
* Returns a sorted array of objects that match given conditions
* @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
* @param string $sortBy
* @param boolean $ascending
* @param int limit
* @return array $recordList
*/
function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
{
$connection = Database::Connect();
$sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
$this->pog_query = "select * from `record` ";
$recordList = Array();
if (sizeof($fcv_array) > 0)
{
$this->pog_query .= " where ";
for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
{
if (sizeof($fcv_array[$i]) == 1)
{
$this->pog_query .= " ".$fcv_array[$i][0]." ";
continue;
}
else
{
if ($i > 0 && sizeof($fcv_array[$i-1]) != 1)
{
$this->pog_query .= " AND ";
}
if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
{
if ($GLOBALS['configuration']['db_encoding'] == 1)
{
$value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'";
$this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value;
}
else
{
$value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'";
$this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
}
}
else
{
$value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'";
$this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
}
}
}
}
if ($sortBy != '')
{
if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET')
{
if ($GLOBALS['configuration']['db_encoding'] == 1)
{
$sortBy = "BASE64_DECODE($sortBy) ";
}
else
{
$sortBy = "$sortBy ";
}
}
else
{
$sortBy = "$sortBy ";
}
}
else
{
$sortBy = "recordid";
}
$this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit";
$thisObjectName = get_class($this);
$cursor = Database::Reader($this->pog_query, $connection);
while ($row = Database::Read($cursor))
{
$record = new $thisObjectName();
$record->recordId = $row['recordid'];
$record->userId = $row['userid'];
$record->reference = $this->Unescape($row['reference']);
$record->data = $this->Unescape($row['data']);
$record->version = $this->Unescape($row['version']);
$record->creation_date = $row['creation_date'];
- $record->update_date = $row['update_date'];
+ $oDate = strtotime($row['update_date']);
+ $record->update_date = date('r', $oDate);
$record->access_date = $row['access_date'];
$recordList[] = $record;
}
return $recordList;
}
/**
* Saves the object to the database
* @return integer $recordId
*/
function Save($deep = true)
{
$connection = Database::Connect();
+ $this->update_date = date( 'r');
+ $this->access_date = date( 'r');
$this->pog_query = "select `recordid` from `record` where `recordid`='".$this->recordId."' LIMIT 1";
$rows = Database::Query($this->pog_query, $connection);
if ($rows > 0)
{
$this->pog_query = "update `record` set
`userid`='".$this->userId."',
`reference`='".$this->Escape($this->reference)."',
`data`='".$this->Escape($this->data)."',
`version`='".$this->Escape($this->version)."',
`creation_date`='".$this->creation_date."',
`update_date`='".$this->update_date."',
`access_date`='".$this->access_date."' where `recordid`='".$this->recordId."'";
}
else
{
$this->pog_query = "insert into `record` (`userid`, `reference`, `data`, `version`, `creation_date`, `update_date`, `access_date` ) values (
'".$this->userId."',
'".$this->Escape($this->reference)."',
'".$this->Escape($this->data)."',
'".$this->Escape($this->version)."',
'".$this->creation_date."',
'".$this->update_date."',
'".$this->access_date."' )";
}
$insertId = Database::InsertOrUpdate($this->pog_query, $connection);
if ($this->recordId == "")
{
$this->recordId = $insertId;
}
if ($deep)
{
foreach ($this->_recordversionList as $recordversion)
{
$recordversion->recordId = $this->recordId;
$recordversion->Save($deep);
}
}
return $this->recordId;
}
/**
* Clones the object and saves it to the database
* @return integer $recordId
*/
function SaveNew($deep = false)
{
$this->recordId = '';
+ $this->creation_date = date( 'Y-m-d H:i:s');
return $this->Save($deep);
}
/**
* Deletes the object from the database
* @return boolean
*/
function Delete($deep = false, $across = false)
{
if ($deep)
{
$recordversionList = $this->GetRecordversionList();
foreach ($recordversionList as $recordversion)
{
$recordversion->Delete($deep, $across);
}
}
$connection = Database::Connect();
$this->pog_query = "delete from `record` where `recordid`='".$this->recordId."'";
return Database::NonQuery($this->pog_query, $connection);
}
/**
* Deletes a list of objects that match given conditions
* @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
* @param bool $deep
* @return
*/
function DeleteList($fcv_array, $deep = false, $across = false)
{
if (sizeof($fcv_array) > 0)
{
if ($deep || $across)
{
$objectList = $this->GetList($fcv_array);
foreach ($objectList as $object)
{
$object->Delete($deep, $across);
}
}
else
{
$connection = Database::Connect();
$pog_query = "delete from `record` where ";
for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
{
if (sizeof($fcv_array[$i]) == 1)
{
$pog_query .= " ".$fcv_array[$i][0]." ";
continue;
}
else
{
if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1)
{
$pog_query .= " AND ";
}
if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
{
$pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'";
}
else
{
$pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'";
}
}
}
return Database::NonQuery($pog_query, $connection);
}
}
}
/**
* Associates the user object to this one
* @return boolean
*/
function GetUser()
{
$user = new user();
return $user->Get($this->userId);
}
/**
* Associates the user object to this one
* @return
*/
function SetUser(&$user)
{
$this->userId = $user->userId;
}
/**
* Gets a list of recordversion objects associated to this one
* @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
* @param string $sortBy
* @param boolean $ascending
* @param int limit
* @return array of recordversion objects
*/
function GetRecordversionList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
{
$recordversion = new recordversion();
$fcv_array[] = array("recordId", "=", $this->recordId);
$dbObjects = $recordversion->GetList($fcv_array, $sortBy, $ascending, $limit);
return $dbObjects;
}
/**
* Makes this the parent of all recordversion objects in the recordversion List array. Any existing recordversion will become orphan(s)
* @return null
*/
function SetRecordversionList(&$list)
{
$this->_recordversionList = array();
$existingRecordversionList = $this->GetRecordversionList();
foreach ($existingRecordversionList as $recordversion)
{
$recordversion->recordId = '';
$recordversion->Save(false);
}
$this->_recordversionList = $list;
}
/**
* Associates the recordversion object to this one
* @return
*/
function AddRecordversion(&$recordversion)
{
$recordversion->recordId = $this->recordId;
$found = false;
foreach($this->_recordversionList as $recordversion2)
{
if ($recordversion->recordversionId > 0 && $recordversion->recordversionId == $recordversion2->recordversionId)
{
$found = true;
break;
}
}
if (!$found)
{
$this->_recordversionList[] = $recordversion;
}
}
}
-?> \ No newline at end of file
+?>
diff --git a/backend/php/src/objects/class.recordversion.php b/backend/php/src/objects/class.recordversion.php
index 3fbc436..f2de14a 100644
--- a/backend/php/src/objects/class.recordversion.php
+++ b/backend/php/src/objects/class.recordversion.php
@@ -67,315 +67,317 @@ class recordversion extends POG_Base
/**
* @var TIMESTAMP
*/
public $creation_date;
/**
* @var TIMESTAMP
*/
public $update_date;
/**
* @var TIMESTAMP
*/
public $access_date;
public $pog_attribute_type = array(
"recordversionId" => array('db_attributes' => array("NUMERIC", "INT")),
"record" => array('db_attributes' => array("OBJECT", "BELONGSTO")),
"reference" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
"header" => array('db_attributes' => array("TEXT", "LONGTEXT")),
"data" => array('db_attributes' => array("TEXT", "LONGTEXT")),
"version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
"previous_version_key" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
"previous_version_id" => array('db_attributes' => array("NUMERIC", "INT")),
"creation_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
"update_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
"access_date" => array('db_attributes' => array("NUMERIC", "TIMESTAMP")),
);
public $pog_query;
/**
* Getter for some private attributes
* @return mixed $attribute
*/
public function __get($attribute)
{
if (isset($this->{"_".$attribute}))
{
return $this->{"_".$attribute};
}
else
{
return false;
}
}
function recordversion($reference='', $header='', $data='', $version='', $previous_version_key='', $previous_version_id='', $creation_date='', $update_date='', $access_date='')
{
$this->reference = $reference;
$this->header = $header;
$this->data = $data;
$this->version = $version;
$this->previous_version_key = $previous_version_key;
$this->previous_version_id = $previous_version_id;
$this->creation_date = $creation_date;
$this->update_date = $update_date;
$this->access_date = $access_date;
}
/**
* Gets object from database
* @param integer $recordversionId
* @return object $recordversion
*/
function Get($recordversionId)
{
$connection = Database::Connect();
$this->pog_query = "select * from `recordversion` where `recordversionid`='".intval($recordversionId)."' LIMIT 1";
$cursor = Database::Reader($this->pog_query, $connection);
while ($row = Database::Read($cursor))
{
$this->recordversionId = $row['recordversionid'];
$this->recordId = $row['recordid'];
$this->reference = $this->Unescape($row['reference']);
$this->header = $this->Unescape($row['header']);
$this->data = $this->Unescape($row['data']);
$this->version = $this->Unescape($row['version']);
$this->previous_version_key = $this->Unescape($row['previous_version_key']);
$this->previous_version_id = $this->Unescape($row['previous_version_id']);
$this->creation_date = $row['creation_date'];
$this->update_date = $row['update_date'];
$this->access_date = $row['access_date'];
}
return $this;
}
/**
* Returns a sorted array of objects that match given conditions
* @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
* @param string $sortBy
* @param boolean $ascending
* @param int limit
* @return array $recordversionList
*/
function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
{
$connection = Database::Connect();
$sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
$this->pog_query = "select * from `recordversion` ";
$recordversionList = Array();
if (sizeof($fcv_array) > 0)
{
$this->pog_query .= " where ";
for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
{
if (sizeof($fcv_array[$i]) == 1)
{
$this->pog_query .= " ".$fcv_array[$i][0]." ";
continue;
}
else
{
if ($i > 0 && sizeof($fcv_array[$i-1]) != 1)
{
$this->pog_query .= " AND ";
}
if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
{
if ($GLOBALS['configuration']['db_encoding'] == 1)
{
$value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'";
$this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value;
}
else
{
$value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'";
$this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
}
}
else
{
$value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'";
$this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
}
}
}
}
if ($sortBy != '')
{
if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET')
{
if ($GLOBALS['configuration']['db_encoding'] == 1)
{
$sortBy = "BASE64_DECODE($sortBy) ";
}
else
{
$sortBy = "$sortBy ";
}
}
else
{
$sortBy = "$sortBy ";
}
}
else
{
$sortBy = "recordversionid";
}
$this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit";
$thisObjectName = get_class($this);
$cursor = Database::Reader($this->pog_query, $connection);
while ($row = Database::Read($cursor))
{
$recordversion = new $thisObjectName();
$recordversion->recordversionId = $row['recordversionid'];
$recordversion->recordId = $row['recordid'];
$recordversion->reference = $this->Unescape($row['reference']);
$recordversion->header = $this->Unescape($row['header']);
$recordversion->data = $this->Unescape($row['data']);
$recordversion->version = $this->Unescape($row['version']);
$recordversion->previous_version_key = $this->Unescape($row['previous_version_key']);
$recordversion->previous_version_id = $this->Unescape($row['previous_version_id']);
$recordversion->creation_date = $row['creation_date'];
$recordversion->update_date = $row['update_date'];
$recordversion->access_date = $row['access_date'];
$recordversionList[] = $recordversion;
}
return $recordversionList;
}
/**
* Saves the object to the database
* @return integer $recordversionId
*/
function Save()
{
$connection = Database::Connect();
+ $this->update_date = date( 'Y-m-d H:i:s');
+ $this->access_date = date( 'Y-m-d H:i:s');
$this->pog_query = "select `recordversionid` from `recordversion` where `recordversionid`='".$this->recordversionId."' LIMIT 1";
$rows = Database::Query($this->pog_query, $connection);
if ($rows > 0)
{
$this->pog_query = "update `recordversion` set
`recordid`='".$this->recordId."',
`reference`='".$this->Escape($this->reference)."',
`header`='".$this->Escape($this->header)."',
`data`='".$this->Escape($this->data)."',
`version`='".$this->Escape($this->version)."',
`previous_version_key`='".$this->Escape($this->previous_version_key)."',
`previous_version_id`='".$this->Escape($this->previous_version_id)."',
`creation_date`='".$this->creation_date."',
`update_date`='".$this->update_date."',
`access_date`='".$this->access_date."' where `recordversionid`='".$this->recordversionId."'";
}
else
{
$this->pog_query = "insert into `recordversion` (`recordid`, `reference`, `header`, `data`, `version`, `previous_version_key`, `previous_version_id`, `creation_date`, `update_date`, `access_date` ) values (
'".$this->recordId."',
'".$this->Escape($this->reference)."',
'".$this->Escape($this->header)."',
'".$this->Escape($this->data)."',
'".$this->Escape($this->version)."',
'".$this->Escape($this->previous_version_key)."',
'".$this->Escape($this->previous_version_id)."',
'".$this->creation_date."',
'".$this->update_date."',
'".$this->access_date."' )";
}
$insertId = Database::InsertOrUpdate($this->pog_query, $connection);
if ($this->recordversionId == "")
{
$this->recordversionId = $insertId;
}
return $this->recordversionId;
}
/**
* Clones the object and saves it to the database
* @return integer $recordversionId
*/
function SaveNew()
{
$this->recordversionId = '';
return $this->Save();
}
/**
* Deletes the object from the database
* @return boolean
*/
function Delete()
{
$connection = Database::Connect();
$this->pog_query = "delete from `recordversion` where `recordversionid`='".$this->recordversionId."'";
return Database::NonQuery($this->pog_query, $connection);
}
/**
* Deletes a list of objects that match given conditions
* @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
* @param bool $deep
* @return
*/
function DeleteList($fcv_array)
{
if (sizeof($fcv_array) > 0)
{
$connection = Database::Connect();
$pog_query = "delete from `recordversion` where ";
for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
{
if (sizeof($fcv_array[$i]) == 1)
{
$pog_query .= " ".$fcv_array[$i][0]." ";
continue;
}
else
{
if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1)
{
$pog_query .= " AND ";
}
if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
{
$pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'";
}
else
{
$pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'";
}
}
}
return Database::NonQuery($pog_query, $connection);
}
}
/**
* Associates the record object to this one
* @return boolean
*/
function GetRecord()
{
$record = new record();
return $record->Get($this->recordId);
}
/**
* Associates the record object to this one
* @return
*/
function SetRecord(&$record)
{
$this->recordId = $record->recordId;
}
}
-?> \ No newline at end of file
+?>