forked from Combodo/approval-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax.approval.php
119 lines (111 loc) · 3.42 KB
/
ajax.approval.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
<?php
/**
* Copyright (C) 2013-2020 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
if (!defined('__DIR__')) define('__DIR__', dirname(__FILE__));
require_once(__DIR__.'/../../approot.inc.php');
require_once(APPROOT.'/application/application.inc.php');
if (version_compare(ITOP_DESIGN_LATEST_VERSION , '3.0') < 0) {
require_once(APPROOT.'/application/webpage.class.inc.php');
require_once(APPROOT.'/application/ajaxwebpage.class.inc.php');
}
try
{
$sOperation = utils::ReadParam('operation', '');
switch($sOperation)
{
case 'send_reminder':
require_once(APPROOT.'/application/startup.inc.php');
require_once(APPROOT.'/application/loginwebpage.class.inc.php');
LoginWebPage::DoLogin(); // Check user rights and prompt if needed
if (version_compare(ITOP_DESIGN_LATEST_VERSION , '3.0') < 0) {
$oPage = new ajax_page('');
$oPage->no_cache();
} else {
$oPage = new AjaxPage('');
}
$oPage->SetContentType('text/html');
try
{
$iSchemeId = utils::ReadParam('approval_id', 0);
$iStep = utils::ReadParam('step', 0);
$bEditMode = utils::ReadParam('edit_mode', 0);
$oScheme = MetaModel::GetObject('ApprovalScheme', $iSchemeId, false);
if (!$oScheme)
{
throw new Exception(Dict::S('Approval:Form:ObjectDeleted'));
}
if ($oScheme->Get('status') == 'accepted')
{
throw new Exception(Dict::S('Approval:Form:AlreadyApproved'));
}
if ($oScheme->Get('status') == 'rejected')
{
throw new Exception(Dict::S('Approval:Form:AlreadyRejected'));
}
$aSteps = $oScheme->GetSteps();
if ($iStep < $oScheme->Get('current_step'))
{
if ($aSteps[$iStep]['approved'])
{
throw new Exception(Dict::S('Approval:Form:StepApproved'));
}
throw new Exception(Dict::S('Approval:Form:StepRejected'));
}
$aAwaited = $oScheme->GetAwaitedReplies();
$Sent = 0;
if (count($aAwaited) > 0)
{
$oObject = MetaModel::GetObject($oScheme->Get('obj_class'), $oScheme->Get('obj_key'));
$aReminders = array();
foreach ($aAwaited as $aData)
{
$oTarget = MetaModel::GetObject($aData['class'], $aData['id'], false);
if ($oTarget)
{
if (array_key_exists('substitute_to', $aData))
{
$oSubstituteTo = MetaModel::GetObject($aData['substitute_to']['class'], $aData['substitute_to']['id'], false);
}
else
{
$oSubstituteTo = null;
}
$oScheme->SendApprovalRequest($oTarget, $oObject, $aData['passcode'], $oSubstituteTo, true);
$Sent++;
}
}
}
$oPage->add(Dict::Format('Approval:ReminderDone', $Sent));
if (($Sent > 0) && !$bEditMode)
{
// Reload the object details so as to refresh the notifications tab
$oPage->add_script("window.location.reload();");
}
}
catch (Exception $e)
{
$oPage->p('Error: '.$e->getMessage());
}
$oPage->output();
break;
}
}
catch (Exception $e)
{
IssueLog::Error($e->getMessage());
}