function save_filter($conn, $filters, $data) { //Getting the number of filters to be applied of the group $cont = $filters->get_num_filter_added(); //We need at least one, otherwise we show an error. if ($cont < 1) { $return['error'] = TRUE; $return['msg'] = _('At least one filter needed'); return $return; } $name = utf8_decode($data['name']); $descr = utf8_decode($data['descr']); ossim_valid($name, OSS_NOECHARS, OSS_ALPHA, OSS_PUNC, 'illegal:' . _('Group Name')); ossim_valid($descr, OSS_ALPHA, OSS_NULLABLE, OSS_PUNC, OSS_AT, OSS_NL, 'illegal:' . _('Description')); if (ossim_error()) { $response['error'] = TRUE; $response['msg'] = ossim_get_error(); ossim_clean_error(); return $response; } //Trying to save the filters, in case of error an exception will arise try { $new_id = Util::uuid(); $ctx = Session::get_default_ctx(); $group = new Asset_group($new_id); $group->set_name($name); $group->set_descr($descr); $group->set_ctx($ctx); $group->save_in_db($conn); $group->save_assets_from_search($conn); $filters->empty_filter_search($conn); $return['error'] = FALSE; $return['id'] = $new_id; $return['msg'] = 'ok'; Asset_filter_list::delete_filters_from_session(); } catch (Exception $e) { $return['error'] = TRUE; $return['msg'] = $e->getMessage(); } return $return; }
} catch (Exception $e) { Util::response_bad_request(_('Error! Asset group could not be deleted') . ': ' . $e->getMessage()); } } break; case 'add_new_assets': $group_id = POST('asset_id'); if (!valid_hex32($group_id)) { Util::response_bad_request(_('Error! Asset group ID not allowed. Selected assets could not be added')); } else { try { $db = new ossim_db(); $conn = $db->connect(); $num_assets = Filter_list::get_total_selection($conn, 'asset'); $asset_group = new Asset_group($group_id); $asset_group->save_assets_from_search($conn); $db->close(); $data['status'] = 'success'; $data['data'] = sprintf(_("%s assets have been added to group"), $num_assets); } catch (Exception $e) { Util::response_bad_request(_('Error! Selected assets could not be added') . ': ' . $e->getMessage()); } } break; case 'delete_assets': $group_id = POST('asset_id'); if (!valid_hex32($group_id)) { Util::response_bad_request(_('Error! Asset group ID not allowed. Selected assets could not be removed')); } else { try { $db = new ossim_db();