<?php session_start();
if (isset($_SESSION['logged']) && $_SESSION['logged'] == 'yes') {
		include ('../../../scripts/classes.php');
		if ($_SESSION['lang']=="EN"){$lang="EN"; include ('../../../lang/en.php');}elseif ($_SESSION['lang']=="GR"){$lang="GR";include ('../../../lang/gr.php');}else {$lang="EN";include ('../../../en.php');}
        
        $user_id = Core::GetUserId();
        
		$array = getGlobalSettings(); foreach ($array as $settings){extract($settings);}
		$array_sms = getSMSSettings(); foreach ($array_sms as $sms_settings){extract($sms_settings);} 
		$page_title = _SMS_STATUS_UPDATE;
		$mode = _SMS_STATUS_UPDATE;                                       
?>	
<!DOCTYPE html SYSTEM "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $page_title ?></title>
<link rel="shortcut icon" href="../../../img/favicon.png" />
<link href="../../../cms1.css" rel="stylesheet" type="text/css" /> 
</head>
<body>
<script>top.document.title=self.document.title;</script>
	<div>
		<fieldset>
		<legend><?php echo $mode ?></legend>
		<div class="align-left">
        <?php				
                            $api = $_GET['msgid'];
        					// check charge
        					$charge_url = "http://api.clickatell.com/http/getmsgcharge?user=$primary_acc_user&password=$primary_acc_pass&api_id=$primary_http_api_id";
        					$charge_url = $charge_url."&cliMsgId=$api";
        					$charge_return = file($charge_url);
        
        					foreach($charge_return as $item){
        						$findmsg = strpos($item, "cliMsgId:");
        						$findcharge = strpos($item, "charge:");
        						$findstatus = strpos($item, "status:");
        						$length = strlen($item);
        					//Find the climsgid
        						$part1 = substr($item, $findmsg, $findstatus);
        						$part2no = strpos($item, $part1);
        						$apo = trim(substr($item, $findmsg, $findcharge ));
        						$status= trim(substr($item, $findstatus, $length ));
        						$charge= trim(substr($item, $findcharge, $findstatus));
        					//find charge
        						$ret = $charge;
        						$sess = explode(":",$ret);
        						$charge = trim($sess[1]);
        					//find status
        						$ret = $status;
        						$sess = explode(":",$ret);
        						$status = trim($sess[1]);
        					$sql = "UPDATE sms_outbox SET status = '$status' , charge = '$charge', updated_on = NOW(), updated_by = '$user_id' WHERE message_id ='$api'";
        					$result = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli));
        }
        echo "<br /><br />";
        echo "<div align=\"center\">$lbl_info_updating_record</div><br />";
        echo '<div align="center"><img src="../../../img/loading.gif" alt="loading..." /></div>';
        ?>	
        <script type="text/javascript">history.back();</script>

        </div>
		</fieldset>
	</div>
</body>
</html>
<?php
} else {
    header('Location: login.php');
}
?>