forked from Combodo/approval-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.php
210 lines (182 loc) · 6.66 KB
/
report.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
<?php
// Copyright (C) 2012 Combodo SARL
//
// This program 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; version 3 of the License.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/**
* Execute the combodo-approbation actions
*
* @author Erwan Taloc <erwan.taloc@combodo.com>
* @author Romain Quetiez <romain.quetiez@combodo.com>
* @author Denis Flaven <denis.flaven@combodo.com>
* @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
*/
@include_once(__DIR__.'/../../approot.inc.php');
@include_once(__DIR__.'/../../../approot.inc.php');
require_once(APPROOT.'/application/application.inc.php');
require_once(APPROOT.'/application/itopwebpage.class.inc.php');
function DoShowAllStatuses($oP, $sClass)
{
if (strlen($sClass) == 0)
{
throw new Exception("Missing mandatory param 'class'");
}
$oP->add('<h1 class="ibo-title--text">Helper tool for training and documentation</h1>');
$oP->p('Showing statuses for all of the approvals (ongoing or not!)');
$aClasses = MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL); // Including the specified class itself
$sClassList = implode(", ", CMDBSource::Quote($aClasses));
$oSearch = DBObjectSearch::FromOQL("SELECT ApprovalScheme WHERE obj_class IN ($sClassList)");
$oSet = new DBObjectSet($oSearch);
while ($oScheme = $oSet->Fetch())
{
$oObject = MetaModel::GetObject($oScheme->Get('obj_class'), $oScheme->Get('obj_key'));
$oP->p('Approval for '.$oScheme->GetHyperlink());
$oP->add($oScheme->GetDisplayStatus($oP));
}
}
function DoShowOngoing($oP, $sClass)
{
if (strlen($sClass) == 0)
{
throw new Exception("Missing mandatory param 'class'");
}
$iCurrentUserContact = UserRights::GetContactId();
$oP->add('<h1 class="ibo-title--text">'.Dict::Format('Approval:Ongoing-Title+', MetaModel::GetName($sClass)).'</h1>');
if ($iCurrentUserContact > 0)
{
$bFilter = (utils::ReadParam('do_filter_my_approvals', '') == 'on');
$sDisabled = '';
}
else
{
// No contact is associated to the current user: disable the filtering capability
$bFilter = false;
$sDisabled = 'DISABLED';
}
$oAppContext = new ApplicationContext();
$sReport = utils::GetAbsoluteUrlExecPage();
// the form uses GET to allow for example archive mode toogling to work (see N.1108)
$oP->add('<form id="filter_approvals" action="'.$sReport.'" method="get">');
$aExecPageArgs = utils::GetExecPageArguments('approval-base', 'report.php');
foreach($aExecPageArgs as $sName => $sValue) {
$oP->add('<input type="hidden" name="'.$sName.'" value="'.$sValue.'">');
}
$oP->add('<input type="hidden" name="class" value="'.$sClass.'">');
$sChecked = $bFilter ? 'CHECKED' : '';
$oP->add('<input id="do_filter_my_approvals" name="do_filter_my_approvals" type="checkbox" '.$sChecked.' '.$sDisabled.'>');
$oP->add('<label for="do_filter_my_approvals">'.Dict::S('Approval:Ongoing-FilterMyApprovals').'</label>');
$oP->add($oAppContext->GetForForm());
$oP->add('</form>');
$oP->add_ready_script(
<<<EOF
$('#do_filter_my_approvals').bind('click', function() {
$('form#filter_approvals').submit();
});
EOF
);
$aClasses = MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL); // Including the specified class itself
$sClassList = implode(", ", CMDBSource::Quote($aClasses));
$oSearch = DBObjectSearch::FromOQL("SELECT ApprovalScheme WHERE status = 'ongoing' AND obj_class IN ($sClassList)");
$oSet = new DBObjectSet($oSearch, array('started' => true));
$aIds = array();
while ($oApproval = $oSet->Fetch())
{
if (!$bFilter || $oApproval->IsActiveApprover('Person', $iCurrentUserContact))
{
$aIds[] = $oApproval->Get('obj_key');
}
}
if (count($aIds) == 0)
{
$oP->p(Dict::S('Approval:Ongoing-NothingCurrently'));
}
else
{
$sIds = implode(", ", CMDBSource::Quote($aIds));
$oObjSearch = DBObjectSearch::FromOQL("SELECT $sClass WHERE id IN ($sIds)");
$oBlock = new DisplayBlock($oObjSearch, 'list', false);
$oBlock->Display($oP, 'ongoing_appr', array('menu' => false));
}
}
try
{
require_once(APPROOT.'/application/startup.inc.php');
require_once(MODULESROOT.'approval-base/approvalwebpage.class.inc.php');
$oAppContext = new ApplicationContext();
require_once(APPROOT.'/application/loginwebpage.class.inc.php');
LoginWebPage::DoLogin(); // Check user rights and prompt if needed
$oP = new iTopWebPage(Dict::S('Approval:Ongoing-Title'));
$sOperation = utils::ReadParam('operation', '');
$sClass = utils::ReadParam('class', null);
switch($sOperation)
{
case 'show_all_statuses':
// This is an helper for troubleshooting the display of statuses and/or document the module
DoShowAllStatuses($oP, $sClass);
break;
case 'show_ongoing':
default:
DoShowOngoing($oP, $sClass);
break;
}
$oP->output();
}
catch(CoreException $e)
{
require_once(APPROOT.'/setup/setuppage.class.inc.php');
$oP = new SetupPage(Dict::S('UI:PageTitle:FatalError'));
$oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
$oP->error(Dict::Format('UI:Error_Details', $e->getHtmlDesc()));
$oP->output();
if (MetaModel::IsLogEnabledIssue())
{
if (MetaModel::IsValidClass('EventIssue'))
{
$oLog = new EventIssue();
$oLog->Set('message', $e->getMessage());
$oLog->Set('userinfo', '');
$oLog->Set('issue', $e->GetIssue());
$oLog->Set('impact', 'Page could not be displayed');
$oLog->Set('callstack', $e->getTrace());
$oLog->Set('data', $e->getContextData());
$oLog->DBInsertNoReload();
}
IssueLog::Error($e->getMessage());
}
// For debugging only
//throw $e;
}
catch(Exception $e)
{
require_once(APPROOT.'/setup/setuppage.class.inc.php');
$oP = new SetupPage(Dict::S('UI:PageTitle:FatalError'));
$oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
$oP->error(Dict::Format('UI:Error_Details', $e->getMessage()));
$oP->output();
if (MetaModel::IsLogEnabledIssue())
{
if (MetaModel::IsValidClass('EventIssue'))
{
$oLog = new EventIssue();
$oLog->Set('message', $e->getMessage());
$oLog->Set('userinfo', '');
$oLog->Set('issue', 'PHP Exception');
$oLog->Set('impact', 'Page could not be displayed');
$oLog->Set('callstack', $e->getTrace());
$oLog->Set('data', array());
$oLog->DBInsertNoReload();
}
IssueLog::Error($e->getMessage());
}
}
?>