<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$zdb = $_SESSION["zdbyear_" . $dbname];


mysqli_select_db($conn, $zdb);
$admin = $_SESSION["admin_" . $dbname];
$success = false;

$file = "invoice.php";

$keyfld = "vouchno";
$zroot = $_SESSION["zdir"];
$zroot1 = substr($zroot,0,-5);
$myyear = $_SESSION[$myyear];


$getvouch = $_REQUEST['vouch'];

$convmsp = (string) $getvouch;
$clen = strlen($convmsp);

$dcode = "";

for ($i = 0; $i < $clen; $i++) {
    $c1 = substr($convmsp, $i, 1);
    $getmsp = mysqli_query($conn, "Select * from $zroot.msp where no = '$c1'") or die(mysqli_error($conn));
    $fetmsp = mysqli_fetch_array($getmsp);
    $codmsp = $fetmsp['code'];
    $dcode = $dcode . $codmsp;
}

$convmsp2 = (string) $myyear;
$clen2 = strlen($convmsp2);

$dcode2 = "";

for ($i2 = 0; $i2 < $clen2; $i2++) {
    $c12 = substr($convmsp2, $i2, 1);
    $getmsp2 = mysqli_query($conn, "Select * from $zroot.msp where no = '$c12'") or die(mysqli_error($conn));
    $fetmsp2 = mysqli_fetch_array($getmsp2);
    $codmsp2 = $fetmsp2['code'];
    $dcode2 = $dcode2 . $codmsp2;
}

$code = $_REQUEST["scode"];


$mfschool = mysqli_query($conn, "SELECT email FROM `accmast` WHERE custcode='$code'") or die(mysqli_error($conn));
$mgschool = mysqli_fetch_array($mfschool);

$emailid = $mgschool['email'];
//    $emailid = 'arish850@gmail.com';
$from = "rajcomputers@hotmail.com";
$to = $emailid;
$subject = 'INVOICE FROM MAHARASHTRA BHARATEEYA SHIKSHAN MANDAL';
//        $headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers = "From: MBSM\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message = 'Reply at :mbsmandal@gmail.com';
$message .= '<html><body>';
$message .= '<h1></h1>';
$message .= '</body></html>';

$message .= '<html><body>';

$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . 'MAHARASHTRA BHARATEEYA SHIKSHAN MANDAL' . "</td></tr>";

//        $message .= "<tr><td><strong>COPY LINK TO DOWNLOAD OR PRINT INVOICE:</strong> </td><td>" . 'http://apps4real.com/epiweb/invoice_print_mail.php?v_qx_a=' . 'siez' . '&yr_i=' . 'nddl' . '&v_qx_n=' . $dcode . '&yr_f=' . $dcode2 . '&v_qx_o=' . 'sief' . '&yr_u=' . 'mkln' . "</td></tr>";
$message .= "<tr><td><strong>COPY LINK TO DOWNLOAD OR PRINT INVOICE:</strong> </td><td><a href='http://techfar.in/epiweb/invoice_print_mail.php?v_qx_a=siez&yr_i=nddl&v_qx_n=$dcode&yr_f=$dcode2&v_qx_o=sief&yr_u=mkln'>Click To View Invoice</a></td></tr>";
$addURLS = $_POST['addURLS'];
if (($addURLS) != '') {
    $message .= "<tr><td><strong>URL To Change (additional):</strong> </td><td>" . strip_tags($addURLS) . "</td></tr>";
}
$curText = htmlentities($_POST['curText']);
if (($curText) != '') {
    $message .= "<tr><td><strong>CURRENT Content:</strong> </td><td>" . $curText . "</td></tr>";
}

$message .= "</table>";
$message .= "</body></html>";

if (mail($to, $subject, $message, $headers)) {
    echo "Mail Send To "." ".$emailid;
} else {
    echo "Invalid Email Id";
}