$BILL->UpdateUrlCategoryMatchByName($url['url'], $catname);
            }
        }
    }
    switch ($emanager->getAction()) {
        case $emanager->action->UPD:
            $item = json_decode($emanager->getItem());
            $BILL->UpdateUrlCategoryMatch($item->u2cid, $item->url, $item->cid);
            break;
        case $emanager->action->DEL:
            $item = json_decode($emanager->getItem());
            $BILL->DeleteUrlCategoryMatch($item->u2cid);
            break;
        case $emanager->action->ADD:
            $item = json_decode($emanager->getItem());
            $BILL->AddUrlCategoryMatch($item->url, $item->cid);
            break;
    }
    $emanager->eraseAction();
}
/**
 * Retrieve urls matchescategories from the database
 */
$url_cats = $BILL->GetUrlCategoriesMatch($url_cats_unmatched_grid_pager->get_curpage(), 10, $url_cats_unmatched_grid->get_sorting(), $url_cats_unmatched_grid->get_sort_direction(), array(0), array(), $url_cats_unmatched_grid->get_filterfield(), $url_cats_unmatched_grid->get_filtering());
foreach ($url_cats as $cat) {
    $url_cats_unmatched_ds->add_row(array($cat['u2cid'], $cat['url'], $cat['cid'], $cat));
}
/**
 * Retrieve categories from the database
 */
$url_cats = $BILL->GetUrlCategoriesMatch($url_cats_matched_grid_pager->get_curpage(), 10, $url_cats_matched_grid->get_sorting(), $url_cats_matched_grid->get_sort_direction(), array(), array(0), $url_cats_matched_grid->get_filterfield(), $url_cats_matched_grid->get_filtering());
 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);
                 break;
             case 'replace':
                 $BILL->ReplaceUrlCategoryKeyword($word, $setcid);
                 $BILL->ResolveUrlCategoryConflict($word);
                 break;