[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
Poco Forums • View topic - Create QR codes from address book

Create QR codes from address book

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

Create QR codes from address book

Postby MarkB » Sun Aug 26, 2012 3:51 am

Generate QR codes from contacts.

Address books are not modified.

Tested with PocoMail 4.8, Windows 7, Firefox 14, and various online barcode readers -- but not :( with a smart phone. I'm guessing about which options (e.g., size) are desirable here.

This script ignores address book groups.

Code: Select all
{ QRCodeGen
{ ---------
{
{ PURPOSE:
{
{   Generate a QR code from a PocoMail address-book contact.
{
{ INSTRUCTIONS:
{
{    Run the script. Select an address book, a contact, and a barcode format.
{    Available formats are
{      * email address
{      * contact information (name, email) in meCard format
{      * contact information (name, email) in vCard format
{
{ SETUP:
{
{    Change the default address book in line 1 to suit yourself.
{
{    Under GetBookName: optionally, if you have just one address book, comment-out the
{    InputBox line and use instead
{         Set $bookname "MyBook"
{
{ NOTES:
{
{    The QR code displays in the user's default browser. Internet Explorer 9 offers to
{    open the image in your default viewer.
{
{    The script saves a tiny HTML file called QRCodeGen.htm in the Scripts folder, to
{    make use of the encodeURIComponent function in JavaScript. The default browser
{    must have JavaScript enabled.
{
{    The following barcode options are hard-coded in the script: barcode size, error
{    correction (L), character encoding (UTF-8).
{
{    About privacy: Contact info is submitted to Google's Chart API. Google keeps the
{    data for "no more than two weeks" and only for "debugging purposes"
{    ([URL removed because of forum limit on number of URLs]; and
{    elsewhere; accessed 2012-08-22). Connection is HTTP.
{
{    MarkB, 2012


Set $defaultbook "Address"


:GetBookName
{  Get the name of an address book
{  Define $bookname, $bookfile
InputBox $bookname "Please select an address book%addressbooks%" $defaultbook
Set $bookfile $addresspath
AddStrings $bookfile $bookname ".ini"
FileExists &flag $bookfile
If &flag Then GetFile
MessageBox "Can't find that address book"
Goto GetBookName


:GetFile
{  Read in the address book
{  Define $rawcontacts
OpenBody $rawcontacts $bookfile


{ Compile a list of contacts for display
{   $rawcontacts is a multi-line variable, each line of which is a CSV that depicts
{   either a single contact or a contact group.
{   $optionlist is a list in HTML <option></option> form.
{   For each line in $rawcontacts
{     Ignore if it is a group
{     Extract contact's name and email address
{     Enter that name+address in $optionlist
Set $optionlist ""
Set #i 0
Set #count 0
LineCount #max $rawcontacts
Dec #max
:ContactsLoop
If #i > #max Then ExitContactsLoop
GetLine $line #i $rawcontacts
ReadCSV $entry $line
LineCount #n $entry
If #n < 8 Then EndContactsLoop  { Bad contact
GetLine $nickname 0 $entry
GetLine $displayas 1 $entry
GetLine $emailaddress 2 $entry
{GetLine $note 3 $entry
GetLine $firstname 5 $entry
GetLine $middlename 6 $entry
GetLine $lastname 7 $entry
Trim $nickname
Trim $displayas
Trim $emailaddress
CharCount #nchars $emailaddress
If #nchars < 8 Then EndContactsLoop  { Bad contact
If #nchars > 80 Then EndContactsLoop  { Bad contact
If "@" ^ $emailaddress Then CheckDot
Goto EndContactsLoop  { Bad contact
:CheckDot
If "." ^ $emailaddress Then GetFull
Goto EndContactsLoop  { Bad contact
:GetFull
{ Get full name
Set $fullname ""
AddStrings $fullname $firstname " " $middlename " " $lastname
:CleanSpaces
StringPos #pos "  " $fullname  { That's a double space
If #pos < 1 Then DoneDouble
ChopString $fullname #pos 1
Goto CleanSpaces
:DoneDouble
Trim $fullname
If $fullname ! "" Then GotFirstMidLast
Set $fullname $nickname
If $fullname ! "" Then DoneName
Set $fullname $displayas
If $fullname ! "" Then DoneName
Set $fullname $emailaddress
If $fullname ! "" Then DoneName
Goto EndContactsLoop  { Bad contact
:GotFirstMidLast
If $nickname = "" Then DoneName
If $nickname = $firstname Then DoneName
AddStrings $fullname " (" $nickname ")"
:DoneName
{ Add entry to $optionlist
Inc #count
If #count < 26 Then AddEntry
Set #count 1
AddStrings $optionlist "\n"
:AddEntry
AddStrings $optionlist "<option>" $fullname " &lt;" $emailaddress "&gt;</option>"
:EndContactsLoop
Inc #i
Goto ContactsLoop
:ExitContactsLoop


{ Get user's selections
{  Define $contact, $format
Embed $html1 "EndEmbed"
<html>
<body>
<form>
<hr>
<p>Contact:</p>
&nbsp; &nbsp;<select name="$contact">
EndEmbed
{
Embed $html2 "EndEmbed"
</select>
<hr>
<p>Bar code format:</p>
&nbsp; <input type='radio' name='$format' value='Email'> Email address<br>
&nbsp; <input type='radio' name='$format' value='Mecard' checked> Contact information, meCard format<br>
&nbsp; <input type='radio' name='$format' value='Vcard'> Contact information,  vCard format<br>
<hr>
</form>
<p>Hit <span style="font-weight: bold;">OK</span> to display the QR code in your browser,
or <span style="font-weight: bold;">Cancel</span> to abort the script.</p>
</body>
</html>
EndEmbed
{
set $html ""
AddStrings $html $html1 $optionlist $html2
Set $contact ""
Set $format ""
DialogBox $html


{ Extract a name and email address from $contact
{  Define $name, $emailaddress
Set $name $contact
ExtractName $name
Set $emailaddress $contact
ExtractEmail $emailaddress


{ Configure the URI
{  with $format, $name, $emailaddress
Goto $format
MessageBox "Script error"
Exit


:Email
Set $uristring "'http://chart.apis.google.com/chart?cht=qr&chs=500x500&chld=L&choe=UTF-8&chl=mailto%3A' + encodeURIComponent('[contact-email]')"
Goto ReplaceStuffInUri


:Mecard
Set $uristring "'http://chart.apis.google.com/chart?cht=qr&chs=500x500&chld=L&choe=UTF-8&chl=MECARD%3AN%3A' + encodeURIComponent('[contact-name]') + '%3BEMAIL%3A' + encodeURIComponent('[contact-email]') + '%3B%3B'"
Goto ReplaceStuffInUri


:Vcard
Set $uristring "'http://chart.apis.google.com/chart?cht=qr&chs=500x500&chld=L&choe=UTF-8&chl=BEGIN%3AVCARD%0AN%3A' + encodeURIComponent('[contact-name]') + '%0AEMAIL%3A' + encodeURIComponent('[contact-email]') + '%0AEND%3AVCARD'"
Goto ReplaceStuffInUri


:ReplaceStuffInUri
StringPos #pos "[contact-name]" $uristring
If #pos < 1 Then DoContactEmail
SubStrings $uristring "[contact-name]"
InsertString $uristring #pos $name
:DoContactEmail
StringPos #pos "[contact-email]" $uristring
If #pos < 1 Then DisplayCode
SubStrings $uristring "[contact-email]"
InsertString $uristring #pos $emailaddress


:DisplayCode
{ Create HTML page; save it; open it
Embed $html "EndEmbed"
<html>
<body>
<script type='text/javascript'>
location = [uri];
</script>
</body>
</html>
EndEmbed
StringPos #pos "[uri]" $html
SubStrings $html "[uri]"
InsertString $html #pos $uristring
Set $filename $scriptpath
AddStrings $filename "QRCodeGen.htm"
AppendToFile False
SaveBody $html $filename
Execute $filename


Exit
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Re: Create QR codes from address book

Postby MarkB » Mon Aug 27, 2012 12:52 am

The link that was removed from the Notes:
https://developers.google.com/chart/int ... ty_privacy

The script's dialog and the corresponding QR code:


Image

Uploaded with ImageShack.us
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 1 guest

cron