<?php

header("Content-type: text/vnd.Wap.wml");
header("Cache-Control: no-store, no-cache, must-revalidate");
echo("<?xml version=\"1.0\"?>");
echo "<!DOCTYPE wml PUBLIC \"-//WapFORUM//DTD WML 1.1//EN\"". " \"http://www.Wapforum.org/DTD/wml_1.1.xml\">";
?>
<wml>
<?php
include("config.php");
include("core.php");
connectdb();
$action = $_GET["action"];
$sid = $_GET["sid"];
$who = $_GET["who"];
if(islogged($sid)==false)
{
    echo "<card id=\"main\" title=\"your site nam\">";
      echo "<p align=\"center\">";
      echo "You are not logged in<br/>";
      echo "Or Your session has been expired<br/><br/>";
      echo "<a href=\"index.php\">Login</a>";
      echo "</p>";
      echo "</card>";
      echo "</wml>";
      exit();
}
$uid = getuid_sid($sid);
if(isbanned($uid))
    {
        echo "<card id=\"main\" title=\"your site nam\">";
      echo "<p align=\"center\">";
      echo "<img src=\"images/notok.gif\" alt=\"x\"/><br/>";
      echo "You are <b>Banned</b><br/>";
      $banto = mysql_fetch_array(mysql_query("SELECT timeto FROM ibwf_penalties WHERE uid='".$uid."' AND penalty='1'"));
      $remain = $banto[0]- time();
      $rmsg = gettimemsg($remain);
      echo "Time to finish your penalty: $rmsg<br/><br/>";
      //echo "<a href=\"index.php\">Login</a>";
      echo "</p>";
      echo "</card>";
      echo "</wml>";
      exit();
    }


if($action=="chapel")
{
  addonline(getuid_sid($sid),"Wap Chapel","");
  echo "<card id=\"main\" title=\"Chapel\">";
  echo "<p align=\"center\">";
  echo "<u><b>your site nam Chapel</b></u><br/>";
  echo "<img src=\"smilies/pop.gif\" alt=\"*\"/><br/>";
  echo "Welcome To your site nam Wap Online Chapel. <br/>";
  echo "Here You Can Get Married Online.<br/><br/>";
  $couple = mysql_fetch_array(mysql_query("SELECT who, partner, req FROM couple WHERE partner='".$uid."'"));
  if($couple[2]=='1')
  {
  $unick = getnick_uid($couple[1]);
  $nick = getnick_uid($couple[0]);
  $nopl = mysql_fetch_array(mysql_query("SELECT sex FROM ibwf_users WHERE id='".$couple[0]."'"));
   if($nopl[0]=='M')
  {
    $usex = "Husband";
  }else if($nopl[0]=='F'){
    $usex = "Wife";
  }else{
    $usex = "Partner";
  }

  echo "<b>Marriage Between $unick and $nick</b><br/><br/>";
  echo "Your Only one step away from Marrying your true love. All you need to do is read and accept the vows below<br/><br/>";
  echo "$unick, do you take $nick to be your wedded $usex to live together in marriage.<br/>";
  echo "Do you promise to love, comfort, honor and keep <br/>";
  echo "For better or worse, for richer or poorer, in sickness and in health.<br/>";
  echo "And forsaking all others, be faithful only to<br/>";
  echo "so long as you both shall live?<br/><br/>";
  echo "<a href=\"chapel.php?action=reqacc&amp;sid=$sid&amp;who=$couple[0]\">I Do</a><br/>";
  echo "<a href=\"chapel.php?action=reqref&amp;sid=$sid&amp;who=$couple[1]\">Sorry, I Dont</a><br/><br/>";

  }else{

  echo "To Begin Please Enter The Nickname Of The User You Want to Marry, A PM will be sent<br/>";
  echo "To them asking if they wish to marry you and inviting them to the chapel to complete the service.<br/>";
  echo "By Sending the message below you agree to the below vows also<br/><br/>";
  $nick = getnick_sid($sid);
  echo "$nick, do you take [user] to be your wedded [wife/husband] to live together in marriage.<br/>";
  echo "Do you promise to love, comfort, honor and keep [him/her]<br/>";
  echo "For better or worse, for richer or poorer, in sickness and in health.<br/>";
  echo "And forsaking all others, be faithful only to<br/>";
  echo "[him/her] so long as you both shall live?<br/><br/>";
  $whonick = getnick_uid($who);
  echo "Username:<br/><input name=\"usr\" maxlength=\"25\"/><br/>";
  echo "<anchor>I Do<go href=\"chapel.php?action=getreq&amp;sid=$sid\" method=\"post\">";
  echo "<postfield name=\"usr\" value=\"$(usr)\"/></go></anchor><br/><br/>";
  }
  echo "<a href=\"chapel.php?action=div&amp;sid=$sid\">Divorce!</a><br/>";
  echo "<small>Please Note: This Marriage IS NOT Legally Binding</small><br/>";
  echo "<a href=\"index.php?action=main&amp;sid=$sid\">Main Menu</a>";
  echo "</p>";
  echo "</card>";
}

