<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=198245769678955&ev=PageView&noscript=1"/>

Using WhizBase to send ICQ messages

16. mart 2010, 12:00

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version.

In this tutorial I will use 3 files, pager.wbsp for the processing, email.wbsp for sending the messages and eng.ic as a language file.

Multilingual abilities

WhizBase has built-in multilingual support, but I will not use it in this tutorial because it is not supported in 5.1 version. So I will use the older method of including a language file.

In this language file we will define variables with the language content:

$wbsetv[l_send|Send the message to this ICQ number:]
$wbsetv[l_emne|Subject:]
$wbsetv[l_besked|Message:]
$wbsetv[l_ditnavn|Your name:]
$wbsetv[l_dinepost|Your email address:]
$wbsetv[l_sendbeskeden|Send the message]
$wbsetv[l_icqikkeudfyldt|You forgot to fill in the ICQ number that the message should be sent to.]
$wbsetv[l_ingenbesked|You forgot to write a message.]
$wbsetv[l_tilbage|Back]
$wbsetv[l_over450tegn|The message is too long. Maximum is 450 characters.]
$wbsetv[l_epostikkeudfyldt|You forgot to fill in your email address.]
$wbsetv[l_beskedenafsendt|The message has been sent.]

I've used $wbsetv to set language variables, now I will save this code as "lang.ic" and put it in lang folder I have created on webs root. I have that practice to separate language files from others.

Subroutine code

WhizBase supports subroutines (from version 5.1 on); it is something like a custom function available in some languages like VB. This is a powerful new technology in WhizBase which eases rapid application developments.

The code of a subroutine can be added in any place in WhizBase code, but it is preferably to put it after <!--WB_BeginTemplate--> so we can find it easily.

The syntax used for adding subroutines is:

<!--WB_BeginSub_subroutinename-->
subroutine code
<!--WB_EndSub-->

We will need to provide the subroutine name and the subroutine code, which is any set of WhizBase commands and code.

I will make a subroutine to show a back input with error message if the user makes any mistake in the form.

