BxBaseStudioSettings.php 9.1 KB

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