2012-10-26 Miguel de Dios <miguel.dedios@artica.es>

* include/functions_api.php: fixed the function
	"api_set_apply_all_policies".
	
	Fixes: #3576289
	
	* include/functions.php, include/functions_filemanager.php: cleaned
	source code style.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7099 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2012-10-26 17:37:57 +00:00
parent 4c16ac1d13
commit 16324125b9
4 changed files with 69 additions and 59 deletions

View File

@ -1,3 +1,13 @@
2012-10-26 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_api.php: fixed the function
"api_set_apply_all_policies".
Fixes: #3576289
* include/functions.php, include/functions_filemanager.php: cleaned
source code style.
2012-10-26 Ramon Novoa <rnovoa@artica.es> 2012-10-26 Ramon Novoa <rnovoa@artica.es>
* include/functions_reporting.php, * include/functions_reporting.php,

View File

@ -1630,4 +1630,4 @@ function copy_dir($src, $dst) {
} }
closedir($dir); closedir($dir);
} }
?> ?>

View File

@ -807,7 +807,7 @@ function api_get_all_agents($thrash1, $thrash2, $other, $thrash3) {
} }
if (isset($other['data'][3])) { if (isset($other['data'][3])) {
// Filter by name // Filter by name
if ($other['data'][3] != ""){ if ($other['data'][3] != "") {
$where .= " AND nombre LIKE ('%" . $other['data'][3] . "%')"; $where .= " AND nombre LIKE ('%" . $other['data'][3] . "%')";
} }
} }
@ -2742,45 +2742,44 @@ function api_set_stop_downtime($id, $thrash1, $other, $thrash3) {
* @param $thrash3 Don't use * @param $thrash3 Don't use
*/ */
function api_set_add_agent_policy($id, $thrash1, $other, $thrash3) { function api_set_add_agent_policy($id, $thrash1, $other, $thrash3) {
if ($id == ""){ if ($id == "") {
returnError('error_add_agent_policy', __('Error adding agent to policy. Id_policy cannot be left blank.')); returnError('error_add_agent_policy', __('Error adding agent to policy. Id_policy cannot be left blank.'));
return; return;
} }
if ($other['data'][0] == ""){ if ($other['data'][0] == "") {
returnError('error_add_agent_policy', __('Error adding agent to policy. Id_agent cannot be left blank.')); returnError('error_add_agent_policy', __('Error adding agent to policy. Id_agent cannot be left blank.'));
return; return;
} }
// Check if the agent exists // Check if the agent exists
$result_agent = db_get_value ('id_agente', 'tagente', 'id_agente', (int) $other['data'][0]); $result_agent = db_get_value ('id_agente', 'tagente', 'id_agente', (int) $other['data'][0]);
if (!$result_agent){ if (!$result_agent) {
returnError('error_add_agent_policy', __('Error adding agent to policy. Id_agent doesn\'t exists.')); returnError('error_add_agent_policy', __('Error adding agent to policy. Id_agent doesn\'t exists.'));
return; return;
} }
// Check if the agent is already in the policy // Check if the agent is already in the policy
$id_agent_policy = enterprise_hook('policies_get_agents', array($id, array('id_agent' => $other['data'][0]), 'id')); $id_agent_policy = enterprise_hook('policies_get_agents', array($id, array('id_agent' => $other['data'][0]), 'id'));
if ($id_agent_policy === ENTERPRISE_NOT_HOOK) { if ($id_agent_policy === ENTERPRISE_NOT_HOOK) {
returnError('error_add_agent_policy', __('Error adding agent to policy.')); returnError('error_add_agent_policy', __('Error adding agent to policy.'));
return; return;
} }
if ($id_agent_policy === false){ if ($id_agent_policy === false) {
$success = enterprise_hook('policies_create_agent', array($other['data'][0], $id, true)); $success = enterprise_hook('policies_create_agent', array($other['data'][0], $id, true));
} }
else { else {
returnError('error_add_agent_policy', __('Error adding agent to policy. The agent is already in the policy.')); returnError('error_add_agent_policy', __('Error adding agent to policy. The agent is already in the policy.'));
return; return;
} }
if ($success) if ($success)
returnData('string', array('type' => 'string', 'data' => $success)); returnData('string', array('type' => 'string', 'data' => $success));
else else
returnError('error_add_agent_policy', 'Error adding agent to policy.'); returnError('error_add_agent_policy', 'Error adding agent to policy.');
} }
/** /**
@ -3575,11 +3574,11 @@ function api_set_update_snmp_module_policy($id, $thrash1, $other, $thrash3) {
* @param $thrash3 Don't use * @param $thrash3 Don't use
*/ */
function api_set_apply_policy($id, $thrash1, $other, $thrash3) { function api_set_apply_policy($id, $thrash1, $other, $thrash3) {
if ($id == ""){ if ($id == "") {
returnError('error_apply_policy', __('Error applying policy. Id_policy cannot be left blank.')); returnError('error_apply_policy', __('Error applying policy. Id_policy cannot be left blank.'));
return; return;
} }
# Check if this operation is duplicated # Check if this operation is duplicated
$duplicated = enterprise_hook('policies_get_policy_queue_status', array($id)); $duplicated = enterprise_hook('policies_get_policy_queue_status', array($id));
@ -3591,20 +3590,20 @@ function api_set_apply_policy($id, $thrash1, $other, $thrash3) {
else { else {
returnError('error_apply_policy', __('Error applying policy.')); returnError('error_apply_policy', __('Error applying policy.'));
return; return;
} }
} }
if ($duplicated == STATUS_IN_QUEUE_APPLYING or $duplicated == STATUS_IN_QUEUE_IN){ if ($duplicated == STATUS_IN_QUEUE_APPLYING or $duplicated == STATUS_IN_QUEUE_IN){
// We want to return a value // We want to return a value
if ($other == "return") { if ($other == "return") {
return -1; return -1;
} }
else { else {
returnError('error_apply_policy', __('Error applying policy. This policy is already pending to apply.')); returnError('error_apply_policy', __('Error applying policy. This policy is already pending to apply.'));
return; return;
} }
} }
$id = enterprise_hook('add_policy_queue_operation', array($id, 0, 'apply')); $id = enterprise_hook('add_policy_queue_operation', array($id, 0, 'apply'));
if ($id === ENTERPRISE_NOT_HOOK) { if ($id === ENTERPRISE_NOT_HOOK) {
@ -3612,24 +3611,24 @@ function api_set_apply_policy($id, $thrash1, $other, $thrash3) {
if ($other == "return") { if ($other == "return") {
return -1; return -1;
} }
else { else {
returnError('error_apply_policy', __('Error applying policy.')); returnError('error_apply_policy', __('Error applying policy.'));
return; return;
} }
} }
// We want to return a value // We want to return a value
if ($other == "return") { if ($other == "return") {
if ($id) if ($id)
return $id; return $id;
else else
return -1; return -1;
} }
else { else {
if ($id) if ($id)
returnData('string', array('type' => 'string', 'data' => $id)); returnData('string', array('type' => 'string', 'data' => $id));
else else
returnError('error_apply_policy', 'Error applying policy.'); returnError('error_apply_policy', 'Error applying policy.');
} }
} }
@ -3647,35 +3646,36 @@ function api_set_apply_policy($id, $thrash1, $other, $thrash3) {
* *
* @param $thrash3 Don't use * @param $thrash3 Don't use
*/ */
function api_set_apply_all_policies($id, $thrash1, $other, $thrash3) { function api_set_apply_all_policies($thrash1, $thrash2, $other, $thrash3) {
$policies = array(); $policies = array();
# Get all policies # Get all policies
$policies = enterprise_hook('policies_get_policies', array(false, false, false, true)); $policies = enterprise_hook('policies_get_policies', array(false, false, false, true));
if ($duplicated === ENTERPRISE_NOT_HOOK) { if ($policies === ENTERPRISE_NOT_HOOK) {
returnError('error_apply_all_policy', __('Error applying all policies.')); returnError('error_apply_all_policy', __('Error applying all policies.'));
return; return;
} }
$num_policies = count($policies); $num_policies = count($policies);
$count_results = 0; $count_results = 0;
foreach ($policies as $policy){ foreach ($policies as $policy) {
$return_value = set_apply_policy($policy['id'], '', 'return', ''); $return_value = enterprise_hook('add_policy_queue_operation',
array($policy['id'], 0, 'apply'));
if ($return_value != -1){
if ($return_value != -1) {
$count_results++; $count_results++;
} }
} }
if ($num_policies > $count_results){ if ($num_policies > $count_results) {
$errors = $num_policies - $count_results; $errors = $num_policies - $count_results;
returnError('error_apply_policy', 'Error applying policy. ' . $errors . ' failed. '); returnError('error_apply_policy', 'Error applying policy. ' . $errors . ' failed. ');
} }
else { else {
returnData('string', array('type' => 'string', 'data' => $count_results)); returnData('string', array('type' => 'string', 'data' => $count_results));
} }
} }
/** /**
@ -3700,26 +3700,26 @@ function api_set_apply_all_policies($id, $thrash1, $other, $thrash3) {
function api_set_create_group($id, $thrash1, $other, $thrash3) { function api_set_create_group($id, $thrash1, $other, $thrash3) {
$group_name = $id; $group_name = $id;
if ($id == ""){ if ($id == "") {
returnError('error_create_group', __('Error in group creation. Group_name cannot be left blank.')); returnError('error_create_group', __('Error in group creation. Group_name cannot be left blank.'));
return; return;
} }
if ($other['data'][0] == ""){ if ($other['data'][0] == "") {
returnError('error_create_group', __('Error in group creation. Icon_name cannot be left blank.')); returnError('error_create_group', __('Error in group creation. Icon_name cannot be left blank.'));
return; return;
} }
if ($other['data'][1] != ""){ if ($other['data'][1] != "") {
$group = groups_get_group_by_id($other['data'][1]); $group = groups_get_group_by_id($other['data'][1]);
if ($group == false){ if ($group == false) {
returnError('error_create_group', __('Error in group creation. Id_parent_group doesn\'t exists.')); returnError('error_create_group', __('Error in group creation. Id_parent_group doesn\'t exists.'));
return; return;
} }
} }
if ($other['data'][1] != ""){ if ($other['data'][1] != "") {
$values = array( $values = array(
'icon' => $other['data'][0], 'icon' => $other['data'][0],
'parent' => $other['data'][1] 'parent' => $other['data'][1]
@ -3727,9 +3727,9 @@ function api_set_create_group($id, $thrash1, $other, $thrash3) {
} }
else { else {
$values = array( $values = array(
'icon' => $other['data'][0] 'icon' => $other['data'][0]
); );
} }
$id_group = groups_create_group($group_name, $values); $id_group = groups_create_group($group_name, $values);

View File

@ -545,7 +545,7 @@ function filemanager_file_explorer($real_directory, $relative_directory, $url, $
$table->data[1][1] .= html_print_input_hidden('hash', md5($real_directory . $relative_directory . $config['dbpass']), true); $table->data[1][1] .= html_print_input_hidden('hash', md5($real_directory . $relative_directory . $config['dbpass']), true);
$table->data[1][1] .= html_print_input_hidden('hash2', md5($relative_directory . $config['dbpass']), true); $table->data[1][1] .= html_print_input_hidden('hash2', md5($relative_directory . $config['dbpass']), true);
$table->data[1][1] .= html_print_input_hidden ('upload_file_or_zip', 1, true); $table->data[1][1] .= html_print_input_hidden ('upload_file_or_zip', 1, true);
$table->data[1][1] .= '</form>'; $table->data[1][1] .= '</form>';
$table->data[1][1] .= '</div>'; $table->data[1][1] .= '</div>';
$table->data[1][1] .= '<div id="create_text_file" style="display: none;">'; $table->data[1][1] .= '<div id="create_text_file" style="display: none;">';
@ -690,7 +690,7 @@ function filemanager_box_upload_file_complex($real_directory, $relative_director
echo '<form method="post" action="' . $url . '" enctype="multipart/form-data">'; echo '<form method="post" action="' . $url . '" enctype="multipart/form-data">';
html_print_table ($table); html_print_table ($table);
echo '</form>'; echo '</form>';
} }
/** /**