#* we define the pager Subroutine *#
<!--WB_BeginSub_pager-->
<html><head><title>Pager</title>
<style type=text/css>
body {background:white; font-family:helvetica; font-size:10pt; color:#000000} </style>
</head><body>
<center>$wbgetv[msg]<br />
<input type="button" onClick="history.go(-1)" value="&lt;&lt;&lt; $wbgetv[l_tilbage]">
</center>
</body></html>
<!--WB_EndSub-->

Call the language file

I will call the language file by wbrinc after defining which language I am using.

#* Please set here your language file *#
$wbsetv[lang|eng]
#**************************************#

#* We include the language file *#
$wbrinc[lang/$wbgetv[lang].ic]

As you see I am using relative paths but I can also use absolute paths, WhizBase supports both.

The Form

I will make a simple HTML form which submits the page to itself, I will put it in a variable so I can use it later where I need it.

$wbsetv[formular|<form action="" method="post"><table bgcolor="#cccccc" border="#000000" cellspacing="0" cellpadding="5">
<tr><td><font size="2" face="arial" color="#000000">$wbgetv[l_send]</td>
<td><input type="text" name="icqnummer" size="25" /></td>
<tr><td><font size="2" face="arial" color="#000000">$wbgetv[l_emne]</td>
<td><input type="text" name="emne" size="25" /></td>
<tr><td><font size="2" face="arial" color="#000000">$wbgetv[l_besked]</td>
<td><textarea name="besked" cols="25" rows="8" wrap"=virtual"></textarea></td>
<tr><td><font size="2" face="arial" color="#000000">$wbgetv[l_ditnavn]</td>
<td><input type="text" name="navn" size="25" /></td>
<tr><td><font size="2" face="arial" color="#000000">$wbgetv[l_dinepost]</td>
<td><input type="text" name="epost" size="25" /></td>
<tr><td>&nbsp;</td>
<td><font size="2" face="arial" color="#000000"><input type="submit" name="submit" value="$wbgetv[l_sendbeskeden]" />
</table></form>]

As I previously indicated, I am using language file's variables instead of text. This is to support multilingualism.

If this do that, if not do not, then do that or this

I made a simple validation IF conditions block, I am using this like that just to show how we can use complex IF conditions in WhizBase, but in real life I use JS for this type of validation - then there's no need to refresh the page to validate if an input is empty.

$wbif["$wbv[submit]"<>""|
$wbsetv[OK|1]
$wbif["$wbv[emne]"=""|$wbsetv[OK|0]$wbsetv[emne|No subject]|$wbsetv[emne|$wbv[emne]]]
$wbif["$wbv[navn]"=""|$wbsetv[OK|0]$wbsetv[navn|No name]|$wbsetv[navn|$wbv[navn]]]

#* If no ICQ number was specified... *#
$wbif["$wbv[icqnummer]"=""|$wbsetv[OK|0]$wbsetv[msg|$wbgetv[l_icqikkeudfyldt]] $wbsub[pager]|
#* If the user did not write a message... *#
$wbif[$wblen[$wbv[besked]]=0|$wbsetv[OK|0]$wbsetv[msg|$wbgetv[l_ingenbesked]] $wbsub[pager]|

#* The message body cannot contain more than 450 characters *#

$wbif[$wblen[$wbv[besked]]>450|$wbsetv[OK|0]$wbsetv[msg|$wbgetv[l_over450tegn]] $wbsub[pager]|

#* If the user did not specify his/her email address... *#

$wbif[$wblen[$wbv[epost]]=0|$wbsetv[OK|0]$wbsetv[msg|$wbgetv[l_epostikkeudfyldt]] $wbsub[pager]|]
]
]
]

#* Sending the message *#
$wbif[$wbgetv[OK]=1|$wbsetv[msg|$wbgetv[l_beskedenafsendt]] $wbsetv[to|$wbv[icqnummer]@pager.icq.com] $wbsetv[body|$wbv[besked]] $wbsetv[from|$wbgetv[navn] <$wbv[epost]>] $wbgeturl[email.wbsp?to=$wbesc[$wbgetv[to]]&from=$wbesc[$wbgetv[from]]&body=$wbesc[$wbgetv[body]]]|]
|
$wbgetv[formular]
]

The first IF is to check if I have submitted the form or I am coming to the site first time. If the submit is submitted I will go ahead with validation, if not I will show the form variable.

Then I have a number of conditions, if everything is OK I will go on and send the message to ICQ, if not I will define the error message from the language file and call the subroutine.

If everything is OK, I call a file I will create later by $wbgeturl, I named it email.wbsp, and will pass to it variables to, from, and body. All escaped by $wbesc function.

In case one of the conditions do not pass I call the subroutine pager by $wbsub[] to show the error message.

In case I did not submit a form yet it will skip all the conditions and show me the form we specified above before.

Now we will put all this together in one file:

[FormFields]
WB_Command=R
wb_showlogo=F
<!--WB_BeginTemplate-->
#* Please set here your language file *#
$wbsetv[lang|eng]
#**************************************#

#* We include the language file *#
$wbrinc[lang/$wbgetv[lang].ic]

#* we define the pager Subroutine *#
<!--WB_BeginSub_pager-->
<html><head><title>Pager</title>
<style type=text/css>
body {background:white; font-family:helvetica; font-size:10pt; color:#000000}
</style>
</head><body>
<center>$wbgetv[msg]<br />
<input type="button" onClick="history.go(-1)" value="&lt;&lt;&lt; $wbgetv[l_tilbage]">
</center>
</body></html>
<!--WB_EndSub-->

$wbsetv[formular|<form action="" method="post"><TABLE bgcolor="#cccccc" border="#000000" cellspacing="0" cellpadding="5">
<tr><td><font size="2" face="arial" color="#000000">$wbgetv[l_send]</td>
<td><input type="text" name="icqnummer" size="25" /></td>
<tr><td><font size="2" face="arial" color="#000000">$wbgetv[l_emne]</td>
<td><input type="text" name="emne" size="25" /></td>
<tr><td><font size="2" face="arial" color="#000000">$wbgetv[l_besked]</td>
<td><textarea name="besked" cols="25" rows="8" wrap"=virtual"></textarea></td>
<tr><td><font size="2" face="arial" color="#000000">$wbgetv[l_ditnavn]</td>
<td><input type="text" name="navn" size="25" /></td>
<tr><td><font size="2" face="arial" color="#000000">$wbgetv[l_dinepost]</td>
<td><input type="text" name="epost" size="25" /></td>
<tr><td>&nbsp;</td>
<td><font size="2" face="arial" color="#000000"><input type="submit" name="submit" value="$wbgetv[l_sendbeskeden]" />
</table></form>]

$wbif["$wbv[submit]"<>""|
$wbsetv[OK|1]
$wbif["$wbv[emne]"=""|$wbsetv[OK|0]$wbsetv[emne|No subject]|$wbsetv[emne|$wbv[emne]]]
$wbif["$wbv[navn]"=""|$wbsetv[OK|0]$wbsetv[navn|No name]|$wbsetv[navn|$wbv[navn]]]

#* If no ICQ number was specified... *#
$wbif["$wbv[icqnummer]"=""|$wbsetv[OK|0]$wbsetv[msg|$wbgetv[l_icqikkeudfyldt]] $wbsub[pager]|
#* If the user did not write a message... *#
$wbif[$wblen[$wbv[besked]]=0|$wbsetv[OK|0]$wbsetv[msg|$wbgetv[l_ingenbesked]] $wbsub[pager]|

#* The message body cannot contain more than 450 characters *#

$wbif[$wblen[$wbv[besked]]>450|$wbsetv[OK|0]$wbsetv[msg|$wbgetv[l_over450tegn]] $wbsub[pager]|

#* If the user did not specify his/her email address... *#

$wbif[$wblen[$wbv[epost]]=0|$wbsetv[OK|0]$wbsetv[msg|$wbgetv[l_epostikkeudfyldt]] $wbsub[pager]|]
]
]
]

#* Sending the message *#
$wbif[$wbgetv[OK]=1|$wbsetv[msg|$wbgetv[l_beskedenafsendt]] $wbsetv[to|$wbv[icqnummer]@pager.icq.com] $wbsetv[body|$wbv[besked]] $wbsetv[from|$wbgetv[navn] <$wbv[epost]>]
$wbgeturl[email.wbsp?to=$wbesc[$wbgetv[to]]&from=$wbesc[$wbgetv[from]]&body=$wbesc[$wbgetv[body]]]|]
|
$wbgetv[formular]
]

Save this file as default.wbsp.

Sending the email

Finally the message we want to send to some ICQ account we send it by email. In WhizBase sending emails are very simple. You just need four variables, three we have already passed in the $wbgeturl function and the fourth is set in this file.

[FormFields]
wb_mailserver=mail.localhost #* Here we define the outgoing mail server *#
wb_command=p
WB_To=$wbv{to}
WB_From=$wbv{from}
<!--WB_BeginTemplate-->
$wbv[body]

I hope this tutorial helped you learn more about WhizBase capabilities. Until the next article, have a good time.

For more information email me at: NurAzije [at] Gmail [dot] com Or visit WhizBase official site at www.whizbase.com