<?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($_POST['id'])	?	trim($_POST['id'])	:	"0";
$message	= "";

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

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

			if($tc_id!='')
			{	
				$sqlUpdate = " UPDATE ".TABLEPREFIX."country SET tc_name='".addslashes($txtTitle)."',tc_status='".addslashes($chkActive)."',
								tc_code='".addslashes($txtSTitle)."' WHERE tc_id='$tc_id' ";
				mysql_query($sqlUpdate) or die(mysql_error());
				$message = "<font color='green'>Country updated successfully.</font>";
			}
			else
			{
				$sqlIns = " INSERT INTO ".TABLEPREFIX."country (tc_code,tc_name,tc_status) VALUES ('".addslashes($txtSTitle)."',
								'".addslashes($txtTitle)."','".addslashes($chkActive)."') ";
				mysql_query($sqlIns) or die(mysql_error());
				$message = "<font color='green'>Country added successfully.</font>";
			}//end else
		header('location:settings.php?message='.$message);
		//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 Country_chk()
{

    var frm	= document.formCountry;

    if (frm.txtTitle.value == "") {
        alert("Please enter name of the country.");
        frm.txtTitle.focus();
        return false;
    }
    else
    {
        return true;
    }
}
function showListCountry(id){
    if(id==''){
        $('#div_country').show();
        $('#div_add_country').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 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($tc_id!=''){?>
              Edit
                <?php }else{?>
				
                Add New
                <?php }?>
            Country</strong></td>
              
              </tr>
            </table></td>
          </tr>
        </table>
		<form name="formCountry" method="POST" action="<?php echo $PHP_SELF?>" onSubmit="return Country_chk()">
  <input type=hidden name='Call' value="save">
  <input name='tc_id' type=hidden id="tc_id" value="<?php echo $tc_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">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">Short Name <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">Active</td>
                  <td class="maintext2"><input name="chkActive" type="radio" value="A" <?php if($chkActive=='A'){echo 'checked';}if($chkActive==''){echo 'checked';}?>>
						      Yes <input type="radio" name="chkActive" value="N" <?php if($chkActive=='N'){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="14%"  border="0" cellspacing="0" cellpadding="0">
                            <tr>
							  <td><input name="BackNow" class="back-btn" style="cursor: pointer;" type="button"  onclick="showListCountry(<?php echo $tc_id?>)"value="Back"></td>
                              <td><input class="loginbutton" style="cursor: pointer;" type="submit" value="<?php if($tc_id!=''){?>Edit<?php }else{?>Add<?php }?> Country" name="submit2"></td>
                              <?php //if ($tc_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>
