Great discoveries this past week. First of all, Debugbar is a great plugin for Internet Explorer for examining the DOM of websites, especially those that have complex dynamically created DOM with javascript. Also you can run javascript in the Debugbar console on the website without resorting to "navigating" out of the URL (you don't have to type the script into the URL input field, or navigate out of the native URL using links or favorites), which makes running these scripts possible when you have Web Controls/Agents on your source URL.
You can access the data within a frame in the DOM using the following javascript syntax:
str = top.myframename.document.GetElementById('myelementid').innerHTML;
and then use javascript REGULAR EXPRESSIONS (Regex) functions to parse the data into usable formats
Autohotkey is capable of launching javascript, but it is trickey. You have to either use the URL input field or Debugbar Javascript Console to do it, neither of which is elegant, or you have to use the COM library which is documented on the Autohotkey forum, again, which will require a learning curve. A better solution is to use Autohotkey to reliably click the correct objects in the browser, and the two tricks I have learned are:
CoordMode, Mouse, Screen
That line allows you to accurately base Mouse Movements and Click Coordinates to be relative to the screen instead of to the window, which helps when the script is popping up windows all over the place. The other trick is
Sleep, 100
Between each Click, it's good to pause the program for 1/10th of a second to let the computer catch up with itself. Prevents errors.
Tuesday, July 27, 2010
Monday, July 5, 2010
PHP Script accept query string data and place onto PDF form
require_once('fpdf.php');
require_once('fpdi.php');
$pdf = new FPDI();
$pdf->AddPage();
$pdf->setSourceFile('../pdfdoc\MedSolMRICTheadneck.pdf');
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 10, 10, 200);
$pdf->SetFont('Arial','B',10);
$pdf->SetTextColor(0,0,255);
$pdf->SetXY(56, 50);
$pdf->Write(0, $_GET['lastname'].'---'.$_GET['firstname'].'---'.$_GET['dob']);
$pdf->Output();
?>
Notes:
-The $_GET[] array names are in quotes to make WAMP happy and match the query string names the the javascript bookmarklet that sent the query
-The main work in writing this is finding the XY coordinates in the third to last line
-Copy and paste the 4 line block for each data entry point on the form, each with its own XY coordinates
-Note the color 0,0,255 (blue). Other useful colors: 0,0,0 - black and 255,0,0 - red.
-Note the 'B' parameter in font for bold: helpful when filling out forms.
-Note the source file path with the backslashes again to make WAMP happy.
So, big picture: You've invoked a bookmarklet to navigate from a website with data to a PHP script on WAMP which pulls up a PDF document in your localhost directory tree and inserts the data on the form. Now you run your AutoHotKey script to print or fax it.
require_once('fpdi.php');
$pdf = new FPDI();
$pdf->AddPage();
$pdf->setSourceFile('../pdfdoc\MedSolMRICTheadneck.pdf');
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 10, 10, 200);
$pdf->SetFont('Arial','B',10);
$pdf->SetTextColor(0,0,255);
$pdf->SetXY(56, 50);
$pdf->Write(0, $_GET['lastname'].'---'.$_GET['firstname'].'---'.$_GET['dob']);
$pdf->Output();
?>
Notes:
-The $_GET[] array names are in quotes to make WAMP happy and match the query string names the the javascript bookmarklet that sent the query
-The main work in writing this is finding the XY coordinates in the third to last line
-Copy and paste the 4 line block for each data entry point on the form, each with its own XY coordinates
-Note the color 0,0,255 (blue). Other useful colors: 0,0,0 - black and 255,0,0 - red.
-Note the 'B' parameter in font for bold: helpful when filling out forms.
-Note the source file path with the backslashes again to make WAMP happy.
So, big picture: You've invoked a bookmarklet to navigate from a website with data to a PHP script on WAMP which pulls up a PDF document in your localhost directory tree and inserts the data on the form. Now you run your AutoHotKey script to print or fax it.
AutoHotKey Script for Emailing a PDF File
:*:][::
Send {Click 1228,100}
Send {Click 1145,254}
SetKeyDelay,700,100
Send !a
SetKeyDelay,50,100
Send doc@scanr.com
Send {Tab}{Tab}{tab}^a
SendRaw +18005551212
Send !s
return
The keystrokes ][ trigger two mouseclicks to pull "send page" from EI7, followed by keystrokes that send the attachment to an online faxing service.
(Note: the asterisk near the beginning causes the script to execute immediately with the ][ trigger, without a following spacebar. Sometimes, you need to precede the execution with a spacebar keystroke to "clear" previous keystrokes.)
Send {Click 1228,100}
Send {Click 1145,254}
SetKeyDelay,700,100
Send !a
SetKeyDelay,50,100
Send doc@scanr.com
Send {Tab}{Tab}{tab}^a
SendRaw +18005551212
Send !s
return
The keystrokes ][ trigger two mouseclicks to pull "send page" from EI7, followed by keystrokes that send the attachment to an online faxing service.
(Note: the asterisk near the beginning causes the script to execute immediately with the ][ trigger, without a following spacebar. Sometimes, you need to precede the execution with a spacebar keystroke to "clear" previous keystrokes.)
Javascript to fetch and submit data
This script will fetch data from the input fields of a web site and submit the data as a query string to a URL of your choosing:
javascript:
var lastname_elem = document.getElementById
('ctl00_ContentPlaceHolder1_txtLName');
var lastname = lastname_elem.value;
alert(lastname);
var firstname_elem = document.getElementById
('ctl00_ContentPlaceHolder1_txtFName');
var firstname = firstname_elem.value;
alert(firstname);
var dob_elem = document.getElementById
('ctl00_ContentPlaceHolder1_txtDOB');
var dob = dob_elem.value;
alert(dob);
open('http://example.com?lastname='+lastname+
'&firstname='+firstname+
'&dob='+dob,
'_self',
'resizable,location,menubar,toolbar,scrollbars,status');
You just need to find out the element id for the input fields. This example pops the data from the input fields into alert text boxes before submitting the get request to the next web site, for debugging purposes.
javascript:
var lastname_elem = document.getElementById
('ctl00_ContentPlaceHolder1_txtLName');
var lastname = lastname_elem.value;
alert(lastname);
var firstname_elem = document.getElementById
('ctl00_ContentPlaceHolder1_txtFName');
var firstname = firstname_elem.value;
alert(firstname);
var dob_elem = document.getElementById
('ctl00_ContentPlaceHolder1_txtDOB');
var dob = dob_elem.value;
alert(dob);
open('http://example.com?lastname='+lastname+
'&firstname='+firstname+
'&dob='+dob,
'_self',
'resizable,location,menubar,toolbar,scrollbars,status');
You just need to find out the element id for the input fields. This example pops the data from the input fields into alert text boxes before submitting the get request to the next web site, for debugging purposes.
Sunday, July 4, 2010
More on MAMP to WAMP migration - fpdf Scripts
Not sure if this is a MAMP to WAMP issue or a PHP 5.2 to 5.3 issue, since both changed at the same time but here is what I found while migrating fpdf scripts:
1. MAMP likes the &= syntax. Change to = in WAMP. If you don't, you will get a lengthy error message.
2. If you open a pdf file and view it in the Internet Explorer Browser, and get a whole lot of gibberish characters, if you close your browser and reopen it and try again, the pdf will open normally. It either has something to do with cacheing or with IE security settings in tying browser objects to Adobe Reader, a third-party application. I have also read that it is a IE6 bug, although it happened to me in IE7. If it persists, perhaps switching to firefox would help, I never did that experiment.
1. MAMP likes the &= syntax. Change to = in WAMP. If you don't, you will get a lengthy error message.
2. If you open a pdf file and view it in the Internet Explorer Browser, and get a whole lot of gibberish characters, if you close your browser and reopen it and try again, the pdf will open normally. It either has something to do with cacheing or with IE security settings in tying browser objects to Adobe Reader, a third-party application. I have also read that it is a IE6 bug, although it happened to me in IE7. If it persists, perhaps switching to firefox would help, I never did that experiment.
Sunday, June 27, 2010
Strategy Session
I have re-thought the overall strategy for a particular kind of application. Here are the steps that I think will be successful:
1. Use javascript bookmarklets to run customized code within the browser that interacts with the infomation within the browser window from the server. (Trigger the bookmarklets by setting up icons in the "links bar" for IE or the "bookmarks bar" for Safari.)
2. Use javascript cookies (within the document object) to store and retrieve data from the server, and to monitor the client for subscription expiration dates. Encrypt and delete the relevent information after use.
3. Use javascript to trigger 'autohotkey scripts' for windows or 'language&text shortcuts' for mac. This allows screentouch activation of specific shortcuts without needing a platform-specific keyboard, or a keyboard at all.
4. Use VNC to allow cross-platform access to the browser (such as from a mobile phone or tablet device). Use VPN to allow remote desktop connections to potential customers for set-up and troubleshooting.
5. Market the product/service via Twitter ( instead of by mail / email / phone / meeting / advertising / facebook ). Start with the major blog-style twitterers with large followings (within the appropriate subject matter), and then enter their "following lists" for ever expanding names of leaders for targeted populations.
1. Use javascript bookmarklets to run customized code within the browser that interacts with the infomation within the browser window from the server. (Trigger the bookmarklets by setting up icons in the "links bar" for IE or the "bookmarks bar" for Safari.)
2. Use javascript cookies (within the document object) to store and retrieve data from the server, and to monitor the client for subscription expiration dates. Encrypt and delete the relevent information after use.
3. Use javascript to trigger 'autohotkey scripts' for windows or 'language&text shortcuts' for mac. This allows screentouch activation of specific shortcuts without needing a platform-specific keyboard, or a keyboard at all.
4. Use VNC to allow cross-platform access to the browser (such as from a mobile phone or tablet device). Use VPN to allow remote desktop connections to potential customers for set-up and troubleshooting.
5. Market the product/service via Twitter ( instead of by mail / email / phone / meeting / advertising / facebook ). Start with the major blog-style twitterers with large followings (within the appropriate subject matter), and then enter their "following lists" for ever expanding names of leaders for targeted populations.
Monday, June 21, 2010
Migrating PHP/SQL from MAMP to WAMP
1. Exported my database to a .sql file, using phpmyadmin. Created a new database with the same name in WAMP and left it empty. Then imported it within the phpmyadmin environment using the import function from within the empty database. Initially got error message because the database exceeded the 2MB size limit (it was 7.5MB) but followed the directions as prompted to change the php.ini file so that the max_filesize parameter was 8MB.
2. PHP scripts that ran in MAMP initially wouldn't run in WAMP. Got error messages saying I had to initiallize array variables before using them, and "undefined constant blah, assumed 'blah' " meaning put array component names in quotes, as in $array["blah"] not $array[blah].
3. Various allowable permutations of embedding SQL commands within PHP using different orders of double or single quotes behave erratically in WAMP, much testing and debugging necessary.
4. Default user/password to access mysql in MAMP ("root"/"root") changed to "root"/"" in WAMP.
2. PHP scripts that ran in MAMP initially wouldn't run in WAMP. Got error messages saying I had to initiallize array variables before using them, and "undefined constant blah, assumed 'blah' " meaning put array component names in quotes, as in $array["blah"] not $array[blah].
3. Various allowable permutations of embedding SQL commands within PHP using different orders of double or single quotes behave erratically in WAMP, much testing and debugging necessary.
4. Default user/password to access mysql in MAMP ("root"/"root") changed to "root"/"" in WAMP.
Subscribe to:
Posts (Atom)