foreach ($clean_url_delete_data as $clean_url_data => $_v) {
         list($attribute_id, $item_id) = explode("_", $clean_url_data);
         db_query("\n                DELETE FROM {$tables['attributes_values']}\n                WHERE item_id = '{$item_id}' AND attribute_id = '{$attribute_id}' AND code = '{$language}'\n                    AND (item_type = 'O' OR item_type = 'OS')\n            ");
     }
     $top_message = array('content' => cw_get_langvar_by_name('txt_redirect_rule_deleted'), 'type' => 'I');
 }
 // add owner clean url
 if ($action == "add" && !empty($clean_urls_add_data)) {
     if (!empty($clean_urls_add_data['dinamic_url']) && trim($clean_urls_add_data['dinamic_url']) != 'search' && !empty($clean_urls_add_data['static_url'])) {
         $dinamic_url = cw_clean_url_adjust($clean_urls_add_data['dinamic_url']);
         $static_url = trim($clean_urls_add_data['static_url'], '\\ /');
         $language = !empty($current_language) ? $current_language : $config['default_customer_language'];
         $attribute_id = cw_query_first_cell("\n                SELECT attribute_id FROM {$tables['attributes']} WHERE field='clean_url' AND item_type = 'O'\n            ");
         $item_id = cw_query_first_cell("\n                SELECT MAX(item_id) FROM {$tables['attributes_values']} WHERE attribute_id='{$attribute_id}' AND item_type = 'O'\n            ") + 1;
         $params = array('item_id' => $item_id, 'item_type' => "O", 'attribute_id' => $attribute_id, 'code' => $language);
         $params['value'] = cw_clean_url_check_and_generate($dinamic_url, $params, $language);
         cw_array2insert('attributes_values', $params);
         $params['item_type'] = "OS";
         $params['value'] = $static_url;
         cw_array2insert('attributes_values', $params);
         $top_message = array('content' => cw_get_langvar_by_name('txt_new_redirect_rule_added'), 'type' => 'I');
     } else {
         $top_message = array('content' => cw_get_langvar_by_name('txt_error_new_redirect_rule_added'), 'type' => 'W');
     }
 }
 // reset filter
 if ($action == "reset") {
     $clean_urls_data = array();
 }
 // filter
 $where = "";
function cw_clean_url_attributes_save($item_id, $item_type, $attributes, $language = null, $extra = array())
{
    global $tables, $current_language, $config;
    # kornev, we don't need this function if the clean url is not in the return - because it's partial update in this case
    # kornev, and we will re-generate the url wrongly
    if (!isset($attributes['clean_url'])) {
        return null;
    }
    $language = !empty($current_language) ? $current_language : $config['default_customer_language'];
    $fields = array('P' => array('field' => 'product', 'table' => $tables['products'], 'key' => 'product_id'), 'C' => array('field' => 'category', 'table' => $tables['categories'], 'key' => 'category_id'), 'M' => array('field' => 'manufacturer', 'table' => $tables['manufacturers'], 'key' => 'manufacturer_id'), 'AB' => array('field' => 'name', 'table' => $tables['cms'], 'key' => 'contentsection_id'));
    if (!$fields[$item_type]) {
        return null;
    }
    $clean_url = trim($attributes['clean_url']);
    if (!$clean_url) {
        $tp = $fields[$item_type];
        $clean_url = cw_clean_url_adjust(cw_query_first_cell("select {$tp['field']} from {$tp['table']} where {$tp['key']} = '{$item_id}'"));
    }
    $att = cw_call('cw_attributes_filter', array(array('addon' => 'clean_urls', 'item_type' => $item_type, 'field' => 'clean_url'), true));
    $params = array('attribute_id' => $att['attribute_id'], 'item_type' => $item_type, 'item_id' => $item_id);
    $attributes['clean_url'] = cw_clean_url_check_and_generate($clean_url, $params, $language);
    // replace $attributes['clean_url'] in input params
    return new EventReturn($attributes, array($item_id, $item_type, $attributes, $language, $extra));
}