hosts); } // Selecting usrgroups by user $sql = 'SELECT ug.usrgrpid '. ' FROM users_groups ug '. ' WHERE ug.userid='.$USER_DETAILS['userid']; $user_groups = DBfetch(DBselect($sql)); $user_groups[] = 0; // to ALL user groups // // Selecting groups by Hosts $sql = 'SELECT hg.hostid,hg.groupid '. ' FROM hosts_groups hg '. ' WHERE '.DBcondition('hg.hostid',$hosts); $hg_res = DBselect($sql); while($hg_rows = DBfetch($hg_res)){ $hosts_groups[$hg_rows['groupid']][$hg_rows['hostid']] = $hg_rows['hostid']; $hg_groups[$hg_rows['groupid']] = $hg_rows['groupid']; } $hg_groups[] = 0; // to ALL host groups // $hosts_read_only = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_RES_IDS_ARRAY); $hosts_read_write = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_WRITE,PERM_RES_IDS_ARRAY); $hosts_read_only = array_intersect($hosts,$hosts_read_only); $hosts_read_write = array_intersect($hosts,$hosts_read_write); // initialize array foreach($hosts as $id => $hostid){ $scripts_by_host[$hostid] = array(); } //----- $sql = 'SELECT s.* FROM scripts s'. ' WHERE '.DBin_node('s.scriptid'). ' AND '.DBcondition('s.groupid',$hg_groups). ' AND '.DBcondition('s.usrgrpid',$user_groups). ' ORDER BY scriptid ASC'; $res=DBselect($sql); while($script = DBfetch($res)){ $add_to_hosts = array(); if(PERM_READ_WRITE == $script['host_access']){ if($script['groupid'] > 0) $add_to_hosts = array_intersect($hosts_read_write, $hosts_groups[$script['groupid']]); else $add_to_hosts = $hosts_read_write; } else if(PERM_READ_ONLY == $script['host_access']){ if($script['groupid'] > 0) $add_to_hosts = array_intersect($hosts_read_only, $hosts_groups[$script['groupid']]); else $add_to_hosts = $hosts_read_only; } foreach($add_to_hosts as $id => $hostid){ $scripts_by_host[$hostid][] = $script; } } /* */ //SDI($scripts_by_host); return $scripts_by_host; } ?>