<?php
require_once ("../config.inc.php");
require_once ("../includes/adminlogincheck.inc.php");
require_once ("../includes/mysql.inc.php");
require_once ("../includes/arrays.inc.php");

$page		= isset($_REQUEST['page'])	?	trim($_REQUEST['page'])	:	"1";
$id			= isset($_REQUEST['id'])	?	trim($_REQUEST['id'])	:	"0";
$message	= "";

if (!$objDB) 
{
	$message	= "Unable to Locate Database Server.";
}//end if
else 
{
	//$id = $_GET['id'];
        $id = $_POST['id'];
	
	if (intval($id) != 0)
	{
		$sqlEdit = " SELECT * FROM ".TABLEPREFIX."gateways WHERE id='$id'";
		$rsEdit = mysql_query($sqlEdit);
		if($arrEdit= mysql_fetch_array($rsEdit))
		{
 			@extract($arrEdit);
			$txtTitle=$arrEdit['provider'];
			$txtSTitle=$arrEdit['vSMSgateway'];
			$txtMTitle=$arrEdit['vMMSgateway'];
			$chkActive=$arrEdit['vActive'];
		}//end if
	}//end first if

        $serviceFlag = 0;
	//add or update Country
	if(isset($_POST['Call']) && $_POST['Call']=='save')
	{
            print_r($_POST);
			@extract($_POST);
			
                        $id = $_POST['id'] ;
                        $txtTitle = $_POST["txtTitle"];
                        $txtSTitle = $_POST["txtSTitle"];
                        $txtMTitle = $_POST["txtMTitle"];
                        $chkActive =  $_POST["chkActive"];
			

			if($id!='')
			{
                            if(!isset($_POST['BackNow']))
                                 {
                                    $sqlUpdate = " UPDATE ".TABLEPREFIX."gateways SET provider='".addslashes($txtTitle)."',vActive='".addslashes($chkActive)."',
                                                                    vSMSgateway='".addslashes($txtSTitle)."',vMMSgateway='".addslashes($txtMTitle)."' WHERE id='$id' ";
                                    mysql_query($sqlUpdate) or die(mysql_error());
                                    $message = "<font color='green'>Mobile Service Provider updated successfully.</font>";
                                    $serviceFlag=1;
                                 }
                               else
                                {
                                    $serviceFlag=0;
                                }
			}
			else
			{
				$sqlIns = " INSERT INTO ".TABLEPREFIX."gateways (provider,vSMSgateway,vMMSgateway,vActive) VALUES ('".addslashes($txtTitle)."',
								'".addslashes($txtSTitle)."','".addslashes($txtMTitle)."','".addslashes($chkActive)."') ";
				mysql_query($sqlIns) or die(mysql_error());
				$message = "Mobile Service Provider added successfully.";
                                $serviceFlag=2;
			}//end else
                
                  header('location:settings.php');  
		//header('location:sms.php?msgflag='.$serviceFlag);
		//exit();
	}//end if
	//$message
}//end else

//include_once('title.inc.php');
?>
<script language="javascript" src="../js/validation.js" type="text/javascript"></script>
<script language="javascript">
function sms_chk()
{

    var frm	= document.formSms;

    if (frm.txtTitle.value == "") {
        alert("Please enter Provider Name.");
        frm.txtTitle.focus();
        return false;
    }
    if (frm.txtSTitle.value == "") {
        alert("Please enter SMS Gateway.");
        frm.txtSTitle.focus();
        return false;
    }
   
    return true;
			
}
function showListSms(id){
    if(id==''){
        $('#div_state').show();
        $('#div_add_state').hide();
    }
    else{
      window.location.href='settings.php' ;
    }
}
</script>
<table width="100%"  border="0" cellspacing="0" cellpadding="0" class="tblestyle_admin2">
  <tr>
    <td valign="top" class="white"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="72%" valign="top"><?php  //include_once('tophtml.php');?>
			<table width="100%"  border="0" cellspacing="0" cellpadding="5">
          <tr>
            <td><table width="100%"  border="0" cellspacing="0" cellpadding="5">
              <tr>
                <td width="41%"><strong class="sb-hd"><?php if($id!=''){?>
              Edit
                <?php }else{?>
                Add New
                <?php }?>
              Mobile Service Provider</strong></td>
                
              </tr>
            </table></td>
          </tr>
        </table>
		<form name="formSms" method="POST" action="<?php echo $PHP_SELF?>" onSubmit="return sms_chk()">
  <input type=hidden name='Call' value="save">
  <input name='id' type=hidden id="id" value="<?php echo $id?>">
          <table width="100%"  border="0" cellspacing="0" cellpadding="5">
            <tr>
              <td><table width="100%"  border="0" cellspacing="0" cellpadding="0">
				<?php if ($objDB) 
					  { 
				?>
					<?php 	if(isset($message) && $message!='')
							{
					?>
                <tr align="left">
                  <td align="center" class="maintext2">&nbsp;</td>
                  <td colspan="2" class="maintext2 warning"><?php echo $message;?></td>
                  </tr>
					<?php  	}//end if?>
  				<tr align="left">
                 
                  <td width="27%" class="maintext2">Provider Name <span class="warning">*</span></td>
                  <td width="70%" class="maintext2"><input name="txtTitle" class="textbox3 txt-bx" id="txtTitle" value="<?php echo $txtTitle?>" size="35" maxlength="100"></td></tr>
                 <tr align="left">
                
                  <td class="maintext2">SMS Gateway <span class="warning">*</span></td>
                  <td class="maintext2"><input name="txtSTitle" class="textbox3 txt-bx" id="txtSTitle" value="<?php echo $txtSTitle?>" size="35" maxlength="100"></td>
                 </tr>
                 <tr align="left">
               
                   <td class="maintext2">MMS Gateway</td>
                   <td class="maintext2"><input name="txtMTitle" class="textbox3 txt-bx" id="txtMTitle" value="<?php echo $txtMTitle?>" size="35" maxlength="100"></td>
                 </tr>
                <tr align="left">
                
                  <td class="maintext2">Active</td>
                  <td class="maintext2"><input name="chkActive" type="radio" value="1" <?php if($chkActive=='1'){echo 'checked';}if($chkActive==''){echo 'checked';}?>>
						      Yes <input type="radio" name="chkActive" value="0" <?php if($chkActive=='0'){echo 'checked';}?>>No</td>
                </tr>
				<?php 			
						}//end first if
				?>
              </table>
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td align="right"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                     
                    </table>
                      <?php if ($objDB) 
					  { 
					?>
                      <table width="100%"  border="0" cellspacing="0" cellpadding="5">
                      <tr>
					  <td width="27%"></td>
                        <td align="left"><table width="22%"  border="0" cellspacing="0" cellpadding="0">
                            <tr>
							<td><input name="BackNow" style="cursor: pointer;" type="button"  onclick="showListState(<?php echo $ts_id?>)" class="back-btn" value="Back"></td>
                              <td><input class="loginbutton" type="submit" value="<?php if($id!=''){?>Edit<?php }else{?>Add<?php }?> Mobile Service Provider" name="submit2"></td>
                              <?php //if ($id > 0) { ?>
                              
								<?php //}//end if?>
                              </tr>
                        </table></td>
                      </tr>
                    </table>
					<?php 		
						}//end first if
				?></td>
                  </tr>
                </table></td>
            </tr>
          </table></form></td>
        </tr>
    </table>      
    </td>
  </tr>
</table>
