update.class.php 5.1 KB

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