BxBaseStudioPermissionsLevels.php 25 KB

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