2013-03-11 Miguel de Dios <miguel.dedios@artica.es>

* godmode/agentes/module_manager_editor_common.php: show only the
	tags that the user has.
	
	Fixes: #3607617
	
	* include/functions_tags.php: cleaned source code style.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7825 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2013-03-11 13:01:42 +00:00
parent 86fb89169f
commit d31783a8ff
3 changed files with 142 additions and 99 deletions

View File

@ -1,3 +1,12 @@
2013-03-11 Miguel de Dios <miguel.dedios@artica.es>
* godmode/agentes/module_manager_editor_common.php: show only the
tags that the user has.
Fixes: #3607617
* include/functions_tags.php: cleaned source code style.
2013-03-11 Kikuchi Koichiro <koichiro@rworks.jp> 2013-03-11 Kikuchi Koichiro <koichiro@rworks.jp>
* extensions/update_manager/lib/libupdate_manager_client.php, * extensions/update_manager/lib/libupdate_manager_client.php,

View File

@ -348,7 +348,8 @@ else {
$__id = $__id_pol_mod; $__id = $__id_pol_mod;
} }
$table_advanced->data[6][1] = html_print_select_from_sql ( if (!tags_has_user_acl_tags($config["id_user"])) {
$table_advanced->data[6][1] = html_print_select_from_sql (
"SELECT id_tag, name "SELECT id_tag, name
FROM ttag FROM ttag
WHERE id_tag NOT IN ( WHERE id_tag NOT IN (
@ -357,6 +358,35 @@ $table_advanced->data[6][1] = html_print_select_from_sql (
WHERE a.id_tag = b.id_tag AND $__id_where = $__id ) WHERE a.id_tag = b.id_tag AND $__id_where = $__id )
ORDER BY name", 'id_tag_available[]', '', '','','', ORDER BY name", 'id_tag_available[]', '', '','','',
true, true, false, false, 'width: 200px', '5'); true, true, false, false, 'width: 200px', '5');
}
else {
$user_tags = tags_get_user_tags($config["id_user"], "AW");
if (!empty($user_tags)) {
$id_user_tags = array_keys($user_tags);
$table_advanced->data[6][1] = html_print_select_from_sql (
"SELECT id_tag, name
FROM ttag
WHERE id_tag IN (" . implode(',', $id_user_tags) . ") AND
id_tag NOT IN (
SELECT a.id_tag
FROM ttag a, $__table_modules b
WHERE a.id_tag = b.id_tag AND $__id_where = $__id )
ORDER BY name", 'id_tag_available[]', '', '','','',
true, true, false, false, 'width: 200px', '5');
}
else {
$table_advanced->data[6][1] = html_print_select_from_sql (
"SELECT id_tag, name
FROM ttag
WHERE id_tag NOT IN (
SELECT a.id_tag
FROM ttag a, $__table_modules b
WHERE a.id_tag = b.id_tag AND $__id_where = $__id )
ORDER BY name", 'id_tag_available[]', '', '','','',
true, true, false, false, 'width: 200px', '5');
}
}
$table_advanced->data[6][2] = html_print_image('images/darrowright.png', true, array('id' => 'right', 'title' => __('Add tags to module'))); //html_print_input_image ('add', 'images/darrowright.png', 1, '', true, array ('title' => __('Add tags to module'))); $table_advanced->data[6][2] = html_print_image('images/darrowright.png', true, array('id' => 'right', 'title' => __('Add tags to module'))); //html_print_input_image ('add', 'images/darrowright.png', 1, '', true, array ('title' => __('Add tags to module')));
$table_advanced->data[6][2] .= '<br><br><br><br>' . html_print_image('images/darrowleft.png', true, array('id' => 'left', 'title' => __('Delete tags to module'))); //html_print_input_image ('add', 'images/darrowleft.png', 1, '', true, array ('title' => __('Delete tags to module'))); $table_advanced->data[6][2] .= '<br><br><br><br>' . html_print_image('images/darrowleft.png', true, array('id' => 'left', 'title' => __('Delete tags to module'))); //html_print_input_image ('add', 'images/darrowleft.png', 1, '', true, array ('title' => __('Delete tags to module')));

View File

@ -28,7 +28,8 @@
*/ */
function tags_agent_critical ($id_tag) { function tags_agent_critical ($id_tag) {
return db_get_sql ("SELECT COUNT(*) FROM tagente, tagente_modulo, ttag_module return db_get_sql ("SELECT COUNT(*)
FROM tagente, tagente_modulo, ttag_module
WHERE tagente.id_agente = tagente_modulo.id_agente WHERE tagente.id_agente = tagente_modulo.id_agente
AND tagente.disabled=0 AND tagente.disabled=0
AND tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo AND tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo
@ -45,7 +46,8 @@ function tags_agent_critical ($id_tag) {
*/ */
function tags_agent_unknown ($id_tag) { function tags_agent_unknown ($id_tag) {
return db_get_sql ("SELECT COUNT(*) FROM tagente, tagente_modulo, ttag_module return db_get_sql ("SELECT COUNT(*)
FROM tagente, tagente_modulo, ttag_module
WHERE tagente.id_agente = tagente_modulo.id_agente WHERE tagente.id_agente = tagente_modulo.id_agente
AND tagente.disabled=0 AND tagente.disabled=0
AND tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo AND tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo
@ -84,7 +86,8 @@ function tags_total_agents ($id_tag) {
*/ */
function tags_agent_ok ($id_tag) { function tags_agent_ok ($id_tag) {
return db_get_sql ("SELECT COUNT(*) FROM tagente, tagente_modulo, ttag_module return db_get_sql ("SELECT COUNT(*)
FROM tagente, tagente_modulo, ttag_module
WHERE tagente.id_agente = tagente_modulo.id_agente WHERE tagente.id_agente = tagente_modulo.id_agente
AND tagente.disabled=0 AND tagente.disabled=0
AND tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo AND tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo
@ -101,7 +104,8 @@ function tags_agent_ok ($id_tag) {
*/ */
function tags_agent_warning ($id_tag) { function tags_agent_warning ($id_tag) {
return db_get_sql ("SELECT COUNT(*) FROM tagente, tagente_modulo, ttag_module return db_get_sql ("SELECT COUNT(*)
FROM tagente, tagente_modulo, ttag_module
WHERE tagente.id_agente = tagente_modulo.id_agente WHERE tagente.id_agente = tagente_modulo.id_agente
AND tagente.disabled=0 AND tagente.disabled=0
AND tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo AND tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo
@ -143,7 +147,7 @@ function tags_search_tag ($tag_name_description = false, $filter = false, $only_
break; break;
} }
} }
else{ else {
$sql = 'SELECT * FROM ttag'; $sql = 'SELECT * FROM ttag';
} }
if ($filter !== false) { if ($filter !== false) {
@ -190,7 +194,7 @@ function tags_search_tag ($tag_name_description = false, $filter = false, $only_
* @return mixed Tag id or false. * @return mixed Tag id or false.
*/ */
function tags_create_tag($values) { function tags_create_tag($values) {
if (empty($values)){ if (empty($values)) {
return false; return false;
} }
@ -215,7 +219,7 @@ function tags_search_tag_id($id) {
* *
* @return mixed String with tag name or false. * @return mixed String with tag name or false.
*/ */
function tags_get_name($id){ function tags_get_name($id) {
return db_get_value_filter ('name', 'ttag', array('id_tag' => $id)); return db_get_value_filter ('name', 'ttag', array('id_tag' => $id));
} }
@ -226,7 +230,7 @@ function tags_get_name($id){
* *
* @return int Tag id. * @return int Tag id.
*/ */
function tags_get_id($name){ function tags_get_id($name) {
return db_get_value_filter ('id_tag', 'ttag', array('name' => $name)); return db_get_value_filter ('id_tag', 'ttag', array('name' => $name));
} }
@ -237,7 +241,7 @@ function tags_get_id($name){
* *
* @return mixed String with tag description or false. * @return mixed String with tag description or false.
*/ */
function tags_get_description($id){ function tags_get_description($id) {
return db_get_value_filter('description', 'ttag', array('id_tag' => $id)); return db_get_value_filter('description', 'ttag', array('id_tag' => $id));
} }
@ -248,7 +252,7 @@ function tags_get_description($id){
* *
* @return mixed String with tag url or false. * @return mixed String with tag url or false.
*/ */
function tags_get_url($id){ function tags_get_url($id) {
return db_get_value_filter('description', 'ttag', array('id_tag' => $id)); return db_get_value_filter('description', 'ttag', array('id_tag' => $id));
} }
@ -259,7 +263,7 @@ function tags_get_url($id){
* *
* @return mixed Int with the tag's count or false. * @return mixed Int with the tag's count or false.
*/ */
function tags_get_modules_count($id){ function tags_get_modules_count($id) {
$num_modules = (int)db_get_value_filter('count(*)', 'ttag_module', array('id_tag' => $id)); $num_modules = (int)db_get_value_filter('count(*)', 'ttag_module', array('id_tag' => $id));
$num_policy_modules = (int)db_get_value_filter('count(*)', 'ttag_policy_module', array('id_tag' => $id)); $num_policy_modules = (int)db_get_value_filter('count(*)', 'ttag_policy_module', array('id_tag' => $id));
@ -273,7 +277,7 @@ function tags_get_modules_count($id){
* *
* @return mixed Int with the tag's count or false. * @return mixed Int with the tag's count or false.
*/ */
function tags_get_local_modules_count($id){ function tags_get_local_modules_count($id) {
$num_modules = (int)db_get_value_filter('count(*)', 'ttag_module', array('id_tag' => $id)); $num_modules = (int)db_get_value_filter('count(*)', 'ttag_module', array('id_tag' => $id));
return $num_modules; return $num_modules;
@ -286,7 +290,7 @@ function tags_get_local_modules_count($id){
* *
* @return mixed Int with the tag's count or false. * @return mixed Int with the tag's count or false.
*/ */
function tags_get_modules_tag_count($id){ function tags_get_modules_tag_count($id) {
$num_modules = (int)db_get_value_filter('count(*)', 'ttag_module', array('id_agente_modulo' => $id)); $num_modules = (int)db_get_value_filter('count(*)', 'ttag_module', array('id_agente_modulo' => $id));
return $num_modules; return $num_modules;
@ -299,7 +303,7 @@ function tags_get_modules_tag_count($id){
* *
* @return mixed Int with the tag's count or false. * @return mixed Int with the tag's count or false.
*/ */
function tags_get_policy_modules_count($id){ function tags_get_policy_modules_count($id) {
$num_policy_modules = (int)db_get_value_filter('count(*)', 'ttag_policy_module', array('id_tag' => $id)); $num_policy_modules = (int)db_get_value_filter('count(*)', 'ttag_policy_module', array('id_tag' => $id));
return $num_policy_modules; return $num_policy_modules;
@ -315,7 +319,7 @@ function tags_get_policy_modules_count($id){
* *
* @return bool True or false if something goes wrong. * @return bool True or false if something goes wrong.
*/ */
function tags_update_tag($values, $where){ function tags_update_tag($values, $where) {
return db_process_sql_update ('ttag', $values, $where); return db_process_sql_update ('ttag', $values, $where);
} }
@ -326,7 +330,7 @@ function tags_update_tag($values, $where){
* *
* @return bool True or false if something goes wrong. * @return bool True or false if something goes wrong.
*/ */
function tags_delete_tag ($id_tag){ function tags_delete_tag ($id_tag) {
$errn = 0; $errn = 0;
$result_tag = db_process_delete_temp ('ttag', 'id_tag', $id_tag); $result_tag = db_process_delete_temp ('ttag', 'id_tag', $id_tag);
@ -341,11 +345,11 @@ function tags_delete_tag ($id_tag){
if ($result_policy === false) if ($result_policy === false)
$errn++; $errn++;
if ($errn == 0){ if ($errn == 0) {
db_process_sql_commit(); db_process_sql_commit();
return true; return true;
} }
else{ else {
db_process_sql_rollback(); db_process_sql_rollback();
return false; return false;
} }
@ -357,7 +361,7 @@ function tags_delete_tag ($id_tag){
* *
* @return mixed Int with the tag's count. * @return mixed Int with the tag's count.
*/ */
function tags_get_tag_count(){ function tags_get_tag_count() {
return (int)db_get_value('count(*)', 'ttag'); return (int)db_get_value('count(*)', 'ttag');
} }
@ -369,7 +373,7 @@ function tags_get_tag_count(){
* *
* @return bool True or false if something goes wrong. * @return bool True or false if something goes wrong.
*/ */
function tags_insert_module_tag ($id_agent_module, $tags){ function tags_insert_module_tag ($id_agent_module, $tags) {
$errn = 0; $errn = 0;
$values = array(); $values = array();
@ -378,7 +382,7 @@ function tags_insert_module_tag ($id_agent_module, $tags){
$tags = array(); $tags = array();
} }
foreach ($tags as $tag){ foreach ($tags as $tag) {
//Protect against default insert //Protect against default insert
if (empty($tag)) if (empty($tag))
continue; continue;
@ -390,7 +394,7 @@ function tags_insert_module_tag ($id_agent_module, $tags){
$errn++; $errn++;
} }
/* if ($errn > 0){ /* if ($errn > 0) {
db_process_sql_rollback(); db_process_sql_rollback();
return false; return false;
} }
@ -408,13 +412,13 @@ function tags_insert_module_tag ($id_agent_module, $tags){
* *
* @return bool True or false if something goes wrong. * @return bool True or false if something goes wrong.
*/ */
function tags_insert_policy_module_tag ($id_agent_module, $tags){ function tags_insert_policy_module_tag ($id_agent_module, $tags) {
$errn = 0; $errn = 0;
db_process_sql_begin(); db_process_sql_begin();
$values = array(); $values = array();
foreach ($tags as $tag){ foreach ($tags as $tag) {
//Protect against default insert //Protect against default insert
if (empty($tag)) if (empty($tag))
continue; continue;
@ -426,11 +430,11 @@ function tags_insert_policy_module_tag ($id_agent_module, $tags){
$errn++; $errn++;
} }
if ($errn > 0){ if ($errn > 0) {
db_process_sql_rollback(); db_process_sql_rollback();
return false; return false;
} }
else{ else {
db_process_sql_commit(); db_process_sql_commit();
return true; return true;
} }
@ -445,7 +449,7 @@ function tags_insert_policy_module_tag ($id_agent_module, $tags){
* *
* @return bool True or false if something goes wrong. * @return bool True or false if something goes wrong.
*/ */
function tags_update_module_tag ($id_agent_module, $tags, $autocommit = false){ function tags_update_module_tag ($id_agent_module, $tags, $autocommit = false) {
$errn = 0; $errn = 0;
if (empty($tags)) if (empty($tags))
@ -455,7 +459,7 @@ function tags_update_module_tag ($id_agent_module, $tags, $autocommit = false){
$result_tag = db_process_sql_delete ('ttag_module', array('id_agente_modulo' => $id_agent_module)); $result_tag = db_process_sql_delete ('ttag_module', array('id_agente_modulo' => $id_agent_module));
$values = array(); $values = array();
foreach ($tags as $tag){ foreach ($tags as $tag) {
//Protect against default insert //Protect against default insert
if (empty($tag)) if (empty($tag))
continue; continue;
@ -478,7 +482,7 @@ function tags_update_module_tag ($id_agent_module, $tags, $autocommit = false){
* *
* @return bool True or false if something goes wrong. * @return bool True or false if something goes wrong.
*/ */
function tags_update_policy_module_tag ($id_policy_module, $tags, $autocommit = false){ function tags_update_policy_module_tag ($id_policy_module, $tags, $autocommit = false) {
$errn = 0; $errn = 0;
if (empty($tags)) if (empty($tags))
@ -509,7 +513,7 @@ function tags_update_policy_module_tag ($id_policy_module, $tags, $autocommit =
* *
* @return mixed Array with module tags or false if something goes wrong. * @return mixed Array with module tags or false if something goes wrong.
*/ */
function tags_get_module_tags ($id_agent_module){ function tags_get_module_tags ($id_agent_module) {
if (empty($id_agent_module)) if (empty($id_agent_module))
return false; return false;
@ -519,7 +523,7 @@ function tags_get_module_tags ($id_agent_module){
return array(); return array();
$return = array(); $return = array();
foreach ($tags as $tag){ foreach ($tags as $tag) {
$return[] = $tag['id_tag']; $return[] = $tag['id_tag'];
} }
@ -533,7 +537,7 @@ function tags_get_module_tags ($id_agent_module){
* *
* @return mixed Array with module tags or false if something goes wrong. * @return mixed Array with module tags or false if something goes wrong.
*/ */
function tags_get_policy_module_tags ($id_policy_module){ function tags_get_policy_module_tags ($id_policy_module) {
if (empty($id_policy_module)) if (empty($id_policy_module))
return false; return false;
@ -543,7 +547,7 @@ function tags_get_policy_module_tags ($id_policy_module){
return false; return false;
$return = array(); $return = array();
foreach ($tags as $tag){ foreach ($tags as $tag) {
$return[] = $tag['id_tag']; $return[] = $tag['id_tag'];
} }
@ -915,7 +919,7 @@ function tags_get_user_tags($id_user = false, $access = 'AR') {
$profiles_without_tags = db_get_value_sql($query); $profiles_without_tags = db_get_value_sql($query);
if($profiles_without_tags > 0) { if ($profiles_without_tags > 0) {
return $all_tags; return $all_tags;
} }