BxBaseStudioPermissionsLevels.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. class BxBaseStudioPermissionsLevels extends BxDolStudioPermissionsLevels
  11. {
  12. public static $iBinMB = 1048576;
  13. protected $sUrlPage;
  14. function __construct($aOptions, $oTemplate = false)
  15. {
  16. parent::__construct($aOptions, $oTemplate);
  17. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_prm_btn_level_edit');
  18. $this->_aOptions['actions_single']['delete']['attr']['title'] = _t('_adm_prm_btn_level_delete');
  19. $this->sUrlPage = BX_DOL_URL_STUDIO . 'builder_permissions.php?page=levels';
  20. }
  21. public function performActionAdd()
  22. {
  23. $sAction = 'add';
  24. $oForm = $this->_getFormObject($sAction);
  25. $oForm->initChecker();
  26. if($oForm->isSubmittedAndValid()) {
  27. if(($iId = $this->_getAvailableId()) === false) {
  28. echoJson(array('msg' => _t('_adm_prm_err_level_id')));
  29. return;
  30. }
  31. $mixedIcon = '';
  32. if(!empty($_FILES['Icon_image']['tmp_name'])) {
  33. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  34. $mixedIcon = $oStorage->storeFileFromForm($_FILES['Icon_image'], false, 0);
  35. if($mixedIcon === false) {
  36. echoJson(array('msg' => _t('_adm_prm_err_level_icon_image') . $oStorage->getErrorString()));
  37. return;
  38. }
  39. $oStorage->afterUploadCleanup($mixedIcon, 0);
  40. }
  41. if(empty($mixedIcon))
  42. $mixedIcon = $oForm->getCleanValue('Icon');
  43. if(empty($mixedIcon))
  44. $mixedIcon = 'acl-unconfirmed.png';
  45. BxDolForm::setSubmittedValue('Icon', $mixedIcon, $oForm->aFormAttrs['method']);
  46. $fQuotaSize = round($oForm->getCleanValue('QuotaSize'), 1);
  47. BxDolForm::setSubmittedValue('QuotaSize', self::$iBinMB * $fQuotaSize, $oForm->aFormAttrs['method']);
  48. $fQuotaMaxFileSize = round($oForm->getCleanValue('QuotaMaxFileSize'), 1);
  49. BxDolForm::setSubmittedValue('QuotaMaxFileSize', self::$iBinMB * $fQuotaMaxFileSize, $oForm->aFormAttrs['method']);
  50. $iId = (int)$oForm->insert(array('ID' => $iId, 'Icon' => $mixedIcon, 'Order' => $this->oDb->getLevelOrderMax() + 1));
  51. if($iId != 0) {
  52. $aLevel = array();
  53. $this->oDb->getLevels(array('type' => 'by_id', 'value' => (int)$iId), $aLevel, false);
  54. $iActionsFrom = (int)$oForm->getCleanValue('Actions');
  55. if($iActionsFrom > 0) {
  56. $aActions = array();
  57. $this->oDb->getActions(array('type' => 'by_level_id', 'value' => $iActionsFrom), $aActions, false);
  58. foreach($aActions as $aAction)
  59. $this->oDb->switchAction($iId, $aAction['id'], true, array(
  60. 'AllowedCount' => $aAction['allowed_count'],
  61. 'AllowedPeriodLen' => $aAction['allowed_period_len'],
  62. 'AllowedPeriodStart' => $aAction['allowed_period_start'],
  63. 'AllowedPeriodEnd' => $aAction['allowed_period_end'],
  64. 'AdditionalParamValue' => $aAction['additional_param_value']
  65. ));
  66. }
  67. // create system event
  68. bx_alert('acl', 'added', $iId, 0, array('level' => $aLevel));
  69. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  70. }
  71. else
  72. $aRes = array('msg' => _t('_adm_prm_err_level_create'));
  73. echoJson($aRes);
  74. }
  75. else {
  76. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-prm-level-create-popup', _t('_adm_prm_txt_level_create_popup'), $this->_oTemplate->parseHtmlByName('prm_add_level.html', array(
  77. 'form_id' => $oForm->aFormAttrs['id'],
  78. 'form' => $oForm->getCode(true),
  79. 'object' => $this->_sObject,
  80. 'action' => $sAction
  81. )));
  82. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  83. }
  84. }
  85. public function performActionEdit()
  86. {
  87. $sAction = 'edit';
  88. $aIds = bx_get('ids');
  89. if(!$aIds || !is_array($aIds)) {
  90. $iId = (int)bx_get('id');
  91. if(!$iId) {
  92. echoJson(array());
  93. exit;
  94. }
  95. $aIds = array($iId);
  96. }
  97. $iId = $aIds[0];
  98. $aLevel = array();
  99. $iLevel = $this->oDb->getLevels(array('type' => 'by_id', 'value' => $iId), $aLevel);
  100. if($iLevel != 1 || empty($aLevel)){
  101. echoJson(array());
  102. exit;
  103. }
  104. $oForm = $this->_getFormObject($sAction, $aLevel);
  105. $oForm->initChecker();
  106. if($oForm->isSubmittedAndValid()) {
  107. $bIconImageCur = is_numeric($aLevel['icon']) && (int)$aLevel['icon'] != 0;
  108. $bIconImageNew = !empty($_FILES['Icon_image']['tmp_name']);
  109. $sIconFont = $oForm->getCleanValue('Icon');
  110. $bIconFont = !empty($sIconFont);
  111. if($bIconImageCur && ($bIconImageNew || $bIconFont)) {
  112. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  113. if(!$oStorage->deleteFile((int)$aLevel['icon'], 0)) {
  114. echoJson(array('msg' => _t('_adm_prm_err_level_icon_image_remove')));
  115. return;
  116. }
  117. }
  118. $sIcon = $sIconFont;
  119. if($bIconImageNew) {
  120. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  121. $sIcon = $oStorage->storeFileFromForm($_FILES['Icon_image'], false, 0);
  122. if($sIcon === false) {
  123. echoJson(array('msg' => _t('_adm_prm_err_level_icon_image') . $oStorage->getErrorString()));
  124. return;
  125. }
  126. $oStorage->afterUploadCleanup($sIcon, 0);
  127. } else if($bIconImageCur && !$bIconFont)
  128. $sIcon = $aLevel['icon'];
  129. BxDolForm::setSubmittedValue('Icon', $sIcon, $oForm->aFormAttrs['method']);
  130. $fQuotaSize = round($oForm->getCleanValue('QuotaSize'), 1);
  131. BxDolForm::setSubmittedValue('QuotaSize', self::$iBinMB * $fQuotaSize, $oForm->aFormAttrs['method']);
  132. $fQuotaMaxFileSize = round($oForm->getCleanValue('QuotaMaxFileSize'), 1);
  133. BxDolForm::setSubmittedValue('QuotaMaxFileSize', self::$iBinMB * $fQuotaMaxFileSize, $oForm->aFormAttrs['method']);
  134. if($oForm->update($iId) !== false) {
  135. $aLevel = array();
  136. $this->oDb->getLevels(array('type' => 'by_id', 'value' => (int)$iId), $aLevel, false);
  137. // create system event
  138. bx_alert('acl', 'edited', $iId, 0, array('level' => $aLevel));
  139. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  140. }
  141. else
  142. $aRes = array('msg' => _t('_adm_prm_err_level_edit'));
  143. echoJson($aRes);
  144. }
  145. else {
  146. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-prm-level-edit-popup', _t('_adm_prm_txt_level_edit_popup', _t($aLevel['name'])), $this->_oTemplate->parseHtmlByName('prm_add_level.html', array(
  147. 'form_id' => $oForm->aFormAttrs['id'],
  148. 'form' => $oForm->getCode(true),
  149. 'object' => $this->_sObject,
  150. 'action' => $sAction
  151. )));
  152. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  153. }
  154. }
  155. public function performActionDelete()
  156. {
  157. $iAffected = 0;
  158. $aIds = bx_get('ids');
  159. if(!$aIds || !is_array($aIds)) {
  160. echoJson(array());
  161. exit;
  162. }
  163. $aIdsAffected = array ();
  164. foreach($aIds as $iId) {
  165. if(!$this->delete($iId))
  166. continue;
  167. $aIdsAffected[] = $iId;
  168. $iAffected++;
  169. }
  170. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_prm_err_level_delete')));
  171. }
  172. public function performActionDeleteIcon()
  173. {
  174. $sAction = 'delete_icon';
  175. $aIds = bx_get('ids');
  176. if(empty($aIds[0])) {
  177. echoJson(array());
  178. exit;
  179. }
  180. $iId = (int)$aIds[0];
  181. $aLevel = array();
  182. $iLevel = $this->oDb->getLevels(array('type' => 'by_id', 'value' => $iId), $aLevel);
  183. if($iLevel != 1 || empty($aLevel)){
  184. echoJson(array());
  185. exit;
  186. }
  187. if(is_numeric($aLevel['icon']) && (int)$aLevel['icon'] != 0)
  188. if(!BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$aLevel['icon'], 0)) {
  189. echoJson(array());
  190. exit;
  191. }
  192. if($this->oDb->updateLevels($aLevel['id'], array('icon' => '')) !== false)
  193. echoJson(array('grid' => $this->getCode(false), 'blink' => $iId, 'preview' => $this->_getIconPreview($aLevel['id']), 'eval' => $this->getJsObject() . ".onDeleteIcon(oData)"));
  194. }
  195. public function getJsObject()
  196. {
  197. return 'oBxDolStudioPermissionsLevels';
  198. }
  199. public function getCode($isDisplayHeader = true)
  200. {
  201. return $this->_oTemplate->parseHtmlByName('prm_levels.html', array(
  202. 'content' => parent::getCode($isDisplayHeader),
  203. 'js_object' => $this->getJsObject(),
  204. 'page_url' => $this->sUrlPage,
  205. 'grid_object' => $this->_sObject,
  206. 'params_divider' => $this->sParamsDivider
  207. ));
  208. }
  209. protected function _addJsCss()
  210. {
  211. parent::_addJsCss();
  212. $this->_oTemplate->addJs(array('jquery.form.min.js', 'permissions_levels.js'));
  213. $oForm = new BxTemplStudioFormView(array());
  214. $oForm->addCssJs();
  215. }
  216. protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow)
  217. {
  218. if(in_array($aRow['ID'], array(MEMBERSHIP_ID_NON_MEMBER, MEMBERSHIP_ID_ACCOUNT, MEMBERSHIP_ID_STANDARD, MEMBERSHIP_ID_UNCONFIRMED, MEMBERSHIP_ID_PENDING, MEMBERSHIP_ID_SUSPENDED)))
  219. return parent::_getCellDefault('', $sKey, $aField, $aRow);;
  220. return parent::_getCellSwitcher($mixedValue, $sKey, $aField, $aRow);
  221. }
  222. protected function _getCellIcon ($mixedValue, $sKey, $aField, $aRow)
  223. {
  224. $mixedValue = $this->_oTemplate->getImage($mixedValue, array('class' => 'bx-prm-level-icon'));
  225. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  226. }
  227. protected function _getCellActionsList ($mixedValue, $sKey, $aField, $aRow)
  228. {
  229. $aActions = array();
  230. $iActions = $this->oDb->getActions(array('type' => 'by_level_id', 'value' => $aRow['ID']), $aActions);
  231. $sLink = BX_DOL_URL_STUDIO . 'builder_permissions.php?page=actions&level=' . $aRow['ID'];
  232. $mixedValue = $this->_oTemplate->parseLink($sLink, _t('_adm_prm_txt_n_actions', $iActions), array(
  233. 'title' => _t('_adm_prm_txt_manage_actions')
  234. ));
  235. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  236. }
  237. protected function _getCellQuotaSize ($mixedValue, $sKey, $aField, $aRow)
  238. {
  239. return parent::_getCellDefault ($mixedValue > 0 ? _t_format_size($mixedValue) : '&infin;', $sKey, $aField, $aRow);
  240. }
  241. protected function _getCellQuotaNumber ($mixedValue, $sKey, $aField, $aRow)
  242. {
  243. return parent::_getCellDefault ($mixedValue > 0 ? $mixedValue : '&infin;', $sKey, $aField, $aRow);
  244. }
  245. protected function _getCellQuotaMaxFileSize ($mixedValue, $sKey, $aField, $aRow)
  246. {
  247. return parent::_getCellDefault ($mixedValue > 0 ? _t_format_size($mixedValue) : '&infin;', $sKey, $aField, $aRow);
  248. }
  249. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  250. {
  251. if ($sType == 'single' && $aRow['Removable'] != 'yes')
  252. return '';
  253. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  254. }
  255. protected function _getIconPreview($iId, $sIconImage = '', $sIconFont = '')
  256. {
  257. $bIconImage = !empty($sIconImage);
  258. $bIconFont = !empty($sIconFont);
  259. return $this->_oTemplate->parseHtmlByName('prm_level_icon_preview.html', array(
  260. 'id' => $iId,
  261. 'bx_if:show_icon_empty' => array(
  262. 'condition' => !$bIconImage && !$bIconFont,
  263. 'content' => array()
  264. ),
  265. 'bx_if:show_icon_image' => array(
  266. 'condition' => $bIconImage,
  267. 'content' => array(
  268. 'js_object' => $this->getJsObject(),
  269. 'url' => $sIconImage,
  270. 'id' => $iId
  271. )
  272. ),
  273. 'bx_if:show_icon_font' => array(
  274. 'condition' => $bIconFont,
  275. 'content' => array(
  276. 'icon' => $sIconFont
  277. )
  278. )
  279. ));
  280. }
  281. protected function _getFormObject($sAction, $aLevel = array())
  282. {
  283. bx_import('BxTemplStudioFormView');
  284. $aForm = array(
  285. 'form_attrs' => array(
  286. 'id' => 'adm-prm-level-create',
  287. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  288. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT,
  289. 'enctype' => 'multipart/form-data',
  290. ),
  291. 'params' => array (
  292. 'db' => array(
  293. 'table' => 'sys_acl_levels',
  294. 'key' => 'ID',
  295. 'uri' => '',
  296. 'uri_title' => '',
  297. 'submit_name' => 'do_submit'
  298. ),
  299. ),
  300. 'inputs' => array (
  301. 'id' => array(
  302. 'type' => 'hidden',
  303. 'name' => 'id',
  304. 'value' => isset($aLevel['id']) ? (int)$aLevel['id'] : 0,
  305. 'db' => array (
  306. 'pass' => 'Int',
  307. ),
  308. ),
  309. 'Active' => array(
  310. 'type' => 'hidden',
  311. 'name' => 'Active',
  312. 'value' => 'yes',
  313. 'db' => array (
  314. 'pass' => 'Xss',
  315. ),
  316. ),
  317. 'Purchasable' => array(
  318. 'type' => 'hidden',
  319. 'name' => 'Purchasable',
  320. 'value' => 'no',
  321. 'db' => array (
  322. 'pass' => 'Xss',
  323. ),
  324. ),
  325. 'Removable' => array(
  326. 'type' => 'hidden',
  327. 'name' => 'Removable',
  328. 'value' => 'yes',
  329. 'db' => array (
  330. 'pass' => 'Xss',
  331. ),
  332. ),
  333. 'Name' => array(
  334. 'type' => 'text_translatable',
  335. 'name' => 'Name',
  336. 'caption' => _t('_adm_prm_txt_level_name'),
  337. 'info' => _t('_adm_prm_dsc_level_name'),
  338. 'value' => '_adm_prm_txt_level',
  339. 'required' => '1',
  340. 'db' => array (
  341. 'pass' => 'Xss',
  342. ),
  343. 'checker' => array (
  344. 'func' => 'LengthTranslatable',
  345. 'params' => array(3, 100, 'Name'),
  346. 'error' => _t('_adm_prm_err_level_name'),
  347. ),
  348. ),
  349. 'Description' => array(
  350. 'type' => 'textarea_translatable',
  351. 'name' => 'Description',
  352. 'caption' => _t('_adm_prm_txt_level_description'),
  353. 'info' => _t('_adm_prm_dsc_level_description'),
  354. 'value' => isset($aLevel['description']) ? $aLevel['description'] : '_adm_prm_txt_level',
  355. 'code' => 1,
  356. 'db' => array (
  357. 'pass' => 'XssHtml',
  358. )
  359. ),
  360. 'QuotaSize' => array(
  361. 'type' => 'text',
  362. 'name' => 'QuotaSize',
  363. 'caption' => _t('_adm_prm_txt_level_quota_size'),
  364. 'info' => _t('_adm_prm_dsc_level_quota_size'),
  365. 'value' => isset($aLevel['quota_size']) ? round($aLevel['quota_size'] / self::$iBinMB, 1) : '0',
  366. 'required' => '1',
  367. 'db' => array (
  368. 'pass' => 'Float',
  369. ),
  370. 'checker' => array (
  371. 'func' => 'preg',
  372. 'params' => array('/^[0-9\.]+$/'),
  373. 'error' => _t('_adm_prm_err_level_quota_size'),
  374. ),
  375. ),
  376. 'QuotaMaxFileSize' => array(
  377. 'type' => 'text',
  378. 'name' => 'QuotaMaxFileSize',
  379. 'caption' => _t('_adm_prm_txt_level_quota_max_file_size'),
  380. 'info' => _t('_adm_prm_dsc_level_quota_max_file_size'),
  381. 'value' => isset($aLevel['quota_max_file_size']) ? round($aLevel['quota_max_file_size'] / self::$iBinMB, 1) : '',
  382. 'required' => '1',
  383. 'db' => array (
  384. 'pass' => 'Float',
  385. ),
  386. 'checker' => array (
  387. 'func' => 'preg',
  388. 'params' => array('/^[0-9\.]+$/'),
  389. 'error' => _t('_adm_prm_err_level_quota_max_file_size'),
  390. ),
  391. ),
  392. 'QuotaNumber' => array(
  393. 'type' => 'text',
  394. 'name' => 'QuotaNumber',
  395. 'caption' => _t('_adm_prm_txt_level_quota_number'),
  396. 'info' => _t('_adm_prm_dsc_level_quota_number'),
  397. 'value' => isset($aLevel['quota_number']) ? (int)$aLevel['quota_number'] : '0',
  398. 'required' => '1',
  399. 'db' => array (
  400. 'pass' => 'Int',
  401. ),
  402. 'checker' => array (
  403. 'func' => 'preg',
  404. 'params' => array('/^[0-9]+$/'),
  405. 'error' => _t('_adm_prm_err_level_quota_number'),
  406. ),
  407. ),
  408. 'Icon' => array(
  409. 'type' => 'text',
  410. 'name' => 'Icon',
  411. 'caption' => _t('_adm_prm_txt_level_icon'),
  412. 'info' => _t('_adm_prm_dsc_level_icon'),
  413. 'value' => '',
  414. 'required' => '0',
  415. 'db' => array (
  416. 'pass' => 'Xss',
  417. ),
  418. 'checker' => array (
  419. 'func' => '',
  420. 'params' => array(),
  421. 'error' => _t('_adm_prm_err_level_icon'),
  422. ),
  423. ),
  424. 'Icon_image' => array(
  425. 'type' => 'file',
  426. 'name' => 'Icon_image',
  427. 'caption' => _t('_adm_prm_txt_level_icon_image'),
  428. 'info' => _t('_adm_prm_dsc_level_icon_image'),
  429. 'value' => '',
  430. 'checker' => array (
  431. 'func' => '',
  432. 'params' => '',
  433. 'error' => _t('_adm_prm_err_level_icon_image'),
  434. ),
  435. ),
  436. 'Icon_preview' => array(
  437. 'type' => 'custom',
  438. 'name' => 'Icon_preview',
  439. 'caption' => _t('_adm_prm_txt_level_icon_image_old'),
  440. 'content' => ''
  441. ),
  442. 'Actions' => array(
  443. 'type' => 'select',
  444. 'name' => 'Actions',
  445. 'caption' => _t('_adm_prm_txt_level_actions_copy'),
  446. 'values' => array(
  447. array('key' => 0, 'value' => _t('_sys_txt_empty'))
  448. ),
  449. ),
  450. 'controls' => array(
  451. 'name' => 'controls',
  452. 'type' => 'input_set',
  453. array(
  454. 'type' => 'submit',
  455. 'name' => 'do_submit',
  456. 'value' => _t('_adm_prm_btn_level_add'),
  457. ),
  458. array (
  459. 'type' => 'reset',
  460. 'name' => 'close',
  461. 'value' => _t('_adm_prm_btn_level_cancel'),
  462. 'attrs' => array(
  463. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  464. 'class' => 'bx-def-margin-sec-left',
  465. ),
  466. )
  467. )
  468. )
  469. );
  470. $aLevels = array();
  471. $this->oDb->getLevels(array('type' => 'all_pair'), $aLevels, false);
  472. foreach($aLevels as $iId => $sName)
  473. $aForm['inputs']['Actions']['values'][] = array('key' => $iId, 'value' => _t($sName));
  474. switch($sAction) {
  475. case 'add':
  476. unset($aForm['inputs']['id']);
  477. unset($aForm['inputs']['Icon_preview']);
  478. $aForm['form_attrs']['id'] .= 'create';
  479. break;
  480. case 'edit':
  481. unset($aForm['inputs']['Active']);
  482. unset($aForm['inputs']['Purchasable']);
  483. unset($aForm['inputs']['Removable']);
  484. unset($aForm['inputs']['Name']);
  485. unset($aForm['inputs']['Actions']);
  486. $aForm['form_attrs']['id'] .= 'edit';
  487. $aForm['inputs']['Icon_image']['caption'] = _t('_adm_prm_txt_level_icon_image_new');
  488. $aForm['inputs']['controls'][0]['value'] = _t('_adm_prm_btn_level_save');
  489. $sIconImage = $sIconFont = "";
  490. if(!empty($aLevel['icon'])) {
  491. if(is_numeric($aLevel['icon']) && (int)$aLevel['icon'] != 0) {
  492. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  493. $sIconImage = $oStorage->getFileUrlById((int)$aLevel['icon']);
  494. } else {
  495. $sIconFont = $aLevel['icon'];
  496. $aForm['inputs']['Icon']['value'] = $sIconFont;
  497. }
  498. }
  499. $aForm['inputs']['Icon_preview']['content'] = $this->_getIconPreview($aLevel['id'], $sIconImage, $sIconFont);
  500. break;
  501. }
  502. return new BxTemplStudioFormView($aForm);
  503. }
  504. protected function _getAvailableId()
  505. {
  506. $aLevels = array();
  507. $this->oDb->getLevels(array('type' =>'all_order_id'), $aLevels, false);
  508. $iId = 1;
  509. foreach($aLevels as $aLevel) {
  510. if($iId != (int)$aLevel['id'])
  511. break;
  512. $iId++;
  513. }
  514. return $iId <= BX_DOL_STUDIO_PERMISSIONS_LEVEL_ID_INT_MAX ? $iId : false;
  515. }
  516. }
  517. /** @} */