<?php

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

############################

/*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 ;

};

###############################

$pay_title=$_REQUEST['pay_title'];

$pay_id = $_POST['pay_id'];
if($_POST['action'] == 'save') {
	if (trim($pay_title) == "")
		$error_message="Please enter title";
	if($error_message)
	{
		error_page($error_message,GENERAL_USER_ERROR);
		exit;
	}
	
	$query = "UPDATE payment_systems SET ps_title = '$pay_title' WHERE ps_id='$pay_id'";
	mysql_query($query) or die(mysql_error());
}
if($_GET['action'] == 'status')
{
	$pay_id = $_GET['pay_id'];
	$sql_result = mysql_query("SELECT * FROM  payment_systems WHERE ps_id='$pay_id'", $link);
	$payments = mysql_fetch_object($sql_result);
	if ($payments->ps_active == 'yes') {
		$sql_query = "UPDATE payment_systems SET ps_active = 'no' WHERE ps_id='$pay_id'";
	} else {
		$sql_query = "UPDATE payment_systems SET ps_active = 'yes' WHERE ps_id='$pay_id'";
	}
	mysql_query($sql_query);
}

$query = "  SELECT *
            FROM payment_service_params ";
$service_res = mysql_query($query);

# retrieve the template
$area = 'member';

?>
<?php include("include/header.php"); ?>
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<div style="padding-left:10px">
<table width="200px"  border="0" cellpadding="0" cellspacing="2">
<tr>
<td>
<? include("admin_tabs.php");?>

<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;Payment Gateways</div></div>
<div class="clear"></div>
<div class="admin-page">
<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>&nbsp;</td></tr>
  <tr>
    <td>

    <form method="post" action="<?php echo $CONST_LINK_ROOT?>/admin/settings_gateways.php<?php print("?PHPSESSID=".session_id()); ?>" name="frmPremFunc">
            <table width="100%"  border="0" cellspacing="0" cellpadding="4">
               <!-- <tr align="left">
                    <th width=46% class="admin-head2"><?=ADM_PAYMENTS_TITLE?></td>
                    <th width=20% class="admin-head2"><?=ADM_PAYMENTS_PREFIX?></td>
                    <th width=12% class="admin-head2"><?=ADM_PAYMENTS_CONFIGURE?></td>
                    <th width=12% class="admin-head2"><?=ADM_PAYMENTS_STATUS?></td>
                    <th width=12% class="admin-head2"><?=ucfirst(GENERAL_EDIT)?></td>
                </tr>-->
                <?php
                $payments = get_payments_list();

                foreach ($payments as $payment)
                {
                    ?>
                    <tr align=left>
                        <td class="blue"><?if($payment->set == 'yes'){?>
                                <?=$payment->ps_title?><strong> </strong><?}else{?>
                            <?=$payment->ps_title?> <?}?></td>
                      <td class="tdodd"><!--DWLayoutEmptyCell-->&nbsp;</td>
                      <td class="tdodd"><a href="<?=$CONST_LINK_ROOT?>/admin/edit_gateways.php?ps_id=<?=$payment->ps_id?>"><?=GENERAL_EDIT?></a></td>
                        <td class="tdodd">-&nbsp;&nbsp;&nbsp;<a href="<?=$CONST_LINK_ROOT?>/admin/settings_gateways.php?action=status&pay_id=<?=$payment->ps_id?>"><?= $payment->ps_active=='yes' ? ADM_PAYMENTS_DEACTIVATE : ADM_PAYMENTS_ACTIVATE ?></a></td>
                       <!-- <td class="tdodd"><a href="<?=$CONST_LINK_ROOT?>/admin/admin_payedit.php?pay_id=<?=$payment->ps_id?>"><?=GENERAL_EDIT?></a></td>-->
                    </tr>
					<tr><!--<td><strong class="blue">Paypal</strong></td><td><a href="<?=$CONST_LINK_ROOT?>/admin/settings_gateways.php?action=status&pay_id=<?=$payment->ps_id?>"><?= $payment->ps_active=='yes' ? ADM_PAYMENTS_DEACTIVATE : ADM_PAYMENTS_ACTIVATE ?></a></td><td><a href="<?=$CONST_LINK_ROOT?>/admin/settings_gateways.php?ps_id=<?=$payment->ps_id?>"><?=GENERAL_EDIT?></a></td><td>&nbsp;</td>-->
                    <?php
                }
                ?>
            </table>
        </form>

        </td>
      </tr>
	</table>
<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">
    </td>
  </tr>

  <tr>
    <td class="admin-head">&nbsp;</td>
  </tr>
  <tr>
    <td class="admin-head">&nbsp;</td>
  </tr>
  <tr>

    <td class="admin-head"><b>Active Installed Payment Gateway</b></td>
  </tr>

<tr><td>
<table>
  <tr>
    <td class="admin-head2">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr><td class="admin-head2"><strong>Select Gateway</strong></td><td>&nbsp;</td><td><select name="menu1" style="width:150px">
    <option>Paypal</option>
  </select></td></tr>
  <tr><td colspan="3" align="right"><input type=button class=normal name=CANCEL2 value="Add" style="font-size:11px; font-family:verdana" /></td></tr>
</table>
</td>
</tr>

    <?php /*?><tr>

        <td valign="top" align="left" class="admin-head2"><?=$payment_system->ps_title?></td>
    </tr>

    <tr>

        <td>

            <table border="0" width="100%" cellpadding="2" cellspacing="10">

                <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">

               

                <tr align=center>

                    <td align=left>

                       <b> <?=ADM_PAYMENTS_MAX_AMOUNT?>  </b>                  </td>

                    <td align="left">

                        <input type=text class="inputs" name="max_amount" value="<?=$payment_system->ps_max_amount?>">                    </td>

                    <td></td>
                    <td><span class="tdfoot">
                      <input type=submit class=button name=SAVE2 value="<?=GENERAL_SAVE?>" style="font-size:11px; font-family:verdana" />
                    </span></td>
                    <td><span class="tdfoot">
                    <input type=button class=button name=CANCEL2 value="Cancel" onclick="location.href='<?=$CONST_LINK_ROOT?>/admin/settings_gateways.php'" style="font-size:11px; font-family:verdana" />
                    </span></td>
                </tr>
                </form>
           </table>        </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>

            <table border="0" width=100% 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=center>

                        <th width="8%" align=right>

                            <?=$param->psp_name?>                        </th>

                        <td width="36%">

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

                        <td width="42%" class="admin-head2">

                            <?=$param->psp_type?>                        </td>

                        <td width="14%" class="admin-head2">

                            <?=$param->psp_description?>                        </td>
                    </tr>

                    <?php

                }

                ?>

                    <tr>

                        <td align="left"  colspan="4" class="tdfoot">

                            <div align="right">
                              <select name=pay_service onchange="this.form.submit();" >
                                <?php while ($row = mysql_fetch_object($pay_serv_res)) { ?>
                                <option value="<?=$row->pay_service?>" <?if ($pay_service==$row->pay_service) echo "selected"?>>
                                  <?=$SERVICES[$row->pay_service]?>
                                <?php } ?>
                                </option>
                              </select>
                               &nbsp; &nbsp; &nbsp; <input type=submit class=button name=SAVE value="<?=GENERAL_SAVE?>" onClick="this.form['act'].value = 'save_serv_settings'" style="font-size:11px; font-family:verdana"> &nbsp; <input type=button class=button name=CANCEL value="Cancel" onClick="location.href='<?=$CONST_LINK_ROOT?>/admin/settings_gateways.php'" style="font-size:11px; font-family:verdana"></div></td>
                    </tr>
           </table>  </form>      </td>
    </tr><?php */?>
</table></div><div class="admin-page-bottom"></div></div>
<?php mysql_close( $link ); ?>
<?php include("include/footer.php"); ?>