BxDevFormsForms.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <? 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('BxTemplStudioFormsForms');
  13. class BxDevFormsForms extends BxTemplStudioFormsForms {
  14. protected $oModule;
  15. function __construct($aOptions, $oTemplate = false) {
  16. parent::__construct($aOptions, $oTemplate);
  17. $this->oModule = BxDolModule::getInstance('bx_developer');
  18. $this->sUrlViewDisplays = BX_DOL_URL_STUDIO . 'module.php?name=' . $this->oModule->_oConfig->getName() . '&page=forms&form_page=displays&form_module=%s&form_object=%s';
  19. $this->_aOptions['actions_single']['export']['attr']['title'] = _t('_bx_dev_frm_btn_forms_gl_export');
  20. }
  21. public function performActionAdd() {
  22. $sAction = 'add';
  23. bx_import('BxDolForm');
  24. $oForm = BxDolForm::getObjectInstance('mod_dev_forms_form', 'mod_dev_forms_form_add');
  25. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction;
  26. $oForm->aInputs['module']['values'] = array_merge(array('' => _t('_bx_dev_frm_txt_select_module')), BxDolStudioUtils::getModules());
  27. $oForm->initChecker();
  28. if($oForm->isSubmittedAndValid()) {
  29. $sObject = uriGenerate($oForm->getCleanValue('object'), 'sys_objects_form', 'object', 'object');
  30. BxDolForm::setSubmittedValue('object', $sObject, $oForm->aFormAttrs['method']);
  31. if(($iId = (int)$oForm->insert()) != 0)
  32. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  33. else
  34. $aRes = array('msg' => _t('_bx_dev_frm_err_forms_create'));
  35. $this->_echoResultJson($aRes, true);
  36. }
  37. else {
  38. bx_import('BxTemplStudioFunctions');
  39. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('bx-dev-frm-form-create-popup', _t('_bx_dev_frm_txt_forms_create_popup'), $this->oModule->_oTemplate->parseHtmlByName('form_add_form.html', array(
  40. 'form_id' => $oForm->aFormAttrs['id'],
  41. 'form' => $oForm->getCode(true),
  42. 'object' => $this->_sObject,
  43. 'action' => $sAction
  44. )));
  45. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  46. }
  47. }
  48. public function performActionEdit() {
  49. $sAction = 'edit';
  50. $aIds = bx_get('ids');
  51. if(!$aIds || !is_array($aIds)) {
  52. $iId = (int)bx_get('id');
  53. if(!$iId) {
  54. $this->_echoResultJson(array());
  55. exit;
  56. }
  57. $aIds = array($iId);
  58. }
  59. $iId = $aIds[0];
  60. $aForm = array();
  61. $this->oDb->getForms(array('type' => 'by_id', 'value' => $iId), $aForm, false);
  62. if(empty($aForm) || !is_array($aForm)){
  63. $this->_echoResultJson(array());
  64. exit;
  65. }
  66. bx_import('BxDolForm');
  67. $oForm = BxDolForm::getObjectInstance('mod_dev_forms_form', 'mod_dev_forms_form_edit');
  68. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction;
  69. $oForm->aInputs['module']['values'] = array_merge(array('' => _t('_bx_dev_frm_txt_select_module')), BxDolStudioUtils::getModules());
  70. $oForm->aInputs['controls'][0]['value'] = _t('_bx_dev_frm_btn_forms_save');
  71. $aForm['form_attrs'] = BxDevFunctions::unserializeString($aForm['form_attrs']);
  72. $aForm['params'] = BxDevFunctions::unserializeString($aForm['params']);
  73. $oForm->initChecker($aForm);
  74. if($oForm->isSubmittedAndValid()) {
  75. $sValue = BxDolForm::getSubmittedValue('form_attrs', $oForm->aFormAttrs['method']);
  76. $sValue = BxDevFunctions::serializeString($sValue);
  77. BxDolForm::setSubmittedValue('form_attrs', $sValue, $oForm->aFormAttrs['method']);
  78. $sValue = BxDolForm::getSubmittedValue('params', $oForm->aFormAttrs['method']);
  79. $sValue = BxDevFunctions::serializeString($sValue);
  80. BxDolForm::setSubmittedValue('params', $sValue, $oForm->aFormAttrs['method']);
  81. if($oForm->update($iId) !== false)
  82. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  83. else
  84. $aRes = array('msg' => _t('_bx_dev_frm_err_forms_edit'));
  85. $this->_echoResultJson($aRes, true);
  86. }
  87. else {
  88. bx_import('BxTemplStudioFunctions');
  89. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('bx-dev-frm-form-edit-popup', _t('_bx_dev_frm_txt_forms_edit_popup', _t($aForm['title'])), $this->oModule->_oTemplate->parseHtmlByName('form_add_form.html', array(
  90. 'form_id' => $oForm->aFormAttrs['id'],
  91. 'form' => $oForm->getCode(true),
  92. 'object' => $this->_sObject,
  93. 'action' => $sAction
  94. )));
  95. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  96. }
  97. }
  98. public function performActionExport() {
  99. $sContentInsert = $sContentDelete = "";
  100. $aIds = bx_get('ids');
  101. if(!$aIds || !is_array($aIds)) {
  102. $iId = (int)bx_get('id');
  103. if(!$iId) {
  104. $this->_echoResultJson(array());
  105. exit;
  106. }
  107. $aIds = array($iId);
  108. }
  109. $iId = $aIds[0];
  110. $aForm = array();
  111. $this->oDb->getForms(array('type' => 'by_id', 'value' => $iId), $aForm, false);
  112. if(empty($aForm) || !is_array($aForm)){
  113. $this->_echoResultJson(array());
  114. exit;
  115. }
  116. $sContentInsert .= ($this->oModule->_oDb->getQueryInsert('sys_objects_form', array($aForm), "Dumping data for '" . $aForm['object'] . "' form"));
  117. $sContentDelete .= ($this->oModule->_oDb->getQueryDelete('sys_objects_form', 'object', array($aForm), "Deleting data for '" . $aForm['object'] . "' form"));
  118. $aDisplays = array();
  119. $this->oDb->getDisplays(array('type' => 'by_object', 'value' => $aForm['object']), $aDisplays, false);
  120. $sContentInsert .= $this->oModule->_oDb->getQueryInsert('sys_form_displays', $aDisplays, false, array('id', 'name'));
  121. $sContentDelete .= $this->oModule->_oDb->getQueryDelete('sys_form_displays', 'object', array($aForm), false);
  122. $aFields = array();
  123. $this->oDb->getFields(array('type' => 'dump_inputs', 'value' => $aForm['object']), $aFields, false);
  124. $sContentInsert .= $this->oModule->_oDb->getQueryInsert('sys_form_inputs', $aFields);
  125. $sContentDelete .= $this->oModule->_oDb->getQueryDelete('sys_form_inputs', 'object', array($aForm), false);
  126. $aConnections = array();
  127. $this->oDb->getFields(array('type' => 'dump_connections', 'value' => $aForm['object']), $aConnections, false);
  128. $sContentInsert .= $this->oModule->_oDb->getQueryInsert('sys_form_display_inputs', $aConnections);
  129. $sContentDelete .= $this->oModule->_oDb->getQueryDelete('sys_form_display_inputs', 'display_name', $aDisplays);
  130. $aFormStructure = array(
  131. 'form_attrs' => array(),
  132. 'inputs' => array (
  133. 'insert' => array(
  134. 'type' => 'textarea',
  135. 'name' => 'insert',
  136. 'caption' => _t('_bx_dev_frm_txt_forms_export_insert'),
  137. 'value' => $sContentInsert,
  138. ),
  139. 'delete' => array(
  140. 'type' => 'textarea',
  141. 'name' => 'delete',
  142. 'caption' => _t('_bx_dev_frm_txt_forms_export_delete'),
  143. 'value' => $sContentDelete,
  144. ),
  145. 'done' => array (
  146. 'type' => 'button',
  147. 'name' => 'done',
  148. 'value' => _t('_bx_dev_frm_btn_forms_done'),
  149. 'attrs' => array(
  150. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  151. ),
  152. )
  153. )
  154. );
  155. $oForm = new BxTemplStudioFormView($aFormStructure);
  156. bx_import('BxTemplStudioFunctions');
  157. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('bx-dev-frm-form-export-popup', _t('_bx_dev_frm_txt_forms_export_popup', _t($aForm['title'])), $this->oModule->_oTemplate->parseHtmlByName('form_export.html', array(
  158. 'content' => $oForm->getCode()
  159. )));
  160. $this->_echoResultJson(array('popup' => $sContent), true);
  161. }
  162. }
  163. /** @} */