include dirname(__FILE__) . '/../../config/config.inc.php'; } if (file_exists(dirname(__FILE__) . '/dao.class.php')) { include_once "dao.class.php"; } /* Variables */ $dao = new Dao(); $key = $_GET["key"]; /* Read header */ function readHeader($c, $str) { header($str . "\n"); return strlen($str); } /* Get OpenSi invoice */ $return = $dao->getInvoice($key); if (isset($return[0]['number_invoice'])) { /* Call webservice - curl */ $c = curl_init(); curl_setopt($c, CURLOPT_URL, Configuration::get('OSI_WS_URL') . '?service_id=' . Configuration::get('OSI_SERVICE_CODE') . '&action=get_facture&facture_ref=' . $return[0]['number_invoice'] . '.pdf'); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); curl_setopt($c, CURLOPT_HEADERFUNCTION, "readHeader"); curl_setopt($c, CURLOPT_USERPWD, Configuration::get('OSI_WS_LOGIN') . ':' . Configuration::get('OSI_WS_PASSWD')); $output = curl_exec($c); if ($output === false) { trigger_error("Erreur curl : " . curl_error($c), E_USER_WARNING); } else { header('Content-type: application/pdf'); header('Content-Disposition: attachement; filename=facture_' . $return[0]['number_invoice'] . '.pdf'); echo $output; }