asp.net to php

B

Bllich

Hello,

I have a small web app (Default.aspx, Default.aspx.cs)
and one of my clients demands a PHP version.
I have no prior experience in PHP coding
so if anyone could help translate this two
small files, I would be very gratefull.

Kind regards,

Ivan
 
B

B

<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebPages.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>0001</title>
</head>
<body>
<form id="form1" runat="server">
&nbsp;<table border="0" style="position: static; width: 385px;
height: 403px;" align="center">
<tr>
<td style="width: 484px; height: 555px;">


<asp:Label ID="lblBegin" runat="server" Style="position:
static;" Text="0006" Font-Bold="True" Font-Italic="True" Font-
Names="Arial" Font-Size="10pt" Font-Strikeout="False" Font-
Underline="False" ForeColor="#C0C000" Width="340px"></asp:Label><br />
<br />

<asp:Label ID="lblName" runat="server" Height="3px"
Style="position: static;" Text="Your Name:" Font-Bold="True" Font-
Italic="True" Font-Names="Arial" Font-Size="10pt" Font-Strikeout="False"
Font-Underline="False" ForeColor="#C0C000"></asp:Label>
<asp:TextBox ID="txtName" runat="server" Style="position:
static;" Width="166px"></asp:TextBox><br />
<br />
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-
Names="Arial" Font-Size="10pt"
ForeColor="#C0C000" Style="position: static" Text="Your
Email:"></asp:Label>&nbsp;
<asp:TextBox ID="TextBox20" runat="server"
Style="position: static" Width="164px" TabIndex="1"></asp:TextBox><br />
<br />

<asp:Label ID="lblMessage" runat="server" Style="position:
static;" Text="Message:" Font-Bold="True" Font-Italic="True" Font-
Names="Arial" Font-Size="10pt" Font-Strikeout="False" Font-
Underline="False" ForeColor="#C0C000"></asp:Label><br />
<br />
<asp:TextBox ID="txtBody" runat="server"
Style="position: static;" TabIndex="2" Width="337px" Enabled="False">0007
</asp:TextBox><br />
<br />

<asp:Label ID="lblPleaseEnter" runat="server" Style="position:
static;" Font-Bold="True" Font-Italic="True" Font-Names="Arial" Font-
Size="10pt" Font-Strikeout="False" Font-Underline="False"
ForeColor="#C0C000" Width="308px"></asp:Label><br />
<br />
<asp:Label ID="Label2" runat="server" Font-
Bold="True" Font-Names="Arial" Font-Size="10pt"
ForeColor="#C0C000" Style="position: static" Text="Friend's
Name:"></asp:Label>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
<asp:Label ID="Label3" runat="server" Font-
Bold="True" Font-Names="Arial" Font-Size="10pt"
ForeColor="#C0C000" Style="position: static" Text="Friend's
Email address:"></asp:Label><br />
<asp:TextBox ID="TextBox10" runat="server"
Style="position: static" Visible="False" TabIndex="3" Width="148px">
</asp:TextBox>
<asp:TextBox ID="TextBox0" runat="server"
Style="position: static;" Width="180px" TabIndex="3" Visible="False">
</asp:TextBox><br />
<asp:TextBox ID="TextBox11" runat="server"
Style="position: static" Visible="False" TabIndex="3" Width="148px">
</asp:TextBox>
<asp:TextBox ID="TextBox1" runat="server"
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
<asp:TextBox ID="TextBox12" runat="server"
Style="position: static" Visible="False" TabIndex="3" Width="148px">
</asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
<asp:TextBox ID="TextBox13" runat="server"
Style="position: static" Visible="False" TabIndex="3" Width="148px">
</asp:TextBox>
<asp:TextBox ID="TextBox3" runat="server"
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
<asp:TextBox ID="TextBox14" runat="server"
Style="position: static" Visible="False" TabIndex="3" Width="148px">
</asp:TextBox>
<asp:TextBox ID="TextBox4" runat="server"
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
<asp:TextBox ID="TextBox15" runat="server"
Style="position: static" Visible="False" TabIndex="3" Width="148px">
</asp:TextBox>
<asp:TextBox ID="TextBox5" runat="server"
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
<asp:TextBox ID="TextBox16" runat="server"
Style="position: static" Visible="False" TabIndex="3" Width="148px">
</asp:TextBox>
<asp:TextBox ID="TextBox6" runat="server"
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
<asp:TextBox ID="TextBox17" runat="server"
Style="position: static" Visible="False" TabIndex="3" Width="148px">
</asp:TextBox>
<asp:TextBox ID="TextBox7" runat="server"
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
<asp:TextBox ID="TextBox18" runat="server" Style="position:
static" Visible="False" TabIndex="3" Width="148px"></asp:TextBox>
<asp:TextBox ID="TextBox8" runat="server"
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
<asp:TextBox ID="TextBox19" runat="server" Style="position:
static" Visible="False" TabIndex="3" Width="148px"></asp:TextBox>
<asp:TextBox ID="TextBox9" runat="server"
Style="position: static;" TabIndex="3" Width="180px" Visible="False">
</asp:TextBox><br />
<br />


