File indexing completed on 2024-12-22 05:33:28
0001 <?php 0002 0003 /** 0004 * ocs-webserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-webserver. 0009 * 0010 * This program is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as 0012 * published by the Free Software Foundation, either version 3 of the 0013 * License, or (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 **/ 0023 class Backend_StoreController extends Local_Controller_Action_Backend 0024 { 0025 0026 const RESULT_OK = "OK"; 0027 const RESULT_ERROR = "ERROR"; 0028 const DATA_ID_NAME = 'store_id'; 0029 0030 /** @var Default_Model_DbTable_ConfigStore */ 0031 protected $_model; 0032 protected $_modelName = 'Default_Model_DbTable_ConfigStore'; 0033 protected $_pageTitle = 'Manage Store Config'; 0034 0035 public function init() 0036 { 0037 $this->_model = new $this->_modelName(); 0038 0039 $this->view->pageTitle = $this->_pageTitle; 0040 0041 parent::init(); 0042 } 0043 0044 public function indexAction() 0045 { 0046 0047 } 0048 0049 public function createAction() 0050 { 0051 $jTableResult = array(); 0052 try { 0053 $allParams = $this->getAllParams(); 0054 $resultWalk = array_walk($allParams, function (&$value) { 0055 $value = strlen($value) == 0 ? null : $value; 0056 }); 0057 if (false === $resultWalk) { 0058 throw new Exception('array_walk through input parameters failed.'); 0059 } 0060 //$newRow = $this->_model->createRow($allParams); 0061 //$result = $newRow->save(); 0062 $newRow = $this->_model->save($allParams); 0063 0064 $jTableResult['Result'] = self::RESULT_OK; 0065 $jTableResult['Record'] = $newRow->toArray(); 0066 } catch (Exception $e) { 0067 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0068 $translate = Zend_Registry::get('Zend_Translate'); 0069 $jTableResult['Result'] = self::RESULT_ERROR; 0070 $jTableResult['Message'] = $translate->_('Error while processing data.'); 0071 } 0072 0073 $this->_helper->json($jTableResult); 0074 } 0075 0076 public function initcacheAction() 0077 { 0078 $allStoresCat = $this->_model->fetchAllStoresAndCategories(true); 0079 $allStoresConfig = $this->_model->fetchAllStoresConfigArray(true); 0080 0081 $modelPCat = new Default_Model_ProjectCategory(); 0082 foreach ($allStoresConfig as $config) { 0083 $modelPCat->fetchCategoryTreeForStore($config['store_id'], true); 0084 $this->_model->fetchConfigForStore($config['store_id'], true); 0085 } 0086 } 0087 0088 public function updateAction() 0089 { 0090 $jTableResult = array(); 0091 try { 0092 $values = $this->getAllParams(); 0093 0094 foreach ($values as $key => $value) { 0095 if ($value == '') { 0096 $values[$key] = new Zend_Db_Expr('NULL'); 0097 } 0098 } 0099 0100 // patch checkbox is_show_title get no parameter when is_show_title = 0 0101 if (!isset($values['is_show_title'])) { 0102 $values['is_show_title'] = 0; 0103 } 0104 if (!isset($values['is_show_git_projects'])) { 0105 $values['is_show_git_projects'] = 0; 0106 } 0107 if (!isset($values['is_show_blog_news'])) { 0108 $values['is_show_blog_news'] = 0; 0109 } 0110 if (!isset($values['is_show_forum_news'])) { 0111 $values['is_show_forum_news'] = 0; 0112 } 0113 if (!isset($values['is_show_in_menu'])) { 0114 $values['is_show_in_menu'] = 0; 0115 } 0116 if (!isset($values['is_show_real_domain_as_url'])) { 0117 $values['is_show_real_domain_as_url'] = 0; 0118 } 0119 if (!isset($values['cross_domain_login'])) { 0120 $values['cross_domain_login'] = 0; 0121 } 0122 if (!isset($values['is_client'])) { 0123 $values['is_client'] = 0; 0124 } 0125 0126 $record = $this->_model->save($values); 0127 0128 $this->initCache($record->store_id); 0129 0130 $tagsid = $this->getParam('tags_id', null); 0131 $tagmodel = new Default_Model_Tags(); 0132 $tagmodel->updateTagsPerStore($values['store_id'], $tagsid); 0133 0134 $groupsid = $this->getParam('groups_id', null); 0135 $groupmodel = new Default_Model_TagGroup(); 0136 $groupmodel->updateTagGroupsPerStore($values['store_id'], $groupsid); 0137 0138 $jTableResult = array(); 0139 $jTableResult['Result'] = self::RESULT_OK; 0140 } catch (Exception $e) { 0141 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0142 $translate = Zend_Registry::get('Zend_Translate'); 0143 $jTableResult['Result'] = self::RESULT_ERROR; 0144 $jTableResult['Message'] = $translate->_('Error while processing data.'); 0145 } 0146 0147 $this->_helper->json($jTableResult); 0148 } 0149 0150 protected function initCache($store_id) 0151 { 0152 $modelPCat = new Default_Model_ProjectCategory(); 0153 $modelPCat->fetchCategoryTreeForStore($store_id, true); 0154 0155 $this->_model->fetchConfigForStore($store_id, true); 0156 $this->_model->fetchAllStoresAndCategories(true); 0157 $this->_model->fetchAllStoresConfigArray(true); 0158 } 0159 0160 public function deleteAction() 0161 { 0162 $dataId = (int)$this->getParam(self::DATA_ID_NAME, null); 0163 0164 $this->_model->deleteId($dataId); 0165 0166 $this->cacheClear($dataId); 0167 0168 $jTableResult = array(); 0169 $jTableResult['Result'] = self::RESULT_OK; 0170 0171 $this->_helper->json($jTableResult); 0172 } 0173 0174 protected function cacheClear($store_id) 0175 { 0176 /** @var Zend_Cache_Core $cache */ 0177 $cache = Zend_Registry::get('cache'); 0178 $cache->remove(Default_Model_ProjectCategory::CACHE_TREE_STORE . "_{$store_id}"); 0179 $cache->remove(Default_Model_DbTable_ConfigStore::CACHE_STORE_CONFIG . "_{$store_id}"); 0180 $this->_model->fetchAllStoresAndCategories(true); 0181 $this->_model->fetchAllStoresConfigArray(true); 0182 } 0183 0184 public function listAction() 0185 { 0186 $startIndex = (int)$this->getParam('jtStartIndex'); 0187 $pageSize = (int)$this->getParam('jtPageSize'); 0188 $sorting = $this->getParam('jtSorting'); 0189 $filter['hostname'] = $this->getParam('filter_hostname'); 0190 $filter['category_id'] = $this->getParam('filter_category_id'); 0191 0192 $select = $this->_model->select()->from($this->_model, array( 0193 '*', 0194 'groups_id' => new Zend_Db_Expr('(SELECT GROUP_CONCAT(CASE WHEN `tag`.`tag_fullname` IS NULL THEN `tag`.`tag_name` ELSE `tag`.`tag_fullname` END) 0195 FROM `config_store_tag`,`tag` 0196 WHERE `tag`.`tag_id` = `config_store_tag`.`tag_id` AND `config_store_tag`.`store_id` = `config_store`.`store_id` 0197 GROUP BY `config_store_tag`.`store_id`) AS `tags_name`, 0198 (SELECT GROUP_CONCAT(`tag`.`tag_id`) 0199 FROM `config_store_tag`,`tag` 0200 WHERE `tag`.`tag_id` = `config_store_tag`.`tag_id` AND `config_store_tag`.`store_id` = `config_store`.`store_id` 0201 GROUP BY `config_store_tag`.`store_id`) AS `tags_id`, 0202 (SELECT GROUP_CONCAT(`tag_group`.`group_name`) 0203 FROM `config_store_tag_group`,`tag_group` 0204 WHERE `tag_group`.`group_id` = `config_store_tag_group`.`tag_group_id` AND `config_store_tag_group`.`store_id` = `config_store`.`store_id` 0205 GROUP BY `config_store_tag_group`.`store_id`) AS `groups_name`, 0206 (SELECT GROUP_CONCAT(`tag_group`.`group_id`) 0207 FROM `config_store_tag_group`,`tag_group` 0208 WHERE `tag_group`.`group_id` = `config_store_tag_group`.`tag_group_id` AND `config_store_tag_group`.`store_id` = `config_store`.`store_id` 0209 GROUP BY `config_store_tag_group`.`store_id`)') 0210 ))->order($sorting)->limit($pageSize, $startIndex)->setIntegrityCheck(false); 0211 0212 $select->joinLeft('browse_list_types', 'browse_list_types.browse_list_type_id = config_store.browse_list_type', 0213 array('browse_list_type_name' => 'name')); 0214 0215 foreach ($filter as $key => $value) { 0216 if (false === empty($value)) { 0217 $select->where("{$key} like ?", $value); 0218 } 0219 } 0220 0221 $reports = $this->_model->fetchAll($select); 0222 0223 $select = $this->_model->select()->from($this->_model)->setIntegrityCheck(false); 0224 foreach ($filter as $key => $value) { 0225 if (false === empty($value)) { 0226 $select->where("{$key} like ?", $value); 0227 } 0228 } 0229 $reportsAll = $this->_model->fetchAll($select->limit(null, null)->reset('columns') 0230 ->columns(array('countAll' => new Zend_Db_Expr('count(*)')))); 0231 0232 $jTableResult = array(); 0233 $jTableResult['Result'] = self::RESULT_OK; 0234 $jTableResult['Records'] = $reports->toArray(); 0235 $jTableResult['TotalRecordCount'] = $reportsAll->current()->countAll; 0236 0237 $this->_helper->json($jTableResult); 0238 } 0239 0240 public function hostnamesAction() 0241 { 0242 $result = true; 0243 $id = (int)$this->getParam('c'); 0244 0245 try { 0246 $records = $this->_model->fetchHostnamesForJTable($id); 0247 } catch (Exception $e) { 0248 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0249 $result = false; 0250 $records = array(); 0251 } 0252 0253 $jTableResult = array(); 0254 $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR; 0255 $jTableResult['Options'] = $records; 0256 0257 $this->_helper->json($jTableResult); 0258 } 0259 0260 public function loadstoreconfigAction() 0261 { 0262 $jTableResult = array(); 0263 try { 0264 $configStoreId = $this->getParam('c'); 0265 0266 $modelConfig = new Backend_Model_ClientFileConfig($configStoreId); 0267 $modelConfig->loadClientConfig(); 0268 if ($modelConfig->getDefaultConfigLoaded()) { 0269 $this->view->defaultConfigLoaded = true; 0270 } 0271 $form = $modelConfig->getForm(); 0272 $this->view->formConfig = $form; 0273 $view = $this->view->render('store/configform.phtml'); 0274 0275 $jTableResult = array(); 0276 $jTableResult['Result'] = self::RESULT_OK; 0277 $jTableResult['ViewRecord'] = $view; 0278 } catch (Exception $e) { 0279 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0280 $translate = Zend_Registry::get('Zend_Translate'); 0281 $this->getResponse()->setHttpResponseCode(500); 0282 $jTableResult['Result'] = self::RESULT_ERROR; 0283 $jTableResult['Message'] = $translate->_('Error while processing data.'); 0284 } 0285 0286 $this->_helper->json($jTableResult); 0287 } 0288 0289 public function savestoreconfigAction() 0290 { 0291 $jTableResult = array(); 0292 try { 0293 $clientName = $this->getParam('clientname'); 0294 unset($_POST['clientname']); 0295 $modelConfig = new Backend_Model_ClientFileConfig($clientName); 0296 $modelConfig->saveClientConfig($_POST, $clientName); 0297 0298 $jTableResult = array(); 0299 $jTableResult['Result'] = self::RESULT_OK; 0300 } catch (Exception $e) { 0301 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0302 $translate = Zend_Registry::get('Zend_Translate'); 0303 $jTableResult['Result'] = self::RESULT_ERROR; 0304 $jTableResult['Message'] = $translate->_('Error while processing data.'); 0305 } 0306 0307 $this->_helper->json($jTableResult); 0308 } 0309 0310 public function tagsallAction() 0311 { 0312 0313 $result = true; 0314 $tagmodel = new Default_Model_Tags(); 0315 try { 0316 $resultRows = $tagmodel->getAllTagsForStoreFilter(); 0317 $resultForSelect = array(); 0318 $resultForSelect[] = array('DisplayText' => '', 'Value' => ''); 0319 foreach ($resultRows as $row) { 0320 $resultForSelect[] = array( 0321 'DisplayText' => $row['tag_name'] . '[' . $row['tag_id'] . ']', 0322 'Value' => $row['tag_id'] 0323 ); 0324 } 0325 } catch (Exception $e) { 0326 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0327 $result = false; 0328 $records = array(); 0329 } 0330 0331 $jTableResult = array(); 0332 $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR; 0333 $jTableResult['Options'] = $resultForSelect; 0334 0335 $this->_helper->json($jTableResult); 0336 } 0337 0338 0339 public function alltaggroupsAction() 0340 { 0341 0342 $result = true; 0343 $tagmodel = new Default_Model_TagGroup(); 0344 0345 try { 0346 $resultRows = $tagmodel->fetchAllGroups(); 0347 $resultForSelect = array(); 0348 $resultForSelect[] = array('DisplayText' => '', 'Value' => ''); 0349 foreach ($resultRows as $row) { 0350 $resultForSelect[] = 0351 array( 0352 'DisplayText' => $row['group_name'] . '[' . $row['group_id'] . ']', 0353 'Value' => $row['group_id'] 0354 ); 0355 } 0356 } catch (Exception $e) { 0357 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0358 $result = false; 0359 $records = array(); 0360 } 0361 0362 $jTableResult = array(); 0363 $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR; 0364 $jTableResult['Options'] = $resultForSelect; 0365 0366 $this->_helper->json($jTableResult); 0367 } 0368 0369 0370 public function createaboutAction() 0371 { 0372 $store_id = (int)$this->getParam('c'); 0373 $config = Zend_Registry::get('config'); 0374 $static_config = $config->settings->static; 0375 $include_path = $static_config->include_path . 'store_about/'; 0376 try { 0377 if (touch($include_path . '/' . $store_id . '.phtml')) { 0378 $result = true; 0379 } else { 0380 $result = false; 0381 } 0382 } catch (Exception $e) { 0383 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0384 $result = false; 0385 } 0386 0387 $jTableResult = array(); 0388 $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR; 0389 0390 $this->_helper->json($jTableResult); 0391 } 0392 0393 public function readaboutAction() 0394 { 0395 $store_id = (int)$this->getParam('c'); 0396 $config = Zend_Registry::get('config'); 0397 $static_config = $config->settings->static; 0398 $include_path = $static_config->include_path . 'store_about/'; 0399 $filecontent = ''; 0400 $result = true; 0401 0402 try { 0403 if (file_exists($include_path . '/' . $store_id . '.phtml')) { 0404 $filecontent = file_get_contents($include_path . '/' . $store_id . '.phtml'); 0405 } 0406 } catch (Exception $e) { 0407 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0408 $result = false; 0409 } 0410 0411 $jTableResult = array(); 0412 $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR; 0413 $jTableResult['c'] = $store_id; 0414 $jTableResult['CatAbout'] = $filecontent; 0415 0416 $this->_helper->json($jTableResult); 0417 } 0418 0419 public function saveaboutAction() 0420 { 0421 $store_id = (int)$this->getParam('c'); 0422 $cat_about = $this->getParam('ca'); 0423 0424 $config = Zend_Registry::get('config'); 0425 $static_config = $config->settings->static; 0426 $include_path = $static_config->include_path . 'store_about/'; 0427 0428 try { 0429 file_put_contents($include_path . '/' . $store_id . '.phtml', $cat_about); 0430 $result = true; 0431 } catch (Exception $e) { 0432 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0433 $result = false; 0434 } 0435 0436 $jTableResult = array(); 0437 $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR; 0438 0439 $this->_helper->json($jTableResult); 0440 } 0441 0442 }