AclHelper.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <?php
  2. Lib::loadClass('Api_WfsNs');
  3. Lib::loadClass('ProcesHelper');
  4. Lib::loadClass('Router');
  5. Lib::loadClass('Route_UrlAction');
  6. class Core_AclHelper {// Helper class for Acl
  7. public static function hasCreatePerms($acl) {
  8. foreach ($acl->getFieldListByIdZasob() as $fieldName) {// TODO: use getFieldList
  9. // echo"<p>\$acl->canCreateField({$fieldName}): (".$acl->canCreateField($fieldName).")</p>";
  10. if ($acl->canCreateField($fieldName)) return true;
  11. }
  12. return false;
  13. }
  14. public static function hasGeomFields($acl) {
  15. foreach ($acl->getFieldListByIdZasob() as $fieldName) {
  16. // echo"<p>\$acl->isGeomField({$fieldName}): (".$acl->isGeomField($fieldName).") \$acl->canReadField({$fieldName}): (".$acl->canReadField($fieldName).")</p>";
  17. if ($acl->isGeomField($fieldName) && $acl->canReadField($fieldName)) return true;
  18. }
  19. return false;
  20. }
  21. // @returns array [ field => string(perms like 'RWX') ]
  22. public static function getFieldPerms($acl) {// TODO: fetch perms for given Acl by namespace
  23. // TODO:? cache session or only current request (static)
  24. $fieldPerms = array();
  25. foreach ($acl->getFields() as $idField => $field) {
  26. $fieldPerms[ $field['name'] ] = $field['perms'];
  27. }
  28. return $fieldPerms;
  29. }
  30. public static function getExportFieldList($acl) {
  31. $exportFields = array();
  32. foreach (self::getFieldPerms($acl) as $fieldName => $perms) {
  33. if (false !== strpos($perms, 'E')) {
  34. $exportFields[] = $fieldName;
  35. }
  36. }
  37. return $exportFields;
  38. }
  39. public static function getAclByTypeName($typeName, $forceTblAclInit = false) {// TODO: replace getAclFromTypeName in WFS
  40. return self::getAclByNamespace(str_replace(':', '/', $typeName), $forceTblAclInit);
  41. }
  42. public static function getAclByNamespace($namespace, $forceTblAclInit = false) {
  43. $ns = self::parseNamespaceUrl($namespace);
  44. $acl = User::getAcl()->getObjectAcl($ns['prefix'], $ns['name']);
  45. if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
  46. $acl->init($forceTblAclInit);
  47. return $acl;
  48. }
  49. public static function getMoreFunctionsCell($acl, $args) {
  50. $id = V::get('primary_key', 0, $args, 'int');
  51. if ($id <= 0) throw new HttpException("404", 404);
  52. $record = V::get('record', null, $args);
  53. $rowFunList = array();
  54. $tableName = $acl->getName();
  55. $record = ($record)? $record : $acl->getItem($id);
  56. if(1){// TODO: fetch $totalMsgs from TableMsgs
  57. $msgs = Router::getRoute('Msgs');
  58. $msgsList = $msgs->getActiveMessagesForTableRecord($tableName, $id);
  59. $totalMsgs = count($msgsList);
  60. $rowFunc = new stdClass();
  61. $rowFunc->id = 'msgs';
  62. $rowFunc->ico = 'glyphicon glyphicon-envelope';
  63. $rowFunc->href = 'index.php?_route=TableMsgs&_task=tableRow&idTable=' . $acl->getID() . '&idRow=' . $id;
  64. $rowFunc->title = "Wiadomości ({$totalMsgs})";
  65. $rowFunc->label = "Wiadomości <span class=\"badge\">{$totalMsgs}</span>";
  66. $rowFunList[] = $rowFunc;
  67. }
  68. if ('CRM_PROCES' == $acl->getName()) {// TODO: mv to table gui xml or php class
  69. // procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id=22001
  70. $rowFunc = new stdClass();
  71. $rowFunc->ico = 'glyphicon glyphicon-eye-open';
  72. $rowFunc->href = "procesy5.php?task=CRM_PROCES&filtr_id={$id}";
  73. $rowFunc->title = "Zobacz na drzewie procesów {{$id}}";
  74. $rowFunList[] = $rowFunc;
  75. $wskazniki = ProcesHelper::get_wskazniki($id);
  76. $connectedZasobyTotal = count($wskazniki);
  77. $rowFunc = new stdClass();
  78. $rowFunc->ico = 'glyphicon glyphicon-random';
  79. $rowFunc->href = "index.php?MENU_INIT=PROCES_ADD_ZASOB&procesID={$id}";
  80. $rowFunc->title = "Powiązane zasoby <span class=\"badge\">{$connectedZasobyTotal}</span>";
  81. $rowFunList[] = $rowFunc;
  82. }
  83. if ('CRM_LISTA_ZASOBOW' == $acl->getName()) {// TODO: mv to table gui xml or php class
  84. // procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id=22001
  85. $rowFunc = new stdClass();
  86. $rowFunc->ico = 'glyphicon glyphicon-eye-open';
  87. $rowFunc->href = "procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id={$id}";
  88. $rowFunc->title = "Zobacz na drzewie zasobów [{$id}]";
  89. $rowFunList[] = $rowFunc;
  90. // index.php?MENU_INIT=ZASOB_OBOWIAZKI&id_zasob=22001
  91. $rowFunc = new stdClass();
  92. $rowFunc->ico = 'glyphicon glyphicon-random';
  93. $rowFunc->href = "index.php?MENU_INIT=ZASOB_OBOWIAZKI&id_zasob={$id}";
  94. $rowFunc->title = "Powiązane procesy (OB)";
  95. $rowFunList[] = $rowFunc;
  96. // index.php?MENU_INIT=ZASOB_EXTERNAL_IDS&id_zasob=22001
  97. $rowFunc = new stdClass();
  98. $rowFunc->ico = 'glyphicon glyphicon-random';
  99. $rowFunc->href = "index.php?MENU_INIT=ZASOB_EXTERNAL_IDS&id_zasob={$id}";
  100. $rowFunc->title = "Powiązane dane (IDS)";
  101. $rowFunList[] = $rowFunc;
  102. $groupTypeList = array();
  103. $groupTypeList[] = 'STANOWISKO';
  104. $groupTypeList[] = 'PODMIOT';
  105. $groupTypeList[] = 'DZIAL';
  106. if (in_array($record->TYPE, $groupTypeList)) {
  107. $rowFunc = new stdClass();
  108. $rowFunc->ico = 'glyphicon glyphicon-retweet';
  109. $rowFunc->href = "index.php?_route=Users&_task=syncGroup&idGroup={$id}";
  110. $rowFunc->title = "Synchronizuj do LDAP";
  111. $rowFunList[] = $rowFunc;
  112. }
  113. }
  114. if ('ADMIN_USERS' == $acl->getName()) {// TODO: mv to table gui xml
  115. if ($acl->canReadRecord($record) && $acl->canReadObjectField('ADM_ACCOUNT', $record)) {
  116. $rowFunc = new stdClass();
  117. $rowFunc->ico = 'glyphicon glyphicon-user';
  118. $rowFunc->href = 'index.php?_route=Users&_task=userGroups&usrLogin=' . $record->ADM_ACCOUNT;
  119. $rowFunc->title = "Ustal stanowisko";
  120. $rowFunList[] = $rowFunc;
  121. $rowFunc = new stdClass();
  122. $rowFunc->ico = 'glyphicon glyphicon-retweet';
  123. $rowFunc->href = 'index.php?_route=Users&_task=syncUser&usrLogin=' . $record->ADM_ACCOUNT;
  124. $rowFunc->title = "Synchronizuj do LDAP";
  125. $rowFunList[] = $rowFunc;
  126. $rowFunc = new stdClass();
  127. $rowFunc->ico = 'glyphicon glyphicon-minus';
  128. $rowFunc->href = 'index.php?MENU_INIT=USER_OCENA_PRACOWNIKA&usrLogin=' . $record->ADM_ACCOUNT;
  129. $rowFunc->title = "Ocena pracownika";
  130. $rowFunList[] = $rowFunc;
  131. }
  132. }
  133. if ($urlFunctions = Route_UrlAction::getTableFunctions($acl->getID(), $id, $acl->getName(), User::getLogin())) {
  134. foreach ($urlFunctions as $urlFunction) {
  135. // TODO: is allowed to view - test by Router::getRoute('UrlAction')->isFunctionAllowedForRecord($routeName = $urlFunction['name'], $acl->getID(), $id);
  136. $rowFunction = array();
  137. $rowFunction['href'] = $urlFunction['baseLink'];
  138. $rowFunction['ico'] = V::get('ico', 'glyphicon glyphicon-share', $urlFunction);
  139. $rowFunction['label'] = $urlFunction['label'];
  140. $rowFunction['title'] = V::get('title', $urlFunction['label'], $urlFunction);
  141. if (!empty($urlFunction['link_target'])) $rowFunction['target'] = $urlFunction['link_target'];
  142. if (!empty($urlFunction['cell_id_params'])) {
  143. $urlParams = array();// [ "{$urlParamName}={$paramValue}" ]
  144. foreach ($urlFunction['cell_id_params'] as $idField => $urlParamName) {
  145. $paramValue = '';
  146. $fld = $acl->getField($idField);
  147. if ($fld) {
  148. $fldName = $fld['name'];
  149. $paramValue = V::get($fldName, '', $record);
  150. $urlParams[] = "{$urlParamName}={$paramValue}";
  151. }
  152. }
  153. if (!empty($urlParams)) $rowFunction['href'] .= "&" . implode("&", $urlParams);
  154. }
  155. $rowFunList[] = $rowFunction;
  156. }
  157. }
  158. return $rowFunList;
  159. }
  160. public static function getAclList() {// @usage Core_AclHelper::getAclList();// @returns array [ $typeName , ... ]
  161. $aclList = array();
  162. // Schema_AccessGroupStorageAcl, load by User::getAcl()->getObjectAcl('default_objects', $objName);
  163. // $objClassName = "Schema_{$objName}StorageAcl";
  164. // if (!Lib::tryLoadClass($objClassName)) throw new HttpException("Not implemented", 501);
  165. // $ grep -r 'class ' SE/se-lib/Schema/*Acl.php
  166. // SE/se-lib/Schema/AccessGroupStorageAcl.php:class Schema_AccessGroupStorageAcl extends Core_AclBase
  167. // SE/se-lib/Schema/AccessOwnerStorageAcl.php:class Schema_AccessOwnerStorageAcl extends Core_AclBase
  168. // SE/se-lib/Schema/FileStorageAcl.php:class Schema_FileStorageAcl extends Core_AclBase
  169. // SE/se-lib/Schema/KorespondencjaStorageAcl.php:class Schema_KorespondencjaStorageAcl extends Core_AclBase
  170. // SE/se-lib/Schema/TestPermsStorageAcl.php:class Schema_TestPermsStorageAcl extends Core_AclBase
  171. $aclList[] = 'default_objects:AccessGroupRead';
  172. $aclList[] = 'default_objects:AccessGroupWrite';
  173. $aclList[] = 'default_objects:AccessOwner';
  174. $aclList[] = 'default_objects:File';
  175. $aclList[] = 'default_objects:Korespondencja';
  176. $aclList[] = 'default_objects:TestPerms';
  177. // TODO: read from Database
  178. // $aclList[] = 'default_db__x3A__TEST_PERMS:TEST_PERMS';// uproszczona wersja: default_db:TEST_PERMS
  179. $cleanHostName = str_replace(array(".", "-"), '_', $_SERVER['SERVER_NAME']);
  180. if (file_exists(APP_PATH_SCHEMA . "/gui/company/{$cleanHostName}/get_object_list.php")) {
  181. $objList = include APP_PATH_SCHEMA . "/gui/company/{$cleanHostName}/get_object_list.php";
  182. if (!empty($objList) && is_array($objList)) {
  183. foreach ($objList as $objectName) {
  184. if (!in_array($objectName, $aclList)) $aclList[] = $objectName;
  185. }
  186. }
  187. }
  188. return $aclList;
  189. }
  190. /**
  191. * Parse namespace url into parts.
  192. *
  193. * @param $namespace - absolute or relative url
  194. * @return array:
  195. * name: element name
  196. * url: url wihtout name
  197. * prefix: xml prefix
  198. * sourceName: used by engine - maybe to remove (used by Core_AclHelper::getAclByNamespace($namespace))
  199. *
  200. * @example - create xmlns attribute:
  201. * xmlns:{$ns['prefix']}="{$ns['url']}"
  202. *
  203. * @example - wfs typeName:
  204. * typeName = "{$ns['prefix']}:{$ns['name']}"
  205. *
  206. * @example 'default_db/TEST_PERMS' => Array:
  207. * [name] => TEST_PERMS
  208. * [prefix] => default_db
  209. * [url] => https://biuro.biall-net.pl/wfs/default_db
  210. * [sourceName] => default_db
  211. *
  212. * @example 'default_objects/AccessOwner' => Array:
  213. * [name] => AccessOwner
  214. * [prefix] => default_objects
  215. * [url] => https://biuro.biall-net.pl/wfs/default_objects
  216. * [sourceName] => default_objects
  217. *
  218. * @example 'default_db/ZALICZKA/Zaliczka' => Array:
  219. * [name] => Zaliczka
  220. * [prefix] => default_db__x3A__Zaliczka
  221. * [url] => https://biuro.biall-net.pl/wfs/default_db/ZALICZKA
  222. * [sourceName] => table_objects
  223. *
  224. */
  225. public static function parseNamespaceUrl($namespace) {// returns assoc array: [ 'name', 'url', 'prefix', 'sourceName' ]
  226. // TODO: the same algo like getAclByNamespace($namespace)
  227. $baseNsUri = Api_WfsNs::getBaseWfsUri();
  228. if ('http' != substr($namespace, 0, 4)) $namespace = "{$baseNsUri}/{$namespace}";//Request::getHostUri() . '/' . $namespace;
  229. $nsUrl = $baseNsUri . '/' . '';
  230. if ("{$baseNsUri}/" != substr($namespace, 0, strlen($baseNsUri) + 1)) throw new HttpException("Zasoby zewnętrzenj systemu nie są jeszcze zaimplementowane", 501);
  231. $relativeNsUrl = substr($namespace, strlen($baseNsUri) + 1);
  232. // convert '__x3A__' to '/' in url
  233. $nsEx = explode('/', str_replace('__x3A__', '/', $relativeNsUrl));// "http://biuro.biall-net.pl/wfs/ default_db/{$nazwa_tabeli}/{$nazwa_obj}
  234. // default_db__x3A__ZALICZKA/Zaliczka => default_db/ZALICZKA/Zaliczka
  235. $sourceName = array_shift($nsEx);// remove first element - source name
  236. $objName = array_pop($nsEx);// name is always last part from url
  237. if ('default_db' == $sourceName || 'p5_default_db' == $sourceName) {
  238. if (count($nsEx) > 1) throw new Exception("Nieznany namespace default_db: '{$relativeNsUrl}'", 501);
  239. $sourceName = 'default_db';
  240. $nsPrefix = $sourceName;
  241. if (1 == count($nsEx)) {
  242. $sourceName = 'table_objects';// TODO: another source name to read from simpleSchema @see Core_AclSimpleSchemaBase
  243. $nsPrefix = 'default_db__x3A__' . $objName;
  244. }
  245. // $objName = $nsEx[1];// 'default_db/ZALICZKA:Zaliczka' => ('objects', 'Zaliczka') - possible name conflicts
  246. $nsUrl = trim($baseNsUri . '/default_db/' . implode("/", $nsEx), '/');
  247. return [ 'name' => $objName, 'prefix' => $nsPrefix, 'url' => $nsUrl, 'sourceName' => $sourceName ];
  248. }
  249. else if ('default_objects' == $sourceName || 'SystemObjects' == $sourceName) {
  250. if (count($nsEx) > 1) throw new Exception("Nieznany namespace SystemObjects: '{$relativeNsUrl}'", 501);
  251. $sourceName = 'default_objects';
  252. $nsUrl = trim($baseNsUri . '/default_objects/' . implode("/", $nsEx), '/');
  253. $nsPrefix = 'default_objects';
  254. return [ 'name' => $objName, 'prefix' => $nsPrefix, 'url' => $nsUrl, 'sourceName' => $sourceName ];
  255. }
  256. else if ('p5_objects' == $sourceName || 'objects' == $sourceName) {
  257. if (count($nsEx) > 1) throw new Exception("Nieznany namespace SystemObjects: '{$relativeNsUrl}'", 501);
  258. $sourceName = 'default_objects';
  259. $nsUrl = trim($baseNsUri . '/default_objects/' . implode("/", $nsEx), '/');
  260. $nsPrefix = 'default_objects';
  261. return [ 'name' => $objName, 'prefix' => $nsPrefix, 'url' => $nsUrl, 'sourceName' => $sourceName ];
  262. }
  263. else if ('zasob_' == substr($sourceName, 0, 6)) {
  264. $dbName = substr($sourceName, 6);// database id
  265. throw new Exception("TODO db[{$dbName}] namespace '{$relativeNsUrl}'", 501);
  266. }
  267. else throw new Exception("Nieznany namespace '{$relativeNsUrl}'", 501);
  268. }
  269. public static function insertRef($objectName, $pk, $childName, $childPk) {// TODO: $idTransaction
  270. $refTable = self::getRefTable($objectName, $childName);
  271. $sqlPk = DB::getPDO()->quote($pk, PDO::PARAM_STR);
  272. $sqlChildPk = DB::getPDO()->quote($childPk, PDO::PARAM_STR);
  273. DB::getPDO()->exec("
  274. insert into `{$refTable}` (`PRIMARY_KEY`, `REMOTE_PRIMARY_KEY`)
  275. values ({$sqlPk}, {$sqlChildPk})
  276. ");
  277. }
  278. public static function cleanRefs($objectName, $pk, $childName) {// TODO: $idTransaction
  279. $refTable = self::getRefTable($objectName, $childName);
  280. $sqlPk = DB::getPDO()->quote($pk, PDO::PARAM_STR);
  281. DB::getPDO()->exec("
  282. update `{$refTable}` set `A_STATUS` = 'DELETED'
  283. where `PRIMARY_KEY` = {$sqlPk}
  284. ");
  285. }
  286. public static function getRefTable($objectName, $childName) {
  287. static $cacheRefTables = array();
  288. $refTable = "{$objectName}__#REF__{$childName}";
  289. if (in_array($refTable, $cacheRefTables)) return $refTable;
  290. DB::getPDO()->exec("
  291. CREATE TABLE IF NOT EXISTS `{$refTable}` (
  292. `PRIMARY_KEY` int(11) NOT NULL,
  293. `REMOTE_PRIMARY_KEY` int(11) NOT NULL,
  294. `A_STATUS` enum('WAITING', 'NORMAL', 'DELETED') NOT NULL DEFAULT 'WAITING',
  295. `A_RECORD_UPDATE_DATE` timestamp ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  296. -- TODO `TRANACTION_ID` int(11) NOT NULL
  297. KEY `PRIMARY_KEY` (`PRIMARY_KEY`),
  298. KEY `REMOTE_PRIMARY_KEY` (`REMOTE_PRIMARY_KEY`)
  299. ) ENGINE=MyISAM DEFAULT CHARSET=latin2;
  300. ");
  301. try {
  302. DB::getPDO()->exec(" ALTER TABLE `{$refTable}` ADD `A_STATUS` enum('WAITING', 'NORMAL', 'DELETED') NOT NULL DEFAULT 'WAITING' ");
  303. } catch (Exception $e) {
  304. // echo 'C.'.get_class($this).' L.' . __LINE__ . " Error:";print_r($e->getMessage());echo "\n";
  305. }
  306. try {
  307. DB::getPDO()->exec(" ALTER TABLE `{$refTable}` ADD `A_RECORD_UPDATE_DATE` timestamp ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ");
  308. } catch (Exception $e) {
  309. // echo 'C.'.get_class($this).' L.' . __LINE__ . " Error:";print_r($e->getMessage());echo "\n";
  310. }
  311. $cacheRefTables[] = $refTable;
  312. return $refTable;
  313. }
  314. public static function getInstanceTable($rootTableName) {
  315. static $cacheInstanceTables = array();
  316. $instanceTable = "{$rootTableName}__#INSTANCE";
  317. if (in_array($instanceTable, $cacheInstanceTables)) return $instanceTable;
  318. DB::getPDO()->exec("
  319. CREATE TABLE IF NOT EXISTS `{$instanceTable}` (
  320. `PRIMARY_KEY` int(11) NOT NULL,
  321. `REMOTE_PRIMARY_KEY` int(11) NOT NULL,
  322. `A_STATUS` enum('WAITING', 'NORMAL', 'DELETED') NOT NULL DEFAULT 'WAITING',
  323. `A_RECORD_UPDATE_DATE` timestamp ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  324. -- TODO `TRANACTION_ID` int(11) NOT NULL
  325. KEY `PRIMARY_KEY` (`PRIMARY_KEY`),
  326. KEY `REMOTE_PRIMARY_KEY` (`REMOTE_PRIMARY_KEY`)
  327. ) ENGINE=MyISAM DEFAULT CHARSET=latin2;
  328. ");
  329. try {
  330. DB::getPDO()->exec(" ALTER TABLE `{$instanceTable}` ADD `A_STATUS` enum('WAITING', 'NORMAL', 'DELETED') NOT NULL DEFAULT 'WAITING' ");
  331. } catch (Exception $e) {
  332. // echo 'C.'.get_class($this).' L.' . __LINE__ . " Error:";print_r($e->getMessage());echo "\n";
  333. }
  334. try {
  335. DB::getPDO()->exec(" ALTER TABLE `{$instanceTable}` ADD `A_RECORD_UPDATE_DATE` timestamp ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ");
  336. } catch (Exception $e) {
  337. // echo 'C.'.get_class($this).' L.' . __LINE__ . " Error:";print_r($e->getMessage());echo "\n";
  338. }
  339. $cacheInstanceTables[] = $instanceTable;
  340. return $instanceTable;
  341. }
  342. public static function getTransactionTable($rootTableName) {
  343. static $cacheTransactionTables = array();
  344. $transactionTable = "{$rootTableName}__#TRANSACTION";
  345. if (in_array($transactionTable, $cacheTransactionTables)) return $transactionTable;
  346. DB::getPDO()->exec("
  347. CREATE TABLE IF NOT EXISTS `{$transactionTable}` (
  348. `ID` int(11) NOT NULL,
  349. `A_ACTION_ID_USER` int(11) DEFAULT NULL, -- NULL for scripts
  350. `A_ACTION_AUTHOR` varchar(255) NOT NULL DEFAULT '',
  351. `A_ACTION_DATE` timestamp ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  352. `A_STATUS` enum('WAITING', 'NORMAL', 'DELETED') NOT NULL DEFAULT 'WAITING',
  353. `A_CONTEXT_TRANSACTION` varchar(255) NOT NULL DEFAULT '',
  354. PRIMARY KEY (`ID`)
  355. ) ENGINE=MyISAM DEFAULT CHARSET=latin2;
  356. ");
  357. $cacheTransactionTables[] = $transactionTable;
  358. return $transactionTable;
  359. }
  360. public static function startTransaction($rootTableName, $idUser, $author = '') {
  361. $refTable = self::getTransactionTable($rootTableName);
  362. $sqlIdUser = ((int)$idUser > 0) ? DB::getPDO()->quote($idUser, PDO::PARAM_INT) : 'NULL';
  363. $sqlAuthor = DB::getPDO()->quote($author, PDO::PARAM_STR);
  364. DB::getPDO()->exec("
  365. insert into `{$refTable}` (`A_ACTION_ID_USER`, `A_ACTION_AUTHOR`)
  366. values ({$sqlIdUser}, {$sqlAuthor})
  367. ");
  368. return DB::getPDO()->lastInsertId();
  369. }
  370. public static function rollbackTransaction($rootTableName, $idTransaction) {
  371. // TODO: rollbackTransaction
  372. }
  373. public static function commitTransaction($rootTableName, $idTransaction) {
  374. // TODO: COMMIT
  375. }
  376. }