BxDevFormsPreValues.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. {
  15. function __construct($aOptions, $oTemplate = false)
  16. {
  17. parent::__construct($aOptions, $oTemplate);
  18. $this->oModule = BxDolModule::getInstance('bx_developer');
  19. $this->sUrlPage = BX_DOL_URL_STUDIO . 'module.php?name=' . $this->oModule->_oConfig->getName() . '&page=forms&form_page=pre_values';
  20. $sModule = bx_get('form_module');
  21. if(!empty($sModule)) {
  22. $this->sModule = bx_process_input($sModule);
  23. $this->_aQueryAppend['module'] = $this->sModule;
  24. }
  25. $sList = bx_get('form_list');
  26. if(!empty($sList)) {
  27. $this->sList = bx_process_input($sList);
  28. $this->_aQueryAppend['list'] = $this->sList;
  29. }
  30. }
  31. public function performActionAdd()
  32. {
  33. $sAction = 'add';
  34. $sFormObject = $this->oModule->_oConfig->getObject('form_forms_prevalue');
  35. $sFormDisplay = $this->oModule->_oConfig->getObject('form_display_forms_prevalue_add');
  36. bx_import('BxDolForm');
  37. $oForm = BxDolForm::getObjectInstance($sFormObject, $sFormDisplay, $this->oModule->_oTemplate);
  38. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&list=' . $this->sList;
  39. $this->onLoad($oForm->aInputs);
  40. $oForm->initChecker();
  41. if($oForm->isSubmittedAndValid()) {
  42. if(!$this->onAdd($oForm))
  43. return;
  44. if(($iId = (int)$oForm->insert()) != 0)
  45. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  46. else
  47. $aRes = array('msg' => _t('_bx_dev_frm_err_prevalues_create'));
  48. $this->_echoResultJson($aRes, true);
  49. } else {
  50. bx_import('BxTemplStudioFunctions');
  51. $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(
  52. 'form_id' => $oForm->aFormAttrs['id'],
  53. 'form' => $oForm->getCode(true),
  54. 'object' => $this->_sObject,
  55. 'action' => $sAction
  56. )));
  57. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  58. }
  59. }
  60. public function performActionEdit()
  61. {
  62. $sAction = 'edit';
  63. $sFormObject = $this->oModule->_oConfig->getObject('form_forms_prevalue');
  64. $sFormDisplay = $this->oModule->_oConfig->getObject('form_display_forms_prevalue_edit');
  65. $aValue = $this->_getItem('getValues');
  66. if($aValue === false) {
  67. $this->_echoResultJson(array());
  68. exit;
  69. }
  70. bx_import('BxDolForm');
  71. $oForm = BxDolForm::getObjectInstance($sFormObject, $sFormDisplay, $this->oModule->_oTemplate);
  72. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&list=' . $this->sList;
  73. $this->onLoad($oForm->aInputs);
  74. $oForm->initChecker($aValue);
  75. if($oForm->isSubmittedAndValid()) {
  76. if($oForm->update($aValue['id']) !== false) {
  77. $this->onSave($oForm);
  78. $aRes = array('grid' => $this->getCode(false), 'blink' => $aValue['id']);
  79. } else
  80. $aRes = array('msg' => _t('_bx_dev_frm_err_prevalues_edit'));
  81. $this->_echoResultJson($aRes, true);
  82. } else {
  83. bx_import('BxTemplStudioFunctions');
  84. $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(
  85. 'form_id' => $oForm->aFormAttrs['id'],
  86. 'form' => $oForm->getCode(true),
  87. 'object' => $this->_sObject,
  88. 'action' => $sAction
  89. )));
  90. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  91. }
  92. }
  93. private function onLoad(&$aInputs)
  94. {
  95. $aLists = array();
  96. $this->oDb->getLists(array('type' => 'all'), $aLists, false);
  97. foreach($aLists as $aList)
  98. $aInputs['Key']['values'][$aList['key']] = _t($aList['title']);
  99. asort($aInputs['Key']['values']);
  100. $aInputs['Key']['values'] = array_merge(array('' => _t('_bx_dev_frm_txt_prevalues_key_select')), $aInputs['Key']['values']);
  101. $aInputs['Key']['value'] = $this->sList;
  102. $aInputs['Value']['value'] = $this->_getAvailableSetValue($this->sList);
  103. }
  104. private function onAdd(&$oForm)
  105. {
  106. $aList = array();
  107. $this->oDb->getLists(array('type' => 'by_key', 'value' => $oForm->getCleanValue('Key')), $aList, false);
  108. if((int)$aList['use_for_sets'] == 1) {
  109. $mixedValue = $oForm->getCleanValue('Value');
  110. if(!$this->canUseForSet($mixedValue)) {
  111. if($this->oDb->isListUsedInSet($this->sList)) {
  112. $this->_echoResultJson(array('msg' => _t('_bx_dev_frm_err_prevalues_create_forbidden', BX_DOL_STUDIO_FIELD_PRE_VALUE_INT_MAX)), true);
  113. return false;
  114. }
  115. $this->oDb->updateList($aList['id'], array('use_for_sets' => '0'));
  116. }
  117. }
  118. return true;
  119. }
  120. private function onSave(&$oForm)
  121. {
  122. $aList = array();
  123. $this->oDb->getLists(array('type' => 'by_key', 'value' => $oForm->getCleanValue('Key')), $aList, false);
  124. $iUseInSets = 1;
  125. $aValues = BxDolForm::getDataItems($aList['key']);
  126. foreach($aValues as $mixedValue => $sTitle)
  127. if(!$this->canUseForSet($mixedValue)) {
  128. $iUseInSets = 0;
  129. break;
  130. }
  131. if($iUseInSets != (int)$aList['use_for_sets'])
  132. $this->oDb->updateList($aList['id'], array('use_for_sets' => $iUseInSets));
  133. }
  134. }
  135. /** @} */