<?php
ob_start();

/***************************************************************************************************
 PROGRAM DESCRIPTION :  PROGRAM TO CHANGE AND VALIDATE THE EXISTING MAIL SETTINGS
 VARIABLES           :  footertxt       = COMMON MAIL FOOTER
                        headertxt       = COMMON MAIL HEADER
                        mailamnt        = COST PER PAID MAIL
                        action          = SELECTED ACTION (CHANGE COST PER MAIL, HEADER OR FOOTER)
***************************************************************************************************/

include '../includes/session.php';
include '../includes/constants.php';
include '../includes/functions.php';
include_once '../includes/allstripslashes.php';

$partners = new partners;
$partners->connection($host, $user, $pass, $db);

/****************************************************************************/
$footertxt = trim($_POST['footertxt']);         // COMMON MAIL FOOTER
$headertxt = trim($_POST['headertxt']);         // COMMON MAIL HEADER
$mailamnt  = trim($_POST['mailamnt']);          // COST PER PAID MAIL
$action    = trim($_POST['action']);            // SELECTED ACTION
/****************************************************************************/

// Use mysqli connection
$conn = $partners->conn;

/************************PROCESS ACTIONS***************************************/
switch ($action) {
    case 'Modify Amount': // CHANGE COST PER MAIL

        if (!is_numeric($mailamnt) || $mailamnt === '') {
            $msg = "Error In Data : Invalid Amount Entry";
        } else {
            $stmt = $conn->prepare("UPDATE partners_admin SET admin_mailamnt = ?");
            $stmt->bind_param("d", $mailamnt);

            if ($stmt->execute()) {
                $msg = "Amount Per Mail changed";
                $MAILAMNT = $mailamnt;
            } else {
                $msg = "Unknown Error! Please Try Again";
            }

            $stmt->close();
        }
        break;

    case 'Modify  Options': // MODIFY HEADER AND FOOTER

        $headertxt1 = $conn->real_escape_string($headertxt);
        $footertxt1 = $conn->real_escape_string($footertxt);

        $sql = "UPDATE partners_admin SET admin_mailheader = '$headertxt1', admin_mailfooter = '$footertxt1'";
        if ($conn->query($sql)) {
            $msg = "Header and Footer changed";
            $MAILHEADER = stripslashes($headertxt);
            $_SESSION['MAILHEADER'] = $MAILHEADER;
            $MAILFOOTER = stripslashes($footertxt);
            $_SESSION['MAILFOOTER'] = $MAILFOOTER;
        } else {
            $msg = "Unknown Error! Please Try Again";
        }
        break;

    default:
        $msg = "Invalid action";
        break;
}
/***************************************************************************/

header("Location: index.php?Act=mailsettings&msg=" . urlencode($msg));
exit;
?>
