-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddEnv.php
187 lines (173 loc) · 7.4 KB
/
addEnv.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
<?php
/**
* $Id: addEnv.php,v 1.11 2008/05/07 11:45:15 david_iondev Exp $
* Trac integration for dotProject
*
* This file has 2 roles:
* 1) Manage existing hosts-environment setups
* 2) Act as a backend to the various forms that add or edit host and environment settings
*
* @author David Raison <[email protected]>
* @package TracIntegration
* @version 0.5
* @since 0.1
* @copyright ION Development (www.iongroup.lu)
* @license http://www.gnu.org/copyleft/gpl.html GPL License 2 or later
*/
if (!defined('DP_BASE_DIR')){
die('You should not access this file directly.');
}
// Checking permissions
$perms =& $AppUI->acl();
$canRead = $perms->checkModule( $m, 'view');
$canDelete = $perms->checkModule( $m, 'delete');
$canAdd = $perms->checkModule( $m, 'add');
if(!$canRead)
$AppUI->redirect('m=public&a=access_denied');
$AppUI->getModuleJS($m,$a);
$AppUI->savePlace();
$titleBlock = new CTitleBlock( 'Trac', 'trac_logo.png', $m, "$m.$a" );
$titleBlock->addCrumb('?m=trac&a=index',$AppUI->_('View Environments'));
$titleBlock->show();
require_once 'trac.class.php';
$tracpr = new CTracIntegrator();
/*** The Backend Part - request data handling ***/
// first check if a project_id is defined. Else we can't save anything at all
if(($project_id = dPgetParam($_REQUEST,'project_id')) != '' && $canAdd){
// Save environments
if ($oldenv = $AppUI->getState('oldenv')) $AppUI->setState('oldenv',false); // resetting
if ($oldrpc = $AppUI->getState('oldrpc')) $AppUI->setState('oldrpc',0); // resetting
$newenv = dPgetParam($_REQUEST,'newenv',0);
$hasrpc = dPgetParam($_REQUEST,'hasrpc',0);
if ($oldenv && $newenv && ($newenv != $oldenv || $hasrpc != $oldrpc)){ // that's an update (of either the environment name or its rpc state)
if ($tracpr->updateEnvironment($newenv,$project_id,$hasrpc))
$AppUI->setMsg('Environment updated',UI_MSG_OK);
} elseif($newenv && !$oldenv) { // new environment
if ($tracpr->addEnvironment($newenv,$project_id,$hasrpc))
$AppUI->setMsg('Environment added',UI_MSG_OK);
}
// Save new host (first check if there has been a change at all)
$existHost = dPgetParam($_REQUEST,'existURL',0);
if ($oldhost = $AppUI->getState('oldhost')) $AppUI->setState('oldhost',false); // resetting
if (($newurl = dPgetParam($_REQUEST,'newurl')) != ''){
// if a new hosts has been set, then add that one.
try {
$host_id = $tracpr->addHost($newurl);
$tracpr->setHostLink($host_id,$project_id,$oldhost);
$AppUI->setMsg('New host added',UI_MSG_OK);
} catch (Exception $e) {
$AppUI->setMsg('Host not added, exception: '.$e->getMessage(),UI_MSG_ERROR);
}
} elseif ($existHost && $existHost != '0' && ($existHost != $oldhost || !$tracpr->fetchHosts($project_id))){
/* then the user has selected a new host from the select box.
* @attention NEW can also mean that this project didn't have any host set so far.
* @attention ($existHost != $oldhost) can also evaluate to TRUE if oldhost is not set.
* We only need to add or change a link in this case.
*/
if($tracpr->setHostLink($existHost,$project_id,$oldhost))
$AppUI->setMsg('Host link added',UI_MSG_OK);
else
$AppUI->setMsg('Host not added',UI_MSG_ERROR);
} else
$addhost = false;
// redirect to projects module if that's where we came from
if (dPgetParam($_REQUEST,'submit') == 'saveTracConf'){
$tab = $AppUI->getState('tabid');
$AppUI->redirect('m=projects&a=view&project_id='.$project_id.'&tab='.$tab);
return;
}
}
// We can delete stuff without knowing about the project_id though
// Delete environments
if (($todel = dPgetParam($_REQUEST,'deleteEnv')) != '' && $canDelete){
if($tracpr->deleteEnvironment($todel))
$AppUI->setMsg('Environment deleted',UI_MSG_OK);
else
$AppUI->setMsg('Failed deleting',UI_MSG_ERROR);
}
// Delete hosts
if (($todel = dPgetParam($_REQUEST,'deleteHost')) != '' && $canDelete){
if ($tracpr->deleteHost($todel))
$AppUI->setMsg('Host deleted',UI_MSG_OK);
else
$AppUI->setMsg('Failed deleting',UI_MSG_ERROR);
}
/*** The Frontend Part - display existing setups ***/
?>
<h3>Existing Setups</h3>
<form name="deleteEnv" action="?m=trac&a=addEnv" method="post">
<table style="border: 1px solid navy; background: skyblue url(style/default/images/titlegrad.jpg) repeat scroll 0% 50%; width: 50%; color: white;">
<thead><tr><th>Host</th><th>Environment</th><th>[Project]</th><th>Action</th></tr></thead><tbody>
<?php
// fetch existing projects
require_once $AppUI->getModuleClass('projects');
$projObj = new CProject();
$projectRows = $projObj->getAllowedProjectsInRows($AppUI->user_id);
$projects = $projectRows->GetRows(); // FetchRow(), GetAssoc() [AdoDB RecordSet object]
$orderedProjects = array();
foreach($projects as $project)
$orderedProjects[$project['project_id']] = $project['project_name'];
$hosts = $tracpr->fetchHosts();
foreach($hosts as $host){
print('<tr><td>'.$host['dthost'].'</td>');
if($canDelete){
print('<td colspan="2"/><td><button id="deleteHost_'.$host['idhost'].'" name="deleteHost"'
.'value="'.$host['idhost'].'" style="background: transparent;'
.'border:0;" title="Click to delete this host">'
.dPshowImage( './images/icons/stock_delete-16.png', '16', '16', '' )
.'</button></td></tr>');
}
$envs = $tracpr->getEnvironmentsFromHost($host['idhost']); // can be more than one
if(!empty($envs)){
$envs = (is_array($envs[0])) ? $envs : array($envs);
foreach($envs as $env){
printf('<tr><td/><td>%s</td>',$env['dtenvironment']);
$projId = $tracpr->getProjectFromEnvironment($env['idenvironment']);
printf('<td>[%s]</td>',$orderedProjects[$projId]);
if($canDelete){
print('<td><button id="deleteEnv_'.$env['idenvironment'].'" name="deleteEnv"'
.'value="'.$env['idenvironment'].'" style="background: transparent;'
.'border:0;" title="Click to delete this environment">'
.dPshowImage( './images/icons/stock_delete-16.png', '16', '16', '' )
.'</button></td></tr>');
}
}
}
}
?>
</tbody></table>
</form>
<?php
/**
* this way of editing is deprecated in favor of adding environments directly in the projects module.
* It will be unavailable until there's a js library available for dotproject or I found another solution.
* @todo (see above):
* - try to set the host automatically when a project has been selected
* or to narrow down the possible choices of projects when a host has been selected
* - check if there is a project first!!
*/
/*
if ($canAdd) {
?>
<h3>New Setup</h3>
<form action="?m=trac&a=addEnv" method="post" name="addNewEnv">
<table style="border: 1px solid navy; background: skyblue url(style/default/images/titlegrad.jpg) repeat scroll 0% 50%; width: 50%; color: white;">
<thead><tr><th>Name</th></tr></thead><tbody>
<tr><td><label for="project">Project</label></td><td><select id="projects" name="project_id" onchange=""/>
<?php
// @TODO 0.3: if the selected project already has an attributed environment,
// change the button to "edit" and
// display the existing data instead of empty fields
foreach($projects as $project)
printf('<option value="%d">%s</option>',$project['project_id'],$project['project_name']);
?>
</select></td></tr>
<tr><td><label for="host">Host</label></td><td><input id="newhost" name="host" type="text"/></td></tr>
<tr><td><label for="environment">Environment name</label></td><td><input id="environment" name="newenv" type="text"/></td></tr>
<tr><td colspan="2" style="text-align:right;"><button name="submit" value="saveEnv" title="Click to add">Add</button></td></tr>
</tbody></table>
</form>
<?php
}
*/
?>