BxBaseStudioSettings.php 9.5 KB

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