BxDevFormsPreValues.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Developer Developer
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolModule');
  12. bx_import('BxTemplStudioFormsPreValues');
  13. class BxDevFormsPreValues extends BxTemplStudioFormsPreValues {
  14. function __construct($aOptions, $oTemplate = false) {
  15. parent::__construct($aOptions, $oTemplate);
  16. $this->oModule = BxDolModule::getInstance('bx_developer');
  17. $this->sUrlPage = BX_DOL_URL_STUDIO . 'module.php?name=' . $this->oModule->_oConfig->getName() . '&page=forms&form_page=pre_values';
  18. $sModule = bx_get('form_module');
  19. if(!empty($sModule)) {
  20. $this->sModule = bx_process_input($sModule);
  21. $this->_aQueryAppend['module'] = $this->sModule;
  22. }
  23. $sList = bx_get('form_list');
  24. if(!empty($sList)) {
  25. $this->sList = bx_process_input($sList);
  26. $this->_aQueryAppend['list'] = $this->sList;
  27. }
  28. }
  29. public function performActionAdd() {
  30. $sAction = 'add';
  31. bx_import('BxDolForm');
  32. $oForm = BxDolForm::getObjectInstance('mod_dev_forms_prevalue', 'mod_dev_forms_prevalue_add');
  33. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&list=' . $this->sList;
  34. $this->onLoad($oForm->aInputs);
  35. $oForm->initChecker();
  36. if($oForm->isSubmittedAndValid()) {
  37. if(!$this->onAdd($oForm))
  38. return;
  39. if(($iId = (int)$oForm->insert()) != 0)
  40. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  41. else
  42. $aRes = array('msg' => _t('_bx_dev_frm_err_prevalues_create'));
  43. $this->_echoResultJson($aRes, true);
  44. }
  45. else {
  46. bx_import('BxTemplStudioFunctions');
  47. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('bx-dev-frm-prevalue-create-popup', _t('_bx_dev_frm_txt_prevalues_create_popup'), $this->oModule->_oTemplate->parseHtmlByName('form_add_value.html', array(
  48. 'form_id' => $oForm->aFormAttrs['id'],
  49. 'form' => $oForm->getCode(true),
  50. 'object' => $this->_sObject,
  51. 'action' => $sAction
  52. )));
  53. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  54. }
  55. }
  56. public function performActionEdit() {
  57. $sAction = 'edit';
  58. $aValue = $this->_getItem('getValues');
  59. if($aValue === false) {
  60. $this->_echoResultJson(array());
  61. exit;
  62. }
  63. bx_import('BxDolForm');
  64. $oForm = BxDolForm::getObjectInstance('mod_dev_forms_prevalue', 'mod_dev_forms_prevalue_edit');
  65. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&list=' . $this->sList;
  66. $this->onLoad($oForm->aInputs);
  67. $oForm->initChecker($aValue);
  68. if($oForm->isSubmittedAndValid()) {
  69. if($oForm->update($aValue['id']) !== false) {
  70. $this->onSave($oForm);
  71. $aRes = array('grid' => $this->getCode(false), 'blink' => $aValue['id']);
  72. }
  73. else
  74. $aRes = array('msg' => _t('_bx_dev_frm_err_prevalues_edit'));
  75. $this->_echoResultJson($aRes, true);
  76. }
  77. else {
  78. bx_import('BxTemplStudioFunctions');
  79. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('bx-dev-frm-prevalue-edit-popup', _t('_bx_dev_frm_txt_prevalues_edit_popup', _t($aValue['lkey'])), $this->oModule->_oTemplate->parseHtmlByName('form_add_value.html', array(
  80. 'form_id' => $oForm->aFormAttrs['id'],
  81. 'form' => $oForm->getCode(true),
  82. 'object' => $this->_sObject,
  83. 'action' => $sAction
  84. )));
  85. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  86. }
  87. }
  88. private function onLoad(&$aInputs) {
  89. $aLists = array();
  90. $this->oDb->getLists(array('type' => 'all'), $aLists, false);
  91. foreach($aLists as $aList)
  92. $aInputs['Key']['values'][$aList['key']] = _t($aList['title']);
  93. asort($aInputs['Key']['values']);
  94. $aInputs['Key']['values'] = array_merge(array('' => _t('_bx_dev_frm_txt_prevalues_key_select')), $aInputs['Key']['values']);
  95. $aInputs['Key']['value'] = $this->sList;
  96. $aInputs['Value']['value'] = $this->_getAvailableSetValue($this->sList);
  97. }
  98. private function onAdd(&$oForm) {
  99. $aList = array();
  100. $this->oDb->getLists(array('type' => 'by_key', 'value' => $oForm->getCleanValue('Key')), $aList, false);
  101. if((int)$aList['use_for_sets'] == 1) {
  102. $mixedValue = $oForm->getCleanValue('Value');
  103. if(!$this->canUseForSet($mixedValue)) {
  104. if($this->oDb->isListUsedInSet($this->sList)) {
  105. $this->_echoResultJson(array('msg' => _t('_bx_dev_frm_err_prevalues_create_forbidden', BX_DOL_STUDIO_FIELD_PRE_VALUE_INT_MAX)), true);
  106. return false;
  107. }
  108. $this->oDb->updateList($aList['id'], array('use_for_sets' => '0'));
  109. }
  110. }
  111. return true;
  112. }
  113. private function onSave(&$oForm) {
  114. $aList = array();
  115. $this->oDb->getLists(array('type' => 'by_key', 'value' => $oForm->getCleanValue('Key')), $aList, false);
  116. $iUseInSets = 1;
  117. $aValues = BxDolForm::getDataItems($aList['key']);
  118. foreach($aValues as $mixedValue => $sTitle)
  119. if(!$this->canUseForSet($mixedValue)) {
  120. $iUseInSets = 0;
  121. break;
  122. }
  123. if($iUseInSets != (int)$aList['use_for_sets'])
  124. $this->oDb->updateList($aList['id'], array('use_for_sets' => $iUseInSets));
  125. }
  126. }
  127. /** @} */