<?php

include("../includes/site_config.php");
include('../session_handler.inc');
include('../message.php');
require_once('../error.php');
require_once('../functions.php');
//if ($Sess_UserType != "A") {
//    exit;
//}

if (empty($_REQUEST['country_id'])) {
	echo "<script> window.location='$CONST_LINK_ROOT/admin/admin_geography.php'</script>";
     //header("Location: $CONST_LINK_ROOT/admin/admin_geography.php?PHPSESSID=".session_id());
    exit;
}

if($_POST[act]) {
    $_status = (isset($_POST[gcn_status]))?1:0;
    $sql_query = "UPDATE geo_country SET gcn_name = '$_POST[gcn_name]', gcn_status = '$_status', gcn_order = '$_POST[gcn_order]', gcn_regionid = '$_POST[gcn_regionid]' WHERE gcn_countryid = '$_POST[country_id]'";
//print_r($sql_query);
    mysql_query($sql_query, $link);
	echo "<script> window.location='$CONST_LINK_ROOT/admin/admin_geography.php'</script>";
     //header("Location: $CONST_LINK_ROOT/admin/admin_geography.php?PHPSESSID=".session_id());
    exit;
}

$query = "SELECT * FROM geo_country WHERE gcn_countryid = '".$_REQUEST['country_id']."'";
$res = mysql_query($query);
$country = mysql_fetch_object($res);

$query="SELECT *
        FROM geo_region
        ORDER BY grg_order, grg_name";
$regions = mysql_query($query,$link) or die(mysql_error());

# retrieve the template
$area = 'member';

?>
<?php include("include/header.php"); ?>
<table width="<?php print("$CONST_TABLE_WIDTH"); ?>" align="<?php print("$CONST_TABLE_ALIGN"); ?>" border="0" cellspacing="<?php print("$CONST_TABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_TABLE_CELLPADDING"); ?>">
  <tr>
    <td align="right">
      <?php //require_once("$CONST_INCLUDE_ROOT/user_status.inc.php");?>
    </td>
  </tr>
  <tr>
    <td class="pageheader"><?php echo GEOGRAPHY_SECTION_NAME ?></td>
  </tr>

    <tr>
        <td>
            <table border="0" width="100%" cellpadding="2" cellspacing="10">
                <form method="post" action="<?php echo $CONST_LINK_ROOT?>/admin/admin_countryedit.php<?php print("?PHPSESSID=".session_id()); ?>">
                <input type="hidden" name="country_id" value="<?=$_REQUEST['country_id']?>">
                <input type="hidden" name="act" value="save">
                <tr>
                    <td colspan="3" align="left" valign="top" class="tdhead">&nbsp; </td>
                </tr>
                <tr align=center>
                    <th align=right>
                        <?=SEARCH_COUNTRY?>
                    </th>
                    <td align="left">
                        <input type="text" class="input" name="gcn_name" value="<?=$country->gcn_name?>">
                    </td>
                    <td></td>
                </tr>
                <tr align=center>
                    <th align=right>
                        <?=ADM_GEO_REGION?>
                    </th>
                    <td  align="left">
                      <select class="input" size="1" name="gcn_regionid" tabindex="1">
                      <?php
                      while ($sql_array = mysql_fetch_object($regions)) {
                        if ($sql_array->grg_regionid == $country->gcn_regionid)
                            print("<option value='$sql_array->grg_regionid' selected>$sql_array->grg_name</option>\n");
                        else
                            print("<option value='$sql_array->grg_regionid'>$sql_array->grg_name</option>\n");
                      }
                      ?>
                      </select>
                    </td>
                    <td></td>
                </tr>
                <tr align=center>
                    <th align=right>
                        <?=ADM_CORDER?>
                    </th>
                    <td align="left">
                        <input type="text" class="input" name="gcn_order" value="<?=$country->gcn_order?>">
                    </td>
                    <td></td>
                </tr>
                <tr align=center>
                    <th align=right>
                        <?=ADM_CSTATUS?>
                    </th>
                    <td align="left">
                        <input type="checkbox" name="gcn_status" value="1" <?php if($country->gcn_status) echo ' checked'; ?> class=inputf>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td align="center"  colspan="3" class="tdfoot">
                        <input type=submit class=button name=SAVE value="<?=GENERAL_SAVE?>">
                        <input type=button class=button name=CANCEL value="Cancel" onClick="location.href='<?=$CONST_LINK_ROOT?>/admin/admin_geography.php<?php print("?PHPSESSID=".session_id()); ?>'">
                    </td>
                </tr>
                </form>
           </table>

        </td>
    </tr>

</table>
<?php mysql_close( $link ); ?>
<?php include("include/footer.php"); ?>