/**
 *
 * @return grid_data_source
 */
function create_ds_header($manager)
{
    global $cats_cid;
    return new grid_data_source(new grid_header_item_array(new grid_header_item('u2cid', 'Id', type::STRING, true), new grid_header_item('url', 'URL', type::LINK_NEWWIN, true, null, true, true), new grid_header_item('cid', 'Категория', type::STRING, true, new cat_urls_formatter('category', $cats_cid, $manager)), new grid_header_item('actions', 'Действия', null, false, new cat_urls_formatter('actions', $cats_cid, $manager))));
}
$url_cats_unmatched_ds = create_ds_header($emanager->client_id());
$url_cats_unmatched_grid = new ajax_grid('url_cats_grid_unmatched', $url_cats_unmatched_ds, $ajaxbuf_url_cats);
$url_cats_unmatched_grid_pager = new ajax_grid_pager('url_cats_grid_pager_unmatched', $BILL->GetCategoriesUrlUnMatchedCount($url_cats_unmatched_grid->get_filterfield(), $url_cats_unmatched_grid->get_filtering()), 10);
$url_cats_unmatched_grid->attach_pager($url_cats_unmatched_grid_pager);
$url_cats_matched_ds = create_ds_header($emanager->client_id());
$url_cats_matched_grid = new ajax_grid('url_cats_grid_matched', $url_cats_matched_ds, $ajaxbuf_url_matched_cats);
$url_cats_matched_grid_pager = new ajax_grid_pager('url_cats_grid_pager_matched', $BILL->GetCategoriesUrlMatchedCount($url_cats_matched_grid->get_filterfield(), $url_cats_matched_grid->get_filtering()), 10);
$url_cats_matched_grid->attach_pager($url_cats_matched_grid_pager);
/**
 * Check if we need to make some actions
 */
if ($emanager->isAnyAction()) {
    //special actions
    if ($emanager->getAction() == 'changeCatByName') {
        $item = json_decode($emanager->getItem());
        $BILL->UpdateUrlCategoryMatchByName($item->url, $item->name);
    } elseif ($emanager->getAction() == 'recognizeAll') {
        $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());
        require_once dirname(__FILE__) . '/CADBiS/recognize.php';
        foreach ($url_cats as $url) {
            $catname = Recognizer::recognizeByUrlCheck($url['url']);
            if (!empty($catname)) {