}
    if ($sort_direction != "") {
        if (!empty($orderby)) {
            $orderby .= $sort_direction ? " ASC" : " DESC";
        }
        $smarty->assign('h_sort_direction', abs($sort_direction - 1));
    }
    $clean_urls_history_list = cw_clean_url_get_clean_urls_history_list_data($orderby);
    $smarty->assign('clean_urls_history_list', $clean_urls_history_list);
} else {
    $page = !empty($page) ? $page : 1;
    // edit clean url
    if ($action == "edit") {
        if (!empty($new_url) && !empty($attribute_id) && !empty($item_id) && !empty($item_type)) {
            $language = !empty($current_language) ? $current_language : $config['default_customer_language'];
            $result = cw_clean_url_check_url_and_save_value($new_url, $item_id, $item_type, $attribute_id, $language);
            exit($result);
        }
        exit("");
    }
    // delete owner clean url
    if ($action == "delete" && !empty($clean_url_delete_data)) {
        $language = !empty($current_language) ? $current_language : $config['default_customer_language'];
        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)) {
function cw_clean_url_attributes_save_attribute($params, $return)
{
    global $tables, $current_language, $config;
    $productid = $params['item_id'];
    $item_type = $params['item_type'];
    $attributes = $params['attributes'];
    if (empty($productid) || $item_type != 'P' || empty($attributes)) {
        return $return;
    }
    $clean_url_attribute = cw_call('cw_attributes_filter', array(array('field' => 'clean_url', 'item_type' => clean_urls_attributes_values_item_type), true));
    $clean_url_attribute_id = $clean_url_attribute['attribute_id'];
    if (is_array($attributes) && $clean_url_attribute_id) {
        $language = !empty($current_language) ? $current_language : $config['default_customer_language'];
        foreach ($attributes as $field => $values) {
            $attribute = cw_call('cw_attributes_filter', array(array('field' => $field, 'item_type' => 'P'), true));
            if (!$attribute) {
                continue;
            }
            $attribute_id = $attribute['attribute_id'];
            $attribute_type = $attribute['type'];
            $attribute_name = $attribute['name'];
            if (!in_array($attribute_type, array("text", "textarea", "selectbox", "multiple_selectbox"))) {
                continue;
            }
            if (!is_array($values)) {
                $values = array($values);
            }
            foreach ($values as $attribute_value_id) {
                $attribute_default_value = cw_query_first_cell("SELECT value FROM {$tables['attributes_default']}\n                    WHERE attribute_id = '{$attribute_id}' AND attribute_value_id = '{$attribute_value_id}' AND active = 1");
                if (!empty($attribute_default_value)) {
                    cw_clean_url_check_url_and_save_value($attribute_name . '-' . $attribute_default_value, $attribute_value_id, clean_urls_attributes_values_item_type, $clean_url_attribute_id, $language);
                }
            }
        }
    }
    return $return;
}