<?php  include("../config/connection.php"); 


$selCronwork=mysql_query("select * from cronWork   
where cronWork_name='phantomJob' and cronWork_status=0");
if(mysql_num_rows($selCronwork)==0){
	exit();}

 
$updateCornWork=mysql_query("update cronWork  set 
cronWork_date=now(),cronWork_status=1
where cronWork_name='phantomJob' and cronWork_status=0");

 






$selectCopyTo=mysql_query("select * from TxtMessage where 
TxtMessage_copyToqueu=0
and TxtMessage_messageStatus=1");





while($row=mysql_fetch_array($selectCopyTo)){ 


$selectMessage=mysql_query("select * from TxtMessage where 
TxtMessage_copyToqueu=0
and TxtMessage_messageStatus=1 and TxtMessage_id='".$row['TxtMessage_id']."'"); // recheck it 
if(mysql_num_rows($selectMessage)==1){
	
	
	
	$update=mysql_query(" update TxtMessage set
	TxtMessage_copyToqueu=1	
	where TxtMessage_id='".$row['TxtMessage_id']."' "); // start sending to queu
	
 
// copy this To Queu

$data="insert into Queuu(Queuu_date, 
Queuu_serviceid, 
Queuu_text, 
Queuu_mobile,
 Queuu_status, 
 Queuu_messageID)
values ";

$selectSubcribesinService=mysql_query("select *
 from Subscribers where Subscribers_servicesID='".$row['TxtMessage_servicesId']."'
  and Subscribers_Statusid=1");
while($rodata=mysql_fetch_array($selectSubcribesinService)){
	
	$data=$data."(now()
	,'".$row['TxtMessage_servicesId']."'
	,'".$row['TxtMessage_text']."'
	,'".$rodata['Subscribers_mobile']."'
	,0
	,'".$row['TxtMessage_id']."'
	),";
	
	
	
	}



$data=$data."(now()
	,'".$row['TxtMessage_servicesId']."'
	,'".$row['TxtMessage_text']."'
	,'0000000000'
	,0
	,'".$row['TxtMessage_id']."'
	)";
	






$insertTToQueu=mysql_query($data);

if($insertTToQueu){


$update=mysql_query(" update TxtMessage set
	TxtMessage_copyToqueu=2	
	where TxtMessage_id='".$row['TxtMessage_id']."' "); // finish sending to queu 

}


}




}


$updateCornWork=mysql_query("update cronWork  set 
cronWork_date=now(),cronWork_status=0
where cronWork_name='phantomJob' and cronWork_status=1");



?>