<?php

include("../includes/site_config.php");
include('../session_handler.inc');
include('../message.php');
require_once('../error.php');
require_once('../functions.php');
$pay_id = $_REQUEST['ps_id'];
$sde_eventid = $_REQUEST[sde_eventid];
if (empty($_REQUEST['ps_id'])) {
        $error_message=SD_PRGSUBSCRIBE_MAIL_INCORRECT;
        error_page($error_message,GENERAL_USER_ERROR);
        exit;

}



if($_POST[act]) {

    if($_POST[act] == "save_main_settings") {

        $sql_query = "UPDATE payment_systems SET ps_max_amount = $_POST[max_amount] WHERE ps_id = $_POST[ps_id]";

        mysql_query($sql_query, $link);

    }

    elseif($_POST[act] == "save_serv_settings") {

        foreach ($_REQUEST['params'] as $psp_id => $par_array) {

            $query = "UPDATE payment_params

                      SET

                        psp_value = '".$par_array['psp_value']."'

                      WHERE psp_id='$psp_id'";

            mysql_query($query) or die(mysql_error());

        }

    }
	echo "<script> location.href='settings_gateways.php'</script>";
     //header("Location: $CONST_LINK_ROOT/admin/settings_gateways.php");

    exit;

}

$pay_service = ($_REQUEST['pay_service']) ? $_REQUEST['pay_service'] : 'premium';



$query = "SELECT * FROM payment_systems WHERE ps_id = '".$_REQUEST['ps_id']."'";

$res = mysql_query($query);

$payment_system = mysql_fetch_object($res);



$params = get_payment_params($payment_system->ps_prefix, $pay_service, 'admin');



$query = "  SELECT *

            FROM payment_systems a

                INNER JOIN payment_services b

                    on (a.ps_id = b.ps_id)

            WHERE a.ps_id = '".$_REQUEST['ps_id']."'";

$pay_serv_res = mysql_query($query);



$query = "  SELECT *

            FROM payment_service_params ";

$res = mysql_query($query);

while ($row = mysql_fetch_object($res)) {

    $SERVICES[$row->psp_service] = $row->psp_title ;

};



# retrieve the template

$area = 'member';



?>

<?php include("include/header.php"); ?>
<? include("admin_tabs.php");?>
<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;Edit Gateways</div></div>
<div class="clear"></div>
<div class="admin-page"><div align="left">
<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="left">
<form method="post" action="<?php echo $CONST_LINK_ROOT?>/admin/edit_gateways.php<?php print("?PHPSESSID=".session_id()); ?>">
            
                <input type="hidden" name="ps_id" value="<?=$_REQUEST['ps_id']?>">

                <input type="hidden" name="act" value="save_main_settings">
</form>


        </td>

    </tr>



    <form method="post" action="<?php echo $CONST_LINK_ROOT?>/admin/edit_gateways.php<?php print("?PHPSESSID=".session_id()); ?>" name="frmPremFunc">

    <input type="hidden" name="ps_id" value="<?=$_REQUEST['ps_id']?>">

       <input type="hidden" name="act" value="">

    <tr>

        <td align="center">&nbsp;</td>

    </tr>

    <tr>

        <td align="left">

            <table border="0" align="left" cellpadding="2" cellspacing="10">

                <tr>

                    <td colspan="4" align="left" valign="top" class="admin-head2">&nbsp; </td>

                </tr>

                <?php

                foreach ($params as $param)

                {

                    ?>

                    <tr align=left>

                        <th align=left>

                            <?=$param->psp_name?>

                        </th>

                  <td align="left">

                            <input type=text class="input" name="params[<?=$param->psp_id?>][psp_value]" value="<?=$param->psp_value?>">

                        </td>

                        <td class="admin-head2" align="left"></td>

                      <td class="admin-head2" align="left">&nbsp;</td>

                </tr>

                    <?php

                }

                ?>

                    <tr>

                        <td align="left"  colspan="3" class="normal">

                            <input type=submit class=normal name=SAVE value="<?=GENERAL_SAVE?>" onClick="this.form['act'].value = 'save_serv_settings'">

                            <input type=button class=normal name=CANCEL value="Cancel" onClick="location.href='<?=$CONST_LINK_ROOT?>/admin/settings_gateways.php'">

                        </td>

                    </tr>

           </table>



        </td>

    </tr>

    </form>

</table>




</div>
</div><div class="admin-page-bottom"></div></div>
<?php mysql_close( $link ); ?>

<?php include("include/footer.php"); ?>