update.class.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. /**
  11. * Loads form customization set editing panel
  12. *
  13. * @package modx
  14. * @subpackage manager.controllers
  15. */
  16. class SecurityFormsSetUpdateManagerController extends modManagerController {
  17. public $setArray = array();
  18. /**
  19. * Check for any permissions or requirements to load page
  20. * @return bool
  21. */
  22. public function checkPermissions() {
  23. return $this->modx->hasPermission('customize_forms');
  24. }
  25. /**
  26. * Register custom CSS/JS for the page
  27. * @return void
  28. */
  29. public function loadCustomCssJs() {
  30. $mgrUrl = $this->modx->getOption('manager_url',null,MODX_MANAGER_URL);
  31. $this->addJavascript($mgrUrl.'assets/modext/widgets/fc/modx.fc.common.js');
  32. $this->addJavascript($mgrUrl.'assets/modext/widgets/fc/modx.panel.fcset.js');
  33. $this->addJavascript($mgrUrl.'assets/modext/sections/fc/set/update.js');
  34. $this->addHtml('<script type="text/javascript">
  35. // <![CDATA[
  36. Ext.onReady(function() {
  37. MODx.load({
  38. xtype: "modx-page-fc-set-update"
  39. ,set: "'.$this->setArray['id'].'"
  40. ,record: '.$this->modx->toJSON($this->setArray).'
  41. });
  42. });
  43. // ]]>
  44. </script>');
  45. }
  46. /**
  47. * Custom logic code here for setting placeholders, etc
  48. * @param array $scriptProperties
  49. * @return mixed
  50. */
  51. public function process(array $scriptProperties = array()) {
  52. $placeholders = array();
  53. /* get profile */
  54. if (empty($scriptProperties['id'])) return $this->failure($this->modx->lexicon('set_err_ns'));
  55. $c = $this->modx->newQuery('modFormCustomizationSet');
  56. $c->leftJoin('modTemplate','Template');
  57. $c->select($this->modx->getSelectColumns('modFormCustomizationSet','modFormCustomizationSet'));
  58. $c->select(array(
  59. 'Template.templatename',
  60. ));
  61. $c->where(array(
  62. 'id' => $scriptProperties['id'],
  63. ));
  64. /** @var modFormCustomizationSet $set */
  65. $set = $this->modx->getObject('modFormCustomizationSet',$c);
  66. if (empty($set)) return $this->failure($this->modx->lexicon('set_err_nfs',array('id' => $scriptProperties['id'])));
  67. $this->setArray = $set->toArray();
  68. $setData = $set->getData();
  69. /* format fields */
  70. $this->setArray['fields'] = array();
  71. if (!empty($setData['fields'])) {
  72. foreach ($setData['fields'] as $field) {
  73. $this->setArray['fields'][] = array(
  74. $field['id'],
  75. $field['action'],
  76. $field['name'],
  77. $field['tab'],
  78. (int)$field['tab_rank'],
  79. $field['other'],
  80. (int)$field['rank'],
  81. (boolean)$field['visible'],
  82. $field['label'],
  83. $field['default_value'],
  84. );
  85. }
  86. }
  87. /* format tabs */
  88. $this->setArray['tabs'] = array();
  89. if (!empty($setData['tabs'])) {
  90. foreach ($setData['tabs'] as $tab) {
  91. $this->setArray['tabs'][] = array(
  92. (int)$tab['id'],
  93. $tab['action'],
  94. $tab['name'],
  95. !empty($tab['form']) ? $tab['form'] : '',
  96. !empty($tab['other']) ? $tab['other'] : '',
  97. (int)$tab['rank'],
  98. (boolean)$tab['visible'],
  99. $tab['label'],
  100. $tab['type'],
  101. 'core',
  102. );
  103. }
  104. }
  105. /* format tvs */
  106. $this->setArray['tvs'] = array();
  107. if (!empty($setData['tvs'])) {
  108. foreach ($setData['tvs'] as $tv) {
  109. $this->setArray['tvs'][] = array(
  110. (int)$tv['id'],
  111. $tv['name'],
  112. $tv['tab'],
  113. (int)$tv['rank'],
  114. (boolean)$tv['visible'],
  115. $tv['label'],
  116. $tv['default_value'],
  117. !empty($tv['category_name']) ? $tv['category_name'] : $this->modx->lexicon('none'),
  118. htmlspecialchars($tv['default_text'],null,$this->modx->getOption('modx_charset',null,'UTF-8')),
  119. );
  120. }
  121. }
  122. if (empty($this->setArray['template'])) $this->setArray['template'] = 0;
  123. $placeholders['set'] = $this->setArray;
  124. return $placeholders;
  125. }
  126. /**
  127. * Return the pagetitle
  128. *
  129. * @return string
  130. */
  131. public function getPageTitle() {
  132. return $this->modx->lexicon('form_customization');
  133. }
  134. /**
  135. * Return the location of the template file
  136. * @return string
  137. */
  138. public function getTemplateFile() {
  139. return '';
  140. }
  141. /**
  142. * Specify the language topics to load
  143. * @return array
  144. */
  145. public function getLanguageTopics() {
  146. return array('user','access','policy','formcustomization');
  147. }
  148. /**
  149. * Get the Help URL
  150. * @return string
  151. */
  152. public function getHelpUrl() {
  153. return 'Form+Customization+Sets';
  154. }
  155. }