493 lines
15 KiB
PHP
493 lines
15 KiB
PHP
<?php
|
|
|
|
namespace BRSystems\Core\App\pubUsers\inc;
|
|
|
|
use BRSystems\Core\Library\cCore\cCore;
|
|
|
|
/**
|
|
* pubUsersCfg Controller
|
|
*
|
|
* @category pubUsersCfg Controller
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @since Version 2.0
|
|
*/
|
|
class pubUsersCfg
|
|
{
|
|
private $boolCFG = [];
|
|
private $tableCFG = [];
|
|
private $pluginCFG = [];
|
|
private $valueCFG = [];
|
|
private $valueAdvCFG = [];
|
|
|
|
private $baseBoolCFG = [
|
|
'bFullScreen' => 1,
|
|
'bUseDarkMode' => 0,
|
|
/*'logoAnimation' => 1,
|
|
'logoSmall' => 0,*/
|
|
'bShowBtnLabels' => 1,
|
|
];
|
|
const TBL_TRANSACTION = 'pubTransaction';
|
|
public $baseTableCFG = [
|
|
// Exact module name
|
|
'pubLursoftDataReq' => [],
|
|
'pubUserManager' => [],
|
|
self::TBL_TRANSACTION => [],
|
|
'pubPartners' => [],
|
|
'pubObjects' => [],
|
|
'pubBalance' => [],
|
|
'pubBugs' => [],
|
|
'pubRoutePages' => [],
|
|
'pubIncDocuments' => [],
|
|
'pubDocuments' => [],
|
|
'pubTimeAccounting' => [],
|
|
'pubClassificators' => [],
|
|
'pubAccountingCl' => [],
|
|
'pubAccounting' => [],
|
|
'pubVisitorsRegister' => [],
|
|
'pubApartmentsMetersMeasurements' => [],
|
|
'pubApartmentsMeters' => [],
|
|
|
|
// Dummy module name
|
|
'pubClassificatorsTypes' => [],
|
|
'pubClassificatorsProjects' => [],
|
|
'pubClassificatorsContracts' => [],
|
|
'pubClassificatorsTransports' => [],
|
|
];
|
|
public $tablesToControllers = [
|
|
// Dummy module Actual module Function to call
|
|
'pubClassificatorsTypes' => ['m' => 'pubClassificators', 'f' => 'tableFieldsForTypes'],
|
|
'pubClassificatorsTransports' => ['m' => 'pubClassificators', 'f' => 'tableFieldsForTransports'],
|
|
'pubClassificatorsProjects' => ['m' => 'pubClassificators', 'f' => 'tableFieldsForProjects'],
|
|
'pubClassificatorsContracts' => ['m' => 'pubClassificators', 'f' => 'tableFieldsForContracts'],
|
|
];
|
|
// m - minimize, e - enabled, c - column
|
|
private $basePluginCFG = [];
|
|
|
|
const BaseValuesFavoriteCompanyList = 'vFavoriteCompanyList';
|
|
public $baseValuesCFG = [
|
|
'iRecordsPerPage' => 20,
|
|
'iActiveYear' => [],
|
|
self::BaseValuesFavoriteCompanyList => [],
|
|
];
|
|
public $baseValuesAdvCFG = [
|
|
'vDashboardCFG' => [],
|
|
'vAdditionalTableData' => [],
|
|
'vProfileData' => [],
|
|
'vAddressBook' => [],
|
|
];
|
|
public $siteMapId = [
|
|
'cmsMailEngine' => 259,
|
|
];
|
|
|
|
public $module;
|
|
private $controller;
|
|
private $userId;
|
|
|
|
const bools = 'bools';
|
|
const tables = 'tables';
|
|
const plugins = 'plugins';
|
|
const values = 'values';
|
|
const values_adv = 'values_adv';
|
|
|
|
const ADV_KEY_TBL = 'vAdditionalTableData';
|
|
const ADV_PROP_SORT = 'sLastSortCfg';
|
|
|
|
/**
|
|
* Class constructor
|
|
* @param object|pubUsersController $ctrl - user class controller object
|
|
* @param int|bool $userId - user id to init
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category pubUsersCfg Controller
|
|
*/
|
|
public function __construct($ctrl, $userId = false)
|
|
{
|
|
$this->controller = $ctrl;
|
|
$this->module = new pubUsersModule($ctrl->selCompId);
|
|
|
|
$this->initUserCfg($userId);
|
|
}
|
|
|
|
/**
|
|
* Function to initialize config class
|
|
*
|
|
* @param bool $userId - init class for specific user
|
|
* @return bool
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category pubUsersCfg Controller
|
|
*/
|
|
private function initUserCfg($userId = false)
|
|
{
|
|
|
|
if ($userId) {
|
|
$this->userId = $userId;
|
|
if ($cfg = $this->module->getUserCfg($this->userId)) {
|
|
$cfg = unserialize($cfg);
|
|
}
|
|
|
|
if (isset($cfg[self::bools]) && is_array($cfg[self::bools])) {
|
|
$vUCfg = array_intersect_key($cfg[self::bools], $this->baseBoolCFG);
|
|
$this->boolCFG = array_merge($this->baseBoolCFG, $vUCfg);
|
|
} else {
|
|
$this->boolCFG = $this->baseBoolCFG;
|
|
}
|
|
if (isset($cfg[self::tables]) && is_array($cfg[self::tables])) {
|
|
$vUCfg = array_intersect_key($cfg[self::tables], $this->baseTableCFG);
|
|
$this->tableCFG = array_merge($this->baseTableCFG, $vUCfg);
|
|
} else {
|
|
$this->tableCFG = $this->baseTableCFG;
|
|
}
|
|
if (isset($cfg[self::plugins]) && is_array($cfg[self::plugins])) {
|
|
$vUCfg = array_intersect_key($cfg[self::plugins], $this->basePluginCFG);
|
|
$this->pluginCFG = array_merge($this->basePluginCFG, $vUCfg);
|
|
} else {
|
|
$this->pluginCFG = $this->basePluginCFG;
|
|
}
|
|
if (isset($cfg[self::values]) && is_array($cfg[self::values])) {
|
|
$vUCfg = array_intersect_key($cfg[self::values], $this->baseValuesCFG);
|
|
$this->valueCFG = array_merge($this->baseValuesCFG, $vUCfg);
|
|
} else {
|
|
$this->valueCFG = $this->baseValuesCFG;
|
|
}
|
|
if (isset($cfg[self::values_adv]) && is_array($cfg[self::values_adv])) {
|
|
$vUCfg = array_intersect_key($cfg[self::values_adv], $this->baseValuesAdvCFG);
|
|
$this->valueAdvCFG = array_merge($this->baseValuesAdvCFG, $vUCfg);
|
|
} else {
|
|
$this->valueAdvCFG = $this->baseValuesAdvCFG;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Function to save user config
|
|
*
|
|
* @return bool true / false
|
|
* @category pubUsersCfg Controller
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
*/
|
|
public function saveUserCFG()
|
|
{
|
|
|
|
if ($this->userId) {
|
|
$data = $this->getUserCFG();
|
|
return $this->module->saveUserCFG($this->userId, array('user_cfg' => serialize($data)));
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Function to get whole user config
|
|
*
|
|
* @param mixed $type - direct type access
|
|
* @return array|bool
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category pubUsersCfg Controller
|
|
*/
|
|
public function getUserCFG($type = false)
|
|
{
|
|
$cfg = array(
|
|
self::bools => $this->boolCFG,
|
|
self::tables => $this->tableCFG,
|
|
self::plugins => $this->pluginCFG,
|
|
self::values => $this->valueCFG,
|
|
self::values_adv => $this->valueAdvCFG,
|
|
);
|
|
|
|
if ($type && isset($cfg[$type])) {
|
|
return $cfg[$type];
|
|
} else {
|
|
return $cfg;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Function to get whole base config
|
|
*
|
|
* @param mixed $type - direct type access
|
|
* @return array|bool
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category pubUsersCfg Controller
|
|
*/
|
|
public function getBaseCFG($type = false)
|
|
{
|
|
$cfg = array(
|
|
self::bools => $this->baseBoolCFG,
|
|
self::tables => $this->baseTableCFG,
|
|
self::plugins => $this->basePluginCFG,
|
|
self::values => $this->baseValuesCFG,
|
|
);
|
|
|
|
if ($type && isset($cfg[$type])) {
|
|
return $cfg[$type];
|
|
} else {
|
|
return $cfg;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Function to get bools user cfg value
|
|
*
|
|
* @param bool $name - property name
|
|
* @return bool true / false
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category pubUsersCfg Controller
|
|
*/
|
|
public function getProperty($name = false)
|
|
{
|
|
if ($name && isset($this->boolCFG[$name])) {
|
|
return $this->boolCFG[$name];
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Function to set bools user cfg value
|
|
*
|
|
* @param string $name - property name
|
|
* @param mixed $value - property value
|
|
* @return bool true / false
|
|
* @category pubUsersCfg Controller
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
*/
|
|
private function setProperty($name, $value)
|
|
{
|
|
if ($name && isset($this->baseBoolCFG[$name])) {
|
|
$this->boolCFG[$name] = $value;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Function to get tables user cfg value
|
|
*
|
|
* @param bool $name - property name
|
|
* @return bool true / false
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category pubUsersCfg Controller
|
|
*/
|
|
public function getTableProperty($name = false)
|
|
{
|
|
|
|
if ($name && isset($this->tableCFG[$name])) {
|
|
return $this->tableCFG[$name];
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Function to set tables user cfg value
|
|
*
|
|
* @param string $name - property name
|
|
* @param mixed $value - property value
|
|
* @return bool true / false
|
|
* @category pubUsersCfg Controller
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
*/
|
|
private function setTableProperty($name, $value)
|
|
{
|
|
if ($name && isset($this->baseTableCFG[$name])) {
|
|
$this->tableCFG[$name] = $value;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Function to get value user cfg value
|
|
*
|
|
* @param bool $name - property name
|
|
* @return bool true / false
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category pubUsersCfg Controller
|
|
*/
|
|
public function getValueProperty($name = false)
|
|
{
|
|
if ($name && isset($this->valueCFG[$name])) {
|
|
return $this->valueCFG[$name];
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Function to set value user cfg value
|
|
*
|
|
* @param string $name - property name
|
|
* @param mixed $value - property value
|
|
* @return bool true / false
|
|
* @category pubUsersCfg Controller
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
*/
|
|
private function setValueProperty($name, $value)
|
|
{
|
|
if ($name && isset($this->baseValuesCFG[$name])) {
|
|
$this->valueCFG[$name] = $value;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Function to set user property
|
|
*
|
|
* @param mixed $prop - property name / array of properties
|
|
* @param bool $value - property value
|
|
* @return bool true / false
|
|
* @category pubUsersCfg Controller
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
*/
|
|
public function addProperties($prop, $value = false)
|
|
{
|
|
|
|
$bTable = getP("table");
|
|
|
|
// Handle array save
|
|
if (is_array($prop)) {
|
|
if (count($prop)) {
|
|
foreach ($prop as $k => $v) {
|
|
if ($bTable) {
|
|
$this->setTableProperty($k, $v);
|
|
} else {
|
|
$this->setProperty($k, $v);
|
|
}
|
|
}
|
|
|
|
$this->saveUserCFG();
|
|
}
|
|
return true;
|
|
|
|
// Handle individual prop value
|
|
} elseif ($prop && $value) {
|
|
|
|
if ($bTable) {
|
|
$this->setTableProperty($prop, $value);
|
|
} else {
|
|
$this->setProperty($prop, $value);
|
|
}
|
|
|
|
$this->saveUserCFG();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Function to set user property advanced
|
|
*
|
|
* @param array $prop - properties name / array of properties
|
|
* @param mixed $type - properties type
|
|
* @return bool true / false
|
|
* @category pubUsersCfg Controller
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
*/
|
|
public function addPropertiesAdvanced($prop, $type = false)
|
|
{
|
|
|
|
if ($type && $prop && count($prop)) {
|
|
|
|
switch ($type) {
|
|
case self::plugins:
|
|
foreach ($prop as $k => $v) {
|
|
if ($k && isset($this->basePluginCFG[$k])) {
|
|
unset($this->pluginCFG[$k]);
|
|
$this->pluginCFG[$k] = $v;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case self::values:
|
|
foreach ($prop as $k => $v) {
|
|
if ($k && isset($this->baseValuesCFG[$k])) {
|
|
//unset($this->valueCFG[$k]);
|
|
$this->valueCFG[$k] = $v;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case self::values_adv:
|
|
foreach ($prop as $k => $v) {
|
|
if ($k && isset($this->baseValuesAdvCFG[$k])) {
|
|
$this->valueAdvCFG[$k] = $v;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
// Save user config
|
|
return $this->saveUserCFG();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Function to set properties to core class object
|
|
*
|
|
* @param cCore $coreObj - core module object
|
|
* @return void
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category pubUsersCfg Controller
|
|
*/
|
|
public function setupPropertiesToCore(cCore &$coreObj): void
|
|
{
|
|
// NOT superuser
|
|
if (!$coreObj->oUser->suser->suser) {
|
|
|
|
$vUpdateData = [];
|
|
|
|
// Update user activity time
|
|
$iActivityTime = $coreObj->oUser->suser->activity_time;
|
|
if (!$iActivityTime || $iActivityTime < time()) {
|
|
$iActivityTime = time() + 60 * 5;
|
|
$coreObj->oUser->suser->activity_time = $iActivityTime;
|
|
$vUpdateData['user_last_login'] = time();
|
|
}
|
|
|
|
// Update user last lang ID
|
|
$vUserData = $coreObj->oUser->suser->data;
|
|
if (!!$vUserData && isset($vUserData['user_lang_id'])) {
|
|
if ($coreObj->uri_data['p_lang_id'] != $vUserData['user_lang_id']) {
|
|
$vUpdateData['user_lang_id'] = $coreObj->uri_data['p_lang_id'];
|
|
$coreObj->oUser->suser->data['user_lang_id'] = $coreObj->uri_data['p_lang_id'];
|
|
}
|
|
}
|
|
|
|
// Update user db record
|
|
if (!!$vUpdateData) {
|
|
$this->module->updateUserDataById($coreObj->oUser->getUser(), $vUpdateData);
|
|
}
|
|
}
|
|
|
|
|
|
if (!empty($this->valueCFG['iRecordsPerPage'])) {
|
|
$coreObj->pubTableRecordsPerPage = $this->valueCFG['iRecordsPerPage'];
|
|
}
|
|
|
|
// Check advanced values for setup
|
|
if (!empty($this->valueAdvCFG['vAdditionalTableData'])) {
|
|
// Get Table object
|
|
$vTableSettings = [];
|
|
if (
|
|
!empty($coreObj->uri_data['mod_code']) &&
|
|
!empty($this->valueAdvCFG['vAdditionalTableData'][$coreObj->uri_data['mod_code']])
|
|
) {
|
|
$vTableSettings = $this->valueAdvCFG['vAdditionalTableData'][$coreObj->uri_data['mod_code']];
|
|
}
|
|
|
|
// Reset table row count
|
|
if (!empty($vTableSettings['iRecordsPerPage'])) {
|
|
$coreObj->pubTableRecordsPerPage = $vTableSettings['iRecordsPerPage'];
|
|
}
|
|
}
|
|
|
|
|
|
if (isset($this->boolCFG['bShowBtnLabels'])) {
|
|
$coreObj->oView->SHOW_BTN_LABELS = $this->boolCFG['bShowBtnLabels'];
|
|
}
|
|
}
|
|
}
|