Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 27th, 2012  |  syntax: None  |  size: 7.91 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. require_once 'Zend/Loader.php';
  3.  
  4. //Mimeo Account Information
  5. $Mimeo_Root_URL = "https://connect.sandbox.mimeo.com/2010/09/";
  6. $Mimeo_User_Name = "[YOUR MIMEO EMAIL ADDRESS]";
  7. $Mimeo_Password = "[YOUR MIMEO PASSWORD]";
  8.  
  9. //Actually Register the Printer
  10. $client = new Zend_Gdata_HttpClient();  
  11. $client = $client->setClientLoginToken($_SESSION['Client_Login_Token']);
  12.  
  13. $client->setHeaders('Authorization','GoogleLogin auth='.$_SESSION['Client_Login_Token']);
  14. $client->setHeaders('X-CloudPrint-Proxy','Mimeo');             
  15.  
  16. //GCP Services - Register
  17. $client->setUri('http://www.google.com/cloudprint/interface/fetch');
  18.  
  19. // Your printer definition                                             
  20. $Printer_ID = "[Your Printer ID]";
  21.  
  22. //echo "Fetching: " . $Printer_ID . "<br />";
  23. $client->setParameterPost('printerid', $Printer_ID);
  24. $response = $client->request(Zend_Http_Client::POST);
  25. $JobResponse = json_decode($response->getBody());
  26.  
  27. if(isset($JobResponse->jobs))
  28.         {
  29.                
  30.         $Jobs = $JobResponse->jobs;
  31.        
  32.         // ----------------
  33.         // Retrieve a list of print jobs for printer
  34.         // ----------------
  35.        
  36.         foreach($Jobs as $Job)
  37.                 {
  38.        
  39.                 $Job_ID = $Job->id;
  40.                 $Job_Title = $Job->title;
  41.                 $Job_Content_Type = $Job->contentType;
  42.                 $File_URL = $Job->fileUrl;
  43.                 $Job_NumberPages = $Job->numberOfPages;
  44.                 $Job_Status = $Job->status;
  45.                
  46.                 $client->setUri($File_URL);
  47.                 $FileResponse = $client->request(Zend_Http_Client::POST);
  48.                 $FileContent = $FileResponse->getBody();                                                                                       
  49.                
  50.                 //  Set a local folder you wish to save print job PDF to.
  51.                 $Save_Filename = 'files/' . $Job_ID . ".pdf";
  52.                
  53.                 //echo "Saving " . $Save_Filename . "<br />";
  54.             $fh = fopen($Save_Filename, "w");
  55.             if($fh==false)
  56.                 die("unable to create file");
  57.             fputs($fh,$FileContent,strlen($FileContent));
  58.             fclose ($fh);      
  59.        
  60.                 // Set a Full URL for your File
  61.             $Print_Job_URL = "http://yourdomain.com/" . $Save_Filename;
  62.                                                                                                        
  63.                 // ----------------
  64.                 // Begin Send a Print Job to Mimeo
  65.                 // ----------------
  66.                
  67.                 // Order Delivery Information - Where Are You Sending?  Users Info Should be Registered Somewhere
  68.                 $CompanyName = "";
  69.                 $FirstName = "";
  70.                 $LastName = "";
  71.                 $Name = "";
  72.                 $CareOf = "";
  73.                 $Street = "";
  74.                 $ApartmentOrSuite = "";
  75.                 $StateOrProvince = "";
  76.                 $City = "";
  77.                 $PostalCode = "";
  78.                 $Country = "";
  79.                 $IsResidential = "";
  80.                 $TelephoneNumber ="";
  81.                 $Email= "";
  82.                
  83.                 // billing card info - Do not include if account credit or credit card
  84.                 $NameOnCard= "";
  85.                 $Number= "";
  86.                 $BillingPostalCode= "";
  87.                 $CreditCardType= "";
  88.                 $ExpirationMonth= "";
  89.                 $ExpirationYear= "";
  90.          
  91.          
  92.                 // Create a new product for ordering in the Mimeo system.        
  93.                 $rest = new MimeoRESTClient($Mimeo_Root_URL,$Mimeo_User_Name,$Mimeo_Password);
  94.                 $template = "custom";
  95.                 $url = "OrderService/NewProduct?template=" . $template . "&documentTemplateId=" . $Document_ID;
  96.                 $rest->createRequest($url,"GET","");
  97.                 $rest->sendRequest();
  98.                 $output = $rest->getResponseBody();
  99.                 $OrderTemplate = $output;
  100.                
  101.                 $xml = new SimpleXMLElement($output);
  102.                 $OrderXML = new SimpleXMLElement($output);
  103.                        
  104.                 //Set these source of Document to be the PDF that is coming from Google Apps - Google Cloud Print
  105.                 $xml->Product->Content->DocumentSection[0]->Source = $Job_URL;
  106.  
  107.                 // Set Shipping Information
  108.                 $xml->Addresses->RecipientAddress->CompanyName = $CompanyName;
  109.                 $xml->Addresses->RecipientAddress->Name = $Name;
  110.                 $xml->Addresses->RecipientAddress->FirstName = $FirstName;
  111.                 $xml->Addresses->RecipientAddress->LastName = $LastName;
  112.                 $xml->Addresses->RecipientAddress->CareOf = $CareOf;
  113.                 $xml->Addresses->RecipientAddress->Street = $Street;
  114.                 $xml->Addresses->RecipientAddress->ApartmentOrSuite = $ApartmentOrSuite;
  115.                 $xml->Addresses->RecipientAddress->City = $City;
  116.                 $xml->Addresses->RecipientAddress->StateOrProvince = $StateOrProvince;
  117.                 $xml->Addresses->RecipientAddress->PostalCode = $PostalCode;
  118.                 $xml->Addresses->RecipientAddress->Country = $Country;
  119.                 $xml->Addresses->RecipientAddress->TelephoneNumber = $TelephoneNumber;
  120.                 $xml->Addresses->RecipientAddress->Email = $Email;
  121.                 $xml->Addresses->RecipientAddress->IsResidential = $IsResidential;
  122.                        
  123.                 ///Set the order quantity
  124.                 $xml->Details->OrderQuantity = "1";
  125.                
  126.                 //Set the XML to Send Back
  127.                 $SendXML = $xml->asXML();
  128.                
  129.                 // Get the shipping options for this new product, with applied shipping information.
  130.                 // Currently just pulls the 1 to 3 Days entry entry, it can be updated to be more logical
  131.                
  132.                 $rest = new MimeoRESTClient($Mimeo_Root_URL,$Mimeo_User_Name,$Mimeo_Password);
  133.                 $url = "OrderService/GetShippingOptions";
  134.                 $rest->createRequest($url,"POST","");
  135.                 $rest->setHeader("Content-Type","application/xml");
  136.                 $rest->setBody($SendXML);
  137.                 $rest->sendRequest();
  138.                 $shipopts = $rest->getResponseBody();
  139.                
  140.                 //Store Order Template for Manipulation
  141.                 $xml = new SimpleXMLElement($shipopts);
  142.                
  143.                 $ShippingChoice = "";
  144.                 $_SESSION['Shipping'] = "";
  145.                 foreach ($xml->Details->ShippingOptions->ShippingOption as $ShippingOption)
  146.                         {
  147.                
  148.                         if($ShippingOption->Name == '1 to 3 Days')
  149.                                 {
  150.                                 $ShippingChoice = $ShippingOption->Id;
  151.                                 $ShippingChoiceName = $ShippingOption->Name;
  152.                                 $Shipping_Choice = $ShippingChoice;
  153.                                 $Shipping_Choice_Name = trim(strip_tags($ShippingChoiceName));                                 
  154.                                 }
  155.                                
  156.                         }
  157.  
  158.                 ///Set the order ShippingChoice for the Order
  159.                 $xml->Details->ShippingChoice = $ShippingChoice;
  160.                 $xml->Details->ShippingOptions = "";
  161.        
  162.                 //Set the XML to Send Back
  163.                 $SendXML = $xml->asXML();
  164.                
  165.                 // Get the Quote for this Order
  166.                 $rest = new MimeoRESTClient($Mimeo_Root_URL,$Mimeo_User_Name,$Mimeo_Password);
  167.                 $url = "OrderService/GetQuote";
  168.                 $rest->createRequest($url,"POST","");
  169.                 $rest->setHeader("Content-Type","application/xml");
  170.                 $rest->setBody($SendXML);
  171.                 $rest->sendRequest();
  172.                 $orderquote = $rest->getResponseBody();
  173.        
  174.                 $xml = new SimpleXMLElement($orderquote);
  175.                
  176.                 $OrderQuantity = $xml->Details->OrderQuantity;
  177.                
  178.                 $ProductPrice = number_format(round($xml->Details->ProductPrice,4), 2, '.', ',');
  179.                 $ShippingPrice = number_format(round($xml->Details->ShippingPrice,4), 2, '.', ',');
  180.                 $TotalPrice = number_format(round($xml->Details->TotalPrice,4), 2, '.', ',');
  181.  
  182.                 echo "<h3>Order Details</h3><ul>";
  183.                 echo "<li><strong>Quantity:</strong> " . $OrderQuantity . "</li>";     
  184.                
  185.                 // Set the Billing Information (If Applies)
  186.                 $xml->Payment->PaymentMethodType = "CreditCard";
  187.                 $xml->Payment->CreditCard->NameOnCard = $NameOnCard;
  188.                 $xml->Payment->CreditCard->Number = $Number;
  189.                 $xml->Payment->CreditCard->BillingPostalCode = $BillingPostalCode;
  190.                 $xml->Payment->CreditCard->CreditCardType = $CreditCardType;
  191.                 $xml->Payment->CreditCard->ExpirationMonth = $ExpirationMonth;
  192.                 $xml->Payment->CreditCard->ExpirationYear = $ExpirationYear;
  193.        
  194.                 //Set the XML to Send Back and Place Order
  195.                 $SendXML = $xml->asXML();
  196.                 $rest = new MimeoRESTClient($Mimeo_Root_URL,$Mimeo_User_Name,$Mimeo_Password);
  197.                 $url = "OrderService/PlaceOrder";
  198.                 $rest->createRequest($url,"POST","");
  199.                 $rest->setHeader("Content-Type","application/xml");
  200.                 $rest->setBody($SendXML);
  201.                 $rest->sendRequest();
  202.                 $orderinfo = $rest->getResponseBody();
  203.                 $xml = new SimpleXMLElement($orderinfo);
  204.                 $OrderID = $xml->Details->OrderId;
  205.                 $OrderFriendlyId = $xml->OrderFriendlyId;
  206.                
  207.                 // ----------------
  208.                 // End Send a Print Job to Mimeo
  209.                 // ----------------
  210.                
  211.                 // ----------------
  212.                 // Begin Update Status of Google Cloud Print Job
  213.                 // ----------------            
  214.                
  215.                 //Update Status of the Print Job with Google
  216.                 $client = Zend_Gdata_ClientLogin::getHttpClient($G_Email, $G_Pass, 'cloudprint');
  217.                 $Client_Login_Token = $client->getClientLoginToken();
  218.                 $client->setHeaders('Authorization','GoogleLogin auth='.$Client_Login_Token);
  219.                 $client->setHeaders('X-CloudPrint-Proxy','Mimeo');
  220.                
  221.                 //GCP Services - Register
  222.                 $client->setUri('http://www.google.com/cloudprint/interface/control');
  223.                 $client->setParameterPost('jobid', $Job_ID);
  224.                 $client->setParameterPost('status', 'Done');
  225.                 $response = $client->request(Zend_Http_Client::POST);
  226.                 $PrinterResponse = json_decode($response->getBody());
  227.                
  228.                 // ----------------
  229.                 // End Update Status of Google Cloud Print Job
  230.                 // ----------------            
  231.                
  232.                 }
  233.  
  234.         }                                                              
  235. ?>