<?php

class ControllerExtensionExtensionPromotion extends Controller {
	public function index() { 

        $api_ocf = '<iframe style="text-align: center;border: 1px solid #ccc;width: 100%;height: 50%;adding: 0px 0px 0px 0px;margin: 0px 0px 0px 0px;" src="'.API_OCF_AFFICHE.'"></iframe>';      

        $My_Ver['ver'] = 'oc3';
        $handle = curl_init(OPENCART_APIOCF);
        curl_setopt($handle,  CURLOPT_RETURNTRANSFER, 1);
        $rep_http = curl_exec($handle);  
        $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); 
        curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 15);                   
        curl_setopt($handle, CURLOPT_TIMEOUT, 10); 
        curl_close($handle);        
        if($httpCode == '200'){  
        $curl = curl_init(OPENCART_APIOCF);              
        curl_setopt($curl, CURLOPT_COOKIESESSION, true);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $My_Ver);              
        curl_setopt($curl, CURLOPT_SSLVERSION, 0);
       	curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15);
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        curl_setopt($curl, CURLOPT_MAXREDIRS, 2);
        $answer = curl_exec($curl);
        $errorCurl = curl_errno($curl);
        curl_close($curl);
        
        if(($errorCurl == 0) && ($answer == 'oc3')){ echo $answer;
        //if($errorCurl == 0) {
        echo $api_ocf ;
        } else{ echo $errorCurl; echo $answer;}  
        
      } elseif($httpCode == '415'){ 
        echo $httpCode.$api_ocf ;
      }                              
        else{ echo $httpCode;}  
     
	}
}
