chdongles.php 3.84 KB
Newer Older
Kulya's avatar
Kulya committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
<?php namespace AloVoice; ?>
<style>
	.alv_table_lines .nowrp {
		white-space: nowrap;
	}
	.loadingline{
		display:none;
	}
</style>
<center><h3 class="h3 card-body">GSM линии </h3> <div class="loadingline"></div><a href="#" onClick="updateDongleAccounts()" id="dongle_ussd_send_btn" class="btn btn-primary title_line_button"><i class="fa fa-phone"></i>  Проверить баланс номеров</a></center>
<br/>

<table class="table" id="stats_block_table">
	<thead>
		<tr>
			<th>Порт</th>
			<th>Номер</th>
			<th>Статус</th>
			<th>IMEI</th>
			<!--th>Последнее USSD</th-->
			<th>Инфо</th>
			<th>Действие</th>
		</tr>
	</thead>
	<tbody id="chdongles_table_body"> </tbody> 
</table>

<script>

var afterLoadPage = function(){
	var updatingTm = false;
	var dn=0;
	var dnc=1;
	window.updateDongleOneAccount = function(device,numcode){
		loadAloVoiceInfo(
			{"restmethod":"alovoice_update_dongles_accounts","device":device,"numcode":numcode},
			function(res){
				console.log("AloVoice GSM dongle ACC RES:",res);
			}
		)
	};

	window.updateDongleAccounts = function(){
		console.log("ChLdPg:",window.loadedpage);
		updatingTm = true;
		var dnglLngth = $(".alv_table_lines").length;
		$(".loadingline").show().text("Отправка USSD №"+dnc);
		$("#dongle_ussd_send_btn").hide();
		console.log("AloVoice GSM dongle UPDATING...",dnglLngth, dnc);
		$(".alv_table_lines").each(function(ind){
			if(ind==dn){
				var device = $(this).attr("data-device");
				var numcode = $(this).attr("data-numcode");
				loadAloVoiceInfo(
					{"restmethod":"alovoice_update_dongles_accounts","device":device,"numcode":numcode},
					function(res){
						console.log("AloVoice GSM dongle ACC RES:",res);
						if(dnc==dnglLngth){
							console.log("accounting DONE!");
							setTimeout(afterLoadPage,10000);
							$(".loadingline").hide();
							$("#dongle_ussd_send_btn").show();
							updatingTm = false;
							dn=0;
							dnc=1;
						} else {
							setTimeout( updateDongleAccounts,2000);
							dn++;
							dnc++;
						}
					}
				);
				
				
			}
		});

	};
	
	var donglesUpdate = function(){
	
		if(updatingTm == true){ return; }
		loadAloVoiceInfo("alovoice_dongle_channels",function(res){
			console.log("AloVoice GSM dongles RES:",res);

			if(typeof res.gsmlines != 'undefined' ){
				$("#chdongles_table_body").html('');
				res.gsmlines.forEach(function(val){
					console.log("Each ACC:",val);
					var statusLine = (val.datas[2]=="free") ? '<span style="color:green;">'+val.datas[2]+'</span>' : val.datas[2];
					var statusLine = (statusLine=="dialing") ? '<span style="color:yellow;">'+statusLine+'</span>' : statusLine;
					var statusLine = (statusLine=="outgoing") ? '<span style="color:blue;">'+statusLine+'</span>' : statusLine;
					//var statusLine = (val.datas[2]=="dialing") ? '<span style="color:yellow;">'+val.datas[2]+'</span>' : val.datas[2];
					
					var lineHTML = '<tr class="alv_table_lines" id="dng_line_'+val.datas[1]+'" data-device="'+val.datas[1]+'" data-numcode="'+val.datas[5].substr(-9,2)+'">'
						+'<td class="nowrp" > <span>'+val.datas[1]+'</span></td>' //<i class="fa fa-telegram tgcolor"></i>
						+'<td class="nowrp" > <b>'+val.datas[5].substr(-9,2)+' '+val.datas[5].substr(-7)+'</b></td>'
						+'<td class="nowrp" >'+statusLine +'</td>'
						+'<td class="nowrp" >'+val.datas[3]+'</td>'
						+'<td>'+val.ussd+'</td>'
						+'<td class="nowrp" ><a href="#" onClick="updateDongleOneAccount(\''+val.datas[1]+'\',\''+val.datas[5].substr(-9,2)+'\');"><i class="fa fa-money"></i> Проверить</a></td>'
						+'</tr>';
					
					$("#chdongles_table_body").append(lineHTML);
				});
			}
			
			setTimeout(donglesUpdate,10000);
		}); 
	}
	
	donglesUpdate();
	//setInterval(donglesUpdate,10000);
};

</script>