else if($action=="getreq")
{
  addonline(getuid_sid($sid),"Wap Chapel","");
  echo "<card id=\"main\" title=\"Chapel\">";
  echo "<p align=\"center\">";
  $usr = $_POST["usr"];
  $who = getuid_nick($usr);

$we = mysql_fetch_array(mysql_query("SELECT who, partner, accept, req FROM couple WHERE who='".$uid."'"));
if($we[2]=='1')
       {
        $wer = getnick_uid($we[1]);
        echo "You're already married to $wer!<br/><br/>";
        echo "<a href=\"index.php?action=main&amp;sid=$sid\">Main Menu</a>";
        echo "</p>";
        echo "</card>";
        echo "</wml>";
        exit();
       }

$me = mysql_fetch_array(mysql_query("SELECT who, partner, accept, req FROM couple WHERE partner='".$uid."'"));
if($me[2]=='1')
       {
        $sya = getnick_uid($me[0]);
        echo "You're already married to $sya!<br/><br/>";
        echo "<a href=\"index.php?action=main&amp;sid=$sid\">Main Menu</a>";
        echo "</p>";
        echo "</card>";
        echo "</wml>";
        exit();
       }

    if($who==0)
    {
      echo "User Does Not exist<br/>";
    }else if($who==$uid)
    {
      echo "lol.. Why do you wanna marry yourself? PMPL..<br/><br/>";
    }else{

  $whonick = getnick_uid($who);
$couple = mysql_fetch_array(mysql_query("SELECT who, partner, accept, req FROM couple WHERE partner='".$who."'"));
     if($couple[2]=='1')
       {
         $sya = getnick_uid($couple[0]);
         echo "$whonick is already married to $sya. Try your luck to other users!<br/><br/>";
       }
    
  $byuid = getuid_sid($sid);
  $tm = time();
  if((!isignored($byuid, $who))&&(!istrashed($byuid)))
    {
  $unick = getnick_uid($uid);
  $pmtext = "-kisslips- $unick would like to To ask For your hand in marriage, to accept or refuse visit the chapel link in the site main page [small][i]p.s: this is an automatic pm[/i][/small]";
  $res = mysql_query("INSERT INTO ibwf_private SET text='".$pmtext."', byuid='".$byuid."', touid='".$who."', timesent='".$tm."'");
     }else{
    $res = true;
     }  
  if($res)
  {
    echo "<u><b>your site nam Wap Chapel</b></u>";
  echo "<br/>Here You Can Get Married Online.<br/><br/>";
  echo "Marriage Request was sent successfully to $whonick<br/>";
  echo "Please wait for a response<br/><br/>";
  echo "<small>Please Note: This Marriage IS NOT Legally Binding</small><br/>";
  mysql_query("INSERT INTO couple SET req='1', partner='".$who."', who='".$uid."', time='".time()."'");
  }else{
    echo "Can't Send your Request to $whonick<br/><br/>";
  }
}

  echo "<a href=\"index.php?action=main&amp;sid=$sid\">Main Menu</a>";
  echo "</p>";
  echo "</card>";
}
else if($action=="reqacc")
{
  $who = $_GET["who"];
  addonline(getuid_sid($sid),"Wap Chapel","");
  echo "<card id=\"main\" title=\"Chapel\">";
  echo "<p align=\"center\">";
  echo "<b>your site nam Wap Chapel</b><br/><br/>";
  $nick = getnick_uid($who);
  echo "Congratulations! Your Marriage To $nick Is Complete. We Hope You Are Both Happy in your new Relationship.<br/><br/>";
  $byuid = getuid_sid($sid);
  $msg = "Congratulations! Your Marriage To $nick Is Complete. We Hope You Are Both Happy in your new Relationship [small][i]p.s: this is an automatic pm[/i][/small]";
  mysql_query("INSERT INTO ibwf_private SET text='".$msg."', byuid='".$byuid."', touid='".$who."', unread='1', timesent='".time()."'");
  mysql_query("UPDATE couple SET accept='1', req='2', joined='".time()."' WHERE partner='".$uid."' AND who='".$who."'");

  $nick = getnick_uid($who);
  $byuid = getuid_sid($sid);
  $unick = getnick_uid($byuid);
  $fmsg = "$nick and I just get married!";
  mysql_query("UPDATE ibwf_users SET shouts='".$fmsg."' WHERE id='".$byuid."'");
  echo "<small>Please Note: This Marriage IS NOT Legally Binding</small><br/>";
  echo "<a href=\"index.php?action=main&amp;sid=$sid\">Main Menu</a>";
  echo "</p>";
  echo "</card>";
}