<asp:Label ID="lblEnd" runat="server" Style="position: static;"
Text="0008" Width="344px" Font-Bold="True" Font-Italic="True" Font-
Names="Arial" Font-Size="10pt" Font-Strikeout="False" Font-
Underline="False" ForeColor="#C0C000"></asp:Label><br />
<br />
<asp:CheckBox Visible="true" ID="chkSpam"
runat="server" Height="19px" Style="position: static;" Text="0009"
TabIndex="4" Width="344px" Font-Bold="True" Font-Italic="True" Font-
Names="Arial" Font-Size="10pt" Font-Strikeout="False" Font-
Underline="False" ForeColor="#C0C000" /><br />
<br />

<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Style="position: static;" Text="Send"
Width="116px" TabIndex="5" />&nbsp;
<asp:Button ID="btnClear" runat="server"
OnClick="btnClear_Click" Style="position: static;" Text="Clear"
TabIndex="6" Width="51px" /></td>
</tr>
</table>
<asp:HiddenField ID="txtCodedString2" runat="server"
Value="0003" />

<asp:Label ID="lblMin" runat="server" Style="left: 190px;
position: static; top: -37px" Text="0004" Visible="False"></asp:Label>
<asp:Label ID="lblMax" runat="server" Style="left: 190px;
position: static; top: -37px" Text="0005" Visible="False"></asp:Label>
<asp:HiddenField ID="txtCodedString" runat="server"
Value="0002" />
<br />


</form>
</body>
</html>
 
B

B

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Mail;

