<?php
    include "scrinit.php";
    $usr=$_SESSION['usr'];
	require_once 'soapClient.class.php';
	$ws=new WebsmsClient($cfg);
	
	$sp=mysqli_query($con,"select smsname from sysset");
	$row=mysqli_fetch_array($sp);
	$sender = $row['smsname'];
	$des=$_SESSION['ph'];
	$mes=$_SESSION['sms1'];
	$fl=$_SESSION['fl'];
	
	$credits1=$ws->getCredits();
	///// get next autoinncrement
	$sql = "SHOW TABLE STATUS LIKE 'smsout'";
	$result=$con->query($sql);
	$row = $result->fetch_assoc();
	$smc= $row['Auto_increment'];
	
	echo "<br>";
	$i=0;
	foreach ($des as $t)
	{
		if (!empty($t) or $t <> 0)
		{
			$mesx=$mes[$i];
			echo "Μήνυμα: ".$mesx;$i++;
			echo $i.". ".$t."<br>";
			$res=$ws->submitSM($sender,$t,$mesx,"GSM");
			if ($res)
			{  $dtm = date('Y-m-d H:i:s');
			   $sql = $dbcon->prepare("insert into smsout (datetm,smscode,tel) values(?,?,?)");
			   $sql->execute([$dtm,$smc,$t]);
			}
	    }
	}
	echo "<br>";
	echo "ΕΧΟΥΝ ΣΤΑΛΕΙ ".$i."΄ΜΗΝΥΜΑΤΑ";
	$credits2=$ws->getCredits();
	echo "<p>";
	echo "<p>"."ΑΡΧΙΚΕΣ ΜΟΝΑΔΕΣ:".$credits1."</p>";
	echo "<p>"."ΥΠΟΛΟΙΠΟΜΕΝΕΣ ΜΟΝΑΔΕΣ:".$credits2."</p>";
	
	if($credits1 > $credits2)
	{
		foreach ($mes as $mesx)
		{
			$sql = "insert into smsoutmes (smscode,mes,senderpmp,source) 
			values('$smc','$mesx','$usr','$fl')";
			if (!mysqli_query($con,$sql)) 
	        {
		      echo mysqli_error($con); 
	        }
		}
	}
	
	
	
?>
<br />
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a>
</body>
</html>