Linux multi-monitor fullscreen support
[ryzomcore.git] / web / public_php / admin / tool_guild_locator.php
blob841846ae4d03a9a458e138e22a79dc63e9d56f34
1 <?php
3 require_once('common.php');
4 require_once('functions_tool_main.php');
5 require_once('functions_tool_guild_locator.php');
7 if (!tool_admin_applications_check('tool_guild_locator')) nt_common_redirect('index.php');
9 nt_common_add_debug('-- Starting on \'tool_guild_locator.php\'');
11 $tpl->assign('tool_title', "Guild Locator");
13 $view_domain_id = nt_auth_get_session_var('view_domain_id');
14 $view_shard_id = nt_auth_get_session_var('view_shard_id');
16 if (!$view_domain_id)
18 $view_domain_id = $nel_user['group_default_domain_id'];
19 $view_shard_id = $nel_user['group_default_shard_id'];
20 nt_auth_set_session_var('view_domain_id', $view_domain_id);
21 nt_auth_set_session_var('view_shard_id', $view_shard_id);
24 if (isset($NELTOOL['GET_VARS']['domain']))
26 if ($view_domain_id != $NELTOOL['GET_VARS']['domain'])
28 $view_domain_id = $NELTOOL['GET_VARS']['domain'];
29 nt_auth_set_session_var('view_domain_id', $view_domain_id);
31 $view_shard_id = null;
32 nt_auth_unset_session_var('view_shard_id');
36 if (isset($NELTOOL['GET_VARS']['shard']))
38 $view_shard_id = $NELTOOL['GET_VARS']['shard'];
39 nt_auth_set_session_var('view_shard_id', $view_shard_id);
42 if (isset($NELTOOL['GET_VARS']['refdata']))
44 $tmp_data = unserialize(base64_decode($NELTOOL['GET_VARS']['refdata']));
45 if (is_array($tmp_data))
47 $NELTOOL['POST_VARS'] = $tmp_data;
51 $current_refresh_rate = nt_auth_get_session_var('current_refresh_rate');
53 if (isset($_POST['services_refresh']))
55 if ($current_refresh_rate != $_POST['services_refresh'])
57 $current_refresh_rate = $_POST['services_refresh'];
58 nt_auth_set_session_var('current_refresh_rate',$current_refresh_rate);
62 if ($current_refresh_rate == null)
64 $current_refresh_rate = 0;
66 elseif ($current_refresh_rate > 0)
68 $tpl->assign('nel_tool_refresh', '<meta http-equiv=refresh content="'. $current_refresh_rate .'">');
71 $tpl->assign('tool_refresh_list', $refresh_rates);
72 $tpl->assign('tool_refresh_rate', $current_refresh_rate);
74 $tpl->assign('tool_domain_list', $nel_user['access']['domains']);
75 $tpl->assign('tool_domain_selected', $view_domain_id);
77 $tpl->assign('tool_shard_list', $nel_user['access']['shards']);
78 $tpl->assign('tool_shard_selected', $view_shard_id);
80 $tool_shard_filters = tool_main_get_shard_ids($view_shard_id);
81 $tpl->assign('tool_shard_filters', $tool_shard_filters);
83 if (tool_admin_applications_check('tool_guild_locator_manage_guild')) $tpl->assign('restriction_tool_guild_locator_manage_guild',true);
84 if (tool_admin_applications_check('tool_guild_locator_manage_members')) $tpl->assign('restriction_tool_guild_locator_manage_members',true);
85 if (tool_admin_applications_check('tool_guild_locator_manage_forums')) $tpl->assign('restriction_tool_guild_locator_manage_forums',true);
87 if ($view_domain_id)
89 $tool_as_error = null;
91 $AS_Name = tool_main_get_domain_name($view_domain_id);
92 $AS_Host = tool_main_get_domain_host($view_domain_id);
93 $AS_Port = tool_main_get_domain_port($view_domain_id);
94 $AS_ShardName = tool_main_get_shard_name($view_shard_id);
95 $MFS_Web = tool_main_get_domain_data($view_domain_id, 'domain_mfs_web');
97 $tpl->assign('tool_page_title', 'Guild Locator - '. $AS_Name . ($AS_ShardName != '' ? ' / '. $AS_ShardName : ''));
99 $tool_as_error = null;
101 if ($AS_Host && $AS_Port)
103 $adminService = new MyAdminService;
104 if (@$adminService->connect($AS_Host, $AS_Port, $res) === false)
106 nt_common_add_debug($res);
107 $tpl->assign('tool_domain_error', $res );
109 else
111 $tool_services_gl = null;
112 if (isset($NELTOOL['POST_VARS']['services_gl'])) $tool_services_gl = $NELTOOL['POST_VARS']['services_gl'];
113 elseif (isset($NELTOOL['GET_VARS']['services_gl'])) $tool_services_gl = $NELTOOL['GET_VARS']['services_gl'];
115 if ($tool_services_gl)
117 $tpl->assign('tool_post_data', base64_encode(serialize($NELTOOL['POST_VARS'])));
119 switch ($tool_services_gl)
121 case 'display guilds':
123 $service_list = tool_main_get_checked_services();
124 if (sizeof($service_list))
126 $service_command = 'dumpGuildList local';
128 nt_log("Domain '$AS_Name' : '$service_command' on ". implode(', ',array_values($service_list)));
130 $tpl->assign('tool_service_select_list', array_combine($service_list, $service_list));
131 $tpl->assign('tool_execute_result', '');
132 $command_return_data = array();
134 reset($service_list);
135 foreach($service_list as $service)
137 //nt_common_add_debug("about to run 'displayPlayers' on '$service' ...");
139 $adminService->serviceCmd($service, $service_command);
140 if (!$adminService->waitCallback())
142 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for command : '. $service_command);
144 else
146 // the locator displays a nice output, no need for the raw one
147 //$tpl->assign('tool_execute_command', $service_command);
151 if (sizeof($command_return_data))
153 $guild_data = tool_gl_parse_dump_guild_list($command_return_data);
154 $tpl->assign('tool_guild_data', $guild_data);
158 break;
160 case 'update name':
162 if (($tool_services_gl == 'update name') && tool_admin_applications_check('tool_guild_locator_manage_guild'))
164 $service = $NELTOOL['POST_VARS']['servicealias'];
165 $guild_shard_id = $NELTOOL['POST_VARS']['guildshardid'];
166 $guild_id = $NELTOOL['POST_VARS']['guildid'];
167 $new_guild_name = $NELTOOL['POST_VARS']['new_guild_name'];
169 $new_guild_name = trim($new_guild_name);
170 if (ereg("^[a-zA-Z0-9\ ]+$", $new_guild_name))
172 // this is a small hack that was done by daniel so i could use the renameGuild command without an EID
173 $service_command = 'renameGuild admin_tool '. $guild_shard_id .':'. $guild_id .' "'. $new_guild_name .'"';
175 nt_log("Domain '$AS_Name' : '$service_command' on ". $service);
177 $tpl->assign('tool_execute_result', '');
178 $command_return_data = array();
180 $adminService->serviceCmd($service, $service_command);
181 if (!$adminService->waitCallback())
183 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for command : '. $service_command);
185 else
187 // tool_guild_errors
190 else
192 $tpl->assign('tool_guild_errors', array('New name contains illegal characters.'));
195 $NELTOOL['GET_VARS']['servicealias'] = $service;
196 $NELTOOL['GET_VARS']['guildshardid'] = $guild_shard_id;
197 $NELTOOL['GET_VARS']['guildid'] = $guild_id;
200 case 'update description':
202 if (($tool_services_gl == 'update description') && tool_admin_applications_check('tool_guild_locator_manage_guild'))
204 $service = $NELTOOL['POST_VARS']['servicealias'];
205 $guild_shard_id = $NELTOOL['POST_VARS']['guildshardid'];
206 $guild_id = $NELTOOL['POST_VARS']['guildid'];
207 $new_guild_desc = $NELTOOL['POST_VARS']['new_guild_description'];
209 $new_guild_desc = trim($new_guild_desc);
210 if (ereg("^[a-zA-Z0-9\ ]+$", $new_guild_desc))
212 $service_command = 'setGuildDescription '. $guild_shard_id .':'. $guild_id .' "'. $new_guild_desc .'"';
214 nt_log("Domain '$AS_Name' : '$service_command' on ". $service);
216 $tpl->assign('tool_execute_result', '');
217 $command_return_data = array();
219 $adminService->serviceCmd($service, $service_command);
220 if (!$adminService->waitCallback())
222 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for command : '. $service_command);
224 else
226 // tool_guild_errors
230 else
232 $tpl->assign('tool_guild_errors', array('New description contains illegal characters.'));
235 $NELTOOL['GET_VARS']['servicealias'] = $service;
236 $NELTOOL['GET_VARS']['guildshardid'] = $guild_shard_id;
237 $NELTOOL['GET_VARS']['guildid'] = $guild_id;
240 case 'setleader':
242 if (($tool_services_gl == 'setleader') && tool_admin_applications_check('tool_guild_locator_manage_members'))
244 $service = $NELTOOL['GET_VARS']['servicealias'];
245 $guild_shard_id = $NELTOOL['GET_VARS']['guildshardid'];
246 $guild_id = $NELTOOL['GET_VARS']['guildid'];
247 $member_eid = $NELTOOL['GET_VARS']['eid'];
249 // guildSetLeader <guildName|<shardId>:<guildId> <member eid>
251 $service_command = 'guildSetLeader '. $guild_shard_id .':'. $guild_id .' '. $member_eid;
253 nt_log("Domain '$AS_Name' : '$service_command' on ". $service);
255 $tpl->assign('tool_execute_result', '');
256 $command_return_data = array();
258 $adminService->serviceCmd($service, $service_command);
259 if (!$adminService->waitCallback())
261 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for command : '. $service_command);
263 else
265 // the locator displays a nice output, no need for the raw one
266 //$tpl->assign('tool_execute_command', $service_command);
267 $tpl->assign('tool_guild_errors', tool_gl_parse_grade_change($command_return_data));
273 case 'promote':
275 if (($tool_services_gl == 'promote') && tool_admin_applications_check('tool_guild_locator_manage_members'))
277 $service = $NELTOOL['GET_VARS']['servicealias'];
278 $guild_shard_id = $NELTOOL['GET_VARS']['guildshardid'];
279 $guild_id = $NELTOOL['GET_VARS']['guildid'];
280 $member_eid = $NELTOOL['GET_VARS']['eid'];
281 $member_grade = $NELTOOL['GET_VARS']['grade'];
283 $new_grade = 'Member';
284 if ($member_grade == 'Officer') $new_grade = 'Officer';
285 elseif ($member_grade == 'HighOfficer') $new_grade = 'HighOfficer';
287 // guildSetGrade <guildName|<shardId>:<guildId> <member eid> <grade = Member/Officer/HighOfficer/Leader>
289 $service_command = 'guildSetGrade '. $guild_shard_id .':'. $guild_id .' '. $member_eid .' '. $new_grade;
291 nt_log("Domain '$AS_Name' : '$service_command' on ". $service);
293 $tpl->assign('tool_execute_result', '');
294 $command_return_data = array();
296 $adminService->serviceCmd($service, $service_command);
297 if (!$adminService->waitCallback())
299 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for command : '. $service_command);
301 else
303 // the locator displays a nice output, no need for the raw one
304 //$tpl->assign('tool_execute_command', $service_command);
305 $tpl->assign('tool_guild_errors', tool_gl_parse_grade_change($command_return_data));
311 case 'demote':
313 if (($tool_services_gl == 'demote') && tool_admin_applications_check('tool_guild_locator_manage_members'))
315 $service = $NELTOOL['GET_VARS']['servicealias'];
316 $guild_shard_id = $NELTOOL['GET_VARS']['guildshardid'];
317 $guild_id = $NELTOOL['GET_VARS']['guildid'];
318 $member_eid = $NELTOOL['GET_VARS']['eid'];
319 $member_grade = $NELTOOL['GET_VARS']['grade'];
321 $new_grade = 'Member';
322 if ($member_grade == 'Officer') $new_grade = 'Officer';
323 elseif ($member_grade == 'Member') $new_grade = 'Member';
325 // guildSetGrade <guildName|<shardId>:<guildId> <member eid> <grade = Member/Officer/HighOfficer/Leader>
327 $service_command = 'guildSetGrade '. $guild_shard_id .':'. $guild_id .' '. $member_eid .' '. $new_grade;
329 nt_log("Domain '$AS_Name' : '$service_command' on ". $service);
331 $tpl->assign('tool_execute_result', '');
332 $command_return_data = array();
334 $adminService->serviceCmd($service, $service_command);
335 if (!$adminService->waitCallback())
337 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for command : '. $service_command);
339 else
341 // the locator displays a nice output, no need for the raw one
342 //$tpl->assign('tool_execute_command', $service_command);
343 $tpl->assign('tool_guild_errors', tool_gl_parse_grade_change($command_return_data));
348 case 'dumpguild':
350 $service = $NELTOOL['GET_VARS']['servicealias'];
351 $guild_shard_id = $NELTOOL['GET_VARS']['guildshardid'];
352 $guild_id = $NELTOOL['GET_VARS']['guildid'];
354 if (($guild_shard_id > 0) && ($guild_id > 0) && ($service != ''))
356 $service_command = 'dumpGuild '. $guild_shard_id .':'. $guild_id;
358 nt_log("Domain '$AS_Name' : '$service_command' on ". $service);
360 $tpl->assign('tool_execute_result', '');
361 $command_return_data = array();
363 $adminService->serviceCmd($service, $service_command);
364 if (!$adminService->waitCallback())
366 nt_common_add_debug('Error while waiting for callback on service \''. $service .'\' for command : '. $service_command);
368 else
370 // the locator displays a nice output, no need for the raw one
371 //$tpl->assign('tool_execute_command', $service_command);
374 if (sizeof($command_return_data))
376 $tool_sub_services_gl = null;
377 if (isset($NELTOOL['POST_VARS']['subservices_gl'])) $tool_sub_services_gl = $NELTOOL['POST_VARS']['subservices_gl'];
378 elseif (isset($NELTOOL['GET_VARS']['subservices_gl'])) $tool_sub_services_gl = $NELTOOL['GET_VARS']['subservices_gl'];
380 $guild_dump_data = tool_gl_parse_dump_guild($command_return_data);
381 $tpl->assign('tool_guild_dump_data', $guild_dump_data);
382 $tpl->assign('tool_service', $service);
384 // view ingame guild forums
385 if (tool_admin_applications_check('tool_guild_locator_manage_forums'))
387 if ($tool_sub_services_gl)
389 switch ($tool_sub_services_gl)
391 case 'viewthread':
393 $view_forum_threadid = $NELTOOL['GET_VARS']['threadid'];
394 $view_forum_recoverable = $NELTOOL['GET_VARS']['recoverable'];
396 $thread_name = ($view_forum_recoverable == 1 ? '_':'') .'thread_'. $view_forum_threadid .'.index';
398 $view_thread_data_raw = tool_gl_view_forum($MFS_Web, $guild_shard_id, $guild_dump_data['guild_name'], $thread_name);
399 $view_thread_data = tool_gl_parse_thread_view($view_thread_data_raw);
400 $tpl->assign('tool_guild_thread', $view_thread_data);
402 break;
404 case 'recoverthread':
406 $recover_forum_threadid = $NELTOOL['GET_VARS']['threadid'];
408 $thread_name = '_thread_'. $recover_forum_threadid .'.index';
409 tool_gl_view_forum($MFS_Web, $guild_shard_id, $guild_dump_data['guild_name'], $recover_forum_threadid, true);
411 break;
415 $view_forum_data_raw = tool_gl_view_forum($MFS_Web, $guild_shard_id, $guild_dump_data['guild_name']);
416 $view_forum_data = tool_gl_parse_forum_view($view_forum_data_raw);
418 if (is_array($view_forum_data)) $tpl->assign('tool_guild_forums', $view_forum_data);
419 else $tpl->assign('tool_guild_forums_error', $view_forum_data);
425 break;
430 if (isset($NELTOOL['GET_VARS']['eid']))
432 $locate_eid = $NELTOOL['GET_VARS']['eid'];
436 $status = $adminService->getStates();
437 nt_common_add_debug($status);
439 $domainServices = tool_main_parse_status($status);
441 $filteredServices = array();
442 reset($domainServices);
443 foreach($domainServices as $aKey => $aService)
445 // we are only interested in EGS
446 if ($aService['ShortName'] == 'EGS')
448 $filteredServices[] = $aService;
452 $tpl->assign('tool_services_list', $filteredServices);
457 $tpl->display('tool_guild_locator.tpl');