Friday, April 19, 2013

How to get all Calendar Names for a Zimbra Mail user using SOAP


I came across such a requirement while working on a project which uses Zimbra Mail Server ( version 7.0 ). I spent hours searching for a proper example or documentation on how to do this.In spite of spending so many hours i couldn't find any proper example at all. However i managed to find out how to do this by trial and error method. So i thought it would be good to share how i did it with all.

Note: Soap extension should be enabled in your web server.

Now you can try the following code to get list of all calendars in a user account.


 <?php  
      function xml2array ( $xmlObject, $out = array () )  
      {  
           foreach ( (array) $xmlObject as $index => $node )  
                $out[$index] = ( is_object ( $node ) ) ? xml2array ( $node ) : $node;  
           return $out;  
      }  
   $client = new SoapClient(null,  
     array(  
       'location' => "YOUR ZIMBRA SOAP URL",  
       'uri' => "urn:zimbraAccount",  
       'trace' => 1,  
       'exceptions' => 1,  
       'soap_version' => SOAP_1_1,  
       'style' => SOAP_RPC,  
       'use' => SOAP_LITERAL  
     )  
   );  
   echo "Client Built<br>";  
      //Provide username (eg. mm@zimbra.testdomain.com) and password       
      $var = new SoapVar('<account by="name">mm@zimbra.testdomain.com</account><password>mmr123c</password>', XSD_ANYXML);            
      $params = array(  
                $var,  
                );                 
   echo "Params built<br>";  
   try {  
     echo "Creating header<br>";  
     $soapHeader = new SoapHeader(  
           'urn:zimbraAccount',  
           'context'  
           );  
     echo "Authorizing<br>";      
     $result = $client->__soapCall(  
           "AuthRequest",   
           $params,   
           null,  
           $soapHeader  
     );  
     echo "Authorized<br>";    
           $authToken=$result['authToken'];  
     //print_r($result);  
                try {  
                     echo "Trying to get Folders<br>";  
                     $soapHeader = new SoapHeader(  
                                    'urn:zimbraMail',  
                                    'context',  
                                         new SoapVar(  
                                              '<ns1:context><format type="xml" /></ns1:context>',  
                                              XSD_ANYXML  
                                         )                                     
                                    );  
                     $result = $client->__soapCall(  
                                    "GetFolderRequest",   
                                    array(''),   
                                    array('uri' => 'urn:zimbraMail'),  
                                    $soapHeader  
                     );  
                     echo "Got folder info<br>";    
                     $xml = new SimpleXMLElement($client->__getLastResponse());  
                     $xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');  
                     $body = $xml->xpath('//soap:Body');  
                     $xml->registerXPathNamespace('zimbra', 'urn:zimbraMail');  
                     $GetFolderResponse = $xml->xpath('//soap:Body/zimbra:GetFolderResponse');  
                     $folder = $GetFolderResponse[0]->folder;  
                     $folder->registerXPathNamespace('zimbra', 'urn:zimbraMail');  
         $appointments = $folder->xpath('zimbra:folder[@view="appointment"]');  
                     $links = $folder->xpath('zimbra:link[@view="appointment"]');  
                     //print_r($appointments);  
                     //print_r($links);  
                     $appointments = xml2array ( $appointments, $out = array () );  
                     $links = xml2array ( $links, $out = array () );  
                     echo "<pre/>";  
                     print_r($appointments);  
                     print_r($links);  
                     //echo htmlentities($client->__getLastRequest()) . "<br><br>";  
         //echo htmlentities($client->__getLastResponse()) . "<br><br>";  
                } catch (SoapFault $exception) {  
                     echo "exception caught while trying to fetch Folder info<br><br>";  
                     //echo htmlentities($client->__getLastRequest()) . "<br><br>";  
                  // echo htmlentities($client->__getLastRequestHeaders()) . "<br><br>";  
                  // echo htmlentities($client->__getLastResponseHeaders()) . "<br><br>";  
                     echo htmlentities($client->__getLastResponse()) . "<br><br>";  
                     //echo $exception . "<br><br>";  
                }  
   } catch (SoapFault $exception) {  
     echo "exception caught while trying to authorize<br><br>";  
     //echo htmlentities($client->__getLastRequest()) . "<br><br>";  
     // echo htmlentities($client->__getLastRequestHeaders()) . "<br><br>";  
     //echo htmlentities($client->__getLastResponseHeaders()) . "<br><br>";  
     echo htmlentities($client->__getLastResponse()) . "<br><br>";  
     //echo $exception . "<br><br>";  
   }  
 ?>  

Friday, December 21, 2012

To all Developers who have integrated Twitter@Anywhere:

It is deprecated and will stop functioning soon. Please follow below URL to see more information regarding this.

https://dev.twitter.com/blog/sunsetting-anywhere

Monday, July 21, 2008

Implementing Website payments pro (Payflow pro) using PHP

Use the following functions to implement website payments pro or payflow pro.













Include the above functions then do the following.

Tuesday, June 24, 2008

Paypal Reporting API - PHP code

Most of the websites use paypal processor for their online payments.Transaction details and various reports can be checked from Paypal Manager interface. The same reports can be generated using API calls(reporting xml api).We can generate reports using PHP as follows.

Library needed

1. Curl

Common Parameters for all API calls

All the API call require payal account information.So we can save these details in an array as follows.




Common Functions

The following functions are common for all API calls.












Steps to generate Custom Reports

1.The parameters needed for generating a custom report are 'start_date' and 'end_date'.So we can save the parameters in an array as follows.



2.Now we can run the report request as follows.



Here the second parametes is the name of the report.To generate another report we just need to change the report name and give the corresponding parameters in the parameter array.Remeber to give parameter names as keys of parameter array.

3.We will get reportId if the above Api call is successful.We can parse the response from above call and get reportId as follows.



4. Request for the results.



5.Now we can get all the fields in the report.



We can arrange the field names in an array using the function GenerateFieldArray().



6.Finally we can get data for our report.



Now we just need to display it in a report format.

Saturday, June 21, 2008

The accident...

Hi guys..

I would like to share some of those funny moments which we may come across in our day to day life.Have a good a laugh at the following one.

It was a really busy day at office.After having a wrestling with my client to make him understand some of the issues in the project ,which he never understood... i was really tired.As usual i took bus to home from bus station.The traffic on the roads seemed more hectic than usual.Once the bus got out of the city traffic, the driver was in a hurry to make up for the lost time.It was past 7 pm and there was hardly any light on the village roads.

The bus was taking a turn at some high speed,suddenly there was a huge noise from passengers on the bus.When the driver turned around,he saw the passengers and the conductor, who stood on the door step shouting at him to stop the bus.The driver soon had his thoughts on the person walking on the side of the road...may be he is being hit...By the time the bus stopped, the conductor jumped out and started running backwards.

The poor driver was really frightened of the consequences which drivers has to face on such occasions.Locals running in will usually handle the driver before contacting the police.Having seen the conductor running away, the driver jumped out and ran as if he is participating in a 100 m race.

By the time the conductor returned to the bus after taking the money bag which had fallen out of his hand while the bus was taking the turn,he saw the passengers having a laugh riot.I was having the laugh of my life and there was not even a single drop of stress left on my mind.One of the passengers told the conductor what happened... he too couldn't resist the comedy.Finally the conductor took his mobile and called the driver and told him what happened.The driver may have reached miles away or may be he was more afraid of the laughter people will have on him,it took some time before he returned.

I still remember the face of the driver....No words can explain the expression on his face....