93405c28e14e53a596950fa0223adc52839547c1
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / View / Wizard / SaveWizardView.php
1 <?php
2 namespace TYPO3\CMS\Form\View\Wizard;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * The form wizard save view
19 *
20 * @author Patrick Broens <patrick@patrickbroens.nl>
21 */
22 class SaveWizardView extends \TYPO3\CMS\Form\View\Wizard\AbstractWizardView {
23
24 /**
25 * The main render method
26 *
27 * Gathers all content and echos it to the screen
28 *
29 * @return void
30 */
31 public function render() {
32 $success = FALSE;
33 // Check if the referenced record is available
34 $this->recordIsAvailable = $this->repository->hasRecord();
35 if ($this->recordIsAvailable) {
36 // Save the data
37 $success = $this->repository->save();
38 }
39 $this->headerOutput($success);
40 }
41
42 /**
43 * Construct the reponse header
44 *
45 * @param string $success JSON string
46 * @return void
47 */
48 protected function headerOutput($success) {
49 if (!$success) {
50 header('HTTP/1.1 500 Internal Server Error');
51 $jsonArray = array('message' => 'Failed to save the form');
52 } else {
53 $jsonArray = array('message' => 'Changes saved successfully');
54 }
55 $json = json_encode($jsonArray);
56 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
57 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . 'GMT');
58 header('Cache-Control: no-cache, must-revalidate');
59 header('Pragma: no-cache');
60 header('Content-Length: ' . strlen($json));
61 header('Content-Type: application/json; charset=utf-8');
62 header('Content-Transfer-Encoding: 8bit');
63 echo $json;
64 die;
65 }
66
67 }