function brain_insert($ProductID, $m)
{
    $sel1___ = $m->query('select brain_base.Slug from brain_base where brain_base.id=' . $ProductID);
    $res1___ = $sel1___->fetch_assoc();
    "http://brain.com.ua/" . $res1___['Slug'] . " .html";
    $html_item = file_get_contents('http://brain.com.ua/' . $res1___['Slug'] . '.html');
    phpQuery::newDocument($html_item);
    $CatImg = pq('div.clear_fix ul.product_slider li');
    foreach ($CatImg as $CI) {
        $Item['Images_brain'][] = pq($CI)->find('img')->attr('src');
        $Item['Images_local'][] = copy___(pq($CI)->find('img')->attr('src'));
        //        echo "<br>";
        //        echo 1;
        //        var_dump($Item['Images_local']);
        //        var_dump($Item['Images_local']);
    }
    if (isset($Item['Images_brain'])) {
        $CountProductImages = count($Item['Images_brain']);
        for ($cnt_img = 0; $cnt_img < $CountProductImages; $cnt_img++) {
            $ItemI[$cnt_img]['Images_brain'] = $Item['Images_brain'][$cnt_img];
            $ItemI[$cnt_img]['Images_local'] = $Item['Images_local'][$cnt_img];
        }
        $Item['Images'] = $ItemI;
    }
    $DescItem = pq('.description_wrapper');
    $Item['FullDescription'] = $m->real_escape_string(trim(pq($DescItem)->html()));
    $Item['FullDescription'];
    $ItemSpec = pq('.table div.row');
    foreach ($ItemSpec as $IS) {
        $AttName[] = pq($IS)->find('div')->text();
        $AttValue[] = pq($IS)->find('.text_right')->text();
    }
    $CountAttributerReturn = count($AttName);
    for ($cnt_aa = 0; $cnt_aa < $CountAttributerReturn; $cnt_aa++) {
        $AttributerR[$cnt_aa]['name'] = $m->real_escape_string(trim($AttName[$cnt_aa]));
        $AttributerR[$cnt_aa]['value'] = $m->real_escape_string(trim($AttValue[$cnt_aa]));
    }
    $Item['Attributes'] = $AttributerR;
    $upd0___ = $m->query("UPDATE brain_base SET FullDescription = '" . $Item['FullDescription'] . "' WHERE id = " . $ProductID);
    foreach ($Item['Images'] as $II) {
        $ins0___ = $m->query("INSERT INTO brain_images VALUES ('', " . $ProductID . ", '" . $II['Images_brain'] . "', '" . $II['Images_local'] . "')");
    }
    foreach ($Item['Attributes'] as $IA) {
        /// puth in value in name product tovar
        $ins1___ = $m->query("INSERT INTO brain_attributes VALUES ('', " . $ProductID . ", '" . $IA['name'] . "', '" . $IA['value'] . "')");
    }
    $upd1___ = $m->query("UPDATE brain_base SET i = 1 WHERE id = " . $ProductID);
    return 1;
}
function insert_pars($link, $m)
{
    $url = 'http://yugcontract.ua' . $link;
    $html = file_get_contents($url);
    phpQuery::newDocument($html);
    $ProductName = pq('.good-info-header');
    $ProductId = pq('.good-info-number');
    $ProductDescription = pq('.goods-item-panes');
    $ProductSlug = pq('.item-descr-small-content');
    $ProductImages = pq('#images-list a');
    $ProductImage = pq('#images-preview');
    $ProductPropertiesDeleteClass = pq('.properties-table .prop-header')->removeAttr('class');
    $ProductPropertiesName = pq('.properties-table .prop');
    //print_r($ProductPropertiesName);
    $ProductPropertiesValue = pq('.properties-table .val');
    $Product['url'] = $link;
    $Product['name'] = $m->real_escape_string(trim(pq($ProductName)->text()));
    $str = $Product['name'];
    $www = strstr($str, "(");
    $Product['Product_code'] = substr(substr($www, 0, -1), 1);
    $Product['id'] = (int) preg_replace("/[^0-9]/", '', pq($ProductId)->text());
    $Product['description'] = $m->real_escape_string(trim(pq($ProductDescription)->find('.content')->html()));
    $Product['slug'] = $m->real_escape_string(trim(pq($ProductSlug)->find('ul li')->html()));
    $Product['image_yug'] = pq($ProductImage)->attr('href');
    if ($Product['image_yug']) {
        $Product['image_local'] = copy___($Product['image_yug']);
    } else {
        $Product['image_local'] = '';
    }
    foreach ($ProductImages as $PI) {
        $Product['amages_yug'][] = pq($PI)->attr('href');
        $Product['images_local'][] = copy___(pq($PI)->attr('href'));
    }
    if (isset($Product['amages_yug'])) {
        $CountProductImages = count($Product['amages_yug']);
        for ($cnt_img = 0; $cnt_img < $CountProductImages; $cnt_img++) {
            $ProductI[$cnt_img]['amages_yug'] = $Product['amages_yug'][$cnt_img];
            $ProductI[$cnt_img]['images_local'] = $Product['images_local'][$cnt_img];
        }
        $Product['images'] = $ProductI;
    }
    foreach ($ProductPropertiesName as $PPN) {
        $Product['properties_name'][] = pq($PPN)->removeClass('prop-header')->text();
    }
    foreach ($ProductPropertiesValue as $PPV) {
        $Product['properties_value'][] = pq($PPV)->text();
    }
    if (isset($Product['properties_name'])) {
        $CountProductProperties = count($Product['properties_name']);
        for ($cnt_prop = 0; $cnt_prop < $CountProductProperties; $cnt_prop++) {
            $ProductProperties[$cnt_prop]['properties_name'] = $m->real_escape_string(trim($Product['properties_name'][$cnt_prop]));
            $ProductProperties[$cnt_prop]['properties_value'] = $m->real_escape_string(trim($Product['properties_value'][$cnt_prop]));
        }
        $Product['properties'] = $ProductProperties;
    }
    $ins0___ = $m->query("INSERT INTO yug_base VALUES ('', '" . $Product['id'] . "', '" . $Product['name'] . "','" . $Product['slug'] . "', '" . $Product['url'] . "', '" . $Product['description'] . "', '" . $Product['Product_code'] . "',0, now());");
    $sel0___ = $m->query("SELECT MAX(id) m FROM yug_base");
    $res0___ = $sel0___->fetch_assoc();
    if (isset($Product['images'])) {
        foreach ($Product['images'] as $PI___) {
            $ins1___ = $m->query("INSERT INTO yug_images VALUES ('', '" . $res0___['m'] . "', '" . $PI___['amages_yug'] . "', '" . $PI___['images_local'] . "');");
        }
    }
    if (isset($Product['properties'])) {
        foreach ($Product['properties'] as $PP___) {
            $ins2___ = $m->query("INSERT INTO yug_attributes VALUES ('', '" . $res0___['m'] . "', '" . $PP___['properties_name'] . "', '" . $PP___['properties_value'] . "');");
        }
    }
    unset($html);
}