|
|
@@ -36,6 +36,7 @@ class TableAcl extends Core_AclBase {
|
|
|
public $_name = '';
|
|
|
public $_label = '';
|
|
|
public $_opis = '';
|
|
|
+ public $_executed_fieldsInit = null;
|
|
|
public $_fields = array();
|
|
|
public $_types = array();
|
|
|
public $_virtualFieldsIdList = array();
|
|
|
@@ -169,31 +170,26 @@ class TableAcl extends Core_AclBase {
|
|
|
}
|
|
|
|
|
|
public function getField($fieldID) {
|
|
|
- return $this->_fields[$fieldID];
|
|
|
+ return $this->getFields()[$fieldID];
|
|
|
}
|
|
|
|
|
|
public function hasFieldById($fieldID) {
|
|
|
- return array_key_exists($fieldID, $this->_fields);
|
|
|
- }
|
|
|
-
|
|
|
- public function removeField($fieldID) {
|
|
|
- if (array_key_exists($fieldID, $this->_fields)) {
|
|
|
- unset($this->_fields[$fieldID]);
|
|
|
- }
|
|
|
+ return array_key_exists($fieldID, $this->getFields());
|
|
|
}
|
|
|
|
|
|
public function getFields() {
|
|
|
+ $this->fieldsInit();
|
|
|
return $this->_fields;
|
|
|
}
|
|
|
|
|
|
public function setFieldPerms($fieldID, $perms) {
|
|
|
- if (array_key_exists($fieldID, $this->_fields)) {
|
|
|
+ if (array_key_exists($fieldID, $this->getFields())) {
|
|
|
$this->_fields[$fieldID]['perms'] .= $perms;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public function getFieldPerms($fieldID) {
|
|
|
- if (array_key_exists($fieldID, $this->_fields)) {
|
|
|
+ if (array_key_exists($fieldID, $this->getFields())) {
|
|
|
$perms = V::get('perms', '', $this->_fields[$fieldID]);
|
|
|
if ($perms) {
|
|
|
return implode(',', array_unique(str_split($perms)));
|
|
|
@@ -203,7 +199,7 @@ class TableAcl extends Core_AclBase {
|
|
|
}
|
|
|
|
|
|
public function hasFieldPerm($fieldID, $perm) {// TODO: legacy
|
|
|
- if (array_key_exists($fieldID, $this->_fields)) {
|
|
|
+ if (array_key_exists($fieldID, $this->getFields())) {
|
|
|
if (false !== strpos($this->_fields[$fieldID]['perms'], $perm)) {
|
|
|
return true;
|
|
|
}
|
|
|
@@ -217,7 +213,7 @@ class TableAcl extends Core_AclBase {
|
|
|
if (empty($fieldName)) {
|
|
|
return;
|
|
|
}
|
|
|
- foreach ($this->_fields as $kID => $vField) {
|
|
|
+ foreach ($this->getFields() as $kID => $vField) {
|
|
|
if ($vField['name'] == $fieldName) {
|
|
|
$fieldID = $kID;
|
|
|
}
|
|
|
@@ -226,7 +222,7 @@ class TableAcl extends Core_AclBase {
|
|
|
}
|
|
|
|
|
|
public function hasEditPerms() {
|
|
|
- foreach ($this->_fields as $kFldID => $vFld) {
|
|
|
+ foreach ($this->getFields() as $kFldID => $vFld) {
|
|
|
if ($this->hasFieldPerm($kFldID, 'W')) return true;
|
|
|
if ($this->hasFieldPerm($kFldID, 'C')) return true;
|
|
|
if ($this->hasFieldPerm($kFldID, 'S')) return true;
|
|
|
@@ -235,7 +231,7 @@ class TableAcl extends Core_AclBase {
|
|
|
}
|
|
|
|
|
|
public function hasSuperAccessPerms() {
|
|
|
- foreach ($this->_fields as $kFldID => $vFld) {
|
|
|
+ foreach ($this->getFields() as $kFldID => $vFld) {
|
|
|
if ($this->hasFieldPerm($kFldID, 'S')) {
|
|
|
return true;
|
|
|
}
|
|
|
@@ -247,7 +243,7 @@ class TableAcl extends Core_AclBase {
|
|
|
}
|
|
|
|
|
|
public function hasPermSuperWrite() {
|
|
|
- foreach ($this->_fields as $kFldID => $vFld) {
|
|
|
+ foreach ($this->getFields() as $kFldID => $vFld) {
|
|
|
if ($this->hasFieldPerm($kFldID, 'S')) {
|
|
|
return true;
|
|
|
}
|
|
|
@@ -268,7 +264,7 @@ class TableAcl extends Core_AclBase {
|
|
|
$adminFields[] = 'A_RECORD_CREATE_AUTHOR';
|
|
|
$adminFields[] = 'A_RECORD_UPDATE_DATE';
|
|
|
$adminFields[] = 'A_RECORD_UPDATE_AUTHOR';
|
|
|
- $fieldName = $this->_fields[$fieldID]['name'];
|
|
|
+ $fieldName = $this->getFields()[$fieldID]['name'];
|
|
|
if ($taskPerm == 'R' && in_array($fieldName, $adminFields)) {
|
|
|
return true;
|
|
|
}
|
|
|
@@ -381,7 +377,7 @@ class TableAcl extends Core_AclBase {
|
|
|
else throw new Exception("Brak uprawnień do tego pola ({$taskPerm})");
|
|
|
}
|
|
|
|
|
|
- $colName = $this->_fields[$fieldID]['name'];
|
|
|
+ $colName = $this->getFields()[$fieldID]['name'];
|
|
|
if ($colName == 'ID') return;
|
|
|
|
|
|
$colType = $this->getFieldTypeById($fieldID);
|
|
|
@@ -642,7 +638,7 @@ class TableAcl extends Core_AclBase {
|
|
|
return $out;
|
|
|
}
|
|
|
|
|
|
- $colName = $this->_fields[$fieldID]['name'];
|
|
|
+ $colName = $this->getFields()[$fieldID]['name'];
|
|
|
if ($colName == 'ID') {
|
|
|
return $out;
|
|
|
}
|
|
|
@@ -937,35 +933,32 @@ class TableAcl extends Core_AclBase {
|
|
|
return $_cache[$idTable];
|
|
|
}
|
|
|
|
|
|
- if (empty($tableConfig)) {
|
|
|
- throw new Exception("Brak danych konfiguracyjnych do tabeli nr {$idTable} #TACL" . __LINE__);
|
|
|
-
|
|
|
- $zasobObj = ProcesHelper::getZasobTableInfo($idTable);
|
|
|
- if (!$zasobObj) {
|
|
|
- return null;// TODO: throw new Exception("Zasob TABELA ID={$idTable} nie istnieje");
|
|
|
- }
|
|
|
- $tableConfig['db'] = $zasobObj->P__ID;
|
|
|
- $tableConfig['name'] = $zasobObj->DESC;
|
|
|
- $tableConfig['label'] = $zasobObj->DESC_PL;
|
|
|
- $tableConfig['opis'] = $zasobObj->OPIS;
|
|
|
-
|
|
|
- $userAcl = User::getAcl();
|
|
|
- $userPermsForTable = $userAcl->getPermsForTable($idTable);
|
|
|
- if (!$userPermsForTable) {
|
|
|
- return null;// TODO: throw new Exception("Brak uprawnień do pól Tabeli nr {$idTable} '{$zasobObj->DESC}'");
|
|
|
- }
|
|
|
- echo'<pre>$userPermsForTable('.$idTable.') ';print_r($userPermsForTable);echo'</pre>';
|
|
|
- if(0){// TODO: from UserAcl big query
|
|
|
- $foundTbls[$r->ZASOB_PARENT_ID]->addField($r->ID_ZASOB, $r->ZASOB_DESC, $r->ZASOB_OPIS, $r->z__SORT_PRIO, $r->ZASOB_DESC_PL);
|
|
|
- $foundTbls[$r->ZASOB_PARENT_ID]->setFieldPerms($r->ID_ZASOB, $r->FORM_TREAT);
|
|
|
- $tableConfig['fields'];// $this->_fields
|
|
|
- $tableConfig['virtualFieldsIdList'];// $this->_virtualFieldsIdList
|
|
|
- //$tableConfig['types'];// $this->_types
|
|
|
- }
|
|
|
- }
|
|
|
- if (empty($tableConfig)) {
|
|
|
- throw new Exception("Brak danych konfiguracyjnych do tabeli nr {$idTable} #TACL" . __LINE__);
|
|
|
- }
|
|
|
+ if (empty($tableConfig)) throw new Exception("Brak danych konfiguracyjnych do tabeli nr {$idTable} #TACL" . __LINE__);
|
|
|
+ // if (empty($tableConfig)) {
|
|
|
+ // $zasobObj = ProcesHelper::getZasobTableInfo($idTable);
|
|
|
+ // if (!$zasobObj) {
|
|
|
+ // return null;// TODO: throw new Exception("Zasob TABELA ID={$idTable} nie istnieje");
|
|
|
+ // }
|
|
|
+ // $tableConfig['db'] = $zasobObj->P__ID;
|
|
|
+ // $tableConfig['name'] = $zasobObj->DESC;
|
|
|
+ // $tableConfig['label'] = $zasobObj->DESC_PL;
|
|
|
+ // $tableConfig['opis'] = $zasobObj->OPIS;
|
|
|
+ //
|
|
|
+ // $userAcl = User::getAcl();
|
|
|
+ // $userPermsForTable = $userAcl->getPermsForTable($idTable);
|
|
|
+ // if (!$userPermsForTable) {
|
|
|
+ // return null;// TODO: throw new Exception("Brak uprawnień do pól Tabeli nr {$idTable} '{$zasobObj->DESC}'");
|
|
|
+ // }
|
|
|
+ // echo'<pre>$userPermsForTable('.$idTable.') ';print_r($userPermsForTable);echo'</pre>';
|
|
|
+ // if(0){// TODO: from UserAcl big query
|
|
|
+ // $foundTbls[$r->ZASOB_PARENT_ID]->addField($r->ID_ZASOB, $r->ZASOB_DESC, $r->ZASOB_OPIS, $r->z__SORT_PRIO, $r->ZASOB_DESC_PL);
|
|
|
+ // $foundTbls[$r->ZASOB_PARENT_ID]->setFieldPerms($r->ID_ZASOB, $r->FORM_TREAT);
|
|
|
+ // $tableConfig['fields'];// $this->getFields()
|
|
|
+ // $tableConfig['virtualFieldsIdList'];// $this->_virtualFieldsIdList
|
|
|
+ // //$tableConfig['types'];// $this->_types
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ if (empty($tableConfig)) throw new Exception("Brak danych konfiguracyjnych do tabeli nr {$idTable} #TACL" . __LINE__);
|
|
|
$obj = new TableAcl($idTable);
|
|
|
$obj->fromArray($tableConfig);
|
|
|
$obj->getRootTableName();
|
|
|
@@ -982,12 +975,20 @@ class TableAcl extends Core_AclBase {
|
|
|
}
|
|
|
|
|
|
public function init($force = false) {
|
|
|
+ // DBG::log("DBG INIT - init ({$this->_zasobID}, {$this->_rootTableName})");
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fieldsInit($force = false) {
|
|
|
+ if (null !== $this->_executed_fieldsInit) return;
|
|
|
+ $this->_executed_fieldsInit = true;
|
|
|
+
|
|
|
+ DBG::log("DBG INIT - fieldsInit ({$this->_zasobID}, {$this->_rootTableName})");
|
|
|
$this->loadSchema();
|
|
|
if (empty($this->_fields)) {
|
|
|
$this->_types = array();// clear _types @see $this->isInitialized
|
|
|
$userAcl = User::getAcl();
|
|
|
$fieldsConfig = $userAcl->getPermsForTable($this->_zasobID);
|
|
|
- DBG::log(['msg'=>"INIT({$this->_zasobID})::initFieldsFromConfig \$fieldsConfig", '$fieldsConfig'=>$fieldsConfig]);
|
|
|
+ // DBG::log(['msg'=>"INIT({$this->_zasobID})::initFieldsFromConfig \$fieldsConfig", '$fieldsConfig'=>$fieldsConfig]);
|
|
|
$this->initFieldsFromConfig($fieldsConfig);
|
|
|
//DBG::_('DBG_SCH', '1', "INIT::\$fieldsConfig({$this->_zasobID}) fields(".count($this->_fields).")", $this, __CLASS__, __FUNCTION__, __LINE__ );
|
|
|
}
|
|
|
@@ -997,16 +998,16 @@ class TableAcl extends Core_AclBase {
|
|
|
}
|
|
|
DBG::simpleLog('auth', "TableAcl::init(name: '{$this->_name}')");
|
|
|
|
|
|
- DBG::log(['msg'=>"INIT({$this->_zasobID}):: \$this", '$this'=>$this, 'name'=>$this->getName()]);
|
|
|
+ // DBG::log(['msg'=>"INIT({$this->_zasobID}):: \$this", '$this'=>$this, 'name'=>$this->getName()]);
|
|
|
$ds = $this->getDataSource();
|
|
|
- DBG::log(['msg'=>"INIT({$this->_zasobID})::getDataSource \$ds", '$ds'=>$ds]);
|
|
|
+ // DBG::log(['msg'=>"INIT({$this->_zasobID})::getDataSource \$ds", '$ds'=>$ds]);
|
|
|
$this->_types = $ds->getFieldTypes();
|
|
|
- DBG::log(['msg'=>"INIT({$this->_zasobID})::getFieldTypes \$this->_types", '$this->_types'=>$this->_types]);
|
|
|
+ // DBG::log(['msg'=>"INIT({$this->_zasobID})::getFieldTypes \$this->_types", '$this->_types'=>$this->_types]);
|
|
|
|
|
|
uasort($this->_fields, array($this, 'sortFieldsCallback'));
|
|
|
|
|
|
$this->_fixTypes();
|
|
|
- DBG::log(['msg'=>"INIT({$this->_zasobID})::after fixTypes \$this->_types", '$this->_types'=>$this->_types]);
|
|
|
+ // DBG::log(['msg'=>"INIT({$this->_zasobID})::after fixTypes \$this->_types", '$this->_types'=>$this->_types]);
|
|
|
|
|
|
$this->save();
|
|
|
}
|
|
|
@@ -1198,12 +1199,12 @@ class TableAcl extends Core_AclBase {
|
|
|
*/
|
|
|
function save() {
|
|
|
$_SESSION['TableAcl_cache'][$this->_zasobID] = $this->toArray();
|
|
|
- DBG::log("save(name='{$_SESSION['TableAcl_cache'][$this->_zasobID]['name']}')");
|
|
|
+ // DBG::log("save(name='{$_SESSION['TableAcl_cache'][$this->_zasobID]['name']}')");
|
|
|
// DBG::simpleLog('auth', "TableAcl::save(name: '{$this->_name}')");
|
|
|
}
|
|
|
|
|
|
public function getFieldTypeById($fieldID) {
|
|
|
- if (!array_key_exists($fieldID, $this->_fields)) return null;
|
|
|
+ if (!array_key_exists($fieldID, $this->getFields())) return null;
|
|
|
$fieldName = $this->_fields[$fieldID]['name'];
|
|
|
if (!array_key_exists($fieldName, $this->_types)) return null;
|
|
|
return $this->_types[$fieldName];
|
|
|
@@ -1222,13 +1223,13 @@ class TableAcl extends Core_AclBase {
|
|
|
public function getVisibleFieldListByIdZasob() {
|
|
|
$cols = array();
|
|
|
$id = 0;
|
|
|
- foreach ($this->_fields as $kFieldID => $vField) {
|
|
|
+ foreach ($this->getFields() as $kFieldID => $vField) {
|
|
|
if ($vField['name'] == 'ID') {
|
|
|
$id = $kFieldID;
|
|
|
}
|
|
|
}
|
|
|
$cols[$id] = 'ID';
|
|
|
- foreach ($this->_fields as $kFieldID => $vField) {
|
|
|
+ foreach ($this->getFields() as $kFieldID => $vField) {
|
|
|
if ($vField['name'] == 'ID') {
|
|
|
continue;
|
|
|
}
|
|
|
@@ -1255,7 +1256,7 @@ class TableAcl extends Core_AclBase {
|
|
|
public function getRealFieldList() {
|
|
|
$cols = array();
|
|
|
$cols[] = 'ID';
|
|
|
- foreach ($this->_fields as $kFieldID => $vField) {
|
|
|
+ foreach ($this->getFields() as $kFieldID => $vField) {
|
|
|
if ($vField['name'] == 'ID') {
|
|
|
continue;
|
|
|
}
|
|
|
@@ -1268,12 +1269,12 @@ class TableAcl extends Core_AclBase {
|
|
|
|
|
|
public function getFieldListByIdZasob() {
|
|
|
$cols = array();
|
|
|
- foreach ($this->_fields as $idField => $fld) {
|
|
|
+ foreach ($this->getFields() as $idField => $fld) {
|
|
|
if ($fld['name'] == 'ID') {
|
|
|
$cols[$idField] = 'ID';
|
|
|
}
|
|
|
}
|
|
|
- foreach ($this->_fields as $idField => $fld) {
|
|
|
+ foreach ($this->getFields() as $idField => $fld) {
|
|
|
if ($fld['name'] == 'ID') continue;
|
|
|
$cols[$idField] = $fld['name'];
|
|
|
}
|
|
|
@@ -1281,12 +1282,12 @@ class TableAcl extends Core_AclBase {
|
|
|
}
|
|
|
public function getRealFieldListByIdZasob() {
|
|
|
$cols = array();
|
|
|
- foreach ($this->_fields as $idField => $fld) {
|
|
|
+ foreach ($this->getFields() as $idField => $fld) {
|
|
|
if ($fld['name'] == 'ID') {
|
|
|
$cols[$idField] = 'ID';
|
|
|
}
|
|
|
}
|
|
|
- foreach ($this->_fields as $idField => $fld) {
|
|
|
+ foreach ($this->getFields() as $idField => $fld) {
|
|
|
if ($fld['name'] == 'ID') continue;
|
|
|
if (array_key_exists($fld['name'], $this->_types)) {
|
|
|
$cols[$idField] = $fld['name'];
|
|
|
@@ -1297,7 +1298,7 @@ class TableAcl extends Core_AclBase {
|
|
|
|
|
|
public function getVirtualFieldListByIdZasob() {
|
|
|
$cols = array();
|
|
|
- foreach ($this->_fields as $kFieldID => $vField) {
|
|
|
+ foreach ($this->getFields() as $kFieldID => $vField) {
|
|
|
if ($vField['name'] == 'ID') {
|
|
|
continue;
|
|
|
}
|
|
|
@@ -1314,7 +1315,7 @@ class TableAcl extends Core_AclBase {
|
|
|
|
|
|
public function getFieldLabel($fieldName) {
|
|
|
$idField = $this->getFieldIdByName($fieldName);
|
|
|
- if (array_key_exists($idField, $this->_fields)) {
|
|
|
+ if (array_key_exists($idField, $this->getFields())) {
|
|
|
if (!empty($this->_fields[$idField]['label'])) {
|
|
|
return $this->_fields[$idField]['label'];
|
|
|
}
|
|
|
@@ -1324,7 +1325,7 @@ class TableAcl extends Core_AclBase {
|
|
|
|
|
|
public function getFieldOpis($fieldName) {
|
|
|
$idField = $this->getFieldIdByName($fieldName);
|
|
|
- if (array_key_exists($idField, $this->_fields)) {
|
|
|
+ if (array_key_exists($idField, $this->getFields())) {
|
|
|
if (!empty($this->_fields[$idField]['opis'])) {
|
|
|
return $this->_fields[$idField]['opis'];
|
|
|
}
|
|
|
@@ -1374,12 +1375,13 @@ class TableAcl extends Core_AclBase {
|
|
|
}
|
|
|
|
|
|
public function fromArray($arr) {
|
|
|
- DBG::log("fromArray(name='{$arr['name']}')");
|
|
|
+ // DBG::log("fromArray(name='{$arr['name']}')");
|
|
|
$this->_db = $arr['db'];
|
|
|
$this->_name = $arr['name'];
|
|
|
$this->_rootTableName = V::get('_rootTableName', null, $arr);
|
|
|
$this->_label = $arr['label'];
|
|
|
$this->_opis = $arr['opis'];
|
|
|
+ $this->_executed_fieldsInit = V::get('_executed_fieldsInit', null, $arr);
|
|
|
$this->_fields = V::get('fields', array(), $arr);
|
|
|
$this->_virtualFieldsIdList = V::get('virtualFieldsIdList', array(), $arr);
|
|
|
$this->_types = V::get('types', array(), $arr);
|
|
|
@@ -1392,6 +1394,7 @@ class TableAcl extends Core_AclBase {
|
|
|
$arr['_rootTableName'] = $this->_rootTableName;
|
|
|
$arr['label'] = $this->_label;
|
|
|
$arr['opis'] = $this->_opis;
|
|
|
+ if ($this->_executed_fieldsInit) $arr['_executed_fieldsInit'] = $this->_executed_fieldsInit;
|
|
|
$arr['fields'] = $this->_fields;
|
|
|
$arr['virtualFieldsIdList'] = $this->_virtualFieldsIdList;
|
|
|
$arr['types'] = $this->_types;
|