BxBaseStudioPermissionsLevels.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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-item-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 _getFormObject($sAction, $aLevel = array())
  257. {
  258. bx_import('BxTemplStudioFormView');
  259. $aForm = array(
  260. 'form_attrs' => array(
  261. 'id' => 'adm-prm-level-create',
  262. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  263. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT,
  264. 'enctype' => 'multipart/form-data',
  265. ),
  266. 'params' => array (
  267. 'db' => array(
  268. 'table' => 'sys_acl_levels',
  269. 'key' => 'ID',
  270. 'uri' => '',
  271. 'uri_title' => '',
  272. 'submit_name' => 'do_submit'
  273. ),
  274. ),
  275. 'inputs' => array (
  276. 'id' => array(
  277. 'type' => 'hidden',
  278. 'name' => 'id',
  279. 'value' => isset($aLevel['id']) ? (int)$aLevel['id'] : 0,
  280. 'db' => array (
  281. 'pass' => 'Int',
  282. ),
  283. ),
  284. 'Active' => array(
  285. 'type' => 'hidden',
  286. 'name' => 'Active',
  287. 'value' => 'yes',
  288. 'db' => array (
  289. 'pass' => 'Xss',
  290. ),
  291. ),
  292. 'Purchasable' => array(
  293. 'type' => 'hidden',
  294. 'name' => 'Purchasable',
  295. 'value' => 'no',
  296. 'db' => array (
  297. 'pass' => 'Xss',
  298. ),
  299. ),
  300. 'Removable' => array(
  301. 'type' => 'hidden',
  302. 'name' => 'Removable',
  303. 'value' => 'yes',
  304. 'db' => array (
  305. 'pass' => 'Xss',
  306. ),
  307. ),
  308. 'Name' => array(
  309. 'type' => 'text_translatable',
  310. 'name' => 'Name',
  311. 'caption' => _t('_adm_prm_txt_level_name'),
  312. 'info' => _t('_adm_prm_dsc_level_name'),
  313. 'value' => '_adm_prm_txt_level',
  314. 'required' => '1',
  315. 'db' => array (
  316. 'pass' => 'Xss',
  317. ),
  318. 'checker' => array (
  319. 'func' => 'LengthTranslatable',
  320. 'params' => array(3, 100, 'Name'),
  321. 'error' => _t('_adm_prm_err_level_name'),
  322. ),
  323. ),
  324. 'Description' => array(
  325. 'type' => 'textarea_translatable',
  326. 'name' => 'Description',
  327. 'caption' => _t('_adm_prm_txt_level_description'),
  328. 'info' => _t('_adm_prm_dsc_level_description'),
  329. 'value' => isset($aLevel['description']) ? $aLevel['description'] : '_adm_prm_txt_level',
  330. 'code' => 1,
  331. 'db' => array (
  332. 'pass' => 'XssHtml',
  333. )
  334. ),
  335. 'QuotaSize' => array(
  336. 'type' => 'text',
  337. 'name' => 'QuotaSize',
  338. 'caption' => _t('_adm_prm_txt_level_quota_size'),
  339. 'info' => _t('_adm_prm_dsc_level_quota_size'),
  340. 'value' => isset($aLevel['quota_size']) ? round($aLevel['quota_size'] / self::$iBinMB, 1) : '0',
  341. 'required' => '1',
  342. 'db' => array (
  343. 'pass' => 'Float',
  344. ),
  345. 'checker' => array (
  346. 'func' => 'preg',
  347. 'params' => array('/^[0-9\.]+$/'),
  348. 'error' => _t('_adm_prm_err_level_quota_size'),
  349. ),
  350. ),
  351. 'QuotaMaxFileSize' => array(
  352. 'type' => 'text',
  353. 'name' => 'QuotaMaxFileSize',
  354. 'caption' => _t('_adm_prm_txt_level_quota_max_file_size'),
  355. 'info' => _t('_adm_prm_dsc_level_quota_max_file_size'),
  356. 'value' => isset($aLevel['quota_max_file_size']) ? round($aLevel['quota_max_file_size'] / self::$iBinMB, 1) : '',
  357. 'required' => '1',
  358. 'db' => array (
  359. 'pass' => 'Float',
  360. ),
  361. 'checker' => array (
  362. 'func' => 'preg',
  363. 'params' => array('/^[0-9\.]+$/'),
  364. 'error' => _t('_adm_prm_err_level_quota_max_file_size'),
  365. ),
  366. ),
  367. 'QuotaNumber' => array(
  368. 'type' => 'text',
  369. 'name' => 'QuotaNumber',
  370. 'caption' => _t('_adm_prm_txt_level_quota_number'),
  371. 'info' => _t('_adm_prm_dsc_level_quota_number'),
  372. 'value' => isset($aLevel['quota_number']) ? (int)$aLevel['quota_number'] : '0',
  373. 'required' => '1',
  374. 'db' => array (
  375. 'pass' => 'Int',
  376. ),
  377. 'checker' => array (
  378. 'func' => 'preg',
  379. 'params' => array('/^[0-9]+$/'),
  380. 'error' => _t('_adm_prm_err_level_quota_number'),
  381. ),
  382. ),
  383. 'PasswordExpired' => array(
  384. 'type' => 'text',
  385. 'name' => 'PasswordExpired',
  386. 'caption' => _t('_adm_prm_txt_level_password_expired'),
  387. 'info' => _t('_adm_prm_dsc_level_password_expired'),
  388. 'value' => isset($aLevel['password_expired']) ? (int)$aLevel['password_expired'] : '0',
  389. 'required' => '1',
  390. 'db' => array (
  391. 'pass' => 'Int',
  392. ),
  393. 'checker' => array (
  394. 'func' => 'preg',
  395. 'params' => array('/^[0-9]+$/'),
  396. 'error' => _t('_adm_prm_err_level_password_expired'),
  397. ),
  398. ),
  399. 'PasswordExpiredNotify' => array(
  400. 'type' => 'text',
  401. 'name' => 'PasswordExpiredNotify',
  402. 'caption' => _t('_adm_prm_txt_level_password_expired_notify'),
  403. 'info' => _t('_adm_prm_dsc_level_password_expired_notify'),
  404. 'value' => isset($aLevel['password_expired_notify']) ? (int)$aLevel['password_expired_notify'] : '0',
  405. 'required' => '1',
  406. 'db' => array (
  407. 'pass' => 'Int',
  408. ),
  409. 'checker' => array (
  410. 'func' => 'preg',
  411. 'params' => array('/^[0-9]+$/'),
  412. 'error' => _t('_adm_prm_err_level_password_expired_notify'),
  413. ),
  414. ),
  415. 'Icon' => array(
  416. 'type' => 'textarea',
  417. 'name' => 'Icon',
  418. 'caption' => _t('_adm_prm_txt_level_icon'),
  419. 'info' => _t('_adm_prm_dsc_level_icon'),
  420. 'value' => '',
  421. 'required' => '0',
  422. 'code' => 1,
  423. 'db' => array (
  424. 'pass' => 'Xss',
  425. ),
  426. 'checker' => array (
  427. 'func' => '',
  428. 'params' => array(),
  429. 'error' => _t('_adm_prm_err_level_icon'),
  430. ),
  431. 'attrs' => array('class' => 'bx-form-input-textarea-small'),
  432. ),
  433. 'Icon_image' => array(
  434. 'type' => 'file',
  435. 'name' => 'Icon_image',
  436. 'caption' => _t('_adm_prm_txt_level_icon_image'),
  437. 'info' => _t('_adm_prm_dsc_level_icon_image'),
  438. 'value' => '',
  439. 'checker' => array (
  440. 'func' => '',
  441. 'params' => '',
  442. 'error' => _t('_adm_prm_err_level_icon_image'),
  443. ),
  444. ),
  445. 'Icon_preview' => array(
  446. 'type' => 'custom',
  447. 'name' => 'Icon_preview',
  448. 'caption' => _t('_adm_prm_txt_level_icon_image_old'),
  449. 'content' => ''
  450. ),
  451. 'Actions' => array(
  452. 'type' => 'select',
  453. 'name' => 'Actions',
  454. 'caption' => _t('_adm_prm_txt_level_actions_copy'),
  455. 'values' => array(
  456. array('key' => 0, 'value' => _t('_sys_txt_empty'))
  457. ),
  458. ),
  459. 'controls' => array(
  460. 'name' => 'controls',
  461. 'type' => 'input_set',
  462. array(
  463. 'type' => 'submit',
  464. 'name' => 'do_submit',
  465. 'value' => _t('_adm_prm_btn_level_add'),
  466. ),
  467. array (
  468. 'type' => 'reset',
  469. 'name' => 'close',
  470. 'value' => _t('_adm_prm_btn_level_cancel'),
  471. 'attrs' => array(
  472. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  473. 'class' => 'bx-def-margin-sec-left',
  474. ),
  475. )
  476. )
  477. )
  478. );
  479. $aLevels = array();
  480. $this->oDb->getLevels(array('type' => 'all_pair'), $aLevels, false);
  481. foreach($aLevels as $iId => $sName)
  482. $aForm['inputs']['Actions']['values'][] = array('key' => $iId, 'value' => _t($sName));
  483. switch($sAction) {
  484. case 'add':
  485. unset($aForm['inputs']['id']);
  486. unset($aForm['inputs']['Icon_preview']);
  487. $aForm['form_attrs']['id'] .= 'create';
  488. break;
  489. case 'edit':
  490. unset($aForm['inputs']['Active']);
  491. unset($aForm['inputs']['Purchasable']);
  492. unset($aForm['inputs']['Removable']);
  493. unset($aForm['inputs']['Name']);
  494. unset($aForm['inputs']['Actions']);
  495. $aForm['form_attrs']['id'] .= 'edit';
  496. $aForm['inputs']['Icon_image']['caption'] = _t('_adm_prm_txt_level_icon_image_new');
  497. $aForm['inputs']['controls'][0]['value'] = _t('_adm_prm_btn_level_save');
  498. $sIconImage = $sIconFont = "";
  499. if(!empty($aLevel['icon'])) {
  500. if(is_numeric($aLevel['icon']) && (int)$aLevel['icon'] != 0) {
  501. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  502. $sIconImage = $oStorage->getFileUrlById((int)$aLevel['icon']);
  503. } else {
  504. $sIconFont = $aLevel['icon'];
  505. $aForm['inputs']['Icon']['value'] = $sIconFont;
  506. }
  507. }
  508. $aForm['inputs']['Icon_preview']['content'] = $this->_getIconPreview($aLevel['id'], $sIconImage, $sIconFont);
  509. break;
  510. }
  511. return new BxTemplStudioFormView($aForm);
  512. }
  513. protected function _getAvailableId()
  514. {
  515. $aLevels = array();
  516. $this->oDb->getLevels(array('type' =>'all_order_id'), $aLevels, false);
  517. $iId = 1;
  518. foreach($aLevels as $aLevel) {
  519. if($iId != (int)$aLevel['id'])
  520. break;
  521. $iId++;
  522. }
  523. return $iId <= BX_DOL_STUDIO_PERMISSIONS_LEVEL_ID_INT_MAX ? $iId : false;
  524. }
  525. }
  526. /** @} */