else if($action=="reqref")
{
  $who = $_GET["who"];
  addonline(getuid_sid($sid),"Wap Chapel","");
  echo "<card id=\"main\" title=\"Chapel\">";
  echo "<p align=\"center\">";
  echo "<b>your site nam Wap Chapel</b><br/><br/>";
  $nick = getnick_uid($who);
  echo "Ohh.. We are sorry to hear about Your Decision, your proposer has been informed of your decison, thank you.<br/><br/>";
  $byuid = getuid_sid($sid);
  $couple = mysql_fetch_array(mysql_query("SELECT who, partner FROM couple WHERE partner='".$uid."'"));
  $msg = "Sorry, $nick has refused your proposal. we are sorry to hear this, but feel free to try again at a later date [small][i]p.s: this is an automatic pm[/i][/small]";
  mysql_query("INSERT INTO ibwf_private SET text='".$msg."', byuid='".$byuid."', touid='".$couple[0]."', unread='1', timesent='".time()."'");
$res = mysql_query("DELETE FROM couple WHERE partner='".$uid."' AND who='".$couple[0]."'");
  echo "<small>Please Note: This Marriage IS NOT Legally Binding</small><br/>";
  echo "<a href=\"index.php?action=main&amp;sid=$sid\">Main Menu</a>";
  echo "</p>";
  echo "</card>";
}else if($action=="div")
{
addonline(getuid_sid($sid),"Wap Chapel","");
  echo "<card id=\"main\" title=\"Chapel\">";
  echo "<p align=\"center\">";
  $me = mysql_fetch_array(mysql_query("SELECT who, partner, accept, req FROM couple WHERE who='".$uid."'"));
  $you = mysql_fetch_array(mysql_query("SELECT who, partner, accept, req FROM couple WHERE partner='".$uid."'"));

  $nick = getnick_uid($me[0]);
  $unick = getnick_uid($you[1]);

if($uid==$me[0])
{
  echo "Do you really want to divorce $unick? <br/>-----<br/>";
}

if($uid==$you[1])
{
  echo "Do you really want to divorce $nick? <br/>-----<br/>";
}

$wed = mysql_fetch_array(mysql_query("SELECT partner FROM couple WHERE who='".$uid."'"));
if (!$wed)
{
$wed = mysql_fetch_array(mysql_query("SELECT who FROM couple WHERE partner='".$uid."'"));
}
$who = $wed[0];

echo "<anchor>Yes";
echo "<go href=\"chapel.php?action=sep&amp;sid=$sid\" method=\"post\">";  
echo "<postfield name=\"who\" value=\"$(who)\"/>";
echo "</go></anchor><br/>";
echo "<a href=\"chapel.php?action=chapel&amp;sid=$sid\">No</a><br/>----<br/>";
  echo "<a href=\"index.php?action=main&amp;sid=$sid\">Main Menu</a>";
  echo "</p>";
  echo "</card>";
}else if($action=="sep")
{
addonline(getuid_sid($sid),"Wap Chapel","");
  echo "<card id=\"main\" title=\"Chapel\">";
  echo "<p align=\"center\">";
$who = $_POST["who"];
$uid = getuid_sid($sid);
$res = mysql_query("DELETE FROM couple WHERE who='".$uid."' OR partner='".$uid."'");

if($res)
{
$nick = getnick_uid($who);
echo "You have successfully divorced $nick!<br/><br/>";
}else{
echo "Database Error!<br/><br/>";

}
  echo "<a href=\"index.php?action=main&amp;sid=$sid\">Main Menu</a>";
  echo "</p>";
  echo "</card>";
}else{

  addonline(getuid_sid($sid),"Lost in Chapel lol","");
  echo "<card id=\"main\" title=\"Chapel\">";
  echo "<p align=\"center\">";
  echo "I don't know how did you get into here, but there's nothing to show<br/><br/>";
  echo "<a href=\"index.php?action=main&amp;sid=$sid\">Main Menu</a>";
  echo "</p></card>";
}

?>

</wml>