1
0

BxBaseStudioPermissionsLevels.php 24 KB

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