By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 921 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

Pass variables to PHP from VBA?

P: 90
First of all I apologise if this is the wrong place to post this; if it fits better somewhere else, could you either tell me, or could a mod move it for me. Thanks.


Access 2003

I've set up a phone system (using trixbox if anyone's familiar with it); and I'd like to be able to click a button on our database which will send the phone number to the phone to dial, without having to type the number in.

The first code below is the php that works, if I have it programmed into the phone and hard-code the number and the IP address (x'd out for security). Of course this makes it work for one phone, with one number.

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. function push2phone($server,$phone,$data) 
  3. $xml2 = "xml=$data"; 
  4. $post = "POST / HTTP/1.1\r\n"; 
  5. $post .= "Host: $phone\r\n"; 
  6. $post .= "Referer: $server\r\n"; 
  7. $post .= "Connection: Keep-Alive\r\n"; 
  8. $post .= "Content-Length: ".strlen($xml2)."\r\n\r\n"; 
  9. #echo $post; 
  10. $fp = @fsockopen ( $phone, 80, $errno, $errstr, 5); 
  11. if($fp) 
  12. @fputs($fp, $post.$xml2); 
  13. flush(); 
  14. fclose($fp); 
  15. ############################## 
  16. $xml = "<AastraIPPhoneTextScreen>\n"; 
  17. $xml .= "<Title>Push test</Title>\n"; 
  18. $xml .= "<MenuItem>Call Customer\n"; 
  19. $xml .= "<Prompt>Call CustName</Prompt>\n"; 
  20. $xml .= "<Dial>90xxxxxxxxxx</Dial>\n"; 
  21. $xml .= "</MenuItem>\n"; 
  22. $xml .= "</AastraIPPhoneTextScreen>\n"; 
  23. push2phone("10.0.0.xxx","10.0.0.xxx",$xml); 
  24. echo $xml; 
  25. ?>
The following is the query I'd like to run in access, and pass the results to the PHP. The form links are correct and if I run this, it comes up with the correct formatting etc.
Expand|Select|Wrap|Line Numbers
  1. CustName = Forms![Edit Cust].[CustName]
  2. Number = Forms![Edit Cust].Number
  3. Mob = Forms![Edit Cust].Mob
  4. ext = 212
  5. If IsNull(Number) = False Then
  6.     MenuNumber = "<MenuItem>" & vbCrLf & _
  7. "<Prompt>Call " & CustName & "</Prompt>" & vbCrLf & _
  8. "<URI>9" & Number & "</URI>" & vbCrLf & _
  9. "</MenuItem>" & vbCrLf
  10. Else: MenuNumber = ""
  11. End If
  12.  
  13. If IsNull(Mob) = False Then
  14.     MenuMob = "<MenuItem>" & vbCrLf & _
  15. "<Prompt>Call " & CustName & " Mobile</Prompt>" & vbCrLf & _
  16. "<URI>9" & Mob & "</URI>" & vbCrLf & _
  17. "</MenuItem>" & vbCrLf
  18. Else: MenuMob = ""
  19. End If
  20.  
  21. myxml = "xml=<AastraIPPhoneDirectory>" & vbCrLf & _
  22. "<Title>Call Customer</Title>" & vbCrLf & _
  23. MenuNumber & MenuMob & _
  24. "</AastraIPPhoneDirectory>"
So; is there anyway I can push that to the PHP, or recode the PHP into VBA?

Thanks
Mandi
Sep 16 '08 #1
Share this Question
Share on Google+
12 Replies


NeoPa
Expert Mod 15k+
P: 31,342
Mandi, I don't know PHP at all, but some of the concepts seem clear just by looking at it.

Would I be right in thinking that your aim in the VBA code is to create a large string where all the earlier PHP code is stored. The exception being that line #25 of your PHP code (in the string) is actually set to the number from your form?
Sep 16 '08 #2

P: 90
Mandi, I don't know PHP at all, but some of the concepts seem clear just by looking at it.

Would I be right in thinking that your aim in the VBA code is to create a large string where all the earlier PHP code is stored. The exception being that line #25 of your PHP code (in the string) is actually set to the number from your form?
Sort of. The VBA is set up to make the xml to be passed to the phone; populating the relevant areas with numbers and names if they exist, and excluding that section if they don't. Hence the three sections; one for phone, one for mobile, one to pull it all together.
So yes, that's the string I need.

I can understand the PHP, I know what it does, I just don't know how I can change the hardcoded xml to the variable xml from the VBA. (Explaining myself has never been my strong point; I apologise)

To run the PHP from the phone I program the button to go to the URL http://xx.xx.xx.xx/callfromdb.php which is the phone server IP and name of the PHP file.
So I assume I need to post the XML and relevant phones IP (based on the user; I can sort that with a table and DLookUp) to the PHP to be inserted into the relevant places.

I've been looking at this site here which is where I got the PHP from. Pages 14 and 44 are most relevant I think.

Does this make sense?
Sep 17 '08 #3

P: 90
I think that I need to think of this like form data. I need to name it.
For example, if I used the vba to name the xml 'xmlstring' and the relevant IP address 'phoneip', then, in the PHP, if I called them with something like
Expand|Select|Wrap|Line Numbers
  1. $xml= $_POST['xmlstring'];
  2. $phone= $_POST['phoneip'];
Then that *should* work, I think.

But how do I go about naming things like that in VBA?
I think there's something I could do with the SetRequestHeader, but when I try I just keep getting errors; so either I'm way off the mark or I'm not setting it right.
Sep 17 '08 #4

FishVal
Expert 2.5K+
P: 2,653
Hello, Mandi.

I have little to nothing knowledge in PHP.
Though I suspect you couldn't "push that to the PHP". The very idea seems to me bizzare.

Access could hardly call a procedure on PHP server. The only conventional way to do it (not sure, its only my guess) is to open php link via FollowHyperlink() VBA function.

The rest should be done by PHP code. It should query database for a value stored in a known location - special table or query exposing a single value or more general table where relevant record could be find/recognized by PHP code.

One more point.

Again, I'm not sure, but it may be possible to write to a socket in VBA code as it is an ordinary file (worth trying anyway). If not, then it may be possible in any other way to do it.

Regards,
Fish
Sep 17 '08 #5

P: 90
Hello, Mandi.

I have little to nothing knowledge in PHP.
Though I suspect you couldn't "push that to the PHP". The very idea seems to me bizzare.

Access could hardly call a procedure on PHP server. The only conventional way to do it (not sure, its only my guess) is to open php link via FollowHyperlink() VBA function.

The rest should be done by PHP code. It should query database for a value stored in a known location - special table or query exposing a single value or more general table where relevant record could be find/recognized by PHP code.

One more point.

Again, I'm not sure, but it may be possible to write to a socket in VBA code as it is an ordinary file (worth trying anyway). If not, then it may be possible in any other way to do it.

Regards,
Fish
Thanks for your reply.
I have little knowledge in most coding unfortunately.
I've been looking at php tutorials in an attempt to understand anything, but I keep coming to the block that pretty much everything it mentions is to do with form-data on websites.

The more I look around, the more confused I get.
The database we have the numbers in is access 2003, front end on each person PC, back end (including the table with the numbers in) on the server.
The phones each have their own IP (Aastra 55i IP phones) and are connected via trixbox which is another computer (running linux OS).

The php file is saved on the trixbox computer.
I want the number to be based on the record that the user is looking at on their computer.
And it has to dial on their phone, not someone elses.

With no knowledge of php, and not much of vba, I'm sure you can see why I thought the 'pushing to php' would work as I can't for the life of me figure out how to tell the computer "this user wants that number. dial it on their phone."

I have been told that it is possible to set something up so that a hyperlink can be used (http://phoneipaddress?number=01234567891), but the person who told me that just said "you'd have to write some xml glue". A week after asking for clarification I still have no reply.

Has anyone come accross anything like this; or has any idea where I can continue to look?
Sep 17 '08 #6

NeoPa
Expert Mod 15k+
P: 31,342
Mandi,

It's very important that the questions are treated as strictly logical questions. This is like cross-roads and I need to know which route to take. "Sort of yes I suppose, I really want to go there (points)" does not help me to decide which road to take. It simply leaves me needing to ask more questions. If we're lucky I can eventually pin down a route. Otherwise I am for ever trying to get beyond explanations phrased in terms for which I have no reference.

Let me try another approach. I will put down some fairly basic VBA which produces a string in the variable strMyXML. What I want you to do is to see if you can get this string to work as PHP (Your code gives no example of how the string is used to produce provide PHP which can be executed). You will of course, need to change the code manually to reflect the variable items in the code (such as phone number etc). I imagine this should be very straightforward.

If we can prove this concept (I'm interested to see how you enable your PHP code), then we can then go forward and look at what's needed for including the values from a form into your PHP string.
Expand|Select|Wrap|Line Numbers
  1. Dim strMyXML As String
  2. ...
  3. strMyXML = "<?php" & vbCRLF
  4. strMyXML = strMyXML & "#" & vbCRLF
  5. strMyXML = strMyXML & "function push2phone($server,$phone,$data)" & vbCRLF
  6. strMyXML = strMyXML & "{" & vbCRLF
  7. strMyXML = strMyXML & "$xml2 = ""xml=$data"";" & vbCRLF
  8. strMyXML = strMyXML & "$post = ""POST / HTTP/1.1\r\n"";" & vbCRLF
  9. strMyXML = strMyXML & "$post .= ""Host: $phone\r\n"";" & vbCRLF
  10. strMyXML = strMyXML & "$post .= ""Referer: $server\r\n"";" & vbCRLF
  11. strMyXML = strMyXML & "$post .= ""Connection: Keep-Alive\r\n"";" & vbCRLF
  12. strMyXML = strMyXML & "$post .= ""Content-Length: "".strlen($xml2).""\r\n\r\n"";" & vbCRLF
  13. strMyXML = strMyXML & "#echo $post;" & vbCRLF
  14. strMyXML = strMyXML & "$fp = @fsockopen ( $phone, 80, $errno, $errstr, 5);" & vbCRLF
  15. strMyXML = strMyXML & "if($fp)" & vbCRLF
  16. strMyXML = strMyXML & "{" & vbCRLF
  17. strMyXML = strMyXML & "@fputs($fp, $post.$xml2);" & vbCRLF
  18. strMyXML = strMyXML & "flush();" & vbCRLF
  19. strMyXML = strMyXML & "fclose($fp);" & vbCRLF
  20. strMyXML = strMyXML & "}" & vbCRLF
  21. strMyXML = strMyXML & "}" & vbCRLF
  22. strMyXML = strMyXML & "##############################" & vbCRLF
  23. strMyXML = strMyXML & "$xml = ""<AastraIPPhoneTextScreen>\n"";" & vbCRLF
  24. strMyXML = strMyXML & "$xml .= ""<Title>Push test</Title>\n"";" & vbCRLF
  25. strMyXML = strMyXML & "$xml .= ""<MenuItem>Call Customer\n"";" & vbCRLF
  26. strMyXML = strMyXML & "$xml .= ""<Prompt>Call CustName</Prompt>\n"";" & vbCRLF
  27. strMyXML = strMyXML & "$xml .= ""<Dial>90xxxxxxxxxx</Dial>\n"";" & vbCRLF
  28. strMyXML = strMyXML & "$xml .= ""</MenuItem>\n"";" & vbCRLF
  29. strMyXML = strMyXML & "$xml .= ""</AastraIPPhoneTextScreen>\n"";" & vbCRLF
  30. strMyXML = strMyXML & "push2phone(""10.0.0.xxx"",""10.0.0.xxx"",$xml);" & vbCRLF
  31. strMyXML = strMyXML & "echo $xml;" & vbCRLF
  32. strMyXML = strMyXML & "?>" & vbCRLF
  33. Call MsgBox(strMyXML)
The MsgBox() call at the end is to make sure that this is exactly as you expect it to be (barring possible line-wraps).

Do whatever you need to do after that to get it to be used and let us know if it works. If so, we have a way forward. If not, then either one of us has made a mistake somewhere, or the concept is fundamentally wrong & I understood you even less well than I thought ;)
Sep 17 '08 #7

FishVal
Expert 2.5K+
P: 2,653
...
I have been told that it is possible to set something up so that a hyperlink can be used (http://phoneipaddress?number=01234567891), but the person who told me that just said "you'd have to write some xml glue"....
That definitely makes sense.
Though I know nothing in web development, I'm aware of that arguments may be passes via link. That makes my previous suggestion having more sense.
The whole logic becomes tight:
  • In Access code create in a table, let us say [tblCalls] a record based on values generating via VBA code you've posted above and containing all necessary information for PHP code to make its job.
  • Using FollowHyperlink() VBA function open a link with your PHP procedure passing primary key of [tblCalls] as argument in link.
  • In PHP code query Access database to get record from [tblCalls] where primary key is what you've passed in link.

I could help you with p.1.
As for pp. 2,3 you should better ask question on PHP forum.

Regards,
Fish
Sep 17 '08 #8

P: 90
Thanks NeoPa.

I'll go play with that see if I can get it to do something.

I've always found that my biggest problem with anything is that I know how I want it to be/work/look, I just can't explain it very well.

I think with all the hunting I've been doing over the last couple of weeks I've just confused myself beyond help lol

It would be much easier for me to explain if someone had experience / knowledge of trixbox and aastra phones, but when I try to get help on those forums I just get told to try the exact thing that I originally stated in my first post.

I'll scoot and try things now.
Thanks all for your help
Sep 17 '08 #9

P: 90
  • In Access code create in a table, let us say [tblCalls] a record based on values generating via VBA code you've posted above and containing all necessary information for PHP code to make its job.
  • Using FollowHyperlink() VBA function open a link with your PHP procedure passing primary key of [tblCalls] as argument in link.
  • In PHP code query Access database to get record from [tblCalls] where primary key is what you've passed in link.
That sounds logical.
To generate the values I guess it's as simple as an append query with the critera set to the open forms customer number, and selecting the customer number, phone number and possibly mobile number if I eventually get it working okay.
I think I can work most of that, but I think you're right about moving to a PHP board.

Thank you for all your help, and thank you for putting up with my incredibly bad explanations.

Mandi
Sep 17 '08 #10

NeoPa
Expert Mod 15k+
P: 31,342
No worries Mandi.

I'm sure if you can provide the answers I need then we have a good path forwards :)
Sep 17 '08 #11

P: 90
NeoPa

Thanks for your help, but I've found a solution.
I think I was over-complicating things.
Solution at this thread

Thanks for trying to help, and for putting up with my bad explanations ;)

Mandi
Sep 17 '08 #12

NeoPa
Expert Mod 15k+
P: 31,342
No worries Mandi. You got your solution and that's the main thing :)
Sep 17 '08 #13

Post your reply

Sign in to post your reply or Sign up for a free account.