break;
        case $emanager->action->UPD:
            $item = json_decode($emanager->getItem());
            $item->keywords = explode(',', $item->keywords);
            for ($i = 0; $i < count($item->keywords); ++$i) {
                $item->keywords[$i] = rtrim(ltrim($item->keywords[$i]));
                if (strlen($item->keywords[$i]) < 4 || empty($item->keywords[$i])) {
                    array_splice($item->keywords, $i, 1);
                    $i = 0;
                }
            }
            $BILL->UpdateUrlCategoryKeywords($item->cid, $item->keywords);
            $BILL->UpdateUrlCategory($item->cid, array('title' => $item->title, 'title_ru' => $item->title_ru));
            break;
        case $emanager->action->DEL:
            $item = json_decode($emanager->getItem());
            if ($item->cid > 0) {
                $BILL->DeleteUrlCategory($item->cid);
            }
            break;
    }
    $emanager->eraseAction();
}
/**
 * Retrieve categories from the database
 */
$cats = $BILL->GetUrlCategories($cats_grid_pager->get_curpage(), $cats_grid_pager->get_pagesize(), $cats_grid->get_sorting(), $cats_grid->get_sort_direction(), $cats_grid->get_filterfield(), $cats_grid->get_filtering());
foreach ($cats as $cat) {
    $cat['keywords'] = implode(", ", $BILL->GetUrlCategoryKeywords($cat['cid']));
    $cats_ds->add_row(array($cat['cid'], $cat['title'], $cat['title_ru'], $cat));
}
    die(Recognizer::recognizeByUrlCheck($_GET['url']));
} else {
    $BILL = new CBilling($GV["dbhost"], $GV["dbname"], $GV["dblogin"], $GV["dbpassword"]);
    $result = "";
    $url = "www.yandex.ru";
    if (isset($_REQUEST['url'])) {
        $url = $_REQUEST['url'];
    }
    $current_cid = $BILL->GetUrlCategory($url);
    $cats = $BILL->GetUrlCategories();
    $kwds_weights = $BILL->GetKeywordsWeights();
    $cat_by_cid = array();
    $i = 0;
    foreach ($cats as &$cat) {
        $cat_by_cid[$cat['cid']] = $i++;
        $cat['keywords'] = $BILL->GetUrlCategoryKeywords($cat['cid']);
    }
    // Setting url category
    if (isset($_GET['set']) || isset($_POST['btnAttach'])) {
        if ($setcid > 0 && !empty($url)) {
            $BILL->AddUrlCategoryMatch($url, $setcid);
        }
    }
    // Applying conflicts resolves
    if (isset($_POST['btnResolveConflicts'])) {
        $actionfor = $_POST['actionfor'];
        foreach ($actionfor as $word => $action) {
            switch ($action) {
                case 'delete':
                    $BILL->DeleteUrlCategoryKeyword($word);
                    $BILL->ResolveUrlCategoryConflict($word);