BxBaseStudioPermissionsLevels.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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. $this->oDb->cleanCache('sys_acl_levels' . $iId);
  136. $aLevel = array();
  137. $this->oDb->getLevels(array('type' => 'by_id', 'value' => (int)$iId), $aLevel, false);
  138. // create system event
  139. bx_alert('acl', 'edited', $iId, 0, array('level' => $aLevel));
  140. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  141. }
  142. else
  143. $aRes = array('msg' => _t('_adm_prm_err_level_edit'));
  144. echoJson($aRes);
  145. }
  146. else {
  147. $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(
  148. 'form_id' => $oForm->aFormAttrs['id'],
  149. 'form' => $oForm->getCode(true),
  150. 'object' => $this->_sObject,
  151. 'action' => $sAction
  152. )));
  153. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  154. }
  155. }
  156. public function performActionDelete()
  157. {
  158. $iAffected = 0;
  159. $aIds = bx_get('ids');
  160. if(!$aIds || !is_array($aIds)) {
  161. echoJson(array());
  162. exit;
  163. }
  164. $aIdsAffected = array ();
  165. foreach($aIds as $iId) {
  166. if(!$this->delete($iId))
  167. continue;
  168. $aIdsAffected[] = $iId;
  169. $iAffected++;
  170. }
  171. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_prm_err_level_delete')));
  172. }
  173. public function performActionDeleteIcon()
  174. {
  175. $sAction = 'delete_icon';
  176. $aIds = bx_get('ids');
  177. if(empty($aIds[0])) {
  178. echoJson(array());
  179. exit;
  180. }
  181. $iId = (int)$aIds[0];
  182. $aLevel = array();
  183. $iLevel = $this->oDb->getLevels(array('type' => 'by_id', 'value' => $iId), $aLevel);
  184. if($iLevel != 1 || empty($aLevel)){
  185. echoJson(array());
  186. exit;
  187. }
  188. if(is_numeric($aLevel['icon']) && (int)$aLevel['icon'] != 0)
  189. if(!BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$aLevel['icon'], 0)) {
  190. echoJson(array());
  191. exit;
  192. }
  193. if($this->oDb->updateLevels($aLevel['id'], array('icon' => '')) !== false)
  194. echoJson(array('grid' => $this->getCode(false), 'blink' => $iId, 'preview' => $this->_getIconPreview($aLevel['id']), 'eval' => $this->getJsObject() . ".onDeleteIcon(oData)"));
  195. }
  196. public function getJsObject()
  197. {
  198. return 'oBxDolStudioPermissionsLevels';
  199. }
  200. public function getCode($isDisplayHeader = true)
  201. {
  202. return $this->_oTemplate->parseHtmlByName('prm_levels.html', array(
  203. 'content' => parent::getCode($isDisplayHeader),
  204. 'js_object' => $this->getJsObject(),
  205. 'page_url' => $this->sUrlPage,
  206. 'grid_object' => $this->_sObject,
  207. 'params_divider' => $this->sParamsDivider
  208. ));
  209. }
  210. protected function _addJsCss()
  211. {
  212. parent::_addJsCss();
  213. $this->_oTemplate->addJs(array('jquery.form.min.js', 'permissions_levels.js'));
  214. $oForm = new BxTemplStudioFormView(array());
  215. $oForm->addCssJs();
  216. }
  217. protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow)
  218. {
  219. 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)))
  220. return parent::_getCellDefault('', $sKey, $aField, $aRow);;
  221. return parent::_getCellSwitcher($mixedValue, $sKey, $aField, $aRow);
  222. }
  223. protected function _getCellIcon ($mixedValue, $sKey, $aField, $aRow)
  224. {
  225. $mixedValue = $this->_oTemplate->getImage($mixedValue, array('class' => 'bx-prm-level-icon'));
  226. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  227. }
  228. protected function _getCellActionsList ($mixedValue, $sKey, $aField, $aRow)
  229. {
  230. $aActions = array();
  231. $iActions = $this->oDb->getActions(array('type' => 'by_level_id', 'value' => $aRow['ID']), $aActions);
  232. $sLink = BX_DOL_URL_STUDIO . 'builder_permissions.php?page=actions&level=' . $aRow['ID'];
  233. $mixedValue = $this->_oTemplate->parseLink($sLink, _t('_adm_prm_txt_n_actions', $iActions), array(
  234. 'title' => _t('_adm_prm_txt_manage_actions')
  235. ));
  236. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  237. }
  238. protected function _getCellQuotaSize ($mixedValue, $sKey, $aField, $aRow)
  239. {
  240. return parent::_getCellDefault ($mixedValue > 0 ? _t_format_size($mixedValue) : '&infin;', $sKey, $aField, $aRow);
  241. }
  242. protected function _getCellQuotaNumber ($mixedValue, $sKey, $aField, $aRow)
  243. {
  244. return parent::_getCellDefault ($mixedValue > 0 ? $mixedValue : '&infin;', $sKey, $aField, $aRow);
  245. }
  246. protected function _getCellQuotaMaxFileSize ($mixedValue, $sKey, $aField, $aRow)
  247. {
  248. return parent::_getCellDefault ($mixedValue > 0 ? _t_format_size($mixedValue) : '&infin;', $sKey, $aField, $aRow);
  249. }
  250. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  251. {
  252. if ($sType == 'single' && $aRow['Removable'] != 'yes')
  253. return '';
  254. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  255. }
  256. protected function _getIconPreview($iId, $sIconImage = '', $sIcon = '')
  257. {
  258. $bIconImage = !empty($sIconImage);
  259. $aIcons = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIcon($sIcon);
  260. $sIconHtml = $aIcons[2] . $aIcons[3] . $aIcons[4];
  261. $bIconHtml = !empty($sIconHtml) && !$bIconImage;
  262. return $this->_oTemplate->parseHtmlByName('prm_level_icon_preview.html', array(
  263. 'id' => $iId,
  264. 'bx_if:show_icon_empty' => array(
  265. 'condition' => !$bIconImage && !$bIconHtml,
  266. 'content' => array()
  267. ),
  268. 'bx_if:show_icon_image' => array(
  269. 'condition' => $bIconImage,
  270. 'content' => array(
  271. 'js_object' => $this->getJsObject(),
  272. 'url' => $sIconImage,
  273. 'id' => $iId
  274. )
  275. ),
  276. 'bx_if:show_icon_html' => array(
  277. 'condition' => $bIconHtml,
  278. 'content' => array(
  279. 'icon' => $sIconHtml
  280. )
  281. )
  282. ));
  283. }
  284. protected function _getFormObject($sAction, $aLevel = array())
  285. {
  286. bx_import('BxTemplStudioFormView');
  287. $aForm = array(
  288. 'form_attrs' => array(
  289. 'id' => 'adm-prm-level-create',
  290. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  291. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT,
  292. 'enctype' => 'multipart/form-data',
  293. ),
  294. 'params' => array (
  295. 'db' => array(
  296. 'table' => 'sys_acl_levels',
  297. 'key' => 'ID',
  298. 'uri' => '',
  299. 'uri_title' => '',
  300. 'submit_name' => 'do_submit'
  301. ),
  302. ),
  303. 'inputs' => array (
  304. 'id' => array(
  305. 'type' => 'hidden',
  306. 'name' => 'id',
  307. 'value' => isset($aLevel['id']) ? (int)$aLevel['id'] : 0,
  308. 'db' => array (
  309. 'pass' => 'Int',
  310. ),
  311. ),
  312. 'Active' => array(
  313. 'type' => 'hidden',
  314. 'name' => 'Active',
  315. 'value' => 'yes',
  316. 'db' => array (
  317. 'pass' => 'Xss',
  318. ),
  319. ),
  320. 'Purchasable' => array(
  321. 'type' => 'hidden',
  322. 'name' => 'Purchasable',
  323. 'value' => 'no',
  324. 'db' => array (
  325. 'pass' => 'Xss',
  326. ),
  327. ),
  328. 'Removable' => array(
  329. 'type' => 'hidden',
  330. 'name' => 'Removable',
  331. 'value' => 'yes',
  332. 'db' => array (
  333. 'pass' => 'Xss',
  334. ),
  335. ),
  336. 'Name' => array(
  337. 'type' => 'text_translatable',
  338. 'name' => 'Name',
  339. 'caption' => _t('_adm_prm_txt_level_name'),
  340. 'info' => _t('_adm_prm_dsc_level_name'),
  341. 'value' => '_adm_prm_txt_level',
  342. 'required' => '1',
  343. 'db' => array (
  344. 'pass' => 'Xss',
  345. ),
  346. 'checker' => array (
  347. 'func' => 'LengthTranslatable',
  348. 'params' => array(3, 100, 'Name'),
  349. 'error' => _t('_adm_prm_err_level_name'),
  350. ),
  351. ),
  352. 'Description' => array(
  353. 'type' => 'textarea_translatable',
  354. 'name' => 'Description',
  355. 'caption' => _t('_adm_prm_txt_level_description'),
  356. 'info' => _t('_adm_prm_dsc_level_description'),
  357. 'value' => isset($aLevel['description']) ? $aLevel['description'] : '_adm_prm_txt_level',
  358. 'code' => 1,
  359. 'db' => array (
  360. 'pass' => 'XssHtml',
  361. )
  362. ),
  363. 'QuotaSize' => array(
  364. 'type' => 'text',
  365. 'name' => 'QuotaSize',
  366. 'caption' => _t('_adm_prm_txt_level_quota_size'),
  367. 'info' => _t('_adm_prm_dsc_level_quota_size'),
  368. 'value' => isset($aLevel['quota_size']) ? round($aLevel['quota_size'] / self::$iBinMB, 1) : '0',
  369. 'required' => '1',
  370. 'db' => array (
  371. 'pass' => 'Float',
  372. ),
  373. 'checker' => array (
  374. 'func' => 'preg',
  375. 'params' => array('/^[0-9\.]+$/'),
  376. 'error' => _t('_adm_prm_err_level_quota_size'),
  377. ),
  378. ),
  379. 'QuotaMaxFileSize' => array(
  380. 'type' => 'text',
  381. 'name' => 'QuotaMaxFileSize',
  382. 'caption' => _t('_adm_prm_txt_level_quota_max_file_size'),
  383. 'info' => _t('_adm_prm_dsc_level_quota_max_file_size'),
  384. 'value' => isset($aLevel['quota_max_file_size']) ? round($aLevel['quota_max_file_size'] / self::$iBinMB, 1) : '',
  385. 'required' => '1',
  386. 'db' => array (
  387. 'pass' => 'Float',
  388. ),
  389. 'checker' => array (
  390. 'func' => 'preg',
  391. 'params' => array('/^[0-9\.]+$/'),
  392. 'error' => _t('_adm_prm_err_level_quota_max_file_size'),
  393. ),
  394. ),
  395. 'QuotaNumber' => array(
  396. 'type' => 'text',
  397. 'name' => 'QuotaNumber',
  398. 'caption' => _t('_adm_prm_txt_level_quota_number'),
  399. 'info' => _t('_adm_prm_dsc_level_quota_number'),
  400. 'value' => isset($aLevel['quota_number']) ? (int)$aLevel['quota_number'] : '0',
  401. 'required' => '1',
  402. 'db' => array (
  403. 'pass' => 'Int',
  404. ),
  405. 'checker' => array (
  406. 'func' => 'preg',
  407. 'params' => array('/^[0-9]+$/'),
  408. 'error' => _t('_adm_prm_err_level_quota_number'),
  409. ),
  410. ),
  411. 'Icon' => array(
  412. 'type' => 'textarea',
  413. 'name' => 'Icon',
  414. 'caption' => _t('_adm_prm_txt_level_icon'),
  415. 'info' => _t('_adm_prm_dsc_level_icon'),
  416. 'value' => '',
  417. 'required' => '0',
  418. 'code' => 1,
  419. 'db' => array (
  420. 'pass' => 'Xss',
  421. ),
  422. 'checker' => array (
  423. 'func' => '',
  424. 'params' => array(),
  425. 'error' => _t('_adm_prm_err_level_icon'),
  426. ),
  427. 'attrs' => array('class' => 'bx-form-input-textarea-small'),
  428. ),
  429. 'Icon_image' => array(
  430. 'type' => 'file',
  431. 'name' => 'Icon_image',
  432. 'caption' => _t('_adm_prm_txt_level_icon_image'),
  433. 'info' => _t('_adm_prm_dsc_level_icon_image'),
  434. 'value' => '',
  435. 'checker' => array (
  436. 'func' => '',
  437. 'params' => '',
  438. 'error' => _t('_adm_prm_err_level_icon_image'),
  439. ),
  440. ),
  441. 'Icon_preview' => array(
  442. 'type' => 'custom',
  443. 'name' => 'Icon_preview',
  444. 'caption' => _t('_adm_prm_txt_level_icon_image_old'),
  445. 'content' => ''
  446. ),
  447. 'Actions' => array(
  448. 'type' => 'select',
  449. 'name' => 'Actions',
  450. 'caption' => _t('_adm_prm_txt_level_actions_copy'),
  451. 'values' => array(
  452. array('key' => 0, 'value' => _t('_sys_txt_empty'))
  453. ),
  454. ),
  455. 'controls' => array(
  456. 'name' => 'controls',
  457. 'type' => 'input_set',
  458. array(
  459. 'type' => 'submit',
  460. 'name' => 'do_submit',
  461. 'value' => _t('_adm_prm_btn_level_add'),
  462. ),
  463. array (
  464. 'type' => 'reset',
  465. 'name' => 'close',
  466. 'value' => _t('_adm_prm_btn_level_cancel'),
  467. 'attrs' => array(
  468. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  469. 'class' => 'bx-def-margin-sec-left',
  470. ),
  471. )
  472. )
  473. )
  474. );
  475. $aLevels = array();
  476. $this->oDb->getLevels(array('type' => 'all_pair'), $aLevels, false);
  477. foreach($aLevels as $iId => $sName)
  478. $aForm['inputs']['Actions']['values'][] = array('key' => $iId, 'value' => _t($sName));
  479. switch($sAction) {
  480. case 'add':
  481. unset($aForm['inputs']['id']);
  482. unset($aForm['inputs']['Icon_preview']);
  483. $aForm['form_attrs']['id'] .= 'create';
  484. break;
  485. case 'edit':
  486. unset($aForm['inputs']['Active']);
  487. unset($aForm['inputs']['Purchasable']);
  488. unset($aForm['inputs']['Removable']);
  489. unset($aForm['inputs']['Name']);
  490. unset($aForm['inputs']['Actions']);
  491. $aForm['form_attrs']['id'] .= 'edit';
  492. $aForm['inputs']['Icon_image']['caption'] = _t('_adm_prm_txt_level_icon_image_new');
  493. $aForm['inputs']['controls'][0]['value'] = _t('_adm_prm_btn_level_save');
  494. $sIconImage = $sIconFont = "";
  495. if(!empty($aLevel['icon'])) {
  496. if(is_numeric($aLevel['icon']) && (int)$aLevel['icon'] != 0) {
  497. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  498. $sIconImage = $oStorage->getFileUrlById((int)$aLevel['icon']);
  499. } else {
  500. $sIconFont = $aLevel['icon'];
  501. $aForm['inputs']['Icon']['value'] = $sIconFont;
  502. }
  503. }
  504. $aForm['inputs']['Icon_preview']['content'] = $this->_getIconPreview($aLevel['id'], $sIconImage, $sIconFont);
  505. break;
  506. }
  507. return new BxTemplStudioFormView($aForm);
  508. }
  509. protected function _getAvailableId()
  510. {
  511. $aLevels = array();
  512. $this->oDb->getLevels(array('type' =>'all_order_id'), $aLevels, false);
  513. $iId = 1;
  514. foreach($aLevels as $aLevel) {
  515. if($iId != (int)$aLevel['id'])
  516. break;
  517. $iId++;
  518. }
  519. return $iId <= BX_DOL_STUDIO_PERMISSIONS_LEVEL_ID_INT_MAX ? $iId : false;
  520. }
  521. }
  522. /** @} */