BxBaseStudioSettings.php 9.1 KB

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