<?php
session_start();
//include_once ('Public.php');
include ('dbf.php');
include ('jdf.php');
$tn=jdate('Y/m/d');
$h=jdate('h:i:s');
$tou='SMS ارسال';
if (isset($_POST['sms3'])  and ($_POST['matn']!="" || $_POST['topic']!=" "))
{
	$check="0";$i=0;$ch=0;
    if($_GET['Search2']!="جستجو تاریخ...") $add2="&&Search2=".$_GET['Search2'];else $add2="";
	if($qsend!="") $add="&&qsend=".$qsend."&&Val=".$Val."&&Cap=".$Cap."&&Search=".$_GET['Search'].$add2;
    $checkbox=0;
	$fz=mysql_query("select * from sms where (city='{$_SESSION['city']}') order by `ip` ");
	$i=0;
	while($vz=mysql_fetch_assoc($fz))
	{
	 if(isset($_POST['ch1'][$i]) and $vz['ip']==$_POST['ch1'][$i]){
	  $sql=mysql_query("select * from sms where (city='{$_SESSION['city']}') order by `ip` ");
    $aa=$vz['matn5'];
	if ($_POST['topic']!==" ")
	{
	$fx=mysql_query("select * from sms_matn where (ip='{$_POST['topic']}' and city='{$_SESSION['city']}') order by `ip` ");
	$vx=mysql_fetch_assoc($fx);
	$matn=$vx['matn'];
	}
	else
	$matn=$_POST['matn'];
    $matn=$_POST['tname1']." ".$vz['matn2'].' '.$matn;$message="         SMS با نام ارسال شد .";
	mysql_query("insert into `sms1` (matn1,matn2,matn3,matn4,matn5,user,city)
	VALUES ('{$vz['matn1']}','{$matn}','{$tn}','{$h}','{$vz['matn5']}','{$_SESSION['user']}','{$_SESSION['city']}')");
	$i++;
	$checkbox=1;?>
	<script language="javascript">
	   window.open("http://websms.amootco.ir/Send.aspx?Username=no_tabatabaie&Password=98521456&Number=100008081<?php echo '&Recipient='.$aa.'&Body='.$matn; ?>&Flash=false%&Unicode=false",'_blank')
//openedWindow.close();
    </script>
<?php
echo $matn."<br/>";
}
	}
  if($checkbox!=1){?>
    <script>
		window.alert("هیچ سطری انتخاب نشده است");
		window.location.href="custom.php?sending=1" ;
	</script>
	<?php }?>
	<script>
		window.alert("<?php echo $message; ?>");
		window.location.href="custom.php?sending=1" ;
	</script>
	<?php
}
else if ( isset($_POST['sms2']) and ($_POST['matn']!="" || $_POST['topic']!=" "))
{
	$check="0";$i=0;$ch=0;
    if($_GET['Search2']!="جستجو تاریخ...") $add2="&&Search2=".$_GET['Search2'];else $add2="";
	if($qsend!="") $add="&&qsend=".$qsend."&&Val=".$Val."&&Cap=".$Cap."&&Search=".$_GET['Search'].$add2;
    $sql=mysql_query("select * from sms where (city='{$_SESSION['city']}' and user='{$_SESSION['user']}' ) order by `ip` ");
    $checkbox=0;
 	$fz=mysql_query("select * from sms where (city='{$_SESSION['city']}') order by `ip` ");
	$i=0;
	while($vz=mysql_fetch_assoc($fz))
	{
	 if(isset($_POST['ch1'][$i]) and $vz['ip']==$_POST['ch1'][$i]){
	  $sql=mysql_query("select * from sms where (city='{$_SESSION['city']}') order by `ip` ");
    $a[]=$vz['matn5'];
	if ($_POST['topic']!==" ")
	{
	$fx=mysql_query("select * from sms_matn where (ip='{$_POST['topic']}' and city='{$_SESSION['city']}') order by `ip` ");
	$vx=mysql_fetch_assoc($fx);
	$matn=$vx['matn'];
	}
	else
	$matn=$_POST['matn'];
	$message="         SMS ارسال شد .";
    echo $matn."<br/>";
	mysql_query("insert into `sms1` (matn1,matn2,matn3,matn4,matn5,user,city)
	VALUES ('{$vz['matn1']}','{$matn}','{$tn}','{$h}','{$vz['matn5']}','{$_SESSION['user']}','{$_SESSION['city']}')");
	$i++;
	$checkbox=1;
	}
	}
	if($checkbox==1)
	  $aa=join(',',$a);
    else{?>
    <script>
		window.alert("هیچ سطری انتخاب نشده است");
		window.location.href="custom.php?sending=1" ;
	</script>
	<?php }?>
		<script language="javascript">
window.open("http://websms.amootco.ir/Send.aspx?Username=no_tabatabaie&Password=98521456&Number=100008081<?php echo '&Recipient='.$aa.'&Body='.$matn; ?>&Flash=false%&Unicode=false",'_blank')	//openedWindow.close();
		</script>
	<script>
		window.alert("<?php echo $message; ?>");
		window.location.href="custom.php?sending=1" ;
	</script>
	<?php
}
elseif ($_POST['matn']=="")
{
?>
	<script>
		window.alert("                 متن پیام تعیین نشده است.");
		window.location.href="custom.php?sending=1" ;
	</script>
<?php
}
include ('custom.php');
?>