1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8class Services_Wiki_StructureController
9{
10	function setUp()
11	{
12		Services_Exception_Disabled::check('feature_wiki');
13		Services_Exception_Disabled::check('feature_wiki_structure');
14	}
15
16	function action_save_structure($input)
17	{
18		$data = json_decode($input->data->text());
19		if ($data) {
20			$structlib = TikiLib::lib('struct');
21			$structlib->reorder_structure($data);
22			$params = json_decode($input->params->text());
23
24			$_GET = [];		// self_link and query objects used by get_toc adds all this request data to the action links
25			$_POST = [];
26
27			$html = $structlib->get_toc(
28				$params->page_ref_id,
29				$params->order,
30				$params->showdesc,
31				$params->numbering,
32				$params->numberPrefix,
33				$params->type,
34				$params->page,
35				$params->maxdepth,
36				$params->mindepth,
37				$params->mindepthsortalpha,
38				$params->structurePageName
39			);
40
41			//Empty structure caches to refresh structure data in menu module. Seems better to empty cache for any possible subnodes, might make it a bit slow
42			$cachelib = TikiLib::lib('cache');
43			$structurePages = [];
44			$structurePages = $structlib->s_get_structure_pages($params->page_ref_id);
45			foreach ($structurePages as &$value) {
46				$cachetype = 'structure_' . $value["page_ref_id"] . '_';
47				$cachelib->empty_type_cache($cachetype);
48			}
49			unset($value);
50		}
51		return ['html' => $html];
52	}
53}
54