<?php
session_start();
ob_implicit_flush (true);

date_default_timezone_set("Europe/Athens");
if ($_SESSION['islogin']=='' ) 
{ 
  echo "ΠΡΕΠΕΙ ΝΑ ΕΓΓΡΑΦΕΙΤΕ ΓΙΑ ΝΑ ΧΡΗΣΙΜΟΠΟΙΗΣΕΤΕ ΤΟ ΣΥΣΤΗΜΑ"."<BR>";
  sleep(3);
  header("Location: loginall.php"); /* Redirect browser */
  exit();
}
$usr=$_SESSION['usr'];
$fl='delay';
	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'];
	$credits1=$ws->getCredits();
	$des=$_SESSION['tel'];
	$mes=$_SESSION['sms1'];
	$sql = $dbcon->prepare("SELECT MAX(smscode) as maxcode FROM smsout ");
    $sql->execute();
    $row=$sql->fetch(PDO::FETCH_ASSOC);
    $smc=$row['maxcode']+1;
	foreach ($des as $t)
	{
		if (!empty($t) or $t <> 0)
		{
	    $res=$ws->submitSM($sender,$t,$mes,"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]);
		}
		}
	}
	$credits2=$ws->getCredits();
	if($credits1 > $credits2)
	{
		$sql = $dbcon->prepare("insert into smsoutmes (smscode,mes,senderpmp,source) values(?,?,?,?)");
        $sql->execute([$smc,$mes,$usr,$fl]);
	}
	
?>