query access database remotely?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mandanarchi
    New Member
    • Sep 2008
    • 90

    query access database remotely?

    Before I begin I want to apologise if my explanations are less than clear; that said, I'll try and be as detailed as possible.

    Scenario:
    User (XP OS, running office 2003) - IP = 1xx.x.x.101
    phone system (linux OS, running 'trixbox') - IP = 1xx.x.x.222
    phones (aastra 55i IP phones) - IP = 1xx.x.x.201

    I want to be able to click a button on the customer record on our database on their computer, and have that customers number sent to the phone, so picking up the phone dials the number.
    Still with me?

    M'kay.
    I have a php file that does what I want, IF I hard code the number and phones IP address into it. Obviously useless in the context I want it. (See bottom of post for code)

    I know it's possible to send the info as a hyperlink such as http://1xx.x.x.222/callfromdb.php? number=01234567 890&ipadd=1xx.x .x.201
    (I think that's where I'd have to send it anyway. That's the link I have hard-coded into the phone (before the ?) which worked, but now for some reason doesn't.

    This sounds like the most plausible method (from my extremely limited knowledge), so could someone help me modify the code for this method please?

    I know about POST and GET, but the tutorials are confusing the heck outta me, and I think I've fried my brain.

    callfromdb.php
    Code:
    <?php
    #
    function push2phone($server,$phone,$data)
    {
    $xml = "xml=".$data;
    $post = "POST / HTTP/1.1\r\n";
    $post .= "Host: $phone\r\n";
    $post .= "Referer: $server\r\n";
    $post .= "Connection: Keep-Alive\r\n";
    $post .= "Content-Type: text/xml\r\n";
    $post .= "Content-Length: ".strlen($xml)."\r\n\r\n";
    $fp = @fsockopen ( $phone, 80, $errno, $errstr, 5);
    if($fp)
    {
    fputs($fp, $post.$xml);
    flush();
    fclose($fp);
    }
    }
    ##############################
    $xml = "<AastraIPPhoneTextMenu>\n";
    $xml .= "<Title>Call Customer</Title>\n";
    $xml .= "<MenuItem>\n";
    $xml .= "<Prompt>Call Customer</Prompt>\n";
    $xml .= "<URI>Dial:01234567890</URI>\n";
    $xml .= "</MenuItem>\n";
    $xml .= "</AastraIPPhoneTextMenu>\n";
    push2phone("1xx.x.x.222","1xx.x.x.201" ,$xml);
    ?>
    I can more-or-less understand the code; I just don't know where to begin rewriting it.
    Code:
    $_REQUEST['number']
    apparently features somewhere; or possibly GET instead of request.

    If you follow this and understand it, you're a genius and I thank you.
    If you need clarification on something, please ask and I'll try my hardest not to make it worse.

    Thank you all in advance for any help you can give.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    So all you need, essentially, is to replace the hard-coded number and phone IP address with the values from the GET string?

    You could simply do this at the top of the page:
    [code=php]
    $phoneNumber = $_GET['number'];
    $phoneIP = $_GET['ipaddr'];
    [/code]
    And the replace the hard coded lines with those variables.
    Like say:
    [code=php]
    $data = "<URI>Dial: $phoneNumber</URI>";
    myFunction($pho neIP, $data);
    [/code]

    Comment

    • mandanarchi
      New Member
      • Sep 2008
      • 90

      #3
      Originally posted by Atli
      [code=php]
      $phoneNumber = $_GET['number'];
      $phoneIP = $_GET['ipaddr'];
      [/code]
      Does it matter where in the code I put that?
      Cos I've tried and nothing happens; I just get taken to a blank webpage.

      Thanks

      Comment

      • mandanarchi
        New Member
        • Sep 2008
        • 90

        #4
        Hang on, it kinda works.

        It seems to work intermittently.
        I went to the page and it work; rang and everything.
        Then I tried going again and nothing happened.

        I think there must be some sort of delay or something, but I guess that's more phone related than something wrong with the php...

        Thank you =)

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          The delay could be because of the Connection header you set there.
          Try changing it from "Keep-Alive" to "Close".

          That should tell the phone to close the connection immediately.

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Heya, mandanarchi.

            Try removing the '@' in front of fsockopen() and looking at this article to see if anything untoward is going on.

            Comment

            • mandanarchi
              New Member
              • Sep 2008
              • 90

              #7
              Thanks both.

              Once I'd added it to the VBA (using the 'follow hyperlink' method) all was fine.
              My only snag is that it opens IE or FF (depending on default); but I know that's the normal behaviour of the method.

              Code:
              <?php
              #
              function push2phone($server,$phone,$data)
              {
              $phonenumber = $_REQUEST['number'];
              $phone = $_REQUEST['phone'];
              
              $xml = "xml=".$data;
              $post = "POST / HTTP/1.1\r\n";
              $post .= "Host: $phone\r\n";
              $post .= "Referer: $server\r\n";
              $post .= "Connection: Keep-Alive\r\n";
              $post .= "Content-Type: text/xml\r\n";
              $post .= "Content-Length: ".strlen($xml)."\r\n\r\n";
              $fp = @fsockopen ( $phone, 80, $errno, $errstr, 5);
              if($fp)
                      {
                      fputs($fp, $post.$xml);
                      flush();
                      fclose($fp);
                      }
              }
              ##############################
              
              $xml = "<AastraIPPhoneTextMenu>\n";
              $xml .= "<Title>Call Customer</Title>\n";
              $xml .= "<MenuItem>\n";
              $xml .= "<Prompt>Call Customer</Prompt>\n";
              $xml .= "<Dial>$phonenumber</Dial>\n";
              $xml .= "</MenuItem>\n";
              $xml .= "</AastraIPPhoneTextMenu>\n";
              push2phone("serverIP",$phone,$xml);
              ?>
              That's my working code. I just follow the hyperlink to http://serverIP/callfromdb.php? phone=[phoneIP]&number=[number2dial] and it works.

              Thank you =)

              Comment

              Working...