forked from artursudnik/webpagetest-monitor
/
editJob.php
144 lines (134 loc) · 4.55 KB
/
editJob.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
<?php
require("login/login.php");
include 'monitor.inc';
$ownerId="";
$userId = getCurrentUserId();
if ( isset($_REQUEST['id']) ){
$jobId = $_REQUEST['id'];
$ownerId = getOwnerIdFor($jobId, 'WPTJob');
$currentJobCount = getUserJobCount($userId);
$maxJobsPerMonth = getMaxJobsPerMonth($userId);
$folderId = getFolderIdFor($jobId, 'WPTJob');
} else {
if ( isset($_REQUEST['folderId'])){
$folderId = $_REQUEST['folderId'];
} else {
$folderId = getRootFolderForUser($userId,'WPTJob');
}
}
if (!hasPermission('WPTJob', $folderId, PERMISSION_UPDATE)) {
echo "Invalid Permission";
exit;
}
// Folder shares for the Alerts
$folderShares = getFolderShares($userId, 'Alert');
$alertFolderIds = array();
foreach ($folderShares as $key => $folderShare) {
foreach ($folderShare as $k => $share) {
$alertFolderIds[] = $k;
}
}
// Scripts
$folderShares = getFolderShares($userId, 'WPTScript');
$scriptFolderIds = array();
foreach ($folderShares as $key => $folderShare) {
foreach ($folderShare as $k => $share) {
$scriptFolderIds [] = $k;
}
}
$wptLocations = getWptLocations();
$wptLocs = array();
foreach ($wptLocations as $loc) {
$key = $loc['Location'];
$wptLocs[$loc->WPTHost['HostURL'] . ' ' . $key] = $loc['Label'] .' (' . $key. ' '. $loc->WPTHost['HostURL']. ')';
}
if (isset($jobId)) {
$q = Doctrine_Query::create()->from('WPTJob j')->where('j.Id= ?', $jobId);
$result = $q->fetchOne();
$q->free(true);
$scriptId = $result['WPTScript']['Id'];
$smarty->assign('selectedLocation', $result['Host'] . ' ' . $result['Location']);
} else {
$result = new WPTJob();
$result['Frequency'] = 60;
$smarty->assign('selectedLocation', '');
}
if (isset($scriptId)){
$scriptFolderId = getFolderIdFor($scriptId,'WPTScript');
$canChangeScript = hasPermission('WPTScript',$scriptFolderId, PERMISSION_UPDATE);
} else {
$canChangeScript = true;
}
$smarty->assign('canChangeScript',$canChangeScript);
if (!$result['WPTBandwidthDown'] && $result['WPTBandwidthDown'] != 0)
$result['WPTBandwidthDown'] = 1500;
if (!$result['WPTBandwidthUp'] && $result['WPTBandwidthUp'] != 0)
$result['WPTBandwidthUp'] = 384;
if (!$result['WPTBandwidthLatency'] && $result['WPTBandwidthLatency'] != 0)
$result['WPTBandwidthLatency'] = 50;
if (!$result['WPTBandwidthPacketLoss'] && $result['WPTBandwidthPacketLoss'] != 0)
$result['WPTBandwidthPacketLoss'] = 0;
$q = Doctrine_Query::create()->from('WPTScript s')->orderBy('s.Label');
if ($folderId > -1 && hasPermission('WPTScript', $folderId, PERMISSION_UPDATE)) {
$q->andWhereIn('s.WPTScriptFolderId', $scriptFolderIds);
} else {
$q->andWhere('s.UserId = ?', $userId);
}
$scripts = $q->fetchArray();
$q->free(true);
$scriptArray = array();
foreach ($scripts as $script) {
$id = $script['Id'];
$scriptArray[$id] = $script['Label'];
}
$q = Doctrine_Query::create()->from('Alert a')->orderBy('a.Label');
if (!empty($alertFolderIds) && $folderId > -1 && hasPermission('Alert', $folderId, PERMISSION_UPDATE)) {
$q->andWhereIn('a.AlertFolderId', $alertFolderIds);
} else {
$q->andWhere('a.UserId = ?', $userId);
}
$alerts = $q->fetchArray();
$q->free(true);
$alertArray = array();
$alert = array();
foreach ($alerts as $a) {
$idx = $a['Id'];
$alert['Id'] = $a['Id'];
$alert['Label'] = $a['Label'];
$alert['Active'] = $a['Active'];
$alert['Selected'] = 0;
$alertArray[$idx] = $alert;
}
$q = Doctrine_Query::create()->from('WPTJob_Alert a');
if (isset($jobId)){
$q->where('a.WPTJobId= ?', $jobId);
}
$selectedAlerts = $q->fetchArray();
$q->free(true);
foreach ($selectedAlerts as $selected) {
$aid = $selected['AlertId'];
if ($a = $alertArray[$aid]['Id']) {
$alertArray[$aid]['Selected'] = 1;
}
}
// Set vars for smarty
if(!isset($maxJobsPerMonth)){
$maxJobsPerMonth="";
}
if(!isset($currentJobCount)){
$currentJobCount="";
}
$folderTree = getFolderTree($userId, 'WPTJob');
$shares = getFolderShares($userId, 'WPTJob');
$smarty->assign('folderTree', $folderTree);
$smarty->assign('shares', $shares);
$smarty->assign('folderId', $folderId);
$smarty->assign('alerts', $alertArray);
$smarty->assign('maxJobsPerMonth', $maxJobsPerMonth);
$smarty->assign('currentJobCount', $currentJobCount);
$smarty->assign('job', $result);
$smarty->assign('ownerId', $ownerId);
$smarty->assign('scripts', $scriptArray);
$smarty->assign('wptLocations', $wptLocs);
$smarty->display('job/addJob.tpl');
?>