Avoid create agent if no group is selected

This commit is contained in:
fbsanchez 2020-09-29 15:48:20 +02:00
parent 5d63bc547e
commit d73c215b91
3 changed files with 33 additions and 8 deletions

View File

@ -322,7 +322,16 @@ $table_primary_group = '<div class="label_select"><p class="input_label">'.__('P
$table_primary_group .= '<div class="label_select_parent">';
// Cannot change primary group if user have not permission for that group.
if (isset($groups[$grupo]) || $new_agent) {
$table_primary_group .= html_print_select_groups(false, 'AR', false, 'grupo', $grupo, '', '', 0, true);
$table_primary_group .= html_print_input(
[
'type' => 'select_groups',
'returnAllGroup' => false,
'name' => 'grupo',
'selected' => $grupo,
'return' => true,
'required' => true,
]
);
} else {
$table_primary_group .= groups_get_name($grupo);
$table_primary_group .= html_print_input_hidden('grupo', $grupo, true);

View File

@ -193,7 +193,7 @@ if ($create_agent) {
$direccion_agente = io_safe_input($direccion_agente);
$nombre_agente = hash('sha256', $alias.'|'.$direccion_agente.'|'.time().'|'.sprintf('%04d', rand(0, 10000)));
$grupo = (int) get_parameter_post('grupo');
$grupo = get_parameter_post('grupo', null);
$intervalo = (string) get_parameter_post('intervalo', SECONDS_5MINUTES);
$comentarios = (string) get_parameter_post('comentarios', '');
$modo = (int) get_parameter_post('modo');
@ -215,6 +215,13 @@ if ($create_agent) {
$secondary_groups = (string) get_parameter('secondary_hidden', '');
$fields = db_get_all_fields_in_table('tagent_custom_fields');
if ($grupo === null) {
$agent_creation_error = __('No group specified');
$agent_created_ok = 0;
} else {
$grupo = (int) $grupo;
}
if ($fields === false) {
$fields = [];
}
@ -229,7 +236,7 @@ if ($create_agent) {
if ($alias == '') {
$agent_creation_error = __('No agent alias specified');
$agent_created_ok = 0;
} else {
} else if ($agent_created_ok != 0) {
if ($alias_as_name) {
$sql = 'SELECT nombre FROM tagente WHERE nombre = "'.$alias.'"';
$exists_alias = db_get_row_sql($sql);

View File

@ -435,6 +435,7 @@ function html_print_select_style($fields, $name, $selected='', $style='', $scrip
* @param array $include_groups Add groups to select.
* @param string $size Style, size (width) of element.
* @param boolean $simple_multiple_options Discovery simple multiple inputs.
* @param boolean $required Required input.
*
* @return string HTML code if return parameter is true.
*/
@ -460,7 +461,8 @@ function html_print_select_groups(
$delete_groups=false,
$include_groups=false,
$size=false,
$simple_multiple_options=false
$simple_multiple_options=false,
$required=false
) {
$output = '';
@ -528,7 +530,8 @@ function html_print_select_groups(
false,
'',
false,
$simple_multiple_options
$simple_multiple_options,
$required
);
if (empty($size) === true) {
@ -644,7 +647,8 @@ function html_print_select(
$modal=false,
$message='',
$select_all=false,
$simple_multiple_options=false
$simple_multiple_options=false,
$required=false
) {
$output = "\n";
@ -694,7 +698,11 @@ function html_print_select(
$styleText = 'style="'.$style.'"';
}
$output .= '<select id="'.$id.'" name="'.$name.'"'.$attributes.' '.$styleText.'>';
if ($required) {
$required = 'required';
}
$output .= '<select '.$required.' id="'.$id.'" name="'.$name.'"'.$attributes.' '.$styleText.'>';
if ($nothing !== false) {
if ($nothing != '' || empty($fields)) {
@ -4362,7 +4370,8 @@ function html_print_input($data, $wrapper='div', $input_only=false)
((isset($data['delete_groups']) === true) ? $data['delete_groups'] : false),
((isset($data['include_groups']) === true) ? $data['include_groups'] : false),
((isset($data['size']) === true) ? $data['size'] : false),
((isset($data['simple_multiple_options']) === true) ? $data['simple_multiple_options'] : false)
((isset($data['simple_multiple_options']) === true) ? $data['simple_multiple_options'] : false),
((isset($data['required']) === true) ? $data['required'] : false)
);
break;