1
0

BxBaseStudioPermissionsLevels.php 26 KB

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