function timers() { console.log("yeah right"); } $(document).ready(function () { function getPushArray(auctions){ if(Object.keys(auctions).length > 0){ $.ajax({ type: "GET", url: "/daemons.php", data: { type: 'emergencyCheck', auctions: JSON.stringify(auctions) }, success: function(data) { console.log(data); data = JSON.parse(data); if(data.result === 'ok'){ //setTimeout(function(){ // collectAuctions(); //}, 100); } }, error: function () { } }); } } function collectAuctions(){ var auctions = {}; $('.bnr_timer_calculation').each(function(key){ const value = parseInt($(this).html()); const auction_id = $(this).attr('data-auction_id'); const closed_status = parseInt($('.closed_status[data-auction_id="' + auction_id + '"]').html()); if(value < 1 && closed_status === 0){ auctions[key] = { id: auction_id, less_time: value }; } }); console.log("collectAuctions::::" + new Date()); console.log(auctions); getPushArray(auctions); } // collectAuctions(); var auctions = {}; $('.bnr_timer_calculation').each(function(key){ const value = parseInt($(this).html()); const auction_id = $(this).attr('data-auction_id'); auctions[key] = { id: auction_id, less_time: value }; }); $.ajax({ type: "GET", url: "/daemons.php", data: { type: 'firstLoad', auctions: JSON.stringify(auctions) }, success: function(data) { console.log('firstLoad'); console.log(data); data = JSON.parse(data); if(data.result === 'ok'){ setInterval(function(){ collectAuctions(); }, 1000); } }, error: function () { } }); var auctionObjects = new Array(); $('.auction-item').each(function () { var auctionId = $(this).attr('id'); auctionObjects[auctionId] = $('.' + auctionId); auctionObjects[auctionId]['flash-elements'] = $('.' + auctionId + ' .countdown, .' + auctionId + ' .bid-price, .', + auctionId + ' .blink'); auctionObjects[auctionId]['bt'] = $('.' + auctionId + ' .bnr_timer_calculation'); auctionObjects[auctionId]['bid-price'] = $('.' + auctionId + ' .bid-price'); auctionObjects[auctionId]['bid-bidder'] = $('.' + auctionId + ' .bid-bidder'); auctionObjects[auctionId]['timer'] = $('.' + auctionId + ' .countdown'); auctionObjects[auctionId]['blink'] = $('.' + auctionId + ' .blink'); auctionObjects[auctionId]['seat_status'] = $('.' + auctionId + ' .seat_status'); auctionObjects[auctionId]['time_inc'] = $('.' + auctionId + ' .time_inc'); auctionObjects[auctionId]['min_seat'] = $('.' + auctionId + ' .min_seat'); auctionObjects[auctionId]['seat_sold'] = $('.' + auctionId + ' .seat_sold'); auctionObjects[auctionId]['closed_status'] = $('.' + auctionId + ' .closed_status'); auctionObjects[auctionId]['bid-button'] = $('.' + auctionId + ' .bid-button'); auctionObjects[auctionId]['indicadores'] = $('.' + auctionId + ' .indicadores'); auctionObjects[auctionId]['time_left'] = $('.' + auctionId + ' .time_left'); auctionObjects[auctionId]['no_mostrar'] = $('.' + auctionId + ' .no_mostrar'); auctionObjects[auctionId]['bid-loading'] = $('.' + auctionId + ' .bid-loading'); auctionObjects[auctionId]['bid-message'] = $('.' + auctionId + ' .bid-message'); auctionObjects[auctionId]['bid-histories'] = $('#bidHistoryTable' + auctionId); auctionObjects[auctionId]['bid-histories-p'] = $('#bidHistoryTable' + auctionId + ' p'); auctionObjects[auctionId]['bid-histories-tbody'] = $('#bidHistoryTable' + auctionId + ' tbody'); }); setInterval(function () { $('.auction-item').each(function () { var auctionId = $(this).attr('id'); var closed = parseInt(auctionObjects[auctionId]['closed_status'].html()); var diff = parseInt(auctionObjects[auctionId]['bt'].html()); var diff_raw = parseInt(auctionObjects[auctionId]['bt'].html()); var seat_status = parseInt(auctionObjects[auctionId]['seat_status'].html()); var time_inc = parseInt(auctionObjects[auctionId]['time_inc'].html()); var min_seat = parseInt(auctionObjects[auctionId]['min_seat'].html()); var seat_sold = parseInt(auctionObjects[auctionId]['seat_sold'].html()); var bidder = auctionObjects[auctionId]['bid-bidder'].html(); var bidPrice = auctionObjects[auctionId]['bid-price'].html(); if (diff < 0) diff = 1; var day = parseInt(Math.floor(diff / 86400)); if (day < 1) { day = 0; } else { day = day; } diff -= day * 86400; var hour = parseInt(Math.floor(diff / 3600)); if (hour < 10) hour = '0' + hour; diff -= hour * 3600; var minute = parseInt(Math.floor(diff / 60)); if (minute < 10) minute = '0' + minute; diff -= minute * 60; var second = parseInt(diff); if (second < 10) second = '0' + second; var result = day + 'd ' + hour + ':' + minute + ':' + second; if (day > 0) { var result = day + 'd ' + hour + ':' + minute + ':' + second; } else { var result = hour + ':' + minute + ':' + second; } if (seat_status == 1 && seat_sold != min_seat) { var result = seat_sold + '/' + min_seat + Seats; } //window.console.log(auctionId+' : '+result); //console.log(diff_raw, "====>", diff); if (diff_raw > 0) { //console.log(auctionId, '===>', result); auctionObjects[auctionId]['timer'].html(result); if (diff_raw >= time_inc) { $('.timer_fill').width('100%'); } if (diff_raw < 10) { auctionObjects[auctionId]['timer'].addClass('red_timer'); $('.timer_fill').addClass('red_timer'); } else { auctionObjects[auctionId]['timer'].removeClass('red_timer'); $('.timer_fill').removeClass('red_timer'); } if (diff_raw < time_inc) { var width = ((diff_raw / time_inc) * 100) + '%'; $('.timer_fill').width(width); } } else { if (closed == 1) { // $(".bid-balance").html(0); //updateBidBalance(); //$('.bid-balance').html( parseInt($('.bid-balance').html())); if (diff_raw < -5 && page_name == 'view') { location.reload(); return false; } if (auctionObjects[auctionId].hasClass('detail_view')) { ////new lines auctionObjects[auctionId]['timer'].html(Sold); auctionObjects[auctionId]['bid-button'].hide(); auctionObjects[auctionId]['time_left'].hide(); setTimeout(function() { location.reload(); return false; }, 9000); // <-- time in milliseconds ////new lines } else { auctionObjects[auctionId]['timer'].html(Sold); auctionObjects[auctionId]['bid-button'].hide(); auctionObjects[auctionId]['indicadores'].hide(); auctionObjects[auctionId]['time_left'].hide(); auctionObjects[auctionId]['no_mostrar'].css('display', 'block'); auctionObjects[auctionId].addClass('is_closed'); if (!auctionObjects[auctionId].find('.close_sticker')) auctionObjects[auctionId].find('.thumb').append(''); } } else { // auctionObjects[auctionId]['timer'].html('Checking..'); } } /*if (parseInt(auctionObjects[auctionId]['bt'].html()) <= 0 && auctionObjects[ auctionId]['timer'].html() != "Sold") { auctionObjects[auctionId]['bt'].html( 11 ); } else {*/ var newTime = parseInt(auctionObjects[auctionId]['bt'].html()) - 1; if (newTime < 0) { newTime = 0; } auctionObjects[auctionId]['bt'].html(newTime); //} //return false; }); }, 1000); connect(); function connect() { var socket = io.connect("https://www.mazadent.net:3001", {transports: ['websocket', 'polling', 'flashsocket']}), timer; socket.on('error', function() { console.log('socket error'); if (!socket.connected) { timer = window.setInterval(function() { connect() }, 1000); } }); socket.on('connect', function() { console.log('socket connected'); window.clearInterval(timer); $('#connected_push').html('Connected PUSH '); socket.on('push',function(data) { get_push_data(data); }); }); } function get_push_data(pushJson) { $.each(pushJson, function (key) { try { console.log('Processing key:', key); var data = JSON.parse(key); // Parse the key as JSON if (!Array.isArray(data) || data.length === 0) { console.warn('Invalid or empty data received:', data); return; // Skip processing if data is not an array or is empty } data = data[0]; // Access the first element of the array if (!data || typeof data !== 'object' || data.id === undefined) { console.warn('Missing or invalid "id" in data:', data); return; // Skip processing if "id" is missing or invalid } console.log('Valid data:', data); var auctionId2 = 'auction_' + data.id; if (auctionObjects[auctionId2]) { if (data.s !== undefined) { var currentTime = parseInt(auctionObjects[auctionId2]['bt'].html()); var pushTime = parseInt(data.s); if (pushTime >= 0) { auctionObjects[auctionId2]['bt'].html(data.s); } } if (data.auto_update != 1) { var bid_price = parseFloat(data.p); var bid_price1 = formatMoney(bid_price); $('.bids_bb_' + data.bb_id).html(data.bb_bids); $('.edit_bb_input_' + data.bb_id).val(data.bb_bids); if (data.seat_sold > 0) auctionObjects[auctionId2]['seat_sold'].html(data.seat_sold); if (data.seat_status > 0) auctionObjects[auctionId2]['seat_status'].html(data.seat_status); auctionObjects[auctionId2]['bid-price'].html(bid_price + ' EGP').append(''); auctionObjects[auctionId2]['bid-bidder'].html(data.u); auctionObjects[auctionId2]['closed_status'].html(data.cs); if (data.auto_update == 1 || 1) { auctionObjects[auctionId2]['blink'].effect("highlight", { color: "#ff0000" }, 1000); auctionObjects[auctionId2].addClass("blinking").delay(200).queue(function (next) { $(this).removeClass("blinking"); next(); }); } if (data.bd > 0) { // Handle bid deduction logic here } if (page_name == 'view') { if (data.s > 0) { var row = '' + data.BC + '' + data.BU + '' + parseFloat(data.p) + ' LE' + ''; if (data.BU !== "Mazadent") { auctionObjects[auctionId2]['bid-histories-tbody'].prepend(row); } var myremovedElems = $("#bidHistoryTable" + auctionId2 + " tr:gt(10)").remove(); } } } } else { console.warn('Auction object not found for ID:', data.id); } } catch (error) { console.error('Error processing push data:', error); } }); } $('.mazadentBtn').click(function (e) { e.stopPropagation(); var id = $(this).data('id'); var type = $(this).data('type'); var bid = $(this).data('bid'); if (type == 1) { $('.mazadent_model h3').html(mazadent_spy); $('.mazadent_model p.des1').html(mazadent_spy_des1); $('.mazadent_model p.des2').html(mazadent_spy_des2); } else { $('.mazadent_model h3').html(mazadent_pro); $('.mazadent_model p.des1').html(mazadent_pro_des1); $('.mazadent_model p.des2').html(mazadent_pro_des2); } $('.mazadent_model label ').html('' + mazadent_activate + '' + Close + ''); $('.mazadent_model .mazadent_table').hide(); $('.mazadent_model .error_inner').css('top', '23%'); $('.mazadent_model').show(); }); $('.bid-button-link').click(function () { //debugger; var auctionId = $(this).attr('title'); var countClick = parseInt($(".countOf"+auctionId).html()); if(countClick>29){ $('.popup_model p ').html('You missed your chance
every one get only 30 free clicks allowed.'); $('.popup_model label ').html(''); $('.popup_model_inner packages').html(''); $('.popup_model_inner div span').hide(); $('.popup_model').show(); setTimeout(function() { $('.popup_model').fadeOut('fast'); }, 5000); // <-- time in milliseconds return false; }else{ $(".countOf"+auctionId).html(countClick+1); } var auctionElement = 'auction_' + $(this).attr('title'); //auctionObjects[auctionElement]['bid-button'].hide(1); //auctionObjects[auctionElement]['bid-loading'].show(1); var params = $(this).attr('href') + '&ms=' + new Date().getTime(); $('.popup_model_inner packages').html(''); $.ajax({ url: params, dataType: 'json', success: function (data) { if (data.Auction.msg_id == 7) { $('.popup_model p ').html(data.Auction.message); $('.popup_model label ').html(''); $('.popup_model_inner packages').html('

50
' + Bids + '
' + Buy + '

100
' + Bids + '
' + Buy + '

200
' + Bids + '
' + Buy + '

' + view_all + '' + Close + '
'); $('.popup_model_inner div span').hide(); $('.popup_model').show(); } else if (data.Auction.msg_id == 5) { //alert("1"); // cancle bid debit //$('.bid-balance').html(parseInt($('.bid-balance').html()) - parseInt(data.Auction.bd)); //cancel mazadent-points $('.mazadent_points').html((data.Auction.dp).toFixed(2)); } else if (data.Auction.msg_id == 2) { $('.popup_model p ').html(data.Auction.message); $('.popup_model label ').html('' + click_here_to_buy_seat_lang + '' + Close + ''); $('.popup_model_inner div span').hide(); $('.popup_model').show(); } else { $('.popup_model p ').html(data.Auction.message); $('.popup_model label ').html(''); $('.popup_model').show(); } if( data.Auction.msg_id == 8){ $('.popup_model p ').html(data.Auction.message); $('.popup_model').hide(); $(".popup-overlay, .popup-content").addClass("active"); $("body").addClass("popup-bg"); } //auctionObjects[auctionElement]['bid-button'].show(1); //auctionObjects[auctionElement]['bid-loading'].hide(1); } }); return false; }); }); function formatMoney(amount, decimalCount = 2, decimal = ",", thousands = ".") { try { decimalCount = Math.abs(decimalCount); decimalCount = isNaN(decimalCount) ? 2 : decimalCount; const negativeSign = amount < 0 ? "-" : ""; let i = parseInt(amount = Math.abs(Number(amount) || 0).toFixed(decimalCount)).toString(); let j = (i.length > 3) ? i.length % 3 : 0; return negativeSign + (j ? i.substr(0, j) + thousands : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands) + (decimalCount ? decimal + Math.abs(amount - i).toFixed(decimalCount).slice(2) : ""); } catch (e) { console.log(e) } };