Merge pull request #16005 from magnolia61/Contribution_Invoice_Privacy
[civicrm-core.git] / CRM / UF / Form / Inline / Preview.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class generates form components
20 * for previewing Civicrm Profile Group
21 */
22 class CRM_UF_Form_Inline_Preview extends CRM_UF_Form_AbstractPreview {
23
24 /**
25 * Pre processing work done here.
26 *
27 * gets session variables for group or field id
28 */
29 public function preProcess() {
30 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
31 // CRM_Core_Controller validates qfKey for POST requests, but not necessarily
32 // for GET requests. Allowing GET would therefore be CSRF vulnerability.
33 CRM_Core_Error::fatal(ts('Preview only supports HTTP POST'));
34 }
35 // Inline forms don't get menu-level permission checks
36 $checkPermission = [
37 [
38 'administer CiviCRM',
39 'manage event profiles',
40 ],
41 ];
42 if (!CRM_Core_Permission::check($checkPermission)) {
43 CRM_Core_Error::statusBounce(ts('Permission Denied'));
44 }
45 $content = json_decode($_REQUEST['ufData'], TRUE);
46 foreach (['ufGroup', 'ufFieldCollection'] as $key) {
47 if (!is_array($content[$key])) {
48 CRM_Core_Error::fatal("Missing JSON parameter, $key");
49 }
50 }
51 //echo '<pre>'.htmlentities(var_export($content, TRUE)) .'</pre>';
52 //CRM_Utils_System::civiExit();
53 $fields = CRM_Core_BAO_UFGroup::formatUFFields($content['ufGroup'], $content['ufFieldCollection']);
54 //$fields = CRM_Core_BAO_UFGroup::getFields(1);
55 $this->setProfile($fields);
56 //echo '<pre>'.htmlentities(var_export($fields, TRUE)) .'</pre>';CRM_Utils_System::civiExit();
57 }
58
59 }