update.class.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 the policy management page
  12. *
  13. * @package modx
  14. * @subpackage manager.controllers
  15. */
  16. class SecurityAccessPolicyUpdateManagerController extends modManagerController {
  17. public $policyArray = 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('policy_edit');
  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/security/modx.panel.access.policy.js');
  32. $this->addJavascript($mgrUrl.'assets/modext/sections/security/access/policy/update.js');
  33. $this->addHtml('
  34. <script type="text/javascript">
  35. // <![CDATA[
  36. Ext.onReady(function() {
  37. MODx.load({
  38. xtype: "modx-page-access-policy"
  39. ,policy: "'.$this->policyArray['id'].'"
  40. ,record: '.$this->modx->toJSON($this->policyArray).'
  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. if (empty($scriptProperties['id']) || strlen($scriptProperties['id']) !== strlen((integer)$scriptProperties['id'])) {
  54. return $this->failure($this->modx->lexicon('access_policy_err_ns'));
  55. }
  56. $policy = $this->modx->getObject('modAccessPolicy', array('id' => $scriptProperties['id']));
  57. if (empty($policy)) return $this->failure($this->modx->lexicon('access_policy_err_nf'));
  58. $placeholders['policy'] = $policy;
  59. /* setup policy array */
  60. $this->policyArray = $policy->get(array(
  61. 'id',
  62. 'name',
  63. 'description',
  64. 'lexicon',
  65. 'class',
  66. 'template',
  67. 'parent',
  68. ));
  69. $this->policyArray['permissions'] = $policy->getPermissions();
  70. $placeholders['policy'] = $this->policyArray;
  71. return $placeholders;
  72. }
  73. /**
  74. * Return the pagetitle
  75. *
  76. * @return string
  77. */
  78. public function getPageTitle() {
  79. return $this->modx->lexicon('policy').': '.$this->policyArray['name'];
  80. }
  81. /**
  82. * Return the location of the template file
  83. * @return string
  84. */
  85. public function getTemplateFile() {
  86. return '';
  87. }
  88. /**
  89. * Specify the language topics to load
  90. * @return array
  91. */
  92. public function getLanguageTopics() {
  93. return array('user','access','policy','context');
  94. }
  95. /**
  96. * Get the Help URL
  97. * @return string
  98. */
  99. public function getHelpUrl() {
  100. return 'Policies';
  101. }
  102. }