* @since Version 2.0 */ class sysUsersCfg { private $boolCFG = array(); private $tableCFG = array(); private $pluginCFG = array(); private $valueCFG = array(); private $baseBoolCFG = array( 'leftmenu' => 1, 'fullTable' => 0, //'bShowBtnLabels' => 1, ); private $baseTableCFG = array( /* SYSTEM SITE MODULES */ 'sysSiteModules'=> array(), 'sysSiteMapPUB' => array(), 'sysSiteMapCMS' => array(), /* CMS TABLE CFG */ 'cmsClassificators'=> array(), 'cmsMessages' => array(), 'cmsSubscriptions' => array(), 'cmsTextManager' => array(), 'cmsMailsConstructor' => array(), 'cmsSvnProjectManager' => array(), /* Association */ 'cmsApartmentsMetersMeasurements' => array(), 'cmsAssociationEmails' => array(), 'cmsApartmentsMeters' => array(), 'cmsApartments' => array(), /* PUB - for companies and pub users */ 'cmsAccountActivation' => array(), 'cmsAccountManager' => array(), 'cmsAccountsToBill' => array(), 'cmsPubUsers' => array(), 'cmsPermissions' => array(), 'cmsPermissionGroups' => array(), //'cmsCompanies' => array(), 'cmsReportsDefiner' => array(), /* CMS - mail modules */ 'cmsMailEngineSent' => array(), 'cmsMailEngine' => array(), /* CMS USERS */ //'sysUsers' => array(), 'sysUsersManager' => array(), 'sysPermissionGroups' => array(), 'sysPermissions'=> array(), 'sysIpFilter' => array(), /* SITE BASE */ 'sysApcOverview' => array(), 'sysLanguages' => array(), 'sysMenus' => array(), 'sysTranslations' => array(), 'sysTranslationsPub'=> array(), 'sysActionLog' => array(), ); public $tablesToControllers = array( // Dummy module Actual module Function to call //'pubClassificatorsTypes' => array('m' => 'pubClassificators', 'f' => 'tableFieldsForTypes'), 'sysSiteMapPUB' => array('m' => 'sysSiteMap', 'f' => 'getTableFieldsPub'), 'sysSiteMapCMS' => array('m' => 'sysSiteMap', 'f' => 'getTableFields'), ); // m - minimize, e - enabled, c - column private $basePluginCFG = array( /*'cmsPubUsers' => array('c' => 1, 'e' => true, 'm' => false), 'cmsSuggestions' => array('c' => 3, 'e' => true, 'm' => false), 'cmsSuggestionsComments' => array('c' => 3, 'e' => true, 'm' => false), 'cmsMailEngine' => array('c' => 3, 'e' => false, 'm' => false),*/ ); public $baseValuesCFG = array( 'iRecordsPerPage' => 20, 'sThemetitle' => '', ); static $baseValuesCFG_hidden = array( 'sThemetitle', ); public $siteMapId = array( 'cmsMailEngine' => 259, ); private $userId; public $oModule; const bools = 'bools'; const tables = 'tables'; const plugins = 'plugins'; const values = 'values'; /** * Class constructor * * @param int|bool $userId - user id to init */ public function __construct($userId = false) { $this->oModule = new sysUsersModule(); $this->initUserCfg($userId); } /** * Function to initialize config class * * @author Mareks Keišs * @category sysUsersCfg Controller * @param bool $userId - init class for specific user * @return array of data */ private function initUserCfg($userId = false){ if($userId){ $this->userId = $userId; if($cfg = $this->oModule->getUserCfg($this->userId)){ $cfg = unserialize($cfg); } if(isset($cfg[self::bools]) && is_array($cfg[self::bools])){ $ucfg = array_intersect_key($cfg[self::bools], $this->baseBoolCFG); $this->boolCFG = array_merge($this->baseBoolCFG, $ucfg); }else{ $this->boolCFG = $this->baseBoolCFG; } if(isset($cfg[self::tables]) && is_array($cfg[self::tables])){ $ucfg = array_intersect_key($cfg[self::tables], $this->baseTableCFG); $this->tableCFG = array_merge($this->baseTableCFG, $ucfg); }else{ $this->tableCFG = $this->baseTableCFG; } if(isset($cfg[self::plugins]) && is_array($cfg[self::plugins])){ $ucfg = array_intersect_key($cfg[self::plugins], $this->basePluginCFG); $this->pluginCFG = array_merge($this->basePluginCFG, $ucfg); }else{ $this->pluginCFG = $this->basePluginCFG; } if(isset($cfg[self::values]) && is_array($cfg[self::values])){ $ucfg = array_intersect_key($cfg[self::values], $this->baseValuesCFG); $this->valueCFG = array_merge($this->baseValuesCFG, $ucfg); }else{ $this->valueCFG = $this->baseValuesCFG; } return true; } return false; } /** * Function to save user config * * @author Mareks Keišs * @category sysUsersCfg Controller * @return bool true / false */ public function saveUserCFG(){ if($this->userId){ $data = $this->getUserCFG(); return $this->oModule->saveUserCFG($this->userId, array('user_cfg' => serialize($data))); } return false; } /** * Function to get whole user config * * @author Mareks Keišs * @category sysUsersCfg Controller * @param mixed $type - direct type access * @return bool true / false */ public function getUserCFG($type = false){ $cfg = array( self::bools => $this->boolCFG, self::tables => $this->tableCFG, self::plugins => $this->pluginCFG, self::values => $this->valueCFG, ); if($type && isset($cfg[$type])){ return $cfg[$type]; }else{ return $cfg; } } /** * Function to get whole base config * * @author Mareks Keišs * @category sysUsersCfg Controller * @param mixed $type - direct type access * @return bool true / false */ 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 * * @author Mareks Keišs * @category sysUsersCfg Controller * @param bool $name - property name * @return bool true / false */ public function getProperty($name = false){ if($name && isset($this->boolCFG[$name])){ return $this->boolCFG[$name]; } return false; } /** * Function to set bools user cfg value * * @author Mareks Keišs * @category sysUsersCfg Controller * @param string $name - property name * @param mixed $value - property value * @return bool true / false */ 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 * * @author Mareks Keišs * @category sysUsersCfg Controller * @param bool $name - property name * @return bool true / false */ public function getTableProperty($name = false){ if($name && isset($this->tableCFG[$name])){ return $this->tableCFG[$name]; } return false; } /** * Function to set tables user cfg value * * @author Mareks Keišs * @category sysUsersCfg Controller * @param string $name - property name * @param mixed $value - property value * @return bool true / false */ 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 * * @author Mareks Keišs * @category sysUsersCfg Controller * @param bool $name - property name * @return bool true / false */ public function getValueProperty($name = false){ if($name && isset($this->valueCFG[$name])){ return $this->valueCFG[$name]; } return false; } /** * Function to set value user cfg value * * @author Mareks Keišs * @category sysUsersCfg Controller * @param string $name - property name * @param mixed $value - property value * @return bool true / false */ private function setValueProperty($name, $value){ if($name && isset($this->baseValuesCFG[$name])){ $this->valueCFG[$name] = $value; return true; } return false; } /** * Function to set user property * * @author Mareks Keišs * @category sysUsersCfg Controller * @param mixed $prop - property name / array of properties * @param bool $value - property value * @return bool true / false */ 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 * * @author Mareks Keišs * @category sysUsersCfg Controller * @param array $prop - properties name / array of properties * @param mixed $type - properties type * @return bool true / false */ 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; } // Save user config $this->saveUserCFG(); } return false; } /** * Function to set properties to core class object * * @author Mareks Keišs * @category sysUsersCfg Controller * @param object $coreObj - core module object * @return bool true */ public function setupPropertiesToCore(&$coreObj){ if(!!$coreObj){ if(!empty($this->valueCFG['iRecordsPerPage'])) $coreObj->cmsTableRecordsPerPage = $this->valueCFG['iRecordsPerPage']; /*if(isset($this->boolCFG['bShowBtnLabels'])) $coreObj->oView->SHOW_BTN_LABELS = $this->boolCFG['bShowBtnLabels'];*/ } return true; } }