function cw_product_generate_sku($ean_type = 0, $field = 'productcode', $prefix = 'PC')
{
    global $tables, $app_main_dir;
    if ($ean_type == 'ean13') {
        $cols = 13;
    } elseif ($ean_type == 'ean8') {
        $cols = 8;
    } else {
        $cols = intval($ean_type);
    }
    do {
        if (empty($cols)) {
            $code = $prefix . cw_core_generate_string(8);
        } else {
            $code = cw_core_generate_string($cols - 1, false);
            if (in_array($ean_type, array('ean13', 'ean8'), true)) {
                include_once $app_main_dir . '/include/barcode/BarCode.php';
                include_once $app_main_dir . '/include/barcode/FColor.php';
                include_once $app_main_dir . '/include/barcode/FDrawing.php';
                include_once $app_main_dir . '/include/barcode/' . $ean_type . '.BarCode.php';
                $code_obj = new $ean_type($code);
                $code = $code_obj->getFull();
            }
        }
        $is_ex = cw_query_first_cell("select count(*) from {$tables['products']} where {$field}='{$code}'");
    } while ($is_ex);
    return $code;
}
function cw_user_generate_password()
{
    return cw_core_generate_string(8);
}
<?php

cw_load('user', 'attributes');
$top_message =& cw_session_register('top_message', array());
$payment_modified_data =& cw_session_register('payment_modified_data', array());
if ($action == 'update' && is_array($posted_data)) {
    foreach ($posted_data as $k => $v) {
        if ($v['del']) {
            cw_call('cw_payment_delete', array($k));
            continue;
        }
        $v['code'] = $edited_language;
        $v['payment_id'] = $k;
        if (strlen($v['payment_code']) < 4) {
            $v['payment_code'] = cw_core_generate_string(4, true);
        }
        cw_array2update('payment_methods', $v, "payment_id='{$k}'", array('payment_code', 'orderby', 'title', 'active'));
    }
    $top_message = array('content' => cw_get_langvar_by_name('msg_adm_payment_methods_upd'), 'type' => 'I');
    cw_header_location("index.php?target={$target}&mode={$mode}");
}
if ($action == 'update_method') {
    $rules = array('payment_code' => '', 'title' => '');
    $posted_data['payment_id'] = $payment_id;
    $posted_data['attributes'] = $attributes;
    $fillerror = cw_error_check($posted_data, $rules, 'G');
    if (!$fillerror) {
        if (is_array($posted_data['payment_operations'])) {
            $posted_data['payment_operations'] = array_sum($posted_data['payment_operations']);
        }
        if (!$payment_id) {