1
0

BxBaseStudioSettings.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentView Trident Studio Representation classes
  7. * @ingroup TridentStudio
  8. * @{
  9. */
  10. class BxBaseStudioSettings extends BxDolStudioSettings
  11. {
  12. public function __construct($sType = '', $sCategory = '')
  13. {
  14. parent::__construct($sType, $sCategory);
  15. }
  16. public function getPageCss()
  17. {
  18. return array_merge(parent::getPageCss(), array('forms.css'));
  19. }
  20. public function getPageJs()
  21. {
  22. return array_merge(parent::getPageJs(), array('settings.js'));
  23. }
  24. public function getPageJsObject()
  25. {
  26. return 'oBxDolStudioSettings';
  27. }
  28. public function getPageMenu($aMenu = array(), $aMarkers = array())
  29. {
  30. $aTypes = $aMenu = array();
  31. if($this->oDb->getTypes(array('type' => 'all'), $aTypes) > 0 ) {
  32. $aTypesGrouped = array();
  33. foreach($aTypes as $aType)
  34. $aTypesGrouped[$aType['group']][] = $aType;
  35. foreach($aTypesGrouped as $sGroup => $aTypes)
  36. foreach($aTypes as $aType)
  37. $aMenu[] = array(
  38. 'name' => $aType['name'],
  39. 'icon' => $this->getMenuIcon($sGroup, $aType),
  40. 'link' => BX_DOL_URL_STUDIO . 'settings.php?page=' . $aType['name'],
  41. 'title' => $aType['caption'],
  42. 'selected' => $aType['name'] == $this->sType
  43. );
  44. }
  45. return parent::getPageMenu($aMenu);
  46. }
  47. public function getPageCode($sCategorySelected = '')
  48. {
  49. $oTemplate = BxDolStudioTemplate::getInstance();
  50. $aCategories = array();
  51. $iCategories = $this->oDb->getCategories(array('type' => 'by_type_name_key_name', 'type_name' => $this->sType, 'category_name' => $this->sCategory, 'hidden' => 0), $aCategories);
  52. if($iCategories > 0)
  53. $aCategories = array_keys($aCategories);
  54. $bWrap = count($aCategories) > 1;
  55. $aForm = array(
  56. 'form_attrs' => array(
  57. 'id' => 'adm-settings-form',
  58. 'name' => 'adm-settings-form',
  59. 'action' => BX_DOL_URL_STUDIO . 'settings.php?page=' . $this->sType,
  60. 'method' => 'post',
  61. 'enctype' => 'multipart/form-data',
  62. 'target' => 'adm-settings-iframe'
  63. ),
  64. 'params' => array(
  65. 'db' => array(
  66. 'table' => 'sys_options',
  67. 'key' => 'id',
  68. 'uri' => '',
  69. 'uri_title' => '',
  70. 'submit_name' => 'save'
  71. ),
  72. ),
  73. 'inputs' => array()
  74. );
  75. foreach($aCategories as $sCategory) {
  76. $aFields = array();
  77. if(empty($sCategory))
  78. continue;
  79. $aCategory = array();
  80. $iCategory = $this->oDb->getCategories(array('type' => 'by_name', 'value' => $sCategory), $aCategory);
  81. if($iCategory != 1)
  82. continue;
  83. $aOptions = array();
  84. $iOptions = $this->oDb->getOptions(array('type' => 'by_category_id', 'value' => $aCategory['id']), $aOptions);
  85. foreach($aOptions as $aOption)
  86. $aFields[$aOption['name']] = $this->field($aOption);
  87. if($bWrap) {
  88. $aCategory['selected'] = $aCategory['name'] == $sCategorySelected;
  89. $aFields = $this->header($aCategory, $aFields);
  90. }
  91. $aForm['inputs'] = array_merge($aForm['inputs'], $aFields);
  92. }
  93. $aForm['inputs'] = array_merge(
  94. $aForm['inputs'],
  95. (!$bWrap ? array() : array(
  96. 'header_save' => array(
  97. 'type' => 'block_header',
  98. ),
  99. )),
  100. array(
  101. 'categories' => array(
  102. 'type' => 'hidden',
  103. 'name' => 'categories',
  104. 'value' => implode(',', $aCategories),
  105. 'db' => array (
  106. 'pass' => 'Xss',
  107. ),
  108. ),
  109. 'save' => array(
  110. 'type' => 'submit',
  111. 'name' => 'save',
  112. 'value' => _t("_adm_btn_settings_save"),
  113. )
  114. )
  115. );
  116. $oForm = new BxTemplStudioFormView($aForm);
  117. $oForm->initChecker();
  118. if($oForm->isSubmittedAndValid()) {
  119. echo $this->saveChanges($oForm);
  120. exit;
  121. }
  122. return $oTemplate->parseHtmlByName('settings.html', array('js_object' => $this->getPageJsObject(), 'form' => $oForm->getCode()));
  123. }
  124. protected function header($aCategory, $aFields)
  125. {
  126. return array_merge(
  127. array(
  128. 'category_' . $aCategory['id'] . '_beg' => array(
  129. 'type' => 'block_header',
  130. 'name' => 'category_' . $aCategory['id'] . '_beg',
  131. 'caption' => _t($aCategory['caption']),
  132. 'collapsable' => true,
  133. 'collapsed' => !$aCategory['selected']
  134. )
  135. ),
  136. $aFields);
  137. }
  138. protected function field($aItem)
  139. {
  140. $aField = array();
  141. switch($aItem['type']) {
  142. case 'digit':
  143. $aField = array(
  144. 'type' => 'text',
  145. 'name' => $aItem['name'],
  146. 'caption' => _t($aItem['caption']),
  147. 'value' => $aItem['value'],
  148. 'db' => array (
  149. 'pass' => 'Xss',
  150. ),
  151. );
  152. break;
  153. case 'text':
  154. $aField = array(
  155. 'type' => 'textarea',
  156. 'name' => $aItem['name'],
  157. 'caption' => _t($aItem['caption']),
  158. 'value' => $aItem['value'],
  159. 'db' => array (
  160. 'pass' => 'XssHtml',
  161. ),
  162. );
  163. break;
  164. case 'checkbox':
  165. $aField = array(
  166. 'type' => 'checkbox',
  167. 'name' => $aItem['name'],
  168. 'caption' => _t($aItem['caption']),
  169. 'value' => 'on',
  170. 'checked' => $aItem['value'] == 'on',
  171. 'db' => array (
  172. 'pass' => 'Xss',
  173. ),
  174. );
  175. break;
  176. case 'list':
  177. case 'rlist':
  178. $aField = array(
  179. 'type' => 'checkbox_set',
  180. 'name' => $aItem['name'],
  181. 'caption' => _t($aItem['caption']),
  182. 'value' => !empty($aItem['value']) ? explode(',', $aItem['value']) : array(),
  183. 'reverse' => $aItem['type'] == 'rlist',
  184. 'db' => array (
  185. 'pass' => 'Xss',
  186. ),
  187. );
  188. if (BxDolService::isSerializedService($aItem['extra']))
  189. $aField['values'] = BxDolService::callSerialized($aItem['extra']);
  190. else
  191. foreach(explode(',', $aItem['extra']) as $sValue)
  192. $aField['values'][$sValue] = $sValue;
  193. break;
  194. case 'select':
  195. $aField = array(
  196. 'type' => 'select',
  197. 'name' => $aItem['name'],
  198. 'caption' => _t($aItem['caption']),
  199. 'value' => $aItem['value'],
  200. 'values' => array(),
  201. 'db' => array (
  202. 'pass' => 'Xss',
  203. ),
  204. );
  205. if (BxDolService::isSerializedService($aItem['extra']))
  206. $aField['values'] = BxDolService::callSerialized($aItem['extra']);
  207. else
  208. foreach(explode(',', $aItem['extra']) as $sValue)
  209. $aField['values'][] = array('key' => $sValue, 'value' => $sValue);
  210. break;
  211. case 'file':
  212. $aField = array(
  213. 'type' => 'file',
  214. 'name' => $aItem['name'],
  215. 'caption' => _t($aItem['caption']),
  216. 'value' => $aItem['value'],
  217. 'db' => array (
  218. 'pass' => 'Xss'
  219. )
  220. );
  221. break;
  222. }
  223. return $aField;
  224. }
  225. protected function getMenuIcon($sGroup, &$aType)
  226. {
  227. if(empty($aType['icon']) || ($sUrl = BxDolStudioTemplate::getInstance()->getIconUrl($aType['icon'])) == "")
  228. switch($sGroup) {
  229. case BX_DOL_STUDIO_STG_GROUP_MODULES:
  230. $aType['icon'] = BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_MODULE);
  231. break;
  232. case BX_DOL_STUDIO_STG_GROUP_LANGUAGES:
  233. $aType['icon'] = BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_LANGUAGE);
  234. break;
  235. case BX_DOL_STUDIO_STG_GROUP_TEMPLATES:
  236. $aType['icon'] = BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_TEMPLATE);
  237. break;
  238. }
  239. return $aType['icon'];
  240. }
  241. }
  242. /** @} */