1<?php
2/**
3 * @package tikiwiki
4 */
5// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
6//
7// All Rights Reserved. See copyright.txt for details and a complete list of authors.
8// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9// $Id$
10
11require_once('tiki-setup.php');
12global $monitor_filename, $stat_array;
13$access = TikiLib::lib('access');
14
15if ($prefs['feature_trackers'] != 'y') {
16	$access->output_serialized(['msg' => tra('This feature is disabled') . ': feature_trackers']);
17	die();
18}
19if ($prefs['feature_ajax'] != 'y') {
20	$access->output_serialized(['msg' => tra('This feature is disabled') . ': feature_ajax']);
21	die();
22}
23if (! isset($_REQUEST['trackerId'])) {
24	$access->output_serialized(['msg' => tra('No tracker indicated')]);
25	die();
26}
27
28/**
29 * @param array $in_vals
30 */
31function saveStatus($in_vals = [])
32{
33	global $stat_array, $monitor_filename;
34	$stat_array = array_merge($stat_array, $in_vals);
35	$fp_mon = fopen($monitor_filename, 'w');
36	fwrite($fp_mon, serialize($stat_array));
37	fclose($fp_mon);
38}
39
40$monitor_filename = $prefs['tmpDir'] . '/tracker_' . $_REQUEST['trackerId'] . '_monitor.json';
41
42if (isset($_REQUEST['trackerId']) && isset($_REQUEST['xuser'])) {
43	if (is_file($monitor_filename)) {
44		$stat_array = unserialize(file_get_contents($monitor_filename));
45	} else {
46		$access->output_serialized(['msg' => 'No monitor file found']);
47		die();
48	}
49
50	$stat_array = unserialize(file_get_contents($monitor_filename));
51
52	//$stat_array = file($monitor_filename);
53	$json_data = [];
54	foreach ($stat_array as $k => $v) {
55		if ($k == 'user' && $v != $user) {
56			$json_data['msg'] = tra("Another user is currently exporting that tracker. Please try again later.") . ' ' . tra('Or delete the file: ' . $monitor_filename);
57			break;
58		} else {
59			$json_data[$k] = $v;
60		}
61	}
62
63	$access->output_serialized($json_data);
64}
65