3 $tool_admin_menu = array(array('title' => 'Main',
5 'uri' => 'tool_administration.php?toolmode=help',
6 'tpl' => 'tool_administration.tpl',
7 'access' => '', // ALWAYS LEAVE EMPTY !
9 array('title' => 'Users',
11 'uri' => 'tool_administration.php?toolmode=users',
12 'tpl' => 'tool_administration_users.tpl',
13 'access' => 'tool_admin_user',
15 array('title' => 'Groups',
17 'uri' => 'tool_administration.php?toolmode=groups',
18 'tpl' => 'tool_administration_groups.tpl',
19 'access' => 'tool_admin_group',
21 array('title' => 'Restarts',
23 'uri' => 'tool_administration.php?toolmode=restarts',
24 'tpl' => 'tool_administration_restarts.tpl',
25 'access' => 'tool_admin_restart',
27 array('title' => 'Applications',
28 'key' => 'applications',
29 'uri' => 'tool_administration.php?toolmode=applications',
30 'tpl' => 'tool_administration_applications.tpl',
31 'access' => 'tool_admin_application',
33 array('title' => 'Domains',
35 'uri' => 'tool_administration.php?toolmode=domains',
36 'tpl' => 'tool_administration_domains.tpl',
37 'access' => 'tool_admin_domain',
39 array('title' => 'Shards',
41 'uri' => 'tool_administration.php?toolmode=shards',
42 'tpl' => 'tool_administration_shards.tpl',
43 'access' => 'tool_admin_shard',
45 array('title' => 'Logs',
47 'uri' => 'tool_administration.php?toolmode=logs',
48 'tpl' => 'tool_administration_logs.tpl',
49 'access' => 'tool_admin_logs',
53 $tool_language_list = array(array('lang_id' => 'en',
54 'lang_name' => 'English',
56 array('lang_id' => 'fr',
57 'lang_name' => 'French',
59 array('lang_id' => 'de',
60 'lang_name' => 'German',
64 function tool_admin_menu_get_item_from_key($key)
66 global $tool_admin_menu;
68 reset($tool_admin_menu);
69 foreach($tool_admin_menu as $tool_menu)
71 if ($tool_menu['key'] == $key) return $tool_menu;
77 function tool_admin_users_get_list($group_list)
83 $sql = "SELECT * FROM ". NELDB_USER_TABLE
." ORDER BY user_name ASC";
84 if ($result = $db->sql_query($sql))
86 if ($db->sql_numrows($result))
89 while ($row = $db->sql_fetchrow($result))
91 $row['user_group_name'] = tool_admin_groups_get_name_from_id($group_list, $row['user_group_id']);
100 function tool_admin_groups_get_user_list($group_id)
106 $sql = "SELECT * FROM ". NELDB_USER_TABLE
." WHERE user_group_id=". $group_id ." ORDER BY user_name ASC";
107 if ($result = $db->sql_query($sql))
109 if ($db->sql_numrows($result))
111 $data = $db->sql_fetchrowset($result);
118 function tool_admin_groups_get_list()
124 $sql = "SELECT * FROM ". NELDB_GROUP_TABLE
." ORDER BY group_name ASC";
125 if ($result = $db->sql_query($sql))
127 if ($db->sql_numrows($result))
129 while ($row = $db->sql_fetchrow($result))
131 $row['group_level_name'] = tool_admin_groups_get_level_name_from_id($row['group_level']);
140 function tool_admin_groups_get_level_name_from_id($group_level)
142 global $nel_user_group_levels;
144 reset($nel_user_group_levels);
145 foreach($nel_user_group_levels as $level_data)
147 if ($group_level == $level_data['level_id'])
149 return $level_data['level_name'];
153 return tool_admin_groups_get_level_name_from_id(0);
156 function tool_admin_groups_get_name_from_id($group_list, $group_id)
161 foreach($group_list as $group_data)
163 if ($group_data['group_id'] == $group_id)
165 $data = $group_data['group_name'];
172 function tool_admin_users_get_id($user_id)
178 $sql = "SELECT * FROM ". NELDB_USER_TABLE
." WHERE user_id=". $user_id;
179 if ($result = $db->sql_query($sql))
181 if ($db->sql_numrows($result))
183 $data = $db->sql_fetchrow($result);
189 function tool_admin_users_add($user_name, $user_password, $user_group, $user_active)
193 $user_name = trim($user_name);
194 $user_password = trim($user_password);
196 if ($user_name == '') return "/!\ Error: user name is empty!";
197 if ($user_password == '') return "/!\ Error: password is empty!";
199 $user_exists = tool_admin_users_name_exist($user_name);
202 $sql = "INSERT INTO ". NELDB_USER_TABLE
;
203 $sql .= " (`user_name`,`user_password`,`user_group_id`,`user_created`,`user_active`)";
205 $sql .= " ('". $user_name ."','". md5($user_password) ."','". $user_group ."','". time() ."','". $user_active ."')";
206 $db->sql_query($sql);
210 return "/!\ Error: user name already exists in the database!";
213 function tool_admin_users_name_exist($user_name)
219 $sql = "SELECT user_id, user_name FROM ". NELDB_USER_TABLE
." WHERE user_name='". $user_name ."'";
220 if ($result = $db->sql_query($sql))
222 if ($db->sql_numrows($result))
231 function tool_admin_users_del($user_id)
235 $sql = "DELETE FROM ". NELDB_USER_TABLE
." WHERE user_id=". $user_id;
236 $db->sql_query($sql);
239 function tool_admin_users_update($user_id, $user_name, $user_password, $user_group, $user_active)
243 $user_name = trim($user_name);
244 $user_password = trim($user_password);
246 if ($user_name == "") return "/!\ Error: user name is empty!";
247 if (!ereg("^([[:alnum:]]+)$",$user_name)) return "/!\ Error: invalid user name, only alpha numerical characters allowed!";
249 $sql = "SELECT * FROM ". NELDB_USER_TABLE
." WHERE user_name='". $user_name ."' AND user_id<>". $user_id;
250 if ($result = $db->sql_query($sql))
252 if ($db->sql_numrows($result))
254 return "/!\ Error: user name already exists in database!";
259 if ($user_password != '') $sql_ext = ",user_password='". md5($user_password) ."'";
261 $sql = "UPDATE ". NELDB_USER_TABLE
." SET user_name='". $user_name ."',user_group_id='". $user_group ."',user_active='". $user_active ."'". $sql_ext ." WHERE user_id=". $user_id;
262 $db->sql_query($sql);
267 function tool_admin_groups_get_id($group_id)
273 $sql = "SELECT * FROM ". NELDB_GROUP_TABLE
." WHERE group_id=". $group_id;
274 if ($result = $db->sql_query($sql))
276 if ($db->sql_numrows($result))
278 $data = $db->sql_fetchrow($result);
285 function tool_admin_groups_add($group_name, $group_level, $group_default, $group_active)
289 $group_name = trim($group_name);
290 if ($group_name == '') return "/!\ Error: group name is empty!";
292 $group_exists = tool_admin_groups_name_exist($group_name);
295 if ($group_default == 1)
297 $sql = "UPDATE ". NELDB_GROUP_TABLE
." SET group_default=0";
298 $db->sql_query($sql);
301 $sql = "INSERT INTO ". NELDB_GROUP_TABLE
;
302 $sql .= " (`group_name`,`group_level`,`group_default`,`group_active`) ";
304 $sql .= " ('". $group_name ."',". $group_level .",". $group_default .",". $group_active .")";
305 $db->sql_query($sql);
310 return "/!\ Error: group name already exists in the database!";
313 function tool_admin_groups_name_exist($group_name)
319 $sql = "SELECT group_id, group_name FROM ". NELDB_GROUP_TABLE
." WHERE group_name='". $group_name ."'";
320 if ($result = $db->sql_query($sql))
322 if ($db->sql_numrows($result))
332 function tool_admin_groups_del($group_id)
336 $sql = "DELETE FROM ". NELDB_GROUP_TABLE
." WHERE group_id=". $group_id;
337 $db->sql_query($sql);
340 function tool_admin_groups_update($group_id, $group_name, $group_level, $group_default, $group_active)
344 $group_name = trim($group_name);
346 if ($group_name == "") return "/!\ Error: group name is empty!";
347 if (!ereg("^([[:alnum:]]+)$",$group_name)) return "/!\ Error: invalid group name, only alpha numerical characters allowed!";
349 $sql = "SELECT * FROM ". NELDB_GROUP_TABLE
." WHERE group_name='". $group_name ."' AND group_id<>". $group_id;
350 if ($result = $db->sql_query($sql))
352 if ($db->sql_numrows($result))
354 return "/!\ Error: group name already exists in database!";
358 if ($group_default == 1)
360 $sql = "UPDATE ". NELDB_GROUP_TABLE
." SET group_default=0";
361 $db->sql_query($sql);
364 $sql = "UPDATE ". NELDB_GROUP_TABLE
." SET group_name='". $group_name ."',group_level='". $group_level ."',group_default='". $group_default ."',group_active='". $group_active ."' WHERE group_id=". $group_id;
365 $db->sql_query($sql);
370 function tool_admin_groups_update_default_domain($group_id, $domain_id)
374 $sql = "SELECT * FROM ". NELDB_GROUP_TABLE
." WHERE group_id=". $group_id;
375 if ($result = $db->sql_query($sql))
377 if ($db->sql_numrows($result))
379 $row = $db->sql_fetchrow($result);
381 if ($row['group_default_domain_id'] != $domain_id)
383 $sql = "UPDATE ". NELDB_GROUP_TABLE
." SET group_default_domain_id=". $domain_id .",group_default_shard_id=0 WHERE group_id=". $group_id;
384 $db->sql_query($sql);
389 return "/!\ Error: invalid group id!";
396 function tool_admin_groups_update_default_shard($group_id, $shard_id)
400 $sql = "SELECT * FROM ". NELDB_GROUP_TABLE
." WHERE group_id=". $group_id;
401 if ($result = $db->sql_query($sql))
403 if ($db->sql_numrows($result))
405 $sql = "UPDATE ". NELDB_GROUP_TABLE
." SET group_default_shard_id=". $shard_id ." WHERE group_id=". $group_id;
406 $db->sql_query($sql);
410 return "/!\ Error: invalid group id!";
417 function tool_admin_groups_update_default_application($group_id, $application_id)
421 $sql = "SELECT * FROM ". NELDB_GROUP_TABLE
." WHERE group_id=". $group_id;
422 if ($result = $db->sql_query($sql))
424 if ($db->sql_numrows($result))
426 $sql = "UPDATE ". NELDB_GROUP_TABLE
." SET group_default_application_id=". $application_id ." WHERE group_id=". $group_id;
427 $db->sql_query($sql);
431 return "/!\ Error: invalid group id!";
439 function tool_admin_applications_get_list()
445 $sql = "SELECT * FROM ". NELDB_APPLICATION_TABLE
." ORDER BY application_order ASC, application_name ASC";
446 if ($result = $db->sql_query($sql))
448 if ($db->sql_numrows($result))
450 $data = $db->sql_fetchrowset($result);
457 function tool_admin_applications_get_id($application_id)
463 $sql = "SELECT * FROM ". NELDB_APPLICATION_TABLE
." WHERE application_id=". $application_id;
464 if ($result = $db->sql_query($sql))
466 if ($db->sql_numrows($result))
468 $data = $db->sql_fetchrow($result);
475 function tool_admin_applications_add($application_name, $application_uri, $application_restriction, $application_icon, $application_order, $application_visible)
479 $application_name = trim($application_name);
480 if ($application_name == '') return "/!\ Error: application name is empty!";
482 $application_exists = tool_admin_applications_name_exist($application_name);
483 if (!$application_exists)
485 $sql = "INSERT INTO ". NELDB_APPLICATION_TABLE
;
486 $sql .= " (`application_name`,`application_uri`,`application_restriction`,`application_order`,`application_visible`,`application_icon`) ";
488 $sql .= " ('". $application_name ."','". $application_uri ."','". $application_restriction ."','". $application_order ."','". $application_visible ."','". $application_icon ."')";
489 $db->sql_query($sql);
494 return "/!\ Error: application name already exists in the database!";
497 function tool_admin_applications_name_exist($application_name)
503 $sql = "SELECT application_id, application_name FROM ". NELDB_APPLICATION_TABLE
." WHERE application_name='". $application_name ."'";
504 if ($result = $db->sql_query($sql))
506 if ($db->sql_numrows($result))
515 function tool_admin_applications_del($application_id)
519 $sql = "DELETE FROM ". NELDB_USER_APPLICATION_TABLE
." WHERE user_application_application_id=". $application_id;
520 $db->sql_query($sql);
522 $sql = "DELETE FROM ". NELDB_GROUP_APPLICATION_TABLE
." WHERE group_application_application_id=". $application_id;
523 $db->sql_query($sql);
525 $sql = "DELETE FROM ". NELDB_APPLICATION_TABLE
." WHERE application_id=". $application_id;
526 $db->sql_query($sql);
529 function tool_admin_applications_update($application_id, $application_name, $application_uri, $application_restriction, $application_icon, $application_order, $application_visible)
533 $application_name = trim($application_name);
534 if ($application_name == "") return "/!\ Error: application name is empty!";
536 $sql = "SELECT * FROM ". NELDB_APPLICATION_TABLE
." WHERE application_name='". $application_name ."' AND application_id<>". $application_id;
537 if ($result = $db->sql_query($sql))
539 if ($db->sql_numrows($result))
541 return "/!\ Error: application name already exists in database!";
545 $sql = "UPDATE ". NELDB_APPLICATION_TABLE
." SET application_name='". $application_name ."',application_uri='". $application_uri ."',application_restriction='". $application_restriction ."',application_icon='". $application_icon ."',application_order='". $application_order ."',application_visible='". $application_visible ."' WHERE application_id=". $application_id;
546 $db->sql_query($sql);
551 function tool_admin_domains_get_list()
557 $sql = "SELECT * FROM ". NELDB_DOMAIN_TABLE
." ORDER BY domain_name ASC";
558 if ($result = $db->sql_query($sql))
560 if ($db->sql_numrows($result))
562 $data = $db->sql_fetchrowset($result);
569 function tool_admin_domains_add($domain_name, $domain_application, $domain_as_host, $domain_as_port, $domain_rrd_path, $domain_las_admin_path, $domain_las_local_path, $domain_sql_string, $domain_cs_sql_string, $domain_hd_check, $domain_mfs_web)
573 $domain_name = trim($domain_name);
574 if ($domain_name == '') return "/!\ Error: domain name is empty!";
576 $domain_exists = tool_admin_domains_name_exist($domain_name);
579 $sql = "INSERT INTO ". NELDB_DOMAIN_TABLE
;
580 $sql .= " (`domain_name`,`domain_application`,`domain_as_host`,`domain_as_port`,`domain_rrd_path`,`domain_las_admin_path`,`domain_las_local_path`,`domain_sql_string`,`domain_hd_check`,`domain_mfs_web`,`domain_cs_sql_string`) ";
582 $sql .= " ('". $domain_name ."','". $domain_application ."','". $domain_as_host ."','". $domain_as_port ."','". $domain_rrd_path ."','". $domain_las_admin_path ."','". $domain_las_local_path ."','". $domain_sql_string ."',". $domain_hd_check .",'". $domain_mfs_web ."','". $domain_cs_sql_string ."') ";
583 $db->sql_query($sql);
588 return "/!\ Error: domain name already exists in the database!";
591 function tool_admin_domains_name_exist($domain_name)
597 $sql = "SELECT domain_id, domain_name FROM ". NELDB_DOMAIN_TABLE
." WHERE domain_name='". $domain_name ."'";
598 if ($result = $db->sql_query($sql))
600 if ($db->sql_numrows($result))
609 function tool_admin_domains_get_id($domain_id)
615 $sql = "SELECT * FROM ". NELDB_DOMAIN_TABLE
." WHERE domain_id=". $domain_id;
616 if ($result = $db->sql_query($sql))
618 if ($db->sql_numrows($result))
620 $data = $db->sql_fetchrow($result);
627 function tool_admin_domains_del($domain_id)
631 $sql = "DELETE FROM ". NELDB_USER_SHARD_TABLE
." WHERE user_shard_domain_id=". $domain_id;
632 $db->sql_query($sql);
634 $sql = "DELETE FROM ". NELDB_USER_DOMAIN_TABLE
." WHERE user_domain_domain_id=". $domain_id;
635 $db->sql_query($sql);
637 $sql = "DELETE FROM ". NELDB_GROUP_SHARD_TABLE
." WHERE group_shard_domain_id=". $domain_id;
638 $db->sql_query($sql);
640 $sql = "DELETE FROM ". NELDB_GROUP_DOMAIN_TABLE
." WHERE group_domain_domain_id=". $domain_id;
641 $db->sql_query($sql);
643 $sql = "DELETE FROM ". NELDB_SHARD_TABLE
." WHERE shard_domain_id=". $domain_id;
644 $db->sql_query($sql);
646 $sql = "DELETE FROM ". NELDB_DOMAIN_TABLE
." WHERE domain_id=". $domain_id;
647 $db->sql_query($sql);
651 function tool_admin_domains_update($domain_id, $domain_name, $domain_application, $domain_as_host, $domain_as_port, $domain_rrd_path, $domain_las_admin_path, $domain_las_local_path, $domain_sql_string, $domain_cs_sql_string, $domain_hd_check, $domain_mfs_web)
655 $domain_name = trim($domain_name);
657 if ($domain_name == "") return "/!\ Error: domain name is empty!";
659 $sql = "SELECT * FROM ". NELDB_DOMAIN_TABLE
." WHERE domain_name='". $domain_name ."' AND domain_id<>". $domain_id;
660 if ($result = $db->sql_query($sql))
662 if ($db->sql_numrows($result))
664 return "/!\ Error: domain name already exists in database!";
668 $sql = "UPDATE ". NELDB_DOMAIN_TABLE
." SET domain_name='". $domain_name."',domain_application='". $domain_application ."',domain_as_host='". $domain_as_host ."',domain_as_port='". $domain_as_port ."',domain_rrd_path='". $domain_rrd_path ."',domain_las_admin_path='". $domain_las_admin_path ."',domain_las_local_path='". $domain_las_local_path ."',domain_sql_string='". $domain_sql_string ."',domain_hd_check=". $domain_hd_check .",domain_mfs_web='". $domain_mfs_web ."',domain_cs_sql_string='". $domain_cs_sql_string ."' WHERE domain_id=". $domain_id;
669 $db->sql_query($sql);
674 function tool_admin_shards_get_list()
680 $sql = "SELECT * FROM ". NELDB_SHARD_TABLE
." LEFT JOIN ". NELDB_DOMAIN_TABLE
." ON (shard_domain_id=domain_id) ORDER BY domain_name ASC, shard_name ASC";
681 if ($result = $db->sql_query($sql))
683 if ($db->sql_numrows($result))
685 $data = $db->sql_fetchrowset($result);
692 function tool_admin_shards_add($shard_name, $shard_as_id, $shard_domain_id, $shard_language)
696 $shard_name = trim($shard_name);
697 if ($shard_name == '') return "/!\ Error: shard name is empty!";
699 $shard_as_id = trim($shard_as_id);
700 //if (!is_numeric($shard_as_id)) return "/!\ Error: shard AS Id is invalid!";
702 //$shard_exists = tool_admin_shards_name_exist($shard_as_id);
703 //if (!$shard_exists)
705 $sql = "INSERT INTO ". NELDB_SHARD_TABLE
;
706 $sql .= " (`shard_name`,`shard_as_id`,`shard_domain_id`,`shard_lang`) ";
708 $sql .= " ('". $shard_name ."','". $shard_as_id ."','". $shard_domain_id ."','". $shard_language ."') ";
709 $db->sql_query($sql);
713 //return "/!\ Error: shard AS Id already exists in the database!";
716 function tool_admin_shards_name_exist($shard_as_id, $except_id=false)
720 if ($shard_as_id == '*' ||
$shard_as_id == '?') return false;
724 $sql = "SELECT * FROM ". NELDB_SHARD_TABLE
." WHERE shard_as_id='". $shard_as_id ."'";
725 if ($except_id !== false) $sql .= " AND shard_id<>". $except_id;
727 if ($result = $db->sql_query($sql))
729 if ($db->sql_numrows($result))
738 function tool_admin_shards_get_id($shard_id)
744 $sql = "SELECT * FROM ". NELDB_SHARD_TABLE
." WHERE shard_id=". $shard_id;
745 if ($result = $db->sql_query($sql))
747 if ($db->sql_numrows($result))
749 $data = $db->sql_fetchrow($result);
756 function tool_admin_shards_del($shard_id)
760 $sql = "DELETE FROM ". NELDB_USER_SHARD_TABLE
." WHERE user_shard_shard_id=". $shard_id;
761 $db->sql_query($sql);
763 $sql = "DELETE FROM ". NELDB_GROUP_SHARD_TABLE
." WHERE group_shard_shard_id=". $shard_id;
764 $db->sql_query($sql);
766 $sql = "DELETE FROM ". NELDB_SHARD_TABLE
." WHERE shard_id=". $shard_id;
767 $db->sql_query($sql);
770 function tool_admin_shards_update($shard_id, $shard_name, $shard_as_id, $shard_domain_id, $shard_language)
774 $shard_name = trim($shard_name);
775 if ($shard_name == '') return "/!\ Error: shard name is empty!";
777 $shard_as_id = trim($shard_as_id);
778 //if (!is_numeric($shard_as_id)) return "/!\ Error: shard AS Id is invalid!";
780 //$shard_exists = tool_admin_shards_name_exist($shard_as_id, $shard_id);
781 //if (!$shard_exists)
783 $sql = "UPDATE ". NELDB_SHARD_TABLE
." SET shard_name='". $shard_name ."',shard_as_id='". $shard_as_id ."',shard_domain_id='". $shard_domain_id ."',shard_lang='". $shard_language ."' WHERE shard_id=". $shard_id;
784 $db->sql_query($sql);
789 //return "/!\ Error: shard AS Id already exists in the database!";
794 function tool_admin_users_domains_update($user_id, $group_id, $domain_ids)
798 $user_domains = tool_admin_users_domains_get_list($user_id, true);
799 $group_domains = tool_admin_groups_domains_get_list($group_id, true);
801 $sql = "DELETE FROM ". NELDB_USER_DOMAIN_TABLE
." WHERE user_domain_user_id=". $user_id;
802 $db->sql_query($sql);
804 if (is_array($domain_ids) and sizeof($domain_ids))
807 foreach($domain_ids as $domain_id)
809 if (is_numeric($domain_id) && $domain_id > 0)
811 $sql = "INSERT INTO ". NELDB_USER_DOMAIN_TABLE
." (`user_domain_user_id`,`user_domain_domain_id`) VALUES ('". $user_id ."','". $domain_id ."')";
812 $db->sql_query($sql);
817 // now we remove all shards except those that belong to the user AND group
819 $sql = "DELETE FROM ". NELDB_USER_SHARD_TABLE
." WHERE user_shard_user_id=". $user_id;
820 if (is_array($domain_ids) && sizeof($domain_ids)) $sql .= " AND user_shard_domain_id NOT IN (". implode(',',array_values($domain_ids)) .")";
821 if (is_array($group_domains) && sizeof($group_domains)) $sql .= " AND user_shard_domain_id NOT IN (". implode(',',array_values($group_domains)) .")";
822 $db->sql_query($sql);
825 function tool_admin_users_domains_get_list($user_id, $compact = false)
832 $sql = "SELECT * FROM ". NELDB_USER_DOMAIN_TABLE
." LEFT JOIN ". NELDB_DOMAIN_TABLE
." ON (user_domain_domain_id=domain_id) WHERE user_domain_user_id=". $user_id ." ORDER BY domain_name ASC";
833 if ($result = $db->sql_query($sql))
835 if ($db->sql_numrows($result))
837 $data1 = $db->sql_fetchrowset($result);
844 foreach($data1 as $data_tmp)
846 $data[] = $data_tmp['user_domain_domain_id'];
859 function tool_admin_groups_domains_get_list($group_id, $compact = false)
866 $sql = "SELECT * FROM ". NELDB_GROUP_DOMAIN_TABLE
." LEFT JOIN ". NELDB_DOMAIN_TABLE
." ON (group_domain_domain_id=domain_id) WHERE group_domain_group_id=". $group_id ." ORDER BY domain_name ASC";
867 if ($result = $db->sql_query($sql))
869 if ($db->sql_numrows($result))
871 $data1 = $db->sql_fetchrowset($result);
878 foreach($data1 as $data_tmp)
880 $data[] = $data_tmp['group_domain_domain_id'];
888 //nt_common_add_debug($data);
893 function tool_admin_users_domains_merge($domain_list, $user_list, $group_list)
897 if (is_array($domain_list) && sizeof($domain_list))
900 foreach($domain_list as $domain)
902 if (in_array($domain['domain_id'], $group_list))
904 $domain['domain_disabled'] = true;
905 $domain['domain_visible'] = true;
907 elseif (in_array($domain['domain_id'], $user_list))
909 $domain['domain_selected'] = true;
910 $domain['domain_visible'] = true;
920 function tool_admin_users_shards_get_list($user_id, $compact = false)
927 $sql = "SELECT * FROM ". NELDB_USER_SHARD_TABLE
." LEFT JOIN ". NELDB_SHARD_TABLE
." ON (user_shard_shard_id=shard_id) WHERE user_shard_user_id=". $user_id ." ORDER BY shard_name ASC";
928 if ($result = $db->sql_query($sql))
930 if ($db->sql_numrows($result))
932 $data1 = $db->sql_fetchrowset($result);
939 foreach($data1 as $data_tmp)
941 $data[] = $data_tmp['user_shard_shard_id'];
954 function tool_admin_groups_shards_get_list($group_id, $compact = false)
961 $sql = "SELECT * FROM ". NELDB_GROUP_SHARD_TABLE
." LEFT JOIN ". NELDB_SHARD_TABLE
." ON (group_shard_shard_id=shard_id) WHERE group_shard_group_id=". $group_id ." ORDER BY shard_name ASC";
962 if ($result = $db->sql_query($sql))
964 if ($db->sql_numrows($result))
966 $data1 = $db->sql_fetchrowset($result);
973 foreach($data1 as $data_tmp)
975 $data[] = $data_tmp['group_shard_shard_id'];
986 function tool_admin_users_shards_merge($domain_list, $shard_list, $user_list, $group_list)
990 if (is_array($shard_list) && sizeof($shard_list))
993 foreach($shard_list as $shard)
995 if (in_array($shard['shard_id'], $group_list))
997 $shard['shard_disabled'] = true;
999 elseif (in_array($shard['shard_id'], $user_list))
1001 $shard['shard_selected'] = true;
1007 $shard_list = $data1;
1012 // now we sort the shards by their domain
1013 if (is_array($domain_list) && sizeof($domain_list))
1015 reset($domain_list);
1016 foreach($domain_list as $domain)
1018 // looks for the shards that belong to this domain
1020 foreach($shard_list as $shard)
1022 if ($domain['domain_id'] == $shard['shard_domain_id'])
1024 $domain['shard_list'][] = $shard;
1031 $domain_list = $data2;
1034 return $domain_list;
1037 function tool_admin_users_shards_update($user_id, $group_id, $shard_ids)
1041 $sql = "DELETE FROM ". NELDB_USER_SHARD_TABLE
." WHERE user_shard_user_id=". $user_id;
1042 $db->sql_query($sql);
1044 if (is_array($shard_ids) && sizeof($shard_ids))
1047 foreach($shard_ids as $shard_tmp)
1049 $tmp = explode('_', $shard_tmp);
1050 $domain_id = $tmp[0];
1051 $shard_id = $tmp[1];
1053 if (is_numeric($domain_id) && is_numeric($shard_id) && $domain_id > 0 && $shard_id > 0)
1055 $sql = "INSERT INTO ". NELDB_USER_SHARD_TABLE
." (`user_shard_user_id`,`user_shard_shard_id`,`user_shard_domain_id`) VALUES ('". $user_id ."','". $shard_id ."','". $domain_id ."')";
1056 $db->sql_query($sql);
1062 function tool_admin_groups_domains_update($group_id, $domain_ids)
1066 $sql = "DELETE FROM ". NELDB_GROUP_DOMAIN_TABLE
." WHERE group_domain_group_id=". $group_id;
1067 $db->sql_query($sql);
1069 if (is_array($domain_ids) and sizeof($domain_ids))
1072 foreach($domain_ids as $domain_id)
1074 if (is_numeric($domain_id) && $domain_id > 0)
1076 $sql = "INSERT INTO ". NELDB_GROUP_DOMAIN_TABLE
." (`group_domain_group_id`,`group_domain_domain_id`) VALUES ('". $group_id ."','". $domain_id ."')";
1077 $db->sql_query($sql);
1082 $sql = "DELETE FROM ". NELDB_GROUP_SHARD_TABLE
." WHERE group_shard_group_id=". $group_id;
1083 if (is_array($domain_ids) && sizeof($domain_ids)) $sql .= " AND group_shard_domain_id NOT IN (". implode(',',array_values($domain_ids)) .")";
1084 $db->sql_query($sql);
1086 // we need to check some stuff for each user in this group
1088 // first we get the list of users that belong to his group
1089 $sql = "SELECT * FROM ". NELDB_USER_TABLE
." WHERE user_group_id=". $group_id;
1090 if ($result = $db->sql_query($sql))
1092 if ($db->sql_numrows($result))
1094 while ($row = $db->sql_fetchrow($result))
1097 $user_id = $row['user_id'];
1099 // get the domains specific to the user
1100 $user_domain_list = tool_admin_users_domains_get_list($user_id, true);
1102 // then we delete the shard that don't belong to the group nor user
1103 $sql = "DELETE FROM ". NELDB_USER_SHARD_TABLE
." WHERE user_shard_user_id=". $user_id;
1104 if (is_array($domain_ids) && sizeof($domain_ids)) $sql .= " AND user_shard_domain_id NOT IN (". implode(',', array_values($domain_ids)) .")";
1105 if (is_array($user_domain_list) && sizeof($user_domain_list)) $sql .= " AND user_shard_domain_id NOT IN (". implode(',', array_values($user_domain_list)) .")";
1106 $db->sql_query($sql);
1108 // make sure users don't have a domain that already belongs to a group
1109 $sql = "DELETE FROM ". NELDB_USER_DOMAIN_TABLE
." WHERE user_domain_user_id=". $user_id;
1110 if (is_array($domain_ids) && sizeof($domain_ids)) $sql .= " AND user_domain_domain_id IN (". implode(',', array_values($domain_ids)) .")";
1111 $db->sql_query($sql);
1118 function tool_admin_groups_domains_merge($domain_list, $group_list)
1122 if (is_array($domain_list) && sizeof($domain_list))
1124 reset($domain_list);
1125 foreach($domain_list as $domain)
1127 if (in_array($domain['domain_id'], $group_list))
1129 $domain['domain_visible'] = true;
1130 $domain['domain_selected'] = true;
1140 function tool_admin_groups_shards_merge($domain_list, $shard_list, $group_list)
1144 if (is_array($shard_list) && sizeof($shard_list))
1147 foreach($shard_list as $shard)
1149 if (in_array($shard['shard_id'], $group_list))
1151 $shard['shard_selected'] = true;
1157 $shard_list = $data1;
1162 // now we sort the shards by their domain
1163 if (is_array($domain_list) && sizeof($domain_list) && is_array($shard_list) && sizeof($shard_list))
1165 reset($domain_list);
1166 foreach($domain_list as $domain)
1168 // looks for the shards that belong to this domain
1170 foreach($shard_list as $shard)
1172 if ($domain['domain_id'] == $shard['shard_domain_id'])
1174 $domain['shard_list'][] = $shard;
1181 $domain_list = $data2;
1184 return $domain_list;
1187 function tool_admin_groups_shards_update($group_id, $shard_ids)
1191 $sql = "DELETE FROM ". NELDB_GROUP_SHARD_TABLE
." WHERE group_shard_group_id=". $group_id;
1192 $db->sql_query($sql);
1194 if (is_array($shard_ids) && sizeof($shard_ids))
1196 $user_shard_ids = array();
1199 foreach($shard_ids as $shard_tmp)
1201 $tmp = explode('_', $shard_tmp);
1202 $domain_id = $tmp[0];
1203 $shard_id = $tmp[1];
1205 $group_shard_ids[] = $shard_id;
1207 if (is_numeric($domain_id) && is_numeric($shard_id) && $domain_id > 0 && $shard_id > 0)
1209 $sql = "INSERT INTO ". NELDB_GROUP_SHARD_TABLE
." (`group_shard_group_id`,`group_shard_shard_id`,`group_shard_domain_id`) VALUES ('". $group_id ."','". $shard_id ."','". $domain_id ."')";
1210 $db->sql_query($sql);
1214 // we need to check some stuff for each user in this group
1216 // first we get the list of users that belong to his group
1217 $sql = "SELECT * FROM ". NELDB_USER_TABLE
." WHERE user_group_id=". $group_id;
1218 if ($result = $db->sql_query($sql))
1220 if ($db->sql_numrows($result))
1222 while ($row = $db->sql_fetchrow($result))
1225 $user_ids[] = $row['user_id'];
1228 $sql = "DELETE FROM ". NELDB_USER_SHARD_TABLE
." WHERE user_shard_user_id IN (". implode(',',array_values($user_ids)) .") AND user_shard_shard_id IN (". implode(',', array_values($group_shard_ids)) .")";
1229 $db->sql_query($sql);
1236 function tool_admin_groups_applications_update($group_id, $application_ids)
1240 $sql = "DELETE FROM ". NELDB_GROUP_APPLICATION_TABLE
." WHERE group_application_group_id=". $group_id;
1241 $db->sql_query($sql);
1243 if (is_array($application_ids) && sizeof($application_ids))
1245 reset($application_ids);
1246 foreach($application_ids as $application_id)
1248 $sql = "INSERT INTO ". NELDB_GROUP_APPLICATION_TABLE
." (`group_application_group_id`,`group_application_application_id`) VALUES ('". $group_id ."','". $application_id ."')";
1249 $db->sql_query($sql);
1252 // we need to make sure no user in this group has this application
1253 $sql = "SELECT * FROM ". NELDB_USER_TABLE
." WHERE user_group_id=". $group_id;
1254 if ($result = $db->sql_query($sql))
1256 if ($db->sql_numrows($result))
1258 while ($row = $db->sql_fetchrow($result))
1261 $user_ids[] = $row['user_id'];
1264 $sql = "DELETE FROM ". NELDB_USER_APPLICATION_TABLE
." WHERE user_application_user_id IN (". implode(',',array_values($user_ids)) .") AND user_application_application_id IN (". implode(',', array_values($application_ids)) .")";
1265 $db->sql_query($sql);
1273 function tool_admin_groups_applications_get_list($group_id, $compact = false)
1280 $sql = "SELECT * FROM ". NELDB_GROUP_APPLICATION_TABLE
." LEFT JOIN ". NELDB_APPLICATION_TABLE
." ON (group_application_application_id=application_id) WHERE group_application_group_id=". $group_id;
1281 if ($result = $db->sql_query($sql))
1283 if ($db->sql_numrows($result))
1285 $data1 = $db->sql_fetchrowset($result);
1292 foreach($data1 as $data_tmp)
1294 $data[] = $data_tmp['group_application_application_id'];
1305 function tool_admin_groups_applications_merge($appl_list, $group_list)
1309 if (is_array($appl_list) && sizeof($appl_list))
1312 foreach($appl_list as $appl)
1314 if (in_array($appl['application_id'], $group_list))
1316 $appl['application_selected'] = true;
1322 $appl_list = $data1;
1328 function tool_admin_users_applications_get_list($user_id, $compact = false)
1335 $sql = "SELECT * FROM ". NELDB_USER_APPLICATION_TABLE
." LEFT JOIN ". NELDB_APPLICATION_TABLE
." ON (user_application_application_id=application_id) WHERE user_application_user_id=". $user_id;
1336 if ($result = $db->sql_query($sql))
1338 if ($db->sql_numrows($result))
1340 $data1 = $db->sql_fetchrowset($result);
1347 foreach($data1 as $data_tmp)
1349 $data[] = $data_tmp['user_application_application_id'];
1360 function tool_admin_users_applications_merge($appl_list, $user_list, $group_list)
1364 if (is_array($appl_list) && sizeof($appl_list))
1367 foreach($appl_list as $appl)
1369 if (in_array($appl['application_id'], $group_list))
1371 $appl['application_disabled'] = true;
1373 elseif (in_array($appl['application_id'], $user_list))
1375 $appl['application_selected'] = true;
1381 $appl_list = $data1;
1387 function tool_admin_users_applications_update($user_id, $application_ids)
1391 $sql = "DELETE FROM ". NELDB_USER_APPLICATION_TABLE
." WHERE user_application_user_id=". $user_id;
1392 $db->sql_query($sql);
1394 if (is_array($application_ids) && sizeof($application_ids))
1396 reset($application_ids);
1397 foreach($application_ids as $application_id)
1399 if (is_numeric($application_id) && $application_id > 0)
1401 $sql = "INSERT INTO ". NELDB_USER_APPLICATION_TABLE
." (`user_application_user_id`,`user_application_application_id`) VALUES ('". $user_id ."','". $application_id ."')";
1402 $db->sql_query($sql);
1408 function tool_admin_applications_build_menu_list($user_access)
1412 // return $user_access['applications'];
1414 if (is_array($user_access['applications']) && sizeof($user_access['applications']))
1416 reset($user_access['applications']);
1417 foreach($user_access['applications'] as $appl_data)
1419 if ($appl_data['application_visible'] == 1)
1421 $user_check = tool_admin_applications_build_menu_check($appl_data['application_id'], $user_access['user_applications'], 'user_application_application_id');
1422 $group_check = tool_admin_applications_build_menu_check($appl_data['application_id'], $user_access['group_applications'], 'group_application_application_id');
1424 if ($appl_data['application_restriction'] == '')
1426 $menu[] = $appl_data;
1428 elseif ($user_check ||
$group_check)
1430 $menu[] = $appl_data;
1439 function tool_admin_applications_get_default($data, $application_id)
1441 if (is_array($data) && sizeof($data))
1444 foreach($data as $dt)
1446 if ($dt['application_id'] == $application_id)
1455 function tool_admin_applications_build_menu_check($appl_id, $data, $data_name)
1457 if (is_array($data) && sizeof($data))
1460 foreach($data as $dt)
1462 if ($dt[$data_name] == $appl_id)
1472 function tool_admin_applications_check($appl)
1476 $ua = $nel_user['access']['user_applications'];
1477 $ga = $nel_user['access']['group_applications'];
1479 if (is_array($ua) && sizeof($ua))
1484 if ($a['application_restriction'] == $appl)
1491 if (is_array($ga) && sizeof($ga))
1496 if ($a['application_restriction'] == $appl)
1506 function tool_admin_menu_get_list($ie)
1508 global $tool_admin_menu;
1511 $new_menu = array();
1513 reset($tool_admin_menu);
1514 foreach($tool_admin_menu as $menu_item)
1516 if (($menu_item['access'] == '') ||
tool_admin_applications_check($menu_item['access']))
1520 $new_menu[] = $menu_item;
1528 function tool_admin_users_groups_domains_merge()
1532 $user_domains = array();
1534 $ud = $nel_user['access']['user_domains'];
1535 $gd = $nel_user['access']['group_domains'];
1537 $dd = tool_admin_domains_get_list();
1539 if (is_array($dd) && sizeof($dd))
1542 foreach($dd as $domain_item)
1547 foreach($ud as $udomain)
1549 if ($domain_item['domain_id'] == $udomain['domain_id'])
1551 $user_domains[] = $domain_item;
1559 foreach($gd as $gdomain)
1561 if ($domain_item['domain_id'] == $gdomain['domain_id'])
1563 $user_domains[] = $domain_item;
1570 return $user_domains;
1573 function tool_admin_users_groups_shards_merge()
1577 $user_shards = array();
1579 $us = $nel_user['access']['user_shards'];
1580 $gs = $nel_user['access']['group_shards'];
1582 $ss = tool_admin_shards_get_list();
1584 if (is_array($ss) && sizeof($ss))
1587 foreach($ss as $shard_item)
1592 foreach($us as $ushard)
1594 if ($shard_item['shard_id'] == $ushard['shard_id'])
1596 $user_shards[] = $shard_item;
1604 foreach($gs as $gshard)
1606 if ($shard_item['shard_id'] == $gshard['shard_id'])
1608 $user_shards[] = $shard_item;
1615 return $user_shards;
1618 function tool_admin_logs_get_count()
1624 $sql = "SELECT * FROM ". NELDB_LOG_TABLE
;
1625 if ($result = $db->sql_query($sql))
1627 $total = $db->sql_numrows($result);
1633 function tool_admin_logs_get_list($start=0,$limit=25)
1639 $sql = "SELECT * FROM ". NELDB_LOG_TABLE
." ORDER BY logs_id DESC LIMIT ". $start .",". $limit;
1640 if ($result = $db->sql_query($sql))
1642 if ($db->sql_numrows($result))
1644 $data = $db->sql_fetchrowset($result);
1651 function tool_admin_domains_get_nel($application)
1655 $domain_data = null;
1657 if ($db->sql_select_db('nel'))
1659 $sql = "SELECT * FROM domain WHERE domain_name='". $application ."'";
1660 if ($result = $db->sql_query($sql))
1662 if ($db->sql_numrows($result))
1664 $domain_data = $db->sql_fetchrow($result);
1668 $db->sql_reselect_db();
1671 return $domain_data;
1674 //function tool_admin_domains_update_nel($domain_id, $domain_name, $domain_version, $domain_status)
1675 function tool_admin_domains_update_nel($domain_id, $domain_name, $domain_status)
1679 if ($db->sql_select_db('nel'))
1681 //$sql = "UPDATE domain SET status='". $domain_status ."',patch_version=". $domain_version ." WHERE domain_id=". $domain_id ." AND domain_name='". $domain_name ."'";
1682 $sql = "UPDATE domain SET status='". $domain_status ."' WHERE domain_id=". $domain_id ." AND domain_name='". $domain_name ."'";
1683 $db->sql_query($sql);
1685 $db->sql_reselect_db();
1689 function tool_admin_restarts_get_list($order='ASC')
1695 $sql = "SELECT * FROM ". NELDB_RESTART_GROUP_TABLE
." ORDER BY restart_group_order ". $order .", restart_group_name ". $order;
1696 if ($result = $db->sql_query($sql))
1698 if ($db->sql_numrows($result))
1700 $data = $db->sql_fetchrowset($result);
1707 function tool_admin_restarts_add($restart_name, $restart_list, $restart_order)
1711 $restart_name = trim($restart_name);
1712 if ($restart_name == '') return "/!\ Error: restart group name is empty!";
1714 $restart_list = trim($restart_list);
1715 if ($restart_list == '') return "/!\ Error: restart group list is empty!";
1717 $restart_order = trim($restart_order);
1718 if (!is_numeric($restart_order)) return "/!\ Error: restart group order is not numeric!";
1720 $sql = "INSERT INTO ". NELDB_RESTART_GROUP_TABLE
;
1721 $sql .= " (`restart_group_id`,`restart_group_name`,`restart_group_list`,`restart_group_order`) ";
1723 $sql .= " (0,'". $restart_name ."','". $restart_list ."','". $restart_order ."') ";
1724 $db->sql_query($sql);
1729 function tool_admin_restarts_get_id($restart_id)
1735 $sql = "SELECT * FROM ". NELDB_RESTART_GROUP_TABLE
." WHERE restart_group_id=". $restart_id;
1736 if ($result = $db->sql_query($sql))
1738 if ($db->sql_numrows($result))
1740 $data = $db->sql_fetchrow($result);
1747 function tool_admin_restarts_del($restart_id)
1751 $sql = "DELETE FROM ". NELDB_RESTART_GROUP_TABLE
." WHERE restart_group_id=". $restart_id;
1752 $db->sql_query($sql);
1755 function tool_admin_restarts_update($restart_id, $restart_name, $restart_list, $restart_order)
1759 $restart_name = trim($restart_name);
1760 if ($restart_name == '') return "/!\ Error: restart group name is empty!";
1762 $restart_list = trim($restart_list);
1763 if ($restart_list == '') return "/!\ Error: restart group list is empty!";
1765 $restart_order = trim($restart_order);
1766 if (!is_numeric($restart_order)) return "/!\ Error: restart group order is not numeric!";
1768 $sql = "UPDATE ". NELDB_RESTART_GROUP_TABLE
." SET restart_group_name='". $restart_name ."',restart_group_list='". $restart_list ."',restart_group_order='". $restart_order ."' WHERE restart_group_id=". $restart_id;
1769 $db->sql_query($sql);
1774 function tool_admin_restart_messages_add($message_name, $message_value, $message_lang)
1778 $message_name = trim($message_name);
1779 if ($message_name == '') return "/!\ Error: restart message name is empty!";
1781 $message_value = trim($message_value);
1782 if ($message_value == '') return "/!\ Error: restart message value is empty!";
1784 $sql = "INSERT INTO ". NELDB_RESTART_MESSAGE_TABLE
;
1785 $sql .= " (`restart_message_id`,`restart_message_name`,`restart_message_value`,`restart_message_lang`) ";
1787 $sql .= " (0,'". $message_name ."','". $message_value ."','". $message_lang ."') ";
1788 $db->sql_query($sql);
1793 function tool_admin_restart_messages_get_list()
1799 $sql = "SELECT * FROM ". NELDB_RESTART_MESSAGE_TABLE
." ORDER BY restart_message_name ASC, restart_message_lang ASC";
1800 if ($result = $db->sql_query($sql))
1802 if ($db->sql_numrows($result))
1804 $data = $db->sql_fetchrowset($result);
1811 function tool_admin_restart_messages_get_id($message_id)
1817 $sql = "SELECT * FROM ". NELDB_RESTART_MESSAGE_TABLE
." WHERE restart_message_id=". $message_id;
1818 if ($result = $db->sql_query($sql))
1820 if ($db->sql_numrows($result))
1822 $data = $db->sql_fetchrow($result);
1829 function tool_admin_restart_messages_get_list_from_name($message_name,$lang=null)
1838 $sql_ext = " AND restart_message_lang='". $lang ."'";
1841 $sql = "SELECT * FROM ". NELDB_RESTART_MESSAGE_TABLE
." WHERE restart_message_name='". $message_name ."' ". $sql_ext ." ORDER BY restart_message_lang ASC";
1842 if ($result = $db->sql_query($sql))
1844 if ($db->sql_numrows($result))
1846 $data = $db->sql_fetchrowset($result);
1853 function tool_admin_restart_messages_del($message_id)
1857 $sql = "DELETE FROM ". NELDB_RESTART_MESSAGE_TABLE
." WHERE restart_message_id=". $message_id;
1858 $db->sql_query($sql);
1861 function tool_admin_restart_messages_update($message_id, $message_name, $message_value, $message_lang)
1865 $message_name = trim($message_name);
1866 if ($message_name == '') return "/!\ Error: restart message name is empty!";
1868 $message_value = trim($message_value);
1869 if ($message_value == '') return "/!\ Error: restart message value is empty!";
1871 $sql = "UPDATE ". NELDB_RESTART_MESSAGE_TABLE
." SET restart_message_name='". $message_name ."',restart_message_value='". $message_value ."',restart_message_lang='". $message_lang ."' WHERE restart_message_id=". $message_id;
1872 $db->sql_query($sql);