Esempio n. 1
0
         $q = "delete from `tbl_sources` where `id` = '" . mysql_escape_string($id) . "'";
     }
     db_query($q);
     $q = "select count(id) as `cnt` from `tbl_sources`";
     $rs = db_query($q);
     $r = mysql_fetch_assoc($rs);
     $out = array('total' => intval($r['cnt']), 'have_favorits' => $r['cnt'] > 0 ? 1 : 0);
     echo json_encode($out);
     exit;
     break;
 case 'restore_link':
     $ids = rq('id', -2);
     $cat_type = rq('cat_type');
     $cat_id = rq('cat_id', 2);
     delete_offer($ids, 0);
     cache_outs_update($ids);
     $offers_arr = offers_total($cat_type, $cat_id);
     $out = array('total' => $offers_arr['total'], 'total_html' => tpx('links_table_total', $offers_arr), 'more' => $offers_arr['more']);
     echo json_encode($out);
     exit;
     break;
     // ну а вдруг кто-то уберёт exit ;)
 // ну а вдруг кто-то уберёт exit ;)
 case 'delete_sale':
     $conversion_id = rq('conversion_id', 2);
     delete_sale_by_id($conversion_id);
     exit;
     break;
 case 'get_sales':
     $sales = get_sales($_POST['sType'], $_POST['sStart'], $_POST['sEnd']);
     echo json_encode($sales);
function edit_offer($category_id, $link_name, $link_url, $link_id = 0)
{
    $link_name = trim(str_replace(array("\r\n", "\r", "\n", "\t"), '', $link_name));
    $link_url = trim(str_replace(array("\r\n", "\r", "\n", "\t"), '', $link_url));
    if (trim($link_url) != '') {
        if (!(strpos($link_url, 'http://') === 0 || strpos($link_url, 'https://') === 0)) {
            $link_url = "http://{$link_url}";
        }
        if ($link_name == '') {
            $link_name = "Оффер #{$link_id}";
        }
        $ins = array('offer_name' => $link_name, 'offer_tracking_url' => $link_url, 'date_add' => date('Y-m-d H:i:s'));
        // Add link
        if (empty($link_id)) {
            $q = insertsql($ins, 'tbl_offers');
            db_query($q);
            $link_id = mysql_insert_id();
        } else {
            $ins['id'] = $link_id;
            $q = updatesql($ins, 'tbl_offers', 'id');
            db_query($q);
            $q = "delete from `tbl_links_categories` where `offer_id` = '" . $link_id . "'";
            db_query($q);
        }
        if (!empty($category_id)) {
            // Add link to selected category
            $ins = array('category_id' => $category_id, 'offer_id' => $link_id);
            $q = insertsql($ins, 'tbl_links_categories');
            db_query($q);
        }
    }
    cache_outs_update($link_id);
}