<?php
session_start();?>
<html dir="rtl">
<head>
   	<link rel="shortcut icon" href="images/novinrayane.ico" />
    <link rel="stylesheet" type="text/css" href="css/style.css">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php  include ('class1.php');
if($_GET['page2']=="smslist.php") $page2="smslist.php";
if (isset($_GET['ipp']))
{
	$fa=mysql_query("select * from ozv where (ip='{$_GET['ipp']}' and city='{$_SESSION['city']}')");
	$va=mysql_fetch_assoc($fa);

	if($va['sh_t']!="")
	{
	$list = $va['sh_t'];
	if ($list!="")
	{
		$len=strlen($list);
		if($len>14) $ss=2;
		else $ss=1;
		$len=$len-$ss;
		$list=substr($list,$ss,$len);
		$nam=$va['lname'];
		mysql_query("insert into `sms` (matn1,matn2,matn5,user,city)
		VALUES ('{$va['ip']}','{$nam}','{$list}','{$_SESSION['user']}','{$_SESSION['city']}')");
	}
	}
}
?>
<title>نرم افزار كتابداري و كتابخواني نوين</title>
</head>
<body bgcolor="#8498A9" vlink="#763CD1" alink="#aa0008" dir="rtl" onKeyDown="onKeyDown(event)">
<form method="post" action="sms.php?<?php echo "page2=".$page2."&&".$add;?>" >
					<?php
					$mode=0;
					$mode=$_GET["mod"];
					$q=$_GET['ip'];
					if (isset($_POST['sms1']) || ($mode=="delete") || (isset($_POST["del"])) || ($_GET['lo']==1) || (isset($_GET["ipp"])) || ($_GET['sending']==1))
					{
					for($i=0;$i<count($_POST['sms']);$i++)
					{
					$sms1=$sms.$i;
					$arr[$i]=array("sms"=>$_POST['sms'][$i]);

					}
					if ($mode=="delete")
					{
						$fg=mysql_query("delete from `sms` where (ip='$q' and city='{$_SESSION['city']}') ");
					}
					if (isset($_POST["del"]))
					{
						$fg=mysql_query("delete from `sms` where (city='{$_SESSION['city']}') ");
					}
					if ($_GET['lo']==1)
					{
					//echo $fg1;
					$fa=mysql_query($fg1);
					while($va=mysql_fetch_assoc($fa))
						{
						if($va['tell4']!="")
						{
						$list = explode("-", $va['tell4']);
						for($j=0;$j<count($list);$j++)
						{
						if ($list[$j]!="")
						{
						$len=strlen($list[$j]);
						if($len>14) $ss=2;
						else $ss=1;
						$len=$len-$ss;
						$list[$j]=substr($list[$j],$ss,$len);
						if ($va['lname'])
						$nam=$va['lname'];
						else
						$nam=$va['company'];
//echo "fff-".$va['ip'].$nam;
					//	mysql_query("insert into `sms` (matn1,matn2)VALUES ('{$va['ip']}','{$nam}')");
					//	echo "<br/>insert into `sms` (matn1,matn2)VALUES ('{$va['ip']}','{$nam}')";

						mysql_query("insert into `sms` (matn1,matn2,matn5,user,city)
						VALUES ('{$va['ip']}','{$nam}','{$list[$j]}','{$_SESSION['user']}','{$_SESSION['city']}')");
						}
						}
						}
						}
					}
					else
					{
					for($i=0;$i<count($arr);$i++)
					{
						$fa=mysql_query("select * from costom_pas1 where (ip='{$arr[$i]['sms']}' and city='{$_SESSION['city']}')");
						$va=mysql_fetch_assoc($fa);
						if($va['tell4']!="")
						{
						$list = explode("-", $va['tell4']);
						for($j=0;$j<count($list);$j++)
						{
						if ($list[$j]!="")
						{
						$len=strlen($list[$j]);
						if($len>14) $ss=2;
						else $ss=1;
						$len=$len-$ss;
						$list[$j]=substr($list[$j],$ss,$len);
						if ($va['lname'])
						$nam=$va['lname'];
						else
						$nam=$va['company'];
						mysql_query("insert into `sms` (matn1,matn2,matn5,user,city)
						VALUES ('{$va['ip']}','{$nam}','{$list[$j]}','{$_SESSION['user']}','{$_SESSION['city']}')");
						}
						}
						}
					}
					}
					?>
					<tr  bgcolor="mistyrose"  bgcolor="mistyrose">
					<td align="center" colspan="11">
					<table border="1" align="center"  bgcolor="mistyrose">
					 <tr>
					  <td align="center"  bgcolor="mistyrose">
					<br/>	<span class="fontb1">لیست اسامی اشخاص جهت ارسال SMS</span><br/><br/>
					</td>
					</tr>
					<tr class="font2"  bgcolor="mistyrose">
					<td width="100%" align="center" colspan="9">
					<table border="1" width="100%" align="center">
					<?php echo '<tr  align="center" class="font2" >'; ?>
					  	<td width="30">
							<a href="smslist.php?logg=1&&sending=1&&page2=smslist.php" style="cursor:pointer;color:purple">انتخاب همه</a><br/>
							<a href="smslist.php?logg=2&&sending=1&&page2=smslist.php" style="cursor:pointer;color:blue">عدم انتخاب همه</a>
						</td>
					  	<td width="10">حذف</td>
					  	<td width="10">ارسال</td>
						<td width="10">رديف</td>
						<td width="90" class="fontb1">نام شخص</td>
						<td width="90" class="fontb1">شرکت</td>
						<td width="60" class="fontb1">شماره همراه</td>
					</tr>
					  	<?php
					  	if ($n1['admin']==1)
					  	$fq=mysql_query("select * from sms where (city='{$_SESSION['city']}') order by `ip` ");
					  	else
					  	$fq=mysql_query("select * from sms where (city='{$_SESSION['city']}' ) order by `ip` ");
						$i=1;include("jdf.php");
						while($vq=mysql_fetch_assoc($fq))
						{
						$cc=$vq['ip'];
						?>
							<tr  align='center' class="font2">
							<td width="5">
							<input type="checkbox" name="ch1[]" value="<?php echo $cc; ?>" <?php if ($_GET['logg']==1) { echo "checked"; }?> />
							<input type="hidden" name="ip[]" value="<?php echo $cc; ?>">
							</td>
						<?php
						    $date1=jdate("Y/m/d");//echo "date=".$date1;
						    $sq1=mysql_query("select * from sms1 where (city='{$_SESSION['city']}' ) and (matn1='{$vq['matn1']}') and (matn3='$date1') and  (matn5='{$vq['matn5']}')");
                            $t1=mysql_fetch_assoc($sq1);
                           // echo "select * from sms1 where (city='{$_SESSION['user']}') and matn1='{$vq['matn1']}' and matn3='$date1' <br/>";
						    if ($t1!="") {//echo "hjh";
						     $td1="<td class='link'><img src='images/sabtf2.png' width='20px' height='20px' border='0'></td>";
						    }
						    else $td1="<td>&nbsp;</td>";
						    $tt=mysql_query("select * from ozv where (city='{$_SESSION['city']}'  and ip='{$vq['matn1']}')  order by `ip` ");
	                        $tt1=mysql_fetch_assoc($tt);
							echo   "
							<td class='link'><a href='smslist.php?ip=".$cc."&mod=delete".$add."'><img src='images/b_drop.png' border='0' width='20' height='20'></a></td>
							$td1
							<td>$i</td>
							<td><span class:font2>".$vq['matn2']."</td>
							<td><span class:font2>".$tt1['fname']."</td>
							<td><span class:font2>".$vq['matn5']."</td></tr>";
							$i++;
						}
					?>
					</table></td></tr>
					<tr  bgcolor="mistyrose">
						<td colspan="11" align="right">
							<table width="100%">
								<tr>
									<td class="fontb1">
		                             لطفاً متن پیام را تایپ فرمایید:</td>
								</tr>
								<tr>
									<td align="right" class="fontb1">
									انتخاب موضوع :
										<?php
										$dsG = mysql_query("select * from `sms_matn` where city='{$_SESSION['city']}' order by ip") or die('خطا در اجرای دستور انتخاب گروه ها');
										print "<select name='topic' tabindex='1' style='font-family:tahoma;font-size:10pt'><option value=' '>انتخاب فرمایید...</option>";
										while ($rowG = mysql_fetch_array($dsG))
										{
							  			$ip_G = $rowG['ip'];
							  			$topic_G = $rowG['topic'];
							  				print "<option  value='$ip_G' >$topic_G</option>";
										}
										print " </select>"; ?>
									</td>
								</tr>
								<tr>
									<td align="right" class="fontb1">
										متن قبل از نام :
										<input type="text" name="tname1" value="جناب آقای " style="font-family:tahoma;font-size:12" />
									</td>
								</tr>
								<tr>
									<td align="center">
										<textarea name="matn" rows="5" cols="95" tabindex='1' style="font-family:tahoma"></textarea>
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr bgcolor="mistyrose" >
					 <td class="font3"  colspan="10">
					    <?php
					    include("exam.php");
						$sql=mysql_query("select * from msgsms where city='{$_SESSION['city']}' order by  ip desc");
						$t=mysql_fetch_assoc($sql);
						echo "مانده حساب : <span class='fonterror' >".$t['mandeh']." </span>ریال<br/>";
						echo "<span >مبلغ پیامک فارسی : <span class='fonterror' >".$t['fprice']." </span>ریال<br/>";
						echo "<span >مبلغ پیامک انگلیسی : <span class='fonterror' >".$t['eprice']." </span>ریال<br/>";
					//	echo "</span>";
						 ?>
					 </td>
					</tr>
					<tr  bgcolor="mistyrose">
						<td align="center" title="تاييد ارسال SMS" colspan="9">
							<table width="100%" border="0">
								<tr>
									<td align="left">
										<button tabindex="1" title="ارسال SMS بی نام" name="sms2" type="submit" ><img src="images/sms.png"  name="Add"  border="0" width="30" height="30" ></button>
									    <button tabindex="1" title="ارسال SMS با نام" name="sms3" type="submit" ><img src="images/sms1.png"  name="Add"  border="0" width="30" height="30" ></button>
									</td>
									</form>
									<form method="post" action="">
									<td align="right" width="45%">
										<button tabindex="1" title="حذف ليست" name="del" type="submit" ><img src="images/b_drop.png"  name="Add"  border="0" width="30" height="30" ></button>
									</td>
								</tr>
							</table>
							</td>
					 </tr></table>
						</td>
					</TR>
					<?PHP
					}
					?>
					</body>