-
Notifications
You must be signed in to change notification settings - Fork 205
/
project_members.php
146 lines (128 loc) · 4.55 KB
/
project_members.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
<?php
require_once( "db.inc.php" );
require_once( "facilities.inc.php" );
if(!$person->WriteAccess){
// No soup for you.
header('Location: '.redirect());
exit;
}
// This page has no function without a valid project id
if(!isset($_REQUEST['projectid'])){
echo "How'd you get here without a referral?";
exit;
}
if ( ! isset($_REQUEST['datacenterid'] )) {
$DataCenterID = 0;
} else {
$DataCenterID = $_REQUEST['datacenterid'];
}
if ( ! isset( $_REQUEST['membertype'] )) {
$memberType = "Device";
} else {
$memberType = in_array( $_REQUEST['membertype'], array( "Device", "Cabinet" ))?$_REQUEST['membertype']:"Device";
}
$proj = Projects::getProject( $_REQUEST['projectid'] );
// Update if form was submitted and action is set
if(isset($_POST['action']) && $_POST['action']=="Submit"){
$ProjectID = $_REQUEST['projectid'];
ProjectMembership::clearMembership( $ProjectID );
$grpMembers=!empty($_POST['chosen'])?$_POST['chosen']:array();
if (( sizeof( $grpMembers ) > 0 ) && isset( $_REQUEST['projectid'] )) {
foreach ( $grpMembers as $devID ) {
ProjectMembership::addMember( $ProjectID, $devID, $memberType );
}
}
}
$dcList = DataCenter::GetDCList();
// Here we diverge between devices and cabinets
if ( $memberType == "Device" ) {
$memberList = ProjectMembership::getProjectMembership( $proj->ProjectID, false, false );
$devList = Device::getDevicesByDC( $DataCenterID );
// Build an array of DeviceIDs that are in the memberList
$dev = new Device();
$memberKeys = array();
foreach ( $memberList as $mem ) {
$memberKeys[$mem->DeviceID] = $mem->Label;
}
} elseif ( $memberType == "Cabinet" ) {
$c = new Cabinet();
$c->DataCenterID = $DataCenterID;
$memberList = ProjectMembership::getProjectCabinets( $proj->ProjectID, false );
$cabList = $c->ListCabinetsByDC();
$memberKeys = array();
foreach ( $memberList as $mem ) {
$memberKeys[$mem->CabinetID] = $mem->Location;
}
}
natsort( $memberKeys );
?>
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><?php __("openDCIM Project Membership Maintenance"); ?></title>
<link rel="stylesheet" href="css/inventory.php" type="text/css">
<link rel="stylesheet" href="css/jquery-ui.css" type="text/css">
<link rel="stylesheet" href="css/jquery.ui.multiselect.css" type="text/css">
<script type="text/javascript" src="scripts/jquery.min.js"></script>
<script type="text/javascript" src="scripts/jquery-ui.min.js"></script>
<script type="text/javascript" src="scripts/jquery.ui.multiselect.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#chosenList').multiselect({sortable:false});
$('#datacenterid').change(function(e){
document.location.href='project_members.php?membertype=<?php echo $memberType; ?>&projectid='+$('#projectid').val()+'&datacenterid='+this.value;
});
});
</script>
</head>
<body id="projectgroup">
<div class="centermargin">
<?php
echo '<form id="projectform" method="POST">
<input type="hidden" name="projectid" id="projectid" value="',$proj->ProjectID,'">
<input type="hidden" name="membertype" id="membertype" value="',$memberType,'">
<h3>',__("Project to Administer"),': ',$proj->ProjectName,'</h3>
<select name="datacenterid" id="datacenterid" width="200px"><option value="0">Choose a Data Center</option>';
foreach ( $dcList as $dc ) {
if ( $dc->DataCenterID == $DataCenterID ) {
$selected = "SELECTED";
} else {
$selected = "";
}
print "<option value=\"$dc->DataCenterID\" $selected>$dc->Name</option>";
}
if ( $memberType == "Device" ) {
echo '</select>
<div>
<select name="chosen[]" id="chosenList" size="15" multiple="multiple">';
foreach($memberKeys as $DeviceID=>$Label) {
print "<option value='$DeviceID' selected>$Label</option>";
}
foreach($devList as $devRow){
if ( ! array_key_exists( $devRow->DeviceID, $memberKeys )) {
print "\t\t<option value=\"$devRow->DeviceID\">$devRow->Label</option>\n";
}
}
} elseif ( $memberType == "Cabinet" ) {
echo '</select>
<div>
<select name="chosen[]" id="chosenList" size="15" multiple="multiple">';
foreach($memberKeys as $CabinetID=>$Location ) {
print "<option value='$CabinetID' selected>$Location</option>";
}
foreach($cabList as $cabRow){
if ( ! array_key_exists( $cabRow->CabinetID, $memberKeys )) {
print "\t\t<option value=\"$cabRow->CabinetID\">$cabRow->Location</option>\n";
}
}
}
echo '</select>
<button type="submit" value="Submit" name="action">',__("Submit"),'</button>';
?>
</div>
</form>
</div>
</body>
</html>