-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfluent_agent_presentation.module
308 lines (264 loc) · 10.9 KB
/
fluent_agent_presentation.module
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<?php
/**
* Display help and module information
* @param path which path of the site we're displaying help
* @param arg array that holds the current path as would be returned from arg() function
* @return help text for the path
*/
function fluent_agent_presentation_help($path, $arg) {
$output = ''; //declare your output variable
switch ($path) {
case "admin/help#agent_present":
$output = '<p>'. t("This is FluentUI Graphs") .'</p>';
break;
}
return $output;
} // function fluent_agent_presentation_help
function fluent_agent_presentation_perm() {
return array('access fluent_agent_presentation content');
} // function fluent_agent_presentation_perm()
function fluent_agent_presentation_menu() {
$items = array();
$items['admin/settings/agent_present'] = array(
'title' => t('Agent presenter Settings'),
'description' => t('Description of your Fluent UI settings page'),
'page callback' => 'drupal_get_form',
'page arguments' => array('fluent_agent_presentation_admin'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
//this is added for this current tutorial.
$items['agent/present/remote-view-real-time/%'] = array(
'title' => 'Agent Presentation',
'page callback' => 'agent_agent_device',
'page arguments' => array(3,''),
'access arguments' => array('access agent content'),
'type' => MENU_CALLBACK
);
$items['agent/present/remote-view-real-time/%/%'] = array(
'title' => 'Agent Presentation',
'page callback' => 'agent_agent_device',
'page arguments' => array(3, 4),
'access arguments' => array('access agent content'),
'type' => MENU_CALLBACK
);
//this is added for this current tutorial.
$items['agent/present/remote-view-status/%/%'] = array(
'title' => 'Agent Presentation',
'page callback' => 'agent_agent_device_present',
'page arguments' => array(2, 3, 4),
'access arguments' => array('access agent content'),
'type' => MENU_CALLBACK
);
//this is added for this current tutorial.
$items['agent/present/remote-view-status/%'] = array(
'title' => 'Agent Presentation',
'page callback' => 'agent_present_fluentui_device',
'page arguments' => array(2, 3),
'access arguments' => array('access fluent_agent_presentation content'),
'type' => MENU_CALLBACK
);
//this is added for this current tutorial.
$items['agent_present'] = array(
'title' => 'Agent Presentation',
'page callback' => 'agent_present_fluentui_device',
'page arguments' => array(1, 2),
'access arguments' => array('access fluent_agent_presentation content'),
'type' => MENU_NORMAL_ITEM
);
return $items;
}
function fluent_agent_presentation_admin() {
$form = array();
$query = "select hostname, port_add from {agent_settings} where settings_id = 1";
$i=0;
$query_result = db_query($query);
while ($links = db_fetch_object($query_result)) {
$value_arr['host'] = $links->hostname;
$value_arr['port'] = $links->port_add;
}
$form['agent_hostname'] = array('#type' => 'textfield',
'#title' => t('Host name'),
'#default_value' => $value_arr['host'],
'#maxlength' => 255,
'#description' => t('Enter the HOST URL.'),
'#required' => TRUE,
);
$form['agent_port'] = array(
'#type' => 'textfield',
'#title' => t('Port'),
'#default_value' => $value_arr['port'],
'#size' => 4,
'#maxlength' => 4,
'#description' => t("Enter the PORT."),
'#required' => TRUE,
);
$form['#submit'][] = 'fluent_agent_presentation_admin_submit';
return system_settings_form($form);
}
function fluent_agent_presentation_admin_submit($form, &$form_state) {
$port = $form_state['values']['agent_port'];
$hosturl = $form_state['values']['agent_hostname'];
$exe_query = db_query("UPDATE {agent_settings} SET hostname = '%s', port_add = '%s' WHERE settings_id = %d", $hosturl,$port,1);
if ($exe_query !== false) {
$msg = 'Updated ';
$vars = array('%id'=>1);
watchdog('fluent_agent_presentation_module', $msg, $vars, WATCHDOG_INFO);
drupal_set_message(t('Updated port'));
} else {
$msg = 'Could not Update ';
$vars = array();
watchdog('fluent_agent_presentation_module', $msg, $vars, WATCHDOG_ERROR);
drupal_set_message(t('Could not Update.'));
}
$form_state['redirect'] = 'admin/settings/agent_present';
}
function fluent_agent_presentation_block($op='list', $delta=0) {
// set up the block
$block = array();
if ($op == "list") {
// Generate listing of blocks from this module, for the admin/block page
$block[0]["info"] = t('agent_present_graph');
}
else if ($op == 'view') {
// Generate our block content
}
return $block;
} // end fluentui_block
function agent_present_admin_validate($form, &$form_state) {
$maxdisp = $form_state['values']['agent_port'];
if (!is_numeric($maxdisp)) {
form_set_error('agent_port', t('You must enter an integer for Port number.'));
}
else if ($maxdisp <= 0) {
form_set_error('agent_port', t('Enter the correct Port number.'));
}
}
function agent_present_all() {
// content variable that will be returned for display
$page_content = '';
$output = theme('agent_present_list', 'BP', '2');
return $output;
}
function agent_present_fluentui_device($device_id,$device) {
$variables = array();
$variables['device'] = $device;
$variables['domain'] = strtolower($device_id);
$output = theme('agent_present_device', $variables['device'],$variables['domain']);
return $output;
}
function agent_agent_device_present($action,$device_id,$device) {
$variables = array();
$variables['device'] = $device;
$variables['domain'] = strtolower($device_id);
$variables['action'] = $action;
$output = theme('agent_device_present', $variables['device'],$variables['domain'],$variables['action']);
return $output;
}
/**
* Implementation of hook_theme()
*/
function fluent_agent_presentation_theme() {
return array(
'agent_present_list' => array(
'template' => 'tpl/agent_present_list',
'arguments' => array('devices' => NULL, 'id' => NULL),
),
'agent_present_device' => array(
'template' => 'tpl/agent_presentation_list',
'arguments' => array('device' => NULL, 'domain' => NULL),
),
'agent_device_present' => array(
'template' => 'tpl/agent_device_status',
'arguments' => array('device' => NULL, 'domain' => NULL, 'action' => NULL),
),
'agent_device' => array(
'template' => 'tpl/agent_device_graphs',
'arguments' => array('device' => NULL, 'domain' => NULL),
),
);
}
/**
* Implementation of hook_init().
*/
function fluent_agent_presentation_init() {
drupal_add_js(drupal_get_path('module', 'fluent_agent_presentation') .'/js/jquery-1.6.3.min.js');
drupal_add_js(drupal_get_path('module', 'fluent_agent_presentation') .'/js/jquery.flot.min.js');
drupal_add_js(drupal_get_path('module', 'fluent_agent_presentation') .'/js/cookie.js');
}
function template_preprocess_agent_device_present(&$variables) {
drupal_add_js('modules/fluent_agent_presentation/js/'.$variables['domain'].'.js');
drupal_add_js('modules/fluent_agent_presentation/js/websocket.js');
$variables['settings'] = _agent_present_get_settings_value();
}
function template_preprocess_agent_present_list(&$variables) {
$block_content = '';
$value_arr = array();
$variables['settings'] = _agent_present_get_settings_value();
$query = "select root.device_name as root_name, down1.device_name as down1_name from {agent_devices} as root left outer join {agent_devices} as down1 on down1.device_category = root.device_id where root.device_category = 0 order by root_name, down1_name";
$i=0;
$query_result = db_query($query);
while ($links = db_fetch_object($query_result)) {
$value_arr[$i]['name'] = l($links->root_name, 'agent_present/'.$links->root_name);
$value_arr[$i]['sub'] = l($links->down1_name, 'agent_present/'.$links->root_name.'/'.$links->down1_name);
$value_arr[$i]['sub_text'] = $links->down1_name;
$value_arr[$i]['name_text'] = $links->root_name;
$value_arr[$i++]['link'] = l($links->down1_name, 'agent_present/'.$links->root_name.'/'.$links->down1_name);
}
$variables['devices'] = $value_arr;
}
function template_preprocess_agent_present_device(&$variables) {
global $base_url;
$variables['base_url'] = $base_url;
$where = '';
$block_content = '';
$value_arr = array();
$variables['settings'] = _agent_present_get_settings_value();
if($variables['device']!='') {
$where = " and root.device_name = '".$variables['device']."'";
}
$query = "select root.device_name as root_name, down1.device_name as down1_name from {agent_devices} as root left outer join {agent_devices} as down1 on down1.device_category = root.device_id where root.device_category = 0 $where order by root_name, down1_name";
$i=0;
$query_result = db_query($query);
while ($links = db_fetch_object($query_result)) {
if(module_exists("agent_present")) {
$value_arr[$i]['name'] = l($links->root_name, 'agent/present/remote-view-real-time/'.$links->root_name);
$value_arr[$i]['sub'] = l($links->down1_name, 'agent/present/remote-view-real-time/'.$links->root_name.'/'.$links->down1_name);
} else {
$value_arr[$i]['name'] = $links->root_name;
$value_arr[$i]['sub'] = $links->down1_name;
}
$value_arr[$i]['sub_text'] = $links->down1_name;
if($links->root_name!="TEMP") $value_arr[$i]['name_text'] = $links->root_name;
else $value_arr[$i]['name_text'] = "TEMPERATURE";
$value_arr[$i++]['link'] = l($links->down1_name, 'agent/'.$links->root_name.'/'.$links->down1_name);
}
$variables['devices'] = $value_arr;
}
function agent_agent_device($device_id,$device) {
$variables = array();
$variables['device'] = $device;
$variables['domain'] = strtolower($device_id);
$output = theme('agent_device', $variables['device'],$variables['domain']);
return $output;
}
function template_preprocess_agent_device(&$variables) {
drupal_add_js('modules/fluent_agent_presentation/js/'.$variables['domain'].'.js');
$variables['status'] = 0;
if(module_exists("fluent_agent_controller")) {
drupal_add_js('modules/fluent_agent_presentation/js/websocket.js');
$variables['status'] = 1;
}
$variables['settings'] = _agent_present_get_settings_value();
}
function _agent_present_get_settings_value() {
$value_arr = array();
$query = "select hostname, port_add from {agent_settings} where settings_id = 1";
$i=0;
$query_result = db_query($query);
while ($links = db_fetch_object($query_result)) {
$value_arr['host'] = $links->hostname;
$value_arr['port'] = $links->port_add;
}
return $value_arr;
}