-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.php
158 lines (123 loc) · 3.88 KB
/
data.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
session_start();
if (empty($_SESSION['uname'])) {
$project = file_get_contents("data.txt");
$project_json = json_decode($project);
$project_json->canWrite = false;
$project_json->canWriteOnParent = false;
$returnArray = array(
'ok' => true,
'project' => $project_json,
'hash' => md5($project),
'message' => '',
'errorMessages' => '',
'uname' => "未登录用户"
);
echo json_encode($returnArray);
} elseif (!empty($_POST['CM']) && !empty($_POST['prj']) && !empty($_POST['hash']) && $_POST['CM'] == 'SVPROJECT') {
$hash = md5(file_get_contents("data.txt"));
$project = json_decode($_POST['prj']);
if (!isset($project->resources)) {
$project->resources = array(
'id' => 'tmp_1',
'name' => 'Resource 1'
);
}
if (!isset($project->roles)) {
$project->roles = array(
'id' => 'tmp_1',
'name' => 'Developer'
);
}
$project->lastModify = $_SESSION['uname'];
if ($hash == $_POST['hash']) {
file_put_contents("data.txt", json_encode($project));
file_put_contents("data" . date("Ymd") . ".txt", json_encode($project));
$returnOk = true;
$errorMessages = array();
$message = '';
} else {
$returnOk = false;
$errorMessages = array();
$message = '版本已变更,请刷新后重试!';
}
$returnArray = array(
'ok' => $returnOk,
'project' => $project,
'hash' => md5(json_encode($project)),
'message' => $message,
'errorMessages' => $errorMessages
);
echo json_encode($returnArray);
} elseif (!empty($_GET['CM']) && $_GET['CM'] == 'GETHASH') {
$project = file_get_contents("data.txt");
$objProject = json_decode($project);
$returnArray = array(
'ok' => true,
'hash' => md5($project),
'message' => '',
'errorMessages' => '',
'lastModify' => $objProject->lastModify
);
echo json_encode($returnArray);
} elseif (!empty($_GET['CM']) && $_GET['CM'] == 'BACKUP') {
$project = file_get_contents("data.txt");
$backupProject = file_get_contents("backupdata.txt");
$projectJson = json_decode($project);
$backupProjectJson = json_decode($backupProject);
$fromTime = strtotime("-20 day") * 1000;
$bcount = 0;
foreach ($backupProjectJson->tasks AS $key => $task) {
$bcount++;
}
echo "1:" . count($projectJson->tasks) . " b:" . $bcount;
$parentIds = array(1 => 0 , 2 => 0 , 3 => 0);
foreach ($projectJson->tasks AS $key => $task) {
if ($task->level > 1 && $task->end < $fromTime) {
$task->parentId = $parentIds[$task->level-1];
$backupProjectJson->tasks->{$task->id} = $task;
echo $task->id;
unset($projectJson->tasks[$key]);
}
$parentIds[$task->level] = $task->id;
}
$projectJson->tasks = array_values($projectJson->tasks);
file_put_contents("data.txt", json_encode($projectJson));
file_put_contents("backupdata.txt", json_encode($backupProjectJson));
echo "DONE";
} elseif (!empty($_GET['CM']) && $_GET['CM'] == 'REVERSE') {
$project = file_get_contents("data.txt");
$backupProject = file_get_contents("backupdata.txt");
$projectJson = json_decode($project);
$backupProjectJson = json_decode($backupProject);
foreach ($backupProjectJson->tasks AS $key => $task) {
foreach ($projectJson->tasks AS $skey => $stask) {
if ($stask->id == $task->parentId) {
unset($task->parentId);
array_splice($projectJson->tasks, $skey+1, 0, array($task));
unset($backupProjectJson->tasks->{$key});
break;
}
}
}
$bcount = 0;
foreach ($backupProjectJson->tasks AS $key => $task) {
$bcount++;
}
echo "1:" . count($projectJson->tasks) . " b:" . $bcount;
file_put_contents("data.txt", json_encode($projectJson));
file_put_contents("backupdata.txt", json_encode($backupProjectJson));
echo "DONE";
} else {
$project = file_get_contents("data.txt");
$returnArray = array(
'ok' => true,
'project' => json_decode($project),
'hash' => md5($project),
'message' => '',
'errorMessages' => '',
'uname' => $_SESSION['uname']
);
echo json_encode($returnArray);
}
?>