forked from lbayle/codev
/
index.php
238 lines (195 loc) · 8.41 KB
/
index.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
require('include/session.inc.php');
/*
This file is part of CoDev-Timetracking.
CoDev-Timetracking is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CoDev-Timetracking is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CoDev-Timetracking. If not, see <http://www.gnu.org/licenses/>.
*/
require('path.inc.php');
// check if INSTALL needed
if (!file_exists(Constants::$config_file)) {
header('Location: install/install.php');
exit;
}
class IndexController extends Controller {
/**
* Initialize complex static variables
* @static
*/
public static function staticInit() {
// Nothing special
}
protected function display() {
// Drifted tasks
if(Tools::isConnectedUser()) {
$isAdmin = $this->session_user->isTeamMember(Config::getInstance()->getValue(Config::id_adminTeamId));
$isManager = $this->session_user->isTeamManager($this->teamid);
// check codevtt version
if (1 == Constants::$isCheckLatestVersion) {
try {
if ($isAdmin || ($isManager && (date('d') < 4))) {
$latestVersionInfo = Tools::getLatestVersionInfo(3);
if (FALSE !== $latestVersionInfo) {
if ( Config::codevVersion != $latestVersionInfo['version'] ) {
$this->smartyHelper->assign('latestVersionInfo', $latestVersionInfo);
}
}
}
} catch (Exception $e) {
// version check should never break CodevTT usage...
// (no log, even logs could raise errors)
}
}
// if CodevTT installed since at least 6 month,
// then display FairPlay message every 3 month (mar, jun, sep, dec) during 3 days.
if (($isManager || $isAdmin) &&
(0 == date('m') % 3) && (date('d') > 27) &&
(time() - Constants::$codevInstall_timestamp > (60*60*24 * 180))
) {
$this->smartyHelper->assign('displayFairPlay', true);
$this->smartyHelper->assign('codevInstall_date', date('Y-m-d', Constants::$codevInstall_timestamp));
}
if ($isAdmin) {
// check global configuration
$cerrList = ConsistencyCheck2::checkMantisDefaultProjectWorkflow();
// add more checks here
if (count($cerrList) > 0) {
$systemConsistencyErrors = array();
foreach ($cerrList as $cerr) {
$systemConsistencyErrors[] = array('severity' => $cerr->getLiteralSeverity(),
'desc' => $cerr->desc);
}
$this->smartyHelper->assign('systemConsistencyErrors', $systemConsistencyErrors);
}
}
// updateBacklog DialogBox
if (isset($_POST['bugid'])) {
$bugid = Tools::getSecurePOSTStringValue('bugid');
$backlog = Tools::getSecurePOSTStringValue('backlog', '');
$issue = IssueCache::getInstance()->getIssue($bugid);
$issue->setBacklog($backlog);
}
$driftedTasks = $this->getIssuesInDrift();
if(isset($driftedTasks)) {
$this->smartyHelper->assign('driftedTasks', $driftedTasks);
}
// Consistency errors
$consistencyErrors = $this->getConsistencyErrors();
// no specific Mgr errors right now
#$consistencyErrorsMgr = $this->getConsistencyErrorsMgr($this->session_user);
#$consistencyErrors = array_merge($consistencyErrors, $consistencyErrorsMgr);
if(count($consistencyErrors) > 0) {
$this->smartyHelper->assign('consistencyErrorsTitle', count($consistencyErrors).' '.T_("Errors in your Tasks"));
$this->smartyHelper->assign('consistencyErrors', $consistencyErrors);
}
}
}
/**
* Get issues in drift
* @param User $this->session_user
* @return mixed[]
*/
private function getIssuesInDrift() {
$driftedTasks = array();
if (0 != $this->teamid) {
// get all teams except those where i'm Observer
#$dTeamList = $this->session_user->getDevTeamList();
#$mTeamList = $this->session_user->getManagedTeamList();
#$teamList = $dTeamList + $mTeamList; // array_merge does not work ?!
$teamList = array($this->teamid => $this->teamList[$this->teamid]);
// except disabled projects
$projList = $this->session_user->getProjectList($teamList, true, false);
$allIssueList = $this->session_user->getAssignedIssues($projList);
$issueList = array();
foreach ($allIssueList as $issue) {
$driftEE = $issue->getDrift();
if ($driftEE >= 1) {
$issueList[] = $issue;
}
}
if (count($issueList) > 0) {
foreach ($issueList as $issue) {
// TODO: check if issue in team project list ?
$driftEE = $issue->getDrift();
$formatedTitle = $issue->getFormattedIds();
$formatedSummary = str_replace("'", "\'", $issue->getSummary());
$formatedSummary = str_replace('"', "\'", $formatedSummary);
$driftedTasks[] = array('issueInfoURL' => Tools::issueInfoURL($issue->getId()),
'projectName' => $issue->getProjectName(),
'driftEE' => $driftEE,
'formatedTitle' => $formatedTitle,
'bugId' => $issue->getId(),
'backlog' => $issue->getBacklog(),
'formatedSummary' => $formatedSummary,
'summary' => $issue->getSummary());
}
}
}
return $driftedTasks;
}
/**
* Get consistency errors
* @return mixed[]
*/
private function getConsistencyErrors() {
$consistencyErrors = array(); // if null, array_merge fails !
if (0 != $this->teamid) {
// only this team's projects
#$teamList = $this->teamList;
$teamList = array($this->teamid => $this->teamList[$this->teamid]);
// except disabled projects
$projList = $this->session_user->getProjectList($teamList, true, false);
$issueList = $this->session_user->getAssignedIssues($projList, true);
$ccheck = new ConsistencyCheck2($issueList, $this->teamid);
$cerrList = $ccheck->check();
if (count($cerrList) > 0) {
foreach ($cerrList as $cerr) {
if ($this->session_user->getId() == $cerr->userId) {
$issue = IssueCache::getInstance()->getIssue($cerr->bugId);
$titleAttr = array(
T_('Project') => $issue->getProjectName(),
T_('Summary') => $issue->getSummary(),
);
$consistencyErrors[] = array('issueURL' => Tools::issueInfoURL($cerr->bugId, $titleAttr),
'status' => Constants::$statusNames[$cerr->status],
'desc' => $cerr->desc);
}
}
}
}
return $consistencyErrors;
}
/**
* managers get some more consistencyErrors
* @param User $this->session_user
* @return mixed[]
*/
private function getConsistencyErrorsMgr() {
$consistencyErrors = array(); // if null, array_merge fails !
/*
$mTeamList = array_keys($this->session_user->getManagedTeamList());
$lTeamList = array_keys($this->session_user->getLeadedTeamList());
$teamList = array_merge($mTeamList, $lTeamList);
$issueList = array();
foreach ($teamList as $teamid) {
$issues = TeamCache::getInstance()->getTeam($teamid)->getTeamIssueList(true, false);
$issueList = array_merge($issueList, $issues);
}
*/
// nothing to check right now...
return $consistencyErrors;
}
}
// ========== MAIN ===========
IndexController::staticInit();
$controller = new IndexController('./', Constants::$homepage_title,'index');
$controller->execute();
?>