1
0

BxDevFormsPreValues.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. bx_import('BxDolForm');
  35. $oForm = BxDolForm::getObjectInstance('mod_dev_forms_prevalue', 'mod_dev_forms_prevalue_add');
  36. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&list=' . $this->sList;
  37. $this->onLoad($oForm->aInputs);
  38. $oForm->initChecker();
  39. if($oForm->isSubmittedAndValid()) {
  40. if(!$this->onAdd($oForm))
  41. return;
  42. if(($iId = (int)$oForm->insert()) != 0)
  43. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  44. else
  45. $aRes = array('msg' => _t('_bx_dev_frm_err_prevalues_create'));
  46. $this->_echoResultJson($aRes, true);
  47. } else {
  48. bx_import('BxTemplStudioFunctions');
  49. $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(
  50. 'form_id' => $oForm->aFormAttrs['id'],
  51. 'form' => $oForm->getCode(true),
  52. 'object' => $this->_sObject,
  53. 'action' => $sAction
  54. )));
  55. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  56. }
  57. }
  58. public function performActionEdit()
  59. {
  60. $sAction = 'edit';
  61. $aValue = $this->_getItem('getValues');
  62. if($aValue === false) {
  63. $this->_echoResultJson(array());
  64. exit;
  65. }
  66. bx_import('BxDolForm');
  67. $oForm = BxDolForm::getObjectInstance('mod_dev_forms_prevalue', 'mod_dev_forms_prevalue_edit');
  68. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&list=' . $this->sList;
  69. $this->onLoad($oForm->aInputs);
  70. $oForm->initChecker($aValue);
  71. if($oForm->isSubmittedAndValid()) {
  72. if($oForm->update($aValue['id']) !== false) {
  73. $this->onSave($oForm);
  74. $aRes = array('grid' => $this->getCode(false), 'blink' => $aValue['id']);
  75. } else
  76. $aRes = array('msg' => _t('_bx_dev_frm_err_prevalues_edit'));
  77. $this->_echoResultJson($aRes, true);
  78. } else {
  79. bx_import('BxTemplStudioFunctions');
  80. $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(
  81. 'form_id' => $oForm->aFormAttrs['id'],
  82. 'form' => $oForm->getCode(true),
  83. 'object' => $this->_sObject,
  84. 'action' => $sAction
  85. )));
  86. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  87. }
  88. }
  89. private function onLoad(&$aInputs)
  90. {
  91. $aLists = array();
  92. $this->oDb->getLists(array('type' => 'all'), $aLists, false);
  93. foreach($aLists as $aList)
  94. $aInputs['Key']['values'][$aList['key']] = _t($aList['title']);
  95. asort($aInputs['Key']['values']);
  96. $aInputs['Key']['values'] = array_merge(array('' => _t('_bx_dev_frm_txt_prevalues_key_select')), $aInputs['Key']['values']);
  97. $aInputs['Key']['value'] = $this->sList;
  98. $aInputs['Value']['value'] = $this->_getAvailableSetValue($this->sList);
  99. }
  100. private function onAdd(&$oForm)
  101. {
  102. $aList = array();
  103. $this->oDb->getLists(array('type' => 'by_key', 'value' => $oForm->getCleanValue('Key')), $aList, false);
  104. if((int)$aList['use_for_sets'] == 1) {
  105. $mixedValue = $oForm->getCleanValue('Value');
  106. if(!$this->canUseForSet($mixedValue)) {
  107. if($this->oDb->isListUsedInSet($this->sList)) {
  108. $this->_echoResultJson(array('msg' => _t('_bx_dev_frm_err_prevalues_create_forbidden', BX_DOL_STUDIO_FIELD_PRE_VALUE_INT_MAX)), true);
  109. return false;
  110. }
  111. $this->oDb->updateList($aList['id'], array('use_for_sets' => '0'));
  112. }
  113. }
  114. return true;
  115. }
  116. private function onSave(&$oForm)
  117. {
  118. $aList = array();
  119. $this->oDb->getLists(array('type' => 'by_key', 'value' => $oForm->getCleanValue('Key')), $aList, false);
  120. $iUseInSets = 1;
  121. $aValues = BxDolForm::getDataItems($aList['key']);
  122. foreach($aValues as $mixedValue => $sTitle)
  123. if(!$this->canUseForSet($mixedValue)) {
  124. $iUseInSets = 0;
  125. break;
  126. }
  127. if($iUseInSets != (int)$aList['use_for_sets'])
  128. $this->oDb->updateList($aList['id'], array('use_for_sets' => $iUseInSets));
  129. }
  130. }
  131. /** @} */