<? 
require_once "include/application.php"; 
require_once "include/paginator.php";
require_once "include/paginator_html.php";
require_once "include/function.php";

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="sddm.css" >
<script src="include/validation.js" type="text/javascript"></script>
<title><? echo TITLE?></title>
</head>
<body>

<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#f1efd8">
  <tr>
    <td  colspan="2" align="center"><? require_once "include/header.php"; ?></td>
  </tr>
  <tr>
    <td colspan="2" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td width="185" valign="top" bgcolor="e6f3f9">
	
<? require_once "include/columnLeft.php"; ?>	</td>
    <td width="834" valign="top">
	<form name="form" method="post" action="<?=$PHP_SELF ?>" >
	  <table width="700" border="0" align="center" cellpadding="0" cellspacing="0">
      
      <tr>
        <td width="10"><img src="images/border/03.gif" width="10" height="9" alt="" /></td>
        <td width="676"><img src="images/border/04.gif" alt="" width="100%" height="9" /></td>
        <td width="14"><img src="images/border/05.gif" width="14" height="9" alt="" /></td>
        </tr>
      <tr>

        <td valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="50%" height="30" class="TitleH3"> SMS Alert </td>
            <td width="50%" class="TitleH3"><span class="require">SMS Credit Balance : <? echo SMSBalance() ?></span></td>
          </tr>
          <tr>
            <td height="1" colspan="2" bgcolor="#B8ED83"></td>
          </tr>
          <tr>
            <td colspan="2" ><? echo "<div class='Msg'>$action_msg</div>" ?>&nbsp;</td>
          </tr>

        </table>
          <table border="0" cellpadding="1" width="100%" cellspacing="2" class="small">

            <tr>
              <td height="16" colspan="9" class="text12"><span class="TextH1">
                <select name="sType" id="sType">
                  <option value="Name">Alert Name</option>
                  <option value="Template">Template Name</option>
                </select>
                <input name="sReferral" type="text" id="sReferral" value="<? echo $sReferral ?>" size="35" />
                User
                <select name="user" id="user" >
                  <?
						 for($i=0;$i<count($ugrp); $i++)
						 {
							echo "<option value='".$ugrp[$i]."' ";
							if($user==$ugrp[$i])echo "selected";
							echo ">".$ugrp[$i]." </option>";
						 }

?>
                </select>
                <input name="btnSearch" type="submit" class="btn" id="btnSearch" value="Search"/>
                <? stayfocus("form","sType",$sType) ?>
              </span></td>
            </tr>
            <tr>
              <td height="17" colspan="9" class="text12"><input type="button" name="btnAdd" value="Add New Alert" class="btn150" onclick="location.href='sms_newAlert.php'"/></td>
            </tr>
            <tr>
              <td width="43" height="23" background="images/tab-btns.gif" class="TextH1"><div align="center">No </div></td>
              <td width="233" background="images/tab-btns.gif" class="TextH1"><div align="left">Alert Name </div></td>
              <td width="131" background="images/tab-btns.gif" class="TextH1">SenderID</td>
              <td width="119" background="images/tab-btns.gif" class="TextH1">Alert Setting </td>
              <td width="86" background="images/tab-btns.gif" class="TextH1"><div align="center">User</div></td>
              <td width="38" background="images/tab-btns.gif">&nbsp;</td>
            </tr>
            <?
	if(!$user)$user=$_SESSION["egoUser"];		
	$sql="select smsa_user,smsa_sender,smsa_dob,smsa_senddate,smsa_id,smsa_name from sms_alert left join sms_template on smsa_template = smst_id where smsa_user='$user' ";

	if($sReferral){
		if($sType=="Name")$sql.="and smsa_name like '%$sReferral%'";			
		else if($sType=="Template")$sql.="and smst_name like '%$sReferral%'";			
	}
	$result=mysql_query($sql);
	$num_rows=mysql_num_rows($result);
	
	$pass="so=1&sReferral=$sReferral&sType=$sType";    
	$a =& new Paginator_html($_GET['page'],$num_rows,$pass);	
	$a->set_Limit(15); 
	$a->set_Links(10);  	
	$limit1 = $a->getRange1();  
	$limit2 = $a->getRange2();  
	$sql.=" order by smsa_id desc limit $limit1,$limit2 ";	
	$result=mysql_query($sql) or die(mysql_error());
	$j=1;
	while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC))
	{
		echo "<tr bgcolor='#ffffff' class='TextH1'>"; 
		$id=$myrow["smsa_id"];
	    echo "<td height='20' align='center' class='text12'>".$j++."</td>";	  				
	    echo "<td class='text12'>".$myrow["smsa_name"]."</td>";	  	
	    echo "<td class='text12'>".$myrow["smsa_sender"]."</td>";	  	
		
		if($myrow["smsa_dob"]==99)$set="DOB send to the same day<br>";
		else if($myrow["smsa_dob"] > 0 && $myrow["smsa_dob"] < 99)$set="DOB before ".$myrow["smsa_dob"]." day(s)<br>";

		if($myrow["smsa_senddate"]<>"0000-00-00")$set.= "Specify Date : ".window_date($myrow["smsa_senddate"]);
	    echo "<td class='text12'>$set</td>";	  	
	    echo "<td class='text12' align='center'>".$myrow["smsa_user"]."</td>";	  	
	    echo "<td align='center' class='text12'><a href='sms_alertSearchEdit.php?id=$id'><img src='images/view.jpg' border='0'></a>";			
		echo "</td>";	  								
		echo "</tr>";

	}

?>
            <tr>
              <td colspan="9" class="TextH2"><? echo "Total Record :[".$num_rows."] "; if($num_rows)$a->previousNext();?></td>
            </tr>
          </table></td>

      </tr>
 
    </table>
	  <br />
	</form>	</td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#333333"><div align="center"><span class="Footer">
      <br />
      <? require_once "footer.php"; ?>
    </span></div></td>
  </tr>
</table>
</body>
</html>
<?
if(array_search("SMS",$menulist)==false)
		print("<script type='text/javascript'>location.href='index.php'</script>");
?>