Using WhizBase to send ICQ messages

AID: 2634
  • Status: Published

1210 points

  • ByNurAzije
  • TypeTutorial
  • Posted on2010-03-09 at 06:51:23
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.]
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:

Select allOpen in new window




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-->
                                    
1:
2:
3:

Select allOpen in new window



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-->
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:

Select allOpen in new window



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]
                                    
1:
2:
3:
4:
5:
6:

Select allOpen in new window



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>]
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:

Select allOpen in new window



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]
]
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:

Select allOpen in new window



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]
]
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:

Select allOpen in new window



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]
                                    
1:
2:
3:
4:
5:
6:
7:

Select allOpen in new window



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

NurAzije is a PHP and WhizBase programmer, who at the time of article publication is working in partnership with WhizBase on several projects.
- - -
Asked On
2010-03-09 at 06:51:23ID2634
Tags

ICQ

,

pager

,

whizbase

,

subroutine

Topic

Scripting Languages

Views
685

Comments

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top Scripting Languages Experts

  1. mplungjan

    145,789

    Master

    0 points yesterday

    Profile
    Rank: Savant
  2. Ray_Paseur

    91,292

    Master

    0 points yesterday

    Profile
    Rank: Savant
  3. billprew

    63,376

    Master

    0 points yesterday

    Profile
    Rank: Genius
  4. RobSampson

    54,636

    Master

    0 points yesterday

    Profile
    Rank: Genius
  5. DaveBaldwin

    51,700

    Master

    2,000 points yesterday

    Profile
    Rank: Genius
  6. sedgwick

    43,950

    1,600 points yesterday

    Profile
    Rank: Genius
  7. leakim971

    43,184

    0 points yesterday

    Profile
    Rank: Genius
  8. dgofman

    36,400

    0 points yesterday

    Profile
    Rank: Genius
  9. COBOLdinosaur

    28,424

    0 points yesterday

    Profile
    Rank: Genius
  10. woolmilkporc

    24,200

    0 points yesterday

    Profile
    Rank: Genius
  11. ozo

    20,600

    0 points yesterday

    Profile
    Rank: Savant
  12. Qlemo

    19,984

    2,000 points yesterday

    Profile
    Rank: Genius
  13. chaituu

    19,100

    0 points yesterday

    Profile
    Rank: Sage
  14. tagit

    19,000

    0 points yesterday

    Profile
    Rank: Genius
  15. farzanj

    18,550

    0 points yesterday

    Profile
    Rank: Genius
  16. nap0leon

    15,094

    0 points yesterday

    Profile
    Rank: Sage
  17. paultomasi

    14,700

    0 points yesterday

    Profile
    Rank: Master
  18. StingRaY

    13,136

    0 points yesterday

    Profile
    Rank: Wizard
  19. jason1178

    13,044

    0 points yesterday

    Profile
    Rank: Genius
  20. HainKurt

    12,350

    0 points yesterday

    Profile
    Rank: Genius
  21. HonorGod

    11,600

    0 points yesterday

    Profile
    Rank: Genius
  22. ahoffmann

    11,136

    0 points yesterday

    Profile
    Rank: Genius
  23. basicinstinct

    10,800

    0 points yesterday

    Profile
    Rank: Genius
  24. leew

    10,030

    0 points yesterday

    Profile
    Rank: Savant
  25. ChrisStanyon

    9,864

    0 points yesterday

    Profile
    Rank: Sage

Hall Of Fame