function cw_import_esprinet_get_product_info($cookie, $list_page)
{
    $products = array();
    preg_match('/<!--Filtra-->(.*)<\\/body>/ims', $list_page, $area_parse);
    preg_match_all('/<a.*onClick="window\\.open\\(\'(.*)\'.*\\).*<strong>.*Codice:.*<\\/strong>(.*)<br><a href="(.*)">(.*)<\\/a><\\/td>.*<td.*><a href="(.*)" target="_self"><img src="\\/iPriOper\\/.*".*><\\/a>.*<\\/td>.*<td colspan="16".*>(.*)<\\/td>/Uims', $area_parse[1], $fnd);
    if ($fnd) {
        foreach ($fnd[2] as $k => $val) {
            $tmp = parse_url($fnd[3][$k]);
            $add_info = cw_http_get_request('it.esprinet.com', $tmp['path'], $tmp['query'], $cookie);
            preg_match('/<td.*>Codice EAN<\\/td>.*<td.*>(.*)<\\/td>.*<td.*>Peso con Imballo.*<\\/td>.*<td.*>(.*)<\\/td>.*<a.*onClick="window.open\\(\'(.*)\'.*\\).*<td.*>Street Price \\(iva esclusa\\)<\\/td>.*<td.*>[^\\d]*([\\d\\.,]*)[^\\.^\\d^,]*<\\/td>.*<td.*>IL TUO PREZZO<\\/td>.*<td.*>.*<span.*>[^\\d]*([\\d\\.,]*)[^\\.^\\d^,]*<\\/span>.*<\\/td>/Uims', $add_info[1], $info);
            $descr_url = '/Area_Operativa/disponibilita/' . trim($info[3]);
            $tmp = parse_url($descr_url);
            $descr = cw_http_get_request('it.esprinet.com', $tmp['path'], 'cod_art=' . trim($val), $cookie);
            preg_match('/DESCRIZIONE PRODOTTO.*<td>(.*)<\\/td>/Uims', $descr[1], $fulldescr);
            $spec_url = trim($fnd[5][$k]);
            $tmp = parse_url($spec_url);
            $spec_page = cw_http_get_request('it.esprinet.com', $tmp['path'], $tmp['query'], $cookie);
            preg_match('/<div id="schedaTecnica">(.*)<\\/table>/Uims', $spec_page[1], $spec_page);
            preg_match_all('/<tr>.*<td.*><strong>(.*)<\\/strong><\\/td>.*<td.*>(.*)<\\/td>.*<\\/tr>/Uims', $spec_page[1], $spec);
            if (is_array($spec)) {
                $spec_descr = '<table width="100%" cellspacing="1" cellpadding="3" border="0" bgcolor="#cccccc" style="" class="te-2" id="Tbl_Scheda_tecnica">' . "\n";
                foreach ($spec[1] as $sp => $v) {
                    $spec_descr .= "<tr bgcolor=\"" . ($sp % 2 ? '#ececec' : '#ffffff') . "\">\n<td width=\"120\" valign=\"top\" align=\"left\" class=\"te-2-b\">" . $v . "</td>\n<td align=\"left\">" . $spec[2][$sp] . "</td>\n</tr>\n";
                }
                $spec_descr .= '</table>';
            }
            $val = strtoupper(trim($val));
            $products[$val] = array('product' => utf8_encode(trim($fnd[4][$k])), 'descr' => utf8_encode(trim($fnd[6][$k])), 'fulldescr' => utf8_encode(trim($fulldescr[1])), 'specifications' => utf8_encode($spec_descr), 'eancode' => strtoupper($info[1]), 'productcode' => $val, 'weight' => cw_convert_numeric($info[2], '2,.'), 'price' => cw_convert_numeric($info[4], '2,.'), 'wholesale' => array('quantity' => 1, 'price' => cw_convert_numeric($info[5], '2,.')), 'image' => 'http://it.esprinet.com' . trim($fnd[1][$k]));
        }
    }
    return $products;
}
function cw_import_cosmos_el_get_product_info($cookie, $list_page)
{
    preg_match_all('/<img width="100" border="0" src="(.*)">.*<a onClick="window.location = \'articolidettvisArea.xml\\?S1=(.*)&amp;S2=\' \\+ encodeURIComponent\\(\'(.*)\'\\); return false;" href="#"><font face="Verdana" size="1" color="#00009c"><b>(.*)<\\/b><\\/font><\\/a>.*Prezzo:.*<font color="red"><b>(.*)&nbsp;.*Codice prodotto:.*<b>(.*)<\\/b>/Uims', $list_page, $fnd);
    $products = array();
    if ($fnd[1]) {
        foreach ($fnd[1] as $k => $v) {
            $product = array('product' => utf8_encode(trim($fnd[4][$k])), 'descr' => '', 'fulldescr' => '', 'specifications' => '', 'eancode' => trim($fnd[3][$k]), 'productcode' => trim($fnd[3][$k]), 'weight' => 0, 'price' => cw_convert_numeric($fnd[5][$k], '2.'), 'wholesale' => array('quantity' => 1, 'price' => cw_convert_numeric($fnd[5][$k], '2.')), 'image' => 'http://www.cosmosel.it/Portale/Cosmos/B2B/it/AreaRiservata/' . trim($fnd[1][$k]));
            $products[] = $product;
        }
    }
    return $products;
}
function cw_import_chipstation_get_product_info($cookie, $list_page)
{
    preg_match_all('/<a href="javascript:popup_foto\\(\'(.*)\'\\)"><img src=\'(.*)\' border=0 ><\\/a>.*<a href=\'(.*)\' title="Codice Articolo:(.*) -  > " onClick="window\\.open\\(\'(.*)\',.*>(.*)<\\/a><\\/td>.*<td  bgcolor="#.*" align=center>&euro; (.*)<\\/td>/Uims', $list_page, $fnd);
    $products = array();
    if ($fnd[1]) {
        foreach ($fnd[1] as $k => $v) {
            $get = array('name=Chipstation', 'op=ricerca_veloce', 'q=' . $substring);
            $product_page = cw_http_get_request('www.chipstation.it', '/' . trim($fnd[5][$k]), '', $cookie);
            preg_match('/<a href=\'javascript:popup\\("(.*)"\\)\'>.*<img src="(.*)" border=0><\\/a>.*<div style="text-align: justify">(.*)<\\/div>/Uims', $product_page[1], $details);
            $product = array('product' => utf8_encode(trim($fnd[6][$k])), 'descr' => utf8_encode(trim($details[3])), 'fulldescr' => utf8_encode(trim($details[3])), 'specifications' => '', 'eancode' => trim($fnd[4][$k]), 'productcode' => trim($fnd[4][$k]), 'weight' => 0, 'price' => cw_convert_numeric($fnd[7][$k], '2,'), 'wholesale' => array('quantity' => 1, 'price' => cw_convert_numeric($fnd[7][$k], '2,.')), 'image' => 'http://www.chipstation.it/' . trim($details[2]));
            $products[] = $product;
        }
    }
    return $products;
}
function cw_config_update($category, $options)
{
    global $tables;
    $config_category_id = cw_query_first_cell("SELECT config_category_id FROM {$tables['config_categories']} WHERE category='{$category}'");
    $var_properties = cw_query_hash("SELECT name, type FROM {$tables['config']} WHERE config_category_id='{$config_category_id}'", "name", false, true);
    $section_data = array();
    foreach ($options as $key => $val) {
        if (isset($var_properties[$key])) {
            if ($var_properties[$key] == "numeric") {
                $val = doubleval(cw_convert_numeric($val));
            } elseif ($var_properties[$key] == "textarea") {
                $val = strtr($val, array("\r" => ''));
            } elseif ($var_properties[$key] == "multiselector") {
                $val = implode(";", $val);
            } elseif ($var_properties[$key] == "checkbox") {
                $val = in_array($val, array('on', '1', 'Y')) ? 'Y' : 'N';
            } elseif (in_array($var_properties[$key], array('shipping', 'memberships', 'doc_status'))) {
                $ret = array();
                if (is_array($val)) {
                    foreach ($val as $k => $v) {
                        $ret[$v] = 1;
                    }
                }
                $val = serialize($ret);
            }
            cw_array2update("config", array("value" => $val), "name='" . $key . "' AND config_category_id='" . $config_category_id . "'");
            $section_data[stripslashes($key)] = stripslashes($val);
        }
    }
}
function cw_convert_number($var, $from = NULL)
{
    global $config;
    if (strlen(@$var) == 0) {
        return $var;
    }
    if (empty($from)) {
        $from = $config['Appearance']['number_format'];
    }
    if (empty($from)) {
        $from = "2.,";
    }
    if ($config['price']['more_signs'] == 'Y') {
        $from = strtr($from, array('2' => '3'));
    }
    return round(cw_convert_numeric($var, $from), intval(substr($from, 0, 1)));
}