namespace WebPages
{
public partial class Default : System.Web.UI.Page
{
ArrayList lstEmails = new ArrayList();
ArrayList lstNames = new ArrayList();

protected void Page_Load(object sender, EventArgs e)
{
txtName.Focus();
lblPleaseEnter.Text = "Please enter at least " + lblMin.Text
+ " friend's Email addresses:";
lstEmails.Add(TextBox0);
lstEmails.Add(TextBox1);
lstEmails.Add(TextBox2);
lstEmails.Add(TextBox3);
lstEmails.Add(TextBox4);
lstEmails.Add(TextBox5);
lstEmails.Add(TextBox6);
lstEmails.Add(TextBox7);
lstEmails.Add(TextBox8);
lstEmails.Add(TextBox9);
lstNames.Add(TextBox10);
lstNames.Add(TextBox11);
lstNames.Add(TextBox12);
lstNames.Add(TextBox13);
lstNames.Add(TextBox14);
lstNames.Add(TextBox15);
lstNames.Add(TextBox16);
lstNames.Add(TextBox17);
lstNames.Add(TextBox18);
lstNames.Add(TextBox19);
for (int i = 0; i < int.Parse(lblMax.Text); i++)
{
((TextBox)lstEmails).Visible = true;
((TextBox)lstNames).Visible = true;
}

lblPleaseEnter.Text = "Please invite at least " + lblMin.Text
+ " of your friends";
}

protected void Button1_Click(object sender, EventArgs e)
{
if ((txtName.Text.Trim() == "") || (TextBox20.Text.Trim() ==
""))
{
Response.Write("<script>alert('Please enter your name and
email address!');</script>");
txtName.Focus();
}
else
{
ArrayList enteredEmails = new ArrayList();
for (int i = 0; i < int.Parse(lblMax.Text); i++)
{
if (((TextBox)lstEmails).Text.Trim() != "")
{
if (!enteredEmails.Contains(((TextBox)lstEmails
).Text.Trim()))
{
if (((TextBox)lstNames).Text.Trim() == "")
{
Response.Write("<script>alert('Please add
names with email addresses!');</script>");
return;
}
else
enteredEmails.Add(((TextBox)lstEmails
).Text.Trim());
}
else
{
if (lblMin.Text == "1")
{
Response.Write("<script>alert('Please add
at least 1 email address without repeating!');</script>");
return;
}
else
{
Response.Write("<script>alert('Please add
at least " + lblMin.Text + " different email addresses!');</script>");
return;
}
}
}
}
if (enteredEmails.Count < int.Parse(lblMin.Text))
{
if (lblMin.Text == "1")
{
Response.Write("<script>alert('Please add at
least one name and email address without repeating!');</script>");
return;
}
else
{
Response.Write("<script>alert('Please add at
least " + lblMin.Text + " different names and email addresses!');
</script>");
return;
}
}
else
{
string[] txtEmails = new string[enteredEmails.Count];
for (int i = 0; i < enteredEmails.Count; i++)
txtEmails = enteredEmails.ToString();
if (chkSpam.Visible)
{
if (chkSpam.Checked)
{
string strReturn = SendInvitations
(txtName.Text, txtBody.Text, txtEmails, txtCodedString.Value, lstNames);
if (strReturn == "")
if (decodeThankYou(txtCodedString2.Value)
[enteredEmails.Count - int.Parse(lblMin.Text)].ToString().Substring(0,4)
== "http")
Response.Redirect(decodeThankYou
(txtCodedString2.Value)[enteredEmails.Count - int.Parse
(lblMin.Text)].ToString());
else
try
{
Server.Transfer(decodeThankYou
(txtCodedString2.Value)[enteredEmails.Count - int.Parse
(lblMin.Text)].ToString());
}
catch
{ }
else
Response.Write("<script>alert
('"+strReturn+"');</script>");
}
else
{
Response.Write("<script>alert('Please confirm
that you are not using this for spam!');</script>");
}
}
else
{
string strReturn = SendInvitations(txtName.Text,
txtBody.Text, txtEmails, txtCodedString.Value, lstNames);
if (strReturn == "")
if (decodeThankYou(txtCodedString2.Value)
[enteredEmails.Count - int.Parse(lblMin.Text)].ToString().Substring(0, 4)
== "http")
Response.Redirect(decodeThankYou
(txtCodedString2.Value)[enteredEmails.Count - int.Parse
(lblMin.Text)].ToString());
else
Server.Transfer(decodeThankYou
(txtCodedString2.Value)[enteredEmails.Count - int.Parse
(lblMin.Text)].ToString());
else
Response.Write("<script>alert('" + strReturn
+ "');</script>");
}
}
}
}

protected void btnClear_Click(object sender, EventArgs e)
{
for (int i = 0; i < int.Parse(lblMax.Text); i++)
((TextBox)lstEmails).Text = "";
}

private string SendInvitations(string name, string body, string[]
emails, string codedString, ArrayList friend)
{
try
{
DecodeData dd = decode(codedString);
SmtpClient sc;
if (dd.smtp == "default")
sc = new SmtpClient();
else
sc = new SmtpClient(dd.smtp, dd.port);

if (dd.authUser != "")
{
sc.UseDefaultCredentials = false;
sc.Credentials = new NetworkCredential(dd.authUser,
dd.authPass);
}
try
{
for (int i = 0; i < emails.Length; i++)
{
if (dd.sender == "Visitor")
dd.sender = TextBox20.Text;
sc.Send(dd.sender, emails, dd.subject.Replace
("#VISITORNAME", name).Replace("#FRIENDNAME", ((TextBox)friend).Text),
body);
if (dd.referral)
sc.Send(dd.sender, dd.email, "Tell A Friend
referral report", "Email sent form " + name +" ("+ TextBox20.Text+") to
" + ((TextBox)friend).Text +" (" + emails + ")\n\nSubject:\r\n" +
dd.subject.Replace("#VISITORNAME", name).Replace("#FRIENDNAME",
((TextBox)friend).Text) + "\r\n\r\n" + "Body:\r\n" + body);
}
return "";
}
catch
{
return "Server error. Please check if all the
addresses really exist.";
}
}
catch
{
return "Server error. Please try again later.";
}
}

private DecodeData decode(string codedString)
{
DecodeData dd = new DecodeData();
dd.sender = codedString.Substring(0, codedString.IndexOf
("###"));
codedString = codedString.Substring(codedString.IndexOf
("###") + 3);
dd.subject = codedString.Substring(0, codedString.IndexOf
("###"));
codedString = codedString.Substring(codedString.IndexOf
("###") + 3);
if (codedString.Substring(0, codedString.IndexOf("###")) ==
"true")
dd.referral = true;
else
dd.referral = false;
codedString = codedString.Substring(codedString.IndexOf
("###") + 3);
dd.smtp = codedString.Substring(0, codedString.IndexOf
("###"));
codedString = codedString.Substring(codedString.IndexOf
("###") + 3);
dd.port = int.Parse(codedString.Substring(0,
codedString.IndexOf("###")));
codedString = codedString.Substring(codedString.IndexOf
("###") + 3);
if (codedString.IndexOf("###") == -1)
{
dd.email = codedString.Substring(0);
dd.authUser = "";
dd.authPass = "";
}
else
{
dd.email = codedString.Substring(0, codedString.IndexOf
("###"));
codedString = codedString.Substring(codedString.IndexOf
("###") + 3);
dd.authUser = codedString.Substring(0,
codedString.IndexOf("###"));
codedString = codedString.Substring(codedString.IndexOf
("###") + 3);
dd.authPass = codedString.Substring(0);
}
return dd;
}

private ArrayList decodeThankYou(string codedString)
{
ArrayList al = new ArrayList(int.Parse(lblMax.Text) -
int.Parse(lblMin.Text) + 1);
for (int i = 0; i < int.Parse(lblMax.Text) - int.Parse
(lblMin.Text) + 1; i++)
{
al.Add(codedString.Substring(0, codedString.IndexOf
("###")));
codedString = codedString.Substring(codedString.IndexOf
("###") + 3);
}
return al;
}

protected void txtName_TextChanged(object sender, EventArgs e)
{

}

}

class DecodeData
{
private string _sender;
private string _subject;
private bool _referral;
private string _smtp;
private int _port;
private string _email;
private string _authUser;
private string _authPass;

public string sender
{
get { return _sender; }
set { _sender = value; }
}

public string subject
{
get { return _subject; }
set { _subject = value; }
}

public bool referral
{
get { return _referral; }
set { _referral = value; }
}

public string smtp
{
get { return _smtp; }
set { _smtp = value; }
}

public int port
{
get { return _port; }
set { _port = value; }
}

public string email
{
get { return _email; }
set { _email = value; }
}

public string authUser
{
get { return _authUser; }
set { _authUser = value; }
}

public string authPass
{
get { return _authPass; }
set { _authPass = value; }
}
}
}
 
L

Lasse Vågsæther Karlsen

Bllich said:
Hello,

I have a small web app (Default.aspx, Default.aspx.cs)
and one of my clients demands a PHP version.
I have no prior experience in PHP coding
so if anyone could help translate this two
small files, I would be very gratefull.

Kind regards,

Ivan

What happens if there is a bug in the translation, or you need to expand
the page? I mean, provided someone translates the files for you, who
will maintain them?

To be honest, if your client demands a PHP version, you're going to have
to either learn PHP yourself, or form a maintenance relationship with
someone who can help you in the long term, otherwise you're going to
have problems down the road.

Never promise more than you can deliver. Sometimes the best answer is
"no, can't do that".
 
B

B

What happens if there is a bug in the translation, or you need to expand
the page? I mean, provided someone translates the files for you, who
will maintain them?

To be honest, if your client demands a PHP version, you're going to have
to either learn PHP yourself, or form a maintenance relationship with
someone who can help you in the long term, otherwise you're going to
have problems down the road.

Never promise more than you can deliver. Sometimes the best answer is
"no, can't do that".

a simple comment form a simple man.

if you cannot help on the subject please do not post.

this is just a little web page that will never be changed in
any way, just needs a php version also...

it is a part of a big winForm program that generates a lot
of stuff.

I wanted to ask somebody to give me a hand, I will debug on
eclipse/apache and make it work afterwards..

I don't like php to be honest, but I clearly asked for translation, not for
comment.

Regards,

Ivan
 
L

Lasse Vågsæther Karlsen

B said:
a simple comment form a simple man.

if you cannot help on the subject please do not post.

If this is, as you say, something that will never be changed in any way,
then I agree, my post probably didn't help.

But having the experience of maintaining such a never-changing simple
application, I do know that things change, regardless of what you think
now or the client says. A client that says "We will never require a
change to this application" is, in my experience, wrong.

At some point your client will change hosting firm or platform, and need
just this small tweak to get it running again because of a new SMTP
server or similar, that require slightly different authentication
semantics or whatnot. Perhaps a new version of PHP is in use, which
doesn't support the specific version of the library your code is made
against.

If you, at that point, still doesn't have the necessary PHP knowledge,
doing that will entail you going back online to find someone that can
fix your own application.

Personally I would never have that kind of dependency on some unknown
3rd party that may or may not be able to help you in the future.

My tip was to get the required knowledge, find someone you can form a
relationship will that does, or give it up.

It might be contrary to what you want, but I still think my hint was
helpful, in the general sense, and I'm not just answering you, I'm also
answering that unknown someone that finds yours and mine post in the
future wondering about the same issue.
this is just a little web page that will never be changed in
any way, just needs a php version also...

it is a part of a big winForm program that generates a lot
of stuff.

I wanted to ask somebody to give me a hand, I will debug on
eclipse/apache and make it work afterwards..

I don't like php to be honest, but I clearly asked for translation, not for
comment.

Well, I'm sorry to say this, but what I think is helpful might not
coincide with your opinion. That will not stop me from posting though.
 
B

B

It might be contrary to what you want, but I still think my hint was
helpful, in the general sense, and I'm not just answering you, I'm also
answering that unknown someone that finds yours and mine post in the
future wondering about the same issue.

if that someone is in my situation then you are not helping him eather. ;)
just kidding..

ok,
I can figure out PHP in a week or two, but I don't have that time now.

This is a piece of cake job and that's the reason why it is posted on news
here.

I have many clients and lines of code written so I know everything you're
referring to.. I could probably learn everything I need from the PHP code
of this same program, so small changes would be fixed along the way.

On other hand, I will have the time to study PHP in future, but I don't
have it now. I will learn it for a few months, but I cannot do it now.
But I need the translation now. If some changes then come along the way,
I'll be ready. Get it?

As for smtp, nothing changes, both ways with or without auth are in the
existing code, so ... really, nothing changes. You cannot figure out the
app completely because the numbers 0001, 0002 ... are generated with other
program.

nhf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

PHP versus ASP.net 3
vshost 3
Capturing image of a hidden control (webbrowser)... 1
php to asp.net 1
Simple PDF library 1
Using PHP in a .Net environment? 6
6 php lines 2 asp 1
C# + PHP ? 1

Top